2007-03-24 Paul Brook <paul@codesourcery.com>
[binutils-gdb.git] / gas / config / tc-arm.c
1 /* tc-arm.c -- Assemble for the ARM
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006
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 2, or (at your option)
16 any later version.
17
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with GAS; see the file COPYING. If not, write to the Free
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 02110-1301, USA. */
27
28 #include <limits.h>
29 #include <stdarg.h>
30 #define NO_RELOC 0
31 #include "as.h"
32 #include "safe-ctype.h"
33 #include "subsegs.h"
34 #include "obstack.h"
35
36 #include "opcode/arm.h"
37
38 #ifdef OBJ_ELF
39 #include "elf/arm.h"
40 #include "dw2gencfi.h"
41 #endif
42
43 #include "dwarf2dbg.h"
44
45 #define WARN_DEPRECATED 1
46
47 #ifdef OBJ_ELF
48 /* Must be at least the size of the largest unwind opcode (currently two). */
49 #define ARM_OPCODE_CHUNK_SIZE 8
50
51 /* This structure holds the unwinding state. */
52
53 static struct
54 {
55 symbolS * proc_start;
56 symbolS * table_entry;
57 symbolS * personality_routine;
58 int personality_index;
59 /* The segment containing the function. */
60 segT saved_seg;
61 subsegT saved_subseg;
62 /* Opcodes generated from this function. */
63 unsigned char * opcodes;
64 int opcode_count;
65 int opcode_alloc;
66 /* The number of bytes pushed to the stack. */
67 offsetT frame_size;
68 /* We don't add stack adjustment opcodes immediately so that we can merge
69 multiple adjustments. We can also omit the final adjustment
70 when using a frame pointer. */
71 offsetT pending_offset;
72 /* These two fields are set by both unwind_movsp and unwind_setfp. They
73 hold the reg+offset to use when restoring sp from a frame pointer. */
74 offsetT fp_offset;
75 int fp_reg;
76 /* Nonzero if an unwind_setfp directive has been seen. */
77 unsigned fp_used:1;
78 /* Nonzero if the last opcode restores sp from fp_reg. */
79 unsigned sp_restored:1;
80 } unwind;
81
82 /* Bit N indicates that an R_ARM_NONE relocation has been output for
83 __aeabi_unwind_cpp_prN already if set. This enables dependencies to be
84 emitted only once per section, to save unnecessary bloat. */
85 static unsigned int marked_pr_dependency = 0;
86
87 #endif /* OBJ_ELF */
88
89 /* Results from operand parsing worker functions. */
90
91 typedef enum
92 {
93 PARSE_OPERAND_SUCCESS,
94 PARSE_OPERAND_FAIL,
95 PARSE_OPERAND_FAIL_NO_BACKTRACK
96 } parse_operand_result;
97
98 enum arm_float_abi
99 {
100 ARM_FLOAT_ABI_HARD,
101 ARM_FLOAT_ABI_SOFTFP,
102 ARM_FLOAT_ABI_SOFT
103 };
104
105 /* Types of processor to assemble for. */
106 #ifndef CPU_DEFAULT
107 #if defined __XSCALE__
108 #define CPU_DEFAULT ARM_ARCH_XSCALE
109 #else
110 #if defined __thumb__
111 #define CPU_DEFAULT ARM_ARCH_V5T
112 #endif
113 #endif
114 #endif
115
116 #ifndef FPU_DEFAULT
117 # ifdef TE_LINUX
118 # define FPU_DEFAULT FPU_ARCH_FPA
119 # elif defined (TE_NetBSD)
120 # ifdef OBJ_ELF
121 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
122 # else
123 /* Legacy a.out format. */
124 # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
125 # endif
126 # elif defined (TE_VXWORKS)
127 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
128 # else
129 /* For backwards compatibility, default to FPA. */
130 # define FPU_DEFAULT FPU_ARCH_FPA
131 # endif
132 #endif /* ifndef FPU_DEFAULT */
133
134 #define streq(a, b) (strcmp (a, b) == 0)
135
136 static arm_feature_set cpu_variant;
137 static arm_feature_set arm_arch_used;
138 static arm_feature_set thumb_arch_used;
139
140 /* Flags stored in private area of BFD structure. */
141 static int uses_apcs_26 = FALSE;
142 static int atpcs = FALSE;
143 static int support_interwork = FALSE;
144 static int uses_apcs_float = FALSE;
145 static int pic_code = FALSE;
146
147 /* Variables that we set while parsing command-line options. Once all
148 options have been read we re-process these values to set the real
149 assembly flags. */
150 static const arm_feature_set *legacy_cpu = NULL;
151 static const arm_feature_set *legacy_fpu = NULL;
152
153 static const arm_feature_set *mcpu_cpu_opt = NULL;
154 static const arm_feature_set *mcpu_fpu_opt = NULL;
155 static const arm_feature_set *march_cpu_opt = NULL;
156 static const arm_feature_set *march_fpu_opt = NULL;
157 static const arm_feature_set *mfpu_opt = NULL;
158 static const arm_feature_set *object_arch = NULL;
159
160 /* Constants for known architecture features. */
161 static const arm_feature_set fpu_default = FPU_DEFAULT;
162 static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
163 static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
164 static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
165 static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
166 static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
167 static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
168 static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
169 static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
170
171 #ifdef CPU_DEFAULT
172 static const arm_feature_set cpu_default = CPU_DEFAULT;
173 #endif
174
175 static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
176 static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
177 static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
178 static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
179 static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
180 static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
181 static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
182 static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
183 static const arm_feature_set arm_ext_v4t_5 =
184 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
185 static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
186 static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
187 static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
188 static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
189 static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
190 static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
191 static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
192 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
193 static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
194 static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
195 static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
196 static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
197 static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
198 static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
199
200 static const arm_feature_set arm_arch_any = ARM_ANY;
201 static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
202 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
203 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
204
205 static const arm_feature_set arm_cext_iwmmxt2 =
206 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
207 static const arm_feature_set arm_cext_iwmmxt =
208 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
209 static const arm_feature_set arm_cext_xscale =
210 ARM_FEATURE (0, ARM_CEXT_XSCALE);
211 static const arm_feature_set arm_cext_maverick =
212 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
213 static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
214 static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
215 static const arm_feature_set fpu_vfp_ext_v1xd =
216 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
217 static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
218 static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
219 static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
220 static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
221 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
222 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
223
224 static int mfloat_abi_opt = -1;
225 /* Record user cpu selection for object attributes. */
226 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
227 /* Must be long enough to hold any of the names in arm_cpus. */
228 static char selected_cpu_name[16];
229 #ifdef OBJ_ELF
230 # ifdef EABI_DEFAULT
231 static int meabi_flags = EABI_DEFAULT;
232 # else
233 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
234 # endif
235
236 bfd_boolean
237 arm_is_eabi(void)
238 {
239 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
240 }
241 #endif
242
243 #ifdef OBJ_ELF
244 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
245 symbolS * GOT_symbol;
246 #endif
247
248 /* 0: assemble for ARM,
249 1: assemble for Thumb,
250 2: assemble for Thumb even though target CPU does not support thumb
251 instructions. */
252 static int thumb_mode = 0;
253
254 /* If unified_syntax is true, we are processing the new unified
255 ARM/Thumb syntax. Important differences from the old ARM mode:
256
257 - Immediate operands do not require a # prefix.
258 - Conditional affixes always appear at the end of the
259 instruction. (For backward compatibility, those instructions
260 that formerly had them in the middle, continue to accept them
261 there.)
262 - The IT instruction may appear, and if it does is validated
263 against subsequent conditional affixes. It does not generate
264 machine code.
265
266 Important differences from the old Thumb mode:
267
268 - Immediate operands do not require a # prefix.
269 - Most of the V6T2 instructions are only available in unified mode.
270 - The .N and .W suffixes are recognized and honored (it is an error
271 if they cannot be honored).
272 - All instructions set the flags if and only if they have an 's' affix.
273 - Conditional affixes may be used. They are validated against
274 preceding IT instructions. Unlike ARM mode, you cannot use a
275 conditional affix except in the scope of an IT instruction. */
276
277 static bfd_boolean unified_syntax = FALSE;
278
279 enum neon_el_type
280 {
281 NT_invtype,
282 NT_untyped,
283 NT_integer,
284 NT_float,
285 NT_poly,
286 NT_signed,
287 NT_unsigned
288 };
289
290 struct neon_type_el
291 {
292 enum neon_el_type type;
293 unsigned size;
294 };
295
296 #define NEON_MAX_TYPE_ELS 4
297
298 struct neon_type
299 {
300 struct neon_type_el el[NEON_MAX_TYPE_ELS];
301 unsigned elems;
302 };
303
304 struct arm_it
305 {
306 const char * error;
307 unsigned long instruction;
308 int size;
309 int size_req;
310 int cond;
311 /* "uncond_value" is set to the value in place of the conditional field in
312 unconditional versions of the instruction, or -1 if nothing is
313 appropriate. */
314 int uncond_value;
315 struct neon_type vectype;
316 /* Set to the opcode if the instruction needs relaxation.
317 Zero if the instruction is not relaxed. */
318 unsigned long relax;
319 struct
320 {
321 bfd_reloc_code_real_type type;
322 expressionS exp;
323 int pc_rel;
324 } reloc;
325
326 struct
327 {
328 unsigned reg;
329 signed int imm;
330 struct neon_type_el vectype;
331 unsigned present : 1; /* Operand present. */
332 unsigned isreg : 1; /* Operand was a register. */
333 unsigned immisreg : 1; /* .imm field is a second register. */
334 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
335 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
336 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
337 instructions. This allows us to disambiguate ARM <-> vector insns. */
338 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
339 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
340 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
341 unsigned issingle : 1; /* Operand is VFP single-precision register. */
342 unsigned hasreloc : 1; /* Operand has relocation suffix. */
343 unsigned writeback : 1; /* Operand has trailing ! */
344 unsigned preind : 1; /* Preindexed address. */
345 unsigned postind : 1; /* Postindexed address. */
346 unsigned negative : 1; /* Index register was negated. */
347 unsigned shifted : 1; /* Shift applied to operation. */
348 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
349 } operands[6];
350 };
351
352 static struct arm_it inst;
353
354 #define NUM_FLOAT_VALS 8
355
356 const char * fp_const[] =
357 {
358 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
359 };
360
361 /* Number of littlenums required to hold an extended precision number. */
362 #define MAX_LITTLENUMS 6
363
364 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
365
366 #define FAIL (-1)
367 #define SUCCESS (0)
368
369 #define SUFF_S 1
370 #define SUFF_D 2
371 #define SUFF_E 3
372 #define SUFF_P 4
373
374 #define CP_T_X 0x00008000
375 #define CP_T_Y 0x00400000
376
377 #define CONDS_BIT 0x00100000
378 #define LOAD_BIT 0x00100000
379
380 #define DOUBLE_LOAD_FLAG 0x00000001
381
382 struct asm_cond
383 {
384 const char * template;
385 unsigned long value;
386 };
387
388 #define COND_ALWAYS 0xE
389
390 struct asm_psr
391 {
392 const char *template;
393 unsigned long field;
394 };
395
396 struct asm_barrier_opt
397 {
398 const char *template;
399 unsigned long value;
400 };
401
402 /* The bit that distinguishes CPSR and SPSR. */
403 #define SPSR_BIT (1 << 22)
404
405 /* The individual PSR flag bits. */
406 #define PSR_c (1 << 16)
407 #define PSR_x (1 << 17)
408 #define PSR_s (1 << 18)
409 #define PSR_f (1 << 19)
410
411 struct reloc_entry
412 {
413 char *name;
414 bfd_reloc_code_real_type reloc;
415 };
416
417 enum vfp_reg_pos
418 {
419 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
420 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
421 };
422
423 enum vfp_ldstm_type
424 {
425 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
426 };
427
428 /* Bits for DEFINED field in neon_typed_alias. */
429 #define NTA_HASTYPE 1
430 #define NTA_HASINDEX 2
431
432 struct neon_typed_alias
433 {
434 unsigned char defined;
435 unsigned char index;
436 struct neon_type_el eltype;
437 };
438
439 /* ARM register categories. This includes coprocessor numbers and various
440 architecture extensions' registers. */
441 enum arm_reg_type
442 {
443 REG_TYPE_RN,
444 REG_TYPE_CP,
445 REG_TYPE_CN,
446 REG_TYPE_FN,
447 REG_TYPE_VFS,
448 REG_TYPE_VFD,
449 REG_TYPE_NQ,
450 REG_TYPE_VFSD,
451 REG_TYPE_NDQ,
452 REG_TYPE_NSDQ,
453 REG_TYPE_VFC,
454 REG_TYPE_MVF,
455 REG_TYPE_MVD,
456 REG_TYPE_MVFX,
457 REG_TYPE_MVDX,
458 REG_TYPE_MVAX,
459 REG_TYPE_DSPSC,
460 REG_TYPE_MMXWR,
461 REG_TYPE_MMXWC,
462 REG_TYPE_MMXWCG,
463 REG_TYPE_XSCALE,
464 };
465
466 /* Structure for a hash table entry for a register.
467 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
468 information which states whether a vector type or index is specified (for a
469 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
470 struct reg_entry
471 {
472 const char *name;
473 unsigned char number;
474 unsigned char type;
475 unsigned char builtin;
476 struct neon_typed_alias *neon;
477 };
478
479 /* Diagnostics used when we don't get a register of the expected type. */
480 const char *const reg_expected_msgs[] =
481 {
482 N_("ARM register expected"),
483 N_("bad or missing co-processor number"),
484 N_("co-processor register expected"),
485 N_("FPA register expected"),
486 N_("VFP single precision register expected"),
487 N_("VFP/Neon double precision register expected"),
488 N_("Neon quad precision register expected"),
489 N_("VFP single or double precision register expected"),
490 N_("Neon double or quad precision register expected"),
491 N_("VFP single, double or Neon quad precision register expected"),
492 N_("VFP system register expected"),
493 N_("Maverick MVF register expected"),
494 N_("Maverick MVD register expected"),
495 N_("Maverick MVFX register expected"),
496 N_("Maverick MVDX register expected"),
497 N_("Maverick MVAX register expected"),
498 N_("Maverick DSPSC register expected"),
499 N_("iWMMXt data register expected"),
500 N_("iWMMXt control register expected"),
501 N_("iWMMXt scalar register expected"),
502 N_("XScale accumulator register expected"),
503 };
504
505 /* Some well known registers that we refer to directly elsewhere. */
506 #define REG_SP 13
507 #define REG_LR 14
508 #define REG_PC 15
509
510 /* ARM instructions take 4bytes in the object file, Thumb instructions
511 take 2: */
512 #define INSN_SIZE 4
513
514 struct asm_opcode
515 {
516 /* Basic string to match. */
517 const char *template;
518
519 /* Parameters to instruction. */
520 unsigned char operands[8];
521
522 /* Conditional tag - see opcode_lookup. */
523 unsigned int tag : 4;
524
525 /* Basic instruction code. */
526 unsigned int avalue : 28;
527
528 /* Thumb-format instruction code. */
529 unsigned int tvalue;
530
531 /* Which architecture variant provides this instruction. */
532 const arm_feature_set *avariant;
533 const arm_feature_set *tvariant;
534
535 /* Function to call to encode instruction in ARM format. */
536 void (* aencode) (void);
537
538 /* Function to call to encode instruction in Thumb format. */
539 void (* tencode) (void);
540 };
541
542 /* Defines for various bits that we will want to toggle. */
543 #define INST_IMMEDIATE 0x02000000
544 #define OFFSET_REG 0x02000000
545 #define HWOFFSET_IMM 0x00400000
546 #define SHIFT_BY_REG 0x00000010
547 #define PRE_INDEX 0x01000000
548 #define INDEX_UP 0x00800000
549 #define WRITE_BACK 0x00200000
550 #define LDM_TYPE_2_OR_3 0x00400000
551 #define CPSI_MMOD 0x00020000
552
553 #define LITERAL_MASK 0xf000f000
554 #define OPCODE_MASK 0xfe1fffff
555 #define V4_STR_BIT 0x00000020
556
557 #define DATA_OP_SHIFT 21
558
559 #define T2_OPCODE_MASK 0xfe1fffff
560 #define T2_DATA_OP_SHIFT 21
561
562 /* Codes to distinguish the arithmetic instructions. */
563 #define OPCODE_AND 0
564 #define OPCODE_EOR 1
565 #define OPCODE_SUB 2
566 #define OPCODE_RSB 3
567 #define OPCODE_ADD 4
568 #define OPCODE_ADC 5
569 #define OPCODE_SBC 6
570 #define OPCODE_RSC 7
571 #define OPCODE_TST 8
572 #define OPCODE_TEQ 9
573 #define OPCODE_CMP 10
574 #define OPCODE_CMN 11
575 #define OPCODE_ORR 12
576 #define OPCODE_MOV 13
577 #define OPCODE_BIC 14
578 #define OPCODE_MVN 15
579
580 #define T2_OPCODE_AND 0
581 #define T2_OPCODE_BIC 1
582 #define T2_OPCODE_ORR 2
583 #define T2_OPCODE_ORN 3
584 #define T2_OPCODE_EOR 4
585 #define T2_OPCODE_ADD 8
586 #define T2_OPCODE_ADC 10
587 #define T2_OPCODE_SBC 11
588 #define T2_OPCODE_SUB 13
589 #define T2_OPCODE_RSB 14
590
591 #define T_OPCODE_MUL 0x4340
592 #define T_OPCODE_TST 0x4200
593 #define T_OPCODE_CMN 0x42c0
594 #define T_OPCODE_NEG 0x4240
595 #define T_OPCODE_MVN 0x43c0
596
597 #define T_OPCODE_ADD_R3 0x1800
598 #define T_OPCODE_SUB_R3 0x1a00
599 #define T_OPCODE_ADD_HI 0x4400
600 #define T_OPCODE_ADD_ST 0xb000
601 #define T_OPCODE_SUB_ST 0xb080
602 #define T_OPCODE_ADD_SP 0xa800
603 #define T_OPCODE_ADD_PC 0xa000
604 #define T_OPCODE_ADD_I8 0x3000
605 #define T_OPCODE_SUB_I8 0x3800
606 #define T_OPCODE_ADD_I3 0x1c00
607 #define T_OPCODE_SUB_I3 0x1e00
608
609 #define T_OPCODE_ASR_R 0x4100
610 #define T_OPCODE_LSL_R 0x4080
611 #define T_OPCODE_LSR_R 0x40c0
612 #define T_OPCODE_ROR_R 0x41c0
613 #define T_OPCODE_ASR_I 0x1000
614 #define T_OPCODE_LSL_I 0x0000
615 #define T_OPCODE_LSR_I 0x0800
616
617 #define T_OPCODE_MOV_I8 0x2000
618 #define T_OPCODE_CMP_I8 0x2800
619 #define T_OPCODE_CMP_LR 0x4280
620 #define T_OPCODE_MOV_HR 0x4600
621 #define T_OPCODE_CMP_HR 0x4500
622
623 #define T_OPCODE_LDR_PC 0x4800
624 #define T_OPCODE_LDR_SP 0x9800
625 #define T_OPCODE_STR_SP 0x9000
626 #define T_OPCODE_LDR_IW 0x6800
627 #define T_OPCODE_STR_IW 0x6000
628 #define T_OPCODE_LDR_IH 0x8800
629 #define T_OPCODE_STR_IH 0x8000
630 #define T_OPCODE_LDR_IB 0x7800
631 #define T_OPCODE_STR_IB 0x7000
632 #define T_OPCODE_LDR_RW 0x5800
633 #define T_OPCODE_STR_RW 0x5000
634 #define T_OPCODE_LDR_RH 0x5a00
635 #define T_OPCODE_STR_RH 0x5200
636 #define T_OPCODE_LDR_RB 0x5c00
637 #define T_OPCODE_STR_RB 0x5400
638
639 #define T_OPCODE_PUSH 0xb400
640 #define T_OPCODE_POP 0xbc00
641
642 #define T_OPCODE_BRANCH 0xe000
643
644 #define THUMB_SIZE 2 /* Size of thumb instruction. */
645 #define THUMB_PP_PC_LR 0x0100
646 #define THUMB_LOAD_BIT 0x0800
647 #define THUMB2_LOAD_BIT 0x00100000
648
649 #define BAD_ARGS _("bad arguments to instruction")
650 #define BAD_PC _("r15 not allowed here")
651 #define BAD_COND _("instruction cannot be conditional")
652 #define BAD_OVERLAP _("registers may not be the same")
653 #define BAD_HIREG _("lo register required")
654 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
655 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
656 #define BAD_BRANCH _("branch must be last instruction in IT block")
657 #define BAD_NOT_IT _("instruction not allowed in IT block")
658 #define BAD_FPU _("selected FPU does not support instruction")
659
660 static struct hash_control *arm_ops_hsh;
661 static struct hash_control *arm_cond_hsh;
662 static struct hash_control *arm_shift_hsh;
663 static struct hash_control *arm_psr_hsh;
664 static struct hash_control *arm_v7m_psr_hsh;
665 static struct hash_control *arm_reg_hsh;
666 static struct hash_control *arm_reloc_hsh;
667 static struct hash_control *arm_barrier_opt_hsh;
668
669 /* Stuff needed to resolve the label ambiguity
670 As:
671 ...
672 label: <insn>
673 may differ from:
674 ...
675 label:
676 <insn>
677 */
678
679 symbolS * last_label_seen;
680 static int label_is_thumb_function_name = FALSE;
681 \f
682 /* Literal pool structure. Held on a per-section
683 and per-sub-section basis. */
684
685 #define MAX_LITERAL_POOL_SIZE 1024
686 typedef struct literal_pool
687 {
688 expressionS literals [MAX_LITERAL_POOL_SIZE];
689 unsigned int next_free_entry;
690 unsigned int id;
691 symbolS * symbol;
692 segT section;
693 subsegT sub_section;
694 struct literal_pool * next;
695 } literal_pool;
696
697 /* Pointer to a linked list of literal pools. */
698 literal_pool * list_of_pools = NULL;
699
700 /* State variables for IT block handling. */
701 static bfd_boolean current_it_mask = 0;
702 static int current_cc;
703
704 \f
705 /* Pure syntax. */
706
707 /* This array holds the chars that always start a comment. If the
708 pre-processor is disabled, these aren't very useful. */
709 const char comment_chars[] = "@";
710
711 /* This array holds the chars that only start a comment at the beginning of
712 a line. If the line seems to have the form '# 123 filename'
713 .line and .file directives will appear in the pre-processed output. */
714 /* Note that input_file.c hand checks for '#' at the beginning of the
715 first line of the input file. This is because the compiler outputs
716 #NO_APP at the beginning of its output. */
717 /* Also note that comments like this one will always work. */
718 const char line_comment_chars[] = "#";
719
720 const char line_separator_chars[] = ";";
721
722 /* Chars that can be used to separate mant
723 from exp in floating point numbers. */
724 const char EXP_CHARS[] = "eE";
725
726 /* Chars that mean this number is a floating point constant. */
727 /* As in 0f12.456 */
728 /* or 0d1.2345e12 */
729
730 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
731
732 /* Prefix characters that indicate the start of an immediate
733 value. */
734 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
735
736 /* Separator character handling. */
737
738 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
739
740 static inline int
741 skip_past_char (char ** str, char c)
742 {
743 if (**str == c)
744 {
745 (*str)++;
746 return SUCCESS;
747 }
748 else
749 return FAIL;
750 }
751 #define skip_past_comma(str) skip_past_char (str, ',')
752
753 /* Arithmetic expressions (possibly involving symbols). */
754
755 /* Return TRUE if anything in the expression is a bignum. */
756
757 static int
758 walk_no_bignums (symbolS * sp)
759 {
760 if (symbol_get_value_expression (sp)->X_op == O_big)
761 return 1;
762
763 if (symbol_get_value_expression (sp)->X_add_symbol)
764 {
765 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
766 || (symbol_get_value_expression (sp)->X_op_symbol
767 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
768 }
769
770 return 0;
771 }
772
773 static int in_my_get_expression = 0;
774
775 /* Third argument to my_get_expression. */
776 #define GE_NO_PREFIX 0
777 #define GE_IMM_PREFIX 1
778 #define GE_OPT_PREFIX 2
779 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
780 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
781 #define GE_OPT_PREFIX_BIG 3
782
783 static int
784 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
785 {
786 char * save_in;
787 segT seg;
788
789 /* In unified syntax, all prefixes are optional. */
790 if (unified_syntax)
791 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
792 : GE_OPT_PREFIX;
793
794 switch (prefix_mode)
795 {
796 case GE_NO_PREFIX: break;
797 case GE_IMM_PREFIX:
798 if (!is_immediate_prefix (**str))
799 {
800 inst.error = _("immediate expression requires a # prefix");
801 return FAIL;
802 }
803 (*str)++;
804 break;
805 case GE_OPT_PREFIX:
806 case GE_OPT_PREFIX_BIG:
807 if (is_immediate_prefix (**str))
808 (*str)++;
809 break;
810 default: abort ();
811 }
812
813 memset (ep, 0, sizeof (expressionS));
814
815 save_in = input_line_pointer;
816 input_line_pointer = *str;
817 in_my_get_expression = 1;
818 seg = expression (ep);
819 in_my_get_expression = 0;
820
821 if (ep->X_op == O_illegal)
822 {
823 /* We found a bad expression in md_operand(). */
824 *str = input_line_pointer;
825 input_line_pointer = save_in;
826 if (inst.error == NULL)
827 inst.error = _("bad expression");
828 return 1;
829 }
830
831 #ifdef OBJ_AOUT
832 if (seg != absolute_section
833 && seg != text_section
834 && seg != data_section
835 && seg != bss_section
836 && seg != undefined_section)
837 {
838 inst.error = _("bad segment");
839 *str = input_line_pointer;
840 input_line_pointer = save_in;
841 return 1;
842 }
843 #endif
844
845 /* Get rid of any bignums now, so that we don't generate an error for which
846 we can't establish a line number later on. Big numbers are never valid
847 in instructions, which is where this routine is always called. */
848 if (prefix_mode != GE_OPT_PREFIX_BIG
849 && (ep->X_op == O_big
850 || (ep->X_add_symbol
851 && (walk_no_bignums (ep->X_add_symbol)
852 || (ep->X_op_symbol
853 && walk_no_bignums (ep->X_op_symbol))))))
854 {
855 inst.error = _("invalid constant");
856 *str = input_line_pointer;
857 input_line_pointer = save_in;
858 return 1;
859 }
860
861 *str = input_line_pointer;
862 input_line_pointer = save_in;
863 return 0;
864 }
865
866 /* Turn a string in input_line_pointer into a floating point constant
867 of type TYPE, and store the appropriate bytes in *LITP. The number
868 of LITTLENUMS emitted is stored in *SIZEP. An error message is
869 returned, or NULL on OK.
870
871 Note that fp constants aren't represent in the normal way on the ARM.
872 In big endian mode, things are as expected. However, in little endian
873 mode fp constants are big-endian word-wise, and little-endian byte-wise
874 within the words. For example, (double) 1.1 in big endian mode is
875 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
876 the byte sequence 99 99 f1 3f 9a 99 99 99.
877
878 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
879
880 char *
881 md_atof (int type, char * litP, int * sizeP)
882 {
883 int prec;
884 LITTLENUM_TYPE words[MAX_LITTLENUMS];
885 char *t;
886 int i;
887
888 switch (type)
889 {
890 case 'f':
891 case 'F':
892 case 's':
893 case 'S':
894 prec = 2;
895 break;
896
897 case 'd':
898 case 'D':
899 case 'r':
900 case 'R':
901 prec = 4;
902 break;
903
904 case 'x':
905 case 'X':
906 prec = 6;
907 break;
908
909 case 'p':
910 case 'P':
911 prec = 6;
912 break;
913
914 default:
915 *sizeP = 0;
916 return _("bad call to MD_ATOF()");
917 }
918
919 t = atof_ieee (input_line_pointer, type, words);
920 if (t)
921 input_line_pointer = t;
922 *sizeP = prec * 2;
923
924 if (target_big_endian)
925 {
926 for (i = 0; i < prec; i++)
927 {
928 md_number_to_chars (litP, (valueT) words[i], 2);
929 litP += 2;
930 }
931 }
932 else
933 {
934 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
935 for (i = prec - 1; i >= 0; i--)
936 {
937 md_number_to_chars (litP, (valueT) words[i], 2);
938 litP += 2;
939 }
940 else
941 /* For a 4 byte float the order of elements in `words' is 1 0.
942 For an 8 byte float the order is 1 0 3 2. */
943 for (i = 0; i < prec; i += 2)
944 {
945 md_number_to_chars (litP, (valueT) words[i + 1], 2);
946 md_number_to_chars (litP + 2, (valueT) words[i], 2);
947 litP += 4;
948 }
949 }
950
951 return 0;
952 }
953
954 /* We handle all bad expressions here, so that we can report the faulty
955 instruction in the error message. */
956 void
957 md_operand (expressionS * expr)
958 {
959 if (in_my_get_expression)
960 expr->X_op = O_illegal;
961 }
962
963 /* Immediate values. */
964
965 /* Generic immediate-value read function for use in directives.
966 Accepts anything that 'expression' can fold to a constant.
967 *val receives the number. */
968 #ifdef OBJ_ELF
969 static int
970 immediate_for_directive (int *val)
971 {
972 expressionS exp;
973 exp.X_op = O_illegal;
974
975 if (is_immediate_prefix (*input_line_pointer))
976 {
977 input_line_pointer++;
978 expression (&exp);
979 }
980
981 if (exp.X_op != O_constant)
982 {
983 as_bad (_("expected #constant"));
984 ignore_rest_of_line ();
985 return FAIL;
986 }
987 *val = exp.X_add_number;
988 return SUCCESS;
989 }
990 #endif
991
992 /* Register parsing. */
993
994 /* Generic register parser. CCP points to what should be the
995 beginning of a register name. If it is indeed a valid register
996 name, advance CCP over it and return the reg_entry structure;
997 otherwise return NULL. Does not issue diagnostics. */
998
999 static struct reg_entry *
1000 arm_reg_parse_multi (char **ccp)
1001 {
1002 char *start = *ccp;
1003 char *p;
1004 struct reg_entry *reg;
1005
1006 #ifdef REGISTER_PREFIX
1007 if (*start != REGISTER_PREFIX)
1008 return NULL;
1009 start++;
1010 #endif
1011 #ifdef OPTIONAL_REGISTER_PREFIX
1012 if (*start == OPTIONAL_REGISTER_PREFIX)
1013 start++;
1014 #endif
1015
1016 p = start;
1017 if (!ISALPHA (*p) || !is_name_beginner (*p))
1018 return NULL;
1019
1020 do
1021 p++;
1022 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1023
1024 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1025
1026 if (!reg)
1027 return NULL;
1028
1029 *ccp = p;
1030 return reg;
1031 }
1032
1033 static int
1034 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1035 enum arm_reg_type type)
1036 {
1037 /* Alternative syntaxes are accepted for a few register classes. */
1038 switch (type)
1039 {
1040 case REG_TYPE_MVF:
1041 case REG_TYPE_MVD:
1042 case REG_TYPE_MVFX:
1043 case REG_TYPE_MVDX:
1044 /* Generic coprocessor register names are allowed for these. */
1045 if (reg && reg->type == REG_TYPE_CN)
1046 return reg->number;
1047 break;
1048
1049 case REG_TYPE_CP:
1050 /* For backward compatibility, a bare number is valid here. */
1051 {
1052 unsigned long processor = strtoul (start, ccp, 10);
1053 if (*ccp != start && processor <= 15)
1054 return processor;
1055 }
1056
1057 case REG_TYPE_MMXWC:
1058 /* WC includes WCG. ??? I'm not sure this is true for all
1059 instructions that take WC registers. */
1060 if (reg && reg->type == REG_TYPE_MMXWCG)
1061 return reg->number;
1062 break;
1063
1064 default:
1065 break;
1066 }
1067
1068 return FAIL;
1069 }
1070
1071 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1072 return value is the register number or FAIL. */
1073
1074 static int
1075 arm_reg_parse (char **ccp, enum arm_reg_type type)
1076 {
1077 char *start = *ccp;
1078 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1079 int ret;
1080
1081 /* Do not allow a scalar (reg+index) to parse as a register. */
1082 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1083 return FAIL;
1084
1085 if (reg && reg->type == type)
1086 return reg->number;
1087
1088 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1089 return ret;
1090
1091 *ccp = start;
1092 return FAIL;
1093 }
1094
1095 /* Parse a Neon type specifier. *STR should point at the leading '.'
1096 character. Does no verification at this stage that the type fits the opcode
1097 properly. E.g.,
1098
1099 .i32.i32.s16
1100 .s32.f32
1101 .u16
1102
1103 Can all be legally parsed by this function.
1104
1105 Fills in neon_type struct pointer with parsed information, and updates STR
1106 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1107 type, FAIL if not. */
1108
1109 static int
1110 parse_neon_type (struct neon_type *type, char **str)
1111 {
1112 char *ptr = *str;
1113
1114 if (type)
1115 type->elems = 0;
1116
1117 while (type->elems < NEON_MAX_TYPE_ELS)
1118 {
1119 enum neon_el_type thistype = NT_untyped;
1120 unsigned thissize = -1u;
1121
1122 if (*ptr != '.')
1123 break;
1124
1125 ptr++;
1126
1127 /* Just a size without an explicit type. */
1128 if (ISDIGIT (*ptr))
1129 goto parsesize;
1130
1131 switch (TOLOWER (*ptr))
1132 {
1133 case 'i': thistype = NT_integer; break;
1134 case 'f': thistype = NT_float; break;
1135 case 'p': thistype = NT_poly; break;
1136 case 's': thistype = NT_signed; break;
1137 case 'u': thistype = NT_unsigned; break;
1138 case 'd':
1139 thistype = NT_float;
1140 thissize = 64;
1141 ptr++;
1142 goto done;
1143 default:
1144 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1145 return FAIL;
1146 }
1147
1148 ptr++;
1149
1150 /* .f is an abbreviation for .f32. */
1151 if (thistype == NT_float && !ISDIGIT (*ptr))
1152 thissize = 32;
1153 else
1154 {
1155 parsesize:
1156 thissize = strtoul (ptr, &ptr, 10);
1157
1158 if (thissize != 8 && thissize != 16 && thissize != 32
1159 && thissize != 64)
1160 {
1161 as_bad (_("bad size %d in type specifier"), thissize);
1162 return FAIL;
1163 }
1164 }
1165
1166 done:
1167 if (type)
1168 {
1169 type->el[type->elems].type = thistype;
1170 type->el[type->elems].size = thissize;
1171 type->elems++;
1172 }
1173 }
1174
1175 /* Empty/missing type is not a successful parse. */
1176 if (type->elems == 0)
1177 return FAIL;
1178
1179 *str = ptr;
1180
1181 return SUCCESS;
1182 }
1183
1184 /* Errors may be set multiple times during parsing or bit encoding
1185 (particularly in the Neon bits), but usually the earliest error which is set
1186 will be the most meaningful. Avoid overwriting it with later (cascading)
1187 errors by calling this function. */
1188
1189 static void
1190 first_error (const char *err)
1191 {
1192 if (!inst.error)
1193 inst.error = err;
1194 }
1195
1196 /* Parse a single type, e.g. ".s32", leading period included. */
1197 static int
1198 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1199 {
1200 char *str = *ccp;
1201 struct neon_type optype;
1202
1203 if (*str == '.')
1204 {
1205 if (parse_neon_type (&optype, &str) == SUCCESS)
1206 {
1207 if (optype.elems == 1)
1208 *vectype = optype.el[0];
1209 else
1210 {
1211 first_error (_("only one type should be specified for operand"));
1212 return FAIL;
1213 }
1214 }
1215 else
1216 {
1217 first_error (_("vector type expected"));
1218 return FAIL;
1219 }
1220 }
1221 else
1222 return FAIL;
1223
1224 *ccp = str;
1225
1226 return SUCCESS;
1227 }
1228
1229 /* Special meanings for indices (which have a range of 0-7), which will fit into
1230 a 4-bit integer. */
1231
1232 #define NEON_ALL_LANES 15
1233 #define NEON_INTERLEAVE_LANES 14
1234
1235 /* Parse either a register or a scalar, with an optional type. Return the
1236 register number, and optionally fill in the actual type of the register
1237 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1238 type/index information in *TYPEINFO. */
1239
1240 static int
1241 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1242 enum arm_reg_type *rtype,
1243 struct neon_typed_alias *typeinfo)
1244 {
1245 char *str = *ccp;
1246 struct reg_entry *reg = arm_reg_parse_multi (&str);
1247 struct neon_typed_alias atype;
1248 struct neon_type_el parsetype;
1249
1250 atype.defined = 0;
1251 atype.index = -1;
1252 atype.eltype.type = NT_invtype;
1253 atype.eltype.size = -1;
1254
1255 /* Try alternate syntax for some types of register. Note these are mutually
1256 exclusive with the Neon syntax extensions. */
1257 if (reg == NULL)
1258 {
1259 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1260 if (altreg != FAIL)
1261 *ccp = str;
1262 if (typeinfo)
1263 *typeinfo = atype;
1264 return altreg;
1265 }
1266
1267 /* Undo polymorphism when a set of register types may be accepted. */
1268 if ((type == REG_TYPE_NDQ
1269 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1270 || (type == REG_TYPE_VFSD
1271 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1272 || (type == REG_TYPE_NSDQ
1273 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1274 || reg->type == REG_TYPE_NQ))
1275 || (type == REG_TYPE_MMXWC
1276 && (reg->type == REG_TYPE_MMXWCG)))
1277 type = reg->type;
1278
1279 if (type != reg->type)
1280 return FAIL;
1281
1282 if (reg->neon)
1283 atype = *reg->neon;
1284
1285 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1286 {
1287 if ((atype.defined & NTA_HASTYPE) != 0)
1288 {
1289 first_error (_("can't redefine type for operand"));
1290 return FAIL;
1291 }
1292 atype.defined |= NTA_HASTYPE;
1293 atype.eltype = parsetype;
1294 }
1295
1296 if (skip_past_char (&str, '[') == SUCCESS)
1297 {
1298 if (type != REG_TYPE_VFD)
1299 {
1300 first_error (_("only D registers may be indexed"));
1301 return FAIL;
1302 }
1303
1304 if ((atype.defined & NTA_HASINDEX) != 0)
1305 {
1306 first_error (_("can't change index for operand"));
1307 return FAIL;
1308 }
1309
1310 atype.defined |= NTA_HASINDEX;
1311
1312 if (skip_past_char (&str, ']') == SUCCESS)
1313 atype.index = NEON_ALL_LANES;
1314 else
1315 {
1316 expressionS exp;
1317
1318 my_get_expression (&exp, &str, GE_NO_PREFIX);
1319
1320 if (exp.X_op != O_constant)
1321 {
1322 first_error (_("constant expression required"));
1323 return FAIL;
1324 }
1325
1326 if (skip_past_char (&str, ']') == FAIL)
1327 return FAIL;
1328
1329 atype.index = exp.X_add_number;
1330 }
1331 }
1332
1333 if (typeinfo)
1334 *typeinfo = atype;
1335
1336 if (rtype)
1337 *rtype = type;
1338
1339 *ccp = str;
1340
1341 return reg->number;
1342 }
1343
1344 /* Like arm_reg_parse, but allow allow the following extra features:
1345 - If RTYPE is non-zero, return the (possibly restricted) type of the
1346 register (e.g. Neon double or quad reg when either has been requested).
1347 - If this is a Neon vector type with additional type information, fill
1348 in the struct pointed to by VECTYPE (if non-NULL).
1349 This function will fault on encountering a scalar.
1350 */
1351
1352 static int
1353 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1354 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1355 {
1356 struct neon_typed_alias atype;
1357 char *str = *ccp;
1358 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1359
1360 if (reg == FAIL)
1361 return FAIL;
1362
1363 /* Do not allow a scalar (reg+index) to parse as a register. */
1364 if ((atype.defined & NTA_HASINDEX) != 0)
1365 {
1366 first_error (_("register operand expected, but got scalar"));
1367 return FAIL;
1368 }
1369
1370 if (vectype)
1371 *vectype = atype.eltype;
1372
1373 *ccp = str;
1374
1375 return reg;
1376 }
1377
1378 #define NEON_SCALAR_REG(X) ((X) >> 4)
1379 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1380
1381 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1382 have enough information to be able to do a good job bounds-checking. So, we
1383 just do easy checks here, and do further checks later. */
1384
1385 static int
1386 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1387 {
1388 int reg;
1389 char *str = *ccp;
1390 struct neon_typed_alias atype;
1391
1392 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
1393
1394 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1395 return FAIL;
1396
1397 if (atype.index == NEON_ALL_LANES)
1398 {
1399 first_error (_("scalar must have an index"));
1400 return FAIL;
1401 }
1402 else if (atype.index >= 64 / elsize)
1403 {
1404 first_error (_("scalar index out of range"));
1405 return FAIL;
1406 }
1407
1408 if (type)
1409 *type = atype.eltype;
1410
1411 *ccp = str;
1412
1413 return reg * 16 + atype.index;
1414 }
1415
1416 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1417 static long
1418 parse_reg_list (char ** strp)
1419 {
1420 char * str = * strp;
1421 long range = 0;
1422 int another_range;
1423
1424 /* We come back here if we get ranges concatenated by '+' or '|'. */
1425 do
1426 {
1427 another_range = 0;
1428
1429 if (*str == '{')
1430 {
1431 int in_range = 0;
1432 int cur_reg = -1;
1433
1434 str++;
1435 do
1436 {
1437 int reg;
1438
1439 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1440 {
1441 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
1442 return FAIL;
1443 }
1444
1445 if (in_range)
1446 {
1447 int i;
1448
1449 if (reg <= cur_reg)
1450 {
1451 first_error (_("bad range in register list"));
1452 return FAIL;
1453 }
1454
1455 for (i = cur_reg + 1; i < reg; i++)
1456 {
1457 if (range & (1 << i))
1458 as_tsktsk
1459 (_("Warning: duplicated register (r%d) in register list"),
1460 i);
1461 else
1462 range |= 1 << i;
1463 }
1464 in_range = 0;
1465 }
1466
1467 if (range & (1 << reg))
1468 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1469 reg);
1470 else if (reg <= cur_reg)
1471 as_tsktsk (_("Warning: register range not in ascending order"));
1472
1473 range |= 1 << reg;
1474 cur_reg = reg;
1475 }
1476 while (skip_past_comma (&str) != FAIL
1477 || (in_range = 1, *str++ == '-'));
1478 str--;
1479
1480 if (*str++ != '}')
1481 {
1482 first_error (_("missing `}'"));
1483 return FAIL;
1484 }
1485 }
1486 else
1487 {
1488 expressionS expr;
1489
1490 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1491 return FAIL;
1492
1493 if (expr.X_op == O_constant)
1494 {
1495 if (expr.X_add_number
1496 != (expr.X_add_number & 0x0000ffff))
1497 {
1498 inst.error = _("invalid register mask");
1499 return FAIL;
1500 }
1501
1502 if ((range & expr.X_add_number) != 0)
1503 {
1504 int regno = range & expr.X_add_number;
1505
1506 regno &= -regno;
1507 regno = (1 << regno) - 1;
1508 as_tsktsk
1509 (_("Warning: duplicated register (r%d) in register list"),
1510 regno);
1511 }
1512
1513 range |= expr.X_add_number;
1514 }
1515 else
1516 {
1517 if (inst.reloc.type != 0)
1518 {
1519 inst.error = _("expression too complex");
1520 return FAIL;
1521 }
1522
1523 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1524 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1525 inst.reloc.pc_rel = 0;
1526 }
1527 }
1528
1529 if (*str == '|' || *str == '+')
1530 {
1531 str++;
1532 another_range = 1;
1533 }
1534 }
1535 while (another_range);
1536
1537 *strp = str;
1538 return range;
1539 }
1540
1541 /* Types of registers in a list. */
1542
1543 enum reg_list_els
1544 {
1545 REGLIST_VFP_S,
1546 REGLIST_VFP_D,
1547 REGLIST_NEON_D
1548 };
1549
1550 /* Parse a VFP register list. If the string is invalid return FAIL.
1551 Otherwise return the number of registers, and set PBASE to the first
1552 register. Parses registers of type ETYPE.
1553 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1554 - Q registers can be used to specify pairs of D registers
1555 - { } can be omitted from around a singleton register list
1556 FIXME: This is not implemented, as it would require backtracking in
1557 some cases, e.g.:
1558 vtbl.8 d3,d4,d5
1559 This could be done (the meaning isn't really ambiguous), but doesn't
1560 fit in well with the current parsing framework.
1561 - 32 D registers may be used (also true for VFPv3).
1562 FIXME: Types are ignored in these register lists, which is probably a
1563 bug. */
1564
1565 static int
1566 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
1567 {
1568 char *str = *ccp;
1569 int base_reg;
1570 int new_base;
1571 enum arm_reg_type regtype = 0;
1572 int max_regs = 0;
1573 int count = 0;
1574 int warned = 0;
1575 unsigned long mask = 0;
1576 int i;
1577
1578 if (*str != '{')
1579 {
1580 inst.error = _("expecting {");
1581 return FAIL;
1582 }
1583
1584 str++;
1585
1586 switch (etype)
1587 {
1588 case REGLIST_VFP_S:
1589 regtype = REG_TYPE_VFS;
1590 max_regs = 32;
1591 break;
1592
1593 case REGLIST_VFP_D:
1594 regtype = REG_TYPE_VFD;
1595 break;
1596
1597 case REGLIST_NEON_D:
1598 regtype = REG_TYPE_NDQ;
1599 break;
1600 }
1601
1602 if (etype != REGLIST_VFP_S)
1603 {
1604 /* VFPv3 allows 32 D registers. */
1605 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
1606 {
1607 max_regs = 32;
1608 if (thumb_mode)
1609 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1610 fpu_vfp_ext_v3);
1611 else
1612 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1613 fpu_vfp_ext_v3);
1614 }
1615 else
1616 max_regs = 16;
1617 }
1618
1619 base_reg = max_regs;
1620
1621 do
1622 {
1623 int setmask = 1, addregs = 1;
1624
1625 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
1626
1627 if (new_base == FAIL)
1628 {
1629 first_error (_(reg_expected_msgs[regtype]));
1630 return FAIL;
1631 }
1632
1633 if (new_base >= max_regs)
1634 {
1635 first_error (_("register out of range in list"));
1636 return FAIL;
1637 }
1638
1639 /* Note: a value of 2 * n is returned for the register Q<n>. */
1640 if (regtype == REG_TYPE_NQ)
1641 {
1642 setmask = 3;
1643 addregs = 2;
1644 }
1645
1646 if (new_base < base_reg)
1647 base_reg = new_base;
1648
1649 if (mask & (setmask << new_base))
1650 {
1651 first_error (_("invalid register list"));
1652 return FAIL;
1653 }
1654
1655 if ((mask >> new_base) != 0 && ! warned)
1656 {
1657 as_tsktsk (_("register list not in ascending order"));
1658 warned = 1;
1659 }
1660
1661 mask |= setmask << new_base;
1662 count += addregs;
1663
1664 if (*str == '-') /* We have the start of a range expression */
1665 {
1666 int high_range;
1667
1668 str++;
1669
1670 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
1671 == FAIL)
1672 {
1673 inst.error = gettext (reg_expected_msgs[regtype]);
1674 return FAIL;
1675 }
1676
1677 if (high_range >= max_regs)
1678 {
1679 first_error (_("register out of range in list"));
1680 return FAIL;
1681 }
1682
1683 if (regtype == REG_TYPE_NQ)
1684 high_range = high_range + 1;
1685
1686 if (high_range <= new_base)
1687 {
1688 inst.error = _("register range not in ascending order");
1689 return FAIL;
1690 }
1691
1692 for (new_base += addregs; new_base <= high_range; new_base += addregs)
1693 {
1694 if (mask & (setmask << new_base))
1695 {
1696 inst.error = _("invalid register list");
1697 return FAIL;
1698 }
1699
1700 mask |= setmask << new_base;
1701 count += addregs;
1702 }
1703 }
1704 }
1705 while (skip_past_comma (&str) != FAIL);
1706
1707 str++;
1708
1709 /* Sanity check -- should have raised a parse error above. */
1710 if (count == 0 || count > max_regs)
1711 abort ();
1712
1713 *pbase = base_reg;
1714
1715 /* Final test -- the registers must be consecutive. */
1716 mask >>= base_reg;
1717 for (i = 0; i < count; i++)
1718 {
1719 if ((mask & (1u << i)) == 0)
1720 {
1721 inst.error = _("non-contiguous register range");
1722 return FAIL;
1723 }
1724 }
1725
1726 *ccp = str;
1727
1728 return count;
1729 }
1730
1731 /* True if two alias types are the same. */
1732
1733 static int
1734 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1735 {
1736 if (!a && !b)
1737 return 1;
1738
1739 if (!a || !b)
1740 return 0;
1741
1742 if (a->defined != b->defined)
1743 return 0;
1744
1745 if ((a->defined & NTA_HASTYPE) != 0
1746 && (a->eltype.type != b->eltype.type
1747 || a->eltype.size != b->eltype.size))
1748 return 0;
1749
1750 if ((a->defined & NTA_HASINDEX) != 0
1751 && (a->index != b->index))
1752 return 0;
1753
1754 return 1;
1755 }
1756
1757 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1758 The base register is put in *PBASE.
1759 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
1760 the return value.
1761 The register stride (minus one) is put in bit 4 of the return value.
1762 Bits [6:5] encode the list length (minus one).
1763 The type of the list elements is put in *ELTYPE, if non-NULL. */
1764
1765 #define NEON_LANE(X) ((X) & 0xf)
1766 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
1767 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1768
1769 static int
1770 parse_neon_el_struct_list (char **str, unsigned *pbase,
1771 struct neon_type_el *eltype)
1772 {
1773 char *ptr = *str;
1774 int base_reg = -1;
1775 int reg_incr = -1;
1776 int count = 0;
1777 int lane = -1;
1778 int leading_brace = 0;
1779 enum arm_reg_type rtype = REG_TYPE_NDQ;
1780 int addregs = 1;
1781 const char *const incr_error = "register stride must be 1 or 2";
1782 const char *const type_error = "mismatched element/structure types in list";
1783 struct neon_typed_alias firsttype;
1784
1785 if (skip_past_char (&ptr, '{') == SUCCESS)
1786 leading_brace = 1;
1787
1788 do
1789 {
1790 struct neon_typed_alias atype;
1791 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1792
1793 if (getreg == FAIL)
1794 {
1795 first_error (_(reg_expected_msgs[rtype]));
1796 return FAIL;
1797 }
1798
1799 if (base_reg == -1)
1800 {
1801 base_reg = getreg;
1802 if (rtype == REG_TYPE_NQ)
1803 {
1804 reg_incr = 1;
1805 addregs = 2;
1806 }
1807 firsttype = atype;
1808 }
1809 else if (reg_incr == -1)
1810 {
1811 reg_incr = getreg - base_reg;
1812 if (reg_incr < 1 || reg_incr > 2)
1813 {
1814 first_error (_(incr_error));
1815 return FAIL;
1816 }
1817 }
1818 else if (getreg != base_reg + reg_incr * count)
1819 {
1820 first_error (_(incr_error));
1821 return FAIL;
1822 }
1823
1824 if (!neon_alias_types_same (&atype, &firsttype))
1825 {
1826 first_error (_(type_error));
1827 return FAIL;
1828 }
1829
1830 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1831 modes. */
1832 if (ptr[0] == '-')
1833 {
1834 struct neon_typed_alias htype;
1835 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1836 if (lane == -1)
1837 lane = NEON_INTERLEAVE_LANES;
1838 else if (lane != NEON_INTERLEAVE_LANES)
1839 {
1840 first_error (_(type_error));
1841 return FAIL;
1842 }
1843 if (reg_incr == -1)
1844 reg_incr = 1;
1845 else if (reg_incr != 1)
1846 {
1847 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
1848 return FAIL;
1849 }
1850 ptr++;
1851 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
1852 if (hireg == FAIL)
1853 {
1854 first_error (_(reg_expected_msgs[rtype]));
1855 return FAIL;
1856 }
1857 if (!neon_alias_types_same (&htype, &firsttype))
1858 {
1859 first_error (_(type_error));
1860 return FAIL;
1861 }
1862 count += hireg + dregs - getreg;
1863 continue;
1864 }
1865
1866 /* If we're using Q registers, we can't use [] or [n] syntax. */
1867 if (rtype == REG_TYPE_NQ)
1868 {
1869 count += 2;
1870 continue;
1871 }
1872
1873 if ((atype.defined & NTA_HASINDEX) != 0)
1874 {
1875 if (lane == -1)
1876 lane = atype.index;
1877 else if (lane != atype.index)
1878 {
1879 first_error (_(type_error));
1880 return FAIL;
1881 }
1882 }
1883 else if (lane == -1)
1884 lane = NEON_INTERLEAVE_LANES;
1885 else if (lane != NEON_INTERLEAVE_LANES)
1886 {
1887 first_error (_(type_error));
1888 return FAIL;
1889 }
1890 count++;
1891 }
1892 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
1893
1894 /* No lane set by [x]. We must be interleaving structures. */
1895 if (lane == -1)
1896 lane = NEON_INTERLEAVE_LANES;
1897
1898 /* Sanity check. */
1899 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
1900 || (count > 1 && reg_incr == -1))
1901 {
1902 first_error (_("error parsing element/structure list"));
1903 return FAIL;
1904 }
1905
1906 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
1907 {
1908 first_error (_("expected }"));
1909 return FAIL;
1910 }
1911
1912 if (reg_incr == -1)
1913 reg_incr = 1;
1914
1915 if (eltype)
1916 *eltype = firsttype.eltype;
1917
1918 *pbase = base_reg;
1919 *str = ptr;
1920
1921 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
1922 }
1923
1924 /* Parse an explicit relocation suffix on an expression. This is
1925 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1926 arm_reloc_hsh contains no entries, so this function can only
1927 succeed if there is no () after the word. Returns -1 on error,
1928 BFD_RELOC_UNUSED if there wasn't any suffix. */
1929 static int
1930 parse_reloc (char **str)
1931 {
1932 struct reloc_entry *r;
1933 char *p, *q;
1934
1935 if (**str != '(')
1936 return BFD_RELOC_UNUSED;
1937
1938 p = *str + 1;
1939 q = p;
1940
1941 while (*q && *q != ')' && *q != ',')
1942 q++;
1943 if (*q != ')')
1944 return -1;
1945
1946 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1947 return -1;
1948
1949 *str = q + 1;
1950 return r->reloc;
1951 }
1952
1953 /* Directives: register aliases. */
1954
1955 static struct reg_entry *
1956 insert_reg_alias (char *str, int number, int type)
1957 {
1958 struct reg_entry *new;
1959 const char *name;
1960
1961 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1962 {
1963 if (new->builtin)
1964 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
1965
1966 /* Only warn about a redefinition if it's not defined as the
1967 same register. */
1968 else if (new->number != number || new->type != type)
1969 as_warn (_("ignoring redefinition of register alias '%s'"), str);
1970
1971 return 0;
1972 }
1973
1974 name = xstrdup (str);
1975 new = xmalloc (sizeof (struct reg_entry));
1976
1977 new->name = name;
1978 new->number = number;
1979 new->type = type;
1980 new->builtin = FALSE;
1981 new->neon = NULL;
1982
1983 if (hash_insert (arm_reg_hsh, name, (PTR) new))
1984 abort ();
1985
1986 return new;
1987 }
1988
1989 static void
1990 insert_neon_reg_alias (char *str, int number, int type,
1991 struct neon_typed_alias *atype)
1992 {
1993 struct reg_entry *reg = insert_reg_alias (str, number, type);
1994
1995 if (!reg)
1996 {
1997 first_error (_("attempt to redefine typed alias"));
1998 return;
1999 }
2000
2001 if (atype)
2002 {
2003 reg->neon = xmalloc (sizeof (struct neon_typed_alias));
2004 *reg->neon = *atype;
2005 }
2006 }
2007
2008 /* Look for the .req directive. This is of the form:
2009
2010 new_register_name .req existing_register_name
2011
2012 If we find one, or if it looks sufficiently like one that we want to
2013 handle any error here, return non-zero. Otherwise return zero. */
2014
2015 static int
2016 create_register_alias (char * newname, char *p)
2017 {
2018 struct reg_entry *old;
2019 char *oldname, *nbuf;
2020 size_t nlen;
2021
2022 /* The input scrubber ensures that whitespace after the mnemonic is
2023 collapsed to single spaces. */
2024 oldname = p;
2025 if (strncmp (oldname, " .req ", 6) != 0)
2026 return 0;
2027
2028 oldname += 6;
2029 if (*oldname == '\0')
2030 return 0;
2031
2032 old = hash_find (arm_reg_hsh, oldname);
2033 if (!old)
2034 {
2035 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2036 return 1;
2037 }
2038
2039 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2040 the desired alias name, and p points to its end. If not, then
2041 the desired alias name is in the global original_case_string. */
2042 #ifdef TC_CASE_SENSITIVE
2043 nlen = p - newname;
2044 #else
2045 newname = original_case_string;
2046 nlen = strlen (newname);
2047 #endif
2048
2049 nbuf = alloca (nlen + 1);
2050 memcpy (nbuf, newname, nlen);
2051 nbuf[nlen] = '\0';
2052
2053 /* Create aliases under the new name as stated; an all-lowercase
2054 version of the new name; and an all-uppercase version of the new
2055 name. */
2056 insert_reg_alias (nbuf, old->number, old->type);
2057
2058 for (p = nbuf; *p; p++)
2059 *p = TOUPPER (*p);
2060
2061 if (strncmp (nbuf, newname, nlen))
2062 insert_reg_alias (nbuf, old->number, old->type);
2063
2064 for (p = nbuf; *p; p++)
2065 *p = TOLOWER (*p);
2066
2067 if (strncmp (nbuf, newname, nlen))
2068 insert_reg_alias (nbuf, old->number, old->type);
2069
2070 return 1;
2071 }
2072
2073 /* Create a Neon typed/indexed register alias using directives, e.g.:
2074 X .dn d5.s32[1]
2075 Y .qn 6.s16
2076 Z .dn d7
2077 T .dn Z[0]
2078 These typed registers can be used instead of the types specified after the
2079 Neon mnemonic, so long as all operands given have types. Types can also be
2080 specified directly, e.g.:
2081 vadd d0.s32, d1.s32, d2.s32
2082 */
2083
2084 static int
2085 create_neon_reg_alias (char *newname, char *p)
2086 {
2087 enum arm_reg_type basetype;
2088 struct reg_entry *basereg;
2089 struct reg_entry mybasereg;
2090 struct neon_type ntype;
2091 struct neon_typed_alias typeinfo;
2092 char *namebuf, *nameend;
2093 int namelen;
2094
2095 typeinfo.defined = 0;
2096 typeinfo.eltype.type = NT_invtype;
2097 typeinfo.eltype.size = -1;
2098 typeinfo.index = -1;
2099
2100 nameend = p;
2101
2102 if (strncmp (p, " .dn ", 5) == 0)
2103 basetype = REG_TYPE_VFD;
2104 else if (strncmp (p, " .qn ", 5) == 0)
2105 basetype = REG_TYPE_NQ;
2106 else
2107 return 0;
2108
2109 p += 5;
2110
2111 if (*p == '\0')
2112 return 0;
2113
2114 basereg = arm_reg_parse_multi (&p);
2115
2116 if (basereg && basereg->type != basetype)
2117 {
2118 as_bad (_("bad type for register"));
2119 return 0;
2120 }
2121
2122 if (basereg == NULL)
2123 {
2124 expressionS exp;
2125 /* Try parsing as an integer. */
2126 my_get_expression (&exp, &p, GE_NO_PREFIX);
2127 if (exp.X_op != O_constant)
2128 {
2129 as_bad (_("expression must be constant"));
2130 return 0;
2131 }
2132 basereg = &mybasereg;
2133 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2134 : exp.X_add_number;
2135 basereg->neon = 0;
2136 }
2137
2138 if (basereg->neon)
2139 typeinfo = *basereg->neon;
2140
2141 if (parse_neon_type (&ntype, &p) == SUCCESS)
2142 {
2143 /* We got a type. */
2144 if (typeinfo.defined & NTA_HASTYPE)
2145 {
2146 as_bad (_("can't redefine the type of a register alias"));
2147 return 0;
2148 }
2149
2150 typeinfo.defined |= NTA_HASTYPE;
2151 if (ntype.elems != 1)
2152 {
2153 as_bad (_("you must specify a single type only"));
2154 return 0;
2155 }
2156 typeinfo.eltype = ntype.el[0];
2157 }
2158
2159 if (skip_past_char (&p, '[') == SUCCESS)
2160 {
2161 expressionS exp;
2162 /* We got a scalar index. */
2163
2164 if (typeinfo.defined & NTA_HASINDEX)
2165 {
2166 as_bad (_("can't redefine the index of a scalar alias"));
2167 return 0;
2168 }
2169
2170 my_get_expression (&exp, &p, GE_NO_PREFIX);
2171
2172 if (exp.X_op != O_constant)
2173 {
2174 as_bad (_("scalar index must be constant"));
2175 return 0;
2176 }
2177
2178 typeinfo.defined |= NTA_HASINDEX;
2179 typeinfo.index = exp.X_add_number;
2180
2181 if (skip_past_char (&p, ']') == FAIL)
2182 {
2183 as_bad (_("expecting ]"));
2184 return 0;
2185 }
2186 }
2187
2188 namelen = nameend - newname;
2189 namebuf = alloca (namelen + 1);
2190 strncpy (namebuf, newname, namelen);
2191 namebuf[namelen] = '\0';
2192
2193 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2194 typeinfo.defined != 0 ? &typeinfo : NULL);
2195
2196 /* Insert name in all uppercase. */
2197 for (p = namebuf; *p; p++)
2198 *p = TOUPPER (*p);
2199
2200 if (strncmp (namebuf, newname, namelen))
2201 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2202 typeinfo.defined != 0 ? &typeinfo : NULL);
2203
2204 /* Insert name in all lowercase. */
2205 for (p = namebuf; *p; p++)
2206 *p = TOLOWER (*p);
2207
2208 if (strncmp (namebuf, newname, namelen))
2209 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2210 typeinfo.defined != 0 ? &typeinfo : NULL);
2211
2212 return 1;
2213 }
2214
2215 /* Should never be called, as .req goes between the alias and the
2216 register name, not at the beginning of the line. */
2217 static void
2218 s_req (int a ATTRIBUTE_UNUSED)
2219 {
2220 as_bad (_("invalid syntax for .req directive"));
2221 }
2222
2223 static void
2224 s_dn (int a ATTRIBUTE_UNUSED)
2225 {
2226 as_bad (_("invalid syntax for .dn directive"));
2227 }
2228
2229 static void
2230 s_qn (int a ATTRIBUTE_UNUSED)
2231 {
2232 as_bad (_("invalid syntax for .qn directive"));
2233 }
2234
2235 /* The .unreq directive deletes an alias which was previously defined
2236 by .req. For example:
2237
2238 my_alias .req r11
2239 .unreq my_alias */
2240
2241 static void
2242 s_unreq (int a ATTRIBUTE_UNUSED)
2243 {
2244 char * name;
2245 char saved_char;
2246
2247 name = input_line_pointer;
2248
2249 while (*input_line_pointer != 0
2250 && *input_line_pointer != ' '
2251 && *input_line_pointer != '\n')
2252 ++input_line_pointer;
2253
2254 saved_char = *input_line_pointer;
2255 *input_line_pointer = 0;
2256
2257 if (!*name)
2258 as_bad (_("invalid syntax for .unreq directive"));
2259 else
2260 {
2261 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
2262
2263 if (!reg)
2264 as_bad (_("unknown register alias '%s'"), name);
2265 else if (reg->builtin)
2266 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2267 name);
2268 else
2269 {
2270 hash_delete (arm_reg_hsh, name);
2271 free ((char *) reg->name);
2272 if (reg->neon)
2273 free (reg->neon);
2274 free (reg);
2275 }
2276 }
2277
2278 *input_line_pointer = saved_char;
2279 demand_empty_rest_of_line ();
2280 }
2281
2282 /* Directives: Instruction set selection. */
2283
2284 #ifdef OBJ_ELF
2285 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2286 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2287 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2288 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2289
2290 static enum mstate mapstate = MAP_UNDEFINED;
2291
2292 void
2293 mapping_state (enum mstate state)
2294 {
2295 symbolS * symbolP;
2296 const char * symname;
2297 int type;
2298
2299 if (mapstate == state)
2300 /* The mapping symbol has already been emitted.
2301 There is nothing else to do. */
2302 return;
2303
2304 mapstate = state;
2305
2306 switch (state)
2307 {
2308 case MAP_DATA:
2309 symname = "$d";
2310 type = BSF_NO_FLAGS;
2311 break;
2312 case MAP_ARM:
2313 symname = "$a";
2314 type = BSF_NO_FLAGS;
2315 break;
2316 case MAP_THUMB:
2317 symname = "$t";
2318 type = BSF_NO_FLAGS;
2319 break;
2320 case MAP_UNDEFINED:
2321 return;
2322 default:
2323 abort ();
2324 }
2325
2326 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2327
2328 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
2329 symbol_table_insert (symbolP);
2330 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2331
2332 switch (state)
2333 {
2334 case MAP_ARM:
2335 THUMB_SET_FUNC (symbolP, 0);
2336 ARM_SET_THUMB (symbolP, 0);
2337 ARM_SET_INTERWORK (symbolP, support_interwork);
2338 break;
2339
2340 case MAP_THUMB:
2341 THUMB_SET_FUNC (symbolP, 1);
2342 ARM_SET_THUMB (symbolP, 1);
2343 ARM_SET_INTERWORK (symbolP, support_interwork);
2344 break;
2345
2346 case MAP_DATA:
2347 default:
2348 return;
2349 }
2350 }
2351 #else
2352 #define mapping_state(x) /* nothing */
2353 #endif
2354
2355 /* Find the real, Thumb encoded start of a Thumb function. */
2356
2357 static symbolS *
2358 find_real_start (symbolS * symbolP)
2359 {
2360 char * real_start;
2361 const char * name = S_GET_NAME (symbolP);
2362 symbolS * new_target;
2363
2364 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2365 #define STUB_NAME ".real_start_of"
2366
2367 if (name == NULL)
2368 abort ();
2369
2370 /* The compiler may generate BL instructions to local labels because
2371 it needs to perform a branch to a far away location. These labels
2372 do not have a corresponding ".real_start_of" label. We check
2373 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2374 the ".real_start_of" convention for nonlocal branches. */
2375 if (S_IS_LOCAL (symbolP) || name[0] == '.')
2376 return symbolP;
2377
2378 real_start = ACONCAT ((STUB_NAME, name, NULL));
2379 new_target = symbol_find (real_start);
2380
2381 if (new_target == NULL)
2382 {
2383 as_warn ("Failed to find real start of function: %s\n", name);
2384 new_target = symbolP;
2385 }
2386
2387 return new_target;
2388 }
2389
2390 static void
2391 opcode_select (int width)
2392 {
2393 switch (width)
2394 {
2395 case 16:
2396 if (! thumb_mode)
2397 {
2398 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
2399 as_bad (_("selected processor does not support THUMB opcodes"));
2400
2401 thumb_mode = 1;
2402 /* No need to force the alignment, since we will have been
2403 coming from ARM mode, which is word-aligned. */
2404 record_alignment (now_seg, 1);
2405 }
2406 mapping_state (MAP_THUMB);
2407 break;
2408
2409 case 32:
2410 if (thumb_mode)
2411 {
2412 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
2413 as_bad (_("selected processor does not support ARM opcodes"));
2414
2415 thumb_mode = 0;
2416
2417 if (!need_pass_2)
2418 frag_align (2, 0, 0);
2419
2420 record_alignment (now_seg, 1);
2421 }
2422 mapping_state (MAP_ARM);
2423 break;
2424
2425 default:
2426 as_bad (_("invalid instruction size selected (%d)"), width);
2427 }
2428 }
2429
2430 static void
2431 s_arm (int ignore ATTRIBUTE_UNUSED)
2432 {
2433 opcode_select (32);
2434 demand_empty_rest_of_line ();
2435 }
2436
2437 static void
2438 s_thumb (int ignore ATTRIBUTE_UNUSED)
2439 {
2440 opcode_select (16);
2441 demand_empty_rest_of_line ();
2442 }
2443
2444 static void
2445 s_code (int unused ATTRIBUTE_UNUSED)
2446 {
2447 int temp;
2448
2449 temp = get_absolute_expression ();
2450 switch (temp)
2451 {
2452 case 16:
2453 case 32:
2454 opcode_select (temp);
2455 break;
2456
2457 default:
2458 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2459 }
2460 }
2461
2462 static void
2463 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2464 {
2465 /* If we are not already in thumb mode go into it, EVEN if
2466 the target processor does not support thumb instructions.
2467 This is used by gcc/config/arm/lib1funcs.asm for example
2468 to compile interworking support functions even if the
2469 target processor should not support interworking. */
2470 if (! thumb_mode)
2471 {
2472 thumb_mode = 2;
2473 record_alignment (now_seg, 1);
2474 }
2475
2476 demand_empty_rest_of_line ();
2477 }
2478
2479 static void
2480 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2481 {
2482 s_thumb (0);
2483
2484 /* The following label is the name/address of the start of a Thumb function.
2485 We need to know this for the interworking support. */
2486 label_is_thumb_function_name = TRUE;
2487 }
2488
2489 /* Perform a .set directive, but also mark the alias as
2490 being a thumb function. */
2491
2492 static void
2493 s_thumb_set (int equiv)
2494 {
2495 /* XXX the following is a duplicate of the code for s_set() in read.c
2496 We cannot just call that code as we need to get at the symbol that
2497 is created. */
2498 char * name;
2499 char delim;
2500 char * end_name;
2501 symbolS * symbolP;
2502
2503 /* Especial apologies for the random logic:
2504 This just grew, and could be parsed much more simply!
2505 Dean - in haste. */
2506 name = input_line_pointer;
2507 delim = get_symbol_end ();
2508 end_name = input_line_pointer;
2509 *end_name = delim;
2510
2511 if (*input_line_pointer != ',')
2512 {
2513 *end_name = 0;
2514 as_bad (_("expected comma after name \"%s\""), name);
2515 *end_name = delim;
2516 ignore_rest_of_line ();
2517 return;
2518 }
2519
2520 input_line_pointer++;
2521 *end_name = 0;
2522
2523 if (name[0] == '.' && name[1] == '\0')
2524 {
2525 /* XXX - this should not happen to .thumb_set. */
2526 abort ();
2527 }
2528
2529 if ((symbolP = symbol_find (name)) == NULL
2530 && (symbolP = md_undefined_symbol (name)) == NULL)
2531 {
2532 #ifndef NO_LISTING
2533 /* When doing symbol listings, play games with dummy fragments living
2534 outside the normal fragment chain to record the file and line info
2535 for this symbol. */
2536 if (listing & LISTING_SYMBOLS)
2537 {
2538 extern struct list_info_struct * listing_tail;
2539 fragS * dummy_frag = xmalloc (sizeof (fragS));
2540
2541 memset (dummy_frag, 0, sizeof (fragS));
2542 dummy_frag->fr_type = rs_fill;
2543 dummy_frag->line = listing_tail;
2544 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2545 dummy_frag->fr_symbol = symbolP;
2546 }
2547 else
2548 #endif
2549 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2550
2551 #ifdef OBJ_COFF
2552 /* "set" symbols are local unless otherwise specified. */
2553 SF_SET_LOCAL (symbolP);
2554 #endif /* OBJ_COFF */
2555 } /* Make a new symbol. */
2556
2557 symbol_table_insert (symbolP);
2558
2559 * end_name = delim;
2560
2561 if (equiv
2562 && S_IS_DEFINED (symbolP)
2563 && S_GET_SEGMENT (symbolP) != reg_section)
2564 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2565
2566 pseudo_set (symbolP);
2567
2568 demand_empty_rest_of_line ();
2569
2570 /* XXX Now we come to the Thumb specific bit of code. */
2571
2572 THUMB_SET_FUNC (symbolP, 1);
2573 ARM_SET_THUMB (symbolP, 1);
2574 #if defined OBJ_ELF || defined OBJ_COFF
2575 ARM_SET_INTERWORK (symbolP, support_interwork);
2576 #endif
2577 }
2578
2579 /* Directives: Mode selection. */
2580
2581 /* .syntax [unified|divided] - choose the new unified syntax
2582 (same for Arm and Thumb encoding, modulo slight differences in what
2583 can be represented) or the old divergent syntax for each mode. */
2584 static void
2585 s_syntax (int unused ATTRIBUTE_UNUSED)
2586 {
2587 char *name, delim;
2588
2589 name = input_line_pointer;
2590 delim = get_symbol_end ();
2591
2592 if (!strcasecmp (name, "unified"))
2593 unified_syntax = TRUE;
2594 else if (!strcasecmp (name, "divided"))
2595 unified_syntax = FALSE;
2596 else
2597 {
2598 as_bad (_("unrecognized syntax mode \"%s\""), name);
2599 return;
2600 }
2601 *input_line_pointer = delim;
2602 demand_empty_rest_of_line ();
2603 }
2604
2605 /* Directives: sectioning and alignment. */
2606
2607 /* Same as s_align_ptwo but align 0 => align 2. */
2608
2609 static void
2610 s_align (int unused ATTRIBUTE_UNUSED)
2611 {
2612 int temp;
2613 long temp_fill;
2614 long max_alignment = 15;
2615
2616 temp = get_absolute_expression ();
2617 if (temp > max_alignment)
2618 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2619 else if (temp < 0)
2620 {
2621 as_bad (_("alignment negative. 0 assumed."));
2622 temp = 0;
2623 }
2624
2625 if (*input_line_pointer == ',')
2626 {
2627 input_line_pointer++;
2628 temp_fill = get_absolute_expression ();
2629 }
2630 else
2631 temp_fill = 0;
2632
2633 if (!temp)
2634 temp = 2;
2635
2636 /* Only make a frag if we HAVE to. */
2637 if (temp && !need_pass_2)
2638 frag_align (temp, (int) temp_fill, 0);
2639 demand_empty_rest_of_line ();
2640
2641 record_alignment (now_seg, temp);
2642 }
2643
2644 static void
2645 s_bss (int ignore ATTRIBUTE_UNUSED)
2646 {
2647 /* We don't support putting frags in the BSS segment, we fake it by
2648 marking in_bss, then looking at s_skip for clues. */
2649 subseg_set (bss_section, 0);
2650 demand_empty_rest_of_line ();
2651 mapping_state (MAP_DATA);
2652 }
2653
2654 static void
2655 s_even (int ignore ATTRIBUTE_UNUSED)
2656 {
2657 /* Never make frag if expect extra pass. */
2658 if (!need_pass_2)
2659 frag_align (1, 0, 0);
2660
2661 record_alignment (now_seg, 1);
2662
2663 demand_empty_rest_of_line ();
2664 }
2665
2666 /* Directives: Literal pools. */
2667
2668 static literal_pool *
2669 find_literal_pool (void)
2670 {
2671 literal_pool * pool;
2672
2673 for (pool = list_of_pools; pool != NULL; pool = pool->next)
2674 {
2675 if (pool->section == now_seg
2676 && pool->sub_section == now_subseg)
2677 break;
2678 }
2679
2680 return pool;
2681 }
2682
2683 static literal_pool *
2684 find_or_make_literal_pool (void)
2685 {
2686 /* Next literal pool ID number. */
2687 static unsigned int latest_pool_num = 1;
2688 literal_pool * pool;
2689
2690 pool = find_literal_pool ();
2691
2692 if (pool == NULL)
2693 {
2694 /* Create a new pool. */
2695 pool = xmalloc (sizeof (* pool));
2696 if (! pool)
2697 return NULL;
2698
2699 pool->next_free_entry = 0;
2700 pool->section = now_seg;
2701 pool->sub_section = now_subseg;
2702 pool->next = list_of_pools;
2703 pool->symbol = NULL;
2704
2705 /* Add it to the list. */
2706 list_of_pools = pool;
2707 }
2708
2709 /* New pools, and emptied pools, will have a NULL symbol. */
2710 if (pool->symbol == NULL)
2711 {
2712 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2713 (valueT) 0, &zero_address_frag);
2714 pool->id = latest_pool_num ++;
2715 }
2716
2717 /* Done. */
2718 return pool;
2719 }
2720
2721 /* Add the literal in the global 'inst'
2722 structure to the relevent literal pool. */
2723
2724 static int
2725 add_to_lit_pool (void)
2726 {
2727 literal_pool * pool;
2728 unsigned int entry;
2729
2730 pool = find_or_make_literal_pool ();
2731
2732 /* Check if this literal value is already in the pool. */
2733 for (entry = 0; entry < pool->next_free_entry; entry ++)
2734 {
2735 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2736 && (inst.reloc.exp.X_op == O_constant)
2737 && (pool->literals[entry].X_add_number
2738 == inst.reloc.exp.X_add_number)
2739 && (pool->literals[entry].X_unsigned
2740 == inst.reloc.exp.X_unsigned))
2741 break;
2742
2743 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2744 && (inst.reloc.exp.X_op == O_symbol)
2745 && (pool->literals[entry].X_add_number
2746 == inst.reloc.exp.X_add_number)
2747 && (pool->literals[entry].X_add_symbol
2748 == inst.reloc.exp.X_add_symbol)
2749 && (pool->literals[entry].X_op_symbol
2750 == inst.reloc.exp.X_op_symbol))
2751 break;
2752 }
2753
2754 /* Do we need to create a new entry? */
2755 if (entry == pool->next_free_entry)
2756 {
2757 if (entry >= MAX_LITERAL_POOL_SIZE)
2758 {
2759 inst.error = _("literal pool overflow");
2760 return FAIL;
2761 }
2762
2763 pool->literals[entry] = inst.reloc.exp;
2764 pool->next_free_entry += 1;
2765 }
2766
2767 inst.reloc.exp.X_op = O_symbol;
2768 inst.reloc.exp.X_add_number = ((int) entry) * 4;
2769 inst.reloc.exp.X_add_symbol = pool->symbol;
2770
2771 return SUCCESS;
2772 }
2773
2774 /* Can't use symbol_new here, so have to create a symbol and then at
2775 a later date assign it a value. Thats what these functions do. */
2776
2777 static void
2778 symbol_locate (symbolS * symbolP,
2779 const char * name, /* It is copied, the caller can modify. */
2780 segT segment, /* Segment identifier (SEG_<something>). */
2781 valueT valu, /* Symbol value. */
2782 fragS * frag) /* Associated fragment. */
2783 {
2784 unsigned int name_length;
2785 char * preserved_copy_of_name;
2786
2787 name_length = strlen (name) + 1; /* +1 for \0. */
2788 obstack_grow (&notes, name, name_length);
2789 preserved_copy_of_name = obstack_finish (&notes);
2790
2791 #ifdef tc_canonicalize_symbol_name
2792 preserved_copy_of_name =
2793 tc_canonicalize_symbol_name (preserved_copy_of_name);
2794 #endif
2795
2796 S_SET_NAME (symbolP, preserved_copy_of_name);
2797
2798 S_SET_SEGMENT (symbolP, segment);
2799 S_SET_VALUE (symbolP, valu);
2800 symbol_clear_list_pointers (symbolP);
2801
2802 symbol_set_frag (symbolP, frag);
2803
2804 /* Link to end of symbol chain. */
2805 {
2806 extern int symbol_table_frozen;
2807
2808 if (symbol_table_frozen)
2809 abort ();
2810 }
2811
2812 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
2813
2814 obj_symbol_new_hook (symbolP);
2815
2816 #ifdef tc_symbol_new_hook
2817 tc_symbol_new_hook (symbolP);
2818 #endif
2819
2820 #ifdef DEBUG_SYMS
2821 verify_symbol_chain (symbol_rootP, symbol_lastP);
2822 #endif /* DEBUG_SYMS */
2823 }
2824
2825
2826 static void
2827 s_ltorg (int ignored ATTRIBUTE_UNUSED)
2828 {
2829 unsigned int entry;
2830 literal_pool * pool;
2831 char sym_name[20];
2832
2833 pool = find_literal_pool ();
2834 if (pool == NULL
2835 || pool->symbol == NULL
2836 || pool->next_free_entry == 0)
2837 return;
2838
2839 mapping_state (MAP_DATA);
2840
2841 /* Align pool as you have word accesses.
2842 Only make a frag if we have to. */
2843 if (!need_pass_2)
2844 frag_align (2, 0, 0);
2845
2846 record_alignment (now_seg, 2);
2847
2848 sprintf (sym_name, "$$lit_\002%x", pool->id);
2849
2850 symbol_locate (pool->symbol, sym_name, now_seg,
2851 (valueT) frag_now_fix (), frag_now);
2852 symbol_table_insert (pool->symbol);
2853
2854 ARM_SET_THUMB (pool->symbol, thumb_mode);
2855
2856 #if defined OBJ_COFF || defined OBJ_ELF
2857 ARM_SET_INTERWORK (pool->symbol, support_interwork);
2858 #endif
2859
2860 for (entry = 0; entry < pool->next_free_entry; entry ++)
2861 /* First output the expression in the instruction to the pool. */
2862 emit_expr (&(pool->literals[entry]), 4); /* .word */
2863
2864 /* Mark the pool as empty. */
2865 pool->next_free_entry = 0;
2866 pool->symbol = NULL;
2867 }
2868
2869 #ifdef OBJ_ELF
2870 /* Forward declarations for functions below, in the MD interface
2871 section. */
2872 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
2873 static valueT create_unwind_entry (int);
2874 static void start_unwind_section (const segT, int);
2875 static void add_unwind_opcode (valueT, int);
2876 static void flush_pending_unwind (void);
2877
2878 /* Directives: Data. */
2879
2880 static void
2881 s_arm_elf_cons (int nbytes)
2882 {
2883 expressionS exp;
2884
2885 #ifdef md_flush_pending_output
2886 md_flush_pending_output ();
2887 #endif
2888
2889 if (is_it_end_of_statement ())
2890 {
2891 demand_empty_rest_of_line ();
2892 return;
2893 }
2894
2895 #ifdef md_cons_align
2896 md_cons_align (nbytes);
2897 #endif
2898
2899 mapping_state (MAP_DATA);
2900 do
2901 {
2902 int reloc;
2903 char *base = input_line_pointer;
2904
2905 expression (& exp);
2906
2907 if (exp.X_op != O_symbol)
2908 emit_expr (&exp, (unsigned int) nbytes);
2909 else
2910 {
2911 char *before_reloc = input_line_pointer;
2912 reloc = parse_reloc (&input_line_pointer);
2913 if (reloc == -1)
2914 {
2915 as_bad (_("unrecognized relocation suffix"));
2916 ignore_rest_of_line ();
2917 return;
2918 }
2919 else if (reloc == BFD_RELOC_UNUSED)
2920 emit_expr (&exp, (unsigned int) nbytes);
2921 else
2922 {
2923 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
2924 int size = bfd_get_reloc_size (howto);
2925
2926 if (reloc == BFD_RELOC_ARM_PLT32)
2927 {
2928 as_bad (_("(plt) is only valid on branch targets"));
2929 reloc = BFD_RELOC_UNUSED;
2930 size = 0;
2931 }
2932
2933 if (size > nbytes)
2934 as_bad (_("%s relocations do not fit in %d bytes"),
2935 howto->name, nbytes);
2936 else
2937 {
2938 /* We've parsed an expression stopping at O_symbol.
2939 But there may be more expression left now that we
2940 have parsed the relocation marker. Parse it again.
2941 XXX Surely there is a cleaner way to do this. */
2942 char *p = input_line_pointer;
2943 int offset;
2944 char *save_buf = alloca (input_line_pointer - base);
2945 memcpy (save_buf, base, input_line_pointer - base);
2946 memmove (base + (input_line_pointer - before_reloc),
2947 base, before_reloc - base);
2948
2949 input_line_pointer = base + (input_line_pointer-before_reloc);
2950 expression (&exp);
2951 memcpy (base, save_buf, p - base);
2952
2953 offset = nbytes - size;
2954 p = frag_more ((int) nbytes);
2955 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
2956 size, &exp, 0, reloc);
2957 }
2958 }
2959 }
2960 }
2961 while (*input_line_pointer++ == ',');
2962
2963 /* Put terminator back into stream. */
2964 input_line_pointer --;
2965 demand_empty_rest_of_line ();
2966 }
2967
2968
2969 /* Parse a .rel31 directive. */
2970
2971 static void
2972 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
2973 {
2974 expressionS exp;
2975 char *p;
2976 valueT highbit;
2977
2978 highbit = 0;
2979 if (*input_line_pointer == '1')
2980 highbit = 0x80000000;
2981 else if (*input_line_pointer != '0')
2982 as_bad (_("expected 0 or 1"));
2983
2984 input_line_pointer++;
2985 if (*input_line_pointer != ',')
2986 as_bad (_("missing comma"));
2987 input_line_pointer++;
2988
2989 #ifdef md_flush_pending_output
2990 md_flush_pending_output ();
2991 #endif
2992
2993 #ifdef md_cons_align
2994 md_cons_align (4);
2995 #endif
2996
2997 mapping_state (MAP_DATA);
2998
2999 expression (&exp);
3000
3001 p = frag_more (4);
3002 md_number_to_chars (p, highbit, 4);
3003 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3004 BFD_RELOC_ARM_PREL31);
3005
3006 demand_empty_rest_of_line ();
3007 }
3008
3009 /* Directives: AEABI stack-unwind tables. */
3010
3011 /* Parse an unwind_fnstart directive. Simply records the current location. */
3012
3013 static void
3014 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3015 {
3016 demand_empty_rest_of_line ();
3017 /* Mark the start of the function. */
3018 unwind.proc_start = expr_build_dot ();
3019
3020 /* Reset the rest of the unwind info. */
3021 unwind.opcode_count = 0;
3022 unwind.table_entry = NULL;
3023 unwind.personality_routine = NULL;
3024 unwind.personality_index = -1;
3025 unwind.frame_size = 0;
3026 unwind.fp_offset = 0;
3027 unwind.fp_reg = 13;
3028 unwind.fp_used = 0;
3029 unwind.sp_restored = 0;
3030 }
3031
3032
3033 /* Parse a handlerdata directive. Creates the exception handling table entry
3034 for the function. */
3035
3036 static void
3037 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3038 {
3039 demand_empty_rest_of_line ();
3040 if (unwind.table_entry)
3041 as_bad (_("dupicate .handlerdata directive"));
3042
3043 create_unwind_entry (1);
3044 }
3045
3046 /* Parse an unwind_fnend directive. Generates the index table entry. */
3047
3048 static void
3049 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3050 {
3051 long where;
3052 char *ptr;
3053 valueT val;
3054
3055 demand_empty_rest_of_line ();
3056
3057 /* Add eh table entry. */
3058 if (unwind.table_entry == NULL)
3059 val = create_unwind_entry (0);
3060 else
3061 val = 0;
3062
3063 /* Add index table entry. This is two words. */
3064 start_unwind_section (unwind.saved_seg, 1);
3065 frag_align (2, 0, 0);
3066 record_alignment (now_seg, 2);
3067
3068 ptr = frag_more (8);
3069 where = frag_now_fix () - 8;
3070
3071 /* Self relative offset of the function start. */
3072 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3073 BFD_RELOC_ARM_PREL31);
3074
3075 /* Indicate dependency on EHABI-defined personality routines to the
3076 linker, if it hasn't been done already. */
3077 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3078 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3079 {
3080 static const char *const name[] = {
3081 "__aeabi_unwind_cpp_pr0",
3082 "__aeabi_unwind_cpp_pr1",
3083 "__aeabi_unwind_cpp_pr2"
3084 };
3085 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3086 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3087 marked_pr_dependency |= 1 << unwind.personality_index;
3088 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3089 = marked_pr_dependency;
3090 }
3091
3092 if (val)
3093 /* Inline exception table entry. */
3094 md_number_to_chars (ptr + 4, val, 4);
3095 else
3096 /* Self relative offset of the table entry. */
3097 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3098 BFD_RELOC_ARM_PREL31);
3099
3100 /* Restore the original section. */
3101 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3102 }
3103
3104
3105 /* Parse an unwind_cantunwind directive. */
3106
3107 static void
3108 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3109 {
3110 demand_empty_rest_of_line ();
3111 if (unwind.personality_routine || unwind.personality_index != -1)
3112 as_bad (_("personality routine specified for cantunwind frame"));
3113
3114 unwind.personality_index = -2;
3115 }
3116
3117
3118 /* Parse a personalityindex directive. */
3119
3120 static void
3121 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3122 {
3123 expressionS exp;
3124
3125 if (unwind.personality_routine || unwind.personality_index != -1)
3126 as_bad (_("duplicate .personalityindex directive"));
3127
3128 expression (&exp);
3129
3130 if (exp.X_op != O_constant
3131 || exp.X_add_number < 0 || exp.X_add_number > 15)
3132 {
3133 as_bad (_("bad personality routine number"));
3134 ignore_rest_of_line ();
3135 return;
3136 }
3137
3138 unwind.personality_index = exp.X_add_number;
3139
3140 demand_empty_rest_of_line ();
3141 }
3142
3143
3144 /* Parse a personality directive. */
3145
3146 static void
3147 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3148 {
3149 char *name, *p, c;
3150
3151 if (unwind.personality_routine || unwind.personality_index != -1)
3152 as_bad (_("duplicate .personality directive"));
3153
3154 name = input_line_pointer;
3155 c = get_symbol_end ();
3156 p = input_line_pointer;
3157 unwind.personality_routine = symbol_find_or_make (name);
3158 *p = c;
3159 demand_empty_rest_of_line ();
3160 }
3161
3162
3163 /* Parse a directive saving core registers. */
3164
3165 static void
3166 s_arm_unwind_save_core (void)
3167 {
3168 valueT op;
3169 long range;
3170 int n;
3171
3172 range = parse_reg_list (&input_line_pointer);
3173 if (range == FAIL)
3174 {
3175 as_bad (_("expected register list"));
3176 ignore_rest_of_line ();
3177 return;
3178 }
3179
3180 demand_empty_rest_of_line ();
3181
3182 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3183 into .unwind_save {..., sp...}. We aren't bothered about the value of
3184 ip because it is clobbered by calls. */
3185 if (unwind.sp_restored && unwind.fp_reg == 12
3186 && (range & 0x3000) == 0x1000)
3187 {
3188 unwind.opcode_count--;
3189 unwind.sp_restored = 0;
3190 range = (range | 0x2000) & ~0x1000;
3191 unwind.pending_offset = 0;
3192 }
3193
3194 /* Pop r4-r15. */
3195 if (range & 0xfff0)
3196 {
3197 /* See if we can use the short opcodes. These pop a block of up to 8
3198 registers starting with r4, plus maybe r14. */
3199 for (n = 0; n < 8; n++)
3200 {
3201 /* Break at the first non-saved register. */
3202 if ((range & (1 << (n + 4))) == 0)
3203 break;
3204 }
3205 /* See if there are any other bits set. */
3206 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3207 {
3208 /* Use the long form. */
3209 op = 0x8000 | ((range >> 4) & 0xfff);
3210 add_unwind_opcode (op, 2);
3211 }
3212 else
3213 {
3214 /* Use the short form. */
3215 if (range & 0x4000)
3216 op = 0xa8; /* Pop r14. */
3217 else
3218 op = 0xa0; /* Do not pop r14. */
3219 op |= (n - 1);
3220 add_unwind_opcode (op, 1);
3221 }
3222 }
3223
3224 /* Pop r0-r3. */
3225 if (range & 0xf)
3226 {
3227 op = 0xb100 | (range & 0xf);
3228 add_unwind_opcode (op, 2);
3229 }
3230
3231 /* Record the number of bytes pushed. */
3232 for (n = 0; n < 16; n++)
3233 {
3234 if (range & (1 << n))
3235 unwind.frame_size += 4;
3236 }
3237 }
3238
3239
3240 /* Parse a directive saving FPA registers. */
3241
3242 static void
3243 s_arm_unwind_save_fpa (int reg)
3244 {
3245 expressionS exp;
3246 int num_regs;
3247 valueT op;
3248
3249 /* Get Number of registers to transfer. */
3250 if (skip_past_comma (&input_line_pointer) != FAIL)
3251 expression (&exp);
3252 else
3253 exp.X_op = O_illegal;
3254
3255 if (exp.X_op != O_constant)
3256 {
3257 as_bad (_("expected , <constant>"));
3258 ignore_rest_of_line ();
3259 return;
3260 }
3261
3262 num_regs = exp.X_add_number;
3263
3264 if (num_regs < 1 || num_regs > 4)
3265 {
3266 as_bad (_("number of registers must be in the range [1:4]"));
3267 ignore_rest_of_line ();
3268 return;
3269 }
3270
3271 demand_empty_rest_of_line ();
3272
3273 if (reg == 4)
3274 {
3275 /* Short form. */
3276 op = 0xb4 | (num_regs - 1);
3277 add_unwind_opcode (op, 1);
3278 }
3279 else
3280 {
3281 /* Long form. */
3282 op = 0xc800 | (reg << 4) | (num_regs - 1);
3283 add_unwind_opcode (op, 2);
3284 }
3285 unwind.frame_size += num_regs * 12;
3286 }
3287
3288
3289 /* Parse a directive saving VFP registers for ARMv6 and above. */
3290
3291 static void
3292 s_arm_unwind_save_vfp_armv6 (void)
3293 {
3294 int count;
3295 unsigned int start;
3296 valueT op;
3297 int num_vfpv3_regs = 0;
3298 int num_regs_below_16;
3299
3300 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3301 if (count == FAIL)
3302 {
3303 as_bad (_("expected register list"));
3304 ignore_rest_of_line ();
3305 return;
3306 }
3307
3308 demand_empty_rest_of_line ();
3309
3310 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3311 than FSTMX/FLDMX-style ones). */
3312
3313 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3314 if (start >= 16)
3315 num_vfpv3_regs = count;
3316 else if (start + count > 16)
3317 num_vfpv3_regs = start + count - 16;
3318
3319 if (num_vfpv3_regs > 0)
3320 {
3321 int start_offset = start > 16 ? start - 16 : 0;
3322 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3323 add_unwind_opcode (op, 2);
3324 }
3325
3326 /* Generate opcode for registers numbered in the range 0 .. 15. */
3327 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3328 assert (num_regs_below_16 + num_vfpv3_regs == count);
3329 if (num_regs_below_16 > 0)
3330 {
3331 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3332 add_unwind_opcode (op, 2);
3333 }
3334
3335 unwind.frame_size += count * 8;
3336 }
3337
3338
3339 /* Parse a directive saving VFP registers for pre-ARMv6. */
3340
3341 static void
3342 s_arm_unwind_save_vfp (void)
3343 {
3344 int count;
3345 unsigned int reg;
3346 valueT op;
3347
3348 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
3349 if (count == FAIL)
3350 {
3351 as_bad (_("expected register list"));
3352 ignore_rest_of_line ();
3353 return;
3354 }
3355
3356 demand_empty_rest_of_line ();
3357
3358 if (reg == 8)
3359 {
3360 /* Short form. */
3361 op = 0xb8 | (count - 1);
3362 add_unwind_opcode (op, 1);
3363 }
3364 else
3365 {
3366 /* Long form. */
3367 op = 0xb300 | (reg << 4) | (count - 1);
3368 add_unwind_opcode (op, 2);
3369 }
3370 unwind.frame_size += count * 8 + 4;
3371 }
3372
3373
3374 /* Parse a directive saving iWMMXt data registers. */
3375
3376 static void
3377 s_arm_unwind_save_mmxwr (void)
3378 {
3379 int reg;
3380 int hi_reg;
3381 int i;
3382 unsigned mask = 0;
3383 valueT op;
3384
3385 if (*input_line_pointer == '{')
3386 input_line_pointer++;
3387
3388 do
3389 {
3390 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3391
3392 if (reg == FAIL)
3393 {
3394 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3395 goto error;
3396 }
3397
3398 if (mask >> reg)
3399 as_tsktsk (_("register list not in ascending order"));
3400 mask |= 1 << reg;
3401
3402 if (*input_line_pointer == '-')
3403 {
3404 input_line_pointer++;
3405 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3406 if (hi_reg == FAIL)
3407 {
3408 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3409 goto error;
3410 }
3411 else if (reg >= hi_reg)
3412 {
3413 as_bad (_("bad register range"));
3414 goto error;
3415 }
3416 for (; reg < hi_reg; reg++)
3417 mask |= 1 << reg;
3418 }
3419 }
3420 while (skip_past_comma (&input_line_pointer) != FAIL);
3421
3422 if (*input_line_pointer == '}')
3423 input_line_pointer++;
3424
3425 demand_empty_rest_of_line ();
3426
3427 /* Generate any deferred opcodes because we're going to be looking at
3428 the list. */
3429 flush_pending_unwind ();
3430
3431 for (i = 0; i < 16; i++)
3432 {
3433 if (mask & (1 << i))
3434 unwind.frame_size += 8;
3435 }
3436
3437 /* Attempt to combine with a previous opcode. We do this because gcc
3438 likes to output separate unwind directives for a single block of
3439 registers. */
3440 if (unwind.opcode_count > 0)
3441 {
3442 i = unwind.opcodes[unwind.opcode_count - 1];
3443 if ((i & 0xf8) == 0xc0)
3444 {
3445 i &= 7;
3446 /* Only merge if the blocks are contiguous. */
3447 if (i < 6)
3448 {
3449 if ((mask & 0xfe00) == (1 << 9))
3450 {
3451 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3452 unwind.opcode_count--;
3453 }
3454 }
3455 else if (i == 6 && unwind.opcode_count >= 2)
3456 {
3457 i = unwind.opcodes[unwind.opcode_count - 2];
3458 reg = i >> 4;
3459 i &= 0xf;
3460
3461 op = 0xffff << (reg - 1);
3462 if (reg > 0
3463 && ((mask & op) == (1u << (reg - 1))))
3464 {
3465 op = (1 << (reg + i + 1)) - 1;
3466 op &= ~((1 << reg) - 1);
3467 mask |= op;
3468 unwind.opcode_count -= 2;
3469 }
3470 }
3471 }
3472 }
3473
3474 hi_reg = 15;
3475 /* We want to generate opcodes in the order the registers have been
3476 saved, ie. descending order. */
3477 for (reg = 15; reg >= -1; reg--)
3478 {
3479 /* Save registers in blocks. */
3480 if (reg < 0
3481 || !(mask & (1 << reg)))
3482 {
3483 /* We found an unsaved reg. Generate opcodes to save the
3484 preceeding block. */
3485 if (reg != hi_reg)
3486 {
3487 if (reg == 9)
3488 {
3489 /* Short form. */
3490 op = 0xc0 | (hi_reg - 10);
3491 add_unwind_opcode (op, 1);
3492 }
3493 else
3494 {
3495 /* Long form. */
3496 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3497 add_unwind_opcode (op, 2);
3498 }
3499 }
3500 hi_reg = reg - 1;
3501 }
3502 }
3503
3504 return;
3505 error:
3506 ignore_rest_of_line ();
3507 }
3508
3509 static void
3510 s_arm_unwind_save_mmxwcg (void)
3511 {
3512 int reg;
3513 int hi_reg;
3514 unsigned mask = 0;
3515 valueT op;
3516
3517 if (*input_line_pointer == '{')
3518 input_line_pointer++;
3519
3520 do
3521 {
3522 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3523
3524 if (reg == FAIL)
3525 {
3526 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3527 goto error;
3528 }
3529
3530 reg -= 8;
3531 if (mask >> reg)
3532 as_tsktsk (_("register list not in ascending order"));
3533 mask |= 1 << reg;
3534
3535 if (*input_line_pointer == '-')
3536 {
3537 input_line_pointer++;
3538 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3539 if (hi_reg == FAIL)
3540 {
3541 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3542 goto error;
3543 }
3544 else if (reg >= hi_reg)
3545 {
3546 as_bad (_("bad register range"));
3547 goto error;
3548 }
3549 for (; reg < hi_reg; reg++)
3550 mask |= 1 << reg;
3551 }
3552 }
3553 while (skip_past_comma (&input_line_pointer) != FAIL);
3554
3555 if (*input_line_pointer == '}')
3556 input_line_pointer++;
3557
3558 demand_empty_rest_of_line ();
3559
3560 /* Generate any deferred opcodes because we're going to be looking at
3561 the list. */
3562 flush_pending_unwind ();
3563
3564 for (reg = 0; reg < 16; reg++)
3565 {
3566 if (mask & (1 << reg))
3567 unwind.frame_size += 4;
3568 }
3569 op = 0xc700 | mask;
3570 add_unwind_opcode (op, 2);
3571 return;
3572 error:
3573 ignore_rest_of_line ();
3574 }
3575
3576
3577 /* Parse an unwind_save directive.
3578 If the argument is non-zero, this is a .vsave directive. */
3579
3580 static void
3581 s_arm_unwind_save (int arch_v6)
3582 {
3583 char *peek;
3584 struct reg_entry *reg;
3585 bfd_boolean had_brace = FALSE;
3586
3587 /* Figure out what sort of save we have. */
3588 peek = input_line_pointer;
3589
3590 if (*peek == '{')
3591 {
3592 had_brace = TRUE;
3593 peek++;
3594 }
3595
3596 reg = arm_reg_parse_multi (&peek);
3597
3598 if (!reg)
3599 {
3600 as_bad (_("register expected"));
3601 ignore_rest_of_line ();
3602 return;
3603 }
3604
3605 switch (reg->type)
3606 {
3607 case REG_TYPE_FN:
3608 if (had_brace)
3609 {
3610 as_bad (_("FPA .unwind_save does not take a register list"));
3611 ignore_rest_of_line ();
3612 return;
3613 }
3614 s_arm_unwind_save_fpa (reg->number);
3615 return;
3616
3617 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
3618 case REG_TYPE_VFD:
3619 if (arch_v6)
3620 s_arm_unwind_save_vfp_armv6 ();
3621 else
3622 s_arm_unwind_save_vfp ();
3623 return;
3624 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
3625 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
3626
3627 default:
3628 as_bad (_(".unwind_save does not support this kind of register"));
3629 ignore_rest_of_line ();
3630 }
3631 }
3632
3633
3634 /* Parse an unwind_movsp directive. */
3635
3636 static void
3637 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
3638 {
3639 int reg;
3640 valueT op;
3641 int offset;
3642
3643 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3644 if (reg == FAIL)
3645 {
3646 as_bad (_(reg_expected_msgs[REG_TYPE_RN]));
3647 ignore_rest_of_line ();
3648 return;
3649 }
3650
3651 /* Optional constant. */
3652 if (skip_past_comma (&input_line_pointer) != FAIL)
3653 {
3654 if (immediate_for_directive (&offset) == FAIL)
3655 return;
3656 }
3657 else
3658 offset = 0;
3659
3660 demand_empty_rest_of_line ();
3661
3662 if (reg == REG_SP || reg == REG_PC)
3663 {
3664 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
3665 return;
3666 }
3667
3668 if (unwind.fp_reg != REG_SP)
3669 as_bad (_("unexpected .unwind_movsp directive"));
3670
3671 /* Generate opcode to restore the value. */
3672 op = 0x90 | reg;
3673 add_unwind_opcode (op, 1);
3674
3675 /* Record the information for later. */
3676 unwind.fp_reg = reg;
3677 unwind.fp_offset = unwind.frame_size - offset;
3678 unwind.sp_restored = 1;
3679 }
3680
3681 /* Parse an unwind_pad directive. */
3682
3683 static void
3684 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
3685 {
3686 int offset;
3687
3688 if (immediate_for_directive (&offset) == FAIL)
3689 return;
3690
3691 if (offset & 3)
3692 {
3693 as_bad (_("stack increment must be multiple of 4"));
3694 ignore_rest_of_line ();
3695 return;
3696 }
3697
3698 /* Don't generate any opcodes, just record the details for later. */
3699 unwind.frame_size += offset;
3700 unwind.pending_offset += offset;
3701
3702 demand_empty_rest_of_line ();
3703 }
3704
3705 /* Parse an unwind_setfp directive. */
3706
3707 static void
3708 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
3709 {
3710 int sp_reg;
3711 int fp_reg;
3712 int offset;
3713
3714 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3715 if (skip_past_comma (&input_line_pointer) == FAIL)
3716 sp_reg = FAIL;
3717 else
3718 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3719
3720 if (fp_reg == FAIL || sp_reg == FAIL)
3721 {
3722 as_bad (_("expected <reg>, <reg>"));
3723 ignore_rest_of_line ();
3724 return;
3725 }
3726
3727 /* Optional constant. */
3728 if (skip_past_comma (&input_line_pointer) != FAIL)
3729 {
3730 if (immediate_for_directive (&offset) == FAIL)
3731 return;
3732 }
3733 else
3734 offset = 0;
3735
3736 demand_empty_rest_of_line ();
3737
3738 if (sp_reg != 13 && sp_reg != unwind.fp_reg)
3739 {
3740 as_bad (_("register must be either sp or set by a previous"
3741 "unwind_movsp directive"));
3742 return;
3743 }
3744
3745 /* Don't generate any opcodes, just record the information for later. */
3746 unwind.fp_reg = fp_reg;
3747 unwind.fp_used = 1;
3748 if (sp_reg == 13)
3749 unwind.fp_offset = unwind.frame_size - offset;
3750 else
3751 unwind.fp_offset -= offset;
3752 }
3753
3754 /* Parse an unwind_raw directive. */
3755
3756 static void
3757 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
3758 {
3759 expressionS exp;
3760 /* This is an arbitrary limit. */
3761 unsigned char op[16];
3762 int count;
3763
3764 expression (&exp);
3765 if (exp.X_op == O_constant
3766 && skip_past_comma (&input_line_pointer) != FAIL)
3767 {
3768 unwind.frame_size += exp.X_add_number;
3769 expression (&exp);
3770 }
3771 else
3772 exp.X_op = O_illegal;
3773
3774 if (exp.X_op != O_constant)
3775 {
3776 as_bad (_("expected <offset>, <opcode>"));
3777 ignore_rest_of_line ();
3778 return;
3779 }
3780
3781 count = 0;
3782
3783 /* Parse the opcode. */
3784 for (;;)
3785 {
3786 if (count >= 16)
3787 {
3788 as_bad (_("unwind opcode too long"));
3789 ignore_rest_of_line ();
3790 }
3791 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
3792 {
3793 as_bad (_("invalid unwind opcode"));
3794 ignore_rest_of_line ();
3795 return;
3796 }
3797 op[count++] = exp.X_add_number;
3798
3799 /* Parse the next byte. */
3800 if (skip_past_comma (&input_line_pointer) == FAIL)
3801 break;
3802
3803 expression (&exp);
3804 }
3805
3806 /* Add the opcode bytes in reverse order. */
3807 while (count--)
3808 add_unwind_opcode (op[count], 1);
3809
3810 demand_empty_rest_of_line ();
3811 }
3812
3813
3814 /* Parse a .eabi_attribute directive. */
3815
3816 static void
3817 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
3818 {
3819 expressionS exp;
3820 bfd_boolean is_string;
3821 int tag;
3822 unsigned int i = 0;
3823 char *s = NULL;
3824 char saved_char;
3825
3826 expression (& exp);
3827 if (exp.X_op != O_constant)
3828 goto bad;
3829
3830 tag = exp.X_add_number;
3831 if (tag == 4 || tag == 5 || tag == 32 || (tag > 32 && (tag & 1) != 0))
3832 is_string = 1;
3833 else
3834 is_string = 0;
3835
3836 if (skip_past_comma (&input_line_pointer) == FAIL)
3837 goto bad;
3838 if (tag == 32 || !is_string)
3839 {
3840 expression (& exp);
3841 if (exp.X_op != O_constant)
3842 {
3843 as_bad (_("expected numeric constant"));
3844 ignore_rest_of_line ();
3845 return;
3846 }
3847 i = exp.X_add_number;
3848 }
3849 if (tag == Tag_compatibility
3850 && skip_past_comma (&input_line_pointer) == FAIL)
3851 {
3852 as_bad (_("expected comma"));
3853 ignore_rest_of_line ();
3854 return;
3855 }
3856 if (is_string)
3857 {
3858 skip_whitespace(input_line_pointer);
3859 if (*input_line_pointer != '"')
3860 goto bad_string;
3861 input_line_pointer++;
3862 s = input_line_pointer;
3863 while (*input_line_pointer && *input_line_pointer != '"')
3864 input_line_pointer++;
3865 if (*input_line_pointer != '"')
3866 goto bad_string;
3867 saved_char = *input_line_pointer;
3868 *input_line_pointer = 0;
3869 }
3870 else
3871 {
3872 s = NULL;
3873 saved_char = 0;
3874 }
3875
3876 if (tag == Tag_compatibility)
3877 elf32_arm_add_eabi_attr_compat (stdoutput, i, s);
3878 else if (is_string)
3879 elf32_arm_add_eabi_attr_string (stdoutput, tag, s);
3880 else
3881 elf32_arm_add_eabi_attr_int (stdoutput, tag, i);
3882
3883 if (s)
3884 {
3885 *input_line_pointer = saved_char;
3886 input_line_pointer++;
3887 }
3888 demand_empty_rest_of_line ();
3889 return;
3890 bad_string:
3891 as_bad (_("bad string constant"));
3892 ignore_rest_of_line ();
3893 return;
3894 bad:
3895 as_bad (_("expected <tag> , <value>"));
3896 ignore_rest_of_line ();
3897 }
3898 #endif /* OBJ_ELF */
3899
3900 static void s_arm_arch (int);
3901 static void s_arm_object_arch (int);
3902 static void s_arm_cpu (int);
3903 static void s_arm_fpu (int);
3904
3905 #ifdef TE_PE
3906
3907 static void
3908 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
3909 {
3910 expressionS exp;
3911
3912 do
3913 {
3914 expression (&exp);
3915 if (exp.X_op == O_symbol)
3916 exp.X_op = O_secrel;
3917
3918 emit_expr (&exp, 4);
3919 }
3920 while (*input_line_pointer++ == ',');
3921
3922 input_line_pointer--;
3923 demand_empty_rest_of_line ();
3924 }
3925 #endif /* TE_PE */
3926
3927 /* This table describes all the machine specific pseudo-ops the assembler
3928 has to support. The fields are:
3929 pseudo-op name without dot
3930 function to call to execute this pseudo-op
3931 Integer arg to pass to the function. */
3932
3933 const pseudo_typeS md_pseudo_table[] =
3934 {
3935 /* Never called because '.req' does not start a line. */
3936 { "req", s_req, 0 },
3937 /* Following two are likewise never called. */
3938 { "dn", s_dn, 0 },
3939 { "qn", s_qn, 0 },
3940 { "unreq", s_unreq, 0 },
3941 { "bss", s_bss, 0 },
3942 { "align", s_align, 0 },
3943 { "arm", s_arm, 0 },
3944 { "thumb", s_thumb, 0 },
3945 { "code", s_code, 0 },
3946 { "force_thumb", s_force_thumb, 0 },
3947 { "thumb_func", s_thumb_func, 0 },
3948 { "thumb_set", s_thumb_set, 0 },
3949 { "even", s_even, 0 },
3950 { "ltorg", s_ltorg, 0 },
3951 { "pool", s_ltorg, 0 },
3952 { "syntax", s_syntax, 0 },
3953 { "cpu", s_arm_cpu, 0 },
3954 { "arch", s_arm_arch, 0 },
3955 { "object_arch", s_arm_object_arch, 0 },
3956 { "fpu", s_arm_fpu, 0 },
3957 #ifdef OBJ_ELF
3958 { "word", s_arm_elf_cons, 4 },
3959 { "long", s_arm_elf_cons, 4 },
3960 { "rel31", s_arm_rel31, 0 },
3961 { "fnstart", s_arm_unwind_fnstart, 0 },
3962 { "fnend", s_arm_unwind_fnend, 0 },
3963 { "cantunwind", s_arm_unwind_cantunwind, 0 },
3964 { "personality", s_arm_unwind_personality, 0 },
3965 { "personalityindex", s_arm_unwind_personalityindex, 0 },
3966 { "handlerdata", s_arm_unwind_handlerdata, 0 },
3967 { "save", s_arm_unwind_save, 0 },
3968 { "vsave", s_arm_unwind_save, 1 },
3969 { "movsp", s_arm_unwind_movsp, 0 },
3970 { "pad", s_arm_unwind_pad, 0 },
3971 { "setfp", s_arm_unwind_setfp, 0 },
3972 { "unwind_raw", s_arm_unwind_raw, 0 },
3973 { "eabi_attribute", s_arm_eabi_attribute, 0 },
3974 #else
3975 { "word", cons, 4},
3976
3977 /* These are used for dwarf. */
3978 {"2byte", cons, 2},
3979 {"4byte", cons, 4},
3980 {"8byte", cons, 8},
3981 /* These are used for dwarf2. */
3982 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
3983 { "loc", dwarf2_directive_loc, 0 },
3984 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
3985 #endif
3986 { "extend", float_cons, 'x' },
3987 { "ldouble", float_cons, 'x' },
3988 { "packed", float_cons, 'p' },
3989 #ifdef TE_PE
3990 {"secrel32", pe_directive_secrel, 0},
3991 #endif
3992 { 0, 0, 0 }
3993 };
3994 \f
3995 /* Parser functions used exclusively in instruction operands. */
3996
3997 /* Generic immediate-value read function for use in insn parsing.
3998 STR points to the beginning of the immediate (the leading #);
3999 VAL receives the value; if the value is outside [MIN, MAX]
4000 issue an error. PREFIX_OPT is true if the immediate prefix is
4001 optional. */
4002
4003 static int
4004 parse_immediate (char **str, int *val, int min, int max,
4005 bfd_boolean prefix_opt)
4006 {
4007 expressionS exp;
4008 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4009 if (exp.X_op != O_constant)
4010 {
4011 inst.error = _("constant expression required");
4012 return FAIL;
4013 }
4014
4015 if (exp.X_add_number < min || exp.X_add_number > max)
4016 {
4017 inst.error = _("immediate value out of range");
4018 return FAIL;
4019 }
4020
4021 *val = exp.X_add_number;
4022 return SUCCESS;
4023 }
4024
4025 /* Less-generic immediate-value read function with the possibility of loading a
4026 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
4027 instructions. Puts the result directly in inst.operands[i]. */
4028
4029 static int
4030 parse_big_immediate (char **str, int i)
4031 {
4032 expressionS exp;
4033 char *ptr = *str;
4034
4035 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4036
4037 if (exp.X_op == O_constant)
4038 {
4039 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4040 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4041 O_constant. We have to be careful not to break compilation for
4042 32-bit X_add_number, though. */
4043 if ((exp.X_add_number & ~0xffffffffl) != 0)
4044 {
4045 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4046 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4047 inst.operands[i].regisimm = 1;
4048 }
4049 }
4050 else if (exp.X_op == O_big
4051 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4052 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4053 {
4054 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4055 /* Bignums have their least significant bits in
4056 generic_bignum[0]. Make sure we put 32 bits in imm and
4057 32 bits in reg, in a (hopefully) portable way. */
4058 assert (parts != 0);
4059 inst.operands[i].imm = 0;
4060 for (j = 0; j < parts; j++, idx++)
4061 inst.operands[i].imm |= generic_bignum[idx]
4062 << (LITTLENUM_NUMBER_OF_BITS * j);
4063 inst.operands[i].reg = 0;
4064 for (j = 0; j < parts; j++, idx++)
4065 inst.operands[i].reg |= generic_bignum[idx]
4066 << (LITTLENUM_NUMBER_OF_BITS * j);
4067 inst.operands[i].regisimm = 1;
4068 }
4069 else
4070 return FAIL;
4071
4072 *str = ptr;
4073
4074 return SUCCESS;
4075 }
4076
4077 /* Returns the pseudo-register number of an FPA immediate constant,
4078 or FAIL if there isn't a valid constant here. */
4079
4080 static int
4081 parse_fpa_immediate (char ** str)
4082 {
4083 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4084 char * save_in;
4085 expressionS exp;
4086 int i;
4087 int j;
4088
4089 /* First try and match exact strings, this is to guarantee
4090 that some formats will work even for cross assembly. */
4091
4092 for (i = 0; fp_const[i]; i++)
4093 {
4094 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4095 {
4096 char *start = *str;
4097
4098 *str += strlen (fp_const[i]);
4099 if (is_end_of_line[(unsigned char) **str])
4100 return i + 8;
4101 *str = start;
4102 }
4103 }
4104
4105 /* Just because we didn't get a match doesn't mean that the constant
4106 isn't valid, just that it is in a format that we don't
4107 automatically recognize. Try parsing it with the standard
4108 expression routines. */
4109
4110 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
4111
4112 /* Look for a raw floating point number. */
4113 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4114 && is_end_of_line[(unsigned char) *save_in])
4115 {
4116 for (i = 0; i < NUM_FLOAT_VALS; i++)
4117 {
4118 for (j = 0; j < MAX_LITTLENUMS; j++)
4119 {
4120 if (words[j] != fp_values[i][j])
4121 break;
4122 }
4123
4124 if (j == MAX_LITTLENUMS)
4125 {
4126 *str = save_in;
4127 return i + 8;
4128 }
4129 }
4130 }
4131
4132 /* Try and parse a more complex expression, this will probably fail
4133 unless the code uses a floating point prefix (eg "0f"). */
4134 save_in = input_line_pointer;
4135 input_line_pointer = *str;
4136 if (expression (&exp) == absolute_section
4137 && exp.X_op == O_big
4138 && exp.X_add_number < 0)
4139 {
4140 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4141 Ditto for 15. */
4142 if (gen_to_words (words, 5, (long) 15) == 0)
4143 {
4144 for (i = 0; i < NUM_FLOAT_VALS; i++)
4145 {
4146 for (j = 0; j < MAX_LITTLENUMS; j++)
4147 {
4148 if (words[j] != fp_values[i][j])
4149 break;
4150 }
4151
4152 if (j == MAX_LITTLENUMS)
4153 {
4154 *str = input_line_pointer;
4155 input_line_pointer = save_in;
4156 return i + 8;
4157 }
4158 }
4159 }
4160 }
4161
4162 *str = input_line_pointer;
4163 input_line_pointer = save_in;
4164 inst.error = _("invalid FPA immediate expression");
4165 return FAIL;
4166 }
4167
4168 /* Returns 1 if a number has "quarter-precision" float format
4169 0baBbbbbbc defgh000 00000000 00000000. */
4170
4171 static int
4172 is_quarter_float (unsigned imm)
4173 {
4174 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4175 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4176 }
4177
4178 /* Parse an 8-bit "quarter-precision" floating point number of the form:
4179 0baBbbbbbc defgh000 00000000 00000000.
4180 The minus-zero case needs special handling, since it can't be encoded in the
4181 "quarter-precision" float format, but can nonetheless be loaded as an integer
4182 constant. */
4183
4184 static unsigned
4185 parse_qfloat_immediate (char **ccp, int *immed)
4186 {
4187 char *str = *ccp;
4188 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4189
4190 skip_past_char (&str, '#');
4191
4192 if ((str = atof_ieee (str, 's', words)) != NULL)
4193 {
4194 unsigned fpword = 0;
4195 int i;
4196
4197 /* Our FP word must be 32 bits (single-precision FP). */
4198 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4199 {
4200 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4201 fpword |= words[i];
4202 }
4203
4204 if (is_quarter_float (fpword) || fpword == 0x80000000)
4205 *immed = fpword;
4206 else
4207 return FAIL;
4208
4209 *ccp = str;
4210
4211 return SUCCESS;
4212 }
4213
4214 return FAIL;
4215 }
4216
4217 /* Shift operands. */
4218 enum shift_kind
4219 {
4220 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4221 };
4222
4223 struct asm_shift_name
4224 {
4225 const char *name;
4226 enum shift_kind kind;
4227 };
4228
4229 /* Third argument to parse_shift. */
4230 enum parse_shift_mode
4231 {
4232 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4233 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4234 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4235 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4236 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4237 };
4238
4239 /* Parse a <shift> specifier on an ARM data processing instruction.
4240 This has three forms:
4241
4242 (LSL|LSR|ASL|ASR|ROR) Rs
4243 (LSL|LSR|ASL|ASR|ROR) #imm
4244 RRX
4245
4246 Note that ASL is assimilated to LSL in the instruction encoding, and
4247 RRX to ROR #0 (which cannot be written as such). */
4248
4249 static int
4250 parse_shift (char **str, int i, enum parse_shift_mode mode)
4251 {
4252 const struct asm_shift_name *shift_name;
4253 enum shift_kind shift;
4254 char *s = *str;
4255 char *p = s;
4256 int reg;
4257
4258 for (p = *str; ISALPHA (*p); p++)
4259 ;
4260
4261 if (p == *str)
4262 {
4263 inst.error = _("shift expression expected");
4264 return FAIL;
4265 }
4266
4267 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
4268
4269 if (shift_name == NULL)
4270 {
4271 inst.error = _("shift expression expected");
4272 return FAIL;
4273 }
4274
4275 shift = shift_name->kind;
4276
4277 switch (mode)
4278 {
4279 case NO_SHIFT_RESTRICT:
4280 case SHIFT_IMMEDIATE: break;
4281
4282 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4283 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4284 {
4285 inst.error = _("'LSL' or 'ASR' required");
4286 return FAIL;
4287 }
4288 break;
4289
4290 case SHIFT_LSL_IMMEDIATE:
4291 if (shift != SHIFT_LSL)
4292 {
4293 inst.error = _("'LSL' required");
4294 return FAIL;
4295 }
4296 break;
4297
4298 case SHIFT_ASR_IMMEDIATE:
4299 if (shift != SHIFT_ASR)
4300 {
4301 inst.error = _("'ASR' required");
4302 return FAIL;
4303 }
4304 break;
4305
4306 default: abort ();
4307 }
4308
4309 if (shift != SHIFT_RRX)
4310 {
4311 /* Whitespace can appear here if the next thing is a bare digit. */
4312 skip_whitespace (p);
4313
4314 if (mode == NO_SHIFT_RESTRICT
4315 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4316 {
4317 inst.operands[i].imm = reg;
4318 inst.operands[i].immisreg = 1;
4319 }
4320 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4321 return FAIL;
4322 }
4323 inst.operands[i].shift_kind = shift;
4324 inst.operands[i].shifted = 1;
4325 *str = p;
4326 return SUCCESS;
4327 }
4328
4329 /* Parse a <shifter_operand> for an ARM data processing instruction:
4330
4331 #<immediate>
4332 #<immediate>, <rotate>
4333 <Rm>
4334 <Rm>, <shift>
4335
4336 where <shift> is defined by parse_shift above, and <rotate> is a
4337 multiple of 2 between 0 and 30. Validation of immediate operands
4338 is deferred to md_apply_fix. */
4339
4340 static int
4341 parse_shifter_operand (char **str, int i)
4342 {
4343 int value;
4344 expressionS expr;
4345
4346 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
4347 {
4348 inst.operands[i].reg = value;
4349 inst.operands[i].isreg = 1;
4350
4351 /* parse_shift will override this if appropriate */
4352 inst.reloc.exp.X_op = O_constant;
4353 inst.reloc.exp.X_add_number = 0;
4354
4355 if (skip_past_comma (str) == FAIL)
4356 return SUCCESS;
4357
4358 /* Shift operation on register. */
4359 return parse_shift (str, i, NO_SHIFT_RESTRICT);
4360 }
4361
4362 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4363 return FAIL;
4364
4365 if (skip_past_comma (str) == SUCCESS)
4366 {
4367 /* #x, y -- ie explicit rotation by Y. */
4368 if (my_get_expression (&expr, str, GE_NO_PREFIX))
4369 return FAIL;
4370
4371 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4372 {
4373 inst.error = _("constant expression expected");
4374 return FAIL;
4375 }
4376
4377 value = expr.X_add_number;
4378 if (value < 0 || value > 30 || value % 2 != 0)
4379 {
4380 inst.error = _("invalid rotation");
4381 return FAIL;
4382 }
4383 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4384 {
4385 inst.error = _("invalid constant");
4386 return FAIL;
4387 }
4388
4389 /* Convert to decoded value. md_apply_fix will put it back. */
4390 inst.reloc.exp.X_add_number
4391 = (((inst.reloc.exp.X_add_number << (32 - value))
4392 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
4393 }
4394
4395 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4396 inst.reloc.pc_rel = 0;
4397 return SUCCESS;
4398 }
4399
4400 /* Group relocation information. Each entry in the table contains the
4401 textual name of the relocation as may appear in assembler source
4402 and must end with a colon.
4403 Along with this textual name are the relocation codes to be used if
4404 the corresponding instruction is an ALU instruction (ADD or SUB only),
4405 an LDR, an LDRS, or an LDC. */
4406
4407 struct group_reloc_table_entry
4408 {
4409 const char *name;
4410 int alu_code;
4411 int ldr_code;
4412 int ldrs_code;
4413 int ldc_code;
4414 };
4415
4416 typedef enum
4417 {
4418 /* Varieties of non-ALU group relocation. */
4419
4420 GROUP_LDR,
4421 GROUP_LDRS,
4422 GROUP_LDC
4423 } group_reloc_type;
4424
4425 static struct group_reloc_table_entry group_reloc_table[] =
4426 { /* Program counter relative: */
4427 { "pc_g0_nc",
4428 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4429 0, /* LDR */
4430 0, /* LDRS */
4431 0 }, /* LDC */
4432 { "pc_g0",
4433 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4434 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4435 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4436 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4437 { "pc_g1_nc",
4438 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4439 0, /* LDR */
4440 0, /* LDRS */
4441 0 }, /* LDC */
4442 { "pc_g1",
4443 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4444 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4445 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4446 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4447 { "pc_g2",
4448 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4449 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4450 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4451 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4452 /* Section base relative */
4453 { "sb_g0_nc",
4454 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4455 0, /* LDR */
4456 0, /* LDRS */
4457 0 }, /* LDC */
4458 { "sb_g0",
4459 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4460 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4461 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4462 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4463 { "sb_g1_nc",
4464 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4465 0, /* LDR */
4466 0, /* LDRS */
4467 0 }, /* LDC */
4468 { "sb_g1",
4469 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4470 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4471 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4472 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4473 { "sb_g2",
4474 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4475 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4476 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4477 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4478
4479 /* Given the address of a pointer pointing to the textual name of a group
4480 relocation as may appear in assembler source, attempt to find its details
4481 in group_reloc_table. The pointer will be updated to the character after
4482 the trailing colon. On failure, FAIL will be returned; SUCCESS
4483 otherwise. On success, *entry will be updated to point at the relevant
4484 group_reloc_table entry. */
4485
4486 static int
4487 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4488 {
4489 unsigned int i;
4490 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4491 {
4492 int length = strlen (group_reloc_table[i].name);
4493
4494 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0 &&
4495 (*str)[length] == ':')
4496 {
4497 *out = &group_reloc_table[i];
4498 *str += (length + 1);
4499 return SUCCESS;
4500 }
4501 }
4502
4503 return FAIL;
4504 }
4505
4506 /* Parse a <shifter_operand> for an ARM data processing instruction
4507 (as for parse_shifter_operand) where group relocations are allowed:
4508
4509 #<immediate>
4510 #<immediate>, <rotate>
4511 #:<group_reloc>:<expression>
4512 <Rm>
4513 <Rm>, <shift>
4514
4515 where <group_reloc> is one of the strings defined in group_reloc_table.
4516 The hashes are optional.
4517
4518 Everything else is as for parse_shifter_operand. */
4519
4520 static parse_operand_result
4521 parse_shifter_operand_group_reloc (char **str, int i)
4522 {
4523 /* Determine if we have the sequence of characters #: or just :
4524 coming next. If we do, then we check for a group relocation.
4525 If we don't, punt the whole lot to parse_shifter_operand. */
4526
4527 if (((*str)[0] == '#' && (*str)[1] == ':')
4528 || (*str)[0] == ':')
4529 {
4530 struct group_reloc_table_entry *entry;
4531
4532 if ((*str)[0] == '#')
4533 (*str) += 2;
4534 else
4535 (*str)++;
4536
4537 /* Try to parse a group relocation. Anything else is an error. */
4538 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4539 {
4540 inst.error = _("unknown group relocation");
4541 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4542 }
4543
4544 /* We now have the group relocation table entry corresponding to
4545 the name in the assembler source. Next, we parse the expression. */
4546 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4547 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4548
4549 /* Record the relocation type (always the ALU variant here). */
4550 inst.reloc.type = entry->alu_code;
4551 assert (inst.reloc.type != 0);
4552
4553 return PARSE_OPERAND_SUCCESS;
4554 }
4555 else
4556 return parse_shifter_operand (str, i) == SUCCESS
4557 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4558
4559 /* Never reached. */
4560 }
4561
4562 /* Parse all forms of an ARM address expression. Information is written
4563 to inst.operands[i] and/or inst.reloc.
4564
4565 Preindexed addressing (.preind=1):
4566
4567 [Rn, #offset] .reg=Rn .reloc.exp=offset
4568 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4569 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4570 .shift_kind=shift .reloc.exp=shift_imm
4571
4572 These three may have a trailing ! which causes .writeback to be set also.
4573
4574 Postindexed addressing (.postind=1, .writeback=1):
4575
4576 [Rn], #offset .reg=Rn .reloc.exp=offset
4577 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4578 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4579 .shift_kind=shift .reloc.exp=shift_imm
4580
4581 Unindexed addressing (.preind=0, .postind=0):
4582
4583 [Rn], {option} .reg=Rn .imm=option .immisreg=0
4584
4585 Other:
4586
4587 [Rn]{!} shorthand for [Rn,#0]{!}
4588 =immediate .isreg=0 .reloc.exp=immediate
4589 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
4590
4591 It is the caller's responsibility to check for addressing modes not
4592 supported by the instruction, and to set inst.reloc.type. */
4593
4594 static parse_operand_result
4595 parse_address_main (char **str, int i, int group_relocations,
4596 group_reloc_type group_type)
4597 {
4598 char *p = *str;
4599 int reg;
4600
4601 if (skip_past_char (&p, '[') == FAIL)
4602 {
4603 if (skip_past_char (&p, '=') == FAIL)
4604 {
4605 /* bare address - translate to PC-relative offset */
4606 inst.reloc.pc_rel = 1;
4607 inst.operands[i].reg = REG_PC;
4608 inst.operands[i].isreg = 1;
4609 inst.operands[i].preind = 1;
4610 }
4611 /* else a load-constant pseudo op, no special treatment needed here */
4612
4613 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4614 return PARSE_OPERAND_FAIL;
4615
4616 *str = p;
4617 return PARSE_OPERAND_SUCCESS;
4618 }
4619
4620 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
4621 {
4622 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4623 return PARSE_OPERAND_FAIL;
4624 }
4625 inst.operands[i].reg = reg;
4626 inst.operands[i].isreg = 1;
4627
4628 if (skip_past_comma (&p) == SUCCESS)
4629 {
4630 inst.operands[i].preind = 1;
4631
4632 if (*p == '+') p++;
4633 else if (*p == '-') p++, inst.operands[i].negative = 1;
4634
4635 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4636 {
4637 inst.operands[i].imm = reg;
4638 inst.operands[i].immisreg = 1;
4639
4640 if (skip_past_comma (&p) == SUCCESS)
4641 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4642 return PARSE_OPERAND_FAIL;
4643 }
4644 else if (skip_past_char (&p, ':') == SUCCESS)
4645 {
4646 /* FIXME: '@' should be used here, but it's filtered out by generic
4647 code before we get to see it here. This may be subject to
4648 change. */
4649 expressionS exp;
4650 my_get_expression (&exp, &p, GE_NO_PREFIX);
4651 if (exp.X_op != O_constant)
4652 {
4653 inst.error = _("alignment must be constant");
4654 return PARSE_OPERAND_FAIL;
4655 }
4656 inst.operands[i].imm = exp.X_add_number << 8;
4657 inst.operands[i].immisalign = 1;
4658 /* Alignments are not pre-indexes. */
4659 inst.operands[i].preind = 0;
4660 }
4661 else
4662 {
4663 if (inst.operands[i].negative)
4664 {
4665 inst.operands[i].negative = 0;
4666 p--;
4667 }
4668
4669 if (group_relocations &&
4670 ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4671
4672 {
4673 struct group_reloc_table_entry *entry;
4674
4675 /* Skip over the #: or : sequence. */
4676 if (*p == '#')
4677 p += 2;
4678 else
4679 p++;
4680
4681 /* Try to parse a group relocation. Anything else is an
4682 error. */
4683 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
4684 {
4685 inst.error = _("unknown group relocation");
4686 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4687 }
4688
4689 /* We now have the group relocation table entry corresponding to
4690 the name in the assembler source. Next, we parse the
4691 expression. */
4692 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4693 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4694
4695 /* Record the relocation type. */
4696 switch (group_type)
4697 {
4698 case GROUP_LDR:
4699 inst.reloc.type = entry->ldr_code;
4700 break;
4701
4702 case GROUP_LDRS:
4703 inst.reloc.type = entry->ldrs_code;
4704 break;
4705
4706 case GROUP_LDC:
4707 inst.reloc.type = entry->ldc_code;
4708 break;
4709
4710 default:
4711 assert (0);
4712 }
4713
4714 if (inst.reloc.type == 0)
4715 {
4716 inst.error = _("this group relocation is not allowed on this instruction");
4717 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4718 }
4719 }
4720 else
4721 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4722 return PARSE_OPERAND_FAIL;
4723 }
4724 }
4725
4726 if (skip_past_char (&p, ']') == FAIL)
4727 {
4728 inst.error = _("']' expected");
4729 return PARSE_OPERAND_FAIL;
4730 }
4731
4732 if (skip_past_char (&p, '!') == SUCCESS)
4733 inst.operands[i].writeback = 1;
4734
4735 else if (skip_past_comma (&p) == SUCCESS)
4736 {
4737 if (skip_past_char (&p, '{') == SUCCESS)
4738 {
4739 /* [Rn], {expr} - unindexed, with option */
4740 if (parse_immediate (&p, &inst.operands[i].imm,
4741 0, 255, TRUE) == FAIL)
4742 return PARSE_OPERAND_FAIL;
4743
4744 if (skip_past_char (&p, '}') == FAIL)
4745 {
4746 inst.error = _("'}' expected at end of 'option' field");
4747 return PARSE_OPERAND_FAIL;
4748 }
4749 if (inst.operands[i].preind)
4750 {
4751 inst.error = _("cannot combine index with option");
4752 return PARSE_OPERAND_FAIL;
4753 }
4754 *str = p;
4755 return PARSE_OPERAND_SUCCESS;
4756 }
4757 else
4758 {
4759 inst.operands[i].postind = 1;
4760 inst.operands[i].writeback = 1;
4761
4762 if (inst.operands[i].preind)
4763 {
4764 inst.error = _("cannot combine pre- and post-indexing");
4765 return PARSE_OPERAND_FAIL;
4766 }
4767
4768 if (*p == '+') p++;
4769 else if (*p == '-') p++, inst.operands[i].negative = 1;
4770
4771 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4772 {
4773 /* We might be using the immediate for alignment already. If we
4774 are, OR the register number into the low-order bits. */
4775 if (inst.operands[i].immisalign)
4776 inst.operands[i].imm |= reg;
4777 else
4778 inst.operands[i].imm = reg;
4779 inst.operands[i].immisreg = 1;
4780
4781 if (skip_past_comma (&p) == SUCCESS)
4782 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4783 return PARSE_OPERAND_FAIL;
4784 }
4785 else
4786 {
4787 if (inst.operands[i].negative)
4788 {
4789 inst.operands[i].negative = 0;
4790 p--;
4791 }
4792 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4793 return PARSE_OPERAND_FAIL;
4794 }
4795 }
4796 }
4797
4798 /* If at this point neither .preind nor .postind is set, we have a
4799 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
4800 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
4801 {
4802 inst.operands[i].preind = 1;
4803 inst.reloc.exp.X_op = O_constant;
4804 inst.reloc.exp.X_add_number = 0;
4805 }
4806 *str = p;
4807 return PARSE_OPERAND_SUCCESS;
4808 }
4809
4810 static int
4811 parse_address (char **str, int i)
4812 {
4813 return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS
4814 ? SUCCESS : FAIL;
4815 }
4816
4817 static parse_operand_result
4818 parse_address_group_reloc (char **str, int i, group_reloc_type type)
4819 {
4820 return parse_address_main (str, i, 1, type);
4821 }
4822
4823 /* Parse an operand for a MOVW or MOVT instruction. */
4824 static int
4825 parse_half (char **str)
4826 {
4827 char * p;
4828
4829 p = *str;
4830 skip_past_char (&p, '#');
4831 if (strncasecmp (p, ":lower16:", 9) == 0)
4832 inst.reloc.type = BFD_RELOC_ARM_MOVW;
4833 else if (strncasecmp (p, ":upper16:", 9) == 0)
4834 inst.reloc.type = BFD_RELOC_ARM_MOVT;
4835
4836 if (inst.reloc.type != BFD_RELOC_UNUSED)
4837 {
4838 p += 9;
4839 skip_whitespace(p);
4840 }
4841
4842 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4843 return FAIL;
4844
4845 if (inst.reloc.type == BFD_RELOC_UNUSED)
4846 {
4847 if (inst.reloc.exp.X_op != O_constant)
4848 {
4849 inst.error = _("constant expression expected");
4850 return FAIL;
4851 }
4852 if (inst.reloc.exp.X_add_number < 0
4853 || inst.reloc.exp.X_add_number > 0xffff)
4854 {
4855 inst.error = _("immediate value out of range");
4856 return FAIL;
4857 }
4858 }
4859 *str = p;
4860 return SUCCESS;
4861 }
4862
4863 /* Miscellaneous. */
4864
4865 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
4866 or a bitmask suitable to be or-ed into the ARM msr instruction. */
4867 static int
4868 parse_psr (char **str)
4869 {
4870 char *p;
4871 unsigned long psr_field;
4872 const struct asm_psr *psr;
4873 char *start;
4874
4875 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
4876 feature for ease of use and backwards compatibility. */
4877 p = *str;
4878 if (strncasecmp (p, "SPSR", 4) == 0)
4879 psr_field = SPSR_BIT;
4880 else if (strncasecmp (p, "CPSR", 4) == 0)
4881 psr_field = 0;
4882 else
4883 {
4884 start = p;
4885 do
4886 p++;
4887 while (ISALNUM (*p) || *p == '_');
4888
4889 psr = hash_find_n (arm_v7m_psr_hsh, start, p - start);
4890 if (!psr)
4891 return FAIL;
4892
4893 *str = p;
4894 return psr->field;
4895 }
4896
4897 p += 4;
4898 if (*p == '_')
4899 {
4900 /* A suffix follows. */
4901 p++;
4902 start = p;
4903
4904 do
4905 p++;
4906 while (ISALNUM (*p) || *p == '_');
4907
4908 psr = hash_find_n (arm_psr_hsh, start, p - start);
4909 if (!psr)
4910 goto error;
4911
4912 psr_field |= psr->field;
4913 }
4914 else
4915 {
4916 if (ISALNUM (*p))
4917 goto error; /* Garbage after "[CS]PSR". */
4918
4919 psr_field |= (PSR_c | PSR_f);
4920 }
4921 *str = p;
4922 return psr_field;
4923
4924 error:
4925 inst.error = _("flag for {c}psr instruction expected");
4926 return FAIL;
4927 }
4928
4929 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
4930 value suitable for splatting into the AIF field of the instruction. */
4931
4932 static int
4933 parse_cps_flags (char **str)
4934 {
4935 int val = 0;
4936 int saw_a_flag = 0;
4937 char *s = *str;
4938
4939 for (;;)
4940 switch (*s++)
4941 {
4942 case '\0': case ',':
4943 goto done;
4944
4945 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
4946 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
4947 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
4948
4949 default:
4950 inst.error = _("unrecognized CPS flag");
4951 return FAIL;
4952 }
4953
4954 done:
4955 if (saw_a_flag == 0)
4956 {
4957 inst.error = _("missing CPS flags");
4958 return FAIL;
4959 }
4960
4961 *str = s - 1;
4962 return val;
4963 }
4964
4965 /* Parse an endian specifier ("BE" or "LE", case insensitive);
4966 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
4967
4968 static int
4969 parse_endian_specifier (char **str)
4970 {
4971 int little_endian;
4972 char *s = *str;
4973
4974 if (strncasecmp (s, "BE", 2))
4975 little_endian = 0;
4976 else if (strncasecmp (s, "LE", 2))
4977 little_endian = 1;
4978 else
4979 {
4980 inst.error = _("valid endian specifiers are be or le");
4981 return FAIL;
4982 }
4983
4984 if (ISALNUM (s[2]) || s[2] == '_')
4985 {
4986 inst.error = _("valid endian specifiers are be or le");
4987 return FAIL;
4988 }
4989
4990 *str = s + 2;
4991 return little_endian;
4992 }
4993
4994 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
4995 value suitable for poking into the rotate field of an sxt or sxta
4996 instruction, or FAIL on error. */
4997
4998 static int
4999 parse_ror (char **str)
5000 {
5001 int rot;
5002 char *s = *str;
5003
5004 if (strncasecmp (s, "ROR", 3) == 0)
5005 s += 3;
5006 else
5007 {
5008 inst.error = _("missing rotation field after comma");
5009 return FAIL;
5010 }
5011
5012 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5013 return FAIL;
5014
5015 switch (rot)
5016 {
5017 case 0: *str = s; return 0x0;
5018 case 8: *str = s; return 0x1;
5019 case 16: *str = s; return 0x2;
5020 case 24: *str = s; return 0x3;
5021
5022 default:
5023 inst.error = _("rotation can only be 0, 8, 16, or 24");
5024 return FAIL;
5025 }
5026 }
5027
5028 /* Parse a conditional code (from conds[] below). The value returned is in the
5029 range 0 .. 14, or FAIL. */
5030 static int
5031 parse_cond (char **str)
5032 {
5033 char *p, *q;
5034 const struct asm_cond *c;
5035
5036 p = q = *str;
5037 while (ISALPHA (*q))
5038 q++;
5039
5040 c = hash_find_n (arm_cond_hsh, p, q - p);
5041 if (!c)
5042 {
5043 inst.error = _("condition required");
5044 return FAIL;
5045 }
5046
5047 *str = q;
5048 return c->value;
5049 }
5050
5051 /* Parse an option for a barrier instruction. Returns the encoding for the
5052 option, or FAIL. */
5053 static int
5054 parse_barrier (char **str)
5055 {
5056 char *p, *q;
5057 const struct asm_barrier_opt *o;
5058
5059 p = q = *str;
5060 while (ISALPHA (*q))
5061 q++;
5062
5063 o = hash_find_n (arm_barrier_opt_hsh, p, q - p);
5064 if (!o)
5065 return FAIL;
5066
5067 *str = q;
5068 return o->value;
5069 }
5070
5071 /* Parse the operands of a table branch instruction. Similar to a memory
5072 operand. */
5073 static int
5074 parse_tb (char **str)
5075 {
5076 char * p = *str;
5077 int reg;
5078
5079 if (skip_past_char (&p, '[') == FAIL)
5080 {
5081 inst.error = _("'[' expected");
5082 return FAIL;
5083 }
5084
5085 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5086 {
5087 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5088 return FAIL;
5089 }
5090 inst.operands[0].reg = reg;
5091
5092 if (skip_past_comma (&p) == FAIL)
5093 {
5094 inst.error = _("',' expected");
5095 return FAIL;
5096 }
5097
5098 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5099 {
5100 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5101 return FAIL;
5102 }
5103 inst.operands[0].imm = reg;
5104
5105 if (skip_past_comma (&p) == SUCCESS)
5106 {
5107 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5108 return FAIL;
5109 if (inst.reloc.exp.X_add_number != 1)
5110 {
5111 inst.error = _("invalid shift");
5112 return FAIL;
5113 }
5114 inst.operands[0].shifted = 1;
5115 }
5116
5117 if (skip_past_char (&p, ']') == FAIL)
5118 {
5119 inst.error = _("']' expected");
5120 return FAIL;
5121 }
5122 *str = p;
5123 return SUCCESS;
5124 }
5125
5126 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5127 information on the types the operands can take and how they are encoded.
5128 Up to four operands may be read; this function handles setting the
5129 ".present" field for each read operand itself.
5130 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5131 else returns FAIL. */
5132
5133 static int
5134 parse_neon_mov (char **str, int *which_operand)
5135 {
5136 int i = *which_operand, val;
5137 enum arm_reg_type rtype;
5138 char *ptr = *str;
5139 struct neon_type_el optype;
5140
5141 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5142 {
5143 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5144 inst.operands[i].reg = val;
5145 inst.operands[i].isscalar = 1;
5146 inst.operands[i].vectype = optype;
5147 inst.operands[i++].present = 1;
5148
5149 if (skip_past_comma (&ptr) == FAIL)
5150 goto wanted_comma;
5151
5152 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5153 goto wanted_arm;
5154
5155 inst.operands[i].reg = val;
5156 inst.operands[i].isreg = 1;
5157 inst.operands[i].present = 1;
5158 }
5159 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
5160 != FAIL)
5161 {
5162 /* Cases 0, 1, 2, 3, 5 (D only). */
5163 if (skip_past_comma (&ptr) == FAIL)
5164 goto wanted_comma;
5165
5166 inst.operands[i].reg = val;
5167 inst.operands[i].isreg = 1;
5168 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5169 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5170 inst.operands[i].isvec = 1;
5171 inst.operands[i].vectype = optype;
5172 inst.operands[i++].present = 1;
5173
5174 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5175 {
5176 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5177 Case 13: VMOV <Sd>, <Rm> */
5178 inst.operands[i].reg = val;
5179 inst.operands[i].isreg = 1;
5180 inst.operands[i].present = 1;
5181
5182 if (rtype == REG_TYPE_NQ)
5183 {
5184 first_error (_("can't use Neon quad register here"));
5185 return FAIL;
5186 }
5187 else if (rtype != REG_TYPE_VFS)
5188 {
5189 i++;
5190 if (skip_past_comma (&ptr) == FAIL)
5191 goto wanted_comma;
5192 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5193 goto wanted_arm;
5194 inst.operands[i].reg = val;
5195 inst.operands[i].isreg = 1;
5196 inst.operands[i].present = 1;
5197 }
5198 }
5199 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5200 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5201 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5202 Case 10: VMOV.F32 <Sd>, #<imm>
5203 Case 11: VMOV.F64 <Dd>, #<imm> */
5204 ;
5205 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5206 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5207 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5208 ;
5209 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5210 &optype)) != FAIL)
5211 {
5212 /* Case 0: VMOV<c><q> <Qd>, <Qm>
5213 Case 1: VMOV<c><q> <Dd>, <Dm>
5214 Case 8: VMOV.F32 <Sd>, <Sm>
5215 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5216
5217 inst.operands[i].reg = val;
5218 inst.operands[i].isreg = 1;
5219 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5220 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5221 inst.operands[i].isvec = 1;
5222 inst.operands[i].vectype = optype;
5223 inst.operands[i].present = 1;
5224
5225 if (skip_past_comma (&ptr) == SUCCESS)
5226 {
5227 /* Case 15. */
5228 i++;
5229
5230 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5231 goto wanted_arm;
5232
5233 inst.operands[i].reg = val;
5234 inst.operands[i].isreg = 1;
5235 inst.operands[i++].present = 1;
5236
5237 if (skip_past_comma (&ptr) == FAIL)
5238 goto wanted_comma;
5239
5240 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5241 goto wanted_arm;
5242
5243 inst.operands[i].reg = val;
5244 inst.operands[i].isreg = 1;
5245 inst.operands[i++].present = 1;
5246 }
5247 }
5248 else
5249 {
5250 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5251 return FAIL;
5252 }
5253 }
5254 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5255 {
5256 /* Cases 6, 7. */
5257 inst.operands[i].reg = val;
5258 inst.operands[i].isreg = 1;
5259 inst.operands[i++].present = 1;
5260
5261 if (skip_past_comma (&ptr) == FAIL)
5262 goto wanted_comma;
5263
5264 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5265 {
5266 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5267 inst.operands[i].reg = val;
5268 inst.operands[i].isscalar = 1;
5269 inst.operands[i].present = 1;
5270 inst.operands[i].vectype = optype;
5271 }
5272 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5273 {
5274 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5275 inst.operands[i].reg = val;
5276 inst.operands[i].isreg = 1;
5277 inst.operands[i++].present = 1;
5278
5279 if (skip_past_comma (&ptr) == FAIL)
5280 goto wanted_comma;
5281
5282 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
5283 == FAIL)
5284 {
5285 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5286 return FAIL;
5287 }
5288
5289 inst.operands[i].reg = val;
5290 inst.operands[i].isreg = 1;
5291 inst.operands[i].isvec = 1;
5292 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5293 inst.operands[i].vectype = optype;
5294 inst.operands[i].present = 1;
5295
5296 if (rtype == REG_TYPE_VFS)
5297 {
5298 /* Case 14. */
5299 i++;
5300 if (skip_past_comma (&ptr) == FAIL)
5301 goto wanted_comma;
5302 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5303 &optype)) == FAIL)
5304 {
5305 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5306 return FAIL;
5307 }
5308 inst.operands[i].reg = val;
5309 inst.operands[i].isreg = 1;
5310 inst.operands[i].isvec = 1;
5311 inst.operands[i].issingle = 1;
5312 inst.operands[i].vectype = optype;
5313 inst.operands[i].present = 1;
5314 }
5315 }
5316 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5317 != FAIL)
5318 {
5319 /* Case 13. */
5320 inst.operands[i].reg = val;
5321 inst.operands[i].isreg = 1;
5322 inst.operands[i].isvec = 1;
5323 inst.operands[i].issingle = 1;
5324 inst.operands[i].vectype = optype;
5325 inst.operands[i++].present = 1;
5326 }
5327 }
5328 else
5329 {
5330 first_error (_("parse error"));
5331 return FAIL;
5332 }
5333
5334 /* Successfully parsed the operands. Update args. */
5335 *which_operand = i;
5336 *str = ptr;
5337 return SUCCESS;
5338
5339 wanted_comma:
5340 first_error (_("expected comma"));
5341 return FAIL;
5342
5343 wanted_arm:
5344 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5345 return FAIL;
5346 }
5347
5348 /* Matcher codes for parse_operands. */
5349 enum operand_parse_code
5350 {
5351 OP_stop, /* end of line */
5352
5353 OP_RR, /* ARM register */
5354 OP_RRnpc, /* ARM register, not r15 */
5355 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5356 OP_RRw, /* ARM register, not r15, optional trailing ! */
5357 OP_RCP, /* Coprocessor number */
5358 OP_RCN, /* Coprocessor register */
5359 OP_RF, /* FPA register */
5360 OP_RVS, /* VFP single precision register */
5361 OP_RVD, /* VFP double precision register (0..15) */
5362 OP_RND, /* Neon double precision register (0..31) */
5363 OP_RNQ, /* Neon quad precision register */
5364 OP_RVSD, /* VFP single or double precision register */
5365 OP_RNDQ, /* Neon double or quad precision register */
5366 OP_RNSDQ, /* Neon single, double or quad precision register */
5367 OP_RNSC, /* Neon scalar D[X] */
5368 OP_RVC, /* VFP control register */
5369 OP_RMF, /* Maverick F register */
5370 OP_RMD, /* Maverick D register */
5371 OP_RMFX, /* Maverick FX register */
5372 OP_RMDX, /* Maverick DX register */
5373 OP_RMAX, /* Maverick AX register */
5374 OP_RMDS, /* Maverick DSPSC register */
5375 OP_RIWR, /* iWMMXt wR register */
5376 OP_RIWC, /* iWMMXt wC register */
5377 OP_RIWG, /* iWMMXt wCG register */
5378 OP_RXA, /* XScale accumulator register */
5379
5380 OP_REGLST, /* ARM register list */
5381 OP_VRSLST, /* VFP single-precision register list */
5382 OP_VRDLST, /* VFP double-precision register list */
5383 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5384 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5385 OP_NSTRLST, /* Neon element/structure list */
5386
5387 OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */
5388 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
5389 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5390 OP_RR_RNSC, /* ARM reg or Neon scalar. */
5391 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5392 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5393 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5394 OP_VMOV, /* Neon VMOV operands. */
5395 OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */
5396 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
5397 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5398
5399 OP_I0, /* immediate zero */
5400 OP_I7, /* immediate value 0 .. 7 */
5401 OP_I15, /* 0 .. 15 */
5402 OP_I16, /* 1 .. 16 */
5403 OP_I16z, /* 0 .. 16 */
5404 OP_I31, /* 0 .. 31 */
5405 OP_I31w, /* 0 .. 31, optional trailing ! */
5406 OP_I32, /* 1 .. 32 */
5407 OP_I32z, /* 0 .. 32 */
5408 OP_I63, /* 0 .. 63 */
5409 OP_I63s, /* -64 .. 63 */
5410 OP_I64, /* 1 .. 64 */
5411 OP_I64z, /* 0 .. 64 */
5412 OP_I255, /* 0 .. 255 */
5413
5414 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5415 OP_I7b, /* 0 .. 7 */
5416 OP_I15b, /* 0 .. 15 */
5417 OP_I31b, /* 0 .. 31 */
5418
5419 OP_SH, /* shifter operand */
5420 OP_SHG, /* shifter operand with possible group relocation */
5421 OP_ADDR, /* Memory address expression (any mode) */
5422 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5423 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5424 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
5425 OP_EXP, /* arbitrary expression */
5426 OP_EXPi, /* same, with optional immediate prefix */
5427 OP_EXPr, /* same, with optional relocation suffix */
5428 OP_HALF, /* 0 .. 65535 or low/high reloc. */
5429
5430 OP_CPSF, /* CPS flags */
5431 OP_ENDI, /* Endianness specifier */
5432 OP_PSR, /* CPSR/SPSR mask for msr */
5433 OP_COND, /* conditional code */
5434 OP_TB, /* Table branch. */
5435
5436 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5437 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5438
5439 OP_RRnpc_I0, /* ARM register or literal 0 */
5440 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5441 OP_RR_EXi, /* ARM register or expression with imm prefix */
5442 OP_RF_IF, /* FPA register or immediate */
5443 OP_RIWR_RIWC, /* iWMMXt R or C reg */
5444 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
5445
5446 /* Optional operands. */
5447 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5448 OP_oI31b, /* 0 .. 31 */
5449 OP_oI32b, /* 1 .. 32 */
5450 OP_oIffffb, /* 0 .. 65535 */
5451 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5452
5453 OP_oRR, /* ARM register */
5454 OP_oRRnpc, /* ARM register, not the PC */
5455 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5456 OP_oRND, /* Optional Neon double precision register */
5457 OP_oRNQ, /* Optional Neon quad precision register */
5458 OP_oRNDQ, /* Optional Neon double or quad precision register */
5459 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
5460 OP_oSHll, /* LSL immediate */
5461 OP_oSHar, /* ASR immediate */
5462 OP_oSHllar, /* LSL or ASR immediate */
5463 OP_oROR, /* ROR 0/8/16/24 */
5464 OP_oBARRIER, /* Option argument for a barrier instruction. */
5465
5466 OP_FIRST_OPTIONAL = OP_oI7b
5467 };
5468
5469 /* Generic instruction operand parser. This does no encoding and no
5470 semantic validation; it merely squirrels values away in the inst
5471 structure. Returns SUCCESS or FAIL depending on whether the
5472 specified grammar matched. */
5473 static int
5474 parse_operands (char *str, const unsigned char *pattern)
5475 {
5476 unsigned const char *upat = pattern;
5477 char *backtrack_pos = 0;
5478 const char *backtrack_error = 0;
5479 int i, val, backtrack_index = 0;
5480 enum arm_reg_type rtype;
5481 parse_operand_result result;
5482
5483 #define po_char_or_fail(chr) do { \
5484 if (skip_past_char (&str, chr) == FAIL) \
5485 goto bad_args; \
5486 } while (0)
5487
5488 #define po_reg_or_fail(regtype) do { \
5489 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5490 &inst.operands[i].vectype); \
5491 if (val == FAIL) \
5492 { \
5493 first_error (_(reg_expected_msgs[regtype])); \
5494 goto failure; \
5495 } \
5496 inst.operands[i].reg = val; \
5497 inst.operands[i].isreg = 1; \
5498 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5499 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5500 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5501 || rtype == REG_TYPE_VFD \
5502 || rtype == REG_TYPE_NQ); \
5503 } while (0)
5504
5505 #define po_reg_or_goto(regtype, label) do { \
5506 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5507 &inst.operands[i].vectype); \
5508 if (val == FAIL) \
5509 goto label; \
5510 \
5511 inst.operands[i].reg = val; \
5512 inst.operands[i].isreg = 1; \
5513 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5514 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5515 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5516 || rtype == REG_TYPE_VFD \
5517 || rtype == REG_TYPE_NQ); \
5518 } while (0)
5519
5520 #define po_imm_or_fail(min, max, popt) do { \
5521 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5522 goto failure; \
5523 inst.operands[i].imm = val; \
5524 } while (0)
5525
5526 #define po_scalar_or_goto(elsz, label) do { \
5527 val = parse_scalar (&str, elsz, &inst.operands[i].vectype); \
5528 if (val == FAIL) \
5529 goto label; \
5530 inst.operands[i].reg = val; \
5531 inst.operands[i].isscalar = 1; \
5532 } while (0)
5533
5534 #define po_misc_or_fail(expr) do { \
5535 if (expr) \
5536 goto failure; \
5537 } while (0)
5538
5539 #define po_misc_or_fail_no_backtrack(expr) do { \
5540 result = expr; \
5541 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK)\
5542 backtrack_pos = 0; \
5543 if (result != PARSE_OPERAND_SUCCESS) \
5544 goto failure; \
5545 } while (0)
5546
5547 skip_whitespace (str);
5548
5549 for (i = 0; upat[i] != OP_stop; i++)
5550 {
5551 if (upat[i] >= OP_FIRST_OPTIONAL)
5552 {
5553 /* Remember where we are in case we need to backtrack. */
5554 assert (!backtrack_pos);
5555 backtrack_pos = str;
5556 backtrack_error = inst.error;
5557 backtrack_index = i;
5558 }
5559
5560 if (i > 0 && (i > 1 || inst.operands[0].present))
5561 po_char_or_fail (',');
5562
5563 switch (upat[i])
5564 {
5565 /* Registers */
5566 case OP_oRRnpc:
5567 case OP_RRnpc:
5568 case OP_oRR:
5569 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5570 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5571 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
5572 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
5573 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
5574 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5575 case OP_oRND:
5576 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
5577 case OP_RVC: po_reg_or_fail (REG_TYPE_VFC); break;
5578 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
5579 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
5580 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
5581 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
5582 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
5583 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
5584 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
5585 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
5586 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
5587 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5588 case OP_oRNQ:
5589 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
5590 case OP_oRNDQ:
5591 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
5592 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
5593 case OP_oRNSDQ:
5594 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5595
5596 /* Neon scalar. Using an element size of 8 means that some invalid
5597 scalars are accepted here, so deal with those in later code. */
5598 case OP_RNSC: po_scalar_or_goto (8, failure); break;
5599
5600 /* WARNING: We can expand to two operands here. This has the potential
5601 to totally confuse the backtracking mechanism! It will be OK at
5602 least as long as we don't try to use optional args as well,
5603 though. */
5604 case OP_NILO:
5605 {
5606 po_reg_or_goto (REG_TYPE_NDQ, try_imm);
5607 inst.operands[i].present = 1;
5608 i++;
5609 skip_past_comma (&str);
5610 po_reg_or_goto (REG_TYPE_NDQ, one_reg_only);
5611 break;
5612 one_reg_only:
5613 /* Optional register operand was omitted. Unfortunately, it's in
5614 operands[i-1] and we need it to be in inst.operands[i]. Fix that
5615 here (this is a bit grotty). */
5616 inst.operands[i] = inst.operands[i-1];
5617 inst.operands[i-1].present = 0;
5618 break;
5619 try_imm:
5620 /* There's a possibility of getting a 64-bit immediate here, so
5621 we need special handling. */
5622 if (parse_big_immediate (&str, i) == FAIL)
5623 {
5624 inst.error = _("immediate value is out of range");
5625 goto failure;
5626 }
5627 }
5628 break;
5629
5630 case OP_RNDQ_I0:
5631 {
5632 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
5633 break;
5634 try_imm0:
5635 po_imm_or_fail (0, 0, TRUE);
5636 }
5637 break;
5638
5639 case OP_RVSD_I0:
5640 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
5641 break;
5642
5643 case OP_RR_RNSC:
5644 {
5645 po_scalar_or_goto (8, try_rr);
5646 break;
5647 try_rr:
5648 po_reg_or_fail (REG_TYPE_RN);
5649 }
5650 break;
5651
5652 case OP_RNSDQ_RNSC:
5653 {
5654 po_scalar_or_goto (8, try_nsdq);
5655 break;
5656 try_nsdq:
5657 po_reg_or_fail (REG_TYPE_NSDQ);
5658 }
5659 break;
5660
5661 case OP_RNDQ_RNSC:
5662 {
5663 po_scalar_or_goto (8, try_ndq);
5664 break;
5665 try_ndq:
5666 po_reg_or_fail (REG_TYPE_NDQ);
5667 }
5668 break;
5669
5670 case OP_RND_RNSC:
5671 {
5672 po_scalar_or_goto (8, try_vfd);
5673 break;
5674 try_vfd:
5675 po_reg_or_fail (REG_TYPE_VFD);
5676 }
5677 break;
5678
5679 case OP_VMOV:
5680 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
5681 not careful then bad things might happen. */
5682 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
5683 break;
5684
5685 case OP_RNDQ_IMVNb:
5686 {
5687 po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm);
5688 break;
5689 try_mvnimm:
5690 /* There's a possibility of getting a 64-bit immediate here, so
5691 we need special handling. */
5692 if (parse_big_immediate (&str, i) == FAIL)
5693 {
5694 inst.error = _("immediate value is out of range");
5695 goto failure;
5696 }
5697 }
5698 break;
5699
5700 case OP_RNDQ_I63b:
5701 {
5702 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
5703 break;
5704 try_shimm:
5705 po_imm_or_fail (0, 63, TRUE);
5706 }
5707 break;
5708
5709 case OP_RRnpcb:
5710 po_char_or_fail ('[');
5711 po_reg_or_fail (REG_TYPE_RN);
5712 po_char_or_fail (']');
5713 break;
5714
5715 case OP_RRw:
5716 case OP_oRRw:
5717 po_reg_or_fail (REG_TYPE_RN);
5718 if (skip_past_char (&str, '!') == SUCCESS)
5719 inst.operands[i].writeback = 1;
5720 break;
5721
5722 /* Immediates */
5723 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
5724 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
5725 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5726 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
5727 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
5728 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5729 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
5730 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5731 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
5732 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
5733 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
5734 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
5735
5736 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
5737 case OP_oI7b:
5738 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
5739 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
5740 case OP_oI31b:
5741 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5742 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
5743 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
5744
5745 /* Immediate variants */
5746 case OP_oI255c:
5747 po_char_or_fail ('{');
5748 po_imm_or_fail (0, 255, TRUE);
5749 po_char_or_fail ('}');
5750 break;
5751
5752 case OP_I31w:
5753 /* The expression parser chokes on a trailing !, so we have
5754 to find it first and zap it. */
5755 {
5756 char *s = str;
5757 while (*s && *s != ',')
5758 s++;
5759 if (s[-1] == '!')
5760 {
5761 s[-1] = '\0';
5762 inst.operands[i].writeback = 1;
5763 }
5764 po_imm_or_fail (0, 31, TRUE);
5765 if (str == s - 1)
5766 str = s;
5767 }
5768 break;
5769
5770 /* Expressions */
5771 case OP_EXPi: EXPi:
5772 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5773 GE_OPT_PREFIX));
5774 break;
5775
5776 case OP_EXP:
5777 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5778 GE_NO_PREFIX));
5779 break;
5780
5781 case OP_EXPr: EXPr:
5782 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5783 GE_NO_PREFIX));
5784 if (inst.reloc.exp.X_op == O_symbol)
5785 {
5786 val = parse_reloc (&str);
5787 if (val == -1)
5788 {
5789 inst.error = _("unrecognized relocation suffix");
5790 goto failure;
5791 }
5792 else if (val != BFD_RELOC_UNUSED)
5793 {
5794 inst.operands[i].imm = val;
5795 inst.operands[i].hasreloc = 1;
5796 }
5797 }
5798 break;
5799
5800 /* Operand for MOVW or MOVT. */
5801 case OP_HALF:
5802 po_misc_or_fail (parse_half (&str));
5803 break;
5804
5805 /* Register or expression */
5806 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
5807 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
5808
5809 /* Register or immediate */
5810 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
5811 I0: po_imm_or_fail (0, 0, FALSE); break;
5812
5813 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
5814 IF:
5815 if (!is_immediate_prefix (*str))
5816 goto bad_args;
5817 str++;
5818 val = parse_fpa_immediate (&str);
5819 if (val == FAIL)
5820 goto failure;
5821 /* FPA immediates are encoded as registers 8-15.
5822 parse_fpa_immediate has already applied the offset. */
5823 inst.operands[i].reg = val;
5824 inst.operands[i].isreg = 1;
5825 break;
5826
5827 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
5828 I32z: po_imm_or_fail (0, 32, FALSE); break;
5829
5830 /* Two kinds of register */
5831 case OP_RIWR_RIWC:
5832 {
5833 struct reg_entry *rege = arm_reg_parse_multi (&str);
5834 if (!rege
5835 || (rege->type != REG_TYPE_MMXWR
5836 && rege->type != REG_TYPE_MMXWC
5837 && rege->type != REG_TYPE_MMXWCG))
5838 {
5839 inst.error = _("iWMMXt data or control register expected");
5840 goto failure;
5841 }
5842 inst.operands[i].reg = rege->number;
5843 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
5844 }
5845 break;
5846
5847 case OP_RIWC_RIWG:
5848 {
5849 struct reg_entry *rege = arm_reg_parse_multi (&str);
5850 if (!rege
5851 || (rege->type != REG_TYPE_MMXWC
5852 && rege->type != REG_TYPE_MMXWCG))
5853 {
5854 inst.error = _("iWMMXt control register expected");
5855 goto failure;
5856 }
5857 inst.operands[i].reg = rege->number;
5858 inst.operands[i].isreg = 1;
5859 }
5860 break;
5861
5862 /* Misc */
5863 case OP_CPSF: val = parse_cps_flags (&str); break;
5864 case OP_ENDI: val = parse_endian_specifier (&str); break;
5865 case OP_oROR: val = parse_ror (&str); break;
5866 case OP_PSR: val = parse_psr (&str); break;
5867 case OP_COND: val = parse_cond (&str); break;
5868 case OP_oBARRIER:val = parse_barrier (&str); break;
5869
5870 case OP_RVC_PSR:
5871 po_reg_or_goto (REG_TYPE_VFC, try_psr);
5872 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
5873 break;
5874 try_psr:
5875 val = parse_psr (&str);
5876 break;
5877
5878 case OP_APSR_RR:
5879 po_reg_or_goto (REG_TYPE_RN, try_apsr);
5880 break;
5881 try_apsr:
5882 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
5883 instruction). */
5884 if (strncasecmp (str, "APSR_", 5) == 0)
5885 {
5886 unsigned found = 0;
5887 str += 5;
5888 while (found < 15)
5889 switch (*str++)
5890 {
5891 case 'c': found = (found & 1) ? 16 : found | 1; break;
5892 case 'n': found = (found & 2) ? 16 : found | 2; break;
5893 case 'z': found = (found & 4) ? 16 : found | 4; break;
5894 case 'v': found = (found & 8) ? 16 : found | 8; break;
5895 default: found = 16;
5896 }
5897 if (found != 15)
5898 goto failure;
5899 inst.operands[i].isvec = 1;
5900 }
5901 else
5902 goto failure;
5903 break;
5904
5905 case OP_TB:
5906 po_misc_or_fail (parse_tb (&str));
5907 break;
5908
5909 /* Register lists */
5910 case OP_REGLST:
5911 val = parse_reg_list (&str);
5912 if (*str == '^')
5913 {
5914 inst.operands[1].writeback = 1;
5915 str++;
5916 }
5917 break;
5918
5919 case OP_VRSLST:
5920 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
5921 break;
5922
5923 case OP_VRDLST:
5924 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
5925 break;
5926
5927 case OP_VRSDLST:
5928 /* Allow Q registers too. */
5929 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5930 REGLIST_NEON_D);
5931 if (val == FAIL)
5932 {
5933 inst.error = NULL;
5934 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5935 REGLIST_VFP_S);
5936 inst.operands[i].issingle = 1;
5937 }
5938 break;
5939
5940 case OP_NRDLST:
5941 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5942 REGLIST_NEON_D);
5943 break;
5944
5945 case OP_NSTRLST:
5946 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
5947 &inst.operands[i].vectype);
5948 break;
5949
5950 /* Addressing modes */
5951 case OP_ADDR:
5952 po_misc_or_fail (parse_address (&str, i));
5953 break;
5954
5955 case OP_ADDRGLDR:
5956 po_misc_or_fail_no_backtrack (
5957 parse_address_group_reloc (&str, i, GROUP_LDR));
5958 break;
5959
5960 case OP_ADDRGLDRS:
5961 po_misc_or_fail_no_backtrack (
5962 parse_address_group_reloc (&str, i, GROUP_LDRS));
5963 break;
5964
5965 case OP_ADDRGLDC:
5966 po_misc_or_fail_no_backtrack (
5967 parse_address_group_reloc (&str, i, GROUP_LDC));
5968 break;
5969
5970 case OP_SH:
5971 po_misc_or_fail (parse_shifter_operand (&str, i));
5972 break;
5973
5974 case OP_SHG:
5975 po_misc_or_fail_no_backtrack (
5976 parse_shifter_operand_group_reloc (&str, i));
5977 break;
5978
5979 case OP_oSHll:
5980 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
5981 break;
5982
5983 case OP_oSHar:
5984 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
5985 break;
5986
5987 case OP_oSHllar:
5988 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
5989 break;
5990
5991 default:
5992 as_fatal ("unhandled operand code %d", upat[i]);
5993 }
5994
5995 /* Various value-based sanity checks and shared operations. We
5996 do not signal immediate failures for the register constraints;
5997 this allows a syntax error to take precedence. */
5998 switch (upat[i])
5999 {
6000 case OP_oRRnpc:
6001 case OP_RRnpc:
6002 case OP_RRnpcb:
6003 case OP_RRw:
6004 case OP_oRRw:
6005 case OP_RRnpc_I0:
6006 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6007 inst.error = BAD_PC;
6008 break;
6009
6010 case OP_CPSF:
6011 case OP_ENDI:
6012 case OP_oROR:
6013 case OP_PSR:
6014 case OP_RVC_PSR:
6015 case OP_COND:
6016 case OP_oBARRIER:
6017 case OP_REGLST:
6018 case OP_VRSLST:
6019 case OP_VRDLST:
6020 case OP_VRSDLST:
6021 case OP_NRDLST:
6022 case OP_NSTRLST:
6023 if (val == FAIL)
6024 goto failure;
6025 inst.operands[i].imm = val;
6026 break;
6027
6028 default:
6029 break;
6030 }
6031
6032 /* If we get here, this operand was successfully parsed. */
6033 inst.operands[i].present = 1;
6034 continue;
6035
6036 bad_args:
6037 inst.error = BAD_ARGS;
6038
6039 failure:
6040 if (!backtrack_pos)
6041 {
6042 /* The parse routine should already have set inst.error, but set a
6043 defaut here just in case. */
6044 if (!inst.error)
6045 inst.error = _("syntax error");
6046 return FAIL;
6047 }
6048
6049 /* Do not backtrack over a trailing optional argument that
6050 absorbed some text. We will only fail again, with the
6051 'garbage following instruction' error message, which is
6052 probably less helpful than the current one. */
6053 if (backtrack_index == i && backtrack_pos != str
6054 && upat[i+1] == OP_stop)
6055 {
6056 if (!inst.error)
6057 inst.error = _("syntax error");
6058 return FAIL;
6059 }
6060
6061 /* Try again, skipping the optional argument at backtrack_pos. */
6062 str = backtrack_pos;
6063 inst.error = backtrack_error;
6064 inst.operands[backtrack_index].present = 0;
6065 i = backtrack_index;
6066 backtrack_pos = 0;
6067 }
6068
6069 /* Check that we have parsed all the arguments. */
6070 if (*str != '\0' && !inst.error)
6071 inst.error = _("garbage following instruction");
6072
6073 return inst.error ? FAIL : SUCCESS;
6074 }
6075
6076 #undef po_char_or_fail
6077 #undef po_reg_or_fail
6078 #undef po_reg_or_goto
6079 #undef po_imm_or_fail
6080 #undef po_scalar_or_fail
6081 \f
6082 /* Shorthand macro for instruction encoding functions issuing errors. */
6083 #define constraint(expr, err) do { \
6084 if (expr) \
6085 { \
6086 inst.error = err; \
6087 return; \
6088 } \
6089 } while (0)
6090
6091 /* Functions for operand encoding. ARM, then Thumb. */
6092
6093 #define rotate_left(v, n) (v << n | v >> (32 - n))
6094
6095 /* If VAL can be encoded in the immediate field of an ARM instruction,
6096 return the encoded form. Otherwise, return FAIL. */
6097
6098 static unsigned int
6099 encode_arm_immediate (unsigned int val)
6100 {
6101 unsigned int a, i;
6102
6103 for (i = 0; i < 32; i += 2)
6104 if ((a = rotate_left (val, i)) <= 0xff)
6105 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6106
6107 return FAIL;
6108 }
6109
6110 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6111 return the encoded form. Otherwise, return FAIL. */
6112 static unsigned int
6113 encode_thumb32_immediate (unsigned int val)
6114 {
6115 unsigned int a, i;
6116
6117 if (val <= 0xff)
6118 return val;
6119
6120 for (i = 1; i <= 24; i++)
6121 {
6122 a = val >> i;
6123 if ((val & ~(0xff << i)) == 0)
6124 return ((val >> i) & 0x7f) | ((32 - i) << 7);
6125 }
6126
6127 a = val & 0xff;
6128 if (val == ((a << 16) | a))
6129 return 0x100 | a;
6130 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6131 return 0x300 | a;
6132
6133 a = val & 0xff00;
6134 if (val == ((a << 16) | a))
6135 return 0x200 | (a >> 8);
6136
6137 return FAIL;
6138 }
6139 /* Encode a VFP SP or DP register number into inst.instruction. */
6140
6141 static void
6142 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6143 {
6144 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6145 && reg > 15)
6146 {
6147 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
6148 {
6149 if (thumb_mode)
6150 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
6151 fpu_vfp_ext_v3);
6152 else
6153 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
6154 fpu_vfp_ext_v3);
6155 }
6156 else
6157 {
6158 first_error (_("D register out of range for selected VFP version"));
6159 return;
6160 }
6161 }
6162
6163 switch (pos)
6164 {
6165 case VFP_REG_Sd:
6166 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6167 break;
6168
6169 case VFP_REG_Sn:
6170 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6171 break;
6172
6173 case VFP_REG_Sm:
6174 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6175 break;
6176
6177 case VFP_REG_Dd:
6178 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6179 break;
6180
6181 case VFP_REG_Dn:
6182 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6183 break;
6184
6185 case VFP_REG_Dm:
6186 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6187 break;
6188
6189 default:
6190 abort ();
6191 }
6192 }
6193
6194 /* Encode a <shift> in an ARM-format instruction. The immediate,
6195 if any, is handled by md_apply_fix. */
6196 static void
6197 encode_arm_shift (int i)
6198 {
6199 if (inst.operands[i].shift_kind == SHIFT_RRX)
6200 inst.instruction |= SHIFT_ROR << 5;
6201 else
6202 {
6203 inst.instruction |= inst.operands[i].shift_kind << 5;
6204 if (inst.operands[i].immisreg)
6205 {
6206 inst.instruction |= SHIFT_BY_REG;
6207 inst.instruction |= inst.operands[i].imm << 8;
6208 }
6209 else
6210 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6211 }
6212 }
6213
6214 static void
6215 encode_arm_shifter_operand (int i)
6216 {
6217 if (inst.operands[i].isreg)
6218 {
6219 inst.instruction |= inst.operands[i].reg;
6220 encode_arm_shift (i);
6221 }
6222 else
6223 inst.instruction |= INST_IMMEDIATE;
6224 }
6225
6226 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
6227 static void
6228 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
6229 {
6230 assert (inst.operands[i].isreg);
6231 inst.instruction |= inst.operands[i].reg << 16;
6232
6233 if (inst.operands[i].preind)
6234 {
6235 if (is_t)
6236 {
6237 inst.error = _("instruction does not accept preindexed addressing");
6238 return;
6239 }
6240 inst.instruction |= PRE_INDEX;
6241 if (inst.operands[i].writeback)
6242 inst.instruction |= WRITE_BACK;
6243
6244 }
6245 else if (inst.operands[i].postind)
6246 {
6247 assert (inst.operands[i].writeback);
6248 if (is_t)
6249 inst.instruction |= WRITE_BACK;
6250 }
6251 else /* unindexed - only for coprocessor */
6252 {
6253 inst.error = _("instruction does not accept unindexed addressing");
6254 return;
6255 }
6256
6257 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6258 && (((inst.instruction & 0x000f0000) >> 16)
6259 == ((inst.instruction & 0x0000f000) >> 12)))
6260 as_warn ((inst.instruction & LOAD_BIT)
6261 ? _("destination register same as write-back base")
6262 : _("source register same as write-back base"));
6263 }
6264
6265 /* inst.operands[i] was set up by parse_address. Encode it into an
6266 ARM-format mode 2 load or store instruction. If is_t is true,
6267 reject forms that cannot be used with a T instruction (i.e. not
6268 post-indexed). */
6269 static void
6270 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
6271 {
6272 encode_arm_addr_mode_common (i, is_t);
6273
6274 if (inst.operands[i].immisreg)
6275 {
6276 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6277 inst.instruction |= inst.operands[i].imm;
6278 if (!inst.operands[i].negative)
6279 inst.instruction |= INDEX_UP;
6280 if (inst.operands[i].shifted)
6281 {
6282 if (inst.operands[i].shift_kind == SHIFT_RRX)
6283 inst.instruction |= SHIFT_ROR << 5;
6284 else
6285 {
6286 inst.instruction |= inst.operands[i].shift_kind << 5;
6287 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6288 }
6289 }
6290 }
6291 else /* immediate offset in inst.reloc */
6292 {
6293 if (inst.reloc.type == BFD_RELOC_UNUSED)
6294 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
6295 }
6296 }
6297
6298 /* inst.operands[i] was set up by parse_address. Encode it into an
6299 ARM-format mode 3 load or store instruction. Reject forms that
6300 cannot be used with such instructions. If is_t is true, reject
6301 forms that cannot be used with a T instruction (i.e. not
6302 post-indexed). */
6303 static void
6304 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
6305 {
6306 if (inst.operands[i].immisreg && inst.operands[i].shifted)
6307 {
6308 inst.error = _("instruction does not accept scaled register index");
6309 return;
6310 }
6311
6312 encode_arm_addr_mode_common (i, is_t);
6313
6314 if (inst.operands[i].immisreg)
6315 {
6316 inst.instruction |= inst.operands[i].imm;
6317 if (!inst.operands[i].negative)
6318 inst.instruction |= INDEX_UP;
6319 }
6320 else /* immediate offset in inst.reloc */
6321 {
6322 inst.instruction |= HWOFFSET_IMM;
6323 if (inst.reloc.type == BFD_RELOC_UNUSED)
6324 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
6325 }
6326 }
6327
6328 /* inst.operands[i] was set up by parse_address. Encode it into an
6329 ARM-format instruction. Reject all forms which cannot be encoded
6330 into a coprocessor load/store instruction. If wb_ok is false,
6331 reject use of writeback; if unind_ok is false, reject use of
6332 unindexed addressing. If reloc_override is not 0, use it instead
6333 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6334 (in which case it is preserved). */
6335
6336 static int
6337 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
6338 {
6339 inst.instruction |= inst.operands[i].reg << 16;
6340
6341 assert (!(inst.operands[i].preind && inst.operands[i].postind));
6342
6343 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
6344 {
6345 assert (!inst.operands[i].writeback);
6346 if (!unind_ok)
6347 {
6348 inst.error = _("instruction does not support unindexed addressing");
6349 return FAIL;
6350 }
6351 inst.instruction |= inst.operands[i].imm;
6352 inst.instruction |= INDEX_UP;
6353 return SUCCESS;
6354 }
6355
6356 if (inst.operands[i].preind)
6357 inst.instruction |= PRE_INDEX;
6358
6359 if (inst.operands[i].writeback)
6360 {
6361 if (inst.operands[i].reg == REG_PC)
6362 {
6363 inst.error = _("pc may not be used with write-back");
6364 return FAIL;
6365 }
6366 if (!wb_ok)
6367 {
6368 inst.error = _("instruction does not support writeback");
6369 return FAIL;
6370 }
6371 inst.instruction |= WRITE_BACK;
6372 }
6373
6374 if (reloc_override)
6375 inst.reloc.type = reloc_override;
6376 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6377 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6378 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6379 {
6380 if (thumb_mode)
6381 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6382 else
6383 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6384 }
6385
6386 return SUCCESS;
6387 }
6388
6389 /* inst.reloc.exp describes an "=expr" load pseudo-operation.
6390 Determine whether it can be performed with a move instruction; if
6391 it can, convert inst.instruction to that move instruction and
6392 return 1; if it can't, convert inst.instruction to a literal-pool
6393 load and return 0. If this is not a valid thing to do in the
6394 current context, set inst.error and return 1.
6395
6396 inst.operands[i] describes the destination register. */
6397
6398 static int
6399 move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6400 {
6401 unsigned long tbit;
6402
6403 if (thumb_p)
6404 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6405 else
6406 tbit = LOAD_BIT;
6407
6408 if ((inst.instruction & tbit) == 0)
6409 {
6410 inst.error = _("invalid pseudo operation");
6411 return 1;
6412 }
6413 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
6414 {
6415 inst.error = _("constant expression expected");
6416 return 1;
6417 }
6418 if (inst.reloc.exp.X_op == O_constant)
6419 {
6420 if (thumb_p)
6421 {
6422 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
6423 {
6424 /* This can be done with a mov(1) instruction. */
6425 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6426 inst.instruction |= inst.reloc.exp.X_add_number;
6427 return 1;
6428 }
6429 }
6430 else
6431 {
6432 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6433 if (value != FAIL)
6434 {
6435 /* This can be done with a mov instruction. */
6436 inst.instruction &= LITERAL_MASK;
6437 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6438 inst.instruction |= value & 0xfff;
6439 return 1;
6440 }
6441
6442 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6443 if (value != FAIL)
6444 {
6445 /* This can be done with a mvn instruction. */
6446 inst.instruction &= LITERAL_MASK;
6447 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6448 inst.instruction |= value & 0xfff;
6449 return 1;
6450 }
6451 }
6452 }
6453
6454 if (add_to_lit_pool () == FAIL)
6455 {
6456 inst.error = _("literal pool insertion failed");
6457 return 1;
6458 }
6459 inst.operands[1].reg = REG_PC;
6460 inst.operands[1].isreg = 1;
6461 inst.operands[1].preind = 1;
6462 inst.reloc.pc_rel = 1;
6463 inst.reloc.type = (thumb_p
6464 ? BFD_RELOC_ARM_THUMB_OFFSET
6465 : (mode_3
6466 ? BFD_RELOC_ARM_HWLITERAL
6467 : BFD_RELOC_ARM_LITERAL));
6468 return 0;
6469 }
6470
6471 /* Functions for instruction encoding, sorted by subarchitecture.
6472 First some generics; their names are taken from the conventional
6473 bit positions for register arguments in ARM format instructions. */
6474
6475 static void
6476 do_noargs (void)
6477 {
6478 }
6479
6480 static void
6481 do_rd (void)
6482 {
6483 inst.instruction |= inst.operands[0].reg << 12;
6484 }
6485
6486 static void
6487 do_rd_rm (void)
6488 {
6489 inst.instruction |= inst.operands[0].reg << 12;
6490 inst.instruction |= inst.operands[1].reg;
6491 }
6492
6493 static void
6494 do_rd_rn (void)
6495 {
6496 inst.instruction |= inst.operands[0].reg << 12;
6497 inst.instruction |= inst.operands[1].reg << 16;
6498 }
6499
6500 static void
6501 do_rn_rd (void)
6502 {
6503 inst.instruction |= inst.operands[0].reg << 16;
6504 inst.instruction |= inst.operands[1].reg << 12;
6505 }
6506
6507 static void
6508 do_rd_rm_rn (void)
6509 {
6510 unsigned Rn = inst.operands[2].reg;
6511 /* Enforce restrictions on SWP instruction. */
6512 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6513 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6514 _("Rn must not overlap other operands"));
6515 inst.instruction |= inst.operands[0].reg << 12;
6516 inst.instruction |= inst.operands[1].reg;
6517 inst.instruction |= Rn << 16;
6518 }
6519
6520 static void
6521 do_rd_rn_rm (void)
6522 {
6523 inst.instruction |= inst.operands[0].reg << 12;
6524 inst.instruction |= inst.operands[1].reg << 16;
6525 inst.instruction |= inst.operands[2].reg;
6526 }
6527
6528 static void
6529 do_rm_rd_rn (void)
6530 {
6531 inst.instruction |= inst.operands[0].reg;
6532 inst.instruction |= inst.operands[1].reg << 12;
6533 inst.instruction |= inst.operands[2].reg << 16;
6534 }
6535
6536 static void
6537 do_imm0 (void)
6538 {
6539 inst.instruction |= inst.operands[0].imm;
6540 }
6541
6542 static void
6543 do_rd_cpaddr (void)
6544 {
6545 inst.instruction |= inst.operands[0].reg << 12;
6546 encode_arm_cp_address (1, TRUE, TRUE, 0);
6547 }
6548
6549 /* ARM instructions, in alphabetical order by function name (except
6550 that wrapper functions appear immediately after the function they
6551 wrap). */
6552
6553 /* This is a pseudo-op of the form "adr rd, label" to be converted
6554 into a relative address of the form "add rd, pc, #label-.-8". */
6555
6556 static void
6557 do_adr (void)
6558 {
6559 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
6560
6561 /* Frag hacking will turn this into a sub instruction if the offset turns
6562 out to be negative. */
6563 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
6564 inst.reloc.pc_rel = 1;
6565 inst.reloc.exp.X_add_number -= 8;
6566 }
6567
6568 /* This is a pseudo-op of the form "adrl rd, label" to be converted
6569 into a relative address of the form:
6570 add rd, pc, #low(label-.-8)"
6571 add rd, rd, #high(label-.-8)" */
6572
6573 static void
6574 do_adrl (void)
6575 {
6576 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
6577
6578 /* Frag hacking will turn this into a sub instruction if the offset turns
6579 out to be negative. */
6580 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
6581 inst.reloc.pc_rel = 1;
6582 inst.size = INSN_SIZE * 2;
6583 inst.reloc.exp.X_add_number -= 8;
6584 }
6585
6586 static void
6587 do_arit (void)
6588 {
6589 if (!inst.operands[1].present)
6590 inst.operands[1].reg = inst.operands[0].reg;
6591 inst.instruction |= inst.operands[0].reg << 12;
6592 inst.instruction |= inst.operands[1].reg << 16;
6593 encode_arm_shifter_operand (2);
6594 }
6595
6596 static void
6597 do_barrier (void)
6598 {
6599 if (inst.operands[0].present)
6600 {
6601 constraint ((inst.instruction & 0xf0) != 0x40
6602 && inst.operands[0].imm != 0xf,
6603 "bad barrier type");
6604 inst.instruction |= inst.operands[0].imm;
6605 }
6606 else
6607 inst.instruction |= 0xf;
6608 }
6609
6610 static void
6611 do_bfc (void)
6612 {
6613 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6614 constraint (msb > 32, _("bit-field extends past end of register"));
6615 /* The instruction encoding stores the LSB and MSB,
6616 not the LSB and width. */
6617 inst.instruction |= inst.operands[0].reg << 12;
6618 inst.instruction |= inst.operands[1].imm << 7;
6619 inst.instruction |= (msb - 1) << 16;
6620 }
6621
6622 static void
6623 do_bfi (void)
6624 {
6625 unsigned int msb;
6626
6627 /* #0 in second position is alternative syntax for bfc, which is
6628 the same instruction but with REG_PC in the Rm field. */
6629 if (!inst.operands[1].isreg)
6630 inst.operands[1].reg = REG_PC;
6631
6632 msb = inst.operands[2].imm + inst.operands[3].imm;
6633 constraint (msb > 32, _("bit-field extends past end of register"));
6634 /* The instruction encoding stores the LSB and MSB,
6635 not the LSB and width. */
6636 inst.instruction |= inst.operands[0].reg << 12;
6637 inst.instruction |= inst.operands[1].reg;
6638 inst.instruction |= inst.operands[2].imm << 7;
6639 inst.instruction |= (msb - 1) << 16;
6640 }
6641
6642 static void
6643 do_bfx (void)
6644 {
6645 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6646 _("bit-field extends past end of register"));
6647 inst.instruction |= inst.operands[0].reg << 12;
6648 inst.instruction |= inst.operands[1].reg;
6649 inst.instruction |= inst.operands[2].imm << 7;
6650 inst.instruction |= (inst.operands[3].imm - 1) << 16;
6651 }
6652
6653 /* ARM V5 breakpoint instruction (argument parse)
6654 BKPT <16 bit unsigned immediate>
6655 Instruction is not conditional.
6656 The bit pattern given in insns[] has the COND_ALWAYS condition,
6657 and it is an error if the caller tried to override that. */
6658
6659 static void
6660 do_bkpt (void)
6661 {
6662 /* Top 12 of 16 bits to bits 19:8. */
6663 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
6664
6665 /* Bottom 4 of 16 bits to bits 3:0. */
6666 inst.instruction |= inst.operands[0].imm & 0xf;
6667 }
6668
6669 static void
6670 encode_branch (int default_reloc)
6671 {
6672 if (inst.operands[0].hasreloc)
6673 {
6674 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
6675 _("the only suffix valid here is '(plt)'"));
6676 inst.reloc.type = BFD_RELOC_ARM_PLT32;
6677 }
6678 else
6679 {
6680 inst.reloc.type = default_reloc;
6681 }
6682 inst.reloc.pc_rel = 1;
6683 }
6684
6685 static void
6686 do_branch (void)
6687 {
6688 #ifdef OBJ_ELF
6689 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6690 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6691 else
6692 #endif
6693 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6694 }
6695
6696 static void
6697 do_bl (void)
6698 {
6699 #ifdef OBJ_ELF
6700 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6701 {
6702 if (inst.cond == COND_ALWAYS)
6703 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6704 else
6705 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6706 }
6707 else
6708 #endif
6709 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6710 }
6711
6712 /* ARM V5 branch-link-exchange instruction (argument parse)
6713 BLX <target_addr> ie BLX(1)
6714 BLX{<condition>} <Rm> ie BLX(2)
6715 Unfortunately, there are two different opcodes for this mnemonic.
6716 So, the insns[].value is not used, and the code here zaps values
6717 into inst.instruction.
6718 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
6719
6720 static void
6721 do_blx (void)
6722 {
6723 if (inst.operands[0].isreg)
6724 {
6725 /* Arg is a register; the opcode provided by insns[] is correct.
6726 It is not illegal to do "blx pc", just useless. */
6727 if (inst.operands[0].reg == REG_PC)
6728 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
6729
6730 inst.instruction |= inst.operands[0].reg;
6731 }
6732 else
6733 {
6734 /* Arg is an address; this instruction cannot be executed
6735 conditionally, and the opcode must be adjusted. */
6736 constraint (inst.cond != COND_ALWAYS, BAD_COND);
6737 inst.instruction = 0xfa000000;
6738 #ifdef OBJ_ELF
6739 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6740 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6741 else
6742 #endif
6743 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
6744 }
6745 }
6746
6747 static void
6748 do_bx (void)
6749 {
6750 if (inst.operands[0].reg == REG_PC)
6751 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
6752
6753 inst.instruction |= inst.operands[0].reg;
6754 }
6755
6756
6757 /* ARM v5TEJ. Jump to Jazelle code. */
6758
6759 static void
6760 do_bxj (void)
6761 {
6762 if (inst.operands[0].reg == REG_PC)
6763 as_tsktsk (_("use of r15 in bxj is not really useful"));
6764
6765 inst.instruction |= inst.operands[0].reg;
6766 }
6767
6768 /* Co-processor data operation:
6769 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
6770 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
6771 static void
6772 do_cdp (void)
6773 {
6774 inst.instruction |= inst.operands[0].reg << 8;
6775 inst.instruction |= inst.operands[1].imm << 20;
6776 inst.instruction |= inst.operands[2].reg << 12;
6777 inst.instruction |= inst.operands[3].reg << 16;
6778 inst.instruction |= inst.operands[4].reg;
6779 inst.instruction |= inst.operands[5].imm << 5;
6780 }
6781
6782 static void
6783 do_cmp (void)
6784 {
6785 inst.instruction |= inst.operands[0].reg << 16;
6786 encode_arm_shifter_operand (1);
6787 }
6788
6789 /* Transfer between coprocessor and ARM registers.
6790 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
6791 MRC2
6792 MCR{cond}
6793 MCR2
6794
6795 No special properties. */
6796
6797 static void
6798 do_co_reg (void)
6799 {
6800 inst.instruction |= inst.operands[0].reg << 8;
6801 inst.instruction |= inst.operands[1].imm << 21;
6802 inst.instruction |= inst.operands[2].reg << 12;
6803 inst.instruction |= inst.operands[3].reg << 16;
6804 inst.instruction |= inst.operands[4].reg;
6805 inst.instruction |= inst.operands[5].imm << 5;
6806 }
6807
6808 /* Transfer between coprocessor register and pair of ARM registers.
6809 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
6810 MCRR2
6811 MRRC{cond}
6812 MRRC2
6813
6814 Two XScale instructions are special cases of these:
6815
6816 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
6817 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
6818
6819 Result unpredicatable if Rd or Rn is R15. */
6820
6821 static void
6822 do_co_reg2c (void)
6823 {
6824 inst.instruction |= inst.operands[0].reg << 8;
6825 inst.instruction |= inst.operands[1].imm << 4;
6826 inst.instruction |= inst.operands[2].reg << 12;
6827 inst.instruction |= inst.operands[3].reg << 16;
6828 inst.instruction |= inst.operands[4].reg;
6829 }
6830
6831 static void
6832 do_cpsi (void)
6833 {
6834 inst.instruction |= inst.operands[0].imm << 6;
6835 if (inst.operands[1].present)
6836 {
6837 inst.instruction |= CPSI_MMOD;
6838 inst.instruction |= inst.operands[1].imm;
6839 }
6840 }
6841
6842 static void
6843 do_dbg (void)
6844 {
6845 inst.instruction |= inst.operands[0].imm;
6846 }
6847
6848 static void
6849 do_it (void)
6850 {
6851 /* There is no IT instruction in ARM mode. We
6852 process it but do not generate code for it. */
6853 inst.size = 0;
6854 }
6855
6856 static void
6857 do_ldmstm (void)
6858 {
6859 int base_reg = inst.operands[0].reg;
6860 int range = inst.operands[1].imm;
6861
6862 inst.instruction |= base_reg << 16;
6863 inst.instruction |= range;
6864
6865 if (inst.operands[1].writeback)
6866 inst.instruction |= LDM_TYPE_2_OR_3;
6867
6868 if (inst.operands[0].writeback)
6869 {
6870 inst.instruction |= WRITE_BACK;
6871 /* Check for unpredictable uses of writeback. */
6872 if (inst.instruction & LOAD_BIT)
6873 {
6874 /* Not allowed in LDM type 2. */
6875 if ((inst.instruction & LDM_TYPE_2_OR_3)
6876 && ((range & (1 << REG_PC)) == 0))
6877 as_warn (_("writeback of base register is UNPREDICTABLE"));
6878 /* Only allowed if base reg not in list for other types. */
6879 else if (range & (1 << base_reg))
6880 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
6881 }
6882 else /* STM. */
6883 {
6884 /* Not allowed for type 2. */
6885 if (inst.instruction & LDM_TYPE_2_OR_3)
6886 as_warn (_("writeback of base register is UNPREDICTABLE"));
6887 /* Only allowed if base reg not in list, or first in list. */
6888 else if ((range & (1 << base_reg))
6889 && (range & ((1 << base_reg) - 1)))
6890 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
6891 }
6892 }
6893 }
6894
6895 /* ARMv5TE load-consecutive (argument parse)
6896 Mode is like LDRH.
6897
6898 LDRccD R, mode
6899 STRccD R, mode. */
6900
6901 static void
6902 do_ldrd (void)
6903 {
6904 constraint (inst.operands[0].reg % 2 != 0,
6905 _("first destination register must be even"));
6906 constraint (inst.operands[1].present
6907 && inst.operands[1].reg != inst.operands[0].reg + 1,
6908 _("can only load two consecutive registers"));
6909 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
6910 constraint (!inst.operands[2].isreg, _("'[' expected"));
6911
6912 if (!inst.operands[1].present)
6913 inst.operands[1].reg = inst.operands[0].reg + 1;
6914
6915 if (inst.instruction & LOAD_BIT)
6916 {
6917 /* encode_arm_addr_mode_3 will diagnose overlap between the base
6918 register and the first register written; we have to diagnose
6919 overlap between the base and the second register written here. */
6920
6921 if (inst.operands[2].reg == inst.operands[1].reg
6922 && (inst.operands[2].writeback || inst.operands[2].postind))
6923 as_warn (_("base register written back, and overlaps "
6924 "second destination register"));
6925
6926 /* For an index-register load, the index register must not overlap the
6927 destination (even if not write-back). */
6928 else if (inst.operands[2].immisreg
6929 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
6930 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
6931 as_warn (_("index register overlaps destination register"));
6932 }
6933
6934 inst.instruction |= inst.operands[0].reg << 12;
6935 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
6936 }
6937
6938 static void
6939 do_ldrex (void)
6940 {
6941 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
6942 || inst.operands[1].postind || inst.operands[1].writeback
6943 || inst.operands[1].immisreg || inst.operands[1].shifted
6944 || inst.operands[1].negative
6945 /* This can arise if the programmer has written
6946 strex rN, rM, foo
6947 or if they have mistakenly used a register name as the last
6948 operand, eg:
6949 strex rN, rM, rX
6950 It is very difficult to distinguish between these two cases
6951 because "rX" might actually be a label. ie the register
6952 name has been occluded by a symbol of the same name. So we
6953 just generate a general 'bad addressing mode' type error
6954 message and leave it up to the programmer to discover the
6955 true cause and fix their mistake. */
6956 || (inst.operands[1].reg == REG_PC),
6957 BAD_ADDR_MODE);
6958
6959 constraint (inst.reloc.exp.X_op != O_constant
6960 || inst.reloc.exp.X_add_number != 0,
6961 _("offset must be zero in ARM encoding"));
6962
6963 inst.instruction |= inst.operands[0].reg << 12;
6964 inst.instruction |= inst.operands[1].reg << 16;
6965 inst.reloc.type = BFD_RELOC_UNUSED;
6966 }
6967
6968 static void
6969 do_ldrexd (void)
6970 {
6971 constraint (inst.operands[0].reg % 2 != 0,
6972 _("even register required"));
6973 constraint (inst.operands[1].present
6974 && inst.operands[1].reg != inst.operands[0].reg + 1,
6975 _("can only load two consecutive registers"));
6976 /* If op 1 were present and equal to PC, this function wouldn't
6977 have been called in the first place. */
6978 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
6979
6980 inst.instruction |= inst.operands[0].reg << 12;
6981 inst.instruction |= inst.operands[2].reg << 16;
6982 }
6983
6984 static void
6985 do_ldst (void)
6986 {
6987 inst.instruction |= inst.operands[0].reg << 12;
6988 if (!inst.operands[1].isreg)
6989 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
6990 return;
6991 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
6992 }
6993
6994 static void
6995 do_ldstt (void)
6996 {
6997 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
6998 reject [Rn,...]. */
6999 if (inst.operands[1].preind)
7000 {
7001 constraint (inst.reloc.exp.X_op != O_constant ||
7002 inst.reloc.exp.X_add_number != 0,
7003 _("this instruction requires a post-indexed address"));
7004
7005 inst.operands[1].preind = 0;
7006 inst.operands[1].postind = 1;
7007 inst.operands[1].writeback = 1;
7008 }
7009 inst.instruction |= inst.operands[0].reg << 12;
7010 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7011 }
7012
7013 /* Halfword and signed-byte load/store operations. */
7014
7015 static void
7016 do_ldstv4 (void)
7017 {
7018 inst.instruction |= inst.operands[0].reg << 12;
7019 if (!inst.operands[1].isreg)
7020 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
7021 return;
7022 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
7023 }
7024
7025 static void
7026 do_ldsttv4 (void)
7027 {
7028 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7029 reject [Rn,...]. */
7030 if (inst.operands[1].preind)
7031 {
7032 constraint (inst.reloc.exp.X_op != O_constant ||
7033 inst.reloc.exp.X_add_number != 0,
7034 _("this instruction requires a post-indexed address"));
7035
7036 inst.operands[1].preind = 0;
7037 inst.operands[1].postind = 1;
7038 inst.operands[1].writeback = 1;
7039 }
7040 inst.instruction |= inst.operands[0].reg << 12;
7041 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7042 }
7043
7044 /* Co-processor register load/store.
7045 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7046 static void
7047 do_lstc (void)
7048 {
7049 inst.instruction |= inst.operands[0].reg << 8;
7050 inst.instruction |= inst.operands[1].reg << 12;
7051 encode_arm_cp_address (2, TRUE, TRUE, 0);
7052 }
7053
7054 static void
7055 do_mlas (void)
7056 {
7057 /* This restriction does not apply to mls (nor to mla in v6 or later). */
7058 if (inst.operands[0].reg == inst.operands[1].reg
7059 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
7060 && !(inst.instruction & 0x00400000))
7061 as_tsktsk (_("Rd and Rm should be different in mla"));
7062
7063 inst.instruction |= inst.operands[0].reg << 16;
7064 inst.instruction |= inst.operands[1].reg;
7065 inst.instruction |= inst.operands[2].reg << 8;
7066 inst.instruction |= inst.operands[3].reg << 12;
7067 }
7068
7069 static void
7070 do_mov (void)
7071 {
7072 inst.instruction |= inst.operands[0].reg << 12;
7073 encode_arm_shifter_operand (1);
7074 }
7075
7076 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7077 static void
7078 do_mov16 (void)
7079 {
7080 bfd_vma imm;
7081 bfd_boolean top;
7082
7083 top = (inst.instruction & 0x00400000) != 0;
7084 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7085 _(":lower16: not allowed this instruction"));
7086 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7087 _(":upper16: not allowed instruction"));
7088 inst.instruction |= inst.operands[0].reg << 12;
7089 if (inst.reloc.type == BFD_RELOC_UNUSED)
7090 {
7091 imm = inst.reloc.exp.X_add_number;
7092 /* The value is in two pieces: 0:11, 16:19. */
7093 inst.instruction |= (imm & 0x00000fff);
7094 inst.instruction |= (imm & 0x0000f000) << 4;
7095 }
7096 }
7097
7098 static void do_vfp_nsyn_opcode (const char *);
7099
7100 static int
7101 do_vfp_nsyn_mrs (void)
7102 {
7103 if (inst.operands[0].isvec)
7104 {
7105 if (inst.operands[1].reg != 1)
7106 first_error (_("operand 1 must be FPSCR"));
7107 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7108 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7109 do_vfp_nsyn_opcode ("fmstat");
7110 }
7111 else if (inst.operands[1].isvec)
7112 do_vfp_nsyn_opcode ("fmrx");
7113 else
7114 return FAIL;
7115
7116 return SUCCESS;
7117 }
7118
7119 static int
7120 do_vfp_nsyn_msr (void)
7121 {
7122 if (inst.operands[0].isvec)
7123 do_vfp_nsyn_opcode ("fmxr");
7124 else
7125 return FAIL;
7126
7127 return SUCCESS;
7128 }
7129
7130 static void
7131 do_mrs (void)
7132 {
7133 if (do_vfp_nsyn_mrs () == SUCCESS)
7134 return;
7135
7136 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7137 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7138 != (PSR_c|PSR_f),
7139 _("'CPSR' or 'SPSR' expected"));
7140 inst.instruction |= inst.operands[0].reg << 12;
7141 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7142 }
7143
7144 /* Two possible forms:
7145 "{C|S}PSR_<field>, Rm",
7146 "{C|S}PSR_f, #expression". */
7147
7148 static void
7149 do_msr (void)
7150 {
7151 if (do_vfp_nsyn_msr () == SUCCESS)
7152 return;
7153
7154 inst.instruction |= inst.operands[0].imm;
7155 if (inst.operands[1].isreg)
7156 inst.instruction |= inst.operands[1].reg;
7157 else
7158 {
7159 inst.instruction |= INST_IMMEDIATE;
7160 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7161 inst.reloc.pc_rel = 0;
7162 }
7163 }
7164
7165 static void
7166 do_mul (void)
7167 {
7168 if (!inst.operands[2].present)
7169 inst.operands[2].reg = inst.operands[0].reg;
7170 inst.instruction |= inst.operands[0].reg << 16;
7171 inst.instruction |= inst.operands[1].reg;
7172 inst.instruction |= inst.operands[2].reg << 8;
7173
7174 if (inst.operands[0].reg == inst.operands[1].reg
7175 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7176 as_tsktsk (_("Rd and Rm should be different in mul"));
7177 }
7178
7179 /* Long Multiply Parser
7180 UMULL RdLo, RdHi, Rm, Rs
7181 SMULL RdLo, RdHi, Rm, Rs
7182 UMLAL RdLo, RdHi, Rm, Rs
7183 SMLAL RdLo, RdHi, Rm, Rs. */
7184
7185 static void
7186 do_mull (void)
7187 {
7188 inst.instruction |= inst.operands[0].reg << 12;
7189 inst.instruction |= inst.operands[1].reg << 16;
7190 inst.instruction |= inst.operands[2].reg;
7191 inst.instruction |= inst.operands[3].reg << 8;
7192
7193 /* rdhi, rdlo and rm must all be different. */
7194 if (inst.operands[0].reg == inst.operands[1].reg
7195 || inst.operands[0].reg == inst.operands[2].reg
7196 || inst.operands[1].reg == inst.operands[2].reg)
7197 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7198 }
7199
7200 static void
7201 do_nop (void)
7202 {
7203 if (inst.operands[0].present)
7204 {
7205 /* Architectural NOP hints are CPSR sets with no bits selected. */
7206 inst.instruction &= 0xf0000000;
7207 inst.instruction |= 0x0320f000 + inst.operands[0].imm;
7208 }
7209 }
7210
7211 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7212 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7213 Condition defaults to COND_ALWAYS.
7214 Error if Rd, Rn or Rm are R15. */
7215
7216 static void
7217 do_pkhbt (void)
7218 {
7219 inst.instruction |= inst.operands[0].reg << 12;
7220 inst.instruction |= inst.operands[1].reg << 16;
7221 inst.instruction |= inst.operands[2].reg;
7222 if (inst.operands[3].present)
7223 encode_arm_shift (3);
7224 }
7225
7226 /* ARM V6 PKHTB (Argument Parse). */
7227
7228 static void
7229 do_pkhtb (void)
7230 {
7231 if (!inst.operands[3].present)
7232 {
7233 /* If the shift specifier is omitted, turn the instruction
7234 into pkhbt rd, rm, rn. */
7235 inst.instruction &= 0xfff00010;
7236 inst.instruction |= inst.operands[0].reg << 12;
7237 inst.instruction |= inst.operands[1].reg;
7238 inst.instruction |= inst.operands[2].reg << 16;
7239 }
7240 else
7241 {
7242 inst.instruction |= inst.operands[0].reg << 12;
7243 inst.instruction |= inst.operands[1].reg << 16;
7244 inst.instruction |= inst.operands[2].reg;
7245 encode_arm_shift (3);
7246 }
7247 }
7248
7249 /* ARMv5TE: Preload-Cache
7250
7251 PLD <addr_mode>
7252
7253 Syntactically, like LDR with B=1, W=0, L=1. */
7254
7255 static void
7256 do_pld (void)
7257 {
7258 constraint (!inst.operands[0].isreg,
7259 _("'[' expected after PLD mnemonic"));
7260 constraint (inst.operands[0].postind,
7261 _("post-indexed expression used in preload instruction"));
7262 constraint (inst.operands[0].writeback,
7263 _("writeback used in preload instruction"));
7264 constraint (!inst.operands[0].preind,
7265 _("unindexed addressing used in preload instruction"));
7266 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7267 }
7268
7269 /* ARMv7: PLI <addr_mode> */
7270 static void
7271 do_pli (void)
7272 {
7273 constraint (!inst.operands[0].isreg,
7274 _("'[' expected after PLI mnemonic"));
7275 constraint (inst.operands[0].postind,
7276 _("post-indexed expression used in preload instruction"));
7277 constraint (inst.operands[0].writeback,
7278 _("writeback used in preload instruction"));
7279 constraint (!inst.operands[0].preind,
7280 _("unindexed addressing used in preload instruction"));
7281 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7282 inst.instruction &= ~PRE_INDEX;
7283 }
7284
7285 static void
7286 do_push_pop (void)
7287 {
7288 inst.operands[1] = inst.operands[0];
7289 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7290 inst.operands[0].isreg = 1;
7291 inst.operands[0].writeback = 1;
7292 inst.operands[0].reg = REG_SP;
7293 do_ldmstm ();
7294 }
7295
7296 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7297 word at the specified address and the following word
7298 respectively.
7299 Unconditionally executed.
7300 Error if Rn is R15. */
7301
7302 static void
7303 do_rfe (void)
7304 {
7305 inst.instruction |= inst.operands[0].reg << 16;
7306 if (inst.operands[0].writeback)
7307 inst.instruction |= WRITE_BACK;
7308 }
7309
7310 /* ARM V6 ssat (argument parse). */
7311
7312 static void
7313 do_ssat (void)
7314 {
7315 inst.instruction |= inst.operands[0].reg << 12;
7316 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7317 inst.instruction |= inst.operands[2].reg;
7318
7319 if (inst.operands[3].present)
7320 encode_arm_shift (3);
7321 }
7322
7323 /* ARM V6 usat (argument parse). */
7324
7325 static void
7326 do_usat (void)
7327 {
7328 inst.instruction |= inst.operands[0].reg << 12;
7329 inst.instruction |= inst.operands[1].imm << 16;
7330 inst.instruction |= inst.operands[2].reg;
7331
7332 if (inst.operands[3].present)
7333 encode_arm_shift (3);
7334 }
7335
7336 /* ARM V6 ssat16 (argument parse). */
7337
7338 static void
7339 do_ssat16 (void)
7340 {
7341 inst.instruction |= inst.operands[0].reg << 12;
7342 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7343 inst.instruction |= inst.operands[2].reg;
7344 }
7345
7346 static void
7347 do_usat16 (void)
7348 {
7349 inst.instruction |= inst.operands[0].reg << 12;
7350 inst.instruction |= inst.operands[1].imm << 16;
7351 inst.instruction |= inst.operands[2].reg;
7352 }
7353
7354 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7355 preserving the other bits.
7356
7357 setend <endian_specifier>, where <endian_specifier> is either
7358 BE or LE. */
7359
7360 static void
7361 do_setend (void)
7362 {
7363 if (inst.operands[0].imm)
7364 inst.instruction |= 0x200;
7365 }
7366
7367 static void
7368 do_shift (void)
7369 {
7370 unsigned int Rm = (inst.operands[1].present
7371 ? inst.operands[1].reg
7372 : inst.operands[0].reg);
7373
7374 inst.instruction |= inst.operands[0].reg << 12;
7375 inst.instruction |= Rm;
7376 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
7377 {
7378 inst.instruction |= inst.operands[2].reg << 8;
7379 inst.instruction |= SHIFT_BY_REG;
7380 }
7381 else
7382 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7383 }
7384
7385 static void
7386 do_smc (void)
7387 {
7388 inst.reloc.type = BFD_RELOC_ARM_SMC;
7389 inst.reloc.pc_rel = 0;
7390 }
7391
7392 static void
7393 do_swi (void)
7394 {
7395 inst.reloc.type = BFD_RELOC_ARM_SWI;
7396 inst.reloc.pc_rel = 0;
7397 }
7398
7399 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7400 SMLAxy{cond} Rd,Rm,Rs,Rn
7401 SMLAWy{cond} Rd,Rm,Rs,Rn
7402 Error if any register is R15. */
7403
7404 static void
7405 do_smla (void)
7406 {
7407 inst.instruction |= inst.operands[0].reg << 16;
7408 inst.instruction |= inst.operands[1].reg;
7409 inst.instruction |= inst.operands[2].reg << 8;
7410 inst.instruction |= inst.operands[3].reg << 12;
7411 }
7412
7413 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7414 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7415 Error if any register is R15.
7416 Warning if Rdlo == Rdhi. */
7417
7418 static void
7419 do_smlal (void)
7420 {
7421 inst.instruction |= inst.operands[0].reg << 12;
7422 inst.instruction |= inst.operands[1].reg << 16;
7423 inst.instruction |= inst.operands[2].reg;
7424 inst.instruction |= inst.operands[3].reg << 8;
7425
7426 if (inst.operands[0].reg == inst.operands[1].reg)
7427 as_tsktsk (_("rdhi and rdlo must be different"));
7428 }
7429
7430 /* ARM V5E (El Segundo) signed-multiply (argument parse)
7431 SMULxy{cond} Rd,Rm,Rs
7432 Error if any register is R15. */
7433
7434 static void
7435 do_smul (void)
7436 {
7437 inst.instruction |= inst.operands[0].reg << 16;
7438 inst.instruction |= inst.operands[1].reg;
7439 inst.instruction |= inst.operands[2].reg << 8;
7440 }
7441
7442 /* ARM V6 srs (argument parse). The variable fields in the encoding are
7443 the same for both ARM and Thumb-2. */
7444
7445 static void
7446 do_srs (void)
7447 {
7448 int reg;
7449
7450 if (inst.operands[0].present)
7451 {
7452 reg = inst.operands[0].reg;
7453 constraint (reg != 13, _("SRS base register must be r13"));
7454 }
7455 else
7456 reg = 13;
7457
7458 inst.instruction |= reg << 16;
7459 inst.instruction |= inst.operands[1].imm;
7460 if (inst.operands[0].writeback || inst.operands[1].writeback)
7461 inst.instruction |= WRITE_BACK;
7462 }
7463
7464 /* ARM V6 strex (argument parse). */
7465
7466 static void
7467 do_strex (void)
7468 {
7469 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7470 || inst.operands[2].postind || inst.operands[2].writeback
7471 || inst.operands[2].immisreg || inst.operands[2].shifted
7472 || inst.operands[2].negative
7473 /* See comment in do_ldrex(). */
7474 || (inst.operands[2].reg == REG_PC),
7475 BAD_ADDR_MODE);
7476
7477 constraint (inst.operands[0].reg == inst.operands[1].reg
7478 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
7479
7480 constraint (inst.reloc.exp.X_op != O_constant
7481 || inst.reloc.exp.X_add_number != 0,
7482 _("offset must be zero in ARM encoding"));
7483
7484 inst.instruction |= inst.operands[0].reg << 12;
7485 inst.instruction |= inst.operands[1].reg;
7486 inst.instruction |= inst.operands[2].reg << 16;
7487 inst.reloc.type = BFD_RELOC_UNUSED;
7488 }
7489
7490 static void
7491 do_strexd (void)
7492 {
7493 constraint (inst.operands[1].reg % 2 != 0,
7494 _("even register required"));
7495 constraint (inst.operands[2].present
7496 && inst.operands[2].reg != inst.operands[1].reg + 1,
7497 _("can only store two consecutive registers"));
7498 /* If op 2 were present and equal to PC, this function wouldn't
7499 have been called in the first place. */
7500 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
7501
7502 constraint (inst.operands[0].reg == inst.operands[1].reg
7503 || inst.operands[0].reg == inst.operands[1].reg + 1
7504 || inst.operands[0].reg == inst.operands[3].reg,
7505 BAD_OVERLAP);
7506
7507 inst.instruction |= inst.operands[0].reg << 12;
7508 inst.instruction |= inst.operands[1].reg;
7509 inst.instruction |= inst.operands[3].reg << 16;
7510 }
7511
7512 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
7513 extends it to 32-bits, and adds the result to a value in another
7514 register. You can specify a rotation by 0, 8, 16, or 24 bits
7515 before extracting the 16-bit value.
7516 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
7517 Condition defaults to COND_ALWAYS.
7518 Error if any register uses R15. */
7519
7520 static void
7521 do_sxtah (void)
7522 {
7523 inst.instruction |= inst.operands[0].reg << 12;
7524 inst.instruction |= inst.operands[1].reg << 16;
7525 inst.instruction |= inst.operands[2].reg;
7526 inst.instruction |= inst.operands[3].imm << 10;
7527 }
7528
7529 /* ARM V6 SXTH.
7530
7531 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
7532 Condition defaults to COND_ALWAYS.
7533 Error if any register uses R15. */
7534
7535 static void
7536 do_sxth (void)
7537 {
7538 inst.instruction |= inst.operands[0].reg << 12;
7539 inst.instruction |= inst.operands[1].reg;
7540 inst.instruction |= inst.operands[2].imm << 10;
7541 }
7542 \f
7543 /* VFP instructions. In a logical order: SP variant first, monad
7544 before dyad, arithmetic then move then load/store. */
7545
7546 static void
7547 do_vfp_sp_monadic (void)
7548 {
7549 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7550 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
7551 }
7552
7553 static void
7554 do_vfp_sp_dyadic (void)
7555 {
7556 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7557 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7558 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
7559 }
7560
7561 static void
7562 do_vfp_sp_compare_z (void)
7563 {
7564 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7565 }
7566
7567 static void
7568 do_vfp_dp_sp_cvt (void)
7569 {
7570 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7571 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
7572 }
7573
7574 static void
7575 do_vfp_sp_dp_cvt (void)
7576 {
7577 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7578 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7579 }
7580
7581 static void
7582 do_vfp_reg_from_sp (void)
7583 {
7584 inst.instruction |= inst.operands[0].reg << 12;
7585 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7586 }
7587
7588 static void
7589 do_vfp_reg2_from_sp2 (void)
7590 {
7591 constraint (inst.operands[2].imm != 2,
7592 _("only two consecutive VFP SP registers allowed here"));
7593 inst.instruction |= inst.operands[0].reg << 12;
7594 inst.instruction |= inst.operands[1].reg << 16;
7595 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
7596 }
7597
7598 static void
7599 do_vfp_sp_from_reg (void)
7600 {
7601 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
7602 inst.instruction |= inst.operands[1].reg << 12;
7603 }
7604
7605 static void
7606 do_vfp_sp2_from_reg2 (void)
7607 {
7608 constraint (inst.operands[0].imm != 2,
7609 _("only two consecutive VFP SP registers allowed here"));
7610 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
7611 inst.instruction |= inst.operands[1].reg << 12;
7612 inst.instruction |= inst.operands[2].reg << 16;
7613 }
7614
7615 static void
7616 do_vfp_sp_ldst (void)
7617 {
7618 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7619 encode_arm_cp_address (1, FALSE, TRUE, 0);
7620 }
7621
7622 static void
7623 do_vfp_dp_ldst (void)
7624 {
7625 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7626 encode_arm_cp_address (1, FALSE, TRUE, 0);
7627 }
7628
7629
7630 static void
7631 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
7632 {
7633 if (inst.operands[0].writeback)
7634 inst.instruction |= WRITE_BACK;
7635 else
7636 constraint (ldstm_type != VFP_LDSTMIA,
7637 _("this addressing mode requires base-register writeback"));
7638 inst.instruction |= inst.operands[0].reg << 16;
7639 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
7640 inst.instruction |= inst.operands[1].imm;
7641 }
7642
7643 static void
7644 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
7645 {
7646 int count;
7647
7648 if (inst.operands[0].writeback)
7649 inst.instruction |= WRITE_BACK;
7650 else
7651 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
7652 _("this addressing mode requires base-register writeback"));
7653
7654 inst.instruction |= inst.operands[0].reg << 16;
7655 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7656
7657 count = inst.operands[1].imm << 1;
7658 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
7659 count += 1;
7660
7661 inst.instruction |= count;
7662 }
7663
7664 static void
7665 do_vfp_sp_ldstmia (void)
7666 {
7667 vfp_sp_ldstm (VFP_LDSTMIA);
7668 }
7669
7670 static void
7671 do_vfp_sp_ldstmdb (void)
7672 {
7673 vfp_sp_ldstm (VFP_LDSTMDB);
7674 }
7675
7676 static void
7677 do_vfp_dp_ldstmia (void)
7678 {
7679 vfp_dp_ldstm (VFP_LDSTMIA);
7680 }
7681
7682 static void
7683 do_vfp_dp_ldstmdb (void)
7684 {
7685 vfp_dp_ldstm (VFP_LDSTMDB);
7686 }
7687
7688 static void
7689 do_vfp_xp_ldstmia (void)
7690 {
7691 vfp_dp_ldstm (VFP_LDSTMIAX);
7692 }
7693
7694 static void
7695 do_vfp_xp_ldstmdb (void)
7696 {
7697 vfp_dp_ldstm (VFP_LDSTMDBX);
7698 }
7699
7700 static void
7701 do_vfp_dp_rd_rm (void)
7702 {
7703 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7704 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7705 }
7706
7707 static void
7708 do_vfp_dp_rn_rd (void)
7709 {
7710 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
7711 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7712 }
7713
7714 static void
7715 do_vfp_dp_rd_rn (void)
7716 {
7717 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7718 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7719 }
7720
7721 static void
7722 do_vfp_dp_rd_rn_rm (void)
7723 {
7724 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7725 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7726 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
7727 }
7728
7729 static void
7730 do_vfp_dp_rd (void)
7731 {
7732 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7733 }
7734
7735 static void
7736 do_vfp_dp_rm_rd_rn (void)
7737 {
7738 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
7739 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7740 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
7741 }
7742
7743 /* VFPv3 instructions. */
7744 static void
7745 do_vfp_sp_const (void)
7746 {
7747 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7748 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7749 inst.instruction |= (inst.operands[1].imm & 0x0f);
7750 }
7751
7752 static void
7753 do_vfp_dp_const (void)
7754 {
7755 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7756 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7757 inst.instruction |= (inst.operands[1].imm & 0x0f);
7758 }
7759
7760 static void
7761 vfp_conv (int srcsize)
7762 {
7763 unsigned immbits = srcsize - inst.operands[1].imm;
7764 inst.instruction |= (immbits & 1) << 5;
7765 inst.instruction |= (immbits >> 1);
7766 }
7767
7768 static void
7769 do_vfp_sp_conv_16 (void)
7770 {
7771 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7772 vfp_conv (16);
7773 }
7774
7775 static void
7776 do_vfp_dp_conv_16 (void)
7777 {
7778 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7779 vfp_conv (16);
7780 }
7781
7782 static void
7783 do_vfp_sp_conv_32 (void)
7784 {
7785 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7786 vfp_conv (32);
7787 }
7788
7789 static void
7790 do_vfp_dp_conv_32 (void)
7791 {
7792 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7793 vfp_conv (32);
7794 }
7795
7796 \f
7797 /* FPA instructions. Also in a logical order. */
7798
7799 static void
7800 do_fpa_cmp (void)
7801 {
7802 inst.instruction |= inst.operands[0].reg << 16;
7803 inst.instruction |= inst.operands[1].reg;
7804 }
7805
7806 static void
7807 do_fpa_ldmstm (void)
7808 {
7809 inst.instruction |= inst.operands[0].reg << 12;
7810 switch (inst.operands[1].imm)
7811 {
7812 case 1: inst.instruction |= CP_T_X; break;
7813 case 2: inst.instruction |= CP_T_Y; break;
7814 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
7815 case 4: break;
7816 default: abort ();
7817 }
7818
7819 if (inst.instruction & (PRE_INDEX | INDEX_UP))
7820 {
7821 /* The instruction specified "ea" or "fd", so we can only accept
7822 [Rn]{!}. The instruction does not really support stacking or
7823 unstacking, so we have to emulate these by setting appropriate
7824 bits and offsets. */
7825 constraint (inst.reloc.exp.X_op != O_constant
7826 || inst.reloc.exp.X_add_number != 0,
7827 _("this instruction does not support indexing"));
7828
7829 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
7830 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
7831
7832 if (!(inst.instruction & INDEX_UP))
7833 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
7834
7835 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
7836 {
7837 inst.operands[2].preind = 0;
7838 inst.operands[2].postind = 1;
7839 }
7840 }
7841
7842 encode_arm_cp_address (2, TRUE, TRUE, 0);
7843 }
7844
7845 \f
7846 /* iWMMXt instructions: strictly in alphabetical order. */
7847
7848 static void
7849 do_iwmmxt_tandorc (void)
7850 {
7851 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
7852 }
7853
7854 static void
7855 do_iwmmxt_textrc (void)
7856 {
7857 inst.instruction |= inst.operands[0].reg << 12;
7858 inst.instruction |= inst.operands[1].imm;
7859 }
7860
7861 static void
7862 do_iwmmxt_textrm (void)
7863 {
7864 inst.instruction |= inst.operands[0].reg << 12;
7865 inst.instruction |= inst.operands[1].reg << 16;
7866 inst.instruction |= inst.operands[2].imm;
7867 }
7868
7869 static void
7870 do_iwmmxt_tinsr (void)
7871 {
7872 inst.instruction |= inst.operands[0].reg << 16;
7873 inst.instruction |= inst.operands[1].reg << 12;
7874 inst.instruction |= inst.operands[2].imm;
7875 }
7876
7877 static void
7878 do_iwmmxt_tmia (void)
7879 {
7880 inst.instruction |= inst.operands[0].reg << 5;
7881 inst.instruction |= inst.operands[1].reg;
7882 inst.instruction |= inst.operands[2].reg << 12;
7883 }
7884
7885 static void
7886 do_iwmmxt_waligni (void)
7887 {
7888 inst.instruction |= inst.operands[0].reg << 12;
7889 inst.instruction |= inst.operands[1].reg << 16;
7890 inst.instruction |= inst.operands[2].reg;
7891 inst.instruction |= inst.operands[3].imm << 20;
7892 }
7893
7894 static void
7895 do_iwmmxt_wmerge (void)
7896 {
7897 inst.instruction |= inst.operands[0].reg << 12;
7898 inst.instruction |= inst.operands[1].reg << 16;
7899 inst.instruction |= inst.operands[2].reg;
7900 inst.instruction |= inst.operands[3].imm << 21;
7901 }
7902
7903 static void
7904 do_iwmmxt_wmov (void)
7905 {
7906 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
7907 inst.instruction |= inst.operands[0].reg << 12;
7908 inst.instruction |= inst.operands[1].reg << 16;
7909 inst.instruction |= inst.operands[1].reg;
7910 }
7911
7912 static void
7913 do_iwmmxt_wldstbh (void)
7914 {
7915 int reloc;
7916 inst.instruction |= inst.operands[0].reg << 12;
7917 if (thumb_mode)
7918 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
7919 else
7920 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
7921 encode_arm_cp_address (1, TRUE, FALSE, reloc);
7922 }
7923
7924 static void
7925 do_iwmmxt_wldstw (void)
7926 {
7927 /* RIWR_RIWC clears .isreg for a control register. */
7928 if (!inst.operands[0].isreg)
7929 {
7930 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7931 inst.instruction |= 0xf0000000;
7932 }
7933
7934 inst.instruction |= inst.operands[0].reg << 12;
7935 encode_arm_cp_address (1, TRUE, TRUE, 0);
7936 }
7937
7938 static void
7939 do_iwmmxt_wldstd (void)
7940 {
7941 inst.instruction |= inst.operands[0].reg << 12;
7942 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
7943 && inst.operands[1].immisreg)
7944 {
7945 inst.instruction &= ~0x1a000ff;
7946 inst.instruction |= (0xf << 28);
7947 if (inst.operands[1].preind)
7948 inst.instruction |= PRE_INDEX;
7949 if (!inst.operands[1].negative)
7950 inst.instruction |= INDEX_UP;
7951 if (inst.operands[1].writeback)
7952 inst.instruction |= WRITE_BACK;
7953 inst.instruction |= inst.operands[1].reg << 16;
7954 inst.instruction |= inst.reloc.exp.X_add_number << 4;
7955 inst.instruction |= inst.operands[1].imm;
7956 }
7957 else
7958 encode_arm_cp_address (1, TRUE, FALSE, 0);
7959 }
7960
7961 static void
7962 do_iwmmxt_wshufh (void)
7963 {
7964 inst.instruction |= inst.operands[0].reg << 12;
7965 inst.instruction |= inst.operands[1].reg << 16;
7966 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
7967 inst.instruction |= (inst.operands[2].imm & 0x0f);
7968 }
7969
7970 static void
7971 do_iwmmxt_wzero (void)
7972 {
7973 /* WZERO reg is an alias for WANDN reg, reg, reg. */
7974 inst.instruction |= inst.operands[0].reg;
7975 inst.instruction |= inst.operands[0].reg << 12;
7976 inst.instruction |= inst.operands[0].reg << 16;
7977 }
7978
7979 static void
7980 do_iwmmxt_wrwrwr_or_imm5 (void)
7981 {
7982 if (inst.operands[2].isreg)
7983 do_rd_rn_rm ();
7984 else {
7985 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
7986 _("immediate operand requires iWMMXt2"));
7987 do_rd_rn ();
7988 if (inst.operands[2].imm == 0)
7989 {
7990 switch ((inst.instruction >> 20) & 0xf)
7991 {
7992 case 4:
7993 case 5:
7994 case 6:
7995 case 7:
7996 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
7997 inst.operands[2].imm = 16;
7998 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
7999 break;
8000 case 8:
8001 case 9:
8002 case 10:
8003 case 11:
8004 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8005 inst.operands[2].imm = 32;
8006 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8007 break;
8008 case 12:
8009 case 13:
8010 case 14:
8011 case 15:
8012 {
8013 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8014 unsigned long wrn;
8015 wrn = (inst.instruction >> 16) & 0xf;
8016 inst.instruction &= 0xff0fff0f;
8017 inst.instruction |= wrn;
8018 /* Bail out here; the instruction is now assembled. */
8019 return;
8020 }
8021 }
8022 }
8023 /* Map 32 -> 0, etc. */
8024 inst.operands[2].imm &= 0x1f;
8025 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8026 }
8027 }
8028 \f
8029 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8030 operations first, then control, shift, and load/store. */
8031
8032 /* Insns like "foo X,Y,Z". */
8033
8034 static void
8035 do_mav_triple (void)
8036 {
8037 inst.instruction |= inst.operands[0].reg << 16;
8038 inst.instruction |= inst.operands[1].reg;
8039 inst.instruction |= inst.operands[2].reg << 12;
8040 }
8041
8042 /* Insns like "foo W,X,Y,Z".
8043 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
8044
8045 static void
8046 do_mav_quad (void)
8047 {
8048 inst.instruction |= inst.operands[0].reg << 5;
8049 inst.instruction |= inst.operands[1].reg << 12;
8050 inst.instruction |= inst.operands[2].reg << 16;
8051 inst.instruction |= inst.operands[3].reg;
8052 }
8053
8054 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8055 static void
8056 do_mav_dspsc (void)
8057 {
8058 inst.instruction |= inst.operands[1].reg << 12;
8059 }
8060
8061 /* Maverick shift immediate instructions.
8062 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8063 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
8064
8065 static void
8066 do_mav_shift (void)
8067 {
8068 int imm = inst.operands[2].imm;
8069
8070 inst.instruction |= inst.operands[0].reg << 12;
8071 inst.instruction |= inst.operands[1].reg << 16;
8072
8073 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8074 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8075 Bit 4 should be 0. */
8076 imm = (imm & 0xf) | ((imm & 0x70) << 1);
8077
8078 inst.instruction |= imm;
8079 }
8080 \f
8081 /* XScale instructions. Also sorted arithmetic before move. */
8082
8083 /* Xscale multiply-accumulate (argument parse)
8084 MIAcc acc0,Rm,Rs
8085 MIAPHcc acc0,Rm,Rs
8086 MIAxycc acc0,Rm,Rs. */
8087
8088 static void
8089 do_xsc_mia (void)
8090 {
8091 inst.instruction |= inst.operands[1].reg;
8092 inst.instruction |= inst.operands[2].reg << 12;
8093 }
8094
8095 /* Xscale move-accumulator-register (argument parse)
8096
8097 MARcc acc0,RdLo,RdHi. */
8098
8099 static void
8100 do_xsc_mar (void)
8101 {
8102 inst.instruction |= inst.operands[1].reg << 12;
8103 inst.instruction |= inst.operands[2].reg << 16;
8104 }
8105
8106 /* Xscale move-register-accumulator (argument parse)
8107
8108 MRAcc RdLo,RdHi,acc0. */
8109
8110 static void
8111 do_xsc_mra (void)
8112 {
8113 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8114 inst.instruction |= inst.operands[0].reg << 12;
8115 inst.instruction |= inst.operands[1].reg << 16;
8116 }
8117 \f
8118 /* Encoding functions relevant only to Thumb. */
8119
8120 /* inst.operands[i] is a shifted-register operand; encode
8121 it into inst.instruction in the format used by Thumb32. */
8122
8123 static void
8124 encode_thumb32_shifted_operand (int i)
8125 {
8126 unsigned int value = inst.reloc.exp.X_add_number;
8127 unsigned int shift = inst.operands[i].shift_kind;
8128
8129 constraint (inst.operands[i].immisreg,
8130 _("shift by register not allowed in thumb mode"));
8131 inst.instruction |= inst.operands[i].reg;
8132 if (shift == SHIFT_RRX)
8133 inst.instruction |= SHIFT_ROR << 4;
8134 else
8135 {
8136 constraint (inst.reloc.exp.X_op != O_constant,
8137 _("expression too complex"));
8138
8139 constraint (value > 32
8140 || (value == 32 && (shift == SHIFT_LSL
8141 || shift == SHIFT_ROR)),
8142 _("shift expression is too large"));
8143
8144 if (value == 0)
8145 shift = SHIFT_LSL;
8146 else if (value == 32)
8147 value = 0;
8148
8149 inst.instruction |= shift << 4;
8150 inst.instruction |= (value & 0x1c) << 10;
8151 inst.instruction |= (value & 0x03) << 6;
8152 }
8153 }
8154
8155
8156 /* inst.operands[i] was set up by parse_address. Encode it into a
8157 Thumb32 format load or store instruction. Reject forms that cannot
8158 be used with such instructions. If is_t is true, reject forms that
8159 cannot be used with a T instruction; if is_d is true, reject forms
8160 that cannot be used with a D instruction. */
8161
8162 static void
8163 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8164 {
8165 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8166
8167 constraint (!inst.operands[i].isreg,
8168 _("Instruction does not support =N addresses"));
8169
8170 inst.instruction |= inst.operands[i].reg << 16;
8171 if (inst.operands[i].immisreg)
8172 {
8173 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
8174 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8175 constraint (inst.operands[i].negative,
8176 _("Thumb does not support negative register indexing"));
8177 constraint (inst.operands[i].postind,
8178 _("Thumb does not support register post-indexing"));
8179 constraint (inst.operands[i].writeback,
8180 _("Thumb does not support register indexing with writeback"));
8181 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8182 _("Thumb supports only LSL in shifted register indexing"));
8183
8184 inst.instruction |= inst.operands[i].imm;
8185 if (inst.operands[i].shifted)
8186 {
8187 constraint (inst.reloc.exp.X_op != O_constant,
8188 _("expression too complex"));
8189 constraint (inst.reloc.exp.X_add_number < 0
8190 || inst.reloc.exp.X_add_number > 3,
8191 _("shift out of range"));
8192 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8193 }
8194 inst.reloc.type = BFD_RELOC_UNUSED;
8195 }
8196 else if (inst.operands[i].preind)
8197 {
8198 constraint (is_pc && inst.operands[i].writeback,
8199 _("cannot use writeback with PC-relative addressing"));
8200 constraint (is_t && inst.operands[i].writeback,
8201 _("cannot use writeback with this instruction"));
8202
8203 if (is_d)
8204 {
8205 inst.instruction |= 0x01000000;
8206 if (inst.operands[i].writeback)
8207 inst.instruction |= 0x00200000;
8208 }
8209 else
8210 {
8211 inst.instruction |= 0x00000c00;
8212 if (inst.operands[i].writeback)
8213 inst.instruction |= 0x00000100;
8214 }
8215 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8216 }
8217 else if (inst.operands[i].postind)
8218 {
8219 assert (inst.operands[i].writeback);
8220 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8221 constraint (is_t, _("cannot use post-indexing with this instruction"));
8222
8223 if (is_d)
8224 inst.instruction |= 0x00200000;
8225 else
8226 inst.instruction |= 0x00000900;
8227 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8228 }
8229 else /* unindexed - only for coprocessor */
8230 inst.error = _("instruction does not accept unindexed addressing");
8231 }
8232
8233 /* Table of Thumb instructions which exist in both 16- and 32-bit
8234 encodings (the latter only in post-V6T2 cores). The index is the
8235 value used in the insns table below. When there is more than one
8236 possible 16-bit encoding for the instruction, this table always
8237 holds variant (1).
8238 Also contains several pseudo-instructions used during relaxation. */
8239 #define T16_32_TAB \
8240 X(adc, 4140, eb400000), \
8241 X(adcs, 4140, eb500000), \
8242 X(add, 1c00, eb000000), \
8243 X(adds, 1c00, eb100000), \
8244 X(addi, 0000, f1000000), \
8245 X(addis, 0000, f1100000), \
8246 X(add_pc,000f, f20f0000), \
8247 X(add_sp,000d, f10d0000), \
8248 X(adr, 000f, f20f0000), \
8249 X(and, 4000, ea000000), \
8250 X(ands, 4000, ea100000), \
8251 X(asr, 1000, fa40f000), \
8252 X(asrs, 1000, fa50f000), \
8253 X(b, e000, f000b000), \
8254 X(bcond, d000, f0008000), \
8255 X(bic, 4380, ea200000), \
8256 X(bics, 4380, ea300000), \
8257 X(cmn, 42c0, eb100f00), \
8258 X(cmp, 2800, ebb00f00), \
8259 X(cpsie, b660, f3af8400), \
8260 X(cpsid, b670, f3af8600), \
8261 X(cpy, 4600, ea4f0000), \
8262 X(dec_sp,80dd, f1ad0d00), \
8263 X(eor, 4040, ea800000), \
8264 X(eors, 4040, ea900000), \
8265 X(inc_sp,00dd, f10d0d00), \
8266 X(ldmia, c800, e8900000), \
8267 X(ldr, 6800, f8500000), \
8268 X(ldrb, 7800, f8100000), \
8269 X(ldrh, 8800, f8300000), \
8270 X(ldrsb, 5600, f9100000), \
8271 X(ldrsh, 5e00, f9300000), \
8272 X(ldr_pc,4800, f85f0000), \
8273 X(ldr_pc2,4800, f85f0000), \
8274 X(ldr_sp,9800, f85d0000), \
8275 X(lsl, 0000, fa00f000), \
8276 X(lsls, 0000, fa10f000), \
8277 X(lsr, 0800, fa20f000), \
8278 X(lsrs, 0800, fa30f000), \
8279 X(mov, 2000, ea4f0000), \
8280 X(movs, 2000, ea5f0000), \
8281 X(mul, 4340, fb00f000), \
8282 X(muls, 4340, ffffffff), /* no 32b muls */ \
8283 X(mvn, 43c0, ea6f0000), \
8284 X(mvns, 43c0, ea7f0000), \
8285 X(neg, 4240, f1c00000), /* rsb #0 */ \
8286 X(negs, 4240, f1d00000), /* rsbs #0 */ \
8287 X(orr, 4300, ea400000), \
8288 X(orrs, 4300, ea500000), \
8289 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8290 X(push, b400, e92d0000), /* stmdb sp!,... */ \
8291 X(rev, ba00, fa90f080), \
8292 X(rev16, ba40, fa90f090), \
8293 X(revsh, bac0, fa90f0b0), \
8294 X(ror, 41c0, fa60f000), \
8295 X(rors, 41c0, fa70f000), \
8296 X(sbc, 4180, eb600000), \
8297 X(sbcs, 4180, eb700000), \
8298 X(stmia, c000, e8800000), \
8299 X(str, 6000, f8400000), \
8300 X(strb, 7000, f8000000), \
8301 X(strh, 8000, f8200000), \
8302 X(str_sp,9000, f84d0000), \
8303 X(sub, 1e00, eba00000), \
8304 X(subs, 1e00, ebb00000), \
8305 X(subi, 8000, f1a00000), \
8306 X(subis, 8000, f1b00000), \
8307 X(sxtb, b240, fa4ff080), \
8308 X(sxth, b200, fa0ff080), \
8309 X(tst, 4200, ea100f00), \
8310 X(uxtb, b2c0, fa5ff080), \
8311 X(uxth, b280, fa1ff080), \
8312 X(nop, bf00, f3af8000), \
8313 X(yield, bf10, f3af8001), \
8314 X(wfe, bf20, f3af8002), \
8315 X(wfi, bf30, f3af8003), \
8316 X(sev, bf40, f3af9004), /* typo, 8004? */
8317
8318 /* To catch errors in encoding functions, the codes are all offset by
8319 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8320 as 16-bit instructions. */
8321 #define X(a,b,c) T_MNEM_##a
8322 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8323 #undef X
8324
8325 #define X(a,b,c) 0x##b
8326 static const unsigned short thumb_op16[] = { T16_32_TAB };
8327 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8328 #undef X
8329
8330 #define X(a,b,c) 0x##c
8331 static const unsigned int thumb_op32[] = { T16_32_TAB };
8332 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8333 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
8334 #undef X
8335 #undef T16_32_TAB
8336
8337 /* Thumb instruction encoders, in alphabetical order. */
8338
8339 /* ADDW or SUBW. */
8340 static void
8341 do_t_add_sub_w (void)
8342 {
8343 int Rd, Rn;
8344
8345 Rd = inst.operands[0].reg;
8346 Rn = inst.operands[1].reg;
8347
8348 constraint (Rd == 15, _("PC not allowed as destination"));
8349 inst.instruction |= (Rn << 16) | (Rd << 8);
8350 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8351 }
8352
8353 /* Parse an add or subtract instruction. We get here with inst.instruction
8354 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8355
8356 static void
8357 do_t_add_sub (void)
8358 {
8359 int Rd, Rs, Rn;
8360
8361 Rd = inst.operands[0].reg;
8362 Rs = (inst.operands[1].present
8363 ? inst.operands[1].reg /* Rd, Rs, foo */
8364 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8365
8366 if (unified_syntax)
8367 {
8368 bfd_boolean flags;
8369 bfd_boolean narrow;
8370 int opcode;
8371
8372 flags = (inst.instruction == T_MNEM_adds
8373 || inst.instruction == T_MNEM_subs);
8374 if (flags)
8375 narrow = (current_it_mask == 0);
8376 else
8377 narrow = (current_it_mask != 0);
8378 if (!inst.operands[2].isreg)
8379 {
8380 int add;
8381
8382 add = (inst.instruction == T_MNEM_add
8383 || inst.instruction == T_MNEM_adds);
8384 opcode = 0;
8385 if (inst.size_req != 4)
8386 {
8387 /* Attempt to use a narrow opcode, with relaxation if
8388 appropriate. */
8389 if (Rd == REG_SP && Rs == REG_SP && !flags)
8390 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8391 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8392 opcode = T_MNEM_add_sp;
8393 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8394 opcode = T_MNEM_add_pc;
8395 else if (Rd <= 7 && Rs <= 7 && narrow)
8396 {
8397 if (flags)
8398 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8399 else
8400 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8401 }
8402 if (opcode)
8403 {
8404 inst.instruction = THUMB_OP16(opcode);
8405 inst.instruction |= (Rd << 4) | Rs;
8406 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8407 if (inst.size_req != 2)
8408 inst.relax = opcode;
8409 }
8410 else
8411 constraint (inst.size_req == 2, BAD_HIREG);
8412 }
8413 if (inst.size_req == 4
8414 || (inst.size_req != 2 && !opcode))
8415 {
8416 if (Rs == REG_PC)
8417 {
8418 /* Always use addw/subw. */
8419 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8420 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8421 }
8422 else
8423 {
8424 inst.instruction = THUMB_OP32 (inst.instruction);
8425 inst.instruction = (inst.instruction & 0xe1ffffff)
8426 | 0x10000000;
8427 if (flags)
8428 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8429 else
8430 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
8431 }
8432 inst.instruction |= Rd << 8;
8433 inst.instruction |= Rs << 16;
8434 }
8435 }
8436 else
8437 {
8438 Rn = inst.operands[2].reg;
8439 /* See if we can do this with a 16-bit instruction. */
8440 if (!inst.operands[2].shifted && inst.size_req != 4)
8441 {
8442 if (Rd > 7 || Rs > 7 || Rn > 7)
8443 narrow = FALSE;
8444
8445 if (narrow)
8446 {
8447 inst.instruction = ((inst.instruction == T_MNEM_adds
8448 || inst.instruction == T_MNEM_add)
8449 ? T_OPCODE_ADD_R3
8450 : T_OPCODE_SUB_R3);
8451 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8452 return;
8453 }
8454
8455 if (inst.instruction == T_MNEM_add)
8456 {
8457 if (Rd == Rs)
8458 {
8459 inst.instruction = T_OPCODE_ADD_HI;
8460 inst.instruction |= (Rd & 8) << 4;
8461 inst.instruction |= (Rd & 7);
8462 inst.instruction |= Rn << 3;
8463 return;
8464 }
8465 /* ... because addition is commutative! */
8466 else if (Rd == Rn)
8467 {
8468 inst.instruction = T_OPCODE_ADD_HI;
8469 inst.instruction |= (Rd & 8) << 4;
8470 inst.instruction |= (Rd & 7);
8471 inst.instruction |= Rs << 3;
8472 return;
8473 }
8474 }
8475 }
8476 /* If we get here, it can't be done in 16 bits. */
8477 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
8478 _("shift must be constant"));
8479 inst.instruction = THUMB_OP32 (inst.instruction);
8480 inst.instruction |= Rd << 8;
8481 inst.instruction |= Rs << 16;
8482 encode_thumb32_shifted_operand (2);
8483 }
8484 }
8485 else
8486 {
8487 constraint (inst.instruction == T_MNEM_adds
8488 || inst.instruction == T_MNEM_subs,
8489 BAD_THUMB32);
8490
8491 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
8492 {
8493 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
8494 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
8495 BAD_HIREG);
8496
8497 inst.instruction = (inst.instruction == T_MNEM_add
8498 ? 0x0000 : 0x8000);
8499 inst.instruction |= (Rd << 4) | Rs;
8500 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8501 return;
8502 }
8503
8504 Rn = inst.operands[2].reg;
8505 constraint (inst.operands[2].shifted, _("unshifted register required"));
8506
8507 /* We now have Rd, Rs, and Rn set to registers. */
8508 if (Rd > 7 || Rs > 7 || Rn > 7)
8509 {
8510 /* Can't do this for SUB. */
8511 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
8512 inst.instruction = T_OPCODE_ADD_HI;
8513 inst.instruction |= (Rd & 8) << 4;
8514 inst.instruction |= (Rd & 7);
8515 if (Rs == Rd)
8516 inst.instruction |= Rn << 3;
8517 else if (Rn == Rd)
8518 inst.instruction |= Rs << 3;
8519 else
8520 constraint (1, _("dest must overlap one source register"));
8521 }
8522 else
8523 {
8524 inst.instruction = (inst.instruction == T_MNEM_add
8525 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
8526 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8527 }
8528 }
8529 }
8530
8531 static void
8532 do_t_adr (void)
8533 {
8534 if (unified_syntax && inst.size_req == 0 && inst.operands[0].reg <= 7)
8535 {
8536 /* Defer to section relaxation. */
8537 inst.relax = inst.instruction;
8538 inst.instruction = THUMB_OP16 (inst.instruction);
8539 inst.instruction |= inst.operands[0].reg << 4;
8540 }
8541 else if (unified_syntax && inst.size_req != 2)
8542 {
8543 /* Generate a 32-bit opcode. */
8544 inst.instruction = THUMB_OP32 (inst.instruction);
8545 inst.instruction |= inst.operands[0].reg << 8;
8546 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
8547 inst.reloc.pc_rel = 1;
8548 }
8549 else
8550 {
8551 /* Generate a 16-bit opcode. */
8552 inst.instruction = THUMB_OP16 (inst.instruction);
8553 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8554 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
8555 inst.reloc.pc_rel = 1;
8556
8557 inst.instruction |= inst.operands[0].reg << 4;
8558 }
8559 }
8560
8561 /* Arithmetic instructions for which there is just one 16-bit
8562 instruction encoding, and it allows only two low registers.
8563 For maximal compatibility with ARM syntax, we allow three register
8564 operands even when Thumb-32 instructions are not available, as long
8565 as the first two are identical. For instance, both "sbc r0,r1" and
8566 "sbc r0,r0,r1" are allowed. */
8567 static void
8568 do_t_arit3 (void)
8569 {
8570 int Rd, Rs, Rn;
8571
8572 Rd = inst.operands[0].reg;
8573 Rs = (inst.operands[1].present
8574 ? inst.operands[1].reg /* Rd, Rs, foo */
8575 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8576 Rn = inst.operands[2].reg;
8577
8578 if (unified_syntax)
8579 {
8580 if (!inst.operands[2].isreg)
8581 {
8582 /* For an immediate, we always generate a 32-bit opcode;
8583 section relaxation will shrink it later if possible. */
8584 inst.instruction = THUMB_OP32 (inst.instruction);
8585 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8586 inst.instruction |= Rd << 8;
8587 inst.instruction |= Rs << 16;
8588 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8589 }
8590 else
8591 {
8592 bfd_boolean narrow;
8593
8594 /* See if we can do this with a 16-bit instruction. */
8595 if (THUMB_SETS_FLAGS (inst.instruction))
8596 narrow = current_it_mask == 0;
8597 else
8598 narrow = current_it_mask != 0;
8599
8600 if (Rd > 7 || Rn > 7 || Rs > 7)
8601 narrow = FALSE;
8602 if (inst.operands[2].shifted)
8603 narrow = FALSE;
8604 if (inst.size_req == 4)
8605 narrow = FALSE;
8606
8607 if (narrow
8608 && Rd == Rs)
8609 {
8610 inst.instruction = THUMB_OP16 (inst.instruction);
8611 inst.instruction |= Rd;
8612 inst.instruction |= Rn << 3;
8613 return;
8614 }
8615
8616 /* If we get here, it can't be done in 16 bits. */
8617 constraint (inst.operands[2].shifted
8618 && inst.operands[2].immisreg,
8619 _("shift must be constant"));
8620 inst.instruction = THUMB_OP32 (inst.instruction);
8621 inst.instruction |= Rd << 8;
8622 inst.instruction |= Rs << 16;
8623 encode_thumb32_shifted_operand (2);
8624 }
8625 }
8626 else
8627 {
8628 /* On its face this is a lie - the instruction does set the
8629 flags. However, the only supported mnemonic in this mode
8630 says it doesn't. */
8631 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
8632
8633 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8634 _("unshifted register required"));
8635 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8636 constraint (Rd != Rs,
8637 _("dest and source1 must be the same register"));
8638
8639 inst.instruction = THUMB_OP16 (inst.instruction);
8640 inst.instruction |= Rd;
8641 inst.instruction |= Rn << 3;
8642 }
8643 }
8644
8645 /* Similarly, but for instructions where the arithmetic operation is
8646 commutative, so we can allow either of them to be different from
8647 the destination operand in a 16-bit instruction. For instance, all
8648 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
8649 accepted. */
8650 static void
8651 do_t_arit3c (void)
8652 {
8653 int Rd, Rs, Rn;
8654
8655 Rd = inst.operands[0].reg;
8656 Rs = (inst.operands[1].present
8657 ? inst.operands[1].reg /* Rd, Rs, foo */
8658 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8659 Rn = inst.operands[2].reg;
8660
8661 if (unified_syntax)
8662 {
8663 if (!inst.operands[2].isreg)
8664 {
8665 /* For an immediate, we always generate a 32-bit opcode;
8666 section relaxation will shrink it later if possible. */
8667 inst.instruction = THUMB_OP32 (inst.instruction);
8668 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8669 inst.instruction |= Rd << 8;
8670 inst.instruction |= Rs << 16;
8671 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8672 }
8673 else
8674 {
8675 bfd_boolean narrow;
8676
8677 /* See if we can do this with a 16-bit instruction. */
8678 if (THUMB_SETS_FLAGS (inst.instruction))
8679 narrow = current_it_mask == 0;
8680 else
8681 narrow = current_it_mask != 0;
8682
8683 if (Rd > 7 || Rn > 7 || Rs > 7)
8684 narrow = FALSE;
8685 if (inst.operands[2].shifted)
8686 narrow = FALSE;
8687 if (inst.size_req == 4)
8688 narrow = FALSE;
8689
8690 if (narrow)
8691 {
8692 if (Rd == Rs)
8693 {
8694 inst.instruction = THUMB_OP16 (inst.instruction);
8695 inst.instruction |= Rd;
8696 inst.instruction |= Rn << 3;
8697 return;
8698 }
8699 if (Rd == Rn)
8700 {
8701 inst.instruction = THUMB_OP16 (inst.instruction);
8702 inst.instruction |= Rd;
8703 inst.instruction |= Rs << 3;
8704 return;
8705 }
8706 }
8707
8708 /* If we get here, it can't be done in 16 bits. */
8709 constraint (inst.operands[2].shifted
8710 && inst.operands[2].immisreg,
8711 _("shift must be constant"));
8712 inst.instruction = THUMB_OP32 (inst.instruction);
8713 inst.instruction |= Rd << 8;
8714 inst.instruction |= Rs << 16;
8715 encode_thumb32_shifted_operand (2);
8716 }
8717 }
8718 else
8719 {
8720 /* On its face this is a lie - the instruction does set the
8721 flags. However, the only supported mnemonic in this mode
8722 says it doesn't. */
8723 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
8724
8725 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8726 _("unshifted register required"));
8727 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8728
8729 inst.instruction = THUMB_OP16 (inst.instruction);
8730 inst.instruction |= Rd;
8731
8732 if (Rd == Rs)
8733 inst.instruction |= Rn << 3;
8734 else if (Rd == Rn)
8735 inst.instruction |= Rs << 3;
8736 else
8737 constraint (1, _("dest must overlap one source register"));
8738 }
8739 }
8740
8741 static void
8742 do_t_barrier (void)
8743 {
8744 if (inst.operands[0].present)
8745 {
8746 constraint ((inst.instruction & 0xf0) != 0x40
8747 && inst.operands[0].imm != 0xf,
8748 "bad barrier type");
8749 inst.instruction |= inst.operands[0].imm;
8750 }
8751 else
8752 inst.instruction |= 0xf;
8753 }
8754
8755 static void
8756 do_t_bfc (void)
8757 {
8758 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8759 constraint (msb > 32, _("bit-field extends past end of register"));
8760 /* The instruction encoding stores the LSB and MSB,
8761 not the LSB and width. */
8762 inst.instruction |= inst.operands[0].reg << 8;
8763 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
8764 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
8765 inst.instruction |= msb - 1;
8766 }
8767
8768 static void
8769 do_t_bfi (void)
8770 {
8771 unsigned int msb;
8772
8773 /* #0 in second position is alternative syntax for bfc, which is
8774 the same instruction but with REG_PC in the Rm field. */
8775 if (!inst.operands[1].isreg)
8776 inst.operands[1].reg = REG_PC;
8777
8778 msb = inst.operands[2].imm + inst.operands[3].imm;
8779 constraint (msb > 32, _("bit-field extends past end of register"));
8780 /* The instruction encoding stores the LSB and MSB,
8781 not the LSB and width. */
8782 inst.instruction |= inst.operands[0].reg << 8;
8783 inst.instruction |= inst.operands[1].reg << 16;
8784 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8785 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8786 inst.instruction |= msb - 1;
8787 }
8788
8789 static void
8790 do_t_bfx (void)
8791 {
8792 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8793 _("bit-field extends past end of register"));
8794 inst.instruction |= inst.operands[0].reg << 8;
8795 inst.instruction |= inst.operands[1].reg << 16;
8796 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8797 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8798 inst.instruction |= inst.operands[3].imm - 1;
8799 }
8800
8801 /* ARM V5 Thumb BLX (argument parse)
8802 BLX <target_addr> which is BLX(1)
8803 BLX <Rm> which is BLX(2)
8804 Unfortunately, there are two different opcodes for this mnemonic.
8805 So, the insns[].value is not used, and the code here zaps values
8806 into inst.instruction.
8807
8808 ??? How to take advantage of the additional two bits of displacement
8809 available in Thumb32 mode? Need new relocation? */
8810
8811 static void
8812 do_t_blx (void)
8813 {
8814 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8815 if (inst.operands[0].isreg)
8816 /* We have a register, so this is BLX(2). */
8817 inst.instruction |= inst.operands[0].reg << 3;
8818 else
8819 {
8820 /* No register. This must be BLX(1). */
8821 inst.instruction = 0xf000e800;
8822 #ifdef OBJ_ELF
8823 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8824 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
8825 else
8826 #endif
8827 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
8828 inst.reloc.pc_rel = 1;
8829 }
8830 }
8831
8832 static void
8833 do_t_branch (void)
8834 {
8835 int opcode;
8836 int cond;
8837
8838 if (current_it_mask)
8839 {
8840 /* Conditional branches inside IT blocks are encoded as unconditional
8841 branches. */
8842 cond = COND_ALWAYS;
8843 /* A branch must be the last instruction in an IT block. */
8844 constraint (current_it_mask != 0x10, BAD_BRANCH);
8845 }
8846 else
8847 cond = inst.cond;
8848
8849 if (cond != COND_ALWAYS)
8850 opcode = T_MNEM_bcond;
8851 else
8852 opcode = inst.instruction;
8853
8854 if (unified_syntax && inst.size_req == 4)
8855 {
8856 inst.instruction = THUMB_OP32(opcode);
8857 if (cond == COND_ALWAYS)
8858 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
8859 else
8860 {
8861 assert (cond != 0xF);
8862 inst.instruction |= cond << 22;
8863 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
8864 }
8865 }
8866 else
8867 {
8868 inst.instruction = THUMB_OP16(opcode);
8869 if (cond == COND_ALWAYS)
8870 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
8871 else
8872 {
8873 inst.instruction |= cond << 8;
8874 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
8875 }
8876 /* Allow section relaxation. */
8877 if (unified_syntax && inst.size_req != 2)
8878 inst.relax = opcode;
8879 }
8880
8881 inst.reloc.pc_rel = 1;
8882 }
8883
8884 static void
8885 do_t_bkpt (void)
8886 {
8887 constraint (inst.cond != COND_ALWAYS,
8888 _("instruction is always unconditional"));
8889 if (inst.operands[0].present)
8890 {
8891 constraint (inst.operands[0].imm > 255,
8892 _("immediate value out of range"));
8893 inst.instruction |= inst.operands[0].imm;
8894 }
8895 }
8896
8897 static void
8898 do_t_branch23 (void)
8899 {
8900 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8901 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
8902 inst.reloc.pc_rel = 1;
8903
8904 /* If the destination of the branch is a defined symbol which does not have
8905 the THUMB_FUNC attribute, then we must be calling a function which has
8906 the (interfacearm) attribute. We look for the Thumb entry point to that
8907 function and change the branch to refer to that function instead. */
8908 if ( inst.reloc.exp.X_op == O_symbol
8909 && inst.reloc.exp.X_add_symbol != NULL
8910 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8911 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8912 inst.reloc.exp.X_add_symbol =
8913 find_real_start (inst.reloc.exp.X_add_symbol);
8914 }
8915
8916 static void
8917 do_t_bx (void)
8918 {
8919 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8920 inst.instruction |= inst.operands[0].reg << 3;
8921 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
8922 should cause the alignment to be checked once it is known. This is
8923 because BX PC only works if the instruction is word aligned. */
8924 }
8925
8926 static void
8927 do_t_bxj (void)
8928 {
8929 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8930 if (inst.operands[0].reg == REG_PC)
8931 as_tsktsk (_("use of r15 in bxj is not really useful"));
8932
8933 inst.instruction |= inst.operands[0].reg << 16;
8934 }
8935
8936 static void
8937 do_t_clz (void)
8938 {
8939 inst.instruction |= inst.operands[0].reg << 8;
8940 inst.instruction |= inst.operands[1].reg << 16;
8941 inst.instruction |= inst.operands[1].reg;
8942 }
8943
8944 static void
8945 do_t_cps (void)
8946 {
8947 constraint (current_it_mask, BAD_NOT_IT);
8948 inst.instruction |= inst.operands[0].imm;
8949 }
8950
8951 static void
8952 do_t_cpsi (void)
8953 {
8954 constraint (current_it_mask, BAD_NOT_IT);
8955 if (unified_syntax
8956 && (inst.operands[1].present || inst.size_req == 4)
8957 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
8958 {
8959 unsigned int imod = (inst.instruction & 0x0030) >> 4;
8960 inst.instruction = 0xf3af8000;
8961 inst.instruction |= imod << 9;
8962 inst.instruction |= inst.operands[0].imm << 5;
8963 if (inst.operands[1].present)
8964 inst.instruction |= 0x100 | inst.operands[1].imm;
8965 }
8966 else
8967 {
8968 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
8969 && (inst.operands[0].imm & 4),
8970 _("selected processor does not support 'A' form "
8971 "of this instruction"));
8972 constraint (inst.operands[1].present || inst.size_req == 4,
8973 _("Thumb does not support the 2-argument "
8974 "form of this instruction"));
8975 inst.instruction |= inst.operands[0].imm;
8976 }
8977 }
8978
8979 /* THUMB CPY instruction (argument parse). */
8980
8981 static void
8982 do_t_cpy (void)
8983 {
8984 if (inst.size_req == 4)
8985 {
8986 inst.instruction = THUMB_OP32 (T_MNEM_mov);
8987 inst.instruction |= inst.operands[0].reg << 8;
8988 inst.instruction |= inst.operands[1].reg;
8989 }
8990 else
8991 {
8992 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
8993 inst.instruction |= (inst.operands[0].reg & 0x7);
8994 inst.instruction |= inst.operands[1].reg << 3;
8995 }
8996 }
8997
8998 static void
8999 do_t_cbz (void)
9000 {
9001 constraint (current_it_mask, BAD_NOT_IT);
9002 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9003 inst.instruction |= inst.operands[0].reg;
9004 inst.reloc.pc_rel = 1;
9005 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9006 }
9007
9008 static void
9009 do_t_dbg (void)
9010 {
9011 inst.instruction |= inst.operands[0].imm;
9012 }
9013
9014 static void
9015 do_t_div (void)
9016 {
9017 if (!inst.operands[1].present)
9018 inst.operands[1].reg = inst.operands[0].reg;
9019 inst.instruction |= inst.operands[0].reg << 8;
9020 inst.instruction |= inst.operands[1].reg << 16;
9021 inst.instruction |= inst.operands[2].reg;
9022 }
9023
9024 static void
9025 do_t_hint (void)
9026 {
9027 if (unified_syntax && inst.size_req == 4)
9028 inst.instruction = THUMB_OP32 (inst.instruction);
9029 else
9030 inst.instruction = THUMB_OP16 (inst.instruction);
9031 }
9032
9033 static void
9034 do_t_it (void)
9035 {
9036 unsigned int cond = inst.operands[0].imm;
9037
9038 constraint (current_it_mask, BAD_NOT_IT);
9039 current_it_mask = (inst.instruction & 0xf) | 0x10;
9040 current_cc = cond;
9041
9042 /* If the condition is a negative condition, invert the mask. */
9043 if ((cond & 0x1) == 0x0)
9044 {
9045 unsigned int mask = inst.instruction & 0x000f;
9046
9047 if ((mask & 0x7) == 0)
9048 /* no conversion needed */;
9049 else if ((mask & 0x3) == 0)
9050 mask ^= 0x8;
9051 else if ((mask & 0x1) == 0)
9052 mask ^= 0xC;
9053 else
9054 mask ^= 0xE;
9055
9056 inst.instruction &= 0xfff0;
9057 inst.instruction |= mask;
9058 }
9059
9060 inst.instruction |= cond << 4;
9061 }
9062
9063 static void
9064 do_t_ldmstm (void)
9065 {
9066 /* This really doesn't seem worth it. */
9067 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9068 _("expression too complex"));
9069 constraint (inst.operands[1].writeback,
9070 _("Thumb load/store multiple does not support {reglist}^"));
9071
9072 if (unified_syntax)
9073 {
9074 /* See if we can use a 16-bit instruction. */
9075 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9076 && inst.size_req != 4
9077 && inst.operands[0].reg <= 7
9078 && !(inst.operands[1].imm & ~0xff)
9079 && (inst.instruction == T_MNEM_stmia
9080 ? inst.operands[0].writeback
9081 : (inst.operands[0].writeback
9082 == !(inst.operands[1].imm & (1 << inst.operands[0].reg)))))
9083 {
9084 if (inst.instruction == T_MNEM_stmia
9085 && (inst.operands[1].imm & (1 << inst.operands[0].reg))
9086 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9087 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9088 inst.operands[0].reg);
9089
9090 inst.instruction = THUMB_OP16 (inst.instruction);
9091 inst.instruction |= inst.operands[0].reg << 8;
9092 inst.instruction |= inst.operands[1].imm;
9093 }
9094 else
9095 {
9096 if (inst.operands[1].imm & (1 << 13))
9097 as_warn (_("SP should not be in register list"));
9098 if (inst.instruction == T_MNEM_stmia)
9099 {
9100 if (inst.operands[1].imm & (1 << 15))
9101 as_warn (_("PC should not be in register list"));
9102 if (inst.operands[1].imm & (1 << inst.operands[0].reg))
9103 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9104 inst.operands[0].reg);
9105 }
9106 else
9107 {
9108 if (inst.operands[1].imm & (1 << 14)
9109 && inst.operands[1].imm & (1 << 15))
9110 as_warn (_("LR and PC should not both be in register list"));
9111 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9112 && inst.operands[0].writeback)
9113 as_warn (_("base register should not be in register list "
9114 "when written back"));
9115 }
9116 if (inst.instruction < 0xffff)
9117 inst.instruction = THUMB_OP32 (inst.instruction);
9118 inst.instruction |= inst.operands[0].reg << 16;
9119 inst.instruction |= inst.operands[1].imm;
9120 if (inst.operands[0].writeback)
9121 inst.instruction |= WRITE_BACK;
9122 }
9123 }
9124 else
9125 {
9126 constraint (inst.operands[0].reg > 7
9127 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
9128 constraint (inst.instruction != T_MNEM_ldmia
9129 && inst.instruction != T_MNEM_stmia,
9130 _("Thumb-2 instruction only valid in unified syntax"));
9131 if (inst.instruction == T_MNEM_stmia)
9132 {
9133 if (!inst.operands[0].writeback)
9134 as_warn (_("this instruction will write back the base register"));
9135 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9136 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9137 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9138 inst.operands[0].reg);
9139 }
9140 else
9141 {
9142 if (!inst.operands[0].writeback
9143 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9144 as_warn (_("this instruction will write back the base register"));
9145 else if (inst.operands[0].writeback
9146 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9147 as_warn (_("this instruction will not write back the base register"));
9148 }
9149
9150 inst.instruction = THUMB_OP16 (inst.instruction);
9151 inst.instruction |= inst.operands[0].reg << 8;
9152 inst.instruction |= inst.operands[1].imm;
9153 }
9154 }
9155
9156 static void
9157 do_t_ldrex (void)
9158 {
9159 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9160 || inst.operands[1].postind || inst.operands[1].writeback
9161 || inst.operands[1].immisreg || inst.operands[1].shifted
9162 || inst.operands[1].negative,
9163 BAD_ADDR_MODE);
9164
9165 inst.instruction |= inst.operands[0].reg << 12;
9166 inst.instruction |= inst.operands[1].reg << 16;
9167 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9168 }
9169
9170 static void
9171 do_t_ldrexd (void)
9172 {
9173 if (!inst.operands[1].present)
9174 {
9175 constraint (inst.operands[0].reg == REG_LR,
9176 _("r14 not allowed as first register "
9177 "when second register is omitted"));
9178 inst.operands[1].reg = inst.operands[0].reg + 1;
9179 }
9180 constraint (inst.operands[0].reg == inst.operands[1].reg,
9181 BAD_OVERLAP);
9182
9183 inst.instruction |= inst.operands[0].reg << 12;
9184 inst.instruction |= inst.operands[1].reg << 8;
9185 inst.instruction |= inst.operands[2].reg << 16;
9186 }
9187
9188 static void
9189 do_t_ldst (void)
9190 {
9191 unsigned long opcode;
9192 int Rn;
9193
9194 opcode = inst.instruction;
9195 if (unified_syntax)
9196 {
9197 if (!inst.operands[1].isreg)
9198 {
9199 if (opcode <= 0xffff)
9200 inst.instruction = THUMB_OP32 (opcode);
9201 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9202 return;
9203 }
9204 if (inst.operands[1].isreg
9205 && !inst.operands[1].writeback
9206 && !inst.operands[1].shifted && !inst.operands[1].postind
9207 && !inst.operands[1].negative && inst.operands[0].reg <= 7
9208 && opcode <= 0xffff
9209 && inst.size_req != 4)
9210 {
9211 /* Insn may have a 16-bit form. */
9212 Rn = inst.operands[1].reg;
9213 if (inst.operands[1].immisreg)
9214 {
9215 inst.instruction = THUMB_OP16 (opcode);
9216 /* [Rn, Ri] */
9217 if (Rn <= 7 && inst.operands[1].imm <= 7)
9218 goto op16;
9219 }
9220 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9221 && opcode != T_MNEM_ldrsb)
9222 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9223 || (Rn == REG_SP && opcode == T_MNEM_str))
9224 {
9225 /* [Rn, #const] */
9226 if (Rn > 7)
9227 {
9228 if (Rn == REG_PC)
9229 {
9230 if (inst.reloc.pc_rel)
9231 opcode = T_MNEM_ldr_pc2;
9232 else
9233 opcode = T_MNEM_ldr_pc;
9234 }
9235 else
9236 {
9237 if (opcode == T_MNEM_ldr)
9238 opcode = T_MNEM_ldr_sp;
9239 else
9240 opcode = T_MNEM_str_sp;
9241 }
9242 inst.instruction = inst.operands[0].reg << 8;
9243 }
9244 else
9245 {
9246 inst.instruction = inst.operands[0].reg;
9247 inst.instruction |= inst.operands[1].reg << 3;
9248 }
9249 inst.instruction |= THUMB_OP16 (opcode);
9250 if (inst.size_req == 2)
9251 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9252 else
9253 inst.relax = opcode;
9254 return;
9255 }
9256 }
9257 /* Definitely a 32-bit variant. */
9258 inst.instruction = THUMB_OP32 (opcode);
9259 inst.instruction |= inst.operands[0].reg << 12;
9260 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
9261 return;
9262 }
9263
9264 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9265
9266 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
9267 {
9268 /* Only [Rn,Rm] is acceptable. */
9269 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
9270 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
9271 || inst.operands[1].postind || inst.operands[1].shifted
9272 || inst.operands[1].negative,
9273 _("Thumb does not support this addressing mode"));
9274 inst.instruction = THUMB_OP16 (inst.instruction);
9275 goto op16;
9276 }
9277
9278 inst.instruction = THUMB_OP16 (inst.instruction);
9279 if (!inst.operands[1].isreg)
9280 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9281 return;
9282
9283 constraint (!inst.operands[1].preind
9284 || inst.operands[1].shifted
9285 || inst.operands[1].writeback,
9286 _("Thumb does not support this addressing mode"));
9287 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
9288 {
9289 constraint (inst.instruction & 0x0600,
9290 _("byte or halfword not valid for base register"));
9291 constraint (inst.operands[1].reg == REG_PC
9292 && !(inst.instruction & THUMB_LOAD_BIT),
9293 _("r15 based store not allowed"));
9294 constraint (inst.operands[1].immisreg,
9295 _("invalid base register for register offset"));
9296
9297 if (inst.operands[1].reg == REG_PC)
9298 inst.instruction = T_OPCODE_LDR_PC;
9299 else if (inst.instruction & THUMB_LOAD_BIT)
9300 inst.instruction = T_OPCODE_LDR_SP;
9301 else
9302 inst.instruction = T_OPCODE_STR_SP;
9303
9304 inst.instruction |= inst.operands[0].reg << 8;
9305 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9306 return;
9307 }
9308
9309 constraint (inst.operands[1].reg > 7, BAD_HIREG);
9310 if (!inst.operands[1].immisreg)
9311 {
9312 /* Immediate offset. */
9313 inst.instruction |= inst.operands[0].reg;
9314 inst.instruction |= inst.operands[1].reg << 3;
9315 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9316 return;
9317 }
9318
9319 /* Register offset. */
9320 constraint (inst.operands[1].imm > 7, BAD_HIREG);
9321 constraint (inst.operands[1].negative,
9322 _("Thumb does not support this addressing mode"));
9323
9324 op16:
9325 switch (inst.instruction)
9326 {
9327 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
9328 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
9329 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
9330 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
9331 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
9332 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
9333 case 0x5600 /* ldrsb */:
9334 case 0x5e00 /* ldrsh */: break;
9335 default: abort ();
9336 }
9337
9338 inst.instruction |= inst.operands[0].reg;
9339 inst.instruction |= inst.operands[1].reg << 3;
9340 inst.instruction |= inst.operands[1].imm << 6;
9341 }
9342
9343 static void
9344 do_t_ldstd (void)
9345 {
9346 if (!inst.operands[1].present)
9347 {
9348 inst.operands[1].reg = inst.operands[0].reg + 1;
9349 constraint (inst.operands[0].reg == REG_LR,
9350 _("r14 not allowed here"));
9351 }
9352 inst.instruction |= inst.operands[0].reg << 12;
9353 inst.instruction |= inst.operands[1].reg << 8;
9354 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
9355
9356 }
9357
9358 static void
9359 do_t_ldstt (void)
9360 {
9361 inst.instruction |= inst.operands[0].reg << 12;
9362 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
9363 }
9364
9365 static void
9366 do_t_mla (void)
9367 {
9368 inst.instruction |= inst.operands[0].reg << 8;
9369 inst.instruction |= inst.operands[1].reg << 16;
9370 inst.instruction |= inst.operands[2].reg;
9371 inst.instruction |= inst.operands[3].reg << 12;
9372 }
9373
9374 static void
9375 do_t_mlal (void)
9376 {
9377 inst.instruction |= inst.operands[0].reg << 12;
9378 inst.instruction |= inst.operands[1].reg << 8;
9379 inst.instruction |= inst.operands[2].reg << 16;
9380 inst.instruction |= inst.operands[3].reg;
9381 }
9382
9383 static void
9384 do_t_mov_cmp (void)
9385 {
9386 if (unified_syntax)
9387 {
9388 int r0off = (inst.instruction == T_MNEM_mov
9389 || inst.instruction == T_MNEM_movs) ? 8 : 16;
9390 unsigned long opcode;
9391 bfd_boolean narrow;
9392 bfd_boolean low_regs;
9393
9394 low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7);
9395 opcode = inst.instruction;
9396 if (current_it_mask)
9397 narrow = opcode != T_MNEM_movs;
9398 else
9399 narrow = opcode != T_MNEM_movs || low_regs;
9400 if (inst.size_req == 4
9401 || inst.operands[1].shifted)
9402 narrow = FALSE;
9403
9404 if (!inst.operands[1].isreg)
9405 {
9406 /* Immediate operand. */
9407 if (current_it_mask == 0 && opcode == T_MNEM_mov)
9408 narrow = 0;
9409 if (low_regs && narrow)
9410 {
9411 inst.instruction = THUMB_OP16 (opcode);
9412 inst.instruction |= inst.operands[0].reg << 8;
9413 if (inst.size_req == 2)
9414 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9415 else
9416 inst.relax = opcode;
9417 }
9418 else
9419 {
9420 inst.instruction = THUMB_OP32 (inst.instruction);
9421 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9422 inst.instruction |= inst.operands[0].reg << r0off;
9423 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9424 }
9425 }
9426 else if (!narrow)
9427 {
9428 inst.instruction = THUMB_OP32 (inst.instruction);
9429 inst.instruction |= inst.operands[0].reg << r0off;
9430 encode_thumb32_shifted_operand (1);
9431 }
9432 else
9433 switch (inst.instruction)
9434 {
9435 case T_MNEM_mov:
9436 inst.instruction = T_OPCODE_MOV_HR;
9437 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9438 inst.instruction |= (inst.operands[0].reg & 0x7);
9439 inst.instruction |= inst.operands[1].reg << 3;
9440 break;
9441
9442 case T_MNEM_movs:
9443 /* We know we have low registers at this point.
9444 Generate ADD Rd, Rs, #0. */
9445 inst.instruction = T_OPCODE_ADD_I3;
9446 inst.instruction |= inst.operands[0].reg;
9447 inst.instruction |= inst.operands[1].reg << 3;
9448 break;
9449
9450 case T_MNEM_cmp:
9451 if (low_regs)
9452 {
9453 inst.instruction = T_OPCODE_CMP_LR;
9454 inst.instruction |= inst.operands[0].reg;
9455 inst.instruction |= inst.operands[1].reg << 3;
9456 }
9457 else
9458 {
9459 inst.instruction = T_OPCODE_CMP_HR;
9460 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9461 inst.instruction |= (inst.operands[0].reg & 0x7);
9462 inst.instruction |= inst.operands[1].reg << 3;
9463 }
9464 break;
9465 }
9466 return;
9467 }
9468
9469 inst.instruction = THUMB_OP16 (inst.instruction);
9470 if (inst.operands[1].isreg)
9471 {
9472 if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8)
9473 {
9474 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
9475 since a MOV instruction produces unpredictable results. */
9476 if (inst.instruction == T_OPCODE_MOV_I8)
9477 inst.instruction = T_OPCODE_ADD_I3;
9478 else
9479 inst.instruction = T_OPCODE_CMP_LR;
9480
9481 inst.instruction |= inst.operands[0].reg;
9482 inst.instruction |= inst.operands[1].reg << 3;
9483 }
9484 else
9485 {
9486 if (inst.instruction == T_OPCODE_MOV_I8)
9487 inst.instruction = T_OPCODE_MOV_HR;
9488 else
9489 inst.instruction = T_OPCODE_CMP_HR;
9490 do_t_cpy ();
9491 }
9492 }
9493 else
9494 {
9495 constraint (inst.operands[0].reg > 7,
9496 _("only lo regs allowed with immediate"));
9497 inst.instruction |= inst.operands[0].reg << 8;
9498 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9499 }
9500 }
9501
9502 static void
9503 do_t_mov16 (void)
9504 {
9505 bfd_vma imm;
9506 bfd_boolean top;
9507
9508 top = (inst.instruction & 0x00800000) != 0;
9509 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
9510 {
9511 constraint (top, _(":lower16: not allowed this instruction"));
9512 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
9513 }
9514 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
9515 {
9516 constraint (!top, _(":upper16: not allowed this instruction"));
9517 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
9518 }
9519
9520 inst.instruction |= inst.operands[0].reg << 8;
9521 if (inst.reloc.type == BFD_RELOC_UNUSED)
9522 {
9523 imm = inst.reloc.exp.X_add_number;
9524 inst.instruction |= (imm & 0xf000) << 4;
9525 inst.instruction |= (imm & 0x0800) << 15;
9526 inst.instruction |= (imm & 0x0700) << 4;
9527 inst.instruction |= (imm & 0x00ff);
9528 }
9529 }
9530
9531 static void
9532 do_t_mvn_tst (void)
9533 {
9534 if (unified_syntax)
9535 {
9536 int r0off = (inst.instruction == T_MNEM_mvn
9537 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
9538 bfd_boolean narrow;
9539
9540 if (inst.size_req == 4
9541 || inst.instruction > 0xffff
9542 || inst.operands[1].shifted
9543 || inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9544 narrow = FALSE;
9545 else if (inst.instruction == T_MNEM_cmn)
9546 narrow = TRUE;
9547 else if (THUMB_SETS_FLAGS (inst.instruction))
9548 narrow = (current_it_mask == 0);
9549 else
9550 narrow = (current_it_mask != 0);
9551
9552 if (!inst.operands[1].isreg)
9553 {
9554 /* For an immediate, we always generate a 32-bit opcode;
9555 section relaxation will shrink it later if possible. */
9556 if (inst.instruction < 0xffff)
9557 inst.instruction = THUMB_OP32 (inst.instruction);
9558 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9559 inst.instruction |= inst.operands[0].reg << r0off;
9560 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9561 }
9562 else
9563 {
9564 /* See if we can do this with a 16-bit instruction. */
9565 if (narrow)
9566 {
9567 inst.instruction = THUMB_OP16 (inst.instruction);
9568 inst.instruction |= inst.operands[0].reg;
9569 inst.instruction |= inst.operands[1].reg << 3;
9570 }
9571 else
9572 {
9573 constraint (inst.operands[1].shifted
9574 && inst.operands[1].immisreg,
9575 _("shift must be constant"));
9576 if (inst.instruction < 0xffff)
9577 inst.instruction = THUMB_OP32 (inst.instruction);
9578 inst.instruction |= inst.operands[0].reg << r0off;
9579 encode_thumb32_shifted_operand (1);
9580 }
9581 }
9582 }
9583 else
9584 {
9585 constraint (inst.instruction > 0xffff
9586 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
9587 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
9588 _("unshifted register required"));
9589 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9590 BAD_HIREG);
9591
9592 inst.instruction = THUMB_OP16 (inst.instruction);
9593 inst.instruction |= inst.operands[0].reg;
9594 inst.instruction |= inst.operands[1].reg << 3;
9595 }
9596 }
9597
9598 static void
9599 do_t_mrs (void)
9600 {
9601 int flags;
9602
9603 if (do_vfp_nsyn_mrs () == SUCCESS)
9604 return;
9605
9606 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
9607 if (flags == 0)
9608 {
9609 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m),
9610 _("selected processor does not support "
9611 "requested special purpose register"));
9612 }
9613 else
9614 {
9615 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9616 _("selected processor does not support "
9617 "requested special purpose register %x"));
9618 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9619 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
9620 _("'CPSR' or 'SPSR' expected"));
9621 }
9622
9623 inst.instruction |= inst.operands[0].reg << 8;
9624 inst.instruction |= (flags & SPSR_BIT) >> 2;
9625 inst.instruction |= inst.operands[1].imm & 0xff;
9626 }
9627
9628 static void
9629 do_t_msr (void)
9630 {
9631 int flags;
9632
9633 if (do_vfp_nsyn_msr () == SUCCESS)
9634 return;
9635
9636 constraint (!inst.operands[1].isreg,
9637 _("Thumb encoding does not support an immediate here"));
9638 flags = inst.operands[0].imm;
9639 if (flags & ~0xff)
9640 {
9641 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9642 _("selected processor does not support "
9643 "requested special purpose register"));
9644 }
9645 else
9646 {
9647 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m),
9648 _("selected processor does not support "
9649 "requested special purpose register"));
9650 flags |= PSR_f;
9651 }
9652 inst.instruction |= (flags & SPSR_BIT) >> 2;
9653 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
9654 inst.instruction |= (flags & 0xff);
9655 inst.instruction |= inst.operands[1].reg << 16;
9656 }
9657
9658 static void
9659 do_t_mul (void)
9660 {
9661 if (!inst.operands[2].present)
9662 inst.operands[2].reg = inst.operands[0].reg;
9663
9664 /* There is no 32-bit MULS and no 16-bit MUL. */
9665 if (unified_syntax && inst.instruction == T_MNEM_mul)
9666 {
9667 inst.instruction = THUMB_OP32 (inst.instruction);
9668 inst.instruction |= inst.operands[0].reg << 8;
9669 inst.instruction |= inst.operands[1].reg << 16;
9670 inst.instruction |= inst.operands[2].reg << 0;
9671 }
9672 else
9673 {
9674 constraint (!unified_syntax
9675 && inst.instruction == T_MNEM_muls, BAD_THUMB32);
9676 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9677 BAD_HIREG);
9678
9679 inst.instruction = THUMB_OP16 (inst.instruction);
9680 inst.instruction |= inst.operands[0].reg;
9681
9682 if (inst.operands[0].reg == inst.operands[1].reg)
9683 inst.instruction |= inst.operands[2].reg << 3;
9684 else if (inst.operands[0].reg == inst.operands[2].reg)
9685 inst.instruction |= inst.operands[1].reg << 3;
9686 else
9687 constraint (1, _("dest must overlap one source register"));
9688 }
9689 }
9690
9691 static void
9692 do_t_mull (void)
9693 {
9694 inst.instruction |= inst.operands[0].reg << 12;
9695 inst.instruction |= inst.operands[1].reg << 8;
9696 inst.instruction |= inst.operands[2].reg << 16;
9697 inst.instruction |= inst.operands[3].reg;
9698
9699 if (inst.operands[0].reg == inst.operands[1].reg)
9700 as_tsktsk (_("rdhi and rdlo must be different"));
9701 }
9702
9703 static void
9704 do_t_nop (void)
9705 {
9706 if (unified_syntax)
9707 {
9708 if (inst.size_req == 4 || inst.operands[0].imm > 15)
9709 {
9710 inst.instruction = THUMB_OP32 (inst.instruction);
9711 inst.instruction |= inst.operands[0].imm;
9712 }
9713 else
9714 {
9715 inst.instruction = THUMB_OP16 (inst.instruction);
9716 inst.instruction |= inst.operands[0].imm << 4;
9717 }
9718 }
9719 else
9720 {
9721 constraint (inst.operands[0].present,
9722 _("Thumb does not support NOP with hints"));
9723 inst.instruction = 0x46c0;
9724 }
9725 }
9726
9727 static void
9728 do_t_neg (void)
9729 {
9730 if (unified_syntax)
9731 {
9732 bfd_boolean narrow;
9733
9734 if (THUMB_SETS_FLAGS (inst.instruction))
9735 narrow = (current_it_mask == 0);
9736 else
9737 narrow = (current_it_mask != 0);
9738 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9739 narrow = FALSE;
9740 if (inst.size_req == 4)
9741 narrow = FALSE;
9742
9743 if (!narrow)
9744 {
9745 inst.instruction = THUMB_OP32 (inst.instruction);
9746 inst.instruction |= inst.operands[0].reg << 8;
9747 inst.instruction |= inst.operands[1].reg << 16;
9748 }
9749 else
9750 {
9751 inst.instruction = THUMB_OP16 (inst.instruction);
9752 inst.instruction |= inst.operands[0].reg;
9753 inst.instruction |= inst.operands[1].reg << 3;
9754 }
9755 }
9756 else
9757 {
9758 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9759 BAD_HIREG);
9760 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9761
9762 inst.instruction = THUMB_OP16 (inst.instruction);
9763 inst.instruction |= inst.operands[0].reg;
9764 inst.instruction |= inst.operands[1].reg << 3;
9765 }
9766 }
9767
9768 static void
9769 do_t_pkhbt (void)
9770 {
9771 inst.instruction |= inst.operands[0].reg << 8;
9772 inst.instruction |= inst.operands[1].reg << 16;
9773 inst.instruction |= inst.operands[2].reg;
9774 if (inst.operands[3].present)
9775 {
9776 unsigned int val = inst.reloc.exp.X_add_number;
9777 constraint (inst.reloc.exp.X_op != O_constant,
9778 _("expression too complex"));
9779 inst.instruction |= (val & 0x1c) << 10;
9780 inst.instruction |= (val & 0x03) << 6;
9781 }
9782 }
9783
9784 static void
9785 do_t_pkhtb (void)
9786 {
9787 if (!inst.operands[3].present)
9788 inst.instruction &= ~0x00000020;
9789 do_t_pkhbt ();
9790 }
9791
9792 static void
9793 do_t_pld (void)
9794 {
9795 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
9796 }
9797
9798 static void
9799 do_t_push_pop (void)
9800 {
9801 unsigned mask;
9802
9803 constraint (inst.operands[0].writeback,
9804 _("push/pop do not support {reglist}^"));
9805 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9806 _("expression too complex"));
9807
9808 mask = inst.operands[0].imm;
9809 if ((mask & ~0xff) == 0)
9810 inst.instruction = THUMB_OP16 (inst.instruction);
9811 else if ((inst.instruction == T_MNEM_push
9812 && (mask & ~0xff) == 1 << REG_LR)
9813 || (inst.instruction == T_MNEM_pop
9814 && (mask & ~0xff) == 1 << REG_PC))
9815 {
9816 inst.instruction = THUMB_OP16 (inst.instruction);
9817 inst.instruction |= THUMB_PP_PC_LR;
9818 mask &= 0xff;
9819 }
9820 else if (unified_syntax)
9821 {
9822 if (mask & (1 << 13))
9823 inst.error = _("SP not allowed in register list");
9824 if (inst.instruction == T_MNEM_push)
9825 {
9826 if (mask & (1 << 15))
9827 inst.error = _("PC not allowed in register list");
9828 }
9829 else
9830 {
9831 if (mask & (1 << 14)
9832 && mask & (1 << 15))
9833 inst.error = _("LR and PC should not both be in register list");
9834 }
9835 if ((mask & (mask - 1)) == 0)
9836 {
9837 /* Single register push/pop implemented as str/ldr. */
9838 if (inst.instruction == T_MNEM_push)
9839 inst.instruction = 0xf84d0d04; /* str reg, [sp, #-4]! */
9840 else
9841 inst.instruction = 0xf85d0b04; /* ldr reg, [sp], #4 */
9842 mask = ffs(mask) - 1;
9843 mask <<= 12;
9844 }
9845 else
9846 inst.instruction = THUMB_OP32 (inst.instruction);
9847 }
9848 else
9849 {
9850 inst.error = _("invalid register list to push/pop instruction");
9851 return;
9852 }
9853
9854 inst.instruction |= mask;
9855 }
9856
9857 static void
9858 do_t_rbit (void)
9859 {
9860 inst.instruction |= inst.operands[0].reg << 8;
9861 inst.instruction |= inst.operands[1].reg << 16;
9862 }
9863
9864 static void
9865 do_t_rev (void)
9866 {
9867 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
9868 && inst.size_req != 4)
9869 {
9870 inst.instruction = THUMB_OP16 (inst.instruction);
9871 inst.instruction |= inst.operands[0].reg;
9872 inst.instruction |= inst.operands[1].reg << 3;
9873 }
9874 else if (unified_syntax)
9875 {
9876 inst.instruction = THUMB_OP32 (inst.instruction);
9877 inst.instruction |= inst.operands[0].reg << 8;
9878 inst.instruction |= inst.operands[1].reg << 16;
9879 inst.instruction |= inst.operands[1].reg;
9880 }
9881 else
9882 inst.error = BAD_HIREG;
9883 }
9884
9885 static void
9886 do_t_rsb (void)
9887 {
9888 int Rd, Rs;
9889
9890 Rd = inst.operands[0].reg;
9891 Rs = (inst.operands[1].present
9892 ? inst.operands[1].reg /* Rd, Rs, foo */
9893 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9894
9895 inst.instruction |= Rd << 8;
9896 inst.instruction |= Rs << 16;
9897 if (!inst.operands[2].isreg)
9898 {
9899 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9900 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9901 }
9902 else
9903 encode_thumb32_shifted_operand (2);
9904 }
9905
9906 static void
9907 do_t_setend (void)
9908 {
9909 constraint (current_it_mask, BAD_NOT_IT);
9910 if (inst.operands[0].imm)
9911 inst.instruction |= 0x8;
9912 }
9913
9914 static void
9915 do_t_shift (void)
9916 {
9917 if (!inst.operands[1].present)
9918 inst.operands[1].reg = inst.operands[0].reg;
9919
9920 if (unified_syntax)
9921 {
9922 bfd_boolean narrow;
9923 int shift_kind;
9924
9925 switch (inst.instruction)
9926 {
9927 case T_MNEM_asr:
9928 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
9929 case T_MNEM_lsl:
9930 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
9931 case T_MNEM_lsr:
9932 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
9933 case T_MNEM_ror:
9934 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
9935 default: abort ();
9936 }
9937
9938 if (THUMB_SETS_FLAGS (inst.instruction))
9939 narrow = (current_it_mask == 0);
9940 else
9941 narrow = (current_it_mask != 0);
9942 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9943 narrow = FALSE;
9944 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
9945 narrow = FALSE;
9946 if (inst.operands[2].isreg
9947 && (inst.operands[1].reg != inst.operands[0].reg
9948 || inst.operands[2].reg > 7))
9949 narrow = FALSE;
9950 if (inst.size_req == 4)
9951 narrow = FALSE;
9952
9953 if (!narrow)
9954 {
9955 if (inst.operands[2].isreg)
9956 {
9957 inst.instruction = THUMB_OP32 (inst.instruction);
9958 inst.instruction |= inst.operands[0].reg << 8;
9959 inst.instruction |= inst.operands[1].reg << 16;
9960 inst.instruction |= inst.operands[2].reg;
9961 }
9962 else
9963 {
9964 inst.operands[1].shifted = 1;
9965 inst.operands[1].shift_kind = shift_kind;
9966 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
9967 ? T_MNEM_movs : T_MNEM_mov);
9968 inst.instruction |= inst.operands[0].reg << 8;
9969 encode_thumb32_shifted_operand (1);
9970 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
9971 inst.reloc.type = BFD_RELOC_UNUSED;
9972 }
9973 }
9974 else
9975 {
9976 if (inst.operands[2].isreg)
9977 {
9978 switch (shift_kind)
9979 {
9980 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
9981 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
9982 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
9983 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
9984 default: abort ();
9985 }
9986
9987 inst.instruction |= inst.operands[0].reg;
9988 inst.instruction |= inst.operands[2].reg << 3;
9989 }
9990 else
9991 {
9992 switch (shift_kind)
9993 {
9994 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
9995 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
9996 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
9997 default: abort ();
9998 }
9999 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10000 inst.instruction |= inst.operands[0].reg;
10001 inst.instruction |= inst.operands[1].reg << 3;
10002 }
10003 }
10004 }
10005 else
10006 {
10007 constraint (inst.operands[0].reg > 7
10008 || inst.operands[1].reg > 7, BAD_HIREG);
10009 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10010
10011 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
10012 {
10013 constraint (inst.operands[2].reg > 7, BAD_HIREG);
10014 constraint (inst.operands[0].reg != inst.operands[1].reg,
10015 _("source1 and dest must be same register"));
10016
10017 switch (inst.instruction)
10018 {
10019 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
10020 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
10021 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
10022 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
10023 default: abort ();
10024 }
10025
10026 inst.instruction |= inst.operands[0].reg;
10027 inst.instruction |= inst.operands[2].reg << 3;
10028 }
10029 else
10030 {
10031 switch (inst.instruction)
10032 {
10033 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
10034 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
10035 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
10036 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
10037 default: abort ();
10038 }
10039 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10040 inst.instruction |= inst.operands[0].reg;
10041 inst.instruction |= inst.operands[1].reg << 3;
10042 }
10043 }
10044 }
10045
10046 static void
10047 do_t_simd (void)
10048 {
10049 inst.instruction |= inst.operands[0].reg << 8;
10050 inst.instruction |= inst.operands[1].reg << 16;
10051 inst.instruction |= inst.operands[2].reg;
10052 }
10053
10054 static void
10055 do_t_smc (void)
10056 {
10057 unsigned int value = inst.reloc.exp.X_add_number;
10058 constraint (inst.reloc.exp.X_op != O_constant,
10059 _("expression too complex"));
10060 inst.reloc.type = BFD_RELOC_UNUSED;
10061 inst.instruction |= (value & 0xf000) >> 12;
10062 inst.instruction |= (value & 0x0ff0);
10063 inst.instruction |= (value & 0x000f) << 16;
10064 }
10065
10066 static void
10067 do_t_ssat (void)
10068 {
10069 inst.instruction |= inst.operands[0].reg << 8;
10070 inst.instruction |= inst.operands[1].imm - 1;
10071 inst.instruction |= inst.operands[2].reg << 16;
10072
10073 if (inst.operands[3].present)
10074 {
10075 constraint (inst.reloc.exp.X_op != O_constant,
10076 _("expression too complex"));
10077
10078 if (inst.reloc.exp.X_add_number != 0)
10079 {
10080 if (inst.operands[3].shift_kind == SHIFT_ASR)
10081 inst.instruction |= 0x00200000; /* sh bit */
10082 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10083 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10084 }
10085 inst.reloc.type = BFD_RELOC_UNUSED;
10086 }
10087 }
10088
10089 static void
10090 do_t_ssat16 (void)
10091 {
10092 inst.instruction |= inst.operands[0].reg << 8;
10093 inst.instruction |= inst.operands[1].imm - 1;
10094 inst.instruction |= inst.operands[2].reg << 16;
10095 }
10096
10097 static void
10098 do_t_strex (void)
10099 {
10100 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10101 || inst.operands[2].postind || inst.operands[2].writeback
10102 || inst.operands[2].immisreg || inst.operands[2].shifted
10103 || inst.operands[2].negative,
10104 BAD_ADDR_MODE);
10105
10106 inst.instruction |= inst.operands[0].reg << 8;
10107 inst.instruction |= inst.operands[1].reg << 12;
10108 inst.instruction |= inst.operands[2].reg << 16;
10109 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
10110 }
10111
10112 static void
10113 do_t_strexd (void)
10114 {
10115 if (!inst.operands[2].present)
10116 inst.operands[2].reg = inst.operands[1].reg + 1;
10117
10118 constraint (inst.operands[0].reg == inst.operands[1].reg
10119 || inst.operands[0].reg == inst.operands[2].reg
10120 || inst.operands[0].reg == inst.operands[3].reg
10121 || inst.operands[1].reg == inst.operands[2].reg,
10122 BAD_OVERLAP);
10123
10124 inst.instruction |= inst.operands[0].reg;
10125 inst.instruction |= inst.operands[1].reg << 12;
10126 inst.instruction |= inst.operands[2].reg << 8;
10127 inst.instruction |= inst.operands[3].reg << 16;
10128 }
10129
10130 static void
10131 do_t_sxtah (void)
10132 {
10133 inst.instruction |= inst.operands[0].reg << 8;
10134 inst.instruction |= inst.operands[1].reg << 16;
10135 inst.instruction |= inst.operands[2].reg;
10136 inst.instruction |= inst.operands[3].imm << 4;
10137 }
10138
10139 static void
10140 do_t_sxth (void)
10141 {
10142 if (inst.instruction <= 0xffff && inst.size_req != 4
10143 && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10144 && (!inst.operands[2].present || inst.operands[2].imm == 0))
10145 {
10146 inst.instruction = THUMB_OP16 (inst.instruction);
10147 inst.instruction |= inst.operands[0].reg;
10148 inst.instruction |= inst.operands[1].reg << 3;
10149 }
10150 else if (unified_syntax)
10151 {
10152 if (inst.instruction <= 0xffff)
10153 inst.instruction = THUMB_OP32 (inst.instruction);
10154 inst.instruction |= inst.operands[0].reg << 8;
10155 inst.instruction |= inst.operands[1].reg;
10156 inst.instruction |= inst.operands[2].imm << 4;
10157 }
10158 else
10159 {
10160 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
10161 _("Thumb encoding does not support rotation"));
10162 constraint (1, BAD_HIREG);
10163 }
10164 }
10165
10166 static void
10167 do_t_swi (void)
10168 {
10169 inst.reloc.type = BFD_RELOC_ARM_SWI;
10170 }
10171
10172 static void
10173 do_t_tb (void)
10174 {
10175 int half;
10176
10177 half = (inst.instruction & 0x10) != 0;
10178 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
10179 constraint (inst.operands[0].immisreg,
10180 _("instruction requires register index"));
10181 constraint (inst.operands[0].imm == 15,
10182 _("PC is not a valid index register"));
10183 constraint (!half && inst.operands[0].shifted,
10184 _("instruction does not allow shifted index"));
10185 inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm;
10186 }
10187
10188 static void
10189 do_t_usat (void)
10190 {
10191 inst.instruction |= inst.operands[0].reg << 8;
10192 inst.instruction |= inst.operands[1].imm;
10193 inst.instruction |= inst.operands[2].reg << 16;
10194
10195 if (inst.operands[3].present)
10196 {
10197 constraint (inst.reloc.exp.X_op != O_constant,
10198 _("expression too complex"));
10199 if (inst.reloc.exp.X_add_number != 0)
10200 {
10201 if (inst.operands[3].shift_kind == SHIFT_ASR)
10202 inst.instruction |= 0x00200000; /* sh bit */
10203
10204 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10205 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10206 }
10207 inst.reloc.type = BFD_RELOC_UNUSED;
10208 }
10209 }
10210
10211 static void
10212 do_t_usat16 (void)
10213 {
10214 inst.instruction |= inst.operands[0].reg << 8;
10215 inst.instruction |= inst.operands[1].imm;
10216 inst.instruction |= inst.operands[2].reg << 16;
10217 }
10218
10219 /* Neon instruction encoder helpers. */
10220
10221 /* Encodings for the different types for various Neon opcodes. */
10222
10223 /* An "invalid" code for the following tables. */
10224 #define N_INV -1u
10225
10226 struct neon_tab_entry
10227 {
10228 unsigned integer;
10229 unsigned float_or_poly;
10230 unsigned scalar_or_imm;
10231 };
10232
10233 /* Map overloaded Neon opcodes to their respective encodings. */
10234 #define NEON_ENC_TAB \
10235 X(vabd, 0x0000700, 0x1200d00, N_INV), \
10236 X(vmax, 0x0000600, 0x0000f00, N_INV), \
10237 X(vmin, 0x0000610, 0x0200f00, N_INV), \
10238 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
10239 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
10240 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
10241 X(vadd, 0x0000800, 0x0000d00, N_INV), \
10242 X(vsub, 0x1000800, 0x0200d00, N_INV), \
10243 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
10244 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
10245 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
10246 /* Register variants of the following two instructions are encoded as
10247 vcge / vcgt with the operands reversed. */ \
10248 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
10249 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
10250 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
10251 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
10252 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
10253 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
10254 X(vmlal, 0x0800800, N_INV, 0x0800240), \
10255 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
10256 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
10257 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
10258 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
10259 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
10260 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
10261 X(vshl, 0x0000400, N_INV, 0x0800510), \
10262 X(vqshl, 0x0000410, N_INV, 0x0800710), \
10263 X(vand, 0x0000110, N_INV, 0x0800030), \
10264 X(vbic, 0x0100110, N_INV, 0x0800030), \
10265 X(veor, 0x1000110, N_INV, N_INV), \
10266 X(vorn, 0x0300110, N_INV, 0x0800010), \
10267 X(vorr, 0x0200110, N_INV, 0x0800010), \
10268 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
10269 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
10270 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
10271 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
10272 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
10273 X(vst1, 0x0000000, 0x0800000, N_INV), \
10274 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
10275 X(vst2, 0x0000100, 0x0800100, N_INV), \
10276 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
10277 X(vst3, 0x0000200, 0x0800200, N_INV), \
10278 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
10279 X(vst4, 0x0000300, 0x0800300, N_INV), \
10280 X(vmovn, 0x1b20200, N_INV, N_INV), \
10281 X(vtrn, 0x1b20080, N_INV, N_INV), \
10282 X(vqmovn, 0x1b20200, N_INV, N_INV), \
10283 X(vqmovun, 0x1b20240, N_INV, N_INV), \
10284 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
10285 X(vnmla, 0xe000a40, 0xe000b40, N_INV), \
10286 X(vnmls, 0xe100a40, 0xe100b40, N_INV), \
10287 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
10288 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
10289 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
10290 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
10291
10292 enum neon_opc
10293 {
10294 #define X(OPC,I,F,S) N_MNEM_##OPC
10295 NEON_ENC_TAB
10296 #undef X
10297 };
10298
10299 static const struct neon_tab_entry neon_enc_tab[] =
10300 {
10301 #define X(OPC,I,F,S) { (I), (F), (S) }
10302 NEON_ENC_TAB
10303 #undef X
10304 };
10305
10306 #define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10307 #define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10308 #define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10309 #define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10310 #define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10311 #define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10312 #define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10313 #define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10314 #define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10315 #define NEON_ENC_SINGLE(X) \
10316 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
10317 #define NEON_ENC_DOUBLE(X) \
10318 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
10319
10320 /* Define shapes for instruction operands. The following mnemonic characters
10321 are used in this table:
10322
10323 F - VFP S<n> register
10324 D - Neon D<n> register
10325 Q - Neon Q<n> register
10326 I - Immediate
10327 S - Scalar
10328 R - ARM register
10329 L - D<n> register list
10330
10331 This table is used to generate various data:
10332 - enumerations of the form NS_DDR to be used as arguments to
10333 neon_select_shape.
10334 - a table classifying shapes into single, double, quad, mixed.
10335 - a table used to drive neon_select_shape.
10336 */
10337
10338 #define NEON_SHAPE_DEF \
10339 X(3, (D, D, D), DOUBLE), \
10340 X(3, (Q, Q, Q), QUAD), \
10341 X(3, (D, D, I), DOUBLE), \
10342 X(3, (Q, Q, I), QUAD), \
10343 X(3, (D, D, S), DOUBLE), \
10344 X(3, (Q, Q, S), QUAD), \
10345 X(2, (D, D), DOUBLE), \
10346 X(2, (Q, Q), QUAD), \
10347 X(2, (D, S), DOUBLE), \
10348 X(2, (Q, S), QUAD), \
10349 X(2, (D, R), DOUBLE), \
10350 X(2, (Q, R), QUAD), \
10351 X(2, (D, I), DOUBLE), \
10352 X(2, (Q, I), QUAD), \
10353 X(3, (D, L, D), DOUBLE), \
10354 X(2, (D, Q), MIXED), \
10355 X(2, (Q, D), MIXED), \
10356 X(3, (D, Q, I), MIXED), \
10357 X(3, (Q, D, I), MIXED), \
10358 X(3, (Q, D, D), MIXED), \
10359 X(3, (D, Q, Q), MIXED), \
10360 X(3, (Q, Q, D), MIXED), \
10361 X(3, (Q, D, S), MIXED), \
10362 X(3, (D, Q, S), MIXED), \
10363 X(4, (D, D, D, I), DOUBLE), \
10364 X(4, (Q, Q, Q, I), QUAD), \
10365 X(2, (F, F), SINGLE), \
10366 X(3, (F, F, F), SINGLE), \
10367 X(2, (F, I), SINGLE), \
10368 X(2, (F, D), MIXED), \
10369 X(2, (D, F), MIXED), \
10370 X(3, (F, F, I), MIXED), \
10371 X(4, (R, R, F, F), SINGLE), \
10372 X(4, (F, F, R, R), SINGLE), \
10373 X(3, (D, R, R), DOUBLE), \
10374 X(3, (R, R, D), DOUBLE), \
10375 X(2, (S, R), SINGLE), \
10376 X(2, (R, S), SINGLE), \
10377 X(2, (F, R), SINGLE), \
10378 X(2, (R, F), SINGLE)
10379
10380 #define S2(A,B) NS_##A##B
10381 #define S3(A,B,C) NS_##A##B##C
10382 #define S4(A,B,C,D) NS_##A##B##C##D
10383
10384 #define X(N, L, C) S##N L
10385
10386 enum neon_shape
10387 {
10388 NEON_SHAPE_DEF,
10389 NS_NULL
10390 };
10391
10392 #undef X
10393 #undef S2
10394 #undef S3
10395 #undef S4
10396
10397 enum neon_shape_class
10398 {
10399 SC_SINGLE,
10400 SC_DOUBLE,
10401 SC_QUAD,
10402 SC_MIXED
10403 };
10404
10405 #define X(N, L, C) SC_##C
10406
10407 static enum neon_shape_class neon_shape_class[] =
10408 {
10409 NEON_SHAPE_DEF
10410 };
10411
10412 #undef X
10413
10414 enum neon_shape_el
10415 {
10416 SE_F,
10417 SE_D,
10418 SE_Q,
10419 SE_I,
10420 SE_S,
10421 SE_R,
10422 SE_L
10423 };
10424
10425 /* Register widths of above. */
10426 static unsigned neon_shape_el_size[] =
10427 {
10428 32,
10429 64,
10430 128,
10431 0,
10432 32,
10433 32,
10434 0
10435 };
10436
10437 struct neon_shape_info
10438 {
10439 unsigned els;
10440 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
10441 };
10442
10443 #define S2(A,B) { SE_##A, SE_##B }
10444 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
10445 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
10446
10447 #define X(N, L, C) { N, S##N L }
10448
10449 static struct neon_shape_info neon_shape_tab[] =
10450 {
10451 NEON_SHAPE_DEF
10452 };
10453
10454 #undef X
10455 #undef S2
10456 #undef S3
10457 #undef S4
10458
10459 /* Bit masks used in type checking given instructions.
10460 'N_EQK' means the type must be the same as (or based on in some way) the key
10461 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
10462 set, various other bits can be set as well in order to modify the meaning of
10463 the type constraint. */
10464
10465 enum neon_type_mask
10466 {
10467 N_S8 = 0x000001,
10468 N_S16 = 0x000002,
10469 N_S32 = 0x000004,
10470 N_S64 = 0x000008,
10471 N_U8 = 0x000010,
10472 N_U16 = 0x000020,
10473 N_U32 = 0x000040,
10474 N_U64 = 0x000080,
10475 N_I8 = 0x000100,
10476 N_I16 = 0x000200,
10477 N_I32 = 0x000400,
10478 N_I64 = 0x000800,
10479 N_8 = 0x001000,
10480 N_16 = 0x002000,
10481 N_32 = 0x004000,
10482 N_64 = 0x008000,
10483 N_P8 = 0x010000,
10484 N_P16 = 0x020000,
10485 N_F32 = 0x040000,
10486 N_F64 = 0x080000,
10487 N_KEY = 0x100000, /* key element (main type specifier). */
10488 N_EQK = 0x200000, /* given operand has the same type & size as the key. */
10489 N_VFP = 0x400000, /* VFP mode: operand size must match register width. */
10490 N_DBL = 0x000001, /* if N_EQK, this operand is twice the size. */
10491 N_HLF = 0x000002, /* if N_EQK, this operand is half the size. */
10492 N_SGN = 0x000004, /* if N_EQK, this operand is forced to be signed. */
10493 N_UNS = 0x000008, /* if N_EQK, this operand is forced to be unsigned. */
10494 N_INT = 0x000010, /* if N_EQK, this operand is forced to be integer. */
10495 N_FLT = 0x000020, /* if N_EQK, this operand is forced to be float. */
10496 N_SIZ = 0x000040, /* if N_EQK, this operand is forced to be size-only. */
10497 N_UTYP = 0,
10498 N_MAX_NONSPECIAL = N_F64
10499 };
10500
10501 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
10502
10503 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
10504 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
10505 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
10506 #define N_SUF_32 (N_SU_32 | N_F32)
10507 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
10508 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
10509
10510 /* Pass this as the first type argument to neon_check_type to ignore types
10511 altogether. */
10512 #define N_IGNORE_TYPE (N_KEY | N_EQK)
10513
10514 /* Select a "shape" for the current instruction (describing register types or
10515 sizes) from a list of alternatives. Return NS_NULL if the current instruction
10516 doesn't fit. For non-polymorphic shapes, checking is usually done as a
10517 function of operand parsing, so this function doesn't need to be called.
10518 Shapes should be listed in order of decreasing length. */
10519
10520 static enum neon_shape
10521 neon_select_shape (enum neon_shape shape, ...)
10522 {
10523 va_list ap;
10524 enum neon_shape first_shape = shape;
10525
10526 /* Fix missing optional operands. FIXME: we don't know at this point how
10527 many arguments we should have, so this makes the assumption that we have
10528 > 1. This is true of all current Neon opcodes, I think, but may not be
10529 true in the future. */
10530 if (!inst.operands[1].present)
10531 inst.operands[1] = inst.operands[0];
10532
10533 va_start (ap, shape);
10534
10535 for (; shape != NS_NULL; shape = va_arg (ap, int))
10536 {
10537 unsigned j;
10538 int matches = 1;
10539
10540 for (j = 0; j < neon_shape_tab[shape].els; j++)
10541 {
10542 if (!inst.operands[j].present)
10543 {
10544 matches = 0;
10545 break;
10546 }
10547
10548 switch (neon_shape_tab[shape].el[j])
10549 {
10550 case SE_F:
10551 if (!(inst.operands[j].isreg
10552 && inst.operands[j].isvec
10553 && inst.operands[j].issingle
10554 && !inst.operands[j].isquad))
10555 matches = 0;
10556 break;
10557
10558 case SE_D:
10559 if (!(inst.operands[j].isreg
10560 && inst.operands[j].isvec
10561 && !inst.operands[j].isquad
10562 && !inst.operands[j].issingle))
10563 matches = 0;
10564 break;
10565
10566 case SE_R:
10567 if (!(inst.operands[j].isreg
10568 && !inst.operands[j].isvec))
10569 matches = 0;
10570 break;
10571
10572 case SE_Q:
10573 if (!(inst.operands[j].isreg
10574 && inst.operands[j].isvec
10575 && inst.operands[j].isquad
10576 && !inst.operands[j].issingle))
10577 matches = 0;
10578 break;
10579
10580 case SE_I:
10581 if (!(!inst.operands[j].isreg
10582 && !inst.operands[j].isscalar))
10583 matches = 0;
10584 break;
10585
10586 case SE_S:
10587 if (!(!inst.operands[j].isreg
10588 && inst.operands[j].isscalar))
10589 matches = 0;
10590 break;
10591
10592 case SE_L:
10593 break;
10594 }
10595 }
10596 if (matches)
10597 break;
10598 }
10599
10600 va_end (ap);
10601
10602 if (shape == NS_NULL && first_shape != NS_NULL)
10603 first_error (_("invalid instruction shape"));
10604
10605 return shape;
10606 }
10607
10608 /* True if SHAPE is predominantly a quadword operation (most of the time, this
10609 means the Q bit should be set). */
10610
10611 static int
10612 neon_quad (enum neon_shape shape)
10613 {
10614 return neon_shape_class[shape] == SC_QUAD;
10615 }
10616
10617 static void
10618 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
10619 unsigned *g_size)
10620 {
10621 /* Allow modification to be made to types which are constrained to be
10622 based on the key element, based on bits set alongside N_EQK. */
10623 if ((typebits & N_EQK) != 0)
10624 {
10625 if ((typebits & N_HLF) != 0)
10626 *g_size /= 2;
10627 else if ((typebits & N_DBL) != 0)
10628 *g_size *= 2;
10629 if ((typebits & N_SGN) != 0)
10630 *g_type = NT_signed;
10631 else if ((typebits & N_UNS) != 0)
10632 *g_type = NT_unsigned;
10633 else if ((typebits & N_INT) != 0)
10634 *g_type = NT_integer;
10635 else if ((typebits & N_FLT) != 0)
10636 *g_type = NT_float;
10637 else if ((typebits & N_SIZ) != 0)
10638 *g_type = NT_untyped;
10639 }
10640 }
10641
10642 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
10643 operand type, i.e. the single type specified in a Neon instruction when it
10644 is the only one given. */
10645
10646 static struct neon_type_el
10647 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
10648 {
10649 struct neon_type_el dest = *key;
10650
10651 assert ((thisarg & N_EQK) != 0);
10652
10653 neon_modify_type_size (thisarg, &dest.type, &dest.size);
10654
10655 return dest;
10656 }
10657
10658 /* Convert Neon type and size into compact bitmask representation. */
10659
10660 static enum neon_type_mask
10661 type_chk_of_el_type (enum neon_el_type type, unsigned size)
10662 {
10663 switch (type)
10664 {
10665 case NT_untyped:
10666 switch (size)
10667 {
10668 case 8: return N_8;
10669 case 16: return N_16;
10670 case 32: return N_32;
10671 case 64: return N_64;
10672 default: ;
10673 }
10674 break;
10675
10676 case NT_integer:
10677 switch (size)
10678 {
10679 case 8: return N_I8;
10680 case 16: return N_I16;
10681 case 32: return N_I32;
10682 case 64: return N_I64;
10683 default: ;
10684 }
10685 break;
10686
10687 case NT_float:
10688 switch (size)
10689 {
10690 case 32: return N_F32;
10691 case 64: return N_F64;
10692 default: ;
10693 }
10694 break;
10695
10696 case NT_poly:
10697 switch (size)
10698 {
10699 case 8: return N_P8;
10700 case 16: return N_P16;
10701 default: ;
10702 }
10703 break;
10704
10705 case NT_signed:
10706 switch (size)
10707 {
10708 case 8: return N_S8;
10709 case 16: return N_S16;
10710 case 32: return N_S32;
10711 case 64: return N_S64;
10712 default: ;
10713 }
10714 break;
10715
10716 case NT_unsigned:
10717 switch (size)
10718 {
10719 case 8: return N_U8;
10720 case 16: return N_U16;
10721 case 32: return N_U32;
10722 case 64: return N_U64;
10723 default: ;
10724 }
10725 break;
10726
10727 default: ;
10728 }
10729
10730 return N_UTYP;
10731 }
10732
10733 /* Convert compact Neon bitmask type representation to a type and size. Only
10734 handles the case where a single bit is set in the mask. */
10735
10736 static int
10737 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
10738 enum neon_type_mask mask)
10739 {
10740 if ((mask & N_EQK) != 0)
10741 return FAIL;
10742
10743 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
10744 *size = 8;
10745 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
10746 *size = 16;
10747 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
10748 *size = 32;
10749 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
10750 *size = 64;
10751 else
10752 return FAIL;
10753
10754 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
10755 *type = NT_signed;
10756 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
10757 *type = NT_unsigned;
10758 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
10759 *type = NT_integer;
10760 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
10761 *type = NT_untyped;
10762 else if ((mask & (N_P8 | N_P16)) != 0)
10763 *type = NT_poly;
10764 else if ((mask & (N_F32 | N_F64)) != 0)
10765 *type = NT_float;
10766 else
10767 return FAIL;
10768
10769 return SUCCESS;
10770 }
10771
10772 /* Modify a bitmask of allowed types. This is only needed for type
10773 relaxation. */
10774
10775 static unsigned
10776 modify_types_allowed (unsigned allowed, unsigned mods)
10777 {
10778 unsigned size;
10779 enum neon_el_type type;
10780 unsigned destmask;
10781 int i;
10782
10783 destmask = 0;
10784
10785 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
10786 {
10787 if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS)
10788 {
10789 neon_modify_type_size (mods, &type, &size);
10790 destmask |= type_chk_of_el_type (type, size);
10791 }
10792 }
10793
10794 return destmask;
10795 }
10796
10797 /* Check type and return type classification.
10798 The manual states (paraphrase): If one datatype is given, it indicates the
10799 type given in:
10800 - the second operand, if there is one
10801 - the operand, if there is no second operand
10802 - the result, if there are no operands.
10803 This isn't quite good enough though, so we use a concept of a "key" datatype
10804 which is set on a per-instruction basis, which is the one which matters when
10805 only one data type is written.
10806 Note: this function has side-effects (e.g. filling in missing operands). All
10807 Neon instructions should call it before performing bit encoding. */
10808
10809 static struct neon_type_el
10810 neon_check_type (unsigned els, enum neon_shape ns, ...)
10811 {
10812 va_list ap;
10813 unsigned i, pass, key_el = 0;
10814 unsigned types[NEON_MAX_TYPE_ELS];
10815 enum neon_el_type k_type = NT_invtype;
10816 unsigned k_size = -1u;
10817 struct neon_type_el badtype = {NT_invtype, -1};
10818 unsigned key_allowed = 0;
10819
10820 /* Optional registers in Neon instructions are always (not) in operand 1.
10821 Fill in the missing operand here, if it was omitted. */
10822 if (els > 1 && !inst.operands[1].present)
10823 inst.operands[1] = inst.operands[0];
10824
10825 /* Suck up all the varargs. */
10826 va_start (ap, ns);
10827 for (i = 0; i < els; i++)
10828 {
10829 unsigned thisarg = va_arg (ap, unsigned);
10830 if (thisarg == N_IGNORE_TYPE)
10831 {
10832 va_end (ap);
10833 return badtype;
10834 }
10835 types[i] = thisarg;
10836 if ((thisarg & N_KEY) != 0)
10837 key_el = i;
10838 }
10839 va_end (ap);
10840
10841 if (inst.vectype.elems > 0)
10842 for (i = 0; i < els; i++)
10843 if (inst.operands[i].vectype.type != NT_invtype)
10844 {
10845 first_error (_("types specified in both the mnemonic and operands"));
10846 return badtype;
10847 }
10848
10849 /* Duplicate inst.vectype elements here as necessary.
10850 FIXME: No idea if this is exactly the same as the ARM assembler,
10851 particularly when an insn takes one register and one non-register
10852 operand. */
10853 if (inst.vectype.elems == 1 && els > 1)
10854 {
10855 unsigned j;
10856 inst.vectype.elems = els;
10857 inst.vectype.el[key_el] = inst.vectype.el[0];
10858 for (j = 0; j < els; j++)
10859 if (j != key_el)
10860 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
10861 types[j]);
10862 }
10863 else if (inst.vectype.elems == 0 && els > 0)
10864 {
10865 unsigned j;
10866 /* No types were given after the mnemonic, so look for types specified
10867 after each operand. We allow some flexibility here; as long as the
10868 "key" operand has a type, we can infer the others. */
10869 for (j = 0; j < els; j++)
10870 if (inst.operands[j].vectype.type != NT_invtype)
10871 inst.vectype.el[j] = inst.operands[j].vectype;
10872
10873 if (inst.operands[key_el].vectype.type != NT_invtype)
10874 {
10875 for (j = 0; j < els; j++)
10876 if (inst.operands[j].vectype.type == NT_invtype)
10877 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
10878 types[j]);
10879 }
10880 else
10881 {
10882 first_error (_("operand types can't be inferred"));
10883 return badtype;
10884 }
10885 }
10886 else if (inst.vectype.elems != els)
10887 {
10888 first_error (_("type specifier has the wrong number of parts"));
10889 return badtype;
10890 }
10891
10892 for (pass = 0; pass < 2; pass++)
10893 {
10894 for (i = 0; i < els; i++)
10895 {
10896 unsigned thisarg = types[i];
10897 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
10898 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
10899 enum neon_el_type g_type = inst.vectype.el[i].type;
10900 unsigned g_size = inst.vectype.el[i].size;
10901
10902 /* Decay more-specific signed & unsigned types to sign-insensitive
10903 integer types if sign-specific variants are unavailable. */
10904 if ((g_type == NT_signed || g_type == NT_unsigned)
10905 && (types_allowed & N_SU_ALL) == 0)
10906 g_type = NT_integer;
10907
10908 /* If only untyped args are allowed, decay any more specific types to
10909 them. Some instructions only care about signs for some element
10910 sizes, so handle that properly. */
10911 if ((g_size == 8 && (types_allowed & N_8) != 0)
10912 || (g_size == 16 && (types_allowed & N_16) != 0)
10913 || (g_size == 32 && (types_allowed & N_32) != 0)
10914 || (g_size == 64 && (types_allowed & N_64) != 0))
10915 g_type = NT_untyped;
10916
10917 if (pass == 0)
10918 {
10919 if ((thisarg & N_KEY) != 0)
10920 {
10921 k_type = g_type;
10922 k_size = g_size;
10923 key_allowed = thisarg & ~N_KEY;
10924 }
10925 }
10926 else
10927 {
10928 if ((thisarg & N_VFP) != 0)
10929 {
10930 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
10931 unsigned regwidth = neon_shape_el_size[regshape], match;
10932
10933 /* In VFP mode, operands must match register widths. If we
10934 have a key operand, use its width, else use the width of
10935 the current operand. */
10936 if (k_size != -1u)
10937 match = k_size;
10938 else
10939 match = g_size;
10940
10941 if (regwidth != match)
10942 {
10943 first_error (_("operand size must match register width"));
10944 return badtype;
10945 }
10946 }
10947
10948 if ((thisarg & N_EQK) == 0)
10949 {
10950 unsigned given_type = type_chk_of_el_type (g_type, g_size);
10951
10952 if ((given_type & types_allowed) == 0)
10953 {
10954 first_error (_("bad type in Neon instruction"));
10955 return badtype;
10956 }
10957 }
10958 else
10959 {
10960 enum neon_el_type mod_k_type = k_type;
10961 unsigned mod_k_size = k_size;
10962 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
10963 if (g_type != mod_k_type || g_size != mod_k_size)
10964 {
10965 first_error (_("inconsistent types in Neon instruction"));
10966 return badtype;
10967 }
10968 }
10969 }
10970 }
10971 }
10972
10973 return inst.vectype.el[key_el];
10974 }
10975
10976 /* Neon-style VFP instruction forwarding. */
10977
10978 /* Thumb VFP instructions have 0xE in the condition field. */
10979
10980 static void
10981 do_vfp_cond_or_thumb (void)
10982 {
10983 if (thumb_mode)
10984 inst.instruction |= 0xe0000000;
10985 else
10986 inst.instruction |= inst.cond << 28;
10987 }
10988
10989 /* Look up and encode a simple mnemonic, for use as a helper function for the
10990 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
10991 etc. It is assumed that operand parsing has already been done, and that the
10992 operands are in the form expected by the given opcode (this isn't necessarily
10993 the same as the form in which they were parsed, hence some massaging must
10994 take place before this function is called).
10995 Checks current arch version against that in the looked-up opcode. */
10996
10997 static void
10998 do_vfp_nsyn_opcode (const char *opname)
10999 {
11000 const struct asm_opcode *opcode;
11001
11002 opcode = hash_find (arm_ops_hsh, opname);
11003
11004 if (!opcode)
11005 abort ();
11006
11007 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
11008 thumb_mode ? *opcode->tvariant : *opcode->avariant),
11009 _(BAD_FPU));
11010
11011 if (thumb_mode)
11012 {
11013 inst.instruction = opcode->tvalue;
11014 opcode->tencode ();
11015 }
11016 else
11017 {
11018 inst.instruction = (inst.cond << 28) | opcode->avalue;
11019 opcode->aencode ();
11020 }
11021 }
11022
11023 static void
11024 do_vfp_nsyn_add_sub (enum neon_shape rs)
11025 {
11026 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
11027
11028 if (rs == NS_FFF)
11029 {
11030 if (is_add)
11031 do_vfp_nsyn_opcode ("fadds");
11032 else
11033 do_vfp_nsyn_opcode ("fsubs");
11034 }
11035 else
11036 {
11037 if (is_add)
11038 do_vfp_nsyn_opcode ("faddd");
11039 else
11040 do_vfp_nsyn_opcode ("fsubd");
11041 }
11042 }
11043
11044 /* Check operand types to see if this is a VFP instruction, and if so call
11045 PFN (). */
11046
11047 static int
11048 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
11049 {
11050 enum neon_shape rs;
11051 struct neon_type_el et;
11052
11053 switch (args)
11054 {
11055 case 2:
11056 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11057 et = neon_check_type (2, rs,
11058 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11059 break;
11060
11061 case 3:
11062 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11063 et = neon_check_type (3, rs,
11064 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11065 break;
11066
11067 default:
11068 abort ();
11069 }
11070
11071 if (et.type != NT_invtype)
11072 {
11073 pfn (rs);
11074 return SUCCESS;
11075 }
11076 else
11077 inst.error = NULL;
11078
11079 return FAIL;
11080 }
11081
11082 static void
11083 do_vfp_nsyn_mla_mls (enum neon_shape rs)
11084 {
11085 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
11086
11087 if (rs == NS_FFF)
11088 {
11089 if (is_mla)
11090 do_vfp_nsyn_opcode ("fmacs");
11091 else
11092 do_vfp_nsyn_opcode ("fmscs");
11093 }
11094 else
11095 {
11096 if (is_mla)
11097 do_vfp_nsyn_opcode ("fmacd");
11098 else
11099 do_vfp_nsyn_opcode ("fmscd");
11100 }
11101 }
11102
11103 static void
11104 do_vfp_nsyn_mul (enum neon_shape rs)
11105 {
11106 if (rs == NS_FFF)
11107 do_vfp_nsyn_opcode ("fmuls");
11108 else
11109 do_vfp_nsyn_opcode ("fmuld");
11110 }
11111
11112 static void
11113 do_vfp_nsyn_abs_neg (enum neon_shape rs)
11114 {
11115 int is_neg = (inst.instruction & 0x80) != 0;
11116 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
11117
11118 if (rs == NS_FF)
11119 {
11120 if (is_neg)
11121 do_vfp_nsyn_opcode ("fnegs");
11122 else
11123 do_vfp_nsyn_opcode ("fabss");
11124 }
11125 else
11126 {
11127 if (is_neg)
11128 do_vfp_nsyn_opcode ("fnegd");
11129 else
11130 do_vfp_nsyn_opcode ("fabsd");
11131 }
11132 }
11133
11134 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
11135 insns belong to Neon, and are handled elsewhere. */
11136
11137 static void
11138 do_vfp_nsyn_ldm_stm (int is_dbmode)
11139 {
11140 int is_ldm = (inst.instruction & (1 << 20)) != 0;
11141 if (is_ldm)
11142 {
11143 if (is_dbmode)
11144 do_vfp_nsyn_opcode ("fldmdbs");
11145 else
11146 do_vfp_nsyn_opcode ("fldmias");
11147 }
11148 else
11149 {
11150 if (is_dbmode)
11151 do_vfp_nsyn_opcode ("fstmdbs");
11152 else
11153 do_vfp_nsyn_opcode ("fstmias");
11154 }
11155 }
11156
11157 static void
11158 do_vfp_nsyn_sqrt (void)
11159 {
11160 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11161 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11162
11163 if (rs == NS_FF)
11164 do_vfp_nsyn_opcode ("fsqrts");
11165 else
11166 do_vfp_nsyn_opcode ("fsqrtd");
11167 }
11168
11169 static void
11170 do_vfp_nsyn_div (void)
11171 {
11172 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11173 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11174 N_F32 | N_F64 | N_KEY | N_VFP);
11175
11176 if (rs == NS_FFF)
11177 do_vfp_nsyn_opcode ("fdivs");
11178 else
11179 do_vfp_nsyn_opcode ("fdivd");
11180 }
11181
11182 static void
11183 do_vfp_nsyn_nmul (void)
11184 {
11185 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11186 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11187 N_F32 | N_F64 | N_KEY | N_VFP);
11188
11189 if (rs == NS_FFF)
11190 {
11191 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11192 do_vfp_sp_dyadic ();
11193 }
11194 else
11195 {
11196 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11197 do_vfp_dp_rd_rn_rm ();
11198 }
11199 do_vfp_cond_or_thumb ();
11200 }
11201
11202 static void
11203 do_vfp_nsyn_cmp (void)
11204 {
11205 if (inst.operands[1].isreg)
11206 {
11207 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11208 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11209
11210 if (rs == NS_FF)
11211 {
11212 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11213 do_vfp_sp_monadic ();
11214 }
11215 else
11216 {
11217 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11218 do_vfp_dp_rd_rm ();
11219 }
11220 }
11221 else
11222 {
11223 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
11224 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
11225
11226 switch (inst.instruction & 0x0fffffff)
11227 {
11228 case N_MNEM_vcmp:
11229 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
11230 break;
11231 case N_MNEM_vcmpe:
11232 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
11233 break;
11234 default:
11235 abort ();
11236 }
11237
11238 if (rs == NS_FI)
11239 {
11240 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11241 do_vfp_sp_compare_z ();
11242 }
11243 else
11244 {
11245 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11246 do_vfp_dp_rd ();
11247 }
11248 }
11249 do_vfp_cond_or_thumb ();
11250 }
11251
11252 static void
11253 nsyn_insert_sp (void)
11254 {
11255 inst.operands[1] = inst.operands[0];
11256 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
11257 inst.operands[0].reg = 13;
11258 inst.operands[0].isreg = 1;
11259 inst.operands[0].writeback = 1;
11260 inst.operands[0].present = 1;
11261 }
11262
11263 static void
11264 do_vfp_nsyn_push (void)
11265 {
11266 nsyn_insert_sp ();
11267 if (inst.operands[1].issingle)
11268 do_vfp_nsyn_opcode ("fstmdbs");
11269 else
11270 do_vfp_nsyn_opcode ("fstmdbd");
11271 }
11272
11273 static void
11274 do_vfp_nsyn_pop (void)
11275 {
11276 nsyn_insert_sp ();
11277 if (inst.operands[1].issingle)
11278 do_vfp_nsyn_opcode ("fldmias");
11279 else
11280 do_vfp_nsyn_opcode ("fldmiad");
11281 }
11282
11283 /* Fix up Neon data-processing instructions, ORing in the correct bits for
11284 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
11285
11286 static unsigned
11287 neon_dp_fixup (unsigned i)
11288 {
11289 if (thumb_mode)
11290 {
11291 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
11292 if (i & (1 << 24))
11293 i |= 1 << 28;
11294
11295 i &= ~(1 << 24);
11296
11297 i |= 0xef000000;
11298 }
11299 else
11300 i |= 0xf2000000;
11301
11302 return i;
11303 }
11304
11305 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
11306 (0, 1, 2, 3). */
11307
11308 static unsigned
11309 neon_logbits (unsigned x)
11310 {
11311 return ffs (x) - 4;
11312 }
11313
11314 #define LOW4(R) ((R) & 0xf)
11315 #define HI1(R) (((R) >> 4) & 1)
11316
11317 /* Encode insns with bit pattern:
11318
11319 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
11320 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
11321
11322 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
11323 different meaning for some instruction. */
11324
11325 static void
11326 neon_three_same (int isquad, int ubit, int size)
11327 {
11328 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11329 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11330 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
11331 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
11332 inst.instruction |= LOW4 (inst.operands[2].reg);
11333 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
11334 inst.instruction |= (isquad != 0) << 6;
11335 inst.instruction |= (ubit != 0) << 24;
11336 if (size != -1)
11337 inst.instruction |= neon_logbits (size) << 20;
11338
11339 inst.instruction = neon_dp_fixup (inst.instruction);
11340 }
11341
11342 /* Encode instructions of the form:
11343
11344 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
11345 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
11346
11347 Don't write size if SIZE == -1. */
11348
11349 static void
11350 neon_two_same (int qbit, int ubit, int size)
11351 {
11352 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11353 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11354 inst.instruction |= LOW4 (inst.operands[1].reg);
11355 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11356 inst.instruction |= (qbit != 0) << 6;
11357 inst.instruction |= (ubit != 0) << 24;
11358
11359 if (size != -1)
11360 inst.instruction |= neon_logbits (size) << 18;
11361
11362 inst.instruction = neon_dp_fixup (inst.instruction);
11363 }
11364
11365 /* Neon instruction encoders, in approximate order of appearance. */
11366
11367 static void
11368 do_neon_dyadic_i_su (void)
11369 {
11370 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11371 struct neon_type_el et = neon_check_type (3, rs,
11372 N_EQK, N_EQK, N_SU_32 | N_KEY);
11373 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11374 }
11375
11376 static void
11377 do_neon_dyadic_i64_su (void)
11378 {
11379 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11380 struct neon_type_el et = neon_check_type (3, rs,
11381 N_EQK, N_EQK, N_SU_ALL | N_KEY);
11382 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11383 }
11384
11385 static void
11386 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
11387 unsigned immbits)
11388 {
11389 unsigned size = et.size >> 3;
11390 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11391 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11392 inst.instruction |= LOW4 (inst.operands[1].reg);
11393 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11394 inst.instruction |= (isquad != 0) << 6;
11395 inst.instruction |= immbits << 16;
11396 inst.instruction |= (size >> 3) << 7;
11397 inst.instruction |= (size & 0x7) << 19;
11398 if (write_ubit)
11399 inst.instruction |= (uval != 0) << 24;
11400
11401 inst.instruction = neon_dp_fixup (inst.instruction);
11402 }
11403
11404 static void
11405 do_neon_shl_imm (void)
11406 {
11407 if (!inst.operands[2].isreg)
11408 {
11409 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11410 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
11411 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11412 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
11413 }
11414 else
11415 {
11416 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11417 struct neon_type_el et = neon_check_type (3, rs,
11418 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
11419 unsigned int tmp;
11420
11421 /* VSHL/VQSHL 3-register variants have syntax such as:
11422 vshl.xx Dd, Dm, Dn
11423 whereas other 3-register operations encoded by neon_three_same have
11424 syntax like:
11425 vadd.xx Dd, Dn, Dm
11426 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
11427 here. */
11428 tmp = inst.operands[2].reg;
11429 inst.operands[2].reg = inst.operands[1].reg;
11430 inst.operands[1].reg = tmp;
11431 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11432 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11433 }
11434 }
11435
11436 static void
11437 do_neon_qshl_imm (void)
11438 {
11439 if (!inst.operands[2].isreg)
11440 {
11441 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11442 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
11443
11444 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11445 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
11446 inst.operands[2].imm);
11447 }
11448 else
11449 {
11450 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11451 struct neon_type_el et = neon_check_type (3, rs,
11452 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
11453 unsigned int tmp;
11454
11455 /* See note in do_neon_shl_imm. */
11456 tmp = inst.operands[2].reg;
11457 inst.operands[2].reg = inst.operands[1].reg;
11458 inst.operands[1].reg = tmp;
11459 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11460 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11461 }
11462 }
11463
11464 static void
11465 do_neon_rshl (void)
11466 {
11467 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11468 struct neon_type_el et = neon_check_type (3, rs,
11469 N_EQK, N_EQK, N_SU_ALL | N_KEY);
11470 unsigned int tmp;
11471
11472 tmp = inst.operands[2].reg;
11473 inst.operands[2].reg = inst.operands[1].reg;
11474 inst.operands[1].reg = tmp;
11475 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11476 }
11477
11478 static int
11479 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
11480 {
11481 /* Handle .I8 pseudo-instructions. */
11482 if (size == 8)
11483 {
11484 /* Unfortunately, this will make everything apart from zero out-of-range.
11485 FIXME is this the intended semantics? There doesn't seem much point in
11486 accepting .I8 if so. */
11487 immediate |= immediate << 8;
11488 size = 16;
11489 }
11490
11491 if (size >= 32)
11492 {
11493 if (immediate == (immediate & 0x000000ff))
11494 {
11495 *immbits = immediate;
11496 return 0x1;
11497 }
11498 else if (immediate == (immediate & 0x0000ff00))
11499 {
11500 *immbits = immediate >> 8;
11501 return 0x3;
11502 }
11503 else if (immediate == (immediate & 0x00ff0000))
11504 {
11505 *immbits = immediate >> 16;
11506 return 0x5;
11507 }
11508 else if (immediate == (immediate & 0xff000000))
11509 {
11510 *immbits = immediate >> 24;
11511 return 0x7;
11512 }
11513 if ((immediate & 0xffff) != (immediate >> 16))
11514 goto bad_immediate;
11515 immediate &= 0xffff;
11516 }
11517
11518 if (immediate == (immediate & 0x000000ff))
11519 {
11520 *immbits = immediate;
11521 return 0x9;
11522 }
11523 else if (immediate == (immediate & 0x0000ff00))
11524 {
11525 *immbits = immediate >> 8;
11526 return 0xb;
11527 }
11528
11529 bad_immediate:
11530 first_error (_("immediate value out of range"));
11531 return FAIL;
11532 }
11533
11534 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
11535 A, B, C, D. */
11536
11537 static int
11538 neon_bits_same_in_bytes (unsigned imm)
11539 {
11540 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
11541 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
11542 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
11543 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
11544 }
11545
11546 /* For immediate of above form, return 0bABCD. */
11547
11548 static unsigned
11549 neon_squash_bits (unsigned imm)
11550 {
11551 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
11552 | ((imm & 0x01000000) >> 21);
11553 }
11554
11555 /* Compress quarter-float representation to 0b...000 abcdefgh. */
11556
11557 static unsigned
11558 neon_qfloat_bits (unsigned imm)
11559 {
11560 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
11561 }
11562
11563 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
11564 the instruction. *OP is passed as the initial value of the op field, and
11565 may be set to a different value depending on the constant (i.e.
11566 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
11567 MVN). If the immediate looks like a repeated parttern then also
11568 try smaller element sizes. */
11569
11570 static int
11571 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, unsigned *immbits,
11572 int *op, int size, enum neon_el_type type)
11573 {
11574 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
11575 {
11576 if (size != 32 || *op == 1)
11577 return FAIL;
11578 *immbits = neon_qfloat_bits (immlo);
11579 return 0xf;
11580 }
11581
11582 if (size == 64)
11583 {
11584 if (neon_bits_same_in_bytes (immhi)
11585 && neon_bits_same_in_bytes (immlo))
11586 {
11587 if (*op == 1)
11588 return FAIL;
11589 *immbits = (neon_squash_bits (immhi) << 4)
11590 | neon_squash_bits (immlo);
11591 *op = 1;
11592 return 0xe;
11593 }
11594
11595 if (immhi != immlo)
11596 return FAIL;
11597 }
11598
11599 if (size >= 32)
11600 {
11601 if (immlo == (immlo & 0x000000ff))
11602 {
11603 *immbits = immlo;
11604 return 0x0;
11605 }
11606 else if (immlo == (immlo & 0x0000ff00))
11607 {
11608 *immbits = immlo >> 8;
11609 return 0x2;
11610 }
11611 else if (immlo == (immlo & 0x00ff0000))
11612 {
11613 *immbits = immlo >> 16;
11614 return 0x4;
11615 }
11616 else if (immlo == (immlo & 0xff000000))
11617 {
11618 *immbits = immlo >> 24;
11619 return 0x6;
11620 }
11621 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
11622 {
11623 *immbits = (immlo >> 8) & 0xff;
11624 return 0xc;
11625 }
11626 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
11627 {
11628 *immbits = (immlo >> 16) & 0xff;
11629 return 0xd;
11630 }
11631
11632 if ((immlo & 0xffff) != (immlo >> 16))
11633 return FAIL;
11634 immlo &= 0xffff;
11635 }
11636
11637 if (size >= 16)
11638 {
11639 if (immlo == (immlo & 0x000000ff))
11640 {
11641 *immbits = immlo;
11642 return 0x8;
11643 }
11644 else if (immlo == (immlo & 0x0000ff00))
11645 {
11646 *immbits = immlo >> 8;
11647 return 0xa;
11648 }
11649
11650 if ((immlo & 0xff) != (immlo >> 8))
11651 return FAIL;
11652 immlo &= 0xff;
11653 }
11654
11655 if (immlo == (immlo & 0x000000ff))
11656 {
11657 /* Don't allow MVN with 8-bit immediate. */
11658 if (*op == 1)
11659 return FAIL;
11660 *immbits = immlo;
11661 return 0xe;
11662 }
11663
11664 return FAIL;
11665 }
11666
11667 /* Write immediate bits [7:0] to the following locations:
11668
11669 |28/24|23 19|18 16|15 4|3 0|
11670 | 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|
11671
11672 This function is used by VMOV/VMVN/VORR/VBIC. */
11673
11674 static void
11675 neon_write_immbits (unsigned immbits)
11676 {
11677 inst.instruction |= immbits & 0xf;
11678 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
11679 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
11680 }
11681
11682 /* Invert low-order SIZE bits of XHI:XLO. */
11683
11684 static void
11685 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
11686 {
11687 unsigned immlo = xlo ? *xlo : 0;
11688 unsigned immhi = xhi ? *xhi : 0;
11689
11690 switch (size)
11691 {
11692 case 8:
11693 immlo = (~immlo) & 0xff;
11694 break;
11695
11696 case 16:
11697 immlo = (~immlo) & 0xffff;
11698 break;
11699
11700 case 64:
11701 immhi = (~immhi) & 0xffffffff;
11702 /* fall through. */
11703
11704 case 32:
11705 immlo = (~immlo) & 0xffffffff;
11706 break;
11707
11708 default:
11709 abort ();
11710 }
11711
11712 if (xlo)
11713 *xlo = immlo;
11714
11715 if (xhi)
11716 *xhi = immhi;
11717 }
11718
11719 static void
11720 do_neon_logic (void)
11721 {
11722 if (inst.operands[2].present && inst.operands[2].isreg)
11723 {
11724 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11725 neon_check_type (3, rs, N_IGNORE_TYPE);
11726 /* U bit and size field were set as part of the bitmask. */
11727 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11728 neon_three_same (neon_quad (rs), 0, -1);
11729 }
11730 else
11731 {
11732 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
11733 struct neon_type_el et = neon_check_type (2, rs,
11734 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
11735 enum neon_opc opcode = inst.instruction & 0x0fffffff;
11736 unsigned immbits;
11737 int cmode;
11738
11739 if (et.type == NT_invtype)
11740 return;
11741
11742 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11743
11744 immbits = inst.operands[1].imm;
11745 if (et.size == 64)
11746 {
11747 /* .i64 is a pseudo-op, so the immediate must be a repeating
11748 pattern. */
11749 if (immbits != (inst.operands[1].regisimm ?
11750 inst.operands[1].reg : 0))
11751 {
11752 /* Set immbits to an invalid constant. */
11753 immbits = 0xdeadbeef;
11754 }
11755 }
11756
11757 switch (opcode)
11758 {
11759 case N_MNEM_vbic:
11760 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11761 break;
11762
11763 case N_MNEM_vorr:
11764 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11765 break;
11766
11767 case N_MNEM_vand:
11768 /* Pseudo-instruction for VBIC. */
11769 neon_invert_size (&immbits, 0, et.size);
11770 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11771 break;
11772
11773 case N_MNEM_vorn:
11774 /* Pseudo-instruction for VORR. */
11775 neon_invert_size (&immbits, 0, et.size);
11776 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11777 break;
11778
11779 default:
11780 abort ();
11781 }
11782
11783 if (cmode == FAIL)
11784 return;
11785
11786 inst.instruction |= neon_quad (rs) << 6;
11787 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11788 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11789 inst.instruction |= cmode << 8;
11790 neon_write_immbits (immbits);
11791
11792 inst.instruction = neon_dp_fixup (inst.instruction);
11793 }
11794 }
11795
11796 static void
11797 do_neon_bitfield (void)
11798 {
11799 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11800 neon_check_type (3, rs, N_IGNORE_TYPE);
11801 neon_three_same (neon_quad (rs), 0, -1);
11802 }
11803
11804 static void
11805 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
11806 unsigned destbits)
11807 {
11808 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11809 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
11810 types | N_KEY);
11811 if (et.type == NT_float)
11812 {
11813 inst.instruction = NEON_ENC_FLOAT (inst.instruction);
11814 neon_three_same (neon_quad (rs), 0, -1);
11815 }
11816 else
11817 {
11818 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11819 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
11820 }
11821 }
11822
11823 static void
11824 do_neon_dyadic_if_su (void)
11825 {
11826 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
11827 }
11828
11829 static void
11830 do_neon_dyadic_if_su_d (void)
11831 {
11832 /* This version only allow D registers, but that constraint is enforced during
11833 operand parsing so we don't need to do anything extra here. */
11834 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
11835 }
11836
11837 static void
11838 do_neon_dyadic_if_i_d (void)
11839 {
11840 /* The "untyped" case can't happen. Do this to stop the "U" bit being
11841 affected if we specify unsigned args. */
11842 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
11843 }
11844
11845 enum vfp_or_neon_is_neon_bits
11846 {
11847 NEON_CHECK_CC = 1,
11848 NEON_CHECK_ARCH = 2
11849 };
11850
11851 /* Call this function if an instruction which may have belonged to the VFP or
11852 Neon instruction sets, but turned out to be a Neon instruction (due to the
11853 operand types involved, etc.). We have to check and/or fix-up a couple of
11854 things:
11855
11856 - Make sure the user hasn't attempted to make a Neon instruction
11857 conditional.
11858 - Alter the value in the condition code field if necessary.
11859 - Make sure that the arch supports Neon instructions.
11860
11861 Which of these operations take place depends on bits from enum
11862 vfp_or_neon_is_neon_bits.
11863
11864 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
11865 current instruction's condition is COND_ALWAYS, the condition field is
11866 changed to inst.uncond_value. This is necessary because instructions shared
11867 between VFP and Neon may be conditional for the VFP variants only, and the
11868 unconditional Neon version must have, e.g., 0xF in the condition field. */
11869
11870 static int
11871 vfp_or_neon_is_neon (unsigned check)
11872 {
11873 /* Conditions are always legal in Thumb mode (IT blocks). */
11874 if (!thumb_mode && (check & NEON_CHECK_CC))
11875 {
11876 if (inst.cond != COND_ALWAYS)
11877 {
11878 first_error (_(BAD_COND));
11879 return FAIL;
11880 }
11881 if (inst.uncond_value != -1)
11882 inst.instruction |= inst.uncond_value << 28;
11883 }
11884
11885 if ((check & NEON_CHECK_ARCH)
11886 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
11887 {
11888 first_error (_(BAD_FPU));
11889 return FAIL;
11890 }
11891
11892 return SUCCESS;
11893 }
11894
11895 static void
11896 do_neon_addsub_if_i (void)
11897 {
11898 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
11899 return;
11900
11901 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
11902 return;
11903
11904 /* The "untyped" case can't happen. Do this to stop the "U" bit being
11905 affected if we specify unsigned args. */
11906 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
11907 }
11908
11909 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
11910 result to be:
11911 V<op> A,B (A is operand 0, B is operand 2)
11912 to mean:
11913 V<op> A,B,A
11914 not:
11915 V<op> A,B,B
11916 so handle that case specially. */
11917
11918 static void
11919 neon_exchange_operands (void)
11920 {
11921 void *scratch = alloca (sizeof (inst.operands[0]));
11922 if (inst.operands[1].present)
11923 {
11924 /* Swap operands[1] and operands[2]. */
11925 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
11926 inst.operands[1] = inst.operands[2];
11927 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
11928 }
11929 else
11930 {
11931 inst.operands[1] = inst.operands[2];
11932 inst.operands[2] = inst.operands[0];
11933 }
11934 }
11935
11936 static void
11937 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
11938 {
11939 if (inst.operands[2].isreg)
11940 {
11941 if (invert)
11942 neon_exchange_operands ();
11943 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
11944 }
11945 else
11946 {
11947 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11948 struct neon_type_el et = neon_check_type (2, rs,
11949 N_EQK | N_SIZ, immtypes | N_KEY);
11950
11951 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11952 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11953 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11954 inst.instruction |= LOW4 (inst.operands[1].reg);
11955 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11956 inst.instruction |= neon_quad (rs) << 6;
11957 inst.instruction |= (et.type == NT_float) << 10;
11958 inst.instruction |= neon_logbits (et.size) << 18;
11959
11960 inst.instruction = neon_dp_fixup (inst.instruction);
11961 }
11962 }
11963
11964 static void
11965 do_neon_cmp (void)
11966 {
11967 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
11968 }
11969
11970 static void
11971 do_neon_cmp_inv (void)
11972 {
11973 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
11974 }
11975
11976 static void
11977 do_neon_ceq (void)
11978 {
11979 neon_compare (N_IF_32, N_IF_32, FALSE);
11980 }
11981
11982 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
11983 scalars, which are encoded in 5 bits, M : Rm.
11984 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
11985 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
11986 index in M. */
11987
11988 static unsigned
11989 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
11990 {
11991 unsigned regno = NEON_SCALAR_REG (scalar);
11992 unsigned elno = NEON_SCALAR_INDEX (scalar);
11993
11994 switch (elsize)
11995 {
11996 case 16:
11997 if (regno > 7 || elno > 3)
11998 goto bad_scalar;
11999 return regno | (elno << 3);
12000
12001 case 32:
12002 if (regno > 15 || elno > 1)
12003 goto bad_scalar;
12004 return regno | (elno << 4);
12005
12006 default:
12007 bad_scalar:
12008 first_error (_("scalar out of range for multiply instruction"));
12009 }
12010
12011 return 0;
12012 }
12013
12014 /* Encode multiply / multiply-accumulate scalar instructions. */
12015
12016 static void
12017 neon_mul_mac (struct neon_type_el et, int ubit)
12018 {
12019 unsigned scalar;
12020
12021 /* Give a more helpful error message if we have an invalid type. */
12022 if (et.type == NT_invtype)
12023 return;
12024
12025 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
12026 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12027 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12028 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12029 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12030 inst.instruction |= LOW4 (scalar);
12031 inst.instruction |= HI1 (scalar) << 5;
12032 inst.instruction |= (et.type == NT_float) << 8;
12033 inst.instruction |= neon_logbits (et.size) << 20;
12034 inst.instruction |= (ubit != 0) << 24;
12035
12036 inst.instruction = neon_dp_fixup (inst.instruction);
12037 }
12038
12039 static void
12040 do_neon_mac_maybe_scalar (void)
12041 {
12042 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
12043 return;
12044
12045 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12046 return;
12047
12048 if (inst.operands[2].isscalar)
12049 {
12050 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
12051 struct neon_type_el et = neon_check_type (3, rs,
12052 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
12053 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12054 neon_mul_mac (et, neon_quad (rs));
12055 }
12056 else
12057 {
12058 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12059 affected if we specify unsigned args. */
12060 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12061 }
12062 }
12063
12064 static void
12065 do_neon_tst (void)
12066 {
12067 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12068 struct neon_type_el et = neon_check_type (3, rs,
12069 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
12070 neon_three_same (neon_quad (rs), 0, et.size);
12071 }
12072
12073 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
12074 same types as the MAC equivalents. The polynomial type for this instruction
12075 is encoded the same as the integer type. */
12076
12077 static void
12078 do_neon_mul (void)
12079 {
12080 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
12081 return;
12082
12083 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12084 return;
12085
12086 if (inst.operands[2].isscalar)
12087 do_neon_mac_maybe_scalar ();
12088 else
12089 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
12090 }
12091
12092 static void
12093 do_neon_qdmulh (void)
12094 {
12095 if (inst.operands[2].isscalar)
12096 {
12097 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
12098 struct neon_type_el et = neon_check_type (3, rs,
12099 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12100 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12101 neon_mul_mac (et, neon_quad (rs));
12102 }
12103 else
12104 {
12105 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12106 struct neon_type_el et = neon_check_type (3, rs,
12107 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12108 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12109 /* The U bit (rounding) comes from bit mask. */
12110 neon_three_same (neon_quad (rs), 0, et.size);
12111 }
12112 }
12113
12114 static void
12115 do_neon_fcmp_absolute (void)
12116 {
12117 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12118 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12119 /* Size field comes from bit mask. */
12120 neon_three_same (neon_quad (rs), 1, -1);
12121 }
12122
12123 static void
12124 do_neon_fcmp_absolute_inv (void)
12125 {
12126 neon_exchange_operands ();
12127 do_neon_fcmp_absolute ();
12128 }
12129
12130 static void
12131 do_neon_step (void)
12132 {
12133 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12134 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12135 neon_three_same (neon_quad (rs), 0, -1);
12136 }
12137
12138 static void
12139 do_neon_abs_neg (void)
12140 {
12141 enum neon_shape rs;
12142 struct neon_type_el et;
12143
12144 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
12145 return;
12146
12147 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12148 return;
12149
12150 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12151 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
12152
12153 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12154 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12155 inst.instruction |= LOW4 (inst.operands[1].reg);
12156 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12157 inst.instruction |= neon_quad (rs) << 6;
12158 inst.instruction |= (et.type == NT_float) << 10;
12159 inst.instruction |= neon_logbits (et.size) << 18;
12160
12161 inst.instruction = neon_dp_fixup (inst.instruction);
12162 }
12163
12164 static void
12165 do_neon_sli (void)
12166 {
12167 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12168 struct neon_type_el et = neon_check_type (2, rs,
12169 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12170 int imm = inst.operands[2].imm;
12171 constraint (imm < 0 || (unsigned)imm >= et.size,
12172 _("immediate out of range for insert"));
12173 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
12174 }
12175
12176 static void
12177 do_neon_sri (void)
12178 {
12179 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12180 struct neon_type_el et = neon_check_type (2, rs,
12181 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12182 int imm = inst.operands[2].imm;
12183 constraint (imm < 1 || (unsigned)imm > et.size,
12184 _("immediate out of range for insert"));
12185 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
12186 }
12187
12188 static void
12189 do_neon_qshlu_imm (void)
12190 {
12191 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12192 struct neon_type_el et = neon_check_type (2, rs,
12193 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
12194 int imm = inst.operands[2].imm;
12195 constraint (imm < 0 || (unsigned)imm >= et.size,
12196 _("immediate out of range for shift"));
12197 /* Only encodes the 'U present' variant of the instruction.
12198 In this case, signed types have OP (bit 8) set to 0.
12199 Unsigned types have OP set to 1. */
12200 inst.instruction |= (et.type == NT_unsigned) << 8;
12201 /* The rest of the bits are the same as other immediate shifts. */
12202 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
12203 }
12204
12205 static void
12206 do_neon_qmovn (void)
12207 {
12208 struct neon_type_el et = neon_check_type (2, NS_DQ,
12209 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12210 /* Saturating move where operands can be signed or unsigned, and the
12211 destination has the same signedness. */
12212 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12213 if (et.type == NT_unsigned)
12214 inst.instruction |= 0xc0;
12215 else
12216 inst.instruction |= 0x80;
12217 neon_two_same (0, 1, et.size / 2);
12218 }
12219
12220 static void
12221 do_neon_qmovun (void)
12222 {
12223 struct neon_type_el et = neon_check_type (2, NS_DQ,
12224 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12225 /* Saturating move with unsigned results. Operands must be signed. */
12226 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12227 neon_two_same (0, 1, et.size / 2);
12228 }
12229
12230 static void
12231 do_neon_rshift_sat_narrow (void)
12232 {
12233 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12234 or unsigned. If operands are unsigned, results must also be unsigned. */
12235 struct neon_type_el et = neon_check_type (2, NS_DQI,
12236 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12237 int imm = inst.operands[2].imm;
12238 /* This gets the bounds check, size encoding and immediate bits calculation
12239 right. */
12240 et.size /= 2;
12241
12242 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
12243 VQMOVN.I<size> <Dd>, <Qm>. */
12244 if (imm == 0)
12245 {
12246 inst.operands[2].present = 0;
12247 inst.instruction = N_MNEM_vqmovn;
12248 do_neon_qmovn ();
12249 return;
12250 }
12251
12252 constraint (imm < 1 || (unsigned)imm > et.size,
12253 _("immediate out of range"));
12254 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
12255 }
12256
12257 static void
12258 do_neon_rshift_sat_narrow_u (void)
12259 {
12260 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12261 or unsigned. If operands are unsigned, results must also be unsigned. */
12262 struct neon_type_el et = neon_check_type (2, NS_DQI,
12263 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12264 int imm = inst.operands[2].imm;
12265 /* This gets the bounds check, size encoding and immediate bits calculation
12266 right. */
12267 et.size /= 2;
12268
12269 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
12270 VQMOVUN.I<size> <Dd>, <Qm>. */
12271 if (imm == 0)
12272 {
12273 inst.operands[2].present = 0;
12274 inst.instruction = N_MNEM_vqmovun;
12275 do_neon_qmovun ();
12276 return;
12277 }
12278
12279 constraint (imm < 1 || (unsigned)imm > et.size,
12280 _("immediate out of range"));
12281 /* FIXME: The manual is kind of unclear about what value U should have in
12282 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
12283 must be 1. */
12284 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
12285 }
12286
12287 static void
12288 do_neon_movn (void)
12289 {
12290 struct neon_type_el et = neon_check_type (2, NS_DQ,
12291 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12292 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12293 neon_two_same (0, 1, et.size / 2);
12294 }
12295
12296 static void
12297 do_neon_rshift_narrow (void)
12298 {
12299 struct neon_type_el et = neon_check_type (2, NS_DQI,
12300 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12301 int imm = inst.operands[2].imm;
12302 /* This gets the bounds check, size encoding and immediate bits calculation
12303 right. */
12304 et.size /= 2;
12305
12306 /* If immediate is zero then we are a pseudo-instruction for
12307 VMOVN.I<size> <Dd>, <Qm> */
12308 if (imm == 0)
12309 {
12310 inst.operands[2].present = 0;
12311 inst.instruction = N_MNEM_vmovn;
12312 do_neon_movn ();
12313 return;
12314 }
12315
12316 constraint (imm < 1 || (unsigned)imm > et.size,
12317 _("immediate out of range for narrowing operation"));
12318 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
12319 }
12320
12321 static void
12322 do_neon_shll (void)
12323 {
12324 /* FIXME: Type checking when lengthening. */
12325 struct neon_type_el et = neon_check_type (2, NS_QDI,
12326 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
12327 unsigned imm = inst.operands[2].imm;
12328
12329 if (imm == et.size)
12330 {
12331 /* Maximum shift variant. */
12332 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12333 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12334 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12335 inst.instruction |= LOW4 (inst.operands[1].reg);
12336 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12337 inst.instruction |= neon_logbits (et.size) << 18;
12338
12339 inst.instruction = neon_dp_fixup (inst.instruction);
12340 }
12341 else
12342 {
12343 /* A more-specific type check for non-max versions. */
12344 et = neon_check_type (2, NS_QDI,
12345 N_EQK | N_DBL, N_SU_32 | N_KEY);
12346 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12347 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
12348 }
12349 }
12350
12351 /* Check the various types for the VCVT instruction, and return which version
12352 the current instruction is. */
12353
12354 static int
12355 neon_cvt_flavour (enum neon_shape rs)
12356 {
12357 #define CVT_VAR(C,X,Y) \
12358 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
12359 if (et.type != NT_invtype) \
12360 { \
12361 inst.error = NULL; \
12362 return (C); \
12363 }
12364 struct neon_type_el et;
12365 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
12366 || rs == NS_FF) ? N_VFP : 0;
12367 /* The instruction versions which take an immediate take one register
12368 argument, which is extended to the width of the full register. Thus the
12369 "source" and "destination" registers must have the same width. Hack that
12370 here by making the size equal to the key (wider, in this case) operand. */
12371 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
12372
12373 CVT_VAR (0, N_S32, N_F32);
12374 CVT_VAR (1, N_U32, N_F32);
12375 CVT_VAR (2, N_F32, N_S32);
12376 CVT_VAR (3, N_F32, N_U32);
12377
12378 whole_reg = N_VFP;
12379
12380 /* VFP instructions. */
12381 CVT_VAR (4, N_F32, N_F64);
12382 CVT_VAR (5, N_F64, N_F32);
12383 CVT_VAR (6, N_S32, N_F64 | key);
12384 CVT_VAR (7, N_U32, N_F64 | key);
12385 CVT_VAR (8, N_F64 | key, N_S32);
12386 CVT_VAR (9, N_F64 | key, N_U32);
12387 /* VFP instructions with bitshift. */
12388 CVT_VAR (10, N_F32 | key, N_S16);
12389 CVT_VAR (11, N_F32 | key, N_U16);
12390 CVT_VAR (12, N_F64 | key, N_S16);
12391 CVT_VAR (13, N_F64 | key, N_U16);
12392 CVT_VAR (14, N_S16, N_F32 | key);
12393 CVT_VAR (15, N_U16, N_F32 | key);
12394 CVT_VAR (16, N_S16, N_F64 | key);
12395 CVT_VAR (17, N_U16, N_F64 | key);
12396
12397 return -1;
12398 #undef CVT_VAR
12399 }
12400
12401 /* Neon-syntax VFP conversions. */
12402
12403 static void
12404 do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
12405 {
12406 const char *opname = 0;
12407
12408 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
12409 {
12410 /* Conversions with immediate bitshift. */
12411 const char *enc[] =
12412 {
12413 "ftosls",
12414 "ftouls",
12415 "fsltos",
12416 "fultos",
12417 NULL,
12418 NULL,
12419 "ftosld",
12420 "ftould",
12421 "fsltod",
12422 "fultod",
12423 "fshtos",
12424 "fuhtos",
12425 "fshtod",
12426 "fuhtod",
12427 "ftoshs",
12428 "ftouhs",
12429 "ftoshd",
12430 "ftouhd"
12431 };
12432
12433 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12434 {
12435 opname = enc[flavour];
12436 constraint (inst.operands[0].reg != inst.operands[1].reg,
12437 _("operands 0 and 1 must be the same register"));
12438 inst.operands[1] = inst.operands[2];
12439 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
12440 }
12441 }
12442 else
12443 {
12444 /* Conversions without bitshift. */
12445 const char *enc[] =
12446 {
12447 "ftosis",
12448 "ftouis",
12449 "fsitos",
12450 "fuitos",
12451 "fcvtsd",
12452 "fcvtds",
12453 "ftosid",
12454 "ftouid",
12455 "fsitod",
12456 "fuitod"
12457 };
12458
12459 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12460 opname = enc[flavour];
12461 }
12462
12463 if (opname)
12464 do_vfp_nsyn_opcode (opname);
12465 }
12466
12467 static void
12468 do_vfp_nsyn_cvtz (void)
12469 {
12470 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
12471 int flavour = neon_cvt_flavour (rs);
12472 const char *enc[] =
12473 {
12474 "ftosizs",
12475 "ftouizs",
12476 NULL,
12477 NULL,
12478 NULL,
12479 NULL,
12480 "ftosizd",
12481 "ftouizd"
12482 };
12483
12484 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
12485 do_vfp_nsyn_opcode (enc[flavour]);
12486 }
12487
12488 static void
12489 do_neon_cvt (void)
12490 {
12491 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
12492 NS_FD, NS_DF, NS_FF, NS_NULL);
12493 int flavour = neon_cvt_flavour (rs);
12494
12495 /* VFP rather than Neon conversions. */
12496 if (flavour >= 4)
12497 {
12498 do_vfp_nsyn_cvt (rs, flavour);
12499 return;
12500 }
12501
12502 switch (rs)
12503 {
12504 case NS_DDI:
12505 case NS_QQI:
12506 {
12507 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12508 return;
12509
12510 /* Fixed-point conversion with #0 immediate is encoded as an
12511 integer conversion. */
12512 if (inst.operands[2].present && inst.operands[2].imm == 0)
12513 goto int_encode;
12514 unsigned immbits = 32 - inst.operands[2].imm;
12515 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
12516 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12517 if (flavour != -1)
12518 inst.instruction |= enctab[flavour];
12519 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12520 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12521 inst.instruction |= LOW4 (inst.operands[1].reg);
12522 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12523 inst.instruction |= neon_quad (rs) << 6;
12524 inst.instruction |= 1 << 21;
12525 inst.instruction |= immbits << 16;
12526
12527 inst.instruction = neon_dp_fixup (inst.instruction);
12528 }
12529 break;
12530
12531 case NS_DD:
12532 case NS_QQ:
12533 int_encode:
12534 {
12535 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
12536
12537 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12538
12539 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12540 return;
12541
12542 if (flavour != -1)
12543 inst.instruction |= enctab[flavour];
12544
12545 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12546 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12547 inst.instruction |= LOW4 (inst.operands[1].reg);
12548 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12549 inst.instruction |= neon_quad (rs) << 6;
12550 inst.instruction |= 2 << 18;
12551
12552 inst.instruction = neon_dp_fixup (inst.instruction);
12553 }
12554 break;
12555
12556 default:
12557 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
12558 do_vfp_nsyn_cvt (rs, flavour);
12559 }
12560 }
12561
12562 static void
12563 neon_move_immediate (void)
12564 {
12565 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
12566 struct neon_type_el et = neon_check_type (2, rs,
12567 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
12568 unsigned immlo, immhi = 0, immbits;
12569 int op, cmode;
12570
12571 constraint (et.type == NT_invtype,
12572 _("operand size must be specified for immediate VMOV"));
12573
12574 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
12575 op = (inst.instruction & (1 << 5)) != 0;
12576
12577 immlo = inst.operands[1].imm;
12578 if (inst.operands[1].regisimm)
12579 immhi = inst.operands[1].reg;
12580
12581 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
12582 _("immediate has bits set outside the operand size"));
12583
12584 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, &immbits, &op,
12585 et.size, et.type)) == FAIL)
12586 {
12587 /* Invert relevant bits only. */
12588 neon_invert_size (&immlo, &immhi, et.size);
12589 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
12590 with one or the other; those cases are caught by
12591 neon_cmode_for_move_imm. */
12592 op = !op;
12593 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, &immbits, &op,
12594 et.size, et.type)) == FAIL)
12595 {
12596 first_error (_("immediate out of range"));
12597 return;
12598 }
12599 }
12600
12601 inst.instruction &= ~(1 << 5);
12602 inst.instruction |= op << 5;
12603
12604 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12605 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12606 inst.instruction |= neon_quad (rs) << 6;
12607 inst.instruction |= cmode << 8;
12608
12609 neon_write_immbits (immbits);
12610 }
12611
12612 static void
12613 do_neon_mvn (void)
12614 {
12615 if (inst.operands[1].isreg)
12616 {
12617 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12618
12619 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12620 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12621 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12622 inst.instruction |= LOW4 (inst.operands[1].reg);
12623 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12624 inst.instruction |= neon_quad (rs) << 6;
12625 }
12626 else
12627 {
12628 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12629 neon_move_immediate ();
12630 }
12631
12632 inst.instruction = neon_dp_fixup (inst.instruction);
12633 }
12634
12635 /* Encode instructions of form:
12636
12637 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12638 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm |
12639
12640 */
12641
12642 static void
12643 neon_mixed_length (struct neon_type_el et, unsigned size)
12644 {
12645 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12646 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12647 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12648 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12649 inst.instruction |= LOW4 (inst.operands[2].reg);
12650 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12651 inst.instruction |= (et.type == NT_unsigned) << 24;
12652 inst.instruction |= neon_logbits (size) << 20;
12653
12654 inst.instruction = neon_dp_fixup (inst.instruction);
12655 }
12656
12657 static void
12658 do_neon_dyadic_long (void)
12659 {
12660 /* FIXME: Type checking for lengthening op. */
12661 struct neon_type_el et = neon_check_type (3, NS_QDD,
12662 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
12663 neon_mixed_length (et, et.size);
12664 }
12665
12666 static void
12667 do_neon_abal (void)
12668 {
12669 struct neon_type_el et = neon_check_type (3, NS_QDD,
12670 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
12671 neon_mixed_length (et, et.size);
12672 }
12673
12674 static void
12675 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
12676 {
12677 if (inst.operands[2].isscalar)
12678 {
12679 struct neon_type_el et = neon_check_type (3, NS_QDS,
12680 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
12681 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12682 neon_mul_mac (et, et.type == NT_unsigned);
12683 }
12684 else
12685 {
12686 struct neon_type_el et = neon_check_type (3, NS_QDD,
12687 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
12688 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12689 neon_mixed_length (et, et.size);
12690 }
12691 }
12692
12693 static void
12694 do_neon_mac_maybe_scalar_long (void)
12695 {
12696 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
12697 }
12698
12699 static void
12700 do_neon_dyadic_wide (void)
12701 {
12702 struct neon_type_el et = neon_check_type (3, NS_QQD,
12703 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
12704 neon_mixed_length (et, et.size);
12705 }
12706
12707 static void
12708 do_neon_dyadic_narrow (void)
12709 {
12710 struct neon_type_el et = neon_check_type (3, NS_QDD,
12711 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
12712 /* Operand sign is unimportant, and the U bit is part of the opcode,
12713 so force the operand type to integer. */
12714 et.type = NT_integer;
12715 neon_mixed_length (et, et.size / 2);
12716 }
12717
12718 static void
12719 do_neon_mul_sat_scalar_long (void)
12720 {
12721 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
12722 }
12723
12724 static void
12725 do_neon_vmull (void)
12726 {
12727 if (inst.operands[2].isscalar)
12728 do_neon_mac_maybe_scalar_long ();
12729 else
12730 {
12731 struct neon_type_el et = neon_check_type (3, NS_QDD,
12732 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
12733 if (et.type == NT_poly)
12734 inst.instruction = NEON_ENC_POLY (inst.instruction);
12735 else
12736 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12737 /* For polynomial encoding, size field must be 0b00 and the U bit must be
12738 zero. Should be OK as-is. */
12739 neon_mixed_length (et, et.size);
12740 }
12741 }
12742
12743 static void
12744 do_neon_ext (void)
12745 {
12746 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
12747 struct neon_type_el et = neon_check_type (3, rs,
12748 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12749 unsigned imm = (inst.operands[3].imm * et.size) / 8;
12750 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12751 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12752 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12753 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12754 inst.instruction |= LOW4 (inst.operands[2].reg);
12755 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12756 inst.instruction |= neon_quad (rs) << 6;
12757 inst.instruction |= imm << 8;
12758
12759 inst.instruction = neon_dp_fixup (inst.instruction);
12760 }
12761
12762 static void
12763 do_neon_rev (void)
12764 {
12765 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12766 struct neon_type_el et = neon_check_type (2, rs,
12767 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12768 unsigned op = (inst.instruction >> 7) & 3;
12769 /* N (width of reversed regions) is encoded as part of the bitmask. We
12770 extract it here to check the elements to be reversed are smaller.
12771 Otherwise we'd get a reserved instruction. */
12772 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
12773 assert (elsize != 0);
12774 constraint (et.size >= elsize,
12775 _("elements must be smaller than reversal region"));
12776 neon_two_same (neon_quad (rs), 1, et.size);
12777 }
12778
12779 static void
12780 do_neon_dup (void)
12781 {
12782 if (inst.operands[1].isscalar)
12783 {
12784 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
12785 struct neon_type_el et = neon_check_type (2, rs,
12786 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12787 unsigned sizebits = et.size >> 3;
12788 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
12789 int logsize = neon_logbits (et.size);
12790 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
12791
12792 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
12793 return;
12794
12795 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12796 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12797 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12798 inst.instruction |= LOW4 (dm);
12799 inst.instruction |= HI1 (dm) << 5;
12800 inst.instruction |= neon_quad (rs) << 6;
12801 inst.instruction |= x << 17;
12802 inst.instruction |= sizebits << 16;
12803
12804 inst.instruction = neon_dp_fixup (inst.instruction);
12805 }
12806 else
12807 {
12808 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
12809 struct neon_type_el et = neon_check_type (2, rs,
12810 N_8 | N_16 | N_32 | N_KEY, N_EQK);
12811 /* Duplicate ARM register to lanes of vector. */
12812 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
12813 switch (et.size)
12814 {
12815 case 8: inst.instruction |= 0x400000; break;
12816 case 16: inst.instruction |= 0x000020; break;
12817 case 32: inst.instruction |= 0x000000; break;
12818 default: break;
12819 }
12820 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
12821 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
12822 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
12823 inst.instruction |= neon_quad (rs) << 21;
12824 /* The encoding for this instruction is identical for the ARM and Thumb
12825 variants, except for the condition field. */
12826 do_vfp_cond_or_thumb ();
12827 }
12828 }
12829
12830 /* VMOV has particularly many variations. It can be one of:
12831 0. VMOV<c><q> <Qd>, <Qm>
12832 1. VMOV<c><q> <Dd>, <Dm>
12833 (Register operations, which are VORR with Rm = Rn.)
12834 2. VMOV<c><q>.<dt> <Qd>, #<imm>
12835 3. VMOV<c><q>.<dt> <Dd>, #<imm>
12836 (Immediate loads.)
12837 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
12838 (ARM register to scalar.)
12839 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
12840 (Two ARM registers to vector.)
12841 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
12842 (Scalar to ARM register.)
12843 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
12844 (Vector to two ARM registers.)
12845 8. VMOV.F32 <Sd>, <Sm>
12846 9. VMOV.F64 <Dd>, <Dm>
12847 (VFP register moves.)
12848 10. VMOV.F32 <Sd>, #imm
12849 11. VMOV.F64 <Dd>, #imm
12850 (VFP float immediate load.)
12851 12. VMOV <Rd>, <Sm>
12852 (VFP single to ARM reg.)
12853 13. VMOV <Sd>, <Rm>
12854 (ARM reg to VFP single.)
12855 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
12856 (Two ARM regs to two VFP singles.)
12857 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
12858 (Two VFP singles to two ARM regs.)
12859
12860 These cases can be disambiguated using neon_select_shape, except cases 1/9
12861 and 3/11 which depend on the operand type too.
12862
12863 All the encoded bits are hardcoded by this function.
12864
12865 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
12866 Cases 5, 7 may be used with VFPv2 and above.
12867
12868 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
12869 can specify a type where it doesn't make sense to, and is ignored).
12870 */
12871
12872 static void
12873 do_neon_mov (void)
12874 {
12875 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
12876 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
12877 NS_NULL);
12878 struct neon_type_el et;
12879 const char *ldconst = 0;
12880
12881 switch (rs)
12882 {
12883 case NS_DD: /* case 1/9. */
12884 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
12885 /* It is not an error here if no type is given. */
12886 inst.error = NULL;
12887 if (et.type == NT_float && et.size == 64)
12888 {
12889 do_vfp_nsyn_opcode ("fcpyd");
12890 break;
12891 }
12892 /* fall through. */
12893
12894 case NS_QQ: /* case 0/1. */
12895 {
12896 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12897 return;
12898 /* The architecture manual I have doesn't explicitly state which
12899 value the U bit should have for register->register moves, but
12900 the equivalent VORR instruction has U = 0, so do that. */
12901 inst.instruction = 0x0200110;
12902 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12903 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12904 inst.instruction |= LOW4 (inst.operands[1].reg);
12905 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12906 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12907 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12908 inst.instruction |= neon_quad (rs) << 6;
12909
12910 inst.instruction = neon_dp_fixup (inst.instruction);
12911 }
12912 break;
12913
12914 case NS_DI: /* case 3/11. */
12915 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
12916 inst.error = NULL;
12917 if (et.type == NT_float && et.size == 64)
12918 {
12919 /* case 11 (fconstd). */
12920 ldconst = "fconstd";
12921 goto encode_fconstd;
12922 }
12923 /* fall through. */
12924
12925 case NS_QI: /* case 2/3. */
12926 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12927 return;
12928 inst.instruction = 0x0800010;
12929 neon_move_immediate ();
12930 inst.instruction = neon_dp_fixup (inst.instruction);
12931 break;
12932
12933 case NS_SR: /* case 4. */
12934 {
12935 unsigned bcdebits = 0;
12936 struct neon_type_el et = neon_check_type (2, NS_NULL,
12937 N_8 | N_16 | N_32 | N_KEY, N_EQK);
12938 int logsize = neon_logbits (et.size);
12939 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
12940 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
12941
12942 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
12943 _(BAD_FPU));
12944 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
12945 && et.size != 32, _(BAD_FPU));
12946 constraint (et.type == NT_invtype, _("bad type for scalar"));
12947 constraint (x >= 64 / et.size, _("scalar index out of range"));
12948
12949 switch (et.size)
12950 {
12951 case 8: bcdebits = 0x8; break;
12952 case 16: bcdebits = 0x1; break;
12953 case 32: bcdebits = 0x0; break;
12954 default: ;
12955 }
12956
12957 bcdebits |= x << logsize;
12958
12959 inst.instruction = 0xe000b10;
12960 do_vfp_cond_or_thumb ();
12961 inst.instruction |= LOW4 (dn) << 16;
12962 inst.instruction |= HI1 (dn) << 7;
12963 inst.instruction |= inst.operands[1].reg << 12;
12964 inst.instruction |= (bcdebits & 3) << 5;
12965 inst.instruction |= (bcdebits >> 2) << 21;
12966 }
12967 break;
12968
12969 case NS_DRR: /* case 5 (fmdrr). */
12970 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
12971 _(BAD_FPU));
12972
12973 inst.instruction = 0xc400b10;
12974 do_vfp_cond_or_thumb ();
12975 inst.instruction |= LOW4 (inst.operands[0].reg);
12976 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
12977 inst.instruction |= inst.operands[1].reg << 12;
12978 inst.instruction |= inst.operands[2].reg << 16;
12979 break;
12980
12981 case NS_RS: /* case 6. */
12982 {
12983 struct neon_type_el et = neon_check_type (2, NS_NULL,
12984 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
12985 unsigned logsize = neon_logbits (et.size);
12986 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
12987 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
12988 unsigned abcdebits = 0;
12989
12990 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
12991 _(BAD_FPU));
12992 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
12993 && et.size != 32, _(BAD_FPU));
12994 constraint (et.type == NT_invtype, _("bad type for scalar"));
12995 constraint (x >= 64 / et.size, _("scalar index out of range"));
12996
12997 switch (et.size)
12998 {
12999 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
13000 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
13001 case 32: abcdebits = 0x00; break;
13002 default: ;
13003 }
13004
13005 abcdebits |= x << logsize;
13006 inst.instruction = 0xe100b10;
13007 do_vfp_cond_or_thumb ();
13008 inst.instruction |= LOW4 (dn) << 16;
13009 inst.instruction |= HI1 (dn) << 7;
13010 inst.instruction |= inst.operands[0].reg << 12;
13011 inst.instruction |= (abcdebits & 3) << 5;
13012 inst.instruction |= (abcdebits >> 2) << 21;
13013 }
13014 break;
13015
13016 case NS_RRD: /* case 7 (fmrrd). */
13017 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13018 _(BAD_FPU));
13019
13020 inst.instruction = 0xc500b10;
13021 do_vfp_cond_or_thumb ();
13022 inst.instruction |= inst.operands[0].reg << 12;
13023 inst.instruction |= inst.operands[1].reg << 16;
13024 inst.instruction |= LOW4 (inst.operands[2].reg);
13025 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13026 break;
13027
13028 case NS_FF: /* case 8 (fcpys). */
13029 do_vfp_nsyn_opcode ("fcpys");
13030 break;
13031
13032 case NS_FI: /* case 10 (fconsts). */
13033 ldconst = "fconsts";
13034 encode_fconstd:
13035 if (is_quarter_float (inst.operands[1].imm))
13036 {
13037 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
13038 do_vfp_nsyn_opcode (ldconst);
13039 }
13040 else
13041 first_error (_("immediate out of range"));
13042 break;
13043
13044 case NS_RF: /* case 12 (fmrs). */
13045 do_vfp_nsyn_opcode ("fmrs");
13046 break;
13047
13048 case NS_FR: /* case 13 (fmsr). */
13049 do_vfp_nsyn_opcode ("fmsr");
13050 break;
13051
13052 /* The encoders for the fmrrs and fmsrr instructions expect three operands
13053 (one of which is a list), but we have parsed four. Do some fiddling to
13054 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
13055 expect. */
13056 case NS_RRFF: /* case 14 (fmrrs). */
13057 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
13058 _("VFP registers must be adjacent"));
13059 inst.operands[2].imm = 2;
13060 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13061 do_vfp_nsyn_opcode ("fmrrs");
13062 break;
13063
13064 case NS_FFRR: /* case 15 (fmsrr). */
13065 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
13066 _("VFP registers must be adjacent"));
13067 inst.operands[1] = inst.operands[2];
13068 inst.operands[2] = inst.operands[3];
13069 inst.operands[0].imm = 2;
13070 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13071 do_vfp_nsyn_opcode ("fmsrr");
13072 break;
13073
13074 default:
13075 abort ();
13076 }
13077 }
13078
13079 static void
13080 do_neon_rshift_round_imm (void)
13081 {
13082 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13083 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
13084 int imm = inst.operands[2].imm;
13085
13086 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
13087 if (imm == 0)
13088 {
13089 inst.operands[2].present = 0;
13090 do_neon_mov ();
13091 return;
13092 }
13093
13094 constraint (imm < 1 || (unsigned)imm > et.size,
13095 _("immediate out of range for shift"));
13096 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
13097 et.size - imm);
13098 }
13099
13100 static void
13101 do_neon_movl (void)
13102 {
13103 struct neon_type_el et = neon_check_type (2, NS_QD,
13104 N_EQK | N_DBL, N_SU_32 | N_KEY);
13105 unsigned sizebits = et.size >> 3;
13106 inst.instruction |= sizebits << 19;
13107 neon_two_same (0, et.type == NT_unsigned, -1);
13108 }
13109
13110 static void
13111 do_neon_trn (void)
13112 {
13113 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13114 struct neon_type_el et = neon_check_type (2, rs,
13115 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13116 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13117 neon_two_same (neon_quad (rs), 1, et.size);
13118 }
13119
13120 static void
13121 do_neon_zip_uzp (void)
13122 {
13123 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13124 struct neon_type_el et = neon_check_type (2, rs,
13125 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13126 if (rs == NS_DD && et.size == 32)
13127 {
13128 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
13129 inst.instruction = N_MNEM_vtrn;
13130 do_neon_trn ();
13131 return;
13132 }
13133 neon_two_same (neon_quad (rs), 1, et.size);
13134 }
13135
13136 static void
13137 do_neon_sat_abs_neg (void)
13138 {
13139 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13140 struct neon_type_el et = neon_check_type (2, rs,
13141 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
13142 neon_two_same (neon_quad (rs), 1, et.size);
13143 }
13144
13145 static void
13146 do_neon_pair_long (void)
13147 {
13148 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13149 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
13150 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
13151 inst.instruction |= (et.type == NT_unsigned) << 7;
13152 neon_two_same (neon_quad (rs), 1, et.size);
13153 }
13154
13155 static void
13156 do_neon_recip_est (void)
13157 {
13158 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13159 struct neon_type_el et = neon_check_type (2, rs,
13160 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
13161 inst.instruction |= (et.type == NT_float) << 8;
13162 neon_two_same (neon_quad (rs), 1, et.size);
13163 }
13164
13165 static void
13166 do_neon_cls (void)
13167 {
13168 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13169 struct neon_type_el et = neon_check_type (2, rs,
13170 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
13171 neon_two_same (neon_quad (rs), 1, et.size);
13172 }
13173
13174 static void
13175 do_neon_clz (void)
13176 {
13177 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13178 struct neon_type_el et = neon_check_type (2, rs,
13179 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
13180 neon_two_same (neon_quad (rs), 1, et.size);
13181 }
13182
13183 static void
13184 do_neon_cnt (void)
13185 {
13186 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13187 struct neon_type_el et = neon_check_type (2, rs,
13188 N_EQK | N_INT, N_8 | N_KEY);
13189 neon_two_same (neon_quad (rs), 1, et.size);
13190 }
13191
13192 static void
13193 do_neon_swp (void)
13194 {
13195 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13196 neon_two_same (neon_quad (rs), 1, -1);
13197 }
13198
13199 static void
13200 do_neon_tbl_tbx (void)
13201 {
13202 unsigned listlenbits;
13203 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
13204
13205 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
13206 {
13207 first_error (_("bad list length for table lookup"));
13208 return;
13209 }
13210
13211 listlenbits = inst.operands[1].imm - 1;
13212 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13213 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13214 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13215 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13216 inst.instruction |= LOW4 (inst.operands[2].reg);
13217 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13218 inst.instruction |= listlenbits << 8;
13219
13220 inst.instruction = neon_dp_fixup (inst.instruction);
13221 }
13222
13223 static void
13224 do_neon_ldm_stm (void)
13225 {
13226 /* P, U and L bits are part of bitmask. */
13227 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
13228 unsigned offsetbits = inst.operands[1].imm * 2;
13229
13230 if (inst.operands[1].issingle)
13231 {
13232 do_vfp_nsyn_ldm_stm (is_dbmode);
13233 return;
13234 }
13235
13236 constraint (is_dbmode && !inst.operands[0].writeback,
13237 _("writeback (!) must be used for VLDMDB and VSTMDB"));
13238
13239 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
13240 _("register list must contain at least 1 and at most 16 "
13241 "registers"));
13242
13243 inst.instruction |= inst.operands[0].reg << 16;
13244 inst.instruction |= inst.operands[0].writeback << 21;
13245 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13246 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
13247
13248 inst.instruction |= offsetbits;
13249
13250 do_vfp_cond_or_thumb ();
13251 }
13252
13253 static void
13254 do_neon_ldr_str (void)
13255 {
13256 int is_ldr = (inst.instruction & (1 << 20)) != 0;
13257
13258 if (inst.operands[0].issingle)
13259 {
13260 if (is_ldr)
13261 do_vfp_nsyn_opcode ("flds");
13262 else
13263 do_vfp_nsyn_opcode ("fsts");
13264 }
13265 else
13266 {
13267 if (is_ldr)
13268 do_vfp_nsyn_opcode ("fldd");
13269 else
13270 do_vfp_nsyn_opcode ("fstd");
13271 }
13272 }
13273
13274 /* "interleave" version also handles non-interleaving register VLD1/VST1
13275 instructions. */
13276
13277 static void
13278 do_neon_ld_st_interleave (void)
13279 {
13280 struct neon_type_el et = neon_check_type (1, NS_NULL,
13281 N_8 | N_16 | N_32 | N_64);
13282 unsigned alignbits = 0;
13283 unsigned idx;
13284 /* The bits in this table go:
13285 0: register stride of one (0) or two (1)
13286 1,2: register list length, minus one (1, 2, 3, 4).
13287 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
13288 We use -1 for invalid entries. */
13289 const int typetable[] =
13290 {
13291 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
13292 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
13293 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
13294 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
13295 };
13296 int typebits;
13297
13298 if (et.type == NT_invtype)
13299 return;
13300
13301 if (inst.operands[1].immisalign)
13302 switch (inst.operands[1].imm >> 8)
13303 {
13304 case 64: alignbits = 1; break;
13305 case 128:
13306 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13307 goto bad_alignment;
13308 alignbits = 2;
13309 break;
13310 case 256:
13311 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13312 goto bad_alignment;
13313 alignbits = 3;
13314 break;
13315 default:
13316 bad_alignment:
13317 first_error (_("bad alignment"));
13318 return;
13319 }
13320
13321 inst.instruction |= alignbits << 4;
13322 inst.instruction |= neon_logbits (et.size) << 6;
13323
13324 /* Bits [4:6] of the immediate in a list specifier encode register stride
13325 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
13326 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
13327 up the right value for "type" in a table based on this value and the given
13328 list style, then stick it back. */
13329 idx = ((inst.operands[0].imm >> 4) & 7)
13330 | (((inst.instruction >> 8) & 3) << 3);
13331
13332 typebits = typetable[idx];
13333
13334 constraint (typebits == -1, _("bad list type for instruction"));
13335
13336 inst.instruction &= ~0xf00;
13337 inst.instruction |= typebits << 8;
13338 }
13339
13340 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
13341 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
13342 otherwise. The variable arguments are a list of pairs of legal (size, align)
13343 values, terminated with -1. */
13344
13345 static int
13346 neon_alignment_bit (int size, int align, int *do_align, ...)
13347 {
13348 va_list ap;
13349 int result = FAIL, thissize, thisalign;
13350
13351 if (!inst.operands[1].immisalign)
13352 {
13353 *do_align = 0;
13354 return SUCCESS;
13355 }
13356
13357 va_start (ap, do_align);
13358
13359 do
13360 {
13361 thissize = va_arg (ap, int);
13362 if (thissize == -1)
13363 break;
13364 thisalign = va_arg (ap, int);
13365
13366 if (size == thissize && align == thisalign)
13367 result = SUCCESS;
13368 }
13369 while (result != SUCCESS);
13370
13371 va_end (ap);
13372
13373 if (result == SUCCESS)
13374 *do_align = 1;
13375 else
13376 first_error (_("unsupported alignment for instruction"));
13377
13378 return result;
13379 }
13380
13381 static void
13382 do_neon_ld_st_lane (void)
13383 {
13384 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
13385 int align_good, do_align = 0;
13386 int logsize = neon_logbits (et.size);
13387 int align = inst.operands[1].imm >> 8;
13388 int n = (inst.instruction >> 8) & 3;
13389 int max_el = 64 / et.size;
13390
13391 if (et.type == NT_invtype)
13392 return;
13393
13394 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
13395 _("bad list length"));
13396 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
13397 _("scalar index out of range"));
13398 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
13399 && et.size == 8,
13400 _("stride of 2 unavailable when element size is 8"));
13401
13402 switch (n)
13403 {
13404 case 0: /* VLD1 / VST1. */
13405 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
13406 32, 32, -1);
13407 if (align_good == FAIL)
13408 return;
13409 if (do_align)
13410 {
13411 unsigned alignbits = 0;
13412 switch (et.size)
13413 {
13414 case 16: alignbits = 0x1; break;
13415 case 32: alignbits = 0x3; break;
13416 default: ;
13417 }
13418 inst.instruction |= alignbits << 4;
13419 }
13420 break;
13421
13422 case 1: /* VLD2 / VST2. */
13423 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
13424 32, 64, -1);
13425 if (align_good == FAIL)
13426 return;
13427 if (do_align)
13428 inst.instruction |= 1 << 4;
13429 break;
13430
13431 case 2: /* VLD3 / VST3. */
13432 constraint (inst.operands[1].immisalign,
13433 _("can't use alignment with this instruction"));
13434 break;
13435
13436 case 3: /* VLD4 / VST4. */
13437 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13438 16, 64, 32, 64, 32, 128, -1);
13439 if (align_good == FAIL)
13440 return;
13441 if (do_align)
13442 {
13443 unsigned alignbits = 0;
13444 switch (et.size)
13445 {
13446 case 8: alignbits = 0x1; break;
13447 case 16: alignbits = 0x1; break;
13448 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
13449 default: ;
13450 }
13451 inst.instruction |= alignbits << 4;
13452 }
13453 break;
13454
13455 default: ;
13456 }
13457
13458 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
13459 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13460 inst.instruction |= 1 << (4 + logsize);
13461
13462 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
13463 inst.instruction |= logsize << 10;
13464 }
13465
13466 /* Encode single n-element structure to all lanes VLD<n> instructions. */
13467
13468 static void
13469 do_neon_ld_dup (void)
13470 {
13471 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
13472 int align_good, do_align = 0;
13473
13474 if (et.type == NT_invtype)
13475 return;
13476
13477 switch ((inst.instruction >> 8) & 3)
13478 {
13479 case 0: /* VLD1. */
13480 assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
13481 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13482 &do_align, 16, 16, 32, 32, -1);
13483 if (align_good == FAIL)
13484 return;
13485 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
13486 {
13487 case 1: break;
13488 case 2: inst.instruction |= 1 << 5; break;
13489 default: first_error (_("bad list length")); return;
13490 }
13491 inst.instruction |= neon_logbits (et.size) << 6;
13492 break;
13493
13494 case 1: /* VLD2. */
13495 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13496 &do_align, 8, 16, 16, 32, 32, 64, -1);
13497 if (align_good == FAIL)
13498 return;
13499 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
13500 _("bad list length"));
13501 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13502 inst.instruction |= 1 << 5;
13503 inst.instruction |= neon_logbits (et.size) << 6;
13504 break;
13505
13506 case 2: /* VLD3. */
13507 constraint (inst.operands[1].immisalign,
13508 _("can't use alignment with this instruction"));
13509 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
13510 _("bad list length"));
13511 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13512 inst.instruction |= 1 << 5;
13513 inst.instruction |= neon_logbits (et.size) << 6;
13514 break;
13515
13516 case 3: /* VLD4. */
13517 {
13518 int align = inst.operands[1].imm >> 8;
13519 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13520 16, 64, 32, 64, 32, 128, -1);
13521 if (align_good == FAIL)
13522 return;
13523 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
13524 _("bad list length"));
13525 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13526 inst.instruction |= 1 << 5;
13527 if (et.size == 32 && align == 128)
13528 inst.instruction |= 0x3 << 6;
13529 else
13530 inst.instruction |= neon_logbits (et.size) << 6;
13531 }
13532 break;
13533
13534 default: ;
13535 }
13536
13537 inst.instruction |= do_align << 4;
13538 }
13539
13540 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
13541 apart from bits [11:4]. */
13542
13543 static void
13544 do_neon_ldx_stx (void)
13545 {
13546 switch (NEON_LANE (inst.operands[0].imm))
13547 {
13548 case NEON_INTERLEAVE_LANES:
13549 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
13550 do_neon_ld_st_interleave ();
13551 break;
13552
13553 case NEON_ALL_LANES:
13554 inst.instruction = NEON_ENC_DUP (inst.instruction);
13555 do_neon_ld_dup ();
13556 break;
13557
13558 default:
13559 inst.instruction = NEON_ENC_LANE (inst.instruction);
13560 do_neon_ld_st_lane ();
13561 }
13562
13563 /* L bit comes from bit mask. */
13564 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13565 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13566 inst.instruction |= inst.operands[1].reg << 16;
13567
13568 if (inst.operands[1].postind)
13569 {
13570 int postreg = inst.operands[1].imm & 0xf;
13571 constraint (!inst.operands[1].immisreg,
13572 _("post-index must be a register"));
13573 constraint (postreg == 0xd || postreg == 0xf,
13574 _("bad register for post-index"));
13575 inst.instruction |= postreg;
13576 }
13577 else if (inst.operands[1].writeback)
13578 {
13579 inst.instruction |= 0xd;
13580 }
13581 else
13582 inst.instruction |= 0xf;
13583
13584 if (thumb_mode)
13585 inst.instruction |= 0xf9000000;
13586 else
13587 inst.instruction |= 0xf4000000;
13588 }
13589
13590 \f
13591 /* Overall per-instruction processing. */
13592
13593 /* We need to be able to fix up arbitrary expressions in some statements.
13594 This is so that we can handle symbols that are an arbitrary distance from
13595 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
13596 which returns part of an address in a form which will be valid for
13597 a data instruction. We do this by pushing the expression into a symbol
13598 in the expr_section, and creating a fix for that. */
13599
13600 static void
13601 fix_new_arm (fragS * frag,
13602 int where,
13603 short int size,
13604 expressionS * exp,
13605 int pc_rel,
13606 int reloc)
13607 {
13608 fixS * new_fix;
13609
13610 switch (exp->X_op)
13611 {
13612 case O_constant:
13613 case O_symbol:
13614 case O_add:
13615 case O_subtract:
13616 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
13617 break;
13618
13619 default:
13620 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
13621 pc_rel, reloc);
13622 break;
13623 }
13624
13625 /* Mark whether the fix is to a THUMB instruction, or an ARM
13626 instruction. */
13627 new_fix->tc_fix_data = thumb_mode;
13628 }
13629
13630 /* Create a frg for an instruction requiring relaxation. */
13631 static void
13632 output_relax_insn (void)
13633 {
13634 char * to;
13635 symbolS *sym;
13636 int offset;
13637
13638 /* The size of the instruction is unknown, so tie the debug info to the
13639 start of the instruction. */
13640 dwarf2_emit_insn (0);
13641
13642 switch (inst.reloc.exp.X_op)
13643 {
13644 case O_symbol:
13645 sym = inst.reloc.exp.X_add_symbol;
13646 offset = inst.reloc.exp.X_add_number;
13647 break;
13648 case O_constant:
13649 sym = NULL;
13650 offset = inst.reloc.exp.X_add_number;
13651 break;
13652 default:
13653 sym = make_expr_symbol (&inst.reloc.exp);
13654 offset = 0;
13655 break;
13656 }
13657 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
13658 inst.relax, sym, offset, NULL/*offset, opcode*/);
13659 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
13660 }
13661
13662 /* Write a 32-bit thumb instruction to buf. */
13663 static void
13664 put_thumb32_insn (char * buf, unsigned long insn)
13665 {
13666 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
13667 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
13668 }
13669
13670 static void
13671 output_inst (const char * str)
13672 {
13673 char * to = NULL;
13674
13675 if (inst.error)
13676 {
13677 as_bad ("%s -- `%s'", inst.error, str);
13678 return;
13679 }
13680 if (inst.relax) {
13681 output_relax_insn();
13682 return;
13683 }
13684 if (inst.size == 0)
13685 return;
13686
13687 to = frag_more (inst.size);
13688
13689 if (thumb_mode && (inst.size > THUMB_SIZE))
13690 {
13691 assert (inst.size == (2 * THUMB_SIZE));
13692 put_thumb32_insn (to, inst.instruction);
13693 }
13694 else if (inst.size > INSN_SIZE)
13695 {
13696 assert (inst.size == (2 * INSN_SIZE));
13697 md_number_to_chars (to, inst.instruction, INSN_SIZE);
13698 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
13699 }
13700 else
13701 md_number_to_chars (to, inst.instruction, inst.size);
13702
13703 if (inst.reloc.type != BFD_RELOC_UNUSED)
13704 fix_new_arm (frag_now, to - frag_now->fr_literal,
13705 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
13706 inst.reloc.type);
13707
13708 dwarf2_emit_insn (inst.size);
13709 }
13710
13711 /* Tag values used in struct asm_opcode's tag field. */
13712 enum opcode_tag
13713 {
13714 OT_unconditional, /* Instruction cannot be conditionalized.
13715 The ARM condition field is still 0xE. */
13716 OT_unconditionalF, /* Instruction cannot be conditionalized
13717 and carries 0xF in its ARM condition field. */
13718 OT_csuffix, /* Instruction takes a conditional suffix. */
13719 OT_csuffixF, /* Some forms of the instruction take a conditional
13720 suffix, others place 0xF where the condition field
13721 would be. */
13722 OT_cinfix3, /* Instruction takes a conditional infix,
13723 beginning at character index 3. (In
13724 unified mode, it becomes a suffix.) */
13725 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
13726 tsts, cmps, cmns, and teqs. */
13727 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
13728 character index 3, even in unified mode. Used for
13729 legacy instructions where suffix and infix forms
13730 may be ambiguous. */
13731 OT_csuf_or_in3, /* Instruction takes either a conditional
13732 suffix or an infix at character index 3. */
13733 OT_odd_infix_unc, /* This is the unconditional variant of an
13734 instruction that takes a conditional infix
13735 at an unusual position. In unified mode,
13736 this variant will accept a suffix. */
13737 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
13738 are the conditional variants of instructions that
13739 take conditional infixes in unusual positions.
13740 The infix appears at character index
13741 (tag - OT_odd_infix_0). These are not accepted
13742 in unified mode. */
13743 };
13744
13745 /* Subroutine of md_assemble, responsible for looking up the primary
13746 opcode from the mnemonic the user wrote. STR points to the
13747 beginning of the mnemonic.
13748
13749 This is not simply a hash table lookup, because of conditional
13750 variants. Most instructions have conditional variants, which are
13751 expressed with a _conditional affix_ to the mnemonic. If we were
13752 to encode each conditional variant as a literal string in the opcode
13753 table, it would have approximately 20,000 entries.
13754
13755 Most mnemonics take this affix as a suffix, and in unified syntax,
13756 'most' is upgraded to 'all'. However, in the divided syntax, some
13757 instructions take the affix as an infix, notably the s-variants of
13758 the arithmetic instructions. Of those instructions, all but six
13759 have the infix appear after the third character of the mnemonic.
13760
13761 Accordingly, the algorithm for looking up primary opcodes given
13762 an identifier is:
13763
13764 1. Look up the identifier in the opcode table.
13765 If we find a match, go to step U.
13766
13767 2. Look up the last two characters of the identifier in the
13768 conditions table. If we find a match, look up the first N-2
13769 characters of the identifier in the opcode table. If we
13770 find a match, go to step CE.
13771
13772 3. Look up the fourth and fifth characters of the identifier in
13773 the conditions table. If we find a match, extract those
13774 characters from the identifier, and look up the remaining
13775 characters in the opcode table. If we find a match, go
13776 to step CM.
13777
13778 4. Fail.
13779
13780 U. Examine the tag field of the opcode structure, in case this is
13781 one of the six instructions with its conditional infix in an
13782 unusual place. If it is, the tag tells us where to find the
13783 infix; look it up in the conditions table and set inst.cond
13784 accordingly. Otherwise, this is an unconditional instruction.
13785 Again set inst.cond accordingly. Return the opcode structure.
13786
13787 CE. Examine the tag field to make sure this is an instruction that
13788 should receive a conditional suffix. If it is not, fail.
13789 Otherwise, set inst.cond from the suffix we already looked up,
13790 and return the opcode structure.
13791
13792 CM. Examine the tag field to make sure this is an instruction that
13793 should receive a conditional infix after the third character.
13794 If it is not, fail. Otherwise, undo the edits to the current
13795 line of input and proceed as for case CE. */
13796
13797 static const struct asm_opcode *
13798 opcode_lookup (char **str)
13799 {
13800 char *end, *base;
13801 char *affix;
13802 const struct asm_opcode *opcode;
13803 const struct asm_cond *cond;
13804 char save[2];
13805 bfd_boolean neon_supported;
13806
13807 neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1);
13808
13809 /* Scan up to the end of the mnemonic, which must end in white space,
13810 '.' (in unified mode, or for Neon instructions), or end of string. */
13811 for (base = end = *str; *end != '\0'; end++)
13812 if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.'))
13813 break;
13814
13815 if (end == base)
13816 return 0;
13817
13818 /* Handle a possible width suffix and/or Neon type suffix. */
13819 if (end[0] == '.')
13820 {
13821 int offset = 2;
13822
13823 /* The .w and .n suffixes are only valid if the unified syntax is in
13824 use. */
13825 if (unified_syntax && end[1] == 'w')
13826 inst.size_req = 4;
13827 else if (unified_syntax && end[1] == 'n')
13828 inst.size_req = 2;
13829 else
13830 offset = 0;
13831
13832 inst.vectype.elems = 0;
13833
13834 *str = end + offset;
13835
13836 if (end[offset] == '.')
13837 {
13838 /* See if we have a Neon type suffix (possible in either unified or
13839 non-unified ARM syntax mode). */
13840 if (parse_neon_type (&inst.vectype, str) == FAIL)
13841 return 0;
13842 }
13843 else if (end[offset] != '\0' && end[offset] != ' ')
13844 return 0;
13845 }
13846 else
13847 *str = end;
13848
13849 /* Look for unaffixed or special-case affixed mnemonic. */
13850 opcode = hash_find_n (arm_ops_hsh, base, end - base);
13851 if (opcode)
13852 {
13853 /* step U */
13854 if (opcode->tag < OT_odd_infix_0)
13855 {
13856 inst.cond = COND_ALWAYS;
13857 return opcode;
13858 }
13859
13860 if (unified_syntax)
13861 as_warn (_("conditional infixes are deprecated in unified syntax"));
13862 affix = base + (opcode->tag - OT_odd_infix_0);
13863 cond = hash_find_n (arm_cond_hsh, affix, 2);
13864 assert (cond);
13865
13866 inst.cond = cond->value;
13867 return opcode;
13868 }
13869
13870 /* Cannot have a conditional suffix on a mnemonic of less than two
13871 characters. */
13872 if (end - base < 3)
13873 return 0;
13874
13875 /* Look for suffixed mnemonic. */
13876 affix = end - 2;
13877 cond = hash_find_n (arm_cond_hsh, affix, 2);
13878 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
13879 if (opcode && cond)
13880 {
13881 /* step CE */
13882 switch (opcode->tag)
13883 {
13884 case OT_cinfix3_legacy:
13885 /* Ignore conditional suffixes matched on infix only mnemonics. */
13886 break;
13887
13888 case OT_cinfix3:
13889 case OT_cinfix3_deprecated:
13890 case OT_odd_infix_unc:
13891 if (!unified_syntax)
13892 return 0;
13893 /* else fall through */
13894
13895 case OT_csuffix:
13896 case OT_csuffixF:
13897 case OT_csuf_or_in3:
13898 inst.cond = cond->value;
13899 return opcode;
13900
13901 case OT_unconditional:
13902 case OT_unconditionalF:
13903 if (thumb_mode)
13904 {
13905 inst.cond = cond->value;
13906 }
13907 else
13908 {
13909 /* delayed diagnostic */
13910 inst.error = BAD_COND;
13911 inst.cond = COND_ALWAYS;
13912 }
13913 return opcode;
13914
13915 default:
13916 return 0;
13917 }
13918 }
13919
13920 /* Cannot have a usual-position infix on a mnemonic of less than
13921 six characters (five would be a suffix). */
13922 if (end - base < 6)
13923 return 0;
13924
13925 /* Look for infixed mnemonic in the usual position. */
13926 affix = base + 3;
13927 cond = hash_find_n (arm_cond_hsh, affix, 2);
13928 if (!cond)
13929 return 0;
13930
13931 memcpy (save, affix, 2);
13932 memmove (affix, affix + 2, (end - affix) - 2);
13933 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
13934 memmove (affix + 2, affix, (end - affix) - 2);
13935 memcpy (affix, save, 2);
13936
13937 if (opcode
13938 && (opcode->tag == OT_cinfix3
13939 || opcode->tag == OT_cinfix3_deprecated
13940 || opcode->tag == OT_csuf_or_in3
13941 || opcode->tag == OT_cinfix3_legacy))
13942 {
13943 /* step CM */
13944 if (unified_syntax
13945 && (opcode->tag == OT_cinfix3
13946 || opcode->tag == OT_cinfix3_deprecated))
13947 as_warn (_("conditional infixes are deprecated in unified syntax"));
13948
13949 inst.cond = cond->value;
13950 return opcode;
13951 }
13952
13953 return 0;
13954 }
13955
13956 void
13957 md_assemble (char *str)
13958 {
13959 char *p = str;
13960 const struct asm_opcode * opcode;
13961
13962 /* Align the previous label if needed. */
13963 if (last_label_seen != NULL)
13964 {
13965 symbol_set_frag (last_label_seen, frag_now);
13966 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
13967 S_SET_SEGMENT (last_label_seen, now_seg);
13968 }
13969
13970 memset (&inst, '\0', sizeof (inst));
13971 inst.reloc.type = BFD_RELOC_UNUSED;
13972
13973 opcode = opcode_lookup (&p);
13974 if (!opcode)
13975 {
13976 /* It wasn't an instruction, but it might be a register alias of
13977 the form alias .req reg, or a Neon .dn/.qn directive. */
13978 if (!create_register_alias (str, p)
13979 && !create_neon_reg_alias (str, p))
13980 as_bad (_("bad instruction `%s'"), str);
13981
13982 return;
13983 }
13984
13985 if (opcode->tag == OT_cinfix3_deprecated)
13986 as_warn (_("s suffix on comparison instruction is deprecated"));
13987
13988 /* The value which unconditional instructions should have in place of the
13989 condition field. */
13990 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
13991
13992 if (thumb_mode)
13993 {
13994 arm_feature_set variant;
13995
13996 variant = cpu_variant;
13997 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
13998 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
13999 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
14000 /* Check that this instruction is supported for this CPU. */
14001 if (!opcode->tvariant
14002 || (thumb_mode == 1
14003 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
14004 {
14005 as_bad (_("selected processor does not support `%s'"), str);
14006 return;
14007 }
14008 if (inst.cond != COND_ALWAYS && !unified_syntax
14009 && opcode->tencode != do_t_branch)
14010 {
14011 as_bad (_("Thumb does not support conditional execution"));
14012 return;
14013 }
14014
14015 /* Check conditional suffixes. */
14016 if (current_it_mask)
14017 {
14018 int cond;
14019 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
14020 current_it_mask <<= 1;
14021 current_it_mask &= 0x1f;
14022 /* The BKPT instruction is unconditional even in an IT block. */
14023 if (!inst.error
14024 && cond != inst.cond && opcode->tencode != do_t_bkpt)
14025 {
14026 as_bad (_("incorrect condition in IT block"));
14027 return;
14028 }
14029 }
14030 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
14031 {
14032 as_bad (_("thumb conditional instrunction not in IT block"));
14033 return;
14034 }
14035
14036 mapping_state (MAP_THUMB);
14037 inst.instruction = opcode->tvalue;
14038
14039 if (!parse_operands (p, opcode->operands))
14040 opcode->tencode ();
14041
14042 /* Clear current_it_mask at the end of an IT block. */
14043 if (current_it_mask == 0x10)
14044 current_it_mask = 0;
14045
14046 if (!(inst.error || inst.relax))
14047 {
14048 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
14049 inst.size = (inst.instruction > 0xffff ? 4 : 2);
14050 if (inst.size_req && inst.size_req != inst.size)
14051 {
14052 as_bad (_("cannot honor width suffix -- `%s'"), str);
14053 return;
14054 }
14055 }
14056 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14057 *opcode->tvariant);
14058 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
14059 set those bits when Thumb-2 32-bit instructions are seen. ie.
14060 anything other than bl/blx.
14061 This is overly pessimistic for relaxable instructions. */
14062 if ((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
14063 || inst.relax)
14064 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14065 arm_ext_v6t2);
14066 }
14067 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
14068 {
14069 /* Check that this instruction is supported for this CPU. */
14070 if (!opcode->avariant ||
14071 !ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant))
14072 {
14073 as_bad (_("selected processor does not support `%s'"), str);
14074 return;
14075 }
14076 if (inst.size_req)
14077 {
14078 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
14079 return;
14080 }
14081
14082 mapping_state (MAP_ARM);
14083 inst.instruction = opcode->avalue;
14084 if (opcode->tag == OT_unconditionalF)
14085 inst.instruction |= 0xF << 28;
14086 else
14087 inst.instruction |= inst.cond << 28;
14088 inst.size = INSN_SIZE;
14089 if (!parse_operands (p, opcode->operands))
14090 opcode->aencode ();
14091 /* Arm mode bx is marked as both v4T and v5 because it's still required
14092 on a hypothetical non-thumb v5 core. */
14093 if (ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v4t)
14094 || ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v5))
14095 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
14096 else
14097 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
14098 *opcode->avariant);
14099 }
14100 else
14101 {
14102 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
14103 "-- `%s'"), str);
14104 return;
14105 }
14106 output_inst (str);
14107 }
14108
14109 /* Various frobbings of labels and their addresses. */
14110
14111 void
14112 arm_start_line_hook (void)
14113 {
14114 last_label_seen = NULL;
14115 }
14116
14117 void
14118 arm_frob_label (symbolS * sym)
14119 {
14120 last_label_seen = sym;
14121
14122 ARM_SET_THUMB (sym, thumb_mode);
14123
14124 #if defined OBJ_COFF || defined OBJ_ELF
14125 ARM_SET_INTERWORK (sym, support_interwork);
14126 #endif
14127
14128 /* Note - do not allow local symbols (.Lxxx) to be labeled
14129 as Thumb functions. This is because these labels, whilst
14130 they exist inside Thumb code, are not the entry points for
14131 possible ARM->Thumb calls. Also, these labels can be used
14132 as part of a computed goto or switch statement. eg gcc
14133 can generate code that looks like this:
14134
14135 ldr r2, [pc, .Laaa]
14136 lsl r3, r3, #2
14137 ldr r2, [r3, r2]
14138 mov pc, r2
14139
14140 .Lbbb: .word .Lxxx
14141 .Lccc: .word .Lyyy
14142 ..etc...
14143 .Laaa: .word Lbbb
14144
14145 The first instruction loads the address of the jump table.
14146 The second instruction converts a table index into a byte offset.
14147 The third instruction gets the jump address out of the table.
14148 The fourth instruction performs the jump.
14149
14150 If the address stored at .Laaa is that of a symbol which has the
14151 Thumb_Func bit set, then the linker will arrange for this address
14152 to have the bottom bit set, which in turn would mean that the
14153 address computation performed by the third instruction would end
14154 up with the bottom bit set. Since the ARM is capable of unaligned
14155 word loads, the instruction would then load the incorrect address
14156 out of the jump table, and chaos would ensue. */
14157 if (label_is_thumb_function_name
14158 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
14159 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
14160 {
14161 /* When the address of a Thumb function is taken the bottom
14162 bit of that address should be set. This will allow
14163 interworking between Arm and Thumb functions to work
14164 correctly. */
14165
14166 THUMB_SET_FUNC (sym, 1);
14167
14168 label_is_thumb_function_name = FALSE;
14169 }
14170
14171 dwarf2_emit_label (sym);
14172 }
14173
14174 int
14175 arm_data_in_code (void)
14176 {
14177 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
14178 {
14179 *input_line_pointer = '/';
14180 input_line_pointer += 5;
14181 *input_line_pointer = 0;
14182 return 1;
14183 }
14184
14185 return 0;
14186 }
14187
14188 char *
14189 arm_canonicalize_symbol_name (char * name)
14190 {
14191 int len;
14192
14193 if (thumb_mode && (len = strlen (name)) > 5
14194 && streq (name + len - 5, "/data"))
14195 *(name + len - 5) = 0;
14196
14197 return name;
14198 }
14199 \f
14200 /* Table of all register names defined by default. The user can
14201 define additional names with .req. Note that all register names
14202 should appear in both upper and lowercase variants. Some registers
14203 also have mixed-case names. */
14204
14205 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
14206 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
14207 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
14208 #define REGSET(p,t) \
14209 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
14210 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
14211 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
14212 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
14213 #define REGSETH(p,t) \
14214 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
14215 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
14216 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
14217 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
14218 #define REGSET2(p,t) \
14219 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
14220 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
14221 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
14222 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
14223
14224 static const struct reg_entry reg_names[] =
14225 {
14226 /* ARM integer registers. */
14227 REGSET(r, RN), REGSET(R, RN),
14228
14229 /* ATPCS synonyms. */
14230 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
14231 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
14232 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
14233
14234 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
14235 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
14236 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
14237
14238 /* Well-known aliases. */
14239 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
14240 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
14241
14242 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
14243 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
14244
14245 /* Coprocessor numbers. */
14246 REGSET(p, CP), REGSET(P, CP),
14247
14248 /* Coprocessor register numbers. The "cr" variants are for backward
14249 compatibility. */
14250 REGSET(c, CN), REGSET(C, CN),
14251 REGSET(cr, CN), REGSET(CR, CN),
14252
14253 /* FPA registers. */
14254 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
14255 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
14256
14257 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
14258 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
14259
14260 /* VFP SP registers. */
14261 REGSET(s,VFS), REGSET(S,VFS),
14262 REGSETH(s,VFS), REGSETH(S,VFS),
14263
14264 /* VFP DP Registers. */
14265 REGSET(d,VFD), REGSET(D,VFD),
14266 /* Extra Neon DP registers. */
14267 REGSETH(d,VFD), REGSETH(D,VFD),
14268
14269 /* Neon QP registers. */
14270 REGSET2(q,NQ), REGSET2(Q,NQ),
14271
14272 /* VFP control registers. */
14273 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
14274 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
14275
14276 /* Maverick DSP coprocessor registers. */
14277 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
14278 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
14279
14280 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
14281 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
14282 REGDEF(dspsc,0,DSPSC),
14283
14284 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
14285 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
14286 REGDEF(DSPSC,0,DSPSC),
14287
14288 /* iWMMXt data registers - p0, c0-15. */
14289 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
14290
14291 /* iWMMXt control registers - p1, c0-3. */
14292 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
14293 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
14294 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
14295 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
14296
14297 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
14298 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
14299 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
14300 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
14301 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
14302
14303 /* XScale accumulator registers. */
14304 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
14305 };
14306 #undef REGDEF
14307 #undef REGNUM
14308 #undef REGSET
14309
14310 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
14311 within psr_required_here. */
14312 static const struct asm_psr psrs[] =
14313 {
14314 /* Backward compatibility notation. Note that "all" is no longer
14315 truly all possible PSR bits. */
14316 {"all", PSR_c | PSR_f},
14317 {"flg", PSR_f},
14318 {"ctl", PSR_c},
14319
14320 /* Individual flags. */
14321 {"f", PSR_f},
14322 {"c", PSR_c},
14323 {"x", PSR_x},
14324 {"s", PSR_s},
14325 /* Combinations of flags. */
14326 {"fs", PSR_f | PSR_s},
14327 {"fx", PSR_f | PSR_x},
14328 {"fc", PSR_f | PSR_c},
14329 {"sf", PSR_s | PSR_f},
14330 {"sx", PSR_s | PSR_x},
14331 {"sc", PSR_s | PSR_c},
14332 {"xf", PSR_x | PSR_f},
14333 {"xs", PSR_x | PSR_s},
14334 {"xc", PSR_x | PSR_c},
14335 {"cf", PSR_c | PSR_f},
14336 {"cs", PSR_c | PSR_s},
14337 {"cx", PSR_c | PSR_x},
14338 {"fsx", PSR_f | PSR_s | PSR_x},
14339 {"fsc", PSR_f | PSR_s | PSR_c},
14340 {"fxs", PSR_f | PSR_x | PSR_s},
14341 {"fxc", PSR_f | PSR_x | PSR_c},
14342 {"fcs", PSR_f | PSR_c | PSR_s},
14343 {"fcx", PSR_f | PSR_c | PSR_x},
14344 {"sfx", PSR_s | PSR_f | PSR_x},
14345 {"sfc", PSR_s | PSR_f | PSR_c},
14346 {"sxf", PSR_s | PSR_x | PSR_f},
14347 {"sxc", PSR_s | PSR_x | PSR_c},
14348 {"scf", PSR_s | PSR_c | PSR_f},
14349 {"scx", PSR_s | PSR_c | PSR_x},
14350 {"xfs", PSR_x | PSR_f | PSR_s},
14351 {"xfc", PSR_x | PSR_f | PSR_c},
14352 {"xsf", PSR_x | PSR_s | PSR_f},
14353 {"xsc", PSR_x | PSR_s | PSR_c},
14354 {"xcf", PSR_x | PSR_c | PSR_f},
14355 {"xcs", PSR_x | PSR_c | PSR_s},
14356 {"cfs", PSR_c | PSR_f | PSR_s},
14357 {"cfx", PSR_c | PSR_f | PSR_x},
14358 {"csf", PSR_c | PSR_s | PSR_f},
14359 {"csx", PSR_c | PSR_s | PSR_x},
14360 {"cxf", PSR_c | PSR_x | PSR_f},
14361 {"cxs", PSR_c | PSR_x | PSR_s},
14362 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
14363 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
14364 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
14365 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
14366 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
14367 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
14368 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
14369 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
14370 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
14371 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
14372 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
14373 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
14374 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
14375 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
14376 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
14377 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
14378 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
14379 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
14380 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
14381 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
14382 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
14383 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
14384 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
14385 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
14386 };
14387
14388 /* Table of V7M psr names. */
14389 static const struct asm_psr v7m_psrs[] =
14390 {
14391 {"apsr", 0 },
14392 {"iapsr", 1 },
14393 {"eapsr", 2 },
14394 {"psr", 3 },
14395 {"ipsr", 5 },
14396 {"epsr", 6 },
14397 {"iepsr", 7 },
14398 {"msp", 8 },
14399 {"psp", 9 },
14400 {"primask", 16},
14401 {"basepri", 17},
14402 {"basepri_max", 18},
14403 {"faultmask", 19},
14404 {"control", 20}
14405 };
14406
14407 /* Table of all shift-in-operand names. */
14408 static const struct asm_shift_name shift_names [] =
14409 {
14410 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
14411 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
14412 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
14413 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
14414 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
14415 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
14416 };
14417
14418 /* Table of all explicit relocation names. */
14419 #ifdef OBJ_ELF
14420 static struct reloc_entry reloc_names[] =
14421 {
14422 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
14423 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
14424 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
14425 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
14426 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
14427 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
14428 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
14429 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
14430 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
14431 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
14432 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
14433 };
14434 #endif
14435
14436 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
14437 static const struct asm_cond conds[] =
14438 {
14439 {"eq", 0x0},
14440 {"ne", 0x1},
14441 {"cs", 0x2}, {"hs", 0x2},
14442 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
14443 {"mi", 0x4},
14444 {"pl", 0x5},
14445 {"vs", 0x6},
14446 {"vc", 0x7},
14447 {"hi", 0x8},
14448 {"ls", 0x9},
14449 {"ge", 0xa},
14450 {"lt", 0xb},
14451 {"gt", 0xc},
14452 {"le", 0xd},
14453 {"al", 0xe}
14454 };
14455
14456 static struct asm_barrier_opt barrier_opt_names[] =
14457 {
14458 { "sy", 0xf },
14459 { "un", 0x7 },
14460 { "st", 0xe },
14461 { "unst", 0x6 }
14462 };
14463
14464 /* Table of ARM-format instructions. */
14465
14466 /* Macros for gluing together operand strings. N.B. In all cases
14467 other than OPS0, the trailing OP_stop comes from default
14468 zero-initialization of the unspecified elements of the array. */
14469 #define OPS0() { OP_stop, }
14470 #define OPS1(a) { OP_##a, }
14471 #define OPS2(a,b) { OP_##a,OP_##b, }
14472 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
14473 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
14474 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
14475 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
14476
14477 /* These macros abstract out the exact format of the mnemonic table and
14478 save some repeated characters. */
14479
14480 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
14481 #define TxCE(mnem, op, top, nops, ops, ae, te) \
14482 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
14483 THUMB_VARIANT, do_##ae, do_##te }
14484
14485 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
14486 a T_MNEM_xyz enumerator. */
14487 #define TCE(mnem, aop, top, nops, ops, ae, te) \
14488 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
14489 #define tCE(mnem, aop, top, nops, ops, ae, te) \
14490 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14491
14492 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
14493 infix after the third character. */
14494 #define TxC3(mnem, op, top, nops, ops, ae, te) \
14495 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
14496 THUMB_VARIANT, do_##ae, do_##te }
14497 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
14498 { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
14499 THUMB_VARIANT, do_##ae, do_##te }
14500 #define TC3(mnem, aop, top, nops, ops, ae, te) \
14501 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
14502 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
14503 TxC3w(mnem, aop, 0x##top, nops, ops, ae, te)
14504 #define tC3(mnem, aop, top, nops, ops, ae, te) \
14505 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14506 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
14507 TxC3w(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14508
14509 /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
14510 appear in the condition table. */
14511 #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
14512 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14513 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
14514
14515 #define TxCM(m1, m2, op, top, nops, ops, ae, te) \
14516 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
14517 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
14518 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
14519 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
14520 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
14521 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
14522 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
14523 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
14524 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
14525 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
14526 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
14527 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
14528 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
14529 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
14530 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
14531 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
14532 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
14533 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
14534 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
14535
14536 #define TCM(m1,m2, aop, top, nops, ops, ae, te) \
14537 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
14538 #define tCM(m1,m2, aop, top, nops, ops, ae, te) \
14539 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
14540
14541 /* Mnemonic that cannot be conditionalized. The ARM condition-code
14542 field is still 0xE. Many of the Thumb variants can be executed
14543 conditionally, so this is checked separately. */
14544 #define TUE(mnem, op, top, nops, ops, ae, te) \
14545 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
14546 THUMB_VARIANT, do_##ae, do_##te }
14547
14548 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
14549 condition code field. */
14550 #define TUF(mnem, op, top, nops, ops, ae, te) \
14551 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
14552 THUMB_VARIANT, do_##ae, do_##te }
14553
14554 /* ARM-only variants of all the above. */
14555 #define CE(mnem, op, nops, ops, ae) \
14556 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14557
14558 #define C3(mnem, op, nops, ops, ae) \
14559 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14560
14561 /* Legacy mnemonics that always have conditional infix after the third
14562 character. */
14563 #define CL(mnem, op, nops, ops, ae) \
14564 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14565 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14566
14567 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
14568 #define cCE(mnem, op, nops, ops, ae) \
14569 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14570
14571 /* Legacy coprocessor instructions where conditional infix and conditional
14572 suffix are ambiguous. For consistency this includes all FPA instructions,
14573 not just the potentially ambiguous ones. */
14574 #define cCL(mnem, op, nops, ops, ae) \
14575 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14576 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14577
14578 /* Coprocessor, takes either a suffix or a position-3 infix
14579 (for an FPA corner case). */
14580 #define C3E(mnem, op, nops, ops, ae) \
14581 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
14582 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14583
14584 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
14585 { #m1 #m2 #m3, OPS##nops ops, \
14586 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14587 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14588
14589 #define CM(m1, m2, op, nops, ops, ae) \
14590 xCM_(m1, , m2, op, nops, ops, ae), \
14591 xCM_(m1, eq, m2, op, nops, ops, ae), \
14592 xCM_(m1, ne, m2, op, nops, ops, ae), \
14593 xCM_(m1, cs, m2, op, nops, ops, ae), \
14594 xCM_(m1, hs, m2, op, nops, ops, ae), \
14595 xCM_(m1, cc, m2, op, nops, ops, ae), \
14596 xCM_(m1, ul, m2, op, nops, ops, ae), \
14597 xCM_(m1, lo, m2, op, nops, ops, ae), \
14598 xCM_(m1, mi, m2, op, nops, ops, ae), \
14599 xCM_(m1, pl, m2, op, nops, ops, ae), \
14600 xCM_(m1, vs, m2, op, nops, ops, ae), \
14601 xCM_(m1, vc, m2, op, nops, ops, ae), \
14602 xCM_(m1, hi, m2, op, nops, ops, ae), \
14603 xCM_(m1, ls, m2, op, nops, ops, ae), \
14604 xCM_(m1, ge, m2, op, nops, ops, ae), \
14605 xCM_(m1, lt, m2, op, nops, ops, ae), \
14606 xCM_(m1, gt, m2, op, nops, ops, ae), \
14607 xCM_(m1, le, m2, op, nops, ops, ae), \
14608 xCM_(m1, al, m2, op, nops, ops, ae)
14609
14610 #define UE(mnem, op, nops, ops, ae) \
14611 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14612
14613 #define UF(mnem, op, nops, ops, ae) \
14614 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14615
14616 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
14617 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
14618 use the same encoding function for each. */
14619 #define NUF(mnem, op, nops, ops, enc) \
14620 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
14621 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14622
14623 /* Neon data processing, version which indirects through neon_enc_tab for
14624 the various overloaded versions of opcodes. */
14625 #define nUF(mnem, op, nops, ops, enc) \
14626 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \
14627 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14628
14629 /* Neon insn with conditional suffix for the ARM version, non-overloaded
14630 version. */
14631 #define NCE_tag(mnem, op, nops, ops, enc, tag) \
14632 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
14633 THUMB_VARIANT, do_##enc, do_##enc }
14634
14635 #define NCE(mnem, op, nops, ops, enc) \
14636 NCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14637
14638 #define NCEF(mnem, op, nops, ops, enc) \
14639 NCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14640
14641 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
14642 #define nCE_tag(mnem, op, nops, ops, enc, tag) \
14643 { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \
14644 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14645
14646 #define nCE(mnem, op, nops, ops, enc) \
14647 nCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14648
14649 #define nCEF(mnem, op, nops, ops, enc) \
14650 nCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14651
14652 #define do_0 0
14653
14654 /* Thumb-only, unconditional. */
14655 #define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
14656
14657 static const struct asm_opcode insns[] =
14658 {
14659 #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
14660 #define THUMB_VARIANT &arm_ext_v4t
14661 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
14662 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
14663 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
14664 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
14665 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
14666 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
14667 tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub),
14668 tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub),
14669 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
14670 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
14671 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
14672 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
14673 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
14674 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
14675 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
14676 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
14677
14678 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
14679 for setting PSR flag bits. They are obsolete in V6 and do not
14680 have Thumb equivalents. */
14681 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
14682 tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
14683 CL(tstp, 110f000, 2, (RR, SH), cmp),
14684 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
14685 tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
14686 CL(cmpp, 150f000, 2, (RR, SH), cmp),
14687 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
14688 tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
14689 CL(cmnp, 170f000, 2, (RR, SH), cmp),
14690
14691 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
14692 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
14693 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
14694 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
14695
14696 tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
14697 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
14698 tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst),
14699 tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
14700
14701 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14702 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14703 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14704 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14705 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14706 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14707
14708 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
14709 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
14710 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
14711 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
14712
14713 /* Pseudo ops. */
14714 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
14715 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
14716 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
14717
14718 /* Thumb-compatibility pseudo ops. */
14719 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
14720 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
14721 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
14722 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
14723 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
14724 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
14725 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
14726 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
14727 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
14728 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
14729 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
14730 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
14731
14732 #undef THUMB_VARIANT
14733 #define THUMB_VARIANT &arm_ext_v6
14734 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
14735
14736 /* V1 instructions with no Thumb analogue prior to V6T2. */
14737 #undef THUMB_VARIANT
14738 #define THUMB_VARIANT &arm_ext_v6t2
14739 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
14740 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
14741 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
14742 TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
14743 CL(teqp, 130f000, 2, (RR, SH), cmp),
14744
14745 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
14746 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
14747 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
14748 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
14749
14750 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14751 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14752
14753 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14754 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14755
14756 /* V1 instructions with no Thumb analogue at all. */
14757 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
14758 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
14759
14760 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
14761 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
14762 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
14763 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
14764 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
14765 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
14766 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
14767 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
14768
14769 #undef ARM_VARIANT
14770 #define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
14771 #undef THUMB_VARIANT
14772 #define THUMB_VARIANT &arm_ext_v4t
14773 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
14774 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
14775
14776 #undef THUMB_VARIANT
14777 #define THUMB_VARIANT &arm_ext_v6t2
14778 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
14779 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
14780
14781 /* Generic coprocessor instructions. */
14782 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
14783 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14784 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14785 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14786 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14787 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
14788 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
14789
14790 #undef ARM_VARIANT
14791 #define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
14792 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
14793 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
14794
14795 #undef ARM_VARIANT
14796 #define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
14797 TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
14798 TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
14799
14800 #undef ARM_VARIANT
14801 #define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
14802 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
14803 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
14804 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
14805 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
14806 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
14807 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
14808 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
14809 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
14810
14811 #undef ARM_VARIANT
14812 #define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
14813 #undef THUMB_VARIANT
14814 #define THUMB_VARIANT &arm_ext_v4t
14815 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14816 tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14817 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14818 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14819 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14820 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14821
14822 #undef ARM_VARIANT
14823 #define ARM_VARIANT &arm_ext_v4t_5
14824 /* ARM Architecture 4T. */
14825 /* Note: bx (and blx) are required on V5, even if the processor does
14826 not support Thumb. */
14827 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
14828
14829 #undef ARM_VARIANT
14830 #define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
14831 #undef THUMB_VARIANT
14832 #define THUMB_VARIANT &arm_ext_v5t
14833 /* Note: blx has 2 variants; the .value coded here is for
14834 BLX(2). Only this variant has conditional execution. */
14835 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
14836 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
14837
14838 #undef THUMB_VARIANT
14839 #define THUMB_VARIANT &arm_ext_v6t2
14840 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
14841 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14842 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14843 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14844 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14845 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
14846 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
14847 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
14848
14849 #undef ARM_VARIANT
14850 #define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
14851 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
14852 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
14853 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
14854 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
14855
14856 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
14857 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
14858
14859 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
14860 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
14861 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
14862 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
14863
14864 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14865 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14866 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14867 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14868
14869 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14870 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14871
14872 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
14873 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
14874 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
14875 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
14876
14877 #undef ARM_VARIANT
14878 #define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
14879 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
14880 TC3(ldrd, 00000d0, e9500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
14881 TC3(strd, 00000f0, e9400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
14882
14883 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
14884 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
14885
14886 #undef ARM_VARIANT
14887 #define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
14888 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
14889
14890 #undef ARM_VARIANT
14891 #define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
14892 #undef THUMB_VARIANT
14893 #define THUMB_VARIANT &arm_ext_v6
14894 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
14895 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
14896 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
14897 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
14898 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
14899 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
14900 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
14901 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
14902 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
14903 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
14904
14905 #undef THUMB_VARIANT
14906 #define THUMB_VARIANT &arm_ext_v6t2
14907 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
14908 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
14909 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
14910
14911 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
14912 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
14913
14914 /* ARM V6 not included in V7M (eg. integer SIMD). */
14915 #undef THUMB_VARIANT
14916 #define THUMB_VARIANT &arm_ext_v6_notm
14917 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
14918 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
14919 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
14920 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14921 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14922 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14923 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14924 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14925 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14926 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14927 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14928 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14929 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14930 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14931 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14932 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14933 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14934 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14935 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14936 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14937 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14938 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14939 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14940 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14941 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14942 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14943 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14944 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14945 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14946 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14947 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14948 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14949 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14950 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14951 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14952 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14953 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14954 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14955 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14956 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
14957 UF(rfeib, 9900a00, 1, (RRw), rfe),
14958 UF(rfeda, 8100a00, 1, (RRw), rfe),
14959 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
14960 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
14961 UF(rfefa, 9900a00, 1, (RRw), rfe),
14962 UF(rfeea, 8100a00, 1, (RRw), rfe),
14963 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
14964 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
14965 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
14966 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
14967 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
14968 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
14969 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
14970 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
14971 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
14972 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14973 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14974 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14975 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
14976 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
14977 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14978 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14979 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
14980 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
14981 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14982 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14983 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14984 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14985 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14986 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14987 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14988 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14989 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14990 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14991 TUF(srsia, 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
14992 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
14993 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
14994 TUF(srsdb, 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
14995 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
14996 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
14997 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
14998 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14999 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15000 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
15001
15002 #undef ARM_VARIANT
15003 #define ARM_VARIANT &arm_ext_v6k
15004 #undef THUMB_VARIANT
15005 #define THUMB_VARIANT &arm_ext_v6k
15006 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
15007 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
15008 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
15009 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
15010
15011 #undef THUMB_VARIANT
15012 #define THUMB_VARIANT &arm_ext_v6_notm
15013 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
15014 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
15015
15016 #undef THUMB_VARIANT
15017 #define THUMB_VARIANT &arm_ext_v6t2
15018 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15019 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15020 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15021 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15022 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
15023
15024 #undef ARM_VARIANT
15025 #define ARM_VARIANT &arm_ext_v6z
15026 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
15027
15028 #undef ARM_VARIANT
15029 #define ARM_VARIANT &arm_ext_v6t2
15030 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
15031 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
15032 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15033 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15034
15035 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
15036 TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
15037 TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
15038 TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
15039
15040 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15041 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15042 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15043 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15044
15045 UT(cbnz, b900, 2, (RR, EXP), t_cbz),
15046 UT(cbz, b100, 2, (RR, EXP), t_cbz),
15047 /* ARM does not really have an IT instruction, so always allow it. */
15048 #undef ARM_VARIANT
15049 #define ARM_VARIANT &arm_ext_v1
15050 TUE(it, 0, bf08, 1, (COND), it, t_it),
15051 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
15052 TUE(ite, 0, bf04, 1, (COND), it, t_it),
15053 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
15054 TUE(itet, 0, bf06, 1, (COND), it, t_it),
15055 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
15056 TUE(itee, 0, bf02, 1, (COND), it, t_it),
15057 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
15058 TUE(itett, 0, bf07, 1, (COND), it, t_it),
15059 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
15060 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
15061 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
15062 TUE(itete, 0, bf05, 1, (COND), it, t_it),
15063 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
15064 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
15065
15066 /* Thumb2 only instructions. */
15067 #undef ARM_VARIANT
15068 #define ARM_VARIANT NULL
15069
15070 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15071 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15072 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
15073 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
15074
15075 /* Thumb-2 hardware division instructions (R and M profiles only). */
15076 #undef THUMB_VARIANT
15077 #define THUMB_VARIANT &arm_ext_div
15078 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
15079 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
15080
15081 /* ARM V7 instructions. */
15082 #undef ARM_VARIANT
15083 #define ARM_VARIANT &arm_ext_v7
15084 #undef THUMB_VARIANT
15085 #define THUMB_VARIANT &arm_ext_v7
15086 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
15087 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
15088 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
15089 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
15090 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
15091
15092 #undef ARM_VARIANT
15093 #define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
15094 cCE(wfs, e200110, 1, (RR), rd),
15095 cCE(rfs, e300110, 1, (RR), rd),
15096 cCE(wfc, e400110, 1, (RR), rd),
15097 cCE(rfc, e500110, 1, (RR), rd),
15098
15099 cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
15100 cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
15101 cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
15102 cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
15103
15104 cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
15105 cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
15106 cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
15107 cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
15108
15109 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
15110 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
15111 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
15112 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
15113 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
15114 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
15115 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
15116 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
15117 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
15118 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
15119 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
15120 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
15121
15122 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
15123 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
15124 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
15125 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
15126 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
15127 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
15128 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
15129 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
15130 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
15131 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
15132 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
15133 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
15134
15135 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
15136 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
15137 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
15138 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
15139 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
15140 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
15141 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
15142 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
15143 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
15144 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
15145 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
15146 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
15147
15148 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
15149 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
15150 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
15151 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
15152 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
15153 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
15154 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
15155 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
15156 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
15157 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
15158 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
15159 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
15160
15161 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
15162 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
15163 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
15164 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
15165 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
15166 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
15167 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
15168 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
15169 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
15170 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
15171 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
15172 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
15173
15174 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
15175 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
15176 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
15177 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
15178 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
15179 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
15180 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
15181 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
15182 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
15183 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
15184 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
15185 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
15186
15187 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
15188 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
15189 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
15190 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
15191 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
15192 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
15193 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
15194 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
15195 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
15196 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
15197 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
15198 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
15199
15200 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
15201 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
15202 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
15203 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
15204 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
15205 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
15206 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
15207 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
15208 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
15209 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
15210 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
15211 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
15212
15213 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
15214 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
15215 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
15216 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
15217 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
15218 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
15219 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
15220 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
15221 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
15222 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
15223 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
15224 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
15225
15226 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
15227 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
15228 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
15229 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
15230 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
15231 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
15232 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
15233 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
15234 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
15235 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
15236 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
15237 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
15238
15239 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
15240 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
15241 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
15242 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
15243 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
15244 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
15245 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
15246 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
15247 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
15248 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
15249 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
15250 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
15251
15252 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
15253 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
15254 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
15255 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
15256 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
15257 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
15258 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
15259 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
15260 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
15261 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
15262 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
15263 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
15264
15265 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
15266 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
15267 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
15268 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
15269 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
15270 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
15271 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
15272 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
15273 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
15274 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
15275 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
15276 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
15277
15278 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
15279 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
15280 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
15281 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
15282 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
15283 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
15284 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
15285 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
15286 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
15287 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
15288 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
15289 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
15290
15291 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
15292 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
15293 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
15294 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
15295 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
15296 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
15297 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
15298 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
15299 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
15300 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
15301 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
15302 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
15303
15304 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
15305 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
15306 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
15307 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
15308 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
15309 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
15310 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
15311 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
15312 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
15313 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
15314 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
15315 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
15316
15317 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
15318 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
15319 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
15320 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
15321 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
15322 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15323 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15324 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15325 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
15326 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
15327 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
15328 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
15329
15330 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
15331 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
15332 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
15333 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
15334 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
15335 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15336 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15337 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15338 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
15339 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
15340 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
15341 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
15342
15343 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
15344 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
15345 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
15346 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
15347 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
15348 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15349 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15350 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15351 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
15352 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
15353 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
15354 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
15355
15356 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
15357 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
15358 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
15359 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
15360 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
15361 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15362 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15363 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15364 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
15365 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
15366 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
15367 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
15368
15369 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
15370 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
15371 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
15372 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
15373 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
15374 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15375 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15376 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15377 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
15378 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
15379 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
15380 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
15381
15382 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
15383 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
15384 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
15385 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
15386 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
15387 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15388 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15389 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15390 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
15391 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
15392 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
15393 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
15394
15395 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
15396 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
15397 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
15398 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
15399 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
15400 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15401 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15402 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15403 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
15404 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
15405 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
15406 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
15407
15408 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
15409 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
15410 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
15411 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
15412 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
15413 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15414 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15415 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15416 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
15417 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
15418 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
15419 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
15420
15421 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
15422 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
15423 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
15424 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
15425 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
15426 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15427 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15428 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15429 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
15430 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
15431 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
15432 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
15433
15434 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
15435 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
15436 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
15437 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
15438 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
15439 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15440 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15441 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15442 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
15443 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
15444 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
15445 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
15446
15447 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15448 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15449 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15450 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15451 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15452 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15453 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15454 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15455 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15456 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15457 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15458 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15459
15460 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15461 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15462 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15463 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15464 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15465 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15466 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15467 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15468 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15469 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15470 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15471 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15472
15473 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15474 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15475 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15476 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15477 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15478 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15479 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15480 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15481 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15482 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15483 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15484 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15485
15486 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
15487 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
15488 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
15489 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
15490
15491 cCL(flts, e000110, 2, (RF, RR), rn_rd),
15492 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
15493 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
15494 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
15495 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
15496 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
15497 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
15498 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
15499 cCL(flte, e080110, 2, (RF, RR), rn_rd),
15500 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
15501 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
15502 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
15503
15504 /* The implementation of the FIX instruction is broken on some
15505 assemblers, in that it accepts a precision specifier as well as a
15506 rounding specifier, despite the fact that this is meaningless.
15507 To be more compatible, we accept it as well, though of course it
15508 does not set any bits. */
15509 cCE(fix, e100110, 2, (RR, RF), rd_rm),
15510 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
15511 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
15512 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
15513 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
15514 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
15515 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
15516 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
15517 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
15518 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
15519 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
15520 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
15521 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
15522
15523 /* Instructions that were new with the real FPA, call them V2. */
15524 #undef ARM_VARIANT
15525 #define ARM_VARIANT &fpu_fpa_ext_v2
15526 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15527 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15528 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15529 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15530 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15531 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15532
15533 #undef ARM_VARIANT
15534 #define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
15535 /* Moves and type conversions. */
15536 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
15537 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
15538 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
15539 cCE(fmstat, ef1fa10, 0, (), noargs),
15540 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
15541 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
15542 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
15543 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15544 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
15545 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15546 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
15547 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
15548
15549 /* Memory operations. */
15550 cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15551 cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15552 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15553 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15554 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15555 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15556 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15557 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15558 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15559 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15560 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15561 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15562 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15563 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15564 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15565 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15566 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15567 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15568
15569 /* Monadic operations. */
15570 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
15571 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
15572 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
15573
15574 /* Dyadic operations. */
15575 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15576 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15577 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15578 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15579 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15580 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15581 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15582 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15583 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15584
15585 /* Comparisons. */
15586 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
15587 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
15588 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
15589 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
15590
15591 #undef ARM_VARIANT
15592 #define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
15593 /* Moves and type conversions. */
15594 cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15595 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15596 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15597 cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
15598 cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
15599 cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
15600 cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
15601 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15602 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
15603 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15604 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15605 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15606 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15607
15608 /* Memory operations. */
15609 cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
15610 cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
15611 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15612 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15613 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15614 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15615 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15616 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15617 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15618 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15619
15620 /* Monadic operations. */
15621 cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15622 cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15623 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15624
15625 /* Dyadic operations. */
15626 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15627 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15628 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15629 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15630 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15631 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15632 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15633 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15634 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15635
15636 /* Comparisons. */
15637 cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15638 cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd),
15639 cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15640 cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd),
15641
15642 #undef ARM_VARIANT
15643 #define ARM_VARIANT &fpu_vfp_ext_v2
15644 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
15645 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
15646 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
15647 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
15648
15649 /* Instructions which may belong to either the Neon or VFP instruction sets.
15650 Individual encoder functions perform additional architecture checks. */
15651 #undef ARM_VARIANT
15652 #define ARM_VARIANT &fpu_vfp_ext_v1xd
15653 #undef THUMB_VARIANT
15654 #define THUMB_VARIANT &fpu_vfp_ext_v1xd
15655 /* These mnemonics are unique to VFP. */
15656 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
15657 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
15658 nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15659 nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15660 nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15661 nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15662 nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15663 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
15664 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
15665 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
15666
15667 /* Mnemonics shared by Neon and VFP. */
15668 nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
15669 nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15670 nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15671
15672 nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15673 nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15674
15675 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15676 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15677
15678 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15679 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15680 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15681 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15682 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15683 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15684 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
15685 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
15686
15687 nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
15688
15689 /* NOTE: All VMOV encoding is special-cased! */
15690 NCE(vmov, 0, 1, (VMOV), neon_mov),
15691 NCE(vmovq, 0, 1, (VMOV), neon_mov),
15692
15693 #undef THUMB_VARIANT
15694 #define THUMB_VARIANT &fpu_neon_ext_v1
15695 #undef ARM_VARIANT
15696 #define ARM_VARIANT &fpu_neon_ext_v1
15697 /* Data processing with three registers of the same length. */
15698 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
15699 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
15700 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
15701 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15702 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15703 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15704 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15705 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15706 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15707 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
15708 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15709 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15710 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15711 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15712 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15713 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
15714 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15715 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
15716 /* If not immediate, fall back to neon_dyadic_i64_su.
15717 shl_imm should accept I8 I16 I32 I64,
15718 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
15719 nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
15720 nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
15721 nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
15722 nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
15723 /* Logic ops, types optional & ignored. */
15724 nUF(vand, vand, 2, (RNDQ, NILO), neon_logic),
15725 nUF(vandq, vand, 2, (RNQ, NILO), neon_logic),
15726 nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic),
15727 nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic),
15728 nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic),
15729 nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic),
15730 nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic),
15731 nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic),
15732 nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
15733 nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
15734 /* Bitfield ops, untyped. */
15735 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15736 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15737 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15738 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15739 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15740 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15741 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
15742 nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15743 nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15744 nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15745 nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15746 nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15747 nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15748 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
15749 back to neon_dyadic_if_su. */
15750 nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
15751 nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
15752 nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
15753 nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
15754 nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
15755 nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
15756 nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
15757 nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
15758 /* Comparison. Type I8 I16 I32 F32. */
15759 nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
15760 nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
15761 /* As above, D registers only. */
15762 nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
15763 nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
15764 /* Int and float variants, signedness unimportant. */
15765 nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
15766 nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
15767 nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
15768 /* Add/sub take types I8 I16 I32 I64 F32. */
15769 nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
15770 nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
15771 /* vtst takes sizes 8, 16, 32. */
15772 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
15773 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
15774 /* VMUL takes I8 I16 I32 F32 P8. */
15775 nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
15776 /* VQD{R}MULH takes S16 S32. */
15777 nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
15778 nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
15779 nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
15780 nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
15781 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
15782 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
15783 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
15784 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
15785 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
15786 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
15787 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
15788 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
15789 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
15790 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
15791 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
15792 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
15793
15794 /* Two address, int/float. Types S8 S16 S32 F32. */
15795 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
15796 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
15797
15798 /* Data processing with two registers and a shift amount. */
15799 /* Right shifts, and variants with rounding.
15800 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
15801 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
15802 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
15803 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
15804 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
15805 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
15806 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
15807 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
15808 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
15809 /* Shift and insert. Sizes accepted 8 16 32 64. */
15810 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
15811 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
15812 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
15813 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
15814 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
15815 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
15816 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
15817 /* Right shift immediate, saturating & narrowing, with rounding variants.
15818 Types accepted S16 S32 S64 U16 U32 U64. */
15819 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
15820 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
15821 /* As above, unsigned. Types accepted S16 S32 S64. */
15822 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
15823 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
15824 /* Right shift narrowing. Types accepted I16 I32 I64. */
15825 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
15826 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
15827 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
15828 nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll),
15829 /* CVT with optional immediate for fixed-point variant. */
15830 nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
15831
15832 nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
15833 nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
15834
15835 /* Data processing, three registers of different lengths. */
15836 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
15837 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
15838 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
15839 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
15840 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
15841 /* If not scalar, fall back to neon_dyadic_long.
15842 Vector types as above, scalar types S16 S32 U16 U32. */
15843 nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
15844 nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
15845 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
15846 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
15847 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
15848 /* Dyadic, narrowing insns. Types I16 I32 I64. */
15849 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
15850 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
15851 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
15852 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
15853 /* Saturating doubling multiplies. Types S16 S32. */
15854 nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
15855 nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
15856 nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
15857 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
15858 S16 S32 U16 U32. */
15859 nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
15860
15861 /* Extract. Size 8. */
15862 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I7), neon_ext),
15863 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I7), neon_ext),
15864
15865 /* Two registers, miscellaneous. */
15866 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
15867 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
15868 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
15869 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
15870 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
15871 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
15872 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
15873 /* Vector replicate. Sizes 8 16 32. */
15874 nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup),
15875 nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup),
15876 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
15877 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
15878 /* VMOVN. Types I16 I32 I64. */
15879 nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn),
15880 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
15881 nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn),
15882 /* VQMOVUN. Types S16 S32 S64. */
15883 nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun),
15884 /* VZIP / VUZP. Sizes 8 16 32. */
15885 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
15886 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
15887 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
15888 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
15889 /* VQABS / VQNEG. Types S8 S16 S32. */
15890 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
15891 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
15892 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
15893 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
15894 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
15895 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
15896 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
15897 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
15898 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
15899 /* Reciprocal estimates. Types U32 F32. */
15900 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
15901 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
15902 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
15903 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
15904 /* VCLS. Types S8 S16 S32. */
15905 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
15906 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
15907 /* VCLZ. Types I8 I16 I32. */
15908 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
15909 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
15910 /* VCNT. Size 8. */
15911 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
15912 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
15913 /* Two address, untyped. */
15914 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
15915 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
15916 /* VTRN. Sizes 8 16 32. */
15917 nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn),
15918 nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn),
15919
15920 /* Table lookup. Size 8. */
15921 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
15922 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
15923
15924 #undef THUMB_VARIANT
15925 #define THUMB_VARIANT &fpu_vfp_v3_or_neon_ext
15926 #undef ARM_VARIANT
15927 #define ARM_VARIANT &fpu_vfp_v3_or_neon_ext
15928 /* Neon element/structure load/store. */
15929 nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
15930 nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
15931 nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
15932 nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
15933 nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
15934 nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
15935 nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
15936 nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
15937
15938 #undef THUMB_VARIANT
15939 #define THUMB_VARIANT &fpu_vfp_ext_v3
15940 #undef ARM_VARIANT
15941 #define ARM_VARIANT &fpu_vfp_ext_v3
15942 cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const),
15943 cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const),
15944 cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
15945 cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
15946 cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
15947 cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
15948 cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
15949 cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
15950 cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
15951 cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
15952 cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
15953 cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
15954 cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
15955 cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
15956 cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
15957 cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
15958 cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
15959 cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
15960
15961 #undef THUMB_VARIANT
15962 #undef ARM_VARIANT
15963 #define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
15964 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
15965 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
15966 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
15967 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
15968 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
15969 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
15970 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
15971 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
15972
15973 #undef ARM_VARIANT
15974 #define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
15975 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
15976 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
15977 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
15978 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
15979 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
15980 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
15981 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
15982 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
15983 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
15984 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
15985 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
15986 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
15987 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
15988 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
15989 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
15990 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
15991 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
15992 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
15993 cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd),
15994 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
15995 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
15996 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
15997 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
15998 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
15999 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16000 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16001 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
16002 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
16003 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
16004 cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn),
16005 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
16006 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
16007 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
16008 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
16009 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
16010 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
16011 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
16012 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16013 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16014 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16015 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16016 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16017 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16018 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16019 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16020 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16021 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
16022 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16023 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16024 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16025 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16026 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16027 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16028 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16029 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16030 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16031 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16032 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16033 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16034 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16035 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16036 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16037 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16038 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16039 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16040 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16041 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16042 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16043 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16044 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16045 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16046 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16047 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16048 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16049 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16050 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16051 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16052 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16053 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16054 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16055 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16056 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16057 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16058 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16059 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16060 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16061 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16062 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16063 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
16064 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16065 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16066 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16067 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16068 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16069 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16070 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16071 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16072 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16073 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16074 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16075 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16076 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16077 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16078 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16079 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16080 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16081 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16082 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16083 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16084 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16085 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
16086 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16087 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16088 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16089 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16090 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16091 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16092 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16093 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16094 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16095 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16096 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16097 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16098 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16099 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16100 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16101 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16102 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16103 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16104 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16105 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16106 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16107 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16108 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16109 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16110 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16111 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16112 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16113 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16114 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16115 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16116 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16117 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
16118 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
16119 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
16120 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
16121 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
16122 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
16123 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16124 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16125 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16126 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
16127 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
16128 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
16129 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
16130 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
16131 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
16132 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16133 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16134 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16135 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16136 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
16137
16138 #undef ARM_VARIANT
16139 #define ARM_VARIANT &arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
16140 cCE(torvscb, e13f190, 1, (RR), iwmmxt_tandorc),
16141 cCE(torvsch, e53f190, 1, (RR), iwmmxt_tandorc),
16142 cCE(torvscw, e93f190, 1, (RR), iwmmxt_tandorc),
16143 cCE(wabsb, e2001c0, 2, (RIWR, RIWR), rd_rn),
16144 cCE(wabsh, e6001c0, 2, (RIWR, RIWR), rd_rn),
16145 cCE(wabsw, ea001c0, 2, (RIWR, RIWR), rd_rn),
16146 cCE(wabsdiffb, e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16147 cCE(wabsdiffh, e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16148 cCE(wabsdiffw, e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16149 cCE(waddbhusl, e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16150 cCE(waddbhusm, e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16151 cCE(waddhc, e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16152 cCE(waddwc, ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16153 cCE(waddsubhx, ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16154 cCE(wavg4, e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16155 cCE(wavg4r, e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16156 cCE(wmaddsn, ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16157 cCE(wmaddsx, eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16158 cCE(wmaddun, ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16159 cCE(wmaddux, e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16160 cCE(wmerge, e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
16161 cCE(wmiabb, e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16162 cCE(wmiabt, e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16163 cCE(wmiatb, e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16164 cCE(wmiatt, e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16165 cCE(wmiabbn, e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16166 cCE(wmiabtn, e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16167 cCE(wmiatbn, e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16168 cCE(wmiattn, e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16169 cCE(wmiawbb, e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16170 cCE(wmiawbt, e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16171 cCE(wmiawtb, ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16172 cCE(wmiawtt, eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16173 cCE(wmiawbbn, ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16174 cCE(wmiawbtn, ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16175 cCE(wmiawtbn, ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16176 cCE(wmiawttn, ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16177 cCE(wmulsmr, ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16178 cCE(wmulumr, ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16179 cCE(wmulwumr, ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16180 cCE(wmulwsmr, ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16181 cCE(wmulwum, ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16182 cCE(wmulwsm, ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16183 cCE(wmulwl, eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16184 cCE(wqmiabb, e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16185 cCE(wqmiabt, e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16186 cCE(wqmiatb, ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16187 cCE(wqmiatt, eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16188 cCE(wqmiabbn, ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16189 cCE(wqmiabtn, ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16190 cCE(wqmiatbn, ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16191 cCE(wqmiattn, ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16192 cCE(wqmulm, e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16193 cCE(wqmulmr, e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16194 cCE(wqmulwm, ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16195 cCE(wqmulwmr, ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16196 cCE(wsubaddhx, ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16197
16198 #undef ARM_VARIANT
16199 #define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
16200 cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16201 cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16202 cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16203 cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
16204 cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16205 cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16206 cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16207 cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
16208 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
16209 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
16210 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
16211 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
16212 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
16213 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
16214 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
16215 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
16216 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
16217 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
16218 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
16219 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
16220 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
16221 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
16222 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
16223 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
16224 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
16225 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
16226 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
16227 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
16228 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
16229 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
16230 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
16231 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
16232 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
16233 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
16234 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
16235 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
16236 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
16237 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
16238 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
16239 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
16240 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
16241 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
16242 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
16243 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
16244 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
16245 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
16246 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
16247 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
16248 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
16249 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
16250 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
16251 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
16252 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
16253 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
16254 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
16255 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
16256 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
16257 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
16258 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
16259 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
16260 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
16261 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
16262 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
16263 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
16264 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16265 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16266 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16267 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16268 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16269 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16270 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16271 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16272 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16273 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16274 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
16275 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
16276 };
16277 #undef ARM_VARIANT
16278 #undef THUMB_VARIANT
16279 #undef TCE
16280 #undef TCM
16281 #undef TUE
16282 #undef TUF
16283 #undef TCC
16284 #undef cCE
16285 #undef cCL
16286 #undef C3E
16287 #undef CE
16288 #undef CM
16289 #undef UE
16290 #undef UF
16291 #undef UT
16292 #undef NUF
16293 #undef nUF
16294 #undef NCE
16295 #undef nCE
16296 #undef OPS0
16297 #undef OPS1
16298 #undef OPS2
16299 #undef OPS3
16300 #undef OPS4
16301 #undef OPS5
16302 #undef OPS6
16303 #undef do_0
16304 \f
16305 /* MD interface: bits in the object file. */
16306
16307 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
16308 for use in the a.out file, and stores them in the array pointed to by buf.
16309 This knows about the endian-ness of the target machine and does
16310 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
16311 2 (short) and 4 (long) Floating numbers are put out as a series of
16312 LITTLENUMS (shorts, here at least). */
16313
16314 void
16315 md_number_to_chars (char * buf, valueT val, int n)
16316 {
16317 if (target_big_endian)
16318 number_to_chars_bigendian (buf, val, n);
16319 else
16320 number_to_chars_littleendian (buf, val, n);
16321 }
16322
16323 static valueT
16324 md_chars_to_number (char * buf, int n)
16325 {
16326 valueT result = 0;
16327 unsigned char * where = (unsigned char *) buf;
16328
16329 if (target_big_endian)
16330 {
16331 while (n--)
16332 {
16333 result <<= 8;
16334 result |= (*where++ & 255);
16335 }
16336 }
16337 else
16338 {
16339 while (n--)
16340 {
16341 result <<= 8;
16342 result |= (where[n] & 255);
16343 }
16344 }
16345
16346 return result;
16347 }
16348
16349 /* MD interface: Sections. */
16350
16351 /* Estimate the size of a frag before relaxing. Assume everything fits in
16352 2 bytes. */
16353
16354 int
16355 md_estimate_size_before_relax (fragS * fragp,
16356 segT segtype ATTRIBUTE_UNUSED)
16357 {
16358 fragp->fr_var = 2;
16359 return 2;
16360 }
16361
16362 /* Convert a machine dependent frag. */
16363
16364 void
16365 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
16366 {
16367 unsigned long insn;
16368 unsigned long old_op;
16369 char *buf;
16370 expressionS exp;
16371 fixS *fixp;
16372 int reloc_type;
16373 int pc_rel;
16374 int opcode;
16375
16376 buf = fragp->fr_literal + fragp->fr_fix;
16377
16378 old_op = bfd_get_16(abfd, buf);
16379 if (fragp->fr_symbol) {
16380 exp.X_op = O_symbol;
16381 exp.X_add_symbol = fragp->fr_symbol;
16382 } else {
16383 exp.X_op = O_constant;
16384 }
16385 exp.X_add_number = fragp->fr_offset;
16386 opcode = fragp->fr_subtype;
16387 switch (opcode)
16388 {
16389 case T_MNEM_ldr_pc:
16390 case T_MNEM_ldr_pc2:
16391 case T_MNEM_ldr_sp:
16392 case T_MNEM_str_sp:
16393 case T_MNEM_ldr:
16394 case T_MNEM_ldrb:
16395 case T_MNEM_ldrh:
16396 case T_MNEM_str:
16397 case T_MNEM_strb:
16398 case T_MNEM_strh:
16399 if (fragp->fr_var == 4)
16400 {
16401 insn = THUMB_OP32(opcode);
16402 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
16403 {
16404 insn |= (old_op & 0x700) << 4;
16405 }
16406 else
16407 {
16408 insn |= (old_op & 7) << 12;
16409 insn |= (old_op & 0x38) << 13;
16410 }
16411 insn |= 0x00000c00;
16412 put_thumb32_insn (buf, insn);
16413 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
16414 }
16415 else
16416 {
16417 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
16418 }
16419 pc_rel = (opcode == T_MNEM_ldr_pc2);
16420 break;
16421 case T_MNEM_adr:
16422 if (fragp->fr_var == 4)
16423 {
16424 insn = THUMB_OP32 (opcode);
16425 insn |= (old_op & 0xf0) << 4;
16426 put_thumb32_insn (buf, insn);
16427 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
16428 }
16429 else
16430 {
16431 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16432 exp.X_add_number -= 4;
16433 }
16434 pc_rel = 1;
16435 break;
16436 case T_MNEM_mov:
16437 case T_MNEM_movs:
16438 case T_MNEM_cmp:
16439 case T_MNEM_cmn:
16440 if (fragp->fr_var == 4)
16441 {
16442 int r0off = (opcode == T_MNEM_mov
16443 || opcode == T_MNEM_movs) ? 0 : 8;
16444 insn = THUMB_OP32 (opcode);
16445 insn = (insn & 0xe1ffffff) | 0x10000000;
16446 insn |= (old_op & 0x700) << r0off;
16447 put_thumb32_insn (buf, insn);
16448 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16449 }
16450 else
16451 {
16452 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
16453 }
16454 pc_rel = 0;
16455 break;
16456 case T_MNEM_b:
16457 if (fragp->fr_var == 4)
16458 {
16459 insn = THUMB_OP32(opcode);
16460 put_thumb32_insn (buf, insn);
16461 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
16462 }
16463 else
16464 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
16465 pc_rel = 1;
16466 break;
16467 case T_MNEM_bcond:
16468 if (fragp->fr_var == 4)
16469 {
16470 insn = THUMB_OP32(opcode);
16471 insn |= (old_op & 0xf00) << 14;
16472 put_thumb32_insn (buf, insn);
16473 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
16474 }
16475 else
16476 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
16477 pc_rel = 1;
16478 break;
16479 case T_MNEM_add_sp:
16480 case T_MNEM_add_pc:
16481 case T_MNEM_inc_sp:
16482 case T_MNEM_dec_sp:
16483 if (fragp->fr_var == 4)
16484 {
16485 /* ??? Choose between add and addw. */
16486 insn = THUMB_OP32 (opcode);
16487 insn |= (old_op & 0xf0) << 4;
16488 put_thumb32_insn (buf, insn);
16489 if (opcode == T_MNEM_add_pc)
16490 reloc_type = BFD_RELOC_ARM_T32_IMM12;
16491 else
16492 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16493 }
16494 else
16495 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16496 pc_rel = 0;
16497 break;
16498
16499 case T_MNEM_addi:
16500 case T_MNEM_addis:
16501 case T_MNEM_subi:
16502 case T_MNEM_subis:
16503 if (fragp->fr_var == 4)
16504 {
16505 insn = THUMB_OP32 (opcode);
16506 insn |= (old_op & 0xf0) << 4;
16507 insn |= (old_op & 0xf) << 16;
16508 put_thumb32_insn (buf, insn);
16509 if (insn & (1 << 20))
16510 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16511 else
16512 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16513 }
16514 else
16515 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16516 pc_rel = 0;
16517 break;
16518 default:
16519 abort();
16520 }
16521 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
16522 reloc_type);
16523 fixp->fx_file = fragp->fr_file;
16524 fixp->fx_line = fragp->fr_line;
16525 fragp->fr_fix += fragp->fr_var;
16526 }
16527
16528 /* Return the size of a relaxable immediate operand instruction.
16529 SHIFT and SIZE specify the form of the allowable immediate. */
16530 static int
16531 relax_immediate (fragS *fragp, int size, int shift)
16532 {
16533 offsetT offset;
16534 offsetT mask;
16535 offsetT low;
16536
16537 /* ??? Should be able to do better than this. */
16538 if (fragp->fr_symbol)
16539 return 4;
16540
16541 low = (1 << shift) - 1;
16542 mask = (1 << (shift + size)) - (1 << shift);
16543 offset = fragp->fr_offset;
16544 /* Force misaligned offsets to 32-bit variant. */
16545 if (offset & low)
16546 return 4;
16547 if (offset & ~mask)
16548 return 4;
16549 return 2;
16550 }
16551
16552 /* Get the address of a symbol during relaxation. */
16553 static addressT
16554 relaxed_symbol_addr(fragS *fragp, long stretch)
16555 {
16556 fragS *sym_frag;
16557 addressT addr;
16558 symbolS *sym;
16559
16560 sym = fragp->fr_symbol;
16561 sym_frag = symbol_get_frag (sym);
16562 know (S_GET_SEGMENT (sym) != absolute_section
16563 || sym_frag == &zero_address_frag);
16564 addr = S_GET_VALUE (sym) + fragp->fr_offset;
16565
16566 /* If frag has yet to be reached on this pass, assume it will
16567 move by STRETCH just as we did. If this is not so, it will
16568 be because some frag between grows, and that will force
16569 another pass. */
16570
16571 if (stretch != 0
16572 && sym_frag->relax_marker != fragp->relax_marker)
16573 addr += stretch;
16574
16575 return addr;
16576 }
16577
16578 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
16579 load. */
16580 static int
16581 relax_adr (fragS *fragp, asection *sec, long stretch)
16582 {
16583 addressT addr;
16584 offsetT val;
16585
16586 /* Assume worst case for symbols not known to be in the same section. */
16587 if (!S_IS_DEFINED(fragp->fr_symbol)
16588 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16589 return 4;
16590
16591 val = relaxed_symbol_addr(fragp, stretch);
16592 addr = fragp->fr_address + fragp->fr_fix;
16593 addr = (addr + 4) & ~3;
16594 /* Force misaligned targets to 32-bit variant. */
16595 if (val & 3)
16596 return 4;
16597 val -= addr;
16598 if (val < 0 || val > 1020)
16599 return 4;
16600 return 2;
16601 }
16602
16603 /* Return the size of a relaxable add/sub immediate instruction. */
16604 static int
16605 relax_addsub (fragS *fragp, asection *sec)
16606 {
16607 char *buf;
16608 int op;
16609
16610 buf = fragp->fr_literal + fragp->fr_fix;
16611 op = bfd_get_16(sec->owner, buf);
16612 if ((op & 0xf) == ((op >> 4) & 0xf))
16613 return relax_immediate (fragp, 8, 0);
16614 else
16615 return relax_immediate (fragp, 3, 0);
16616 }
16617
16618
16619 /* Return the size of a relaxable branch instruction. BITS is the
16620 size of the offset field in the narrow instruction. */
16621
16622 static int
16623 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
16624 {
16625 addressT addr;
16626 offsetT val;
16627 offsetT limit;
16628
16629 /* Assume worst case for symbols not known to be in the same section. */
16630 if (!S_IS_DEFINED(fragp->fr_symbol)
16631 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16632 return 4;
16633
16634 val = relaxed_symbol_addr(fragp, stretch);
16635 addr = fragp->fr_address + fragp->fr_fix + 4;
16636 val -= addr;
16637
16638 /* Offset is a signed value *2 */
16639 limit = 1 << bits;
16640 if (val >= limit || val < -limit)
16641 return 4;
16642 return 2;
16643 }
16644
16645
16646 /* Relax a machine dependent frag. This returns the amount by which
16647 the current size of the frag should change. */
16648
16649 int
16650 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
16651 {
16652 int oldsize;
16653 int newsize;
16654
16655 oldsize = fragp->fr_var;
16656 switch (fragp->fr_subtype)
16657 {
16658 case T_MNEM_ldr_pc2:
16659 newsize = relax_adr(fragp, sec, stretch);
16660 break;
16661 case T_MNEM_ldr_pc:
16662 case T_MNEM_ldr_sp:
16663 case T_MNEM_str_sp:
16664 newsize = relax_immediate(fragp, 8, 2);
16665 break;
16666 case T_MNEM_ldr:
16667 case T_MNEM_str:
16668 newsize = relax_immediate(fragp, 5, 2);
16669 break;
16670 case T_MNEM_ldrh:
16671 case T_MNEM_strh:
16672 newsize = relax_immediate(fragp, 5, 1);
16673 break;
16674 case T_MNEM_ldrb:
16675 case T_MNEM_strb:
16676 newsize = relax_immediate(fragp, 5, 0);
16677 break;
16678 case T_MNEM_adr:
16679 newsize = relax_adr(fragp, sec, stretch);
16680 break;
16681 case T_MNEM_mov:
16682 case T_MNEM_movs:
16683 case T_MNEM_cmp:
16684 case T_MNEM_cmn:
16685 newsize = relax_immediate(fragp, 8, 0);
16686 break;
16687 case T_MNEM_b:
16688 newsize = relax_branch(fragp, sec, 11, stretch);
16689 break;
16690 case T_MNEM_bcond:
16691 newsize = relax_branch(fragp, sec, 8, stretch);
16692 break;
16693 case T_MNEM_add_sp:
16694 case T_MNEM_add_pc:
16695 newsize = relax_immediate (fragp, 8, 2);
16696 break;
16697 case T_MNEM_inc_sp:
16698 case T_MNEM_dec_sp:
16699 newsize = relax_immediate (fragp, 7, 2);
16700 break;
16701 case T_MNEM_addi:
16702 case T_MNEM_addis:
16703 case T_MNEM_subi:
16704 case T_MNEM_subis:
16705 newsize = relax_addsub (fragp, sec);
16706 break;
16707 default:
16708 abort();
16709 }
16710
16711 fragp->fr_var = newsize;
16712 /* Freeze wide instructions that are at or before the same location as
16713 in the previous pass. This avoids infinite loops.
16714 Don't freeze them unconditionally because targets may be artificialy
16715 misaligned by the expansion of preceeding frags. */
16716 if (stretch <= 0 && newsize > 2)
16717 {
16718 md_convert_frag (sec->owner, sec, fragp);
16719 frag_wane(fragp);
16720 }
16721
16722 return newsize - oldsize;
16723 }
16724
16725 /* Round up a section size to the appropriate boundary. */
16726
16727 valueT
16728 md_section_align (segT segment ATTRIBUTE_UNUSED,
16729 valueT size)
16730 {
16731 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
16732 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
16733 {
16734 /* For a.out, force the section size to be aligned. If we don't do
16735 this, BFD will align it for us, but it will not write out the
16736 final bytes of the section. This may be a bug in BFD, but it is
16737 easier to fix it here since that is how the other a.out targets
16738 work. */
16739 int align;
16740
16741 align = bfd_get_section_alignment (stdoutput, segment);
16742 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
16743 }
16744 #endif
16745
16746 return size;
16747 }
16748
16749 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
16750 of an rs_align_code fragment. */
16751
16752 void
16753 arm_handle_align (fragS * fragP)
16754 {
16755 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
16756 static char const thumb_noop[2] = { 0xc0, 0x46 };
16757 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
16758 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
16759
16760 int bytes, fix, noop_size;
16761 char * p;
16762 const char * noop;
16763
16764 if (fragP->fr_type != rs_align_code)
16765 return;
16766
16767 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
16768 p = fragP->fr_literal + fragP->fr_fix;
16769 fix = 0;
16770
16771 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
16772 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
16773
16774 if (fragP->tc_frag_data)
16775 {
16776 if (target_big_endian)
16777 noop = thumb_bigend_noop;
16778 else
16779 noop = thumb_noop;
16780 noop_size = sizeof (thumb_noop);
16781 }
16782 else
16783 {
16784 if (target_big_endian)
16785 noop = arm_bigend_noop;
16786 else
16787 noop = arm_noop;
16788 noop_size = sizeof (arm_noop);
16789 }
16790
16791 if (bytes & (noop_size - 1))
16792 {
16793 fix = bytes & (noop_size - 1);
16794 memset (p, 0, fix);
16795 p += fix;
16796 bytes -= fix;
16797 }
16798
16799 while (bytes >= noop_size)
16800 {
16801 memcpy (p, noop, noop_size);
16802 p += noop_size;
16803 bytes -= noop_size;
16804 fix += noop_size;
16805 }
16806
16807 fragP->fr_fix += fix;
16808 fragP->fr_var = noop_size;
16809 }
16810
16811 /* Called from md_do_align. Used to create an alignment
16812 frag in a code section. */
16813
16814 void
16815 arm_frag_align_code (int n, int max)
16816 {
16817 char * p;
16818
16819 /* We assume that there will never be a requirement
16820 to support alignments greater than 32 bytes. */
16821 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
16822 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
16823
16824 p = frag_var (rs_align_code,
16825 MAX_MEM_FOR_RS_ALIGN_CODE,
16826 1,
16827 (relax_substateT) max,
16828 (symbolS *) NULL,
16829 (offsetT) n,
16830 (char *) NULL);
16831 *p = 0;
16832 }
16833
16834 /* Perform target specific initialisation of a frag. */
16835
16836 void
16837 arm_init_frag (fragS * fragP)
16838 {
16839 /* Record whether this frag is in an ARM or a THUMB area. */
16840 fragP->tc_frag_data = thumb_mode;
16841 }
16842
16843 #ifdef OBJ_ELF
16844 /* When we change sections we need to issue a new mapping symbol. */
16845
16846 void
16847 arm_elf_change_section (void)
16848 {
16849 flagword flags;
16850 segment_info_type *seginfo;
16851
16852 /* Link an unlinked unwind index table section to the .text section. */
16853 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
16854 && elf_linked_to_section (now_seg) == NULL)
16855 elf_linked_to_section (now_seg) = text_section;
16856
16857 if (!SEG_NORMAL (now_seg))
16858 return;
16859
16860 flags = bfd_get_section_flags (stdoutput, now_seg);
16861
16862 /* We can ignore sections that only contain debug info. */
16863 if ((flags & SEC_ALLOC) == 0)
16864 return;
16865
16866 seginfo = seg_info (now_seg);
16867 mapstate = seginfo->tc_segment_info_data.mapstate;
16868 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
16869 }
16870
16871 int
16872 arm_elf_section_type (const char * str, size_t len)
16873 {
16874 if (len == 5 && strncmp (str, "exidx", 5) == 0)
16875 return SHT_ARM_EXIDX;
16876
16877 return -1;
16878 }
16879 \f
16880 /* Code to deal with unwinding tables. */
16881
16882 static void add_unwind_adjustsp (offsetT);
16883
16884 /* Cenerate and deferred unwind frame offset. */
16885
16886 static void
16887 flush_pending_unwind (void)
16888 {
16889 offsetT offset;
16890
16891 offset = unwind.pending_offset;
16892 unwind.pending_offset = 0;
16893 if (offset != 0)
16894 add_unwind_adjustsp (offset);
16895 }
16896
16897 /* Add an opcode to this list for this function. Two-byte opcodes should
16898 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
16899 order. */
16900
16901 static void
16902 add_unwind_opcode (valueT op, int length)
16903 {
16904 /* Add any deferred stack adjustment. */
16905 if (unwind.pending_offset)
16906 flush_pending_unwind ();
16907
16908 unwind.sp_restored = 0;
16909
16910 if (unwind.opcode_count + length > unwind.opcode_alloc)
16911 {
16912 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
16913 if (unwind.opcodes)
16914 unwind.opcodes = xrealloc (unwind.opcodes,
16915 unwind.opcode_alloc);
16916 else
16917 unwind.opcodes = xmalloc (unwind.opcode_alloc);
16918 }
16919 while (length > 0)
16920 {
16921 length--;
16922 unwind.opcodes[unwind.opcode_count] = op & 0xff;
16923 op >>= 8;
16924 unwind.opcode_count++;
16925 }
16926 }
16927
16928 /* Add unwind opcodes to adjust the stack pointer. */
16929
16930 static void
16931 add_unwind_adjustsp (offsetT offset)
16932 {
16933 valueT op;
16934
16935 if (offset > 0x200)
16936 {
16937 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
16938 char bytes[5];
16939 int n;
16940 valueT o;
16941
16942 /* Long form: 0xb2, uleb128. */
16943 /* This might not fit in a word so add the individual bytes,
16944 remembering the list is built in reverse order. */
16945 o = (valueT) ((offset - 0x204) >> 2);
16946 if (o == 0)
16947 add_unwind_opcode (0, 1);
16948
16949 /* Calculate the uleb128 encoding of the offset. */
16950 n = 0;
16951 while (o)
16952 {
16953 bytes[n] = o & 0x7f;
16954 o >>= 7;
16955 if (o)
16956 bytes[n] |= 0x80;
16957 n++;
16958 }
16959 /* Add the insn. */
16960 for (; n; n--)
16961 add_unwind_opcode (bytes[n - 1], 1);
16962 add_unwind_opcode (0xb2, 1);
16963 }
16964 else if (offset > 0x100)
16965 {
16966 /* Two short opcodes. */
16967 add_unwind_opcode (0x3f, 1);
16968 op = (offset - 0x104) >> 2;
16969 add_unwind_opcode (op, 1);
16970 }
16971 else if (offset > 0)
16972 {
16973 /* Short opcode. */
16974 op = (offset - 4) >> 2;
16975 add_unwind_opcode (op, 1);
16976 }
16977 else if (offset < 0)
16978 {
16979 offset = -offset;
16980 while (offset > 0x100)
16981 {
16982 add_unwind_opcode (0x7f, 1);
16983 offset -= 0x100;
16984 }
16985 op = ((offset - 4) >> 2) | 0x40;
16986 add_unwind_opcode (op, 1);
16987 }
16988 }
16989
16990 /* Finish the list of unwind opcodes for this function. */
16991 static void
16992 finish_unwind_opcodes (void)
16993 {
16994 valueT op;
16995
16996 if (unwind.fp_used)
16997 {
16998 /* Adjust sp as necessary. */
16999 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
17000 flush_pending_unwind ();
17001
17002 /* After restoring sp from the frame pointer. */
17003 op = 0x90 | unwind.fp_reg;
17004 add_unwind_opcode (op, 1);
17005 }
17006 else
17007 flush_pending_unwind ();
17008 }
17009
17010
17011 /* Start an exception table entry. If idx is nonzero this is an index table
17012 entry. */
17013
17014 static void
17015 start_unwind_section (const segT text_seg, int idx)
17016 {
17017 const char * text_name;
17018 const char * prefix;
17019 const char * prefix_once;
17020 const char * group_name;
17021 size_t prefix_len;
17022 size_t text_len;
17023 char * sec_name;
17024 size_t sec_name_len;
17025 int type;
17026 int flags;
17027 int linkonce;
17028
17029 if (idx)
17030 {
17031 prefix = ELF_STRING_ARM_unwind;
17032 prefix_once = ELF_STRING_ARM_unwind_once;
17033 type = SHT_ARM_EXIDX;
17034 }
17035 else
17036 {
17037 prefix = ELF_STRING_ARM_unwind_info;
17038 prefix_once = ELF_STRING_ARM_unwind_info_once;
17039 type = SHT_PROGBITS;
17040 }
17041
17042 text_name = segment_name (text_seg);
17043 if (streq (text_name, ".text"))
17044 text_name = "";
17045
17046 if (strncmp (text_name, ".gnu.linkonce.t.",
17047 strlen (".gnu.linkonce.t.")) == 0)
17048 {
17049 prefix = prefix_once;
17050 text_name += strlen (".gnu.linkonce.t.");
17051 }
17052
17053 prefix_len = strlen (prefix);
17054 text_len = strlen (text_name);
17055 sec_name_len = prefix_len + text_len;
17056 sec_name = xmalloc (sec_name_len + 1);
17057 memcpy (sec_name, prefix, prefix_len);
17058 memcpy (sec_name + prefix_len, text_name, text_len);
17059 sec_name[prefix_len + text_len] = '\0';
17060
17061 flags = SHF_ALLOC;
17062 linkonce = 0;
17063 group_name = 0;
17064
17065 /* Handle COMDAT group. */
17066 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
17067 {
17068 group_name = elf_group_name (text_seg);
17069 if (group_name == NULL)
17070 {
17071 as_bad ("Group section `%s' has no group signature",
17072 segment_name (text_seg));
17073 ignore_rest_of_line ();
17074 return;
17075 }
17076 flags |= SHF_GROUP;
17077 linkonce = 1;
17078 }
17079
17080 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
17081
17082 /* Set the setion link for index tables. */
17083 if (idx)
17084 elf_linked_to_section (now_seg) = text_seg;
17085 }
17086
17087
17088 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
17089 personality routine data. Returns zero, or the index table value for
17090 and inline entry. */
17091
17092 static valueT
17093 create_unwind_entry (int have_data)
17094 {
17095 int size;
17096 addressT where;
17097 char *ptr;
17098 /* The current word of data. */
17099 valueT data;
17100 /* The number of bytes left in this word. */
17101 int n;
17102
17103 finish_unwind_opcodes ();
17104
17105 /* Remember the current text section. */
17106 unwind.saved_seg = now_seg;
17107 unwind.saved_subseg = now_subseg;
17108
17109 start_unwind_section (now_seg, 0);
17110
17111 if (unwind.personality_routine == NULL)
17112 {
17113 if (unwind.personality_index == -2)
17114 {
17115 if (have_data)
17116 as_bad (_("handerdata in cantunwind frame"));
17117 return 1; /* EXIDX_CANTUNWIND. */
17118 }
17119
17120 /* Use a default personality routine if none is specified. */
17121 if (unwind.personality_index == -1)
17122 {
17123 if (unwind.opcode_count > 3)
17124 unwind.personality_index = 1;
17125 else
17126 unwind.personality_index = 0;
17127 }
17128
17129 /* Space for the personality routine entry. */
17130 if (unwind.personality_index == 0)
17131 {
17132 if (unwind.opcode_count > 3)
17133 as_bad (_("too many unwind opcodes for personality routine 0"));
17134
17135 if (!have_data)
17136 {
17137 /* All the data is inline in the index table. */
17138 data = 0x80;
17139 n = 3;
17140 while (unwind.opcode_count > 0)
17141 {
17142 unwind.opcode_count--;
17143 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17144 n--;
17145 }
17146
17147 /* Pad with "finish" opcodes. */
17148 while (n--)
17149 data = (data << 8) | 0xb0;
17150
17151 return data;
17152 }
17153 size = 0;
17154 }
17155 else
17156 /* We get two opcodes "free" in the first word. */
17157 size = unwind.opcode_count - 2;
17158 }
17159 else
17160 /* An extra byte is required for the opcode count. */
17161 size = unwind.opcode_count + 1;
17162
17163 size = (size + 3) >> 2;
17164 if (size > 0xff)
17165 as_bad (_("too many unwind opcodes"));
17166
17167 frag_align (2, 0, 0);
17168 record_alignment (now_seg, 2);
17169 unwind.table_entry = expr_build_dot ();
17170
17171 /* Allocate the table entry. */
17172 ptr = frag_more ((size << 2) + 4);
17173 where = frag_now_fix () - ((size << 2) + 4);
17174
17175 switch (unwind.personality_index)
17176 {
17177 case -1:
17178 /* ??? Should this be a PLT generating relocation? */
17179 /* Custom personality routine. */
17180 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
17181 BFD_RELOC_ARM_PREL31);
17182
17183 where += 4;
17184 ptr += 4;
17185
17186 /* Set the first byte to the number of additional words. */
17187 data = size - 1;
17188 n = 3;
17189 break;
17190
17191 /* ABI defined personality routines. */
17192 case 0:
17193 /* Three opcodes bytes are packed into the first word. */
17194 data = 0x80;
17195 n = 3;
17196 break;
17197
17198 case 1:
17199 case 2:
17200 /* The size and first two opcode bytes go in the first word. */
17201 data = ((0x80 + unwind.personality_index) << 8) | size;
17202 n = 2;
17203 break;
17204
17205 default:
17206 /* Should never happen. */
17207 abort ();
17208 }
17209
17210 /* Pack the opcodes into words (MSB first), reversing the list at the same
17211 time. */
17212 while (unwind.opcode_count > 0)
17213 {
17214 if (n == 0)
17215 {
17216 md_number_to_chars (ptr, data, 4);
17217 ptr += 4;
17218 n = 4;
17219 data = 0;
17220 }
17221 unwind.opcode_count--;
17222 n--;
17223 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17224 }
17225
17226 /* Finish off the last word. */
17227 if (n < 4)
17228 {
17229 /* Pad with "finish" opcodes. */
17230 while (n--)
17231 data = (data << 8) | 0xb0;
17232
17233 md_number_to_chars (ptr, data, 4);
17234 }
17235
17236 if (!have_data)
17237 {
17238 /* Add an empty descriptor if there is no user-specified data. */
17239 ptr = frag_more (4);
17240 md_number_to_chars (ptr, 0, 4);
17241 }
17242
17243 return 0;
17244 }
17245
17246
17247 /* Initialize the DWARF-2 unwind information for this procedure. */
17248
17249 void
17250 tc_arm_frame_initial_instructions (void)
17251 {
17252 cfi_add_CFA_def_cfa (REG_SP, 0);
17253 }
17254 #endif /* OBJ_ELF */
17255
17256 /* Convert REGNAME to a DWARF-2 register number. */
17257
17258 int
17259 tc_arm_regname_to_dw2regnum (char *regname)
17260 {
17261 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
17262
17263 if (reg == FAIL)
17264 return -1;
17265
17266 return reg;
17267 }
17268
17269 #ifdef TE_PE
17270 void
17271 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
17272 {
17273 expressionS expr;
17274
17275 expr.X_op = O_secrel;
17276 expr.X_add_symbol = symbol;
17277 expr.X_add_number = 0;
17278 emit_expr (&expr, size);
17279 }
17280 #endif
17281
17282 /* MD interface: Symbol and relocation handling. */
17283
17284 /* Return the address within the segment that a PC-relative fixup is
17285 relative to. For ARM, PC-relative fixups applied to instructions
17286 are generally relative to the location of the fixup plus 8 bytes.
17287 Thumb branches are offset by 4, and Thumb loads relative to PC
17288 require special handling. */
17289
17290 long
17291 md_pcrel_from_section (fixS * fixP, segT seg)
17292 {
17293 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
17294
17295 /* If this is pc-relative and we are going to emit a relocation
17296 then we just want to put out any pipeline compensation that the linker
17297 will need. Otherwise we want to use the calculated base.
17298 For WinCE we skip the bias for externals as well, since this
17299 is how the MS ARM-CE assembler behaves and we want to be compatible. */
17300 if (fixP->fx_pcrel
17301 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
17302 || (arm_force_relocation (fixP)
17303 #ifdef TE_WINCE
17304 && !S_IS_EXTERNAL (fixP->fx_addsy)
17305 #endif
17306 )))
17307 base = 0;
17308
17309 switch (fixP->fx_r_type)
17310 {
17311 /* PC relative addressing on the Thumb is slightly odd as the
17312 bottom two bits of the PC are forced to zero for the
17313 calculation. This happens *after* application of the
17314 pipeline offset. However, Thumb adrl already adjusts for
17315 this, so we need not do it again. */
17316 case BFD_RELOC_ARM_THUMB_ADD:
17317 return base & ~3;
17318
17319 case BFD_RELOC_ARM_THUMB_OFFSET:
17320 case BFD_RELOC_ARM_T32_OFFSET_IMM:
17321 case BFD_RELOC_ARM_T32_ADD_PC12:
17322 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
17323 return (base + 4) & ~3;
17324
17325 /* Thumb branches are simply offset by +4. */
17326 case BFD_RELOC_THUMB_PCREL_BRANCH7:
17327 case BFD_RELOC_THUMB_PCREL_BRANCH9:
17328 case BFD_RELOC_THUMB_PCREL_BRANCH12:
17329 case BFD_RELOC_THUMB_PCREL_BRANCH20:
17330 case BFD_RELOC_THUMB_PCREL_BRANCH23:
17331 case BFD_RELOC_THUMB_PCREL_BRANCH25:
17332 case BFD_RELOC_THUMB_PCREL_BLX:
17333 return base + 4;
17334
17335 /* ARM mode branches are offset by +8. However, the Windows CE
17336 loader expects the relocation not to take this into account. */
17337 case BFD_RELOC_ARM_PCREL_BRANCH:
17338 case BFD_RELOC_ARM_PCREL_CALL:
17339 case BFD_RELOC_ARM_PCREL_JUMP:
17340 case BFD_RELOC_ARM_PCREL_BLX:
17341 case BFD_RELOC_ARM_PLT32:
17342 #ifdef TE_WINCE
17343 /* When handling fixups immediately, because we have already
17344 discovered the value of a symbol, or the address of the frag involved
17345 we must account for the offset by +8, as the OS loader will never see the reloc.
17346 see fixup_segment() in write.c
17347 The S_IS_EXTERNAL test handles the case of global symbols.
17348 Those need the calculated base, not just the pipe compensation the linker will need. */
17349 if (fixP->fx_pcrel
17350 && fixP->fx_addsy != NULL
17351 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
17352 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
17353 return base + 8;
17354 return base;
17355 #else
17356 return base + 8;
17357 #endif
17358
17359 /* ARM mode loads relative to PC are also offset by +8. Unlike
17360 branches, the Windows CE loader *does* expect the relocation
17361 to take this into account. */
17362 case BFD_RELOC_ARM_OFFSET_IMM:
17363 case BFD_RELOC_ARM_OFFSET_IMM8:
17364 case BFD_RELOC_ARM_HWLITERAL:
17365 case BFD_RELOC_ARM_LITERAL:
17366 case BFD_RELOC_ARM_CP_OFF_IMM:
17367 return base + 8;
17368
17369
17370 /* Other PC-relative relocations are un-offset. */
17371 default:
17372 return base;
17373 }
17374 }
17375
17376 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
17377 Otherwise we have no need to default values of symbols. */
17378
17379 symbolS *
17380 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
17381 {
17382 #ifdef OBJ_ELF
17383 if (name[0] == '_' && name[1] == 'G'
17384 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
17385 {
17386 if (!GOT_symbol)
17387 {
17388 if (symbol_find (name))
17389 as_bad ("GOT already in the symbol table");
17390
17391 GOT_symbol = symbol_new (name, undefined_section,
17392 (valueT) 0, & zero_address_frag);
17393 }
17394
17395 return GOT_symbol;
17396 }
17397 #endif
17398
17399 return 0;
17400 }
17401
17402 /* Subroutine of md_apply_fix. Check to see if an immediate can be
17403 computed as two separate immediate values, added together. We
17404 already know that this value cannot be computed by just one ARM
17405 instruction. */
17406
17407 static unsigned int
17408 validate_immediate_twopart (unsigned int val,
17409 unsigned int * highpart)
17410 {
17411 unsigned int a;
17412 unsigned int i;
17413
17414 for (i = 0; i < 32; i += 2)
17415 if (((a = rotate_left (val, i)) & 0xff) != 0)
17416 {
17417 if (a & 0xff00)
17418 {
17419 if (a & ~ 0xffff)
17420 continue;
17421 * highpart = (a >> 8) | ((i + 24) << 7);
17422 }
17423 else if (a & 0xff0000)
17424 {
17425 if (a & 0xff000000)
17426 continue;
17427 * highpart = (a >> 16) | ((i + 16) << 7);
17428 }
17429 else
17430 {
17431 assert (a & 0xff000000);
17432 * highpart = (a >> 24) | ((i + 8) << 7);
17433 }
17434
17435 return (a & 0xff) | (i << 7);
17436 }
17437
17438 return FAIL;
17439 }
17440
17441 static int
17442 validate_offset_imm (unsigned int val, int hwse)
17443 {
17444 if ((hwse && val > 255) || val > 4095)
17445 return FAIL;
17446 return val;
17447 }
17448
17449 /* Subroutine of md_apply_fix. Do those data_ops which can take a
17450 negative immediate constant by altering the instruction. A bit of
17451 a hack really.
17452 MOV <-> MVN
17453 AND <-> BIC
17454 ADC <-> SBC
17455 by inverting the second operand, and
17456 ADD <-> SUB
17457 CMP <-> CMN
17458 by negating the second operand. */
17459
17460 static int
17461 negate_data_op (unsigned long * instruction,
17462 unsigned long value)
17463 {
17464 int op, new_inst;
17465 unsigned long negated, inverted;
17466
17467 negated = encode_arm_immediate (-value);
17468 inverted = encode_arm_immediate (~value);
17469
17470 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
17471 switch (op)
17472 {
17473 /* First negates. */
17474 case OPCODE_SUB: /* ADD <-> SUB */
17475 new_inst = OPCODE_ADD;
17476 value = negated;
17477 break;
17478
17479 case OPCODE_ADD:
17480 new_inst = OPCODE_SUB;
17481 value = negated;
17482 break;
17483
17484 case OPCODE_CMP: /* CMP <-> CMN */
17485 new_inst = OPCODE_CMN;
17486 value = negated;
17487 break;
17488
17489 case OPCODE_CMN:
17490 new_inst = OPCODE_CMP;
17491 value = negated;
17492 break;
17493
17494 /* Now Inverted ops. */
17495 case OPCODE_MOV: /* MOV <-> MVN */
17496 new_inst = OPCODE_MVN;
17497 value = inverted;
17498 break;
17499
17500 case OPCODE_MVN:
17501 new_inst = OPCODE_MOV;
17502 value = inverted;
17503 break;
17504
17505 case OPCODE_AND: /* AND <-> BIC */
17506 new_inst = OPCODE_BIC;
17507 value = inverted;
17508 break;
17509
17510 case OPCODE_BIC:
17511 new_inst = OPCODE_AND;
17512 value = inverted;
17513 break;
17514
17515 case OPCODE_ADC: /* ADC <-> SBC */
17516 new_inst = OPCODE_SBC;
17517 value = inverted;
17518 break;
17519
17520 case OPCODE_SBC:
17521 new_inst = OPCODE_ADC;
17522 value = inverted;
17523 break;
17524
17525 /* We cannot do anything. */
17526 default:
17527 return FAIL;
17528 }
17529
17530 if (value == (unsigned) FAIL)
17531 return FAIL;
17532
17533 *instruction &= OPCODE_MASK;
17534 *instruction |= new_inst << DATA_OP_SHIFT;
17535 return value;
17536 }
17537
17538 /* Like negate_data_op, but for Thumb-2. */
17539
17540 static unsigned int
17541 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
17542 {
17543 int op, new_inst;
17544 int rd;
17545 unsigned int negated, inverted;
17546
17547 negated = encode_thumb32_immediate (-value);
17548 inverted = encode_thumb32_immediate (~value);
17549
17550 rd = (*instruction >> 8) & 0xf;
17551 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
17552 switch (op)
17553 {
17554 /* ADD <-> SUB. Includes CMP <-> CMN. */
17555 case T2_OPCODE_SUB:
17556 new_inst = T2_OPCODE_ADD;
17557 value = negated;
17558 break;
17559
17560 case T2_OPCODE_ADD:
17561 new_inst = T2_OPCODE_SUB;
17562 value = negated;
17563 break;
17564
17565 /* ORR <-> ORN. Includes MOV <-> MVN. */
17566 case T2_OPCODE_ORR:
17567 new_inst = T2_OPCODE_ORN;
17568 value = inverted;
17569 break;
17570
17571 case T2_OPCODE_ORN:
17572 new_inst = T2_OPCODE_ORR;
17573 value = inverted;
17574 break;
17575
17576 /* AND <-> BIC. TST has no inverted equivalent. */
17577 case T2_OPCODE_AND:
17578 new_inst = T2_OPCODE_BIC;
17579 if (rd == 15)
17580 value = FAIL;
17581 else
17582 value = inverted;
17583 break;
17584
17585 case T2_OPCODE_BIC:
17586 new_inst = T2_OPCODE_AND;
17587 value = inverted;
17588 break;
17589
17590 /* ADC <-> SBC */
17591 case T2_OPCODE_ADC:
17592 new_inst = T2_OPCODE_SBC;
17593 value = inverted;
17594 break;
17595
17596 case T2_OPCODE_SBC:
17597 new_inst = T2_OPCODE_ADC;
17598 value = inverted;
17599 break;
17600
17601 /* We cannot do anything. */
17602 default:
17603 return FAIL;
17604 }
17605
17606 if (value == (unsigned int)FAIL)
17607 return FAIL;
17608
17609 *instruction &= T2_OPCODE_MASK;
17610 *instruction |= new_inst << T2_DATA_OP_SHIFT;
17611 return value;
17612 }
17613
17614 /* Read a 32-bit thumb instruction from buf. */
17615 static unsigned long
17616 get_thumb32_insn (char * buf)
17617 {
17618 unsigned long insn;
17619 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
17620 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
17621
17622 return insn;
17623 }
17624
17625
17626 /* We usually want to set the low bit on the address of thumb function
17627 symbols. In particular .word foo - . should have the low bit set.
17628 Generic code tries to fold the difference of two symbols to
17629 a constant. Prevent this and force a relocation when the first symbols
17630 is a thumb function. */
17631 int
17632 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
17633 {
17634 if (op == O_subtract
17635 && l->X_op == O_symbol
17636 && r->X_op == O_symbol
17637 && THUMB_IS_FUNC (l->X_add_symbol))
17638 {
17639 l->X_op = O_subtract;
17640 l->X_op_symbol = r->X_add_symbol;
17641 l->X_add_number -= r->X_add_number;
17642 return 1;
17643 }
17644 /* Process as normal. */
17645 return 0;
17646 }
17647
17648 void
17649 md_apply_fix (fixS * fixP,
17650 valueT * valP,
17651 segT seg)
17652 {
17653 offsetT value = * valP;
17654 offsetT newval;
17655 unsigned int newimm;
17656 unsigned long temp;
17657 int sign;
17658 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
17659
17660 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
17661
17662 /* Note whether this will delete the relocation. */
17663
17664 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
17665 fixP->fx_done = 1;
17666
17667 /* On a 64-bit host, silently truncate 'value' to 32 bits for
17668 consistency with the behavior on 32-bit hosts. Remember value
17669 for emit_reloc. */
17670 value &= 0xffffffff;
17671 value ^= 0x80000000;
17672 value -= 0x80000000;
17673
17674 *valP = value;
17675 fixP->fx_addnumber = value;
17676
17677 /* Same treatment for fixP->fx_offset. */
17678 fixP->fx_offset &= 0xffffffff;
17679 fixP->fx_offset ^= 0x80000000;
17680 fixP->fx_offset -= 0x80000000;
17681
17682 switch (fixP->fx_r_type)
17683 {
17684 case BFD_RELOC_NONE:
17685 /* This will need to go in the object file. */
17686 fixP->fx_done = 0;
17687 break;
17688
17689 case BFD_RELOC_ARM_IMMEDIATE:
17690 /* We claim that this fixup has been processed here,
17691 even if in fact we generate an error because we do
17692 not have a reloc for it, so tc_gen_reloc will reject it. */
17693 fixP->fx_done = 1;
17694
17695 if (fixP->fx_addsy
17696 && ! S_IS_DEFINED (fixP->fx_addsy))
17697 {
17698 as_bad_where (fixP->fx_file, fixP->fx_line,
17699 _("undefined symbol %s used as an immediate value"),
17700 S_GET_NAME (fixP->fx_addsy));
17701 break;
17702 }
17703
17704 newimm = encode_arm_immediate (value);
17705 temp = md_chars_to_number (buf, INSN_SIZE);
17706
17707 /* If the instruction will fail, see if we can fix things up by
17708 changing the opcode. */
17709 if (newimm == (unsigned int) FAIL
17710 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
17711 {
17712 as_bad_where (fixP->fx_file, fixP->fx_line,
17713 _("invalid constant (%lx) after fixup"),
17714 (unsigned long) value);
17715 break;
17716 }
17717
17718 newimm |= (temp & 0xfffff000);
17719 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
17720 break;
17721
17722 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
17723 {
17724 unsigned int highpart = 0;
17725 unsigned int newinsn = 0xe1a00000; /* nop. */
17726
17727 newimm = encode_arm_immediate (value);
17728 temp = md_chars_to_number (buf, INSN_SIZE);
17729
17730 /* If the instruction will fail, see if we can fix things up by
17731 changing the opcode. */
17732 if (newimm == (unsigned int) FAIL
17733 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
17734 {
17735 /* No ? OK - try using two ADD instructions to generate
17736 the value. */
17737 newimm = validate_immediate_twopart (value, & highpart);
17738
17739 /* Yes - then make sure that the second instruction is
17740 also an add. */
17741 if (newimm != (unsigned int) FAIL)
17742 newinsn = temp;
17743 /* Still No ? Try using a negated value. */
17744 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
17745 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
17746 /* Otherwise - give up. */
17747 else
17748 {
17749 as_bad_where (fixP->fx_file, fixP->fx_line,
17750 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
17751 (long) value);
17752 break;
17753 }
17754
17755 /* Replace the first operand in the 2nd instruction (which
17756 is the PC) with the destination register. We have
17757 already added in the PC in the first instruction and we
17758 do not want to do it again. */
17759 newinsn &= ~ 0xf0000;
17760 newinsn |= ((newinsn & 0x0f000) << 4);
17761 }
17762
17763 newimm |= (temp & 0xfffff000);
17764 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
17765
17766 highpart |= (newinsn & 0xfffff000);
17767 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
17768 }
17769 break;
17770
17771 case BFD_RELOC_ARM_OFFSET_IMM:
17772 if (!fixP->fx_done && seg->use_rela_p)
17773 value = 0;
17774
17775 case BFD_RELOC_ARM_LITERAL:
17776 sign = value >= 0;
17777
17778 if (value < 0)
17779 value = - value;
17780
17781 if (validate_offset_imm (value, 0) == FAIL)
17782 {
17783 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
17784 as_bad_where (fixP->fx_file, fixP->fx_line,
17785 _("invalid literal constant: pool needs to be closer"));
17786 else
17787 as_bad_where (fixP->fx_file, fixP->fx_line,
17788 _("bad immediate value for offset (%ld)"),
17789 (long) value);
17790 break;
17791 }
17792
17793 newval = md_chars_to_number (buf, INSN_SIZE);
17794 newval &= 0xff7ff000;
17795 newval |= value | (sign ? INDEX_UP : 0);
17796 md_number_to_chars (buf, newval, INSN_SIZE);
17797 break;
17798
17799 case BFD_RELOC_ARM_OFFSET_IMM8:
17800 case BFD_RELOC_ARM_HWLITERAL:
17801 sign = value >= 0;
17802
17803 if (value < 0)
17804 value = - value;
17805
17806 if (validate_offset_imm (value, 1) == FAIL)
17807 {
17808 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
17809 as_bad_where (fixP->fx_file, fixP->fx_line,
17810 _("invalid literal constant: pool needs to be closer"));
17811 else
17812 as_bad (_("bad immediate value for half-word offset (%ld)"),
17813 (long) value);
17814 break;
17815 }
17816
17817 newval = md_chars_to_number (buf, INSN_SIZE);
17818 newval &= 0xff7ff0f0;
17819 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
17820 md_number_to_chars (buf, newval, INSN_SIZE);
17821 break;
17822
17823 case BFD_RELOC_ARM_T32_OFFSET_U8:
17824 if (value < 0 || value > 1020 || value % 4 != 0)
17825 as_bad_where (fixP->fx_file, fixP->fx_line,
17826 _("bad immediate value for offset (%ld)"), (long) value);
17827 value /= 4;
17828
17829 newval = md_chars_to_number (buf+2, THUMB_SIZE);
17830 newval |= value;
17831 md_number_to_chars (buf+2, newval, THUMB_SIZE);
17832 break;
17833
17834 case BFD_RELOC_ARM_T32_OFFSET_IMM:
17835 /* This is a complicated relocation used for all varieties of Thumb32
17836 load/store instruction with immediate offset:
17837
17838 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
17839 *4, optional writeback(W)
17840 (doubleword load/store)
17841
17842 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
17843 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
17844 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
17845 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
17846 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
17847
17848 Uppercase letters indicate bits that are already encoded at
17849 this point. Lowercase letters are our problem. For the
17850 second block of instructions, the secondary opcode nybble
17851 (bits 8..11) is present, and bit 23 is zero, even if this is
17852 a PC-relative operation. */
17853 newval = md_chars_to_number (buf, THUMB_SIZE);
17854 newval <<= 16;
17855 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
17856
17857 if ((newval & 0xf0000000) == 0xe0000000)
17858 {
17859 /* Doubleword load/store: 8-bit offset, scaled by 4. */
17860 if (value >= 0)
17861 newval |= (1 << 23);
17862 else
17863 value = -value;
17864 if (value % 4 != 0)
17865 {
17866 as_bad_where (fixP->fx_file, fixP->fx_line,
17867 _("offset not a multiple of 4"));
17868 break;
17869 }
17870 value /= 4;
17871 if (value > 0xff)
17872 {
17873 as_bad_where (fixP->fx_file, fixP->fx_line,
17874 _("offset out of range"));
17875 break;
17876 }
17877 newval &= ~0xff;
17878 }
17879 else if ((newval & 0x000f0000) == 0x000f0000)
17880 {
17881 /* PC-relative, 12-bit offset. */
17882 if (value >= 0)
17883 newval |= (1 << 23);
17884 else
17885 value = -value;
17886 if (value > 0xfff)
17887 {
17888 as_bad_where (fixP->fx_file, fixP->fx_line,
17889 _("offset out of range"));
17890 break;
17891 }
17892 newval &= ~0xfff;
17893 }
17894 else if ((newval & 0x00000100) == 0x00000100)
17895 {
17896 /* Writeback: 8-bit, +/- offset. */
17897 if (value >= 0)
17898 newval |= (1 << 9);
17899 else
17900 value = -value;
17901 if (value > 0xff)
17902 {
17903 as_bad_where (fixP->fx_file, fixP->fx_line,
17904 _("offset out of range"));
17905 break;
17906 }
17907 newval &= ~0xff;
17908 }
17909 else if ((newval & 0x00000f00) == 0x00000e00)
17910 {
17911 /* T-instruction: positive 8-bit offset. */
17912 if (value < 0 || value > 0xff)
17913 {
17914 as_bad_where (fixP->fx_file, fixP->fx_line,
17915 _("offset out of range"));
17916 break;
17917 }
17918 newval &= ~0xff;
17919 newval |= value;
17920 }
17921 else
17922 {
17923 /* Positive 12-bit or negative 8-bit offset. */
17924 int limit;
17925 if (value >= 0)
17926 {
17927 newval |= (1 << 23);
17928 limit = 0xfff;
17929 }
17930 else
17931 {
17932 value = -value;
17933 limit = 0xff;
17934 }
17935 if (value > limit)
17936 {
17937 as_bad_where (fixP->fx_file, fixP->fx_line,
17938 _("offset out of range"));
17939 break;
17940 }
17941 newval &= ~limit;
17942 }
17943
17944 newval |= value;
17945 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
17946 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
17947 break;
17948
17949 case BFD_RELOC_ARM_SHIFT_IMM:
17950 newval = md_chars_to_number (buf, INSN_SIZE);
17951 if (((unsigned long) value) > 32
17952 || (value == 32
17953 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
17954 {
17955 as_bad_where (fixP->fx_file, fixP->fx_line,
17956 _("shift expression is too large"));
17957 break;
17958 }
17959
17960 if (value == 0)
17961 /* Shifts of zero must be done as lsl. */
17962 newval &= ~0x60;
17963 else if (value == 32)
17964 value = 0;
17965 newval &= 0xfffff07f;
17966 newval |= (value & 0x1f) << 7;
17967 md_number_to_chars (buf, newval, INSN_SIZE);
17968 break;
17969
17970 case BFD_RELOC_ARM_T32_IMMEDIATE:
17971 case BFD_RELOC_ARM_T32_ADD_IMM:
17972 case BFD_RELOC_ARM_T32_IMM12:
17973 case BFD_RELOC_ARM_T32_ADD_PC12:
17974 /* We claim that this fixup has been processed here,
17975 even if in fact we generate an error because we do
17976 not have a reloc for it, so tc_gen_reloc will reject it. */
17977 fixP->fx_done = 1;
17978
17979 if (fixP->fx_addsy
17980 && ! S_IS_DEFINED (fixP->fx_addsy))
17981 {
17982 as_bad_where (fixP->fx_file, fixP->fx_line,
17983 _("undefined symbol %s used as an immediate value"),
17984 S_GET_NAME (fixP->fx_addsy));
17985 break;
17986 }
17987
17988 newval = md_chars_to_number (buf, THUMB_SIZE);
17989 newval <<= 16;
17990 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
17991
17992 newimm = FAIL;
17993 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
17994 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
17995 {
17996 newimm = encode_thumb32_immediate (value);
17997 if (newimm == (unsigned int) FAIL)
17998 newimm = thumb32_negate_data_op (&newval, value);
17999 }
18000 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
18001 && newimm == (unsigned int) FAIL)
18002 {
18003 /* Turn add/sum into addw/subw. */
18004 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18005 newval = (newval & 0xfeffffff) | 0x02000000;
18006
18007 /* 12 bit immediate for addw/subw. */
18008 if (value < 0)
18009 {
18010 value = -value;
18011 newval ^= 0x00a00000;
18012 }
18013 if (value > 0xfff)
18014 newimm = (unsigned int) FAIL;
18015 else
18016 newimm = value;
18017 }
18018
18019 if (newimm == (unsigned int)FAIL)
18020 {
18021 as_bad_where (fixP->fx_file, fixP->fx_line,
18022 _("invalid constant (%lx) after fixup"),
18023 (unsigned long) value);
18024 break;
18025 }
18026
18027 newval |= (newimm & 0x800) << 15;
18028 newval |= (newimm & 0x700) << 4;
18029 newval |= (newimm & 0x0ff);
18030
18031 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
18032 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
18033 break;
18034
18035 case BFD_RELOC_ARM_SMC:
18036 if (((unsigned long) value) > 0xffff)
18037 as_bad_where (fixP->fx_file, fixP->fx_line,
18038 _("invalid smc expression"));
18039 newval = md_chars_to_number (buf, INSN_SIZE);
18040 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
18041 md_number_to_chars (buf, newval, INSN_SIZE);
18042 break;
18043
18044 case BFD_RELOC_ARM_SWI:
18045 if (fixP->tc_fix_data != 0)
18046 {
18047 if (((unsigned long) value) > 0xff)
18048 as_bad_where (fixP->fx_file, fixP->fx_line,
18049 _("invalid swi expression"));
18050 newval = md_chars_to_number (buf, THUMB_SIZE);
18051 newval |= value;
18052 md_number_to_chars (buf, newval, THUMB_SIZE);
18053 }
18054 else
18055 {
18056 if (((unsigned long) value) > 0x00ffffff)
18057 as_bad_where (fixP->fx_file, fixP->fx_line,
18058 _("invalid swi expression"));
18059 newval = md_chars_to_number (buf, INSN_SIZE);
18060 newval |= value;
18061 md_number_to_chars (buf, newval, INSN_SIZE);
18062 }
18063 break;
18064
18065 case BFD_RELOC_ARM_MULTI:
18066 if (((unsigned long) value) > 0xffff)
18067 as_bad_where (fixP->fx_file, fixP->fx_line,
18068 _("invalid expression in load/store multiple"));
18069 newval = value | md_chars_to_number (buf, INSN_SIZE);
18070 md_number_to_chars (buf, newval, INSN_SIZE);
18071 break;
18072
18073 #ifdef OBJ_ELF
18074 case BFD_RELOC_ARM_PCREL_CALL:
18075 newval = md_chars_to_number (buf, INSN_SIZE);
18076 if ((newval & 0xf0000000) == 0xf0000000)
18077 temp = 1;
18078 else
18079 temp = 3;
18080 goto arm_branch_common;
18081
18082 case BFD_RELOC_ARM_PCREL_JUMP:
18083 case BFD_RELOC_ARM_PLT32:
18084 #endif
18085 case BFD_RELOC_ARM_PCREL_BRANCH:
18086 temp = 3;
18087 goto arm_branch_common;
18088
18089 case BFD_RELOC_ARM_PCREL_BLX:
18090 temp = 1;
18091 arm_branch_common:
18092 /* We are going to store value (shifted right by two) in the
18093 instruction, in a 24 bit, signed field. Bits 26 through 32 either
18094 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
18095 also be be clear. */
18096 if (value & temp)
18097 as_bad_where (fixP->fx_file, fixP->fx_line,
18098 _("misaligned branch destination"));
18099 if ((value & (offsetT)0xfe000000) != (offsetT)0
18100 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
18101 as_bad_where (fixP->fx_file, fixP->fx_line,
18102 _("branch out of range"));
18103
18104 if (fixP->fx_done || !seg->use_rela_p)
18105 {
18106 newval = md_chars_to_number (buf, INSN_SIZE);
18107 newval |= (value >> 2) & 0x00ffffff;
18108 /* Set the H bit on BLX instructions. */
18109 if (temp == 1)
18110 {
18111 if (value & 2)
18112 newval |= 0x01000000;
18113 else
18114 newval &= ~0x01000000;
18115 }
18116 md_number_to_chars (buf, newval, INSN_SIZE);
18117 }
18118 break;
18119
18120 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
18121 /* CBZ can only branch forward. */
18122
18123 /* Attempts to use CBZ to branch to the next instruction
18124 (which, strictly speaking, are prohibited) will be turned into
18125 no-ops.
18126
18127 FIXME: It may be better to remove the instruction completely and
18128 perform relaxation. */
18129 if (value == -2)
18130 {
18131 newval = md_chars_to_number (buf, THUMB_SIZE);
18132 newval = 0xbf00; /* NOP encoding T1 */
18133 md_number_to_chars (buf, newval, THUMB_SIZE);
18134 }
18135 else
18136 {
18137 if (value & ~0x7e)
18138 as_bad_where (fixP->fx_file, fixP->fx_line,
18139 _("branch out of range"));
18140
18141 if (fixP->fx_done || !seg->use_rela_p)
18142 {
18143 newval = md_chars_to_number (buf, THUMB_SIZE);
18144 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
18145 md_number_to_chars (buf, newval, THUMB_SIZE);
18146 }
18147 }
18148 break;
18149
18150 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
18151 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
18152 as_bad_where (fixP->fx_file, fixP->fx_line,
18153 _("branch out of range"));
18154
18155 if (fixP->fx_done || !seg->use_rela_p)
18156 {
18157 newval = md_chars_to_number (buf, THUMB_SIZE);
18158 newval |= (value & 0x1ff) >> 1;
18159 md_number_to_chars (buf, newval, THUMB_SIZE);
18160 }
18161 break;
18162
18163 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
18164 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
18165 as_bad_where (fixP->fx_file, fixP->fx_line,
18166 _("branch out of range"));
18167
18168 if (fixP->fx_done || !seg->use_rela_p)
18169 {
18170 newval = md_chars_to_number (buf, THUMB_SIZE);
18171 newval |= (value & 0xfff) >> 1;
18172 md_number_to_chars (buf, newval, THUMB_SIZE);
18173 }
18174 break;
18175
18176 case BFD_RELOC_THUMB_PCREL_BRANCH20:
18177 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
18178 as_bad_where (fixP->fx_file, fixP->fx_line,
18179 _("conditional branch out of range"));
18180
18181 if (fixP->fx_done || !seg->use_rela_p)
18182 {
18183 offsetT newval2;
18184 addressT S, J1, J2, lo, hi;
18185
18186 S = (value & 0x00100000) >> 20;
18187 J2 = (value & 0x00080000) >> 19;
18188 J1 = (value & 0x00040000) >> 18;
18189 hi = (value & 0x0003f000) >> 12;
18190 lo = (value & 0x00000ffe) >> 1;
18191
18192 newval = md_chars_to_number (buf, THUMB_SIZE);
18193 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18194 newval |= (S << 10) | hi;
18195 newval2 |= (J1 << 13) | (J2 << 11) | lo;
18196 md_number_to_chars (buf, newval, THUMB_SIZE);
18197 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18198 }
18199 break;
18200
18201 case BFD_RELOC_THUMB_PCREL_BLX:
18202 case BFD_RELOC_THUMB_PCREL_BRANCH23:
18203 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
18204 as_bad_where (fixP->fx_file, fixP->fx_line,
18205 _("branch out of range"));
18206
18207 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
18208 /* For a BLX instruction, make sure that the relocation is rounded up
18209 to a word boundary. This follows the semantics of the instruction
18210 which specifies that bit 1 of the target address will come from bit
18211 1 of the base address. */
18212 value = (value + 1) & ~ 1;
18213
18214 if (fixP->fx_done || !seg->use_rela_p)
18215 {
18216 offsetT newval2;
18217
18218 newval = md_chars_to_number (buf, THUMB_SIZE);
18219 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18220 newval |= (value & 0x7fffff) >> 12;
18221 newval2 |= (value & 0xfff) >> 1;
18222 md_number_to_chars (buf, newval, THUMB_SIZE);
18223 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18224 }
18225 break;
18226
18227 case BFD_RELOC_THUMB_PCREL_BRANCH25:
18228 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
18229 as_bad_where (fixP->fx_file, fixP->fx_line,
18230 _("branch out of range"));
18231
18232 if (fixP->fx_done || !seg->use_rela_p)
18233 {
18234 offsetT newval2;
18235 addressT S, I1, I2, lo, hi;
18236
18237 S = (value & 0x01000000) >> 24;
18238 I1 = (value & 0x00800000) >> 23;
18239 I2 = (value & 0x00400000) >> 22;
18240 hi = (value & 0x003ff000) >> 12;
18241 lo = (value & 0x00000ffe) >> 1;
18242
18243 I1 = !(I1 ^ S);
18244 I2 = !(I2 ^ S);
18245
18246 newval = md_chars_to_number (buf, THUMB_SIZE);
18247 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18248 newval |= (S << 10) | hi;
18249 newval2 |= (I1 << 13) | (I2 << 11) | lo;
18250 md_number_to_chars (buf, newval, THUMB_SIZE);
18251 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18252 }
18253 break;
18254
18255 case BFD_RELOC_8:
18256 if (fixP->fx_done || !seg->use_rela_p)
18257 md_number_to_chars (buf, value, 1);
18258 break;
18259
18260 case BFD_RELOC_16:
18261 if (fixP->fx_done || !seg->use_rela_p)
18262 md_number_to_chars (buf, value, 2);
18263 break;
18264
18265 #ifdef OBJ_ELF
18266 case BFD_RELOC_ARM_TLS_GD32:
18267 case BFD_RELOC_ARM_TLS_LE32:
18268 case BFD_RELOC_ARM_TLS_IE32:
18269 case BFD_RELOC_ARM_TLS_LDM32:
18270 case BFD_RELOC_ARM_TLS_LDO32:
18271 S_SET_THREAD_LOCAL (fixP->fx_addsy);
18272 /* fall through */
18273
18274 case BFD_RELOC_ARM_GOT32:
18275 case BFD_RELOC_ARM_GOTOFF:
18276 case BFD_RELOC_ARM_TARGET2:
18277 if (fixP->fx_done || !seg->use_rela_p)
18278 md_number_to_chars (buf, 0, 4);
18279 break;
18280 #endif
18281
18282 case BFD_RELOC_RVA:
18283 case BFD_RELOC_32:
18284 case BFD_RELOC_ARM_TARGET1:
18285 case BFD_RELOC_ARM_ROSEGREL32:
18286 case BFD_RELOC_ARM_SBREL32:
18287 case BFD_RELOC_32_PCREL:
18288 #ifdef TE_PE
18289 case BFD_RELOC_32_SECREL:
18290 #endif
18291 if (fixP->fx_done || !seg->use_rela_p)
18292 #ifdef TE_WINCE
18293 /* For WinCE we only do this for pcrel fixups. */
18294 if (fixP->fx_done || fixP->fx_pcrel)
18295 #endif
18296 md_number_to_chars (buf, value, 4);
18297 break;
18298
18299 #ifdef OBJ_ELF
18300 case BFD_RELOC_ARM_PREL31:
18301 if (fixP->fx_done || !seg->use_rela_p)
18302 {
18303 newval = md_chars_to_number (buf, 4) & 0x80000000;
18304 if ((value ^ (value >> 1)) & 0x40000000)
18305 {
18306 as_bad_where (fixP->fx_file, fixP->fx_line,
18307 _("rel31 relocation overflow"));
18308 }
18309 newval |= value & 0x7fffffff;
18310 md_number_to_chars (buf, newval, 4);
18311 }
18312 break;
18313 #endif
18314
18315 case BFD_RELOC_ARM_CP_OFF_IMM:
18316 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
18317 if (value < -1023 || value > 1023 || (value & 3))
18318 as_bad_where (fixP->fx_file, fixP->fx_line,
18319 _("co-processor offset out of range"));
18320 cp_off_common:
18321 sign = value >= 0;
18322 if (value < 0)
18323 value = -value;
18324 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18325 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18326 newval = md_chars_to_number (buf, INSN_SIZE);
18327 else
18328 newval = get_thumb32_insn (buf);
18329 newval &= 0xff7fff00;
18330 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
18331 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18332 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18333 md_number_to_chars (buf, newval, INSN_SIZE);
18334 else
18335 put_thumb32_insn (buf, newval);
18336 break;
18337
18338 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
18339 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
18340 if (value < -255 || value > 255)
18341 as_bad_where (fixP->fx_file, fixP->fx_line,
18342 _("co-processor offset out of range"));
18343 value *= 4;
18344 goto cp_off_common;
18345
18346 case BFD_RELOC_ARM_THUMB_OFFSET:
18347 newval = md_chars_to_number (buf, THUMB_SIZE);
18348 /* Exactly what ranges, and where the offset is inserted depends
18349 on the type of instruction, we can establish this from the
18350 top 4 bits. */
18351 switch (newval >> 12)
18352 {
18353 case 4: /* PC load. */
18354 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
18355 forced to zero for these loads; md_pcrel_from has already
18356 compensated for this. */
18357 if (value & 3)
18358 as_bad_where (fixP->fx_file, fixP->fx_line,
18359 _("invalid offset, target not word aligned (0x%08lX)"),
18360 (((unsigned long) fixP->fx_frag->fr_address
18361 + (unsigned long) fixP->fx_where) & ~3)
18362 + (unsigned long) value);
18363
18364 if (value & ~0x3fc)
18365 as_bad_where (fixP->fx_file, fixP->fx_line,
18366 _("invalid offset, value too big (0x%08lX)"),
18367 (long) value);
18368
18369 newval |= value >> 2;
18370 break;
18371
18372 case 9: /* SP load/store. */
18373 if (value & ~0x3fc)
18374 as_bad_where (fixP->fx_file, fixP->fx_line,
18375 _("invalid offset, value too big (0x%08lX)"),
18376 (long) value);
18377 newval |= value >> 2;
18378 break;
18379
18380 case 6: /* Word load/store. */
18381 if (value & ~0x7c)
18382 as_bad_where (fixP->fx_file, fixP->fx_line,
18383 _("invalid offset, value too big (0x%08lX)"),
18384 (long) value);
18385 newval |= value << 4; /* 6 - 2. */
18386 break;
18387
18388 case 7: /* Byte load/store. */
18389 if (value & ~0x1f)
18390 as_bad_where (fixP->fx_file, fixP->fx_line,
18391 _("invalid offset, value too big (0x%08lX)"),
18392 (long) value);
18393 newval |= value << 6;
18394 break;
18395
18396 case 8: /* Halfword load/store. */
18397 if (value & ~0x3e)
18398 as_bad_where (fixP->fx_file, fixP->fx_line,
18399 _("invalid offset, value too big (0x%08lX)"),
18400 (long) value);
18401 newval |= value << 5; /* 6 - 1. */
18402 break;
18403
18404 default:
18405 as_bad_where (fixP->fx_file, fixP->fx_line,
18406 "Unable to process relocation for thumb opcode: %lx",
18407 (unsigned long) newval);
18408 break;
18409 }
18410 md_number_to_chars (buf, newval, THUMB_SIZE);
18411 break;
18412
18413 case BFD_RELOC_ARM_THUMB_ADD:
18414 /* This is a complicated relocation, since we use it for all of
18415 the following immediate relocations:
18416
18417 3bit ADD/SUB
18418 8bit ADD/SUB
18419 9bit ADD/SUB SP word-aligned
18420 10bit ADD PC/SP word-aligned
18421
18422 The type of instruction being processed is encoded in the
18423 instruction field:
18424
18425 0x8000 SUB
18426 0x00F0 Rd
18427 0x000F Rs
18428 */
18429 newval = md_chars_to_number (buf, THUMB_SIZE);
18430 {
18431 int rd = (newval >> 4) & 0xf;
18432 int rs = newval & 0xf;
18433 int subtract = !!(newval & 0x8000);
18434
18435 /* Check for HI regs, only very restricted cases allowed:
18436 Adjusting SP, and using PC or SP to get an address. */
18437 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
18438 || (rs > 7 && rs != REG_SP && rs != REG_PC))
18439 as_bad_where (fixP->fx_file, fixP->fx_line,
18440 _("invalid Hi register with immediate"));
18441
18442 /* If value is negative, choose the opposite instruction. */
18443 if (value < 0)
18444 {
18445 value = -value;
18446 subtract = !subtract;
18447 if (value < 0)
18448 as_bad_where (fixP->fx_file, fixP->fx_line,
18449 _("immediate value out of range"));
18450 }
18451
18452 if (rd == REG_SP)
18453 {
18454 if (value & ~0x1fc)
18455 as_bad_where (fixP->fx_file, fixP->fx_line,
18456 _("invalid immediate for stack address calculation"));
18457 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
18458 newval |= value >> 2;
18459 }
18460 else if (rs == REG_PC || rs == REG_SP)
18461 {
18462 if (subtract || value & ~0x3fc)
18463 as_bad_where (fixP->fx_file, fixP->fx_line,
18464 _("invalid immediate for address calculation (value = 0x%08lX)"),
18465 (unsigned long) value);
18466 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
18467 newval |= rd << 8;
18468 newval |= value >> 2;
18469 }
18470 else if (rs == rd)
18471 {
18472 if (value & ~0xff)
18473 as_bad_where (fixP->fx_file, fixP->fx_line,
18474 _("immediate value out of range"));
18475 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
18476 newval |= (rd << 8) | value;
18477 }
18478 else
18479 {
18480 if (value & ~0x7)
18481 as_bad_where (fixP->fx_file, fixP->fx_line,
18482 _("immediate value out of range"));
18483 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
18484 newval |= rd | (rs << 3) | (value << 6);
18485 }
18486 }
18487 md_number_to_chars (buf, newval, THUMB_SIZE);
18488 break;
18489
18490 case BFD_RELOC_ARM_THUMB_IMM:
18491 newval = md_chars_to_number (buf, THUMB_SIZE);
18492 if (value < 0 || value > 255)
18493 as_bad_where (fixP->fx_file, fixP->fx_line,
18494 _("invalid immediate: %ld is too large"),
18495 (long) value);
18496 newval |= value;
18497 md_number_to_chars (buf, newval, THUMB_SIZE);
18498 break;
18499
18500 case BFD_RELOC_ARM_THUMB_SHIFT:
18501 /* 5bit shift value (0..32). LSL cannot take 32. */
18502 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
18503 temp = newval & 0xf800;
18504 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
18505 as_bad_where (fixP->fx_file, fixP->fx_line,
18506 _("invalid shift value: %ld"), (long) value);
18507 /* Shifts of zero must be encoded as LSL. */
18508 if (value == 0)
18509 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
18510 /* Shifts of 32 are encoded as zero. */
18511 else if (value == 32)
18512 value = 0;
18513 newval |= value << 6;
18514 md_number_to_chars (buf, newval, THUMB_SIZE);
18515 break;
18516
18517 case BFD_RELOC_VTABLE_INHERIT:
18518 case BFD_RELOC_VTABLE_ENTRY:
18519 fixP->fx_done = 0;
18520 return;
18521
18522 case BFD_RELOC_ARM_MOVW:
18523 case BFD_RELOC_ARM_MOVT:
18524 case BFD_RELOC_ARM_THUMB_MOVW:
18525 case BFD_RELOC_ARM_THUMB_MOVT:
18526 if (fixP->fx_done || !seg->use_rela_p)
18527 {
18528 /* REL format relocations are limited to a 16-bit addend. */
18529 if (!fixP->fx_done)
18530 {
18531 if (value < -0x1000 || value > 0xffff)
18532 as_bad_where (fixP->fx_file, fixP->fx_line,
18533 _("offset too big"));
18534 }
18535 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
18536 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18537 {
18538 value >>= 16;
18539 }
18540
18541 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
18542 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18543 {
18544 newval = get_thumb32_insn (buf);
18545 newval &= 0xfbf08f00;
18546 newval |= (value & 0xf000) << 4;
18547 newval |= (value & 0x0800) << 15;
18548 newval |= (value & 0x0700) << 4;
18549 newval |= (value & 0x00ff);
18550 put_thumb32_insn (buf, newval);
18551 }
18552 else
18553 {
18554 newval = md_chars_to_number (buf, 4);
18555 newval &= 0xfff0f000;
18556 newval |= value & 0x0fff;
18557 newval |= (value & 0xf000) << 4;
18558 md_number_to_chars (buf, newval, 4);
18559 }
18560 }
18561 return;
18562
18563 case BFD_RELOC_ARM_ALU_PC_G0_NC:
18564 case BFD_RELOC_ARM_ALU_PC_G0:
18565 case BFD_RELOC_ARM_ALU_PC_G1_NC:
18566 case BFD_RELOC_ARM_ALU_PC_G1:
18567 case BFD_RELOC_ARM_ALU_PC_G2:
18568 case BFD_RELOC_ARM_ALU_SB_G0_NC:
18569 case BFD_RELOC_ARM_ALU_SB_G0:
18570 case BFD_RELOC_ARM_ALU_SB_G1_NC:
18571 case BFD_RELOC_ARM_ALU_SB_G1:
18572 case BFD_RELOC_ARM_ALU_SB_G2:
18573 assert (!fixP->fx_done);
18574 if (!seg->use_rela_p)
18575 {
18576 bfd_vma insn;
18577 bfd_vma encoded_addend;
18578 bfd_vma addend_abs = abs (value);
18579
18580 /* Check that the absolute value of the addend can be
18581 expressed as an 8-bit constant plus a rotation. */
18582 encoded_addend = encode_arm_immediate (addend_abs);
18583 if (encoded_addend == (unsigned int) FAIL)
18584 as_bad_where (fixP->fx_file, fixP->fx_line,
18585 _("the offset 0x%08lX is not representable"),
18586 addend_abs);
18587
18588 /* Extract the instruction. */
18589 insn = md_chars_to_number (buf, INSN_SIZE);
18590
18591 /* If the addend is positive, use an ADD instruction.
18592 Otherwise use a SUB. Take care not to destroy the S bit. */
18593 insn &= 0xff1fffff;
18594 if (value < 0)
18595 insn |= 1 << 22;
18596 else
18597 insn |= 1 << 23;
18598
18599 /* Place the encoded addend into the first 12 bits of the
18600 instruction. */
18601 insn &= 0xfffff000;
18602 insn |= encoded_addend;
18603
18604 /* Update the instruction. */
18605 md_number_to_chars (buf, insn, INSN_SIZE);
18606 }
18607 break;
18608
18609 case BFD_RELOC_ARM_LDR_PC_G0:
18610 case BFD_RELOC_ARM_LDR_PC_G1:
18611 case BFD_RELOC_ARM_LDR_PC_G2:
18612 case BFD_RELOC_ARM_LDR_SB_G0:
18613 case BFD_RELOC_ARM_LDR_SB_G1:
18614 case BFD_RELOC_ARM_LDR_SB_G2:
18615 assert (!fixP->fx_done);
18616 if (!seg->use_rela_p)
18617 {
18618 bfd_vma insn;
18619 bfd_vma addend_abs = abs (value);
18620
18621 /* Check that the absolute value of the addend can be
18622 encoded in 12 bits. */
18623 if (addend_abs >= 0x1000)
18624 as_bad_where (fixP->fx_file, fixP->fx_line,
18625 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
18626 addend_abs);
18627
18628 /* Extract the instruction. */
18629 insn = md_chars_to_number (buf, INSN_SIZE);
18630
18631 /* If the addend is negative, clear bit 23 of the instruction.
18632 Otherwise set it. */
18633 if (value < 0)
18634 insn &= ~(1 << 23);
18635 else
18636 insn |= 1 << 23;
18637
18638 /* Place the absolute value of the addend into the first 12 bits
18639 of the instruction. */
18640 insn &= 0xfffff000;
18641 insn |= addend_abs;
18642
18643 /* Update the instruction. */
18644 md_number_to_chars (buf, insn, INSN_SIZE);
18645 }
18646 break;
18647
18648 case BFD_RELOC_ARM_LDRS_PC_G0:
18649 case BFD_RELOC_ARM_LDRS_PC_G1:
18650 case BFD_RELOC_ARM_LDRS_PC_G2:
18651 case BFD_RELOC_ARM_LDRS_SB_G0:
18652 case BFD_RELOC_ARM_LDRS_SB_G1:
18653 case BFD_RELOC_ARM_LDRS_SB_G2:
18654 assert (!fixP->fx_done);
18655 if (!seg->use_rela_p)
18656 {
18657 bfd_vma insn;
18658 bfd_vma addend_abs = abs (value);
18659
18660 /* Check that the absolute value of the addend can be
18661 encoded in 8 bits. */
18662 if (addend_abs >= 0x100)
18663 as_bad_where (fixP->fx_file, fixP->fx_line,
18664 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
18665 addend_abs);
18666
18667 /* Extract the instruction. */
18668 insn = md_chars_to_number (buf, INSN_SIZE);
18669
18670 /* If the addend is negative, clear bit 23 of the instruction.
18671 Otherwise set it. */
18672 if (value < 0)
18673 insn &= ~(1 << 23);
18674 else
18675 insn |= 1 << 23;
18676
18677 /* Place the first four bits of the absolute value of the addend
18678 into the first 4 bits of the instruction, and the remaining
18679 four into bits 8 .. 11. */
18680 insn &= 0xfffff0f0;
18681 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
18682
18683 /* Update the instruction. */
18684 md_number_to_chars (buf, insn, INSN_SIZE);
18685 }
18686 break;
18687
18688 case BFD_RELOC_ARM_LDC_PC_G0:
18689 case BFD_RELOC_ARM_LDC_PC_G1:
18690 case BFD_RELOC_ARM_LDC_PC_G2:
18691 case BFD_RELOC_ARM_LDC_SB_G0:
18692 case BFD_RELOC_ARM_LDC_SB_G1:
18693 case BFD_RELOC_ARM_LDC_SB_G2:
18694 assert (!fixP->fx_done);
18695 if (!seg->use_rela_p)
18696 {
18697 bfd_vma insn;
18698 bfd_vma addend_abs = abs (value);
18699
18700 /* Check that the absolute value of the addend is a multiple of
18701 four and, when divided by four, fits in 8 bits. */
18702 if (addend_abs & 0x3)
18703 as_bad_where (fixP->fx_file, fixP->fx_line,
18704 _("bad offset 0x%08lX (must be word-aligned)"),
18705 addend_abs);
18706
18707 if ((addend_abs >> 2) > 0xff)
18708 as_bad_where (fixP->fx_file, fixP->fx_line,
18709 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
18710 addend_abs);
18711
18712 /* Extract the instruction. */
18713 insn = md_chars_to_number (buf, INSN_SIZE);
18714
18715 /* If the addend is negative, clear bit 23 of the instruction.
18716 Otherwise set it. */
18717 if (value < 0)
18718 insn &= ~(1 << 23);
18719 else
18720 insn |= 1 << 23;
18721
18722 /* Place the addend (divided by four) into the first eight
18723 bits of the instruction. */
18724 insn &= 0xfffffff0;
18725 insn |= addend_abs >> 2;
18726
18727 /* Update the instruction. */
18728 md_number_to_chars (buf, insn, INSN_SIZE);
18729 }
18730 break;
18731
18732 case BFD_RELOC_UNUSED:
18733 default:
18734 as_bad_where (fixP->fx_file, fixP->fx_line,
18735 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
18736 }
18737 }
18738
18739 /* Translate internal representation of relocation info to BFD target
18740 format. */
18741
18742 arelent *
18743 tc_gen_reloc (asection *section, fixS *fixp)
18744 {
18745 arelent * reloc;
18746 bfd_reloc_code_real_type code;
18747
18748 reloc = xmalloc (sizeof (arelent));
18749
18750 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
18751 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
18752 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
18753
18754 if (fixp->fx_pcrel)
18755 {
18756 if (section->use_rela_p)
18757 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
18758 else
18759 fixp->fx_offset = reloc->address;
18760 }
18761 reloc->addend = fixp->fx_offset;
18762
18763 switch (fixp->fx_r_type)
18764 {
18765 case BFD_RELOC_8:
18766 if (fixp->fx_pcrel)
18767 {
18768 code = BFD_RELOC_8_PCREL;
18769 break;
18770 }
18771
18772 case BFD_RELOC_16:
18773 if (fixp->fx_pcrel)
18774 {
18775 code = BFD_RELOC_16_PCREL;
18776 break;
18777 }
18778
18779 case BFD_RELOC_32:
18780 if (fixp->fx_pcrel)
18781 {
18782 code = BFD_RELOC_32_PCREL;
18783 break;
18784 }
18785
18786 case BFD_RELOC_ARM_MOVW:
18787 if (fixp->fx_pcrel)
18788 {
18789 code = BFD_RELOC_ARM_MOVW_PCREL;
18790 break;
18791 }
18792
18793 case BFD_RELOC_ARM_MOVT:
18794 if (fixp->fx_pcrel)
18795 {
18796 code = BFD_RELOC_ARM_MOVT_PCREL;
18797 break;
18798 }
18799
18800 case BFD_RELOC_ARM_THUMB_MOVW:
18801 if (fixp->fx_pcrel)
18802 {
18803 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
18804 break;
18805 }
18806
18807 case BFD_RELOC_ARM_THUMB_MOVT:
18808 if (fixp->fx_pcrel)
18809 {
18810 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
18811 break;
18812 }
18813
18814 case BFD_RELOC_NONE:
18815 case BFD_RELOC_ARM_PCREL_BRANCH:
18816 case BFD_RELOC_ARM_PCREL_BLX:
18817 case BFD_RELOC_RVA:
18818 case BFD_RELOC_THUMB_PCREL_BRANCH7:
18819 case BFD_RELOC_THUMB_PCREL_BRANCH9:
18820 case BFD_RELOC_THUMB_PCREL_BRANCH12:
18821 case BFD_RELOC_THUMB_PCREL_BRANCH20:
18822 case BFD_RELOC_THUMB_PCREL_BRANCH23:
18823 case BFD_RELOC_THUMB_PCREL_BRANCH25:
18824 case BFD_RELOC_THUMB_PCREL_BLX:
18825 case BFD_RELOC_VTABLE_ENTRY:
18826 case BFD_RELOC_VTABLE_INHERIT:
18827 #ifdef TE_PE
18828 case BFD_RELOC_32_SECREL:
18829 #endif
18830 code = fixp->fx_r_type;
18831 break;
18832
18833 case BFD_RELOC_ARM_LITERAL:
18834 case BFD_RELOC_ARM_HWLITERAL:
18835 /* If this is called then the a literal has
18836 been referenced across a section boundary. */
18837 as_bad_where (fixp->fx_file, fixp->fx_line,
18838 _("literal referenced across section boundary"));
18839 return NULL;
18840
18841 #ifdef OBJ_ELF
18842 case BFD_RELOC_ARM_GOT32:
18843 case BFD_RELOC_ARM_GOTOFF:
18844 case BFD_RELOC_ARM_PLT32:
18845 case BFD_RELOC_ARM_TARGET1:
18846 case BFD_RELOC_ARM_ROSEGREL32:
18847 case BFD_RELOC_ARM_SBREL32:
18848 case BFD_RELOC_ARM_PREL31:
18849 case BFD_RELOC_ARM_TARGET2:
18850 case BFD_RELOC_ARM_TLS_LE32:
18851 case BFD_RELOC_ARM_TLS_LDO32:
18852 case BFD_RELOC_ARM_PCREL_CALL:
18853 case BFD_RELOC_ARM_PCREL_JUMP:
18854 case BFD_RELOC_ARM_ALU_PC_G0_NC:
18855 case BFD_RELOC_ARM_ALU_PC_G0:
18856 case BFD_RELOC_ARM_ALU_PC_G1_NC:
18857 case BFD_RELOC_ARM_ALU_PC_G1:
18858 case BFD_RELOC_ARM_ALU_PC_G2:
18859 case BFD_RELOC_ARM_LDR_PC_G0:
18860 case BFD_RELOC_ARM_LDR_PC_G1:
18861 case BFD_RELOC_ARM_LDR_PC_G2:
18862 case BFD_RELOC_ARM_LDRS_PC_G0:
18863 case BFD_RELOC_ARM_LDRS_PC_G1:
18864 case BFD_RELOC_ARM_LDRS_PC_G2:
18865 case BFD_RELOC_ARM_LDC_PC_G0:
18866 case BFD_RELOC_ARM_LDC_PC_G1:
18867 case BFD_RELOC_ARM_LDC_PC_G2:
18868 case BFD_RELOC_ARM_ALU_SB_G0_NC:
18869 case BFD_RELOC_ARM_ALU_SB_G0:
18870 case BFD_RELOC_ARM_ALU_SB_G1_NC:
18871 case BFD_RELOC_ARM_ALU_SB_G1:
18872 case BFD_RELOC_ARM_ALU_SB_G2:
18873 case BFD_RELOC_ARM_LDR_SB_G0:
18874 case BFD_RELOC_ARM_LDR_SB_G1:
18875 case BFD_RELOC_ARM_LDR_SB_G2:
18876 case BFD_RELOC_ARM_LDRS_SB_G0:
18877 case BFD_RELOC_ARM_LDRS_SB_G1:
18878 case BFD_RELOC_ARM_LDRS_SB_G2:
18879 case BFD_RELOC_ARM_LDC_SB_G0:
18880 case BFD_RELOC_ARM_LDC_SB_G1:
18881 case BFD_RELOC_ARM_LDC_SB_G2:
18882 code = fixp->fx_r_type;
18883 break;
18884
18885 case BFD_RELOC_ARM_TLS_GD32:
18886 case BFD_RELOC_ARM_TLS_IE32:
18887 case BFD_RELOC_ARM_TLS_LDM32:
18888 /* BFD will include the symbol's address in the addend.
18889 But we don't want that, so subtract it out again here. */
18890 if (!S_IS_COMMON (fixp->fx_addsy))
18891 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
18892 code = fixp->fx_r_type;
18893 break;
18894 #endif
18895
18896 case BFD_RELOC_ARM_IMMEDIATE:
18897 as_bad_where (fixp->fx_file, fixp->fx_line,
18898 _("internal relocation (type: IMMEDIATE) not fixed up"));
18899 return NULL;
18900
18901 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
18902 as_bad_where (fixp->fx_file, fixp->fx_line,
18903 _("ADRL used for a symbol not defined in the same file"));
18904 return NULL;
18905
18906 case BFD_RELOC_ARM_OFFSET_IMM:
18907 if (section->use_rela_p)
18908 {
18909 code = fixp->fx_r_type;
18910 break;
18911 }
18912
18913 if (fixp->fx_addsy != NULL
18914 && !S_IS_DEFINED (fixp->fx_addsy)
18915 && S_IS_LOCAL (fixp->fx_addsy))
18916 {
18917 as_bad_where (fixp->fx_file, fixp->fx_line,
18918 _("undefined local label `%s'"),
18919 S_GET_NAME (fixp->fx_addsy));
18920 return NULL;
18921 }
18922
18923 as_bad_where (fixp->fx_file, fixp->fx_line,
18924 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
18925 return NULL;
18926
18927 default:
18928 {
18929 char * type;
18930
18931 switch (fixp->fx_r_type)
18932 {
18933 case BFD_RELOC_NONE: type = "NONE"; break;
18934 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
18935 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
18936 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
18937 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
18938 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
18939 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
18940 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
18941 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
18942 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
18943 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
18944 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
18945 default: type = _("<unknown>"); break;
18946 }
18947 as_bad_where (fixp->fx_file, fixp->fx_line,
18948 _("cannot represent %s relocation in this object file format"),
18949 type);
18950 return NULL;
18951 }
18952 }
18953
18954 #ifdef OBJ_ELF
18955 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
18956 && GOT_symbol
18957 && fixp->fx_addsy == GOT_symbol)
18958 {
18959 code = BFD_RELOC_ARM_GOTPC;
18960 reloc->addend = fixp->fx_offset = reloc->address;
18961 }
18962 #endif
18963
18964 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
18965
18966 if (reloc->howto == NULL)
18967 {
18968 as_bad_where (fixp->fx_file, fixp->fx_line,
18969 _("cannot represent %s relocation in this object file format"),
18970 bfd_get_reloc_code_name (code));
18971 return NULL;
18972 }
18973
18974 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
18975 vtable entry to be used in the relocation's section offset. */
18976 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
18977 reloc->address = fixp->fx_offset;
18978
18979 return reloc;
18980 }
18981
18982 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
18983
18984 void
18985 cons_fix_new_arm (fragS * frag,
18986 int where,
18987 int size,
18988 expressionS * exp)
18989 {
18990 bfd_reloc_code_real_type type;
18991 int pcrel = 0;
18992
18993 /* Pick a reloc.
18994 FIXME: @@ Should look at CPU word size. */
18995 switch (size)
18996 {
18997 case 1:
18998 type = BFD_RELOC_8;
18999 break;
19000 case 2:
19001 type = BFD_RELOC_16;
19002 break;
19003 case 4:
19004 default:
19005 type = BFD_RELOC_32;
19006 break;
19007 case 8:
19008 type = BFD_RELOC_64;
19009 break;
19010 }
19011
19012 #ifdef TE_PE
19013 if (exp->X_op == O_secrel)
19014 {
19015 exp->X_op = O_symbol;
19016 type = BFD_RELOC_32_SECREL;
19017 }
19018 #endif
19019
19020 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
19021 }
19022
19023 #if defined OBJ_COFF || defined OBJ_ELF
19024 void
19025 arm_validate_fix (fixS * fixP)
19026 {
19027 /* If the destination of the branch is a defined symbol which does not have
19028 the THUMB_FUNC attribute, then we must be calling a function which has
19029 the (interfacearm) attribute. We look for the Thumb entry point to that
19030 function and change the branch to refer to that function instead. */
19031 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
19032 && fixP->fx_addsy != NULL
19033 && S_IS_DEFINED (fixP->fx_addsy)
19034 && ! THUMB_IS_FUNC (fixP->fx_addsy))
19035 {
19036 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
19037 }
19038 }
19039 #endif
19040
19041 int
19042 arm_force_relocation (struct fix * fixp)
19043 {
19044 #if defined (OBJ_COFF) && defined (TE_PE)
19045 if (fixp->fx_r_type == BFD_RELOC_RVA)
19046 return 1;
19047 #endif
19048
19049 /* Resolve these relocations even if the symbol is extern or weak. */
19050 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
19051 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
19052 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
19053 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
19054 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
19055 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
19056 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
19057 return 0;
19058
19059 /* Always leave these relocations for the linker. */
19060 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19061 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19062 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19063 return 1;
19064
19065 /* Always generate relocations against function symbols. */
19066 if (fixp->fx_r_type == BFD_RELOC_32
19067 && fixp->fx_addsy
19068 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
19069 return 1;
19070
19071 return generic_force_reloc (fixp);
19072 }
19073
19074 #if defined (OBJ_ELF) || defined (OBJ_COFF)
19075 /* Relocations against function names must be left unadjusted,
19076 so that the linker can use this information to generate interworking
19077 stubs. The MIPS version of this function
19078 also prevents relocations that are mips-16 specific, but I do not
19079 know why it does this.
19080
19081 FIXME:
19082 There is one other problem that ought to be addressed here, but
19083 which currently is not: Taking the address of a label (rather
19084 than a function) and then later jumping to that address. Such
19085 addresses also ought to have their bottom bit set (assuming that
19086 they reside in Thumb code), but at the moment they will not. */
19087
19088 bfd_boolean
19089 arm_fix_adjustable (fixS * fixP)
19090 {
19091 if (fixP->fx_addsy == NULL)
19092 return 1;
19093
19094 /* Preserve relocations against symbols with function type. */
19095 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
19096 return 0;
19097
19098 if (THUMB_IS_FUNC (fixP->fx_addsy)
19099 && fixP->fx_subsy == NULL)
19100 return 0;
19101
19102 /* We need the symbol name for the VTABLE entries. */
19103 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
19104 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19105 return 0;
19106
19107 /* Don't allow symbols to be discarded on GOT related relocs. */
19108 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
19109 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
19110 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
19111 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
19112 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
19113 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
19114 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
19115 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
19116 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
19117 return 0;
19118
19119 /* Similarly for group relocations. */
19120 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19121 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19122 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19123 return 0;
19124
19125 return 1;
19126 }
19127 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
19128
19129 #ifdef OBJ_ELF
19130
19131 const char *
19132 elf32_arm_target_format (void)
19133 {
19134 #ifdef TE_SYMBIAN
19135 return (target_big_endian
19136 ? "elf32-bigarm-symbian"
19137 : "elf32-littlearm-symbian");
19138 #elif defined (TE_VXWORKS)
19139 return (target_big_endian
19140 ? "elf32-bigarm-vxworks"
19141 : "elf32-littlearm-vxworks");
19142 #else
19143 if (target_big_endian)
19144 return "elf32-bigarm";
19145 else
19146 return "elf32-littlearm";
19147 #endif
19148 }
19149
19150 void
19151 armelf_frob_symbol (symbolS * symp,
19152 int * puntp)
19153 {
19154 elf_frob_symbol (symp, puntp);
19155 }
19156 #endif
19157
19158 /* MD interface: Finalization. */
19159
19160 /* A good place to do this, although this was probably not intended
19161 for this kind of use. We need to dump the literal pool before
19162 references are made to a null symbol pointer. */
19163
19164 void
19165 arm_cleanup (void)
19166 {
19167 literal_pool * pool;
19168
19169 for (pool = list_of_pools; pool; pool = pool->next)
19170 {
19171 /* Put it at the end of the relevent section. */
19172 subseg_set (pool->section, pool->sub_section);
19173 #ifdef OBJ_ELF
19174 arm_elf_change_section ();
19175 #endif
19176 s_ltorg (0);
19177 }
19178 }
19179
19180 /* Adjust the symbol table. This marks Thumb symbols as distinct from
19181 ARM ones. */
19182
19183 void
19184 arm_adjust_symtab (void)
19185 {
19186 #ifdef OBJ_COFF
19187 symbolS * sym;
19188
19189 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
19190 {
19191 if (ARM_IS_THUMB (sym))
19192 {
19193 if (THUMB_IS_FUNC (sym))
19194 {
19195 /* Mark the symbol as a Thumb function. */
19196 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
19197 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
19198 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
19199
19200 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
19201 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
19202 else
19203 as_bad (_("%s: unexpected function type: %d"),
19204 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
19205 }
19206 else switch (S_GET_STORAGE_CLASS (sym))
19207 {
19208 case C_EXT:
19209 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
19210 break;
19211 case C_STAT:
19212 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
19213 break;
19214 case C_LABEL:
19215 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
19216 break;
19217 default:
19218 /* Do nothing. */
19219 break;
19220 }
19221 }
19222
19223 if (ARM_IS_INTERWORK (sym))
19224 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
19225 }
19226 #endif
19227 #ifdef OBJ_ELF
19228 symbolS * sym;
19229 char bind;
19230
19231 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
19232 {
19233 if (ARM_IS_THUMB (sym))
19234 {
19235 elf_symbol_type * elf_sym;
19236
19237 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
19238 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
19239
19240 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
19241 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
19242 {
19243 /* If it's a .thumb_func, declare it as so,
19244 otherwise tag label as .code 16. */
19245 if (THUMB_IS_FUNC (sym))
19246 elf_sym->internal_elf_sym.st_info =
19247 ELF_ST_INFO (bind, STT_ARM_TFUNC);
19248 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
19249 elf_sym->internal_elf_sym.st_info =
19250 ELF_ST_INFO (bind, STT_ARM_16BIT);
19251 }
19252 }
19253 }
19254 #endif
19255 }
19256
19257 /* MD interface: Initialization. */
19258
19259 static void
19260 set_constant_flonums (void)
19261 {
19262 int i;
19263
19264 for (i = 0; i < NUM_FLOAT_VALS; i++)
19265 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
19266 abort ();
19267 }
19268
19269 /* Auto-select Thumb mode if it's the only available instruction set for the
19270 given architecture. */
19271
19272 static void
19273 autoselect_thumb_from_cpu_variant (void)
19274 {
19275 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
19276 opcode_select (16);
19277 }
19278
19279 void
19280 md_begin (void)
19281 {
19282 unsigned mach;
19283 unsigned int i;
19284
19285 if ( (arm_ops_hsh = hash_new ()) == NULL
19286 || (arm_cond_hsh = hash_new ()) == NULL
19287 || (arm_shift_hsh = hash_new ()) == NULL
19288 || (arm_psr_hsh = hash_new ()) == NULL
19289 || (arm_v7m_psr_hsh = hash_new ()) == NULL
19290 || (arm_reg_hsh = hash_new ()) == NULL
19291 || (arm_reloc_hsh = hash_new ()) == NULL
19292 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
19293 as_fatal (_("virtual memory exhausted"));
19294
19295 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
19296 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
19297 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
19298 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
19299 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
19300 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
19301 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
19302 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
19303 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
19304 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (PTR) (v7m_psrs + i));
19305 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
19306 hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i));
19307 for (i = 0;
19308 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
19309 i++)
19310 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
19311 (PTR) (barrier_opt_names + i));
19312 #ifdef OBJ_ELF
19313 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
19314 hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i));
19315 #endif
19316
19317 set_constant_flonums ();
19318
19319 /* Set the cpu variant based on the command-line options. We prefer
19320 -mcpu= over -march= if both are set (as for GCC); and we prefer
19321 -mfpu= over any other way of setting the floating point unit.
19322 Use of legacy options with new options are faulted. */
19323 if (legacy_cpu)
19324 {
19325 if (mcpu_cpu_opt || march_cpu_opt)
19326 as_bad (_("use of old and new-style options to set CPU type"));
19327
19328 mcpu_cpu_opt = legacy_cpu;
19329 }
19330 else if (!mcpu_cpu_opt)
19331 mcpu_cpu_opt = march_cpu_opt;
19332
19333 if (legacy_fpu)
19334 {
19335 if (mfpu_opt)
19336 as_bad (_("use of old and new-style options to set FPU type"));
19337
19338 mfpu_opt = legacy_fpu;
19339 }
19340 else if (!mfpu_opt)
19341 {
19342 #if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
19343 /* Some environments specify a default FPU. If they don't, infer it
19344 from the processor. */
19345 if (mcpu_fpu_opt)
19346 mfpu_opt = mcpu_fpu_opt;
19347 else
19348 mfpu_opt = march_fpu_opt;
19349 #else
19350 mfpu_opt = &fpu_default;
19351 #endif
19352 }
19353
19354 if (!mfpu_opt)
19355 {
19356 if (mcpu_cpu_opt != NULL)
19357 mfpu_opt = &fpu_default;
19358 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
19359 mfpu_opt = &fpu_arch_vfp_v2;
19360 else
19361 mfpu_opt = &fpu_arch_fpa;
19362 }
19363
19364 #ifdef CPU_DEFAULT
19365 if (!mcpu_cpu_opt)
19366 {
19367 mcpu_cpu_opt = &cpu_default;
19368 selected_cpu = cpu_default;
19369 }
19370 #else
19371 if (mcpu_cpu_opt)
19372 selected_cpu = *mcpu_cpu_opt;
19373 else
19374 mcpu_cpu_opt = &arm_arch_any;
19375 #endif
19376
19377 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
19378
19379 autoselect_thumb_from_cpu_variant ();
19380
19381 arm_arch_used = thumb_arch_used = arm_arch_none;
19382
19383 #if defined OBJ_COFF || defined OBJ_ELF
19384 {
19385 unsigned int flags = 0;
19386
19387 #if defined OBJ_ELF
19388 flags = meabi_flags;
19389
19390 switch (meabi_flags)
19391 {
19392 case EF_ARM_EABI_UNKNOWN:
19393 #endif
19394 /* Set the flags in the private structure. */
19395 if (uses_apcs_26) flags |= F_APCS26;
19396 if (support_interwork) flags |= F_INTERWORK;
19397 if (uses_apcs_float) flags |= F_APCS_FLOAT;
19398 if (pic_code) flags |= F_PIC;
19399 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
19400 flags |= F_SOFT_FLOAT;
19401
19402 switch (mfloat_abi_opt)
19403 {
19404 case ARM_FLOAT_ABI_SOFT:
19405 case ARM_FLOAT_ABI_SOFTFP:
19406 flags |= F_SOFT_FLOAT;
19407 break;
19408
19409 case ARM_FLOAT_ABI_HARD:
19410 if (flags & F_SOFT_FLOAT)
19411 as_bad (_("hard-float conflicts with specified fpu"));
19412 break;
19413 }
19414
19415 /* Using pure-endian doubles (even if soft-float). */
19416 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
19417 flags |= F_VFP_FLOAT;
19418
19419 #if defined OBJ_ELF
19420 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
19421 flags |= EF_ARM_MAVERICK_FLOAT;
19422 break;
19423
19424 case EF_ARM_EABI_VER4:
19425 case EF_ARM_EABI_VER5:
19426 /* No additional flags to set. */
19427 break;
19428
19429 default:
19430 abort ();
19431 }
19432 #endif
19433 bfd_set_private_flags (stdoutput, flags);
19434
19435 /* We have run out flags in the COFF header to encode the
19436 status of ATPCS support, so instead we create a dummy,
19437 empty, debug section called .arm.atpcs. */
19438 if (atpcs)
19439 {
19440 asection * sec;
19441
19442 sec = bfd_make_section (stdoutput, ".arm.atpcs");
19443
19444 if (sec != NULL)
19445 {
19446 bfd_set_section_flags
19447 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
19448 bfd_set_section_size (stdoutput, sec, 0);
19449 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
19450 }
19451 }
19452 }
19453 #endif
19454
19455 /* Record the CPU type as well. */
19456 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
19457 mach = bfd_mach_arm_iWMMXt2;
19458 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
19459 mach = bfd_mach_arm_iWMMXt;
19460 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
19461 mach = bfd_mach_arm_XScale;
19462 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
19463 mach = bfd_mach_arm_ep9312;
19464 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
19465 mach = bfd_mach_arm_5TE;
19466 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
19467 {
19468 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
19469 mach = bfd_mach_arm_5T;
19470 else
19471 mach = bfd_mach_arm_5;
19472 }
19473 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
19474 {
19475 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
19476 mach = bfd_mach_arm_4T;
19477 else
19478 mach = bfd_mach_arm_4;
19479 }
19480 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
19481 mach = bfd_mach_arm_3M;
19482 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
19483 mach = bfd_mach_arm_3;
19484 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
19485 mach = bfd_mach_arm_2a;
19486 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
19487 mach = bfd_mach_arm_2;
19488 else
19489 mach = bfd_mach_arm_unknown;
19490
19491 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
19492 }
19493
19494 /* Command line processing. */
19495
19496 /* md_parse_option
19497 Invocation line includes a switch not recognized by the base assembler.
19498 See if it's a processor-specific option.
19499
19500 This routine is somewhat complicated by the need for backwards
19501 compatibility (since older releases of gcc can't be changed).
19502 The new options try to make the interface as compatible as
19503 possible with GCC.
19504
19505 New options (supported) are:
19506
19507 -mcpu=<cpu name> Assemble for selected processor
19508 -march=<architecture name> Assemble for selected architecture
19509 -mfpu=<fpu architecture> Assemble for selected FPU.
19510 -EB/-mbig-endian Big-endian
19511 -EL/-mlittle-endian Little-endian
19512 -k Generate PIC code
19513 -mthumb Start in Thumb mode
19514 -mthumb-interwork Code supports ARM/Thumb interworking
19515
19516 For now we will also provide support for:
19517
19518 -mapcs-32 32-bit Program counter
19519 -mapcs-26 26-bit Program counter
19520 -macps-float Floats passed in FP registers
19521 -mapcs-reentrant Reentrant code
19522 -matpcs
19523 (sometime these will probably be replaced with -mapcs=<list of options>
19524 and -matpcs=<list of options>)
19525
19526 The remaining options are only supported for back-wards compatibility.
19527 Cpu variants, the arm part is optional:
19528 -m[arm]1 Currently not supported.
19529 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
19530 -m[arm]3 Arm 3 processor
19531 -m[arm]6[xx], Arm 6 processors
19532 -m[arm]7[xx][t][[d]m] Arm 7 processors
19533 -m[arm]8[10] Arm 8 processors
19534 -m[arm]9[20][tdmi] Arm 9 processors
19535 -mstrongarm[110[0]] StrongARM processors
19536 -mxscale XScale processors
19537 -m[arm]v[2345[t[e]]] Arm architectures
19538 -mall All (except the ARM1)
19539 FP variants:
19540 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
19541 -mfpe-old (No float load/store multiples)
19542 -mvfpxd VFP Single precision
19543 -mvfp All VFP
19544 -mno-fpu Disable all floating point instructions
19545
19546 The following CPU names are recognized:
19547 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
19548 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
19549 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
19550 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
19551 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
19552 arm10t arm10e, arm1020t, arm1020e, arm10200e,
19553 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
19554
19555 */
19556
19557 const char * md_shortopts = "m:k";
19558
19559 #ifdef ARM_BI_ENDIAN
19560 #define OPTION_EB (OPTION_MD_BASE + 0)
19561 #define OPTION_EL (OPTION_MD_BASE + 1)
19562 #else
19563 #if TARGET_BYTES_BIG_ENDIAN
19564 #define OPTION_EB (OPTION_MD_BASE + 0)
19565 #else
19566 #define OPTION_EL (OPTION_MD_BASE + 1)
19567 #endif
19568 #endif
19569
19570 struct option md_longopts[] =
19571 {
19572 #ifdef OPTION_EB
19573 {"EB", no_argument, NULL, OPTION_EB},
19574 #endif
19575 #ifdef OPTION_EL
19576 {"EL", no_argument, NULL, OPTION_EL},
19577 #endif
19578 {NULL, no_argument, NULL, 0}
19579 };
19580
19581 size_t md_longopts_size = sizeof (md_longopts);
19582
19583 struct arm_option_table
19584 {
19585 char *option; /* Option name to match. */
19586 char *help; /* Help information. */
19587 int *var; /* Variable to change. */
19588 int value; /* What to change it to. */
19589 char *deprecated; /* If non-null, print this message. */
19590 };
19591
19592 struct arm_option_table arm_opts[] =
19593 {
19594 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
19595 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
19596 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
19597 &support_interwork, 1, NULL},
19598 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
19599 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
19600 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
19601 1, NULL},
19602 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
19603 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
19604 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
19605 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
19606 NULL},
19607
19608 /* These are recognized by the assembler, but have no affect on code. */
19609 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
19610 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
19611 {NULL, NULL, NULL, 0, NULL}
19612 };
19613
19614 struct arm_legacy_option_table
19615 {
19616 char *option; /* Option name to match. */
19617 const arm_feature_set **var; /* Variable to change. */
19618 const arm_feature_set value; /* What to change it to. */
19619 char *deprecated; /* If non-null, print this message. */
19620 };
19621
19622 const struct arm_legacy_option_table arm_legacy_opts[] =
19623 {
19624 /* DON'T add any new processors to this list -- we want the whole list
19625 to go away... Add them to the processors table instead. */
19626 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19627 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19628 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19629 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19630 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19631 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19632 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19633 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19634 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19635 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19636 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19637 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19638 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19639 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19640 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19641 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19642 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19643 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19644 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19645 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19646 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19647 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19648 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19649 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19650 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19651 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19652 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19653 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19654 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19655 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19656 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19657 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19658 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19659 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19660 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19661 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19662 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19663 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19664 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19665 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19666 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19667 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19668 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19669 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19670 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19671 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19672 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19673 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19674 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19675 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19676 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19677 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19678 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19679 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19680 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19681 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19682 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19683 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19684 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19685 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19686 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19687 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19688 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19689 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19690 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19691 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19692 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19693 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19694 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
19695 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
19696 N_("use -mcpu=strongarm110")},
19697 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
19698 N_("use -mcpu=strongarm1100")},
19699 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
19700 N_("use -mcpu=strongarm1110")},
19701 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
19702 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
19703 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
19704
19705 /* Architecture variants -- don't add any more to this list either. */
19706 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19707 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19708 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19709 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19710 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19711 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19712 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
19713 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
19714 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
19715 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
19716 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
19717 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
19718 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
19719 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
19720 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
19721 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
19722 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
19723 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
19724
19725 /* Floating point variants -- don't add any more to this list either. */
19726 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
19727 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
19728 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
19729 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
19730 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
19731
19732 {NULL, NULL, ARM_ARCH_NONE, NULL}
19733 };
19734
19735 struct arm_cpu_option_table
19736 {
19737 char *name;
19738 const arm_feature_set value;
19739 /* For some CPUs we assume an FPU unless the user explicitly sets
19740 -mfpu=... */
19741 const arm_feature_set default_fpu;
19742 /* The canonical name of the CPU, or NULL to use NAME converted to upper
19743 case. */
19744 const char *canonical_name;
19745 };
19746
19747 /* This list should, at a minimum, contain all the cpu names
19748 recognized by GCC. */
19749 static const struct arm_cpu_option_table arm_cpus[] =
19750 {
19751 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
19752 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
19753 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
19754 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
19755 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
19756 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19757 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19758 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19759 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19760 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19761 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19762 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
19763 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19764 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
19765 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19766 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
19767 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19768 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19769 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19770 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19771 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19772 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19773 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19774 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19775 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19776 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19777 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19778 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19779 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19780 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19781 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19782 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19783 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19784 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19785 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19786 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19787 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19788 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19789 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19790 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
19791 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19792 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19793 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19794 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19795 /* For V5 or later processors we default to using VFP; but the user
19796 should really set the FPU type explicitly. */
19797 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
19798 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19799 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
19800 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
19801 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
19802 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
19803 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
19804 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19805 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
19806 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
19807 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19808 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19809 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
19810 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
19811 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19812 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
19813 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
19814 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19815 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19816 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
19817 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
19818 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
19819 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
19820 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
19821 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
19822 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
19823 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
19824 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
19825 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
19826 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
19827 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
19828 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
19829 | FPU_NEON_EXT_V1),
19830 NULL},
19831 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
19832 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
19833 /* ??? XSCALE is really an architecture. */
19834 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
19835 /* ??? iwmmxt is not a processor. */
19836 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
19837 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
19838 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
19839 /* Maverick */
19840 {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
19841 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
19842 };
19843
19844 struct arm_arch_option_table
19845 {
19846 char *name;
19847 const arm_feature_set value;
19848 const arm_feature_set default_fpu;
19849 };
19850
19851 /* This list should, at a minimum, contain all the architecture names
19852 recognized by GCC. */
19853 static const struct arm_arch_option_table arm_archs[] =
19854 {
19855 {"all", ARM_ANY, FPU_ARCH_FPA},
19856 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
19857 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
19858 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
19859 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
19860 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
19861 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
19862 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
19863 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
19864 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
19865 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
19866 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
19867 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
19868 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
19869 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
19870 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
19871 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
19872 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
19873 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
19874 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
19875 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
19876 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
19877 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
19878 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
19879 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
19880 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
19881 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
19882 /* The official spelling of the ARMv7 profile variants is the dashed form.
19883 Accept the non-dashed form for compatibility with old toolchains. */
19884 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
19885 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
19886 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
19887 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
19888 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
19889 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
19890 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
19891 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
19892 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
19893 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
19894 };
19895
19896 /* ISA extensions in the co-processor space. */
19897 struct arm_option_cpu_value_table
19898 {
19899 char *name;
19900 const arm_feature_set value;
19901 };
19902
19903 static const struct arm_option_cpu_value_table arm_extensions[] =
19904 {
19905 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
19906 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
19907 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
19908 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
19909 {NULL, ARM_ARCH_NONE}
19910 };
19911
19912 /* This list should, at a minimum, contain all the fpu names
19913 recognized by GCC. */
19914 static const struct arm_option_cpu_value_table arm_fpus[] =
19915 {
19916 {"softfpa", FPU_NONE},
19917 {"fpe", FPU_ARCH_FPE},
19918 {"fpe2", FPU_ARCH_FPE},
19919 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
19920 {"fpa", FPU_ARCH_FPA},
19921 {"fpa10", FPU_ARCH_FPA},
19922 {"fpa11", FPU_ARCH_FPA},
19923 {"arm7500fe", FPU_ARCH_FPA},
19924 {"softvfp", FPU_ARCH_VFP},
19925 {"softvfp+vfp", FPU_ARCH_VFP_V2},
19926 {"vfp", FPU_ARCH_VFP_V2},
19927 {"vfp9", FPU_ARCH_VFP_V2},
19928 {"vfp3", FPU_ARCH_VFP_V3},
19929 {"vfp10", FPU_ARCH_VFP_V2},
19930 {"vfp10-r0", FPU_ARCH_VFP_V1},
19931 {"vfpxd", FPU_ARCH_VFP_V1xD},
19932 {"arm1020t", FPU_ARCH_VFP_V1},
19933 {"arm1020e", FPU_ARCH_VFP_V2},
19934 {"arm1136jfs", FPU_ARCH_VFP_V2},
19935 {"arm1136jf-s", FPU_ARCH_VFP_V2},
19936 {"maverick", FPU_ARCH_MAVERICK},
19937 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
19938 {NULL, ARM_ARCH_NONE}
19939 };
19940
19941 struct arm_option_value_table
19942 {
19943 char *name;
19944 long value;
19945 };
19946
19947 static const struct arm_option_value_table arm_float_abis[] =
19948 {
19949 {"hard", ARM_FLOAT_ABI_HARD},
19950 {"softfp", ARM_FLOAT_ABI_SOFTFP},
19951 {"soft", ARM_FLOAT_ABI_SOFT},
19952 {NULL, 0}
19953 };
19954
19955 #ifdef OBJ_ELF
19956 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
19957 static const struct arm_option_value_table arm_eabis[] =
19958 {
19959 {"gnu", EF_ARM_EABI_UNKNOWN},
19960 {"4", EF_ARM_EABI_VER4},
19961 {"5", EF_ARM_EABI_VER5},
19962 {NULL, 0}
19963 };
19964 #endif
19965
19966 struct arm_long_option_table
19967 {
19968 char * option; /* Substring to match. */
19969 char * help; /* Help information. */
19970 int (* func) (char * subopt); /* Function to decode sub-option. */
19971 char * deprecated; /* If non-null, print this message. */
19972 };
19973
19974 static int
19975 arm_parse_extension (char * str, const arm_feature_set **opt_p)
19976 {
19977 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
19978
19979 /* Copy the feature set, so that we can modify it. */
19980 *ext_set = **opt_p;
19981 *opt_p = ext_set;
19982
19983 while (str != NULL && *str != 0)
19984 {
19985 const struct arm_option_cpu_value_table * opt;
19986 char * ext;
19987 int optlen;
19988
19989 if (*str != '+')
19990 {
19991 as_bad (_("invalid architectural extension"));
19992 return 0;
19993 }
19994
19995 str++;
19996 ext = strchr (str, '+');
19997
19998 if (ext != NULL)
19999 optlen = ext - str;
20000 else
20001 optlen = strlen (str);
20002
20003 if (optlen == 0)
20004 {
20005 as_bad (_("missing architectural extension"));
20006 return 0;
20007 }
20008
20009 for (opt = arm_extensions; opt->name != NULL; opt++)
20010 if (strncmp (opt->name, str, optlen) == 0)
20011 {
20012 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
20013 break;
20014 }
20015
20016 if (opt->name == NULL)
20017 {
20018 as_bad (_("unknown architectural extnsion `%s'"), str);
20019 return 0;
20020 }
20021
20022 str = ext;
20023 };
20024
20025 return 1;
20026 }
20027
20028 static int
20029 arm_parse_cpu (char * str)
20030 {
20031 const struct arm_cpu_option_table * opt;
20032 char * ext = strchr (str, '+');
20033 int optlen;
20034
20035 if (ext != NULL)
20036 optlen = ext - str;
20037 else
20038 optlen = strlen (str);
20039
20040 if (optlen == 0)
20041 {
20042 as_bad (_("missing cpu name `%s'"), str);
20043 return 0;
20044 }
20045
20046 for (opt = arm_cpus; opt->name != NULL; opt++)
20047 if (strncmp (opt->name, str, optlen) == 0)
20048 {
20049 mcpu_cpu_opt = &opt->value;
20050 mcpu_fpu_opt = &opt->default_fpu;
20051 if (opt->canonical_name)
20052 strcpy(selected_cpu_name, opt->canonical_name);
20053 else
20054 {
20055 int i;
20056 for (i = 0; i < optlen; i++)
20057 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20058 selected_cpu_name[i] = 0;
20059 }
20060
20061 if (ext != NULL)
20062 return arm_parse_extension (ext, &mcpu_cpu_opt);
20063
20064 return 1;
20065 }
20066
20067 as_bad (_("unknown cpu `%s'"), str);
20068 return 0;
20069 }
20070
20071 static int
20072 arm_parse_arch (char * str)
20073 {
20074 const struct arm_arch_option_table *opt;
20075 char *ext = strchr (str, '+');
20076 int optlen;
20077
20078 if (ext != NULL)
20079 optlen = ext - str;
20080 else
20081 optlen = strlen (str);
20082
20083 if (optlen == 0)
20084 {
20085 as_bad (_("missing architecture name `%s'"), str);
20086 return 0;
20087 }
20088
20089 for (opt = arm_archs; opt->name != NULL; opt++)
20090 if (streq (opt->name, str))
20091 {
20092 march_cpu_opt = &opt->value;
20093 march_fpu_opt = &opt->default_fpu;
20094 strcpy(selected_cpu_name, opt->name);
20095
20096 if (ext != NULL)
20097 return arm_parse_extension (ext, &march_cpu_opt);
20098
20099 return 1;
20100 }
20101
20102 as_bad (_("unknown architecture `%s'\n"), str);
20103 return 0;
20104 }
20105
20106 static int
20107 arm_parse_fpu (char * str)
20108 {
20109 const struct arm_option_cpu_value_table * opt;
20110
20111 for (opt = arm_fpus; opt->name != NULL; opt++)
20112 if (streq (opt->name, str))
20113 {
20114 mfpu_opt = &opt->value;
20115 return 1;
20116 }
20117
20118 as_bad (_("unknown floating point format `%s'\n"), str);
20119 return 0;
20120 }
20121
20122 static int
20123 arm_parse_float_abi (char * str)
20124 {
20125 const struct arm_option_value_table * opt;
20126
20127 for (opt = arm_float_abis; opt->name != NULL; opt++)
20128 if (streq (opt->name, str))
20129 {
20130 mfloat_abi_opt = opt->value;
20131 return 1;
20132 }
20133
20134 as_bad (_("unknown floating point abi `%s'\n"), str);
20135 return 0;
20136 }
20137
20138 #ifdef OBJ_ELF
20139 static int
20140 arm_parse_eabi (char * str)
20141 {
20142 const struct arm_option_value_table *opt;
20143
20144 for (opt = arm_eabis; opt->name != NULL; opt++)
20145 if (streq (opt->name, str))
20146 {
20147 meabi_flags = opt->value;
20148 return 1;
20149 }
20150 as_bad (_("unknown EABI `%s'\n"), str);
20151 return 0;
20152 }
20153 #endif
20154
20155 struct arm_long_option_table arm_long_opts[] =
20156 {
20157 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
20158 arm_parse_cpu, NULL},
20159 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
20160 arm_parse_arch, NULL},
20161 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
20162 arm_parse_fpu, NULL},
20163 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
20164 arm_parse_float_abi, NULL},
20165 #ifdef OBJ_ELF
20166 {"meabi=", N_("<ver>\t assemble for eabi version <ver>"),
20167 arm_parse_eabi, NULL},
20168 #endif
20169 {NULL, NULL, 0, NULL}
20170 };
20171
20172 int
20173 md_parse_option (int c, char * arg)
20174 {
20175 struct arm_option_table *opt;
20176 const struct arm_legacy_option_table *fopt;
20177 struct arm_long_option_table *lopt;
20178
20179 switch (c)
20180 {
20181 #ifdef OPTION_EB
20182 case OPTION_EB:
20183 target_big_endian = 1;
20184 break;
20185 #endif
20186
20187 #ifdef OPTION_EL
20188 case OPTION_EL:
20189 target_big_endian = 0;
20190 break;
20191 #endif
20192
20193 case 'a':
20194 /* Listing option. Just ignore these, we don't support additional
20195 ones. */
20196 return 0;
20197
20198 default:
20199 for (opt = arm_opts; opt->option != NULL; opt++)
20200 {
20201 if (c == opt->option[0]
20202 && ((arg == NULL && opt->option[1] == 0)
20203 || streq (arg, opt->option + 1)))
20204 {
20205 #if WARN_DEPRECATED
20206 /* If the option is deprecated, tell the user. */
20207 if (opt->deprecated != NULL)
20208 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20209 arg ? arg : "", _(opt->deprecated));
20210 #endif
20211
20212 if (opt->var != NULL)
20213 *opt->var = opt->value;
20214
20215 return 1;
20216 }
20217 }
20218
20219 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
20220 {
20221 if (c == fopt->option[0]
20222 && ((arg == NULL && fopt->option[1] == 0)
20223 || streq (arg, fopt->option + 1)))
20224 {
20225 #if WARN_DEPRECATED
20226 /* If the option is deprecated, tell the user. */
20227 if (fopt->deprecated != NULL)
20228 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20229 arg ? arg : "", _(fopt->deprecated));
20230 #endif
20231
20232 if (fopt->var != NULL)
20233 *fopt->var = &fopt->value;
20234
20235 return 1;
20236 }
20237 }
20238
20239 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20240 {
20241 /* These options are expected to have an argument. */
20242 if (c == lopt->option[0]
20243 && arg != NULL
20244 && strncmp (arg, lopt->option + 1,
20245 strlen (lopt->option + 1)) == 0)
20246 {
20247 #if WARN_DEPRECATED
20248 /* If the option is deprecated, tell the user. */
20249 if (lopt->deprecated != NULL)
20250 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
20251 _(lopt->deprecated));
20252 #endif
20253
20254 /* Call the sup-option parser. */
20255 return lopt->func (arg + strlen (lopt->option) - 1);
20256 }
20257 }
20258
20259 return 0;
20260 }
20261
20262 return 1;
20263 }
20264
20265 void
20266 md_show_usage (FILE * fp)
20267 {
20268 struct arm_option_table *opt;
20269 struct arm_long_option_table *lopt;
20270
20271 fprintf (fp, _(" ARM-specific assembler options:\n"));
20272
20273 for (opt = arm_opts; opt->option != NULL; opt++)
20274 if (opt->help != NULL)
20275 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
20276
20277 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20278 if (lopt->help != NULL)
20279 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
20280
20281 #ifdef OPTION_EB
20282 fprintf (fp, _("\
20283 -EB assemble code for a big-endian cpu\n"));
20284 #endif
20285
20286 #ifdef OPTION_EL
20287 fprintf (fp, _("\
20288 -EL assemble code for a little-endian cpu\n"));
20289 #endif
20290 }
20291
20292
20293 #ifdef OBJ_ELF
20294 typedef struct
20295 {
20296 int val;
20297 arm_feature_set flags;
20298 } cpu_arch_ver_table;
20299
20300 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
20301 least features first. */
20302 static const cpu_arch_ver_table cpu_arch_ver[] =
20303 {
20304 {1, ARM_ARCH_V4},
20305 {2, ARM_ARCH_V4T},
20306 {3, ARM_ARCH_V5},
20307 {4, ARM_ARCH_V5TE},
20308 {5, ARM_ARCH_V5TEJ},
20309 {6, ARM_ARCH_V6},
20310 {7, ARM_ARCH_V6Z},
20311 {8, ARM_ARCH_V6K},
20312 {9, ARM_ARCH_V6T2},
20313 {10, ARM_ARCH_V7A},
20314 {10, ARM_ARCH_V7R},
20315 {10, ARM_ARCH_V7M},
20316 {0, ARM_ARCH_NONE}
20317 };
20318
20319 /* Set the public EABI object attributes. */
20320 static void
20321 aeabi_set_public_attributes (void)
20322 {
20323 int arch;
20324 arm_feature_set flags;
20325 arm_feature_set tmp;
20326 const cpu_arch_ver_table *p;
20327
20328 /* Choose the architecture based on the capabilities of the requested cpu
20329 (if any) and/or the instructions actually used. */
20330 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
20331 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
20332 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
20333 /*Allow the user to override the reported architecture. */
20334 if (object_arch)
20335 {
20336 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
20337 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
20338 }
20339
20340 tmp = flags;
20341 arch = 0;
20342 for (p = cpu_arch_ver; p->val; p++)
20343 {
20344 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
20345 {
20346 arch = p->val;
20347 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
20348 }
20349 }
20350
20351 /* Tag_CPU_name. */
20352 if (selected_cpu_name[0])
20353 {
20354 char *p;
20355
20356 p = selected_cpu_name;
20357 if (strncmp(p, "armv", 4) == 0)
20358 {
20359 int i;
20360
20361 p += 4;
20362 for (i = 0; p[i]; i++)
20363 p[i] = TOUPPER (p[i]);
20364 }
20365 elf32_arm_add_eabi_attr_string (stdoutput, 5, p);
20366 }
20367 /* Tag_CPU_arch. */
20368 elf32_arm_add_eabi_attr_int (stdoutput, 6, arch);
20369 /* Tag_CPU_arch_profile. */
20370 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
20371 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'A');
20372 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
20373 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'R');
20374 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m))
20375 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'M');
20376 /* Tag_ARM_ISA_use. */
20377 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_full))
20378 elf32_arm_add_eabi_attr_int (stdoutput, 8, 1);
20379 /* Tag_THUMB_ISA_use. */
20380 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_full))
20381 elf32_arm_add_eabi_attr_int (stdoutput, 9,
20382 ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2) ? 2 : 1);
20383 /* Tag_VFP_arch. */
20384 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v3)
20385 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v3))
20386 elf32_arm_add_eabi_attr_int (stdoutput, 10, 3);
20387 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v2)
20388 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v2))
20389 elf32_arm_add_eabi_attr_int (stdoutput, 10, 2);
20390 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1)
20391 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1)
20392 || ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1xd)
20393 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1xd))
20394 elf32_arm_add_eabi_attr_int (stdoutput, 10, 1);
20395 /* Tag_WMMX_arch. */
20396 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_cext_iwmmxt)
20397 || ARM_CPU_HAS_FEATURE (arm_arch_used, arm_cext_iwmmxt))
20398 elf32_arm_add_eabi_attr_int (stdoutput, 11, 1);
20399 /* Tag_NEON_arch. */
20400 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_neon_ext_v1)
20401 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_neon_ext_v1))
20402 elf32_arm_add_eabi_attr_int (stdoutput, 12, 1);
20403 }
20404
20405 /* Add the .ARM.attributes section. */
20406 void
20407 arm_md_end (void)
20408 {
20409 segT s;
20410 char *p;
20411 addressT addr;
20412 offsetT size;
20413
20414 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
20415 return;
20416
20417 aeabi_set_public_attributes ();
20418 size = elf32_arm_eabi_attr_size (stdoutput);
20419 s = subseg_new (".ARM.attributes", 0);
20420 bfd_set_section_flags (stdoutput, s, SEC_READONLY | SEC_DATA);
20421 addr = frag_now_fix ();
20422 p = frag_more (size);
20423 elf32_arm_set_eabi_attr_contents (stdoutput, (bfd_byte *)p, size);
20424 }
20425 #endif /* OBJ_ELF */
20426
20427
20428 /* Parse a .cpu directive. */
20429
20430 static void
20431 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
20432 {
20433 const struct arm_cpu_option_table *opt;
20434 char *name;
20435 char saved_char;
20436
20437 name = input_line_pointer;
20438 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
20439 input_line_pointer++;
20440 saved_char = *input_line_pointer;
20441 *input_line_pointer = 0;
20442
20443 /* Skip the first "all" entry. */
20444 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
20445 if (streq (opt->name, name))
20446 {
20447 mcpu_cpu_opt = &opt->value;
20448 selected_cpu = opt->value;
20449 if (opt->canonical_name)
20450 strcpy(selected_cpu_name, opt->canonical_name);
20451 else
20452 {
20453 int i;
20454 for (i = 0; opt->name[i]; i++)
20455 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20456 selected_cpu_name[i] = 0;
20457 }
20458 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20459 *input_line_pointer = saved_char;
20460 demand_empty_rest_of_line ();
20461 return;
20462 }
20463 as_bad (_("unknown cpu `%s'"), name);
20464 *input_line_pointer = saved_char;
20465 ignore_rest_of_line ();
20466 }
20467
20468
20469 /* Parse a .arch directive. */
20470
20471 static void
20472 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
20473 {
20474 const struct arm_arch_option_table *opt;
20475 char saved_char;
20476 char *name;
20477
20478 name = input_line_pointer;
20479 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
20480 input_line_pointer++;
20481 saved_char = *input_line_pointer;
20482 *input_line_pointer = 0;
20483
20484 /* Skip the first "all" entry. */
20485 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20486 if (streq (opt->name, name))
20487 {
20488 mcpu_cpu_opt = &opt->value;
20489 selected_cpu = opt->value;
20490 strcpy(selected_cpu_name, opt->name);
20491 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20492 *input_line_pointer = saved_char;
20493 demand_empty_rest_of_line ();
20494 return;
20495 }
20496
20497 as_bad (_("unknown architecture `%s'\n"), name);
20498 *input_line_pointer = saved_char;
20499 ignore_rest_of_line ();
20500 }
20501
20502
20503 /* Parse a .object_arch directive. */
20504
20505 static void
20506 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
20507 {
20508 const struct arm_arch_option_table *opt;
20509 char saved_char;
20510 char *name;
20511
20512 name = input_line_pointer;
20513 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
20514 input_line_pointer++;
20515 saved_char = *input_line_pointer;
20516 *input_line_pointer = 0;
20517
20518 /* Skip the first "all" entry. */
20519 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20520 if (streq (opt->name, name))
20521 {
20522 object_arch = &opt->value;
20523 *input_line_pointer = saved_char;
20524 demand_empty_rest_of_line ();
20525 return;
20526 }
20527
20528 as_bad (_("unknown architecture `%s'\n"), name);
20529 *input_line_pointer = saved_char;
20530 ignore_rest_of_line ();
20531 }
20532
20533
20534 /* Parse a .fpu directive. */
20535
20536 static void
20537 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
20538 {
20539 const struct arm_option_cpu_value_table *opt;
20540 char saved_char;
20541 char *name;
20542
20543 name = input_line_pointer;
20544 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
20545 input_line_pointer++;
20546 saved_char = *input_line_pointer;
20547 *input_line_pointer = 0;
20548
20549 for (opt = arm_fpus; opt->name != NULL; opt++)
20550 if (streq (opt->name, name))
20551 {
20552 mfpu_opt = &opt->value;
20553 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20554 *input_line_pointer = saved_char;
20555 demand_empty_rest_of_line ();
20556 return;
20557 }
20558
20559 as_bad (_("unknown floating point format `%s'\n"), name);
20560 *input_line_pointer = saved_char;
20561 ignore_rest_of_line ();
20562 }
20563
20564 /* Copy symbol information. */
20565 void
20566 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
20567 {
20568 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
20569 }