* config/obj-elf.c (obj_elf_section_type): Add prototype
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
1 /* tc-arm.c -- Assemble for the ARM
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008
4 Free Software Foundation, Inc.
5 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
6 Modified by David Taylor (dtaylor@armltd.co.uk)
7 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
8 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
9 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
10
11 This file is part of GAS, the GNU Assembler.
12
13 GAS is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 3, or (at your option)
16 any later version.
17
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with GAS; see the file COPYING. If not, write to the Free
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 02110-1301, USA. */
27
28 #include <limits.h>
29 #include <stdarg.h>
30 #define NO_RELOC 0
31 #include "as.h"
32 #include "safe-ctype.h"
33 #include "subsegs.h"
34 #include "obstack.h"
35
36 #include "opcode/arm.h"
37
38 #ifdef OBJ_ELF
39 #include "elf/arm.h"
40 #include "dw2gencfi.h"
41 #endif
42
43 #include "dwarf2dbg.h"
44
45 #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 static int fix_v4bx = FALSE;
147
148 /* Variables that we set while parsing command-line options. Once all
149 options have been read we re-process these values to set the real
150 assembly flags. */
151 static const arm_feature_set *legacy_cpu = NULL;
152 static const arm_feature_set *legacy_fpu = NULL;
153
154 static const arm_feature_set *mcpu_cpu_opt = NULL;
155 static const arm_feature_set *mcpu_fpu_opt = NULL;
156 static const arm_feature_set *march_cpu_opt = NULL;
157 static const arm_feature_set *march_fpu_opt = NULL;
158 static const arm_feature_set *mfpu_opt = NULL;
159 static const arm_feature_set *object_arch = NULL;
160
161 /* Constants for known architecture features. */
162 static const arm_feature_set fpu_default = FPU_DEFAULT;
163 static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
164 static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
165 static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
166 static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
167 static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
168 static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
169 static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
170 static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
171
172 #ifdef CPU_DEFAULT
173 static const arm_feature_set cpu_default = CPU_DEFAULT;
174 #endif
175
176 static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
177 static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
178 static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
179 static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
180 static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
181 static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
182 static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
183 static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
184 static const arm_feature_set arm_ext_v4t_5 =
185 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
186 static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
187 static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
188 static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
189 static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
190 static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
191 static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
192 static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
193 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
194 static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
195 static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
196 static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
197 static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
198 static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
199 static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
200 static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
201 static const arm_feature_set arm_ext_m =
202 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_V7M, 0);
203
204 static const arm_feature_set arm_arch_any = ARM_ANY;
205 static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
206 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
207 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
208
209 static const arm_feature_set arm_cext_iwmmxt2 =
210 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
211 static const arm_feature_set arm_cext_iwmmxt =
212 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
213 static const arm_feature_set arm_cext_xscale =
214 ARM_FEATURE (0, ARM_CEXT_XSCALE);
215 static const arm_feature_set arm_cext_maverick =
216 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
217 static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
218 static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
219 static const arm_feature_set fpu_vfp_ext_v1xd =
220 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
221 static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
222 static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
223 static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
224 static const arm_feature_set fpu_vfp_ext_d32 =
225 ARM_FEATURE (0, FPU_VFP_EXT_D32);
226 static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
227 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
228 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
229
230 static int mfloat_abi_opt = -1;
231 /* Record user cpu selection for object attributes. */
232 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
233 /* Must be long enough to hold any of the names in arm_cpus. */
234 static char selected_cpu_name[16];
235 #ifdef OBJ_ELF
236 # ifdef EABI_DEFAULT
237 static int meabi_flags = EABI_DEFAULT;
238 # else
239 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
240 # endif
241
242 bfd_boolean
243 arm_is_eabi (void)
244 {
245 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
246 }
247 #endif
248
249 #ifdef OBJ_ELF
250 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
251 symbolS * GOT_symbol;
252 #endif
253
254 /* 0: assemble for ARM,
255 1: assemble for Thumb,
256 2: assemble for Thumb even though target CPU does not support thumb
257 instructions. */
258 static int thumb_mode = 0;
259
260 /* If unified_syntax is true, we are processing the new unified
261 ARM/Thumb syntax. Important differences from the old ARM mode:
262
263 - Immediate operands do not require a # prefix.
264 - Conditional affixes always appear at the end of the
265 instruction. (For backward compatibility, those instructions
266 that formerly had them in the middle, continue to accept them
267 there.)
268 - The IT instruction may appear, and if it does is validated
269 against subsequent conditional affixes. It does not generate
270 machine code.
271
272 Important differences from the old Thumb mode:
273
274 - Immediate operands do not require a # prefix.
275 - Most of the V6T2 instructions are only available in unified mode.
276 - The .N and .W suffixes are recognized and honored (it is an error
277 if they cannot be honored).
278 - All instructions set the flags if and only if they have an 's' affix.
279 - Conditional affixes may be used. They are validated against
280 preceding IT instructions. Unlike ARM mode, you cannot use a
281 conditional affix except in the scope of an IT instruction. */
282
283 static bfd_boolean unified_syntax = FALSE;
284
285 enum neon_el_type
286 {
287 NT_invtype,
288 NT_untyped,
289 NT_integer,
290 NT_float,
291 NT_poly,
292 NT_signed,
293 NT_unsigned
294 };
295
296 struct neon_type_el
297 {
298 enum neon_el_type type;
299 unsigned size;
300 };
301
302 #define NEON_MAX_TYPE_ELS 4
303
304 struct neon_type
305 {
306 struct neon_type_el el[NEON_MAX_TYPE_ELS];
307 unsigned elems;
308 };
309
310 struct arm_it
311 {
312 const char * error;
313 unsigned long instruction;
314 int size;
315 int size_req;
316 int cond;
317 /* "uncond_value" is set to the value in place of the conditional field in
318 unconditional versions of the instruction, or -1 if nothing is
319 appropriate. */
320 int uncond_value;
321 struct neon_type vectype;
322 /* Set to the opcode if the instruction needs relaxation.
323 Zero if the instruction is not relaxed. */
324 unsigned long relax;
325 struct
326 {
327 bfd_reloc_code_real_type type;
328 expressionS exp;
329 int pc_rel;
330 } reloc;
331
332 struct
333 {
334 unsigned reg;
335 signed int imm;
336 struct neon_type_el vectype;
337 unsigned present : 1; /* Operand present. */
338 unsigned isreg : 1; /* Operand was a register. */
339 unsigned immisreg : 1; /* .imm field is a second register. */
340 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
341 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
342 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
343 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
344 instructions. This allows us to disambiguate ARM <-> vector insns. */
345 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
346 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
347 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
348 unsigned issingle : 1; /* Operand is VFP single-precision register. */
349 unsigned hasreloc : 1; /* Operand has relocation suffix. */
350 unsigned writeback : 1; /* Operand has trailing ! */
351 unsigned preind : 1; /* Preindexed address. */
352 unsigned postind : 1; /* Postindexed address. */
353 unsigned negative : 1; /* Index register was negated. */
354 unsigned shifted : 1; /* Shift applied to operation. */
355 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
356 } operands[6];
357 };
358
359 static struct arm_it inst;
360
361 #define NUM_FLOAT_VALS 8
362
363 const char * fp_const[] =
364 {
365 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
366 };
367
368 /* Number of littlenums required to hold an extended precision number. */
369 #define MAX_LITTLENUMS 6
370
371 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
372
373 #define FAIL (-1)
374 #define SUCCESS (0)
375
376 #define SUFF_S 1
377 #define SUFF_D 2
378 #define SUFF_E 3
379 #define SUFF_P 4
380
381 #define CP_T_X 0x00008000
382 #define CP_T_Y 0x00400000
383
384 #define CONDS_BIT 0x00100000
385 #define LOAD_BIT 0x00100000
386
387 #define DOUBLE_LOAD_FLAG 0x00000001
388
389 struct asm_cond
390 {
391 const char * template;
392 unsigned long value;
393 };
394
395 #define COND_ALWAYS 0xE
396
397 struct asm_psr
398 {
399 const char *template;
400 unsigned long field;
401 };
402
403 struct asm_barrier_opt
404 {
405 const char *template;
406 unsigned long value;
407 };
408
409 /* The bit that distinguishes CPSR and SPSR. */
410 #define SPSR_BIT (1 << 22)
411
412 /* The individual PSR flag bits. */
413 #define PSR_c (1 << 16)
414 #define PSR_x (1 << 17)
415 #define PSR_s (1 << 18)
416 #define PSR_f (1 << 19)
417
418 struct reloc_entry
419 {
420 char *name;
421 bfd_reloc_code_real_type reloc;
422 };
423
424 enum vfp_reg_pos
425 {
426 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
427 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
428 };
429
430 enum vfp_ldstm_type
431 {
432 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
433 };
434
435 /* Bits for DEFINED field in neon_typed_alias. */
436 #define NTA_HASTYPE 1
437 #define NTA_HASINDEX 2
438
439 struct neon_typed_alias
440 {
441 unsigned char defined;
442 unsigned char index;
443 struct neon_type_el eltype;
444 };
445
446 /* ARM register categories. This includes coprocessor numbers and various
447 architecture extensions' registers. */
448 enum arm_reg_type
449 {
450 REG_TYPE_RN,
451 REG_TYPE_CP,
452 REG_TYPE_CN,
453 REG_TYPE_FN,
454 REG_TYPE_VFS,
455 REG_TYPE_VFD,
456 REG_TYPE_NQ,
457 REG_TYPE_VFSD,
458 REG_TYPE_NDQ,
459 REG_TYPE_NSDQ,
460 REG_TYPE_VFC,
461 REG_TYPE_MVF,
462 REG_TYPE_MVD,
463 REG_TYPE_MVFX,
464 REG_TYPE_MVDX,
465 REG_TYPE_MVAX,
466 REG_TYPE_DSPSC,
467 REG_TYPE_MMXWR,
468 REG_TYPE_MMXWC,
469 REG_TYPE_MMXWCG,
470 REG_TYPE_XSCALE,
471 };
472
473 /* Structure for a hash table entry for a register.
474 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
475 information which states whether a vector type or index is specified (for a
476 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
477 struct reg_entry
478 {
479 const char *name;
480 unsigned char number;
481 unsigned char type;
482 unsigned char builtin;
483 struct neon_typed_alias *neon;
484 };
485
486 /* Diagnostics used when we don't get a register of the expected type. */
487 const char *const reg_expected_msgs[] =
488 {
489 N_("ARM register expected"),
490 N_("bad or missing co-processor number"),
491 N_("co-processor register expected"),
492 N_("FPA register expected"),
493 N_("VFP single precision register expected"),
494 N_("VFP/Neon double precision register expected"),
495 N_("Neon quad precision register expected"),
496 N_("VFP single or double precision register expected"),
497 N_("Neon double or quad precision register expected"),
498 N_("VFP single, double or Neon quad precision register expected"),
499 N_("VFP system register expected"),
500 N_("Maverick MVF register expected"),
501 N_("Maverick MVD register expected"),
502 N_("Maverick MVFX register expected"),
503 N_("Maverick MVDX register expected"),
504 N_("Maverick MVAX register expected"),
505 N_("Maverick DSPSC register expected"),
506 N_("iWMMXt data register expected"),
507 N_("iWMMXt control register expected"),
508 N_("iWMMXt scalar register expected"),
509 N_("XScale accumulator register expected"),
510 };
511
512 /* Some well known registers that we refer to directly elsewhere. */
513 #define REG_SP 13
514 #define REG_LR 14
515 #define REG_PC 15
516
517 /* ARM instructions take 4bytes in the object file, Thumb instructions
518 take 2: */
519 #define INSN_SIZE 4
520
521 struct asm_opcode
522 {
523 /* Basic string to match. */
524 const char *template;
525
526 /* Parameters to instruction. */
527 unsigned char operands[8];
528
529 /* Conditional tag - see opcode_lookup. */
530 unsigned int tag : 4;
531
532 /* Basic instruction code. */
533 unsigned int avalue : 28;
534
535 /* Thumb-format instruction code. */
536 unsigned int tvalue;
537
538 /* Which architecture variant provides this instruction. */
539 const arm_feature_set *avariant;
540 const arm_feature_set *tvariant;
541
542 /* Function to call to encode instruction in ARM format. */
543 void (* aencode) (void);
544
545 /* Function to call to encode instruction in Thumb format. */
546 void (* tencode) (void);
547 };
548
549 /* Defines for various bits that we will want to toggle. */
550 #define INST_IMMEDIATE 0x02000000
551 #define OFFSET_REG 0x02000000
552 #define HWOFFSET_IMM 0x00400000
553 #define SHIFT_BY_REG 0x00000010
554 #define PRE_INDEX 0x01000000
555 #define INDEX_UP 0x00800000
556 #define WRITE_BACK 0x00200000
557 #define LDM_TYPE_2_OR_3 0x00400000
558 #define CPSI_MMOD 0x00020000
559
560 #define LITERAL_MASK 0xf000f000
561 #define OPCODE_MASK 0xfe1fffff
562 #define V4_STR_BIT 0x00000020
563
564 #define T2_SUBS_PC_LR 0xf3de8f00
565
566 #define DATA_OP_SHIFT 21
567
568 #define T2_OPCODE_MASK 0xfe1fffff
569 #define T2_DATA_OP_SHIFT 21
570
571 /* Codes to distinguish the arithmetic instructions. */
572 #define OPCODE_AND 0
573 #define OPCODE_EOR 1
574 #define OPCODE_SUB 2
575 #define OPCODE_RSB 3
576 #define OPCODE_ADD 4
577 #define OPCODE_ADC 5
578 #define OPCODE_SBC 6
579 #define OPCODE_RSC 7
580 #define OPCODE_TST 8
581 #define OPCODE_TEQ 9
582 #define OPCODE_CMP 10
583 #define OPCODE_CMN 11
584 #define OPCODE_ORR 12
585 #define OPCODE_MOV 13
586 #define OPCODE_BIC 14
587 #define OPCODE_MVN 15
588
589 #define T2_OPCODE_AND 0
590 #define T2_OPCODE_BIC 1
591 #define T2_OPCODE_ORR 2
592 #define T2_OPCODE_ORN 3
593 #define T2_OPCODE_EOR 4
594 #define T2_OPCODE_ADD 8
595 #define T2_OPCODE_ADC 10
596 #define T2_OPCODE_SBC 11
597 #define T2_OPCODE_SUB 13
598 #define T2_OPCODE_RSB 14
599
600 #define T_OPCODE_MUL 0x4340
601 #define T_OPCODE_TST 0x4200
602 #define T_OPCODE_CMN 0x42c0
603 #define T_OPCODE_NEG 0x4240
604 #define T_OPCODE_MVN 0x43c0
605
606 #define T_OPCODE_ADD_R3 0x1800
607 #define T_OPCODE_SUB_R3 0x1a00
608 #define T_OPCODE_ADD_HI 0x4400
609 #define T_OPCODE_ADD_ST 0xb000
610 #define T_OPCODE_SUB_ST 0xb080
611 #define T_OPCODE_ADD_SP 0xa800
612 #define T_OPCODE_ADD_PC 0xa000
613 #define T_OPCODE_ADD_I8 0x3000
614 #define T_OPCODE_SUB_I8 0x3800
615 #define T_OPCODE_ADD_I3 0x1c00
616 #define T_OPCODE_SUB_I3 0x1e00
617
618 #define T_OPCODE_ASR_R 0x4100
619 #define T_OPCODE_LSL_R 0x4080
620 #define T_OPCODE_LSR_R 0x40c0
621 #define T_OPCODE_ROR_R 0x41c0
622 #define T_OPCODE_ASR_I 0x1000
623 #define T_OPCODE_LSL_I 0x0000
624 #define T_OPCODE_LSR_I 0x0800
625
626 #define T_OPCODE_MOV_I8 0x2000
627 #define T_OPCODE_CMP_I8 0x2800
628 #define T_OPCODE_CMP_LR 0x4280
629 #define T_OPCODE_MOV_HR 0x4600
630 #define T_OPCODE_CMP_HR 0x4500
631
632 #define T_OPCODE_LDR_PC 0x4800
633 #define T_OPCODE_LDR_SP 0x9800
634 #define T_OPCODE_STR_SP 0x9000
635 #define T_OPCODE_LDR_IW 0x6800
636 #define T_OPCODE_STR_IW 0x6000
637 #define T_OPCODE_LDR_IH 0x8800
638 #define T_OPCODE_STR_IH 0x8000
639 #define T_OPCODE_LDR_IB 0x7800
640 #define T_OPCODE_STR_IB 0x7000
641 #define T_OPCODE_LDR_RW 0x5800
642 #define T_OPCODE_STR_RW 0x5000
643 #define T_OPCODE_LDR_RH 0x5a00
644 #define T_OPCODE_STR_RH 0x5200
645 #define T_OPCODE_LDR_RB 0x5c00
646 #define T_OPCODE_STR_RB 0x5400
647
648 #define T_OPCODE_PUSH 0xb400
649 #define T_OPCODE_POP 0xbc00
650
651 #define T_OPCODE_BRANCH 0xe000
652
653 #define THUMB_SIZE 2 /* Size of thumb instruction. */
654 #define THUMB_PP_PC_LR 0x0100
655 #define THUMB_LOAD_BIT 0x0800
656 #define THUMB2_LOAD_BIT 0x00100000
657
658 #define BAD_ARGS _("bad arguments to instruction")
659 #define BAD_PC _("r15 not allowed here")
660 #define BAD_COND _("instruction cannot be conditional")
661 #define BAD_OVERLAP _("registers may not be the same")
662 #define BAD_HIREG _("lo register required")
663 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
664 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
665 #define BAD_BRANCH _("branch must be last instruction in IT block")
666 #define BAD_NOT_IT _("instruction not allowed in IT block")
667 #define BAD_FPU _("selected FPU does not support instruction")
668
669 static struct hash_control *arm_ops_hsh;
670 static struct hash_control *arm_cond_hsh;
671 static struct hash_control *arm_shift_hsh;
672 static struct hash_control *arm_psr_hsh;
673 static struct hash_control *arm_v7m_psr_hsh;
674 static struct hash_control *arm_reg_hsh;
675 static struct hash_control *arm_reloc_hsh;
676 static struct hash_control *arm_barrier_opt_hsh;
677
678 /* Stuff needed to resolve the label ambiguity
679 As:
680 ...
681 label: <insn>
682 may differ from:
683 ...
684 label:
685 <insn> */
686
687 symbolS * last_label_seen;
688 static int label_is_thumb_function_name = FALSE;
689 \f
690 /* Literal pool structure. Held on a per-section
691 and per-sub-section basis. */
692
693 #define MAX_LITERAL_POOL_SIZE 1024
694 typedef struct literal_pool
695 {
696 expressionS literals [MAX_LITERAL_POOL_SIZE];
697 unsigned int next_free_entry;
698 unsigned int id;
699 symbolS * symbol;
700 segT section;
701 subsegT sub_section;
702 struct literal_pool * next;
703 } literal_pool;
704
705 /* Pointer to a linked list of literal pools. */
706 literal_pool * list_of_pools = NULL;
707
708 /* State variables for IT block handling. */
709 static bfd_boolean current_it_mask = 0;
710 static int current_cc;
711 \f
712 /* Pure syntax. */
713
714 /* This array holds the chars that always start a comment. If the
715 pre-processor is disabled, these aren't very useful. */
716 const char comment_chars[] = "@";
717
718 /* This array holds the chars that only start a comment at the beginning of
719 a line. If the line seems to have the form '# 123 filename'
720 .line and .file directives will appear in the pre-processed output. */
721 /* Note that input_file.c hand checks for '#' at the beginning of the
722 first line of the input file. This is because the compiler outputs
723 #NO_APP at the beginning of its output. */
724 /* Also note that comments like this one will always work. */
725 const char line_comment_chars[] = "#";
726
727 const char line_separator_chars[] = ";";
728
729 /* Chars that can be used to separate mant
730 from exp in floating point numbers. */
731 const char EXP_CHARS[] = "eE";
732
733 /* Chars that mean this number is a floating point constant. */
734 /* As in 0f12.456 */
735 /* or 0d1.2345e12 */
736
737 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
738
739 /* Prefix characters that indicate the start of an immediate
740 value. */
741 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
742
743 /* Separator character handling. */
744
745 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
746
747 static inline int
748 skip_past_char (char ** str, char c)
749 {
750 if (**str == c)
751 {
752 (*str)++;
753 return SUCCESS;
754 }
755 else
756 return FAIL;
757 }
758 #define skip_past_comma(str) skip_past_char (str, ',')
759
760 /* Arithmetic expressions (possibly involving symbols). */
761
762 /* Return TRUE if anything in the expression is a bignum. */
763
764 static int
765 walk_no_bignums (symbolS * sp)
766 {
767 if (symbol_get_value_expression (sp)->X_op == O_big)
768 return 1;
769
770 if (symbol_get_value_expression (sp)->X_add_symbol)
771 {
772 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
773 || (symbol_get_value_expression (sp)->X_op_symbol
774 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
775 }
776
777 return 0;
778 }
779
780 static int in_my_get_expression = 0;
781
782 /* Third argument to my_get_expression. */
783 #define GE_NO_PREFIX 0
784 #define GE_IMM_PREFIX 1
785 #define GE_OPT_PREFIX 2
786 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
787 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
788 #define GE_OPT_PREFIX_BIG 3
789
790 static int
791 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
792 {
793 char * save_in;
794 segT seg;
795
796 /* In unified syntax, all prefixes are optional. */
797 if (unified_syntax)
798 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
799 : GE_OPT_PREFIX;
800
801 switch (prefix_mode)
802 {
803 case GE_NO_PREFIX: break;
804 case GE_IMM_PREFIX:
805 if (!is_immediate_prefix (**str))
806 {
807 inst.error = _("immediate expression requires a # prefix");
808 return FAIL;
809 }
810 (*str)++;
811 break;
812 case GE_OPT_PREFIX:
813 case GE_OPT_PREFIX_BIG:
814 if (is_immediate_prefix (**str))
815 (*str)++;
816 break;
817 default: abort ();
818 }
819
820 memset (ep, 0, sizeof (expressionS));
821
822 save_in = input_line_pointer;
823 input_line_pointer = *str;
824 in_my_get_expression = 1;
825 seg = expression (ep);
826 in_my_get_expression = 0;
827
828 if (ep->X_op == O_illegal)
829 {
830 /* We found a bad expression in md_operand(). */
831 *str = input_line_pointer;
832 input_line_pointer = save_in;
833 if (inst.error == NULL)
834 inst.error = _("bad expression");
835 return 1;
836 }
837
838 #ifdef OBJ_AOUT
839 if (seg != absolute_section
840 && seg != text_section
841 && seg != data_section
842 && seg != bss_section
843 && seg != undefined_section)
844 {
845 inst.error = _("bad segment");
846 *str = input_line_pointer;
847 input_line_pointer = save_in;
848 return 1;
849 }
850 #endif
851
852 /* Get rid of any bignums now, so that we don't generate an error for which
853 we can't establish a line number later on. Big numbers are never valid
854 in instructions, which is where this routine is always called. */
855 if (prefix_mode != GE_OPT_PREFIX_BIG
856 && (ep->X_op == O_big
857 || (ep->X_add_symbol
858 && (walk_no_bignums (ep->X_add_symbol)
859 || (ep->X_op_symbol
860 && walk_no_bignums (ep->X_op_symbol))))))
861 {
862 inst.error = _("invalid constant");
863 *str = input_line_pointer;
864 input_line_pointer = save_in;
865 return 1;
866 }
867
868 *str = input_line_pointer;
869 input_line_pointer = save_in;
870 return 0;
871 }
872
873 /* Turn a string in input_line_pointer into a floating point constant
874 of type TYPE, and store the appropriate bytes in *LITP. The number
875 of LITTLENUMS emitted is stored in *SIZEP. An error message is
876 returned, or NULL on OK.
877
878 Note that fp constants aren't represent in the normal way on the ARM.
879 In big endian mode, things are as expected. However, in little endian
880 mode fp constants are big-endian word-wise, and little-endian byte-wise
881 within the words. For example, (double) 1.1 in big endian mode is
882 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
883 the byte sequence 99 99 f1 3f 9a 99 99 99.
884
885 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
886
887 char *
888 md_atof (int type, char * litP, int * sizeP)
889 {
890 int prec;
891 LITTLENUM_TYPE words[MAX_LITTLENUMS];
892 char *t;
893 int i;
894
895 switch (type)
896 {
897 case 'f':
898 case 'F':
899 case 's':
900 case 'S':
901 prec = 2;
902 break;
903
904 case 'd':
905 case 'D':
906 case 'r':
907 case 'R':
908 prec = 4;
909 break;
910
911 case 'x':
912 case 'X':
913 prec = 5;
914 break;
915
916 case 'p':
917 case 'P':
918 prec = 5;
919 break;
920
921 default:
922 *sizeP = 0;
923 return _("Unrecognized or unsupported floating point constant");
924 }
925
926 t = atof_ieee (input_line_pointer, type, words);
927 if (t)
928 input_line_pointer = t;
929 *sizeP = prec * sizeof (LITTLENUM_TYPE);
930
931 if (target_big_endian)
932 {
933 for (i = 0; i < prec; i++)
934 {
935 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
936 litP += sizeof (LITTLENUM_TYPE);
937 }
938 }
939 else
940 {
941 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
942 for (i = prec - 1; i >= 0; i--)
943 {
944 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
945 litP += sizeof (LITTLENUM_TYPE);
946 }
947 else
948 /* For a 4 byte float the order of elements in `words' is 1 0.
949 For an 8 byte float the order is 1 0 3 2. */
950 for (i = 0; i < prec; i += 2)
951 {
952 md_number_to_chars (litP, (valueT) words[i + 1],
953 sizeof (LITTLENUM_TYPE));
954 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
955 (valueT) words[i], sizeof (LITTLENUM_TYPE));
956 litP += 2 * sizeof (LITTLENUM_TYPE);
957 }
958 }
959
960 return NULL;
961 }
962
963 /* We handle all bad expressions here, so that we can report the faulty
964 instruction in the error message. */
965 void
966 md_operand (expressionS * expr)
967 {
968 if (in_my_get_expression)
969 expr->X_op = O_illegal;
970 }
971
972 /* Immediate values. */
973
974 /* Generic immediate-value read function for use in directives.
975 Accepts anything that 'expression' can fold to a constant.
976 *val receives the number. */
977 #ifdef OBJ_ELF
978 static int
979 immediate_for_directive (int *val)
980 {
981 expressionS exp;
982 exp.X_op = O_illegal;
983
984 if (is_immediate_prefix (*input_line_pointer))
985 {
986 input_line_pointer++;
987 expression (&exp);
988 }
989
990 if (exp.X_op != O_constant)
991 {
992 as_bad (_("expected #constant"));
993 ignore_rest_of_line ();
994 return FAIL;
995 }
996 *val = exp.X_add_number;
997 return SUCCESS;
998 }
999 #endif
1000
1001 /* Register parsing. */
1002
1003 /* Generic register parser. CCP points to what should be the
1004 beginning of a register name. If it is indeed a valid register
1005 name, advance CCP over it and return the reg_entry structure;
1006 otherwise return NULL. Does not issue diagnostics. */
1007
1008 static struct reg_entry *
1009 arm_reg_parse_multi (char **ccp)
1010 {
1011 char *start = *ccp;
1012 char *p;
1013 struct reg_entry *reg;
1014
1015 #ifdef REGISTER_PREFIX
1016 if (*start != REGISTER_PREFIX)
1017 return NULL;
1018 start++;
1019 #endif
1020 #ifdef OPTIONAL_REGISTER_PREFIX
1021 if (*start == OPTIONAL_REGISTER_PREFIX)
1022 start++;
1023 #endif
1024
1025 p = start;
1026 if (!ISALPHA (*p) || !is_name_beginner (*p))
1027 return NULL;
1028
1029 do
1030 p++;
1031 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1032
1033 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1034
1035 if (!reg)
1036 return NULL;
1037
1038 *ccp = p;
1039 return reg;
1040 }
1041
1042 static int
1043 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1044 enum arm_reg_type type)
1045 {
1046 /* Alternative syntaxes are accepted for a few register classes. */
1047 switch (type)
1048 {
1049 case REG_TYPE_MVF:
1050 case REG_TYPE_MVD:
1051 case REG_TYPE_MVFX:
1052 case REG_TYPE_MVDX:
1053 /* Generic coprocessor register names are allowed for these. */
1054 if (reg && reg->type == REG_TYPE_CN)
1055 return reg->number;
1056 break;
1057
1058 case REG_TYPE_CP:
1059 /* For backward compatibility, a bare number is valid here. */
1060 {
1061 unsigned long processor = strtoul (start, ccp, 10);
1062 if (*ccp != start && processor <= 15)
1063 return processor;
1064 }
1065
1066 case REG_TYPE_MMXWC:
1067 /* WC includes WCG. ??? I'm not sure this is true for all
1068 instructions that take WC registers. */
1069 if (reg && reg->type == REG_TYPE_MMXWCG)
1070 return reg->number;
1071 break;
1072
1073 default:
1074 break;
1075 }
1076
1077 return FAIL;
1078 }
1079
1080 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1081 return value is the register number or FAIL. */
1082
1083 static int
1084 arm_reg_parse (char **ccp, enum arm_reg_type type)
1085 {
1086 char *start = *ccp;
1087 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1088 int ret;
1089
1090 /* Do not allow a scalar (reg+index) to parse as a register. */
1091 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1092 return FAIL;
1093
1094 if (reg && reg->type == type)
1095 return reg->number;
1096
1097 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1098 return ret;
1099
1100 *ccp = start;
1101 return FAIL;
1102 }
1103
1104 /* Parse a Neon type specifier. *STR should point at the leading '.'
1105 character. Does no verification at this stage that the type fits the opcode
1106 properly. E.g.,
1107
1108 .i32.i32.s16
1109 .s32.f32
1110 .u16
1111
1112 Can all be legally parsed by this function.
1113
1114 Fills in neon_type struct pointer with parsed information, and updates STR
1115 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1116 type, FAIL if not. */
1117
1118 static int
1119 parse_neon_type (struct neon_type *type, char **str)
1120 {
1121 char *ptr = *str;
1122
1123 if (type)
1124 type->elems = 0;
1125
1126 while (type->elems < NEON_MAX_TYPE_ELS)
1127 {
1128 enum neon_el_type thistype = NT_untyped;
1129 unsigned thissize = -1u;
1130
1131 if (*ptr != '.')
1132 break;
1133
1134 ptr++;
1135
1136 /* Just a size without an explicit type. */
1137 if (ISDIGIT (*ptr))
1138 goto parsesize;
1139
1140 switch (TOLOWER (*ptr))
1141 {
1142 case 'i': thistype = NT_integer; break;
1143 case 'f': thistype = NT_float; break;
1144 case 'p': thistype = NT_poly; break;
1145 case 's': thistype = NT_signed; break;
1146 case 'u': thistype = NT_unsigned; break;
1147 case 'd':
1148 thistype = NT_float;
1149 thissize = 64;
1150 ptr++;
1151 goto done;
1152 default:
1153 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1154 return FAIL;
1155 }
1156
1157 ptr++;
1158
1159 /* .f is an abbreviation for .f32. */
1160 if (thistype == NT_float && !ISDIGIT (*ptr))
1161 thissize = 32;
1162 else
1163 {
1164 parsesize:
1165 thissize = strtoul (ptr, &ptr, 10);
1166
1167 if (thissize != 8 && thissize != 16 && thissize != 32
1168 && thissize != 64)
1169 {
1170 as_bad (_("bad size %d in type specifier"), thissize);
1171 return FAIL;
1172 }
1173 }
1174
1175 done:
1176 if (type)
1177 {
1178 type->el[type->elems].type = thistype;
1179 type->el[type->elems].size = thissize;
1180 type->elems++;
1181 }
1182 }
1183
1184 /* Empty/missing type is not a successful parse. */
1185 if (type->elems == 0)
1186 return FAIL;
1187
1188 *str = ptr;
1189
1190 return SUCCESS;
1191 }
1192
1193 /* Errors may be set multiple times during parsing or bit encoding
1194 (particularly in the Neon bits), but usually the earliest error which is set
1195 will be the most meaningful. Avoid overwriting it with later (cascading)
1196 errors by calling this function. */
1197
1198 static void
1199 first_error (const char *err)
1200 {
1201 if (!inst.error)
1202 inst.error = err;
1203 }
1204
1205 /* Parse a single type, e.g. ".s32", leading period included. */
1206 static int
1207 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1208 {
1209 char *str = *ccp;
1210 struct neon_type optype;
1211
1212 if (*str == '.')
1213 {
1214 if (parse_neon_type (&optype, &str) == SUCCESS)
1215 {
1216 if (optype.elems == 1)
1217 *vectype = optype.el[0];
1218 else
1219 {
1220 first_error (_("only one type should be specified for operand"));
1221 return FAIL;
1222 }
1223 }
1224 else
1225 {
1226 first_error (_("vector type expected"));
1227 return FAIL;
1228 }
1229 }
1230 else
1231 return FAIL;
1232
1233 *ccp = str;
1234
1235 return SUCCESS;
1236 }
1237
1238 /* Special meanings for indices (which have a range of 0-7), which will fit into
1239 a 4-bit integer. */
1240
1241 #define NEON_ALL_LANES 15
1242 #define NEON_INTERLEAVE_LANES 14
1243
1244 /* Parse either a register or a scalar, with an optional type. Return the
1245 register number, and optionally fill in the actual type of the register
1246 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1247 type/index information in *TYPEINFO. */
1248
1249 static int
1250 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1251 enum arm_reg_type *rtype,
1252 struct neon_typed_alias *typeinfo)
1253 {
1254 char *str = *ccp;
1255 struct reg_entry *reg = arm_reg_parse_multi (&str);
1256 struct neon_typed_alias atype;
1257 struct neon_type_el parsetype;
1258
1259 atype.defined = 0;
1260 atype.index = -1;
1261 atype.eltype.type = NT_invtype;
1262 atype.eltype.size = -1;
1263
1264 /* Try alternate syntax for some types of register. Note these are mutually
1265 exclusive with the Neon syntax extensions. */
1266 if (reg == NULL)
1267 {
1268 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1269 if (altreg != FAIL)
1270 *ccp = str;
1271 if (typeinfo)
1272 *typeinfo = atype;
1273 return altreg;
1274 }
1275
1276 /* Undo polymorphism when a set of register types may be accepted. */
1277 if ((type == REG_TYPE_NDQ
1278 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1279 || (type == REG_TYPE_VFSD
1280 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1281 || (type == REG_TYPE_NSDQ
1282 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1283 || reg->type == REG_TYPE_NQ))
1284 || (type == REG_TYPE_MMXWC
1285 && (reg->type == REG_TYPE_MMXWCG)))
1286 type = reg->type;
1287
1288 if (type != reg->type)
1289 return FAIL;
1290
1291 if (reg->neon)
1292 atype = *reg->neon;
1293
1294 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1295 {
1296 if ((atype.defined & NTA_HASTYPE) != 0)
1297 {
1298 first_error (_("can't redefine type for operand"));
1299 return FAIL;
1300 }
1301 atype.defined |= NTA_HASTYPE;
1302 atype.eltype = parsetype;
1303 }
1304
1305 if (skip_past_char (&str, '[') == SUCCESS)
1306 {
1307 if (type != REG_TYPE_VFD)
1308 {
1309 first_error (_("only D registers may be indexed"));
1310 return FAIL;
1311 }
1312
1313 if ((atype.defined & NTA_HASINDEX) != 0)
1314 {
1315 first_error (_("can't change index for operand"));
1316 return FAIL;
1317 }
1318
1319 atype.defined |= NTA_HASINDEX;
1320
1321 if (skip_past_char (&str, ']') == SUCCESS)
1322 atype.index = NEON_ALL_LANES;
1323 else
1324 {
1325 expressionS exp;
1326
1327 my_get_expression (&exp, &str, GE_NO_PREFIX);
1328
1329 if (exp.X_op != O_constant)
1330 {
1331 first_error (_("constant expression required"));
1332 return FAIL;
1333 }
1334
1335 if (skip_past_char (&str, ']') == FAIL)
1336 return FAIL;
1337
1338 atype.index = exp.X_add_number;
1339 }
1340 }
1341
1342 if (typeinfo)
1343 *typeinfo = atype;
1344
1345 if (rtype)
1346 *rtype = type;
1347
1348 *ccp = str;
1349
1350 return reg->number;
1351 }
1352
1353 /* Like arm_reg_parse, but allow allow the following extra features:
1354 - If RTYPE is non-zero, return the (possibly restricted) type of the
1355 register (e.g. Neon double or quad reg when either has been requested).
1356 - If this is a Neon vector type with additional type information, fill
1357 in the struct pointed to by VECTYPE (if non-NULL).
1358 This function will fault on encountering a scalar. */
1359
1360 static int
1361 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1362 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1363 {
1364 struct neon_typed_alias atype;
1365 char *str = *ccp;
1366 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1367
1368 if (reg == FAIL)
1369 return FAIL;
1370
1371 /* Do not allow a scalar (reg+index) to parse as a register. */
1372 if ((atype.defined & NTA_HASINDEX) != 0)
1373 {
1374 first_error (_("register operand expected, but got scalar"));
1375 return FAIL;
1376 }
1377
1378 if (vectype)
1379 *vectype = atype.eltype;
1380
1381 *ccp = str;
1382
1383 return reg;
1384 }
1385
1386 #define NEON_SCALAR_REG(X) ((X) >> 4)
1387 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1388
1389 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1390 have enough information to be able to do a good job bounds-checking. So, we
1391 just do easy checks here, and do further checks later. */
1392
1393 static int
1394 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1395 {
1396 int reg;
1397 char *str = *ccp;
1398 struct neon_typed_alias atype;
1399
1400 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
1401
1402 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1403 return FAIL;
1404
1405 if (atype.index == NEON_ALL_LANES)
1406 {
1407 first_error (_("scalar must have an index"));
1408 return FAIL;
1409 }
1410 else if (atype.index >= 64 / elsize)
1411 {
1412 first_error (_("scalar index out of range"));
1413 return FAIL;
1414 }
1415
1416 if (type)
1417 *type = atype.eltype;
1418
1419 *ccp = str;
1420
1421 return reg * 16 + atype.index;
1422 }
1423
1424 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1425 static long
1426 parse_reg_list (char ** strp)
1427 {
1428 char * str = * strp;
1429 long range = 0;
1430 int another_range;
1431
1432 /* We come back here if we get ranges concatenated by '+' or '|'. */
1433 do
1434 {
1435 another_range = 0;
1436
1437 if (*str == '{')
1438 {
1439 int in_range = 0;
1440 int cur_reg = -1;
1441
1442 str++;
1443 do
1444 {
1445 int reg;
1446
1447 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1448 {
1449 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
1450 return FAIL;
1451 }
1452
1453 if (in_range)
1454 {
1455 int i;
1456
1457 if (reg <= cur_reg)
1458 {
1459 first_error (_("bad range in register list"));
1460 return FAIL;
1461 }
1462
1463 for (i = cur_reg + 1; i < reg; i++)
1464 {
1465 if (range & (1 << i))
1466 as_tsktsk
1467 (_("Warning: duplicated register (r%d) in register list"),
1468 i);
1469 else
1470 range |= 1 << i;
1471 }
1472 in_range = 0;
1473 }
1474
1475 if (range & (1 << reg))
1476 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1477 reg);
1478 else if (reg <= cur_reg)
1479 as_tsktsk (_("Warning: register range not in ascending order"));
1480
1481 range |= 1 << reg;
1482 cur_reg = reg;
1483 }
1484 while (skip_past_comma (&str) != FAIL
1485 || (in_range = 1, *str++ == '-'));
1486 str--;
1487
1488 if (*str++ != '}')
1489 {
1490 first_error (_("missing `}'"));
1491 return FAIL;
1492 }
1493 }
1494 else
1495 {
1496 expressionS expr;
1497
1498 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1499 return FAIL;
1500
1501 if (expr.X_op == O_constant)
1502 {
1503 if (expr.X_add_number
1504 != (expr.X_add_number & 0x0000ffff))
1505 {
1506 inst.error = _("invalid register mask");
1507 return FAIL;
1508 }
1509
1510 if ((range & expr.X_add_number) != 0)
1511 {
1512 int regno = range & expr.X_add_number;
1513
1514 regno &= -regno;
1515 regno = (1 << regno) - 1;
1516 as_tsktsk
1517 (_("Warning: duplicated register (r%d) in register list"),
1518 regno);
1519 }
1520
1521 range |= expr.X_add_number;
1522 }
1523 else
1524 {
1525 if (inst.reloc.type != 0)
1526 {
1527 inst.error = _("expression too complex");
1528 return FAIL;
1529 }
1530
1531 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1532 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1533 inst.reloc.pc_rel = 0;
1534 }
1535 }
1536
1537 if (*str == '|' || *str == '+')
1538 {
1539 str++;
1540 another_range = 1;
1541 }
1542 }
1543 while (another_range);
1544
1545 *strp = str;
1546 return range;
1547 }
1548
1549 /* Types of registers in a list. */
1550
1551 enum reg_list_els
1552 {
1553 REGLIST_VFP_S,
1554 REGLIST_VFP_D,
1555 REGLIST_NEON_D
1556 };
1557
1558 /* Parse a VFP register list. If the string is invalid return FAIL.
1559 Otherwise return the number of registers, and set PBASE to the first
1560 register. Parses registers of type ETYPE.
1561 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1562 - Q registers can be used to specify pairs of D registers
1563 - { } can be omitted from around a singleton register list
1564 FIXME: This is not implemented, as it would require backtracking in
1565 some cases, e.g.:
1566 vtbl.8 d3,d4,d5
1567 This could be done (the meaning isn't really ambiguous), but doesn't
1568 fit in well with the current parsing framework.
1569 - 32 D registers may be used (also true for VFPv3).
1570 FIXME: Types are ignored in these register lists, which is probably a
1571 bug. */
1572
1573 static int
1574 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
1575 {
1576 char *str = *ccp;
1577 int base_reg;
1578 int new_base;
1579 enum arm_reg_type regtype = 0;
1580 int max_regs = 0;
1581 int count = 0;
1582 int warned = 0;
1583 unsigned long mask = 0;
1584 int i;
1585
1586 if (*str != '{')
1587 {
1588 inst.error = _("expecting {");
1589 return FAIL;
1590 }
1591
1592 str++;
1593
1594 switch (etype)
1595 {
1596 case REGLIST_VFP_S:
1597 regtype = REG_TYPE_VFS;
1598 max_regs = 32;
1599 break;
1600
1601 case REGLIST_VFP_D:
1602 regtype = REG_TYPE_VFD;
1603 break;
1604
1605 case REGLIST_NEON_D:
1606 regtype = REG_TYPE_NDQ;
1607 break;
1608 }
1609
1610 if (etype != REGLIST_VFP_S)
1611 {
1612 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1613 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
1614 {
1615 max_regs = 32;
1616 if (thumb_mode)
1617 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1618 fpu_vfp_ext_d32);
1619 else
1620 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1621 fpu_vfp_ext_d32);
1622 }
1623 else
1624 max_regs = 16;
1625 }
1626
1627 base_reg = max_regs;
1628
1629 do
1630 {
1631 int setmask = 1, addregs = 1;
1632
1633 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
1634
1635 if (new_base == FAIL)
1636 {
1637 first_error (_(reg_expected_msgs[regtype]));
1638 return FAIL;
1639 }
1640
1641 if (new_base >= max_regs)
1642 {
1643 first_error (_("register out of range in list"));
1644 return FAIL;
1645 }
1646
1647 /* Note: a value of 2 * n is returned for the register Q<n>. */
1648 if (regtype == REG_TYPE_NQ)
1649 {
1650 setmask = 3;
1651 addregs = 2;
1652 }
1653
1654 if (new_base < base_reg)
1655 base_reg = new_base;
1656
1657 if (mask & (setmask << new_base))
1658 {
1659 first_error (_("invalid register list"));
1660 return FAIL;
1661 }
1662
1663 if ((mask >> new_base) != 0 && ! warned)
1664 {
1665 as_tsktsk (_("register list not in ascending order"));
1666 warned = 1;
1667 }
1668
1669 mask |= setmask << new_base;
1670 count += addregs;
1671
1672 if (*str == '-') /* We have the start of a range expression */
1673 {
1674 int high_range;
1675
1676 str++;
1677
1678 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
1679 == FAIL)
1680 {
1681 inst.error = gettext (reg_expected_msgs[regtype]);
1682 return FAIL;
1683 }
1684
1685 if (high_range >= max_regs)
1686 {
1687 first_error (_("register out of range in list"));
1688 return FAIL;
1689 }
1690
1691 if (regtype == REG_TYPE_NQ)
1692 high_range = high_range + 1;
1693
1694 if (high_range <= new_base)
1695 {
1696 inst.error = _("register range not in ascending order");
1697 return FAIL;
1698 }
1699
1700 for (new_base += addregs; new_base <= high_range; new_base += addregs)
1701 {
1702 if (mask & (setmask << new_base))
1703 {
1704 inst.error = _("invalid register list");
1705 return FAIL;
1706 }
1707
1708 mask |= setmask << new_base;
1709 count += addregs;
1710 }
1711 }
1712 }
1713 while (skip_past_comma (&str) != FAIL);
1714
1715 str++;
1716
1717 /* Sanity check -- should have raised a parse error above. */
1718 if (count == 0 || count > max_regs)
1719 abort ();
1720
1721 *pbase = base_reg;
1722
1723 /* Final test -- the registers must be consecutive. */
1724 mask >>= base_reg;
1725 for (i = 0; i < count; i++)
1726 {
1727 if ((mask & (1u << i)) == 0)
1728 {
1729 inst.error = _("non-contiguous register range");
1730 return FAIL;
1731 }
1732 }
1733
1734 *ccp = str;
1735
1736 return count;
1737 }
1738
1739 /* True if two alias types are the same. */
1740
1741 static int
1742 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1743 {
1744 if (!a && !b)
1745 return 1;
1746
1747 if (!a || !b)
1748 return 0;
1749
1750 if (a->defined != b->defined)
1751 return 0;
1752
1753 if ((a->defined & NTA_HASTYPE) != 0
1754 && (a->eltype.type != b->eltype.type
1755 || a->eltype.size != b->eltype.size))
1756 return 0;
1757
1758 if ((a->defined & NTA_HASINDEX) != 0
1759 && (a->index != b->index))
1760 return 0;
1761
1762 return 1;
1763 }
1764
1765 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1766 The base register is put in *PBASE.
1767 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
1768 the return value.
1769 The register stride (minus one) is put in bit 4 of the return value.
1770 Bits [6:5] encode the list length (minus one).
1771 The type of the list elements is put in *ELTYPE, if non-NULL. */
1772
1773 #define NEON_LANE(X) ((X) & 0xf)
1774 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
1775 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1776
1777 static int
1778 parse_neon_el_struct_list (char **str, unsigned *pbase,
1779 struct neon_type_el *eltype)
1780 {
1781 char *ptr = *str;
1782 int base_reg = -1;
1783 int reg_incr = -1;
1784 int count = 0;
1785 int lane = -1;
1786 int leading_brace = 0;
1787 enum arm_reg_type rtype = REG_TYPE_NDQ;
1788 int addregs = 1;
1789 const char *const incr_error = "register stride must be 1 or 2";
1790 const char *const type_error = "mismatched element/structure types in list";
1791 struct neon_typed_alias firsttype;
1792
1793 if (skip_past_char (&ptr, '{') == SUCCESS)
1794 leading_brace = 1;
1795
1796 do
1797 {
1798 struct neon_typed_alias atype;
1799 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1800
1801 if (getreg == FAIL)
1802 {
1803 first_error (_(reg_expected_msgs[rtype]));
1804 return FAIL;
1805 }
1806
1807 if (base_reg == -1)
1808 {
1809 base_reg = getreg;
1810 if (rtype == REG_TYPE_NQ)
1811 {
1812 reg_incr = 1;
1813 addregs = 2;
1814 }
1815 firsttype = atype;
1816 }
1817 else if (reg_incr == -1)
1818 {
1819 reg_incr = getreg - base_reg;
1820 if (reg_incr < 1 || reg_incr > 2)
1821 {
1822 first_error (_(incr_error));
1823 return FAIL;
1824 }
1825 }
1826 else if (getreg != base_reg + reg_incr * count)
1827 {
1828 first_error (_(incr_error));
1829 return FAIL;
1830 }
1831
1832 if (!neon_alias_types_same (&atype, &firsttype))
1833 {
1834 first_error (_(type_error));
1835 return FAIL;
1836 }
1837
1838 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1839 modes. */
1840 if (ptr[0] == '-')
1841 {
1842 struct neon_typed_alias htype;
1843 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1844 if (lane == -1)
1845 lane = NEON_INTERLEAVE_LANES;
1846 else if (lane != NEON_INTERLEAVE_LANES)
1847 {
1848 first_error (_(type_error));
1849 return FAIL;
1850 }
1851 if (reg_incr == -1)
1852 reg_incr = 1;
1853 else if (reg_incr != 1)
1854 {
1855 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
1856 return FAIL;
1857 }
1858 ptr++;
1859 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
1860 if (hireg == FAIL)
1861 {
1862 first_error (_(reg_expected_msgs[rtype]));
1863 return FAIL;
1864 }
1865 if (!neon_alias_types_same (&htype, &firsttype))
1866 {
1867 first_error (_(type_error));
1868 return FAIL;
1869 }
1870 count += hireg + dregs - getreg;
1871 continue;
1872 }
1873
1874 /* If we're using Q registers, we can't use [] or [n] syntax. */
1875 if (rtype == REG_TYPE_NQ)
1876 {
1877 count += 2;
1878 continue;
1879 }
1880
1881 if ((atype.defined & NTA_HASINDEX) != 0)
1882 {
1883 if (lane == -1)
1884 lane = atype.index;
1885 else if (lane != atype.index)
1886 {
1887 first_error (_(type_error));
1888 return FAIL;
1889 }
1890 }
1891 else if (lane == -1)
1892 lane = NEON_INTERLEAVE_LANES;
1893 else if (lane != NEON_INTERLEAVE_LANES)
1894 {
1895 first_error (_(type_error));
1896 return FAIL;
1897 }
1898 count++;
1899 }
1900 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
1901
1902 /* No lane set by [x]. We must be interleaving structures. */
1903 if (lane == -1)
1904 lane = NEON_INTERLEAVE_LANES;
1905
1906 /* Sanity check. */
1907 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
1908 || (count > 1 && reg_incr == -1))
1909 {
1910 first_error (_("error parsing element/structure list"));
1911 return FAIL;
1912 }
1913
1914 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
1915 {
1916 first_error (_("expected }"));
1917 return FAIL;
1918 }
1919
1920 if (reg_incr == -1)
1921 reg_incr = 1;
1922
1923 if (eltype)
1924 *eltype = firsttype.eltype;
1925
1926 *pbase = base_reg;
1927 *str = ptr;
1928
1929 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
1930 }
1931
1932 /* Parse an explicit relocation suffix on an expression. This is
1933 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1934 arm_reloc_hsh contains no entries, so this function can only
1935 succeed if there is no () after the word. Returns -1 on error,
1936 BFD_RELOC_UNUSED if there wasn't any suffix. */
1937 static int
1938 parse_reloc (char **str)
1939 {
1940 struct reloc_entry *r;
1941 char *p, *q;
1942
1943 if (**str != '(')
1944 return BFD_RELOC_UNUSED;
1945
1946 p = *str + 1;
1947 q = p;
1948
1949 while (*q && *q != ')' && *q != ',')
1950 q++;
1951 if (*q != ')')
1952 return -1;
1953
1954 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1955 return -1;
1956
1957 *str = q + 1;
1958 return r->reloc;
1959 }
1960
1961 /* Directives: register aliases. */
1962
1963 static struct reg_entry *
1964 insert_reg_alias (char *str, int number, int type)
1965 {
1966 struct reg_entry *new;
1967 const char *name;
1968
1969 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1970 {
1971 if (new->builtin)
1972 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
1973
1974 /* Only warn about a redefinition if it's not defined as the
1975 same register. */
1976 else if (new->number != number || new->type != type)
1977 as_warn (_("ignoring redefinition of register alias '%s'"), str);
1978
1979 return NULL;
1980 }
1981
1982 name = xstrdup (str);
1983 new = xmalloc (sizeof (struct reg_entry));
1984
1985 new->name = name;
1986 new->number = number;
1987 new->type = type;
1988 new->builtin = FALSE;
1989 new->neon = NULL;
1990
1991 if (hash_insert (arm_reg_hsh, name, (PTR) new))
1992 abort ();
1993
1994 return new;
1995 }
1996
1997 static void
1998 insert_neon_reg_alias (char *str, int number, int type,
1999 struct neon_typed_alias *atype)
2000 {
2001 struct reg_entry *reg = insert_reg_alias (str, number, type);
2002
2003 if (!reg)
2004 {
2005 first_error (_("attempt to redefine typed alias"));
2006 return;
2007 }
2008
2009 if (atype)
2010 {
2011 reg->neon = xmalloc (sizeof (struct neon_typed_alias));
2012 *reg->neon = *atype;
2013 }
2014 }
2015
2016 /* Look for the .req directive. This is of the form:
2017
2018 new_register_name .req existing_register_name
2019
2020 If we find one, or if it looks sufficiently like one that we want to
2021 handle any error here, return TRUE. Otherwise return FALSE. */
2022
2023 static bfd_boolean
2024 create_register_alias (char * newname, char *p)
2025 {
2026 struct reg_entry *old;
2027 char *oldname, *nbuf;
2028 size_t nlen;
2029
2030 /* The input scrubber ensures that whitespace after the mnemonic is
2031 collapsed to single spaces. */
2032 oldname = p;
2033 if (strncmp (oldname, " .req ", 6) != 0)
2034 return FALSE;
2035
2036 oldname += 6;
2037 if (*oldname == '\0')
2038 return FALSE;
2039
2040 old = hash_find (arm_reg_hsh, oldname);
2041 if (!old)
2042 {
2043 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2044 return TRUE;
2045 }
2046
2047 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2048 the desired alias name, and p points to its end. If not, then
2049 the desired alias name is in the global original_case_string. */
2050 #ifdef TC_CASE_SENSITIVE
2051 nlen = p - newname;
2052 #else
2053 newname = original_case_string;
2054 nlen = strlen (newname);
2055 #endif
2056
2057 nbuf = alloca (nlen + 1);
2058 memcpy (nbuf, newname, nlen);
2059 nbuf[nlen] = '\0';
2060
2061 /* Create aliases under the new name as stated; an all-lowercase
2062 version of the new name; and an all-uppercase version of the new
2063 name. */
2064 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2065 {
2066 for (p = nbuf; *p; p++)
2067 *p = TOUPPER (*p);
2068
2069 if (strncmp (nbuf, newname, nlen))
2070 {
2071 /* If this attempt to create an additional alias fails, do not bother
2072 trying to create the all-lower case alias. We will fail and issue
2073 a second, duplicate error message. This situation arises when the
2074 programmer does something like:
2075 foo .req r0
2076 Foo .req r1
2077 The second .req creates the "Foo" alias but then fails to create
2078 the artificial FOO alias because it has already been created by the
2079 first .req. */
2080 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2081 return TRUE;
2082 }
2083
2084 for (p = nbuf; *p; p++)
2085 *p = TOLOWER (*p);
2086
2087 if (strncmp (nbuf, newname, nlen))
2088 insert_reg_alias (nbuf, old->number, old->type);
2089 }
2090
2091 return TRUE;
2092 }
2093
2094 /* Create a Neon typed/indexed register alias using directives, e.g.:
2095 X .dn d5.s32[1]
2096 Y .qn 6.s16
2097 Z .dn d7
2098 T .dn Z[0]
2099 These typed registers can be used instead of the types specified after the
2100 Neon mnemonic, so long as all operands given have types. Types can also be
2101 specified directly, e.g.:
2102 vadd d0.s32, d1.s32, d2.s32 */
2103
2104 static int
2105 create_neon_reg_alias (char *newname, char *p)
2106 {
2107 enum arm_reg_type basetype;
2108 struct reg_entry *basereg;
2109 struct reg_entry mybasereg;
2110 struct neon_type ntype;
2111 struct neon_typed_alias typeinfo;
2112 char *namebuf, *nameend;
2113 int namelen;
2114
2115 typeinfo.defined = 0;
2116 typeinfo.eltype.type = NT_invtype;
2117 typeinfo.eltype.size = -1;
2118 typeinfo.index = -1;
2119
2120 nameend = p;
2121
2122 if (strncmp (p, " .dn ", 5) == 0)
2123 basetype = REG_TYPE_VFD;
2124 else if (strncmp (p, " .qn ", 5) == 0)
2125 basetype = REG_TYPE_NQ;
2126 else
2127 return 0;
2128
2129 p += 5;
2130
2131 if (*p == '\0')
2132 return 0;
2133
2134 basereg = arm_reg_parse_multi (&p);
2135
2136 if (basereg && basereg->type != basetype)
2137 {
2138 as_bad (_("bad type for register"));
2139 return 0;
2140 }
2141
2142 if (basereg == NULL)
2143 {
2144 expressionS exp;
2145 /* Try parsing as an integer. */
2146 my_get_expression (&exp, &p, GE_NO_PREFIX);
2147 if (exp.X_op != O_constant)
2148 {
2149 as_bad (_("expression must be constant"));
2150 return 0;
2151 }
2152 basereg = &mybasereg;
2153 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2154 : exp.X_add_number;
2155 basereg->neon = 0;
2156 }
2157
2158 if (basereg->neon)
2159 typeinfo = *basereg->neon;
2160
2161 if (parse_neon_type (&ntype, &p) == SUCCESS)
2162 {
2163 /* We got a type. */
2164 if (typeinfo.defined & NTA_HASTYPE)
2165 {
2166 as_bad (_("can't redefine the type of a register alias"));
2167 return 0;
2168 }
2169
2170 typeinfo.defined |= NTA_HASTYPE;
2171 if (ntype.elems != 1)
2172 {
2173 as_bad (_("you must specify a single type only"));
2174 return 0;
2175 }
2176 typeinfo.eltype = ntype.el[0];
2177 }
2178
2179 if (skip_past_char (&p, '[') == SUCCESS)
2180 {
2181 expressionS exp;
2182 /* We got a scalar index. */
2183
2184 if (typeinfo.defined & NTA_HASINDEX)
2185 {
2186 as_bad (_("can't redefine the index of a scalar alias"));
2187 return 0;
2188 }
2189
2190 my_get_expression (&exp, &p, GE_NO_PREFIX);
2191
2192 if (exp.X_op != O_constant)
2193 {
2194 as_bad (_("scalar index must be constant"));
2195 return 0;
2196 }
2197
2198 typeinfo.defined |= NTA_HASINDEX;
2199 typeinfo.index = exp.X_add_number;
2200
2201 if (skip_past_char (&p, ']') == FAIL)
2202 {
2203 as_bad (_("expecting ]"));
2204 return 0;
2205 }
2206 }
2207
2208 namelen = nameend - newname;
2209 namebuf = alloca (namelen + 1);
2210 strncpy (namebuf, newname, namelen);
2211 namebuf[namelen] = '\0';
2212
2213 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2214 typeinfo.defined != 0 ? &typeinfo : NULL);
2215
2216 /* Insert name in all uppercase. */
2217 for (p = namebuf; *p; p++)
2218 *p = TOUPPER (*p);
2219
2220 if (strncmp (namebuf, newname, namelen))
2221 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2222 typeinfo.defined != 0 ? &typeinfo : NULL);
2223
2224 /* Insert name in all lowercase. */
2225 for (p = namebuf; *p; p++)
2226 *p = TOLOWER (*p);
2227
2228 if (strncmp (namebuf, newname, namelen))
2229 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2230 typeinfo.defined != 0 ? &typeinfo : NULL);
2231
2232 return 1;
2233 }
2234
2235 /* Should never be called, as .req goes between the alias and the
2236 register name, not at the beginning of the line. */
2237 static void
2238 s_req (int a ATTRIBUTE_UNUSED)
2239 {
2240 as_bad (_("invalid syntax for .req directive"));
2241 }
2242
2243 static void
2244 s_dn (int a ATTRIBUTE_UNUSED)
2245 {
2246 as_bad (_("invalid syntax for .dn directive"));
2247 }
2248
2249 static void
2250 s_qn (int a ATTRIBUTE_UNUSED)
2251 {
2252 as_bad (_("invalid syntax for .qn directive"));
2253 }
2254
2255 /* The .unreq directive deletes an alias which was previously defined
2256 by .req. For example:
2257
2258 my_alias .req r11
2259 .unreq my_alias */
2260
2261 static void
2262 s_unreq (int a ATTRIBUTE_UNUSED)
2263 {
2264 char * name;
2265 char saved_char;
2266
2267 name = input_line_pointer;
2268
2269 while (*input_line_pointer != 0
2270 && *input_line_pointer != ' '
2271 && *input_line_pointer != '\n')
2272 ++input_line_pointer;
2273
2274 saved_char = *input_line_pointer;
2275 *input_line_pointer = 0;
2276
2277 if (!*name)
2278 as_bad (_("invalid syntax for .unreq directive"));
2279 else
2280 {
2281 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
2282
2283 if (!reg)
2284 as_bad (_("unknown register alias '%s'"), name);
2285 else if (reg->builtin)
2286 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2287 name);
2288 else
2289 {
2290 char * p;
2291 char * nbuf;
2292
2293 hash_delete (arm_reg_hsh, name);
2294 free ((char *) reg->name);
2295 if (reg->neon)
2296 free (reg->neon);
2297 free (reg);
2298
2299 /* Also locate the all upper case and all lower case versions.
2300 Do not complain if we cannot find one or the other as it
2301 was probably deleted above. */
2302
2303 nbuf = strdup (name);
2304 for (p = nbuf; *p; p++)
2305 *p = TOUPPER (*p);
2306 reg = hash_find (arm_reg_hsh, nbuf);
2307 if (reg)
2308 {
2309 hash_delete (arm_reg_hsh, nbuf);
2310 free ((char *) reg->name);
2311 if (reg->neon)
2312 free (reg->neon);
2313 free (reg);
2314 }
2315
2316 for (p = nbuf; *p; p++)
2317 *p = TOLOWER (*p);
2318 reg = hash_find (arm_reg_hsh, nbuf);
2319 if (reg)
2320 {
2321 hash_delete (arm_reg_hsh, nbuf);
2322 free ((char *) reg->name);
2323 if (reg->neon)
2324 free (reg->neon);
2325 free (reg);
2326 }
2327
2328 free (nbuf);
2329 }
2330 }
2331
2332 *input_line_pointer = saved_char;
2333 demand_empty_rest_of_line ();
2334 }
2335
2336 /* Directives: Instruction set selection. */
2337
2338 #ifdef OBJ_ELF
2339 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2340 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2341 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2342 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2343
2344 static enum mstate mapstate = MAP_UNDEFINED;
2345
2346 void
2347 mapping_state (enum mstate state)
2348 {
2349 symbolS * symbolP;
2350 const char * symname;
2351 int type;
2352
2353 if (mapstate == state)
2354 /* The mapping symbol has already been emitted.
2355 There is nothing else to do. */
2356 return;
2357
2358 mapstate = state;
2359
2360 switch (state)
2361 {
2362 case MAP_DATA:
2363 symname = "$d";
2364 type = BSF_NO_FLAGS;
2365 break;
2366 case MAP_ARM:
2367 symname = "$a";
2368 type = BSF_NO_FLAGS;
2369 break;
2370 case MAP_THUMB:
2371 symname = "$t";
2372 type = BSF_NO_FLAGS;
2373 break;
2374 case MAP_UNDEFINED:
2375 return;
2376 default:
2377 abort ();
2378 }
2379
2380 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2381
2382 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
2383 symbol_table_insert (symbolP);
2384 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2385
2386 switch (state)
2387 {
2388 case MAP_ARM:
2389 THUMB_SET_FUNC (symbolP, 0);
2390 ARM_SET_THUMB (symbolP, 0);
2391 ARM_SET_INTERWORK (symbolP, support_interwork);
2392 break;
2393
2394 case MAP_THUMB:
2395 THUMB_SET_FUNC (symbolP, 1);
2396 ARM_SET_THUMB (symbolP, 1);
2397 ARM_SET_INTERWORK (symbolP, support_interwork);
2398 break;
2399
2400 case MAP_DATA:
2401 default:
2402 return;
2403 }
2404 }
2405 #else
2406 #define mapping_state(x) /* nothing */
2407 #endif
2408
2409 /* Find the real, Thumb encoded start of a Thumb function. */
2410
2411 static symbolS *
2412 find_real_start (symbolS * symbolP)
2413 {
2414 char * real_start;
2415 const char * name = S_GET_NAME (symbolP);
2416 symbolS * new_target;
2417
2418 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2419 #define STUB_NAME ".real_start_of"
2420
2421 if (name == NULL)
2422 abort ();
2423
2424 /* The compiler may generate BL instructions to local labels because
2425 it needs to perform a branch to a far away location. These labels
2426 do not have a corresponding ".real_start_of" label. We check
2427 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2428 the ".real_start_of" convention for nonlocal branches. */
2429 if (S_IS_LOCAL (symbolP) || name[0] == '.')
2430 return symbolP;
2431
2432 real_start = ACONCAT ((STUB_NAME, name, NULL));
2433 new_target = symbol_find (real_start);
2434
2435 if (new_target == NULL)
2436 {
2437 as_warn (_("Failed to find real start of function: %s\n"), name);
2438 new_target = symbolP;
2439 }
2440
2441 return new_target;
2442 }
2443
2444 static void
2445 opcode_select (int width)
2446 {
2447 switch (width)
2448 {
2449 case 16:
2450 if (! thumb_mode)
2451 {
2452 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
2453 as_bad (_("selected processor does not support THUMB opcodes"));
2454
2455 thumb_mode = 1;
2456 /* No need to force the alignment, since we will have been
2457 coming from ARM mode, which is word-aligned. */
2458 record_alignment (now_seg, 1);
2459 }
2460 mapping_state (MAP_THUMB);
2461 break;
2462
2463 case 32:
2464 if (thumb_mode)
2465 {
2466 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
2467 as_bad (_("selected processor does not support ARM opcodes"));
2468
2469 thumb_mode = 0;
2470
2471 if (!need_pass_2)
2472 frag_align (2, 0, 0);
2473
2474 record_alignment (now_seg, 1);
2475 }
2476 mapping_state (MAP_ARM);
2477 break;
2478
2479 default:
2480 as_bad (_("invalid instruction size selected (%d)"), width);
2481 }
2482 }
2483
2484 static void
2485 s_arm (int ignore ATTRIBUTE_UNUSED)
2486 {
2487 opcode_select (32);
2488 demand_empty_rest_of_line ();
2489 }
2490
2491 static void
2492 s_thumb (int ignore ATTRIBUTE_UNUSED)
2493 {
2494 opcode_select (16);
2495 demand_empty_rest_of_line ();
2496 }
2497
2498 static void
2499 s_code (int unused ATTRIBUTE_UNUSED)
2500 {
2501 int temp;
2502
2503 temp = get_absolute_expression ();
2504 switch (temp)
2505 {
2506 case 16:
2507 case 32:
2508 opcode_select (temp);
2509 break;
2510
2511 default:
2512 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2513 }
2514 }
2515
2516 static void
2517 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2518 {
2519 /* If we are not already in thumb mode go into it, EVEN if
2520 the target processor does not support thumb instructions.
2521 This is used by gcc/config/arm/lib1funcs.asm for example
2522 to compile interworking support functions even if the
2523 target processor should not support interworking. */
2524 if (! thumb_mode)
2525 {
2526 thumb_mode = 2;
2527 record_alignment (now_seg, 1);
2528 }
2529
2530 demand_empty_rest_of_line ();
2531 }
2532
2533 static void
2534 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2535 {
2536 s_thumb (0);
2537
2538 /* The following label is the name/address of the start of a Thumb function.
2539 We need to know this for the interworking support. */
2540 label_is_thumb_function_name = TRUE;
2541 }
2542
2543 /* Perform a .set directive, but also mark the alias as
2544 being a thumb function. */
2545
2546 static void
2547 s_thumb_set (int equiv)
2548 {
2549 /* XXX the following is a duplicate of the code for s_set() in read.c
2550 We cannot just call that code as we need to get at the symbol that
2551 is created. */
2552 char * name;
2553 char delim;
2554 char * end_name;
2555 symbolS * symbolP;
2556
2557 /* Especial apologies for the random logic:
2558 This just grew, and could be parsed much more simply!
2559 Dean - in haste. */
2560 name = input_line_pointer;
2561 delim = get_symbol_end ();
2562 end_name = input_line_pointer;
2563 *end_name = delim;
2564
2565 if (*input_line_pointer != ',')
2566 {
2567 *end_name = 0;
2568 as_bad (_("expected comma after name \"%s\""), name);
2569 *end_name = delim;
2570 ignore_rest_of_line ();
2571 return;
2572 }
2573
2574 input_line_pointer++;
2575 *end_name = 0;
2576
2577 if (name[0] == '.' && name[1] == '\0')
2578 {
2579 /* XXX - this should not happen to .thumb_set. */
2580 abort ();
2581 }
2582
2583 if ((symbolP = symbol_find (name)) == NULL
2584 && (symbolP = md_undefined_symbol (name)) == NULL)
2585 {
2586 #ifndef NO_LISTING
2587 /* When doing symbol listings, play games with dummy fragments living
2588 outside the normal fragment chain to record the file and line info
2589 for this symbol. */
2590 if (listing & LISTING_SYMBOLS)
2591 {
2592 extern struct list_info_struct * listing_tail;
2593 fragS * dummy_frag = xmalloc (sizeof (fragS));
2594
2595 memset (dummy_frag, 0, sizeof (fragS));
2596 dummy_frag->fr_type = rs_fill;
2597 dummy_frag->line = listing_tail;
2598 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2599 dummy_frag->fr_symbol = symbolP;
2600 }
2601 else
2602 #endif
2603 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2604
2605 #ifdef OBJ_COFF
2606 /* "set" symbols are local unless otherwise specified. */
2607 SF_SET_LOCAL (symbolP);
2608 #endif /* OBJ_COFF */
2609 } /* Make a new symbol. */
2610
2611 symbol_table_insert (symbolP);
2612
2613 * end_name = delim;
2614
2615 if (equiv
2616 && S_IS_DEFINED (symbolP)
2617 && S_GET_SEGMENT (symbolP) != reg_section)
2618 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2619
2620 pseudo_set (symbolP);
2621
2622 demand_empty_rest_of_line ();
2623
2624 /* XXX Now we come to the Thumb specific bit of code. */
2625
2626 THUMB_SET_FUNC (symbolP, 1);
2627 ARM_SET_THUMB (symbolP, 1);
2628 #if defined OBJ_ELF || defined OBJ_COFF
2629 ARM_SET_INTERWORK (symbolP, support_interwork);
2630 #endif
2631 }
2632
2633 /* Directives: Mode selection. */
2634
2635 /* .syntax [unified|divided] - choose the new unified syntax
2636 (same for Arm and Thumb encoding, modulo slight differences in what
2637 can be represented) or the old divergent syntax for each mode. */
2638 static void
2639 s_syntax (int unused ATTRIBUTE_UNUSED)
2640 {
2641 char *name, delim;
2642
2643 name = input_line_pointer;
2644 delim = get_symbol_end ();
2645
2646 if (!strcasecmp (name, "unified"))
2647 unified_syntax = TRUE;
2648 else if (!strcasecmp (name, "divided"))
2649 unified_syntax = FALSE;
2650 else
2651 {
2652 as_bad (_("unrecognized syntax mode \"%s\""), name);
2653 return;
2654 }
2655 *input_line_pointer = delim;
2656 demand_empty_rest_of_line ();
2657 }
2658
2659 /* Directives: sectioning and alignment. */
2660
2661 /* Same as s_align_ptwo but align 0 => align 2. */
2662
2663 static void
2664 s_align (int unused ATTRIBUTE_UNUSED)
2665 {
2666 int temp;
2667 bfd_boolean fill_p;
2668 long temp_fill;
2669 long max_alignment = 15;
2670
2671 temp = get_absolute_expression ();
2672 if (temp > max_alignment)
2673 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2674 else if (temp < 0)
2675 {
2676 as_bad (_("alignment negative. 0 assumed."));
2677 temp = 0;
2678 }
2679
2680 if (*input_line_pointer == ',')
2681 {
2682 input_line_pointer++;
2683 temp_fill = get_absolute_expression ();
2684 fill_p = TRUE;
2685 }
2686 else
2687 {
2688 fill_p = FALSE;
2689 temp_fill = 0;
2690 }
2691
2692 if (!temp)
2693 temp = 2;
2694
2695 /* Only make a frag if we HAVE to. */
2696 if (temp && !need_pass_2)
2697 {
2698 if (!fill_p && subseg_text_p (now_seg))
2699 frag_align_code (temp, 0);
2700 else
2701 frag_align (temp, (int) temp_fill, 0);
2702 }
2703 demand_empty_rest_of_line ();
2704
2705 record_alignment (now_seg, temp);
2706 }
2707
2708 static void
2709 s_bss (int ignore ATTRIBUTE_UNUSED)
2710 {
2711 /* We don't support putting frags in the BSS segment, we fake it by
2712 marking in_bss, then looking at s_skip for clues. */
2713 subseg_set (bss_section, 0);
2714 demand_empty_rest_of_line ();
2715 mapping_state (MAP_DATA);
2716 }
2717
2718 static void
2719 s_even (int ignore ATTRIBUTE_UNUSED)
2720 {
2721 /* Never make frag if expect extra pass. */
2722 if (!need_pass_2)
2723 frag_align (1, 0, 0);
2724
2725 record_alignment (now_seg, 1);
2726
2727 demand_empty_rest_of_line ();
2728 }
2729
2730 /* Directives: Literal pools. */
2731
2732 static literal_pool *
2733 find_literal_pool (void)
2734 {
2735 literal_pool * pool;
2736
2737 for (pool = list_of_pools; pool != NULL; pool = pool->next)
2738 {
2739 if (pool->section == now_seg
2740 && pool->sub_section == now_subseg)
2741 break;
2742 }
2743
2744 return pool;
2745 }
2746
2747 static literal_pool *
2748 find_or_make_literal_pool (void)
2749 {
2750 /* Next literal pool ID number. */
2751 static unsigned int latest_pool_num = 1;
2752 literal_pool * pool;
2753
2754 pool = find_literal_pool ();
2755
2756 if (pool == NULL)
2757 {
2758 /* Create a new pool. */
2759 pool = xmalloc (sizeof (* pool));
2760 if (! pool)
2761 return NULL;
2762
2763 pool->next_free_entry = 0;
2764 pool->section = now_seg;
2765 pool->sub_section = now_subseg;
2766 pool->next = list_of_pools;
2767 pool->symbol = NULL;
2768
2769 /* Add it to the list. */
2770 list_of_pools = pool;
2771 }
2772
2773 /* New pools, and emptied pools, will have a NULL symbol. */
2774 if (pool->symbol == NULL)
2775 {
2776 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2777 (valueT) 0, &zero_address_frag);
2778 pool->id = latest_pool_num ++;
2779 }
2780
2781 /* Done. */
2782 return pool;
2783 }
2784
2785 /* Add the literal in the global 'inst'
2786 structure to the relevant literal pool. */
2787
2788 static int
2789 add_to_lit_pool (void)
2790 {
2791 literal_pool * pool;
2792 unsigned int entry;
2793
2794 pool = find_or_make_literal_pool ();
2795
2796 /* Check if this literal value is already in the pool. */
2797 for (entry = 0; entry < pool->next_free_entry; entry ++)
2798 {
2799 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2800 && (inst.reloc.exp.X_op == O_constant)
2801 && (pool->literals[entry].X_add_number
2802 == inst.reloc.exp.X_add_number)
2803 && (pool->literals[entry].X_unsigned
2804 == inst.reloc.exp.X_unsigned))
2805 break;
2806
2807 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2808 && (inst.reloc.exp.X_op == O_symbol)
2809 && (pool->literals[entry].X_add_number
2810 == inst.reloc.exp.X_add_number)
2811 && (pool->literals[entry].X_add_symbol
2812 == inst.reloc.exp.X_add_symbol)
2813 && (pool->literals[entry].X_op_symbol
2814 == inst.reloc.exp.X_op_symbol))
2815 break;
2816 }
2817
2818 /* Do we need to create a new entry? */
2819 if (entry == pool->next_free_entry)
2820 {
2821 if (entry >= MAX_LITERAL_POOL_SIZE)
2822 {
2823 inst.error = _("literal pool overflow");
2824 return FAIL;
2825 }
2826
2827 pool->literals[entry] = inst.reloc.exp;
2828 pool->next_free_entry += 1;
2829 }
2830
2831 inst.reloc.exp.X_op = O_symbol;
2832 inst.reloc.exp.X_add_number = ((int) entry) * 4;
2833 inst.reloc.exp.X_add_symbol = pool->symbol;
2834
2835 return SUCCESS;
2836 }
2837
2838 /* Can't use symbol_new here, so have to create a symbol and then at
2839 a later date assign it a value. Thats what these functions do. */
2840
2841 static void
2842 symbol_locate (symbolS * symbolP,
2843 const char * name, /* It is copied, the caller can modify. */
2844 segT segment, /* Segment identifier (SEG_<something>). */
2845 valueT valu, /* Symbol value. */
2846 fragS * frag) /* Associated fragment. */
2847 {
2848 unsigned int name_length;
2849 char * preserved_copy_of_name;
2850
2851 name_length = strlen (name) + 1; /* +1 for \0. */
2852 obstack_grow (&notes, name, name_length);
2853 preserved_copy_of_name = obstack_finish (&notes);
2854
2855 #ifdef tc_canonicalize_symbol_name
2856 preserved_copy_of_name =
2857 tc_canonicalize_symbol_name (preserved_copy_of_name);
2858 #endif
2859
2860 S_SET_NAME (symbolP, preserved_copy_of_name);
2861
2862 S_SET_SEGMENT (symbolP, segment);
2863 S_SET_VALUE (symbolP, valu);
2864 symbol_clear_list_pointers (symbolP);
2865
2866 symbol_set_frag (symbolP, frag);
2867
2868 /* Link to end of symbol chain. */
2869 {
2870 extern int symbol_table_frozen;
2871
2872 if (symbol_table_frozen)
2873 abort ();
2874 }
2875
2876 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
2877
2878 obj_symbol_new_hook (symbolP);
2879
2880 #ifdef tc_symbol_new_hook
2881 tc_symbol_new_hook (symbolP);
2882 #endif
2883
2884 #ifdef DEBUG_SYMS
2885 verify_symbol_chain (symbol_rootP, symbol_lastP);
2886 #endif /* DEBUG_SYMS */
2887 }
2888
2889
2890 static void
2891 s_ltorg (int ignored ATTRIBUTE_UNUSED)
2892 {
2893 unsigned int entry;
2894 literal_pool * pool;
2895 char sym_name[20];
2896
2897 pool = find_literal_pool ();
2898 if (pool == NULL
2899 || pool->symbol == NULL
2900 || pool->next_free_entry == 0)
2901 return;
2902
2903 mapping_state (MAP_DATA);
2904
2905 /* Align pool as you have word accesses.
2906 Only make a frag if we have to. */
2907 if (!need_pass_2)
2908 frag_align (2, 0, 0);
2909
2910 record_alignment (now_seg, 2);
2911
2912 sprintf (sym_name, "$$lit_\002%x", pool->id);
2913
2914 symbol_locate (pool->symbol, sym_name, now_seg,
2915 (valueT) frag_now_fix (), frag_now);
2916 symbol_table_insert (pool->symbol);
2917
2918 ARM_SET_THUMB (pool->symbol, thumb_mode);
2919
2920 #if defined OBJ_COFF || defined OBJ_ELF
2921 ARM_SET_INTERWORK (pool->symbol, support_interwork);
2922 #endif
2923
2924 for (entry = 0; entry < pool->next_free_entry; entry ++)
2925 /* First output the expression in the instruction to the pool. */
2926 emit_expr (&(pool->literals[entry]), 4); /* .word */
2927
2928 /* Mark the pool as empty. */
2929 pool->next_free_entry = 0;
2930 pool->symbol = NULL;
2931 }
2932
2933 #ifdef OBJ_ELF
2934 /* Forward declarations for functions below, in the MD interface
2935 section. */
2936 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
2937 static valueT create_unwind_entry (int);
2938 static void start_unwind_section (const segT, int);
2939 static void add_unwind_opcode (valueT, int);
2940 static void flush_pending_unwind (void);
2941
2942 /* Directives: Data. */
2943
2944 static void
2945 s_arm_elf_cons (int nbytes)
2946 {
2947 expressionS exp;
2948
2949 #ifdef md_flush_pending_output
2950 md_flush_pending_output ();
2951 #endif
2952
2953 if (is_it_end_of_statement ())
2954 {
2955 demand_empty_rest_of_line ();
2956 return;
2957 }
2958
2959 #ifdef md_cons_align
2960 md_cons_align (nbytes);
2961 #endif
2962
2963 mapping_state (MAP_DATA);
2964 do
2965 {
2966 int reloc;
2967 char *base = input_line_pointer;
2968
2969 expression (& exp);
2970
2971 if (exp.X_op != O_symbol)
2972 emit_expr (&exp, (unsigned int) nbytes);
2973 else
2974 {
2975 char *before_reloc = input_line_pointer;
2976 reloc = parse_reloc (&input_line_pointer);
2977 if (reloc == -1)
2978 {
2979 as_bad (_("unrecognized relocation suffix"));
2980 ignore_rest_of_line ();
2981 return;
2982 }
2983 else if (reloc == BFD_RELOC_UNUSED)
2984 emit_expr (&exp, (unsigned int) nbytes);
2985 else
2986 {
2987 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
2988 int size = bfd_get_reloc_size (howto);
2989
2990 if (reloc == BFD_RELOC_ARM_PLT32)
2991 {
2992 as_bad (_("(plt) is only valid on branch targets"));
2993 reloc = BFD_RELOC_UNUSED;
2994 size = 0;
2995 }
2996
2997 if (size > nbytes)
2998 as_bad (_("%s relocations do not fit in %d bytes"),
2999 howto->name, nbytes);
3000 else
3001 {
3002 /* We've parsed an expression stopping at O_symbol.
3003 But there may be more expression left now that we
3004 have parsed the relocation marker. Parse it again.
3005 XXX Surely there is a cleaner way to do this. */
3006 char *p = input_line_pointer;
3007 int offset;
3008 char *save_buf = alloca (input_line_pointer - base);
3009 memcpy (save_buf, base, input_line_pointer - base);
3010 memmove (base + (input_line_pointer - before_reloc),
3011 base, before_reloc - base);
3012
3013 input_line_pointer = base + (input_line_pointer-before_reloc);
3014 expression (&exp);
3015 memcpy (base, save_buf, p - base);
3016
3017 offset = nbytes - size;
3018 p = frag_more ((int) nbytes);
3019 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3020 size, &exp, 0, reloc);
3021 }
3022 }
3023 }
3024 }
3025 while (*input_line_pointer++ == ',');
3026
3027 /* Put terminator back into stream. */
3028 input_line_pointer --;
3029 demand_empty_rest_of_line ();
3030 }
3031
3032
3033 /* Parse a .rel31 directive. */
3034
3035 static void
3036 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3037 {
3038 expressionS exp;
3039 char *p;
3040 valueT highbit;
3041
3042 highbit = 0;
3043 if (*input_line_pointer == '1')
3044 highbit = 0x80000000;
3045 else if (*input_line_pointer != '0')
3046 as_bad (_("expected 0 or 1"));
3047
3048 input_line_pointer++;
3049 if (*input_line_pointer != ',')
3050 as_bad (_("missing comma"));
3051 input_line_pointer++;
3052
3053 #ifdef md_flush_pending_output
3054 md_flush_pending_output ();
3055 #endif
3056
3057 #ifdef md_cons_align
3058 md_cons_align (4);
3059 #endif
3060
3061 mapping_state (MAP_DATA);
3062
3063 expression (&exp);
3064
3065 p = frag_more (4);
3066 md_number_to_chars (p, highbit, 4);
3067 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3068 BFD_RELOC_ARM_PREL31);
3069
3070 demand_empty_rest_of_line ();
3071 }
3072
3073 /* Directives: AEABI stack-unwind tables. */
3074
3075 /* Parse an unwind_fnstart directive. Simply records the current location. */
3076
3077 static void
3078 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3079 {
3080 demand_empty_rest_of_line ();
3081 /* Mark the start of the function. */
3082 unwind.proc_start = expr_build_dot ();
3083
3084 /* Reset the rest of the unwind info. */
3085 unwind.opcode_count = 0;
3086 unwind.table_entry = NULL;
3087 unwind.personality_routine = NULL;
3088 unwind.personality_index = -1;
3089 unwind.frame_size = 0;
3090 unwind.fp_offset = 0;
3091 unwind.fp_reg = 13;
3092 unwind.fp_used = 0;
3093 unwind.sp_restored = 0;
3094 }
3095
3096
3097 /* Parse a handlerdata directive. Creates the exception handling table entry
3098 for the function. */
3099
3100 static void
3101 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3102 {
3103 demand_empty_rest_of_line ();
3104 if (unwind.table_entry)
3105 as_bad (_("duplicate .handlerdata directive"));
3106
3107 create_unwind_entry (1);
3108 }
3109
3110 /* Parse an unwind_fnend directive. Generates the index table entry. */
3111
3112 static void
3113 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3114 {
3115 long where;
3116 char *ptr;
3117 valueT val;
3118
3119 demand_empty_rest_of_line ();
3120
3121 /* Add eh table entry. */
3122 if (unwind.table_entry == NULL)
3123 val = create_unwind_entry (0);
3124 else
3125 val = 0;
3126
3127 /* Add index table entry. This is two words. */
3128 start_unwind_section (unwind.saved_seg, 1);
3129 frag_align (2, 0, 0);
3130 record_alignment (now_seg, 2);
3131
3132 ptr = frag_more (8);
3133 where = frag_now_fix () - 8;
3134
3135 /* Self relative offset of the function start. */
3136 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3137 BFD_RELOC_ARM_PREL31);
3138
3139 /* Indicate dependency on EHABI-defined personality routines to the
3140 linker, if it hasn't been done already. */
3141 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3142 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3143 {
3144 static const char *const name[] =
3145 {
3146 "__aeabi_unwind_cpp_pr0",
3147 "__aeabi_unwind_cpp_pr1",
3148 "__aeabi_unwind_cpp_pr2"
3149 };
3150 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3151 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3152 marked_pr_dependency |= 1 << unwind.personality_index;
3153 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3154 = marked_pr_dependency;
3155 }
3156
3157 if (val)
3158 /* Inline exception table entry. */
3159 md_number_to_chars (ptr + 4, val, 4);
3160 else
3161 /* Self relative offset of the table entry. */
3162 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3163 BFD_RELOC_ARM_PREL31);
3164
3165 /* Restore the original section. */
3166 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3167 }
3168
3169
3170 /* Parse an unwind_cantunwind directive. */
3171
3172 static void
3173 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3174 {
3175 demand_empty_rest_of_line ();
3176 if (unwind.personality_routine || unwind.personality_index != -1)
3177 as_bad (_("personality routine specified for cantunwind frame"));
3178
3179 unwind.personality_index = -2;
3180 }
3181
3182
3183 /* Parse a personalityindex directive. */
3184
3185 static void
3186 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3187 {
3188 expressionS exp;
3189
3190 if (unwind.personality_routine || unwind.personality_index != -1)
3191 as_bad (_("duplicate .personalityindex directive"));
3192
3193 expression (&exp);
3194
3195 if (exp.X_op != O_constant
3196 || exp.X_add_number < 0 || exp.X_add_number > 15)
3197 {
3198 as_bad (_("bad personality routine number"));
3199 ignore_rest_of_line ();
3200 return;
3201 }
3202
3203 unwind.personality_index = exp.X_add_number;
3204
3205 demand_empty_rest_of_line ();
3206 }
3207
3208
3209 /* Parse a personality directive. */
3210
3211 static void
3212 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3213 {
3214 char *name, *p, c;
3215
3216 if (unwind.personality_routine || unwind.personality_index != -1)
3217 as_bad (_("duplicate .personality directive"));
3218
3219 name = input_line_pointer;
3220 c = get_symbol_end ();
3221 p = input_line_pointer;
3222 unwind.personality_routine = symbol_find_or_make (name);
3223 *p = c;
3224 demand_empty_rest_of_line ();
3225 }
3226
3227
3228 /* Parse a directive saving core registers. */
3229
3230 static void
3231 s_arm_unwind_save_core (void)
3232 {
3233 valueT op;
3234 long range;
3235 int n;
3236
3237 range = parse_reg_list (&input_line_pointer);
3238 if (range == FAIL)
3239 {
3240 as_bad (_("expected register list"));
3241 ignore_rest_of_line ();
3242 return;
3243 }
3244
3245 demand_empty_rest_of_line ();
3246
3247 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3248 into .unwind_save {..., sp...}. We aren't bothered about the value of
3249 ip because it is clobbered by calls. */
3250 if (unwind.sp_restored && unwind.fp_reg == 12
3251 && (range & 0x3000) == 0x1000)
3252 {
3253 unwind.opcode_count--;
3254 unwind.sp_restored = 0;
3255 range = (range | 0x2000) & ~0x1000;
3256 unwind.pending_offset = 0;
3257 }
3258
3259 /* Pop r4-r15. */
3260 if (range & 0xfff0)
3261 {
3262 /* See if we can use the short opcodes. These pop a block of up to 8
3263 registers starting with r4, plus maybe r14. */
3264 for (n = 0; n < 8; n++)
3265 {
3266 /* Break at the first non-saved register. */
3267 if ((range & (1 << (n + 4))) == 0)
3268 break;
3269 }
3270 /* See if there are any other bits set. */
3271 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3272 {
3273 /* Use the long form. */
3274 op = 0x8000 | ((range >> 4) & 0xfff);
3275 add_unwind_opcode (op, 2);
3276 }
3277 else
3278 {
3279 /* Use the short form. */
3280 if (range & 0x4000)
3281 op = 0xa8; /* Pop r14. */
3282 else
3283 op = 0xa0; /* Do not pop r14. */
3284 op |= (n - 1);
3285 add_unwind_opcode (op, 1);
3286 }
3287 }
3288
3289 /* Pop r0-r3. */
3290 if (range & 0xf)
3291 {
3292 op = 0xb100 | (range & 0xf);
3293 add_unwind_opcode (op, 2);
3294 }
3295
3296 /* Record the number of bytes pushed. */
3297 for (n = 0; n < 16; n++)
3298 {
3299 if (range & (1 << n))
3300 unwind.frame_size += 4;
3301 }
3302 }
3303
3304
3305 /* Parse a directive saving FPA registers. */
3306
3307 static void
3308 s_arm_unwind_save_fpa (int reg)
3309 {
3310 expressionS exp;
3311 int num_regs;
3312 valueT op;
3313
3314 /* Get Number of registers to transfer. */
3315 if (skip_past_comma (&input_line_pointer) != FAIL)
3316 expression (&exp);
3317 else
3318 exp.X_op = O_illegal;
3319
3320 if (exp.X_op != O_constant)
3321 {
3322 as_bad (_("expected , <constant>"));
3323 ignore_rest_of_line ();
3324 return;
3325 }
3326
3327 num_regs = exp.X_add_number;
3328
3329 if (num_regs < 1 || num_regs > 4)
3330 {
3331 as_bad (_("number of registers must be in the range [1:4]"));
3332 ignore_rest_of_line ();
3333 return;
3334 }
3335
3336 demand_empty_rest_of_line ();
3337
3338 if (reg == 4)
3339 {
3340 /* Short form. */
3341 op = 0xb4 | (num_regs - 1);
3342 add_unwind_opcode (op, 1);
3343 }
3344 else
3345 {
3346 /* Long form. */
3347 op = 0xc800 | (reg << 4) | (num_regs - 1);
3348 add_unwind_opcode (op, 2);
3349 }
3350 unwind.frame_size += num_regs * 12;
3351 }
3352
3353
3354 /* Parse a directive saving VFP registers for ARMv6 and above. */
3355
3356 static void
3357 s_arm_unwind_save_vfp_armv6 (void)
3358 {
3359 int count;
3360 unsigned int start;
3361 valueT op;
3362 int num_vfpv3_regs = 0;
3363 int num_regs_below_16;
3364
3365 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3366 if (count == FAIL)
3367 {
3368 as_bad (_("expected register list"));
3369 ignore_rest_of_line ();
3370 return;
3371 }
3372
3373 demand_empty_rest_of_line ();
3374
3375 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3376 than FSTMX/FLDMX-style ones). */
3377
3378 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3379 if (start >= 16)
3380 num_vfpv3_regs = count;
3381 else if (start + count > 16)
3382 num_vfpv3_regs = start + count - 16;
3383
3384 if (num_vfpv3_regs > 0)
3385 {
3386 int start_offset = start > 16 ? start - 16 : 0;
3387 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3388 add_unwind_opcode (op, 2);
3389 }
3390
3391 /* Generate opcode for registers numbered in the range 0 .. 15. */
3392 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3393 assert (num_regs_below_16 + num_vfpv3_regs == count);
3394 if (num_regs_below_16 > 0)
3395 {
3396 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3397 add_unwind_opcode (op, 2);
3398 }
3399
3400 unwind.frame_size += count * 8;
3401 }
3402
3403
3404 /* Parse a directive saving VFP registers for pre-ARMv6. */
3405
3406 static void
3407 s_arm_unwind_save_vfp (void)
3408 {
3409 int count;
3410 unsigned int reg;
3411 valueT op;
3412
3413 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
3414 if (count == FAIL)
3415 {
3416 as_bad (_("expected register list"));
3417 ignore_rest_of_line ();
3418 return;
3419 }
3420
3421 demand_empty_rest_of_line ();
3422
3423 if (reg == 8)
3424 {
3425 /* Short form. */
3426 op = 0xb8 | (count - 1);
3427 add_unwind_opcode (op, 1);
3428 }
3429 else
3430 {
3431 /* Long form. */
3432 op = 0xb300 | (reg << 4) | (count - 1);
3433 add_unwind_opcode (op, 2);
3434 }
3435 unwind.frame_size += count * 8 + 4;
3436 }
3437
3438
3439 /* Parse a directive saving iWMMXt data registers. */
3440
3441 static void
3442 s_arm_unwind_save_mmxwr (void)
3443 {
3444 int reg;
3445 int hi_reg;
3446 int i;
3447 unsigned mask = 0;
3448 valueT op;
3449
3450 if (*input_line_pointer == '{')
3451 input_line_pointer++;
3452
3453 do
3454 {
3455 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3456
3457 if (reg == FAIL)
3458 {
3459 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3460 goto error;
3461 }
3462
3463 if (mask >> reg)
3464 as_tsktsk (_("register list not in ascending order"));
3465 mask |= 1 << reg;
3466
3467 if (*input_line_pointer == '-')
3468 {
3469 input_line_pointer++;
3470 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3471 if (hi_reg == FAIL)
3472 {
3473 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3474 goto error;
3475 }
3476 else if (reg >= hi_reg)
3477 {
3478 as_bad (_("bad register range"));
3479 goto error;
3480 }
3481 for (; reg < hi_reg; reg++)
3482 mask |= 1 << reg;
3483 }
3484 }
3485 while (skip_past_comma (&input_line_pointer) != FAIL);
3486
3487 if (*input_line_pointer == '}')
3488 input_line_pointer++;
3489
3490 demand_empty_rest_of_line ();
3491
3492 /* Generate any deferred opcodes because we're going to be looking at
3493 the list. */
3494 flush_pending_unwind ();
3495
3496 for (i = 0; i < 16; i++)
3497 {
3498 if (mask & (1 << i))
3499 unwind.frame_size += 8;
3500 }
3501
3502 /* Attempt to combine with a previous opcode. We do this because gcc
3503 likes to output separate unwind directives for a single block of
3504 registers. */
3505 if (unwind.opcode_count > 0)
3506 {
3507 i = unwind.opcodes[unwind.opcode_count - 1];
3508 if ((i & 0xf8) == 0xc0)
3509 {
3510 i &= 7;
3511 /* Only merge if the blocks are contiguous. */
3512 if (i < 6)
3513 {
3514 if ((mask & 0xfe00) == (1 << 9))
3515 {
3516 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3517 unwind.opcode_count--;
3518 }
3519 }
3520 else if (i == 6 && unwind.opcode_count >= 2)
3521 {
3522 i = unwind.opcodes[unwind.opcode_count - 2];
3523 reg = i >> 4;
3524 i &= 0xf;
3525
3526 op = 0xffff << (reg - 1);
3527 if (reg > 0
3528 && ((mask & op) == (1u << (reg - 1))))
3529 {
3530 op = (1 << (reg + i + 1)) - 1;
3531 op &= ~((1 << reg) - 1);
3532 mask |= op;
3533 unwind.opcode_count -= 2;
3534 }
3535 }
3536 }
3537 }
3538
3539 hi_reg = 15;
3540 /* We want to generate opcodes in the order the registers have been
3541 saved, ie. descending order. */
3542 for (reg = 15; reg >= -1; reg--)
3543 {
3544 /* Save registers in blocks. */
3545 if (reg < 0
3546 || !(mask & (1 << reg)))
3547 {
3548 /* We found an unsaved reg. Generate opcodes to save the
3549 preceding block. */
3550 if (reg != hi_reg)
3551 {
3552 if (reg == 9)
3553 {
3554 /* Short form. */
3555 op = 0xc0 | (hi_reg - 10);
3556 add_unwind_opcode (op, 1);
3557 }
3558 else
3559 {
3560 /* Long form. */
3561 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3562 add_unwind_opcode (op, 2);
3563 }
3564 }
3565 hi_reg = reg - 1;
3566 }
3567 }
3568
3569 return;
3570 error:
3571 ignore_rest_of_line ();
3572 }
3573
3574 static void
3575 s_arm_unwind_save_mmxwcg (void)
3576 {
3577 int reg;
3578 int hi_reg;
3579 unsigned mask = 0;
3580 valueT op;
3581
3582 if (*input_line_pointer == '{')
3583 input_line_pointer++;
3584
3585 do
3586 {
3587 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3588
3589 if (reg == FAIL)
3590 {
3591 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3592 goto error;
3593 }
3594
3595 reg -= 8;
3596 if (mask >> reg)
3597 as_tsktsk (_("register list not in ascending order"));
3598 mask |= 1 << reg;
3599
3600 if (*input_line_pointer == '-')
3601 {
3602 input_line_pointer++;
3603 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3604 if (hi_reg == FAIL)
3605 {
3606 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3607 goto error;
3608 }
3609 else if (reg >= hi_reg)
3610 {
3611 as_bad (_("bad register range"));
3612 goto error;
3613 }
3614 for (; reg < hi_reg; reg++)
3615 mask |= 1 << reg;
3616 }
3617 }
3618 while (skip_past_comma (&input_line_pointer) != FAIL);
3619
3620 if (*input_line_pointer == '}')
3621 input_line_pointer++;
3622
3623 demand_empty_rest_of_line ();
3624
3625 /* Generate any deferred opcodes because we're going to be looking at
3626 the list. */
3627 flush_pending_unwind ();
3628
3629 for (reg = 0; reg < 16; reg++)
3630 {
3631 if (mask & (1 << reg))
3632 unwind.frame_size += 4;
3633 }
3634 op = 0xc700 | mask;
3635 add_unwind_opcode (op, 2);
3636 return;
3637 error:
3638 ignore_rest_of_line ();
3639 }
3640
3641
3642 /* Parse an unwind_save directive.
3643 If the argument is non-zero, this is a .vsave directive. */
3644
3645 static void
3646 s_arm_unwind_save (int arch_v6)
3647 {
3648 char *peek;
3649 struct reg_entry *reg;
3650 bfd_boolean had_brace = FALSE;
3651
3652 /* Figure out what sort of save we have. */
3653 peek = input_line_pointer;
3654
3655 if (*peek == '{')
3656 {
3657 had_brace = TRUE;
3658 peek++;
3659 }
3660
3661 reg = arm_reg_parse_multi (&peek);
3662
3663 if (!reg)
3664 {
3665 as_bad (_("register expected"));
3666 ignore_rest_of_line ();
3667 return;
3668 }
3669
3670 switch (reg->type)
3671 {
3672 case REG_TYPE_FN:
3673 if (had_brace)
3674 {
3675 as_bad (_("FPA .unwind_save does not take a register list"));
3676 ignore_rest_of_line ();
3677 return;
3678 }
3679 input_line_pointer = peek;
3680 s_arm_unwind_save_fpa (reg->number);
3681 return;
3682
3683 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
3684 case REG_TYPE_VFD:
3685 if (arch_v6)
3686 s_arm_unwind_save_vfp_armv6 ();
3687 else
3688 s_arm_unwind_save_vfp ();
3689 return;
3690 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
3691 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
3692
3693 default:
3694 as_bad (_(".unwind_save does not support this kind of register"));
3695 ignore_rest_of_line ();
3696 }
3697 }
3698
3699
3700 /* Parse an unwind_movsp directive. */
3701
3702 static void
3703 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
3704 {
3705 int reg;
3706 valueT op;
3707 int offset;
3708
3709 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3710 if (reg == FAIL)
3711 {
3712 as_bad (_(reg_expected_msgs[REG_TYPE_RN]));
3713 ignore_rest_of_line ();
3714 return;
3715 }
3716
3717 /* Optional constant. */
3718 if (skip_past_comma (&input_line_pointer) != FAIL)
3719 {
3720 if (immediate_for_directive (&offset) == FAIL)
3721 return;
3722 }
3723 else
3724 offset = 0;
3725
3726 demand_empty_rest_of_line ();
3727
3728 if (reg == REG_SP || reg == REG_PC)
3729 {
3730 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
3731 return;
3732 }
3733
3734 if (unwind.fp_reg != REG_SP)
3735 as_bad (_("unexpected .unwind_movsp directive"));
3736
3737 /* Generate opcode to restore the value. */
3738 op = 0x90 | reg;
3739 add_unwind_opcode (op, 1);
3740
3741 /* Record the information for later. */
3742 unwind.fp_reg = reg;
3743 unwind.fp_offset = unwind.frame_size - offset;
3744 unwind.sp_restored = 1;
3745 }
3746
3747 /* Parse an unwind_pad directive. */
3748
3749 static void
3750 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
3751 {
3752 int offset;
3753
3754 if (immediate_for_directive (&offset) == FAIL)
3755 return;
3756
3757 if (offset & 3)
3758 {
3759 as_bad (_("stack increment must be multiple of 4"));
3760 ignore_rest_of_line ();
3761 return;
3762 }
3763
3764 /* Don't generate any opcodes, just record the details for later. */
3765 unwind.frame_size += offset;
3766 unwind.pending_offset += offset;
3767
3768 demand_empty_rest_of_line ();
3769 }
3770
3771 /* Parse an unwind_setfp directive. */
3772
3773 static void
3774 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
3775 {
3776 int sp_reg;
3777 int fp_reg;
3778 int offset;
3779
3780 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3781 if (skip_past_comma (&input_line_pointer) == FAIL)
3782 sp_reg = FAIL;
3783 else
3784 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3785
3786 if (fp_reg == FAIL || sp_reg == FAIL)
3787 {
3788 as_bad (_("expected <reg>, <reg>"));
3789 ignore_rest_of_line ();
3790 return;
3791 }
3792
3793 /* Optional constant. */
3794 if (skip_past_comma (&input_line_pointer) != FAIL)
3795 {
3796 if (immediate_for_directive (&offset) == FAIL)
3797 return;
3798 }
3799 else
3800 offset = 0;
3801
3802 demand_empty_rest_of_line ();
3803
3804 if (sp_reg != 13 && sp_reg != unwind.fp_reg)
3805 {
3806 as_bad (_("register must be either sp or set by a previous"
3807 "unwind_movsp directive"));
3808 return;
3809 }
3810
3811 /* Don't generate any opcodes, just record the information for later. */
3812 unwind.fp_reg = fp_reg;
3813 unwind.fp_used = 1;
3814 if (sp_reg == 13)
3815 unwind.fp_offset = unwind.frame_size - offset;
3816 else
3817 unwind.fp_offset -= offset;
3818 }
3819
3820 /* Parse an unwind_raw directive. */
3821
3822 static void
3823 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
3824 {
3825 expressionS exp;
3826 /* This is an arbitrary limit. */
3827 unsigned char op[16];
3828 int count;
3829
3830 expression (&exp);
3831 if (exp.X_op == O_constant
3832 && skip_past_comma (&input_line_pointer) != FAIL)
3833 {
3834 unwind.frame_size += exp.X_add_number;
3835 expression (&exp);
3836 }
3837 else
3838 exp.X_op = O_illegal;
3839
3840 if (exp.X_op != O_constant)
3841 {
3842 as_bad (_("expected <offset>, <opcode>"));
3843 ignore_rest_of_line ();
3844 return;
3845 }
3846
3847 count = 0;
3848
3849 /* Parse the opcode. */
3850 for (;;)
3851 {
3852 if (count >= 16)
3853 {
3854 as_bad (_("unwind opcode too long"));
3855 ignore_rest_of_line ();
3856 }
3857 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
3858 {
3859 as_bad (_("invalid unwind opcode"));
3860 ignore_rest_of_line ();
3861 return;
3862 }
3863 op[count++] = exp.X_add_number;
3864
3865 /* Parse the next byte. */
3866 if (skip_past_comma (&input_line_pointer) == FAIL)
3867 break;
3868
3869 expression (&exp);
3870 }
3871
3872 /* Add the opcode bytes in reverse order. */
3873 while (count--)
3874 add_unwind_opcode (op[count], 1);
3875
3876 demand_empty_rest_of_line ();
3877 }
3878
3879
3880 /* Parse a .eabi_attribute directive. */
3881
3882 static void
3883 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
3884 {
3885 s_vendor_attribute (OBJ_ATTR_PROC);
3886 }
3887 #endif /* OBJ_ELF */
3888
3889 static void s_arm_arch (int);
3890 static void s_arm_object_arch (int);
3891 static void s_arm_cpu (int);
3892 static void s_arm_fpu (int);
3893
3894 #ifdef TE_PE
3895
3896 static void
3897 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
3898 {
3899 expressionS exp;
3900
3901 do
3902 {
3903 expression (&exp);
3904 if (exp.X_op == O_symbol)
3905 exp.X_op = O_secrel;
3906
3907 emit_expr (&exp, 4);
3908 }
3909 while (*input_line_pointer++ == ',');
3910
3911 input_line_pointer--;
3912 demand_empty_rest_of_line ();
3913 }
3914 #endif /* TE_PE */
3915
3916 /* This table describes all the machine specific pseudo-ops the assembler
3917 has to support. The fields are:
3918 pseudo-op name without dot
3919 function to call to execute this pseudo-op
3920 Integer arg to pass to the function. */
3921
3922 const pseudo_typeS md_pseudo_table[] =
3923 {
3924 /* Never called because '.req' does not start a line. */
3925 { "req", s_req, 0 },
3926 /* Following two are likewise never called. */
3927 { "dn", s_dn, 0 },
3928 { "qn", s_qn, 0 },
3929 { "unreq", s_unreq, 0 },
3930 { "bss", s_bss, 0 },
3931 { "align", s_align, 0 },
3932 { "arm", s_arm, 0 },
3933 { "thumb", s_thumb, 0 },
3934 { "code", s_code, 0 },
3935 { "force_thumb", s_force_thumb, 0 },
3936 { "thumb_func", s_thumb_func, 0 },
3937 { "thumb_set", s_thumb_set, 0 },
3938 { "even", s_even, 0 },
3939 { "ltorg", s_ltorg, 0 },
3940 { "pool", s_ltorg, 0 },
3941 { "syntax", s_syntax, 0 },
3942 { "cpu", s_arm_cpu, 0 },
3943 { "arch", s_arm_arch, 0 },
3944 { "object_arch", s_arm_object_arch, 0 },
3945 { "fpu", s_arm_fpu, 0 },
3946 #ifdef OBJ_ELF
3947 { "word", s_arm_elf_cons, 4 },
3948 { "long", s_arm_elf_cons, 4 },
3949 { "rel31", s_arm_rel31, 0 },
3950 { "fnstart", s_arm_unwind_fnstart, 0 },
3951 { "fnend", s_arm_unwind_fnend, 0 },
3952 { "cantunwind", s_arm_unwind_cantunwind, 0 },
3953 { "personality", s_arm_unwind_personality, 0 },
3954 { "personalityindex", s_arm_unwind_personalityindex, 0 },
3955 { "handlerdata", s_arm_unwind_handlerdata, 0 },
3956 { "save", s_arm_unwind_save, 0 },
3957 { "vsave", s_arm_unwind_save, 1 },
3958 { "movsp", s_arm_unwind_movsp, 0 },
3959 { "pad", s_arm_unwind_pad, 0 },
3960 { "setfp", s_arm_unwind_setfp, 0 },
3961 { "unwind_raw", s_arm_unwind_raw, 0 },
3962 { "eabi_attribute", s_arm_eabi_attribute, 0 },
3963 #else
3964 { "word", cons, 4},
3965
3966 /* These are used for dwarf. */
3967 {"2byte", cons, 2},
3968 {"4byte", cons, 4},
3969 {"8byte", cons, 8},
3970 /* These are used for dwarf2. */
3971 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
3972 { "loc", dwarf2_directive_loc, 0 },
3973 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
3974 #endif
3975 { "extend", float_cons, 'x' },
3976 { "ldouble", float_cons, 'x' },
3977 { "packed", float_cons, 'p' },
3978 #ifdef TE_PE
3979 {"secrel32", pe_directive_secrel, 0},
3980 #endif
3981 { 0, 0, 0 }
3982 };
3983 \f
3984 /* Parser functions used exclusively in instruction operands. */
3985
3986 /* Generic immediate-value read function for use in insn parsing.
3987 STR points to the beginning of the immediate (the leading #);
3988 VAL receives the value; if the value is outside [MIN, MAX]
3989 issue an error. PREFIX_OPT is true if the immediate prefix is
3990 optional. */
3991
3992 static int
3993 parse_immediate (char **str, int *val, int min, int max,
3994 bfd_boolean prefix_opt)
3995 {
3996 expressionS exp;
3997 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
3998 if (exp.X_op != O_constant)
3999 {
4000 inst.error = _("constant expression required");
4001 return FAIL;
4002 }
4003
4004 if (exp.X_add_number < min || exp.X_add_number > max)
4005 {
4006 inst.error = _("immediate value out of range");
4007 return FAIL;
4008 }
4009
4010 *val = exp.X_add_number;
4011 return SUCCESS;
4012 }
4013
4014 /* Less-generic immediate-value read function with the possibility of loading a
4015 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
4016 instructions. Puts the result directly in inst.operands[i]. */
4017
4018 static int
4019 parse_big_immediate (char **str, int i)
4020 {
4021 expressionS exp;
4022 char *ptr = *str;
4023
4024 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4025
4026 if (exp.X_op == O_constant)
4027 {
4028 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4029 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4030 O_constant. We have to be careful not to break compilation for
4031 32-bit X_add_number, though. */
4032 if ((exp.X_add_number & ~0xffffffffl) != 0)
4033 {
4034 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4035 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4036 inst.operands[i].regisimm = 1;
4037 }
4038 }
4039 else if (exp.X_op == O_big
4040 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4041 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4042 {
4043 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4044 /* Bignums have their least significant bits in
4045 generic_bignum[0]. Make sure we put 32 bits in imm and
4046 32 bits in reg, in a (hopefully) portable way. */
4047 assert (parts != 0);
4048 inst.operands[i].imm = 0;
4049 for (j = 0; j < parts; j++, idx++)
4050 inst.operands[i].imm |= generic_bignum[idx]
4051 << (LITTLENUM_NUMBER_OF_BITS * j);
4052 inst.operands[i].reg = 0;
4053 for (j = 0; j < parts; j++, idx++)
4054 inst.operands[i].reg |= generic_bignum[idx]
4055 << (LITTLENUM_NUMBER_OF_BITS * j);
4056 inst.operands[i].regisimm = 1;
4057 }
4058 else
4059 return FAIL;
4060
4061 *str = ptr;
4062
4063 return SUCCESS;
4064 }
4065
4066 /* Returns the pseudo-register number of an FPA immediate constant,
4067 or FAIL if there isn't a valid constant here. */
4068
4069 static int
4070 parse_fpa_immediate (char ** str)
4071 {
4072 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4073 char * save_in;
4074 expressionS exp;
4075 int i;
4076 int j;
4077
4078 /* First try and match exact strings, this is to guarantee
4079 that some formats will work even for cross assembly. */
4080
4081 for (i = 0; fp_const[i]; i++)
4082 {
4083 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4084 {
4085 char *start = *str;
4086
4087 *str += strlen (fp_const[i]);
4088 if (is_end_of_line[(unsigned char) **str])
4089 return i + 8;
4090 *str = start;
4091 }
4092 }
4093
4094 /* Just because we didn't get a match doesn't mean that the constant
4095 isn't valid, just that it is in a format that we don't
4096 automatically recognize. Try parsing it with the standard
4097 expression routines. */
4098
4099 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
4100
4101 /* Look for a raw floating point number. */
4102 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4103 && is_end_of_line[(unsigned char) *save_in])
4104 {
4105 for (i = 0; i < NUM_FLOAT_VALS; i++)
4106 {
4107 for (j = 0; j < MAX_LITTLENUMS; j++)
4108 {
4109 if (words[j] != fp_values[i][j])
4110 break;
4111 }
4112
4113 if (j == MAX_LITTLENUMS)
4114 {
4115 *str = save_in;
4116 return i + 8;
4117 }
4118 }
4119 }
4120
4121 /* Try and parse a more complex expression, this will probably fail
4122 unless the code uses a floating point prefix (eg "0f"). */
4123 save_in = input_line_pointer;
4124 input_line_pointer = *str;
4125 if (expression (&exp) == absolute_section
4126 && exp.X_op == O_big
4127 && exp.X_add_number < 0)
4128 {
4129 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4130 Ditto for 15. */
4131 if (gen_to_words (words, 5, (long) 15) == 0)
4132 {
4133 for (i = 0; i < NUM_FLOAT_VALS; i++)
4134 {
4135 for (j = 0; j < MAX_LITTLENUMS; j++)
4136 {
4137 if (words[j] != fp_values[i][j])
4138 break;
4139 }
4140
4141 if (j == MAX_LITTLENUMS)
4142 {
4143 *str = input_line_pointer;
4144 input_line_pointer = save_in;
4145 return i + 8;
4146 }
4147 }
4148 }
4149 }
4150
4151 *str = input_line_pointer;
4152 input_line_pointer = save_in;
4153 inst.error = _("invalid FPA immediate expression");
4154 return FAIL;
4155 }
4156
4157 /* Returns 1 if a number has "quarter-precision" float format
4158 0baBbbbbbc defgh000 00000000 00000000. */
4159
4160 static int
4161 is_quarter_float (unsigned imm)
4162 {
4163 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4164 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4165 }
4166
4167 /* Parse an 8-bit "quarter-precision" floating point number of the form:
4168 0baBbbbbbc defgh000 00000000 00000000.
4169 The zero and minus-zero cases need special handling, since they can't be
4170 encoded in the "quarter-precision" float format, but can nonetheless be
4171 loaded as integer constants. */
4172
4173 static unsigned
4174 parse_qfloat_immediate (char **ccp, int *immed)
4175 {
4176 char *str = *ccp;
4177 char *fpnum;
4178 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4179 int found_fpchar = 0;
4180
4181 skip_past_char (&str, '#');
4182
4183 /* We must not accidentally parse an integer as a floating-point number. Make
4184 sure that the value we parse is not an integer by checking for special
4185 characters '.' or 'e'.
4186 FIXME: This is a horrible hack, but doing better is tricky because type
4187 information isn't in a very usable state at parse time. */
4188 fpnum = str;
4189 skip_whitespace (fpnum);
4190
4191 if (strncmp (fpnum, "0x", 2) == 0)
4192 return FAIL;
4193 else
4194 {
4195 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4196 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4197 {
4198 found_fpchar = 1;
4199 break;
4200 }
4201
4202 if (!found_fpchar)
4203 return FAIL;
4204 }
4205
4206 if ((str = atof_ieee (str, 's', words)) != NULL)
4207 {
4208 unsigned fpword = 0;
4209 int i;
4210
4211 /* Our FP word must be 32 bits (single-precision FP). */
4212 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4213 {
4214 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4215 fpword |= words[i];
4216 }
4217
4218 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
4219 *immed = fpword;
4220 else
4221 return FAIL;
4222
4223 *ccp = str;
4224
4225 return SUCCESS;
4226 }
4227
4228 return FAIL;
4229 }
4230
4231 /* Shift operands. */
4232 enum shift_kind
4233 {
4234 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4235 };
4236
4237 struct asm_shift_name
4238 {
4239 const char *name;
4240 enum shift_kind kind;
4241 };
4242
4243 /* Third argument to parse_shift. */
4244 enum parse_shift_mode
4245 {
4246 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4247 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4248 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4249 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4250 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4251 };
4252
4253 /* Parse a <shift> specifier on an ARM data processing instruction.
4254 This has three forms:
4255
4256 (LSL|LSR|ASL|ASR|ROR) Rs
4257 (LSL|LSR|ASL|ASR|ROR) #imm
4258 RRX
4259
4260 Note that ASL is assimilated to LSL in the instruction encoding, and
4261 RRX to ROR #0 (which cannot be written as such). */
4262
4263 static int
4264 parse_shift (char **str, int i, enum parse_shift_mode mode)
4265 {
4266 const struct asm_shift_name *shift_name;
4267 enum shift_kind shift;
4268 char *s = *str;
4269 char *p = s;
4270 int reg;
4271
4272 for (p = *str; ISALPHA (*p); p++)
4273 ;
4274
4275 if (p == *str)
4276 {
4277 inst.error = _("shift expression expected");
4278 return FAIL;
4279 }
4280
4281 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
4282
4283 if (shift_name == NULL)
4284 {
4285 inst.error = _("shift expression expected");
4286 return FAIL;
4287 }
4288
4289 shift = shift_name->kind;
4290
4291 switch (mode)
4292 {
4293 case NO_SHIFT_RESTRICT:
4294 case SHIFT_IMMEDIATE: break;
4295
4296 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4297 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4298 {
4299 inst.error = _("'LSL' or 'ASR' required");
4300 return FAIL;
4301 }
4302 break;
4303
4304 case SHIFT_LSL_IMMEDIATE:
4305 if (shift != SHIFT_LSL)
4306 {
4307 inst.error = _("'LSL' required");
4308 return FAIL;
4309 }
4310 break;
4311
4312 case SHIFT_ASR_IMMEDIATE:
4313 if (shift != SHIFT_ASR)
4314 {
4315 inst.error = _("'ASR' required");
4316 return FAIL;
4317 }
4318 break;
4319
4320 default: abort ();
4321 }
4322
4323 if (shift != SHIFT_RRX)
4324 {
4325 /* Whitespace can appear here if the next thing is a bare digit. */
4326 skip_whitespace (p);
4327
4328 if (mode == NO_SHIFT_RESTRICT
4329 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4330 {
4331 inst.operands[i].imm = reg;
4332 inst.operands[i].immisreg = 1;
4333 }
4334 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4335 return FAIL;
4336 }
4337 inst.operands[i].shift_kind = shift;
4338 inst.operands[i].shifted = 1;
4339 *str = p;
4340 return SUCCESS;
4341 }
4342
4343 /* Parse a <shifter_operand> for an ARM data processing instruction:
4344
4345 #<immediate>
4346 #<immediate>, <rotate>
4347 <Rm>
4348 <Rm>, <shift>
4349
4350 where <shift> is defined by parse_shift above, and <rotate> is a
4351 multiple of 2 between 0 and 30. Validation of immediate operands
4352 is deferred to md_apply_fix. */
4353
4354 static int
4355 parse_shifter_operand (char **str, int i)
4356 {
4357 int value;
4358 expressionS expr;
4359
4360 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
4361 {
4362 inst.operands[i].reg = value;
4363 inst.operands[i].isreg = 1;
4364
4365 /* parse_shift will override this if appropriate */
4366 inst.reloc.exp.X_op = O_constant;
4367 inst.reloc.exp.X_add_number = 0;
4368
4369 if (skip_past_comma (str) == FAIL)
4370 return SUCCESS;
4371
4372 /* Shift operation on register. */
4373 return parse_shift (str, i, NO_SHIFT_RESTRICT);
4374 }
4375
4376 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4377 return FAIL;
4378
4379 if (skip_past_comma (str) == SUCCESS)
4380 {
4381 /* #x, y -- ie explicit rotation by Y. */
4382 if (my_get_expression (&expr, str, GE_NO_PREFIX))
4383 return FAIL;
4384
4385 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4386 {
4387 inst.error = _("constant expression expected");
4388 return FAIL;
4389 }
4390
4391 value = expr.X_add_number;
4392 if (value < 0 || value > 30 || value % 2 != 0)
4393 {
4394 inst.error = _("invalid rotation");
4395 return FAIL;
4396 }
4397 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4398 {
4399 inst.error = _("invalid constant");
4400 return FAIL;
4401 }
4402
4403 /* Convert to decoded value. md_apply_fix will put it back. */
4404 inst.reloc.exp.X_add_number
4405 = (((inst.reloc.exp.X_add_number << (32 - value))
4406 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
4407 }
4408
4409 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4410 inst.reloc.pc_rel = 0;
4411 return SUCCESS;
4412 }
4413
4414 /* Group relocation information. Each entry in the table contains the
4415 textual name of the relocation as may appear in assembler source
4416 and must end with a colon.
4417 Along with this textual name are the relocation codes to be used if
4418 the corresponding instruction is an ALU instruction (ADD or SUB only),
4419 an LDR, an LDRS, or an LDC. */
4420
4421 struct group_reloc_table_entry
4422 {
4423 const char *name;
4424 int alu_code;
4425 int ldr_code;
4426 int ldrs_code;
4427 int ldc_code;
4428 };
4429
4430 typedef enum
4431 {
4432 /* Varieties of non-ALU group relocation. */
4433
4434 GROUP_LDR,
4435 GROUP_LDRS,
4436 GROUP_LDC
4437 } group_reloc_type;
4438
4439 static struct group_reloc_table_entry group_reloc_table[] =
4440 { /* Program counter relative: */
4441 { "pc_g0_nc",
4442 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4443 0, /* LDR */
4444 0, /* LDRS */
4445 0 }, /* LDC */
4446 { "pc_g0",
4447 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4448 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4449 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4450 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4451 { "pc_g1_nc",
4452 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4453 0, /* LDR */
4454 0, /* LDRS */
4455 0 }, /* LDC */
4456 { "pc_g1",
4457 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4458 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4459 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4460 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4461 { "pc_g2",
4462 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4463 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4464 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4465 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4466 /* Section base relative */
4467 { "sb_g0_nc",
4468 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4469 0, /* LDR */
4470 0, /* LDRS */
4471 0 }, /* LDC */
4472 { "sb_g0",
4473 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4474 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4475 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4476 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4477 { "sb_g1_nc",
4478 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4479 0, /* LDR */
4480 0, /* LDRS */
4481 0 }, /* LDC */
4482 { "sb_g1",
4483 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4484 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4485 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4486 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4487 { "sb_g2",
4488 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4489 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4490 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4491 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4492
4493 /* Given the address of a pointer pointing to the textual name of a group
4494 relocation as may appear in assembler source, attempt to find its details
4495 in group_reloc_table. The pointer will be updated to the character after
4496 the trailing colon. On failure, FAIL will be returned; SUCCESS
4497 otherwise. On success, *entry will be updated to point at the relevant
4498 group_reloc_table entry. */
4499
4500 static int
4501 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4502 {
4503 unsigned int i;
4504 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4505 {
4506 int length = strlen (group_reloc_table[i].name);
4507
4508 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4509 && (*str)[length] == ':')
4510 {
4511 *out = &group_reloc_table[i];
4512 *str += (length + 1);
4513 return SUCCESS;
4514 }
4515 }
4516
4517 return FAIL;
4518 }
4519
4520 /* Parse a <shifter_operand> for an ARM data processing instruction
4521 (as for parse_shifter_operand) where group relocations are allowed:
4522
4523 #<immediate>
4524 #<immediate>, <rotate>
4525 #:<group_reloc>:<expression>
4526 <Rm>
4527 <Rm>, <shift>
4528
4529 where <group_reloc> is one of the strings defined in group_reloc_table.
4530 The hashes are optional.
4531
4532 Everything else is as for parse_shifter_operand. */
4533
4534 static parse_operand_result
4535 parse_shifter_operand_group_reloc (char **str, int i)
4536 {
4537 /* Determine if we have the sequence of characters #: or just :
4538 coming next. If we do, then we check for a group relocation.
4539 If we don't, punt the whole lot to parse_shifter_operand. */
4540
4541 if (((*str)[0] == '#' && (*str)[1] == ':')
4542 || (*str)[0] == ':')
4543 {
4544 struct group_reloc_table_entry *entry;
4545
4546 if ((*str)[0] == '#')
4547 (*str) += 2;
4548 else
4549 (*str)++;
4550
4551 /* Try to parse a group relocation. Anything else is an error. */
4552 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4553 {
4554 inst.error = _("unknown group relocation");
4555 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4556 }
4557
4558 /* We now have the group relocation table entry corresponding to
4559 the name in the assembler source. Next, we parse the expression. */
4560 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4561 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4562
4563 /* Record the relocation type (always the ALU variant here). */
4564 inst.reloc.type = entry->alu_code;
4565 assert (inst.reloc.type != 0);
4566
4567 return PARSE_OPERAND_SUCCESS;
4568 }
4569 else
4570 return parse_shifter_operand (str, i) == SUCCESS
4571 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4572
4573 /* Never reached. */
4574 }
4575
4576 /* Parse all forms of an ARM address expression. Information is written
4577 to inst.operands[i] and/or inst.reloc.
4578
4579 Preindexed addressing (.preind=1):
4580
4581 [Rn, #offset] .reg=Rn .reloc.exp=offset
4582 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4583 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4584 .shift_kind=shift .reloc.exp=shift_imm
4585
4586 These three may have a trailing ! which causes .writeback to be set also.
4587
4588 Postindexed addressing (.postind=1, .writeback=1):
4589
4590 [Rn], #offset .reg=Rn .reloc.exp=offset
4591 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4592 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4593 .shift_kind=shift .reloc.exp=shift_imm
4594
4595 Unindexed addressing (.preind=0, .postind=0):
4596
4597 [Rn], {option} .reg=Rn .imm=option .immisreg=0
4598
4599 Other:
4600
4601 [Rn]{!} shorthand for [Rn,#0]{!}
4602 =immediate .isreg=0 .reloc.exp=immediate
4603 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
4604
4605 It is the caller's responsibility to check for addressing modes not
4606 supported by the instruction, and to set inst.reloc.type. */
4607
4608 static parse_operand_result
4609 parse_address_main (char **str, int i, int group_relocations,
4610 group_reloc_type group_type)
4611 {
4612 char *p = *str;
4613 int reg;
4614
4615 if (skip_past_char (&p, '[') == FAIL)
4616 {
4617 if (skip_past_char (&p, '=') == FAIL)
4618 {
4619 /* bare address - translate to PC-relative offset */
4620 inst.reloc.pc_rel = 1;
4621 inst.operands[i].reg = REG_PC;
4622 inst.operands[i].isreg = 1;
4623 inst.operands[i].preind = 1;
4624 }
4625 /* else a load-constant pseudo op, no special treatment needed here */
4626
4627 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4628 return PARSE_OPERAND_FAIL;
4629
4630 *str = p;
4631 return PARSE_OPERAND_SUCCESS;
4632 }
4633
4634 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
4635 {
4636 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4637 return PARSE_OPERAND_FAIL;
4638 }
4639 inst.operands[i].reg = reg;
4640 inst.operands[i].isreg = 1;
4641
4642 if (skip_past_comma (&p) == SUCCESS)
4643 {
4644 inst.operands[i].preind = 1;
4645
4646 if (*p == '+') p++;
4647 else if (*p == '-') p++, inst.operands[i].negative = 1;
4648
4649 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4650 {
4651 inst.operands[i].imm = reg;
4652 inst.operands[i].immisreg = 1;
4653
4654 if (skip_past_comma (&p) == SUCCESS)
4655 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4656 return PARSE_OPERAND_FAIL;
4657 }
4658 else if (skip_past_char (&p, ':') == SUCCESS)
4659 {
4660 /* FIXME: '@' should be used here, but it's filtered out by generic
4661 code before we get to see it here. This may be subject to
4662 change. */
4663 expressionS exp;
4664 my_get_expression (&exp, &p, GE_NO_PREFIX);
4665 if (exp.X_op != O_constant)
4666 {
4667 inst.error = _("alignment must be constant");
4668 return PARSE_OPERAND_FAIL;
4669 }
4670 inst.operands[i].imm = exp.X_add_number << 8;
4671 inst.operands[i].immisalign = 1;
4672 /* Alignments are not pre-indexes. */
4673 inst.operands[i].preind = 0;
4674 }
4675 else
4676 {
4677 if (inst.operands[i].negative)
4678 {
4679 inst.operands[i].negative = 0;
4680 p--;
4681 }
4682
4683 if (group_relocations
4684 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4685 {
4686 struct group_reloc_table_entry *entry;
4687
4688 /* Skip over the #: or : sequence. */
4689 if (*p == '#')
4690 p += 2;
4691 else
4692 p++;
4693
4694 /* Try to parse a group relocation. Anything else is an
4695 error. */
4696 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
4697 {
4698 inst.error = _("unknown group relocation");
4699 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4700 }
4701
4702 /* We now have the group relocation table entry corresponding to
4703 the name in the assembler source. Next, we parse the
4704 expression. */
4705 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4706 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4707
4708 /* Record the relocation type. */
4709 switch (group_type)
4710 {
4711 case GROUP_LDR:
4712 inst.reloc.type = entry->ldr_code;
4713 break;
4714
4715 case GROUP_LDRS:
4716 inst.reloc.type = entry->ldrs_code;
4717 break;
4718
4719 case GROUP_LDC:
4720 inst.reloc.type = entry->ldc_code;
4721 break;
4722
4723 default:
4724 assert (0);
4725 }
4726
4727 if (inst.reloc.type == 0)
4728 {
4729 inst.error = _("this group relocation is not allowed on this instruction");
4730 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4731 }
4732 }
4733 else
4734 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4735 return PARSE_OPERAND_FAIL;
4736 }
4737 }
4738
4739 if (skip_past_char (&p, ']') == FAIL)
4740 {
4741 inst.error = _("']' expected");
4742 return PARSE_OPERAND_FAIL;
4743 }
4744
4745 if (skip_past_char (&p, '!') == SUCCESS)
4746 inst.operands[i].writeback = 1;
4747
4748 else if (skip_past_comma (&p) == SUCCESS)
4749 {
4750 if (skip_past_char (&p, '{') == SUCCESS)
4751 {
4752 /* [Rn], {expr} - unindexed, with option */
4753 if (parse_immediate (&p, &inst.operands[i].imm,
4754 0, 255, TRUE) == FAIL)
4755 return PARSE_OPERAND_FAIL;
4756
4757 if (skip_past_char (&p, '}') == FAIL)
4758 {
4759 inst.error = _("'}' expected at end of 'option' field");
4760 return PARSE_OPERAND_FAIL;
4761 }
4762 if (inst.operands[i].preind)
4763 {
4764 inst.error = _("cannot combine index with option");
4765 return PARSE_OPERAND_FAIL;
4766 }
4767 *str = p;
4768 return PARSE_OPERAND_SUCCESS;
4769 }
4770 else
4771 {
4772 inst.operands[i].postind = 1;
4773 inst.operands[i].writeback = 1;
4774
4775 if (inst.operands[i].preind)
4776 {
4777 inst.error = _("cannot combine pre- and post-indexing");
4778 return PARSE_OPERAND_FAIL;
4779 }
4780
4781 if (*p == '+') p++;
4782 else if (*p == '-') p++, inst.operands[i].negative = 1;
4783
4784 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4785 {
4786 /* We might be using the immediate for alignment already. If we
4787 are, OR the register number into the low-order bits. */
4788 if (inst.operands[i].immisalign)
4789 inst.operands[i].imm |= reg;
4790 else
4791 inst.operands[i].imm = reg;
4792 inst.operands[i].immisreg = 1;
4793
4794 if (skip_past_comma (&p) == SUCCESS)
4795 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4796 return PARSE_OPERAND_FAIL;
4797 }
4798 else
4799 {
4800 if (inst.operands[i].negative)
4801 {
4802 inst.operands[i].negative = 0;
4803 p--;
4804 }
4805 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4806 return PARSE_OPERAND_FAIL;
4807 }
4808 }
4809 }
4810
4811 /* If at this point neither .preind nor .postind is set, we have a
4812 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
4813 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
4814 {
4815 inst.operands[i].preind = 1;
4816 inst.reloc.exp.X_op = O_constant;
4817 inst.reloc.exp.X_add_number = 0;
4818 }
4819 *str = p;
4820 return PARSE_OPERAND_SUCCESS;
4821 }
4822
4823 static int
4824 parse_address (char **str, int i)
4825 {
4826 return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS
4827 ? SUCCESS : FAIL;
4828 }
4829
4830 static parse_operand_result
4831 parse_address_group_reloc (char **str, int i, group_reloc_type type)
4832 {
4833 return parse_address_main (str, i, 1, type);
4834 }
4835
4836 /* Parse an operand for a MOVW or MOVT instruction. */
4837 static int
4838 parse_half (char **str)
4839 {
4840 char * p;
4841
4842 p = *str;
4843 skip_past_char (&p, '#');
4844 if (strncasecmp (p, ":lower16:", 9) == 0)
4845 inst.reloc.type = BFD_RELOC_ARM_MOVW;
4846 else if (strncasecmp (p, ":upper16:", 9) == 0)
4847 inst.reloc.type = BFD_RELOC_ARM_MOVT;
4848
4849 if (inst.reloc.type != BFD_RELOC_UNUSED)
4850 {
4851 p += 9;
4852 skip_whitespace (p);
4853 }
4854
4855 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4856 return FAIL;
4857
4858 if (inst.reloc.type == BFD_RELOC_UNUSED)
4859 {
4860 if (inst.reloc.exp.X_op != O_constant)
4861 {
4862 inst.error = _("constant expression expected");
4863 return FAIL;
4864 }
4865 if (inst.reloc.exp.X_add_number < 0
4866 || inst.reloc.exp.X_add_number > 0xffff)
4867 {
4868 inst.error = _("immediate value out of range");
4869 return FAIL;
4870 }
4871 }
4872 *str = p;
4873 return SUCCESS;
4874 }
4875
4876 /* Miscellaneous. */
4877
4878 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
4879 or a bitmask suitable to be or-ed into the ARM msr instruction. */
4880 static int
4881 parse_psr (char **str)
4882 {
4883 char *p;
4884 unsigned long psr_field;
4885 const struct asm_psr *psr;
4886 char *start;
4887
4888 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
4889 feature for ease of use and backwards compatibility. */
4890 p = *str;
4891 if (strncasecmp (p, "SPSR", 4) == 0)
4892 psr_field = SPSR_BIT;
4893 else if (strncasecmp (p, "CPSR", 4) == 0)
4894 psr_field = 0;
4895 else
4896 {
4897 start = p;
4898 do
4899 p++;
4900 while (ISALNUM (*p) || *p == '_');
4901
4902 psr = hash_find_n (arm_v7m_psr_hsh, start, p - start);
4903 if (!psr)
4904 return FAIL;
4905
4906 *str = p;
4907 return psr->field;
4908 }
4909
4910 p += 4;
4911 if (*p == '_')
4912 {
4913 /* A suffix follows. */
4914 p++;
4915 start = p;
4916
4917 do
4918 p++;
4919 while (ISALNUM (*p) || *p == '_');
4920
4921 psr = hash_find_n (arm_psr_hsh, start, p - start);
4922 if (!psr)
4923 goto error;
4924
4925 psr_field |= psr->field;
4926 }
4927 else
4928 {
4929 if (ISALNUM (*p))
4930 goto error; /* Garbage after "[CS]PSR". */
4931
4932 psr_field |= (PSR_c | PSR_f);
4933 }
4934 *str = p;
4935 return psr_field;
4936
4937 error:
4938 inst.error = _("flag for {c}psr instruction expected");
4939 return FAIL;
4940 }
4941
4942 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
4943 value suitable for splatting into the AIF field of the instruction. */
4944
4945 static int
4946 parse_cps_flags (char **str)
4947 {
4948 int val = 0;
4949 int saw_a_flag = 0;
4950 char *s = *str;
4951
4952 for (;;)
4953 switch (*s++)
4954 {
4955 case '\0': case ',':
4956 goto done;
4957
4958 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
4959 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
4960 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
4961
4962 default:
4963 inst.error = _("unrecognized CPS flag");
4964 return FAIL;
4965 }
4966
4967 done:
4968 if (saw_a_flag == 0)
4969 {
4970 inst.error = _("missing CPS flags");
4971 return FAIL;
4972 }
4973
4974 *str = s - 1;
4975 return val;
4976 }
4977
4978 /* Parse an endian specifier ("BE" or "LE", case insensitive);
4979 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
4980
4981 static int
4982 parse_endian_specifier (char **str)
4983 {
4984 int little_endian;
4985 char *s = *str;
4986
4987 if (strncasecmp (s, "BE", 2))
4988 little_endian = 0;
4989 else if (strncasecmp (s, "LE", 2))
4990 little_endian = 1;
4991 else
4992 {
4993 inst.error = _("valid endian specifiers are be or le");
4994 return FAIL;
4995 }
4996
4997 if (ISALNUM (s[2]) || s[2] == '_')
4998 {
4999 inst.error = _("valid endian specifiers are be or le");
5000 return FAIL;
5001 }
5002
5003 *str = s + 2;
5004 return little_endian;
5005 }
5006
5007 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5008 value suitable for poking into the rotate field of an sxt or sxta
5009 instruction, or FAIL on error. */
5010
5011 static int
5012 parse_ror (char **str)
5013 {
5014 int rot;
5015 char *s = *str;
5016
5017 if (strncasecmp (s, "ROR", 3) == 0)
5018 s += 3;
5019 else
5020 {
5021 inst.error = _("missing rotation field after comma");
5022 return FAIL;
5023 }
5024
5025 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5026 return FAIL;
5027
5028 switch (rot)
5029 {
5030 case 0: *str = s; return 0x0;
5031 case 8: *str = s; return 0x1;
5032 case 16: *str = s; return 0x2;
5033 case 24: *str = s; return 0x3;
5034
5035 default:
5036 inst.error = _("rotation can only be 0, 8, 16, or 24");
5037 return FAIL;
5038 }
5039 }
5040
5041 /* Parse a conditional code (from conds[] below). The value returned is in the
5042 range 0 .. 14, or FAIL. */
5043 static int
5044 parse_cond (char **str)
5045 {
5046 char *p, *q;
5047 const struct asm_cond *c;
5048
5049 p = q = *str;
5050 while (ISALPHA (*q))
5051 q++;
5052
5053 c = hash_find_n (arm_cond_hsh, p, q - p);
5054 if (!c)
5055 {
5056 inst.error = _("condition required");
5057 return FAIL;
5058 }
5059
5060 *str = q;
5061 return c->value;
5062 }
5063
5064 /* Parse an option for a barrier instruction. Returns the encoding for the
5065 option, or FAIL. */
5066 static int
5067 parse_barrier (char **str)
5068 {
5069 char *p, *q;
5070 const struct asm_barrier_opt *o;
5071
5072 p = q = *str;
5073 while (ISALPHA (*q))
5074 q++;
5075
5076 o = hash_find_n (arm_barrier_opt_hsh, p, q - p);
5077 if (!o)
5078 return FAIL;
5079
5080 *str = q;
5081 return o->value;
5082 }
5083
5084 /* Parse the operands of a table branch instruction. Similar to a memory
5085 operand. */
5086 static int
5087 parse_tb (char **str)
5088 {
5089 char * p = *str;
5090 int reg;
5091
5092 if (skip_past_char (&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].reg = reg;
5104
5105 if (skip_past_comma (&p) == FAIL)
5106 {
5107 inst.error = _("',' expected");
5108 return FAIL;
5109 }
5110
5111 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5112 {
5113 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5114 return FAIL;
5115 }
5116 inst.operands[0].imm = reg;
5117
5118 if (skip_past_comma (&p) == SUCCESS)
5119 {
5120 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5121 return FAIL;
5122 if (inst.reloc.exp.X_add_number != 1)
5123 {
5124 inst.error = _("invalid shift");
5125 return FAIL;
5126 }
5127 inst.operands[0].shifted = 1;
5128 }
5129
5130 if (skip_past_char (&p, ']') == FAIL)
5131 {
5132 inst.error = _("']' expected");
5133 return FAIL;
5134 }
5135 *str = p;
5136 return SUCCESS;
5137 }
5138
5139 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5140 information on the types the operands can take and how they are encoded.
5141 Up to four operands may be read; this function handles setting the
5142 ".present" field for each read operand itself.
5143 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5144 else returns FAIL. */
5145
5146 static int
5147 parse_neon_mov (char **str, int *which_operand)
5148 {
5149 int i = *which_operand, val;
5150 enum arm_reg_type rtype;
5151 char *ptr = *str;
5152 struct neon_type_el optype;
5153
5154 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5155 {
5156 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5157 inst.operands[i].reg = val;
5158 inst.operands[i].isscalar = 1;
5159 inst.operands[i].vectype = optype;
5160 inst.operands[i++].present = 1;
5161
5162 if (skip_past_comma (&ptr) == FAIL)
5163 goto wanted_comma;
5164
5165 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5166 goto wanted_arm;
5167
5168 inst.operands[i].reg = val;
5169 inst.operands[i].isreg = 1;
5170 inst.operands[i].present = 1;
5171 }
5172 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
5173 != FAIL)
5174 {
5175 /* Cases 0, 1, 2, 3, 5 (D only). */
5176 if (skip_past_comma (&ptr) == FAIL)
5177 goto wanted_comma;
5178
5179 inst.operands[i].reg = val;
5180 inst.operands[i].isreg = 1;
5181 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5182 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5183 inst.operands[i].isvec = 1;
5184 inst.operands[i].vectype = optype;
5185 inst.operands[i++].present = 1;
5186
5187 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5188 {
5189 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5190 Case 13: VMOV <Sd>, <Rm> */
5191 inst.operands[i].reg = val;
5192 inst.operands[i].isreg = 1;
5193 inst.operands[i].present = 1;
5194
5195 if (rtype == REG_TYPE_NQ)
5196 {
5197 first_error (_("can't use Neon quad register here"));
5198 return FAIL;
5199 }
5200 else if (rtype != REG_TYPE_VFS)
5201 {
5202 i++;
5203 if (skip_past_comma (&ptr) == FAIL)
5204 goto wanted_comma;
5205 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5206 goto wanted_arm;
5207 inst.operands[i].reg = val;
5208 inst.operands[i].isreg = 1;
5209 inst.operands[i].present = 1;
5210 }
5211 }
5212 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5213 &optype)) != FAIL)
5214 {
5215 /* Case 0: VMOV<c><q> <Qd>, <Qm>
5216 Case 1: VMOV<c><q> <Dd>, <Dm>
5217 Case 8: VMOV.F32 <Sd>, <Sm>
5218 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5219
5220 inst.operands[i].reg = val;
5221 inst.operands[i].isreg = 1;
5222 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5223 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5224 inst.operands[i].isvec = 1;
5225 inst.operands[i].vectype = optype;
5226 inst.operands[i].present = 1;
5227
5228 if (skip_past_comma (&ptr) == SUCCESS)
5229 {
5230 /* Case 15. */
5231 i++;
5232
5233 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5234 goto wanted_arm;
5235
5236 inst.operands[i].reg = val;
5237 inst.operands[i].isreg = 1;
5238 inst.operands[i++].present = 1;
5239
5240 if (skip_past_comma (&ptr) == FAIL)
5241 goto wanted_comma;
5242
5243 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5244 goto wanted_arm;
5245
5246 inst.operands[i].reg = val;
5247 inst.operands[i].isreg = 1;
5248 inst.operands[i++].present = 1;
5249 }
5250 }
5251 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5252 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5253 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5254 Case 10: VMOV.F32 <Sd>, #<imm>
5255 Case 11: VMOV.F64 <Dd>, #<imm> */
5256 inst.operands[i].immisfloat = 1;
5257 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5258 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5259 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5260 ;
5261 else
5262 {
5263 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5264 return FAIL;
5265 }
5266 }
5267 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5268 {
5269 /* Cases 6, 7. */
5270 inst.operands[i].reg = val;
5271 inst.operands[i].isreg = 1;
5272 inst.operands[i++].present = 1;
5273
5274 if (skip_past_comma (&ptr) == FAIL)
5275 goto wanted_comma;
5276
5277 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5278 {
5279 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5280 inst.operands[i].reg = val;
5281 inst.operands[i].isscalar = 1;
5282 inst.operands[i].present = 1;
5283 inst.operands[i].vectype = optype;
5284 }
5285 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5286 {
5287 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5288 inst.operands[i].reg = val;
5289 inst.operands[i].isreg = 1;
5290 inst.operands[i++].present = 1;
5291
5292 if (skip_past_comma (&ptr) == FAIL)
5293 goto wanted_comma;
5294
5295 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
5296 == FAIL)
5297 {
5298 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5299 return FAIL;
5300 }
5301
5302 inst.operands[i].reg = val;
5303 inst.operands[i].isreg = 1;
5304 inst.operands[i].isvec = 1;
5305 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5306 inst.operands[i].vectype = optype;
5307 inst.operands[i].present = 1;
5308
5309 if (rtype == REG_TYPE_VFS)
5310 {
5311 /* Case 14. */
5312 i++;
5313 if (skip_past_comma (&ptr) == FAIL)
5314 goto wanted_comma;
5315 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5316 &optype)) == FAIL)
5317 {
5318 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5319 return FAIL;
5320 }
5321 inst.operands[i].reg = val;
5322 inst.operands[i].isreg = 1;
5323 inst.operands[i].isvec = 1;
5324 inst.operands[i].issingle = 1;
5325 inst.operands[i].vectype = optype;
5326 inst.operands[i].present = 1;
5327 }
5328 }
5329 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5330 != FAIL)
5331 {
5332 /* Case 13. */
5333 inst.operands[i].reg = val;
5334 inst.operands[i].isreg = 1;
5335 inst.operands[i].isvec = 1;
5336 inst.operands[i].issingle = 1;
5337 inst.operands[i].vectype = optype;
5338 inst.operands[i++].present = 1;
5339 }
5340 }
5341 else
5342 {
5343 first_error (_("parse error"));
5344 return FAIL;
5345 }
5346
5347 /* Successfully parsed the operands. Update args. */
5348 *which_operand = i;
5349 *str = ptr;
5350 return SUCCESS;
5351
5352 wanted_comma:
5353 first_error (_("expected comma"));
5354 return FAIL;
5355
5356 wanted_arm:
5357 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5358 return FAIL;
5359 }
5360
5361 /* Matcher codes for parse_operands. */
5362 enum operand_parse_code
5363 {
5364 OP_stop, /* end of line */
5365
5366 OP_RR, /* ARM register */
5367 OP_RRnpc, /* ARM register, not r15 */
5368 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5369 OP_RRw, /* ARM register, not r15, optional trailing ! */
5370 OP_RCP, /* Coprocessor number */
5371 OP_RCN, /* Coprocessor register */
5372 OP_RF, /* FPA register */
5373 OP_RVS, /* VFP single precision register */
5374 OP_RVD, /* VFP double precision register (0..15) */
5375 OP_RND, /* Neon double precision register (0..31) */
5376 OP_RNQ, /* Neon quad precision register */
5377 OP_RVSD, /* VFP single or double precision register */
5378 OP_RNDQ, /* Neon double or quad precision register */
5379 OP_RNSDQ, /* Neon single, double or quad precision register */
5380 OP_RNSC, /* Neon scalar D[X] */
5381 OP_RVC, /* VFP control register */
5382 OP_RMF, /* Maverick F register */
5383 OP_RMD, /* Maverick D register */
5384 OP_RMFX, /* Maverick FX register */
5385 OP_RMDX, /* Maverick DX register */
5386 OP_RMAX, /* Maverick AX register */
5387 OP_RMDS, /* Maverick DSPSC register */
5388 OP_RIWR, /* iWMMXt wR register */
5389 OP_RIWC, /* iWMMXt wC register */
5390 OP_RIWG, /* iWMMXt wCG register */
5391 OP_RXA, /* XScale accumulator register */
5392
5393 OP_REGLST, /* ARM register list */
5394 OP_VRSLST, /* VFP single-precision register list */
5395 OP_VRDLST, /* VFP double-precision register list */
5396 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5397 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5398 OP_NSTRLST, /* Neon element/structure list */
5399
5400 OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */
5401 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
5402 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5403 OP_RR_RNSC, /* ARM reg or Neon scalar. */
5404 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5405 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5406 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5407 OP_VMOV, /* Neon VMOV operands. */
5408 OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */
5409 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
5410 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5411
5412 OP_I0, /* immediate zero */
5413 OP_I7, /* immediate value 0 .. 7 */
5414 OP_I15, /* 0 .. 15 */
5415 OP_I16, /* 1 .. 16 */
5416 OP_I16z, /* 0 .. 16 */
5417 OP_I31, /* 0 .. 31 */
5418 OP_I31w, /* 0 .. 31, optional trailing ! */
5419 OP_I32, /* 1 .. 32 */
5420 OP_I32z, /* 0 .. 32 */
5421 OP_I63, /* 0 .. 63 */
5422 OP_I63s, /* -64 .. 63 */
5423 OP_I64, /* 1 .. 64 */
5424 OP_I64z, /* 0 .. 64 */
5425 OP_I255, /* 0 .. 255 */
5426
5427 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5428 OP_I7b, /* 0 .. 7 */
5429 OP_I15b, /* 0 .. 15 */
5430 OP_I31b, /* 0 .. 31 */
5431
5432 OP_SH, /* shifter operand */
5433 OP_SHG, /* shifter operand with possible group relocation */
5434 OP_ADDR, /* Memory address expression (any mode) */
5435 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5436 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5437 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
5438 OP_EXP, /* arbitrary expression */
5439 OP_EXPi, /* same, with optional immediate prefix */
5440 OP_EXPr, /* same, with optional relocation suffix */
5441 OP_HALF, /* 0 .. 65535 or low/high reloc. */
5442
5443 OP_CPSF, /* CPS flags */
5444 OP_ENDI, /* Endianness specifier */
5445 OP_PSR, /* CPSR/SPSR mask for msr */
5446 OP_COND, /* conditional code */
5447 OP_TB, /* Table branch. */
5448
5449 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5450 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5451
5452 OP_RRnpc_I0, /* ARM register or literal 0 */
5453 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5454 OP_RR_EXi, /* ARM register or expression with imm prefix */
5455 OP_RF_IF, /* FPA register or immediate */
5456 OP_RIWR_RIWC, /* iWMMXt R or C reg */
5457 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
5458
5459 /* Optional operands. */
5460 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5461 OP_oI31b, /* 0 .. 31 */
5462 OP_oI32b, /* 1 .. 32 */
5463 OP_oIffffb, /* 0 .. 65535 */
5464 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5465
5466 OP_oRR, /* ARM register */
5467 OP_oRRnpc, /* ARM register, not the PC */
5468 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5469 OP_oRND, /* Optional Neon double precision register */
5470 OP_oRNQ, /* Optional Neon quad precision register */
5471 OP_oRNDQ, /* Optional Neon double or quad precision register */
5472 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
5473 OP_oSHll, /* LSL immediate */
5474 OP_oSHar, /* ASR immediate */
5475 OP_oSHllar, /* LSL or ASR immediate */
5476 OP_oROR, /* ROR 0/8/16/24 */
5477 OP_oBARRIER, /* Option argument for a barrier instruction. */
5478
5479 OP_FIRST_OPTIONAL = OP_oI7b
5480 };
5481
5482 /* Generic instruction operand parser. This does no encoding and no
5483 semantic validation; it merely squirrels values away in the inst
5484 structure. Returns SUCCESS or FAIL depending on whether the
5485 specified grammar matched. */
5486 static int
5487 parse_operands (char *str, const unsigned char *pattern)
5488 {
5489 unsigned const char *upat = pattern;
5490 char *backtrack_pos = 0;
5491 const char *backtrack_error = 0;
5492 int i, val, backtrack_index = 0;
5493 enum arm_reg_type rtype;
5494 parse_operand_result result;
5495
5496 #define po_char_or_fail(chr) do { \
5497 if (skip_past_char (&str, chr) == FAIL) \
5498 goto bad_args; \
5499 } while (0)
5500
5501 #define po_reg_or_fail(regtype) do { \
5502 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5503 &inst.operands[i].vectype); \
5504 if (val == FAIL) \
5505 { \
5506 first_error (_(reg_expected_msgs[regtype])); \
5507 goto failure; \
5508 } \
5509 inst.operands[i].reg = val; \
5510 inst.operands[i].isreg = 1; \
5511 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5512 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5513 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5514 || rtype == REG_TYPE_VFD \
5515 || rtype == REG_TYPE_NQ); \
5516 } while (0)
5517
5518 #define po_reg_or_goto(regtype, label) do { \
5519 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5520 &inst.operands[i].vectype); \
5521 if (val == FAIL) \
5522 goto label; \
5523 \
5524 inst.operands[i].reg = val; \
5525 inst.operands[i].isreg = 1; \
5526 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5527 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5528 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5529 || rtype == REG_TYPE_VFD \
5530 || rtype == REG_TYPE_NQ); \
5531 } while (0)
5532
5533 #define po_imm_or_fail(min, max, popt) do { \
5534 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5535 goto failure; \
5536 inst.operands[i].imm = val; \
5537 } while (0)
5538
5539 #define po_scalar_or_goto(elsz, label) do { \
5540 val = parse_scalar (&str, elsz, &inst.operands[i].vectype); \
5541 if (val == FAIL) \
5542 goto label; \
5543 inst.operands[i].reg = val; \
5544 inst.operands[i].isscalar = 1; \
5545 } while (0)
5546
5547 #define po_misc_or_fail(expr) do { \
5548 if (expr) \
5549 goto failure; \
5550 } while (0)
5551
5552 #define po_misc_or_fail_no_backtrack(expr) do { \
5553 result = expr; \
5554 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK)\
5555 backtrack_pos = 0; \
5556 if (result != PARSE_OPERAND_SUCCESS) \
5557 goto failure; \
5558 } while (0)
5559
5560 skip_whitespace (str);
5561
5562 for (i = 0; upat[i] != OP_stop; i++)
5563 {
5564 if (upat[i] >= OP_FIRST_OPTIONAL)
5565 {
5566 /* Remember where we are in case we need to backtrack. */
5567 assert (!backtrack_pos);
5568 backtrack_pos = str;
5569 backtrack_error = inst.error;
5570 backtrack_index = i;
5571 }
5572
5573 if (i > 0 && (i > 1 || inst.operands[0].present))
5574 po_char_or_fail (',');
5575
5576 switch (upat[i])
5577 {
5578 /* Registers */
5579 case OP_oRRnpc:
5580 case OP_RRnpc:
5581 case OP_oRR:
5582 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5583 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5584 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
5585 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
5586 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
5587 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5588 case OP_oRND:
5589 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
5590 case OP_RVC:
5591 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
5592 break;
5593 /* Also accept generic coprocessor regs for unknown registers. */
5594 coproc_reg:
5595 po_reg_or_fail (REG_TYPE_CN);
5596 break;
5597 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
5598 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
5599 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
5600 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
5601 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
5602 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
5603 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
5604 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
5605 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
5606 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5607 case OP_oRNQ:
5608 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
5609 case OP_oRNDQ:
5610 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
5611 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
5612 case OP_oRNSDQ:
5613 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5614
5615 /* Neon scalar. Using an element size of 8 means that some invalid
5616 scalars are accepted here, so deal with those in later code. */
5617 case OP_RNSC: po_scalar_or_goto (8, failure); break;
5618
5619 /* WARNING: We can expand to two operands here. This has the potential
5620 to totally confuse the backtracking mechanism! It will be OK at
5621 least as long as we don't try to use optional args as well,
5622 though. */
5623 case OP_NILO:
5624 {
5625 po_reg_or_goto (REG_TYPE_NDQ, try_imm);
5626 inst.operands[i].present = 1;
5627 i++;
5628 skip_past_comma (&str);
5629 po_reg_or_goto (REG_TYPE_NDQ, one_reg_only);
5630 break;
5631 one_reg_only:
5632 /* Optional register operand was omitted. Unfortunately, it's in
5633 operands[i-1] and we need it to be in inst.operands[i]. Fix that
5634 here (this is a bit grotty). */
5635 inst.operands[i] = inst.operands[i-1];
5636 inst.operands[i-1].present = 0;
5637 break;
5638 try_imm:
5639 /* There's a possibility of getting a 64-bit immediate here, so
5640 we need special handling. */
5641 if (parse_big_immediate (&str, i) == FAIL)
5642 {
5643 inst.error = _("immediate value is out of range");
5644 goto failure;
5645 }
5646 }
5647 break;
5648
5649 case OP_RNDQ_I0:
5650 {
5651 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
5652 break;
5653 try_imm0:
5654 po_imm_or_fail (0, 0, TRUE);
5655 }
5656 break;
5657
5658 case OP_RVSD_I0:
5659 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
5660 break;
5661
5662 case OP_RR_RNSC:
5663 {
5664 po_scalar_or_goto (8, try_rr);
5665 break;
5666 try_rr:
5667 po_reg_or_fail (REG_TYPE_RN);
5668 }
5669 break;
5670
5671 case OP_RNSDQ_RNSC:
5672 {
5673 po_scalar_or_goto (8, try_nsdq);
5674 break;
5675 try_nsdq:
5676 po_reg_or_fail (REG_TYPE_NSDQ);
5677 }
5678 break;
5679
5680 case OP_RNDQ_RNSC:
5681 {
5682 po_scalar_or_goto (8, try_ndq);
5683 break;
5684 try_ndq:
5685 po_reg_or_fail (REG_TYPE_NDQ);
5686 }
5687 break;
5688
5689 case OP_RND_RNSC:
5690 {
5691 po_scalar_or_goto (8, try_vfd);
5692 break;
5693 try_vfd:
5694 po_reg_or_fail (REG_TYPE_VFD);
5695 }
5696 break;
5697
5698 case OP_VMOV:
5699 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
5700 not careful then bad things might happen. */
5701 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
5702 break;
5703
5704 case OP_RNDQ_IMVNb:
5705 {
5706 po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm);
5707 break;
5708 try_mvnimm:
5709 /* There's a possibility of getting a 64-bit immediate here, so
5710 we need special handling. */
5711 if (parse_big_immediate (&str, i) == FAIL)
5712 {
5713 inst.error = _("immediate value is out of range");
5714 goto failure;
5715 }
5716 }
5717 break;
5718
5719 case OP_RNDQ_I63b:
5720 {
5721 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
5722 break;
5723 try_shimm:
5724 po_imm_or_fail (0, 63, TRUE);
5725 }
5726 break;
5727
5728 case OP_RRnpcb:
5729 po_char_or_fail ('[');
5730 po_reg_or_fail (REG_TYPE_RN);
5731 po_char_or_fail (']');
5732 break;
5733
5734 case OP_RRw:
5735 case OP_oRRw:
5736 po_reg_or_fail (REG_TYPE_RN);
5737 if (skip_past_char (&str, '!') == SUCCESS)
5738 inst.operands[i].writeback = 1;
5739 break;
5740
5741 /* Immediates */
5742 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
5743 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
5744 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5745 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
5746 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
5747 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5748 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
5749 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5750 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
5751 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
5752 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
5753 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
5754
5755 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
5756 case OP_oI7b:
5757 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
5758 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
5759 case OP_oI31b:
5760 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5761 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
5762 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
5763
5764 /* Immediate variants */
5765 case OP_oI255c:
5766 po_char_or_fail ('{');
5767 po_imm_or_fail (0, 255, TRUE);
5768 po_char_or_fail ('}');
5769 break;
5770
5771 case OP_I31w:
5772 /* The expression parser chokes on a trailing !, so we have
5773 to find it first and zap it. */
5774 {
5775 char *s = str;
5776 while (*s && *s != ',')
5777 s++;
5778 if (s[-1] == '!')
5779 {
5780 s[-1] = '\0';
5781 inst.operands[i].writeback = 1;
5782 }
5783 po_imm_or_fail (0, 31, TRUE);
5784 if (str == s - 1)
5785 str = s;
5786 }
5787 break;
5788
5789 /* Expressions */
5790 case OP_EXPi: EXPi:
5791 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5792 GE_OPT_PREFIX));
5793 break;
5794
5795 case OP_EXP:
5796 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5797 GE_NO_PREFIX));
5798 break;
5799
5800 case OP_EXPr: EXPr:
5801 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5802 GE_NO_PREFIX));
5803 if (inst.reloc.exp.X_op == O_symbol)
5804 {
5805 val = parse_reloc (&str);
5806 if (val == -1)
5807 {
5808 inst.error = _("unrecognized relocation suffix");
5809 goto failure;
5810 }
5811 else if (val != BFD_RELOC_UNUSED)
5812 {
5813 inst.operands[i].imm = val;
5814 inst.operands[i].hasreloc = 1;
5815 }
5816 }
5817 break;
5818
5819 /* Operand for MOVW or MOVT. */
5820 case OP_HALF:
5821 po_misc_or_fail (parse_half (&str));
5822 break;
5823
5824 /* Register or expression */
5825 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
5826 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
5827
5828 /* Register or immediate */
5829 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
5830 I0: po_imm_or_fail (0, 0, FALSE); break;
5831
5832 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
5833 IF:
5834 if (!is_immediate_prefix (*str))
5835 goto bad_args;
5836 str++;
5837 val = parse_fpa_immediate (&str);
5838 if (val == FAIL)
5839 goto failure;
5840 /* FPA immediates are encoded as registers 8-15.
5841 parse_fpa_immediate has already applied the offset. */
5842 inst.operands[i].reg = val;
5843 inst.operands[i].isreg = 1;
5844 break;
5845
5846 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
5847 I32z: po_imm_or_fail (0, 32, FALSE); break;
5848
5849 /* Two kinds of register */
5850 case OP_RIWR_RIWC:
5851 {
5852 struct reg_entry *rege = arm_reg_parse_multi (&str);
5853 if (!rege
5854 || (rege->type != REG_TYPE_MMXWR
5855 && rege->type != REG_TYPE_MMXWC
5856 && rege->type != REG_TYPE_MMXWCG))
5857 {
5858 inst.error = _("iWMMXt data or control register expected");
5859 goto failure;
5860 }
5861 inst.operands[i].reg = rege->number;
5862 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
5863 }
5864 break;
5865
5866 case OP_RIWC_RIWG:
5867 {
5868 struct reg_entry *rege = arm_reg_parse_multi (&str);
5869 if (!rege
5870 || (rege->type != REG_TYPE_MMXWC
5871 && rege->type != REG_TYPE_MMXWCG))
5872 {
5873 inst.error = _("iWMMXt control register expected");
5874 goto failure;
5875 }
5876 inst.operands[i].reg = rege->number;
5877 inst.operands[i].isreg = 1;
5878 }
5879 break;
5880
5881 /* Misc */
5882 case OP_CPSF: val = parse_cps_flags (&str); break;
5883 case OP_ENDI: val = parse_endian_specifier (&str); break;
5884 case OP_oROR: val = parse_ror (&str); break;
5885 case OP_PSR: val = parse_psr (&str); break;
5886 case OP_COND: val = parse_cond (&str); break;
5887 case OP_oBARRIER:val = parse_barrier (&str); break;
5888
5889 case OP_RVC_PSR:
5890 po_reg_or_goto (REG_TYPE_VFC, try_psr);
5891 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
5892 break;
5893 try_psr:
5894 val = parse_psr (&str);
5895 break;
5896
5897 case OP_APSR_RR:
5898 po_reg_or_goto (REG_TYPE_RN, try_apsr);
5899 break;
5900 try_apsr:
5901 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
5902 instruction). */
5903 if (strncasecmp (str, "APSR_", 5) == 0)
5904 {
5905 unsigned found = 0;
5906 str += 5;
5907 while (found < 15)
5908 switch (*str++)
5909 {
5910 case 'c': found = (found & 1) ? 16 : found | 1; break;
5911 case 'n': found = (found & 2) ? 16 : found | 2; break;
5912 case 'z': found = (found & 4) ? 16 : found | 4; break;
5913 case 'v': found = (found & 8) ? 16 : found | 8; break;
5914 default: found = 16;
5915 }
5916 if (found != 15)
5917 goto failure;
5918 inst.operands[i].isvec = 1;
5919 }
5920 else
5921 goto failure;
5922 break;
5923
5924 case OP_TB:
5925 po_misc_or_fail (parse_tb (&str));
5926 break;
5927
5928 /* Register lists */
5929 case OP_REGLST:
5930 val = parse_reg_list (&str);
5931 if (*str == '^')
5932 {
5933 inst.operands[1].writeback = 1;
5934 str++;
5935 }
5936 break;
5937
5938 case OP_VRSLST:
5939 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
5940 break;
5941
5942 case OP_VRDLST:
5943 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
5944 break;
5945
5946 case OP_VRSDLST:
5947 /* Allow Q registers too. */
5948 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5949 REGLIST_NEON_D);
5950 if (val == FAIL)
5951 {
5952 inst.error = NULL;
5953 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5954 REGLIST_VFP_S);
5955 inst.operands[i].issingle = 1;
5956 }
5957 break;
5958
5959 case OP_NRDLST:
5960 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5961 REGLIST_NEON_D);
5962 break;
5963
5964 case OP_NSTRLST:
5965 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
5966 &inst.operands[i].vectype);
5967 break;
5968
5969 /* Addressing modes */
5970 case OP_ADDR:
5971 po_misc_or_fail (parse_address (&str, i));
5972 break;
5973
5974 case OP_ADDRGLDR:
5975 po_misc_or_fail_no_backtrack (
5976 parse_address_group_reloc (&str, i, GROUP_LDR));
5977 break;
5978
5979 case OP_ADDRGLDRS:
5980 po_misc_or_fail_no_backtrack (
5981 parse_address_group_reloc (&str, i, GROUP_LDRS));
5982 break;
5983
5984 case OP_ADDRGLDC:
5985 po_misc_or_fail_no_backtrack (
5986 parse_address_group_reloc (&str, i, GROUP_LDC));
5987 break;
5988
5989 case OP_SH:
5990 po_misc_or_fail (parse_shifter_operand (&str, i));
5991 break;
5992
5993 case OP_SHG:
5994 po_misc_or_fail_no_backtrack (
5995 parse_shifter_operand_group_reloc (&str, i));
5996 break;
5997
5998 case OP_oSHll:
5999 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6000 break;
6001
6002 case OP_oSHar:
6003 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6004 break;
6005
6006 case OP_oSHllar:
6007 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6008 break;
6009
6010 default:
6011 as_fatal (_("unhandled operand code %d"), upat[i]);
6012 }
6013
6014 /* Various value-based sanity checks and shared operations. We
6015 do not signal immediate failures for the register constraints;
6016 this allows a syntax error to take precedence. */
6017 switch (upat[i])
6018 {
6019 case OP_oRRnpc:
6020 case OP_RRnpc:
6021 case OP_RRnpcb:
6022 case OP_RRw:
6023 case OP_oRRw:
6024 case OP_RRnpc_I0:
6025 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6026 inst.error = BAD_PC;
6027 break;
6028
6029 case OP_CPSF:
6030 case OP_ENDI:
6031 case OP_oROR:
6032 case OP_PSR:
6033 case OP_RVC_PSR:
6034 case OP_COND:
6035 case OP_oBARRIER:
6036 case OP_REGLST:
6037 case OP_VRSLST:
6038 case OP_VRDLST:
6039 case OP_VRSDLST:
6040 case OP_NRDLST:
6041 case OP_NSTRLST:
6042 if (val == FAIL)
6043 goto failure;
6044 inst.operands[i].imm = val;
6045 break;
6046
6047 default:
6048 break;
6049 }
6050
6051 /* If we get here, this operand was successfully parsed. */
6052 inst.operands[i].present = 1;
6053 continue;
6054
6055 bad_args:
6056 inst.error = BAD_ARGS;
6057
6058 failure:
6059 if (!backtrack_pos)
6060 {
6061 /* The parse routine should already have set inst.error, but set a
6062 default here just in case. */
6063 if (!inst.error)
6064 inst.error = _("syntax error");
6065 return FAIL;
6066 }
6067
6068 /* Do not backtrack over a trailing optional argument that
6069 absorbed some text. We will only fail again, with the
6070 'garbage following instruction' error message, which is
6071 probably less helpful than the current one. */
6072 if (backtrack_index == i && backtrack_pos != str
6073 && upat[i+1] == OP_stop)
6074 {
6075 if (!inst.error)
6076 inst.error = _("syntax error");
6077 return FAIL;
6078 }
6079
6080 /* Try again, skipping the optional argument at backtrack_pos. */
6081 str = backtrack_pos;
6082 inst.error = backtrack_error;
6083 inst.operands[backtrack_index].present = 0;
6084 i = backtrack_index;
6085 backtrack_pos = 0;
6086 }
6087
6088 /* Check that we have parsed all the arguments. */
6089 if (*str != '\0' && !inst.error)
6090 inst.error = _("garbage following instruction");
6091
6092 return inst.error ? FAIL : SUCCESS;
6093 }
6094
6095 #undef po_char_or_fail
6096 #undef po_reg_or_fail
6097 #undef po_reg_or_goto
6098 #undef po_imm_or_fail
6099 #undef po_scalar_or_fail
6100 \f
6101 /* Shorthand macro for instruction encoding functions issuing errors. */
6102 #define constraint(expr, err) do { \
6103 if (expr) \
6104 { \
6105 inst.error = err; \
6106 return; \
6107 } \
6108 } while (0)
6109
6110 /* Functions for operand encoding. ARM, then Thumb. */
6111
6112 #define rotate_left(v, n) (v << n | v >> (32 - n))
6113
6114 /* If VAL can be encoded in the immediate field of an ARM instruction,
6115 return the encoded form. Otherwise, return FAIL. */
6116
6117 static unsigned int
6118 encode_arm_immediate (unsigned int val)
6119 {
6120 unsigned int a, i;
6121
6122 for (i = 0; i < 32; i += 2)
6123 if ((a = rotate_left (val, i)) <= 0xff)
6124 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6125
6126 return FAIL;
6127 }
6128
6129 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6130 return the encoded form. Otherwise, return FAIL. */
6131 static unsigned int
6132 encode_thumb32_immediate (unsigned int val)
6133 {
6134 unsigned int a, i;
6135
6136 if (val <= 0xff)
6137 return val;
6138
6139 for (i = 1; i <= 24; i++)
6140 {
6141 a = val >> i;
6142 if ((val & ~(0xff << i)) == 0)
6143 return ((val >> i) & 0x7f) | ((32 - i) << 7);
6144 }
6145
6146 a = val & 0xff;
6147 if (val == ((a << 16) | a))
6148 return 0x100 | a;
6149 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6150 return 0x300 | a;
6151
6152 a = val & 0xff00;
6153 if (val == ((a << 16) | a))
6154 return 0x200 | (a >> 8);
6155
6156 return FAIL;
6157 }
6158 /* Encode a VFP SP or DP register number into inst.instruction. */
6159
6160 static void
6161 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6162 {
6163 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6164 && reg > 15)
6165 {
6166 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
6167 {
6168 if (thumb_mode)
6169 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
6170 fpu_vfp_ext_d32);
6171 else
6172 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
6173 fpu_vfp_ext_d32);
6174 }
6175 else
6176 {
6177 first_error (_("D register out of range for selected VFP version"));
6178 return;
6179 }
6180 }
6181
6182 switch (pos)
6183 {
6184 case VFP_REG_Sd:
6185 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6186 break;
6187
6188 case VFP_REG_Sn:
6189 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6190 break;
6191
6192 case VFP_REG_Sm:
6193 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6194 break;
6195
6196 case VFP_REG_Dd:
6197 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6198 break;
6199
6200 case VFP_REG_Dn:
6201 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6202 break;
6203
6204 case VFP_REG_Dm:
6205 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6206 break;
6207
6208 default:
6209 abort ();
6210 }
6211 }
6212
6213 /* Encode a <shift> in an ARM-format instruction. The immediate,
6214 if any, is handled by md_apply_fix. */
6215 static void
6216 encode_arm_shift (int i)
6217 {
6218 if (inst.operands[i].shift_kind == SHIFT_RRX)
6219 inst.instruction |= SHIFT_ROR << 5;
6220 else
6221 {
6222 inst.instruction |= inst.operands[i].shift_kind << 5;
6223 if (inst.operands[i].immisreg)
6224 {
6225 inst.instruction |= SHIFT_BY_REG;
6226 inst.instruction |= inst.operands[i].imm << 8;
6227 }
6228 else
6229 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6230 }
6231 }
6232
6233 static void
6234 encode_arm_shifter_operand (int i)
6235 {
6236 if (inst.operands[i].isreg)
6237 {
6238 inst.instruction |= inst.operands[i].reg;
6239 encode_arm_shift (i);
6240 }
6241 else
6242 inst.instruction |= INST_IMMEDIATE;
6243 }
6244
6245 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
6246 static void
6247 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
6248 {
6249 assert (inst.operands[i].isreg);
6250 inst.instruction |= inst.operands[i].reg << 16;
6251
6252 if (inst.operands[i].preind)
6253 {
6254 if (is_t)
6255 {
6256 inst.error = _("instruction does not accept preindexed addressing");
6257 return;
6258 }
6259 inst.instruction |= PRE_INDEX;
6260 if (inst.operands[i].writeback)
6261 inst.instruction |= WRITE_BACK;
6262
6263 }
6264 else if (inst.operands[i].postind)
6265 {
6266 assert (inst.operands[i].writeback);
6267 if (is_t)
6268 inst.instruction |= WRITE_BACK;
6269 }
6270 else /* unindexed - only for coprocessor */
6271 {
6272 inst.error = _("instruction does not accept unindexed addressing");
6273 return;
6274 }
6275
6276 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6277 && (((inst.instruction & 0x000f0000) >> 16)
6278 == ((inst.instruction & 0x0000f000) >> 12)))
6279 as_warn ((inst.instruction & LOAD_BIT)
6280 ? _("destination register same as write-back base")
6281 : _("source register same as write-back base"));
6282 }
6283
6284 /* inst.operands[i] was set up by parse_address. Encode it into an
6285 ARM-format mode 2 load or store instruction. If is_t is true,
6286 reject forms that cannot be used with a T instruction (i.e. not
6287 post-indexed). */
6288 static void
6289 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
6290 {
6291 encode_arm_addr_mode_common (i, is_t);
6292
6293 if (inst.operands[i].immisreg)
6294 {
6295 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6296 inst.instruction |= inst.operands[i].imm;
6297 if (!inst.operands[i].negative)
6298 inst.instruction |= INDEX_UP;
6299 if (inst.operands[i].shifted)
6300 {
6301 if (inst.operands[i].shift_kind == SHIFT_RRX)
6302 inst.instruction |= SHIFT_ROR << 5;
6303 else
6304 {
6305 inst.instruction |= inst.operands[i].shift_kind << 5;
6306 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6307 }
6308 }
6309 }
6310 else /* immediate offset in inst.reloc */
6311 {
6312 if (inst.reloc.type == BFD_RELOC_UNUSED)
6313 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
6314 }
6315 }
6316
6317 /* inst.operands[i] was set up by parse_address. Encode it into an
6318 ARM-format mode 3 load or store instruction. Reject forms that
6319 cannot be used with such instructions. If is_t is true, reject
6320 forms that cannot be used with a T instruction (i.e. not
6321 post-indexed). */
6322 static void
6323 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
6324 {
6325 if (inst.operands[i].immisreg && inst.operands[i].shifted)
6326 {
6327 inst.error = _("instruction does not accept scaled register index");
6328 return;
6329 }
6330
6331 encode_arm_addr_mode_common (i, is_t);
6332
6333 if (inst.operands[i].immisreg)
6334 {
6335 inst.instruction |= inst.operands[i].imm;
6336 if (!inst.operands[i].negative)
6337 inst.instruction |= INDEX_UP;
6338 }
6339 else /* immediate offset in inst.reloc */
6340 {
6341 inst.instruction |= HWOFFSET_IMM;
6342 if (inst.reloc.type == BFD_RELOC_UNUSED)
6343 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
6344 }
6345 }
6346
6347 /* inst.operands[i] was set up by parse_address. Encode it into an
6348 ARM-format instruction. Reject all forms which cannot be encoded
6349 into a coprocessor load/store instruction. If wb_ok is false,
6350 reject use of writeback; if unind_ok is false, reject use of
6351 unindexed addressing. If reloc_override is not 0, use it instead
6352 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6353 (in which case it is preserved). */
6354
6355 static int
6356 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
6357 {
6358 inst.instruction |= inst.operands[i].reg << 16;
6359
6360 assert (!(inst.operands[i].preind && inst.operands[i].postind));
6361
6362 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
6363 {
6364 assert (!inst.operands[i].writeback);
6365 if (!unind_ok)
6366 {
6367 inst.error = _("instruction does not support unindexed addressing");
6368 return FAIL;
6369 }
6370 inst.instruction |= inst.operands[i].imm;
6371 inst.instruction |= INDEX_UP;
6372 return SUCCESS;
6373 }
6374
6375 if (inst.operands[i].preind)
6376 inst.instruction |= PRE_INDEX;
6377
6378 if (inst.operands[i].writeback)
6379 {
6380 if (inst.operands[i].reg == REG_PC)
6381 {
6382 inst.error = _("pc may not be used with write-back");
6383 return FAIL;
6384 }
6385 if (!wb_ok)
6386 {
6387 inst.error = _("instruction does not support writeback");
6388 return FAIL;
6389 }
6390 inst.instruction |= WRITE_BACK;
6391 }
6392
6393 if (reloc_override)
6394 inst.reloc.type = reloc_override;
6395 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6396 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6397 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6398 {
6399 if (thumb_mode)
6400 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6401 else
6402 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6403 }
6404
6405 return SUCCESS;
6406 }
6407
6408 /* inst.reloc.exp describes an "=expr" load pseudo-operation.
6409 Determine whether it can be performed with a move instruction; if
6410 it can, convert inst.instruction to that move instruction and
6411 return 1; if it can't, convert inst.instruction to a literal-pool
6412 load and return 0. If this is not a valid thing to do in the
6413 current context, set inst.error and return 1.
6414
6415 inst.operands[i] describes the destination register. */
6416
6417 static int
6418 move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6419 {
6420 unsigned long tbit;
6421
6422 if (thumb_p)
6423 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6424 else
6425 tbit = LOAD_BIT;
6426
6427 if ((inst.instruction & tbit) == 0)
6428 {
6429 inst.error = _("invalid pseudo operation");
6430 return 1;
6431 }
6432 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
6433 {
6434 inst.error = _("constant expression expected");
6435 return 1;
6436 }
6437 if (inst.reloc.exp.X_op == O_constant)
6438 {
6439 if (thumb_p)
6440 {
6441 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
6442 {
6443 /* This can be done with a mov(1) instruction. */
6444 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6445 inst.instruction |= inst.reloc.exp.X_add_number;
6446 return 1;
6447 }
6448 }
6449 else
6450 {
6451 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6452 if (value != FAIL)
6453 {
6454 /* This can be done with a mov instruction. */
6455 inst.instruction &= LITERAL_MASK;
6456 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6457 inst.instruction |= value & 0xfff;
6458 return 1;
6459 }
6460
6461 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6462 if (value != FAIL)
6463 {
6464 /* This can be done with a mvn instruction. */
6465 inst.instruction &= LITERAL_MASK;
6466 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6467 inst.instruction |= value & 0xfff;
6468 return 1;
6469 }
6470 }
6471 }
6472
6473 if (add_to_lit_pool () == FAIL)
6474 {
6475 inst.error = _("literal pool insertion failed");
6476 return 1;
6477 }
6478 inst.operands[1].reg = REG_PC;
6479 inst.operands[1].isreg = 1;
6480 inst.operands[1].preind = 1;
6481 inst.reloc.pc_rel = 1;
6482 inst.reloc.type = (thumb_p
6483 ? BFD_RELOC_ARM_THUMB_OFFSET
6484 : (mode_3
6485 ? BFD_RELOC_ARM_HWLITERAL
6486 : BFD_RELOC_ARM_LITERAL));
6487 return 0;
6488 }
6489
6490 /* Functions for instruction encoding, sorted by sub-architecture.
6491 First some generics; their names are taken from the conventional
6492 bit positions for register arguments in ARM format instructions. */
6493
6494 static void
6495 do_noargs (void)
6496 {
6497 }
6498
6499 static void
6500 do_rd (void)
6501 {
6502 inst.instruction |= inst.operands[0].reg << 12;
6503 }
6504
6505 static void
6506 do_rd_rm (void)
6507 {
6508 inst.instruction |= inst.operands[0].reg << 12;
6509 inst.instruction |= inst.operands[1].reg;
6510 }
6511
6512 static void
6513 do_rd_rn (void)
6514 {
6515 inst.instruction |= inst.operands[0].reg << 12;
6516 inst.instruction |= inst.operands[1].reg << 16;
6517 }
6518
6519 static void
6520 do_rn_rd (void)
6521 {
6522 inst.instruction |= inst.operands[0].reg << 16;
6523 inst.instruction |= inst.operands[1].reg << 12;
6524 }
6525
6526 static void
6527 do_rd_rm_rn (void)
6528 {
6529 unsigned Rn = inst.operands[2].reg;
6530 /* Enforce restrictions on SWP instruction. */
6531 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6532 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6533 _("Rn must not overlap other operands"));
6534 inst.instruction |= inst.operands[0].reg << 12;
6535 inst.instruction |= inst.operands[1].reg;
6536 inst.instruction |= Rn << 16;
6537 }
6538
6539 static void
6540 do_rd_rn_rm (void)
6541 {
6542 inst.instruction |= inst.operands[0].reg << 12;
6543 inst.instruction |= inst.operands[1].reg << 16;
6544 inst.instruction |= inst.operands[2].reg;
6545 }
6546
6547 static void
6548 do_rm_rd_rn (void)
6549 {
6550 inst.instruction |= inst.operands[0].reg;
6551 inst.instruction |= inst.operands[1].reg << 12;
6552 inst.instruction |= inst.operands[2].reg << 16;
6553 }
6554
6555 static void
6556 do_imm0 (void)
6557 {
6558 inst.instruction |= inst.operands[0].imm;
6559 }
6560
6561 static void
6562 do_rd_cpaddr (void)
6563 {
6564 inst.instruction |= inst.operands[0].reg << 12;
6565 encode_arm_cp_address (1, TRUE, TRUE, 0);
6566 }
6567
6568 /* ARM instructions, in alphabetical order by function name (except
6569 that wrapper functions appear immediately after the function they
6570 wrap). */
6571
6572 /* This is a pseudo-op of the form "adr rd, label" to be converted
6573 into a relative address of the form "add rd, pc, #label-.-8". */
6574
6575 static void
6576 do_adr (void)
6577 {
6578 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
6579
6580 /* Frag hacking will turn this into a sub instruction if the offset turns
6581 out to be negative. */
6582 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
6583 inst.reloc.pc_rel = 1;
6584 inst.reloc.exp.X_add_number -= 8;
6585 }
6586
6587 /* This is a pseudo-op of the form "adrl rd, label" to be converted
6588 into a relative address of the form:
6589 add rd, pc, #low(label-.-8)"
6590 add rd, rd, #high(label-.-8)" */
6591
6592 static void
6593 do_adrl (void)
6594 {
6595 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
6596
6597 /* Frag hacking will turn this into a sub instruction if the offset turns
6598 out to be negative. */
6599 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
6600 inst.reloc.pc_rel = 1;
6601 inst.size = INSN_SIZE * 2;
6602 inst.reloc.exp.X_add_number -= 8;
6603 }
6604
6605 static void
6606 do_arit (void)
6607 {
6608 if (!inst.operands[1].present)
6609 inst.operands[1].reg = inst.operands[0].reg;
6610 inst.instruction |= inst.operands[0].reg << 12;
6611 inst.instruction |= inst.operands[1].reg << 16;
6612 encode_arm_shifter_operand (2);
6613 }
6614
6615 static void
6616 do_barrier (void)
6617 {
6618 if (inst.operands[0].present)
6619 {
6620 constraint ((inst.instruction & 0xf0) != 0x40
6621 && inst.operands[0].imm != 0xf,
6622 _("bad barrier type"));
6623 inst.instruction |= inst.operands[0].imm;
6624 }
6625 else
6626 inst.instruction |= 0xf;
6627 }
6628
6629 static void
6630 do_bfc (void)
6631 {
6632 unsigned int msb = inst.operands[1].imm + inst.operands[2].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].imm << 7;
6638 inst.instruction |= (msb - 1) << 16;
6639 }
6640
6641 static void
6642 do_bfi (void)
6643 {
6644 unsigned int msb;
6645
6646 /* #0 in second position is alternative syntax for bfc, which is
6647 the same instruction but with REG_PC in the Rm field. */
6648 if (!inst.operands[1].isreg)
6649 inst.operands[1].reg = REG_PC;
6650
6651 msb = inst.operands[2].imm + inst.operands[3].imm;
6652 constraint (msb > 32, _("bit-field extends past end of register"));
6653 /* The instruction encoding stores the LSB and MSB,
6654 not the LSB and width. */
6655 inst.instruction |= inst.operands[0].reg << 12;
6656 inst.instruction |= inst.operands[1].reg;
6657 inst.instruction |= inst.operands[2].imm << 7;
6658 inst.instruction |= (msb - 1) << 16;
6659 }
6660
6661 static void
6662 do_bfx (void)
6663 {
6664 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6665 _("bit-field extends past end of register"));
6666 inst.instruction |= inst.operands[0].reg << 12;
6667 inst.instruction |= inst.operands[1].reg;
6668 inst.instruction |= inst.operands[2].imm << 7;
6669 inst.instruction |= (inst.operands[3].imm - 1) << 16;
6670 }
6671
6672 /* ARM V5 breakpoint instruction (argument parse)
6673 BKPT <16 bit unsigned immediate>
6674 Instruction is not conditional.
6675 The bit pattern given in insns[] has the COND_ALWAYS condition,
6676 and it is an error if the caller tried to override that. */
6677
6678 static void
6679 do_bkpt (void)
6680 {
6681 /* Top 12 of 16 bits to bits 19:8. */
6682 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
6683
6684 /* Bottom 4 of 16 bits to bits 3:0. */
6685 inst.instruction |= inst.operands[0].imm & 0xf;
6686 }
6687
6688 static void
6689 encode_branch (int default_reloc)
6690 {
6691 if (inst.operands[0].hasreloc)
6692 {
6693 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
6694 _("the only suffix valid here is '(plt)'"));
6695 inst.reloc.type = BFD_RELOC_ARM_PLT32;
6696 }
6697 else
6698 {
6699 inst.reloc.type = default_reloc;
6700 }
6701 inst.reloc.pc_rel = 1;
6702 }
6703
6704 static void
6705 do_branch (void)
6706 {
6707 #ifdef OBJ_ELF
6708 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6709 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6710 else
6711 #endif
6712 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6713 }
6714
6715 static void
6716 do_bl (void)
6717 {
6718 #ifdef OBJ_ELF
6719 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6720 {
6721 if (inst.cond == COND_ALWAYS)
6722 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6723 else
6724 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6725 }
6726 else
6727 #endif
6728 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6729 }
6730
6731 /* ARM V5 branch-link-exchange instruction (argument parse)
6732 BLX <target_addr> ie BLX(1)
6733 BLX{<condition>} <Rm> ie BLX(2)
6734 Unfortunately, there are two different opcodes for this mnemonic.
6735 So, the insns[].value is not used, and the code here zaps values
6736 into inst.instruction.
6737 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
6738
6739 static void
6740 do_blx (void)
6741 {
6742 if (inst.operands[0].isreg)
6743 {
6744 /* Arg is a register; the opcode provided by insns[] is correct.
6745 It is not illegal to do "blx pc", just useless. */
6746 if (inst.operands[0].reg == REG_PC)
6747 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
6748
6749 inst.instruction |= inst.operands[0].reg;
6750 }
6751 else
6752 {
6753 /* Arg is an address; this instruction cannot be executed
6754 conditionally, and the opcode must be adjusted. */
6755 constraint (inst.cond != COND_ALWAYS, BAD_COND);
6756 inst.instruction = 0xfa000000;
6757 #ifdef OBJ_ELF
6758 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6759 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6760 else
6761 #endif
6762 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
6763 }
6764 }
6765
6766 static void
6767 do_bx (void)
6768 {
6769 bfd_boolean want_reloc;
6770
6771 if (inst.operands[0].reg == REG_PC)
6772 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
6773
6774 inst.instruction |= inst.operands[0].reg;
6775 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
6776 it is for ARMv4t or earlier. */
6777 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
6778 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
6779 want_reloc = TRUE;
6780
6781 #ifdef OBJ_ELF
6782 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
6783 #endif
6784 want_reloc = FALSE;
6785
6786 if (want_reloc)
6787 inst.reloc.type = BFD_RELOC_ARM_V4BX;
6788 }
6789
6790
6791 /* ARM v5TEJ. Jump to Jazelle code. */
6792
6793 static void
6794 do_bxj (void)
6795 {
6796 if (inst.operands[0].reg == REG_PC)
6797 as_tsktsk (_("use of r15 in bxj is not really useful"));
6798
6799 inst.instruction |= inst.operands[0].reg;
6800 }
6801
6802 /* Co-processor data operation:
6803 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
6804 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
6805 static void
6806 do_cdp (void)
6807 {
6808 inst.instruction |= inst.operands[0].reg << 8;
6809 inst.instruction |= inst.operands[1].imm << 20;
6810 inst.instruction |= inst.operands[2].reg << 12;
6811 inst.instruction |= inst.operands[3].reg << 16;
6812 inst.instruction |= inst.operands[4].reg;
6813 inst.instruction |= inst.operands[5].imm << 5;
6814 }
6815
6816 static void
6817 do_cmp (void)
6818 {
6819 inst.instruction |= inst.operands[0].reg << 16;
6820 encode_arm_shifter_operand (1);
6821 }
6822
6823 /* Transfer between coprocessor and ARM registers.
6824 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
6825 MRC2
6826 MCR{cond}
6827 MCR2
6828
6829 No special properties. */
6830
6831 static void
6832 do_co_reg (void)
6833 {
6834 inst.instruction |= inst.operands[0].reg << 8;
6835 inst.instruction |= inst.operands[1].imm << 21;
6836 inst.instruction |= inst.operands[2].reg << 12;
6837 inst.instruction |= inst.operands[3].reg << 16;
6838 inst.instruction |= inst.operands[4].reg;
6839 inst.instruction |= inst.operands[5].imm << 5;
6840 }
6841
6842 /* Transfer between coprocessor register and pair of ARM registers.
6843 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
6844 MCRR2
6845 MRRC{cond}
6846 MRRC2
6847
6848 Two XScale instructions are special cases of these:
6849
6850 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
6851 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
6852
6853 Result unpredictable if Rd or Rn is R15. */
6854
6855 static void
6856 do_co_reg2c (void)
6857 {
6858 inst.instruction |= inst.operands[0].reg << 8;
6859 inst.instruction |= inst.operands[1].imm << 4;
6860 inst.instruction |= inst.operands[2].reg << 12;
6861 inst.instruction |= inst.operands[3].reg << 16;
6862 inst.instruction |= inst.operands[4].reg;
6863 }
6864
6865 static void
6866 do_cpsi (void)
6867 {
6868 inst.instruction |= inst.operands[0].imm << 6;
6869 if (inst.operands[1].present)
6870 {
6871 inst.instruction |= CPSI_MMOD;
6872 inst.instruction |= inst.operands[1].imm;
6873 }
6874 }
6875
6876 static void
6877 do_dbg (void)
6878 {
6879 inst.instruction |= inst.operands[0].imm;
6880 }
6881
6882 static void
6883 do_it (void)
6884 {
6885 /* There is no IT instruction in ARM mode. We
6886 process it but do not generate code for it. */
6887 inst.size = 0;
6888 }
6889
6890 static void
6891 do_ldmstm (void)
6892 {
6893 int base_reg = inst.operands[0].reg;
6894 int range = inst.operands[1].imm;
6895
6896 inst.instruction |= base_reg << 16;
6897 inst.instruction |= range;
6898
6899 if (inst.operands[1].writeback)
6900 inst.instruction |= LDM_TYPE_2_OR_3;
6901
6902 if (inst.operands[0].writeback)
6903 {
6904 inst.instruction |= WRITE_BACK;
6905 /* Check for unpredictable uses of writeback. */
6906 if (inst.instruction & LOAD_BIT)
6907 {
6908 /* Not allowed in LDM type 2. */
6909 if ((inst.instruction & LDM_TYPE_2_OR_3)
6910 && ((range & (1 << REG_PC)) == 0))
6911 as_warn (_("writeback of base register is UNPREDICTABLE"));
6912 /* Only allowed if base reg not in list for other types. */
6913 else if (range & (1 << base_reg))
6914 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
6915 }
6916 else /* STM. */
6917 {
6918 /* Not allowed for type 2. */
6919 if (inst.instruction & LDM_TYPE_2_OR_3)
6920 as_warn (_("writeback of base register is UNPREDICTABLE"));
6921 /* Only allowed if base reg not in list, or first in list. */
6922 else if ((range & (1 << base_reg))
6923 && (range & ((1 << base_reg) - 1)))
6924 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
6925 }
6926 }
6927 }
6928
6929 /* ARMv5TE load-consecutive (argument parse)
6930 Mode is like LDRH.
6931
6932 LDRccD R, mode
6933 STRccD R, mode. */
6934
6935 static void
6936 do_ldrd (void)
6937 {
6938 constraint (inst.operands[0].reg % 2 != 0,
6939 _("first destination register must be even"));
6940 constraint (inst.operands[1].present
6941 && inst.operands[1].reg != inst.operands[0].reg + 1,
6942 _("can only load two consecutive registers"));
6943 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
6944 constraint (!inst.operands[2].isreg, _("'[' expected"));
6945
6946 if (!inst.operands[1].present)
6947 inst.operands[1].reg = inst.operands[0].reg + 1;
6948
6949 if (inst.instruction & LOAD_BIT)
6950 {
6951 /* encode_arm_addr_mode_3 will diagnose overlap between the base
6952 register and the first register written; we have to diagnose
6953 overlap between the base and the second register written here. */
6954
6955 if (inst.operands[2].reg == inst.operands[1].reg
6956 && (inst.operands[2].writeback || inst.operands[2].postind))
6957 as_warn (_("base register written back, and overlaps "
6958 "second destination register"));
6959
6960 /* For an index-register load, the index register must not overlap the
6961 destination (even if not write-back). */
6962 else if (inst.operands[2].immisreg
6963 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
6964 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
6965 as_warn (_("index register overlaps destination register"));
6966 }
6967
6968 inst.instruction |= inst.operands[0].reg << 12;
6969 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
6970 }
6971
6972 static void
6973 do_ldrex (void)
6974 {
6975 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
6976 || inst.operands[1].postind || inst.operands[1].writeback
6977 || inst.operands[1].immisreg || inst.operands[1].shifted
6978 || inst.operands[1].negative
6979 /* This can arise if the programmer has written
6980 strex rN, rM, foo
6981 or if they have mistakenly used a register name as the last
6982 operand, eg:
6983 strex rN, rM, rX
6984 It is very difficult to distinguish between these two cases
6985 because "rX" might actually be a label. ie the register
6986 name has been occluded by a symbol of the same name. So we
6987 just generate a general 'bad addressing mode' type error
6988 message and leave it up to the programmer to discover the
6989 true cause and fix their mistake. */
6990 || (inst.operands[1].reg == REG_PC),
6991 BAD_ADDR_MODE);
6992
6993 constraint (inst.reloc.exp.X_op != O_constant
6994 || inst.reloc.exp.X_add_number != 0,
6995 _("offset must be zero in ARM encoding"));
6996
6997 inst.instruction |= inst.operands[0].reg << 12;
6998 inst.instruction |= inst.operands[1].reg << 16;
6999 inst.reloc.type = BFD_RELOC_UNUSED;
7000 }
7001
7002 static void
7003 do_ldrexd (void)
7004 {
7005 constraint (inst.operands[0].reg % 2 != 0,
7006 _("even register required"));
7007 constraint (inst.operands[1].present
7008 && inst.operands[1].reg != inst.operands[0].reg + 1,
7009 _("can only load two consecutive registers"));
7010 /* If op 1 were present and equal to PC, this function wouldn't
7011 have been called in the first place. */
7012 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7013
7014 inst.instruction |= inst.operands[0].reg << 12;
7015 inst.instruction |= inst.operands[2].reg << 16;
7016 }
7017
7018 static void
7019 do_ldst (void)
7020 {
7021 inst.instruction |= inst.operands[0].reg << 12;
7022 if (!inst.operands[1].isreg)
7023 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
7024 return;
7025 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
7026 }
7027
7028 static void
7029 do_ldstt (void)
7030 {
7031 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7032 reject [Rn,...]. */
7033 if (inst.operands[1].preind)
7034 {
7035 constraint (inst.reloc.exp.X_op != O_constant
7036 || inst.reloc.exp.X_add_number != 0,
7037 _("this instruction requires a post-indexed address"));
7038
7039 inst.operands[1].preind = 0;
7040 inst.operands[1].postind = 1;
7041 inst.operands[1].writeback = 1;
7042 }
7043 inst.instruction |= inst.operands[0].reg << 12;
7044 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7045 }
7046
7047 /* Halfword and signed-byte load/store operations. */
7048
7049 static void
7050 do_ldstv4 (void)
7051 {
7052 inst.instruction |= inst.operands[0].reg << 12;
7053 if (!inst.operands[1].isreg)
7054 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
7055 return;
7056 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
7057 }
7058
7059 static void
7060 do_ldsttv4 (void)
7061 {
7062 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7063 reject [Rn,...]. */
7064 if (inst.operands[1].preind)
7065 {
7066 constraint (inst.reloc.exp.X_op != O_constant
7067 || inst.reloc.exp.X_add_number != 0,
7068 _("this instruction requires a post-indexed address"));
7069
7070 inst.operands[1].preind = 0;
7071 inst.operands[1].postind = 1;
7072 inst.operands[1].writeback = 1;
7073 }
7074 inst.instruction |= inst.operands[0].reg << 12;
7075 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7076 }
7077
7078 /* Co-processor register load/store.
7079 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7080 static void
7081 do_lstc (void)
7082 {
7083 inst.instruction |= inst.operands[0].reg << 8;
7084 inst.instruction |= inst.operands[1].reg << 12;
7085 encode_arm_cp_address (2, TRUE, TRUE, 0);
7086 }
7087
7088 static void
7089 do_mlas (void)
7090 {
7091 /* This restriction does not apply to mls (nor to mla in v6 or later). */
7092 if (inst.operands[0].reg == inst.operands[1].reg
7093 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
7094 && !(inst.instruction & 0x00400000))
7095 as_tsktsk (_("Rd and Rm should be different in mla"));
7096
7097 inst.instruction |= inst.operands[0].reg << 16;
7098 inst.instruction |= inst.operands[1].reg;
7099 inst.instruction |= inst.operands[2].reg << 8;
7100 inst.instruction |= inst.operands[3].reg << 12;
7101 }
7102
7103 static void
7104 do_mov (void)
7105 {
7106 inst.instruction |= inst.operands[0].reg << 12;
7107 encode_arm_shifter_operand (1);
7108 }
7109
7110 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7111 static void
7112 do_mov16 (void)
7113 {
7114 bfd_vma imm;
7115 bfd_boolean top;
7116
7117 top = (inst.instruction & 0x00400000) != 0;
7118 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7119 _(":lower16: not allowed this instruction"));
7120 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7121 _(":upper16: not allowed instruction"));
7122 inst.instruction |= inst.operands[0].reg << 12;
7123 if (inst.reloc.type == BFD_RELOC_UNUSED)
7124 {
7125 imm = inst.reloc.exp.X_add_number;
7126 /* The value is in two pieces: 0:11, 16:19. */
7127 inst.instruction |= (imm & 0x00000fff);
7128 inst.instruction |= (imm & 0x0000f000) << 4;
7129 }
7130 }
7131
7132 static void do_vfp_nsyn_opcode (const char *);
7133
7134 static int
7135 do_vfp_nsyn_mrs (void)
7136 {
7137 if (inst.operands[0].isvec)
7138 {
7139 if (inst.operands[1].reg != 1)
7140 first_error (_("operand 1 must be FPSCR"));
7141 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7142 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7143 do_vfp_nsyn_opcode ("fmstat");
7144 }
7145 else if (inst.operands[1].isvec)
7146 do_vfp_nsyn_opcode ("fmrx");
7147 else
7148 return FAIL;
7149
7150 return SUCCESS;
7151 }
7152
7153 static int
7154 do_vfp_nsyn_msr (void)
7155 {
7156 if (inst.operands[0].isvec)
7157 do_vfp_nsyn_opcode ("fmxr");
7158 else
7159 return FAIL;
7160
7161 return SUCCESS;
7162 }
7163
7164 static void
7165 do_mrs (void)
7166 {
7167 if (do_vfp_nsyn_mrs () == SUCCESS)
7168 return;
7169
7170 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7171 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7172 != (PSR_c|PSR_f),
7173 _("'CPSR' or 'SPSR' expected"));
7174 inst.instruction |= inst.operands[0].reg << 12;
7175 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7176 }
7177
7178 /* Two possible forms:
7179 "{C|S}PSR_<field>, Rm",
7180 "{C|S}PSR_f, #expression". */
7181
7182 static void
7183 do_msr (void)
7184 {
7185 if (do_vfp_nsyn_msr () == SUCCESS)
7186 return;
7187
7188 inst.instruction |= inst.operands[0].imm;
7189 if (inst.operands[1].isreg)
7190 inst.instruction |= inst.operands[1].reg;
7191 else
7192 {
7193 inst.instruction |= INST_IMMEDIATE;
7194 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7195 inst.reloc.pc_rel = 0;
7196 }
7197 }
7198
7199 static void
7200 do_mul (void)
7201 {
7202 if (!inst.operands[2].present)
7203 inst.operands[2].reg = inst.operands[0].reg;
7204 inst.instruction |= inst.operands[0].reg << 16;
7205 inst.instruction |= inst.operands[1].reg;
7206 inst.instruction |= inst.operands[2].reg << 8;
7207
7208 if (inst.operands[0].reg == inst.operands[1].reg
7209 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7210 as_tsktsk (_("Rd and Rm should be different in mul"));
7211 }
7212
7213 /* Long Multiply Parser
7214 UMULL RdLo, RdHi, Rm, Rs
7215 SMULL RdLo, RdHi, Rm, Rs
7216 UMLAL RdLo, RdHi, Rm, Rs
7217 SMLAL RdLo, RdHi, Rm, Rs. */
7218
7219 static void
7220 do_mull (void)
7221 {
7222 inst.instruction |= inst.operands[0].reg << 12;
7223 inst.instruction |= inst.operands[1].reg << 16;
7224 inst.instruction |= inst.operands[2].reg;
7225 inst.instruction |= inst.operands[3].reg << 8;
7226
7227 /* rdhi and rdlo must be different. */
7228 if (inst.operands[0].reg == inst.operands[1].reg)
7229 as_tsktsk (_("rdhi and rdlo must be different"));
7230
7231 /* rdhi, rdlo and rm must all be different before armv6. */
7232 if ((inst.operands[0].reg == inst.operands[2].reg
7233 || inst.operands[1].reg == inst.operands[2].reg)
7234 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7235 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7236 }
7237
7238 static void
7239 do_nop (void)
7240 {
7241 if (inst.operands[0].present)
7242 {
7243 /* Architectural NOP hints are CPSR sets with no bits selected. */
7244 inst.instruction &= 0xf0000000;
7245 inst.instruction |= 0x0320f000 + inst.operands[0].imm;
7246 }
7247 }
7248
7249 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7250 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7251 Condition defaults to COND_ALWAYS.
7252 Error if Rd, Rn or Rm are R15. */
7253
7254 static void
7255 do_pkhbt (void)
7256 {
7257 inst.instruction |= inst.operands[0].reg << 12;
7258 inst.instruction |= inst.operands[1].reg << 16;
7259 inst.instruction |= inst.operands[2].reg;
7260 if (inst.operands[3].present)
7261 encode_arm_shift (3);
7262 }
7263
7264 /* ARM V6 PKHTB (Argument Parse). */
7265
7266 static void
7267 do_pkhtb (void)
7268 {
7269 if (!inst.operands[3].present)
7270 {
7271 /* If the shift specifier is omitted, turn the instruction
7272 into pkhbt rd, rm, rn. */
7273 inst.instruction &= 0xfff00010;
7274 inst.instruction |= inst.operands[0].reg << 12;
7275 inst.instruction |= inst.operands[1].reg;
7276 inst.instruction |= inst.operands[2].reg << 16;
7277 }
7278 else
7279 {
7280 inst.instruction |= inst.operands[0].reg << 12;
7281 inst.instruction |= inst.operands[1].reg << 16;
7282 inst.instruction |= inst.operands[2].reg;
7283 encode_arm_shift (3);
7284 }
7285 }
7286
7287 /* ARMv5TE: Preload-Cache
7288
7289 PLD <addr_mode>
7290
7291 Syntactically, like LDR with B=1, W=0, L=1. */
7292
7293 static void
7294 do_pld (void)
7295 {
7296 constraint (!inst.operands[0].isreg,
7297 _("'[' expected after PLD mnemonic"));
7298 constraint (inst.operands[0].postind,
7299 _("post-indexed expression used in preload instruction"));
7300 constraint (inst.operands[0].writeback,
7301 _("writeback used in preload instruction"));
7302 constraint (!inst.operands[0].preind,
7303 _("unindexed addressing used in preload instruction"));
7304 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7305 }
7306
7307 /* ARMv7: PLI <addr_mode> */
7308 static void
7309 do_pli (void)
7310 {
7311 constraint (!inst.operands[0].isreg,
7312 _("'[' expected after PLI mnemonic"));
7313 constraint (inst.operands[0].postind,
7314 _("post-indexed expression used in preload instruction"));
7315 constraint (inst.operands[0].writeback,
7316 _("writeback used in preload instruction"));
7317 constraint (!inst.operands[0].preind,
7318 _("unindexed addressing used in preload instruction"));
7319 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7320 inst.instruction &= ~PRE_INDEX;
7321 }
7322
7323 static void
7324 do_push_pop (void)
7325 {
7326 inst.operands[1] = inst.operands[0];
7327 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7328 inst.operands[0].isreg = 1;
7329 inst.operands[0].writeback = 1;
7330 inst.operands[0].reg = REG_SP;
7331 do_ldmstm ();
7332 }
7333
7334 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7335 word at the specified address and the following word
7336 respectively.
7337 Unconditionally executed.
7338 Error if Rn is R15. */
7339
7340 static void
7341 do_rfe (void)
7342 {
7343 inst.instruction |= inst.operands[0].reg << 16;
7344 if (inst.operands[0].writeback)
7345 inst.instruction |= WRITE_BACK;
7346 }
7347
7348 /* ARM V6 ssat (argument parse). */
7349
7350 static void
7351 do_ssat (void)
7352 {
7353 inst.instruction |= inst.operands[0].reg << 12;
7354 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7355 inst.instruction |= inst.operands[2].reg;
7356
7357 if (inst.operands[3].present)
7358 encode_arm_shift (3);
7359 }
7360
7361 /* ARM V6 usat (argument parse). */
7362
7363 static void
7364 do_usat (void)
7365 {
7366 inst.instruction |= inst.operands[0].reg << 12;
7367 inst.instruction |= inst.operands[1].imm << 16;
7368 inst.instruction |= inst.operands[2].reg;
7369
7370 if (inst.operands[3].present)
7371 encode_arm_shift (3);
7372 }
7373
7374 /* ARM V6 ssat16 (argument parse). */
7375
7376 static void
7377 do_ssat16 (void)
7378 {
7379 inst.instruction |= inst.operands[0].reg << 12;
7380 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7381 inst.instruction |= inst.operands[2].reg;
7382 }
7383
7384 static void
7385 do_usat16 (void)
7386 {
7387 inst.instruction |= inst.operands[0].reg << 12;
7388 inst.instruction |= inst.operands[1].imm << 16;
7389 inst.instruction |= inst.operands[2].reg;
7390 }
7391
7392 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7393 preserving the other bits.
7394
7395 setend <endian_specifier>, where <endian_specifier> is either
7396 BE or LE. */
7397
7398 static void
7399 do_setend (void)
7400 {
7401 if (inst.operands[0].imm)
7402 inst.instruction |= 0x200;
7403 }
7404
7405 static void
7406 do_shift (void)
7407 {
7408 unsigned int Rm = (inst.operands[1].present
7409 ? inst.operands[1].reg
7410 : inst.operands[0].reg);
7411
7412 inst.instruction |= inst.operands[0].reg << 12;
7413 inst.instruction |= Rm;
7414 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
7415 {
7416 inst.instruction |= inst.operands[2].reg << 8;
7417 inst.instruction |= SHIFT_BY_REG;
7418 }
7419 else
7420 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7421 }
7422
7423 static void
7424 do_smc (void)
7425 {
7426 inst.reloc.type = BFD_RELOC_ARM_SMC;
7427 inst.reloc.pc_rel = 0;
7428 }
7429
7430 static void
7431 do_swi (void)
7432 {
7433 inst.reloc.type = BFD_RELOC_ARM_SWI;
7434 inst.reloc.pc_rel = 0;
7435 }
7436
7437 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7438 SMLAxy{cond} Rd,Rm,Rs,Rn
7439 SMLAWy{cond} Rd,Rm,Rs,Rn
7440 Error if any register is R15. */
7441
7442 static void
7443 do_smla (void)
7444 {
7445 inst.instruction |= inst.operands[0].reg << 16;
7446 inst.instruction |= inst.operands[1].reg;
7447 inst.instruction |= inst.operands[2].reg << 8;
7448 inst.instruction |= inst.operands[3].reg << 12;
7449 }
7450
7451 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7452 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7453 Error if any register is R15.
7454 Warning if Rdlo == Rdhi. */
7455
7456 static void
7457 do_smlal (void)
7458 {
7459 inst.instruction |= inst.operands[0].reg << 12;
7460 inst.instruction |= inst.operands[1].reg << 16;
7461 inst.instruction |= inst.operands[2].reg;
7462 inst.instruction |= inst.operands[3].reg << 8;
7463
7464 if (inst.operands[0].reg == inst.operands[1].reg)
7465 as_tsktsk (_("rdhi and rdlo must be different"));
7466 }
7467
7468 /* ARM V5E (El Segundo) signed-multiply (argument parse)
7469 SMULxy{cond} Rd,Rm,Rs
7470 Error if any register is R15. */
7471
7472 static void
7473 do_smul (void)
7474 {
7475 inst.instruction |= inst.operands[0].reg << 16;
7476 inst.instruction |= inst.operands[1].reg;
7477 inst.instruction |= inst.operands[2].reg << 8;
7478 }
7479
7480 /* ARM V6 srs (argument parse). The variable fields in the encoding are
7481 the same for both ARM and Thumb-2. */
7482
7483 static void
7484 do_srs (void)
7485 {
7486 int reg;
7487
7488 if (inst.operands[0].present)
7489 {
7490 reg = inst.operands[0].reg;
7491 constraint (reg != 13, _("SRS base register must be r13"));
7492 }
7493 else
7494 reg = 13;
7495
7496 inst.instruction |= reg << 16;
7497 inst.instruction |= inst.operands[1].imm;
7498 if (inst.operands[0].writeback || inst.operands[1].writeback)
7499 inst.instruction |= WRITE_BACK;
7500 }
7501
7502 /* ARM V6 strex (argument parse). */
7503
7504 static void
7505 do_strex (void)
7506 {
7507 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7508 || inst.operands[2].postind || inst.operands[2].writeback
7509 || inst.operands[2].immisreg || inst.operands[2].shifted
7510 || inst.operands[2].negative
7511 /* See comment in do_ldrex(). */
7512 || (inst.operands[2].reg == REG_PC),
7513 BAD_ADDR_MODE);
7514
7515 constraint (inst.operands[0].reg == inst.operands[1].reg
7516 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
7517
7518 constraint (inst.reloc.exp.X_op != O_constant
7519 || inst.reloc.exp.X_add_number != 0,
7520 _("offset must be zero in ARM encoding"));
7521
7522 inst.instruction |= inst.operands[0].reg << 12;
7523 inst.instruction |= inst.operands[1].reg;
7524 inst.instruction |= inst.operands[2].reg << 16;
7525 inst.reloc.type = BFD_RELOC_UNUSED;
7526 }
7527
7528 static void
7529 do_strexd (void)
7530 {
7531 constraint (inst.operands[1].reg % 2 != 0,
7532 _("even register required"));
7533 constraint (inst.operands[2].present
7534 && inst.operands[2].reg != inst.operands[1].reg + 1,
7535 _("can only store two consecutive registers"));
7536 /* If op 2 were present and equal to PC, this function wouldn't
7537 have been called in the first place. */
7538 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
7539
7540 constraint (inst.operands[0].reg == inst.operands[1].reg
7541 || inst.operands[0].reg == inst.operands[1].reg + 1
7542 || inst.operands[0].reg == inst.operands[3].reg,
7543 BAD_OVERLAP);
7544
7545 inst.instruction |= inst.operands[0].reg << 12;
7546 inst.instruction |= inst.operands[1].reg;
7547 inst.instruction |= inst.operands[3].reg << 16;
7548 }
7549
7550 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
7551 extends it to 32-bits, and adds the result to a value in another
7552 register. You can specify a rotation by 0, 8, 16, or 24 bits
7553 before extracting the 16-bit value.
7554 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
7555 Condition defaults to COND_ALWAYS.
7556 Error if any register uses R15. */
7557
7558 static void
7559 do_sxtah (void)
7560 {
7561 inst.instruction |= inst.operands[0].reg << 12;
7562 inst.instruction |= inst.operands[1].reg << 16;
7563 inst.instruction |= inst.operands[2].reg;
7564 inst.instruction |= inst.operands[3].imm << 10;
7565 }
7566
7567 /* ARM V6 SXTH.
7568
7569 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
7570 Condition defaults to COND_ALWAYS.
7571 Error if any register uses R15. */
7572
7573 static void
7574 do_sxth (void)
7575 {
7576 inst.instruction |= inst.operands[0].reg << 12;
7577 inst.instruction |= inst.operands[1].reg;
7578 inst.instruction |= inst.operands[2].imm << 10;
7579 }
7580 \f
7581 /* VFP instructions. In a logical order: SP variant first, monad
7582 before dyad, arithmetic then move then load/store. */
7583
7584 static void
7585 do_vfp_sp_monadic (void)
7586 {
7587 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7588 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
7589 }
7590
7591 static void
7592 do_vfp_sp_dyadic (void)
7593 {
7594 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7595 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7596 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
7597 }
7598
7599 static void
7600 do_vfp_sp_compare_z (void)
7601 {
7602 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7603 }
7604
7605 static void
7606 do_vfp_dp_sp_cvt (void)
7607 {
7608 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7609 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
7610 }
7611
7612 static void
7613 do_vfp_sp_dp_cvt (void)
7614 {
7615 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7616 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7617 }
7618
7619 static void
7620 do_vfp_reg_from_sp (void)
7621 {
7622 inst.instruction |= inst.operands[0].reg << 12;
7623 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7624 }
7625
7626 static void
7627 do_vfp_reg2_from_sp2 (void)
7628 {
7629 constraint (inst.operands[2].imm != 2,
7630 _("only two consecutive VFP SP registers allowed here"));
7631 inst.instruction |= inst.operands[0].reg << 12;
7632 inst.instruction |= inst.operands[1].reg << 16;
7633 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
7634 }
7635
7636 static void
7637 do_vfp_sp_from_reg (void)
7638 {
7639 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
7640 inst.instruction |= inst.operands[1].reg << 12;
7641 }
7642
7643 static void
7644 do_vfp_sp2_from_reg2 (void)
7645 {
7646 constraint (inst.operands[0].imm != 2,
7647 _("only two consecutive VFP SP registers allowed here"));
7648 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
7649 inst.instruction |= inst.operands[1].reg << 12;
7650 inst.instruction |= inst.operands[2].reg << 16;
7651 }
7652
7653 static void
7654 do_vfp_sp_ldst (void)
7655 {
7656 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7657 encode_arm_cp_address (1, FALSE, TRUE, 0);
7658 }
7659
7660 static void
7661 do_vfp_dp_ldst (void)
7662 {
7663 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7664 encode_arm_cp_address (1, FALSE, TRUE, 0);
7665 }
7666
7667
7668 static void
7669 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
7670 {
7671 if (inst.operands[0].writeback)
7672 inst.instruction |= WRITE_BACK;
7673 else
7674 constraint (ldstm_type != VFP_LDSTMIA,
7675 _("this addressing mode requires base-register writeback"));
7676 inst.instruction |= inst.operands[0].reg << 16;
7677 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
7678 inst.instruction |= inst.operands[1].imm;
7679 }
7680
7681 static void
7682 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
7683 {
7684 int count;
7685
7686 if (inst.operands[0].writeback)
7687 inst.instruction |= WRITE_BACK;
7688 else
7689 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
7690 _("this addressing mode requires base-register writeback"));
7691
7692 inst.instruction |= inst.operands[0].reg << 16;
7693 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7694
7695 count = inst.operands[1].imm << 1;
7696 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
7697 count += 1;
7698
7699 inst.instruction |= count;
7700 }
7701
7702 static void
7703 do_vfp_sp_ldstmia (void)
7704 {
7705 vfp_sp_ldstm (VFP_LDSTMIA);
7706 }
7707
7708 static void
7709 do_vfp_sp_ldstmdb (void)
7710 {
7711 vfp_sp_ldstm (VFP_LDSTMDB);
7712 }
7713
7714 static void
7715 do_vfp_dp_ldstmia (void)
7716 {
7717 vfp_dp_ldstm (VFP_LDSTMIA);
7718 }
7719
7720 static void
7721 do_vfp_dp_ldstmdb (void)
7722 {
7723 vfp_dp_ldstm (VFP_LDSTMDB);
7724 }
7725
7726 static void
7727 do_vfp_xp_ldstmia (void)
7728 {
7729 vfp_dp_ldstm (VFP_LDSTMIAX);
7730 }
7731
7732 static void
7733 do_vfp_xp_ldstmdb (void)
7734 {
7735 vfp_dp_ldstm (VFP_LDSTMDBX);
7736 }
7737
7738 static void
7739 do_vfp_dp_rd_rm (void)
7740 {
7741 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7742 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7743 }
7744
7745 static void
7746 do_vfp_dp_rn_rd (void)
7747 {
7748 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
7749 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7750 }
7751
7752 static void
7753 do_vfp_dp_rd_rn (void)
7754 {
7755 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7756 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7757 }
7758
7759 static void
7760 do_vfp_dp_rd_rn_rm (void)
7761 {
7762 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7763 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7764 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
7765 }
7766
7767 static void
7768 do_vfp_dp_rd (void)
7769 {
7770 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7771 }
7772
7773 static void
7774 do_vfp_dp_rm_rd_rn (void)
7775 {
7776 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
7777 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7778 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
7779 }
7780
7781 /* VFPv3 instructions. */
7782 static void
7783 do_vfp_sp_const (void)
7784 {
7785 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7786 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7787 inst.instruction |= (inst.operands[1].imm & 0x0f);
7788 }
7789
7790 static void
7791 do_vfp_dp_const (void)
7792 {
7793 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7794 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7795 inst.instruction |= (inst.operands[1].imm & 0x0f);
7796 }
7797
7798 static void
7799 vfp_conv (int srcsize)
7800 {
7801 unsigned immbits = srcsize - inst.operands[1].imm;
7802 inst.instruction |= (immbits & 1) << 5;
7803 inst.instruction |= (immbits >> 1);
7804 }
7805
7806 static void
7807 do_vfp_sp_conv_16 (void)
7808 {
7809 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7810 vfp_conv (16);
7811 }
7812
7813 static void
7814 do_vfp_dp_conv_16 (void)
7815 {
7816 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7817 vfp_conv (16);
7818 }
7819
7820 static void
7821 do_vfp_sp_conv_32 (void)
7822 {
7823 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7824 vfp_conv (32);
7825 }
7826
7827 static void
7828 do_vfp_dp_conv_32 (void)
7829 {
7830 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7831 vfp_conv (32);
7832 }
7833 \f
7834 /* FPA instructions. Also in a logical order. */
7835
7836 static void
7837 do_fpa_cmp (void)
7838 {
7839 inst.instruction |= inst.operands[0].reg << 16;
7840 inst.instruction |= inst.operands[1].reg;
7841 }
7842
7843 static void
7844 do_fpa_ldmstm (void)
7845 {
7846 inst.instruction |= inst.operands[0].reg << 12;
7847 switch (inst.operands[1].imm)
7848 {
7849 case 1: inst.instruction |= CP_T_X; break;
7850 case 2: inst.instruction |= CP_T_Y; break;
7851 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
7852 case 4: break;
7853 default: abort ();
7854 }
7855
7856 if (inst.instruction & (PRE_INDEX | INDEX_UP))
7857 {
7858 /* The instruction specified "ea" or "fd", so we can only accept
7859 [Rn]{!}. The instruction does not really support stacking or
7860 unstacking, so we have to emulate these by setting appropriate
7861 bits and offsets. */
7862 constraint (inst.reloc.exp.X_op != O_constant
7863 || inst.reloc.exp.X_add_number != 0,
7864 _("this instruction does not support indexing"));
7865
7866 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
7867 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
7868
7869 if (!(inst.instruction & INDEX_UP))
7870 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
7871
7872 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
7873 {
7874 inst.operands[2].preind = 0;
7875 inst.operands[2].postind = 1;
7876 }
7877 }
7878
7879 encode_arm_cp_address (2, TRUE, TRUE, 0);
7880 }
7881 \f
7882 /* iWMMXt instructions: strictly in alphabetical order. */
7883
7884 static void
7885 do_iwmmxt_tandorc (void)
7886 {
7887 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
7888 }
7889
7890 static void
7891 do_iwmmxt_textrc (void)
7892 {
7893 inst.instruction |= inst.operands[0].reg << 12;
7894 inst.instruction |= inst.operands[1].imm;
7895 }
7896
7897 static void
7898 do_iwmmxt_textrm (void)
7899 {
7900 inst.instruction |= inst.operands[0].reg << 12;
7901 inst.instruction |= inst.operands[1].reg << 16;
7902 inst.instruction |= inst.operands[2].imm;
7903 }
7904
7905 static void
7906 do_iwmmxt_tinsr (void)
7907 {
7908 inst.instruction |= inst.operands[0].reg << 16;
7909 inst.instruction |= inst.operands[1].reg << 12;
7910 inst.instruction |= inst.operands[2].imm;
7911 }
7912
7913 static void
7914 do_iwmmxt_tmia (void)
7915 {
7916 inst.instruction |= inst.operands[0].reg << 5;
7917 inst.instruction |= inst.operands[1].reg;
7918 inst.instruction |= inst.operands[2].reg << 12;
7919 }
7920
7921 static void
7922 do_iwmmxt_waligni (void)
7923 {
7924 inst.instruction |= inst.operands[0].reg << 12;
7925 inst.instruction |= inst.operands[1].reg << 16;
7926 inst.instruction |= inst.operands[2].reg;
7927 inst.instruction |= inst.operands[3].imm << 20;
7928 }
7929
7930 static void
7931 do_iwmmxt_wmerge (void)
7932 {
7933 inst.instruction |= inst.operands[0].reg << 12;
7934 inst.instruction |= inst.operands[1].reg << 16;
7935 inst.instruction |= inst.operands[2].reg;
7936 inst.instruction |= inst.operands[3].imm << 21;
7937 }
7938
7939 static void
7940 do_iwmmxt_wmov (void)
7941 {
7942 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
7943 inst.instruction |= inst.operands[0].reg << 12;
7944 inst.instruction |= inst.operands[1].reg << 16;
7945 inst.instruction |= inst.operands[1].reg;
7946 }
7947
7948 static void
7949 do_iwmmxt_wldstbh (void)
7950 {
7951 int reloc;
7952 inst.instruction |= inst.operands[0].reg << 12;
7953 if (thumb_mode)
7954 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
7955 else
7956 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
7957 encode_arm_cp_address (1, TRUE, FALSE, reloc);
7958 }
7959
7960 static void
7961 do_iwmmxt_wldstw (void)
7962 {
7963 /* RIWR_RIWC clears .isreg for a control register. */
7964 if (!inst.operands[0].isreg)
7965 {
7966 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7967 inst.instruction |= 0xf0000000;
7968 }
7969
7970 inst.instruction |= inst.operands[0].reg << 12;
7971 encode_arm_cp_address (1, TRUE, TRUE, 0);
7972 }
7973
7974 static void
7975 do_iwmmxt_wldstd (void)
7976 {
7977 inst.instruction |= inst.operands[0].reg << 12;
7978 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
7979 && inst.operands[1].immisreg)
7980 {
7981 inst.instruction &= ~0x1a000ff;
7982 inst.instruction |= (0xf << 28);
7983 if (inst.operands[1].preind)
7984 inst.instruction |= PRE_INDEX;
7985 if (!inst.operands[1].negative)
7986 inst.instruction |= INDEX_UP;
7987 if (inst.operands[1].writeback)
7988 inst.instruction |= WRITE_BACK;
7989 inst.instruction |= inst.operands[1].reg << 16;
7990 inst.instruction |= inst.reloc.exp.X_add_number << 4;
7991 inst.instruction |= inst.operands[1].imm;
7992 }
7993 else
7994 encode_arm_cp_address (1, TRUE, FALSE, 0);
7995 }
7996
7997 static void
7998 do_iwmmxt_wshufh (void)
7999 {
8000 inst.instruction |= inst.operands[0].reg << 12;
8001 inst.instruction |= inst.operands[1].reg << 16;
8002 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8003 inst.instruction |= (inst.operands[2].imm & 0x0f);
8004 }
8005
8006 static void
8007 do_iwmmxt_wzero (void)
8008 {
8009 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8010 inst.instruction |= inst.operands[0].reg;
8011 inst.instruction |= inst.operands[0].reg << 12;
8012 inst.instruction |= inst.operands[0].reg << 16;
8013 }
8014
8015 static void
8016 do_iwmmxt_wrwrwr_or_imm5 (void)
8017 {
8018 if (inst.operands[2].isreg)
8019 do_rd_rn_rm ();
8020 else {
8021 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8022 _("immediate operand requires iWMMXt2"));
8023 do_rd_rn ();
8024 if (inst.operands[2].imm == 0)
8025 {
8026 switch ((inst.instruction >> 20) & 0xf)
8027 {
8028 case 4:
8029 case 5:
8030 case 6:
8031 case 7:
8032 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8033 inst.operands[2].imm = 16;
8034 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8035 break;
8036 case 8:
8037 case 9:
8038 case 10:
8039 case 11:
8040 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8041 inst.operands[2].imm = 32;
8042 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8043 break;
8044 case 12:
8045 case 13:
8046 case 14:
8047 case 15:
8048 {
8049 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8050 unsigned long wrn;
8051 wrn = (inst.instruction >> 16) & 0xf;
8052 inst.instruction &= 0xff0fff0f;
8053 inst.instruction |= wrn;
8054 /* Bail out here; the instruction is now assembled. */
8055 return;
8056 }
8057 }
8058 }
8059 /* Map 32 -> 0, etc. */
8060 inst.operands[2].imm &= 0x1f;
8061 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8062 }
8063 }
8064 \f
8065 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8066 operations first, then control, shift, and load/store. */
8067
8068 /* Insns like "foo X,Y,Z". */
8069
8070 static void
8071 do_mav_triple (void)
8072 {
8073 inst.instruction |= inst.operands[0].reg << 16;
8074 inst.instruction |= inst.operands[1].reg;
8075 inst.instruction |= inst.operands[2].reg << 12;
8076 }
8077
8078 /* Insns like "foo W,X,Y,Z".
8079 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
8080
8081 static void
8082 do_mav_quad (void)
8083 {
8084 inst.instruction |= inst.operands[0].reg << 5;
8085 inst.instruction |= inst.operands[1].reg << 12;
8086 inst.instruction |= inst.operands[2].reg << 16;
8087 inst.instruction |= inst.operands[3].reg;
8088 }
8089
8090 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8091 static void
8092 do_mav_dspsc (void)
8093 {
8094 inst.instruction |= inst.operands[1].reg << 12;
8095 }
8096
8097 /* Maverick shift immediate instructions.
8098 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8099 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
8100
8101 static void
8102 do_mav_shift (void)
8103 {
8104 int imm = inst.operands[2].imm;
8105
8106 inst.instruction |= inst.operands[0].reg << 12;
8107 inst.instruction |= inst.operands[1].reg << 16;
8108
8109 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8110 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8111 Bit 4 should be 0. */
8112 imm = (imm & 0xf) | ((imm & 0x70) << 1);
8113
8114 inst.instruction |= imm;
8115 }
8116 \f
8117 /* XScale instructions. Also sorted arithmetic before move. */
8118
8119 /* Xscale multiply-accumulate (argument parse)
8120 MIAcc acc0,Rm,Rs
8121 MIAPHcc acc0,Rm,Rs
8122 MIAxycc acc0,Rm,Rs. */
8123
8124 static void
8125 do_xsc_mia (void)
8126 {
8127 inst.instruction |= inst.operands[1].reg;
8128 inst.instruction |= inst.operands[2].reg << 12;
8129 }
8130
8131 /* Xscale move-accumulator-register (argument parse)
8132
8133 MARcc acc0,RdLo,RdHi. */
8134
8135 static void
8136 do_xsc_mar (void)
8137 {
8138 inst.instruction |= inst.operands[1].reg << 12;
8139 inst.instruction |= inst.operands[2].reg << 16;
8140 }
8141
8142 /* Xscale move-register-accumulator (argument parse)
8143
8144 MRAcc RdLo,RdHi,acc0. */
8145
8146 static void
8147 do_xsc_mra (void)
8148 {
8149 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8150 inst.instruction |= inst.operands[0].reg << 12;
8151 inst.instruction |= inst.operands[1].reg << 16;
8152 }
8153 \f
8154 /* Encoding functions relevant only to Thumb. */
8155
8156 /* inst.operands[i] is a shifted-register operand; encode
8157 it into inst.instruction in the format used by Thumb32. */
8158
8159 static void
8160 encode_thumb32_shifted_operand (int i)
8161 {
8162 unsigned int value = inst.reloc.exp.X_add_number;
8163 unsigned int shift = inst.operands[i].shift_kind;
8164
8165 constraint (inst.operands[i].immisreg,
8166 _("shift by register not allowed in thumb mode"));
8167 inst.instruction |= inst.operands[i].reg;
8168 if (shift == SHIFT_RRX)
8169 inst.instruction |= SHIFT_ROR << 4;
8170 else
8171 {
8172 constraint (inst.reloc.exp.X_op != O_constant,
8173 _("expression too complex"));
8174
8175 constraint (value > 32
8176 || (value == 32 && (shift == SHIFT_LSL
8177 || shift == SHIFT_ROR)),
8178 _("shift expression is too large"));
8179
8180 if (value == 0)
8181 shift = SHIFT_LSL;
8182 else if (value == 32)
8183 value = 0;
8184
8185 inst.instruction |= shift << 4;
8186 inst.instruction |= (value & 0x1c) << 10;
8187 inst.instruction |= (value & 0x03) << 6;
8188 }
8189 }
8190
8191
8192 /* inst.operands[i] was set up by parse_address. Encode it into a
8193 Thumb32 format load or store instruction. Reject forms that cannot
8194 be used with such instructions. If is_t is true, reject forms that
8195 cannot be used with a T instruction; if is_d is true, reject forms
8196 that cannot be used with a D instruction. */
8197
8198 static void
8199 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8200 {
8201 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8202
8203 constraint (!inst.operands[i].isreg,
8204 _("Instruction does not support =N addresses"));
8205
8206 inst.instruction |= inst.operands[i].reg << 16;
8207 if (inst.operands[i].immisreg)
8208 {
8209 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
8210 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8211 constraint (inst.operands[i].negative,
8212 _("Thumb does not support negative register indexing"));
8213 constraint (inst.operands[i].postind,
8214 _("Thumb does not support register post-indexing"));
8215 constraint (inst.operands[i].writeback,
8216 _("Thumb does not support register indexing with writeback"));
8217 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8218 _("Thumb supports only LSL in shifted register indexing"));
8219
8220 inst.instruction |= inst.operands[i].imm;
8221 if (inst.operands[i].shifted)
8222 {
8223 constraint (inst.reloc.exp.X_op != O_constant,
8224 _("expression too complex"));
8225 constraint (inst.reloc.exp.X_add_number < 0
8226 || inst.reloc.exp.X_add_number > 3,
8227 _("shift out of range"));
8228 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8229 }
8230 inst.reloc.type = BFD_RELOC_UNUSED;
8231 }
8232 else if (inst.operands[i].preind)
8233 {
8234 constraint (is_pc && inst.operands[i].writeback,
8235 _("cannot use writeback with PC-relative addressing"));
8236 constraint (is_t && inst.operands[i].writeback,
8237 _("cannot use writeback with this instruction"));
8238
8239 if (is_d)
8240 {
8241 inst.instruction |= 0x01000000;
8242 if (inst.operands[i].writeback)
8243 inst.instruction |= 0x00200000;
8244 }
8245 else
8246 {
8247 inst.instruction |= 0x00000c00;
8248 if (inst.operands[i].writeback)
8249 inst.instruction |= 0x00000100;
8250 }
8251 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8252 }
8253 else if (inst.operands[i].postind)
8254 {
8255 assert (inst.operands[i].writeback);
8256 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8257 constraint (is_t, _("cannot use post-indexing with this instruction"));
8258
8259 if (is_d)
8260 inst.instruction |= 0x00200000;
8261 else
8262 inst.instruction |= 0x00000900;
8263 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8264 }
8265 else /* unindexed - only for coprocessor */
8266 inst.error = _("instruction does not accept unindexed addressing");
8267 }
8268
8269 /* Table of Thumb instructions which exist in both 16- and 32-bit
8270 encodings (the latter only in post-V6T2 cores). The index is the
8271 value used in the insns table below. When there is more than one
8272 possible 16-bit encoding for the instruction, this table always
8273 holds variant (1).
8274 Also contains several pseudo-instructions used during relaxation. */
8275 #define T16_32_TAB \
8276 X(adc, 4140, eb400000), \
8277 X(adcs, 4140, eb500000), \
8278 X(add, 1c00, eb000000), \
8279 X(adds, 1c00, eb100000), \
8280 X(addi, 0000, f1000000), \
8281 X(addis, 0000, f1100000), \
8282 X(add_pc,000f, f20f0000), \
8283 X(add_sp,000d, f10d0000), \
8284 X(adr, 000f, f20f0000), \
8285 X(and, 4000, ea000000), \
8286 X(ands, 4000, ea100000), \
8287 X(asr, 1000, fa40f000), \
8288 X(asrs, 1000, fa50f000), \
8289 X(b, e000, f000b000), \
8290 X(bcond, d000, f0008000), \
8291 X(bic, 4380, ea200000), \
8292 X(bics, 4380, ea300000), \
8293 X(cmn, 42c0, eb100f00), \
8294 X(cmp, 2800, ebb00f00), \
8295 X(cpsie, b660, f3af8400), \
8296 X(cpsid, b670, f3af8600), \
8297 X(cpy, 4600, ea4f0000), \
8298 X(dec_sp,80dd, f1ad0d00), \
8299 X(eor, 4040, ea800000), \
8300 X(eors, 4040, ea900000), \
8301 X(inc_sp,00dd, f10d0d00), \
8302 X(ldmia, c800, e8900000), \
8303 X(ldr, 6800, f8500000), \
8304 X(ldrb, 7800, f8100000), \
8305 X(ldrh, 8800, f8300000), \
8306 X(ldrsb, 5600, f9100000), \
8307 X(ldrsh, 5e00, f9300000), \
8308 X(ldr_pc,4800, f85f0000), \
8309 X(ldr_pc2,4800, f85f0000), \
8310 X(ldr_sp,9800, f85d0000), \
8311 X(lsl, 0000, fa00f000), \
8312 X(lsls, 0000, fa10f000), \
8313 X(lsr, 0800, fa20f000), \
8314 X(lsrs, 0800, fa30f000), \
8315 X(mov, 2000, ea4f0000), \
8316 X(movs, 2000, ea5f0000), \
8317 X(mul, 4340, fb00f000), \
8318 X(muls, 4340, ffffffff), /* no 32b muls */ \
8319 X(mvn, 43c0, ea6f0000), \
8320 X(mvns, 43c0, ea7f0000), \
8321 X(neg, 4240, f1c00000), /* rsb #0 */ \
8322 X(negs, 4240, f1d00000), /* rsbs #0 */ \
8323 X(orr, 4300, ea400000), \
8324 X(orrs, 4300, ea500000), \
8325 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8326 X(push, b400, e92d0000), /* stmdb sp!,... */ \
8327 X(rev, ba00, fa90f080), \
8328 X(rev16, ba40, fa90f090), \
8329 X(revsh, bac0, fa90f0b0), \
8330 X(ror, 41c0, fa60f000), \
8331 X(rors, 41c0, fa70f000), \
8332 X(sbc, 4180, eb600000), \
8333 X(sbcs, 4180, eb700000), \
8334 X(stmia, c000, e8800000), \
8335 X(str, 6000, f8400000), \
8336 X(strb, 7000, f8000000), \
8337 X(strh, 8000, f8200000), \
8338 X(str_sp,9000, f84d0000), \
8339 X(sub, 1e00, eba00000), \
8340 X(subs, 1e00, ebb00000), \
8341 X(subi, 8000, f1a00000), \
8342 X(subis, 8000, f1b00000), \
8343 X(sxtb, b240, fa4ff080), \
8344 X(sxth, b200, fa0ff080), \
8345 X(tst, 4200, ea100f00), \
8346 X(uxtb, b2c0, fa5ff080), \
8347 X(uxth, b280, fa1ff080), \
8348 X(nop, bf00, f3af8000), \
8349 X(yield, bf10, f3af8001), \
8350 X(wfe, bf20, f3af8002), \
8351 X(wfi, bf30, f3af8003), \
8352 X(sev, bf40, f3af9004), /* typo, 8004? */
8353
8354 /* To catch errors in encoding functions, the codes are all offset by
8355 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8356 as 16-bit instructions. */
8357 #define X(a,b,c) T_MNEM_##a
8358 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8359 #undef X
8360
8361 #define X(a,b,c) 0x##b
8362 static const unsigned short thumb_op16[] = { T16_32_TAB };
8363 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8364 #undef X
8365
8366 #define X(a,b,c) 0x##c
8367 static const unsigned int thumb_op32[] = { T16_32_TAB };
8368 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8369 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
8370 #undef X
8371 #undef T16_32_TAB
8372
8373 /* Thumb instruction encoders, in alphabetical order. */
8374
8375 /* ADDW or SUBW. */
8376 static void
8377 do_t_add_sub_w (void)
8378 {
8379 int Rd, Rn;
8380
8381 Rd = inst.operands[0].reg;
8382 Rn = inst.operands[1].reg;
8383
8384 constraint (Rd == 15, _("PC not allowed as destination"));
8385 inst.instruction |= (Rn << 16) | (Rd << 8);
8386 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8387 }
8388
8389 /* Parse an add or subtract instruction. We get here with inst.instruction
8390 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8391
8392 static void
8393 do_t_add_sub (void)
8394 {
8395 int Rd, Rs, Rn;
8396
8397 Rd = inst.operands[0].reg;
8398 Rs = (inst.operands[1].present
8399 ? inst.operands[1].reg /* Rd, Rs, foo */
8400 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8401
8402 if (unified_syntax)
8403 {
8404 bfd_boolean flags;
8405 bfd_boolean narrow;
8406 int opcode;
8407
8408 flags = (inst.instruction == T_MNEM_adds
8409 || inst.instruction == T_MNEM_subs);
8410 if (flags)
8411 narrow = (current_it_mask == 0);
8412 else
8413 narrow = (current_it_mask != 0);
8414 if (!inst.operands[2].isreg)
8415 {
8416 int add;
8417
8418 add = (inst.instruction == T_MNEM_add
8419 || inst.instruction == T_MNEM_adds);
8420 opcode = 0;
8421 if (inst.size_req != 4)
8422 {
8423 /* Attempt to use a narrow opcode, with relaxation if
8424 appropriate. */
8425 if (Rd == REG_SP && Rs == REG_SP && !flags)
8426 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8427 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8428 opcode = T_MNEM_add_sp;
8429 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8430 opcode = T_MNEM_add_pc;
8431 else if (Rd <= 7 && Rs <= 7 && narrow)
8432 {
8433 if (flags)
8434 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8435 else
8436 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8437 }
8438 if (opcode)
8439 {
8440 inst.instruction = THUMB_OP16(opcode);
8441 inst.instruction |= (Rd << 4) | Rs;
8442 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8443 if (inst.size_req != 2)
8444 inst.relax = opcode;
8445 }
8446 else
8447 constraint (inst.size_req == 2, BAD_HIREG);
8448 }
8449 if (inst.size_req == 4
8450 || (inst.size_req != 2 && !opcode))
8451 {
8452 if (Rd == REG_PC)
8453 {
8454 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
8455 _("only SUBS PC, LR, #const allowed"));
8456 constraint (inst.reloc.exp.X_op != O_constant,
8457 _("expression too complex"));
8458 constraint (inst.reloc.exp.X_add_number < 0
8459 || inst.reloc.exp.X_add_number > 0xff,
8460 _("immediate value out of range"));
8461 inst.instruction = T2_SUBS_PC_LR
8462 | inst.reloc.exp.X_add_number;
8463 inst.reloc.type = BFD_RELOC_UNUSED;
8464 return;
8465 }
8466 else if (Rs == REG_PC)
8467 {
8468 /* Always use addw/subw. */
8469 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8470 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8471 }
8472 else
8473 {
8474 inst.instruction = THUMB_OP32 (inst.instruction);
8475 inst.instruction = (inst.instruction & 0xe1ffffff)
8476 | 0x10000000;
8477 if (flags)
8478 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8479 else
8480 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
8481 }
8482 inst.instruction |= Rd << 8;
8483 inst.instruction |= Rs << 16;
8484 }
8485 }
8486 else
8487 {
8488 Rn = inst.operands[2].reg;
8489 /* See if we can do this with a 16-bit instruction. */
8490 if (!inst.operands[2].shifted && inst.size_req != 4)
8491 {
8492 if (Rd > 7 || Rs > 7 || Rn > 7)
8493 narrow = FALSE;
8494
8495 if (narrow)
8496 {
8497 inst.instruction = ((inst.instruction == T_MNEM_adds
8498 || inst.instruction == T_MNEM_add)
8499 ? T_OPCODE_ADD_R3
8500 : T_OPCODE_SUB_R3);
8501 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8502 return;
8503 }
8504
8505 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
8506 {
8507 /* Thumb-1 cores (except v6-M) require at least one high
8508 register in a narrow non flag setting add. */
8509 if (Rd > 7 || Rn > 7
8510 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
8511 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
8512 {
8513 if (Rd == Rn)
8514 {
8515 Rn = Rs;
8516 Rs = Rd;
8517 }
8518 inst.instruction = T_OPCODE_ADD_HI;
8519 inst.instruction |= (Rd & 8) << 4;
8520 inst.instruction |= (Rd & 7);
8521 inst.instruction |= Rn << 3;
8522 return;
8523 }
8524 }
8525 }
8526 /* If we get here, it can't be done in 16 bits. */
8527 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
8528 _("shift must be constant"));
8529 inst.instruction = THUMB_OP32 (inst.instruction);
8530 inst.instruction |= Rd << 8;
8531 inst.instruction |= Rs << 16;
8532 encode_thumb32_shifted_operand (2);
8533 }
8534 }
8535 else
8536 {
8537 constraint (inst.instruction == T_MNEM_adds
8538 || inst.instruction == T_MNEM_subs,
8539 BAD_THUMB32);
8540
8541 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
8542 {
8543 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
8544 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
8545 BAD_HIREG);
8546
8547 inst.instruction = (inst.instruction == T_MNEM_add
8548 ? 0x0000 : 0x8000);
8549 inst.instruction |= (Rd << 4) | Rs;
8550 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8551 return;
8552 }
8553
8554 Rn = inst.operands[2].reg;
8555 constraint (inst.operands[2].shifted, _("unshifted register required"));
8556
8557 /* We now have Rd, Rs, and Rn set to registers. */
8558 if (Rd > 7 || Rs > 7 || Rn > 7)
8559 {
8560 /* Can't do this for SUB. */
8561 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
8562 inst.instruction = T_OPCODE_ADD_HI;
8563 inst.instruction |= (Rd & 8) << 4;
8564 inst.instruction |= (Rd & 7);
8565 if (Rs == Rd)
8566 inst.instruction |= Rn << 3;
8567 else if (Rn == Rd)
8568 inst.instruction |= Rs << 3;
8569 else
8570 constraint (1, _("dest must overlap one source register"));
8571 }
8572 else
8573 {
8574 inst.instruction = (inst.instruction == T_MNEM_add
8575 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
8576 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8577 }
8578 }
8579 }
8580
8581 static void
8582 do_t_adr (void)
8583 {
8584 if (unified_syntax && inst.size_req == 0 && inst.operands[0].reg <= 7)
8585 {
8586 /* Defer to section relaxation. */
8587 inst.relax = inst.instruction;
8588 inst.instruction = THUMB_OP16 (inst.instruction);
8589 inst.instruction |= inst.operands[0].reg << 4;
8590 }
8591 else if (unified_syntax && inst.size_req != 2)
8592 {
8593 /* Generate a 32-bit opcode. */
8594 inst.instruction = THUMB_OP32 (inst.instruction);
8595 inst.instruction |= inst.operands[0].reg << 8;
8596 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
8597 inst.reloc.pc_rel = 1;
8598 }
8599 else
8600 {
8601 /* Generate a 16-bit opcode. */
8602 inst.instruction = THUMB_OP16 (inst.instruction);
8603 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8604 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
8605 inst.reloc.pc_rel = 1;
8606
8607 inst.instruction |= inst.operands[0].reg << 4;
8608 }
8609 }
8610
8611 /* Arithmetic instructions for which there is just one 16-bit
8612 instruction encoding, and it allows only two low registers.
8613 For maximal compatibility with ARM syntax, we allow three register
8614 operands even when Thumb-32 instructions are not available, as long
8615 as the first two are identical. For instance, both "sbc r0,r1" and
8616 "sbc r0,r0,r1" are allowed. */
8617 static void
8618 do_t_arit3 (void)
8619 {
8620 int Rd, Rs, Rn;
8621
8622 Rd = inst.operands[0].reg;
8623 Rs = (inst.operands[1].present
8624 ? inst.operands[1].reg /* Rd, Rs, foo */
8625 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8626 Rn = inst.operands[2].reg;
8627
8628 if (unified_syntax)
8629 {
8630 if (!inst.operands[2].isreg)
8631 {
8632 /* For an immediate, we always generate a 32-bit opcode;
8633 section relaxation will shrink it later if possible. */
8634 inst.instruction = THUMB_OP32 (inst.instruction);
8635 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8636 inst.instruction |= Rd << 8;
8637 inst.instruction |= Rs << 16;
8638 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8639 }
8640 else
8641 {
8642 bfd_boolean narrow;
8643
8644 /* See if we can do this with a 16-bit instruction. */
8645 if (THUMB_SETS_FLAGS (inst.instruction))
8646 narrow = current_it_mask == 0;
8647 else
8648 narrow = current_it_mask != 0;
8649
8650 if (Rd > 7 || Rn > 7 || Rs > 7)
8651 narrow = FALSE;
8652 if (inst.operands[2].shifted)
8653 narrow = FALSE;
8654 if (inst.size_req == 4)
8655 narrow = FALSE;
8656
8657 if (narrow
8658 && Rd == Rs)
8659 {
8660 inst.instruction = THUMB_OP16 (inst.instruction);
8661 inst.instruction |= Rd;
8662 inst.instruction |= Rn << 3;
8663 return;
8664 }
8665
8666 /* If we get here, it can't be done in 16 bits. */
8667 constraint (inst.operands[2].shifted
8668 && inst.operands[2].immisreg,
8669 _("shift must be constant"));
8670 inst.instruction = THUMB_OP32 (inst.instruction);
8671 inst.instruction |= Rd << 8;
8672 inst.instruction |= Rs << 16;
8673 encode_thumb32_shifted_operand (2);
8674 }
8675 }
8676 else
8677 {
8678 /* On its face this is a lie - the instruction does set the
8679 flags. However, the only supported mnemonic in this mode
8680 says it doesn't. */
8681 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
8682
8683 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8684 _("unshifted register required"));
8685 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8686 constraint (Rd != Rs,
8687 _("dest and source1 must be the same register"));
8688
8689 inst.instruction = THUMB_OP16 (inst.instruction);
8690 inst.instruction |= Rd;
8691 inst.instruction |= Rn << 3;
8692 }
8693 }
8694
8695 /* Similarly, but for instructions where the arithmetic operation is
8696 commutative, so we can allow either of them to be different from
8697 the destination operand in a 16-bit instruction. For instance, all
8698 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
8699 accepted. */
8700 static void
8701 do_t_arit3c (void)
8702 {
8703 int Rd, Rs, Rn;
8704
8705 Rd = inst.operands[0].reg;
8706 Rs = (inst.operands[1].present
8707 ? inst.operands[1].reg /* Rd, Rs, foo */
8708 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8709 Rn = inst.operands[2].reg;
8710
8711 if (unified_syntax)
8712 {
8713 if (!inst.operands[2].isreg)
8714 {
8715 /* For an immediate, we always generate a 32-bit opcode;
8716 section relaxation will shrink it later if possible. */
8717 inst.instruction = THUMB_OP32 (inst.instruction);
8718 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8719 inst.instruction |= Rd << 8;
8720 inst.instruction |= Rs << 16;
8721 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8722 }
8723 else
8724 {
8725 bfd_boolean narrow;
8726
8727 /* See if we can do this with a 16-bit instruction. */
8728 if (THUMB_SETS_FLAGS (inst.instruction))
8729 narrow = current_it_mask == 0;
8730 else
8731 narrow = current_it_mask != 0;
8732
8733 if (Rd > 7 || Rn > 7 || Rs > 7)
8734 narrow = FALSE;
8735 if (inst.operands[2].shifted)
8736 narrow = FALSE;
8737 if (inst.size_req == 4)
8738 narrow = FALSE;
8739
8740 if (narrow)
8741 {
8742 if (Rd == Rs)
8743 {
8744 inst.instruction = THUMB_OP16 (inst.instruction);
8745 inst.instruction |= Rd;
8746 inst.instruction |= Rn << 3;
8747 return;
8748 }
8749 if (Rd == Rn)
8750 {
8751 inst.instruction = THUMB_OP16 (inst.instruction);
8752 inst.instruction |= Rd;
8753 inst.instruction |= Rs << 3;
8754 return;
8755 }
8756 }
8757
8758 /* If we get here, it can't be done in 16 bits. */
8759 constraint (inst.operands[2].shifted
8760 && inst.operands[2].immisreg,
8761 _("shift must be constant"));
8762 inst.instruction = THUMB_OP32 (inst.instruction);
8763 inst.instruction |= Rd << 8;
8764 inst.instruction |= Rs << 16;
8765 encode_thumb32_shifted_operand (2);
8766 }
8767 }
8768 else
8769 {
8770 /* On its face this is a lie - the instruction does set the
8771 flags. However, the only supported mnemonic in this mode
8772 says it doesn't. */
8773 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
8774
8775 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8776 _("unshifted register required"));
8777 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8778
8779 inst.instruction = THUMB_OP16 (inst.instruction);
8780 inst.instruction |= Rd;
8781
8782 if (Rd == Rs)
8783 inst.instruction |= Rn << 3;
8784 else if (Rd == Rn)
8785 inst.instruction |= Rs << 3;
8786 else
8787 constraint (1, _("dest must overlap one source register"));
8788 }
8789 }
8790
8791 static void
8792 do_t_barrier (void)
8793 {
8794 if (inst.operands[0].present)
8795 {
8796 constraint ((inst.instruction & 0xf0) != 0x40
8797 && inst.operands[0].imm != 0xf,
8798 _("bad barrier type"));
8799 inst.instruction |= inst.operands[0].imm;
8800 }
8801 else
8802 inst.instruction |= 0xf;
8803 }
8804
8805 static void
8806 do_t_bfc (void)
8807 {
8808 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8809 constraint (msb > 32, _("bit-field extends past end of register"));
8810 /* The instruction encoding stores the LSB and MSB,
8811 not the LSB and width. */
8812 inst.instruction |= inst.operands[0].reg << 8;
8813 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
8814 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
8815 inst.instruction |= msb - 1;
8816 }
8817
8818 static void
8819 do_t_bfi (void)
8820 {
8821 unsigned int msb;
8822
8823 /* #0 in second position is alternative syntax for bfc, which is
8824 the same instruction but with REG_PC in the Rm field. */
8825 if (!inst.operands[1].isreg)
8826 inst.operands[1].reg = REG_PC;
8827
8828 msb = inst.operands[2].imm + inst.operands[3].imm;
8829 constraint (msb > 32, _("bit-field extends past end of register"));
8830 /* The instruction encoding stores the LSB and MSB,
8831 not the LSB and width. */
8832 inst.instruction |= inst.operands[0].reg << 8;
8833 inst.instruction |= inst.operands[1].reg << 16;
8834 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8835 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8836 inst.instruction |= msb - 1;
8837 }
8838
8839 static void
8840 do_t_bfx (void)
8841 {
8842 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8843 _("bit-field extends past end of register"));
8844 inst.instruction |= inst.operands[0].reg << 8;
8845 inst.instruction |= inst.operands[1].reg << 16;
8846 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8847 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8848 inst.instruction |= inst.operands[3].imm - 1;
8849 }
8850
8851 /* ARM V5 Thumb BLX (argument parse)
8852 BLX <target_addr> which is BLX(1)
8853 BLX <Rm> which is BLX(2)
8854 Unfortunately, there are two different opcodes for this mnemonic.
8855 So, the insns[].value is not used, and the code here zaps values
8856 into inst.instruction.
8857
8858 ??? How to take advantage of the additional two bits of displacement
8859 available in Thumb32 mode? Need new relocation? */
8860
8861 static void
8862 do_t_blx (void)
8863 {
8864 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8865 if (inst.operands[0].isreg)
8866 /* We have a register, so this is BLX(2). */
8867 inst.instruction |= inst.operands[0].reg << 3;
8868 else
8869 {
8870 /* No register. This must be BLX(1). */
8871 inst.instruction = 0xf000e800;
8872 #ifdef OBJ_ELF
8873 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8874 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
8875 else
8876 #endif
8877 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
8878 inst.reloc.pc_rel = 1;
8879 }
8880 }
8881
8882 static void
8883 do_t_branch (void)
8884 {
8885 int opcode;
8886 int cond;
8887
8888 if (current_it_mask)
8889 {
8890 /* Conditional branches inside IT blocks are encoded as unconditional
8891 branches. */
8892 cond = COND_ALWAYS;
8893 /* A branch must be the last instruction in an IT block. */
8894 constraint (current_it_mask != 0x10, BAD_BRANCH);
8895 }
8896 else
8897 cond = inst.cond;
8898
8899 if (cond != COND_ALWAYS)
8900 opcode = T_MNEM_bcond;
8901 else
8902 opcode = inst.instruction;
8903
8904 if (unified_syntax && inst.size_req == 4)
8905 {
8906 inst.instruction = THUMB_OP32(opcode);
8907 if (cond == COND_ALWAYS)
8908 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
8909 else
8910 {
8911 assert (cond != 0xF);
8912 inst.instruction |= cond << 22;
8913 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
8914 }
8915 }
8916 else
8917 {
8918 inst.instruction = THUMB_OP16(opcode);
8919 if (cond == COND_ALWAYS)
8920 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
8921 else
8922 {
8923 inst.instruction |= cond << 8;
8924 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
8925 }
8926 /* Allow section relaxation. */
8927 if (unified_syntax && inst.size_req != 2)
8928 inst.relax = opcode;
8929 }
8930
8931 inst.reloc.pc_rel = 1;
8932 }
8933
8934 static void
8935 do_t_bkpt (void)
8936 {
8937 constraint (inst.cond != COND_ALWAYS,
8938 _("instruction is always unconditional"));
8939 if (inst.operands[0].present)
8940 {
8941 constraint (inst.operands[0].imm > 255,
8942 _("immediate value out of range"));
8943 inst.instruction |= inst.operands[0].imm;
8944 }
8945 }
8946
8947 static void
8948 do_t_branch23 (void)
8949 {
8950 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8951 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
8952 inst.reloc.pc_rel = 1;
8953
8954 /* If the destination of the branch is a defined symbol which does not have
8955 the THUMB_FUNC attribute, then we must be calling a function which has
8956 the (interfacearm) attribute. We look for the Thumb entry point to that
8957 function and change the branch to refer to that function instead. */
8958 if ( inst.reloc.exp.X_op == O_symbol
8959 && inst.reloc.exp.X_add_symbol != NULL
8960 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8961 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8962 inst.reloc.exp.X_add_symbol =
8963 find_real_start (inst.reloc.exp.X_add_symbol);
8964 }
8965
8966 static void
8967 do_t_bx (void)
8968 {
8969 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8970 inst.instruction |= inst.operands[0].reg << 3;
8971 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
8972 should cause the alignment to be checked once it is known. This is
8973 because BX PC only works if the instruction is word aligned. */
8974 }
8975
8976 static void
8977 do_t_bxj (void)
8978 {
8979 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8980 if (inst.operands[0].reg == REG_PC)
8981 as_tsktsk (_("use of r15 in bxj is not really useful"));
8982
8983 inst.instruction |= inst.operands[0].reg << 16;
8984 }
8985
8986 static void
8987 do_t_clz (void)
8988 {
8989 inst.instruction |= inst.operands[0].reg << 8;
8990 inst.instruction |= inst.operands[1].reg << 16;
8991 inst.instruction |= inst.operands[1].reg;
8992 }
8993
8994 static void
8995 do_t_cps (void)
8996 {
8997 constraint (current_it_mask, BAD_NOT_IT);
8998 inst.instruction |= inst.operands[0].imm;
8999 }
9000
9001 static void
9002 do_t_cpsi (void)
9003 {
9004 constraint (current_it_mask, BAD_NOT_IT);
9005 if (unified_syntax
9006 && (inst.operands[1].present || inst.size_req == 4)
9007 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
9008 {
9009 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9010 inst.instruction = 0xf3af8000;
9011 inst.instruction |= imod << 9;
9012 inst.instruction |= inst.operands[0].imm << 5;
9013 if (inst.operands[1].present)
9014 inst.instruction |= 0x100 | inst.operands[1].imm;
9015 }
9016 else
9017 {
9018 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9019 && (inst.operands[0].imm & 4),
9020 _("selected processor does not support 'A' form "
9021 "of this instruction"));
9022 constraint (inst.operands[1].present || inst.size_req == 4,
9023 _("Thumb does not support the 2-argument "
9024 "form of this instruction"));
9025 inst.instruction |= inst.operands[0].imm;
9026 }
9027 }
9028
9029 /* THUMB CPY instruction (argument parse). */
9030
9031 static void
9032 do_t_cpy (void)
9033 {
9034 if (inst.size_req == 4)
9035 {
9036 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9037 inst.instruction |= inst.operands[0].reg << 8;
9038 inst.instruction |= inst.operands[1].reg;
9039 }
9040 else
9041 {
9042 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9043 inst.instruction |= (inst.operands[0].reg & 0x7);
9044 inst.instruction |= inst.operands[1].reg << 3;
9045 }
9046 }
9047
9048 static void
9049 do_t_cbz (void)
9050 {
9051 constraint (current_it_mask, BAD_NOT_IT);
9052 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9053 inst.instruction |= inst.operands[0].reg;
9054 inst.reloc.pc_rel = 1;
9055 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9056 }
9057
9058 static void
9059 do_t_dbg (void)
9060 {
9061 inst.instruction |= inst.operands[0].imm;
9062 }
9063
9064 static void
9065 do_t_div (void)
9066 {
9067 if (!inst.operands[1].present)
9068 inst.operands[1].reg = inst.operands[0].reg;
9069 inst.instruction |= inst.operands[0].reg << 8;
9070 inst.instruction |= inst.operands[1].reg << 16;
9071 inst.instruction |= inst.operands[2].reg;
9072 }
9073
9074 static void
9075 do_t_hint (void)
9076 {
9077 if (unified_syntax && inst.size_req == 4)
9078 inst.instruction = THUMB_OP32 (inst.instruction);
9079 else
9080 inst.instruction = THUMB_OP16 (inst.instruction);
9081 }
9082
9083 static void
9084 do_t_it (void)
9085 {
9086 unsigned int cond = inst.operands[0].imm;
9087
9088 constraint (current_it_mask, BAD_NOT_IT);
9089 current_it_mask = (inst.instruction & 0xf) | 0x10;
9090 current_cc = cond;
9091
9092 /* If the condition is a negative condition, invert the mask. */
9093 if ((cond & 0x1) == 0x0)
9094 {
9095 unsigned int mask = inst.instruction & 0x000f;
9096
9097 if ((mask & 0x7) == 0)
9098 /* no conversion needed */;
9099 else if ((mask & 0x3) == 0)
9100 mask ^= 0x8;
9101 else if ((mask & 0x1) == 0)
9102 mask ^= 0xC;
9103 else
9104 mask ^= 0xE;
9105
9106 inst.instruction &= 0xfff0;
9107 inst.instruction |= mask;
9108 }
9109
9110 inst.instruction |= cond << 4;
9111 }
9112
9113 /* Helper function used for both push/pop and ldm/stm. */
9114 static void
9115 encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9116 {
9117 bfd_boolean load;
9118
9119 load = (inst.instruction & (1 << 20)) != 0;
9120
9121 if (mask & (1 << 13))
9122 inst.error = _("SP not allowed in register list");
9123 if (load)
9124 {
9125 if (mask & (1 << 14)
9126 && mask & (1 << 15))
9127 inst.error = _("LR and PC should not both be in register list");
9128
9129 if ((mask & (1 << base)) != 0
9130 && writeback)
9131 as_warn (_("base register should not be in register list "
9132 "when written back"));
9133 }
9134 else
9135 {
9136 if (mask & (1 << 15))
9137 inst.error = _("PC not allowed in register list");
9138
9139 if (mask & (1 << base))
9140 as_warn (_("value stored for r%d is UNPREDICTABLE"), base);
9141 }
9142
9143 if ((mask & (mask - 1)) == 0)
9144 {
9145 /* Single register transfers implemented as str/ldr. */
9146 if (writeback)
9147 {
9148 if (inst.instruction & (1 << 23))
9149 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9150 else
9151 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9152 }
9153 else
9154 {
9155 if (inst.instruction & (1 << 23))
9156 inst.instruction = 0x00800000; /* ia -> [base] */
9157 else
9158 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9159 }
9160
9161 inst.instruction |= 0xf8400000;
9162 if (load)
9163 inst.instruction |= 0x00100000;
9164
9165 mask = ffs (mask) - 1;
9166 mask <<= 12;
9167 }
9168 else if (writeback)
9169 inst.instruction |= WRITE_BACK;
9170
9171 inst.instruction |= mask;
9172 inst.instruction |= base << 16;
9173 }
9174
9175 static void
9176 do_t_ldmstm (void)
9177 {
9178 /* This really doesn't seem worth it. */
9179 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9180 _("expression too complex"));
9181 constraint (inst.operands[1].writeback,
9182 _("Thumb load/store multiple does not support {reglist}^"));
9183
9184 if (unified_syntax)
9185 {
9186 bfd_boolean narrow;
9187 unsigned mask;
9188
9189 narrow = FALSE;
9190 /* See if we can use a 16-bit instruction. */
9191 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9192 && inst.size_req != 4
9193 && !(inst.operands[1].imm & ~0xff))
9194 {
9195 mask = 1 << inst.operands[0].reg;
9196
9197 if (inst.operands[0].reg <= 7
9198 && (inst.instruction == T_MNEM_stmia
9199 ? inst.operands[0].writeback
9200 : (inst.operands[0].writeback
9201 == !(inst.operands[1].imm & mask))))
9202 {
9203 if (inst.instruction == T_MNEM_stmia
9204 && (inst.operands[1].imm & mask)
9205 && (inst.operands[1].imm & (mask - 1)))
9206 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9207 inst.operands[0].reg);
9208
9209 inst.instruction = THUMB_OP16 (inst.instruction);
9210 inst.instruction |= inst.operands[0].reg << 8;
9211 inst.instruction |= inst.operands[1].imm;
9212 narrow = TRUE;
9213 }
9214 else if (inst.operands[0] .reg == REG_SP
9215 && inst.operands[0].writeback)
9216 {
9217 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9218 ? T_MNEM_push : T_MNEM_pop);
9219 inst.instruction |= inst.operands[1].imm;
9220 narrow = TRUE;
9221 }
9222 }
9223
9224 if (!narrow)
9225 {
9226 if (inst.instruction < 0xffff)
9227 inst.instruction = THUMB_OP32 (inst.instruction);
9228
9229 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
9230 inst.operands[0].writeback);
9231 }
9232 }
9233 else
9234 {
9235 constraint (inst.operands[0].reg > 7
9236 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
9237 constraint (inst.instruction != T_MNEM_ldmia
9238 && inst.instruction != T_MNEM_stmia,
9239 _("Thumb-2 instruction only valid in unified syntax"));
9240 if (inst.instruction == T_MNEM_stmia)
9241 {
9242 if (!inst.operands[0].writeback)
9243 as_warn (_("this instruction will write back the base register"));
9244 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9245 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9246 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9247 inst.operands[0].reg);
9248 }
9249 else
9250 {
9251 if (!inst.operands[0].writeback
9252 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9253 as_warn (_("this instruction will write back the base register"));
9254 else if (inst.operands[0].writeback
9255 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9256 as_warn (_("this instruction will not write back the base register"));
9257 }
9258
9259 inst.instruction = THUMB_OP16 (inst.instruction);
9260 inst.instruction |= inst.operands[0].reg << 8;
9261 inst.instruction |= inst.operands[1].imm;
9262 }
9263 }
9264
9265 static void
9266 do_t_ldrex (void)
9267 {
9268 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9269 || inst.operands[1].postind || inst.operands[1].writeback
9270 || inst.operands[1].immisreg || inst.operands[1].shifted
9271 || inst.operands[1].negative,
9272 BAD_ADDR_MODE);
9273
9274 inst.instruction |= inst.operands[0].reg << 12;
9275 inst.instruction |= inst.operands[1].reg << 16;
9276 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9277 }
9278
9279 static void
9280 do_t_ldrexd (void)
9281 {
9282 if (!inst.operands[1].present)
9283 {
9284 constraint (inst.operands[0].reg == REG_LR,
9285 _("r14 not allowed as first register "
9286 "when second register is omitted"));
9287 inst.operands[1].reg = inst.operands[0].reg + 1;
9288 }
9289 constraint (inst.operands[0].reg == inst.operands[1].reg,
9290 BAD_OVERLAP);
9291
9292 inst.instruction |= inst.operands[0].reg << 12;
9293 inst.instruction |= inst.operands[1].reg << 8;
9294 inst.instruction |= inst.operands[2].reg << 16;
9295 }
9296
9297 static void
9298 do_t_ldst (void)
9299 {
9300 unsigned long opcode;
9301 int Rn;
9302
9303 opcode = inst.instruction;
9304 if (unified_syntax)
9305 {
9306 if (!inst.operands[1].isreg)
9307 {
9308 if (opcode <= 0xffff)
9309 inst.instruction = THUMB_OP32 (opcode);
9310 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9311 return;
9312 }
9313 if (inst.operands[1].isreg
9314 && !inst.operands[1].writeback
9315 && !inst.operands[1].shifted && !inst.operands[1].postind
9316 && !inst.operands[1].negative && inst.operands[0].reg <= 7
9317 && opcode <= 0xffff
9318 && inst.size_req != 4)
9319 {
9320 /* Insn may have a 16-bit form. */
9321 Rn = inst.operands[1].reg;
9322 if (inst.operands[1].immisreg)
9323 {
9324 inst.instruction = THUMB_OP16 (opcode);
9325 /* [Rn, Rik] */
9326 if (Rn <= 7 && inst.operands[1].imm <= 7)
9327 goto op16;
9328 }
9329 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9330 && opcode != T_MNEM_ldrsb)
9331 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9332 || (Rn == REG_SP && opcode == T_MNEM_str))
9333 {
9334 /* [Rn, #const] */
9335 if (Rn > 7)
9336 {
9337 if (Rn == REG_PC)
9338 {
9339 if (inst.reloc.pc_rel)
9340 opcode = T_MNEM_ldr_pc2;
9341 else
9342 opcode = T_MNEM_ldr_pc;
9343 }
9344 else
9345 {
9346 if (opcode == T_MNEM_ldr)
9347 opcode = T_MNEM_ldr_sp;
9348 else
9349 opcode = T_MNEM_str_sp;
9350 }
9351 inst.instruction = inst.operands[0].reg << 8;
9352 }
9353 else
9354 {
9355 inst.instruction = inst.operands[0].reg;
9356 inst.instruction |= inst.operands[1].reg << 3;
9357 }
9358 inst.instruction |= THUMB_OP16 (opcode);
9359 if (inst.size_req == 2)
9360 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9361 else
9362 inst.relax = opcode;
9363 return;
9364 }
9365 }
9366 /* Definitely a 32-bit variant. */
9367 inst.instruction = THUMB_OP32 (opcode);
9368 inst.instruction |= inst.operands[0].reg << 12;
9369 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
9370 return;
9371 }
9372
9373 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9374
9375 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
9376 {
9377 /* Only [Rn,Rm] is acceptable. */
9378 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
9379 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
9380 || inst.operands[1].postind || inst.operands[1].shifted
9381 || inst.operands[1].negative,
9382 _("Thumb does not support this addressing mode"));
9383 inst.instruction = THUMB_OP16 (inst.instruction);
9384 goto op16;
9385 }
9386
9387 inst.instruction = THUMB_OP16 (inst.instruction);
9388 if (!inst.operands[1].isreg)
9389 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9390 return;
9391
9392 constraint (!inst.operands[1].preind
9393 || inst.operands[1].shifted
9394 || inst.operands[1].writeback,
9395 _("Thumb does not support this addressing mode"));
9396 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
9397 {
9398 constraint (inst.instruction & 0x0600,
9399 _("byte or halfword not valid for base register"));
9400 constraint (inst.operands[1].reg == REG_PC
9401 && !(inst.instruction & THUMB_LOAD_BIT),
9402 _("r15 based store not allowed"));
9403 constraint (inst.operands[1].immisreg,
9404 _("invalid base register for register offset"));
9405
9406 if (inst.operands[1].reg == REG_PC)
9407 inst.instruction = T_OPCODE_LDR_PC;
9408 else if (inst.instruction & THUMB_LOAD_BIT)
9409 inst.instruction = T_OPCODE_LDR_SP;
9410 else
9411 inst.instruction = T_OPCODE_STR_SP;
9412
9413 inst.instruction |= inst.operands[0].reg << 8;
9414 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9415 return;
9416 }
9417
9418 constraint (inst.operands[1].reg > 7, BAD_HIREG);
9419 if (!inst.operands[1].immisreg)
9420 {
9421 /* Immediate offset. */
9422 inst.instruction |= inst.operands[0].reg;
9423 inst.instruction |= inst.operands[1].reg << 3;
9424 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9425 return;
9426 }
9427
9428 /* Register offset. */
9429 constraint (inst.operands[1].imm > 7, BAD_HIREG);
9430 constraint (inst.operands[1].negative,
9431 _("Thumb does not support this addressing mode"));
9432
9433 op16:
9434 switch (inst.instruction)
9435 {
9436 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
9437 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
9438 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
9439 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
9440 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
9441 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
9442 case 0x5600 /* ldrsb */:
9443 case 0x5e00 /* ldrsh */: break;
9444 default: abort ();
9445 }
9446
9447 inst.instruction |= inst.operands[0].reg;
9448 inst.instruction |= inst.operands[1].reg << 3;
9449 inst.instruction |= inst.operands[1].imm << 6;
9450 }
9451
9452 static void
9453 do_t_ldstd (void)
9454 {
9455 if (!inst.operands[1].present)
9456 {
9457 inst.operands[1].reg = inst.operands[0].reg + 1;
9458 constraint (inst.operands[0].reg == REG_LR,
9459 _("r14 not allowed here"));
9460 }
9461 inst.instruction |= inst.operands[0].reg << 12;
9462 inst.instruction |= inst.operands[1].reg << 8;
9463 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
9464 }
9465
9466 static void
9467 do_t_ldstt (void)
9468 {
9469 inst.instruction |= inst.operands[0].reg << 12;
9470 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
9471 }
9472
9473 static void
9474 do_t_mla (void)
9475 {
9476 inst.instruction |= inst.operands[0].reg << 8;
9477 inst.instruction |= inst.operands[1].reg << 16;
9478 inst.instruction |= inst.operands[2].reg;
9479 inst.instruction |= inst.operands[3].reg << 12;
9480 }
9481
9482 static void
9483 do_t_mlal (void)
9484 {
9485 inst.instruction |= inst.operands[0].reg << 12;
9486 inst.instruction |= inst.operands[1].reg << 8;
9487 inst.instruction |= inst.operands[2].reg << 16;
9488 inst.instruction |= inst.operands[3].reg;
9489 }
9490
9491 static void
9492 do_t_mov_cmp (void)
9493 {
9494 if (unified_syntax)
9495 {
9496 int r0off = (inst.instruction == T_MNEM_mov
9497 || inst.instruction == T_MNEM_movs) ? 8 : 16;
9498 unsigned long opcode;
9499 bfd_boolean narrow;
9500 bfd_boolean low_regs;
9501
9502 low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7);
9503 opcode = inst.instruction;
9504 if (current_it_mask)
9505 narrow = opcode != T_MNEM_movs;
9506 else
9507 narrow = opcode != T_MNEM_movs || low_regs;
9508 if (inst.size_req == 4
9509 || inst.operands[1].shifted)
9510 narrow = FALSE;
9511
9512 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
9513 if (opcode == T_MNEM_movs && inst.operands[1].isreg
9514 && !inst.operands[1].shifted
9515 && inst.operands[0].reg == REG_PC
9516 && inst.operands[1].reg == REG_LR)
9517 {
9518 inst.instruction = T2_SUBS_PC_LR;
9519 return;
9520 }
9521
9522 if (!inst.operands[1].isreg)
9523 {
9524 /* Immediate operand. */
9525 if (current_it_mask == 0 && opcode == T_MNEM_mov)
9526 narrow = 0;
9527 if (low_regs && narrow)
9528 {
9529 inst.instruction = THUMB_OP16 (opcode);
9530 inst.instruction |= inst.operands[0].reg << 8;
9531 if (inst.size_req == 2)
9532 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9533 else
9534 inst.relax = opcode;
9535 }
9536 else
9537 {
9538 inst.instruction = THUMB_OP32 (inst.instruction);
9539 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9540 inst.instruction |= inst.operands[0].reg << r0off;
9541 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9542 }
9543 }
9544 else if (inst.operands[1].shifted && inst.operands[1].immisreg
9545 && (inst.instruction == T_MNEM_mov
9546 || inst.instruction == T_MNEM_movs))
9547 {
9548 /* Register shifts are encoded as separate shift instructions. */
9549 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
9550
9551 if (current_it_mask)
9552 narrow = !flags;
9553 else
9554 narrow = flags;
9555
9556 if (inst.size_req == 4)
9557 narrow = FALSE;
9558
9559 if (!low_regs || inst.operands[1].imm > 7)
9560 narrow = FALSE;
9561
9562 if (inst.operands[0].reg != inst.operands[1].reg)
9563 narrow = FALSE;
9564
9565 switch (inst.operands[1].shift_kind)
9566 {
9567 case SHIFT_LSL:
9568 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
9569 break;
9570 case SHIFT_ASR:
9571 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
9572 break;
9573 case SHIFT_LSR:
9574 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
9575 break;
9576 case SHIFT_ROR:
9577 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
9578 break;
9579 default:
9580 abort ();
9581 }
9582
9583 inst.instruction = opcode;
9584 if (narrow)
9585 {
9586 inst.instruction |= inst.operands[0].reg;
9587 inst.instruction |= inst.operands[1].imm << 3;
9588 }
9589 else
9590 {
9591 if (flags)
9592 inst.instruction |= CONDS_BIT;
9593
9594 inst.instruction |= inst.operands[0].reg << 8;
9595 inst.instruction |= inst.operands[1].reg << 16;
9596 inst.instruction |= inst.operands[1].imm;
9597 }
9598 }
9599 else if (!narrow)
9600 {
9601 /* Some mov with immediate shift have narrow variants.
9602 Register shifts are handled above. */
9603 if (low_regs && inst.operands[1].shifted
9604 && (inst.instruction == T_MNEM_mov
9605 || inst.instruction == T_MNEM_movs))
9606 {
9607 if (current_it_mask)
9608 narrow = (inst.instruction == T_MNEM_mov);
9609 else
9610 narrow = (inst.instruction == T_MNEM_movs);
9611 }
9612
9613 if (narrow)
9614 {
9615 switch (inst.operands[1].shift_kind)
9616 {
9617 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
9618 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
9619 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
9620 default: narrow = FALSE; break;
9621 }
9622 }
9623
9624 if (narrow)
9625 {
9626 inst.instruction |= inst.operands[0].reg;
9627 inst.instruction |= inst.operands[1].reg << 3;
9628 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
9629 }
9630 else
9631 {
9632 inst.instruction = THUMB_OP32 (inst.instruction);
9633 inst.instruction |= inst.operands[0].reg << r0off;
9634 encode_thumb32_shifted_operand (1);
9635 }
9636 }
9637 else
9638 switch (inst.instruction)
9639 {
9640 case T_MNEM_mov:
9641 inst.instruction = T_OPCODE_MOV_HR;
9642 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9643 inst.instruction |= (inst.operands[0].reg & 0x7);
9644 inst.instruction |= inst.operands[1].reg << 3;
9645 break;
9646
9647 case T_MNEM_movs:
9648 /* We know we have low registers at this point.
9649 Generate ADD Rd, Rs, #0. */
9650 inst.instruction = T_OPCODE_ADD_I3;
9651 inst.instruction |= inst.operands[0].reg;
9652 inst.instruction |= inst.operands[1].reg << 3;
9653 break;
9654
9655 case T_MNEM_cmp:
9656 if (low_regs)
9657 {
9658 inst.instruction = T_OPCODE_CMP_LR;
9659 inst.instruction |= inst.operands[0].reg;
9660 inst.instruction |= inst.operands[1].reg << 3;
9661 }
9662 else
9663 {
9664 inst.instruction = T_OPCODE_CMP_HR;
9665 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9666 inst.instruction |= (inst.operands[0].reg & 0x7);
9667 inst.instruction |= inst.operands[1].reg << 3;
9668 }
9669 break;
9670 }
9671 return;
9672 }
9673
9674 inst.instruction = THUMB_OP16 (inst.instruction);
9675 if (inst.operands[1].isreg)
9676 {
9677 if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8)
9678 {
9679 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
9680 since a MOV instruction produces unpredictable results. */
9681 if (inst.instruction == T_OPCODE_MOV_I8)
9682 inst.instruction = T_OPCODE_ADD_I3;
9683 else
9684 inst.instruction = T_OPCODE_CMP_LR;
9685
9686 inst.instruction |= inst.operands[0].reg;
9687 inst.instruction |= inst.operands[1].reg << 3;
9688 }
9689 else
9690 {
9691 if (inst.instruction == T_OPCODE_MOV_I8)
9692 inst.instruction = T_OPCODE_MOV_HR;
9693 else
9694 inst.instruction = T_OPCODE_CMP_HR;
9695 do_t_cpy ();
9696 }
9697 }
9698 else
9699 {
9700 constraint (inst.operands[0].reg > 7,
9701 _("only lo regs allowed with immediate"));
9702 inst.instruction |= inst.operands[0].reg << 8;
9703 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9704 }
9705 }
9706
9707 static void
9708 do_t_mov16 (void)
9709 {
9710 bfd_vma imm;
9711 bfd_boolean top;
9712
9713 top = (inst.instruction & 0x00800000) != 0;
9714 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
9715 {
9716 constraint (top, _(":lower16: not allowed this instruction"));
9717 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
9718 }
9719 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
9720 {
9721 constraint (!top, _(":upper16: not allowed this instruction"));
9722 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
9723 }
9724
9725 inst.instruction |= inst.operands[0].reg << 8;
9726 if (inst.reloc.type == BFD_RELOC_UNUSED)
9727 {
9728 imm = inst.reloc.exp.X_add_number;
9729 inst.instruction |= (imm & 0xf000) << 4;
9730 inst.instruction |= (imm & 0x0800) << 15;
9731 inst.instruction |= (imm & 0x0700) << 4;
9732 inst.instruction |= (imm & 0x00ff);
9733 }
9734 }
9735
9736 static void
9737 do_t_mvn_tst (void)
9738 {
9739 if (unified_syntax)
9740 {
9741 int r0off = (inst.instruction == T_MNEM_mvn
9742 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
9743 bfd_boolean narrow;
9744
9745 if (inst.size_req == 4
9746 || inst.instruction > 0xffff
9747 || inst.operands[1].shifted
9748 || inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9749 narrow = FALSE;
9750 else if (inst.instruction == T_MNEM_cmn)
9751 narrow = TRUE;
9752 else if (THUMB_SETS_FLAGS (inst.instruction))
9753 narrow = (current_it_mask == 0);
9754 else
9755 narrow = (current_it_mask != 0);
9756
9757 if (!inst.operands[1].isreg)
9758 {
9759 /* For an immediate, we always generate a 32-bit opcode;
9760 section relaxation will shrink it later if possible. */
9761 if (inst.instruction < 0xffff)
9762 inst.instruction = THUMB_OP32 (inst.instruction);
9763 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9764 inst.instruction |= inst.operands[0].reg << r0off;
9765 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9766 }
9767 else
9768 {
9769 /* See if we can do this with a 16-bit instruction. */
9770 if (narrow)
9771 {
9772 inst.instruction = THUMB_OP16 (inst.instruction);
9773 inst.instruction |= inst.operands[0].reg;
9774 inst.instruction |= inst.operands[1].reg << 3;
9775 }
9776 else
9777 {
9778 constraint (inst.operands[1].shifted
9779 && inst.operands[1].immisreg,
9780 _("shift must be constant"));
9781 if (inst.instruction < 0xffff)
9782 inst.instruction = THUMB_OP32 (inst.instruction);
9783 inst.instruction |= inst.operands[0].reg << r0off;
9784 encode_thumb32_shifted_operand (1);
9785 }
9786 }
9787 }
9788 else
9789 {
9790 constraint (inst.instruction > 0xffff
9791 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
9792 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
9793 _("unshifted register required"));
9794 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9795 BAD_HIREG);
9796
9797 inst.instruction = THUMB_OP16 (inst.instruction);
9798 inst.instruction |= inst.operands[0].reg;
9799 inst.instruction |= inst.operands[1].reg << 3;
9800 }
9801 }
9802
9803 static void
9804 do_t_mrs (void)
9805 {
9806 int flags;
9807
9808 if (do_vfp_nsyn_mrs () == SUCCESS)
9809 return;
9810
9811 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
9812 if (flags == 0)
9813 {
9814 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
9815 _("selected processor does not support "
9816 "requested special purpose register"));
9817 }
9818 else
9819 {
9820 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9821 _("selected processor does not support "
9822 "requested special purpose register"));
9823 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9824 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
9825 _("'CPSR' or 'SPSR' expected"));
9826 }
9827
9828 inst.instruction |= inst.operands[0].reg << 8;
9829 inst.instruction |= (flags & SPSR_BIT) >> 2;
9830 inst.instruction |= inst.operands[1].imm & 0xff;
9831 }
9832
9833 static void
9834 do_t_msr (void)
9835 {
9836 int flags;
9837
9838 if (do_vfp_nsyn_msr () == SUCCESS)
9839 return;
9840
9841 constraint (!inst.operands[1].isreg,
9842 _("Thumb encoding does not support an immediate here"));
9843 flags = inst.operands[0].imm;
9844 if (flags & ~0xff)
9845 {
9846 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9847 _("selected processor does not support "
9848 "requested special purpose register"));
9849 }
9850 else
9851 {
9852 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
9853 _("selected processor does not support "
9854 "requested special purpose register"));
9855 flags |= PSR_f;
9856 }
9857 inst.instruction |= (flags & SPSR_BIT) >> 2;
9858 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
9859 inst.instruction |= (flags & 0xff);
9860 inst.instruction |= inst.operands[1].reg << 16;
9861 }
9862
9863 static void
9864 do_t_mul (void)
9865 {
9866 if (!inst.operands[2].present)
9867 inst.operands[2].reg = inst.operands[0].reg;
9868
9869 /* There is no 32-bit MULS and no 16-bit MUL. */
9870 if (unified_syntax && inst.instruction == T_MNEM_mul)
9871 {
9872 inst.instruction = THUMB_OP32 (inst.instruction);
9873 inst.instruction |= inst.operands[0].reg << 8;
9874 inst.instruction |= inst.operands[1].reg << 16;
9875 inst.instruction |= inst.operands[2].reg << 0;
9876 }
9877 else
9878 {
9879 constraint (!unified_syntax
9880 && inst.instruction == T_MNEM_muls, BAD_THUMB32);
9881 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9882 BAD_HIREG);
9883
9884 inst.instruction = THUMB_OP16 (inst.instruction);
9885 inst.instruction |= inst.operands[0].reg;
9886
9887 if (inst.operands[0].reg == inst.operands[1].reg)
9888 inst.instruction |= inst.operands[2].reg << 3;
9889 else if (inst.operands[0].reg == inst.operands[2].reg)
9890 inst.instruction |= inst.operands[1].reg << 3;
9891 else
9892 constraint (1, _("dest must overlap one source register"));
9893 }
9894 }
9895
9896 static void
9897 do_t_mull (void)
9898 {
9899 inst.instruction |= inst.operands[0].reg << 12;
9900 inst.instruction |= inst.operands[1].reg << 8;
9901 inst.instruction |= inst.operands[2].reg << 16;
9902 inst.instruction |= inst.operands[3].reg;
9903
9904 if (inst.operands[0].reg == inst.operands[1].reg)
9905 as_tsktsk (_("rdhi and rdlo must be different"));
9906 }
9907
9908 static void
9909 do_t_nop (void)
9910 {
9911 if (unified_syntax)
9912 {
9913 if (inst.size_req == 4 || inst.operands[0].imm > 15)
9914 {
9915 inst.instruction = THUMB_OP32 (inst.instruction);
9916 inst.instruction |= inst.operands[0].imm;
9917 }
9918 else
9919 {
9920 inst.instruction = THUMB_OP16 (inst.instruction);
9921 inst.instruction |= inst.operands[0].imm << 4;
9922 }
9923 }
9924 else
9925 {
9926 constraint (inst.operands[0].present,
9927 _("Thumb does not support NOP with hints"));
9928 inst.instruction = 0x46c0;
9929 }
9930 }
9931
9932 static void
9933 do_t_neg (void)
9934 {
9935 if (unified_syntax)
9936 {
9937 bfd_boolean narrow;
9938
9939 if (THUMB_SETS_FLAGS (inst.instruction))
9940 narrow = (current_it_mask == 0);
9941 else
9942 narrow = (current_it_mask != 0);
9943 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9944 narrow = FALSE;
9945 if (inst.size_req == 4)
9946 narrow = FALSE;
9947
9948 if (!narrow)
9949 {
9950 inst.instruction = THUMB_OP32 (inst.instruction);
9951 inst.instruction |= inst.operands[0].reg << 8;
9952 inst.instruction |= inst.operands[1].reg << 16;
9953 }
9954 else
9955 {
9956 inst.instruction = THUMB_OP16 (inst.instruction);
9957 inst.instruction |= inst.operands[0].reg;
9958 inst.instruction |= inst.operands[1].reg << 3;
9959 }
9960 }
9961 else
9962 {
9963 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9964 BAD_HIREG);
9965 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9966
9967 inst.instruction = THUMB_OP16 (inst.instruction);
9968 inst.instruction |= inst.operands[0].reg;
9969 inst.instruction |= inst.operands[1].reg << 3;
9970 }
9971 }
9972
9973 static void
9974 do_t_pkhbt (void)
9975 {
9976 inst.instruction |= inst.operands[0].reg << 8;
9977 inst.instruction |= inst.operands[1].reg << 16;
9978 inst.instruction |= inst.operands[2].reg;
9979 if (inst.operands[3].present)
9980 {
9981 unsigned int val = inst.reloc.exp.X_add_number;
9982 constraint (inst.reloc.exp.X_op != O_constant,
9983 _("expression too complex"));
9984 inst.instruction |= (val & 0x1c) << 10;
9985 inst.instruction |= (val & 0x03) << 6;
9986 }
9987 }
9988
9989 static void
9990 do_t_pkhtb (void)
9991 {
9992 if (!inst.operands[3].present)
9993 inst.instruction &= ~0x00000020;
9994 do_t_pkhbt ();
9995 }
9996
9997 static void
9998 do_t_pld (void)
9999 {
10000 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
10001 }
10002
10003 static void
10004 do_t_push_pop (void)
10005 {
10006 unsigned mask;
10007
10008 constraint (inst.operands[0].writeback,
10009 _("push/pop do not support {reglist}^"));
10010 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10011 _("expression too complex"));
10012
10013 mask = inst.operands[0].imm;
10014 if ((mask & ~0xff) == 0)
10015 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
10016 else if ((inst.instruction == T_MNEM_push
10017 && (mask & ~0xff) == 1 << REG_LR)
10018 || (inst.instruction == T_MNEM_pop
10019 && (mask & ~0xff) == 1 << REG_PC))
10020 {
10021 inst.instruction = THUMB_OP16 (inst.instruction);
10022 inst.instruction |= THUMB_PP_PC_LR;
10023 inst.instruction |= mask & 0xff;
10024 }
10025 else if (unified_syntax)
10026 {
10027 inst.instruction = THUMB_OP32 (inst.instruction);
10028 encode_thumb2_ldmstm (13, mask, TRUE);
10029 }
10030 else
10031 {
10032 inst.error = _("invalid register list to push/pop instruction");
10033 return;
10034 }
10035 }
10036
10037 static void
10038 do_t_rbit (void)
10039 {
10040 inst.instruction |= inst.operands[0].reg << 8;
10041 inst.instruction |= inst.operands[1].reg << 16;
10042 }
10043
10044 static void
10045 do_t_rev (void)
10046 {
10047 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10048 && inst.size_req != 4)
10049 {
10050 inst.instruction = THUMB_OP16 (inst.instruction);
10051 inst.instruction |= inst.operands[0].reg;
10052 inst.instruction |= inst.operands[1].reg << 3;
10053 }
10054 else if (unified_syntax)
10055 {
10056 inst.instruction = THUMB_OP32 (inst.instruction);
10057 inst.instruction |= inst.operands[0].reg << 8;
10058 inst.instruction |= inst.operands[1].reg << 16;
10059 inst.instruction |= inst.operands[1].reg;
10060 }
10061 else
10062 inst.error = BAD_HIREG;
10063 }
10064
10065 static void
10066 do_t_rsb (void)
10067 {
10068 int Rd, Rs;
10069
10070 Rd = inst.operands[0].reg;
10071 Rs = (inst.operands[1].present
10072 ? inst.operands[1].reg /* Rd, Rs, foo */
10073 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10074
10075 inst.instruction |= Rd << 8;
10076 inst.instruction |= Rs << 16;
10077 if (!inst.operands[2].isreg)
10078 {
10079 bfd_boolean narrow;
10080
10081 if ((inst.instruction & 0x00100000) != 0)
10082 narrow = (current_it_mask == 0);
10083 else
10084 narrow = (current_it_mask != 0);
10085
10086 if (Rd > 7 || Rs > 7)
10087 narrow = FALSE;
10088
10089 if (inst.size_req == 4 || !unified_syntax)
10090 narrow = FALSE;
10091
10092 if (inst.reloc.exp.X_op != O_constant
10093 || inst.reloc.exp.X_add_number != 0)
10094 narrow = FALSE;
10095
10096 /* Turn rsb #0 into 16-bit neg. We should probably do this via
10097 relaxation, but it doesn't seem worth the hassle. */
10098 if (narrow)
10099 {
10100 inst.reloc.type = BFD_RELOC_UNUSED;
10101 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10102 inst.instruction |= Rs << 3;
10103 inst.instruction |= Rd;
10104 }
10105 else
10106 {
10107 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10108 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10109 }
10110 }
10111 else
10112 encode_thumb32_shifted_operand (2);
10113 }
10114
10115 static void
10116 do_t_setend (void)
10117 {
10118 constraint (current_it_mask, BAD_NOT_IT);
10119 if (inst.operands[0].imm)
10120 inst.instruction |= 0x8;
10121 }
10122
10123 static void
10124 do_t_shift (void)
10125 {
10126 if (!inst.operands[1].present)
10127 inst.operands[1].reg = inst.operands[0].reg;
10128
10129 if (unified_syntax)
10130 {
10131 bfd_boolean narrow;
10132 int shift_kind;
10133
10134 switch (inst.instruction)
10135 {
10136 case T_MNEM_asr:
10137 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
10138 case T_MNEM_lsl:
10139 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
10140 case T_MNEM_lsr:
10141 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
10142 case T_MNEM_ror:
10143 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
10144 default: abort ();
10145 }
10146
10147 if (THUMB_SETS_FLAGS (inst.instruction))
10148 narrow = (current_it_mask == 0);
10149 else
10150 narrow = (current_it_mask != 0);
10151 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10152 narrow = FALSE;
10153 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
10154 narrow = FALSE;
10155 if (inst.operands[2].isreg
10156 && (inst.operands[1].reg != inst.operands[0].reg
10157 || inst.operands[2].reg > 7))
10158 narrow = FALSE;
10159 if (inst.size_req == 4)
10160 narrow = FALSE;
10161
10162 if (!narrow)
10163 {
10164 if (inst.operands[2].isreg)
10165 {
10166 inst.instruction = THUMB_OP32 (inst.instruction);
10167 inst.instruction |= inst.operands[0].reg << 8;
10168 inst.instruction |= inst.operands[1].reg << 16;
10169 inst.instruction |= inst.operands[2].reg;
10170 }
10171 else
10172 {
10173 inst.operands[1].shifted = 1;
10174 inst.operands[1].shift_kind = shift_kind;
10175 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
10176 ? T_MNEM_movs : T_MNEM_mov);
10177 inst.instruction |= inst.operands[0].reg << 8;
10178 encode_thumb32_shifted_operand (1);
10179 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
10180 inst.reloc.type = BFD_RELOC_UNUSED;
10181 }
10182 }
10183 else
10184 {
10185 if (inst.operands[2].isreg)
10186 {
10187 switch (shift_kind)
10188 {
10189 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
10190 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
10191 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
10192 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
10193 default: abort ();
10194 }
10195
10196 inst.instruction |= inst.operands[0].reg;
10197 inst.instruction |= inst.operands[2].reg << 3;
10198 }
10199 else
10200 {
10201 switch (shift_kind)
10202 {
10203 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10204 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10205 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10206 default: abort ();
10207 }
10208 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10209 inst.instruction |= inst.operands[0].reg;
10210 inst.instruction |= inst.operands[1].reg << 3;
10211 }
10212 }
10213 }
10214 else
10215 {
10216 constraint (inst.operands[0].reg > 7
10217 || inst.operands[1].reg > 7, BAD_HIREG);
10218 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10219
10220 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
10221 {
10222 constraint (inst.operands[2].reg > 7, BAD_HIREG);
10223 constraint (inst.operands[0].reg != inst.operands[1].reg,
10224 _("source1 and dest must be same register"));
10225
10226 switch (inst.instruction)
10227 {
10228 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
10229 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
10230 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
10231 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
10232 default: abort ();
10233 }
10234
10235 inst.instruction |= inst.operands[0].reg;
10236 inst.instruction |= inst.operands[2].reg << 3;
10237 }
10238 else
10239 {
10240 switch (inst.instruction)
10241 {
10242 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
10243 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
10244 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
10245 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
10246 default: abort ();
10247 }
10248 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10249 inst.instruction |= inst.operands[0].reg;
10250 inst.instruction |= inst.operands[1].reg << 3;
10251 }
10252 }
10253 }
10254
10255 static void
10256 do_t_simd (void)
10257 {
10258 inst.instruction |= inst.operands[0].reg << 8;
10259 inst.instruction |= inst.operands[1].reg << 16;
10260 inst.instruction |= inst.operands[2].reg;
10261 }
10262
10263 static void
10264 do_t_smc (void)
10265 {
10266 unsigned int value = inst.reloc.exp.X_add_number;
10267 constraint (inst.reloc.exp.X_op != O_constant,
10268 _("expression too complex"));
10269 inst.reloc.type = BFD_RELOC_UNUSED;
10270 inst.instruction |= (value & 0xf000) >> 12;
10271 inst.instruction |= (value & 0x0ff0);
10272 inst.instruction |= (value & 0x000f) << 16;
10273 }
10274
10275 static void
10276 do_t_ssat (void)
10277 {
10278 inst.instruction |= inst.operands[0].reg << 8;
10279 inst.instruction |= inst.operands[1].imm - 1;
10280 inst.instruction |= inst.operands[2].reg << 16;
10281
10282 if (inst.operands[3].present)
10283 {
10284 constraint (inst.reloc.exp.X_op != O_constant,
10285 _("expression too complex"));
10286
10287 if (inst.reloc.exp.X_add_number != 0)
10288 {
10289 if (inst.operands[3].shift_kind == SHIFT_ASR)
10290 inst.instruction |= 0x00200000; /* sh bit */
10291 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10292 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10293 }
10294 inst.reloc.type = BFD_RELOC_UNUSED;
10295 }
10296 }
10297
10298 static void
10299 do_t_ssat16 (void)
10300 {
10301 inst.instruction |= inst.operands[0].reg << 8;
10302 inst.instruction |= inst.operands[1].imm - 1;
10303 inst.instruction |= inst.operands[2].reg << 16;
10304 }
10305
10306 static void
10307 do_t_strex (void)
10308 {
10309 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10310 || inst.operands[2].postind || inst.operands[2].writeback
10311 || inst.operands[2].immisreg || inst.operands[2].shifted
10312 || inst.operands[2].negative,
10313 BAD_ADDR_MODE);
10314
10315 inst.instruction |= inst.operands[0].reg << 8;
10316 inst.instruction |= inst.operands[1].reg << 12;
10317 inst.instruction |= inst.operands[2].reg << 16;
10318 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
10319 }
10320
10321 static void
10322 do_t_strexd (void)
10323 {
10324 if (!inst.operands[2].present)
10325 inst.operands[2].reg = inst.operands[1].reg + 1;
10326
10327 constraint (inst.operands[0].reg == inst.operands[1].reg
10328 || inst.operands[0].reg == inst.operands[2].reg
10329 || inst.operands[0].reg == inst.operands[3].reg
10330 || inst.operands[1].reg == inst.operands[2].reg,
10331 BAD_OVERLAP);
10332
10333 inst.instruction |= inst.operands[0].reg;
10334 inst.instruction |= inst.operands[1].reg << 12;
10335 inst.instruction |= inst.operands[2].reg << 8;
10336 inst.instruction |= inst.operands[3].reg << 16;
10337 }
10338
10339 static void
10340 do_t_sxtah (void)
10341 {
10342 inst.instruction |= inst.operands[0].reg << 8;
10343 inst.instruction |= inst.operands[1].reg << 16;
10344 inst.instruction |= inst.operands[2].reg;
10345 inst.instruction |= inst.operands[3].imm << 4;
10346 }
10347
10348 static void
10349 do_t_sxth (void)
10350 {
10351 if (inst.instruction <= 0xffff && inst.size_req != 4
10352 && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10353 && (!inst.operands[2].present || inst.operands[2].imm == 0))
10354 {
10355 inst.instruction = THUMB_OP16 (inst.instruction);
10356 inst.instruction |= inst.operands[0].reg;
10357 inst.instruction |= inst.operands[1].reg << 3;
10358 }
10359 else if (unified_syntax)
10360 {
10361 if (inst.instruction <= 0xffff)
10362 inst.instruction = THUMB_OP32 (inst.instruction);
10363 inst.instruction |= inst.operands[0].reg << 8;
10364 inst.instruction |= inst.operands[1].reg;
10365 inst.instruction |= inst.operands[2].imm << 4;
10366 }
10367 else
10368 {
10369 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
10370 _("Thumb encoding does not support rotation"));
10371 constraint (1, BAD_HIREG);
10372 }
10373 }
10374
10375 static void
10376 do_t_swi (void)
10377 {
10378 inst.reloc.type = BFD_RELOC_ARM_SWI;
10379 }
10380
10381 static void
10382 do_t_tb (void)
10383 {
10384 int half;
10385
10386 half = (inst.instruction & 0x10) != 0;
10387 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
10388 constraint (inst.operands[0].immisreg,
10389 _("instruction requires register index"));
10390 constraint (inst.operands[0].imm == 15,
10391 _("PC is not a valid index register"));
10392 constraint (!half && inst.operands[0].shifted,
10393 _("instruction does not allow shifted index"));
10394 inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm;
10395 }
10396
10397 static void
10398 do_t_usat (void)
10399 {
10400 inst.instruction |= inst.operands[0].reg << 8;
10401 inst.instruction |= inst.operands[1].imm;
10402 inst.instruction |= inst.operands[2].reg << 16;
10403
10404 if (inst.operands[3].present)
10405 {
10406 constraint (inst.reloc.exp.X_op != O_constant,
10407 _("expression too complex"));
10408 if (inst.reloc.exp.X_add_number != 0)
10409 {
10410 if (inst.operands[3].shift_kind == SHIFT_ASR)
10411 inst.instruction |= 0x00200000; /* sh bit */
10412
10413 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10414 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10415 }
10416 inst.reloc.type = BFD_RELOC_UNUSED;
10417 }
10418 }
10419
10420 static void
10421 do_t_usat16 (void)
10422 {
10423 inst.instruction |= inst.operands[0].reg << 8;
10424 inst.instruction |= inst.operands[1].imm;
10425 inst.instruction |= inst.operands[2].reg << 16;
10426 }
10427
10428 /* Neon instruction encoder helpers. */
10429
10430 /* Encodings for the different types for various Neon opcodes. */
10431
10432 /* An "invalid" code for the following tables. */
10433 #define N_INV -1u
10434
10435 struct neon_tab_entry
10436 {
10437 unsigned integer;
10438 unsigned float_or_poly;
10439 unsigned scalar_or_imm;
10440 };
10441
10442 /* Map overloaded Neon opcodes to their respective encodings. */
10443 #define NEON_ENC_TAB \
10444 X(vabd, 0x0000700, 0x1200d00, N_INV), \
10445 X(vmax, 0x0000600, 0x0000f00, N_INV), \
10446 X(vmin, 0x0000610, 0x0200f00, N_INV), \
10447 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
10448 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
10449 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
10450 X(vadd, 0x0000800, 0x0000d00, N_INV), \
10451 X(vsub, 0x1000800, 0x0200d00, N_INV), \
10452 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
10453 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
10454 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
10455 /* Register variants of the following two instructions are encoded as
10456 vcge / vcgt with the operands reversed. */ \
10457 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
10458 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
10459 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
10460 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
10461 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
10462 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
10463 X(vmlal, 0x0800800, N_INV, 0x0800240), \
10464 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
10465 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
10466 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
10467 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
10468 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
10469 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
10470 X(vshl, 0x0000400, N_INV, 0x0800510), \
10471 X(vqshl, 0x0000410, N_INV, 0x0800710), \
10472 X(vand, 0x0000110, N_INV, 0x0800030), \
10473 X(vbic, 0x0100110, N_INV, 0x0800030), \
10474 X(veor, 0x1000110, N_INV, N_INV), \
10475 X(vorn, 0x0300110, N_INV, 0x0800010), \
10476 X(vorr, 0x0200110, N_INV, 0x0800010), \
10477 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
10478 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
10479 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
10480 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
10481 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
10482 X(vst1, 0x0000000, 0x0800000, N_INV), \
10483 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
10484 X(vst2, 0x0000100, 0x0800100, N_INV), \
10485 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
10486 X(vst3, 0x0000200, 0x0800200, N_INV), \
10487 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
10488 X(vst4, 0x0000300, 0x0800300, N_INV), \
10489 X(vmovn, 0x1b20200, N_INV, N_INV), \
10490 X(vtrn, 0x1b20080, N_INV, N_INV), \
10491 X(vqmovn, 0x1b20200, N_INV, N_INV), \
10492 X(vqmovun, 0x1b20240, N_INV, N_INV), \
10493 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
10494 X(vnmla, 0xe000a40, 0xe000b40, N_INV), \
10495 X(vnmls, 0xe100a40, 0xe100b40, N_INV), \
10496 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
10497 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
10498 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
10499 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
10500
10501 enum neon_opc
10502 {
10503 #define X(OPC,I,F,S) N_MNEM_##OPC
10504 NEON_ENC_TAB
10505 #undef X
10506 };
10507
10508 static const struct neon_tab_entry neon_enc_tab[] =
10509 {
10510 #define X(OPC,I,F,S) { (I), (F), (S) }
10511 NEON_ENC_TAB
10512 #undef X
10513 };
10514
10515 #define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10516 #define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10517 #define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10518 #define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10519 #define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10520 #define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10521 #define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10522 #define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10523 #define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10524 #define NEON_ENC_SINGLE(X) \
10525 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
10526 #define NEON_ENC_DOUBLE(X) \
10527 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
10528
10529 /* Define shapes for instruction operands. The following mnemonic characters
10530 are used in this table:
10531
10532 F - VFP S<n> register
10533 D - Neon D<n> register
10534 Q - Neon Q<n> register
10535 I - Immediate
10536 S - Scalar
10537 R - ARM register
10538 L - D<n> register list
10539
10540 This table is used to generate various data:
10541 - enumerations of the form NS_DDR to be used as arguments to
10542 neon_select_shape.
10543 - a table classifying shapes into single, double, quad, mixed.
10544 - a table used to drive neon_select_shape. */
10545
10546 #define NEON_SHAPE_DEF \
10547 X(3, (D, D, D), DOUBLE), \
10548 X(3, (Q, Q, Q), QUAD), \
10549 X(3, (D, D, I), DOUBLE), \
10550 X(3, (Q, Q, I), QUAD), \
10551 X(3, (D, D, S), DOUBLE), \
10552 X(3, (Q, Q, S), QUAD), \
10553 X(2, (D, D), DOUBLE), \
10554 X(2, (Q, Q), QUAD), \
10555 X(2, (D, S), DOUBLE), \
10556 X(2, (Q, S), QUAD), \
10557 X(2, (D, R), DOUBLE), \
10558 X(2, (Q, R), QUAD), \
10559 X(2, (D, I), DOUBLE), \
10560 X(2, (Q, I), QUAD), \
10561 X(3, (D, L, D), DOUBLE), \
10562 X(2, (D, Q), MIXED), \
10563 X(2, (Q, D), MIXED), \
10564 X(3, (D, Q, I), MIXED), \
10565 X(3, (Q, D, I), MIXED), \
10566 X(3, (Q, D, D), MIXED), \
10567 X(3, (D, Q, Q), MIXED), \
10568 X(3, (Q, Q, D), MIXED), \
10569 X(3, (Q, D, S), MIXED), \
10570 X(3, (D, Q, S), MIXED), \
10571 X(4, (D, D, D, I), DOUBLE), \
10572 X(4, (Q, Q, Q, I), QUAD), \
10573 X(2, (F, F), SINGLE), \
10574 X(3, (F, F, F), SINGLE), \
10575 X(2, (F, I), SINGLE), \
10576 X(2, (F, D), MIXED), \
10577 X(2, (D, F), MIXED), \
10578 X(3, (F, F, I), MIXED), \
10579 X(4, (R, R, F, F), SINGLE), \
10580 X(4, (F, F, R, R), SINGLE), \
10581 X(3, (D, R, R), DOUBLE), \
10582 X(3, (R, R, D), DOUBLE), \
10583 X(2, (S, R), SINGLE), \
10584 X(2, (R, S), SINGLE), \
10585 X(2, (F, R), SINGLE), \
10586 X(2, (R, F), SINGLE)
10587
10588 #define S2(A,B) NS_##A##B
10589 #define S3(A,B,C) NS_##A##B##C
10590 #define S4(A,B,C,D) NS_##A##B##C##D
10591
10592 #define X(N, L, C) S##N L
10593
10594 enum neon_shape
10595 {
10596 NEON_SHAPE_DEF,
10597 NS_NULL
10598 };
10599
10600 #undef X
10601 #undef S2
10602 #undef S3
10603 #undef S4
10604
10605 enum neon_shape_class
10606 {
10607 SC_SINGLE,
10608 SC_DOUBLE,
10609 SC_QUAD,
10610 SC_MIXED
10611 };
10612
10613 #define X(N, L, C) SC_##C
10614
10615 static enum neon_shape_class neon_shape_class[] =
10616 {
10617 NEON_SHAPE_DEF
10618 };
10619
10620 #undef X
10621
10622 enum neon_shape_el
10623 {
10624 SE_F,
10625 SE_D,
10626 SE_Q,
10627 SE_I,
10628 SE_S,
10629 SE_R,
10630 SE_L
10631 };
10632
10633 /* Register widths of above. */
10634 static unsigned neon_shape_el_size[] =
10635 {
10636 32,
10637 64,
10638 128,
10639 0,
10640 32,
10641 32,
10642 0
10643 };
10644
10645 struct neon_shape_info
10646 {
10647 unsigned els;
10648 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
10649 };
10650
10651 #define S2(A,B) { SE_##A, SE_##B }
10652 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
10653 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
10654
10655 #define X(N, L, C) { N, S##N L }
10656
10657 static struct neon_shape_info neon_shape_tab[] =
10658 {
10659 NEON_SHAPE_DEF
10660 };
10661
10662 #undef X
10663 #undef S2
10664 #undef S3
10665 #undef S4
10666
10667 /* Bit masks used in type checking given instructions.
10668 'N_EQK' means the type must be the same as (or based on in some way) the key
10669 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
10670 set, various other bits can be set as well in order to modify the meaning of
10671 the type constraint. */
10672
10673 enum neon_type_mask
10674 {
10675 N_S8 = 0x000001,
10676 N_S16 = 0x000002,
10677 N_S32 = 0x000004,
10678 N_S64 = 0x000008,
10679 N_U8 = 0x000010,
10680 N_U16 = 0x000020,
10681 N_U32 = 0x000040,
10682 N_U64 = 0x000080,
10683 N_I8 = 0x000100,
10684 N_I16 = 0x000200,
10685 N_I32 = 0x000400,
10686 N_I64 = 0x000800,
10687 N_8 = 0x001000,
10688 N_16 = 0x002000,
10689 N_32 = 0x004000,
10690 N_64 = 0x008000,
10691 N_P8 = 0x010000,
10692 N_P16 = 0x020000,
10693 N_F32 = 0x040000,
10694 N_F64 = 0x080000,
10695 N_KEY = 0x100000, /* key element (main type specifier). */
10696 N_EQK = 0x200000, /* given operand has the same type & size as the key. */
10697 N_VFP = 0x400000, /* VFP mode: operand size must match register width. */
10698 N_DBL = 0x000001, /* if N_EQK, this operand is twice the size. */
10699 N_HLF = 0x000002, /* if N_EQK, this operand is half the size. */
10700 N_SGN = 0x000004, /* if N_EQK, this operand is forced to be signed. */
10701 N_UNS = 0x000008, /* if N_EQK, this operand is forced to be unsigned. */
10702 N_INT = 0x000010, /* if N_EQK, this operand is forced to be integer. */
10703 N_FLT = 0x000020, /* if N_EQK, this operand is forced to be float. */
10704 N_SIZ = 0x000040, /* if N_EQK, this operand is forced to be size-only. */
10705 N_UTYP = 0,
10706 N_MAX_NONSPECIAL = N_F64
10707 };
10708
10709 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
10710
10711 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
10712 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
10713 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
10714 #define N_SUF_32 (N_SU_32 | N_F32)
10715 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
10716 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
10717
10718 /* Pass this as the first type argument to neon_check_type to ignore types
10719 altogether. */
10720 #define N_IGNORE_TYPE (N_KEY | N_EQK)
10721
10722 /* Select a "shape" for the current instruction (describing register types or
10723 sizes) from a list of alternatives. Return NS_NULL if the current instruction
10724 doesn't fit. For non-polymorphic shapes, checking is usually done as a
10725 function of operand parsing, so this function doesn't need to be called.
10726 Shapes should be listed in order of decreasing length. */
10727
10728 static enum neon_shape
10729 neon_select_shape (enum neon_shape shape, ...)
10730 {
10731 va_list ap;
10732 enum neon_shape first_shape = shape;
10733
10734 /* Fix missing optional operands. FIXME: we don't know at this point how
10735 many arguments we should have, so this makes the assumption that we have
10736 > 1. This is true of all current Neon opcodes, I think, but may not be
10737 true in the future. */
10738 if (!inst.operands[1].present)
10739 inst.operands[1] = inst.operands[0];
10740
10741 va_start (ap, shape);
10742
10743 for (; shape != NS_NULL; shape = va_arg (ap, int))
10744 {
10745 unsigned j;
10746 int matches = 1;
10747
10748 for (j = 0; j < neon_shape_tab[shape].els; j++)
10749 {
10750 if (!inst.operands[j].present)
10751 {
10752 matches = 0;
10753 break;
10754 }
10755
10756 switch (neon_shape_tab[shape].el[j])
10757 {
10758 case SE_F:
10759 if (!(inst.operands[j].isreg
10760 && inst.operands[j].isvec
10761 && inst.operands[j].issingle
10762 && !inst.operands[j].isquad))
10763 matches = 0;
10764 break;
10765
10766 case SE_D:
10767 if (!(inst.operands[j].isreg
10768 && inst.operands[j].isvec
10769 && !inst.operands[j].isquad
10770 && !inst.operands[j].issingle))
10771 matches = 0;
10772 break;
10773
10774 case SE_R:
10775 if (!(inst.operands[j].isreg
10776 && !inst.operands[j].isvec))
10777 matches = 0;
10778 break;
10779
10780 case SE_Q:
10781 if (!(inst.operands[j].isreg
10782 && inst.operands[j].isvec
10783 && inst.operands[j].isquad
10784 && !inst.operands[j].issingle))
10785 matches = 0;
10786 break;
10787
10788 case SE_I:
10789 if (!(!inst.operands[j].isreg
10790 && !inst.operands[j].isscalar))
10791 matches = 0;
10792 break;
10793
10794 case SE_S:
10795 if (!(!inst.operands[j].isreg
10796 && inst.operands[j].isscalar))
10797 matches = 0;
10798 break;
10799
10800 case SE_L:
10801 break;
10802 }
10803 }
10804 if (matches)
10805 break;
10806 }
10807
10808 va_end (ap);
10809
10810 if (shape == NS_NULL && first_shape != NS_NULL)
10811 first_error (_("invalid instruction shape"));
10812
10813 return shape;
10814 }
10815
10816 /* True if SHAPE is predominantly a quadword operation (most of the time, this
10817 means the Q bit should be set). */
10818
10819 static int
10820 neon_quad (enum neon_shape shape)
10821 {
10822 return neon_shape_class[shape] == SC_QUAD;
10823 }
10824
10825 static void
10826 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
10827 unsigned *g_size)
10828 {
10829 /* Allow modification to be made to types which are constrained to be
10830 based on the key element, based on bits set alongside N_EQK. */
10831 if ((typebits & N_EQK) != 0)
10832 {
10833 if ((typebits & N_HLF) != 0)
10834 *g_size /= 2;
10835 else if ((typebits & N_DBL) != 0)
10836 *g_size *= 2;
10837 if ((typebits & N_SGN) != 0)
10838 *g_type = NT_signed;
10839 else if ((typebits & N_UNS) != 0)
10840 *g_type = NT_unsigned;
10841 else if ((typebits & N_INT) != 0)
10842 *g_type = NT_integer;
10843 else if ((typebits & N_FLT) != 0)
10844 *g_type = NT_float;
10845 else if ((typebits & N_SIZ) != 0)
10846 *g_type = NT_untyped;
10847 }
10848 }
10849
10850 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
10851 operand type, i.e. the single type specified in a Neon instruction when it
10852 is the only one given. */
10853
10854 static struct neon_type_el
10855 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
10856 {
10857 struct neon_type_el dest = *key;
10858
10859 assert ((thisarg & N_EQK) != 0);
10860
10861 neon_modify_type_size (thisarg, &dest.type, &dest.size);
10862
10863 return dest;
10864 }
10865
10866 /* Convert Neon type and size into compact bitmask representation. */
10867
10868 static enum neon_type_mask
10869 type_chk_of_el_type (enum neon_el_type type, unsigned size)
10870 {
10871 switch (type)
10872 {
10873 case NT_untyped:
10874 switch (size)
10875 {
10876 case 8: return N_8;
10877 case 16: return N_16;
10878 case 32: return N_32;
10879 case 64: return N_64;
10880 default: ;
10881 }
10882 break;
10883
10884 case NT_integer:
10885 switch (size)
10886 {
10887 case 8: return N_I8;
10888 case 16: return N_I16;
10889 case 32: return N_I32;
10890 case 64: return N_I64;
10891 default: ;
10892 }
10893 break;
10894
10895 case NT_float:
10896 switch (size)
10897 {
10898 case 32: return N_F32;
10899 case 64: return N_F64;
10900 default: ;
10901 }
10902 break;
10903
10904 case NT_poly:
10905 switch (size)
10906 {
10907 case 8: return N_P8;
10908 case 16: return N_P16;
10909 default: ;
10910 }
10911 break;
10912
10913 case NT_signed:
10914 switch (size)
10915 {
10916 case 8: return N_S8;
10917 case 16: return N_S16;
10918 case 32: return N_S32;
10919 case 64: return N_S64;
10920 default: ;
10921 }
10922 break;
10923
10924 case NT_unsigned:
10925 switch (size)
10926 {
10927 case 8: return N_U8;
10928 case 16: return N_U16;
10929 case 32: return N_U32;
10930 case 64: return N_U64;
10931 default: ;
10932 }
10933 break;
10934
10935 default: ;
10936 }
10937
10938 return N_UTYP;
10939 }
10940
10941 /* Convert compact Neon bitmask type representation to a type and size. Only
10942 handles the case where a single bit is set in the mask. */
10943
10944 static int
10945 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
10946 enum neon_type_mask mask)
10947 {
10948 if ((mask & N_EQK) != 0)
10949 return FAIL;
10950
10951 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
10952 *size = 8;
10953 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
10954 *size = 16;
10955 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
10956 *size = 32;
10957 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
10958 *size = 64;
10959 else
10960 return FAIL;
10961
10962 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
10963 *type = NT_signed;
10964 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
10965 *type = NT_unsigned;
10966 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
10967 *type = NT_integer;
10968 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
10969 *type = NT_untyped;
10970 else if ((mask & (N_P8 | N_P16)) != 0)
10971 *type = NT_poly;
10972 else if ((mask & (N_F32 | N_F64)) != 0)
10973 *type = NT_float;
10974 else
10975 return FAIL;
10976
10977 return SUCCESS;
10978 }
10979
10980 /* Modify a bitmask of allowed types. This is only needed for type
10981 relaxation. */
10982
10983 static unsigned
10984 modify_types_allowed (unsigned allowed, unsigned mods)
10985 {
10986 unsigned size;
10987 enum neon_el_type type;
10988 unsigned destmask;
10989 int i;
10990
10991 destmask = 0;
10992
10993 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
10994 {
10995 if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS)
10996 {
10997 neon_modify_type_size (mods, &type, &size);
10998 destmask |= type_chk_of_el_type (type, size);
10999 }
11000 }
11001
11002 return destmask;
11003 }
11004
11005 /* Check type and return type classification.
11006 The manual states (paraphrase): If one datatype is given, it indicates the
11007 type given in:
11008 - the second operand, if there is one
11009 - the operand, if there is no second operand
11010 - the result, if there are no operands.
11011 This isn't quite good enough though, so we use a concept of a "key" datatype
11012 which is set on a per-instruction basis, which is the one which matters when
11013 only one data type is written.
11014 Note: this function has side-effects (e.g. filling in missing operands). All
11015 Neon instructions should call it before performing bit encoding. */
11016
11017 static struct neon_type_el
11018 neon_check_type (unsigned els, enum neon_shape ns, ...)
11019 {
11020 va_list ap;
11021 unsigned i, pass, key_el = 0;
11022 unsigned types[NEON_MAX_TYPE_ELS];
11023 enum neon_el_type k_type = NT_invtype;
11024 unsigned k_size = -1u;
11025 struct neon_type_el badtype = {NT_invtype, -1};
11026 unsigned key_allowed = 0;
11027
11028 /* Optional registers in Neon instructions are always (not) in operand 1.
11029 Fill in the missing operand here, if it was omitted. */
11030 if (els > 1 && !inst.operands[1].present)
11031 inst.operands[1] = inst.operands[0];
11032
11033 /* Suck up all the varargs. */
11034 va_start (ap, ns);
11035 for (i = 0; i < els; i++)
11036 {
11037 unsigned thisarg = va_arg (ap, unsigned);
11038 if (thisarg == N_IGNORE_TYPE)
11039 {
11040 va_end (ap);
11041 return badtype;
11042 }
11043 types[i] = thisarg;
11044 if ((thisarg & N_KEY) != 0)
11045 key_el = i;
11046 }
11047 va_end (ap);
11048
11049 if (inst.vectype.elems > 0)
11050 for (i = 0; i < els; i++)
11051 if (inst.operands[i].vectype.type != NT_invtype)
11052 {
11053 first_error (_("types specified in both the mnemonic and operands"));
11054 return badtype;
11055 }
11056
11057 /* Duplicate inst.vectype elements here as necessary.
11058 FIXME: No idea if this is exactly the same as the ARM assembler,
11059 particularly when an insn takes one register and one non-register
11060 operand. */
11061 if (inst.vectype.elems == 1 && els > 1)
11062 {
11063 unsigned j;
11064 inst.vectype.elems = els;
11065 inst.vectype.el[key_el] = inst.vectype.el[0];
11066 for (j = 0; j < els; j++)
11067 if (j != key_el)
11068 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11069 types[j]);
11070 }
11071 else if (inst.vectype.elems == 0 && els > 0)
11072 {
11073 unsigned j;
11074 /* No types were given after the mnemonic, so look for types specified
11075 after each operand. We allow some flexibility here; as long as the
11076 "key" operand has a type, we can infer the others. */
11077 for (j = 0; j < els; j++)
11078 if (inst.operands[j].vectype.type != NT_invtype)
11079 inst.vectype.el[j] = inst.operands[j].vectype;
11080
11081 if (inst.operands[key_el].vectype.type != NT_invtype)
11082 {
11083 for (j = 0; j < els; j++)
11084 if (inst.operands[j].vectype.type == NT_invtype)
11085 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11086 types[j]);
11087 }
11088 else
11089 {
11090 first_error (_("operand types can't be inferred"));
11091 return badtype;
11092 }
11093 }
11094 else if (inst.vectype.elems != els)
11095 {
11096 first_error (_("type specifier has the wrong number of parts"));
11097 return badtype;
11098 }
11099
11100 for (pass = 0; pass < 2; pass++)
11101 {
11102 for (i = 0; i < els; i++)
11103 {
11104 unsigned thisarg = types[i];
11105 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
11106 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
11107 enum neon_el_type g_type = inst.vectype.el[i].type;
11108 unsigned g_size = inst.vectype.el[i].size;
11109
11110 /* Decay more-specific signed & unsigned types to sign-insensitive
11111 integer types if sign-specific variants are unavailable. */
11112 if ((g_type == NT_signed || g_type == NT_unsigned)
11113 && (types_allowed & N_SU_ALL) == 0)
11114 g_type = NT_integer;
11115
11116 /* If only untyped args are allowed, decay any more specific types to
11117 them. Some instructions only care about signs for some element
11118 sizes, so handle that properly. */
11119 if ((g_size == 8 && (types_allowed & N_8) != 0)
11120 || (g_size == 16 && (types_allowed & N_16) != 0)
11121 || (g_size == 32 && (types_allowed & N_32) != 0)
11122 || (g_size == 64 && (types_allowed & N_64) != 0))
11123 g_type = NT_untyped;
11124
11125 if (pass == 0)
11126 {
11127 if ((thisarg & N_KEY) != 0)
11128 {
11129 k_type = g_type;
11130 k_size = g_size;
11131 key_allowed = thisarg & ~N_KEY;
11132 }
11133 }
11134 else
11135 {
11136 if ((thisarg & N_VFP) != 0)
11137 {
11138 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
11139 unsigned regwidth = neon_shape_el_size[regshape], match;
11140
11141 /* In VFP mode, operands must match register widths. If we
11142 have a key operand, use its width, else use the width of
11143 the current operand. */
11144 if (k_size != -1u)
11145 match = k_size;
11146 else
11147 match = g_size;
11148
11149 if (regwidth != match)
11150 {
11151 first_error (_("operand size must match register width"));
11152 return badtype;
11153 }
11154 }
11155
11156 if ((thisarg & N_EQK) == 0)
11157 {
11158 unsigned given_type = type_chk_of_el_type (g_type, g_size);
11159
11160 if ((given_type & types_allowed) == 0)
11161 {
11162 first_error (_("bad type in Neon instruction"));
11163 return badtype;
11164 }
11165 }
11166 else
11167 {
11168 enum neon_el_type mod_k_type = k_type;
11169 unsigned mod_k_size = k_size;
11170 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
11171 if (g_type != mod_k_type || g_size != mod_k_size)
11172 {
11173 first_error (_("inconsistent types in Neon instruction"));
11174 return badtype;
11175 }
11176 }
11177 }
11178 }
11179 }
11180
11181 return inst.vectype.el[key_el];
11182 }
11183
11184 /* Neon-style VFP instruction forwarding. */
11185
11186 /* Thumb VFP instructions have 0xE in the condition field. */
11187
11188 static void
11189 do_vfp_cond_or_thumb (void)
11190 {
11191 if (thumb_mode)
11192 inst.instruction |= 0xe0000000;
11193 else
11194 inst.instruction |= inst.cond << 28;
11195 }
11196
11197 /* Look up and encode a simple mnemonic, for use as a helper function for the
11198 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
11199 etc. It is assumed that operand parsing has already been done, and that the
11200 operands are in the form expected by the given opcode (this isn't necessarily
11201 the same as the form in which they were parsed, hence some massaging must
11202 take place before this function is called).
11203 Checks current arch version against that in the looked-up opcode. */
11204
11205 static void
11206 do_vfp_nsyn_opcode (const char *opname)
11207 {
11208 const struct asm_opcode *opcode;
11209
11210 opcode = hash_find (arm_ops_hsh, opname);
11211
11212 if (!opcode)
11213 abort ();
11214
11215 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
11216 thumb_mode ? *opcode->tvariant : *opcode->avariant),
11217 _(BAD_FPU));
11218
11219 if (thumb_mode)
11220 {
11221 inst.instruction = opcode->tvalue;
11222 opcode->tencode ();
11223 }
11224 else
11225 {
11226 inst.instruction = (inst.cond << 28) | opcode->avalue;
11227 opcode->aencode ();
11228 }
11229 }
11230
11231 static void
11232 do_vfp_nsyn_add_sub (enum neon_shape rs)
11233 {
11234 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
11235
11236 if (rs == NS_FFF)
11237 {
11238 if (is_add)
11239 do_vfp_nsyn_opcode ("fadds");
11240 else
11241 do_vfp_nsyn_opcode ("fsubs");
11242 }
11243 else
11244 {
11245 if (is_add)
11246 do_vfp_nsyn_opcode ("faddd");
11247 else
11248 do_vfp_nsyn_opcode ("fsubd");
11249 }
11250 }
11251
11252 /* Check operand types to see if this is a VFP instruction, and if so call
11253 PFN (). */
11254
11255 static int
11256 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
11257 {
11258 enum neon_shape rs;
11259 struct neon_type_el et;
11260
11261 switch (args)
11262 {
11263 case 2:
11264 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11265 et = neon_check_type (2, rs,
11266 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11267 break;
11268
11269 case 3:
11270 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11271 et = neon_check_type (3, rs,
11272 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11273 break;
11274
11275 default:
11276 abort ();
11277 }
11278
11279 if (et.type != NT_invtype)
11280 {
11281 pfn (rs);
11282 return SUCCESS;
11283 }
11284 else
11285 inst.error = NULL;
11286
11287 return FAIL;
11288 }
11289
11290 static void
11291 do_vfp_nsyn_mla_mls (enum neon_shape rs)
11292 {
11293 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
11294
11295 if (rs == NS_FFF)
11296 {
11297 if (is_mla)
11298 do_vfp_nsyn_opcode ("fmacs");
11299 else
11300 do_vfp_nsyn_opcode ("fmscs");
11301 }
11302 else
11303 {
11304 if (is_mla)
11305 do_vfp_nsyn_opcode ("fmacd");
11306 else
11307 do_vfp_nsyn_opcode ("fmscd");
11308 }
11309 }
11310
11311 static void
11312 do_vfp_nsyn_mul (enum neon_shape rs)
11313 {
11314 if (rs == NS_FFF)
11315 do_vfp_nsyn_opcode ("fmuls");
11316 else
11317 do_vfp_nsyn_opcode ("fmuld");
11318 }
11319
11320 static void
11321 do_vfp_nsyn_abs_neg (enum neon_shape rs)
11322 {
11323 int is_neg = (inst.instruction & 0x80) != 0;
11324 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
11325
11326 if (rs == NS_FF)
11327 {
11328 if (is_neg)
11329 do_vfp_nsyn_opcode ("fnegs");
11330 else
11331 do_vfp_nsyn_opcode ("fabss");
11332 }
11333 else
11334 {
11335 if (is_neg)
11336 do_vfp_nsyn_opcode ("fnegd");
11337 else
11338 do_vfp_nsyn_opcode ("fabsd");
11339 }
11340 }
11341
11342 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
11343 insns belong to Neon, and are handled elsewhere. */
11344
11345 static void
11346 do_vfp_nsyn_ldm_stm (int is_dbmode)
11347 {
11348 int is_ldm = (inst.instruction & (1 << 20)) != 0;
11349 if (is_ldm)
11350 {
11351 if (is_dbmode)
11352 do_vfp_nsyn_opcode ("fldmdbs");
11353 else
11354 do_vfp_nsyn_opcode ("fldmias");
11355 }
11356 else
11357 {
11358 if (is_dbmode)
11359 do_vfp_nsyn_opcode ("fstmdbs");
11360 else
11361 do_vfp_nsyn_opcode ("fstmias");
11362 }
11363 }
11364
11365 static void
11366 do_vfp_nsyn_sqrt (void)
11367 {
11368 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11369 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11370
11371 if (rs == NS_FF)
11372 do_vfp_nsyn_opcode ("fsqrts");
11373 else
11374 do_vfp_nsyn_opcode ("fsqrtd");
11375 }
11376
11377 static void
11378 do_vfp_nsyn_div (void)
11379 {
11380 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11381 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11382 N_F32 | N_F64 | N_KEY | N_VFP);
11383
11384 if (rs == NS_FFF)
11385 do_vfp_nsyn_opcode ("fdivs");
11386 else
11387 do_vfp_nsyn_opcode ("fdivd");
11388 }
11389
11390 static void
11391 do_vfp_nsyn_nmul (void)
11392 {
11393 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11394 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11395 N_F32 | N_F64 | N_KEY | N_VFP);
11396
11397 if (rs == NS_FFF)
11398 {
11399 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11400 do_vfp_sp_dyadic ();
11401 }
11402 else
11403 {
11404 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11405 do_vfp_dp_rd_rn_rm ();
11406 }
11407 do_vfp_cond_or_thumb ();
11408 }
11409
11410 static void
11411 do_vfp_nsyn_cmp (void)
11412 {
11413 if (inst.operands[1].isreg)
11414 {
11415 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11416 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11417
11418 if (rs == NS_FF)
11419 {
11420 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11421 do_vfp_sp_monadic ();
11422 }
11423 else
11424 {
11425 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11426 do_vfp_dp_rd_rm ();
11427 }
11428 }
11429 else
11430 {
11431 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
11432 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
11433
11434 switch (inst.instruction & 0x0fffffff)
11435 {
11436 case N_MNEM_vcmp:
11437 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
11438 break;
11439 case N_MNEM_vcmpe:
11440 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
11441 break;
11442 default:
11443 abort ();
11444 }
11445
11446 if (rs == NS_FI)
11447 {
11448 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11449 do_vfp_sp_compare_z ();
11450 }
11451 else
11452 {
11453 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11454 do_vfp_dp_rd ();
11455 }
11456 }
11457 do_vfp_cond_or_thumb ();
11458 }
11459
11460 static void
11461 nsyn_insert_sp (void)
11462 {
11463 inst.operands[1] = inst.operands[0];
11464 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
11465 inst.operands[0].reg = 13;
11466 inst.operands[0].isreg = 1;
11467 inst.operands[0].writeback = 1;
11468 inst.operands[0].present = 1;
11469 }
11470
11471 static void
11472 do_vfp_nsyn_push (void)
11473 {
11474 nsyn_insert_sp ();
11475 if (inst.operands[1].issingle)
11476 do_vfp_nsyn_opcode ("fstmdbs");
11477 else
11478 do_vfp_nsyn_opcode ("fstmdbd");
11479 }
11480
11481 static void
11482 do_vfp_nsyn_pop (void)
11483 {
11484 nsyn_insert_sp ();
11485 if (inst.operands[1].issingle)
11486 do_vfp_nsyn_opcode ("fldmias");
11487 else
11488 do_vfp_nsyn_opcode ("fldmiad");
11489 }
11490
11491 /* Fix up Neon data-processing instructions, ORing in the correct bits for
11492 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
11493
11494 static unsigned
11495 neon_dp_fixup (unsigned i)
11496 {
11497 if (thumb_mode)
11498 {
11499 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
11500 if (i & (1 << 24))
11501 i |= 1 << 28;
11502
11503 i &= ~(1 << 24);
11504
11505 i |= 0xef000000;
11506 }
11507 else
11508 i |= 0xf2000000;
11509
11510 return i;
11511 }
11512
11513 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
11514 (0, 1, 2, 3). */
11515
11516 static unsigned
11517 neon_logbits (unsigned x)
11518 {
11519 return ffs (x) - 4;
11520 }
11521
11522 #define LOW4(R) ((R) & 0xf)
11523 #define HI1(R) (((R) >> 4) & 1)
11524
11525 /* Encode insns with bit pattern:
11526
11527 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
11528 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
11529
11530 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
11531 different meaning for some instruction. */
11532
11533 static void
11534 neon_three_same (int isquad, int ubit, int size)
11535 {
11536 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11537 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11538 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
11539 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
11540 inst.instruction |= LOW4 (inst.operands[2].reg);
11541 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
11542 inst.instruction |= (isquad != 0) << 6;
11543 inst.instruction |= (ubit != 0) << 24;
11544 if (size != -1)
11545 inst.instruction |= neon_logbits (size) << 20;
11546
11547 inst.instruction = neon_dp_fixup (inst.instruction);
11548 }
11549
11550 /* Encode instructions of the form:
11551
11552 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
11553 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
11554
11555 Don't write size if SIZE == -1. */
11556
11557 static void
11558 neon_two_same (int qbit, int ubit, int size)
11559 {
11560 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11561 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11562 inst.instruction |= LOW4 (inst.operands[1].reg);
11563 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11564 inst.instruction |= (qbit != 0) << 6;
11565 inst.instruction |= (ubit != 0) << 24;
11566
11567 if (size != -1)
11568 inst.instruction |= neon_logbits (size) << 18;
11569
11570 inst.instruction = neon_dp_fixup (inst.instruction);
11571 }
11572
11573 /* Neon instruction encoders, in approximate order of appearance. */
11574
11575 static void
11576 do_neon_dyadic_i_su (void)
11577 {
11578 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11579 struct neon_type_el et = neon_check_type (3, rs,
11580 N_EQK, N_EQK, N_SU_32 | N_KEY);
11581 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11582 }
11583
11584 static void
11585 do_neon_dyadic_i64_su (void)
11586 {
11587 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11588 struct neon_type_el et = neon_check_type (3, rs,
11589 N_EQK, N_EQK, N_SU_ALL | N_KEY);
11590 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11591 }
11592
11593 static void
11594 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
11595 unsigned immbits)
11596 {
11597 unsigned size = et.size >> 3;
11598 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11599 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11600 inst.instruction |= LOW4 (inst.operands[1].reg);
11601 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11602 inst.instruction |= (isquad != 0) << 6;
11603 inst.instruction |= immbits << 16;
11604 inst.instruction |= (size >> 3) << 7;
11605 inst.instruction |= (size & 0x7) << 19;
11606 if (write_ubit)
11607 inst.instruction |= (uval != 0) << 24;
11608
11609 inst.instruction = neon_dp_fixup (inst.instruction);
11610 }
11611
11612 static void
11613 do_neon_shl_imm (void)
11614 {
11615 if (!inst.operands[2].isreg)
11616 {
11617 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11618 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
11619 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11620 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
11621 }
11622 else
11623 {
11624 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11625 struct neon_type_el et = neon_check_type (3, rs,
11626 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
11627 unsigned int tmp;
11628
11629 /* VSHL/VQSHL 3-register variants have syntax such as:
11630 vshl.xx Dd, Dm, Dn
11631 whereas other 3-register operations encoded by neon_three_same have
11632 syntax like:
11633 vadd.xx Dd, Dn, Dm
11634 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
11635 here. */
11636 tmp = inst.operands[2].reg;
11637 inst.operands[2].reg = inst.operands[1].reg;
11638 inst.operands[1].reg = tmp;
11639 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11640 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11641 }
11642 }
11643
11644 static void
11645 do_neon_qshl_imm (void)
11646 {
11647 if (!inst.operands[2].isreg)
11648 {
11649 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11650 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
11651
11652 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11653 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
11654 inst.operands[2].imm);
11655 }
11656 else
11657 {
11658 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11659 struct neon_type_el et = neon_check_type (3, rs,
11660 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
11661 unsigned int tmp;
11662
11663 /* See note in do_neon_shl_imm. */
11664 tmp = inst.operands[2].reg;
11665 inst.operands[2].reg = inst.operands[1].reg;
11666 inst.operands[1].reg = tmp;
11667 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11668 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11669 }
11670 }
11671
11672 static void
11673 do_neon_rshl (void)
11674 {
11675 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11676 struct neon_type_el et = neon_check_type (3, rs,
11677 N_EQK, N_EQK, N_SU_ALL | N_KEY);
11678 unsigned int tmp;
11679
11680 tmp = inst.operands[2].reg;
11681 inst.operands[2].reg = inst.operands[1].reg;
11682 inst.operands[1].reg = tmp;
11683 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11684 }
11685
11686 static int
11687 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
11688 {
11689 /* Handle .I8 pseudo-instructions. */
11690 if (size == 8)
11691 {
11692 /* Unfortunately, this will make everything apart from zero out-of-range.
11693 FIXME is this the intended semantics? There doesn't seem much point in
11694 accepting .I8 if so. */
11695 immediate |= immediate << 8;
11696 size = 16;
11697 }
11698
11699 if (size >= 32)
11700 {
11701 if (immediate == (immediate & 0x000000ff))
11702 {
11703 *immbits = immediate;
11704 return 0x1;
11705 }
11706 else if (immediate == (immediate & 0x0000ff00))
11707 {
11708 *immbits = immediate >> 8;
11709 return 0x3;
11710 }
11711 else if (immediate == (immediate & 0x00ff0000))
11712 {
11713 *immbits = immediate >> 16;
11714 return 0x5;
11715 }
11716 else if (immediate == (immediate & 0xff000000))
11717 {
11718 *immbits = immediate >> 24;
11719 return 0x7;
11720 }
11721 if ((immediate & 0xffff) != (immediate >> 16))
11722 goto bad_immediate;
11723 immediate &= 0xffff;
11724 }
11725
11726 if (immediate == (immediate & 0x000000ff))
11727 {
11728 *immbits = immediate;
11729 return 0x9;
11730 }
11731 else if (immediate == (immediate & 0x0000ff00))
11732 {
11733 *immbits = immediate >> 8;
11734 return 0xb;
11735 }
11736
11737 bad_immediate:
11738 first_error (_("immediate value out of range"));
11739 return FAIL;
11740 }
11741
11742 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
11743 A, B, C, D. */
11744
11745 static int
11746 neon_bits_same_in_bytes (unsigned imm)
11747 {
11748 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
11749 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
11750 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
11751 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
11752 }
11753
11754 /* For immediate of above form, return 0bABCD. */
11755
11756 static unsigned
11757 neon_squash_bits (unsigned imm)
11758 {
11759 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
11760 | ((imm & 0x01000000) >> 21);
11761 }
11762
11763 /* Compress quarter-float representation to 0b...000 abcdefgh. */
11764
11765 static unsigned
11766 neon_qfloat_bits (unsigned imm)
11767 {
11768 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
11769 }
11770
11771 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
11772 the instruction. *OP is passed as the initial value of the op field, and
11773 may be set to a different value depending on the constant (i.e.
11774 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
11775 MVN). If the immediate looks like a repeated pattern then also
11776 try smaller element sizes. */
11777
11778 static int
11779 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
11780 unsigned *immbits, int *op, int size,
11781 enum neon_el_type type)
11782 {
11783 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
11784 float. */
11785 if (type == NT_float && !float_p)
11786 return FAIL;
11787
11788 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
11789 {
11790 if (size != 32 || *op == 1)
11791 return FAIL;
11792 *immbits = neon_qfloat_bits (immlo);
11793 return 0xf;
11794 }
11795
11796 if (size == 64)
11797 {
11798 if (neon_bits_same_in_bytes (immhi)
11799 && neon_bits_same_in_bytes (immlo))
11800 {
11801 if (*op == 1)
11802 return FAIL;
11803 *immbits = (neon_squash_bits (immhi) << 4)
11804 | neon_squash_bits (immlo);
11805 *op = 1;
11806 return 0xe;
11807 }
11808
11809 if (immhi != immlo)
11810 return FAIL;
11811 }
11812
11813 if (size >= 32)
11814 {
11815 if (immlo == (immlo & 0x000000ff))
11816 {
11817 *immbits = immlo;
11818 return 0x0;
11819 }
11820 else if (immlo == (immlo & 0x0000ff00))
11821 {
11822 *immbits = immlo >> 8;
11823 return 0x2;
11824 }
11825 else if (immlo == (immlo & 0x00ff0000))
11826 {
11827 *immbits = immlo >> 16;
11828 return 0x4;
11829 }
11830 else if (immlo == (immlo & 0xff000000))
11831 {
11832 *immbits = immlo >> 24;
11833 return 0x6;
11834 }
11835 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
11836 {
11837 *immbits = (immlo >> 8) & 0xff;
11838 return 0xc;
11839 }
11840 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
11841 {
11842 *immbits = (immlo >> 16) & 0xff;
11843 return 0xd;
11844 }
11845
11846 if ((immlo & 0xffff) != (immlo >> 16))
11847 return FAIL;
11848 immlo &= 0xffff;
11849 }
11850
11851 if (size >= 16)
11852 {
11853 if (immlo == (immlo & 0x000000ff))
11854 {
11855 *immbits = immlo;
11856 return 0x8;
11857 }
11858 else if (immlo == (immlo & 0x0000ff00))
11859 {
11860 *immbits = immlo >> 8;
11861 return 0xa;
11862 }
11863
11864 if ((immlo & 0xff) != (immlo >> 8))
11865 return FAIL;
11866 immlo &= 0xff;
11867 }
11868
11869 if (immlo == (immlo & 0x000000ff))
11870 {
11871 /* Don't allow MVN with 8-bit immediate. */
11872 if (*op == 1)
11873 return FAIL;
11874 *immbits = immlo;
11875 return 0xe;
11876 }
11877
11878 return FAIL;
11879 }
11880
11881 /* Write immediate bits [7:0] to the following locations:
11882
11883 |28/24|23 19|18 16|15 4|3 0|
11884 | 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|
11885
11886 This function is used by VMOV/VMVN/VORR/VBIC. */
11887
11888 static void
11889 neon_write_immbits (unsigned immbits)
11890 {
11891 inst.instruction |= immbits & 0xf;
11892 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
11893 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
11894 }
11895
11896 /* Invert low-order SIZE bits of XHI:XLO. */
11897
11898 static void
11899 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
11900 {
11901 unsigned immlo = xlo ? *xlo : 0;
11902 unsigned immhi = xhi ? *xhi : 0;
11903
11904 switch (size)
11905 {
11906 case 8:
11907 immlo = (~immlo) & 0xff;
11908 break;
11909
11910 case 16:
11911 immlo = (~immlo) & 0xffff;
11912 break;
11913
11914 case 64:
11915 immhi = (~immhi) & 0xffffffff;
11916 /* fall through. */
11917
11918 case 32:
11919 immlo = (~immlo) & 0xffffffff;
11920 break;
11921
11922 default:
11923 abort ();
11924 }
11925
11926 if (xlo)
11927 *xlo = immlo;
11928
11929 if (xhi)
11930 *xhi = immhi;
11931 }
11932
11933 static void
11934 do_neon_logic (void)
11935 {
11936 if (inst.operands[2].present && inst.operands[2].isreg)
11937 {
11938 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11939 neon_check_type (3, rs, N_IGNORE_TYPE);
11940 /* U bit and size field were set as part of the bitmask. */
11941 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11942 neon_three_same (neon_quad (rs), 0, -1);
11943 }
11944 else
11945 {
11946 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
11947 struct neon_type_el et = neon_check_type (2, rs,
11948 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
11949 enum neon_opc opcode = inst.instruction & 0x0fffffff;
11950 unsigned immbits;
11951 int cmode;
11952
11953 if (et.type == NT_invtype)
11954 return;
11955
11956 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11957
11958 immbits = inst.operands[1].imm;
11959 if (et.size == 64)
11960 {
11961 /* .i64 is a pseudo-op, so the immediate must be a repeating
11962 pattern. */
11963 if (immbits != (inst.operands[1].regisimm ?
11964 inst.operands[1].reg : 0))
11965 {
11966 /* Set immbits to an invalid constant. */
11967 immbits = 0xdeadbeef;
11968 }
11969 }
11970
11971 switch (opcode)
11972 {
11973 case N_MNEM_vbic:
11974 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11975 break;
11976
11977 case N_MNEM_vorr:
11978 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11979 break;
11980
11981 case N_MNEM_vand:
11982 /* Pseudo-instruction for VBIC. */
11983 neon_invert_size (&immbits, 0, et.size);
11984 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11985 break;
11986
11987 case N_MNEM_vorn:
11988 /* Pseudo-instruction for VORR. */
11989 neon_invert_size (&immbits, 0, et.size);
11990 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11991 break;
11992
11993 default:
11994 abort ();
11995 }
11996
11997 if (cmode == FAIL)
11998 return;
11999
12000 inst.instruction |= neon_quad (rs) << 6;
12001 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12002 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12003 inst.instruction |= cmode << 8;
12004 neon_write_immbits (immbits);
12005
12006 inst.instruction = neon_dp_fixup (inst.instruction);
12007 }
12008 }
12009
12010 static void
12011 do_neon_bitfield (void)
12012 {
12013 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12014 neon_check_type (3, rs, N_IGNORE_TYPE);
12015 neon_three_same (neon_quad (rs), 0, -1);
12016 }
12017
12018 static void
12019 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
12020 unsigned destbits)
12021 {
12022 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12023 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
12024 types | N_KEY);
12025 if (et.type == NT_float)
12026 {
12027 inst.instruction = NEON_ENC_FLOAT (inst.instruction);
12028 neon_three_same (neon_quad (rs), 0, -1);
12029 }
12030 else
12031 {
12032 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12033 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
12034 }
12035 }
12036
12037 static void
12038 do_neon_dyadic_if_su (void)
12039 {
12040 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
12041 }
12042
12043 static void
12044 do_neon_dyadic_if_su_d (void)
12045 {
12046 /* This version only allow D registers, but that constraint is enforced during
12047 operand parsing so we don't need to do anything extra here. */
12048 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
12049 }
12050
12051 static void
12052 do_neon_dyadic_if_i_d (void)
12053 {
12054 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12055 affected if we specify unsigned args. */
12056 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12057 }
12058
12059 enum vfp_or_neon_is_neon_bits
12060 {
12061 NEON_CHECK_CC = 1,
12062 NEON_CHECK_ARCH = 2
12063 };
12064
12065 /* Call this function if an instruction which may have belonged to the VFP or
12066 Neon instruction sets, but turned out to be a Neon instruction (due to the
12067 operand types involved, etc.). We have to check and/or fix-up a couple of
12068 things:
12069
12070 - Make sure the user hasn't attempted to make a Neon instruction
12071 conditional.
12072 - Alter the value in the condition code field if necessary.
12073 - Make sure that the arch supports Neon instructions.
12074
12075 Which of these operations take place depends on bits from enum
12076 vfp_or_neon_is_neon_bits.
12077
12078 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
12079 current instruction's condition is COND_ALWAYS, the condition field is
12080 changed to inst.uncond_value. This is necessary because instructions shared
12081 between VFP and Neon may be conditional for the VFP variants only, and the
12082 unconditional Neon version must have, e.g., 0xF in the condition field. */
12083
12084 static int
12085 vfp_or_neon_is_neon (unsigned check)
12086 {
12087 /* Conditions are always legal in Thumb mode (IT blocks). */
12088 if (!thumb_mode && (check & NEON_CHECK_CC))
12089 {
12090 if (inst.cond != COND_ALWAYS)
12091 {
12092 first_error (_(BAD_COND));
12093 return FAIL;
12094 }
12095 if (inst.uncond_value != -1)
12096 inst.instruction |= inst.uncond_value << 28;
12097 }
12098
12099 if ((check & NEON_CHECK_ARCH)
12100 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
12101 {
12102 first_error (_(BAD_FPU));
12103 return FAIL;
12104 }
12105
12106 return SUCCESS;
12107 }
12108
12109 static void
12110 do_neon_addsub_if_i (void)
12111 {
12112 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
12113 return;
12114
12115 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12116 return;
12117
12118 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12119 affected if we specify unsigned args. */
12120 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
12121 }
12122
12123 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
12124 result to be:
12125 V<op> A,B (A is operand 0, B is operand 2)
12126 to mean:
12127 V<op> A,B,A
12128 not:
12129 V<op> A,B,B
12130 so handle that case specially. */
12131
12132 static void
12133 neon_exchange_operands (void)
12134 {
12135 void *scratch = alloca (sizeof (inst.operands[0]));
12136 if (inst.operands[1].present)
12137 {
12138 /* Swap operands[1] and operands[2]. */
12139 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
12140 inst.operands[1] = inst.operands[2];
12141 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
12142 }
12143 else
12144 {
12145 inst.operands[1] = inst.operands[2];
12146 inst.operands[2] = inst.operands[0];
12147 }
12148 }
12149
12150 static void
12151 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
12152 {
12153 if (inst.operands[2].isreg)
12154 {
12155 if (invert)
12156 neon_exchange_operands ();
12157 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
12158 }
12159 else
12160 {
12161 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12162 struct neon_type_el et = neon_check_type (2, rs,
12163 N_EQK | N_SIZ, immtypes | N_KEY);
12164
12165 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12166 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12167 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12168 inst.instruction |= LOW4 (inst.operands[1].reg);
12169 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12170 inst.instruction |= neon_quad (rs) << 6;
12171 inst.instruction |= (et.type == NT_float) << 10;
12172 inst.instruction |= neon_logbits (et.size) << 18;
12173
12174 inst.instruction = neon_dp_fixup (inst.instruction);
12175 }
12176 }
12177
12178 static void
12179 do_neon_cmp (void)
12180 {
12181 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
12182 }
12183
12184 static void
12185 do_neon_cmp_inv (void)
12186 {
12187 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
12188 }
12189
12190 static void
12191 do_neon_ceq (void)
12192 {
12193 neon_compare (N_IF_32, N_IF_32, FALSE);
12194 }
12195
12196 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
12197 scalars, which are encoded in 5 bits, M : Rm.
12198 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
12199 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
12200 index in M. */
12201
12202 static unsigned
12203 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
12204 {
12205 unsigned regno = NEON_SCALAR_REG (scalar);
12206 unsigned elno = NEON_SCALAR_INDEX (scalar);
12207
12208 switch (elsize)
12209 {
12210 case 16:
12211 if (regno > 7 || elno > 3)
12212 goto bad_scalar;
12213 return regno | (elno << 3);
12214
12215 case 32:
12216 if (regno > 15 || elno > 1)
12217 goto bad_scalar;
12218 return regno | (elno << 4);
12219
12220 default:
12221 bad_scalar:
12222 first_error (_("scalar out of range for multiply instruction"));
12223 }
12224
12225 return 0;
12226 }
12227
12228 /* Encode multiply / multiply-accumulate scalar instructions. */
12229
12230 static void
12231 neon_mul_mac (struct neon_type_el et, int ubit)
12232 {
12233 unsigned scalar;
12234
12235 /* Give a more helpful error message if we have an invalid type. */
12236 if (et.type == NT_invtype)
12237 return;
12238
12239 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
12240 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12241 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12242 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12243 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12244 inst.instruction |= LOW4 (scalar);
12245 inst.instruction |= HI1 (scalar) << 5;
12246 inst.instruction |= (et.type == NT_float) << 8;
12247 inst.instruction |= neon_logbits (et.size) << 20;
12248 inst.instruction |= (ubit != 0) << 24;
12249
12250 inst.instruction = neon_dp_fixup (inst.instruction);
12251 }
12252
12253 static void
12254 do_neon_mac_maybe_scalar (void)
12255 {
12256 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
12257 return;
12258
12259 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12260 return;
12261
12262 if (inst.operands[2].isscalar)
12263 {
12264 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
12265 struct neon_type_el et = neon_check_type (3, rs,
12266 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
12267 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12268 neon_mul_mac (et, neon_quad (rs));
12269 }
12270 else
12271 {
12272 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12273 affected if we specify unsigned args. */
12274 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12275 }
12276 }
12277
12278 static void
12279 do_neon_tst (void)
12280 {
12281 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12282 struct neon_type_el et = neon_check_type (3, rs,
12283 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
12284 neon_three_same (neon_quad (rs), 0, et.size);
12285 }
12286
12287 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
12288 same types as the MAC equivalents. The polynomial type for this instruction
12289 is encoded the same as the integer type. */
12290
12291 static void
12292 do_neon_mul (void)
12293 {
12294 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
12295 return;
12296
12297 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12298 return;
12299
12300 if (inst.operands[2].isscalar)
12301 do_neon_mac_maybe_scalar ();
12302 else
12303 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
12304 }
12305
12306 static void
12307 do_neon_qdmulh (void)
12308 {
12309 if (inst.operands[2].isscalar)
12310 {
12311 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
12312 struct neon_type_el et = neon_check_type (3, rs,
12313 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12314 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12315 neon_mul_mac (et, neon_quad (rs));
12316 }
12317 else
12318 {
12319 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12320 struct neon_type_el et = neon_check_type (3, rs,
12321 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12322 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12323 /* The U bit (rounding) comes from bit mask. */
12324 neon_three_same (neon_quad (rs), 0, et.size);
12325 }
12326 }
12327
12328 static void
12329 do_neon_fcmp_absolute (void)
12330 {
12331 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12332 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12333 /* Size field comes from bit mask. */
12334 neon_three_same (neon_quad (rs), 1, -1);
12335 }
12336
12337 static void
12338 do_neon_fcmp_absolute_inv (void)
12339 {
12340 neon_exchange_operands ();
12341 do_neon_fcmp_absolute ();
12342 }
12343
12344 static void
12345 do_neon_step (void)
12346 {
12347 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12348 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12349 neon_three_same (neon_quad (rs), 0, -1);
12350 }
12351
12352 static void
12353 do_neon_abs_neg (void)
12354 {
12355 enum neon_shape rs;
12356 struct neon_type_el et;
12357
12358 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
12359 return;
12360
12361 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12362 return;
12363
12364 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12365 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
12366
12367 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12368 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12369 inst.instruction |= LOW4 (inst.operands[1].reg);
12370 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12371 inst.instruction |= neon_quad (rs) << 6;
12372 inst.instruction |= (et.type == NT_float) << 10;
12373 inst.instruction |= neon_logbits (et.size) << 18;
12374
12375 inst.instruction = neon_dp_fixup (inst.instruction);
12376 }
12377
12378 static void
12379 do_neon_sli (void)
12380 {
12381 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12382 struct neon_type_el et = neon_check_type (2, rs,
12383 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12384 int imm = inst.operands[2].imm;
12385 constraint (imm < 0 || (unsigned)imm >= et.size,
12386 _("immediate out of range for insert"));
12387 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
12388 }
12389
12390 static void
12391 do_neon_sri (void)
12392 {
12393 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12394 struct neon_type_el et = neon_check_type (2, rs,
12395 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12396 int imm = inst.operands[2].imm;
12397 constraint (imm < 1 || (unsigned)imm > et.size,
12398 _("immediate out of range for insert"));
12399 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
12400 }
12401
12402 static void
12403 do_neon_qshlu_imm (void)
12404 {
12405 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12406 struct neon_type_el et = neon_check_type (2, rs,
12407 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
12408 int imm = inst.operands[2].imm;
12409 constraint (imm < 0 || (unsigned)imm >= et.size,
12410 _("immediate out of range for shift"));
12411 /* Only encodes the 'U present' variant of the instruction.
12412 In this case, signed types have OP (bit 8) set to 0.
12413 Unsigned types have OP set to 1. */
12414 inst.instruction |= (et.type == NT_unsigned) << 8;
12415 /* The rest of the bits are the same as other immediate shifts. */
12416 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
12417 }
12418
12419 static void
12420 do_neon_qmovn (void)
12421 {
12422 struct neon_type_el et = neon_check_type (2, NS_DQ,
12423 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12424 /* Saturating move where operands can be signed or unsigned, and the
12425 destination has the same signedness. */
12426 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12427 if (et.type == NT_unsigned)
12428 inst.instruction |= 0xc0;
12429 else
12430 inst.instruction |= 0x80;
12431 neon_two_same (0, 1, et.size / 2);
12432 }
12433
12434 static void
12435 do_neon_qmovun (void)
12436 {
12437 struct neon_type_el et = neon_check_type (2, NS_DQ,
12438 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12439 /* Saturating move with unsigned results. Operands must be signed. */
12440 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12441 neon_two_same (0, 1, et.size / 2);
12442 }
12443
12444 static void
12445 do_neon_rshift_sat_narrow (void)
12446 {
12447 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12448 or unsigned. If operands are unsigned, results must also be unsigned. */
12449 struct neon_type_el et = neon_check_type (2, NS_DQI,
12450 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12451 int imm = inst.operands[2].imm;
12452 /* This gets the bounds check, size encoding and immediate bits calculation
12453 right. */
12454 et.size /= 2;
12455
12456 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
12457 VQMOVN.I<size> <Dd>, <Qm>. */
12458 if (imm == 0)
12459 {
12460 inst.operands[2].present = 0;
12461 inst.instruction = N_MNEM_vqmovn;
12462 do_neon_qmovn ();
12463 return;
12464 }
12465
12466 constraint (imm < 1 || (unsigned)imm > et.size,
12467 _("immediate out of range"));
12468 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
12469 }
12470
12471 static void
12472 do_neon_rshift_sat_narrow_u (void)
12473 {
12474 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12475 or unsigned. If operands are unsigned, results must also be unsigned. */
12476 struct neon_type_el et = neon_check_type (2, NS_DQI,
12477 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12478 int imm = inst.operands[2].imm;
12479 /* This gets the bounds check, size encoding and immediate bits calculation
12480 right. */
12481 et.size /= 2;
12482
12483 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
12484 VQMOVUN.I<size> <Dd>, <Qm>. */
12485 if (imm == 0)
12486 {
12487 inst.operands[2].present = 0;
12488 inst.instruction = N_MNEM_vqmovun;
12489 do_neon_qmovun ();
12490 return;
12491 }
12492
12493 constraint (imm < 1 || (unsigned)imm > et.size,
12494 _("immediate out of range"));
12495 /* FIXME: The manual is kind of unclear about what value U should have in
12496 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
12497 must be 1. */
12498 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
12499 }
12500
12501 static void
12502 do_neon_movn (void)
12503 {
12504 struct neon_type_el et = neon_check_type (2, NS_DQ,
12505 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12506 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12507 neon_two_same (0, 1, et.size / 2);
12508 }
12509
12510 static void
12511 do_neon_rshift_narrow (void)
12512 {
12513 struct neon_type_el et = neon_check_type (2, NS_DQI,
12514 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12515 int imm = inst.operands[2].imm;
12516 /* This gets the bounds check, size encoding and immediate bits calculation
12517 right. */
12518 et.size /= 2;
12519
12520 /* If immediate is zero then we are a pseudo-instruction for
12521 VMOVN.I<size> <Dd>, <Qm> */
12522 if (imm == 0)
12523 {
12524 inst.operands[2].present = 0;
12525 inst.instruction = N_MNEM_vmovn;
12526 do_neon_movn ();
12527 return;
12528 }
12529
12530 constraint (imm < 1 || (unsigned)imm > et.size,
12531 _("immediate out of range for narrowing operation"));
12532 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
12533 }
12534
12535 static void
12536 do_neon_shll (void)
12537 {
12538 /* FIXME: Type checking when lengthening. */
12539 struct neon_type_el et = neon_check_type (2, NS_QDI,
12540 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
12541 unsigned imm = inst.operands[2].imm;
12542
12543 if (imm == et.size)
12544 {
12545 /* Maximum shift variant. */
12546 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12547 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12548 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12549 inst.instruction |= LOW4 (inst.operands[1].reg);
12550 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12551 inst.instruction |= neon_logbits (et.size) << 18;
12552
12553 inst.instruction = neon_dp_fixup (inst.instruction);
12554 }
12555 else
12556 {
12557 /* A more-specific type check for non-max versions. */
12558 et = neon_check_type (2, NS_QDI,
12559 N_EQK | N_DBL, N_SU_32 | N_KEY);
12560 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12561 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
12562 }
12563 }
12564
12565 /* Check the various types for the VCVT instruction, and return which version
12566 the current instruction is. */
12567
12568 static int
12569 neon_cvt_flavour (enum neon_shape rs)
12570 {
12571 #define CVT_VAR(C,X,Y) \
12572 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
12573 if (et.type != NT_invtype) \
12574 { \
12575 inst.error = NULL; \
12576 return (C); \
12577 }
12578 struct neon_type_el et;
12579 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
12580 || rs == NS_FF) ? N_VFP : 0;
12581 /* The instruction versions which take an immediate take one register
12582 argument, which is extended to the width of the full register. Thus the
12583 "source" and "destination" registers must have the same width. Hack that
12584 here by making the size equal to the key (wider, in this case) operand. */
12585 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
12586
12587 CVT_VAR (0, N_S32, N_F32);
12588 CVT_VAR (1, N_U32, N_F32);
12589 CVT_VAR (2, N_F32, N_S32);
12590 CVT_VAR (3, N_F32, N_U32);
12591
12592 whole_reg = N_VFP;
12593
12594 /* VFP instructions. */
12595 CVT_VAR (4, N_F32, N_F64);
12596 CVT_VAR (5, N_F64, N_F32);
12597 CVT_VAR (6, N_S32, N_F64 | key);
12598 CVT_VAR (7, N_U32, N_F64 | key);
12599 CVT_VAR (8, N_F64 | key, N_S32);
12600 CVT_VAR (9, N_F64 | key, N_U32);
12601 /* VFP instructions with bitshift. */
12602 CVT_VAR (10, N_F32 | key, N_S16);
12603 CVT_VAR (11, N_F32 | key, N_U16);
12604 CVT_VAR (12, N_F64 | key, N_S16);
12605 CVT_VAR (13, N_F64 | key, N_U16);
12606 CVT_VAR (14, N_S16, N_F32 | key);
12607 CVT_VAR (15, N_U16, N_F32 | key);
12608 CVT_VAR (16, N_S16, N_F64 | key);
12609 CVT_VAR (17, N_U16, N_F64 | key);
12610
12611 return -1;
12612 #undef CVT_VAR
12613 }
12614
12615 /* Neon-syntax VFP conversions. */
12616
12617 static void
12618 do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
12619 {
12620 const char *opname = 0;
12621
12622 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
12623 {
12624 /* Conversions with immediate bitshift. */
12625 const char *enc[] =
12626 {
12627 "ftosls",
12628 "ftouls",
12629 "fsltos",
12630 "fultos",
12631 NULL,
12632 NULL,
12633 "ftosld",
12634 "ftould",
12635 "fsltod",
12636 "fultod",
12637 "fshtos",
12638 "fuhtos",
12639 "fshtod",
12640 "fuhtod",
12641 "ftoshs",
12642 "ftouhs",
12643 "ftoshd",
12644 "ftouhd"
12645 };
12646
12647 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12648 {
12649 opname = enc[flavour];
12650 constraint (inst.operands[0].reg != inst.operands[1].reg,
12651 _("operands 0 and 1 must be the same register"));
12652 inst.operands[1] = inst.operands[2];
12653 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
12654 }
12655 }
12656 else
12657 {
12658 /* Conversions without bitshift. */
12659 const char *enc[] =
12660 {
12661 "ftosis",
12662 "ftouis",
12663 "fsitos",
12664 "fuitos",
12665 "fcvtsd",
12666 "fcvtds",
12667 "ftosid",
12668 "ftouid",
12669 "fsitod",
12670 "fuitod"
12671 };
12672
12673 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12674 opname = enc[flavour];
12675 }
12676
12677 if (opname)
12678 do_vfp_nsyn_opcode (opname);
12679 }
12680
12681 static void
12682 do_vfp_nsyn_cvtz (void)
12683 {
12684 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
12685 int flavour = neon_cvt_flavour (rs);
12686 const char *enc[] =
12687 {
12688 "ftosizs",
12689 "ftouizs",
12690 NULL,
12691 NULL,
12692 NULL,
12693 NULL,
12694 "ftosizd",
12695 "ftouizd"
12696 };
12697
12698 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
12699 do_vfp_nsyn_opcode (enc[flavour]);
12700 }
12701
12702 static void
12703 do_neon_cvt (void)
12704 {
12705 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
12706 NS_FD, NS_DF, NS_FF, NS_NULL);
12707 int flavour = neon_cvt_flavour (rs);
12708
12709 /* VFP rather than Neon conversions. */
12710 if (flavour >= 4)
12711 {
12712 do_vfp_nsyn_cvt (rs, flavour);
12713 return;
12714 }
12715
12716 switch (rs)
12717 {
12718 case NS_DDI:
12719 case NS_QQI:
12720 {
12721 unsigned immbits;
12722 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
12723
12724 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12725 return;
12726
12727 /* Fixed-point conversion with #0 immediate is encoded as an
12728 integer conversion. */
12729 if (inst.operands[2].present && inst.operands[2].imm == 0)
12730 goto int_encode;
12731 immbits = 32 - inst.operands[2].imm;
12732 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12733 if (flavour != -1)
12734 inst.instruction |= enctab[flavour];
12735 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12736 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12737 inst.instruction |= LOW4 (inst.operands[1].reg);
12738 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12739 inst.instruction |= neon_quad (rs) << 6;
12740 inst.instruction |= 1 << 21;
12741 inst.instruction |= immbits << 16;
12742
12743 inst.instruction = neon_dp_fixup (inst.instruction);
12744 }
12745 break;
12746
12747 case NS_DD:
12748 case NS_QQ:
12749 int_encode:
12750 {
12751 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
12752
12753 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12754
12755 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12756 return;
12757
12758 if (flavour != -1)
12759 inst.instruction |= enctab[flavour];
12760
12761 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12762 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12763 inst.instruction |= LOW4 (inst.operands[1].reg);
12764 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12765 inst.instruction |= neon_quad (rs) << 6;
12766 inst.instruction |= 2 << 18;
12767
12768 inst.instruction = neon_dp_fixup (inst.instruction);
12769 }
12770 break;
12771
12772 default:
12773 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
12774 do_vfp_nsyn_cvt (rs, flavour);
12775 }
12776 }
12777
12778 static void
12779 neon_move_immediate (void)
12780 {
12781 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
12782 struct neon_type_el et = neon_check_type (2, rs,
12783 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
12784 unsigned immlo, immhi = 0, immbits;
12785 int op, cmode, float_p;
12786
12787 constraint (et.type == NT_invtype,
12788 _("operand size must be specified for immediate VMOV"));
12789
12790 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
12791 op = (inst.instruction & (1 << 5)) != 0;
12792
12793 immlo = inst.operands[1].imm;
12794 if (inst.operands[1].regisimm)
12795 immhi = inst.operands[1].reg;
12796
12797 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
12798 _("immediate has bits set outside the operand size"));
12799
12800 float_p = inst.operands[1].immisfloat;
12801
12802 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
12803 et.size, et.type)) == FAIL)
12804 {
12805 /* Invert relevant bits only. */
12806 neon_invert_size (&immlo, &immhi, et.size);
12807 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
12808 with one or the other; those cases are caught by
12809 neon_cmode_for_move_imm. */
12810 op = !op;
12811 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
12812 &op, et.size, et.type)) == FAIL)
12813 {
12814 first_error (_("immediate out of range"));
12815 return;
12816 }
12817 }
12818
12819 inst.instruction &= ~(1 << 5);
12820 inst.instruction |= op << 5;
12821
12822 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12823 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12824 inst.instruction |= neon_quad (rs) << 6;
12825 inst.instruction |= cmode << 8;
12826
12827 neon_write_immbits (immbits);
12828 }
12829
12830 static void
12831 do_neon_mvn (void)
12832 {
12833 if (inst.operands[1].isreg)
12834 {
12835 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12836
12837 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12838 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12839 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12840 inst.instruction |= LOW4 (inst.operands[1].reg);
12841 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12842 inst.instruction |= neon_quad (rs) << 6;
12843 }
12844 else
12845 {
12846 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12847 neon_move_immediate ();
12848 }
12849
12850 inst.instruction = neon_dp_fixup (inst.instruction);
12851 }
12852
12853 /* Encode instructions of form:
12854
12855 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12856 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
12857
12858 static void
12859 neon_mixed_length (struct neon_type_el et, unsigned size)
12860 {
12861 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12862 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12863 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12864 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12865 inst.instruction |= LOW4 (inst.operands[2].reg);
12866 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12867 inst.instruction |= (et.type == NT_unsigned) << 24;
12868 inst.instruction |= neon_logbits (size) << 20;
12869
12870 inst.instruction = neon_dp_fixup (inst.instruction);
12871 }
12872
12873 static void
12874 do_neon_dyadic_long (void)
12875 {
12876 /* FIXME: Type checking for lengthening op. */
12877 struct neon_type_el et = neon_check_type (3, NS_QDD,
12878 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
12879 neon_mixed_length (et, et.size);
12880 }
12881
12882 static void
12883 do_neon_abal (void)
12884 {
12885 struct neon_type_el et = neon_check_type (3, NS_QDD,
12886 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
12887 neon_mixed_length (et, et.size);
12888 }
12889
12890 static void
12891 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
12892 {
12893 if (inst.operands[2].isscalar)
12894 {
12895 struct neon_type_el et = neon_check_type (3, NS_QDS,
12896 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
12897 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12898 neon_mul_mac (et, et.type == NT_unsigned);
12899 }
12900 else
12901 {
12902 struct neon_type_el et = neon_check_type (3, NS_QDD,
12903 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
12904 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12905 neon_mixed_length (et, et.size);
12906 }
12907 }
12908
12909 static void
12910 do_neon_mac_maybe_scalar_long (void)
12911 {
12912 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
12913 }
12914
12915 static void
12916 do_neon_dyadic_wide (void)
12917 {
12918 struct neon_type_el et = neon_check_type (3, NS_QQD,
12919 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
12920 neon_mixed_length (et, et.size);
12921 }
12922
12923 static void
12924 do_neon_dyadic_narrow (void)
12925 {
12926 struct neon_type_el et = neon_check_type (3, NS_QDD,
12927 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
12928 /* Operand sign is unimportant, and the U bit is part of the opcode,
12929 so force the operand type to integer. */
12930 et.type = NT_integer;
12931 neon_mixed_length (et, et.size / 2);
12932 }
12933
12934 static void
12935 do_neon_mul_sat_scalar_long (void)
12936 {
12937 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
12938 }
12939
12940 static void
12941 do_neon_vmull (void)
12942 {
12943 if (inst.operands[2].isscalar)
12944 do_neon_mac_maybe_scalar_long ();
12945 else
12946 {
12947 struct neon_type_el et = neon_check_type (3, NS_QDD,
12948 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
12949 if (et.type == NT_poly)
12950 inst.instruction = NEON_ENC_POLY (inst.instruction);
12951 else
12952 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12953 /* For polynomial encoding, size field must be 0b00 and the U bit must be
12954 zero. Should be OK as-is. */
12955 neon_mixed_length (et, et.size);
12956 }
12957 }
12958
12959 static void
12960 do_neon_ext (void)
12961 {
12962 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
12963 struct neon_type_el et = neon_check_type (3, rs,
12964 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12965 unsigned imm = (inst.operands[3].imm * et.size) / 8;
12966
12967 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
12968 _("shift out of range"));
12969 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12970 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12971 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12972 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12973 inst.instruction |= LOW4 (inst.operands[2].reg);
12974 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12975 inst.instruction |= neon_quad (rs) << 6;
12976 inst.instruction |= imm << 8;
12977
12978 inst.instruction = neon_dp_fixup (inst.instruction);
12979 }
12980
12981 static void
12982 do_neon_rev (void)
12983 {
12984 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12985 struct neon_type_el et = neon_check_type (2, rs,
12986 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12987 unsigned op = (inst.instruction >> 7) & 3;
12988 /* N (width of reversed regions) is encoded as part of the bitmask. We
12989 extract it here to check the elements to be reversed are smaller.
12990 Otherwise we'd get a reserved instruction. */
12991 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
12992 assert (elsize != 0);
12993 constraint (et.size >= elsize,
12994 _("elements must be smaller than reversal region"));
12995 neon_two_same (neon_quad (rs), 1, et.size);
12996 }
12997
12998 static void
12999 do_neon_dup (void)
13000 {
13001 if (inst.operands[1].isscalar)
13002 {
13003 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
13004 struct neon_type_el et = neon_check_type (2, rs,
13005 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13006 unsigned sizebits = et.size >> 3;
13007 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
13008 int logsize = neon_logbits (et.size);
13009 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
13010
13011 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
13012 return;
13013
13014 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13015 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13016 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13017 inst.instruction |= LOW4 (dm);
13018 inst.instruction |= HI1 (dm) << 5;
13019 inst.instruction |= neon_quad (rs) << 6;
13020 inst.instruction |= x << 17;
13021 inst.instruction |= sizebits << 16;
13022
13023 inst.instruction = neon_dp_fixup (inst.instruction);
13024 }
13025 else
13026 {
13027 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
13028 struct neon_type_el et = neon_check_type (2, rs,
13029 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13030 /* Duplicate ARM register to lanes of vector. */
13031 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
13032 switch (et.size)
13033 {
13034 case 8: inst.instruction |= 0x400000; break;
13035 case 16: inst.instruction |= 0x000020; break;
13036 case 32: inst.instruction |= 0x000000; break;
13037 default: break;
13038 }
13039 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13040 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
13041 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
13042 inst.instruction |= neon_quad (rs) << 21;
13043 /* The encoding for this instruction is identical for the ARM and Thumb
13044 variants, except for the condition field. */
13045 do_vfp_cond_or_thumb ();
13046 }
13047 }
13048
13049 /* VMOV has particularly many variations. It can be one of:
13050 0. VMOV<c><q> <Qd>, <Qm>
13051 1. VMOV<c><q> <Dd>, <Dm>
13052 (Register operations, which are VORR with Rm = Rn.)
13053 2. VMOV<c><q>.<dt> <Qd>, #<imm>
13054 3. VMOV<c><q>.<dt> <Dd>, #<imm>
13055 (Immediate loads.)
13056 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
13057 (ARM register to scalar.)
13058 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
13059 (Two ARM registers to vector.)
13060 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
13061 (Scalar to ARM register.)
13062 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
13063 (Vector to two ARM registers.)
13064 8. VMOV.F32 <Sd>, <Sm>
13065 9. VMOV.F64 <Dd>, <Dm>
13066 (VFP register moves.)
13067 10. VMOV.F32 <Sd>, #imm
13068 11. VMOV.F64 <Dd>, #imm
13069 (VFP float immediate load.)
13070 12. VMOV <Rd>, <Sm>
13071 (VFP single to ARM reg.)
13072 13. VMOV <Sd>, <Rm>
13073 (ARM reg to VFP single.)
13074 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
13075 (Two ARM regs to two VFP singles.)
13076 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
13077 (Two VFP singles to two ARM regs.)
13078
13079 These cases can be disambiguated using neon_select_shape, except cases 1/9
13080 and 3/11 which depend on the operand type too.
13081
13082 All the encoded bits are hardcoded by this function.
13083
13084 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
13085 Cases 5, 7 may be used with VFPv2 and above.
13086
13087 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
13088 can specify a type where it doesn't make sense to, and is ignored). */
13089
13090 static void
13091 do_neon_mov (void)
13092 {
13093 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
13094 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
13095 NS_NULL);
13096 struct neon_type_el et;
13097 const char *ldconst = 0;
13098
13099 switch (rs)
13100 {
13101 case NS_DD: /* case 1/9. */
13102 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13103 /* It is not an error here if no type is given. */
13104 inst.error = NULL;
13105 if (et.type == NT_float && et.size == 64)
13106 {
13107 do_vfp_nsyn_opcode ("fcpyd");
13108 break;
13109 }
13110 /* fall through. */
13111
13112 case NS_QQ: /* case 0/1. */
13113 {
13114 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13115 return;
13116 /* The architecture manual I have doesn't explicitly state which
13117 value the U bit should have for register->register moves, but
13118 the equivalent VORR instruction has U = 0, so do that. */
13119 inst.instruction = 0x0200110;
13120 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13121 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13122 inst.instruction |= LOW4 (inst.operands[1].reg);
13123 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13124 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13125 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13126 inst.instruction |= neon_quad (rs) << 6;
13127
13128 inst.instruction = neon_dp_fixup (inst.instruction);
13129 }
13130 break;
13131
13132 case NS_DI: /* case 3/11. */
13133 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13134 inst.error = NULL;
13135 if (et.type == NT_float && et.size == 64)
13136 {
13137 /* case 11 (fconstd). */
13138 ldconst = "fconstd";
13139 goto encode_fconstd;
13140 }
13141 /* fall through. */
13142
13143 case NS_QI: /* case 2/3. */
13144 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13145 return;
13146 inst.instruction = 0x0800010;
13147 neon_move_immediate ();
13148 inst.instruction = neon_dp_fixup (inst.instruction);
13149 break;
13150
13151 case NS_SR: /* case 4. */
13152 {
13153 unsigned bcdebits = 0;
13154 struct neon_type_el et = neon_check_type (2, NS_NULL,
13155 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13156 int logsize = neon_logbits (et.size);
13157 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
13158 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
13159
13160 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13161 _(BAD_FPU));
13162 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13163 && et.size != 32, _(BAD_FPU));
13164 constraint (et.type == NT_invtype, _("bad type for scalar"));
13165 constraint (x >= 64 / et.size, _("scalar index out of range"));
13166
13167 switch (et.size)
13168 {
13169 case 8: bcdebits = 0x8; break;
13170 case 16: bcdebits = 0x1; break;
13171 case 32: bcdebits = 0x0; break;
13172 default: ;
13173 }
13174
13175 bcdebits |= x << logsize;
13176
13177 inst.instruction = 0xe000b10;
13178 do_vfp_cond_or_thumb ();
13179 inst.instruction |= LOW4 (dn) << 16;
13180 inst.instruction |= HI1 (dn) << 7;
13181 inst.instruction |= inst.operands[1].reg << 12;
13182 inst.instruction |= (bcdebits & 3) << 5;
13183 inst.instruction |= (bcdebits >> 2) << 21;
13184 }
13185 break;
13186
13187 case NS_DRR: /* case 5 (fmdrr). */
13188 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13189 _(BAD_FPU));
13190
13191 inst.instruction = 0xc400b10;
13192 do_vfp_cond_or_thumb ();
13193 inst.instruction |= LOW4 (inst.operands[0].reg);
13194 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
13195 inst.instruction |= inst.operands[1].reg << 12;
13196 inst.instruction |= inst.operands[2].reg << 16;
13197 break;
13198
13199 case NS_RS: /* case 6. */
13200 {
13201 struct neon_type_el et = neon_check_type (2, NS_NULL,
13202 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
13203 unsigned logsize = neon_logbits (et.size);
13204 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
13205 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
13206 unsigned abcdebits = 0;
13207
13208 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13209 _(BAD_FPU));
13210 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13211 && et.size != 32, _(BAD_FPU));
13212 constraint (et.type == NT_invtype, _("bad type for scalar"));
13213 constraint (x >= 64 / et.size, _("scalar index out of range"));
13214
13215 switch (et.size)
13216 {
13217 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
13218 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
13219 case 32: abcdebits = 0x00; break;
13220 default: ;
13221 }
13222
13223 abcdebits |= x << logsize;
13224 inst.instruction = 0xe100b10;
13225 do_vfp_cond_or_thumb ();
13226 inst.instruction |= LOW4 (dn) << 16;
13227 inst.instruction |= HI1 (dn) << 7;
13228 inst.instruction |= inst.operands[0].reg << 12;
13229 inst.instruction |= (abcdebits & 3) << 5;
13230 inst.instruction |= (abcdebits >> 2) << 21;
13231 }
13232 break;
13233
13234 case NS_RRD: /* case 7 (fmrrd). */
13235 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13236 _(BAD_FPU));
13237
13238 inst.instruction = 0xc500b10;
13239 do_vfp_cond_or_thumb ();
13240 inst.instruction |= inst.operands[0].reg << 12;
13241 inst.instruction |= inst.operands[1].reg << 16;
13242 inst.instruction |= LOW4 (inst.operands[2].reg);
13243 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13244 break;
13245
13246 case NS_FF: /* case 8 (fcpys). */
13247 do_vfp_nsyn_opcode ("fcpys");
13248 break;
13249
13250 case NS_FI: /* case 10 (fconsts). */
13251 ldconst = "fconsts";
13252 encode_fconstd:
13253 if (is_quarter_float (inst.operands[1].imm))
13254 {
13255 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
13256 do_vfp_nsyn_opcode (ldconst);
13257 }
13258 else
13259 first_error (_("immediate out of range"));
13260 break;
13261
13262 case NS_RF: /* case 12 (fmrs). */
13263 do_vfp_nsyn_opcode ("fmrs");
13264 break;
13265
13266 case NS_FR: /* case 13 (fmsr). */
13267 do_vfp_nsyn_opcode ("fmsr");
13268 break;
13269
13270 /* The encoders for the fmrrs and fmsrr instructions expect three operands
13271 (one of which is a list), but we have parsed four. Do some fiddling to
13272 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
13273 expect. */
13274 case NS_RRFF: /* case 14 (fmrrs). */
13275 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
13276 _("VFP registers must be adjacent"));
13277 inst.operands[2].imm = 2;
13278 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13279 do_vfp_nsyn_opcode ("fmrrs");
13280 break;
13281
13282 case NS_FFRR: /* case 15 (fmsrr). */
13283 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
13284 _("VFP registers must be adjacent"));
13285 inst.operands[1] = inst.operands[2];
13286 inst.operands[2] = inst.operands[3];
13287 inst.operands[0].imm = 2;
13288 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13289 do_vfp_nsyn_opcode ("fmsrr");
13290 break;
13291
13292 default:
13293 abort ();
13294 }
13295 }
13296
13297 static void
13298 do_neon_rshift_round_imm (void)
13299 {
13300 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13301 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
13302 int imm = inst.operands[2].imm;
13303
13304 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
13305 if (imm == 0)
13306 {
13307 inst.operands[2].present = 0;
13308 do_neon_mov ();
13309 return;
13310 }
13311
13312 constraint (imm < 1 || (unsigned)imm > et.size,
13313 _("immediate out of range for shift"));
13314 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
13315 et.size - imm);
13316 }
13317
13318 static void
13319 do_neon_movl (void)
13320 {
13321 struct neon_type_el et = neon_check_type (2, NS_QD,
13322 N_EQK | N_DBL, N_SU_32 | N_KEY);
13323 unsigned sizebits = et.size >> 3;
13324 inst.instruction |= sizebits << 19;
13325 neon_two_same (0, et.type == NT_unsigned, -1);
13326 }
13327
13328 static void
13329 do_neon_trn (void)
13330 {
13331 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13332 struct neon_type_el et = neon_check_type (2, rs,
13333 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13334 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13335 neon_two_same (neon_quad (rs), 1, et.size);
13336 }
13337
13338 static void
13339 do_neon_zip_uzp (void)
13340 {
13341 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13342 struct neon_type_el et = neon_check_type (2, rs,
13343 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13344 if (rs == NS_DD && et.size == 32)
13345 {
13346 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
13347 inst.instruction = N_MNEM_vtrn;
13348 do_neon_trn ();
13349 return;
13350 }
13351 neon_two_same (neon_quad (rs), 1, et.size);
13352 }
13353
13354 static void
13355 do_neon_sat_abs_neg (void)
13356 {
13357 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13358 struct neon_type_el et = neon_check_type (2, rs,
13359 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
13360 neon_two_same (neon_quad (rs), 1, et.size);
13361 }
13362
13363 static void
13364 do_neon_pair_long (void)
13365 {
13366 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13367 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
13368 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
13369 inst.instruction |= (et.type == NT_unsigned) << 7;
13370 neon_two_same (neon_quad (rs), 1, et.size);
13371 }
13372
13373 static void
13374 do_neon_recip_est (void)
13375 {
13376 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13377 struct neon_type_el et = neon_check_type (2, rs,
13378 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
13379 inst.instruction |= (et.type == NT_float) << 8;
13380 neon_two_same (neon_quad (rs), 1, et.size);
13381 }
13382
13383 static void
13384 do_neon_cls (void)
13385 {
13386 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13387 struct neon_type_el et = neon_check_type (2, rs,
13388 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
13389 neon_two_same (neon_quad (rs), 1, et.size);
13390 }
13391
13392 static void
13393 do_neon_clz (void)
13394 {
13395 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13396 struct neon_type_el et = neon_check_type (2, rs,
13397 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
13398 neon_two_same (neon_quad (rs), 1, et.size);
13399 }
13400
13401 static void
13402 do_neon_cnt (void)
13403 {
13404 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13405 struct neon_type_el et = neon_check_type (2, rs,
13406 N_EQK | N_INT, N_8 | N_KEY);
13407 neon_two_same (neon_quad (rs), 1, et.size);
13408 }
13409
13410 static void
13411 do_neon_swp (void)
13412 {
13413 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13414 neon_two_same (neon_quad (rs), 1, -1);
13415 }
13416
13417 static void
13418 do_neon_tbl_tbx (void)
13419 {
13420 unsigned listlenbits;
13421 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
13422
13423 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
13424 {
13425 first_error (_("bad list length for table lookup"));
13426 return;
13427 }
13428
13429 listlenbits = inst.operands[1].imm - 1;
13430 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13431 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13432 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13433 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13434 inst.instruction |= LOW4 (inst.operands[2].reg);
13435 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13436 inst.instruction |= listlenbits << 8;
13437
13438 inst.instruction = neon_dp_fixup (inst.instruction);
13439 }
13440
13441 static void
13442 do_neon_ldm_stm (void)
13443 {
13444 /* P, U and L bits are part of bitmask. */
13445 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
13446 unsigned offsetbits = inst.operands[1].imm * 2;
13447
13448 if (inst.operands[1].issingle)
13449 {
13450 do_vfp_nsyn_ldm_stm (is_dbmode);
13451 return;
13452 }
13453
13454 constraint (is_dbmode && !inst.operands[0].writeback,
13455 _("writeback (!) must be used for VLDMDB and VSTMDB"));
13456
13457 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
13458 _("register list must contain at least 1 and at most 16 "
13459 "registers"));
13460
13461 inst.instruction |= inst.operands[0].reg << 16;
13462 inst.instruction |= inst.operands[0].writeback << 21;
13463 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13464 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
13465
13466 inst.instruction |= offsetbits;
13467
13468 do_vfp_cond_or_thumb ();
13469 }
13470
13471 static void
13472 do_neon_ldr_str (void)
13473 {
13474 int is_ldr = (inst.instruction & (1 << 20)) != 0;
13475
13476 if (inst.operands[0].issingle)
13477 {
13478 if (is_ldr)
13479 do_vfp_nsyn_opcode ("flds");
13480 else
13481 do_vfp_nsyn_opcode ("fsts");
13482 }
13483 else
13484 {
13485 if (is_ldr)
13486 do_vfp_nsyn_opcode ("fldd");
13487 else
13488 do_vfp_nsyn_opcode ("fstd");
13489 }
13490 }
13491
13492 /* "interleave" version also handles non-interleaving register VLD1/VST1
13493 instructions. */
13494
13495 static void
13496 do_neon_ld_st_interleave (void)
13497 {
13498 struct neon_type_el et = neon_check_type (1, NS_NULL,
13499 N_8 | N_16 | N_32 | N_64);
13500 unsigned alignbits = 0;
13501 unsigned idx;
13502 /* The bits in this table go:
13503 0: register stride of one (0) or two (1)
13504 1,2: register list length, minus one (1, 2, 3, 4).
13505 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
13506 We use -1 for invalid entries. */
13507 const int typetable[] =
13508 {
13509 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
13510 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
13511 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
13512 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
13513 };
13514 int typebits;
13515
13516 if (et.type == NT_invtype)
13517 return;
13518
13519 if (inst.operands[1].immisalign)
13520 switch (inst.operands[1].imm >> 8)
13521 {
13522 case 64: alignbits = 1; break;
13523 case 128:
13524 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13525 goto bad_alignment;
13526 alignbits = 2;
13527 break;
13528 case 256:
13529 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13530 goto bad_alignment;
13531 alignbits = 3;
13532 break;
13533 default:
13534 bad_alignment:
13535 first_error (_("bad alignment"));
13536 return;
13537 }
13538
13539 inst.instruction |= alignbits << 4;
13540 inst.instruction |= neon_logbits (et.size) << 6;
13541
13542 /* Bits [4:6] of the immediate in a list specifier encode register stride
13543 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
13544 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
13545 up the right value for "type" in a table based on this value and the given
13546 list style, then stick it back. */
13547 idx = ((inst.operands[0].imm >> 4) & 7)
13548 | (((inst.instruction >> 8) & 3) << 3);
13549
13550 typebits = typetable[idx];
13551
13552 constraint (typebits == -1, _("bad list type for instruction"));
13553
13554 inst.instruction &= ~0xf00;
13555 inst.instruction |= typebits << 8;
13556 }
13557
13558 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
13559 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
13560 otherwise. The variable arguments are a list of pairs of legal (size, align)
13561 values, terminated with -1. */
13562
13563 static int
13564 neon_alignment_bit (int size, int align, int *do_align, ...)
13565 {
13566 va_list ap;
13567 int result = FAIL, thissize, thisalign;
13568
13569 if (!inst.operands[1].immisalign)
13570 {
13571 *do_align = 0;
13572 return SUCCESS;
13573 }
13574
13575 va_start (ap, do_align);
13576
13577 do
13578 {
13579 thissize = va_arg (ap, int);
13580 if (thissize == -1)
13581 break;
13582 thisalign = va_arg (ap, int);
13583
13584 if (size == thissize && align == thisalign)
13585 result = SUCCESS;
13586 }
13587 while (result != SUCCESS);
13588
13589 va_end (ap);
13590
13591 if (result == SUCCESS)
13592 *do_align = 1;
13593 else
13594 first_error (_("unsupported alignment for instruction"));
13595
13596 return result;
13597 }
13598
13599 static void
13600 do_neon_ld_st_lane (void)
13601 {
13602 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
13603 int align_good, do_align = 0;
13604 int logsize = neon_logbits (et.size);
13605 int align = inst.operands[1].imm >> 8;
13606 int n = (inst.instruction >> 8) & 3;
13607 int max_el = 64 / et.size;
13608
13609 if (et.type == NT_invtype)
13610 return;
13611
13612 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
13613 _("bad list length"));
13614 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
13615 _("scalar index out of range"));
13616 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
13617 && et.size == 8,
13618 _("stride of 2 unavailable when element size is 8"));
13619
13620 switch (n)
13621 {
13622 case 0: /* VLD1 / VST1. */
13623 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
13624 32, 32, -1);
13625 if (align_good == FAIL)
13626 return;
13627 if (do_align)
13628 {
13629 unsigned alignbits = 0;
13630 switch (et.size)
13631 {
13632 case 16: alignbits = 0x1; break;
13633 case 32: alignbits = 0x3; break;
13634 default: ;
13635 }
13636 inst.instruction |= alignbits << 4;
13637 }
13638 break;
13639
13640 case 1: /* VLD2 / VST2. */
13641 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
13642 32, 64, -1);
13643 if (align_good == FAIL)
13644 return;
13645 if (do_align)
13646 inst.instruction |= 1 << 4;
13647 break;
13648
13649 case 2: /* VLD3 / VST3. */
13650 constraint (inst.operands[1].immisalign,
13651 _("can't use alignment with this instruction"));
13652 break;
13653
13654 case 3: /* VLD4 / VST4. */
13655 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13656 16, 64, 32, 64, 32, 128, -1);
13657 if (align_good == FAIL)
13658 return;
13659 if (do_align)
13660 {
13661 unsigned alignbits = 0;
13662 switch (et.size)
13663 {
13664 case 8: alignbits = 0x1; break;
13665 case 16: alignbits = 0x1; break;
13666 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
13667 default: ;
13668 }
13669 inst.instruction |= alignbits << 4;
13670 }
13671 break;
13672
13673 default: ;
13674 }
13675
13676 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
13677 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13678 inst.instruction |= 1 << (4 + logsize);
13679
13680 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
13681 inst.instruction |= logsize << 10;
13682 }
13683
13684 /* Encode single n-element structure to all lanes VLD<n> instructions. */
13685
13686 static void
13687 do_neon_ld_dup (void)
13688 {
13689 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
13690 int align_good, do_align = 0;
13691
13692 if (et.type == NT_invtype)
13693 return;
13694
13695 switch ((inst.instruction >> 8) & 3)
13696 {
13697 case 0: /* VLD1. */
13698 assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
13699 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13700 &do_align, 16, 16, 32, 32, -1);
13701 if (align_good == FAIL)
13702 return;
13703 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
13704 {
13705 case 1: break;
13706 case 2: inst.instruction |= 1 << 5; break;
13707 default: first_error (_("bad list length")); return;
13708 }
13709 inst.instruction |= neon_logbits (et.size) << 6;
13710 break;
13711
13712 case 1: /* VLD2. */
13713 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13714 &do_align, 8, 16, 16, 32, 32, 64, -1);
13715 if (align_good == FAIL)
13716 return;
13717 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
13718 _("bad list length"));
13719 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13720 inst.instruction |= 1 << 5;
13721 inst.instruction |= neon_logbits (et.size) << 6;
13722 break;
13723
13724 case 2: /* VLD3. */
13725 constraint (inst.operands[1].immisalign,
13726 _("can't use alignment with this instruction"));
13727 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
13728 _("bad list length"));
13729 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13730 inst.instruction |= 1 << 5;
13731 inst.instruction |= neon_logbits (et.size) << 6;
13732 break;
13733
13734 case 3: /* VLD4. */
13735 {
13736 int align = inst.operands[1].imm >> 8;
13737 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13738 16, 64, 32, 64, 32, 128, -1);
13739 if (align_good == FAIL)
13740 return;
13741 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
13742 _("bad list length"));
13743 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13744 inst.instruction |= 1 << 5;
13745 if (et.size == 32 && align == 128)
13746 inst.instruction |= 0x3 << 6;
13747 else
13748 inst.instruction |= neon_logbits (et.size) << 6;
13749 }
13750 break;
13751
13752 default: ;
13753 }
13754
13755 inst.instruction |= do_align << 4;
13756 }
13757
13758 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
13759 apart from bits [11:4]. */
13760
13761 static void
13762 do_neon_ldx_stx (void)
13763 {
13764 switch (NEON_LANE (inst.operands[0].imm))
13765 {
13766 case NEON_INTERLEAVE_LANES:
13767 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
13768 do_neon_ld_st_interleave ();
13769 break;
13770
13771 case NEON_ALL_LANES:
13772 inst.instruction = NEON_ENC_DUP (inst.instruction);
13773 do_neon_ld_dup ();
13774 break;
13775
13776 default:
13777 inst.instruction = NEON_ENC_LANE (inst.instruction);
13778 do_neon_ld_st_lane ();
13779 }
13780
13781 /* L bit comes from bit mask. */
13782 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13783 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13784 inst.instruction |= inst.operands[1].reg << 16;
13785
13786 if (inst.operands[1].postind)
13787 {
13788 int postreg = inst.operands[1].imm & 0xf;
13789 constraint (!inst.operands[1].immisreg,
13790 _("post-index must be a register"));
13791 constraint (postreg == 0xd || postreg == 0xf,
13792 _("bad register for post-index"));
13793 inst.instruction |= postreg;
13794 }
13795 else if (inst.operands[1].writeback)
13796 {
13797 inst.instruction |= 0xd;
13798 }
13799 else
13800 inst.instruction |= 0xf;
13801
13802 if (thumb_mode)
13803 inst.instruction |= 0xf9000000;
13804 else
13805 inst.instruction |= 0xf4000000;
13806 }
13807 \f
13808 /* Overall per-instruction processing. */
13809
13810 /* We need to be able to fix up arbitrary expressions in some statements.
13811 This is so that we can handle symbols that are an arbitrary distance from
13812 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
13813 which returns part of an address in a form which will be valid for
13814 a data instruction. We do this by pushing the expression into a symbol
13815 in the expr_section, and creating a fix for that. */
13816
13817 static void
13818 fix_new_arm (fragS * frag,
13819 int where,
13820 short int size,
13821 expressionS * exp,
13822 int pc_rel,
13823 int reloc)
13824 {
13825 fixS * new_fix;
13826
13827 switch (exp->X_op)
13828 {
13829 case O_constant:
13830 case O_symbol:
13831 case O_add:
13832 case O_subtract:
13833 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
13834 break;
13835
13836 default:
13837 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
13838 pc_rel, reloc);
13839 break;
13840 }
13841
13842 /* Mark whether the fix is to a THUMB instruction, or an ARM
13843 instruction. */
13844 new_fix->tc_fix_data = thumb_mode;
13845 }
13846
13847 /* Create a frg for an instruction requiring relaxation. */
13848 static void
13849 output_relax_insn (void)
13850 {
13851 char * to;
13852 symbolS *sym;
13853 int offset;
13854
13855 /* The size of the instruction is unknown, so tie the debug info to the
13856 start of the instruction. */
13857 dwarf2_emit_insn (0);
13858
13859 switch (inst.reloc.exp.X_op)
13860 {
13861 case O_symbol:
13862 sym = inst.reloc.exp.X_add_symbol;
13863 offset = inst.reloc.exp.X_add_number;
13864 break;
13865 case O_constant:
13866 sym = NULL;
13867 offset = inst.reloc.exp.X_add_number;
13868 break;
13869 default:
13870 sym = make_expr_symbol (&inst.reloc.exp);
13871 offset = 0;
13872 break;
13873 }
13874 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
13875 inst.relax, sym, offset, NULL/*offset, opcode*/);
13876 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
13877 }
13878
13879 /* Write a 32-bit thumb instruction to buf. */
13880 static void
13881 put_thumb32_insn (char * buf, unsigned long insn)
13882 {
13883 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
13884 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
13885 }
13886
13887 static void
13888 output_inst (const char * str)
13889 {
13890 char * to = NULL;
13891
13892 if (inst.error)
13893 {
13894 as_bad ("%s -- `%s'", inst.error, str);
13895 return;
13896 }
13897 if (inst.relax)
13898 {
13899 output_relax_insn ();
13900 return;
13901 }
13902 if (inst.size == 0)
13903 return;
13904
13905 to = frag_more (inst.size);
13906
13907 if (thumb_mode && (inst.size > THUMB_SIZE))
13908 {
13909 assert (inst.size == (2 * THUMB_SIZE));
13910 put_thumb32_insn (to, inst.instruction);
13911 }
13912 else if (inst.size > INSN_SIZE)
13913 {
13914 assert (inst.size == (2 * INSN_SIZE));
13915 md_number_to_chars (to, inst.instruction, INSN_SIZE);
13916 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
13917 }
13918 else
13919 md_number_to_chars (to, inst.instruction, inst.size);
13920
13921 if (inst.reloc.type != BFD_RELOC_UNUSED)
13922 fix_new_arm (frag_now, to - frag_now->fr_literal,
13923 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
13924 inst.reloc.type);
13925
13926 dwarf2_emit_insn (inst.size);
13927 }
13928
13929 /* Tag values used in struct asm_opcode's tag field. */
13930 enum opcode_tag
13931 {
13932 OT_unconditional, /* Instruction cannot be conditionalized.
13933 The ARM condition field is still 0xE. */
13934 OT_unconditionalF, /* Instruction cannot be conditionalized
13935 and carries 0xF in its ARM condition field. */
13936 OT_csuffix, /* Instruction takes a conditional suffix. */
13937 OT_csuffixF, /* Some forms of the instruction take a conditional
13938 suffix, others place 0xF where the condition field
13939 would be. */
13940 OT_cinfix3, /* Instruction takes a conditional infix,
13941 beginning at character index 3. (In
13942 unified mode, it becomes a suffix.) */
13943 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
13944 tsts, cmps, cmns, and teqs. */
13945 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
13946 character index 3, even in unified mode. Used for
13947 legacy instructions where suffix and infix forms
13948 may be ambiguous. */
13949 OT_csuf_or_in3, /* Instruction takes either a conditional
13950 suffix or an infix at character index 3. */
13951 OT_odd_infix_unc, /* This is the unconditional variant of an
13952 instruction that takes a conditional infix
13953 at an unusual position. In unified mode,
13954 this variant will accept a suffix. */
13955 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
13956 are the conditional variants of instructions that
13957 take conditional infixes in unusual positions.
13958 The infix appears at character index
13959 (tag - OT_odd_infix_0). These are not accepted
13960 in unified mode. */
13961 };
13962
13963 /* Subroutine of md_assemble, responsible for looking up the primary
13964 opcode from the mnemonic the user wrote. STR points to the
13965 beginning of the mnemonic.
13966
13967 This is not simply a hash table lookup, because of conditional
13968 variants. Most instructions have conditional variants, which are
13969 expressed with a _conditional affix_ to the mnemonic. If we were
13970 to encode each conditional variant as a literal string in the opcode
13971 table, it would have approximately 20,000 entries.
13972
13973 Most mnemonics take this affix as a suffix, and in unified syntax,
13974 'most' is upgraded to 'all'. However, in the divided syntax, some
13975 instructions take the affix as an infix, notably the s-variants of
13976 the arithmetic instructions. Of those instructions, all but six
13977 have the infix appear after the third character of the mnemonic.
13978
13979 Accordingly, the algorithm for looking up primary opcodes given
13980 an identifier is:
13981
13982 1. Look up the identifier in the opcode table.
13983 If we find a match, go to step U.
13984
13985 2. Look up the last two characters of the identifier in the
13986 conditions table. If we find a match, look up the first N-2
13987 characters of the identifier in the opcode table. If we
13988 find a match, go to step CE.
13989
13990 3. Look up the fourth and fifth characters of the identifier in
13991 the conditions table. If we find a match, extract those
13992 characters from the identifier, and look up the remaining
13993 characters in the opcode table. If we find a match, go
13994 to step CM.
13995
13996 4. Fail.
13997
13998 U. Examine the tag field of the opcode structure, in case this is
13999 one of the six instructions with its conditional infix in an
14000 unusual place. If it is, the tag tells us where to find the
14001 infix; look it up in the conditions table and set inst.cond
14002 accordingly. Otherwise, this is an unconditional instruction.
14003 Again set inst.cond accordingly. Return the opcode structure.
14004
14005 CE. Examine the tag field to make sure this is an instruction that
14006 should receive a conditional suffix. If it is not, fail.
14007 Otherwise, set inst.cond from the suffix we already looked up,
14008 and return the opcode structure.
14009
14010 CM. Examine the tag field to make sure this is an instruction that
14011 should receive a conditional infix after the third character.
14012 If it is not, fail. Otherwise, undo the edits to the current
14013 line of input and proceed as for case CE. */
14014
14015 static const struct asm_opcode *
14016 opcode_lookup (char **str)
14017 {
14018 char *end, *base;
14019 char *affix;
14020 const struct asm_opcode *opcode;
14021 const struct asm_cond *cond;
14022 char save[2];
14023 bfd_boolean neon_supported;
14024
14025 neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1);
14026
14027 /* Scan up to the end of the mnemonic, which must end in white space,
14028 '.' (in unified mode, or for Neon instructions), or end of string. */
14029 for (base = end = *str; *end != '\0'; end++)
14030 if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.'))
14031 break;
14032
14033 if (end == base)
14034 return 0;
14035
14036 /* Handle a possible width suffix and/or Neon type suffix. */
14037 if (end[0] == '.')
14038 {
14039 int offset = 2;
14040
14041 /* The .w and .n suffixes are only valid if the unified syntax is in
14042 use. */
14043 if (unified_syntax && end[1] == 'w')
14044 inst.size_req = 4;
14045 else if (unified_syntax && end[1] == 'n')
14046 inst.size_req = 2;
14047 else
14048 offset = 0;
14049
14050 inst.vectype.elems = 0;
14051
14052 *str = end + offset;
14053
14054 if (end[offset] == '.')
14055 {
14056 /* See if we have a Neon type suffix (possible in either unified or
14057 non-unified ARM syntax mode). */
14058 if (parse_neon_type (&inst.vectype, str) == FAIL)
14059 return 0;
14060 }
14061 else if (end[offset] != '\0' && end[offset] != ' ')
14062 return 0;
14063 }
14064 else
14065 *str = end;
14066
14067 /* Look for unaffixed or special-case affixed mnemonic. */
14068 opcode = hash_find_n (arm_ops_hsh, base, end - base);
14069 if (opcode)
14070 {
14071 /* step U */
14072 if (opcode->tag < OT_odd_infix_0)
14073 {
14074 inst.cond = COND_ALWAYS;
14075 return opcode;
14076 }
14077
14078 if (unified_syntax)
14079 as_warn (_("conditional infixes are deprecated in unified syntax"));
14080 affix = base + (opcode->tag - OT_odd_infix_0);
14081 cond = hash_find_n (arm_cond_hsh, affix, 2);
14082 assert (cond);
14083
14084 inst.cond = cond->value;
14085 return opcode;
14086 }
14087
14088 /* Cannot have a conditional suffix on a mnemonic of less than two
14089 characters. */
14090 if (end - base < 3)
14091 return 0;
14092
14093 /* Look for suffixed mnemonic. */
14094 affix = end - 2;
14095 cond = hash_find_n (arm_cond_hsh, affix, 2);
14096 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
14097 if (opcode && cond)
14098 {
14099 /* step CE */
14100 switch (opcode->tag)
14101 {
14102 case OT_cinfix3_legacy:
14103 /* Ignore conditional suffixes matched on infix only mnemonics. */
14104 break;
14105
14106 case OT_cinfix3:
14107 case OT_cinfix3_deprecated:
14108 case OT_odd_infix_unc:
14109 if (!unified_syntax)
14110 return 0;
14111 /* else fall through */
14112
14113 case OT_csuffix:
14114 case OT_csuffixF:
14115 case OT_csuf_or_in3:
14116 inst.cond = cond->value;
14117 return opcode;
14118
14119 case OT_unconditional:
14120 case OT_unconditionalF:
14121 if (thumb_mode)
14122 {
14123 inst.cond = cond->value;
14124 }
14125 else
14126 {
14127 /* delayed diagnostic */
14128 inst.error = BAD_COND;
14129 inst.cond = COND_ALWAYS;
14130 }
14131 return opcode;
14132
14133 default:
14134 return 0;
14135 }
14136 }
14137
14138 /* Cannot have a usual-position infix on a mnemonic of less than
14139 six characters (five would be a suffix). */
14140 if (end - base < 6)
14141 return 0;
14142
14143 /* Look for infixed mnemonic in the usual position. */
14144 affix = base + 3;
14145 cond = hash_find_n (arm_cond_hsh, affix, 2);
14146 if (!cond)
14147 return 0;
14148
14149 memcpy (save, affix, 2);
14150 memmove (affix, affix + 2, (end - affix) - 2);
14151 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
14152 memmove (affix + 2, affix, (end - affix) - 2);
14153 memcpy (affix, save, 2);
14154
14155 if (opcode
14156 && (opcode->tag == OT_cinfix3
14157 || opcode->tag == OT_cinfix3_deprecated
14158 || opcode->tag == OT_csuf_or_in3
14159 || opcode->tag == OT_cinfix3_legacy))
14160 {
14161 /* step CM */
14162 if (unified_syntax
14163 && (opcode->tag == OT_cinfix3
14164 || opcode->tag == OT_cinfix3_deprecated))
14165 as_warn (_("conditional infixes are deprecated in unified syntax"));
14166
14167 inst.cond = cond->value;
14168 return opcode;
14169 }
14170
14171 return 0;
14172 }
14173
14174 void
14175 md_assemble (char *str)
14176 {
14177 char *p = str;
14178 const struct asm_opcode * opcode;
14179
14180 /* Align the previous label if needed. */
14181 if (last_label_seen != NULL)
14182 {
14183 symbol_set_frag (last_label_seen, frag_now);
14184 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
14185 S_SET_SEGMENT (last_label_seen, now_seg);
14186 }
14187
14188 memset (&inst, '\0', sizeof (inst));
14189 inst.reloc.type = BFD_RELOC_UNUSED;
14190
14191 opcode = opcode_lookup (&p);
14192 if (!opcode)
14193 {
14194 /* It wasn't an instruction, but it might be a register alias of
14195 the form alias .req reg, or a Neon .dn/.qn directive. */
14196 if (!create_register_alias (str, p)
14197 && !create_neon_reg_alias (str, p))
14198 as_bad (_("bad instruction `%s'"), str);
14199
14200 return;
14201 }
14202
14203 if (opcode->tag == OT_cinfix3_deprecated)
14204 as_warn (_("s suffix on comparison instruction is deprecated"));
14205
14206 /* The value which unconditional instructions should have in place of the
14207 condition field. */
14208 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
14209
14210 if (thumb_mode)
14211 {
14212 arm_feature_set variant;
14213
14214 variant = cpu_variant;
14215 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
14216 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
14217 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
14218 /* Check that this instruction is supported for this CPU. */
14219 if (!opcode->tvariant
14220 || (thumb_mode == 1
14221 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
14222 {
14223 as_bad (_("selected processor does not support `%s'"), str);
14224 return;
14225 }
14226 if (inst.cond != COND_ALWAYS && !unified_syntax
14227 && opcode->tencode != do_t_branch)
14228 {
14229 as_bad (_("Thumb does not support conditional execution"));
14230 return;
14231 }
14232
14233 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) && !inst.size_req)
14234 {
14235 /* Implicit require narrow instructions on Thumb-1. This avoids
14236 relaxation accidentally introducing Thumb-2 instructions. */
14237 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
14238 && !ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr))
14239 inst.size_req = 2;
14240 }
14241
14242 /* Check conditional suffixes. */
14243 if (current_it_mask)
14244 {
14245 int cond;
14246 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
14247 current_it_mask <<= 1;
14248 current_it_mask &= 0x1f;
14249 /* The BKPT instruction is unconditional even in an IT block. */
14250 if (!inst.error
14251 && cond != inst.cond && opcode->tencode != do_t_bkpt)
14252 {
14253 as_bad (_("incorrect condition in IT block"));
14254 return;
14255 }
14256 }
14257 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
14258 {
14259 as_bad (_("thumb conditional instruction not in IT block"));
14260 return;
14261 }
14262
14263 mapping_state (MAP_THUMB);
14264 inst.instruction = opcode->tvalue;
14265
14266 if (!parse_operands (p, opcode->operands))
14267 opcode->tencode ();
14268
14269 /* Clear current_it_mask at the end of an IT block. */
14270 if (current_it_mask == 0x10)
14271 current_it_mask = 0;
14272
14273 if (!(inst.error || inst.relax))
14274 {
14275 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
14276 inst.size = (inst.instruction > 0xffff ? 4 : 2);
14277 if (inst.size_req && inst.size_req != inst.size)
14278 {
14279 as_bad (_("cannot honor width suffix -- `%s'"), str);
14280 return;
14281 }
14282 }
14283
14284 /* Something has gone badly wrong if we try to relax a fixed size
14285 instruction. */
14286 assert (inst.size_req == 0 || !inst.relax);
14287
14288 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14289 *opcode->tvariant);
14290 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
14291 set those bits when Thumb-2 32-bit instructions are seen. ie.
14292 anything other than bl/blx and v6-M instructions.
14293 This is overly pessimistic for relaxable instructions. */
14294 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
14295 || inst.relax)
14296 && !ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr))
14297 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14298 arm_ext_v6t2);
14299 }
14300 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
14301 {
14302 bfd_boolean is_bx;
14303
14304 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
14305 is_bx = (opcode->aencode == do_bx);
14306
14307 /* Check that this instruction is supported for this CPU. */
14308 if (!(is_bx && fix_v4bx)
14309 && !(opcode->avariant &&
14310 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
14311 {
14312 as_bad (_("selected processor does not support `%s'"), str);
14313 return;
14314 }
14315 if (inst.size_req)
14316 {
14317 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
14318 return;
14319 }
14320
14321 mapping_state (MAP_ARM);
14322 inst.instruction = opcode->avalue;
14323 if (opcode->tag == OT_unconditionalF)
14324 inst.instruction |= 0xF << 28;
14325 else
14326 inst.instruction |= inst.cond << 28;
14327 inst.size = INSN_SIZE;
14328 if (!parse_operands (p, opcode->operands))
14329 opcode->aencode ();
14330 /* Arm mode bx is marked as both v4T and v5 because it's still required
14331 on a hypothetical non-thumb v5 core. */
14332 if (is_bx)
14333 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
14334 else
14335 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
14336 *opcode->avariant);
14337 }
14338 else
14339 {
14340 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
14341 "-- `%s'"), str);
14342 return;
14343 }
14344 output_inst (str);
14345 }
14346
14347 /* Various frobbings of labels and their addresses. */
14348
14349 void
14350 arm_start_line_hook (void)
14351 {
14352 last_label_seen = NULL;
14353 }
14354
14355 void
14356 arm_frob_label (symbolS * sym)
14357 {
14358 last_label_seen = sym;
14359
14360 ARM_SET_THUMB (sym, thumb_mode);
14361
14362 #if defined OBJ_COFF || defined OBJ_ELF
14363 ARM_SET_INTERWORK (sym, support_interwork);
14364 #endif
14365
14366 /* Note - do not allow local symbols (.Lxxx) to be labelled
14367 as Thumb functions. This is because these labels, whilst
14368 they exist inside Thumb code, are not the entry points for
14369 possible ARM->Thumb calls. Also, these labels can be used
14370 as part of a computed goto or switch statement. eg gcc
14371 can generate code that looks like this:
14372
14373 ldr r2, [pc, .Laaa]
14374 lsl r3, r3, #2
14375 ldr r2, [r3, r2]
14376 mov pc, r2
14377
14378 .Lbbb: .word .Lxxx
14379 .Lccc: .word .Lyyy
14380 ..etc...
14381 .Laaa: .word Lbbb
14382
14383 The first instruction loads the address of the jump table.
14384 The second instruction converts a table index into a byte offset.
14385 The third instruction gets the jump address out of the table.
14386 The fourth instruction performs the jump.
14387
14388 If the address stored at .Laaa is that of a symbol which has the
14389 Thumb_Func bit set, then the linker will arrange for this address
14390 to have the bottom bit set, which in turn would mean that the
14391 address computation performed by the third instruction would end
14392 up with the bottom bit set. Since the ARM is capable of unaligned
14393 word loads, the instruction would then load the incorrect address
14394 out of the jump table, and chaos would ensue. */
14395 if (label_is_thumb_function_name
14396 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
14397 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
14398 {
14399 /* When the address of a Thumb function is taken the bottom
14400 bit of that address should be set. This will allow
14401 interworking between Arm and Thumb functions to work
14402 correctly. */
14403
14404 THUMB_SET_FUNC (sym, 1);
14405
14406 label_is_thumb_function_name = FALSE;
14407 }
14408
14409 dwarf2_emit_label (sym);
14410 }
14411
14412 int
14413 arm_data_in_code (void)
14414 {
14415 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
14416 {
14417 *input_line_pointer = '/';
14418 input_line_pointer += 5;
14419 *input_line_pointer = 0;
14420 return 1;
14421 }
14422
14423 return 0;
14424 }
14425
14426 char *
14427 arm_canonicalize_symbol_name (char * name)
14428 {
14429 int len;
14430
14431 if (thumb_mode && (len = strlen (name)) > 5
14432 && streq (name + len - 5, "/data"))
14433 *(name + len - 5) = 0;
14434
14435 return name;
14436 }
14437 \f
14438 /* Table of all register names defined by default. The user can
14439 define additional names with .req. Note that all register names
14440 should appear in both upper and lowercase variants. Some registers
14441 also have mixed-case names. */
14442
14443 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
14444 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
14445 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
14446 #define REGSET(p,t) \
14447 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
14448 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
14449 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
14450 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
14451 #define REGSETH(p,t) \
14452 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
14453 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
14454 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
14455 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
14456 #define REGSET2(p,t) \
14457 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
14458 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
14459 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
14460 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
14461
14462 static const struct reg_entry reg_names[] =
14463 {
14464 /* ARM integer registers. */
14465 REGSET(r, RN), REGSET(R, RN),
14466
14467 /* ATPCS synonyms. */
14468 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
14469 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
14470 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
14471
14472 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
14473 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
14474 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
14475
14476 /* Well-known aliases. */
14477 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
14478 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
14479
14480 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
14481 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
14482
14483 /* Coprocessor numbers. */
14484 REGSET(p, CP), REGSET(P, CP),
14485
14486 /* Coprocessor register numbers. The "cr" variants are for backward
14487 compatibility. */
14488 REGSET(c, CN), REGSET(C, CN),
14489 REGSET(cr, CN), REGSET(CR, CN),
14490
14491 /* FPA registers. */
14492 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
14493 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
14494
14495 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
14496 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
14497
14498 /* VFP SP registers. */
14499 REGSET(s,VFS), REGSET(S,VFS),
14500 REGSETH(s,VFS), REGSETH(S,VFS),
14501
14502 /* VFP DP Registers. */
14503 REGSET(d,VFD), REGSET(D,VFD),
14504 /* Extra Neon DP registers. */
14505 REGSETH(d,VFD), REGSETH(D,VFD),
14506
14507 /* Neon QP registers. */
14508 REGSET2(q,NQ), REGSET2(Q,NQ),
14509
14510 /* VFP control registers. */
14511 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
14512 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
14513 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
14514 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
14515 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
14516 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
14517
14518 /* Maverick DSP coprocessor registers. */
14519 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
14520 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
14521
14522 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
14523 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
14524 REGDEF(dspsc,0,DSPSC),
14525
14526 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
14527 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
14528 REGDEF(DSPSC,0,DSPSC),
14529
14530 /* iWMMXt data registers - p0, c0-15. */
14531 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
14532
14533 /* iWMMXt control registers - p1, c0-3. */
14534 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
14535 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
14536 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
14537 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
14538
14539 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
14540 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
14541 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
14542 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
14543 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
14544
14545 /* XScale accumulator registers. */
14546 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
14547 };
14548 #undef REGDEF
14549 #undef REGNUM
14550 #undef REGSET
14551
14552 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
14553 within psr_required_here. */
14554 static const struct asm_psr psrs[] =
14555 {
14556 /* Backward compatibility notation. Note that "all" is no longer
14557 truly all possible PSR bits. */
14558 {"all", PSR_c | PSR_f},
14559 {"flg", PSR_f},
14560 {"ctl", PSR_c},
14561
14562 /* Individual flags. */
14563 {"f", PSR_f},
14564 {"c", PSR_c},
14565 {"x", PSR_x},
14566 {"s", PSR_s},
14567 /* Combinations of flags. */
14568 {"fs", PSR_f | PSR_s},
14569 {"fx", PSR_f | PSR_x},
14570 {"fc", PSR_f | PSR_c},
14571 {"sf", PSR_s | PSR_f},
14572 {"sx", PSR_s | PSR_x},
14573 {"sc", PSR_s | PSR_c},
14574 {"xf", PSR_x | PSR_f},
14575 {"xs", PSR_x | PSR_s},
14576 {"xc", PSR_x | PSR_c},
14577 {"cf", PSR_c | PSR_f},
14578 {"cs", PSR_c | PSR_s},
14579 {"cx", PSR_c | PSR_x},
14580 {"fsx", PSR_f | PSR_s | PSR_x},
14581 {"fsc", PSR_f | PSR_s | PSR_c},
14582 {"fxs", PSR_f | PSR_x | PSR_s},
14583 {"fxc", PSR_f | PSR_x | PSR_c},
14584 {"fcs", PSR_f | PSR_c | PSR_s},
14585 {"fcx", PSR_f | PSR_c | PSR_x},
14586 {"sfx", PSR_s | PSR_f | PSR_x},
14587 {"sfc", PSR_s | PSR_f | PSR_c},
14588 {"sxf", PSR_s | PSR_x | PSR_f},
14589 {"sxc", PSR_s | PSR_x | PSR_c},
14590 {"scf", PSR_s | PSR_c | PSR_f},
14591 {"scx", PSR_s | PSR_c | PSR_x},
14592 {"xfs", PSR_x | PSR_f | PSR_s},
14593 {"xfc", PSR_x | PSR_f | PSR_c},
14594 {"xsf", PSR_x | PSR_s | PSR_f},
14595 {"xsc", PSR_x | PSR_s | PSR_c},
14596 {"xcf", PSR_x | PSR_c | PSR_f},
14597 {"xcs", PSR_x | PSR_c | PSR_s},
14598 {"cfs", PSR_c | PSR_f | PSR_s},
14599 {"cfx", PSR_c | PSR_f | PSR_x},
14600 {"csf", PSR_c | PSR_s | PSR_f},
14601 {"csx", PSR_c | PSR_s | PSR_x},
14602 {"cxf", PSR_c | PSR_x | PSR_f},
14603 {"cxs", PSR_c | PSR_x | PSR_s},
14604 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
14605 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
14606 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
14607 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
14608 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
14609 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
14610 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
14611 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
14612 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
14613 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
14614 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
14615 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
14616 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
14617 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
14618 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
14619 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
14620 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
14621 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
14622 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
14623 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
14624 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
14625 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
14626 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
14627 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
14628 };
14629
14630 /* Table of V7M psr names. */
14631 static const struct asm_psr v7m_psrs[] =
14632 {
14633 {"apsr", 0 }, {"APSR", 0 },
14634 {"iapsr", 1 }, {"IAPSR", 1 },
14635 {"eapsr", 2 }, {"EAPSR", 2 },
14636 {"psr", 3 }, {"PSR", 3 },
14637 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
14638 {"ipsr", 5 }, {"IPSR", 5 },
14639 {"epsr", 6 }, {"EPSR", 6 },
14640 {"iepsr", 7 }, {"IEPSR", 7 },
14641 {"msp", 8 }, {"MSP", 8 },
14642 {"psp", 9 }, {"PSP", 9 },
14643 {"primask", 16}, {"PRIMASK", 16},
14644 {"basepri", 17}, {"BASEPRI", 17},
14645 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
14646 {"faultmask", 19}, {"FAULTMASK", 19},
14647 {"control", 20}, {"CONTROL", 20}
14648 };
14649
14650 /* Table of all shift-in-operand names. */
14651 static const struct asm_shift_name shift_names [] =
14652 {
14653 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
14654 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
14655 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
14656 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
14657 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
14658 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
14659 };
14660
14661 /* Table of all explicit relocation names. */
14662 #ifdef OBJ_ELF
14663 static struct reloc_entry reloc_names[] =
14664 {
14665 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
14666 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
14667 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
14668 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
14669 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
14670 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
14671 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
14672 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
14673 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
14674 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
14675 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
14676 };
14677 #endif
14678
14679 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
14680 static const struct asm_cond conds[] =
14681 {
14682 {"eq", 0x0},
14683 {"ne", 0x1},
14684 {"cs", 0x2}, {"hs", 0x2},
14685 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
14686 {"mi", 0x4},
14687 {"pl", 0x5},
14688 {"vs", 0x6},
14689 {"vc", 0x7},
14690 {"hi", 0x8},
14691 {"ls", 0x9},
14692 {"ge", 0xa},
14693 {"lt", 0xb},
14694 {"gt", 0xc},
14695 {"le", 0xd},
14696 {"al", 0xe}
14697 };
14698
14699 static struct asm_barrier_opt barrier_opt_names[] =
14700 {
14701 { "sy", 0xf },
14702 { "un", 0x7 },
14703 { "st", 0xe },
14704 { "unst", 0x6 }
14705 };
14706
14707 /* Table of ARM-format instructions. */
14708
14709 /* Macros for gluing together operand strings. N.B. In all cases
14710 other than OPS0, the trailing OP_stop comes from default
14711 zero-initialization of the unspecified elements of the array. */
14712 #define OPS0() { OP_stop, }
14713 #define OPS1(a) { OP_##a, }
14714 #define OPS2(a,b) { OP_##a,OP_##b, }
14715 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
14716 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
14717 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
14718 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
14719
14720 /* These macros abstract out the exact format of the mnemonic table and
14721 save some repeated characters. */
14722
14723 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
14724 #define TxCE(mnem, op, top, nops, ops, ae, te) \
14725 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
14726 THUMB_VARIANT, do_##ae, do_##te }
14727
14728 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
14729 a T_MNEM_xyz enumerator. */
14730 #define TCE(mnem, aop, top, nops, ops, ae, te) \
14731 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
14732 #define tCE(mnem, aop, top, nops, ops, ae, te) \
14733 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14734
14735 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
14736 infix after the third character. */
14737 #define TxC3(mnem, op, top, nops, ops, ae, te) \
14738 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
14739 THUMB_VARIANT, do_##ae, do_##te }
14740 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
14741 { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
14742 THUMB_VARIANT, do_##ae, do_##te }
14743 #define TC3(mnem, aop, top, nops, ops, ae, te) \
14744 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
14745 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
14746 TxC3w(mnem, aop, 0x##top, nops, ops, ae, te)
14747 #define tC3(mnem, aop, top, nops, ops, ae, te) \
14748 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14749 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
14750 TxC3w(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14751
14752 /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
14753 appear in the condition table. */
14754 #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
14755 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14756 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
14757
14758 #define TxCM(m1, m2, op, top, nops, ops, ae, te) \
14759 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
14760 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
14761 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
14762 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
14763 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
14764 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
14765 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
14766 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
14767 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
14768 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
14769 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
14770 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
14771 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
14772 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
14773 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
14774 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
14775 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
14776 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
14777 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
14778
14779 #define TCM(m1,m2, aop, top, nops, ops, ae, te) \
14780 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
14781 #define tCM(m1,m2, aop, top, nops, ops, ae, te) \
14782 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
14783
14784 /* Mnemonic that cannot be conditionalized. The ARM condition-code
14785 field is still 0xE. Many of the Thumb variants can be executed
14786 conditionally, so this is checked separately. */
14787 #define TUE(mnem, op, top, nops, ops, ae, te) \
14788 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
14789 THUMB_VARIANT, do_##ae, do_##te }
14790
14791 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
14792 condition code field. */
14793 #define TUF(mnem, op, top, nops, ops, ae, te) \
14794 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
14795 THUMB_VARIANT, do_##ae, do_##te }
14796
14797 /* ARM-only variants of all the above. */
14798 #define CE(mnem, op, nops, ops, ae) \
14799 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14800
14801 #define C3(mnem, op, nops, ops, ae) \
14802 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14803
14804 /* Legacy mnemonics that always have conditional infix after the third
14805 character. */
14806 #define CL(mnem, op, nops, ops, ae) \
14807 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14808 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14809
14810 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
14811 #define cCE(mnem, op, nops, ops, ae) \
14812 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14813
14814 /* Legacy coprocessor instructions where conditional infix and conditional
14815 suffix are ambiguous. For consistency this includes all FPA instructions,
14816 not just the potentially ambiguous ones. */
14817 #define cCL(mnem, op, nops, ops, ae) \
14818 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14819 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14820
14821 /* Coprocessor, takes either a suffix or a position-3 infix
14822 (for an FPA corner case). */
14823 #define C3E(mnem, op, nops, ops, ae) \
14824 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
14825 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14826
14827 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
14828 { #m1 #m2 #m3, OPS##nops ops, \
14829 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14830 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14831
14832 #define CM(m1, m2, op, nops, ops, ae) \
14833 xCM_(m1, , m2, op, nops, ops, ae), \
14834 xCM_(m1, eq, m2, op, nops, ops, ae), \
14835 xCM_(m1, ne, m2, op, nops, ops, ae), \
14836 xCM_(m1, cs, m2, op, nops, ops, ae), \
14837 xCM_(m1, hs, m2, op, nops, ops, ae), \
14838 xCM_(m1, cc, m2, op, nops, ops, ae), \
14839 xCM_(m1, ul, m2, op, nops, ops, ae), \
14840 xCM_(m1, lo, m2, op, nops, ops, ae), \
14841 xCM_(m1, mi, m2, op, nops, ops, ae), \
14842 xCM_(m1, pl, m2, op, nops, ops, ae), \
14843 xCM_(m1, vs, m2, op, nops, ops, ae), \
14844 xCM_(m1, vc, m2, op, nops, ops, ae), \
14845 xCM_(m1, hi, m2, op, nops, ops, ae), \
14846 xCM_(m1, ls, m2, op, nops, ops, ae), \
14847 xCM_(m1, ge, m2, op, nops, ops, ae), \
14848 xCM_(m1, lt, m2, op, nops, ops, ae), \
14849 xCM_(m1, gt, m2, op, nops, ops, ae), \
14850 xCM_(m1, le, m2, op, nops, ops, ae), \
14851 xCM_(m1, al, m2, op, nops, ops, ae)
14852
14853 #define UE(mnem, op, nops, ops, ae) \
14854 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14855
14856 #define UF(mnem, op, nops, ops, ae) \
14857 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14858
14859 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
14860 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
14861 use the same encoding function for each. */
14862 #define NUF(mnem, op, nops, ops, enc) \
14863 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
14864 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14865
14866 /* Neon data processing, version which indirects through neon_enc_tab for
14867 the various overloaded versions of opcodes. */
14868 #define nUF(mnem, op, nops, ops, enc) \
14869 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \
14870 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14871
14872 /* Neon insn with conditional suffix for the ARM version, non-overloaded
14873 version. */
14874 #define NCE_tag(mnem, op, nops, ops, enc, tag) \
14875 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
14876 THUMB_VARIANT, do_##enc, do_##enc }
14877
14878 #define NCE(mnem, op, nops, ops, enc) \
14879 NCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14880
14881 #define NCEF(mnem, op, nops, ops, enc) \
14882 NCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14883
14884 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
14885 #define nCE_tag(mnem, op, nops, ops, enc, tag) \
14886 { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \
14887 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14888
14889 #define nCE(mnem, op, nops, ops, enc) \
14890 nCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14891
14892 #define nCEF(mnem, op, nops, ops, enc) \
14893 nCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14894
14895 #define do_0 0
14896
14897 /* Thumb-only, unconditional. */
14898 #define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
14899
14900 static const struct asm_opcode insns[] =
14901 {
14902 #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
14903 #define THUMB_VARIANT &arm_ext_v4t
14904 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
14905 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
14906 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
14907 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
14908 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
14909 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
14910 tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub),
14911 tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub),
14912 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
14913 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
14914 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
14915 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
14916 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
14917 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
14918 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
14919 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
14920
14921 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
14922 for setting PSR flag bits. They are obsolete in V6 and do not
14923 have Thumb equivalents. */
14924 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
14925 tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
14926 CL(tstp, 110f000, 2, (RR, SH), cmp),
14927 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
14928 tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
14929 CL(cmpp, 150f000, 2, (RR, SH), cmp),
14930 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
14931 tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
14932 CL(cmnp, 170f000, 2, (RR, SH), cmp),
14933
14934 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
14935 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
14936 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
14937 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
14938
14939 tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
14940 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
14941 tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst),
14942 tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
14943
14944 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14945 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14946 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14947 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14948 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14949 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14950
14951 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
14952 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
14953 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
14954 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
14955
14956 /* Pseudo ops. */
14957 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
14958 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
14959 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
14960
14961 /* Thumb-compatibility pseudo ops. */
14962 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
14963 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
14964 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
14965 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
14966 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
14967 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
14968 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
14969 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
14970 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
14971 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
14972 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
14973 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
14974
14975 /* These may simplify to neg. */
14976 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
14977 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
14978
14979 #undef THUMB_VARIANT
14980 #define THUMB_VARIANT &arm_ext_v6
14981 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
14982
14983 /* V1 instructions with no Thumb analogue prior to V6T2. */
14984 #undef THUMB_VARIANT
14985 #define THUMB_VARIANT &arm_ext_v6t2
14986 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
14987 TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
14988 CL(teqp, 130f000, 2, (RR, SH), cmp),
14989
14990 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
14991 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
14992 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
14993 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
14994
14995 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14996 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14997
14998 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14999 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15000
15001 /* V1 instructions with no Thumb analogue at all. */
15002 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
15003 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
15004
15005 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
15006 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
15007 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
15008 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
15009 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
15010 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
15011 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
15012 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
15013
15014 #undef ARM_VARIANT
15015 #define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
15016 #undef THUMB_VARIANT
15017 #define THUMB_VARIANT &arm_ext_v4t
15018 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15019 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15020
15021 #undef THUMB_VARIANT
15022 #define THUMB_VARIANT &arm_ext_v6t2
15023 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
15024 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
15025
15026 /* Generic coprocessor instructions. */
15027 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
15028 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15029 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15030 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15031 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15032 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15033 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15034
15035 #undef ARM_VARIANT
15036 #define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
15037 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15038 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15039
15040 #undef ARM_VARIANT
15041 #define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
15042 #undef THUMB_VARIANT
15043 #define THUMB_VARIANT &arm_ext_msr
15044 TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
15045 TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
15046
15047 #undef ARM_VARIANT
15048 #define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
15049 #undef THUMB_VARIANT
15050 #define THUMB_VARIANT &arm_ext_v6t2
15051 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15052 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15053 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15054 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15055 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15056 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15057 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15058 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15059
15060 #undef ARM_VARIANT
15061 #define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
15062 #undef THUMB_VARIANT
15063 #define THUMB_VARIANT &arm_ext_v4t
15064 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15065 tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15066 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15067 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15068 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15069 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15070
15071 #undef ARM_VARIANT
15072 #define ARM_VARIANT &arm_ext_v4t_5
15073 /* ARM Architecture 4T. */
15074 /* Note: bx (and blx) are required on V5, even if the processor does
15075 not support Thumb. */
15076 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
15077
15078 #undef ARM_VARIANT
15079 #define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
15080 #undef THUMB_VARIANT
15081 #define THUMB_VARIANT &arm_ext_v5t
15082 /* Note: blx has 2 variants; the .value coded here is for
15083 BLX(2). Only this variant has conditional execution. */
15084 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
15085 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
15086
15087 #undef THUMB_VARIANT
15088 #define THUMB_VARIANT &arm_ext_v6t2
15089 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
15090 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15091 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15092 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15093 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15094 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
15095 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15096 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15097
15098 #undef ARM_VARIANT
15099 #define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
15100 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15101 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15102 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15103 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15104
15105 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15106 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15107
15108 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15109 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15110 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15111 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15112
15113 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15114 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15115 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15116 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15117
15118 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15119 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15120
15121 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15122 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15123 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15124 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15125
15126 #undef ARM_VARIANT
15127 #define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
15128 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
15129 TC3(ldrd, 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
15130 TC3(strd, 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
15131
15132 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15133 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15134
15135 #undef ARM_VARIANT
15136 #define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
15137 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
15138
15139 #undef ARM_VARIANT
15140 #define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
15141 #undef THUMB_VARIANT
15142 #define THUMB_VARIANT &arm_ext_v6
15143 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
15144 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
15145 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15146 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15147 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15148 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15149 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15150 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15151 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15152 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
15153
15154 #undef THUMB_VARIANT
15155 #define THUMB_VARIANT &arm_ext_v6t2
15156 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
15157 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
15158 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15159 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15160
15161 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
15162 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
15163
15164 /* ARM V6 not included in V7M (eg. integer SIMD). */
15165 #undef THUMB_VARIANT
15166 #define THUMB_VARIANT &arm_ext_v6_notm
15167 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
15168 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
15169 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
15170 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15171 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15172 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15173 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15174 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15175 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15176 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15177 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15178 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15179 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15180 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15181 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15182 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15183 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15184 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15185 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15186 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15187 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15188 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15189 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15190 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15191 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15192 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15193 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15194 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15195 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15196 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15197 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15198 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15199 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15200 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15201 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15202 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15203 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15204 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15205 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15206 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15207 UF(rfeib, 9900a00, 1, (RRw), rfe),
15208 UF(rfeda, 8100a00, 1, (RRw), rfe),
15209 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15210 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15211 UF(rfefa, 9900a00, 1, (RRw), rfe),
15212 UF(rfeea, 8100a00, 1, (RRw), rfe),
15213 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15214 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15215 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15216 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15217 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15218 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15219 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15220 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15221 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15222 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15223 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15224 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15225 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15226 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15227 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15228 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15229 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15230 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15231 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15232 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15233 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15234 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15235 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15236 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15237 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15238 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15239 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15240 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15241 TUF(srsia, 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
15242 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
15243 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
15244 TUF(srsdb, 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
15245 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
15246 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
15247 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15248 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15249 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
15250
15251 #undef ARM_VARIANT
15252 #define ARM_VARIANT &arm_ext_v6k
15253 #undef THUMB_VARIANT
15254 #define THUMB_VARIANT &arm_ext_v6k
15255 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
15256 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
15257 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
15258 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
15259
15260 #undef THUMB_VARIANT
15261 #define THUMB_VARIANT &arm_ext_v6_notm
15262 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
15263 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
15264
15265 #undef THUMB_VARIANT
15266 #define THUMB_VARIANT &arm_ext_v6t2
15267 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15268 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15269 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15270 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15271 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
15272
15273 #undef ARM_VARIANT
15274 #define ARM_VARIANT &arm_ext_v6z
15275 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
15276
15277 #undef ARM_VARIANT
15278 #define ARM_VARIANT &arm_ext_v6t2
15279 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
15280 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
15281 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15282 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15283
15284 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
15285 TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
15286 TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
15287 TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
15288
15289 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15290 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15291 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15292 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15293
15294 UT(cbnz, b900, 2, (RR, EXP), t_cbz),
15295 UT(cbz, b100, 2, (RR, EXP), t_cbz),
15296 /* ARM does not really have an IT instruction, so always allow it. */
15297 #undef ARM_VARIANT
15298 #define ARM_VARIANT &arm_ext_v1
15299 TUE(it, 0, bf08, 1, (COND), it, t_it),
15300 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
15301 TUE(ite, 0, bf04, 1, (COND), it, t_it),
15302 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
15303 TUE(itet, 0, bf06, 1, (COND), it, t_it),
15304 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
15305 TUE(itee, 0, bf02, 1, (COND), it, t_it),
15306 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
15307 TUE(itett, 0, bf07, 1, (COND), it, t_it),
15308 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
15309 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
15310 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
15311 TUE(itete, 0, bf05, 1, (COND), it, t_it),
15312 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
15313 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
15314
15315 /* Thumb2 only instructions. */
15316 #undef ARM_VARIANT
15317 #define ARM_VARIANT NULL
15318
15319 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15320 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15321 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
15322 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
15323
15324 /* Thumb-2 hardware division instructions (R and M profiles only). */
15325 #undef THUMB_VARIANT
15326 #define THUMB_VARIANT &arm_ext_div
15327 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
15328 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
15329
15330 /* ARM V6M/V7 instructions. */
15331 #undef ARM_VARIANT
15332 #define ARM_VARIANT &arm_ext_barrier
15333 #undef THUMB_VARIANT
15334 #define THUMB_VARIANT &arm_ext_barrier
15335 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
15336 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
15337 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
15338
15339 /* ARM V7 instructions. */
15340 #undef ARM_VARIANT
15341 #define ARM_VARIANT &arm_ext_v7
15342 #undef THUMB_VARIANT
15343 #define THUMB_VARIANT &arm_ext_v7
15344 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
15345 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
15346
15347 #undef ARM_VARIANT
15348 #define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
15349 cCE(wfs, e200110, 1, (RR), rd),
15350 cCE(rfs, e300110, 1, (RR), rd),
15351 cCE(wfc, e400110, 1, (RR), rd),
15352 cCE(rfc, e500110, 1, (RR), rd),
15353
15354 cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
15355 cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
15356 cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
15357 cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
15358
15359 cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
15360 cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
15361 cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
15362 cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
15363
15364 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
15365 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
15366 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
15367 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
15368 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
15369 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
15370 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
15371 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
15372 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
15373 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
15374 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
15375 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
15376
15377 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
15378 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
15379 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
15380 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
15381 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
15382 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
15383 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
15384 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
15385 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
15386 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
15387 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
15388 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
15389
15390 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
15391 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
15392 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
15393 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
15394 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
15395 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
15396 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
15397 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
15398 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
15399 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
15400 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
15401 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
15402
15403 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
15404 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
15405 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
15406 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
15407 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
15408 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
15409 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
15410 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
15411 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
15412 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
15413 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
15414 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
15415
15416 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
15417 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
15418 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
15419 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
15420 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
15421 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
15422 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
15423 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
15424 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
15425 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
15426 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
15427 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
15428
15429 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
15430 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
15431 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
15432 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
15433 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
15434 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
15435 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
15436 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
15437 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
15438 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
15439 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
15440 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
15441
15442 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
15443 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
15444 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
15445 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
15446 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
15447 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
15448 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
15449 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
15450 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
15451 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
15452 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
15453 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
15454
15455 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
15456 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
15457 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
15458 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
15459 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
15460 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
15461 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
15462 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
15463 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
15464 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
15465 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
15466 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
15467
15468 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
15469 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
15470 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
15471 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
15472 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
15473 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
15474 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
15475 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
15476 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
15477 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
15478 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
15479 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
15480
15481 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
15482 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
15483 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
15484 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
15485 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
15486 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
15487 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
15488 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
15489 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
15490 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
15491 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
15492 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
15493
15494 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
15495 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
15496 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
15497 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
15498 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
15499 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
15500 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
15501 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
15502 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
15503 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
15504 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
15505 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
15506
15507 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
15508 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
15509 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
15510 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
15511 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
15512 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
15513 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
15514 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
15515 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
15516 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
15517 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
15518 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
15519
15520 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
15521 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
15522 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
15523 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
15524 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
15525 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
15526 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
15527 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
15528 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
15529 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
15530 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
15531 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
15532
15533 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
15534 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
15535 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
15536 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
15537 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
15538 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
15539 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
15540 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
15541 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
15542 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
15543 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
15544 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
15545
15546 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
15547 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
15548 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
15549 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
15550 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
15551 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
15552 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
15553 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
15554 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
15555 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
15556 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
15557 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
15558
15559 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
15560 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
15561 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
15562 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
15563 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
15564 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
15565 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
15566 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
15567 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
15568 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
15569 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
15570 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
15571
15572 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
15573 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
15574 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
15575 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
15576 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
15577 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15578 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15579 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15580 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
15581 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
15582 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
15583 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
15584
15585 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
15586 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
15587 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
15588 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
15589 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
15590 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15591 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15592 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15593 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
15594 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
15595 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
15596 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
15597
15598 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
15599 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
15600 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
15601 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
15602 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
15603 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15604 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15605 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15606 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
15607 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
15608 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
15609 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
15610
15611 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
15612 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
15613 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
15614 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
15615 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
15616 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15617 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15618 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15619 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
15620 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
15621 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
15622 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
15623
15624 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
15625 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
15626 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
15627 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
15628 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
15629 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15630 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15631 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15632 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
15633 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
15634 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
15635 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
15636
15637 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
15638 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
15639 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
15640 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
15641 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
15642 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15643 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15644 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15645 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
15646 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
15647 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
15648 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
15649
15650 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
15651 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
15652 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
15653 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
15654 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
15655 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15656 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15657 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15658 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
15659 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
15660 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
15661 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
15662
15663 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
15664 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
15665 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
15666 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
15667 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
15668 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15669 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15670 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15671 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
15672 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
15673 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
15674 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
15675
15676 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
15677 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
15678 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
15679 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
15680 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
15681 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15682 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15683 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15684 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
15685 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
15686 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
15687 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
15688
15689 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
15690 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
15691 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
15692 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
15693 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
15694 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15695 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15696 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15697 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
15698 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
15699 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
15700 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
15701
15702 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15703 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15704 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15705 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15706 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15707 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15708 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15709 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15710 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15711 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15712 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15713 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15714
15715 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15716 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15717 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15718 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15719 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15720 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15721 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15722 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15723 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15724 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15725 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15726 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15727
15728 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15729 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15730 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15731 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15732 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15733 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15734 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15735 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15736 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15737 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15738 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15739 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15740
15741 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
15742 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
15743 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
15744 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
15745
15746 cCL(flts, e000110, 2, (RF, RR), rn_rd),
15747 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
15748 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
15749 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
15750 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
15751 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
15752 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
15753 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
15754 cCL(flte, e080110, 2, (RF, RR), rn_rd),
15755 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
15756 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
15757 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
15758
15759 /* The implementation of the FIX instruction is broken on some
15760 assemblers, in that it accepts a precision specifier as well as a
15761 rounding specifier, despite the fact that this is meaningless.
15762 To be more compatible, we accept it as well, though of course it
15763 does not set any bits. */
15764 cCE(fix, e100110, 2, (RR, RF), rd_rm),
15765 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
15766 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
15767 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
15768 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
15769 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
15770 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
15771 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
15772 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
15773 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
15774 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
15775 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
15776 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
15777
15778 /* Instructions that were new with the real FPA, call them V2. */
15779 #undef ARM_VARIANT
15780 #define ARM_VARIANT &fpu_fpa_ext_v2
15781 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15782 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15783 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15784 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15785 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15786 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15787
15788 #undef ARM_VARIANT
15789 #define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
15790 /* Moves and type conversions. */
15791 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
15792 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
15793 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
15794 cCE(fmstat, ef1fa10, 0, (), noargs),
15795 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
15796 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
15797 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
15798 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15799 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
15800 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15801 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
15802 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
15803
15804 /* Memory operations. */
15805 cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15806 cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15807 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15808 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15809 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15810 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15811 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15812 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15813 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15814 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15815 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15816 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15817 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15818 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15819 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15820 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15821 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15822 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15823
15824 /* Monadic operations. */
15825 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
15826 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
15827 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
15828
15829 /* Dyadic operations. */
15830 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15831 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15832 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15833 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15834 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15835 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15836 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15837 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15838 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15839
15840 /* Comparisons. */
15841 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
15842 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
15843 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
15844 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
15845
15846 #undef ARM_VARIANT
15847 #define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
15848 /* Moves and type conversions. */
15849 cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15850 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15851 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15852 cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
15853 cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
15854 cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
15855 cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
15856 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15857 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
15858 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15859 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15860 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15861 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15862
15863 /* Memory operations. */
15864 cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
15865 cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
15866 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15867 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15868 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15869 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15870 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15871 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15872 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15873 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15874
15875 /* Monadic operations. */
15876 cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15877 cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15878 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15879
15880 /* Dyadic operations. */
15881 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15882 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15883 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15884 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15885 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15886 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15887 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15888 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15889 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15890
15891 /* Comparisons. */
15892 cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15893 cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd),
15894 cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15895 cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd),
15896
15897 #undef ARM_VARIANT
15898 #define ARM_VARIANT &fpu_vfp_ext_v2
15899 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
15900 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
15901 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
15902 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
15903
15904 /* Instructions which may belong to either the Neon or VFP instruction sets.
15905 Individual encoder functions perform additional architecture checks. */
15906 #undef ARM_VARIANT
15907 #define ARM_VARIANT &fpu_vfp_ext_v1xd
15908 #undef THUMB_VARIANT
15909 #define THUMB_VARIANT &fpu_vfp_ext_v1xd
15910 /* These mnemonics are unique to VFP. */
15911 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
15912 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
15913 nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15914 nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15915 nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15916 nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15917 nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15918 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
15919 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
15920 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
15921
15922 /* Mnemonics shared by Neon and VFP. */
15923 nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
15924 nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15925 nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15926
15927 nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15928 nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15929
15930 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15931 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15932
15933 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15934 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15935 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15936 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15937 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15938 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15939 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
15940 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
15941
15942 nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
15943
15944 /* NOTE: All VMOV encoding is special-cased! */
15945 NCE(vmov, 0, 1, (VMOV), neon_mov),
15946 NCE(vmovq, 0, 1, (VMOV), neon_mov),
15947
15948 #undef THUMB_VARIANT
15949 #define THUMB_VARIANT &fpu_neon_ext_v1
15950 #undef ARM_VARIANT
15951 #define ARM_VARIANT &fpu_neon_ext_v1
15952 /* Data processing with three registers of the same length. */
15953 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
15954 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
15955 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
15956 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15957 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15958 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15959 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15960 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15961 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15962 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
15963 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15964 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15965 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15966 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15967 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15968 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
15969 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15970 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
15971 /* If not immediate, fall back to neon_dyadic_i64_su.
15972 shl_imm should accept I8 I16 I32 I64,
15973 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
15974 nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
15975 nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
15976 nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
15977 nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
15978 /* Logic ops, types optional & ignored. */
15979 nUF(vand, vand, 2, (RNDQ, NILO), neon_logic),
15980 nUF(vandq, vand, 2, (RNQ, NILO), neon_logic),
15981 nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic),
15982 nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic),
15983 nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic),
15984 nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic),
15985 nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic),
15986 nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic),
15987 nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
15988 nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
15989 /* Bitfield ops, untyped. */
15990 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15991 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15992 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15993 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15994 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15995 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15996 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
15997 nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15998 nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15999 nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
16000 nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
16001 nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
16002 nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
16003 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
16004 back to neon_dyadic_if_su. */
16005 nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
16006 nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
16007 nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
16008 nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
16009 nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16010 nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
16011 nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16012 nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
16013 /* Comparison. Type I8 I16 I32 F32. */
16014 nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
16015 nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
16016 /* As above, D registers only. */
16017 nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16018 nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16019 /* Int and float variants, signedness unimportant. */
16020 nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
16021 nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
16022 nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
16023 /* Add/sub take types I8 I16 I32 I64 F32. */
16024 nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
16025 nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
16026 /* vtst takes sizes 8, 16, 32. */
16027 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
16028 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
16029 /* VMUL takes I8 I16 I32 F32 P8. */
16030 nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
16031 /* VQD{R}MULH takes S16 S32. */
16032 nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16033 nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16034 nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16035 nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16036 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16037 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
16038 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16039 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
16040 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16041 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
16042 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16043 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
16044 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16045 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16046 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16047 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16048
16049 /* Two address, int/float. Types S8 S16 S32 F32. */
16050 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
16051 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
16052
16053 /* Data processing with two registers and a shift amount. */
16054 /* Right shifts, and variants with rounding.
16055 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
16056 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16057 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16058 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16059 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16060 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16061 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16062 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16063 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16064 /* Shift and insert. Sizes accepted 8 16 32 64. */
16065 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
16066 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
16067 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
16068 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
16069 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
16070 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
16071 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
16072 /* Right shift immediate, saturating & narrowing, with rounding variants.
16073 Types accepted S16 S32 S64 U16 U32 U64. */
16074 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16075 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16076 /* As above, unsigned. Types accepted S16 S32 S64. */
16077 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16078 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16079 /* Right shift narrowing. Types accepted I16 I32 I64. */
16080 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16081 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16082 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
16083 nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll),
16084 /* CVT with optional immediate for fixed-point variant. */
16085 nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
16086
16087 nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
16088 nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
16089
16090 /* Data processing, three registers of different lengths. */
16091 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
16092 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
16093 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
16094 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
16095 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
16096 /* If not scalar, fall back to neon_dyadic_long.
16097 Vector types as above, scalar types S16 S32 U16 U32. */
16098 nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16099 nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16100 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
16101 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16102 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16103 /* Dyadic, narrowing insns. Types I16 I32 I64. */
16104 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16105 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16106 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16107 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16108 /* Saturating doubling multiplies. Types S16 S32. */
16109 nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16110 nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16111 nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16112 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
16113 S16 S32 U16 U32. */
16114 nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
16115
16116 /* Extract. Size 8. */
16117 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
16118 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
16119
16120 /* Two registers, miscellaneous. */
16121 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
16122 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
16123 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
16124 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
16125 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
16126 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
16127 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
16128 /* Vector replicate. Sizes 8 16 32. */
16129 nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup),
16130 nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup),
16131 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
16132 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
16133 /* VMOVN. Types I16 I32 I64. */
16134 nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn),
16135 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
16136 nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn),
16137 /* VQMOVUN. Types S16 S32 S64. */
16138 nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun),
16139 /* VZIP / VUZP. Sizes 8 16 32. */
16140 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
16141 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
16142 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
16143 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
16144 /* VQABS / VQNEG. Types S8 S16 S32. */
16145 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16146 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
16147 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16148 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
16149 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
16150 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
16151 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
16152 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
16153 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
16154 /* Reciprocal estimates. Types U32 F32. */
16155 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
16156 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
16157 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
16158 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
16159 /* VCLS. Types S8 S16 S32. */
16160 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
16161 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
16162 /* VCLZ. Types I8 I16 I32. */
16163 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
16164 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
16165 /* VCNT. Size 8. */
16166 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
16167 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
16168 /* Two address, untyped. */
16169 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
16170 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
16171 /* VTRN. Sizes 8 16 32. */
16172 nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn),
16173 nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn),
16174
16175 /* Table lookup. Size 8. */
16176 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16177 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16178
16179 #undef THUMB_VARIANT
16180 #define THUMB_VARIANT &fpu_vfp_v3_or_neon_ext
16181 #undef ARM_VARIANT
16182 #define ARM_VARIANT &fpu_vfp_v3_or_neon_ext
16183 /* Neon element/structure load/store. */
16184 nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16185 nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16186 nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16187 nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16188 nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16189 nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16190 nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16191 nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16192
16193 #undef THUMB_VARIANT
16194 #define THUMB_VARIANT &fpu_vfp_ext_v3
16195 #undef ARM_VARIANT
16196 #define ARM_VARIANT &fpu_vfp_ext_v3
16197 cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const),
16198 cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const),
16199 cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16200 cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16201 cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16202 cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16203 cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16204 cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16205 cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16206 cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16207 cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16208 cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16209 cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16210 cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16211 cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16212 cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16213 cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16214 cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16215
16216 #undef THUMB_VARIANT
16217 #undef ARM_VARIANT
16218 #define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
16219 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16220 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16221 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16222 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16223 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16224 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16225 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
16226 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
16227
16228 #undef ARM_VARIANT
16229 #define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
16230 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
16231 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
16232 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
16233 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
16234 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
16235 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
16236 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
16237 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
16238 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
16239 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16240 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16241 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16242 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16243 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16244 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16245 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16246 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16247 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16248 cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd),
16249 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
16250 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16251 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16252 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16253 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16254 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16255 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16256 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
16257 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
16258 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
16259 cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn),
16260 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
16261 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
16262 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
16263 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
16264 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
16265 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
16266 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
16267 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16268 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16269 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16270 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16271 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16272 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16273 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16274 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16275 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16276 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
16277 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16278 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16279 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16280 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16281 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16282 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16283 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16284 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16285 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16286 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16287 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16288 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16289 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16290 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16291 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16292 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16293 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16294 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16295 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16296 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16297 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16298 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16299 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16300 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16301 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16302 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16303 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16304 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16305 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16306 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16307 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16308 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16309 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16310 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16311 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16312 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16313 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16314 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16315 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16316 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16317 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16318 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
16319 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16320 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16321 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16322 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16323 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16324 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16325 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16326 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16327 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16328 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16329 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16330 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16331 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16332 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16333 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16334 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16335 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16336 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16337 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16338 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16339 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16340 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
16341 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16342 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16343 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16344 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16345 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16346 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16347 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16348 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16349 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16350 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16351 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16352 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16353 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16354 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16355 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16356 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16357 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16358 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16359 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16360 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16361 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16362 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16363 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16364 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16365 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16366 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16367 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16368 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16369 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16370 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16371 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16372 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
16373 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
16374 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
16375 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
16376 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
16377 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
16378 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16379 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16380 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16381 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
16382 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
16383 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
16384 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
16385 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
16386 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
16387 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16388 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16389 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16390 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16391 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
16392
16393 #undef ARM_VARIANT
16394 #define ARM_VARIANT &arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
16395 cCE(torvscb, e13f190, 1, (RR), iwmmxt_tandorc),
16396 cCE(torvsch, e53f190, 1, (RR), iwmmxt_tandorc),
16397 cCE(torvscw, e93f190, 1, (RR), iwmmxt_tandorc),
16398 cCE(wabsb, e2001c0, 2, (RIWR, RIWR), rd_rn),
16399 cCE(wabsh, e6001c0, 2, (RIWR, RIWR), rd_rn),
16400 cCE(wabsw, ea001c0, 2, (RIWR, RIWR), rd_rn),
16401 cCE(wabsdiffb, e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16402 cCE(wabsdiffh, e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16403 cCE(wabsdiffw, e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16404 cCE(waddbhusl, e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16405 cCE(waddbhusm, e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16406 cCE(waddhc, e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16407 cCE(waddwc, ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16408 cCE(waddsubhx, ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16409 cCE(wavg4, e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16410 cCE(wavg4r, e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16411 cCE(wmaddsn, ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16412 cCE(wmaddsx, eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16413 cCE(wmaddun, ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16414 cCE(wmaddux, e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16415 cCE(wmerge, e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
16416 cCE(wmiabb, e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16417 cCE(wmiabt, e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16418 cCE(wmiatb, e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16419 cCE(wmiatt, e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16420 cCE(wmiabbn, e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16421 cCE(wmiabtn, e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16422 cCE(wmiatbn, e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16423 cCE(wmiattn, e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16424 cCE(wmiawbb, e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16425 cCE(wmiawbt, e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16426 cCE(wmiawtb, ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16427 cCE(wmiawtt, eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16428 cCE(wmiawbbn, ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16429 cCE(wmiawbtn, ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16430 cCE(wmiawtbn, ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16431 cCE(wmiawttn, ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16432 cCE(wmulsmr, ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16433 cCE(wmulumr, ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16434 cCE(wmulwumr, ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16435 cCE(wmulwsmr, ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16436 cCE(wmulwum, ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16437 cCE(wmulwsm, ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16438 cCE(wmulwl, eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16439 cCE(wqmiabb, e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16440 cCE(wqmiabt, e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16441 cCE(wqmiatb, ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16442 cCE(wqmiatt, eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16443 cCE(wqmiabbn, ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16444 cCE(wqmiabtn, ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16445 cCE(wqmiatbn, ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16446 cCE(wqmiattn, ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16447 cCE(wqmulm, e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16448 cCE(wqmulmr, e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16449 cCE(wqmulwm, ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16450 cCE(wqmulwmr, ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16451 cCE(wsubaddhx, ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16452
16453 #undef ARM_VARIANT
16454 #define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
16455 cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16456 cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16457 cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16458 cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
16459 cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16460 cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16461 cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16462 cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
16463 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
16464 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
16465 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
16466 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
16467 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
16468 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
16469 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
16470 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
16471 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
16472 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
16473 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
16474 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
16475 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
16476 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
16477 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
16478 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
16479 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
16480 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
16481 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
16482 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
16483 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
16484 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
16485 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
16486 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
16487 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
16488 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
16489 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
16490 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
16491 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
16492 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
16493 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
16494 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
16495 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
16496 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
16497 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
16498 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
16499 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
16500 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
16501 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
16502 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
16503 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
16504 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
16505 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
16506 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
16507 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
16508 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
16509 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
16510 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
16511 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
16512 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
16513 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
16514 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
16515 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
16516 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
16517 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
16518 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
16519 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16520 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16521 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16522 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16523 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16524 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16525 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16526 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16527 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16528 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16529 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
16530 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
16531 };
16532 #undef ARM_VARIANT
16533 #undef THUMB_VARIANT
16534 #undef TCE
16535 #undef TCM
16536 #undef TUE
16537 #undef TUF
16538 #undef TCC
16539 #undef cCE
16540 #undef cCL
16541 #undef C3E
16542 #undef CE
16543 #undef CM
16544 #undef UE
16545 #undef UF
16546 #undef UT
16547 #undef NUF
16548 #undef nUF
16549 #undef NCE
16550 #undef nCE
16551 #undef OPS0
16552 #undef OPS1
16553 #undef OPS2
16554 #undef OPS3
16555 #undef OPS4
16556 #undef OPS5
16557 #undef OPS6
16558 #undef do_0
16559 \f
16560 /* MD interface: bits in the object file. */
16561
16562 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
16563 for use in the a.out file, and stores them in the array pointed to by buf.
16564 This knows about the endian-ness of the target machine and does
16565 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
16566 2 (short) and 4 (long) Floating numbers are put out as a series of
16567 LITTLENUMS (shorts, here at least). */
16568
16569 void
16570 md_number_to_chars (char * buf, valueT val, int n)
16571 {
16572 if (target_big_endian)
16573 number_to_chars_bigendian (buf, val, n);
16574 else
16575 number_to_chars_littleendian (buf, val, n);
16576 }
16577
16578 static valueT
16579 md_chars_to_number (char * buf, int n)
16580 {
16581 valueT result = 0;
16582 unsigned char * where = (unsigned char *) buf;
16583
16584 if (target_big_endian)
16585 {
16586 while (n--)
16587 {
16588 result <<= 8;
16589 result |= (*where++ & 255);
16590 }
16591 }
16592 else
16593 {
16594 while (n--)
16595 {
16596 result <<= 8;
16597 result |= (where[n] & 255);
16598 }
16599 }
16600
16601 return result;
16602 }
16603
16604 /* MD interface: Sections. */
16605
16606 /* Estimate the size of a frag before relaxing. Assume everything fits in
16607 2 bytes. */
16608
16609 int
16610 md_estimate_size_before_relax (fragS * fragp,
16611 segT segtype ATTRIBUTE_UNUSED)
16612 {
16613 fragp->fr_var = 2;
16614 return 2;
16615 }
16616
16617 /* Convert a machine dependent frag. */
16618
16619 void
16620 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
16621 {
16622 unsigned long insn;
16623 unsigned long old_op;
16624 char *buf;
16625 expressionS exp;
16626 fixS *fixp;
16627 int reloc_type;
16628 int pc_rel;
16629 int opcode;
16630
16631 buf = fragp->fr_literal + fragp->fr_fix;
16632
16633 old_op = bfd_get_16(abfd, buf);
16634 if (fragp->fr_symbol)
16635 {
16636 exp.X_op = O_symbol;
16637 exp.X_add_symbol = fragp->fr_symbol;
16638 }
16639 else
16640 {
16641 exp.X_op = O_constant;
16642 }
16643 exp.X_add_number = fragp->fr_offset;
16644 opcode = fragp->fr_subtype;
16645 switch (opcode)
16646 {
16647 case T_MNEM_ldr_pc:
16648 case T_MNEM_ldr_pc2:
16649 case T_MNEM_ldr_sp:
16650 case T_MNEM_str_sp:
16651 case T_MNEM_ldr:
16652 case T_MNEM_ldrb:
16653 case T_MNEM_ldrh:
16654 case T_MNEM_str:
16655 case T_MNEM_strb:
16656 case T_MNEM_strh:
16657 if (fragp->fr_var == 4)
16658 {
16659 insn = THUMB_OP32 (opcode);
16660 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
16661 {
16662 insn |= (old_op & 0x700) << 4;
16663 }
16664 else
16665 {
16666 insn |= (old_op & 7) << 12;
16667 insn |= (old_op & 0x38) << 13;
16668 }
16669 insn |= 0x00000c00;
16670 put_thumb32_insn (buf, insn);
16671 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
16672 }
16673 else
16674 {
16675 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
16676 }
16677 pc_rel = (opcode == T_MNEM_ldr_pc2);
16678 break;
16679 case T_MNEM_adr:
16680 if (fragp->fr_var == 4)
16681 {
16682 insn = THUMB_OP32 (opcode);
16683 insn |= (old_op & 0xf0) << 4;
16684 put_thumb32_insn (buf, insn);
16685 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
16686 }
16687 else
16688 {
16689 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16690 exp.X_add_number -= 4;
16691 }
16692 pc_rel = 1;
16693 break;
16694 case T_MNEM_mov:
16695 case T_MNEM_movs:
16696 case T_MNEM_cmp:
16697 case T_MNEM_cmn:
16698 if (fragp->fr_var == 4)
16699 {
16700 int r0off = (opcode == T_MNEM_mov
16701 || opcode == T_MNEM_movs) ? 0 : 8;
16702 insn = THUMB_OP32 (opcode);
16703 insn = (insn & 0xe1ffffff) | 0x10000000;
16704 insn |= (old_op & 0x700) << r0off;
16705 put_thumb32_insn (buf, insn);
16706 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16707 }
16708 else
16709 {
16710 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
16711 }
16712 pc_rel = 0;
16713 break;
16714 case T_MNEM_b:
16715 if (fragp->fr_var == 4)
16716 {
16717 insn = THUMB_OP32(opcode);
16718 put_thumb32_insn (buf, insn);
16719 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
16720 }
16721 else
16722 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
16723 pc_rel = 1;
16724 break;
16725 case T_MNEM_bcond:
16726 if (fragp->fr_var == 4)
16727 {
16728 insn = THUMB_OP32(opcode);
16729 insn |= (old_op & 0xf00) << 14;
16730 put_thumb32_insn (buf, insn);
16731 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
16732 }
16733 else
16734 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
16735 pc_rel = 1;
16736 break;
16737 case T_MNEM_add_sp:
16738 case T_MNEM_add_pc:
16739 case T_MNEM_inc_sp:
16740 case T_MNEM_dec_sp:
16741 if (fragp->fr_var == 4)
16742 {
16743 /* ??? Choose between add and addw. */
16744 insn = THUMB_OP32 (opcode);
16745 insn |= (old_op & 0xf0) << 4;
16746 put_thumb32_insn (buf, insn);
16747 if (opcode == T_MNEM_add_pc)
16748 reloc_type = BFD_RELOC_ARM_T32_IMM12;
16749 else
16750 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16751 }
16752 else
16753 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16754 pc_rel = 0;
16755 break;
16756
16757 case T_MNEM_addi:
16758 case T_MNEM_addis:
16759 case T_MNEM_subi:
16760 case T_MNEM_subis:
16761 if (fragp->fr_var == 4)
16762 {
16763 insn = THUMB_OP32 (opcode);
16764 insn |= (old_op & 0xf0) << 4;
16765 insn |= (old_op & 0xf) << 16;
16766 put_thumb32_insn (buf, insn);
16767 if (insn & (1 << 20))
16768 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16769 else
16770 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16771 }
16772 else
16773 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16774 pc_rel = 0;
16775 break;
16776 default:
16777 abort ();
16778 }
16779 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
16780 reloc_type);
16781 fixp->fx_file = fragp->fr_file;
16782 fixp->fx_line = fragp->fr_line;
16783 fragp->fr_fix += fragp->fr_var;
16784 }
16785
16786 /* Return the size of a relaxable immediate operand instruction.
16787 SHIFT and SIZE specify the form of the allowable immediate. */
16788 static int
16789 relax_immediate (fragS *fragp, int size, int shift)
16790 {
16791 offsetT offset;
16792 offsetT mask;
16793 offsetT low;
16794
16795 /* ??? Should be able to do better than this. */
16796 if (fragp->fr_symbol)
16797 return 4;
16798
16799 low = (1 << shift) - 1;
16800 mask = (1 << (shift + size)) - (1 << shift);
16801 offset = fragp->fr_offset;
16802 /* Force misaligned offsets to 32-bit variant. */
16803 if (offset & low)
16804 return 4;
16805 if (offset & ~mask)
16806 return 4;
16807 return 2;
16808 }
16809
16810 /* Get the address of a symbol during relaxation. */
16811 static addressT
16812 relaxed_symbol_addr (fragS *fragp, long stretch)
16813 {
16814 fragS *sym_frag;
16815 addressT addr;
16816 symbolS *sym;
16817
16818 sym = fragp->fr_symbol;
16819 sym_frag = symbol_get_frag (sym);
16820 know (S_GET_SEGMENT (sym) != absolute_section
16821 || sym_frag == &zero_address_frag);
16822 addr = S_GET_VALUE (sym) + fragp->fr_offset;
16823
16824 /* If frag has yet to be reached on this pass, assume it will
16825 move by STRETCH just as we did. If this is not so, it will
16826 be because some frag between grows, and that will force
16827 another pass. */
16828
16829 if (stretch != 0
16830 && sym_frag->relax_marker != fragp->relax_marker)
16831 {
16832 fragS *f;
16833
16834 /* Adjust stretch for any alignment frag. Note that if have
16835 been expanding the earlier code, the symbol may be
16836 defined in what appears to be an earlier frag. FIXME:
16837 This doesn't handle the fr_subtype field, which specifies
16838 a maximum number of bytes to skip when doing an
16839 alignment. */
16840 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
16841 {
16842 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
16843 {
16844 if (stretch < 0)
16845 stretch = - ((- stretch)
16846 & ~ ((1 << (int) f->fr_offset) - 1));
16847 else
16848 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
16849 if (stretch == 0)
16850 break;
16851 }
16852 }
16853 if (f != NULL)
16854 addr += stretch;
16855 }
16856
16857 return addr;
16858 }
16859
16860 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
16861 load. */
16862 static int
16863 relax_adr (fragS *fragp, asection *sec, long stretch)
16864 {
16865 addressT addr;
16866 offsetT val;
16867
16868 /* Assume worst case for symbols not known to be in the same section. */
16869 if (!S_IS_DEFINED (fragp->fr_symbol)
16870 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16871 return 4;
16872
16873 val = relaxed_symbol_addr (fragp, stretch);
16874 addr = fragp->fr_address + fragp->fr_fix;
16875 addr = (addr + 4) & ~3;
16876 /* Force misaligned targets to 32-bit variant. */
16877 if (val & 3)
16878 return 4;
16879 val -= addr;
16880 if (val < 0 || val > 1020)
16881 return 4;
16882 return 2;
16883 }
16884
16885 /* Return the size of a relaxable add/sub immediate instruction. */
16886 static int
16887 relax_addsub (fragS *fragp, asection *sec)
16888 {
16889 char *buf;
16890 int op;
16891
16892 buf = fragp->fr_literal + fragp->fr_fix;
16893 op = bfd_get_16(sec->owner, buf);
16894 if ((op & 0xf) == ((op >> 4) & 0xf))
16895 return relax_immediate (fragp, 8, 0);
16896 else
16897 return relax_immediate (fragp, 3, 0);
16898 }
16899
16900
16901 /* Return the size of a relaxable branch instruction. BITS is the
16902 size of the offset field in the narrow instruction. */
16903
16904 static int
16905 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
16906 {
16907 addressT addr;
16908 offsetT val;
16909 offsetT limit;
16910
16911 /* Assume worst case for symbols not known to be in the same section. */
16912 if (!S_IS_DEFINED (fragp->fr_symbol)
16913 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16914 return 4;
16915
16916 val = relaxed_symbol_addr (fragp, stretch);
16917 addr = fragp->fr_address + fragp->fr_fix + 4;
16918 val -= addr;
16919
16920 /* Offset is a signed value *2 */
16921 limit = 1 << bits;
16922 if (val >= limit || val < -limit)
16923 return 4;
16924 return 2;
16925 }
16926
16927
16928 /* Relax a machine dependent frag. This returns the amount by which
16929 the current size of the frag should change. */
16930
16931 int
16932 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
16933 {
16934 int oldsize;
16935 int newsize;
16936
16937 oldsize = fragp->fr_var;
16938 switch (fragp->fr_subtype)
16939 {
16940 case T_MNEM_ldr_pc2:
16941 newsize = relax_adr (fragp, sec, stretch);
16942 break;
16943 case T_MNEM_ldr_pc:
16944 case T_MNEM_ldr_sp:
16945 case T_MNEM_str_sp:
16946 newsize = relax_immediate (fragp, 8, 2);
16947 break;
16948 case T_MNEM_ldr:
16949 case T_MNEM_str:
16950 newsize = relax_immediate (fragp, 5, 2);
16951 break;
16952 case T_MNEM_ldrh:
16953 case T_MNEM_strh:
16954 newsize = relax_immediate (fragp, 5, 1);
16955 break;
16956 case T_MNEM_ldrb:
16957 case T_MNEM_strb:
16958 newsize = relax_immediate (fragp, 5, 0);
16959 break;
16960 case T_MNEM_adr:
16961 newsize = relax_adr (fragp, sec, stretch);
16962 break;
16963 case T_MNEM_mov:
16964 case T_MNEM_movs:
16965 case T_MNEM_cmp:
16966 case T_MNEM_cmn:
16967 newsize = relax_immediate (fragp, 8, 0);
16968 break;
16969 case T_MNEM_b:
16970 newsize = relax_branch (fragp, sec, 11, stretch);
16971 break;
16972 case T_MNEM_bcond:
16973 newsize = relax_branch (fragp, sec, 8, stretch);
16974 break;
16975 case T_MNEM_add_sp:
16976 case T_MNEM_add_pc:
16977 newsize = relax_immediate (fragp, 8, 2);
16978 break;
16979 case T_MNEM_inc_sp:
16980 case T_MNEM_dec_sp:
16981 newsize = relax_immediate (fragp, 7, 2);
16982 break;
16983 case T_MNEM_addi:
16984 case T_MNEM_addis:
16985 case T_MNEM_subi:
16986 case T_MNEM_subis:
16987 newsize = relax_addsub (fragp, sec);
16988 break;
16989 default:
16990 abort ();
16991 }
16992
16993 fragp->fr_var = newsize;
16994 /* Freeze wide instructions that are at or before the same location as
16995 in the previous pass. This avoids infinite loops.
16996 Don't freeze them unconditionally because targets may be artificially
16997 misaligned by the expansion of preceding frags. */
16998 if (stretch <= 0 && newsize > 2)
16999 {
17000 md_convert_frag (sec->owner, sec, fragp);
17001 frag_wane (fragp);
17002 }
17003
17004 return newsize - oldsize;
17005 }
17006
17007 /* Round up a section size to the appropriate boundary. */
17008
17009 valueT
17010 md_section_align (segT segment ATTRIBUTE_UNUSED,
17011 valueT size)
17012 {
17013 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
17014 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
17015 {
17016 /* For a.out, force the section size to be aligned. If we don't do
17017 this, BFD will align it for us, but it will not write out the
17018 final bytes of the section. This may be a bug in BFD, but it is
17019 easier to fix it here since that is how the other a.out targets
17020 work. */
17021 int align;
17022
17023 align = bfd_get_section_alignment (stdoutput, segment);
17024 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
17025 }
17026 #endif
17027
17028 return size;
17029 }
17030
17031 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
17032 of an rs_align_code fragment. */
17033
17034 void
17035 arm_handle_align (fragS * fragP)
17036 {
17037 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
17038 static char const thumb_noop[2] = { 0xc0, 0x46 };
17039 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
17040 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
17041
17042 int bytes, fix, noop_size;
17043 char * p;
17044 const char * noop;
17045
17046 if (fragP->fr_type != rs_align_code)
17047 return;
17048
17049 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
17050 p = fragP->fr_literal + fragP->fr_fix;
17051 fix = 0;
17052
17053 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
17054 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
17055
17056 if (fragP->tc_frag_data)
17057 {
17058 if (target_big_endian)
17059 noop = thumb_bigend_noop;
17060 else
17061 noop = thumb_noop;
17062 noop_size = sizeof (thumb_noop);
17063 }
17064 else
17065 {
17066 if (target_big_endian)
17067 noop = arm_bigend_noop;
17068 else
17069 noop = arm_noop;
17070 noop_size = sizeof (arm_noop);
17071 }
17072
17073 if (bytes & (noop_size - 1))
17074 {
17075 fix = bytes & (noop_size - 1);
17076 memset (p, 0, fix);
17077 p += fix;
17078 bytes -= fix;
17079 }
17080
17081 while (bytes >= noop_size)
17082 {
17083 memcpy (p, noop, noop_size);
17084 p += noop_size;
17085 bytes -= noop_size;
17086 fix += noop_size;
17087 }
17088
17089 fragP->fr_fix += fix;
17090 fragP->fr_var = noop_size;
17091 }
17092
17093 /* Called from md_do_align. Used to create an alignment
17094 frag in a code section. */
17095
17096 void
17097 arm_frag_align_code (int n, int max)
17098 {
17099 char * p;
17100
17101 /* We assume that there will never be a requirement
17102 to support alignments greater than 32 bytes. */
17103 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
17104 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
17105
17106 p = frag_var (rs_align_code,
17107 MAX_MEM_FOR_RS_ALIGN_CODE,
17108 1,
17109 (relax_substateT) max,
17110 (symbolS *) NULL,
17111 (offsetT) n,
17112 (char *) NULL);
17113 *p = 0;
17114 }
17115
17116 /* Perform target specific initialisation of a frag. */
17117
17118 void
17119 arm_init_frag (fragS * fragP)
17120 {
17121 /* Record whether this frag is in an ARM or a THUMB area. */
17122 fragP->tc_frag_data = thumb_mode;
17123 }
17124
17125 #ifdef OBJ_ELF
17126 /* When we change sections we need to issue a new mapping symbol. */
17127
17128 void
17129 arm_elf_change_section (void)
17130 {
17131 flagword flags;
17132 segment_info_type *seginfo;
17133
17134 /* Link an unlinked unwind index table section to the .text section. */
17135 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
17136 && elf_linked_to_section (now_seg) == NULL)
17137 elf_linked_to_section (now_seg) = text_section;
17138
17139 if (!SEG_NORMAL (now_seg))
17140 return;
17141
17142 flags = bfd_get_section_flags (stdoutput, now_seg);
17143
17144 /* We can ignore sections that only contain debug info. */
17145 if ((flags & SEC_ALLOC) == 0)
17146 return;
17147
17148 seginfo = seg_info (now_seg);
17149 mapstate = seginfo->tc_segment_info_data.mapstate;
17150 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
17151 }
17152
17153 int
17154 arm_elf_section_type (const char * str, size_t len)
17155 {
17156 if (len == 5 && strncmp (str, "exidx", 5) == 0)
17157 return SHT_ARM_EXIDX;
17158
17159 return -1;
17160 }
17161 \f
17162 /* Code to deal with unwinding tables. */
17163
17164 static void add_unwind_adjustsp (offsetT);
17165
17166 /* Generate any deferred unwind frame offset. */
17167
17168 static void
17169 flush_pending_unwind (void)
17170 {
17171 offsetT offset;
17172
17173 offset = unwind.pending_offset;
17174 unwind.pending_offset = 0;
17175 if (offset != 0)
17176 add_unwind_adjustsp (offset);
17177 }
17178
17179 /* Add an opcode to this list for this function. Two-byte opcodes should
17180 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
17181 order. */
17182
17183 static void
17184 add_unwind_opcode (valueT op, int length)
17185 {
17186 /* Add any deferred stack adjustment. */
17187 if (unwind.pending_offset)
17188 flush_pending_unwind ();
17189
17190 unwind.sp_restored = 0;
17191
17192 if (unwind.opcode_count + length > unwind.opcode_alloc)
17193 {
17194 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
17195 if (unwind.opcodes)
17196 unwind.opcodes = xrealloc (unwind.opcodes,
17197 unwind.opcode_alloc);
17198 else
17199 unwind.opcodes = xmalloc (unwind.opcode_alloc);
17200 }
17201 while (length > 0)
17202 {
17203 length--;
17204 unwind.opcodes[unwind.opcode_count] = op & 0xff;
17205 op >>= 8;
17206 unwind.opcode_count++;
17207 }
17208 }
17209
17210 /* Add unwind opcodes to adjust the stack pointer. */
17211
17212 static void
17213 add_unwind_adjustsp (offsetT offset)
17214 {
17215 valueT op;
17216
17217 if (offset > 0x200)
17218 {
17219 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
17220 char bytes[5];
17221 int n;
17222 valueT o;
17223
17224 /* Long form: 0xb2, uleb128. */
17225 /* This might not fit in a word so add the individual bytes,
17226 remembering the list is built in reverse order. */
17227 o = (valueT) ((offset - 0x204) >> 2);
17228 if (o == 0)
17229 add_unwind_opcode (0, 1);
17230
17231 /* Calculate the uleb128 encoding of the offset. */
17232 n = 0;
17233 while (o)
17234 {
17235 bytes[n] = o & 0x7f;
17236 o >>= 7;
17237 if (o)
17238 bytes[n] |= 0x80;
17239 n++;
17240 }
17241 /* Add the insn. */
17242 for (; n; n--)
17243 add_unwind_opcode (bytes[n - 1], 1);
17244 add_unwind_opcode (0xb2, 1);
17245 }
17246 else if (offset > 0x100)
17247 {
17248 /* Two short opcodes. */
17249 add_unwind_opcode (0x3f, 1);
17250 op = (offset - 0x104) >> 2;
17251 add_unwind_opcode (op, 1);
17252 }
17253 else if (offset > 0)
17254 {
17255 /* Short opcode. */
17256 op = (offset - 4) >> 2;
17257 add_unwind_opcode (op, 1);
17258 }
17259 else if (offset < 0)
17260 {
17261 offset = -offset;
17262 while (offset > 0x100)
17263 {
17264 add_unwind_opcode (0x7f, 1);
17265 offset -= 0x100;
17266 }
17267 op = ((offset - 4) >> 2) | 0x40;
17268 add_unwind_opcode (op, 1);
17269 }
17270 }
17271
17272 /* Finish the list of unwind opcodes for this function. */
17273 static void
17274 finish_unwind_opcodes (void)
17275 {
17276 valueT op;
17277
17278 if (unwind.fp_used)
17279 {
17280 /* Adjust sp as necessary. */
17281 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
17282 flush_pending_unwind ();
17283
17284 /* After restoring sp from the frame pointer. */
17285 op = 0x90 | unwind.fp_reg;
17286 add_unwind_opcode (op, 1);
17287 }
17288 else
17289 flush_pending_unwind ();
17290 }
17291
17292
17293 /* Start an exception table entry. If idx is nonzero this is an index table
17294 entry. */
17295
17296 static void
17297 start_unwind_section (const segT text_seg, int idx)
17298 {
17299 const char * text_name;
17300 const char * prefix;
17301 const char * prefix_once;
17302 const char * group_name;
17303 size_t prefix_len;
17304 size_t text_len;
17305 char * sec_name;
17306 size_t sec_name_len;
17307 int type;
17308 int flags;
17309 int linkonce;
17310
17311 if (idx)
17312 {
17313 prefix = ELF_STRING_ARM_unwind;
17314 prefix_once = ELF_STRING_ARM_unwind_once;
17315 type = SHT_ARM_EXIDX;
17316 }
17317 else
17318 {
17319 prefix = ELF_STRING_ARM_unwind_info;
17320 prefix_once = ELF_STRING_ARM_unwind_info_once;
17321 type = SHT_PROGBITS;
17322 }
17323
17324 text_name = segment_name (text_seg);
17325 if (streq (text_name, ".text"))
17326 text_name = "";
17327
17328 if (strncmp (text_name, ".gnu.linkonce.t.",
17329 strlen (".gnu.linkonce.t.")) == 0)
17330 {
17331 prefix = prefix_once;
17332 text_name += strlen (".gnu.linkonce.t.");
17333 }
17334
17335 prefix_len = strlen (prefix);
17336 text_len = strlen (text_name);
17337 sec_name_len = prefix_len + text_len;
17338 sec_name = xmalloc (sec_name_len + 1);
17339 memcpy (sec_name, prefix, prefix_len);
17340 memcpy (sec_name + prefix_len, text_name, text_len);
17341 sec_name[prefix_len + text_len] = '\0';
17342
17343 flags = SHF_ALLOC;
17344 linkonce = 0;
17345 group_name = 0;
17346
17347 /* Handle COMDAT group. */
17348 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
17349 {
17350 group_name = elf_group_name (text_seg);
17351 if (group_name == NULL)
17352 {
17353 as_bad (_("Group section `%s' has no group signature"),
17354 segment_name (text_seg));
17355 ignore_rest_of_line ();
17356 return;
17357 }
17358 flags |= SHF_GROUP;
17359 linkonce = 1;
17360 }
17361
17362 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
17363
17364 /* Set the section link for index tables. */
17365 if (idx)
17366 elf_linked_to_section (now_seg) = text_seg;
17367 }
17368
17369
17370 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
17371 personality routine data. Returns zero, or the index table value for
17372 and inline entry. */
17373
17374 static valueT
17375 create_unwind_entry (int have_data)
17376 {
17377 int size;
17378 addressT where;
17379 char *ptr;
17380 /* The current word of data. */
17381 valueT data;
17382 /* The number of bytes left in this word. */
17383 int n;
17384
17385 finish_unwind_opcodes ();
17386
17387 /* Remember the current text section. */
17388 unwind.saved_seg = now_seg;
17389 unwind.saved_subseg = now_subseg;
17390
17391 start_unwind_section (now_seg, 0);
17392
17393 if (unwind.personality_routine == NULL)
17394 {
17395 if (unwind.personality_index == -2)
17396 {
17397 if (have_data)
17398 as_bad (_("handlerdata in cantunwind frame"));
17399 return 1; /* EXIDX_CANTUNWIND. */
17400 }
17401
17402 /* Use a default personality routine if none is specified. */
17403 if (unwind.personality_index == -1)
17404 {
17405 if (unwind.opcode_count > 3)
17406 unwind.personality_index = 1;
17407 else
17408 unwind.personality_index = 0;
17409 }
17410
17411 /* Space for the personality routine entry. */
17412 if (unwind.personality_index == 0)
17413 {
17414 if (unwind.opcode_count > 3)
17415 as_bad (_("too many unwind opcodes for personality routine 0"));
17416
17417 if (!have_data)
17418 {
17419 /* All the data is inline in the index table. */
17420 data = 0x80;
17421 n = 3;
17422 while (unwind.opcode_count > 0)
17423 {
17424 unwind.opcode_count--;
17425 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17426 n--;
17427 }
17428
17429 /* Pad with "finish" opcodes. */
17430 while (n--)
17431 data = (data << 8) | 0xb0;
17432
17433 return data;
17434 }
17435 size = 0;
17436 }
17437 else
17438 /* We get two opcodes "free" in the first word. */
17439 size = unwind.opcode_count - 2;
17440 }
17441 else
17442 /* An extra byte is required for the opcode count. */
17443 size = unwind.opcode_count + 1;
17444
17445 size = (size + 3) >> 2;
17446 if (size > 0xff)
17447 as_bad (_("too many unwind opcodes"));
17448
17449 frag_align (2, 0, 0);
17450 record_alignment (now_seg, 2);
17451 unwind.table_entry = expr_build_dot ();
17452
17453 /* Allocate the table entry. */
17454 ptr = frag_more ((size << 2) + 4);
17455 where = frag_now_fix () - ((size << 2) + 4);
17456
17457 switch (unwind.personality_index)
17458 {
17459 case -1:
17460 /* ??? Should this be a PLT generating relocation? */
17461 /* Custom personality routine. */
17462 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
17463 BFD_RELOC_ARM_PREL31);
17464
17465 where += 4;
17466 ptr += 4;
17467
17468 /* Set the first byte to the number of additional words. */
17469 data = size - 1;
17470 n = 3;
17471 break;
17472
17473 /* ABI defined personality routines. */
17474 case 0:
17475 /* Three opcodes bytes are packed into the first word. */
17476 data = 0x80;
17477 n = 3;
17478 break;
17479
17480 case 1:
17481 case 2:
17482 /* The size and first two opcode bytes go in the first word. */
17483 data = ((0x80 + unwind.personality_index) << 8) | size;
17484 n = 2;
17485 break;
17486
17487 default:
17488 /* Should never happen. */
17489 abort ();
17490 }
17491
17492 /* Pack the opcodes into words (MSB first), reversing the list at the same
17493 time. */
17494 while (unwind.opcode_count > 0)
17495 {
17496 if (n == 0)
17497 {
17498 md_number_to_chars (ptr, data, 4);
17499 ptr += 4;
17500 n = 4;
17501 data = 0;
17502 }
17503 unwind.opcode_count--;
17504 n--;
17505 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17506 }
17507
17508 /* Finish off the last word. */
17509 if (n < 4)
17510 {
17511 /* Pad with "finish" opcodes. */
17512 while (n--)
17513 data = (data << 8) | 0xb0;
17514
17515 md_number_to_chars (ptr, data, 4);
17516 }
17517
17518 if (!have_data)
17519 {
17520 /* Add an empty descriptor if there is no user-specified data. */
17521 ptr = frag_more (4);
17522 md_number_to_chars (ptr, 0, 4);
17523 }
17524
17525 return 0;
17526 }
17527
17528
17529 /* Initialize the DWARF-2 unwind information for this procedure. */
17530
17531 void
17532 tc_arm_frame_initial_instructions (void)
17533 {
17534 cfi_add_CFA_def_cfa (REG_SP, 0);
17535 }
17536 #endif /* OBJ_ELF */
17537
17538 /* Convert REGNAME to a DWARF-2 register number. */
17539
17540 int
17541 tc_arm_regname_to_dw2regnum (char *regname)
17542 {
17543 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
17544
17545 if (reg == FAIL)
17546 return -1;
17547
17548 return reg;
17549 }
17550
17551 #ifdef TE_PE
17552 void
17553 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
17554 {
17555 expressionS expr;
17556
17557 expr.X_op = O_secrel;
17558 expr.X_add_symbol = symbol;
17559 expr.X_add_number = 0;
17560 emit_expr (&expr, size);
17561 }
17562 #endif
17563
17564 /* MD interface: Symbol and relocation handling. */
17565
17566 /* Return the address within the segment that a PC-relative fixup is
17567 relative to. For ARM, PC-relative fixups applied to instructions
17568 are generally relative to the location of the fixup plus 8 bytes.
17569 Thumb branches are offset by 4, and Thumb loads relative to PC
17570 require special handling. */
17571
17572 long
17573 md_pcrel_from_section (fixS * fixP, segT seg)
17574 {
17575 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
17576
17577 /* If this is pc-relative and we are going to emit a relocation
17578 then we just want to put out any pipeline compensation that the linker
17579 will need. Otherwise we want to use the calculated base.
17580 For WinCE we skip the bias for externals as well, since this
17581 is how the MS ARM-CE assembler behaves and we want to be compatible. */
17582 if (fixP->fx_pcrel
17583 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
17584 || (arm_force_relocation (fixP)
17585 #ifdef TE_WINCE
17586 && !S_IS_EXTERNAL (fixP->fx_addsy)
17587 #endif
17588 )))
17589 base = 0;
17590
17591 switch (fixP->fx_r_type)
17592 {
17593 /* PC relative addressing on the Thumb is slightly odd as the
17594 bottom two bits of the PC are forced to zero for the
17595 calculation. This happens *after* application of the
17596 pipeline offset. However, Thumb adrl already adjusts for
17597 this, so we need not do it again. */
17598 case BFD_RELOC_ARM_THUMB_ADD:
17599 return base & ~3;
17600
17601 case BFD_RELOC_ARM_THUMB_OFFSET:
17602 case BFD_RELOC_ARM_T32_OFFSET_IMM:
17603 case BFD_RELOC_ARM_T32_ADD_PC12:
17604 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
17605 return (base + 4) & ~3;
17606
17607 /* Thumb branches are simply offset by +4. */
17608 case BFD_RELOC_THUMB_PCREL_BRANCH7:
17609 case BFD_RELOC_THUMB_PCREL_BRANCH9:
17610 case BFD_RELOC_THUMB_PCREL_BRANCH12:
17611 case BFD_RELOC_THUMB_PCREL_BRANCH20:
17612 case BFD_RELOC_THUMB_PCREL_BRANCH23:
17613 case BFD_RELOC_THUMB_PCREL_BRANCH25:
17614 case BFD_RELOC_THUMB_PCREL_BLX:
17615 return base + 4;
17616
17617 /* ARM mode branches are offset by +8. However, the Windows CE
17618 loader expects the relocation not to take this into account. */
17619 case BFD_RELOC_ARM_PCREL_BRANCH:
17620 case BFD_RELOC_ARM_PCREL_CALL:
17621 case BFD_RELOC_ARM_PCREL_JUMP:
17622 case BFD_RELOC_ARM_PCREL_BLX:
17623 case BFD_RELOC_ARM_PLT32:
17624 #ifdef TE_WINCE
17625 /* When handling fixups immediately, because we have already
17626 discovered the value of a symbol, or the address of the frag involved
17627 we must account for the offset by +8, as the OS loader will never see the reloc.
17628 see fixup_segment() in write.c
17629 The S_IS_EXTERNAL test handles the case of global symbols.
17630 Those need the calculated base, not just the pipe compensation the linker will need. */
17631 if (fixP->fx_pcrel
17632 && fixP->fx_addsy != NULL
17633 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
17634 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
17635 return base + 8;
17636 return base;
17637 #else
17638 return base + 8;
17639 #endif
17640
17641 /* ARM mode loads relative to PC are also offset by +8. Unlike
17642 branches, the Windows CE loader *does* expect the relocation
17643 to take this into account. */
17644 case BFD_RELOC_ARM_OFFSET_IMM:
17645 case BFD_RELOC_ARM_OFFSET_IMM8:
17646 case BFD_RELOC_ARM_HWLITERAL:
17647 case BFD_RELOC_ARM_LITERAL:
17648 case BFD_RELOC_ARM_CP_OFF_IMM:
17649 return base + 8;
17650
17651
17652 /* Other PC-relative relocations are un-offset. */
17653 default:
17654 return base;
17655 }
17656 }
17657
17658 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
17659 Otherwise we have no need to default values of symbols. */
17660
17661 symbolS *
17662 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
17663 {
17664 #ifdef OBJ_ELF
17665 if (name[0] == '_' && name[1] == 'G'
17666 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
17667 {
17668 if (!GOT_symbol)
17669 {
17670 if (symbol_find (name))
17671 as_bad (_("GOT already in the symbol table"));
17672
17673 GOT_symbol = symbol_new (name, undefined_section,
17674 (valueT) 0, & zero_address_frag);
17675 }
17676
17677 return GOT_symbol;
17678 }
17679 #endif
17680
17681 return 0;
17682 }
17683
17684 /* Subroutine of md_apply_fix. Check to see if an immediate can be
17685 computed as two separate immediate values, added together. We
17686 already know that this value cannot be computed by just one ARM
17687 instruction. */
17688
17689 static unsigned int
17690 validate_immediate_twopart (unsigned int val,
17691 unsigned int * highpart)
17692 {
17693 unsigned int a;
17694 unsigned int i;
17695
17696 for (i = 0; i < 32; i += 2)
17697 if (((a = rotate_left (val, i)) & 0xff) != 0)
17698 {
17699 if (a & 0xff00)
17700 {
17701 if (a & ~ 0xffff)
17702 continue;
17703 * highpart = (a >> 8) | ((i + 24) << 7);
17704 }
17705 else if (a & 0xff0000)
17706 {
17707 if (a & 0xff000000)
17708 continue;
17709 * highpart = (a >> 16) | ((i + 16) << 7);
17710 }
17711 else
17712 {
17713 assert (a & 0xff000000);
17714 * highpart = (a >> 24) | ((i + 8) << 7);
17715 }
17716
17717 return (a & 0xff) | (i << 7);
17718 }
17719
17720 return FAIL;
17721 }
17722
17723 static int
17724 validate_offset_imm (unsigned int val, int hwse)
17725 {
17726 if ((hwse && val > 255) || val > 4095)
17727 return FAIL;
17728 return val;
17729 }
17730
17731 /* Subroutine of md_apply_fix. Do those data_ops which can take a
17732 negative immediate constant by altering the instruction. A bit of
17733 a hack really.
17734 MOV <-> MVN
17735 AND <-> BIC
17736 ADC <-> SBC
17737 by inverting the second operand, and
17738 ADD <-> SUB
17739 CMP <-> CMN
17740 by negating the second operand. */
17741
17742 static int
17743 negate_data_op (unsigned long * instruction,
17744 unsigned long value)
17745 {
17746 int op, new_inst;
17747 unsigned long negated, inverted;
17748
17749 negated = encode_arm_immediate (-value);
17750 inverted = encode_arm_immediate (~value);
17751
17752 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
17753 switch (op)
17754 {
17755 /* First negates. */
17756 case OPCODE_SUB: /* ADD <-> SUB */
17757 new_inst = OPCODE_ADD;
17758 value = negated;
17759 break;
17760
17761 case OPCODE_ADD:
17762 new_inst = OPCODE_SUB;
17763 value = negated;
17764 break;
17765
17766 case OPCODE_CMP: /* CMP <-> CMN */
17767 new_inst = OPCODE_CMN;
17768 value = negated;
17769 break;
17770
17771 case OPCODE_CMN:
17772 new_inst = OPCODE_CMP;
17773 value = negated;
17774 break;
17775
17776 /* Now Inverted ops. */
17777 case OPCODE_MOV: /* MOV <-> MVN */
17778 new_inst = OPCODE_MVN;
17779 value = inverted;
17780 break;
17781
17782 case OPCODE_MVN:
17783 new_inst = OPCODE_MOV;
17784 value = inverted;
17785 break;
17786
17787 case OPCODE_AND: /* AND <-> BIC */
17788 new_inst = OPCODE_BIC;
17789 value = inverted;
17790 break;
17791
17792 case OPCODE_BIC:
17793 new_inst = OPCODE_AND;
17794 value = inverted;
17795 break;
17796
17797 case OPCODE_ADC: /* ADC <-> SBC */
17798 new_inst = OPCODE_SBC;
17799 value = inverted;
17800 break;
17801
17802 case OPCODE_SBC:
17803 new_inst = OPCODE_ADC;
17804 value = inverted;
17805 break;
17806
17807 /* We cannot do anything. */
17808 default:
17809 return FAIL;
17810 }
17811
17812 if (value == (unsigned) FAIL)
17813 return FAIL;
17814
17815 *instruction &= OPCODE_MASK;
17816 *instruction |= new_inst << DATA_OP_SHIFT;
17817 return value;
17818 }
17819
17820 /* Like negate_data_op, but for Thumb-2. */
17821
17822 static unsigned int
17823 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
17824 {
17825 int op, new_inst;
17826 int rd;
17827 unsigned int negated, inverted;
17828
17829 negated = encode_thumb32_immediate (-value);
17830 inverted = encode_thumb32_immediate (~value);
17831
17832 rd = (*instruction >> 8) & 0xf;
17833 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
17834 switch (op)
17835 {
17836 /* ADD <-> SUB. Includes CMP <-> CMN. */
17837 case T2_OPCODE_SUB:
17838 new_inst = T2_OPCODE_ADD;
17839 value = negated;
17840 break;
17841
17842 case T2_OPCODE_ADD:
17843 new_inst = T2_OPCODE_SUB;
17844 value = negated;
17845 break;
17846
17847 /* ORR <-> ORN. Includes MOV <-> MVN. */
17848 case T2_OPCODE_ORR:
17849 new_inst = T2_OPCODE_ORN;
17850 value = inverted;
17851 break;
17852
17853 case T2_OPCODE_ORN:
17854 new_inst = T2_OPCODE_ORR;
17855 value = inverted;
17856 break;
17857
17858 /* AND <-> BIC. TST has no inverted equivalent. */
17859 case T2_OPCODE_AND:
17860 new_inst = T2_OPCODE_BIC;
17861 if (rd == 15)
17862 value = FAIL;
17863 else
17864 value = inverted;
17865 break;
17866
17867 case T2_OPCODE_BIC:
17868 new_inst = T2_OPCODE_AND;
17869 value = inverted;
17870 break;
17871
17872 /* ADC <-> SBC */
17873 case T2_OPCODE_ADC:
17874 new_inst = T2_OPCODE_SBC;
17875 value = inverted;
17876 break;
17877
17878 case T2_OPCODE_SBC:
17879 new_inst = T2_OPCODE_ADC;
17880 value = inverted;
17881 break;
17882
17883 /* We cannot do anything. */
17884 default:
17885 return FAIL;
17886 }
17887
17888 if (value == (unsigned int)FAIL)
17889 return FAIL;
17890
17891 *instruction &= T2_OPCODE_MASK;
17892 *instruction |= new_inst << T2_DATA_OP_SHIFT;
17893 return value;
17894 }
17895
17896 /* Read a 32-bit thumb instruction from buf. */
17897 static unsigned long
17898 get_thumb32_insn (char * buf)
17899 {
17900 unsigned long insn;
17901 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
17902 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
17903
17904 return insn;
17905 }
17906
17907
17908 /* We usually want to set the low bit on the address of thumb function
17909 symbols. In particular .word foo - . should have the low bit set.
17910 Generic code tries to fold the difference of two symbols to
17911 a constant. Prevent this and force a relocation when the first symbols
17912 is a thumb function. */
17913 int
17914 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
17915 {
17916 if (op == O_subtract
17917 && l->X_op == O_symbol
17918 && r->X_op == O_symbol
17919 && THUMB_IS_FUNC (l->X_add_symbol))
17920 {
17921 l->X_op = O_subtract;
17922 l->X_op_symbol = r->X_add_symbol;
17923 l->X_add_number -= r->X_add_number;
17924 return 1;
17925 }
17926 /* Process as normal. */
17927 return 0;
17928 }
17929
17930 void
17931 md_apply_fix (fixS * fixP,
17932 valueT * valP,
17933 segT seg)
17934 {
17935 offsetT value = * valP;
17936 offsetT newval;
17937 unsigned int newimm;
17938 unsigned long temp;
17939 int sign;
17940 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
17941
17942 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
17943
17944 /* Note whether this will delete the relocation. */
17945
17946 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
17947 fixP->fx_done = 1;
17948
17949 /* On a 64-bit host, silently truncate 'value' to 32 bits for
17950 consistency with the behaviour on 32-bit hosts. Remember value
17951 for emit_reloc. */
17952 value &= 0xffffffff;
17953 value ^= 0x80000000;
17954 value -= 0x80000000;
17955
17956 *valP = value;
17957 fixP->fx_addnumber = value;
17958
17959 /* Same treatment for fixP->fx_offset. */
17960 fixP->fx_offset &= 0xffffffff;
17961 fixP->fx_offset ^= 0x80000000;
17962 fixP->fx_offset -= 0x80000000;
17963
17964 switch (fixP->fx_r_type)
17965 {
17966 case BFD_RELOC_NONE:
17967 /* This will need to go in the object file. */
17968 fixP->fx_done = 0;
17969 break;
17970
17971 case BFD_RELOC_ARM_IMMEDIATE:
17972 /* We claim that this fixup has been processed here,
17973 even if in fact we generate an error because we do
17974 not have a reloc for it, so tc_gen_reloc will reject it. */
17975 fixP->fx_done = 1;
17976
17977 if (fixP->fx_addsy
17978 && ! S_IS_DEFINED (fixP->fx_addsy))
17979 {
17980 as_bad_where (fixP->fx_file, fixP->fx_line,
17981 _("undefined symbol %s used as an immediate value"),
17982 S_GET_NAME (fixP->fx_addsy));
17983 break;
17984 }
17985
17986 newimm = encode_arm_immediate (value);
17987 temp = md_chars_to_number (buf, INSN_SIZE);
17988
17989 /* If the instruction will fail, see if we can fix things up by
17990 changing the opcode. */
17991 if (newimm == (unsigned int) FAIL
17992 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
17993 {
17994 as_bad_where (fixP->fx_file, fixP->fx_line,
17995 _("invalid constant (%lx) after fixup"),
17996 (unsigned long) value);
17997 break;
17998 }
17999
18000 newimm |= (temp & 0xfffff000);
18001 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
18002 break;
18003
18004 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
18005 {
18006 unsigned int highpart = 0;
18007 unsigned int newinsn = 0xe1a00000; /* nop. */
18008
18009 newimm = encode_arm_immediate (value);
18010 temp = md_chars_to_number (buf, INSN_SIZE);
18011
18012 /* If the instruction will fail, see if we can fix things up by
18013 changing the opcode. */
18014 if (newimm == (unsigned int) FAIL
18015 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
18016 {
18017 /* No ? OK - try using two ADD instructions to generate
18018 the value. */
18019 newimm = validate_immediate_twopart (value, & highpart);
18020
18021 /* Yes - then make sure that the second instruction is
18022 also an add. */
18023 if (newimm != (unsigned int) FAIL)
18024 newinsn = temp;
18025 /* Still No ? Try using a negated value. */
18026 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
18027 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
18028 /* Otherwise - give up. */
18029 else
18030 {
18031 as_bad_where (fixP->fx_file, fixP->fx_line,
18032 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
18033 (long) value);
18034 break;
18035 }
18036
18037 /* Replace the first operand in the 2nd instruction (which
18038 is the PC) with the destination register. We have
18039 already added in the PC in the first instruction and we
18040 do not want to do it again. */
18041 newinsn &= ~ 0xf0000;
18042 newinsn |= ((newinsn & 0x0f000) << 4);
18043 }
18044
18045 newimm |= (temp & 0xfffff000);
18046 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
18047
18048 highpart |= (newinsn & 0xfffff000);
18049 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
18050 }
18051 break;
18052
18053 case BFD_RELOC_ARM_OFFSET_IMM:
18054 if (!fixP->fx_done && seg->use_rela_p)
18055 value = 0;
18056
18057 case BFD_RELOC_ARM_LITERAL:
18058 sign = value >= 0;
18059
18060 if (value < 0)
18061 value = - value;
18062
18063 if (validate_offset_imm (value, 0) == FAIL)
18064 {
18065 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
18066 as_bad_where (fixP->fx_file, fixP->fx_line,
18067 _("invalid literal constant: pool needs to be closer"));
18068 else
18069 as_bad_where (fixP->fx_file, fixP->fx_line,
18070 _("bad immediate value for offset (%ld)"),
18071 (long) value);
18072 break;
18073 }
18074
18075 newval = md_chars_to_number (buf, INSN_SIZE);
18076 newval &= 0xff7ff000;
18077 newval |= value | (sign ? INDEX_UP : 0);
18078 md_number_to_chars (buf, newval, INSN_SIZE);
18079 break;
18080
18081 case BFD_RELOC_ARM_OFFSET_IMM8:
18082 case BFD_RELOC_ARM_HWLITERAL:
18083 sign = value >= 0;
18084
18085 if (value < 0)
18086 value = - value;
18087
18088 if (validate_offset_imm (value, 1) == FAIL)
18089 {
18090 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
18091 as_bad_where (fixP->fx_file, fixP->fx_line,
18092 _("invalid literal constant: pool needs to be closer"));
18093 else
18094 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
18095 (long) value);
18096 break;
18097 }
18098
18099 newval = md_chars_to_number (buf, INSN_SIZE);
18100 newval &= 0xff7ff0f0;
18101 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
18102 md_number_to_chars (buf, newval, INSN_SIZE);
18103 break;
18104
18105 case BFD_RELOC_ARM_T32_OFFSET_U8:
18106 if (value < 0 || value > 1020 || value % 4 != 0)
18107 as_bad_where (fixP->fx_file, fixP->fx_line,
18108 _("bad immediate value for offset (%ld)"), (long) value);
18109 value /= 4;
18110
18111 newval = md_chars_to_number (buf+2, THUMB_SIZE);
18112 newval |= value;
18113 md_number_to_chars (buf+2, newval, THUMB_SIZE);
18114 break;
18115
18116 case BFD_RELOC_ARM_T32_OFFSET_IMM:
18117 /* This is a complicated relocation used for all varieties of Thumb32
18118 load/store instruction with immediate offset:
18119
18120 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
18121 *4, optional writeback(W)
18122 (doubleword load/store)
18123
18124 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
18125 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
18126 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
18127 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
18128 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
18129
18130 Uppercase letters indicate bits that are already encoded at
18131 this point. Lowercase letters are our problem. For the
18132 second block of instructions, the secondary opcode nybble
18133 (bits 8..11) is present, and bit 23 is zero, even if this is
18134 a PC-relative operation. */
18135 newval = md_chars_to_number (buf, THUMB_SIZE);
18136 newval <<= 16;
18137 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
18138
18139 if ((newval & 0xf0000000) == 0xe0000000)
18140 {
18141 /* Doubleword load/store: 8-bit offset, scaled by 4. */
18142 if (value >= 0)
18143 newval |= (1 << 23);
18144 else
18145 value = -value;
18146 if (value % 4 != 0)
18147 {
18148 as_bad_where (fixP->fx_file, fixP->fx_line,
18149 _("offset not a multiple of 4"));
18150 break;
18151 }
18152 value /= 4;
18153 if (value > 0xff)
18154 {
18155 as_bad_where (fixP->fx_file, fixP->fx_line,
18156 _("offset out of range"));
18157 break;
18158 }
18159 newval &= ~0xff;
18160 }
18161 else if ((newval & 0x000f0000) == 0x000f0000)
18162 {
18163 /* PC-relative, 12-bit offset. */
18164 if (value >= 0)
18165 newval |= (1 << 23);
18166 else
18167 value = -value;
18168 if (value > 0xfff)
18169 {
18170 as_bad_where (fixP->fx_file, fixP->fx_line,
18171 _("offset out of range"));
18172 break;
18173 }
18174 newval &= ~0xfff;
18175 }
18176 else if ((newval & 0x00000100) == 0x00000100)
18177 {
18178 /* Writeback: 8-bit, +/- offset. */
18179 if (value >= 0)
18180 newval |= (1 << 9);
18181 else
18182 value = -value;
18183 if (value > 0xff)
18184 {
18185 as_bad_where (fixP->fx_file, fixP->fx_line,
18186 _("offset out of range"));
18187 break;
18188 }
18189 newval &= ~0xff;
18190 }
18191 else if ((newval & 0x00000f00) == 0x00000e00)
18192 {
18193 /* T-instruction: positive 8-bit offset. */
18194 if (value < 0 || value > 0xff)
18195 {
18196 as_bad_where (fixP->fx_file, fixP->fx_line,
18197 _("offset out of range"));
18198 break;
18199 }
18200 newval &= ~0xff;
18201 newval |= value;
18202 }
18203 else
18204 {
18205 /* Positive 12-bit or negative 8-bit offset. */
18206 int limit;
18207 if (value >= 0)
18208 {
18209 newval |= (1 << 23);
18210 limit = 0xfff;
18211 }
18212 else
18213 {
18214 value = -value;
18215 limit = 0xff;
18216 }
18217 if (value > limit)
18218 {
18219 as_bad_where (fixP->fx_file, fixP->fx_line,
18220 _("offset out of range"));
18221 break;
18222 }
18223 newval &= ~limit;
18224 }
18225
18226 newval |= value;
18227 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
18228 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
18229 break;
18230
18231 case BFD_RELOC_ARM_SHIFT_IMM:
18232 newval = md_chars_to_number (buf, INSN_SIZE);
18233 if (((unsigned long) value) > 32
18234 || (value == 32
18235 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
18236 {
18237 as_bad_where (fixP->fx_file, fixP->fx_line,
18238 _("shift expression is too large"));
18239 break;
18240 }
18241
18242 if (value == 0)
18243 /* Shifts of zero must be done as lsl. */
18244 newval &= ~0x60;
18245 else if (value == 32)
18246 value = 0;
18247 newval &= 0xfffff07f;
18248 newval |= (value & 0x1f) << 7;
18249 md_number_to_chars (buf, newval, INSN_SIZE);
18250 break;
18251
18252 case BFD_RELOC_ARM_T32_IMMEDIATE:
18253 case BFD_RELOC_ARM_T32_ADD_IMM:
18254 case BFD_RELOC_ARM_T32_IMM12:
18255 case BFD_RELOC_ARM_T32_ADD_PC12:
18256 /* We claim that this fixup has been processed here,
18257 even if in fact we generate an error because we do
18258 not have a reloc for it, so tc_gen_reloc will reject it. */
18259 fixP->fx_done = 1;
18260
18261 if (fixP->fx_addsy
18262 && ! S_IS_DEFINED (fixP->fx_addsy))
18263 {
18264 as_bad_where (fixP->fx_file, fixP->fx_line,
18265 _("undefined symbol %s used as an immediate value"),
18266 S_GET_NAME (fixP->fx_addsy));
18267 break;
18268 }
18269
18270 newval = md_chars_to_number (buf, THUMB_SIZE);
18271 newval <<= 16;
18272 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
18273
18274 newimm = FAIL;
18275 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
18276 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18277 {
18278 newimm = encode_thumb32_immediate (value);
18279 if (newimm == (unsigned int) FAIL)
18280 newimm = thumb32_negate_data_op (&newval, value);
18281 }
18282 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
18283 && newimm == (unsigned int) FAIL)
18284 {
18285 /* Turn add/sum into addw/subw. */
18286 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18287 newval = (newval & 0xfeffffff) | 0x02000000;
18288
18289 /* 12 bit immediate for addw/subw. */
18290 if (value < 0)
18291 {
18292 value = -value;
18293 newval ^= 0x00a00000;
18294 }
18295 if (value > 0xfff)
18296 newimm = (unsigned int) FAIL;
18297 else
18298 newimm = value;
18299 }
18300
18301 if (newimm == (unsigned int)FAIL)
18302 {
18303 as_bad_where (fixP->fx_file, fixP->fx_line,
18304 _("invalid constant (%lx) after fixup"),
18305 (unsigned long) value);
18306 break;
18307 }
18308
18309 newval |= (newimm & 0x800) << 15;
18310 newval |= (newimm & 0x700) << 4;
18311 newval |= (newimm & 0x0ff);
18312
18313 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
18314 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
18315 break;
18316
18317 case BFD_RELOC_ARM_SMC:
18318 if (((unsigned long) value) > 0xffff)
18319 as_bad_where (fixP->fx_file, fixP->fx_line,
18320 _("invalid smc expression"));
18321 newval = md_chars_to_number (buf, INSN_SIZE);
18322 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
18323 md_number_to_chars (buf, newval, INSN_SIZE);
18324 break;
18325
18326 case BFD_RELOC_ARM_SWI:
18327 if (fixP->tc_fix_data != 0)
18328 {
18329 if (((unsigned long) value) > 0xff)
18330 as_bad_where (fixP->fx_file, fixP->fx_line,
18331 _("invalid swi expression"));
18332 newval = md_chars_to_number (buf, THUMB_SIZE);
18333 newval |= value;
18334 md_number_to_chars (buf, newval, THUMB_SIZE);
18335 }
18336 else
18337 {
18338 if (((unsigned long) value) > 0x00ffffff)
18339 as_bad_where (fixP->fx_file, fixP->fx_line,
18340 _("invalid swi expression"));
18341 newval = md_chars_to_number (buf, INSN_SIZE);
18342 newval |= value;
18343 md_number_to_chars (buf, newval, INSN_SIZE);
18344 }
18345 break;
18346
18347 case BFD_RELOC_ARM_MULTI:
18348 if (((unsigned long) value) > 0xffff)
18349 as_bad_where (fixP->fx_file, fixP->fx_line,
18350 _("invalid expression in load/store multiple"));
18351 newval = value | md_chars_to_number (buf, INSN_SIZE);
18352 md_number_to_chars (buf, newval, INSN_SIZE);
18353 break;
18354
18355 #ifdef OBJ_ELF
18356 case BFD_RELOC_ARM_PCREL_CALL:
18357 newval = md_chars_to_number (buf, INSN_SIZE);
18358 if ((newval & 0xf0000000) == 0xf0000000)
18359 temp = 1;
18360 else
18361 temp = 3;
18362 goto arm_branch_common;
18363
18364 case BFD_RELOC_ARM_PCREL_JUMP:
18365 case BFD_RELOC_ARM_PLT32:
18366 #endif
18367 case BFD_RELOC_ARM_PCREL_BRANCH:
18368 temp = 3;
18369 goto arm_branch_common;
18370
18371 case BFD_RELOC_ARM_PCREL_BLX:
18372 temp = 1;
18373 arm_branch_common:
18374 /* We are going to store value (shifted right by two) in the
18375 instruction, in a 24 bit, signed field. Bits 26 through 32 either
18376 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
18377 also be be clear. */
18378 if (value & temp)
18379 as_bad_where (fixP->fx_file, fixP->fx_line,
18380 _("misaligned branch destination"));
18381 if ((value & (offsetT)0xfe000000) != (offsetT)0
18382 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
18383 as_bad_where (fixP->fx_file, fixP->fx_line,
18384 _("branch out of range"));
18385
18386 if (fixP->fx_done || !seg->use_rela_p)
18387 {
18388 newval = md_chars_to_number (buf, INSN_SIZE);
18389 newval |= (value >> 2) & 0x00ffffff;
18390 /* Set the H bit on BLX instructions. */
18391 if (temp == 1)
18392 {
18393 if (value & 2)
18394 newval |= 0x01000000;
18395 else
18396 newval &= ~0x01000000;
18397 }
18398 md_number_to_chars (buf, newval, INSN_SIZE);
18399 }
18400 break;
18401
18402 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
18403 /* CBZ can only branch forward. */
18404
18405 /* Attempts to use CBZ to branch to the next instruction
18406 (which, strictly speaking, are prohibited) will be turned into
18407 no-ops.
18408
18409 FIXME: It may be better to remove the instruction completely and
18410 perform relaxation. */
18411 if (value == -2)
18412 {
18413 newval = md_chars_to_number (buf, THUMB_SIZE);
18414 newval = 0xbf00; /* NOP encoding T1 */
18415 md_number_to_chars (buf, newval, THUMB_SIZE);
18416 }
18417 else
18418 {
18419 if (value & ~0x7e)
18420 as_bad_where (fixP->fx_file, fixP->fx_line,
18421 _("branch out of range"));
18422
18423 if (fixP->fx_done || !seg->use_rela_p)
18424 {
18425 newval = md_chars_to_number (buf, THUMB_SIZE);
18426 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
18427 md_number_to_chars (buf, newval, THUMB_SIZE);
18428 }
18429 }
18430 break;
18431
18432 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
18433 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
18434 as_bad_where (fixP->fx_file, fixP->fx_line,
18435 _("branch out of range"));
18436
18437 if (fixP->fx_done || !seg->use_rela_p)
18438 {
18439 newval = md_chars_to_number (buf, THUMB_SIZE);
18440 newval |= (value & 0x1ff) >> 1;
18441 md_number_to_chars (buf, newval, THUMB_SIZE);
18442 }
18443 break;
18444
18445 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
18446 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
18447 as_bad_where (fixP->fx_file, fixP->fx_line,
18448 _("branch out of range"));
18449
18450 if (fixP->fx_done || !seg->use_rela_p)
18451 {
18452 newval = md_chars_to_number (buf, THUMB_SIZE);
18453 newval |= (value & 0xfff) >> 1;
18454 md_number_to_chars (buf, newval, THUMB_SIZE);
18455 }
18456 break;
18457
18458 case BFD_RELOC_THUMB_PCREL_BRANCH20:
18459 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
18460 as_bad_where (fixP->fx_file, fixP->fx_line,
18461 _("conditional branch out of range"));
18462
18463 if (fixP->fx_done || !seg->use_rela_p)
18464 {
18465 offsetT newval2;
18466 addressT S, J1, J2, lo, hi;
18467
18468 S = (value & 0x00100000) >> 20;
18469 J2 = (value & 0x00080000) >> 19;
18470 J1 = (value & 0x00040000) >> 18;
18471 hi = (value & 0x0003f000) >> 12;
18472 lo = (value & 0x00000ffe) >> 1;
18473
18474 newval = md_chars_to_number (buf, THUMB_SIZE);
18475 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18476 newval |= (S << 10) | hi;
18477 newval2 |= (J1 << 13) | (J2 << 11) | lo;
18478 md_number_to_chars (buf, newval, THUMB_SIZE);
18479 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18480 }
18481 break;
18482
18483 case BFD_RELOC_THUMB_PCREL_BLX:
18484 case BFD_RELOC_THUMB_PCREL_BRANCH23:
18485 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
18486 as_bad_where (fixP->fx_file, fixP->fx_line,
18487 _("branch out of range"));
18488
18489 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
18490 /* For a BLX instruction, make sure that the relocation is rounded up
18491 to a word boundary. This follows the semantics of the instruction
18492 which specifies that bit 1 of the target address will come from bit
18493 1 of the base address. */
18494 value = (value + 1) & ~ 1;
18495
18496 if (fixP->fx_done || !seg->use_rela_p)
18497 {
18498 offsetT newval2;
18499
18500 newval = md_chars_to_number (buf, THUMB_SIZE);
18501 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18502 newval |= (value & 0x7fffff) >> 12;
18503 newval2 |= (value & 0xfff) >> 1;
18504 md_number_to_chars (buf, newval, THUMB_SIZE);
18505 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18506 }
18507 break;
18508
18509 case BFD_RELOC_THUMB_PCREL_BRANCH25:
18510 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
18511 as_bad_where (fixP->fx_file, fixP->fx_line,
18512 _("branch out of range"));
18513
18514 if (fixP->fx_done || !seg->use_rela_p)
18515 {
18516 offsetT newval2;
18517 addressT S, I1, I2, lo, hi;
18518
18519 S = (value & 0x01000000) >> 24;
18520 I1 = (value & 0x00800000) >> 23;
18521 I2 = (value & 0x00400000) >> 22;
18522 hi = (value & 0x003ff000) >> 12;
18523 lo = (value & 0x00000ffe) >> 1;
18524
18525 I1 = !(I1 ^ S);
18526 I2 = !(I2 ^ S);
18527
18528 newval = md_chars_to_number (buf, THUMB_SIZE);
18529 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18530 newval |= (S << 10) | hi;
18531 newval2 |= (I1 << 13) | (I2 << 11) | lo;
18532 md_number_to_chars (buf, newval, THUMB_SIZE);
18533 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18534 }
18535 break;
18536
18537 case BFD_RELOC_8:
18538 if (fixP->fx_done || !seg->use_rela_p)
18539 md_number_to_chars (buf, value, 1);
18540 break;
18541
18542 case BFD_RELOC_16:
18543 if (fixP->fx_done || !seg->use_rela_p)
18544 md_number_to_chars (buf, value, 2);
18545 break;
18546
18547 #ifdef OBJ_ELF
18548 case BFD_RELOC_ARM_TLS_GD32:
18549 case BFD_RELOC_ARM_TLS_LE32:
18550 case BFD_RELOC_ARM_TLS_IE32:
18551 case BFD_RELOC_ARM_TLS_LDM32:
18552 case BFD_RELOC_ARM_TLS_LDO32:
18553 S_SET_THREAD_LOCAL (fixP->fx_addsy);
18554 /* fall through */
18555
18556 case BFD_RELOC_ARM_GOT32:
18557 case BFD_RELOC_ARM_GOTOFF:
18558 case BFD_RELOC_ARM_TARGET2:
18559 if (fixP->fx_done || !seg->use_rela_p)
18560 md_number_to_chars (buf, 0, 4);
18561 break;
18562 #endif
18563
18564 case BFD_RELOC_RVA:
18565 case BFD_RELOC_32:
18566 case BFD_RELOC_ARM_TARGET1:
18567 case BFD_RELOC_ARM_ROSEGREL32:
18568 case BFD_RELOC_ARM_SBREL32:
18569 case BFD_RELOC_32_PCREL:
18570 #ifdef TE_PE
18571 case BFD_RELOC_32_SECREL:
18572 #endif
18573 if (fixP->fx_done || !seg->use_rela_p)
18574 #ifdef TE_WINCE
18575 /* For WinCE we only do this for pcrel fixups. */
18576 if (fixP->fx_done || fixP->fx_pcrel)
18577 #endif
18578 md_number_to_chars (buf, value, 4);
18579 break;
18580
18581 #ifdef OBJ_ELF
18582 case BFD_RELOC_ARM_PREL31:
18583 if (fixP->fx_done || !seg->use_rela_p)
18584 {
18585 newval = md_chars_to_number (buf, 4) & 0x80000000;
18586 if ((value ^ (value >> 1)) & 0x40000000)
18587 {
18588 as_bad_where (fixP->fx_file, fixP->fx_line,
18589 _("rel31 relocation overflow"));
18590 }
18591 newval |= value & 0x7fffffff;
18592 md_number_to_chars (buf, newval, 4);
18593 }
18594 break;
18595 #endif
18596
18597 case BFD_RELOC_ARM_CP_OFF_IMM:
18598 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
18599 if (value < -1023 || value > 1023 || (value & 3))
18600 as_bad_where (fixP->fx_file, fixP->fx_line,
18601 _("co-processor offset out of range"));
18602 cp_off_common:
18603 sign = value >= 0;
18604 if (value < 0)
18605 value = -value;
18606 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18607 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18608 newval = md_chars_to_number (buf, INSN_SIZE);
18609 else
18610 newval = get_thumb32_insn (buf);
18611 newval &= 0xff7fff00;
18612 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
18613 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18614 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18615 md_number_to_chars (buf, newval, INSN_SIZE);
18616 else
18617 put_thumb32_insn (buf, newval);
18618 break;
18619
18620 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
18621 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
18622 if (value < -255 || value > 255)
18623 as_bad_where (fixP->fx_file, fixP->fx_line,
18624 _("co-processor offset out of range"));
18625 value *= 4;
18626 goto cp_off_common;
18627
18628 case BFD_RELOC_ARM_THUMB_OFFSET:
18629 newval = md_chars_to_number (buf, THUMB_SIZE);
18630 /* Exactly what ranges, and where the offset is inserted depends
18631 on the type of instruction, we can establish this from the
18632 top 4 bits. */
18633 switch (newval >> 12)
18634 {
18635 case 4: /* PC load. */
18636 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
18637 forced to zero for these loads; md_pcrel_from has already
18638 compensated for this. */
18639 if (value & 3)
18640 as_bad_where (fixP->fx_file, fixP->fx_line,
18641 _("invalid offset, target not word aligned (0x%08lX)"),
18642 (((unsigned long) fixP->fx_frag->fr_address
18643 + (unsigned long) fixP->fx_where) & ~3)
18644 + (unsigned long) value);
18645
18646 if (value & ~0x3fc)
18647 as_bad_where (fixP->fx_file, fixP->fx_line,
18648 _("invalid offset, value too big (0x%08lX)"),
18649 (long) value);
18650
18651 newval |= value >> 2;
18652 break;
18653
18654 case 9: /* SP load/store. */
18655 if (value & ~0x3fc)
18656 as_bad_where (fixP->fx_file, fixP->fx_line,
18657 _("invalid offset, value too big (0x%08lX)"),
18658 (long) value);
18659 newval |= value >> 2;
18660 break;
18661
18662 case 6: /* Word load/store. */
18663 if (value & ~0x7c)
18664 as_bad_where (fixP->fx_file, fixP->fx_line,
18665 _("invalid offset, value too big (0x%08lX)"),
18666 (long) value);
18667 newval |= value << 4; /* 6 - 2. */
18668 break;
18669
18670 case 7: /* Byte load/store. */
18671 if (value & ~0x1f)
18672 as_bad_where (fixP->fx_file, fixP->fx_line,
18673 _("invalid offset, value too big (0x%08lX)"),
18674 (long) value);
18675 newval |= value << 6;
18676 break;
18677
18678 case 8: /* Halfword load/store. */
18679 if (value & ~0x3e)
18680 as_bad_where (fixP->fx_file, fixP->fx_line,
18681 _("invalid offset, value too big (0x%08lX)"),
18682 (long) value);
18683 newval |= value << 5; /* 6 - 1. */
18684 break;
18685
18686 default:
18687 as_bad_where (fixP->fx_file, fixP->fx_line,
18688 "Unable to process relocation for thumb opcode: %lx",
18689 (unsigned long) newval);
18690 break;
18691 }
18692 md_number_to_chars (buf, newval, THUMB_SIZE);
18693 break;
18694
18695 case BFD_RELOC_ARM_THUMB_ADD:
18696 /* This is a complicated relocation, since we use it for all of
18697 the following immediate relocations:
18698
18699 3bit ADD/SUB
18700 8bit ADD/SUB
18701 9bit ADD/SUB SP word-aligned
18702 10bit ADD PC/SP word-aligned
18703
18704 The type of instruction being processed is encoded in the
18705 instruction field:
18706
18707 0x8000 SUB
18708 0x00F0 Rd
18709 0x000F Rs
18710 */
18711 newval = md_chars_to_number (buf, THUMB_SIZE);
18712 {
18713 int rd = (newval >> 4) & 0xf;
18714 int rs = newval & 0xf;
18715 int subtract = !!(newval & 0x8000);
18716
18717 /* Check for HI regs, only very restricted cases allowed:
18718 Adjusting SP, and using PC or SP to get an address. */
18719 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
18720 || (rs > 7 && rs != REG_SP && rs != REG_PC))
18721 as_bad_where (fixP->fx_file, fixP->fx_line,
18722 _("invalid Hi register with immediate"));
18723
18724 /* If value is negative, choose the opposite instruction. */
18725 if (value < 0)
18726 {
18727 value = -value;
18728 subtract = !subtract;
18729 if (value < 0)
18730 as_bad_where (fixP->fx_file, fixP->fx_line,
18731 _("immediate value out of range"));
18732 }
18733
18734 if (rd == REG_SP)
18735 {
18736 if (value & ~0x1fc)
18737 as_bad_where (fixP->fx_file, fixP->fx_line,
18738 _("invalid immediate for stack address calculation"));
18739 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
18740 newval |= value >> 2;
18741 }
18742 else if (rs == REG_PC || rs == REG_SP)
18743 {
18744 if (subtract || value & ~0x3fc)
18745 as_bad_where (fixP->fx_file, fixP->fx_line,
18746 _("invalid immediate for address calculation (value = 0x%08lX)"),
18747 (unsigned long) value);
18748 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
18749 newval |= rd << 8;
18750 newval |= value >> 2;
18751 }
18752 else if (rs == rd)
18753 {
18754 if (value & ~0xff)
18755 as_bad_where (fixP->fx_file, fixP->fx_line,
18756 _("immediate value out of range"));
18757 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
18758 newval |= (rd << 8) | value;
18759 }
18760 else
18761 {
18762 if (value & ~0x7)
18763 as_bad_where (fixP->fx_file, fixP->fx_line,
18764 _("immediate value out of range"));
18765 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
18766 newval |= rd | (rs << 3) | (value << 6);
18767 }
18768 }
18769 md_number_to_chars (buf, newval, THUMB_SIZE);
18770 break;
18771
18772 case BFD_RELOC_ARM_THUMB_IMM:
18773 newval = md_chars_to_number (buf, THUMB_SIZE);
18774 if (value < 0 || value > 255)
18775 as_bad_where (fixP->fx_file, fixP->fx_line,
18776 _("invalid immediate: %ld is out of range"),
18777 (long) value);
18778 newval |= value;
18779 md_number_to_chars (buf, newval, THUMB_SIZE);
18780 break;
18781
18782 case BFD_RELOC_ARM_THUMB_SHIFT:
18783 /* 5bit shift value (0..32). LSL cannot take 32. */
18784 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
18785 temp = newval & 0xf800;
18786 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
18787 as_bad_where (fixP->fx_file, fixP->fx_line,
18788 _("invalid shift value: %ld"), (long) value);
18789 /* Shifts of zero must be encoded as LSL. */
18790 if (value == 0)
18791 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
18792 /* Shifts of 32 are encoded as zero. */
18793 else if (value == 32)
18794 value = 0;
18795 newval |= value << 6;
18796 md_number_to_chars (buf, newval, THUMB_SIZE);
18797 break;
18798
18799 case BFD_RELOC_VTABLE_INHERIT:
18800 case BFD_RELOC_VTABLE_ENTRY:
18801 fixP->fx_done = 0;
18802 return;
18803
18804 case BFD_RELOC_ARM_MOVW:
18805 case BFD_RELOC_ARM_MOVT:
18806 case BFD_RELOC_ARM_THUMB_MOVW:
18807 case BFD_RELOC_ARM_THUMB_MOVT:
18808 if (fixP->fx_done || !seg->use_rela_p)
18809 {
18810 /* REL format relocations are limited to a 16-bit addend. */
18811 if (!fixP->fx_done)
18812 {
18813 if (value < -0x8000 || value > 0x7fff)
18814 as_bad_where (fixP->fx_file, fixP->fx_line,
18815 _("offset out of range"));
18816 }
18817 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
18818 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18819 {
18820 value >>= 16;
18821 }
18822
18823 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
18824 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18825 {
18826 newval = get_thumb32_insn (buf);
18827 newval &= 0xfbf08f00;
18828 newval |= (value & 0xf000) << 4;
18829 newval |= (value & 0x0800) << 15;
18830 newval |= (value & 0x0700) << 4;
18831 newval |= (value & 0x00ff);
18832 put_thumb32_insn (buf, newval);
18833 }
18834 else
18835 {
18836 newval = md_chars_to_number (buf, 4);
18837 newval &= 0xfff0f000;
18838 newval |= value & 0x0fff;
18839 newval |= (value & 0xf000) << 4;
18840 md_number_to_chars (buf, newval, 4);
18841 }
18842 }
18843 return;
18844
18845 case BFD_RELOC_ARM_ALU_PC_G0_NC:
18846 case BFD_RELOC_ARM_ALU_PC_G0:
18847 case BFD_RELOC_ARM_ALU_PC_G1_NC:
18848 case BFD_RELOC_ARM_ALU_PC_G1:
18849 case BFD_RELOC_ARM_ALU_PC_G2:
18850 case BFD_RELOC_ARM_ALU_SB_G0_NC:
18851 case BFD_RELOC_ARM_ALU_SB_G0:
18852 case BFD_RELOC_ARM_ALU_SB_G1_NC:
18853 case BFD_RELOC_ARM_ALU_SB_G1:
18854 case BFD_RELOC_ARM_ALU_SB_G2:
18855 assert (!fixP->fx_done);
18856 if (!seg->use_rela_p)
18857 {
18858 bfd_vma insn;
18859 bfd_vma encoded_addend;
18860 bfd_vma addend_abs = abs (value);
18861
18862 /* Check that the absolute value of the addend can be
18863 expressed as an 8-bit constant plus a rotation. */
18864 encoded_addend = encode_arm_immediate (addend_abs);
18865 if (encoded_addend == (unsigned int) FAIL)
18866 as_bad_where (fixP->fx_file, fixP->fx_line,
18867 _("the offset 0x%08lX is not representable"),
18868 (unsigned long) addend_abs);
18869
18870 /* Extract the instruction. */
18871 insn = md_chars_to_number (buf, INSN_SIZE);
18872
18873 /* If the addend is positive, use an ADD instruction.
18874 Otherwise use a SUB. Take care not to destroy the S bit. */
18875 insn &= 0xff1fffff;
18876 if (value < 0)
18877 insn |= 1 << 22;
18878 else
18879 insn |= 1 << 23;
18880
18881 /* Place the encoded addend into the first 12 bits of the
18882 instruction. */
18883 insn &= 0xfffff000;
18884 insn |= encoded_addend;
18885
18886 /* Update the instruction. */
18887 md_number_to_chars (buf, insn, INSN_SIZE);
18888 }
18889 break;
18890
18891 case BFD_RELOC_ARM_LDR_PC_G0:
18892 case BFD_RELOC_ARM_LDR_PC_G1:
18893 case BFD_RELOC_ARM_LDR_PC_G2:
18894 case BFD_RELOC_ARM_LDR_SB_G0:
18895 case BFD_RELOC_ARM_LDR_SB_G1:
18896 case BFD_RELOC_ARM_LDR_SB_G2:
18897 assert (!fixP->fx_done);
18898 if (!seg->use_rela_p)
18899 {
18900 bfd_vma insn;
18901 bfd_vma addend_abs = abs (value);
18902
18903 /* Check that the absolute value of the addend can be
18904 encoded in 12 bits. */
18905 if (addend_abs >= 0x1000)
18906 as_bad_where (fixP->fx_file, fixP->fx_line,
18907 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
18908 (unsigned long) addend_abs);
18909
18910 /* Extract the instruction. */
18911 insn = md_chars_to_number (buf, INSN_SIZE);
18912
18913 /* If the addend is negative, clear bit 23 of the instruction.
18914 Otherwise set it. */
18915 if (value < 0)
18916 insn &= ~(1 << 23);
18917 else
18918 insn |= 1 << 23;
18919
18920 /* Place the absolute value of the addend into the first 12 bits
18921 of the instruction. */
18922 insn &= 0xfffff000;
18923 insn |= addend_abs;
18924
18925 /* Update the instruction. */
18926 md_number_to_chars (buf, insn, INSN_SIZE);
18927 }
18928 break;
18929
18930 case BFD_RELOC_ARM_LDRS_PC_G0:
18931 case BFD_RELOC_ARM_LDRS_PC_G1:
18932 case BFD_RELOC_ARM_LDRS_PC_G2:
18933 case BFD_RELOC_ARM_LDRS_SB_G0:
18934 case BFD_RELOC_ARM_LDRS_SB_G1:
18935 case BFD_RELOC_ARM_LDRS_SB_G2:
18936 assert (!fixP->fx_done);
18937 if (!seg->use_rela_p)
18938 {
18939 bfd_vma insn;
18940 bfd_vma addend_abs = abs (value);
18941
18942 /* Check that the absolute value of the addend can be
18943 encoded in 8 bits. */
18944 if (addend_abs >= 0x100)
18945 as_bad_where (fixP->fx_file, fixP->fx_line,
18946 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
18947 (unsigned long) addend_abs);
18948
18949 /* Extract the instruction. */
18950 insn = md_chars_to_number (buf, INSN_SIZE);
18951
18952 /* If the addend is negative, clear bit 23 of the instruction.
18953 Otherwise set it. */
18954 if (value < 0)
18955 insn &= ~(1 << 23);
18956 else
18957 insn |= 1 << 23;
18958
18959 /* Place the first four bits of the absolute value of the addend
18960 into the first 4 bits of the instruction, and the remaining
18961 four into bits 8 .. 11. */
18962 insn &= 0xfffff0f0;
18963 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
18964
18965 /* Update the instruction. */
18966 md_number_to_chars (buf, insn, INSN_SIZE);
18967 }
18968 break;
18969
18970 case BFD_RELOC_ARM_LDC_PC_G0:
18971 case BFD_RELOC_ARM_LDC_PC_G1:
18972 case BFD_RELOC_ARM_LDC_PC_G2:
18973 case BFD_RELOC_ARM_LDC_SB_G0:
18974 case BFD_RELOC_ARM_LDC_SB_G1:
18975 case BFD_RELOC_ARM_LDC_SB_G2:
18976 assert (!fixP->fx_done);
18977 if (!seg->use_rela_p)
18978 {
18979 bfd_vma insn;
18980 bfd_vma addend_abs = abs (value);
18981
18982 /* Check that the absolute value of the addend is a multiple of
18983 four and, when divided by four, fits in 8 bits. */
18984 if (addend_abs & 0x3)
18985 as_bad_where (fixP->fx_file, fixP->fx_line,
18986 _("bad offset 0x%08lX (must be word-aligned)"),
18987 (unsigned long) addend_abs);
18988
18989 if ((addend_abs >> 2) > 0xff)
18990 as_bad_where (fixP->fx_file, fixP->fx_line,
18991 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
18992 (unsigned long) addend_abs);
18993
18994 /* Extract the instruction. */
18995 insn = md_chars_to_number (buf, INSN_SIZE);
18996
18997 /* If the addend is negative, clear bit 23 of the instruction.
18998 Otherwise set it. */
18999 if (value < 0)
19000 insn &= ~(1 << 23);
19001 else
19002 insn |= 1 << 23;
19003
19004 /* Place the addend (divided by four) into the first eight
19005 bits of the instruction. */
19006 insn &= 0xfffffff0;
19007 insn |= addend_abs >> 2;
19008
19009 /* Update the instruction. */
19010 md_number_to_chars (buf, insn, INSN_SIZE);
19011 }
19012 break;
19013
19014 case BFD_RELOC_ARM_V4BX:
19015 /* This will need to go in the object file. */
19016 fixP->fx_done = 0;
19017 break;
19018
19019 case BFD_RELOC_UNUSED:
19020 default:
19021 as_bad_where (fixP->fx_file, fixP->fx_line,
19022 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
19023 }
19024 }
19025
19026 /* Translate internal representation of relocation info to BFD target
19027 format. */
19028
19029 arelent *
19030 tc_gen_reloc (asection *section, fixS *fixp)
19031 {
19032 arelent * reloc;
19033 bfd_reloc_code_real_type code;
19034
19035 reloc = xmalloc (sizeof (arelent));
19036
19037 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
19038 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
19039 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
19040
19041 if (fixp->fx_pcrel)
19042 {
19043 if (section->use_rela_p)
19044 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
19045 else
19046 fixp->fx_offset = reloc->address;
19047 }
19048 reloc->addend = fixp->fx_offset;
19049
19050 switch (fixp->fx_r_type)
19051 {
19052 case BFD_RELOC_8:
19053 if (fixp->fx_pcrel)
19054 {
19055 code = BFD_RELOC_8_PCREL;
19056 break;
19057 }
19058
19059 case BFD_RELOC_16:
19060 if (fixp->fx_pcrel)
19061 {
19062 code = BFD_RELOC_16_PCREL;
19063 break;
19064 }
19065
19066 case BFD_RELOC_32:
19067 if (fixp->fx_pcrel)
19068 {
19069 code = BFD_RELOC_32_PCREL;
19070 break;
19071 }
19072
19073 case BFD_RELOC_ARM_MOVW:
19074 if (fixp->fx_pcrel)
19075 {
19076 code = BFD_RELOC_ARM_MOVW_PCREL;
19077 break;
19078 }
19079
19080 case BFD_RELOC_ARM_MOVT:
19081 if (fixp->fx_pcrel)
19082 {
19083 code = BFD_RELOC_ARM_MOVT_PCREL;
19084 break;
19085 }
19086
19087 case BFD_RELOC_ARM_THUMB_MOVW:
19088 if (fixp->fx_pcrel)
19089 {
19090 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
19091 break;
19092 }
19093
19094 case BFD_RELOC_ARM_THUMB_MOVT:
19095 if (fixp->fx_pcrel)
19096 {
19097 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
19098 break;
19099 }
19100
19101 case BFD_RELOC_NONE:
19102 case BFD_RELOC_ARM_PCREL_BRANCH:
19103 case BFD_RELOC_ARM_PCREL_BLX:
19104 case BFD_RELOC_RVA:
19105 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19106 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19107 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19108 case BFD_RELOC_THUMB_PCREL_BRANCH20:
19109 case BFD_RELOC_THUMB_PCREL_BRANCH23:
19110 case BFD_RELOC_THUMB_PCREL_BRANCH25:
19111 case BFD_RELOC_THUMB_PCREL_BLX:
19112 case BFD_RELOC_VTABLE_ENTRY:
19113 case BFD_RELOC_VTABLE_INHERIT:
19114 #ifdef TE_PE
19115 case BFD_RELOC_32_SECREL:
19116 #endif
19117 code = fixp->fx_r_type;
19118 break;
19119
19120 case BFD_RELOC_ARM_LITERAL:
19121 case BFD_RELOC_ARM_HWLITERAL:
19122 /* If this is called then the a literal has
19123 been referenced across a section boundary. */
19124 as_bad_where (fixp->fx_file, fixp->fx_line,
19125 _("literal referenced across section boundary"));
19126 return NULL;
19127
19128 #ifdef OBJ_ELF
19129 case BFD_RELOC_ARM_GOT32:
19130 case BFD_RELOC_ARM_GOTOFF:
19131 case BFD_RELOC_ARM_PLT32:
19132 case BFD_RELOC_ARM_TARGET1:
19133 case BFD_RELOC_ARM_ROSEGREL32:
19134 case BFD_RELOC_ARM_SBREL32:
19135 case BFD_RELOC_ARM_PREL31:
19136 case BFD_RELOC_ARM_TARGET2:
19137 case BFD_RELOC_ARM_TLS_LE32:
19138 case BFD_RELOC_ARM_TLS_LDO32:
19139 case BFD_RELOC_ARM_PCREL_CALL:
19140 case BFD_RELOC_ARM_PCREL_JUMP:
19141 case BFD_RELOC_ARM_ALU_PC_G0_NC:
19142 case BFD_RELOC_ARM_ALU_PC_G0:
19143 case BFD_RELOC_ARM_ALU_PC_G1_NC:
19144 case BFD_RELOC_ARM_ALU_PC_G1:
19145 case BFD_RELOC_ARM_ALU_PC_G2:
19146 case BFD_RELOC_ARM_LDR_PC_G0:
19147 case BFD_RELOC_ARM_LDR_PC_G1:
19148 case BFD_RELOC_ARM_LDR_PC_G2:
19149 case BFD_RELOC_ARM_LDRS_PC_G0:
19150 case BFD_RELOC_ARM_LDRS_PC_G1:
19151 case BFD_RELOC_ARM_LDRS_PC_G2:
19152 case BFD_RELOC_ARM_LDC_PC_G0:
19153 case BFD_RELOC_ARM_LDC_PC_G1:
19154 case BFD_RELOC_ARM_LDC_PC_G2:
19155 case BFD_RELOC_ARM_ALU_SB_G0_NC:
19156 case BFD_RELOC_ARM_ALU_SB_G0:
19157 case BFD_RELOC_ARM_ALU_SB_G1_NC:
19158 case BFD_RELOC_ARM_ALU_SB_G1:
19159 case BFD_RELOC_ARM_ALU_SB_G2:
19160 case BFD_RELOC_ARM_LDR_SB_G0:
19161 case BFD_RELOC_ARM_LDR_SB_G1:
19162 case BFD_RELOC_ARM_LDR_SB_G2:
19163 case BFD_RELOC_ARM_LDRS_SB_G0:
19164 case BFD_RELOC_ARM_LDRS_SB_G1:
19165 case BFD_RELOC_ARM_LDRS_SB_G2:
19166 case BFD_RELOC_ARM_LDC_SB_G0:
19167 case BFD_RELOC_ARM_LDC_SB_G1:
19168 case BFD_RELOC_ARM_LDC_SB_G2:
19169 case BFD_RELOC_ARM_V4BX:
19170 code = fixp->fx_r_type;
19171 break;
19172
19173 case BFD_RELOC_ARM_TLS_GD32:
19174 case BFD_RELOC_ARM_TLS_IE32:
19175 case BFD_RELOC_ARM_TLS_LDM32:
19176 /* BFD will include the symbol's address in the addend.
19177 But we don't want that, so subtract it out again here. */
19178 if (!S_IS_COMMON (fixp->fx_addsy))
19179 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
19180 code = fixp->fx_r_type;
19181 break;
19182 #endif
19183
19184 case BFD_RELOC_ARM_IMMEDIATE:
19185 as_bad_where (fixp->fx_file, fixp->fx_line,
19186 _("internal relocation (type: IMMEDIATE) not fixed up"));
19187 return NULL;
19188
19189 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19190 as_bad_where (fixp->fx_file, fixp->fx_line,
19191 _("ADRL used for a symbol not defined in the same file"));
19192 return NULL;
19193
19194 case BFD_RELOC_ARM_OFFSET_IMM:
19195 if (section->use_rela_p)
19196 {
19197 code = fixp->fx_r_type;
19198 break;
19199 }
19200
19201 if (fixp->fx_addsy != NULL
19202 && !S_IS_DEFINED (fixp->fx_addsy)
19203 && S_IS_LOCAL (fixp->fx_addsy))
19204 {
19205 as_bad_where (fixp->fx_file, fixp->fx_line,
19206 _("undefined local label `%s'"),
19207 S_GET_NAME (fixp->fx_addsy));
19208 return NULL;
19209 }
19210
19211 as_bad_where (fixp->fx_file, fixp->fx_line,
19212 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
19213 return NULL;
19214
19215 default:
19216 {
19217 char * type;
19218
19219 switch (fixp->fx_r_type)
19220 {
19221 case BFD_RELOC_NONE: type = "NONE"; break;
19222 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
19223 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
19224 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
19225 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
19226 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
19227 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
19228 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
19229 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
19230 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
19231 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
19232 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
19233 default: type = _("<unknown>"); break;
19234 }
19235 as_bad_where (fixp->fx_file, fixp->fx_line,
19236 _("cannot represent %s relocation in this object file format"),
19237 type);
19238 return NULL;
19239 }
19240 }
19241
19242 #ifdef OBJ_ELF
19243 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
19244 && GOT_symbol
19245 && fixp->fx_addsy == GOT_symbol)
19246 {
19247 code = BFD_RELOC_ARM_GOTPC;
19248 reloc->addend = fixp->fx_offset = reloc->address;
19249 }
19250 #endif
19251
19252 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
19253
19254 if (reloc->howto == NULL)
19255 {
19256 as_bad_where (fixp->fx_file, fixp->fx_line,
19257 _("cannot represent %s relocation in this object file format"),
19258 bfd_get_reloc_code_name (code));
19259 return NULL;
19260 }
19261
19262 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
19263 vtable entry to be used in the relocation's section offset. */
19264 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19265 reloc->address = fixp->fx_offset;
19266
19267 return reloc;
19268 }
19269
19270 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
19271
19272 void
19273 cons_fix_new_arm (fragS * frag,
19274 int where,
19275 int size,
19276 expressionS * exp)
19277 {
19278 bfd_reloc_code_real_type type;
19279 int pcrel = 0;
19280
19281 /* Pick a reloc.
19282 FIXME: @@ Should look at CPU word size. */
19283 switch (size)
19284 {
19285 case 1:
19286 type = BFD_RELOC_8;
19287 break;
19288 case 2:
19289 type = BFD_RELOC_16;
19290 break;
19291 case 4:
19292 default:
19293 type = BFD_RELOC_32;
19294 break;
19295 case 8:
19296 type = BFD_RELOC_64;
19297 break;
19298 }
19299
19300 #ifdef TE_PE
19301 if (exp->X_op == O_secrel)
19302 {
19303 exp->X_op = O_symbol;
19304 type = BFD_RELOC_32_SECREL;
19305 }
19306 #endif
19307
19308 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
19309 }
19310
19311 #if defined OBJ_COFF || defined OBJ_ELF
19312 void
19313 arm_validate_fix (fixS * fixP)
19314 {
19315 /* If the destination of the branch is a defined symbol which does not have
19316 the THUMB_FUNC attribute, then we must be calling a function which has
19317 the (interfacearm) attribute. We look for the Thumb entry point to that
19318 function and change the branch to refer to that function instead. */
19319 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
19320 && fixP->fx_addsy != NULL
19321 && S_IS_DEFINED (fixP->fx_addsy)
19322 && ! THUMB_IS_FUNC (fixP->fx_addsy))
19323 {
19324 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
19325 }
19326 }
19327 #endif
19328
19329 int
19330 arm_force_relocation (struct fix * fixp)
19331 {
19332 #if defined (OBJ_COFF) && defined (TE_PE)
19333 if (fixp->fx_r_type == BFD_RELOC_RVA)
19334 return 1;
19335 #endif
19336
19337 /* Resolve these relocations even if the symbol is extern or weak. */
19338 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
19339 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
19340 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
19341 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
19342 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
19343 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
19344 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
19345 return 0;
19346
19347 /* Always leave these relocations for the linker. */
19348 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19349 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19350 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19351 return 1;
19352
19353 /* Always generate relocations against function symbols. */
19354 if (fixp->fx_r_type == BFD_RELOC_32
19355 && fixp->fx_addsy
19356 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
19357 return 1;
19358
19359 return generic_force_reloc (fixp);
19360 }
19361
19362 #if defined (OBJ_ELF) || defined (OBJ_COFF)
19363 /* Relocations against function names must be left unadjusted,
19364 so that the linker can use this information to generate interworking
19365 stubs. The MIPS version of this function
19366 also prevents relocations that are mips-16 specific, but I do not
19367 know why it does this.
19368
19369 FIXME:
19370 There is one other problem that ought to be addressed here, but
19371 which currently is not: Taking the address of a label (rather
19372 than a function) and then later jumping to that address. Such
19373 addresses also ought to have their bottom bit set (assuming that
19374 they reside in Thumb code), but at the moment they will not. */
19375
19376 bfd_boolean
19377 arm_fix_adjustable (fixS * fixP)
19378 {
19379 if (fixP->fx_addsy == NULL)
19380 return 1;
19381
19382 /* Preserve relocations against symbols with function type. */
19383 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
19384 return 0;
19385
19386 if (THUMB_IS_FUNC (fixP->fx_addsy)
19387 && fixP->fx_subsy == NULL)
19388 return 0;
19389
19390 /* We need the symbol name for the VTABLE entries. */
19391 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
19392 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19393 return 0;
19394
19395 /* Don't allow symbols to be discarded on GOT related relocs. */
19396 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
19397 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
19398 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
19399 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
19400 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
19401 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
19402 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
19403 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
19404 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
19405 return 0;
19406
19407 /* Similarly for group relocations. */
19408 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19409 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19410 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19411 return 0;
19412
19413 return 1;
19414 }
19415 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
19416
19417 #ifdef OBJ_ELF
19418
19419 const char *
19420 elf32_arm_target_format (void)
19421 {
19422 #ifdef TE_SYMBIAN
19423 return (target_big_endian
19424 ? "elf32-bigarm-symbian"
19425 : "elf32-littlearm-symbian");
19426 #elif defined (TE_VXWORKS)
19427 return (target_big_endian
19428 ? "elf32-bigarm-vxworks"
19429 : "elf32-littlearm-vxworks");
19430 #else
19431 if (target_big_endian)
19432 return "elf32-bigarm";
19433 else
19434 return "elf32-littlearm";
19435 #endif
19436 }
19437
19438 void
19439 armelf_frob_symbol (symbolS * symp,
19440 int * puntp)
19441 {
19442 elf_frob_symbol (symp, puntp);
19443 }
19444 #endif
19445
19446 /* MD interface: Finalization. */
19447
19448 /* A good place to do this, although this was probably not intended
19449 for this kind of use. We need to dump the literal pool before
19450 references are made to a null symbol pointer. */
19451
19452 void
19453 arm_cleanup (void)
19454 {
19455 literal_pool * pool;
19456
19457 for (pool = list_of_pools; pool; pool = pool->next)
19458 {
19459 /* Put it at the end of the relevant section. */
19460 subseg_set (pool->section, pool->sub_section);
19461 #ifdef OBJ_ELF
19462 arm_elf_change_section ();
19463 #endif
19464 s_ltorg (0);
19465 }
19466 }
19467
19468 /* Adjust the symbol table. This marks Thumb symbols as distinct from
19469 ARM ones. */
19470
19471 void
19472 arm_adjust_symtab (void)
19473 {
19474 #ifdef OBJ_COFF
19475 symbolS * sym;
19476
19477 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
19478 {
19479 if (ARM_IS_THUMB (sym))
19480 {
19481 if (THUMB_IS_FUNC (sym))
19482 {
19483 /* Mark the symbol as a Thumb function. */
19484 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
19485 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
19486 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
19487
19488 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
19489 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
19490 else
19491 as_bad (_("%s: unexpected function type: %d"),
19492 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
19493 }
19494 else switch (S_GET_STORAGE_CLASS (sym))
19495 {
19496 case C_EXT:
19497 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
19498 break;
19499 case C_STAT:
19500 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
19501 break;
19502 case C_LABEL:
19503 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
19504 break;
19505 default:
19506 /* Do nothing. */
19507 break;
19508 }
19509 }
19510
19511 if (ARM_IS_INTERWORK (sym))
19512 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
19513 }
19514 #endif
19515 #ifdef OBJ_ELF
19516 symbolS * sym;
19517 char bind;
19518
19519 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
19520 {
19521 if (ARM_IS_THUMB (sym))
19522 {
19523 elf_symbol_type * elf_sym;
19524
19525 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
19526 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
19527
19528 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
19529 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
19530 {
19531 /* If it's a .thumb_func, declare it as so,
19532 otherwise tag label as .code 16. */
19533 if (THUMB_IS_FUNC (sym))
19534 elf_sym->internal_elf_sym.st_info =
19535 ELF_ST_INFO (bind, STT_ARM_TFUNC);
19536 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
19537 elf_sym->internal_elf_sym.st_info =
19538 ELF_ST_INFO (bind, STT_ARM_16BIT);
19539 }
19540 }
19541 }
19542 #endif
19543 }
19544
19545 /* MD interface: Initialization. */
19546
19547 static void
19548 set_constant_flonums (void)
19549 {
19550 int i;
19551
19552 for (i = 0; i < NUM_FLOAT_VALS; i++)
19553 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
19554 abort ();
19555 }
19556
19557 /* Auto-select Thumb mode if it's the only available instruction set for the
19558 given architecture. */
19559
19560 static void
19561 autoselect_thumb_from_cpu_variant (void)
19562 {
19563 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
19564 opcode_select (16);
19565 }
19566
19567 void
19568 md_begin (void)
19569 {
19570 unsigned mach;
19571 unsigned int i;
19572
19573 if ( (arm_ops_hsh = hash_new ()) == NULL
19574 || (arm_cond_hsh = hash_new ()) == NULL
19575 || (arm_shift_hsh = hash_new ()) == NULL
19576 || (arm_psr_hsh = hash_new ()) == NULL
19577 || (arm_v7m_psr_hsh = hash_new ()) == NULL
19578 || (arm_reg_hsh = hash_new ()) == NULL
19579 || (arm_reloc_hsh = hash_new ()) == NULL
19580 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
19581 as_fatal (_("virtual memory exhausted"));
19582
19583 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
19584 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
19585 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
19586 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
19587 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
19588 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
19589 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
19590 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
19591 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
19592 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (PTR) (v7m_psrs + i));
19593 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
19594 hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i));
19595 for (i = 0;
19596 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
19597 i++)
19598 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
19599 (PTR) (barrier_opt_names + i));
19600 #ifdef OBJ_ELF
19601 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
19602 hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i));
19603 #endif
19604
19605 set_constant_flonums ();
19606
19607 /* Set the cpu variant based on the command-line options. We prefer
19608 -mcpu= over -march= if both are set (as for GCC); and we prefer
19609 -mfpu= over any other way of setting the floating point unit.
19610 Use of legacy options with new options are faulted. */
19611 if (legacy_cpu)
19612 {
19613 if (mcpu_cpu_opt || march_cpu_opt)
19614 as_bad (_("use of old and new-style options to set CPU type"));
19615
19616 mcpu_cpu_opt = legacy_cpu;
19617 }
19618 else if (!mcpu_cpu_opt)
19619 mcpu_cpu_opt = march_cpu_opt;
19620
19621 if (legacy_fpu)
19622 {
19623 if (mfpu_opt)
19624 as_bad (_("use of old and new-style options to set FPU type"));
19625
19626 mfpu_opt = legacy_fpu;
19627 }
19628 else if (!mfpu_opt)
19629 {
19630 #if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
19631 /* Some environments specify a default FPU. If they don't, infer it
19632 from the processor. */
19633 if (mcpu_fpu_opt)
19634 mfpu_opt = mcpu_fpu_opt;
19635 else
19636 mfpu_opt = march_fpu_opt;
19637 #else
19638 mfpu_opt = &fpu_default;
19639 #endif
19640 }
19641
19642 if (!mfpu_opt)
19643 {
19644 if (mcpu_cpu_opt != NULL)
19645 mfpu_opt = &fpu_default;
19646 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
19647 mfpu_opt = &fpu_arch_vfp_v2;
19648 else
19649 mfpu_opt = &fpu_arch_fpa;
19650 }
19651
19652 #ifdef CPU_DEFAULT
19653 if (!mcpu_cpu_opt)
19654 {
19655 mcpu_cpu_opt = &cpu_default;
19656 selected_cpu = cpu_default;
19657 }
19658 #else
19659 if (mcpu_cpu_opt)
19660 selected_cpu = *mcpu_cpu_opt;
19661 else
19662 mcpu_cpu_opt = &arm_arch_any;
19663 #endif
19664
19665 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
19666
19667 autoselect_thumb_from_cpu_variant ();
19668
19669 arm_arch_used = thumb_arch_used = arm_arch_none;
19670
19671 #if defined OBJ_COFF || defined OBJ_ELF
19672 {
19673 unsigned int flags = 0;
19674
19675 #if defined OBJ_ELF
19676 flags = meabi_flags;
19677
19678 switch (meabi_flags)
19679 {
19680 case EF_ARM_EABI_UNKNOWN:
19681 #endif
19682 /* Set the flags in the private structure. */
19683 if (uses_apcs_26) flags |= F_APCS26;
19684 if (support_interwork) flags |= F_INTERWORK;
19685 if (uses_apcs_float) flags |= F_APCS_FLOAT;
19686 if (pic_code) flags |= F_PIC;
19687 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
19688 flags |= F_SOFT_FLOAT;
19689
19690 switch (mfloat_abi_opt)
19691 {
19692 case ARM_FLOAT_ABI_SOFT:
19693 case ARM_FLOAT_ABI_SOFTFP:
19694 flags |= F_SOFT_FLOAT;
19695 break;
19696
19697 case ARM_FLOAT_ABI_HARD:
19698 if (flags & F_SOFT_FLOAT)
19699 as_bad (_("hard-float conflicts with specified fpu"));
19700 break;
19701 }
19702
19703 /* Using pure-endian doubles (even if soft-float). */
19704 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
19705 flags |= F_VFP_FLOAT;
19706
19707 #if defined OBJ_ELF
19708 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
19709 flags |= EF_ARM_MAVERICK_FLOAT;
19710 break;
19711
19712 case EF_ARM_EABI_VER4:
19713 case EF_ARM_EABI_VER5:
19714 /* No additional flags to set. */
19715 break;
19716
19717 default:
19718 abort ();
19719 }
19720 #endif
19721 bfd_set_private_flags (stdoutput, flags);
19722
19723 /* We have run out flags in the COFF header to encode the
19724 status of ATPCS support, so instead we create a dummy,
19725 empty, debug section called .arm.atpcs. */
19726 if (atpcs)
19727 {
19728 asection * sec;
19729
19730 sec = bfd_make_section (stdoutput, ".arm.atpcs");
19731
19732 if (sec != NULL)
19733 {
19734 bfd_set_section_flags
19735 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
19736 bfd_set_section_size (stdoutput, sec, 0);
19737 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
19738 }
19739 }
19740 }
19741 #endif
19742
19743 /* Record the CPU type as well. */
19744 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
19745 mach = bfd_mach_arm_iWMMXt2;
19746 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
19747 mach = bfd_mach_arm_iWMMXt;
19748 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
19749 mach = bfd_mach_arm_XScale;
19750 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
19751 mach = bfd_mach_arm_ep9312;
19752 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
19753 mach = bfd_mach_arm_5TE;
19754 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
19755 {
19756 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
19757 mach = bfd_mach_arm_5T;
19758 else
19759 mach = bfd_mach_arm_5;
19760 }
19761 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
19762 {
19763 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
19764 mach = bfd_mach_arm_4T;
19765 else
19766 mach = bfd_mach_arm_4;
19767 }
19768 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
19769 mach = bfd_mach_arm_3M;
19770 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
19771 mach = bfd_mach_arm_3;
19772 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
19773 mach = bfd_mach_arm_2a;
19774 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
19775 mach = bfd_mach_arm_2;
19776 else
19777 mach = bfd_mach_arm_unknown;
19778
19779 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
19780 }
19781
19782 /* Command line processing. */
19783
19784 /* md_parse_option
19785 Invocation line includes a switch not recognized by the base assembler.
19786 See if it's a processor-specific option.
19787
19788 This routine is somewhat complicated by the need for backwards
19789 compatibility (since older releases of gcc can't be changed).
19790 The new options try to make the interface as compatible as
19791 possible with GCC.
19792
19793 New options (supported) are:
19794
19795 -mcpu=<cpu name> Assemble for selected processor
19796 -march=<architecture name> Assemble for selected architecture
19797 -mfpu=<fpu architecture> Assemble for selected FPU.
19798 -EB/-mbig-endian Big-endian
19799 -EL/-mlittle-endian Little-endian
19800 -k Generate PIC code
19801 -mthumb Start in Thumb mode
19802 -mthumb-interwork Code supports ARM/Thumb interworking
19803
19804 For now we will also provide support for:
19805
19806 -mapcs-32 32-bit Program counter
19807 -mapcs-26 26-bit Program counter
19808 -macps-float Floats passed in FP registers
19809 -mapcs-reentrant Reentrant code
19810 -matpcs
19811 (sometime these will probably be replaced with -mapcs=<list of options>
19812 and -matpcs=<list of options>)
19813
19814 The remaining options are only supported for back-wards compatibility.
19815 Cpu variants, the arm part is optional:
19816 -m[arm]1 Currently not supported.
19817 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
19818 -m[arm]3 Arm 3 processor
19819 -m[arm]6[xx], Arm 6 processors
19820 -m[arm]7[xx][t][[d]m] Arm 7 processors
19821 -m[arm]8[10] Arm 8 processors
19822 -m[arm]9[20][tdmi] Arm 9 processors
19823 -mstrongarm[110[0]] StrongARM processors
19824 -mxscale XScale processors
19825 -m[arm]v[2345[t[e]]] Arm architectures
19826 -mall All (except the ARM1)
19827 FP variants:
19828 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
19829 -mfpe-old (No float load/store multiples)
19830 -mvfpxd VFP Single precision
19831 -mvfp All VFP
19832 -mno-fpu Disable all floating point instructions
19833
19834 The following CPU names are recognized:
19835 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
19836 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
19837 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
19838 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
19839 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
19840 arm10t arm10e, arm1020t, arm1020e, arm10200e,
19841 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
19842
19843 */
19844
19845 const char * md_shortopts = "m:k";
19846
19847 #ifdef ARM_BI_ENDIAN
19848 #define OPTION_EB (OPTION_MD_BASE + 0)
19849 #define OPTION_EL (OPTION_MD_BASE + 1)
19850 #else
19851 #if TARGET_BYTES_BIG_ENDIAN
19852 #define OPTION_EB (OPTION_MD_BASE + 0)
19853 #else
19854 #define OPTION_EL (OPTION_MD_BASE + 1)
19855 #endif
19856 #endif
19857 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
19858
19859 struct option md_longopts[] =
19860 {
19861 #ifdef OPTION_EB
19862 {"EB", no_argument, NULL, OPTION_EB},
19863 #endif
19864 #ifdef OPTION_EL
19865 {"EL", no_argument, NULL, OPTION_EL},
19866 #endif
19867 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
19868 {NULL, no_argument, NULL, 0}
19869 };
19870
19871 size_t md_longopts_size = sizeof (md_longopts);
19872
19873 struct arm_option_table
19874 {
19875 char *option; /* Option name to match. */
19876 char *help; /* Help information. */
19877 int *var; /* Variable to change. */
19878 int value; /* What to change it to. */
19879 char *deprecated; /* If non-null, print this message. */
19880 };
19881
19882 struct arm_option_table arm_opts[] =
19883 {
19884 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
19885 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
19886 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
19887 &support_interwork, 1, NULL},
19888 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
19889 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
19890 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
19891 1, NULL},
19892 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
19893 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
19894 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
19895 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
19896 NULL},
19897
19898 /* These are recognized by the assembler, but have no affect on code. */
19899 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
19900 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
19901 {NULL, NULL, NULL, 0, NULL}
19902 };
19903
19904 struct arm_legacy_option_table
19905 {
19906 char *option; /* Option name to match. */
19907 const arm_feature_set **var; /* Variable to change. */
19908 const arm_feature_set value; /* What to change it to. */
19909 char *deprecated; /* If non-null, print this message. */
19910 };
19911
19912 const struct arm_legacy_option_table arm_legacy_opts[] =
19913 {
19914 /* DON'T add any new processors to this list -- we want the whole list
19915 to go away... Add them to the processors table instead. */
19916 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19917 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19918 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19919 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19920 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19921 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19922 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19923 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19924 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19925 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19926 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19927 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19928 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19929 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19930 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19931 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19932 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19933 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19934 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19935 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19936 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19937 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19938 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19939 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19940 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19941 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19942 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19943 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19944 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19945 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19946 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19947 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19948 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19949 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19950 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19951 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19952 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19953 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19954 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19955 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19956 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19957 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19958 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19959 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19960 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19961 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19962 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19963 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19964 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19965 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19966 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19967 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19968 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19969 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19970 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19971 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19972 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19973 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19974 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19975 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19976 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19977 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19978 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19979 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19980 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19981 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19982 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19983 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19984 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
19985 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
19986 N_("use -mcpu=strongarm110")},
19987 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
19988 N_("use -mcpu=strongarm1100")},
19989 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
19990 N_("use -mcpu=strongarm1110")},
19991 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
19992 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
19993 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
19994
19995 /* Architecture variants -- don't add any more to this list either. */
19996 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19997 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19998 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19999 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
20000 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
20001 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
20002 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
20003 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
20004 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
20005 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
20006 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
20007 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
20008 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
20009 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
20010 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
20011 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
20012 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
20013 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
20014
20015 /* Floating point variants -- don't add any more to this list either. */
20016 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
20017 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
20018 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
20019 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
20020 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
20021
20022 {NULL, NULL, ARM_ARCH_NONE, NULL}
20023 };
20024
20025 struct arm_cpu_option_table
20026 {
20027 char *name;
20028 const arm_feature_set value;
20029 /* For some CPUs we assume an FPU unless the user explicitly sets
20030 -mfpu=... */
20031 const arm_feature_set default_fpu;
20032 /* The canonical name of the CPU, or NULL to use NAME converted to upper
20033 case. */
20034 const char *canonical_name;
20035 };
20036
20037 /* This list should, at a minimum, contain all the cpu names
20038 recognized by GCC. */
20039 static const struct arm_cpu_option_table arm_cpus[] =
20040 {
20041 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
20042 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
20043 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
20044 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20045 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20046 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20047 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20048 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20049 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20050 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20051 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20052 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20053 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20054 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20055 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20056 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20057 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20058 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20059 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20060 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20061 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20062 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20063 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20064 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20065 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20066 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20067 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20068 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20069 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20070 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20071 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20072 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20073 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20074 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20075 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20076 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20077 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20078 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20079 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20080 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
20081 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20082 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20083 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20084 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20085 /* For V5 or later processors we default to using VFP; but the user
20086 should really set the FPU type explicitly. */
20087 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20088 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20089 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20090 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20091 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20092 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20093 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
20094 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20095 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20096 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
20097 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20098 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20099 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20100 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20101 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20102 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
20103 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20104 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20105 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20106 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
20107 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20108 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
20109 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
20110 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
20111 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
20112 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
20113 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
20114 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
20115 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
20116 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
20117 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
20118 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
20119 | FPU_NEON_EXT_V1),
20120 NULL},
20121 {"cortex-a9", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
20122 | FPU_NEON_EXT_V1),
20123 NULL},
20124 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
20125 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
20126 {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL},
20127 /* ??? XSCALE is really an architecture. */
20128 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
20129 /* ??? iwmmxt is not a processor. */
20130 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
20131 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
20132 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
20133 /* Maverick */
20134 {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
20135 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
20136 };
20137
20138 struct arm_arch_option_table
20139 {
20140 char *name;
20141 const arm_feature_set value;
20142 const arm_feature_set default_fpu;
20143 };
20144
20145 /* This list should, at a minimum, contain all the architecture names
20146 recognized by GCC. */
20147 static const struct arm_arch_option_table arm_archs[] =
20148 {
20149 {"all", ARM_ANY, FPU_ARCH_FPA},
20150 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
20151 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
20152 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
20153 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
20154 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
20155 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
20156 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
20157 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
20158 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
20159 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
20160 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
20161 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
20162 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
20163 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
20164 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
20165 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
20166 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
20167 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
20168 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
20169 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
20170 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
20171 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
20172 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
20173 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
20174 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
20175 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
20176 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
20177 /* The official spelling of the ARMv7 profile variants is the dashed form.
20178 Accept the non-dashed form for compatibility with old toolchains. */
20179 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20180 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20181 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
20182 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20183 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20184 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
20185 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
20186 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
20187 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
20188 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
20189 };
20190
20191 /* ISA extensions in the co-processor space. */
20192 struct arm_option_cpu_value_table
20193 {
20194 char *name;
20195 const arm_feature_set value;
20196 };
20197
20198 static const struct arm_option_cpu_value_table arm_extensions[] =
20199 {
20200 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
20201 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
20202 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
20203 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
20204 {NULL, ARM_ARCH_NONE}
20205 };
20206
20207 /* This list should, at a minimum, contain all the fpu names
20208 recognized by GCC. */
20209 static const struct arm_option_cpu_value_table arm_fpus[] =
20210 {
20211 {"softfpa", FPU_NONE},
20212 {"fpe", FPU_ARCH_FPE},
20213 {"fpe2", FPU_ARCH_FPE},
20214 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
20215 {"fpa", FPU_ARCH_FPA},
20216 {"fpa10", FPU_ARCH_FPA},
20217 {"fpa11", FPU_ARCH_FPA},
20218 {"arm7500fe", FPU_ARCH_FPA},
20219 {"softvfp", FPU_ARCH_VFP},
20220 {"softvfp+vfp", FPU_ARCH_VFP_V2},
20221 {"vfp", FPU_ARCH_VFP_V2},
20222 {"vfp9", FPU_ARCH_VFP_V2},
20223 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
20224 {"vfp10", FPU_ARCH_VFP_V2},
20225 {"vfp10-r0", FPU_ARCH_VFP_V1},
20226 {"vfpxd", FPU_ARCH_VFP_V1xD},
20227 {"vfpv2", FPU_ARCH_VFP_V2},
20228 {"vfpv3", FPU_ARCH_VFP_V3},
20229 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
20230 {"arm1020t", FPU_ARCH_VFP_V1},
20231 {"arm1020e", FPU_ARCH_VFP_V2},
20232 {"arm1136jfs", FPU_ARCH_VFP_V2},
20233 {"arm1136jf-s", FPU_ARCH_VFP_V2},
20234 {"maverick", FPU_ARCH_MAVERICK},
20235 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
20236 {NULL, ARM_ARCH_NONE}
20237 };
20238
20239 struct arm_option_value_table
20240 {
20241 char *name;
20242 long value;
20243 };
20244
20245 static const struct arm_option_value_table arm_float_abis[] =
20246 {
20247 {"hard", ARM_FLOAT_ABI_HARD},
20248 {"softfp", ARM_FLOAT_ABI_SOFTFP},
20249 {"soft", ARM_FLOAT_ABI_SOFT},
20250 {NULL, 0}
20251 };
20252
20253 #ifdef OBJ_ELF
20254 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
20255 static const struct arm_option_value_table arm_eabis[] =
20256 {
20257 {"gnu", EF_ARM_EABI_UNKNOWN},
20258 {"4", EF_ARM_EABI_VER4},
20259 {"5", EF_ARM_EABI_VER5},
20260 {NULL, 0}
20261 };
20262 #endif
20263
20264 struct arm_long_option_table
20265 {
20266 char * option; /* Substring to match. */
20267 char * help; /* Help information. */
20268 int (* func) (char * subopt); /* Function to decode sub-option. */
20269 char * deprecated; /* If non-null, print this message. */
20270 };
20271
20272 static int
20273 arm_parse_extension (char * str, const arm_feature_set **opt_p)
20274 {
20275 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
20276
20277 /* Copy the feature set, so that we can modify it. */
20278 *ext_set = **opt_p;
20279 *opt_p = ext_set;
20280
20281 while (str != NULL && *str != 0)
20282 {
20283 const struct arm_option_cpu_value_table * opt;
20284 char * ext;
20285 int optlen;
20286
20287 if (*str != '+')
20288 {
20289 as_bad (_("invalid architectural extension"));
20290 return 0;
20291 }
20292
20293 str++;
20294 ext = strchr (str, '+');
20295
20296 if (ext != NULL)
20297 optlen = ext - str;
20298 else
20299 optlen = strlen (str);
20300
20301 if (optlen == 0)
20302 {
20303 as_bad (_("missing architectural extension"));
20304 return 0;
20305 }
20306
20307 for (opt = arm_extensions; opt->name != NULL; opt++)
20308 if (strncmp (opt->name, str, optlen) == 0)
20309 {
20310 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
20311 break;
20312 }
20313
20314 if (opt->name == NULL)
20315 {
20316 as_bad (_("unknown architectural extension `%s'"), str);
20317 return 0;
20318 }
20319
20320 str = ext;
20321 };
20322
20323 return 1;
20324 }
20325
20326 static int
20327 arm_parse_cpu (char * str)
20328 {
20329 const struct arm_cpu_option_table * opt;
20330 char * ext = strchr (str, '+');
20331 int optlen;
20332
20333 if (ext != NULL)
20334 optlen = ext - str;
20335 else
20336 optlen = strlen (str);
20337
20338 if (optlen == 0)
20339 {
20340 as_bad (_("missing cpu name `%s'"), str);
20341 return 0;
20342 }
20343
20344 for (opt = arm_cpus; opt->name != NULL; opt++)
20345 if (strncmp (opt->name, str, optlen) == 0)
20346 {
20347 mcpu_cpu_opt = &opt->value;
20348 mcpu_fpu_opt = &opt->default_fpu;
20349 if (opt->canonical_name)
20350 strcpy (selected_cpu_name, opt->canonical_name);
20351 else
20352 {
20353 int i;
20354 for (i = 0; i < optlen; i++)
20355 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20356 selected_cpu_name[i] = 0;
20357 }
20358
20359 if (ext != NULL)
20360 return arm_parse_extension (ext, &mcpu_cpu_opt);
20361
20362 return 1;
20363 }
20364
20365 as_bad (_("unknown cpu `%s'"), str);
20366 return 0;
20367 }
20368
20369 static int
20370 arm_parse_arch (char * str)
20371 {
20372 const struct arm_arch_option_table *opt;
20373 char *ext = strchr (str, '+');
20374 int optlen;
20375
20376 if (ext != NULL)
20377 optlen = ext - str;
20378 else
20379 optlen = strlen (str);
20380
20381 if (optlen == 0)
20382 {
20383 as_bad (_("missing architecture name `%s'"), str);
20384 return 0;
20385 }
20386
20387 for (opt = arm_archs; opt->name != NULL; opt++)
20388 if (streq (opt->name, str))
20389 {
20390 march_cpu_opt = &opt->value;
20391 march_fpu_opt = &opt->default_fpu;
20392 strcpy (selected_cpu_name, opt->name);
20393
20394 if (ext != NULL)
20395 return arm_parse_extension (ext, &march_cpu_opt);
20396
20397 return 1;
20398 }
20399
20400 as_bad (_("unknown architecture `%s'\n"), str);
20401 return 0;
20402 }
20403
20404 static int
20405 arm_parse_fpu (char * str)
20406 {
20407 const struct arm_option_cpu_value_table * opt;
20408
20409 for (opt = arm_fpus; opt->name != NULL; opt++)
20410 if (streq (opt->name, str))
20411 {
20412 mfpu_opt = &opt->value;
20413 return 1;
20414 }
20415
20416 as_bad (_("unknown floating point format `%s'\n"), str);
20417 return 0;
20418 }
20419
20420 static int
20421 arm_parse_float_abi (char * str)
20422 {
20423 const struct arm_option_value_table * opt;
20424
20425 for (opt = arm_float_abis; opt->name != NULL; opt++)
20426 if (streq (opt->name, str))
20427 {
20428 mfloat_abi_opt = opt->value;
20429 return 1;
20430 }
20431
20432 as_bad (_("unknown floating point abi `%s'\n"), str);
20433 return 0;
20434 }
20435
20436 #ifdef OBJ_ELF
20437 static int
20438 arm_parse_eabi (char * str)
20439 {
20440 const struct arm_option_value_table *opt;
20441
20442 for (opt = arm_eabis; opt->name != NULL; opt++)
20443 if (streq (opt->name, str))
20444 {
20445 meabi_flags = opt->value;
20446 return 1;
20447 }
20448 as_bad (_("unknown EABI `%s'\n"), str);
20449 return 0;
20450 }
20451 #endif
20452
20453 struct arm_long_option_table arm_long_opts[] =
20454 {
20455 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
20456 arm_parse_cpu, NULL},
20457 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
20458 arm_parse_arch, NULL},
20459 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
20460 arm_parse_fpu, NULL},
20461 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
20462 arm_parse_float_abi, NULL},
20463 #ifdef OBJ_ELF
20464 {"meabi=", N_("<ver>\t assemble for eabi version <ver>"),
20465 arm_parse_eabi, NULL},
20466 #endif
20467 {NULL, NULL, 0, NULL}
20468 };
20469
20470 int
20471 md_parse_option (int c, char * arg)
20472 {
20473 struct arm_option_table *opt;
20474 const struct arm_legacy_option_table *fopt;
20475 struct arm_long_option_table *lopt;
20476
20477 switch (c)
20478 {
20479 #ifdef OPTION_EB
20480 case OPTION_EB:
20481 target_big_endian = 1;
20482 break;
20483 #endif
20484
20485 #ifdef OPTION_EL
20486 case OPTION_EL:
20487 target_big_endian = 0;
20488 break;
20489 #endif
20490
20491 case OPTION_FIX_V4BX:
20492 fix_v4bx = TRUE;
20493 break;
20494
20495 case 'a':
20496 /* Listing option. Just ignore these, we don't support additional
20497 ones. */
20498 return 0;
20499
20500 default:
20501 for (opt = arm_opts; opt->option != NULL; opt++)
20502 {
20503 if (c == opt->option[0]
20504 && ((arg == NULL && opt->option[1] == 0)
20505 || streq (arg, opt->option + 1)))
20506 {
20507 #if WARN_DEPRECATED
20508 /* If the option is deprecated, tell the user. */
20509 if (opt->deprecated != NULL)
20510 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20511 arg ? arg : "", _(opt->deprecated));
20512 #endif
20513
20514 if (opt->var != NULL)
20515 *opt->var = opt->value;
20516
20517 return 1;
20518 }
20519 }
20520
20521 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
20522 {
20523 if (c == fopt->option[0]
20524 && ((arg == NULL && fopt->option[1] == 0)
20525 || streq (arg, fopt->option + 1)))
20526 {
20527 #if WARN_DEPRECATED
20528 /* If the option is deprecated, tell the user. */
20529 if (fopt->deprecated != NULL)
20530 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20531 arg ? arg : "", _(fopt->deprecated));
20532 #endif
20533
20534 if (fopt->var != NULL)
20535 *fopt->var = &fopt->value;
20536
20537 return 1;
20538 }
20539 }
20540
20541 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20542 {
20543 /* These options are expected to have an argument. */
20544 if (c == lopt->option[0]
20545 && arg != NULL
20546 && strncmp (arg, lopt->option + 1,
20547 strlen (lopt->option + 1)) == 0)
20548 {
20549 #if WARN_DEPRECATED
20550 /* If the option is deprecated, tell the user. */
20551 if (lopt->deprecated != NULL)
20552 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
20553 _(lopt->deprecated));
20554 #endif
20555
20556 /* Call the sup-option parser. */
20557 return lopt->func (arg + strlen (lopt->option) - 1);
20558 }
20559 }
20560
20561 return 0;
20562 }
20563
20564 return 1;
20565 }
20566
20567 void
20568 md_show_usage (FILE * fp)
20569 {
20570 struct arm_option_table *opt;
20571 struct arm_long_option_table *lopt;
20572
20573 fprintf (fp, _(" ARM-specific assembler options:\n"));
20574
20575 for (opt = arm_opts; opt->option != NULL; opt++)
20576 if (opt->help != NULL)
20577 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
20578
20579 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20580 if (lopt->help != NULL)
20581 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
20582
20583 #ifdef OPTION_EB
20584 fprintf (fp, _("\
20585 -EB assemble code for a big-endian cpu\n"));
20586 #endif
20587
20588 #ifdef OPTION_EL
20589 fprintf (fp, _("\
20590 -EL assemble code for a little-endian cpu\n"));
20591 #endif
20592
20593 fprintf (fp, _("\
20594 --fix-v4bx Allow BX in ARMv4 code\n"));
20595 }
20596
20597
20598 #ifdef OBJ_ELF
20599 typedef struct
20600 {
20601 int val;
20602 arm_feature_set flags;
20603 } cpu_arch_ver_table;
20604
20605 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
20606 least features first. */
20607 static const cpu_arch_ver_table cpu_arch_ver[] =
20608 {
20609 {1, ARM_ARCH_V4},
20610 {2, ARM_ARCH_V4T},
20611 {3, ARM_ARCH_V5},
20612 {4, ARM_ARCH_V5TE},
20613 {5, ARM_ARCH_V5TEJ},
20614 {6, ARM_ARCH_V6},
20615 {7, ARM_ARCH_V6Z},
20616 {9, ARM_ARCH_V6K},
20617 {9, ARM_ARCH_V6M},
20618 {8, ARM_ARCH_V6T2},
20619 {10, ARM_ARCH_V7A},
20620 {10, ARM_ARCH_V7R},
20621 {10, ARM_ARCH_V7M},
20622 {0, ARM_ARCH_NONE}
20623 };
20624
20625 /* Set the public EABI object attributes. */
20626 static void
20627 aeabi_set_public_attributes (void)
20628 {
20629 int arch;
20630 arm_feature_set flags;
20631 arm_feature_set tmp;
20632 const cpu_arch_ver_table *p;
20633
20634 /* Choose the architecture based on the capabilities of the requested cpu
20635 (if any) and/or the instructions actually used. */
20636 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
20637 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
20638 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
20639 /*Allow the user to override the reported architecture. */
20640 if (object_arch)
20641 {
20642 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
20643 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
20644 }
20645
20646 tmp = flags;
20647 arch = 0;
20648 for (p = cpu_arch_ver; p->val; p++)
20649 {
20650 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
20651 {
20652 arch = p->val;
20653 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
20654 }
20655 }
20656
20657 /* Tag_CPU_name. */
20658 if (selected_cpu_name[0])
20659 {
20660 char *p;
20661
20662 p = selected_cpu_name;
20663 if (strncmp (p, "armv", 4) == 0)
20664 {
20665 int i;
20666
20667 p += 4;
20668 for (i = 0; p[i]; i++)
20669 p[i] = TOUPPER (p[i]);
20670 }
20671 bfd_elf_add_proc_attr_string (stdoutput, 5, p);
20672 }
20673 /* Tag_CPU_arch. */
20674 bfd_elf_add_proc_attr_int (stdoutput, 6, arch);
20675 /* Tag_CPU_arch_profile. */
20676 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
20677 bfd_elf_add_proc_attr_int (stdoutput, 7, 'A');
20678 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
20679 bfd_elf_add_proc_attr_int (stdoutput, 7, 'R');
20680 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
20681 bfd_elf_add_proc_attr_int (stdoutput, 7, 'M');
20682 /* Tag_ARM_ISA_use. */
20683 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_full))
20684 bfd_elf_add_proc_attr_int (stdoutput, 8, 1);
20685 /* Tag_THUMB_ISA_use. */
20686 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_full))
20687 bfd_elf_add_proc_attr_int (stdoutput, 9,
20688 ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2) ? 2 : 1);
20689 /* Tag_VFP_arch. */
20690 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_d32)
20691 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_d32))
20692 bfd_elf_add_proc_attr_int (stdoutput, 10, 4);
20693 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v3)
20694 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v3))
20695 bfd_elf_add_proc_attr_int (stdoutput, 10, 3);
20696 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v2)
20697 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v2))
20698 bfd_elf_add_proc_attr_int (stdoutput, 10, 2);
20699 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1)
20700 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1)
20701 || ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1xd)
20702 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1xd))
20703 bfd_elf_add_proc_attr_int (stdoutput, 10, 1);
20704 /* Tag_WMMX_arch. */
20705 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_cext_iwmmxt)
20706 || ARM_CPU_HAS_FEATURE (arm_arch_used, arm_cext_iwmmxt))
20707 bfd_elf_add_proc_attr_int (stdoutput, 11, 1);
20708 /* Tag_NEON_arch. */
20709 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_neon_ext_v1)
20710 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_neon_ext_v1))
20711 bfd_elf_add_proc_attr_int (stdoutput, 12, 1);
20712 }
20713
20714 /* Add the default contents for the .ARM.attributes section. */
20715 void
20716 arm_md_end (void)
20717 {
20718 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
20719 return;
20720
20721 aeabi_set_public_attributes ();
20722 }
20723 #endif /* OBJ_ELF */
20724
20725
20726 /* Parse a .cpu directive. */
20727
20728 static void
20729 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
20730 {
20731 const struct arm_cpu_option_table *opt;
20732 char *name;
20733 char saved_char;
20734
20735 name = input_line_pointer;
20736 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
20737 input_line_pointer++;
20738 saved_char = *input_line_pointer;
20739 *input_line_pointer = 0;
20740
20741 /* Skip the first "all" entry. */
20742 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
20743 if (streq (opt->name, name))
20744 {
20745 mcpu_cpu_opt = &opt->value;
20746 selected_cpu = opt->value;
20747 if (opt->canonical_name)
20748 strcpy (selected_cpu_name, opt->canonical_name);
20749 else
20750 {
20751 int i;
20752 for (i = 0; opt->name[i]; i++)
20753 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20754 selected_cpu_name[i] = 0;
20755 }
20756 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20757 *input_line_pointer = saved_char;
20758 demand_empty_rest_of_line ();
20759 return;
20760 }
20761 as_bad (_("unknown cpu `%s'"), name);
20762 *input_line_pointer = saved_char;
20763 ignore_rest_of_line ();
20764 }
20765
20766
20767 /* Parse a .arch directive. */
20768
20769 static void
20770 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
20771 {
20772 const struct arm_arch_option_table *opt;
20773 char saved_char;
20774 char *name;
20775
20776 name = input_line_pointer;
20777 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
20778 input_line_pointer++;
20779 saved_char = *input_line_pointer;
20780 *input_line_pointer = 0;
20781
20782 /* Skip the first "all" entry. */
20783 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20784 if (streq (opt->name, name))
20785 {
20786 mcpu_cpu_opt = &opt->value;
20787 selected_cpu = opt->value;
20788 strcpy (selected_cpu_name, opt->name);
20789 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20790 *input_line_pointer = saved_char;
20791 demand_empty_rest_of_line ();
20792 return;
20793 }
20794
20795 as_bad (_("unknown architecture `%s'\n"), name);
20796 *input_line_pointer = saved_char;
20797 ignore_rest_of_line ();
20798 }
20799
20800
20801 /* Parse a .object_arch directive. */
20802
20803 static void
20804 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
20805 {
20806 const struct arm_arch_option_table *opt;
20807 char saved_char;
20808 char *name;
20809
20810 name = input_line_pointer;
20811 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
20812 input_line_pointer++;
20813 saved_char = *input_line_pointer;
20814 *input_line_pointer = 0;
20815
20816 /* Skip the first "all" entry. */
20817 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20818 if (streq (opt->name, name))
20819 {
20820 object_arch = &opt->value;
20821 *input_line_pointer = saved_char;
20822 demand_empty_rest_of_line ();
20823 return;
20824 }
20825
20826 as_bad (_("unknown architecture `%s'\n"), name);
20827 *input_line_pointer = saved_char;
20828 ignore_rest_of_line ();
20829 }
20830
20831
20832 /* Parse a .fpu directive. */
20833
20834 static void
20835 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
20836 {
20837 const struct arm_option_cpu_value_table *opt;
20838 char saved_char;
20839 char *name;
20840
20841 name = input_line_pointer;
20842 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
20843 input_line_pointer++;
20844 saved_char = *input_line_pointer;
20845 *input_line_pointer = 0;
20846
20847 for (opt = arm_fpus; opt->name != NULL; opt++)
20848 if (streq (opt->name, name))
20849 {
20850 mfpu_opt = &opt->value;
20851 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20852 *input_line_pointer = saved_char;
20853 demand_empty_rest_of_line ();
20854 return;
20855 }
20856
20857 as_bad (_("unknown floating point format `%s'\n"), name);
20858 *input_line_pointer = saved_char;
20859 ignore_rest_of_line ();
20860 }
20861
20862 /* Copy symbol information. */
20863 void
20864 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
20865 {
20866 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
20867 }
This page took 0.61434 seconds and 4 git commands to generate.