2008-03-04 Paul Brook <paul@codesourcery.com>
[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
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_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
225 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
226 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
227
228 static int mfloat_abi_opt = -1;
229 /* Record user cpu selection for object attributes. */
230 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
231 /* Must be long enough to hold any of the names in arm_cpus. */
232 static char selected_cpu_name[16];
233 #ifdef OBJ_ELF
234 # ifdef EABI_DEFAULT
235 static int meabi_flags = EABI_DEFAULT;
236 # else
237 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
238 # endif
239
240 bfd_boolean
241 arm_is_eabi (void)
242 {
243 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
244 }
245 #endif
246
247 #ifdef OBJ_ELF
248 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
249 symbolS * GOT_symbol;
250 #endif
251
252 /* 0: assemble for ARM,
253 1: assemble for Thumb,
254 2: assemble for Thumb even though target CPU does not support thumb
255 instructions. */
256 static int thumb_mode = 0;
257
258 /* If unified_syntax is true, we are processing the new unified
259 ARM/Thumb syntax. Important differences from the old ARM mode:
260
261 - Immediate operands do not require a # prefix.
262 - Conditional affixes always appear at the end of the
263 instruction. (For backward compatibility, those instructions
264 that formerly had them in the middle, continue to accept them
265 there.)
266 - The IT instruction may appear, and if it does is validated
267 against subsequent conditional affixes. It does not generate
268 machine code.
269
270 Important differences from the old Thumb mode:
271
272 - Immediate operands do not require a # prefix.
273 - Most of the V6T2 instructions are only available in unified mode.
274 - The .N and .W suffixes are recognized and honored (it is an error
275 if they cannot be honored).
276 - All instructions set the flags if and only if they have an 's' affix.
277 - Conditional affixes may be used. They are validated against
278 preceding IT instructions. Unlike ARM mode, you cannot use a
279 conditional affix except in the scope of an IT instruction. */
280
281 static bfd_boolean unified_syntax = FALSE;
282
283 enum neon_el_type
284 {
285 NT_invtype,
286 NT_untyped,
287 NT_integer,
288 NT_float,
289 NT_poly,
290 NT_signed,
291 NT_unsigned
292 };
293
294 struct neon_type_el
295 {
296 enum neon_el_type type;
297 unsigned size;
298 };
299
300 #define NEON_MAX_TYPE_ELS 4
301
302 struct neon_type
303 {
304 struct neon_type_el el[NEON_MAX_TYPE_ELS];
305 unsigned elems;
306 };
307
308 struct arm_it
309 {
310 const char * error;
311 unsigned long instruction;
312 int size;
313 int size_req;
314 int cond;
315 /* "uncond_value" is set to the value in place of the conditional field in
316 unconditional versions of the instruction, or -1 if nothing is
317 appropriate. */
318 int uncond_value;
319 struct neon_type vectype;
320 /* Set to the opcode if the instruction needs relaxation.
321 Zero if the instruction is not relaxed. */
322 unsigned long relax;
323 struct
324 {
325 bfd_reloc_code_real_type type;
326 expressionS exp;
327 int pc_rel;
328 } reloc;
329
330 struct
331 {
332 unsigned reg;
333 signed int imm;
334 struct neon_type_el vectype;
335 unsigned present : 1; /* Operand present. */
336 unsigned isreg : 1; /* Operand was a register. */
337 unsigned immisreg : 1; /* .imm field is a second register. */
338 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
339 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
340 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
341 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
342 instructions. This allows us to disambiguate ARM <-> vector insns. */
343 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
344 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
345 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
346 unsigned issingle : 1; /* Operand is VFP single-precision register. */
347 unsigned hasreloc : 1; /* Operand has relocation suffix. */
348 unsigned writeback : 1; /* Operand has trailing ! */
349 unsigned preind : 1; /* Preindexed address. */
350 unsigned postind : 1; /* Postindexed address. */
351 unsigned negative : 1; /* Index register was negated. */
352 unsigned shifted : 1; /* Shift applied to operation. */
353 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
354 } operands[6];
355 };
356
357 static struct arm_it inst;
358
359 #define NUM_FLOAT_VALS 8
360
361 const char * fp_const[] =
362 {
363 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
364 };
365
366 /* Number of littlenums required to hold an extended precision number. */
367 #define MAX_LITTLENUMS 6
368
369 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
370
371 #define FAIL (-1)
372 #define SUCCESS (0)
373
374 #define SUFF_S 1
375 #define SUFF_D 2
376 #define SUFF_E 3
377 #define SUFF_P 4
378
379 #define CP_T_X 0x00008000
380 #define CP_T_Y 0x00400000
381
382 #define CONDS_BIT 0x00100000
383 #define LOAD_BIT 0x00100000
384
385 #define DOUBLE_LOAD_FLAG 0x00000001
386
387 struct asm_cond
388 {
389 const char * template;
390 unsigned long value;
391 };
392
393 #define COND_ALWAYS 0xE
394
395 struct asm_psr
396 {
397 const char *template;
398 unsigned long field;
399 };
400
401 struct asm_barrier_opt
402 {
403 const char *template;
404 unsigned long value;
405 };
406
407 /* The bit that distinguishes CPSR and SPSR. */
408 #define SPSR_BIT (1 << 22)
409
410 /* The individual PSR flag bits. */
411 #define PSR_c (1 << 16)
412 #define PSR_x (1 << 17)
413 #define PSR_s (1 << 18)
414 #define PSR_f (1 << 19)
415
416 struct reloc_entry
417 {
418 char *name;
419 bfd_reloc_code_real_type reloc;
420 };
421
422 enum vfp_reg_pos
423 {
424 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
425 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
426 };
427
428 enum vfp_ldstm_type
429 {
430 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
431 };
432
433 /* Bits for DEFINED field in neon_typed_alias. */
434 #define NTA_HASTYPE 1
435 #define NTA_HASINDEX 2
436
437 struct neon_typed_alias
438 {
439 unsigned char defined;
440 unsigned char index;
441 struct neon_type_el eltype;
442 };
443
444 /* ARM register categories. This includes coprocessor numbers and various
445 architecture extensions' registers. */
446 enum arm_reg_type
447 {
448 REG_TYPE_RN,
449 REG_TYPE_CP,
450 REG_TYPE_CN,
451 REG_TYPE_FN,
452 REG_TYPE_VFS,
453 REG_TYPE_VFD,
454 REG_TYPE_NQ,
455 REG_TYPE_VFSD,
456 REG_TYPE_NDQ,
457 REG_TYPE_NSDQ,
458 REG_TYPE_VFC,
459 REG_TYPE_MVF,
460 REG_TYPE_MVD,
461 REG_TYPE_MVFX,
462 REG_TYPE_MVDX,
463 REG_TYPE_MVAX,
464 REG_TYPE_DSPSC,
465 REG_TYPE_MMXWR,
466 REG_TYPE_MMXWC,
467 REG_TYPE_MMXWCG,
468 REG_TYPE_XSCALE,
469 };
470
471 /* Structure for a hash table entry for a register.
472 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
473 information which states whether a vector type or index is specified (for a
474 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
475 struct reg_entry
476 {
477 const char *name;
478 unsigned char number;
479 unsigned char type;
480 unsigned char builtin;
481 struct neon_typed_alias *neon;
482 };
483
484 /* Diagnostics used when we don't get a register of the expected type. */
485 const char *const reg_expected_msgs[] =
486 {
487 N_("ARM register expected"),
488 N_("bad or missing co-processor number"),
489 N_("co-processor register expected"),
490 N_("FPA register expected"),
491 N_("VFP single precision register expected"),
492 N_("VFP/Neon double precision register expected"),
493 N_("Neon quad precision register expected"),
494 N_("VFP single or double precision register expected"),
495 N_("Neon double or quad precision register expected"),
496 N_("VFP single, double or Neon quad precision register expected"),
497 N_("VFP system register expected"),
498 N_("Maverick MVF register expected"),
499 N_("Maverick MVD register expected"),
500 N_("Maverick MVFX register expected"),
501 N_("Maverick MVDX register expected"),
502 N_("Maverick MVAX register expected"),
503 N_("Maverick DSPSC register expected"),
504 N_("iWMMXt data register expected"),
505 N_("iWMMXt control register expected"),
506 N_("iWMMXt scalar register expected"),
507 N_("XScale accumulator register expected"),
508 };
509
510 /* Some well known registers that we refer to directly elsewhere. */
511 #define REG_SP 13
512 #define REG_LR 14
513 #define REG_PC 15
514
515 /* ARM instructions take 4bytes in the object file, Thumb instructions
516 take 2: */
517 #define INSN_SIZE 4
518
519 struct asm_opcode
520 {
521 /* Basic string to match. */
522 const char *template;
523
524 /* Parameters to instruction. */
525 unsigned char operands[8];
526
527 /* Conditional tag - see opcode_lookup. */
528 unsigned int tag : 4;
529
530 /* Basic instruction code. */
531 unsigned int avalue : 28;
532
533 /* Thumb-format instruction code. */
534 unsigned int tvalue;
535
536 /* Which architecture variant provides this instruction. */
537 const arm_feature_set *avariant;
538 const arm_feature_set *tvariant;
539
540 /* Function to call to encode instruction in ARM format. */
541 void (* aencode) (void);
542
543 /* Function to call to encode instruction in Thumb format. */
544 void (* tencode) (void);
545 };
546
547 /* Defines for various bits that we will want to toggle. */
548 #define INST_IMMEDIATE 0x02000000
549 #define OFFSET_REG 0x02000000
550 #define HWOFFSET_IMM 0x00400000
551 #define SHIFT_BY_REG 0x00000010
552 #define PRE_INDEX 0x01000000
553 #define INDEX_UP 0x00800000
554 #define WRITE_BACK 0x00200000
555 #define LDM_TYPE_2_OR_3 0x00400000
556 #define CPSI_MMOD 0x00020000
557
558 #define LITERAL_MASK 0xf000f000
559 #define OPCODE_MASK 0xfe1fffff
560 #define V4_STR_BIT 0x00000020
561
562 #define T2_SUBS_PC_LR 0xf3de8f00
563
564 #define DATA_OP_SHIFT 21
565
566 #define T2_OPCODE_MASK 0xfe1fffff
567 #define T2_DATA_OP_SHIFT 21
568
569 /* Codes to distinguish the arithmetic instructions. */
570 #define OPCODE_AND 0
571 #define OPCODE_EOR 1
572 #define OPCODE_SUB 2
573 #define OPCODE_RSB 3
574 #define OPCODE_ADD 4
575 #define OPCODE_ADC 5
576 #define OPCODE_SBC 6
577 #define OPCODE_RSC 7
578 #define OPCODE_TST 8
579 #define OPCODE_TEQ 9
580 #define OPCODE_CMP 10
581 #define OPCODE_CMN 11
582 #define OPCODE_ORR 12
583 #define OPCODE_MOV 13
584 #define OPCODE_BIC 14
585 #define OPCODE_MVN 15
586
587 #define T2_OPCODE_AND 0
588 #define T2_OPCODE_BIC 1
589 #define T2_OPCODE_ORR 2
590 #define T2_OPCODE_ORN 3
591 #define T2_OPCODE_EOR 4
592 #define T2_OPCODE_ADD 8
593 #define T2_OPCODE_ADC 10
594 #define T2_OPCODE_SBC 11
595 #define T2_OPCODE_SUB 13
596 #define T2_OPCODE_RSB 14
597
598 #define T_OPCODE_MUL 0x4340
599 #define T_OPCODE_TST 0x4200
600 #define T_OPCODE_CMN 0x42c0
601 #define T_OPCODE_NEG 0x4240
602 #define T_OPCODE_MVN 0x43c0
603
604 #define T_OPCODE_ADD_R3 0x1800
605 #define T_OPCODE_SUB_R3 0x1a00
606 #define T_OPCODE_ADD_HI 0x4400
607 #define T_OPCODE_ADD_ST 0xb000
608 #define T_OPCODE_SUB_ST 0xb080
609 #define T_OPCODE_ADD_SP 0xa800
610 #define T_OPCODE_ADD_PC 0xa000
611 #define T_OPCODE_ADD_I8 0x3000
612 #define T_OPCODE_SUB_I8 0x3800
613 #define T_OPCODE_ADD_I3 0x1c00
614 #define T_OPCODE_SUB_I3 0x1e00
615
616 #define T_OPCODE_ASR_R 0x4100
617 #define T_OPCODE_LSL_R 0x4080
618 #define T_OPCODE_LSR_R 0x40c0
619 #define T_OPCODE_ROR_R 0x41c0
620 #define T_OPCODE_ASR_I 0x1000
621 #define T_OPCODE_LSL_I 0x0000
622 #define T_OPCODE_LSR_I 0x0800
623
624 #define T_OPCODE_MOV_I8 0x2000
625 #define T_OPCODE_CMP_I8 0x2800
626 #define T_OPCODE_CMP_LR 0x4280
627 #define T_OPCODE_MOV_HR 0x4600
628 #define T_OPCODE_CMP_HR 0x4500
629
630 #define T_OPCODE_LDR_PC 0x4800
631 #define T_OPCODE_LDR_SP 0x9800
632 #define T_OPCODE_STR_SP 0x9000
633 #define T_OPCODE_LDR_IW 0x6800
634 #define T_OPCODE_STR_IW 0x6000
635 #define T_OPCODE_LDR_IH 0x8800
636 #define T_OPCODE_STR_IH 0x8000
637 #define T_OPCODE_LDR_IB 0x7800
638 #define T_OPCODE_STR_IB 0x7000
639 #define T_OPCODE_LDR_RW 0x5800
640 #define T_OPCODE_STR_RW 0x5000
641 #define T_OPCODE_LDR_RH 0x5a00
642 #define T_OPCODE_STR_RH 0x5200
643 #define T_OPCODE_LDR_RB 0x5c00
644 #define T_OPCODE_STR_RB 0x5400
645
646 #define T_OPCODE_PUSH 0xb400
647 #define T_OPCODE_POP 0xbc00
648
649 #define T_OPCODE_BRANCH 0xe000
650
651 #define THUMB_SIZE 2 /* Size of thumb instruction. */
652 #define THUMB_PP_PC_LR 0x0100
653 #define THUMB_LOAD_BIT 0x0800
654 #define THUMB2_LOAD_BIT 0x00100000
655
656 #define BAD_ARGS _("bad arguments to instruction")
657 #define BAD_PC _("r15 not allowed here")
658 #define BAD_COND _("instruction cannot be conditional")
659 #define BAD_OVERLAP _("registers may not be the same")
660 #define BAD_HIREG _("lo register required")
661 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
662 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
663 #define BAD_BRANCH _("branch must be last instruction in IT block")
664 #define BAD_NOT_IT _("instruction not allowed in IT block")
665 #define BAD_FPU _("selected FPU does not support instruction")
666
667 static struct hash_control *arm_ops_hsh;
668 static struct hash_control *arm_cond_hsh;
669 static struct hash_control *arm_shift_hsh;
670 static struct hash_control *arm_psr_hsh;
671 static struct hash_control *arm_v7m_psr_hsh;
672 static struct hash_control *arm_reg_hsh;
673 static struct hash_control *arm_reloc_hsh;
674 static struct hash_control *arm_barrier_opt_hsh;
675
676 /* Stuff needed to resolve the label ambiguity
677 As:
678 ...
679 label: <insn>
680 may differ from:
681 ...
682 label:
683 <insn> */
684
685 symbolS * last_label_seen;
686 static int label_is_thumb_function_name = FALSE;
687 \f
688 /* Literal pool structure. Held on a per-section
689 and per-sub-section basis. */
690
691 #define MAX_LITERAL_POOL_SIZE 1024
692 typedef struct literal_pool
693 {
694 expressionS literals [MAX_LITERAL_POOL_SIZE];
695 unsigned int next_free_entry;
696 unsigned int id;
697 symbolS * symbol;
698 segT section;
699 subsegT sub_section;
700 struct literal_pool * next;
701 } literal_pool;
702
703 /* Pointer to a linked list of literal pools. */
704 literal_pool * list_of_pools = NULL;
705
706 /* State variables for IT block handling. */
707 static bfd_boolean current_it_mask = 0;
708 static int current_cc;
709 \f
710 /* Pure syntax. */
711
712 /* This array holds the chars that always start a comment. If the
713 pre-processor is disabled, these aren't very useful. */
714 const char comment_chars[] = "@";
715
716 /* This array holds the chars that only start a comment at the beginning of
717 a line. If the line seems to have the form '# 123 filename'
718 .line and .file directives will appear in the pre-processed output. */
719 /* Note that input_file.c hand checks for '#' at the beginning of the
720 first line of the input file. This is because the compiler outputs
721 #NO_APP at the beginning of its output. */
722 /* Also note that comments like this one will always work. */
723 const char line_comment_chars[] = "#";
724
725 const char line_separator_chars[] = ";";
726
727 /* Chars that can be used to separate mant
728 from exp in floating point numbers. */
729 const char EXP_CHARS[] = "eE";
730
731 /* Chars that mean this number is a floating point constant. */
732 /* As in 0f12.456 */
733 /* or 0d1.2345e12 */
734
735 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
736
737 /* Prefix characters that indicate the start of an immediate
738 value. */
739 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
740
741 /* Separator character handling. */
742
743 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
744
745 static inline int
746 skip_past_char (char ** str, char c)
747 {
748 if (**str == c)
749 {
750 (*str)++;
751 return SUCCESS;
752 }
753 else
754 return FAIL;
755 }
756 #define skip_past_comma(str) skip_past_char (str, ',')
757
758 /* Arithmetic expressions (possibly involving symbols). */
759
760 /* Return TRUE if anything in the expression is a bignum. */
761
762 static int
763 walk_no_bignums (symbolS * sp)
764 {
765 if (symbol_get_value_expression (sp)->X_op == O_big)
766 return 1;
767
768 if (symbol_get_value_expression (sp)->X_add_symbol)
769 {
770 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
771 || (symbol_get_value_expression (sp)->X_op_symbol
772 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
773 }
774
775 return 0;
776 }
777
778 static int in_my_get_expression = 0;
779
780 /* Third argument to my_get_expression. */
781 #define GE_NO_PREFIX 0
782 #define GE_IMM_PREFIX 1
783 #define GE_OPT_PREFIX 2
784 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
785 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
786 #define GE_OPT_PREFIX_BIG 3
787
788 static int
789 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
790 {
791 char * save_in;
792 segT seg;
793
794 /* In unified syntax, all prefixes are optional. */
795 if (unified_syntax)
796 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
797 : GE_OPT_PREFIX;
798
799 switch (prefix_mode)
800 {
801 case GE_NO_PREFIX: break;
802 case GE_IMM_PREFIX:
803 if (!is_immediate_prefix (**str))
804 {
805 inst.error = _("immediate expression requires a # prefix");
806 return FAIL;
807 }
808 (*str)++;
809 break;
810 case GE_OPT_PREFIX:
811 case GE_OPT_PREFIX_BIG:
812 if (is_immediate_prefix (**str))
813 (*str)++;
814 break;
815 default: abort ();
816 }
817
818 memset (ep, 0, sizeof (expressionS));
819
820 save_in = input_line_pointer;
821 input_line_pointer = *str;
822 in_my_get_expression = 1;
823 seg = expression (ep);
824 in_my_get_expression = 0;
825
826 if (ep->X_op == O_illegal)
827 {
828 /* We found a bad expression in md_operand(). */
829 *str = input_line_pointer;
830 input_line_pointer = save_in;
831 if (inst.error == NULL)
832 inst.error = _("bad expression");
833 return 1;
834 }
835
836 #ifdef OBJ_AOUT
837 if (seg != absolute_section
838 && seg != text_section
839 && seg != data_section
840 && seg != bss_section
841 && seg != undefined_section)
842 {
843 inst.error = _("bad segment");
844 *str = input_line_pointer;
845 input_line_pointer = save_in;
846 return 1;
847 }
848 #endif
849
850 /* Get rid of any bignums now, so that we don't generate an error for which
851 we can't establish a line number later on. Big numbers are never valid
852 in instructions, which is where this routine is always called. */
853 if (prefix_mode != GE_OPT_PREFIX_BIG
854 && (ep->X_op == O_big
855 || (ep->X_add_symbol
856 && (walk_no_bignums (ep->X_add_symbol)
857 || (ep->X_op_symbol
858 && walk_no_bignums (ep->X_op_symbol))))))
859 {
860 inst.error = _("invalid constant");
861 *str = input_line_pointer;
862 input_line_pointer = save_in;
863 return 1;
864 }
865
866 *str = input_line_pointer;
867 input_line_pointer = save_in;
868 return 0;
869 }
870
871 /* Turn a string in input_line_pointer into a floating point constant
872 of type TYPE, and store the appropriate bytes in *LITP. The number
873 of LITTLENUMS emitted is stored in *SIZEP. An error message is
874 returned, or NULL on OK.
875
876 Note that fp constants aren't represent in the normal way on the ARM.
877 In big endian mode, things are as expected. However, in little endian
878 mode fp constants are big-endian word-wise, and little-endian byte-wise
879 within the words. For example, (double) 1.1 in big endian mode is
880 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
881 the byte sequence 99 99 f1 3f 9a 99 99 99.
882
883 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
884
885 char *
886 md_atof (int type, char * litP, int * sizeP)
887 {
888 int prec;
889 LITTLENUM_TYPE words[MAX_LITTLENUMS];
890 char *t;
891 int i;
892
893 switch (type)
894 {
895 case 'f':
896 case 'F':
897 case 's':
898 case 'S':
899 prec = 2;
900 break;
901
902 case 'd':
903 case 'D':
904 case 'r':
905 case 'R':
906 prec = 4;
907 break;
908
909 case 'x':
910 case 'X':
911 prec = 5;
912 break;
913
914 case 'p':
915 case 'P':
916 prec = 5;
917 break;
918
919 default:
920 *sizeP = 0;
921 return _("Unrecognized or unsupported floating point constant");
922 }
923
924 t = atof_ieee (input_line_pointer, type, words);
925 if (t)
926 input_line_pointer = t;
927 *sizeP = prec * sizeof (LITTLENUM_TYPE);
928
929 if (target_big_endian)
930 {
931 for (i = 0; i < prec; i++)
932 {
933 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
934 litP += sizeof (LITTLENUM_TYPE);
935 }
936 }
937 else
938 {
939 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
940 for (i = prec - 1; i >= 0; i--)
941 {
942 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
943 litP += sizeof (LITTLENUM_TYPE);
944 }
945 else
946 /* For a 4 byte float the order of elements in `words' is 1 0.
947 For an 8 byte float the order is 1 0 3 2. */
948 for (i = 0; i < prec; i += 2)
949 {
950 md_number_to_chars (litP, (valueT) words[i + 1],
951 sizeof (LITTLENUM_TYPE));
952 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
953 (valueT) words[i], sizeof (LITTLENUM_TYPE));
954 litP += 2 * sizeof (LITTLENUM_TYPE);
955 }
956 }
957
958 return NULL;
959 }
960
961 /* We handle all bad expressions here, so that we can report the faulty
962 instruction in the error message. */
963 void
964 md_operand (expressionS * expr)
965 {
966 if (in_my_get_expression)
967 expr->X_op = O_illegal;
968 }
969
970 /* Immediate values. */
971
972 /* Generic immediate-value read function for use in directives.
973 Accepts anything that 'expression' can fold to a constant.
974 *val receives the number. */
975 #ifdef OBJ_ELF
976 static int
977 immediate_for_directive (int *val)
978 {
979 expressionS exp;
980 exp.X_op = O_illegal;
981
982 if (is_immediate_prefix (*input_line_pointer))
983 {
984 input_line_pointer++;
985 expression (&exp);
986 }
987
988 if (exp.X_op != O_constant)
989 {
990 as_bad (_("expected #constant"));
991 ignore_rest_of_line ();
992 return FAIL;
993 }
994 *val = exp.X_add_number;
995 return SUCCESS;
996 }
997 #endif
998
999 /* Register parsing. */
1000
1001 /* Generic register parser. CCP points to what should be the
1002 beginning of a register name. If it is indeed a valid register
1003 name, advance CCP over it and return the reg_entry structure;
1004 otherwise return NULL. Does not issue diagnostics. */
1005
1006 static struct reg_entry *
1007 arm_reg_parse_multi (char **ccp)
1008 {
1009 char *start = *ccp;
1010 char *p;
1011 struct reg_entry *reg;
1012
1013 #ifdef REGISTER_PREFIX
1014 if (*start != REGISTER_PREFIX)
1015 return NULL;
1016 start++;
1017 #endif
1018 #ifdef OPTIONAL_REGISTER_PREFIX
1019 if (*start == OPTIONAL_REGISTER_PREFIX)
1020 start++;
1021 #endif
1022
1023 p = start;
1024 if (!ISALPHA (*p) || !is_name_beginner (*p))
1025 return NULL;
1026
1027 do
1028 p++;
1029 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1030
1031 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1032
1033 if (!reg)
1034 return NULL;
1035
1036 *ccp = p;
1037 return reg;
1038 }
1039
1040 static int
1041 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1042 enum arm_reg_type type)
1043 {
1044 /* Alternative syntaxes are accepted for a few register classes. */
1045 switch (type)
1046 {
1047 case REG_TYPE_MVF:
1048 case REG_TYPE_MVD:
1049 case REG_TYPE_MVFX:
1050 case REG_TYPE_MVDX:
1051 /* Generic coprocessor register names are allowed for these. */
1052 if (reg && reg->type == REG_TYPE_CN)
1053 return reg->number;
1054 break;
1055
1056 case REG_TYPE_CP:
1057 /* For backward compatibility, a bare number is valid here. */
1058 {
1059 unsigned long processor = strtoul (start, ccp, 10);
1060 if (*ccp != start && processor <= 15)
1061 return processor;
1062 }
1063
1064 case REG_TYPE_MMXWC:
1065 /* WC includes WCG. ??? I'm not sure this is true for all
1066 instructions that take WC registers. */
1067 if (reg && reg->type == REG_TYPE_MMXWCG)
1068 return reg->number;
1069 break;
1070
1071 default:
1072 break;
1073 }
1074
1075 return FAIL;
1076 }
1077
1078 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1079 return value is the register number or FAIL. */
1080
1081 static int
1082 arm_reg_parse (char **ccp, enum arm_reg_type type)
1083 {
1084 char *start = *ccp;
1085 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1086 int ret;
1087
1088 /* Do not allow a scalar (reg+index) to parse as a register. */
1089 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1090 return FAIL;
1091
1092 if (reg && reg->type == type)
1093 return reg->number;
1094
1095 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1096 return ret;
1097
1098 *ccp = start;
1099 return FAIL;
1100 }
1101
1102 /* Parse a Neon type specifier. *STR should point at the leading '.'
1103 character. Does no verification at this stage that the type fits the opcode
1104 properly. E.g.,
1105
1106 .i32.i32.s16
1107 .s32.f32
1108 .u16
1109
1110 Can all be legally parsed by this function.
1111
1112 Fills in neon_type struct pointer with parsed information, and updates STR
1113 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1114 type, FAIL if not. */
1115
1116 static int
1117 parse_neon_type (struct neon_type *type, char **str)
1118 {
1119 char *ptr = *str;
1120
1121 if (type)
1122 type->elems = 0;
1123
1124 while (type->elems < NEON_MAX_TYPE_ELS)
1125 {
1126 enum neon_el_type thistype = NT_untyped;
1127 unsigned thissize = -1u;
1128
1129 if (*ptr != '.')
1130 break;
1131
1132 ptr++;
1133
1134 /* Just a size without an explicit type. */
1135 if (ISDIGIT (*ptr))
1136 goto parsesize;
1137
1138 switch (TOLOWER (*ptr))
1139 {
1140 case 'i': thistype = NT_integer; break;
1141 case 'f': thistype = NT_float; break;
1142 case 'p': thistype = NT_poly; break;
1143 case 's': thistype = NT_signed; break;
1144 case 'u': thistype = NT_unsigned; break;
1145 case 'd':
1146 thistype = NT_float;
1147 thissize = 64;
1148 ptr++;
1149 goto done;
1150 default:
1151 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1152 return FAIL;
1153 }
1154
1155 ptr++;
1156
1157 /* .f is an abbreviation for .f32. */
1158 if (thistype == NT_float && !ISDIGIT (*ptr))
1159 thissize = 32;
1160 else
1161 {
1162 parsesize:
1163 thissize = strtoul (ptr, &ptr, 10);
1164
1165 if (thissize != 8 && thissize != 16 && thissize != 32
1166 && thissize != 64)
1167 {
1168 as_bad (_("bad size %d in type specifier"), thissize);
1169 return FAIL;
1170 }
1171 }
1172
1173 done:
1174 if (type)
1175 {
1176 type->el[type->elems].type = thistype;
1177 type->el[type->elems].size = thissize;
1178 type->elems++;
1179 }
1180 }
1181
1182 /* Empty/missing type is not a successful parse. */
1183 if (type->elems == 0)
1184 return FAIL;
1185
1186 *str = ptr;
1187
1188 return SUCCESS;
1189 }
1190
1191 /* Errors may be set multiple times during parsing or bit encoding
1192 (particularly in the Neon bits), but usually the earliest error which is set
1193 will be the most meaningful. Avoid overwriting it with later (cascading)
1194 errors by calling this function. */
1195
1196 static void
1197 first_error (const char *err)
1198 {
1199 if (!inst.error)
1200 inst.error = err;
1201 }
1202
1203 /* Parse a single type, e.g. ".s32", leading period included. */
1204 static int
1205 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1206 {
1207 char *str = *ccp;
1208 struct neon_type optype;
1209
1210 if (*str == '.')
1211 {
1212 if (parse_neon_type (&optype, &str) == SUCCESS)
1213 {
1214 if (optype.elems == 1)
1215 *vectype = optype.el[0];
1216 else
1217 {
1218 first_error (_("only one type should be specified for operand"));
1219 return FAIL;
1220 }
1221 }
1222 else
1223 {
1224 first_error (_("vector type expected"));
1225 return FAIL;
1226 }
1227 }
1228 else
1229 return FAIL;
1230
1231 *ccp = str;
1232
1233 return SUCCESS;
1234 }
1235
1236 /* Special meanings for indices (which have a range of 0-7), which will fit into
1237 a 4-bit integer. */
1238
1239 #define NEON_ALL_LANES 15
1240 #define NEON_INTERLEAVE_LANES 14
1241
1242 /* Parse either a register or a scalar, with an optional type. Return the
1243 register number, and optionally fill in the actual type of the register
1244 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1245 type/index information in *TYPEINFO. */
1246
1247 static int
1248 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1249 enum arm_reg_type *rtype,
1250 struct neon_typed_alias *typeinfo)
1251 {
1252 char *str = *ccp;
1253 struct reg_entry *reg = arm_reg_parse_multi (&str);
1254 struct neon_typed_alias atype;
1255 struct neon_type_el parsetype;
1256
1257 atype.defined = 0;
1258 atype.index = -1;
1259 atype.eltype.type = NT_invtype;
1260 atype.eltype.size = -1;
1261
1262 /* Try alternate syntax for some types of register. Note these are mutually
1263 exclusive with the Neon syntax extensions. */
1264 if (reg == NULL)
1265 {
1266 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1267 if (altreg != FAIL)
1268 *ccp = str;
1269 if (typeinfo)
1270 *typeinfo = atype;
1271 return altreg;
1272 }
1273
1274 /* Undo polymorphism when a set of register types may be accepted. */
1275 if ((type == REG_TYPE_NDQ
1276 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1277 || (type == REG_TYPE_VFSD
1278 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1279 || (type == REG_TYPE_NSDQ
1280 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1281 || reg->type == REG_TYPE_NQ))
1282 || (type == REG_TYPE_MMXWC
1283 && (reg->type == REG_TYPE_MMXWCG)))
1284 type = reg->type;
1285
1286 if (type != reg->type)
1287 return FAIL;
1288
1289 if (reg->neon)
1290 atype = *reg->neon;
1291
1292 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1293 {
1294 if ((atype.defined & NTA_HASTYPE) != 0)
1295 {
1296 first_error (_("can't redefine type for operand"));
1297 return FAIL;
1298 }
1299 atype.defined |= NTA_HASTYPE;
1300 atype.eltype = parsetype;
1301 }
1302
1303 if (skip_past_char (&str, '[') == SUCCESS)
1304 {
1305 if (type != REG_TYPE_VFD)
1306 {
1307 first_error (_("only D registers may be indexed"));
1308 return FAIL;
1309 }
1310
1311 if ((atype.defined & NTA_HASINDEX) != 0)
1312 {
1313 first_error (_("can't change index for operand"));
1314 return FAIL;
1315 }
1316
1317 atype.defined |= NTA_HASINDEX;
1318
1319 if (skip_past_char (&str, ']') == SUCCESS)
1320 atype.index = NEON_ALL_LANES;
1321 else
1322 {
1323 expressionS exp;
1324
1325 my_get_expression (&exp, &str, GE_NO_PREFIX);
1326
1327 if (exp.X_op != O_constant)
1328 {
1329 first_error (_("constant expression required"));
1330 return FAIL;
1331 }
1332
1333 if (skip_past_char (&str, ']') == FAIL)
1334 return FAIL;
1335
1336 atype.index = exp.X_add_number;
1337 }
1338 }
1339
1340 if (typeinfo)
1341 *typeinfo = atype;
1342
1343 if (rtype)
1344 *rtype = type;
1345
1346 *ccp = str;
1347
1348 return reg->number;
1349 }
1350
1351 /* Like arm_reg_parse, but allow allow the following extra features:
1352 - If RTYPE is non-zero, return the (possibly restricted) type of the
1353 register (e.g. Neon double or quad reg when either has been requested).
1354 - If this is a Neon vector type with additional type information, fill
1355 in the struct pointed to by VECTYPE (if non-NULL).
1356 This function will fault on encountering a scalar. */
1357
1358 static int
1359 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1360 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1361 {
1362 struct neon_typed_alias atype;
1363 char *str = *ccp;
1364 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1365
1366 if (reg == FAIL)
1367 return FAIL;
1368
1369 /* Do not allow a scalar (reg+index) to parse as a register. */
1370 if ((atype.defined & NTA_HASINDEX) != 0)
1371 {
1372 first_error (_("register operand expected, but got scalar"));
1373 return FAIL;
1374 }
1375
1376 if (vectype)
1377 *vectype = atype.eltype;
1378
1379 *ccp = str;
1380
1381 return reg;
1382 }
1383
1384 #define NEON_SCALAR_REG(X) ((X) >> 4)
1385 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1386
1387 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1388 have enough information to be able to do a good job bounds-checking. So, we
1389 just do easy checks here, and do further checks later. */
1390
1391 static int
1392 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1393 {
1394 int reg;
1395 char *str = *ccp;
1396 struct neon_typed_alias atype;
1397
1398 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
1399
1400 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1401 return FAIL;
1402
1403 if (atype.index == NEON_ALL_LANES)
1404 {
1405 first_error (_("scalar must have an index"));
1406 return FAIL;
1407 }
1408 else if (atype.index >= 64 / elsize)
1409 {
1410 first_error (_("scalar index out of range"));
1411 return FAIL;
1412 }
1413
1414 if (type)
1415 *type = atype.eltype;
1416
1417 *ccp = str;
1418
1419 return reg * 16 + atype.index;
1420 }
1421
1422 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1423 static long
1424 parse_reg_list (char ** strp)
1425 {
1426 char * str = * strp;
1427 long range = 0;
1428 int another_range;
1429
1430 /* We come back here if we get ranges concatenated by '+' or '|'. */
1431 do
1432 {
1433 another_range = 0;
1434
1435 if (*str == '{')
1436 {
1437 int in_range = 0;
1438 int cur_reg = -1;
1439
1440 str++;
1441 do
1442 {
1443 int reg;
1444
1445 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1446 {
1447 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
1448 return FAIL;
1449 }
1450
1451 if (in_range)
1452 {
1453 int i;
1454
1455 if (reg <= cur_reg)
1456 {
1457 first_error (_("bad range in register list"));
1458 return FAIL;
1459 }
1460
1461 for (i = cur_reg + 1; i < reg; i++)
1462 {
1463 if (range & (1 << i))
1464 as_tsktsk
1465 (_("Warning: duplicated register (r%d) in register list"),
1466 i);
1467 else
1468 range |= 1 << i;
1469 }
1470 in_range = 0;
1471 }
1472
1473 if (range & (1 << reg))
1474 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1475 reg);
1476 else if (reg <= cur_reg)
1477 as_tsktsk (_("Warning: register range not in ascending order"));
1478
1479 range |= 1 << reg;
1480 cur_reg = reg;
1481 }
1482 while (skip_past_comma (&str) != FAIL
1483 || (in_range = 1, *str++ == '-'));
1484 str--;
1485
1486 if (*str++ != '}')
1487 {
1488 first_error (_("missing `}'"));
1489 return FAIL;
1490 }
1491 }
1492 else
1493 {
1494 expressionS expr;
1495
1496 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1497 return FAIL;
1498
1499 if (expr.X_op == O_constant)
1500 {
1501 if (expr.X_add_number
1502 != (expr.X_add_number & 0x0000ffff))
1503 {
1504 inst.error = _("invalid register mask");
1505 return FAIL;
1506 }
1507
1508 if ((range & expr.X_add_number) != 0)
1509 {
1510 int regno = range & expr.X_add_number;
1511
1512 regno &= -regno;
1513 regno = (1 << regno) - 1;
1514 as_tsktsk
1515 (_("Warning: duplicated register (r%d) in register list"),
1516 regno);
1517 }
1518
1519 range |= expr.X_add_number;
1520 }
1521 else
1522 {
1523 if (inst.reloc.type != 0)
1524 {
1525 inst.error = _("expression too complex");
1526 return FAIL;
1527 }
1528
1529 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1530 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1531 inst.reloc.pc_rel = 0;
1532 }
1533 }
1534
1535 if (*str == '|' || *str == '+')
1536 {
1537 str++;
1538 another_range = 1;
1539 }
1540 }
1541 while (another_range);
1542
1543 *strp = str;
1544 return range;
1545 }
1546
1547 /* Types of registers in a list. */
1548
1549 enum reg_list_els
1550 {
1551 REGLIST_VFP_S,
1552 REGLIST_VFP_D,
1553 REGLIST_NEON_D
1554 };
1555
1556 /* Parse a VFP register list. If the string is invalid return FAIL.
1557 Otherwise return the number of registers, and set PBASE to the first
1558 register. Parses registers of type ETYPE.
1559 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1560 - Q registers can be used to specify pairs of D registers
1561 - { } can be omitted from around a singleton register list
1562 FIXME: This is not implemented, as it would require backtracking in
1563 some cases, e.g.:
1564 vtbl.8 d3,d4,d5
1565 This could be done (the meaning isn't really ambiguous), but doesn't
1566 fit in well with the current parsing framework.
1567 - 32 D registers may be used (also true for VFPv3).
1568 FIXME: Types are ignored in these register lists, which is probably a
1569 bug. */
1570
1571 static int
1572 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
1573 {
1574 char *str = *ccp;
1575 int base_reg;
1576 int new_base;
1577 enum arm_reg_type regtype = 0;
1578 int max_regs = 0;
1579 int count = 0;
1580 int warned = 0;
1581 unsigned long mask = 0;
1582 int i;
1583
1584 if (*str != '{')
1585 {
1586 inst.error = _("expecting {");
1587 return FAIL;
1588 }
1589
1590 str++;
1591
1592 switch (etype)
1593 {
1594 case REGLIST_VFP_S:
1595 regtype = REG_TYPE_VFS;
1596 max_regs = 32;
1597 break;
1598
1599 case REGLIST_VFP_D:
1600 regtype = REG_TYPE_VFD;
1601 break;
1602
1603 case REGLIST_NEON_D:
1604 regtype = REG_TYPE_NDQ;
1605 break;
1606 }
1607
1608 if (etype != REGLIST_VFP_S)
1609 {
1610 /* VFPv3 allows 32 D registers. */
1611 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
1612 {
1613 max_regs = 32;
1614 if (thumb_mode)
1615 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1616 fpu_vfp_ext_v3);
1617 else
1618 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1619 fpu_vfp_ext_v3);
1620 }
1621 else
1622 max_regs = 16;
1623 }
1624
1625 base_reg = max_regs;
1626
1627 do
1628 {
1629 int setmask = 1, addregs = 1;
1630
1631 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
1632
1633 if (new_base == FAIL)
1634 {
1635 first_error (_(reg_expected_msgs[regtype]));
1636 return FAIL;
1637 }
1638
1639 if (new_base >= max_regs)
1640 {
1641 first_error (_("register out of range in list"));
1642 return FAIL;
1643 }
1644
1645 /* Note: a value of 2 * n is returned for the register Q<n>. */
1646 if (regtype == REG_TYPE_NQ)
1647 {
1648 setmask = 3;
1649 addregs = 2;
1650 }
1651
1652 if (new_base < base_reg)
1653 base_reg = new_base;
1654
1655 if (mask & (setmask << new_base))
1656 {
1657 first_error (_("invalid register list"));
1658 return FAIL;
1659 }
1660
1661 if ((mask >> new_base) != 0 && ! warned)
1662 {
1663 as_tsktsk (_("register list not in ascending order"));
1664 warned = 1;
1665 }
1666
1667 mask |= setmask << new_base;
1668 count += addregs;
1669
1670 if (*str == '-') /* We have the start of a range expression */
1671 {
1672 int high_range;
1673
1674 str++;
1675
1676 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
1677 == FAIL)
1678 {
1679 inst.error = gettext (reg_expected_msgs[regtype]);
1680 return FAIL;
1681 }
1682
1683 if (high_range >= max_regs)
1684 {
1685 first_error (_("register out of range in list"));
1686 return FAIL;
1687 }
1688
1689 if (regtype == REG_TYPE_NQ)
1690 high_range = high_range + 1;
1691
1692 if (high_range <= new_base)
1693 {
1694 inst.error = _("register range not in ascending order");
1695 return FAIL;
1696 }
1697
1698 for (new_base += addregs; new_base <= high_range; new_base += addregs)
1699 {
1700 if (mask & (setmask << new_base))
1701 {
1702 inst.error = _("invalid register list");
1703 return FAIL;
1704 }
1705
1706 mask |= setmask << new_base;
1707 count += addregs;
1708 }
1709 }
1710 }
1711 while (skip_past_comma (&str) != FAIL);
1712
1713 str++;
1714
1715 /* Sanity check -- should have raised a parse error above. */
1716 if (count == 0 || count > max_regs)
1717 abort ();
1718
1719 *pbase = base_reg;
1720
1721 /* Final test -- the registers must be consecutive. */
1722 mask >>= base_reg;
1723 for (i = 0; i < count; i++)
1724 {
1725 if ((mask & (1u << i)) == 0)
1726 {
1727 inst.error = _("non-contiguous register range");
1728 return FAIL;
1729 }
1730 }
1731
1732 *ccp = str;
1733
1734 return count;
1735 }
1736
1737 /* True if two alias types are the same. */
1738
1739 static int
1740 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1741 {
1742 if (!a && !b)
1743 return 1;
1744
1745 if (!a || !b)
1746 return 0;
1747
1748 if (a->defined != b->defined)
1749 return 0;
1750
1751 if ((a->defined & NTA_HASTYPE) != 0
1752 && (a->eltype.type != b->eltype.type
1753 || a->eltype.size != b->eltype.size))
1754 return 0;
1755
1756 if ((a->defined & NTA_HASINDEX) != 0
1757 && (a->index != b->index))
1758 return 0;
1759
1760 return 1;
1761 }
1762
1763 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1764 The base register is put in *PBASE.
1765 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
1766 the return value.
1767 The register stride (minus one) is put in bit 4 of the return value.
1768 Bits [6:5] encode the list length (minus one).
1769 The type of the list elements is put in *ELTYPE, if non-NULL. */
1770
1771 #define NEON_LANE(X) ((X) & 0xf)
1772 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
1773 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1774
1775 static int
1776 parse_neon_el_struct_list (char **str, unsigned *pbase,
1777 struct neon_type_el *eltype)
1778 {
1779 char *ptr = *str;
1780 int base_reg = -1;
1781 int reg_incr = -1;
1782 int count = 0;
1783 int lane = -1;
1784 int leading_brace = 0;
1785 enum arm_reg_type rtype = REG_TYPE_NDQ;
1786 int addregs = 1;
1787 const char *const incr_error = "register stride must be 1 or 2";
1788 const char *const type_error = "mismatched element/structure types in list";
1789 struct neon_typed_alias firsttype;
1790
1791 if (skip_past_char (&ptr, '{') == SUCCESS)
1792 leading_brace = 1;
1793
1794 do
1795 {
1796 struct neon_typed_alias atype;
1797 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1798
1799 if (getreg == FAIL)
1800 {
1801 first_error (_(reg_expected_msgs[rtype]));
1802 return FAIL;
1803 }
1804
1805 if (base_reg == -1)
1806 {
1807 base_reg = getreg;
1808 if (rtype == REG_TYPE_NQ)
1809 {
1810 reg_incr = 1;
1811 addregs = 2;
1812 }
1813 firsttype = atype;
1814 }
1815 else if (reg_incr == -1)
1816 {
1817 reg_incr = getreg - base_reg;
1818 if (reg_incr < 1 || reg_incr > 2)
1819 {
1820 first_error (_(incr_error));
1821 return FAIL;
1822 }
1823 }
1824 else if (getreg != base_reg + reg_incr * count)
1825 {
1826 first_error (_(incr_error));
1827 return FAIL;
1828 }
1829
1830 if (!neon_alias_types_same (&atype, &firsttype))
1831 {
1832 first_error (_(type_error));
1833 return FAIL;
1834 }
1835
1836 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1837 modes. */
1838 if (ptr[0] == '-')
1839 {
1840 struct neon_typed_alias htype;
1841 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1842 if (lane == -1)
1843 lane = NEON_INTERLEAVE_LANES;
1844 else if (lane != NEON_INTERLEAVE_LANES)
1845 {
1846 first_error (_(type_error));
1847 return FAIL;
1848 }
1849 if (reg_incr == -1)
1850 reg_incr = 1;
1851 else if (reg_incr != 1)
1852 {
1853 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
1854 return FAIL;
1855 }
1856 ptr++;
1857 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
1858 if (hireg == FAIL)
1859 {
1860 first_error (_(reg_expected_msgs[rtype]));
1861 return FAIL;
1862 }
1863 if (!neon_alias_types_same (&htype, &firsttype))
1864 {
1865 first_error (_(type_error));
1866 return FAIL;
1867 }
1868 count += hireg + dregs - getreg;
1869 continue;
1870 }
1871
1872 /* If we're using Q registers, we can't use [] or [n] syntax. */
1873 if (rtype == REG_TYPE_NQ)
1874 {
1875 count += 2;
1876 continue;
1877 }
1878
1879 if ((atype.defined & NTA_HASINDEX) != 0)
1880 {
1881 if (lane == -1)
1882 lane = atype.index;
1883 else if (lane != atype.index)
1884 {
1885 first_error (_(type_error));
1886 return FAIL;
1887 }
1888 }
1889 else if (lane == -1)
1890 lane = NEON_INTERLEAVE_LANES;
1891 else if (lane != NEON_INTERLEAVE_LANES)
1892 {
1893 first_error (_(type_error));
1894 return FAIL;
1895 }
1896 count++;
1897 }
1898 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
1899
1900 /* No lane set by [x]. We must be interleaving structures. */
1901 if (lane == -1)
1902 lane = NEON_INTERLEAVE_LANES;
1903
1904 /* Sanity check. */
1905 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
1906 || (count > 1 && reg_incr == -1))
1907 {
1908 first_error (_("error parsing element/structure list"));
1909 return FAIL;
1910 }
1911
1912 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
1913 {
1914 first_error (_("expected }"));
1915 return FAIL;
1916 }
1917
1918 if (reg_incr == -1)
1919 reg_incr = 1;
1920
1921 if (eltype)
1922 *eltype = firsttype.eltype;
1923
1924 *pbase = base_reg;
1925 *str = ptr;
1926
1927 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
1928 }
1929
1930 /* Parse an explicit relocation suffix on an expression. This is
1931 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1932 arm_reloc_hsh contains no entries, so this function can only
1933 succeed if there is no () after the word. Returns -1 on error,
1934 BFD_RELOC_UNUSED if there wasn't any suffix. */
1935 static int
1936 parse_reloc (char **str)
1937 {
1938 struct reloc_entry *r;
1939 char *p, *q;
1940
1941 if (**str != '(')
1942 return BFD_RELOC_UNUSED;
1943
1944 p = *str + 1;
1945 q = p;
1946
1947 while (*q && *q != ')' && *q != ',')
1948 q++;
1949 if (*q != ')')
1950 return -1;
1951
1952 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1953 return -1;
1954
1955 *str = q + 1;
1956 return r->reloc;
1957 }
1958
1959 /* Directives: register aliases. */
1960
1961 static struct reg_entry *
1962 insert_reg_alias (char *str, int number, int type)
1963 {
1964 struct reg_entry *new;
1965 const char *name;
1966
1967 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1968 {
1969 if (new->builtin)
1970 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
1971
1972 /* Only warn about a redefinition if it's not defined as the
1973 same register. */
1974 else if (new->number != number || new->type != type)
1975 as_warn (_("ignoring redefinition of register alias '%s'"), str);
1976
1977 return NULL;
1978 }
1979
1980 name = xstrdup (str);
1981 new = xmalloc (sizeof (struct reg_entry));
1982
1983 new->name = name;
1984 new->number = number;
1985 new->type = type;
1986 new->builtin = FALSE;
1987 new->neon = NULL;
1988
1989 if (hash_insert (arm_reg_hsh, name, (PTR) new))
1990 abort ();
1991
1992 return new;
1993 }
1994
1995 static void
1996 insert_neon_reg_alias (char *str, int number, int type,
1997 struct neon_typed_alias *atype)
1998 {
1999 struct reg_entry *reg = insert_reg_alias (str, number, type);
2000
2001 if (!reg)
2002 {
2003 first_error (_("attempt to redefine typed alias"));
2004 return;
2005 }
2006
2007 if (atype)
2008 {
2009 reg->neon = xmalloc (sizeof (struct neon_typed_alias));
2010 *reg->neon = *atype;
2011 }
2012 }
2013
2014 /* Look for the .req directive. This is of the form:
2015
2016 new_register_name .req existing_register_name
2017
2018 If we find one, or if it looks sufficiently like one that we want to
2019 handle any error here, return TRUE. Otherwise return FALSE. */
2020
2021 static bfd_boolean
2022 create_register_alias (char * newname, char *p)
2023 {
2024 struct reg_entry *old;
2025 char *oldname, *nbuf;
2026 size_t nlen;
2027
2028 /* The input scrubber ensures that whitespace after the mnemonic is
2029 collapsed to single spaces. */
2030 oldname = p;
2031 if (strncmp (oldname, " .req ", 6) != 0)
2032 return FALSE;
2033
2034 oldname += 6;
2035 if (*oldname == '\0')
2036 return FALSE;
2037
2038 old = hash_find (arm_reg_hsh, oldname);
2039 if (!old)
2040 {
2041 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2042 return TRUE;
2043 }
2044
2045 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2046 the desired alias name, and p points to its end. If not, then
2047 the desired alias name is in the global original_case_string. */
2048 #ifdef TC_CASE_SENSITIVE
2049 nlen = p - newname;
2050 #else
2051 newname = original_case_string;
2052 nlen = strlen (newname);
2053 #endif
2054
2055 nbuf = alloca (nlen + 1);
2056 memcpy (nbuf, newname, nlen);
2057 nbuf[nlen] = '\0';
2058
2059 /* Create aliases under the new name as stated; an all-lowercase
2060 version of the new name; and an all-uppercase version of the new
2061 name. */
2062 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2063 {
2064 for (p = nbuf; *p; p++)
2065 *p = TOUPPER (*p);
2066
2067 if (strncmp (nbuf, newname, nlen))
2068 {
2069 /* If this attempt to create an additional alias fails, do not bother
2070 trying to create the all-lower case alias. We will fail and issue
2071 a second, duplicate error message. This situation arises when the
2072 programmer does something like:
2073 foo .req r0
2074 Foo .req r1
2075 The second .req creates the "Foo" alias but then fails to create
2076 the artificial FOO alias because it has already been created by the
2077 first .req. */
2078 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2079 return TRUE;
2080 }
2081
2082 for (p = nbuf; *p; p++)
2083 *p = TOLOWER (*p);
2084
2085 if (strncmp (nbuf, newname, nlen))
2086 insert_reg_alias (nbuf, old->number, old->type);
2087 }
2088
2089 return TRUE;
2090 }
2091
2092 /* Create a Neon typed/indexed register alias using directives, e.g.:
2093 X .dn d5.s32[1]
2094 Y .qn 6.s16
2095 Z .dn d7
2096 T .dn Z[0]
2097 These typed registers can be used instead of the types specified after the
2098 Neon mnemonic, so long as all operands given have types. Types can also be
2099 specified directly, e.g.:
2100 vadd d0.s32, d1.s32, d2.s32 */
2101
2102 static int
2103 create_neon_reg_alias (char *newname, char *p)
2104 {
2105 enum arm_reg_type basetype;
2106 struct reg_entry *basereg;
2107 struct reg_entry mybasereg;
2108 struct neon_type ntype;
2109 struct neon_typed_alias typeinfo;
2110 char *namebuf, *nameend;
2111 int namelen;
2112
2113 typeinfo.defined = 0;
2114 typeinfo.eltype.type = NT_invtype;
2115 typeinfo.eltype.size = -1;
2116 typeinfo.index = -1;
2117
2118 nameend = p;
2119
2120 if (strncmp (p, " .dn ", 5) == 0)
2121 basetype = REG_TYPE_VFD;
2122 else if (strncmp (p, " .qn ", 5) == 0)
2123 basetype = REG_TYPE_NQ;
2124 else
2125 return 0;
2126
2127 p += 5;
2128
2129 if (*p == '\0')
2130 return 0;
2131
2132 basereg = arm_reg_parse_multi (&p);
2133
2134 if (basereg && basereg->type != basetype)
2135 {
2136 as_bad (_("bad type for register"));
2137 return 0;
2138 }
2139
2140 if (basereg == NULL)
2141 {
2142 expressionS exp;
2143 /* Try parsing as an integer. */
2144 my_get_expression (&exp, &p, GE_NO_PREFIX);
2145 if (exp.X_op != O_constant)
2146 {
2147 as_bad (_("expression must be constant"));
2148 return 0;
2149 }
2150 basereg = &mybasereg;
2151 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2152 : exp.X_add_number;
2153 basereg->neon = 0;
2154 }
2155
2156 if (basereg->neon)
2157 typeinfo = *basereg->neon;
2158
2159 if (parse_neon_type (&ntype, &p) == SUCCESS)
2160 {
2161 /* We got a type. */
2162 if (typeinfo.defined & NTA_HASTYPE)
2163 {
2164 as_bad (_("can't redefine the type of a register alias"));
2165 return 0;
2166 }
2167
2168 typeinfo.defined |= NTA_HASTYPE;
2169 if (ntype.elems != 1)
2170 {
2171 as_bad (_("you must specify a single type only"));
2172 return 0;
2173 }
2174 typeinfo.eltype = ntype.el[0];
2175 }
2176
2177 if (skip_past_char (&p, '[') == SUCCESS)
2178 {
2179 expressionS exp;
2180 /* We got a scalar index. */
2181
2182 if (typeinfo.defined & NTA_HASINDEX)
2183 {
2184 as_bad (_("can't redefine the index of a scalar alias"));
2185 return 0;
2186 }
2187
2188 my_get_expression (&exp, &p, GE_NO_PREFIX);
2189
2190 if (exp.X_op != O_constant)
2191 {
2192 as_bad (_("scalar index must be constant"));
2193 return 0;
2194 }
2195
2196 typeinfo.defined |= NTA_HASINDEX;
2197 typeinfo.index = exp.X_add_number;
2198
2199 if (skip_past_char (&p, ']') == FAIL)
2200 {
2201 as_bad (_("expecting ]"));
2202 return 0;
2203 }
2204 }
2205
2206 namelen = nameend - newname;
2207 namebuf = alloca (namelen + 1);
2208 strncpy (namebuf, newname, namelen);
2209 namebuf[namelen] = '\0';
2210
2211 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2212 typeinfo.defined != 0 ? &typeinfo : NULL);
2213
2214 /* Insert name in all uppercase. */
2215 for (p = namebuf; *p; p++)
2216 *p = TOUPPER (*p);
2217
2218 if (strncmp (namebuf, newname, namelen))
2219 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2220 typeinfo.defined != 0 ? &typeinfo : NULL);
2221
2222 /* Insert name in all lowercase. */
2223 for (p = namebuf; *p; p++)
2224 *p = TOLOWER (*p);
2225
2226 if (strncmp (namebuf, newname, namelen))
2227 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2228 typeinfo.defined != 0 ? &typeinfo : NULL);
2229
2230 return 1;
2231 }
2232
2233 /* Should never be called, as .req goes between the alias and the
2234 register name, not at the beginning of the line. */
2235 static void
2236 s_req (int a ATTRIBUTE_UNUSED)
2237 {
2238 as_bad (_("invalid syntax for .req directive"));
2239 }
2240
2241 static void
2242 s_dn (int a ATTRIBUTE_UNUSED)
2243 {
2244 as_bad (_("invalid syntax for .dn directive"));
2245 }
2246
2247 static void
2248 s_qn (int a ATTRIBUTE_UNUSED)
2249 {
2250 as_bad (_("invalid syntax for .qn directive"));
2251 }
2252
2253 /* The .unreq directive deletes an alias which was previously defined
2254 by .req. For example:
2255
2256 my_alias .req r11
2257 .unreq my_alias */
2258
2259 static void
2260 s_unreq (int a ATTRIBUTE_UNUSED)
2261 {
2262 char * name;
2263 char saved_char;
2264
2265 name = input_line_pointer;
2266
2267 while (*input_line_pointer != 0
2268 && *input_line_pointer != ' '
2269 && *input_line_pointer != '\n')
2270 ++input_line_pointer;
2271
2272 saved_char = *input_line_pointer;
2273 *input_line_pointer = 0;
2274
2275 if (!*name)
2276 as_bad (_("invalid syntax for .unreq directive"));
2277 else
2278 {
2279 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
2280
2281 if (!reg)
2282 as_bad (_("unknown register alias '%s'"), name);
2283 else if (reg->builtin)
2284 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2285 name);
2286 else
2287 {
2288 char * p;
2289 char * nbuf;
2290
2291 hash_delete (arm_reg_hsh, name);
2292 free ((char *) reg->name);
2293 if (reg->neon)
2294 free (reg->neon);
2295 free (reg);
2296
2297 /* Also locate the all upper case and all lower case versions.
2298 Do not complain if we cannot find one or the other as it
2299 was probably deleted above. */
2300
2301 nbuf = strdup (name);
2302 for (p = nbuf; *p; p++)
2303 *p = TOUPPER (*p);
2304 reg = hash_find (arm_reg_hsh, nbuf);
2305 if (reg)
2306 {
2307 hash_delete (arm_reg_hsh, nbuf);
2308 free ((char *) reg->name);
2309 if (reg->neon)
2310 free (reg->neon);
2311 free (reg);
2312 }
2313
2314 for (p = nbuf; *p; p++)
2315 *p = TOLOWER (*p);
2316 reg = hash_find (arm_reg_hsh, nbuf);
2317 if (reg)
2318 {
2319 hash_delete (arm_reg_hsh, nbuf);
2320 free ((char *) reg->name);
2321 if (reg->neon)
2322 free (reg->neon);
2323 free (reg);
2324 }
2325
2326 free (nbuf);
2327 }
2328 }
2329
2330 *input_line_pointer = saved_char;
2331 demand_empty_rest_of_line ();
2332 }
2333
2334 /* Directives: Instruction set selection. */
2335
2336 #ifdef OBJ_ELF
2337 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2338 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2339 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2340 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2341
2342 static enum mstate mapstate = MAP_UNDEFINED;
2343
2344 void
2345 mapping_state (enum mstate state)
2346 {
2347 symbolS * symbolP;
2348 const char * symname;
2349 int type;
2350
2351 if (mapstate == state)
2352 /* The mapping symbol has already been emitted.
2353 There is nothing else to do. */
2354 return;
2355
2356 mapstate = state;
2357
2358 switch (state)
2359 {
2360 case MAP_DATA:
2361 symname = "$d";
2362 type = BSF_NO_FLAGS;
2363 break;
2364 case MAP_ARM:
2365 symname = "$a";
2366 type = BSF_NO_FLAGS;
2367 break;
2368 case MAP_THUMB:
2369 symname = "$t";
2370 type = BSF_NO_FLAGS;
2371 break;
2372 case MAP_UNDEFINED:
2373 return;
2374 default:
2375 abort ();
2376 }
2377
2378 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2379
2380 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
2381 symbol_table_insert (symbolP);
2382 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2383
2384 switch (state)
2385 {
2386 case MAP_ARM:
2387 THUMB_SET_FUNC (symbolP, 0);
2388 ARM_SET_THUMB (symbolP, 0);
2389 ARM_SET_INTERWORK (symbolP, support_interwork);
2390 break;
2391
2392 case MAP_THUMB:
2393 THUMB_SET_FUNC (symbolP, 1);
2394 ARM_SET_THUMB (symbolP, 1);
2395 ARM_SET_INTERWORK (symbolP, support_interwork);
2396 break;
2397
2398 case MAP_DATA:
2399 default:
2400 return;
2401 }
2402 }
2403 #else
2404 #define mapping_state(x) /* nothing */
2405 #endif
2406
2407 /* Find the real, Thumb encoded start of a Thumb function. */
2408
2409 static symbolS *
2410 find_real_start (symbolS * symbolP)
2411 {
2412 char * real_start;
2413 const char * name = S_GET_NAME (symbolP);
2414 symbolS * new_target;
2415
2416 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2417 #define STUB_NAME ".real_start_of"
2418
2419 if (name == NULL)
2420 abort ();
2421
2422 /* The compiler may generate BL instructions to local labels because
2423 it needs to perform a branch to a far away location. These labels
2424 do not have a corresponding ".real_start_of" label. We check
2425 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2426 the ".real_start_of" convention for nonlocal branches. */
2427 if (S_IS_LOCAL (symbolP) || name[0] == '.')
2428 return symbolP;
2429
2430 real_start = ACONCAT ((STUB_NAME, name, NULL));
2431 new_target = symbol_find (real_start);
2432
2433 if (new_target == NULL)
2434 {
2435 as_warn (_("Failed to find real start of function: %s\n"), name);
2436 new_target = symbolP;
2437 }
2438
2439 return new_target;
2440 }
2441
2442 static void
2443 opcode_select (int width)
2444 {
2445 switch (width)
2446 {
2447 case 16:
2448 if (! thumb_mode)
2449 {
2450 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
2451 as_bad (_("selected processor does not support THUMB opcodes"));
2452
2453 thumb_mode = 1;
2454 /* No need to force the alignment, since we will have been
2455 coming from ARM mode, which is word-aligned. */
2456 record_alignment (now_seg, 1);
2457 }
2458 mapping_state (MAP_THUMB);
2459 break;
2460
2461 case 32:
2462 if (thumb_mode)
2463 {
2464 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
2465 as_bad (_("selected processor does not support ARM opcodes"));
2466
2467 thumb_mode = 0;
2468
2469 if (!need_pass_2)
2470 frag_align (2, 0, 0);
2471
2472 record_alignment (now_seg, 1);
2473 }
2474 mapping_state (MAP_ARM);
2475 break;
2476
2477 default:
2478 as_bad (_("invalid instruction size selected (%d)"), width);
2479 }
2480 }
2481
2482 static void
2483 s_arm (int ignore ATTRIBUTE_UNUSED)
2484 {
2485 opcode_select (32);
2486 demand_empty_rest_of_line ();
2487 }
2488
2489 static void
2490 s_thumb (int ignore ATTRIBUTE_UNUSED)
2491 {
2492 opcode_select (16);
2493 demand_empty_rest_of_line ();
2494 }
2495
2496 static void
2497 s_code (int unused ATTRIBUTE_UNUSED)
2498 {
2499 int temp;
2500
2501 temp = get_absolute_expression ();
2502 switch (temp)
2503 {
2504 case 16:
2505 case 32:
2506 opcode_select (temp);
2507 break;
2508
2509 default:
2510 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2511 }
2512 }
2513
2514 static void
2515 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2516 {
2517 /* If we are not already in thumb mode go into it, EVEN if
2518 the target processor does not support thumb instructions.
2519 This is used by gcc/config/arm/lib1funcs.asm for example
2520 to compile interworking support functions even if the
2521 target processor should not support interworking. */
2522 if (! thumb_mode)
2523 {
2524 thumb_mode = 2;
2525 record_alignment (now_seg, 1);
2526 }
2527
2528 demand_empty_rest_of_line ();
2529 }
2530
2531 static void
2532 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2533 {
2534 s_thumb (0);
2535
2536 /* The following label is the name/address of the start of a Thumb function.
2537 We need to know this for the interworking support. */
2538 label_is_thumb_function_name = TRUE;
2539 }
2540
2541 /* Perform a .set directive, but also mark the alias as
2542 being a thumb function. */
2543
2544 static void
2545 s_thumb_set (int equiv)
2546 {
2547 /* XXX the following is a duplicate of the code for s_set() in read.c
2548 We cannot just call that code as we need to get at the symbol that
2549 is created. */
2550 char * name;
2551 char delim;
2552 char * end_name;
2553 symbolS * symbolP;
2554
2555 /* Especial apologies for the random logic:
2556 This just grew, and could be parsed much more simply!
2557 Dean - in haste. */
2558 name = input_line_pointer;
2559 delim = get_symbol_end ();
2560 end_name = input_line_pointer;
2561 *end_name = delim;
2562
2563 if (*input_line_pointer != ',')
2564 {
2565 *end_name = 0;
2566 as_bad (_("expected comma after name \"%s\""), name);
2567 *end_name = delim;
2568 ignore_rest_of_line ();
2569 return;
2570 }
2571
2572 input_line_pointer++;
2573 *end_name = 0;
2574
2575 if (name[0] == '.' && name[1] == '\0')
2576 {
2577 /* XXX - this should not happen to .thumb_set. */
2578 abort ();
2579 }
2580
2581 if ((symbolP = symbol_find (name)) == NULL
2582 && (symbolP = md_undefined_symbol (name)) == NULL)
2583 {
2584 #ifndef NO_LISTING
2585 /* When doing symbol listings, play games with dummy fragments living
2586 outside the normal fragment chain to record the file and line info
2587 for this symbol. */
2588 if (listing & LISTING_SYMBOLS)
2589 {
2590 extern struct list_info_struct * listing_tail;
2591 fragS * dummy_frag = xmalloc (sizeof (fragS));
2592
2593 memset (dummy_frag, 0, sizeof (fragS));
2594 dummy_frag->fr_type = rs_fill;
2595 dummy_frag->line = listing_tail;
2596 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2597 dummy_frag->fr_symbol = symbolP;
2598 }
2599 else
2600 #endif
2601 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2602
2603 #ifdef OBJ_COFF
2604 /* "set" symbols are local unless otherwise specified. */
2605 SF_SET_LOCAL (symbolP);
2606 #endif /* OBJ_COFF */
2607 } /* Make a new symbol. */
2608
2609 symbol_table_insert (symbolP);
2610
2611 * end_name = delim;
2612
2613 if (equiv
2614 && S_IS_DEFINED (symbolP)
2615 && S_GET_SEGMENT (symbolP) != reg_section)
2616 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2617
2618 pseudo_set (symbolP);
2619
2620 demand_empty_rest_of_line ();
2621
2622 /* XXX Now we come to the Thumb specific bit of code. */
2623
2624 THUMB_SET_FUNC (symbolP, 1);
2625 ARM_SET_THUMB (symbolP, 1);
2626 #if defined OBJ_ELF || defined OBJ_COFF
2627 ARM_SET_INTERWORK (symbolP, support_interwork);
2628 #endif
2629 }
2630
2631 /* Directives: Mode selection. */
2632
2633 /* .syntax [unified|divided] - choose the new unified syntax
2634 (same for Arm and Thumb encoding, modulo slight differences in what
2635 can be represented) or the old divergent syntax for each mode. */
2636 static void
2637 s_syntax (int unused ATTRIBUTE_UNUSED)
2638 {
2639 char *name, delim;
2640
2641 name = input_line_pointer;
2642 delim = get_symbol_end ();
2643
2644 if (!strcasecmp (name, "unified"))
2645 unified_syntax = TRUE;
2646 else if (!strcasecmp (name, "divided"))
2647 unified_syntax = FALSE;
2648 else
2649 {
2650 as_bad (_("unrecognized syntax mode \"%s\""), name);
2651 return;
2652 }
2653 *input_line_pointer = delim;
2654 demand_empty_rest_of_line ();
2655 }
2656
2657 /* Directives: sectioning and alignment. */
2658
2659 /* Same as s_align_ptwo but align 0 => align 2. */
2660
2661 static void
2662 s_align (int unused ATTRIBUTE_UNUSED)
2663 {
2664 int temp;
2665 bfd_boolean fill_p;
2666 long temp_fill;
2667 long max_alignment = 15;
2668
2669 temp = get_absolute_expression ();
2670 if (temp > max_alignment)
2671 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2672 else if (temp < 0)
2673 {
2674 as_bad (_("alignment negative. 0 assumed."));
2675 temp = 0;
2676 }
2677
2678 if (*input_line_pointer == ',')
2679 {
2680 input_line_pointer++;
2681 temp_fill = get_absolute_expression ();
2682 fill_p = TRUE;
2683 }
2684 else
2685 {
2686 fill_p = FALSE;
2687 temp_fill = 0;
2688 }
2689
2690 if (!temp)
2691 temp = 2;
2692
2693 /* Only make a frag if we HAVE to. */
2694 if (temp && !need_pass_2)
2695 {
2696 if (!fill_p && subseg_text_p (now_seg))
2697 frag_align_code (temp, 0);
2698 else
2699 frag_align (temp, (int) temp_fill, 0);
2700 }
2701 demand_empty_rest_of_line ();
2702
2703 record_alignment (now_seg, temp);
2704 }
2705
2706 static void
2707 s_bss (int ignore ATTRIBUTE_UNUSED)
2708 {
2709 /* We don't support putting frags in the BSS segment, we fake it by
2710 marking in_bss, then looking at s_skip for clues. */
2711 subseg_set (bss_section, 0);
2712 demand_empty_rest_of_line ();
2713 mapping_state (MAP_DATA);
2714 }
2715
2716 static void
2717 s_even (int ignore ATTRIBUTE_UNUSED)
2718 {
2719 /* Never make frag if expect extra pass. */
2720 if (!need_pass_2)
2721 frag_align (1, 0, 0);
2722
2723 record_alignment (now_seg, 1);
2724
2725 demand_empty_rest_of_line ();
2726 }
2727
2728 /* Directives: Literal pools. */
2729
2730 static literal_pool *
2731 find_literal_pool (void)
2732 {
2733 literal_pool * pool;
2734
2735 for (pool = list_of_pools; pool != NULL; pool = pool->next)
2736 {
2737 if (pool->section == now_seg
2738 && pool->sub_section == now_subseg)
2739 break;
2740 }
2741
2742 return pool;
2743 }
2744
2745 static literal_pool *
2746 find_or_make_literal_pool (void)
2747 {
2748 /* Next literal pool ID number. */
2749 static unsigned int latest_pool_num = 1;
2750 literal_pool * pool;
2751
2752 pool = find_literal_pool ();
2753
2754 if (pool == NULL)
2755 {
2756 /* Create a new pool. */
2757 pool = xmalloc (sizeof (* pool));
2758 if (! pool)
2759 return NULL;
2760
2761 pool->next_free_entry = 0;
2762 pool->section = now_seg;
2763 pool->sub_section = now_subseg;
2764 pool->next = list_of_pools;
2765 pool->symbol = NULL;
2766
2767 /* Add it to the list. */
2768 list_of_pools = pool;
2769 }
2770
2771 /* New pools, and emptied pools, will have a NULL symbol. */
2772 if (pool->symbol == NULL)
2773 {
2774 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2775 (valueT) 0, &zero_address_frag);
2776 pool->id = latest_pool_num ++;
2777 }
2778
2779 /* Done. */
2780 return pool;
2781 }
2782
2783 /* Add the literal in the global 'inst'
2784 structure to the relevant literal pool. */
2785
2786 static int
2787 add_to_lit_pool (void)
2788 {
2789 literal_pool * pool;
2790 unsigned int entry;
2791
2792 pool = find_or_make_literal_pool ();
2793
2794 /* Check if this literal value is already in the pool. */
2795 for (entry = 0; entry < pool->next_free_entry; entry ++)
2796 {
2797 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2798 && (inst.reloc.exp.X_op == O_constant)
2799 && (pool->literals[entry].X_add_number
2800 == inst.reloc.exp.X_add_number)
2801 && (pool->literals[entry].X_unsigned
2802 == inst.reloc.exp.X_unsigned))
2803 break;
2804
2805 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2806 && (inst.reloc.exp.X_op == O_symbol)
2807 && (pool->literals[entry].X_add_number
2808 == inst.reloc.exp.X_add_number)
2809 && (pool->literals[entry].X_add_symbol
2810 == inst.reloc.exp.X_add_symbol)
2811 && (pool->literals[entry].X_op_symbol
2812 == inst.reloc.exp.X_op_symbol))
2813 break;
2814 }
2815
2816 /* Do we need to create a new entry? */
2817 if (entry == pool->next_free_entry)
2818 {
2819 if (entry >= MAX_LITERAL_POOL_SIZE)
2820 {
2821 inst.error = _("literal pool overflow");
2822 return FAIL;
2823 }
2824
2825 pool->literals[entry] = inst.reloc.exp;
2826 pool->next_free_entry += 1;
2827 }
2828
2829 inst.reloc.exp.X_op = O_symbol;
2830 inst.reloc.exp.X_add_number = ((int) entry) * 4;
2831 inst.reloc.exp.X_add_symbol = pool->symbol;
2832
2833 return SUCCESS;
2834 }
2835
2836 /* Can't use symbol_new here, so have to create a symbol and then at
2837 a later date assign it a value. Thats what these functions do. */
2838
2839 static void
2840 symbol_locate (symbolS * symbolP,
2841 const char * name, /* It is copied, the caller can modify. */
2842 segT segment, /* Segment identifier (SEG_<something>). */
2843 valueT valu, /* Symbol value. */
2844 fragS * frag) /* Associated fragment. */
2845 {
2846 unsigned int name_length;
2847 char * preserved_copy_of_name;
2848
2849 name_length = strlen (name) + 1; /* +1 for \0. */
2850 obstack_grow (&notes, name, name_length);
2851 preserved_copy_of_name = obstack_finish (&notes);
2852
2853 #ifdef tc_canonicalize_symbol_name
2854 preserved_copy_of_name =
2855 tc_canonicalize_symbol_name (preserved_copy_of_name);
2856 #endif
2857
2858 S_SET_NAME (symbolP, preserved_copy_of_name);
2859
2860 S_SET_SEGMENT (symbolP, segment);
2861 S_SET_VALUE (symbolP, valu);
2862 symbol_clear_list_pointers (symbolP);
2863
2864 symbol_set_frag (symbolP, frag);
2865
2866 /* Link to end of symbol chain. */
2867 {
2868 extern int symbol_table_frozen;
2869
2870 if (symbol_table_frozen)
2871 abort ();
2872 }
2873
2874 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
2875
2876 obj_symbol_new_hook (symbolP);
2877
2878 #ifdef tc_symbol_new_hook
2879 tc_symbol_new_hook (symbolP);
2880 #endif
2881
2882 #ifdef DEBUG_SYMS
2883 verify_symbol_chain (symbol_rootP, symbol_lastP);
2884 #endif /* DEBUG_SYMS */
2885 }
2886
2887
2888 static void
2889 s_ltorg (int ignored ATTRIBUTE_UNUSED)
2890 {
2891 unsigned int entry;
2892 literal_pool * pool;
2893 char sym_name[20];
2894
2895 pool = find_literal_pool ();
2896 if (pool == NULL
2897 || pool->symbol == NULL
2898 || pool->next_free_entry == 0)
2899 return;
2900
2901 mapping_state (MAP_DATA);
2902
2903 /* Align pool as you have word accesses.
2904 Only make a frag if we have to. */
2905 if (!need_pass_2)
2906 frag_align (2, 0, 0);
2907
2908 record_alignment (now_seg, 2);
2909
2910 sprintf (sym_name, "$$lit_\002%x", pool->id);
2911
2912 symbol_locate (pool->symbol, sym_name, now_seg,
2913 (valueT) frag_now_fix (), frag_now);
2914 symbol_table_insert (pool->symbol);
2915
2916 ARM_SET_THUMB (pool->symbol, thumb_mode);
2917
2918 #if defined OBJ_COFF || defined OBJ_ELF
2919 ARM_SET_INTERWORK (pool->symbol, support_interwork);
2920 #endif
2921
2922 for (entry = 0; entry < pool->next_free_entry; entry ++)
2923 /* First output the expression in the instruction to the pool. */
2924 emit_expr (&(pool->literals[entry]), 4); /* .word */
2925
2926 /* Mark the pool as empty. */
2927 pool->next_free_entry = 0;
2928 pool->symbol = NULL;
2929 }
2930
2931 #ifdef OBJ_ELF
2932 /* Forward declarations for functions below, in the MD interface
2933 section. */
2934 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
2935 static valueT create_unwind_entry (int);
2936 static void start_unwind_section (const segT, int);
2937 static void add_unwind_opcode (valueT, int);
2938 static void flush_pending_unwind (void);
2939
2940 /* Directives: Data. */
2941
2942 static void
2943 s_arm_elf_cons (int nbytes)
2944 {
2945 expressionS exp;
2946
2947 #ifdef md_flush_pending_output
2948 md_flush_pending_output ();
2949 #endif
2950
2951 if (is_it_end_of_statement ())
2952 {
2953 demand_empty_rest_of_line ();
2954 return;
2955 }
2956
2957 #ifdef md_cons_align
2958 md_cons_align (nbytes);
2959 #endif
2960
2961 mapping_state (MAP_DATA);
2962 do
2963 {
2964 int reloc;
2965 char *base = input_line_pointer;
2966
2967 expression (& exp);
2968
2969 if (exp.X_op != O_symbol)
2970 emit_expr (&exp, (unsigned int) nbytes);
2971 else
2972 {
2973 char *before_reloc = input_line_pointer;
2974 reloc = parse_reloc (&input_line_pointer);
2975 if (reloc == -1)
2976 {
2977 as_bad (_("unrecognized relocation suffix"));
2978 ignore_rest_of_line ();
2979 return;
2980 }
2981 else if (reloc == BFD_RELOC_UNUSED)
2982 emit_expr (&exp, (unsigned int) nbytes);
2983 else
2984 {
2985 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
2986 int size = bfd_get_reloc_size (howto);
2987
2988 if (reloc == BFD_RELOC_ARM_PLT32)
2989 {
2990 as_bad (_("(plt) is only valid on branch targets"));
2991 reloc = BFD_RELOC_UNUSED;
2992 size = 0;
2993 }
2994
2995 if (size > nbytes)
2996 as_bad (_("%s relocations do not fit in %d bytes"),
2997 howto->name, nbytes);
2998 else
2999 {
3000 /* We've parsed an expression stopping at O_symbol.
3001 But there may be more expression left now that we
3002 have parsed the relocation marker. Parse it again.
3003 XXX Surely there is a cleaner way to do this. */
3004 char *p = input_line_pointer;
3005 int offset;
3006 char *save_buf = alloca (input_line_pointer - base);
3007 memcpy (save_buf, base, input_line_pointer - base);
3008 memmove (base + (input_line_pointer - before_reloc),
3009 base, before_reloc - base);
3010
3011 input_line_pointer = base + (input_line_pointer-before_reloc);
3012 expression (&exp);
3013 memcpy (base, save_buf, p - base);
3014
3015 offset = nbytes - size;
3016 p = frag_more ((int) nbytes);
3017 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3018 size, &exp, 0, reloc);
3019 }
3020 }
3021 }
3022 }
3023 while (*input_line_pointer++ == ',');
3024
3025 /* Put terminator back into stream. */
3026 input_line_pointer --;
3027 demand_empty_rest_of_line ();
3028 }
3029
3030
3031 /* Parse a .rel31 directive. */
3032
3033 static void
3034 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3035 {
3036 expressionS exp;
3037 char *p;
3038 valueT highbit;
3039
3040 highbit = 0;
3041 if (*input_line_pointer == '1')
3042 highbit = 0x80000000;
3043 else if (*input_line_pointer != '0')
3044 as_bad (_("expected 0 or 1"));
3045
3046 input_line_pointer++;
3047 if (*input_line_pointer != ',')
3048 as_bad (_("missing comma"));
3049 input_line_pointer++;
3050
3051 #ifdef md_flush_pending_output
3052 md_flush_pending_output ();
3053 #endif
3054
3055 #ifdef md_cons_align
3056 md_cons_align (4);
3057 #endif
3058
3059 mapping_state (MAP_DATA);
3060
3061 expression (&exp);
3062
3063 p = frag_more (4);
3064 md_number_to_chars (p, highbit, 4);
3065 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3066 BFD_RELOC_ARM_PREL31);
3067
3068 demand_empty_rest_of_line ();
3069 }
3070
3071 /* Directives: AEABI stack-unwind tables. */
3072
3073 /* Parse an unwind_fnstart directive. Simply records the current location. */
3074
3075 static void
3076 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3077 {
3078 demand_empty_rest_of_line ();
3079 /* Mark the start of the function. */
3080 unwind.proc_start = expr_build_dot ();
3081
3082 /* Reset the rest of the unwind info. */
3083 unwind.opcode_count = 0;
3084 unwind.table_entry = NULL;
3085 unwind.personality_routine = NULL;
3086 unwind.personality_index = -1;
3087 unwind.frame_size = 0;
3088 unwind.fp_offset = 0;
3089 unwind.fp_reg = 13;
3090 unwind.fp_used = 0;
3091 unwind.sp_restored = 0;
3092 }
3093
3094
3095 /* Parse a handlerdata directive. Creates the exception handling table entry
3096 for the function. */
3097
3098 static void
3099 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3100 {
3101 demand_empty_rest_of_line ();
3102 if (unwind.table_entry)
3103 as_bad (_("duplicate .handlerdata directive"));
3104
3105 create_unwind_entry (1);
3106 }
3107
3108 /* Parse an unwind_fnend directive. Generates the index table entry. */
3109
3110 static void
3111 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3112 {
3113 long where;
3114 char *ptr;
3115 valueT val;
3116
3117 demand_empty_rest_of_line ();
3118
3119 /* Add eh table entry. */
3120 if (unwind.table_entry == NULL)
3121 val = create_unwind_entry (0);
3122 else
3123 val = 0;
3124
3125 /* Add index table entry. This is two words. */
3126 start_unwind_section (unwind.saved_seg, 1);
3127 frag_align (2, 0, 0);
3128 record_alignment (now_seg, 2);
3129
3130 ptr = frag_more (8);
3131 where = frag_now_fix () - 8;
3132
3133 /* Self relative offset of the function start. */
3134 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3135 BFD_RELOC_ARM_PREL31);
3136
3137 /* Indicate dependency on EHABI-defined personality routines to the
3138 linker, if it hasn't been done already. */
3139 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3140 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3141 {
3142 static const char *const name[] =
3143 {
3144 "__aeabi_unwind_cpp_pr0",
3145 "__aeabi_unwind_cpp_pr1",
3146 "__aeabi_unwind_cpp_pr2"
3147 };
3148 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3149 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3150 marked_pr_dependency |= 1 << unwind.personality_index;
3151 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3152 = marked_pr_dependency;
3153 }
3154
3155 if (val)
3156 /* Inline exception table entry. */
3157 md_number_to_chars (ptr + 4, val, 4);
3158 else
3159 /* Self relative offset of the table entry. */
3160 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3161 BFD_RELOC_ARM_PREL31);
3162
3163 /* Restore the original section. */
3164 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3165 }
3166
3167
3168 /* Parse an unwind_cantunwind directive. */
3169
3170 static void
3171 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3172 {
3173 demand_empty_rest_of_line ();
3174 if (unwind.personality_routine || unwind.personality_index != -1)
3175 as_bad (_("personality routine specified for cantunwind frame"));
3176
3177 unwind.personality_index = -2;
3178 }
3179
3180
3181 /* Parse a personalityindex directive. */
3182
3183 static void
3184 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3185 {
3186 expressionS exp;
3187
3188 if (unwind.personality_routine || unwind.personality_index != -1)
3189 as_bad (_("duplicate .personalityindex directive"));
3190
3191 expression (&exp);
3192
3193 if (exp.X_op != O_constant
3194 || exp.X_add_number < 0 || exp.X_add_number > 15)
3195 {
3196 as_bad (_("bad personality routine number"));
3197 ignore_rest_of_line ();
3198 return;
3199 }
3200
3201 unwind.personality_index = exp.X_add_number;
3202
3203 demand_empty_rest_of_line ();
3204 }
3205
3206
3207 /* Parse a personality directive. */
3208
3209 static void
3210 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3211 {
3212 char *name, *p, c;
3213
3214 if (unwind.personality_routine || unwind.personality_index != -1)
3215 as_bad (_("duplicate .personality directive"));
3216
3217 name = input_line_pointer;
3218 c = get_symbol_end ();
3219 p = input_line_pointer;
3220 unwind.personality_routine = symbol_find_or_make (name);
3221 *p = c;
3222 demand_empty_rest_of_line ();
3223 }
3224
3225
3226 /* Parse a directive saving core registers. */
3227
3228 static void
3229 s_arm_unwind_save_core (void)
3230 {
3231 valueT op;
3232 long range;
3233 int n;
3234
3235 range = parse_reg_list (&input_line_pointer);
3236 if (range == FAIL)
3237 {
3238 as_bad (_("expected register list"));
3239 ignore_rest_of_line ();
3240 return;
3241 }
3242
3243 demand_empty_rest_of_line ();
3244
3245 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3246 into .unwind_save {..., sp...}. We aren't bothered about the value of
3247 ip because it is clobbered by calls. */
3248 if (unwind.sp_restored && unwind.fp_reg == 12
3249 && (range & 0x3000) == 0x1000)
3250 {
3251 unwind.opcode_count--;
3252 unwind.sp_restored = 0;
3253 range = (range | 0x2000) & ~0x1000;
3254 unwind.pending_offset = 0;
3255 }
3256
3257 /* Pop r4-r15. */
3258 if (range & 0xfff0)
3259 {
3260 /* See if we can use the short opcodes. These pop a block of up to 8
3261 registers starting with r4, plus maybe r14. */
3262 for (n = 0; n < 8; n++)
3263 {
3264 /* Break at the first non-saved register. */
3265 if ((range & (1 << (n + 4))) == 0)
3266 break;
3267 }
3268 /* See if there are any other bits set. */
3269 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3270 {
3271 /* Use the long form. */
3272 op = 0x8000 | ((range >> 4) & 0xfff);
3273 add_unwind_opcode (op, 2);
3274 }
3275 else
3276 {
3277 /* Use the short form. */
3278 if (range & 0x4000)
3279 op = 0xa8; /* Pop r14. */
3280 else
3281 op = 0xa0; /* Do not pop r14. */
3282 op |= (n - 1);
3283 add_unwind_opcode (op, 1);
3284 }
3285 }
3286
3287 /* Pop r0-r3. */
3288 if (range & 0xf)
3289 {
3290 op = 0xb100 | (range & 0xf);
3291 add_unwind_opcode (op, 2);
3292 }
3293
3294 /* Record the number of bytes pushed. */
3295 for (n = 0; n < 16; n++)
3296 {
3297 if (range & (1 << n))
3298 unwind.frame_size += 4;
3299 }
3300 }
3301
3302
3303 /* Parse a directive saving FPA registers. */
3304
3305 static void
3306 s_arm_unwind_save_fpa (int reg)
3307 {
3308 expressionS exp;
3309 int num_regs;
3310 valueT op;
3311
3312 /* Get Number of registers to transfer. */
3313 if (skip_past_comma (&input_line_pointer) != FAIL)
3314 expression (&exp);
3315 else
3316 exp.X_op = O_illegal;
3317
3318 if (exp.X_op != O_constant)
3319 {
3320 as_bad (_("expected , <constant>"));
3321 ignore_rest_of_line ();
3322 return;
3323 }
3324
3325 num_regs = exp.X_add_number;
3326
3327 if (num_regs < 1 || num_regs > 4)
3328 {
3329 as_bad (_("number of registers must be in the range [1:4]"));
3330 ignore_rest_of_line ();
3331 return;
3332 }
3333
3334 demand_empty_rest_of_line ();
3335
3336 if (reg == 4)
3337 {
3338 /* Short form. */
3339 op = 0xb4 | (num_regs - 1);
3340 add_unwind_opcode (op, 1);
3341 }
3342 else
3343 {
3344 /* Long form. */
3345 op = 0xc800 | (reg << 4) | (num_regs - 1);
3346 add_unwind_opcode (op, 2);
3347 }
3348 unwind.frame_size += num_regs * 12;
3349 }
3350
3351
3352 /* Parse a directive saving VFP registers for ARMv6 and above. */
3353
3354 static void
3355 s_arm_unwind_save_vfp_armv6 (void)
3356 {
3357 int count;
3358 unsigned int start;
3359 valueT op;
3360 int num_vfpv3_regs = 0;
3361 int num_regs_below_16;
3362
3363 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3364 if (count == FAIL)
3365 {
3366 as_bad (_("expected register list"));
3367 ignore_rest_of_line ();
3368 return;
3369 }
3370
3371 demand_empty_rest_of_line ();
3372
3373 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3374 than FSTMX/FLDMX-style ones). */
3375
3376 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3377 if (start >= 16)
3378 num_vfpv3_regs = count;
3379 else if (start + count > 16)
3380 num_vfpv3_regs = start + count - 16;
3381
3382 if (num_vfpv3_regs > 0)
3383 {
3384 int start_offset = start > 16 ? start - 16 : 0;
3385 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3386 add_unwind_opcode (op, 2);
3387 }
3388
3389 /* Generate opcode for registers numbered in the range 0 .. 15. */
3390 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3391 assert (num_regs_below_16 + num_vfpv3_regs == count);
3392 if (num_regs_below_16 > 0)
3393 {
3394 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3395 add_unwind_opcode (op, 2);
3396 }
3397
3398 unwind.frame_size += count * 8;
3399 }
3400
3401
3402 /* Parse a directive saving VFP registers for pre-ARMv6. */
3403
3404 static void
3405 s_arm_unwind_save_vfp (void)
3406 {
3407 int count;
3408 unsigned int reg;
3409 valueT op;
3410
3411 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
3412 if (count == FAIL)
3413 {
3414 as_bad (_("expected register list"));
3415 ignore_rest_of_line ();
3416 return;
3417 }
3418
3419 demand_empty_rest_of_line ();
3420
3421 if (reg == 8)
3422 {
3423 /* Short form. */
3424 op = 0xb8 | (count - 1);
3425 add_unwind_opcode (op, 1);
3426 }
3427 else
3428 {
3429 /* Long form. */
3430 op = 0xb300 | (reg << 4) | (count - 1);
3431 add_unwind_opcode (op, 2);
3432 }
3433 unwind.frame_size += count * 8 + 4;
3434 }
3435
3436
3437 /* Parse a directive saving iWMMXt data registers. */
3438
3439 static void
3440 s_arm_unwind_save_mmxwr (void)
3441 {
3442 int reg;
3443 int hi_reg;
3444 int i;
3445 unsigned mask = 0;
3446 valueT op;
3447
3448 if (*input_line_pointer == '{')
3449 input_line_pointer++;
3450
3451 do
3452 {
3453 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3454
3455 if (reg == FAIL)
3456 {
3457 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3458 goto error;
3459 }
3460
3461 if (mask >> reg)
3462 as_tsktsk (_("register list not in ascending order"));
3463 mask |= 1 << reg;
3464
3465 if (*input_line_pointer == '-')
3466 {
3467 input_line_pointer++;
3468 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3469 if (hi_reg == FAIL)
3470 {
3471 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3472 goto error;
3473 }
3474 else if (reg >= hi_reg)
3475 {
3476 as_bad (_("bad register range"));
3477 goto error;
3478 }
3479 for (; reg < hi_reg; reg++)
3480 mask |= 1 << reg;
3481 }
3482 }
3483 while (skip_past_comma (&input_line_pointer) != FAIL);
3484
3485 if (*input_line_pointer == '}')
3486 input_line_pointer++;
3487
3488 demand_empty_rest_of_line ();
3489
3490 /* Generate any deferred opcodes because we're going to be looking at
3491 the list. */
3492 flush_pending_unwind ();
3493
3494 for (i = 0; i < 16; i++)
3495 {
3496 if (mask & (1 << i))
3497 unwind.frame_size += 8;
3498 }
3499
3500 /* Attempt to combine with a previous opcode. We do this because gcc
3501 likes to output separate unwind directives for a single block of
3502 registers. */
3503 if (unwind.opcode_count > 0)
3504 {
3505 i = unwind.opcodes[unwind.opcode_count - 1];
3506 if ((i & 0xf8) == 0xc0)
3507 {
3508 i &= 7;
3509 /* Only merge if the blocks are contiguous. */
3510 if (i < 6)
3511 {
3512 if ((mask & 0xfe00) == (1 << 9))
3513 {
3514 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3515 unwind.opcode_count--;
3516 }
3517 }
3518 else if (i == 6 && unwind.opcode_count >= 2)
3519 {
3520 i = unwind.opcodes[unwind.opcode_count - 2];
3521 reg = i >> 4;
3522 i &= 0xf;
3523
3524 op = 0xffff << (reg - 1);
3525 if (reg > 0
3526 && ((mask & op) == (1u << (reg - 1))))
3527 {
3528 op = (1 << (reg + i + 1)) - 1;
3529 op &= ~((1 << reg) - 1);
3530 mask |= op;
3531 unwind.opcode_count -= 2;
3532 }
3533 }
3534 }
3535 }
3536
3537 hi_reg = 15;
3538 /* We want to generate opcodes in the order the registers have been
3539 saved, ie. descending order. */
3540 for (reg = 15; reg >= -1; reg--)
3541 {
3542 /* Save registers in blocks. */
3543 if (reg < 0
3544 || !(mask & (1 << reg)))
3545 {
3546 /* We found an unsaved reg. Generate opcodes to save the
3547 preceding block. */
3548 if (reg != hi_reg)
3549 {
3550 if (reg == 9)
3551 {
3552 /* Short form. */
3553 op = 0xc0 | (hi_reg - 10);
3554 add_unwind_opcode (op, 1);
3555 }
3556 else
3557 {
3558 /* Long form. */
3559 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3560 add_unwind_opcode (op, 2);
3561 }
3562 }
3563 hi_reg = reg - 1;
3564 }
3565 }
3566
3567 return;
3568 error:
3569 ignore_rest_of_line ();
3570 }
3571
3572 static void
3573 s_arm_unwind_save_mmxwcg (void)
3574 {
3575 int reg;
3576 int hi_reg;
3577 unsigned mask = 0;
3578 valueT op;
3579
3580 if (*input_line_pointer == '{')
3581 input_line_pointer++;
3582
3583 do
3584 {
3585 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3586
3587 if (reg == FAIL)
3588 {
3589 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3590 goto error;
3591 }
3592
3593 reg -= 8;
3594 if (mask >> reg)
3595 as_tsktsk (_("register list not in ascending order"));
3596 mask |= 1 << reg;
3597
3598 if (*input_line_pointer == '-')
3599 {
3600 input_line_pointer++;
3601 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3602 if (hi_reg == FAIL)
3603 {
3604 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3605 goto error;
3606 }
3607 else if (reg >= hi_reg)
3608 {
3609 as_bad (_("bad register range"));
3610 goto error;
3611 }
3612 for (; reg < hi_reg; reg++)
3613 mask |= 1 << reg;
3614 }
3615 }
3616 while (skip_past_comma (&input_line_pointer) != FAIL);
3617
3618 if (*input_line_pointer == '}')
3619 input_line_pointer++;
3620
3621 demand_empty_rest_of_line ();
3622
3623 /* Generate any deferred opcodes because we're going to be looking at
3624 the list. */
3625 flush_pending_unwind ();
3626
3627 for (reg = 0; reg < 16; reg++)
3628 {
3629 if (mask & (1 << reg))
3630 unwind.frame_size += 4;
3631 }
3632 op = 0xc700 | mask;
3633 add_unwind_opcode (op, 2);
3634 return;
3635 error:
3636 ignore_rest_of_line ();
3637 }
3638
3639
3640 /* Parse an unwind_save directive.
3641 If the argument is non-zero, this is a .vsave directive. */
3642
3643 static void
3644 s_arm_unwind_save (int arch_v6)
3645 {
3646 char *peek;
3647 struct reg_entry *reg;
3648 bfd_boolean had_brace = FALSE;
3649
3650 /* Figure out what sort of save we have. */
3651 peek = input_line_pointer;
3652
3653 if (*peek == '{')
3654 {
3655 had_brace = TRUE;
3656 peek++;
3657 }
3658
3659 reg = arm_reg_parse_multi (&peek);
3660
3661 if (!reg)
3662 {
3663 as_bad (_("register expected"));
3664 ignore_rest_of_line ();
3665 return;
3666 }
3667
3668 switch (reg->type)
3669 {
3670 case REG_TYPE_FN:
3671 if (had_brace)
3672 {
3673 as_bad (_("FPA .unwind_save does not take a register list"));
3674 ignore_rest_of_line ();
3675 return;
3676 }
3677 input_line_pointer = peek;
3678 s_arm_unwind_save_fpa (reg->number);
3679 return;
3680
3681 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
3682 case REG_TYPE_VFD:
3683 if (arch_v6)
3684 s_arm_unwind_save_vfp_armv6 ();
3685 else
3686 s_arm_unwind_save_vfp ();
3687 return;
3688 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
3689 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
3690
3691 default:
3692 as_bad (_(".unwind_save does not support this kind of register"));
3693 ignore_rest_of_line ();
3694 }
3695 }
3696
3697
3698 /* Parse an unwind_movsp directive. */
3699
3700 static void
3701 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
3702 {
3703 int reg;
3704 valueT op;
3705 int offset;
3706
3707 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3708 if (reg == FAIL)
3709 {
3710 as_bad (_(reg_expected_msgs[REG_TYPE_RN]));
3711 ignore_rest_of_line ();
3712 return;
3713 }
3714
3715 /* Optional constant. */
3716 if (skip_past_comma (&input_line_pointer) != FAIL)
3717 {
3718 if (immediate_for_directive (&offset) == FAIL)
3719 return;
3720 }
3721 else
3722 offset = 0;
3723
3724 demand_empty_rest_of_line ();
3725
3726 if (reg == REG_SP || reg == REG_PC)
3727 {
3728 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
3729 return;
3730 }
3731
3732 if (unwind.fp_reg != REG_SP)
3733 as_bad (_("unexpected .unwind_movsp directive"));
3734
3735 /* Generate opcode to restore the value. */
3736 op = 0x90 | reg;
3737 add_unwind_opcode (op, 1);
3738
3739 /* Record the information for later. */
3740 unwind.fp_reg = reg;
3741 unwind.fp_offset = unwind.frame_size - offset;
3742 unwind.sp_restored = 1;
3743 }
3744
3745 /* Parse an unwind_pad directive. */
3746
3747 static void
3748 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
3749 {
3750 int offset;
3751
3752 if (immediate_for_directive (&offset) == FAIL)
3753 return;
3754
3755 if (offset & 3)
3756 {
3757 as_bad (_("stack increment must be multiple of 4"));
3758 ignore_rest_of_line ();
3759 return;
3760 }
3761
3762 /* Don't generate any opcodes, just record the details for later. */
3763 unwind.frame_size += offset;
3764 unwind.pending_offset += offset;
3765
3766 demand_empty_rest_of_line ();
3767 }
3768
3769 /* Parse an unwind_setfp directive. */
3770
3771 static void
3772 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
3773 {
3774 int sp_reg;
3775 int fp_reg;
3776 int offset;
3777
3778 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3779 if (skip_past_comma (&input_line_pointer) == FAIL)
3780 sp_reg = FAIL;
3781 else
3782 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3783
3784 if (fp_reg == FAIL || sp_reg == FAIL)
3785 {
3786 as_bad (_("expected <reg>, <reg>"));
3787 ignore_rest_of_line ();
3788 return;
3789 }
3790
3791 /* Optional constant. */
3792 if (skip_past_comma (&input_line_pointer) != FAIL)
3793 {
3794 if (immediate_for_directive (&offset) == FAIL)
3795 return;
3796 }
3797 else
3798 offset = 0;
3799
3800 demand_empty_rest_of_line ();
3801
3802 if (sp_reg != 13 && sp_reg != unwind.fp_reg)
3803 {
3804 as_bad (_("register must be either sp or set by a previous"
3805 "unwind_movsp directive"));
3806 return;
3807 }
3808
3809 /* Don't generate any opcodes, just record the information for later. */
3810 unwind.fp_reg = fp_reg;
3811 unwind.fp_used = 1;
3812 if (sp_reg == 13)
3813 unwind.fp_offset = unwind.frame_size - offset;
3814 else
3815 unwind.fp_offset -= offset;
3816 }
3817
3818 /* Parse an unwind_raw directive. */
3819
3820 static void
3821 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
3822 {
3823 expressionS exp;
3824 /* This is an arbitrary limit. */
3825 unsigned char op[16];
3826 int count;
3827
3828 expression (&exp);
3829 if (exp.X_op == O_constant
3830 && skip_past_comma (&input_line_pointer) != FAIL)
3831 {
3832 unwind.frame_size += exp.X_add_number;
3833 expression (&exp);
3834 }
3835 else
3836 exp.X_op = O_illegal;
3837
3838 if (exp.X_op != O_constant)
3839 {
3840 as_bad (_("expected <offset>, <opcode>"));
3841 ignore_rest_of_line ();
3842 return;
3843 }
3844
3845 count = 0;
3846
3847 /* Parse the opcode. */
3848 for (;;)
3849 {
3850 if (count >= 16)
3851 {
3852 as_bad (_("unwind opcode too long"));
3853 ignore_rest_of_line ();
3854 }
3855 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
3856 {
3857 as_bad (_("invalid unwind opcode"));
3858 ignore_rest_of_line ();
3859 return;
3860 }
3861 op[count++] = exp.X_add_number;
3862
3863 /* Parse the next byte. */
3864 if (skip_past_comma (&input_line_pointer) == FAIL)
3865 break;
3866
3867 expression (&exp);
3868 }
3869
3870 /* Add the opcode bytes in reverse order. */
3871 while (count--)
3872 add_unwind_opcode (op[count], 1);
3873
3874 demand_empty_rest_of_line ();
3875 }
3876
3877
3878 /* Parse a .eabi_attribute directive. */
3879
3880 static void
3881 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
3882 {
3883 s_vendor_attribute (OBJ_ATTR_PROC);
3884 }
3885 #endif /* OBJ_ELF */
3886
3887 static void s_arm_arch (int);
3888 static void s_arm_object_arch (int);
3889 static void s_arm_cpu (int);
3890 static void s_arm_fpu (int);
3891
3892 #ifdef TE_PE
3893
3894 static void
3895 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
3896 {
3897 expressionS exp;
3898
3899 do
3900 {
3901 expression (&exp);
3902 if (exp.X_op == O_symbol)
3903 exp.X_op = O_secrel;
3904
3905 emit_expr (&exp, 4);
3906 }
3907 while (*input_line_pointer++ == ',');
3908
3909 input_line_pointer--;
3910 demand_empty_rest_of_line ();
3911 }
3912 #endif /* TE_PE */
3913
3914 /* This table describes all the machine specific pseudo-ops the assembler
3915 has to support. The fields are:
3916 pseudo-op name without dot
3917 function to call to execute this pseudo-op
3918 Integer arg to pass to the function. */
3919
3920 const pseudo_typeS md_pseudo_table[] =
3921 {
3922 /* Never called because '.req' does not start a line. */
3923 { "req", s_req, 0 },
3924 /* Following two are likewise never called. */
3925 { "dn", s_dn, 0 },
3926 { "qn", s_qn, 0 },
3927 { "unreq", s_unreq, 0 },
3928 { "bss", s_bss, 0 },
3929 { "align", s_align, 0 },
3930 { "arm", s_arm, 0 },
3931 { "thumb", s_thumb, 0 },
3932 { "code", s_code, 0 },
3933 { "force_thumb", s_force_thumb, 0 },
3934 { "thumb_func", s_thumb_func, 0 },
3935 { "thumb_set", s_thumb_set, 0 },
3936 { "even", s_even, 0 },
3937 { "ltorg", s_ltorg, 0 },
3938 { "pool", s_ltorg, 0 },
3939 { "syntax", s_syntax, 0 },
3940 { "cpu", s_arm_cpu, 0 },
3941 { "arch", s_arm_arch, 0 },
3942 { "object_arch", s_arm_object_arch, 0 },
3943 { "fpu", s_arm_fpu, 0 },
3944 #ifdef OBJ_ELF
3945 { "word", s_arm_elf_cons, 4 },
3946 { "long", s_arm_elf_cons, 4 },
3947 { "rel31", s_arm_rel31, 0 },
3948 { "fnstart", s_arm_unwind_fnstart, 0 },
3949 { "fnend", s_arm_unwind_fnend, 0 },
3950 { "cantunwind", s_arm_unwind_cantunwind, 0 },
3951 { "personality", s_arm_unwind_personality, 0 },
3952 { "personalityindex", s_arm_unwind_personalityindex, 0 },
3953 { "handlerdata", s_arm_unwind_handlerdata, 0 },
3954 { "save", s_arm_unwind_save, 0 },
3955 { "vsave", s_arm_unwind_save, 1 },
3956 { "movsp", s_arm_unwind_movsp, 0 },
3957 { "pad", s_arm_unwind_pad, 0 },
3958 { "setfp", s_arm_unwind_setfp, 0 },
3959 { "unwind_raw", s_arm_unwind_raw, 0 },
3960 { "eabi_attribute", s_arm_eabi_attribute, 0 },
3961 #else
3962 { "word", cons, 4},
3963
3964 /* These are used for dwarf. */
3965 {"2byte", cons, 2},
3966 {"4byte", cons, 4},
3967 {"8byte", cons, 8},
3968 /* These are used for dwarf2. */
3969 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
3970 { "loc", dwarf2_directive_loc, 0 },
3971 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
3972 #endif
3973 { "extend", float_cons, 'x' },
3974 { "ldouble", float_cons, 'x' },
3975 { "packed", float_cons, 'p' },
3976 #ifdef TE_PE
3977 {"secrel32", pe_directive_secrel, 0},
3978 #endif
3979 { 0, 0, 0 }
3980 };
3981 \f
3982 /* Parser functions used exclusively in instruction operands. */
3983
3984 /* Generic immediate-value read function for use in insn parsing.
3985 STR points to the beginning of the immediate (the leading #);
3986 VAL receives the value; if the value is outside [MIN, MAX]
3987 issue an error. PREFIX_OPT is true if the immediate prefix is
3988 optional. */
3989
3990 static int
3991 parse_immediate (char **str, int *val, int min, int max,
3992 bfd_boolean prefix_opt)
3993 {
3994 expressionS exp;
3995 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
3996 if (exp.X_op != O_constant)
3997 {
3998 inst.error = _("constant expression required");
3999 return FAIL;
4000 }
4001
4002 if (exp.X_add_number < min || exp.X_add_number > max)
4003 {
4004 inst.error = _("immediate value out of range");
4005 return FAIL;
4006 }
4007
4008 *val = exp.X_add_number;
4009 return SUCCESS;
4010 }
4011
4012 /* Less-generic immediate-value read function with the possibility of loading a
4013 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
4014 instructions. Puts the result directly in inst.operands[i]. */
4015
4016 static int
4017 parse_big_immediate (char **str, int i)
4018 {
4019 expressionS exp;
4020 char *ptr = *str;
4021
4022 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4023
4024 if (exp.X_op == O_constant)
4025 {
4026 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4027 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4028 O_constant. We have to be careful not to break compilation for
4029 32-bit X_add_number, though. */
4030 if ((exp.X_add_number & ~0xffffffffl) != 0)
4031 {
4032 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4033 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4034 inst.operands[i].regisimm = 1;
4035 }
4036 }
4037 else if (exp.X_op == O_big
4038 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4039 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4040 {
4041 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4042 /* Bignums have their least significant bits in
4043 generic_bignum[0]. Make sure we put 32 bits in imm and
4044 32 bits in reg, in a (hopefully) portable way. */
4045 assert (parts != 0);
4046 inst.operands[i].imm = 0;
4047 for (j = 0; j < parts; j++, idx++)
4048 inst.operands[i].imm |= generic_bignum[idx]
4049 << (LITTLENUM_NUMBER_OF_BITS * j);
4050 inst.operands[i].reg = 0;
4051 for (j = 0; j < parts; j++, idx++)
4052 inst.operands[i].reg |= generic_bignum[idx]
4053 << (LITTLENUM_NUMBER_OF_BITS * j);
4054 inst.operands[i].regisimm = 1;
4055 }
4056 else
4057 return FAIL;
4058
4059 *str = ptr;
4060
4061 return SUCCESS;
4062 }
4063
4064 /* Returns the pseudo-register number of an FPA immediate constant,
4065 or FAIL if there isn't a valid constant here. */
4066
4067 static int
4068 parse_fpa_immediate (char ** str)
4069 {
4070 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4071 char * save_in;
4072 expressionS exp;
4073 int i;
4074 int j;
4075
4076 /* First try and match exact strings, this is to guarantee
4077 that some formats will work even for cross assembly. */
4078
4079 for (i = 0; fp_const[i]; i++)
4080 {
4081 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4082 {
4083 char *start = *str;
4084
4085 *str += strlen (fp_const[i]);
4086 if (is_end_of_line[(unsigned char) **str])
4087 return i + 8;
4088 *str = start;
4089 }
4090 }
4091
4092 /* Just because we didn't get a match doesn't mean that the constant
4093 isn't valid, just that it is in a format that we don't
4094 automatically recognize. Try parsing it with the standard
4095 expression routines. */
4096
4097 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
4098
4099 /* Look for a raw floating point number. */
4100 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4101 && is_end_of_line[(unsigned char) *save_in])
4102 {
4103 for (i = 0; i < NUM_FLOAT_VALS; i++)
4104 {
4105 for (j = 0; j < MAX_LITTLENUMS; j++)
4106 {
4107 if (words[j] != fp_values[i][j])
4108 break;
4109 }
4110
4111 if (j == MAX_LITTLENUMS)
4112 {
4113 *str = save_in;
4114 return i + 8;
4115 }
4116 }
4117 }
4118
4119 /* Try and parse a more complex expression, this will probably fail
4120 unless the code uses a floating point prefix (eg "0f"). */
4121 save_in = input_line_pointer;
4122 input_line_pointer = *str;
4123 if (expression (&exp) == absolute_section
4124 && exp.X_op == O_big
4125 && exp.X_add_number < 0)
4126 {
4127 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4128 Ditto for 15. */
4129 if (gen_to_words (words, 5, (long) 15) == 0)
4130 {
4131 for (i = 0; i < NUM_FLOAT_VALS; i++)
4132 {
4133 for (j = 0; j < MAX_LITTLENUMS; j++)
4134 {
4135 if (words[j] != fp_values[i][j])
4136 break;
4137 }
4138
4139 if (j == MAX_LITTLENUMS)
4140 {
4141 *str = input_line_pointer;
4142 input_line_pointer = save_in;
4143 return i + 8;
4144 }
4145 }
4146 }
4147 }
4148
4149 *str = input_line_pointer;
4150 input_line_pointer = save_in;
4151 inst.error = _("invalid FPA immediate expression");
4152 return FAIL;
4153 }
4154
4155 /* Returns 1 if a number has "quarter-precision" float format
4156 0baBbbbbbc defgh000 00000000 00000000. */
4157
4158 static int
4159 is_quarter_float (unsigned imm)
4160 {
4161 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4162 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4163 }
4164
4165 /* Parse an 8-bit "quarter-precision" floating point number of the form:
4166 0baBbbbbbc defgh000 00000000 00000000.
4167 The zero and minus-zero cases need special handling, since they can't be
4168 encoded in the "quarter-precision" float format, but can nonetheless be
4169 loaded as integer constants. */
4170
4171 static unsigned
4172 parse_qfloat_immediate (char **ccp, int *immed)
4173 {
4174 char *str = *ccp;
4175 char *fpnum;
4176 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4177 int found_fpchar = 0;
4178
4179 skip_past_char (&str, '#');
4180
4181 /* We must not accidentally parse an integer as a floating-point number. Make
4182 sure that the value we parse is not an integer by checking for special
4183 characters '.' or 'e'.
4184 FIXME: This is a horrible hack, but doing better is tricky because type
4185 information isn't in a very usable state at parse time. */
4186 fpnum = str;
4187 skip_whitespace (fpnum);
4188
4189 if (strncmp (fpnum, "0x", 2) == 0)
4190 return FAIL;
4191 else
4192 {
4193 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4194 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4195 {
4196 found_fpchar = 1;
4197 break;
4198 }
4199
4200 if (!found_fpchar)
4201 return FAIL;
4202 }
4203
4204 if ((str = atof_ieee (str, 's', words)) != NULL)
4205 {
4206 unsigned fpword = 0;
4207 int i;
4208
4209 /* Our FP word must be 32 bits (single-precision FP). */
4210 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4211 {
4212 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4213 fpword |= words[i];
4214 }
4215
4216 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
4217 *immed = fpword;
4218 else
4219 return FAIL;
4220
4221 *ccp = str;
4222
4223 return SUCCESS;
4224 }
4225
4226 return FAIL;
4227 }
4228
4229 /* Shift operands. */
4230 enum shift_kind
4231 {
4232 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4233 };
4234
4235 struct asm_shift_name
4236 {
4237 const char *name;
4238 enum shift_kind kind;
4239 };
4240
4241 /* Third argument to parse_shift. */
4242 enum parse_shift_mode
4243 {
4244 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4245 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4246 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4247 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4248 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4249 };
4250
4251 /* Parse a <shift> specifier on an ARM data processing instruction.
4252 This has three forms:
4253
4254 (LSL|LSR|ASL|ASR|ROR) Rs
4255 (LSL|LSR|ASL|ASR|ROR) #imm
4256 RRX
4257
4258 Note that ASL is assimilated to LSL in the instruction encoding, and
4259 RRX to ROR #0 (which cannot be written as such). */
4260
4261 static int
4262 parse_shift (char **str, int i, enum parse_shift_mode mode)
4263 {
4264 const struct asm_shift_name *shift_name;
4265 enum shift_kind shift;
4266 char *s = *str;
4267 char *p = s;
4268 int reg;
4269
4270 for (p = *str; ISALPHA (*p); p++)
4271 ;
4272
4273 if (p == *str)
4274 {
4275 inst.error = _("shift expression expected");
4276 return FAIL;
4277 }
4278
4279 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
4280
4281 if (shift_name == NULL)
4282 {
4283 inst.error = _("shift expression expected");
4284 return FAIL;
4285 }
4286
4287 shift = shift_name->kind;
4288
4289 switch (mode)
4290 {
4291 case NO_SHIFT_RESTRICT:
4292 case SHIFT_IMMEDIATE: break;
4293
4294 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4295 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4296 {
4297 inst.error = _("'LSL' or 'ASR' required");
4298 return FAIL;
4299 }
4300 break;
4301
4302 case SHIFT_LSL_IMMEDIATE:
4303 if (shift != SHIFT_LSL)
4304 {
4305 inst.error = _("'LSL' required");
4306 return FAIL;
4307 }
4308 break;
4309
4310 case SHIFT_ASR_IMMEDIATE:
4311 if (shift != SHIFT_ASR)
4312 {
4313 inst.error = _("'ASR' required");
4314 return FAIL;
4315 }
4316 break;
4317
4318 default: abort ();
4319 }
4320
4321 if (shift != SHIFT_RRX)
4322 {
4323 /* Whitespace can appear here if the next thing is a bare digit. */
4324 skip_whitespace (p);
4325
4326 if (mode == NO_SHIFT_RESTRICT
4327 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4328 {
4329 inst.operands[i].imm = reg;
4330 inst.operands[i].immisreg = 1;
4331 }
4332 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4333 return FAIL;
4334 }
4335 inst.operands[i].shift_kind = shift;
4336 inst.operands[i].shifted = 1;
4337 *str = p;
4338 return SUCCESS;
4339 }
4340
4341 /* Parse a <shifter_operand> for an ARM data processing instruction:
4342
4343 #<immediate>
4344 #<immediate>, <rotate>
4345 <Rm>
4346 <Rm>, <shift>
4347
4348 where <shift> is defined by parse_shift above, and <rotate> is a
4349 multiple of 2 between 0 and 30. Validation of immediate operands
4350 is deferred to md_apply_fix. */
4351
4352 static int
4353 parse_shifter_operand (char **str, int i)
4354 {
4355 int value;
4356 expressionS expr;
4357
4358 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
4359 {
4360 inst.operands[i].reg = value;
4361 inst.operands[i].isreg = 1;
4362
4363 /* parse_shift will override this if appropriate */
4364 inst.reloc.exp.X_op = O_constant;
4365 inst.reloc.exp.X_add_number = 0;
4366
4367 if (skip_past_comma (str) == FAIL)
4368 return SUCCESS;
4369
4370 /* Shift operation on register. */
4371 return parse_shift (str, i, NO_SHIFT_RESTRICT);
4372 }
4373
4374 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4375 return FAIL;
4376
4377 if (skip_past_comma (str) == SUCCESS)
4378 {
4379 /* #x, y -- ie explicit rotation by Y. */
4380 if (my_get_expression (&expr, str, GE_NO_PREFIX))
4381 return FAIL;
4382
4383 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4384 {
4385 inst.error = _("constant expression expected");
4386 return FAIL;
4387 }
4388
4389 value = expr.X_add_number;
4390 if (value < 0 || value > 30 || value % 2 != 0)
4391 {
4392 inst.error = _("invalid rotation");
4393 return FAIL;
4394 }
4395 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4396 {
4397 inst.error = _("invalid constant");
4398 return FAIL;
4399 }
4400
4401 /* Convert to decoded value. md_apply_fix will put it back. */
4402 inst.reloc.exp.X_add_number
4403 = (((inst.reloc.exp.X_add_number << (32 - value))
4404 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
4405 }
4406
4407 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4408 inst.reloc.pc_rel = 0;
4409 return SUCCESS;
4410 }
4411
4412 /* Group relocation information. Each entry in the table contains the
4413 textual name of the relocation as may appear in assembler source
4414 and must end with a colon.
4415 Along with this textual name are the relocation codes to be used if
4416 the corresponding instruction is an ALU instruction (ADD or SUB only),
4417 an LDR, an LDRS, or an LDC. */
4418
4419 struct group_reloc_table_entry
4420 {
4421 const char *name;
4422 int alu_code;
4423 int ldr_code;
4424 int ldrs_code;
4425 int ldc_code;
4426 };
4427
4428 typedef enum
4429 {
4430 /* Varieties of non-ALU group relocation. */
4431
4432 GROUP_LDR,
4433 GROUP_LDRS,
4434 GROUP_LDC
4435 } group_reloc_type;
4436
4437 static struct group_reloc_table_entry group_reloc_table[] =
4438 { /* Program counter relative: */
4439 { "pc_g0_nc",
4440 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4441 0, /* LDR */
4442 0, /* LDRS */
4443 0 }, /* LDC */
4444 { "pc_g0",
4445 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4446 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4447 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4448 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4449 { "pc_g1_nc",
4450 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4451 0, /* LDR */
4452 0, /* LDRS */
4453 0 }, /* LDC */
4454 { "pc_g1",
4455 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4456 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4457 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4458 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4459 { "pc_g2",
4460 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4461 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4462 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4463 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4464 /* Section base relative */
4465 { "sb_g0_nc",
4466 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4467 0, /* LDR */
4468 0, /* LDRS */
4469 0 }, /* LDC */
4470 { "sb_g0",
4471 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4472 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4473 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4474 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4475 { "sb_g1_nc",
4476 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4477 0, /* LDR */
4478 0, /* LDRS */
4479 0 }, /* LDC */
4480 { "sb_g1",
4481 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4482 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4483 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4484 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4485 { "sb_g2",
4486 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4487 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4488 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4489 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4490
4491 /* Given the address of a pointer pointing to the textual name of a group
4492 relocation as may appear in assembler source, attempt to find its details
4493 in group_reloc_table. The pointer will be updated to the character after
4494 the trailing colon. On failure, FAIL will be returned; SUCCESS
4495 otherwise. On success, *entry will be updated to point at the relevant
4496 group_reloc_table entry. */
4497
4498 static int
4499 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4500 {
4501 unsigned int i;
4502 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4503 {
4504 int length = strlen (group_reloc_table[i].name);
4505
4506 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4507 && (*str)[length] == ':')
4508 {
4509 *out = &group_reloc_table[i];
4510 *str += (length + 1);
4511 return SUCCESS;
4512 }
4513 }
4514
4515 return FAIL;
4516 }
4517
4518 /* Parse a <shifter_operand> for an ARM data processing instruction
4519 (as for parse_shifter_operand) where group relocations are allowed:
4520
4521 #<immediate>
4522 #<immediate>, <rotate>
4523 #:<group_reloc>:<expression>
4524 <Rm>
4525 <Rm>, <shift>
4526
4527 where <group_reloc> is one of the strings defined in group_reloc_table.
4528 The hashes are optional.
4529
4530 Everything else is as for parse_shifter_operand. */
4531
4532 static parse_operand_result
4533 parse_shifter_operand_group_reloc (char **str, int i)
4534 {
4535 /* Determine if we have the sequence of characters #: or just :
4536 coming next. If we do, then we check for a group relocation.
4537 If we don't, punt the whole lot to parse_shifter_operand. */
4538
4539 if (((*str)[0] == '#' && (*str)[1] == ':')
4540 || (*str)[0] == ':')
4541 {
4542 struct group_reloc_table_entry *entry;
4543
4544 if ((*str)[0] == '#')
4545 (*str) += 2;
4546 else
4547 (*str)++;
4548
4549 /* Try to parse a group relocation. Anything else is an error. */
4550 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4551 {
4552 inst.error = _("unknown group relocation");
4553 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4554 }
4555
4556 /* We now have the group relocation table entry corresponding to
4557 the name in the assembler source. Next, we parse the expression. */
4558 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4559 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4560
4561 /* Record the relocation type (always the ALU variant here). */
4562 inst.reloc.type = entry->alu_code;
4563 assert (inst.reloc.type != 0);
4564
4565 return PARSE_OPERAND_SUCCESS;
4566 }
4567 else
4568 return parse_shifter_operand (str, i) == SUCCESS
4569 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4570
4571 /* Never reached. */
4572 }
4573
4574 /* Parse all forms of an ARM address expression. Information is written
4575 to inst.operands[i] and/or inst.reloc.
4576
4577 Preindexed addressing (.preind=1):
4578
4579 [Rn, #offset] .reg=Rn .reloc.exp=offset
4580 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4581 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4582 .shift_kind=shift .reloc.exp=shift_imm
4583
4584 These three may have a trailing ! which causes .writeback to be set also.
4585
4586 Postindexed addressing (.postind=1, .writeback=1):
4587
4588 [Rn], #offset .reg=Rn .reloc.exp=offset
4589 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4590 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4591 .shift_kind=shift .reloc.exp=shift_imm
4592
4593 Unindexed addressing (.preind=0, .postind=0):
4594
4595 [Rn], {option} .reg=Rn .imm=option .immisreg=0
4596
4597 Other:
4598
4599 [Rn]{!} shorthand for [Rn,#0]{!}
4600 =immediate .isreg=0 .reloc.exp=immediate
4601 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
4602
4603 It is the caller's responsibility to check for addressing modes not
4604 supported by the instruction, and to set inst.reloc.type. */
4605
4606 static parse_operand_result
4607 parse_address_main (char **str, int i, int group_relocations,
4608 group_reloc_type group_type)
4609 {
4610 char *p = *str;
4611 int reg;
4612
4613 if (skip_past_char (&p, '[') == FAIL)
4614 {
4615 if (skip_past_char (&p, '=') == FAIL)
4616 {
4617 /* bare address - translate to PC-relative offset */
4618 inst.reloc.pc_rel = 1;
4619 inst.operands[i].reg = REG_PC;
4620 inst.operands[i].isreg = 1;
4621 inst.operands[i].preind = 1;
4622 }
4623 /* else a load-constant pseudo op, no special treatment needed here */
4624
4625 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4626 return PARSE_OPERAND_FAIL;
4627
4628 *str = p;
4629 return PARSE_OPERAND_SUCCESS;
4630 }
4631
4632 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
4633 {
4634 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4635 return PARSE_OPERAND_FAIL;
4636 }
4637 inst.operands[i].reg = reg;
4638 inst.operands[i].isreg = 1;
4639
4640 if (skip_past_comma (&p) == SUCCESS)
4641 {
4642 inst.operands[i].preind = 1;
4643
4644 if (*p == '+') p++;
4645 else if (*p == '-') p++, inst.operands[i].negative = 1;
4646
4647 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4648 {
4649 inst.operands[i].imm = reg;
4650 inst.operands[i].immisreg = 1;
4651
4652 if (skip_past_comma (&p) == SUCCESS)
4653 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4654 return PARSE_OPERAND_FAIL;
4655 }
4656 else if (skip_past_char (&p, ':') == SUCCESS)
4657 {
4658 /* FIXME: '@' should be used here, but it's filtered out by generic
4659 code before we get to see it here. This may be subject to
4660 change. */
4661 expressionS exp;
4662 my_get_expression (&exp, &p, GE_NO_PREFIX);
4663 if (exp.X_op != O_constant)
4664 {
4665 inst.error = _("alignment must be constant");
4666 return PARSE_OPERAND_FAIL;
4667 }
4668 inst.operands[i].imm = exp.X_add_number << 8;
4669 inst.operands[i].immisalign = 1;
4670 /* Alignments are not pre-indexes. */
4671 inst.operands[i].preind = 0;
4672 }
4673 else
4674 {
4675 if (inst.operands[i].negative)
4676 {
4677 inst.operands[i].negative = 0;
4678 p--;
4679 }
4680
4681 if (group_relocations
4682 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4683 {
4684 struct group_reloc_table_entry *entry;
4685
4686 /* Skip over the #: or : sequence. */
4687 if (*p == '#')
4688 p += 2;
4689 else
4690 p++;
4691
4692 /* Try to parse a group relocation. Anything else is an
4693 error. */
4694 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
4695 {
4696 inst.error = _("unknown group relocation");
4697 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4698 }
4699
4700 /* We now have the group relocation table entry corresponding to
4701 the name in the assembler source. Next, we parse the
4702 expression. */
4703 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4704 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4705
4706 /* Record the relocation type. */
4707 switch (group_type)
4708 {
4709 case GROUP_LDR:
4710 inst.reloc.type = entry->ldr_code;
4711 break;
4712
4713 case GROUP_LDRS:
4714 inst.reloc.type = entry->ldrs_code;
4715 break;
4716
4717 case GROUP_LDC:
4718 inst.reloc.type = entry->ldc_code;
4719 break;
4720
4721 default:
4722 assert (0);
4723 }
4724
4725 if (inst.reloc.type == 0)
4726 {
4727 inst.error = _("this group relocation is not allowed on this instruction");
4728 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4729 }
4730 }
4731 else
4732 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4733 return PARSE_OPERAND_FAIL;
4734 }
4735 }
4736
4737 if (skip_past_char (&p, ']') == FAIL)
4738 {
4739 inst.error = _("']' expected");
4740 return PARSE_OPERAND_FAIL;
4741 }
4742
4743 if (skip_past_char (&p, '!') == SUCCESS)
4744 inst.operands[i].writeback = 1;
4745
4746 else if (skip_past_comma (&p) == SUCCESS)
4747 {
4748 if (skip_past_char (&p, '{') == SUCCESS)
4749 {
4750 /* [Rn], {expr} - unindexed, with option */
4751 if (parse_immediate (&p, &inst.operands[i].imm,
4752 0, 255, TRUE) == FAIL)
4753 return PARSE_OPERAND_FAIL;
4754
4755 if (skip_past_char (&p, '}') == FAIL)
4756 {
4757 inst.error = _("'}' expected at end of 'option' field");
4758 return PARSE_OPERAND_FAIL;
4759 }
4760 if (inst.operands[i].preind)
4761 {
4762 inst.error = _("cannot combine index with option");
4763 return PARSE_OPERAND_FAIL;
4764 }
4765 *str = p;
4766 return PARSE_OPERAND_SUCCESS;
4767 }
4768 else
4769 {
4770 inst.operands[i].postind = 1;
4771 inst.operands[i].writeback = 1;
4772
4773 if (inst.operands[i].preind)
4774 {
4775 inst.error = _("cannot combine pre- and post-indexing");
4776 return PARSE_OPERAND_FAIL;
4777 }
4778
4779 if (*p == '+') p++;
4780 else if (*p == '-') p++, inst.operands[i].negative = 1;
4781
4782 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4783 {
4784 /* We might be using the immediate for alignment already. If we
4785 are, OR the register number into the low-order bits. */
4786 if (inst.operands[i].immisalign)
4787 inst.operands[i].imm |= reg;
4788 else
4789 inst.operands[i].imm = reg;
4790 inst.operands[i].immisreg = 1;
4791
4792 if (skip_past_comma (&p) == SUCCESS)
4793 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4794 return PARSE_OPERAND_FAIL;
4795 }
4796 else
4797 {
4798 if (inst.operands[i].negative)
4799 {
4800 inst.operands[i].negative = 0;
4801 p--;
4802 }
4803 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4804 return PARSE_OPERAND_FAIL;
4805 }
4806 }
4807 }
4808
4809 /* If at this point neither .preind nor .postind is set, we have a
4810 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
4811 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
4812 {
4813 inst.operands[i].preind = 1;
4814 inst.reloc.exp.X_op = O_constant;
4815 inst.reloc.exp.X_add_number = 0;
4816 }
4817 *str = p;
4818 return PARSE_OPERAND_SUCCESS;
4819 }
4820
4821 static int
4822 parse_address (char **str, int i)
4823 {
4824 return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS
4825 ? SUCCESS : FAIL;
4826 }
4827
4828 static parse_operand_result
4829 parse_address_group_reloc (char **str, int i, group_reloc_type type)
4830 {
4831 return parse_address_main (str, i, 1, type);
4832 }
4833
4834 /* Parse an operand for a MOVW or MOVT instruction. */
4835 static int
4836 parse_half (char **str)
4837 {
4838 char * p;
4839
4840 p = *str;
4841 skip_past_char (&p, '#');
4842 if (strncasecmp (p, ":lower16:", 9) == 0)
4843 inst.reloc.type = BFD_RELOC_ARM_MOVW;
4844 else if (strncasecmp (p, ":upper16:", 9) == 0)
4845 inst.reloc.type = BFD_RELOC_ARM_MOVT;
4846
4847 if (inst.reloc.type != BFD_RELOC_UNUSED)
4848 {
4849 p += 9;
4850 skip_whitespace (p);
4851 }
4852
4853 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4854 return FAIL;
4855
4856 if (inst.reloc.type == BFD_RELOC_UNUSED)
4857 {
4858 if (inst.reloc.exp.X_op != O_constant)
4859 {
4860 inst.error = _("constant expression expected");
4861 return FAIL;
4862 }
4863 if (inst.reloc.exp.X_add_number < 0
4864 || inst.reloc.exp.X_add_number > 0xffff)
4865 {
4866 inst.error = _("immediate value out of range");
4867 return FAIL;
4868 }
4869 }
4870 *str = p;
4871 return SUCCESS;
4872 }
4873
4874 /* Miscellaneous. */
4875
4876 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
4877 or a bitmask suitable to be or-ed into the ARM msr instruction. */
4878 static int
4879 parse_psr (char **str)
4880 {
4881 char *p;
4882 unsigned long psr_field;
4883 const struct asm_psr *psr;
4884 char *start;
4885
4886 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
4887 feature for ease of use and backwards compatibility. */
4888 p = *str;
4889 if (strncasecmp (p, "SPSR", 4) == 0)
4890 psr_field = SPSR_BIT;
4891 else if (strncasecmp (p, "CPSR", 4) == 0)
4892 psr_field = 0;
4893 else
4894 {
4895 start = p;
4896 do
4897 p++;
4898 while (ISALNUM (*p) || *p == '_');
4899
4900 psr = hash_find_n (arm_v7m_psr_hsh, start, p - start);
4901 if (!psr)
4902 return FAIL;
4903
4904 *str = p;
4905 return psr->field;
4906 }
4907
4908 p += 4;
4909 if (*p == '_')
4910 {
4911 /* A suffix follows. */
4912 p++;
4913 start = p;
4914
4915 do
4916 p++;
4917 while (ISALNUM (*p) || *p == '_');
4918
4919 psr = hash_find_n (arm_psr_hsh, start, p - start);
4920 if (!psr)
4921 goto error;
4922
4923 psr_field |= psr->field;
4924 }
4925 else
4926 {
4927 if (ISALNUM (*p))
4928 goto error; /* Garbage after "[CS]PSR". */
4929
4930 psr_field |= (PSR_c | PSR_f);
4931 }
4932 *str = p;
4933 return psr_field;
4934
4935 error:
4936 inst.error = _("flag for {c}psr instruction expected");
4937 return FAIL;
4938 }
4939
4940 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
4941 value suitable for splatting into the AIF field of the instruction. */
4942
4943 static int
4944 parse_cps_flags (char **str)
4945 {
4946 int val = 0;
4947 int saw_a_flag = 0;
4948 char *s = *str;
4949
4950 for (;;)
4951 switch (*s++)
4952 {
4953 case '\0': case ',':
4954 goto done;
4955
4956 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
4957 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
4958 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
4959
4960 default:
4961 inst.error = _("unrecognized CPS flag");
4962 return FAIL;
4963 }
4964
4965 done:
4966 if (saw_a_flag == 0)
4967 {
4968 inst.error = _("missing CPS flags");
4969 return FAIL;
4970 }
4971
4972 *str = s - 1;
4973 return val;
4974 }
4975
4976 /* Parse an endian specifier ("BE" or "LE", case insensitive);
4977 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
4978
4979 static int
4980 parse_endian_specifier (char **str)
4981 {
4982 int little_endian;
4983 char *s = *str;
4984
4985 if (strncasecmp (s, "BE", 2))
4986 little_endian = 0;
4987 else if (strncasecmp (s, "LE", 2))
4988 little_endian = 1;
4989 else
4990 {
4991 inst.error = _("valid endian specifiers are be or le");
4992 return FAIL;
4993 }
4994
4995 if (ISALNUM (s[2]) || s[2] == '_')
4996 {
4997 inst.error = _("valid endian specifiers are be or le");
4998 return FAIL;
4999 }
5000
5001 *str = s + 2;
5002 return little_endian;
5003 }
5004
5005 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5006 value suitable for poking into the rotate field of an sxt or sxta
5007 instruction, or FAIL on error. */
5008
5009 static int
5010 parse_ror (char **str)
5011 {
5012 int rot;
5013 char *s = *str;
5014
5015 if (strncasecmp (s, "ROR", 3) == 0)
5016 s += 3;
5017 else
5018 {
5019 inst.error = _("missing rotation field after comma");
5020 return FAIL;
5021 }
5022
5023 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5024 return FAIL;
5025
5026 switch (rot)
5027 {
5028 case 0: *str = s; return 0x0;
5029 case 8: *str = s; return 0x1;
5030 case 16: *str = s; return 0x2;
5031 case 24: *str = s; return 0x3;
5032
5033 default:
5034 inst.error = _("rotation can only be 0, 8, 16, or 24");
5035 return FAIL;
5036 }
5037 }
5038
5039 /* Parse a conditional code (from conds[] below). The value returned is in the
5040 range 0 .. 14, or FAIL. */
5041 static int
5042 parse_cond (char **str)
5043 {
5044 char *p, *q;
5045 const struct asm_cond *c;
5046
5047 p = q = *str;
5048 while (ISALPHA (*q))
5049 q++;
5050
5051 c = hash_find_n (arm_cond_hsh, p, q - p);
5052 if (!c)
5053 {
5054 inst.error = _("condition required");
5055 return FAIL;
5056 }
5057
5058 *str = q;
5059 return c->value;
5060 }
5061
5062 /* Parse an option for a barrier instruction. Returns the encoding for the
5063 option, or FAIL. */
5064 static int
5065 parse_barrier (char **str)
5066 {
5067 char *p, *q;
5068 const struct asm_barrier_opt *o;
5069
5070 p = q = *str;
5071 while (ISALPHA (*q))
5072 q++;
5073
5074 o = hash_find_n (arm_barrier_opt_hsh, p, q - p);
5075 if (!o)
5076 return FAIL;
5077
5078 *str = q;
5079 return o->value;
5080 }
5081
5082 /* Parse the operands of a table branch instruction. Similar to a memory
5083 operand. */
5084 static int
5085 parse_tb (char **str)
5086 {
5087 char * p = *str;
5088 int reg;
5089
5090 if (skip_past_char (&p, '[') == FAIL)
5091 {
5092 inst.error = _("'[' expected");
5093 return FAIL;
5094 }
5095
5096 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5097 {
5098 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5099 return FAIL;
5100 }
5101 inst.operands[0].reg = reg;
5102
5103 if (skip_past_comma (&p) == FAIL)
5104 {
5105 inst.error = _("',' expected");
5106 return FAIL;
5107 }
5108
5109 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5110 {
5111 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5112 return FAIL;
5113 }
5114 inst.operands[0].imm = reg;
5115
5116 if (skip_past_comma (&p) == SUCCESS)
5117 {
5118 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5119 return FAIL;
5120 if (inst.reloc.exp.X_add_number != 1)
5121 {
5122 inst.error = _("invalid shift");
5123 return FAIL;
5124 }
5125 inst.operands[0].shifted = 1;
5126 }
5127
5128 if (skip_past_char (&p, ']') == FAIL)
5129 {
5130 inst.error = _("']' expected");
5131 return FAIL;
5132 }
5133 *str = p;
5134 return SUCCESS;
5135 }
5136
5137 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5138 information on the types the operands can take and how they are encoded.
5139 Up to four operands may be read; this function handles setting the
5140 ".present" field for each read operand itself.
5141 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5142 else returns FAIL. */
5143
5144 static int
5145 parse_neon_mov (char **str, int *which_operand)
5146 {
5147 int i = *which_operand, val;
5148 enum arm_reg_type rtype;
5149 char *ptr = *str;
5150 struct neon_type_el optype;
5151
5152 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5153 {
5154 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5155 inst.operands[i].reg = val;
5156 inst.operands[i].isscalar = 1;
5157 inst.operands[i].vectype = optype;
5158 inst.operands[i++].present = 1;
5159
5160 if (skip_past_comma (&ptr) == FAIL)
5161 goto wanted_comma;
5162
5163 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5164 goto wanted_arm;
5165
5166 inst.operands[i].reg = val;
5167 inst.operands[i].isreg = 1;
5168 inst.operands[i].present = 1;
5169 }
5170 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
5171 != FAIL)
5172 {
5173 /* Cases 0, 1, 2, 3, 5 (D only). */
5174 if (skip_past_comma (&ptr) == FAIL)
5175 goto wanted_comma;
5176
5177 inst.operands[i].reg = val;
5178 inst.operands[i].isreg = 1;
5179 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5180 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5181 inst.operands[i].isvec = 1;
5182 inst.operands[i].vectype = optype;
5183 inst.operands[i++].present = 1;
5184
5185 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5186 {
5187 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5188 Case 13: VMOV <Sd>, <Rm> */
5189 inst.operands[i].reg = val;
5190 inst.operands[i].isreg = 1;
5191 inst.operands[i].present = 1;
5192
5193 if (rtype == REG_TYPE_NQ)
5194 {
5195 first_error (_("can't use Neon quad register here"));
5196 return FAIL;
5197 }
5198 else if (rtype != REG_TYPE_VFS)
5199 {
5200 i++;
5201 if (skip_past_comma (&ptr) == FAIL)
5202 goto wanted_comma;
5203 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5204 goto wanted_arm;
5205 inst.operands[i].reg = val;
5206 inst.operands[i].isreg = 1;
5207 inst.operands[i].present = 1;
5208 }
5209 }
5210 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5211 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5212 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5213 Case 10: VMOV.F32 <Sd>, #<imm>
5214 Case 11: VMOV.F64 <Dd>, #<imm> */
5215 inst.operands[i].immisfloat = 1;
5216 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5217 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5218 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5219 ;
5220 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5221 &optype)) != FAIL)
5222 {
5223 /* Case 0: VMOV<c><q> <Qd>, <Qm>
5224 Case 1: VMOV<c><q> <Dd>, <Dm>
5225 Case 8: VMOV.F32 <Sd>, <Sm>
5226 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5227
5228 inst.operands[i].reg = val;
5229 inst.operands[i].isreg = 1;
5230 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5231 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5232 inst.operands[i].isvec = 1;
5233 inst.operands[i].vectype = optype;
5234 inst.operands[i].present = 1;
5235
5236 if (skip_past_comma (&ptr) == SUCCESS)
5237 {
5238 /* Case 15. */
5239 i++;
5240
5241 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5242 goto wanted_arm;
5243
5244 inst.operands[i].reg = val;
5245 inst.operands[i].isreg = 1;
5246 inst.operands[i++].present = 1;
5247
5248 if (skip_past_comma (&ptr) == FAIL)
5249 goto wanted_comma;
5250
5251 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5252 goto wanted_arm;
5253
5254 inst.operands[i].reg = val;
5255 inst.operands[i].isreg = 1;
5256 inst.operands[i++].present = 1;
5257 }
5258 }
5259 else
5260 {
5261 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5262 return FAIL;
5263 }
5264 }
5265 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5266 {
5267 /* Cases 6, 7. */
5268 inst.operands[i].reg = val;
5269 inst.operands[i].isreg = 1;
5270 inst.operands[i++].present = 1;
5271
5272 if (skip_past_comma (&ptr) == FAIL)
5273 goto wanted_comma;
5274
5275 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5276 {
5277 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5278 inst.operands[i].reg = val;
5279 inst.operands[i].isscalar = 1;
5280 inst.operands[i].present = 1;
5281 inst.operands[i].vectype = optype;
5282 }
5283 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5284 {
5285 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5286 inst.operands[i].reg = val;
5287 inst.operands[i].isreg = 1;
5288 inst.operands[i++].present = 1;
5289
5290 if (skip_past_comma (&ptr) == FAIL)
5291 goto wanted_comma;
5292
5293 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
5294 == FAIL)
5295 {
5296 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5297 return FAIL;
5298 }
5299
5300 inst.operands[i].reg = val;
5301 inst.operands[i].isreg = 1;
5302 inst.operands[i].isvec = 1;
5303 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5304 inst.operands[i].vectype = optype;
5305 inst.operands[i].present = 1;
5306
5307 if (rtype == REG_TYPE_VFS)
5308 {
5309 /* Case 14. */
5310 i++;
5311 if (skip_past_comma (&ptr) == FAIL)
5312 goto wanted_comma;
5313 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5314 &optype)) == FAIL)
5315 {
5316 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5317 return FAIL;
5318 }
5319 inst.operands[i].reg = val;
5320 inst.operands[i].isreg = 1;
5321 inst.operands[i].isvec = 1;
5322 inst.operands[i].issingle = 1;
5323 inst.operands[i].vectype = optype;
5324 inst.operands[i].present = 1;
5325 }
5326 }
5327 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5328 != FAIL)
5329 {
5330 /* Case 13. */
5331 inst.operands[i].reg = val;
5332 inst.operands[i].isreg = 1;
5333 inst.operands[i].isvec = 1;
5334 inst.operands[i].issingle = 1;
5335 inst.operands[i].vectype = optype;
5336 inst.operands[i++].present = 1;
5337 }
5338 }
5339 else
5340 {
5341 first_error (_("parse error"));
5342 return FAIL;
5343 }
5344
5345 /* Successfully parsed the operands. Update args. */
5346 *which_operand = i;
5347 *str = ptr;
5348 return SUCCESS;
5349
5350 wanted_comma:
5351 first_error (_("expected comma"));
5352 return FAIL;
5353
5354 wanted_arm:
5355 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5356 return FAIL;
5357 }
5358
5359 /* Matcher codes for parse_operands. */
5360 enum operand_parse_code
5361 {
5362 OP_stop, /* end of line */
5363
5364 OP_RR, /* ARM register */
5365 OP_RRnpc, /* ARM register, not r15 */
5366 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5367 OP_RRw, /* ARM register, not r15, optional trailing ! */
5368 OP_RCP, /* Coprocessor number */
5369 OP_RCN, /* Coprocessor register */
5370 OP_RF, /* FPA register */
5371 OP_RVS, /* VFP single precision register */
5372 OP_RVD, /* VFP double precision register (0..15) */
5373 OP_RND, /* Neon double precision register (0..31) */
5374 OP_RNQ, /* Neon quad precision register */
5375 OP_RVSD, /* VFP single or double precision register */
5376 OP_RNDQ, /* Neon double or quad precision register */
5377 OP_RNSDQ, /* Neon single, double or quad precision register */
5378 OP_RNSC, /* Neon scalar D[X] */
5379 OP_RVC, /* VFP control register */
5380 OP_RMF, /* Maverick F register */
5381 OP_RMD, /* Maverick D register */
5382 OP_RMFX, /* Maverick FX register */
5383 OP_RMDX, /* Maverick DX register */
5384 OP_RMAX, /* Maverick AX register */
5385 OP_RMDS, /* Maverick DSPSC register */
5386 OP_RIWR, /* iWMMXt wR register */
5387 OP_RIWC, /* iWMMXt wC register */
5388 OP_RIWG, /* iWMMXt wCG register */
5389 OP_RXA, /* XScale accumulator register */
5390
5391 OP_REGLST, /* ARM register list */
5392 OP_VRSLST, /* VFP single-precision register list */
5393 OP_VRDLST, /* VFP double-precision register list */
5394 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5395 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5396 OP_NSTRLST, /* Neon element/structure list */
5397
5398 OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */
5399 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
5400 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5401 OP_RR_RNSC, /* ARM reg or Neon scalar. */
5402 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5403 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5404 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5405 OP_VMOV, /* Neon VMOV operands. */
5406 OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */
5407 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
5408 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5409
5410 OP_I0, /* immediate zero */
5411 OP_I7, /* immediate value 0 .. 7 */
5412 OP_I15, /* 0 .. 15 */
5413 OP_I16, /* 1 .. 16 */
5414 OP_I16z, /* 0 .. 16 */
5415 OP_I31, /* 0 .. 31 */
5416 OP_I31w, /* 0 .. 31, optional trailing ! */
5417 OP_I32, /* 1 .. 32 */
5418 OP_I32z, /* 0 .. 32 */
5419 OP_I63, /* 0 .. 63 */
5420 OP_I63s, /* -64 .. 63 */
5421 OP_I64, /* 1 .. 64 */
5422 OP_I64z, /* 0 .. 64 */
5423 OP_I255, /* 0 .. 255 */
5424
5425 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5426 OP_I7b, /* 0 .. 7 */
5427 OP_I15b, /* 0 .. 15 */
5428 OP_I31b, /* 0 .. 31 */
5429
5430 OP_SH, /* shifter operand */
5431 OP_SHG, /* shifter operand with possible group relocation */
5432 OP_ADDR, /* Memory address expression (any mode) */
5433 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5434 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5435 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
5436 OP_EXP, /* arbitrary expression */
5437 OP_EXPi, /* same, with optional immediate prefix */
5438 OP_EXPr, /* same, with optional relocation suffix */
5439 OP_HALF, /* 0 .. 65535 or low/high reloc. */
5440
5441 OP_CPSF, /* CPS flags */
5442 OP_ENDI, /* Endianness specifier */
5443 OP_PSR, /* CPSR/SPSR mask for msr */
5444 OP_COND, /* conditional code */
5445 OP_TB, /* Table branch. */
5446
5447 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5448 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5449
5450 OP_RRnpc_I0, /* ARM register or literal 0 */
5451 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5452 OP_RR_EXi, /* ARM register or expression with imm prefix */
5453 OP_RF_IF, /* FPA register or immediate */
5454 OP_RIWR_RIWC, /* iWMMXt R or C reg */
5455 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
5456
5457 /* Optional operands. */
5458 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5459 OP_oI31b, /* 0 .. 31 */
5460 OP_oI32b, /* 1 .. 32 */
5461 OP_oIffffb, /* 0 .. 65535 */
5462 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5463
5464 OP_oRR, /* ARM register */
5465 OP_oRRnpc, /* ARM register, not the PC */
5466 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5467 OP_oRND, /* Optional Neon double precision register */
5468 OP_oRNQ, /* Optional Neon quad precision register */
5469 OP_oRNDQ, /* Optional Neon double or quad precision register */
5470 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
5471 OP_oSHll, /* LSL immediate */
5472 OP_oSHar, /* ASR immediate */
5473 OP_oSHllar, /* LSL or ASR immediate */
5474 OP_oROR, /* ROR 0/8/16/24 */
5475 OP_oBARRIER, /* Option argument for a barrier instruction. */
5476
5477 OP_FIRST_OPTIONAL = OP_oI7b
5478 };
5479
5480 /* Generic instruction operand parser. This does no encoding and no
5481 semantic validation; it merely squirrels values away in the inst
5482 structure. Returns SUCCESS or FAIL depending on whether the
5483 specified grammar matched. */
5484 static int
5485 parse_operands (char *str, const unsigned char *pattern)
5486 {
5487 unsigned const char *upat = pattern;
5488 char *backtrack_pos = 0;
5489 const char *backtrack_error = 0;
5490 int i, val, backtrack_index = 0;
5491 enum arm_reg_type rtype;
5492 parse_operand_result result;
5493
5494 #define po_char_or_fail(chr) do { \
5495 if (skip_past_char (&str, chr) == FAIL) \
5496 goto bad_args; \
5497 } while (0)
5498
5499 #define po_reg_or_fail(regtype) do { \
5500 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5501 &inst.operands[i].vectype); \
5502 if (val == FAIL) \
5503 { \
5504 first_error (_(reg_expected_msgs[regtype])); \
5505 goto failure; \
5506 } \
5507 inst.operands[i].reg = val; \
5508 inst.operands[i].isreg = 1; \
5509 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5510 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5511 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5512 || rtype == REG_TYPE_VFD \
5513 || rtype == REG_TYPE_NQ); \
5514 } while (0)
5515
5516 #define po_reg_or_goto(regtype, label) do { \
5517 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5518 &inst.operands[i].vectype); \
5519 if (val == FAIL) \
5520 goto label; \
5521 \
5522 inst.operands[i].reg = val; \
5523 inst.operands[i].isreg = 1; \
5524 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5525 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5526 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5527 || rtype == REG_TYPE_VFD \
5528 || rtype == REG_TYPE_NQ); \
5529 } while (0)
5530
5531 #define po_imm_or_fail(min, max, popt) do { \
5532 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5533 goto failure; \
5534 inst.operands[i].imm = val; \
5535 } while (0)
5536
5537 #define po_scalar_or_goto(elsz, label) do { \
5538 val = parse_scalar (&str, elsz, &inst.operands[i].vectype); \
5539 if (val == FAIL) \
5540 goto label; \
5541 inst.operands[i].reg = val; \
5542 inst.operands[i].isscalar = 1; \
5543 } while (0)
5544
5545 #define po_misc_or_fail(expr) do { \
5546 if (expr) \
5547 goto failure; \
5548 } while (0)
5549
5550 #define po_misc_or_fail_no_backtrack(expr) do { \
5551 result = expr; \
5552 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK)\
5553 backtrack_pos = 0; \
5554 if (result != PARSE_OPERAND_SUCCESS) \
5555 goto failure; \
5556 } while (0)
5557
5558 skip_whitespace (str);
5559
5560 for (i = 0; upat[i] != OP_stop; i++)
5561 {
5562 if (upat[i] >= OP_FIRST_OPTIONAL)
5563 {
5564 /* Remember where we are in case we need to backtrack. */
5565 assert (!backtrack_pos);
5566 backtrack_pos = str;
5567 backtrack_error = inst.error;
5568 backtrack_index = i;
5569 }
5570
5571 if (i > 0 && (i > 1 || inst.operands[0].present))
5572 po_char_or_fail (',');
5573
5574 switch (upat[i])
5575 {
5576 /* Registers */
5577 case OP_oRRnpc:
5578 case OP_RRnpc:
5579 case OP_oRR:
5580 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5581 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5582 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
5583 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
5584 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
5585 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5586 case OP_oRND:
5587 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
5588 case OP_RVC:
5589 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
5590 break;
5591 /* Also accept generic coprocessor regs for unknown registers. */
5592 coproc_reg:
5593 po_reg_or_fail (REG_TYPE_CN);
5594 break;
5595 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
5596 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
5597 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
5598 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
5599 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
5600 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
5601 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
5602 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
5603 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
5604 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5605 case OP_oRNQ:
5606 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
5607 case OP_oRNDQ:
5608 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
5609 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
5610 case OP_oRNSDQ:
5611 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5612
5613 /* Neon scalar. Using an element size of 8 means that some invalid
5614 scalars are accepted here, so deal with those in later code. */
5615 case OP_RNSC: po_scalar_or_goto (8, failure); break;
5616
5617 /* WARNING: We can expand to two operands here. This has the potential
5618 to totally confuse the backtracking mechanism! It will be OK at
5619 least as long as we don't try to use optional args as well,
5620 though. */
5621 case OP_NILO:
5622 {
5623 po_reg_or_goto (REG_TYPE_NDQ, try_imm);
5624 inst.operands[i].present = 1;
5625 i++;
5626 skip_past_comma (&str);
5627 po_reg_or_goto (REG_TYPE_NDQ, one_reg_only);
5628 break;
5629 one_reg_only:
5630 /* Optional register operand was omitted. Unfortunately, it's in
5631 operands[i-1] and we need it to be in inst.operands[i]. Fix that
5632 here (this is a bit grotty). */
5633 inst.operands[i] = inst.operands[i-1];
5634 inst.operands[i-1].present = 0;
5635 break;
5636 try_imm:
5637 /* There's a possibility of getting a 64-bit immediate here, so
5638 we need special handling. */
5639 if (parse_big_immediate (&str, i) == FAIL)
5640 {
5641 inst.error = _("immediate value is out of range");
5642 goto failure;
5643 }
5644 }
5645 break;
5646
5647 case OP_RNDQ_I0:
5648 {
5649 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
5650 break;
5651 try_imm0:
5652 po_imm_or_fail (0, 0, TRUE);
5653 }
5654 break;
5655
5656 case OP_RVSD_I0:
5657 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
5658 break;
5659
5660 case OP_RR_RNSC:
5661 {
5662 po_scalar_or_goto (8, try_rr);
5663 break;
5664 try_rr:
5665 po_reg_or_fail (REG_TYPE_RN);
5666 }
5667 break;
5668
5669 case OP_RNSDQ_RNSC:
5670 {
5671 po_scalar_or_goto (8, try_nsdq);
5672 break;
5673 try_nsdq:
5674 po_reg_or_fail (REG_TYPE_NSDQ);
5675 }
5676 break;
5677
5678 case OP_RNDQ_RNSC:
5679 {
5680 po_scalar_or_goto (8, try_ndq);
5681 break;
5682 try_ndq:
5683 po_reg_or_fail (REG_TYPE_NDQ);
5684 }
5685 break;
5686
5687 case OP_RND_RNSC:
5688 {
5689 po_scalar_or_goto (8, try_vfd);
5690 break;
5691 try_vfd:
5692 po_reg_or_fail (REG_TYPE_VFD);
5693 }
5694 break;
5695
5696 case OP_VMOV:
5697 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
5698 not careful then bad things might happen. */
5699 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
5700 break;
5701
5702 case OP_RNDQ_IMVNb:
5703 {
5704 po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm);
5705 break;
5706 try_mvnimm:
5707 /* There's a possibility of getting a 64-bit immediate here, so
5708 we need special handling. */
5709 if (parse_big_immediate (&str, i) == FAIL)
5710 {
5711 inst.error = _("immediate value is out of range");
5712 goto failure;
5713 }
5714 }
5715 break;
5716
5717 case OP_RNDQ_I63b:
5718 {
5719 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
5720 break;
5721 try_shimm:
5722 po_imm_or_fail (0, 63, TRUE);
5723 }
5724 break;
5725
5726 case OP_RRnpcb:
5727 po_char_or_fail ('[');
5728 po_reg_or_fail (REG_TYPE_RN);
5729 po_char_or_fail (']');
5730 break;
5731
5732 case OP_RRw:
5733 case OP_oRRw:
5734 po_reg_or_fail (REG_TYPE_RN);
5735 if (skip_past_char (&str, '!') == SUCCESS)
5736 inst.operands[i].writeback = 1;
5737 break;
5738
5739 /* Immediates */
5740 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
5741 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
5742 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5743 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
5744 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
5745 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5746 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
5747 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5748 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
5749 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
5750 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
5751 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
5752
5753 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
5754 case OP_oI7b:
5755 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
5756 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
5757 case OP_oI31b:
5758 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5759 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
5760 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
5761
5762 /* Immediate variants */
5763 case OP_oI255c:
5764 po_char_or_fail ('{');
5765 po_imm_or_fail (0, 255, TRUE);
5766 po_char_or_fail ('}');
5767 break;
5768
5769 case OP_I31w:
5770 /* The expression parser chokes on a trailing !, so we have
5771 to find it first and zap it. */
5772 {
5773 char *s = str;
5774 while (*s && *s != ',')
5775 s++;
5776 if (s[-1] == '!')
5777 {
5778 s[-1] = '\0';
5779 inst.operands[i].writeback = 1;
5780 }
5781 po_imm_or_fail (0, 31, TRUE);
5782 if (str == s - 1)
5783 str = s;
5784 }
5785 break;
5786
5787 /* Expressions */
5788 case OP_EXPi: EXPi:
5789 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5790 GE_OPT_PREFIX));
5791 break;
5792
5793 case OP_EXP:
5794 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5795 GE_NO_PREFIX));
5796 break;
5797
5798 case OP_EXPr: EXPr:
5799 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5800 GE_NO_PREFIX));
5801 if (inst.reloc.exp.X_op == O_symbol)
5802 {
5803 val = parse_reloc (&str);
5804 if (val == -1)
5805 {
5806 inst.error = _("unrecognized relocation suffix");
5807 goto failure;
5808 }
5809 else if (val != BFD_RELOC_UNUSED)
5810 {
5811 inst.operands[i].imm = val;
5812 inst.operands[i].hasreloc = 1;
5813 }
5814 }
5815 break;
5816
5817 /* Operand for MOVW or MOVT. */
5818 case OP_HALF:
5819 po_misc_or_fail (parse_half (&str));
5820 break;
5821
5822 /* Register or expression */
5823 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
5824 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
5825
5826 /* Register or immediate */
5827 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
5828 I0: po_imm_or_fail (0, 0, FALSE); break;
5829
5830 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
5831 IF:
5832 if (!is_immediate_prefix (*str))
5833 goto bad_args;
5834 str++;
5835 val = parse_fpa_immediate (&str);
5836 if (val == FAIL)
5837 goto failure;
5838 /* FPA immediates are encoded as registers 8-15.
5839 parse_fpa_immediate has already applied the offset. */
5840 inst.operands[i].reg = val;
5841 inst.operands[i].isreg = 1;
5842 break;
5843
5844 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
5845 I32z: po_imm_or_fail (0, 32, FALSE); break;
5846
5847 /* Two kinds of register */
5848 case OP_RIWR_RIWC:
5849 {
5850 struct reg_entry *rege = arm_reg_parse_multi (&str);
5851 if (!rege
5852 || (rege->type != REG_TYPE_MMXWR
5853 && rege->type != REG_TYPE_MMXWC
5854 && rege->type != REG_TYPE_MMXWCG))
5855 {
5856 inst.error = _("iWMMXt data or control register expected");
5857 goto failure;
5858 }
5859 inst.operands[i].reg = rege->number;
5860 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
5861 }
5862 break;
5863
5864 case OP_RIWC_RIWG:
5865 {
5866 struct reg_entry *rege = arm_reg_parse_multi (&str);
5867 if (!rege
5868 || (rege->type != REG_TYPE_MMXWC
5869 && rege->type != REG_TYPE_MMXWCG))
5870 {
5871 inst.error = _("iWMMXt control register expected");
5872 goto failure;
5873 }
5874 inst.operands[i].reg = rege->number;
5875 inst.operands[i].isreg = 1;
5876 }
5877 break;
5878
5879 /* Misc */
5880 case OP_CPSF: val = parse_cps_flags (&str); break;
5881 case OP_ENDI: val = parse_endian_specifier (&str); break;
5882 case OP_oROR: val = parse_ror (&str); break;
5883 case OP_PSR: val = parse_psr (&str); break;
5884 case OP_COND: val = parse_cond (&str); break;
5885 case OP_oBARRIER:val = parse_barrier (&str); break;
5886
5887 case OP_RVC_PSR:
5888 po_reg_or_goto (REG_TYPE_VFC, try_psr);
5889 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
5890 break;
5891 try_psr:
5892 val = parse_psr (&str);
5893 break;
5894
5895 case OP_APSR_RR:
5896 po_reg_or_goto (REG_TYPE_RN, try_apsr);
5897 break;
5898 try_apsr:
5899 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
5900 instruction). */
5901 if (strncasecmp (str, "APSR_", 5) == 0)
5902 {
5903 unsigned found = 0;
5904 str += 5;
5905 while (found < 15)
5906 switch (*str++)
5907 {
5908 case 'c': found = (found & 1) ? 16 : found | 1; break;
5909 case 'n': found = (found & 2) ? 16 : found | 2; break;
5910 case 'z': found = (found & 4) ? 16 : found | 4; break;
5911 case 'v': found = (found & 8) ? 16 : found | 8; break;
5912 default: found = 16;
5913 }
5914 if (found != 15)
5915 goto failure;
5916 inst.operands[i].isvec = 1;
5917 }
5918 else
5919 goto failure;
5920 break;
5921
5922 case OP_TB:
5923 po_misc_or_fail (parse_tb (&str));
5924 break;
5925
5926 /* Register lists */
5927 case OP_REGLST:
5928 val = parse_reg_list (&str);
5929 if (*str == '^')
5930 {
5931 inst.operands[1].writeback = 1;
5932 str++;
5933 }
5934 break;
5935
5936 case OP_VRSLST:
5937 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
5938 break;
5939
5940 case OP_VRDLST:
5941 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
5942 break;
5943
5944 case OP_VRSDLST:
5945 /* Allow Q registers too. */
5946 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5947 REGLIST_NEON_D);
5948 if (val == FAIL)
5949 {
5950 inst.error = NULL;
5951 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5952 REGLIST_VFP_S);
5953 inst.operands[i].issingle = 1;
5954 }
5955 break;
5956
5957 case OP_NRDLST:
5958 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5959 REGLIST_NEON_D);
5960 break;
5961
5962 case OP_NSTRLST:
5963 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
5964 &inst.operands[i].vectype);
5965 break;
5966
5967 /* Addressing modes */
5968 case OP_ADDR:
5969 po_misc_or_fail (parse_address (&str, i));
5970 break;
5971
5972 case OP_ADDRGLDR:
5973 po_misc_or_fail_no_backtrack (
5974 parse_address_group_reloc (&str, i, GROUP_LDR));
5975 break;
5976
5977 case OP_ADDRGLDRS:
5978 po_misc_or_fail_no_backtrack (
5979 parse_address_group_reloc (&str, i, GROUP_LDRS));
5980 break;
5981
5982 case OP_ADDRGLDC:
5983 po_misc_or_fail_no_backtrack (
5984 parse_address_group_reloc (&str, i, GROUP_LDC));
5985 break;
5986
5987 case OP_SH:
5988 po_misc_or_fail (parse_shifter_operand (&str, i));
5989 break;
5990
5991 case OP_SHG:
5992 po_misc_or_fail_no_backtrack (
5993 parse_shifter_operand_group_reloc (&str, i));
5994 break;
5995
5996 case OP_oSHll:
5997 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
5998 break;
5999
6000 case OP_oSHar:
6001 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6002 break;
6003
6004 case OP_oSHllar:
6005 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6006 break;
6007
6008 default:
6009 as_fatal (_("unhandled operand code %d"), upat[i]);
6010 }
6011
6012 /* Various value-based sanity checks and shared operations. We
6013 do not signal immediate failures for the register constraints;
6014 this allows a syntax error to take precedence. */
6015 switch (upat[i])
6016 {
6017 case OP_oRRnpc:
6018 case OP_RRnpc:
6019 case OP_RRnpcb:
6020 case OP_RRw:
6021 case OP_oRRw:
6022 case OP_RRnpc_I0:
6023 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6024 inst.error = BAD_PC;
6025 break;
6026
6027 case OP_CPSF:
6028 case OP_ENDI:
6029 case OP_oROR:
6030 case OP_PSR:
6031 case OP_RVC_PSR:
6032 case OP_COND:
6033 case OP_oBARRIER:
6034 case OP_REGLST:
6035 case OP_VRSLST:
6036 case OP_VRDLST:
6037 case OP_VRSDLST:
6038 case OP_NRDLST:
6039 case OP_NSTRLST:
6040 if (val == FAIL)
6041 goto failure;
6042 inst.operands[i].imm = val;
6043 break;
6044
6045 default:
6046 break;
6047 }
6048
6049 /* If we get here, this operand was successfully parsed. */
6050 inst.operands[i].present = 1;
6051 continue;
6052
6053 bad_args:
6054 inst.error = BAD_ARGS;
6055
6056 failure:
6057 if (!backtrack_pos)
6058 {
6059 /* The parse routine should already have set inst.error, but set a
6060 default here just in case. */
6061 if (!inst.error)
6062 inst.error = _("syntax error");
6063 return FAIL;
6064 }
6065
6066 /* Do not backtrack over a trailing optional argument that
6067 absorbed some text. We will only fail again, with the
6068 'garbage following instruction' error message, which is
6069 probably less helpful than the current one. */
6070 if (backtrack_index == i && backtrack_pos != str
6071 && upat[i+1] == OP_stop)
6072 {
6073 if (!inst.error)
6074 inst.error = _("syntax error");
6075 return FAIL;
6076 }
6077
6078 /* Try again, skipping the optional argument at backtrack_pos. */
6079 str = backtrack_pos;
6080 inst.error = backtrack_error;
6081 inst.operands[backtrack_index].present = 0;
6082 i = backtrack_index;
6083 backtrack_pos = 0;
6084 }
6085
6086 /* Check that we have parsed all the arguments. */
6087 if (*str != '\0' && !inst.error)
6088 inst.error = _("garbage following instruction");
6089
6090 return inst.error ? FAIL : SUCCESS;
6091 }
6092
6093 #undef po_char_or_fail
6094 #undef po_reg_or_fail
6095 #undef po_reg_or_goto
6096 #undef po_imm_or_fail
6097 #undef po_scalar_or_fail
6098 \f
6099 /* Shorthand macro for instruction encoding functions issuing errors. */
6100 #define constraint(expr, err) do { \
6101 if (expr) \
6102 { \
6103 inst.error = err; \
6104 return; \
6105 } \
6106 } while (0)
6107
6108 /* Functions for operand encoding. ARM, then Thumb. */
6109
6110 #define rotate_left(v, n) (v << n | v >> (32 - n))
6111
6112 /* If VAL can be encoded in the immediate field of an ARM instruction,
6113 return the encoded form. Otherwise, return FAIL. */
6114
6115 static unsigned int
6116 encode_arm_immediate (unsigned int val)
6117 {
6118 unsigned int a, i;
6119
6120 for (i = 0; i < 32; i += 2)
6121 if ((a = rotate_left (val, i)) <= 0xff)
6122 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6123
6124 return FAIL;
6125 }
6126
6127 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6128 return the encoded form. Otherwise, return FAIL. */
6129 static unsigned int
6130 encode_thumb32_immediate (unsigned int val)
6131 {
6132 unsigned int a, i;
6133
6134 if (val <= 0xff)
6135 return val;
6136
6137 for (i = 1; i <= 24; i++)
6138 {
6139 a = val >> i;
6140 if ((val & ~(0xff << i)) == 0)
6141 return ((val >> i) & 0x7f) | ((32 - i) << 7);
6142 }
6143
6144 a = val & 0xff;
6145 if (val == ((a << 16) | a))
6146 return 0x100 | a;
6147 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6148 return 0x300 | a;
6149
6150 a = val & 0xff00;
6151 if (val == ((a << 16) | a))
6152 return 0x200 | (a >> 8);
6153
6154 return FAIL;
6155 }
6156 /* Encode a VFP SP or DP register number into inst.instruction. */
6157
6158 static void
6159 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6160 {
6161 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6162 && reg > 15)
6163 {
6164 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
6165 {
6166 if (thumb_mode)
6167 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
6168 fpu_vfp_ext_v3);
6169 else
6170 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
6171 fpu_vfp_ext_v3);
6172 }
6173 else
6174 {
6175 first_error (_("D register out of range for selected VFP version"));
6176 return;
6177 }
6178 }
6179
6180 switch (pos)
6181 {
6182 case VFP_REG_Sd:
6183 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6184 break;
6185
6186 case VFP_REG_Sn:
6187 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6188 break;
6189
6190 case VFP_REG_Sm:
6191 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6192 break;
6193
6194 case VFP_REG_Dd:
6195 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6196 break;
6197
6198 case VFP_REG_Dn:
6199 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6200 break;
6201
6202 case VFP_REG_Dm:
6203 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6204 break;
6205
6206 default:
6207 abort ();
6208 }
6209 }
6210
6211 /* Encode a <shift> in an ARM-format instruction. The immediate,
6212 if any, is handled by md_apply_fix. */
6213 static void
6214 encode_arm_shift (int i)
6215 {
6216 if (inst.operands[i].shift_kind == SHIFT_RRX)
6217 inst.instruction |= SHIFT_ROR << 5;
6218 else
6219 {
6220 inst.instruction |= inst.operands[i].shift_kind << 5;
6221 if (inst.operands[i].immisreg)
6222 {
6223 inst.instruction |= SHIFT_BY_REG;
6224 inst.instruction |= inst.operands[i].imm << 8;
6225 }
6226 else
6227 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6228 }
6229 }
6230
6231 static void
6232 encode_arm_shifter_operand (int i)
6233 {
6234 if (inst.operands[i].isreg)
6235 {
6236 inst.instruction |= inst.operands[i].reg;
6237 encode_arm_shift (i);
6238 }
6239 else
6240 inst.instruction |= INST_IMMEDIATE;
6241 }
6242
6243 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
6244 static void
6245 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
6246 {
6247 assert (inst.operands[i].isreg);
6248 inst.instruction |= inst.operands[i].reg << 16;
6249
6250 if (inst.operands[i].preind)
6251 {
6252 if (is_t)
6253 {
6254 inst.error = _("instruction does not accept preindexed addressing");
6255 return;
6256 }
6257 inst.instruction |= PRE_INDEX;
6258 if (inst.operands[i].writeback)
6259 inst.instruction |= WRITE_BACK;
6260
6261 }
6262 else if (inst.operands[i].postind)
6263 {
6264 assert (inst.operands[i].writeback);
6265 if (is_t)
6266 inst.instruction |= WRITE_BACK;
6267 }
6268 else /* unindexed - only for coprocessor */
6269 {
6270 inst.error = _("instruction does not accept unindexed addressing");
6271 return;
6272 }
6273
6274 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6275 && (((inst.instruction & 0x000f0000) >> 16)
6276 == ((inst.instruction & 0x0000f000) >> 12)))
6277 as_warn ((inst.instruction & LOAD_BIT)
6278 ? _("destination register same as write-back base")
6279 : _("source register same as write-back base"));
6280 }
6281
6282 /* inst.operands[i] was set up by parse_address. Encode it into an
6283 ARM-format mode 2 load or store instruction. If is_t is true,
6284 reject forms that cannot be used with a T instruction (i.e. not
6285 post-indexed). */
6286 static void
6287 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
6288 {
6289 encode_arm_addr_mode_common (i, is_t);
6290
6291 if (inst.operands[i].immisreg)
6292 {
6293 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6294 inst.instruction |= inst.operands[i].imm;
6295 if (!inst.operands[i].negative)
6296 inst.instruction |= INDEX_UP;
6297 if (inst.operands[i].shifted)
6298 {
6299 if (inst.operands[i].shift_kind == SHIFT_RRX)
6300 inst.instruction |= SHIFT_ROR << 5;
6301 else
6302 {
6303 inst.instruction |= inst.operands[i].shift_kind << 5;
6304 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6305 }
6306 }
6307 }
6308 else /* immediate offset in inst.reloc */
6309 {
6310 if (inst.reloc.type == BFD_RELOC_UNUSED)
6311 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
6312 }
6313 }
6314
6315 /* inst.operands[i] was set up by parse_address. Encode it into an
6316 ARM-format mode 3 load or store instruction. Reject forms that
6317 cannot be used with such instructions. If is_t is true, reject
6318 forms that cannot be used with a T instruction (i.e. not
6319 post-indexed). */
6320 static void
6321 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
6322 {
6323 if (inst.operands[i].immisreg && inst.operands[i].shifted)
6324 {
6325 inst.error = _("instruction does not accept scaled register index");
6326 return;
6327 }
6328
6329 encode_arm_addr_mode_common (i, is_t);
6330
6331 if (inst.operands[i].immisreg)
6332 {
6333 inst.instruction |= inst.operands[i].imm;
6334 if (!inst.operands[i].negative)
6335 inst.instruction |= INDEX_UP;
6336 }
6337 else /* immediate offset in inst.reloc */
6338 {
6339 inst.instruction |= HWOFFSET_IMM;
6340 if (inst.reloc.type == BFD_RELOC_UNUSED)
6341 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
6342 }
6343 }
6344
6345 /* inst.operands[i] was set up by parse_address. Encode it into an
6346 ARM-format instruction. Reject all forms which cannot be encoded
6347 into a coprocessor load/store instruction. If wb_ok is false,
6348 reject use of writeback; if unind_ok is false, reject use of
6349 unindexed addressing. If reloc_override is not 0, use it instead
6350 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6351 (in which case it is preserved). */
6352
6353 static int
6354 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
6355 {
6356 inst.instruction |= inst.operands[i].reg << 16;
6357
6358 assert (!(inst.operands[i].preind && inst.operands[i].postind));
6359
6360 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
6361 {
6362 assert (!inst.operands[i].writeback);
6363 if (!unind_ok)
6364 {
6365 inst.error = _("instruction does not support unindexed addressing");
6366 return FAIL;
6367 }
6368 inst.instruction |= inst.operands[i].imm;
6369 inst.instruction |= INDEX_UP;
6370 return SUCCESS;
6371 }
6372
6373 if (inst.operands[i].preind)
6374 inst.instruction |= PRE_INDEX;
6375
6376 if (inst.operands[i].writeback)
6377 {
6378 if (inst.operands[i].reg == REG_PC)
6379 {
6380 inst.error = _("pc may not be used with write-back");
6381 return FAIL;
6382 }
6383 if (!wb_ok)
6384 {
6385 inst.error = _("instruction does not support writeback");
6386 return FAIL;
6387 }
6388 inst.instruction |= WRITE_BACK;
6389 }
6390
6391 if (reloc_override)
6392 inst.reloc.type = reloc_override;
6393 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6394 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6395 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6396 {
6397 if (thumb_mode)
6398 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6399 else
6400 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6401 }
6402
6403 return SUCCESS;
6404 }
6405
6406 /* inst.reloc.exp describes an "=expr" load pseudo-operation.
6407 Determine whether it can be performed with a move instruction; if
6408 it can, convert inst.instruction to that move instruction and
6409 return 1; if it can't, convert inst.instruction to a literal-pool
6410 load and return 0. If this is not a valid thing to do in the
6411 current context, set inst.error and return 1.
6412
6413 inst.operands[i] describes the destination register. */
6414
6415 static int
6416 move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6417 {
6418 unsigned long tbit;
6419
6420 if (thumb_p)
6421 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6422 else
6423 tbit = LOAD_BIT;
6424
6425 if ((inst.instruction & tbit) == 0)
6426 {
6427 inst.error = _("invalid pseudo operation");
6428 return 1;
6429 }
6430 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
6431 {
6432 inst.error = _("constant expression expected");
6433 return 1;
6434 }
6435 if (inst.reloc.exp.X_op == O_constant)
6436 {
6437 if (thumb_p)
6438 {
6439 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
6440 {
6441 /* This can be done with a mov(1) instruction. */
6442 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6443 inst.instruction |= inst.reloc.exp.X_add_number;
6444 return 1;
6445 }
6446 }
6447 else
6448 {
6449 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6450 if (value != FAIL)
6451 {
6452 /* This can be done with a mov instruction. */
6453 inst.instruction &= LITERAL_MASK;
6454 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6455 inst.instruction |= value & 0xfff;
6456 return 1;
6457 }
6458
6459 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6460 if (value != FAIL)
6461 {
6462 /* This can be done with a mvn instruction. */
6463 inst.instruction &= LITERAL_MASK;
6464 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6465 inst.instruction |= value & 0xfff;
6466 return 1;
6467 }
6468 }
6469 }
6470
6471 if (add_to_lit_pool () == FAIL)
6472 {
6473 inst.error = _("literal pool insertion failed");
6474 return 1;
6475 }
6476 inst.operands[1].reg = REG_PC;
6477 inst.operands[1].isreg = 1;
6478 inst.operands[1].preind = 1;
6479 inst.reloc.pc_rel = 1;
6480 inst.reloc.type = (thumb_p
6481 ? BFD_RELOC_ARM_THUMB_OFFSET
6482 : (mode_3
6483 ? BFD_RELOC_ARM_HWLITERAL
6484 : BFD_RELOC_ARM_LITERAL));
6485 return 0;
6486 }
6487
6488 /* Functions for instruction encoding, sorted by sub-architecture.
6489 First some generics; their names are taken from the conventional
6490 bit positions for register arguments in ARM format instructions. */
6491
6492 static void
6493 do_noargs (void)
6494 {
6495 }
6496
6497 static void
6498 do_rd (void)
6499 {
6500 inst.instruction |= inst.operands[0].reg << 12;
6501 }
6502
6503 static void
6504 do_rd_rm (void)
6505 {
6506 inst.instruction |= inst.operands[0].reg << 12;
6507 inst.instruction |= inst.operands[1].reg;
6508 }
6509
6510 static void
6511 do_rd_rn (void)
6512 {
6513 inst.instruction |= inst.operands[0].reg << 12;
6514 inst.instruction |= inst.operands[1].reg << 16;
6515 }
6516
6517 static void
6518 do_rn_rd (void)
6519 {
6520 inst.instruction |= inst.operands[0].reg << 16;
6521 inst.instruction |= inst.operands[1].reg << 12;
6522 }
6523
6524 static void
6525 do_rd_rm_rn (void)
6526 {
6527 unsigned Rn = inst.operands[2].reg;
6528 /* Enforce restrictions on SWP instruction. */
6529 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6530 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6531 _("Rn must not overlap other operands"));
6532 inst.instruction |= inst.operands[0].reg << 12;
6533 inst.instruction |= inst.operands[1].reg;
6534 inst.instruction |= Rn << 16;
6535 }
6536
6537 static void
6538 do_rd_rn_rm (void)
6539 {
6540 inst.instruction |= inst.operands[0].reg << 12;
6541 inst.instruction |= inst.operands[1].reg << 16;
6542 inst.instruction |= inst.operands[2].reg;
6543 }
6544
6545 static void
6546 do_rm_rd_rn (void)
6547 {
6548 inst.instruction |= inst.operands[0].reg;
6549 inst.instruction |= inst.operands[1].reg << 12;
6550 inst.instruction |= inst.operands[2].reg << 16;
6551 }
6552
6553 static void
6554 do_imm0 (void)
6555 {
6556 inst.instruction |= inst.operands[0].imm;
6557 }
6558
6559 static void
6560 do_rd_cpaddr (void)
6561 {
6562 inst.instruction |= inst.operands[0].reg << 12;
6563 encode_arm_cp_address (1, TRUE, TRUE, 0);
6564 }
6565
6566 /* ARM instructions, in alphabetical order by function name (except
6567 that wrapper functions appear immediately after the function they
6568 wrap). */
6569
6570 /* This is a pseudo-op of the form "adr rd, label" to be converted
6571 into a relative address of the form "add rd, pc, #label-.-8". */
6572
6573 static void
6574 do_adr (void)
6575 {
6576 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
6577
6578 /* Frag hacking will turn this into a sub instruction if the offset turns
6579 out to be negative. */
6580 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
6581 inst.reloc.pc_rel = 1;
6582 inst.reloc.exp.X_add_number -= 8;
6583 }
6584
6585 /* This is a pseudo-op of the form "adrl rd, label" to be converted
6586 into a relative address of the form:
6587 add rd, pc, #low(label-.-8)"
6588 add rd, rd, #high(label-.-8)" */
6589
6590 static void
6591 do_adrl (void)
6592 {
6593 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
6594
6595 /* Frag hacking will turn this into a sub instruction if the offset turns
6596 out to be negative. */
6597 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
6598 inst.reloc.pc_rel = 1;
6599 inst.size = INSN_SIZE * 2;
6600 inst.reloc.exp.X_add_number -= 8;
6601 }
6602
6603 static void
6604 do_arit (void)
6605 {
6606 if (!inst.operands[1].present)
6607 inst.operands[1].reg = inst.operands[0].reg;
6608 inst.instruction |= inst.operands[0].reg << 12;
6609 inst.instruction |= inst.operands[1].reg << 16;
6610 encode_arm_shifter_operand (2);
6611 }
6612
6613 static void
6614 do_barrier (void)
6615 {
6616 if (inst.operands[0].present)
6617 {
6618 constraint ((inst.instruction & 0xf0) != 0x40
6619 && inst.operands[0].imm != 0xf,
6620 _("bad barrier type"));
6621 inst.instruction |= inst.operands[0].imm;
6622 }
6623 else
6624 inst.instruction |= 0xf;
6625 }
6626
6627 static void
6628 do_bfc (void)
6629 {
6630 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6631 constraint (msb > 32, _("bit-field extends past end of register"));
6632 /* The instruction encoding stores the LSB and MSB,
6633 not the LSB and width. */
6634 inst.instruction |= inst.operands[0].reg << 12;
6635 inst.instruction |= inst.operands[1].imm << 7;
6636 inst.instruction |= (msb - 1) << 16;
6637 }
6638
6639 static void
6640 do_bfi (void)
6641 {
6642 unsigned int msb;
6643
6644 /* #0 in second position is alternative syntax for bfc, which is
6645 the same instruction but with REG_PC in the Rm field. */
6646 if (!inst.operands[1].isreg)
6647 inst.operands[1].reg = REG_PC;
6648
6649 msb = inst.operands[2].imm + inst.operands[3].imm;
6650 constraint (msb > 32, _("bit-field extends past end of register"));
6651 /* The instruction encoding stores the LSB and MSB,
6652 not the LSB and width. */
6653 inst.instruction |= inst.operands[0].reg << 12;
6654 inst.instruction |= inst.operands[1].reg;
6655 inst.instruction |= inst.operands[2].imm << 7;
6656 inst.instruction |= (msb - 1) << 16;
6657 }
6658
6659 static void
6660 do_bfx (void)
6661 {
6662 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6663 _("bit-field extends past end of register"));
6664 inst.instruction |= inst.operands[0].reg << 12;
6665 inst.instruction |= inst.operands[1].reg;
6666 inst.instruction |= inst.operands[2].imm << 7;
6667 inst.instruction |= (inst.operands[3].imm - 1) << 16;
6668 }
6669
6670 /* ARM V5 breakpoint instruction (argument parse)
6671 BKPT <16 bit unsigned immediate>
6672 Instruction is not conditional.
6673 The bit pattern given in insns[] has the COND_ALWAYS condition,
6674 and it is an error if the caller tried to override that. */
6675
6676 static void
6677 do_bkpt (void)
6678 {
6679 /* Top 12 of 16 bits to bits 19:8. */
6680 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
6681
6682 /* Bottom 4 of 16 bits to bits 3:0. */
6683 inst.instruction |= inst.operands[0].imm & 0xf;
6684 }
6685
6686 static void
6687 encode_branch (int default_reloc)
6688 {
6689 if (inst.operands[0].hasreloc)
6690 {
6691 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
6692 _("the only suffix valid here is '(plt)'"));
6693 inst.reloc.type = BFD_RELOC_ARM_PLT32;
6694 }
6695 else
6696 {
6697 inst.reloc.type = default_reloc;
6698 }
6699 inst.reloc.pc_rel = 1;
6700 }
6701
6702 static void
6703 do_branch (void)
6704 {
6705 #ifdef OBJ_ELF
6706 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6707 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6708 else
6709 #endif
6710 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6711 }
6712
6713 static void
6714 do_bl (void)
6715 {
6716 #ifdef OBJ_ELF
6717 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6718 {
6719 if (inst.cond == COND_ALWAYS)
6720 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6721 else
6722 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6723 }
6724 else
6725 #endif
6726 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6727 }
6728
6729 /* ARM V5 branch-link-exchange instruction (argument parse)
6730 BLX <target_addr> ie BLX(1)
6731 BLX{<condition>} <Rm> ie BLX(2)
6732 Unfortunately, there are two different opcodes for this mnemonic.
6733 So, the insns[].value is not used, and the code here zaps values
6734 into inst.instruction.
6735 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
6736
6737 static void
6738 do_blx (void)
6739 {
6740 if (inst.operands[0].isreg)
6741 {
6742 /* Arg is a register; the opcode provided by insns[] is correct.
6743 It is not illegal to do "blx pc", just useless. */
6744 if (inst.operands[0].reg == REG_PC)
6745 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
6746
6747 inst.instruction |= inst.operands[0].reg;
6748 }
6749 else
6750 {
6751 /* Arg is an address; this instruction cannot be executed
6752 conditionally, and the opcode must be adjusted. */
6753 constraint (inst.cond != COND_ALWAYS, BAD_COND);
6754 inst.instruction = 0xfa000000;
6755 #ifdef OBJ_ELF
6756 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6757 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6758 else
6759 #endif
6760 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
6761 }
6762 }
6763
6764 static void
6765 do_bx (void)
6766 {
6767 bfd_boolean want_reloc;
6768
6769 if (inst.operands[0].reg == REG_PC)
6770 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
6771
6772 inst.instruction |= inst.operands[0].reg;
6773 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
6774 it is for ARMv4t or earlier. */
6775 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
6776 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
6777 want_reloc = TRUE;
6778
6779 #ifdef OBJ_ELF
6780 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
6781 #endif
6782 want_reloc = FALSE;
6783
6784 if (want_reloc)
6785 inst.reloc.type = BFD_RELOC_ARM_V4BX;
6786 }
6787
6788
6789 /* ARM v5TEJ. Jump to Jazelle code. */
6790
6791 static void
6792 do_bxj (void)
6793 {
6794 if (inst.operands[0].reg == REG_PC)
6795 as_tsktsk (_("use of r15 in bxj is not really useful"));
6796
6797 inst.instruction |= inst.operands[0].reg;
6798 }
6799
6800 /* Co-processor data operation:
6801 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
6802 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
6803 static void
6804 do_cdp (void)
6805 {
6806 inst.instruction |= inst.operands[0].reg << 8;
6807 inst.instruction |= inst.operands[1].imm << 20;
6808 inst.instruction |= inst.operands[2].reg << 12;
6809 inst.instruction |= inst.operands[3].reg << 16;
6810 inst.instruction |= inst.operands[4].reg;
6811 inst.instruction |= inst.operands[5].imm << 5;
6812 }
6813
6814 static void
6815 do_cmp (void)
6816 {
6817 inst.instruction |= inst.operands[0].reg << 16;
6818 encode_arm_shifter_operand (1);
6819 }
6820
6821 /* Transfer between coprocessor and ARM registers.
6822 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
6823 MRC2
6824 MCR{cond}
6825 MCR2
6826
6827 No special properties. */
6828
6829 static void
6830 do_co_reg (void)
6831 {
6832 inst.instruction |= inst.operands[0].reg << 8;
6833 inst.instruction |= inst.operands[1].imm << 21;
6834 inst.instruction |= inst.operands[2].reg << 12;
6835 inst.instruction |= inst.operands[3].reg << 16;
6836 inst.instruction |= inst.operands[4].reg;
6837 inst.instruction |= inst.operands[5].imm << 5;
6838 }
6839
6840 /* Transfer between coprocessor register and pair of ARM registers.
6841 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
6842 MCRR2
6843 MRRC{cond}
6844 MRRC2
6845
6846 Two XScale instructions are special cases of these:
6847
6848 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
6849 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
6850
6851 Result unpredictable if Rd or Rn is R15. */
6852
6853 static void
6854 do_co_reg2c (void)
6855 {
6856 inst.instruction |= inst.operands[0].reg << 8;
6857 inst.instruction |= inst.operands[1].imm << 4;
6858 inst.instruction |= inst.operands[2].reg << 12;
6859 inst.instruction |= inst.operands[3].reg << 16;
6860 inst.instruction |= inst.operands[4].reg;
6861 }
6862
6863 static void
6864 do_cpsi (void)
6865 {
6866 inst.instruction |= inst.operands[0].imm << 6;
6867 if (inst.operands[1].present)
6868 {
6869 inst.instruction |= CPSI_MMOD;
6870 inst.instruction |= inst.operands[1].imm;
6871 }
6872 }
6873
6874 static void
6875 do_dbg (void)
6876 {
6877 inst.instruction |= inst.operands[0].imm;
6878 }
6879
6880 static void
6881 do_it (void)
6882 {
6883 /* There is no IT instruction in ARM mode. We
6884 process it but do not generate code for it. */
6885 inst.size = 0;
6886 }
6887
6888 static void
6889 do_ldmstm (void)
6890 {
6891 int base_reg = inst.operands[0].reg;
6892 int range = inst.operands[1].imm;
6893
6894 inst.instruction |= base_reg << 16;
6895 inst.instruction |= range;
6896
6897 if (inst.operands[1].writeback)
6898 inst.instruction |= LDM_TYPE_2_OR_3;
6899
6900 if (inst.operands[0].writeback)
6901 {
6902 inst.instruction |= WRITE_BACK;
6903 /* Check for unpredictable uses of writeback. */
6904 if (inst.instruction & LOAD_BIT)
6905 {
6906 /* Not allowed in LDM type 2. */
6907 if ((inst.instruction & LDM_TYPE_2_OR_3)
6908 && ((range & (1 << REG_PC)) == 0))
6909 as_warn (_("writeback of base register is UNPREDICTABLE"));
6910 /* Only allowed if base reg not in list for other types. */
6911 else if (range & (1 << base_reg))
6912 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
6913 }
6914 else /* STM. */
6915 {
6916 /* Not allowed for type 2. */
6917 if (inst.instruction & LDM_TYPE_2_OR_3)
6918 as_warn (_("writeback of base register is UNPREDICTABLE"));
6919 /* Only allowed if base reg not in list, or first in list. */
6920 else if ((range & (1 << base_reg))
6921 && (range & ((1 << base_reg) - 1)))
6922 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
6923 }
6924 }
6925 }
6926
6927 /* ARMv5TE load-consecutive (argument parse)
6928 Mode is like LDRH.
6929
6930 LDRccD R, mode
6931 STRccD R, mode. */
6932
6933 static void
6934 do_ldrd (void)
6935 {
6936 constraint (inst.operands[0].reg % 2 != 0,
6937 _("first destination register must be even"));
6938 constraint (inst.operands[1].present
6939 && inst.operands[1].reg != inst.operands[0].reg + 1,
6940 _("can only load two consecutive registers"));
6941 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
6942 constraint (!inst.operands[2].isreg, _("'[' expected"));
6943
6944 if (!inst.operands[1].present)
6945 inst.operands[1].reg = inst.operands[0].reg + 1;
6946
6947 if (inst.instruction & LOAD_BIT)
6948 {
6949 /* encode_arm_addr_mode_3 will diagnose overlap between the base
6950 register and the first register written; we have to diagnose
6951 overlap between the base and the second register written here. */
6952
6953 if (inst.operands[2].reg == inst.operands[1].reg
6954 && (inst.operands[2].writeback || inst.operands[2].postind))
6955 as_warn (_("base register written back, and overlaps "
6956 "second destination register"));
6957
6958 /* For an index-register load, the index register must not overlap the
6959 destination (even if not write-back). */
6960 else if (inst.operands[2].immisreg
6961 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
6962 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
6963 as_warn (_("index register overlaps destination register"));
6964 }
6965
6966 inst.instruction |= inst.operands[0].reg << 12;
6967 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
6968 }
6969
6970 static void
6971 do_ldrex (void)
6972 {
6973 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
6974 || inst.operands[1].postind || inst.operands[1].writeback
6975 || inst.operands[1].immisreg || inst.operands[1].shifted
6976 || inst.operands[1].negative
6977 /* This can arise if the programmer has written
6978 strex rN, rM, foo
6979 or if they have mistakenly used a register name as the last
6980 operand, eg:
6981 strex rN, rM, rX
6982 It is very difficult to distinguish between these two cases
6983 because "rX" might actually be a label. ie the register
6984 name has been occluded by a symbol of the same name. So we
6985 just generate a general 'bad addressing mode' type error
6986 message and leave it up to the programmer to discover the
6987 true cause and fix their mistake. */
6988 || (inst.operands[1].reg == REG_PC),
6989 BAD_ADDR_MODE);
6990
6991 constraint (inst.reloc.exp.X_op != O_constant
6992 || inst.reloc.exp.X_add_number != 0,
6993 _("offset must be zero in ARM encoding"));
6994
6995 inst.instruction |= inst.operands[0].reg << 12;
6996 inst.instruction |= inst.operands[1].reg << 16;
6997 inst.reloc.type = BFD_RELOC_UNUSED;
6998 }
6999
7000 static void
7001 do_ldrexd (void)
7002 {
7003 constraint (inst.operands[0].reg % 2 != 0,
7004 _("even register required"));
7005 constraint (inst.operands[1].present
7006 && inst.operands[1].reg != inst.operands[0].reg + 1,
7007 _("can only load two consecutive registers"));
7008 /* If op 1 were present and equal to PC, this function wouldn't
7009 have been called in the first place. */
7010 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7011
7012 inst.instruction |= inst.operands[0].reg << 12;
7013 inst.instruction |= inst.operands[2].reg << 16;
7014 }
7015
7016 static void
7017 do_ldst (void)
7018 {
7019 inst.instruction |= inst.operands[0].reg << 12;
7020 if (!inst.operands[1].isreg)
7021 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
7022 return;
7023 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
7024 }
7025
7026 static void
7027 do_ldstt (void)
7028 {
7029 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7030 reject [Rn,...]. */
7031 if (inst.operands[1].preind)
7032 {
7033 constraint (inst.reloc.exp.X_op != O_constant
7034 || inst.reloc.exp.X_add_number != 0,
7035 _("this instruction requires a post-indexed address"));
7036
7037 inst.operands[1].preind = 0;
7038 inst.operands[1].postind = 1;
7039 inst.operands[1].writeback = 1;
7040 }
7041 inst.instruction |= inst.operands[0].reg << 12;
7042 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7043 }
7044
7045 /* Halfword and signed-byte load/store operations. */
7046
7047 static void
7048 do_ldstv4 (void)
7049 {
7050 inst.instruction |= inst.operands[0].reg << 12;
7051 if (!inst.operands[1].isreg)
7052 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
7053 return;
7054 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
7055 }
7056
7057 static void
7058 do_ldsttv4 (void)
7059 {
7060 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7061 reject [Rn,...]. */
7062 if (inst.operands[1].preind)
7063 {
7064 constraint (inst.reloc.exp.X_op != O_constant
7065 || inst.reloc.exp.X_add_number != 0,
7066 _("this instruction requires a post-indexed address"));
7067
7068 inst.operands[1].preind = 0;
7069 inst.operands[1].postind = 1;
7070 inst.operands[1].writeback = 1;
7071 }
7072 inst.instruction |= inst.operands[0].reg << 12;
7073 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7074 }
7075
7076 /* Co-processor register load/store.
7077 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7078 static void
7079 do_lstc (void)
7080 {
7081 inst.instruction |= inst.operands[0].reg << 8;
7082 inst.instruction |= inst.operands[1].reg << 12;
7083 encode_arm_cp_address (2, TRUE, TRUE, 0);
7084 }
7085
7086 static void
7087 do_mlas (void)
7088 {
7089 /* This restriction does not apply to mls (nor to mla in v6 or later). */
7090 if (inst.operands[0].reg == inst.operands[1].reg
7091 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
7092 && !(inst.instruction & 0x00400000))
7093 as_tsktsk (_("Rd and Rm should be different in mla"));
7094
7095 inst.instruction |= inst.operands[0].reg << 16;
7096 inst.instruction |= inst.operands[1].reg;
7097 inst.instruction |= inst.operands[2].reg << 8;
7098 inst.instruction |= inst.operands[3].reg << 12;
7099 }
7100
7101 static void
7102 do_mov (void)
7103 {
7104 inst.instruction |= inst.operands[0].reg << 12;
7105 encode_arm_shifter_operand (1);
7106 }
7107
7108 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7109 static void
7110 do_mov16 (void)
7111 {
7112 bfd_vma imm;
7113 bfd_boolean top;
7114
7115 top = (inst.instruction & 0x00400000) != 0;
7116 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7117 _(":lower16: not allowed this instruction"));
7118 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7119 _(":upper16: not allowed instruction"));
7120 inst.instruction |= inst.operands[0].reg << 12;
7121 if (inst.reloc.type == BFD_RELOC_UNUSED)
7122 {
7123 imm = inst.reloc.exp.X_add_number;
7124 /* The value is in two pieces: 0:11, 16:19. */
7125 inst.instruction |= (imm & 0x00000fff);
7126 inst.instruction |= (imm & 0x0000f000) << 4;
7127 }
7128 }
7129
7130 static void do_vfp_nsyn_opcode (const char *);
7131
7132 static int
7133 do_vfp_nsyn_mrs (void)
7134 {
7135 if (inst.operands[0].isvec)
7136 {
7137 if (inst.operands[1].reg != 1)
7138 first_error (_("operand 1 must be FPSCR"));
7139 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7140 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7141 do_vfp_nsyn_opcode ("fmstat");
7142 }
7143 else if (inst.operands[1].isvec)
7144 do_vfp_nsyn_opcode ("fmrx");
7145 else
7146 return FAIL;
7147
7148 return SUCCESS;
7149 }
7150
7151 static int
7152 do_vfp_nsyn_msr (void)
7153 {
7154 if (inst.operands[0].isvec)
7155 do_vfp_nsyn_opcode ("fmxr");
7156 else
7157 return FAIL;
7158
7159 return SUCCESS;
7160 }
7161
7162 static void
7163 do_mrs (void)
7164 {
7165 if (do_vfp_nsyn_mrs () == SUCCESS)
7166 return;
7167
7168 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7169 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7170 != (PSR_c|PSR_f),
7171 _("'CPSR' or 'SPSR' expected"));
7172 inst.instruction |= inst.operands[0].reg << 12;
7173 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7174 }
7175
7176 /* Two possible forms:
7177 "{C|S}PSR_<field>, Rm",
7178 "{C|S}PSR_f, #expression". */
7179
7180 static void
7181 do_msr (void)
7182 {
7183 if (do_vfp_nsyn_msr () == SUCCESS)
7184 return;
7185
7186 inst.instruction |= inst.operands[0].imm;
7187 if (inst.operands[1].isreg)
7188 inst.instruction |= inst.operands[1].reg;
7189 else
7190 {
7191 inst.instruction |= INST_IMMEDIATE;
7192 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7193 inst.reloc.pc_rel = 0;
7194 }
7195 }
7196
7197 static void
7198 do_mul (void)
7199 {
7200 if (!inst.operands[2].present)
7201 inst.operands[2].reg = inst.operands[0].reg;
7202 inst.instruction |= inst.operands[0].reg << 16;
7203 inst.instruction |= inst.operands[1].reg;
7204 inst.instruction |= inst.operands[2].reg << 8;
7205
7206 if (inst.operands[0].reg == inst.operands[1].reg
7207 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7208 as_tsktsk (_("Rd and Rm should be different in mul"));
7209 }
7210
7211 /* Long Multiply Parser
7212 UMULL RdLo, RdHi, Rm, Rs
7213 SMULL RdLo, RdHi, Rm, Rs
7214 UMLAL RdLo, RdHi, Rm, Rs
7215 SMLAL RdLo, RdHi, Rm, Rs. */
7216
7217 static void
7218 do_mull (void)
7219 {
7220 inst.instruction |= inst.operands[0].reg << 12;
7221 inst.instruction |= inst.operands[1].reg << 16;
7222 inst.instruction |= inst.operands[2].reg;
7223 inst.instruction |= inst.operands[3].reg << 8;
7224
7225 /* rdhi and rdlo must be different. */
7226 if (inst.operands[0].reg == inst.operands[1].reg)
7227 as_tsktsk (_("rdhi and rdlo must be different"));
7228
7229 /* rdhi, rdlo and rm must all be different before armv6. */
7230 if ((inst.operands[0].reg == inst.operands[2].reg
7231 || inst.operands[1].reg == inst.operands[2].reg)
7232 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7233 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7234 }
7235
7236 static void
7237 do_nop (void)
7238 {
7239 if (inst.operands[0].present)
7240 {
7241 /* Architectural NOP hints are CPSR sets with no bits selected. */
7242 inst.instruction &= 0xf0000000;
7243 inst.instruction |= 0x0320f000 + inst.operands[0].imm;
7244 }
7245 }
7246
7247 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7248 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7249 Condition defaults to COND_ALWAYS.
7250 Error if Rd, Rn or Rm are R15. */
7251
7252 static void
7253 do_pkhbt (void)
7254 {
7255 inst.instruction |= inst.operands[0].reg << 12;
7256 inst.instruction |= inst.operands[1].reg << 16;
7257 inst.instruction |= inst.operands[2].reg;
7258 if (inst.operands[3].present)
7259 encode_arm_shift (3);
7260 }
7261
7262 /* ARM V6 PKHTB (Argument Parse). */
7263
7264 static void
7265 do_pkhtb (void)
7266 {
7267 if (!inst.operands[3].present)
7268 {
7269 /* If the shift specifier is omitted, turn the instruction
7270 into pkhbt rd, rm, rn. */
7271 inst.instruction &= 0xfff00010;
7272 inst.instruction |= inst.operands[0].reg << 12;
7273 inst.instruction |= inst.operands[1].reg;
7274 inst.instruction |= inst.operands[2].reg << 16;
7275 }
7276 else
7277 {
7278 inst.instruction |= inst.operands[0].reg << 12;
7279 inst.instruction |= inst.operands[1].reg << 16;
7280 inst.instruction |= inst.operands[2].reg;
7281 encode_arm_shift (3);
7282 }
7283 }
7284
7285 /* ARMv5TE: Preload-Cache
7286
7287 PLD <addr_mode>
7288
7289 Syntactically, like LDR with B=1, W=0, L=1. */
7290
7291 static void
7292 do_pld (void)
7293 {
7294 constraint (!inst.operands[0].isreg,
7295 _("'[' expected after PLD mnemonic"));
7296 constraint (inst.operands[0].postind,
7297 _("post-indexed expression used in preload instruction"));
7298 constraint (inst.operands[0].writeback,
7299 _("writeback used in preload instruction"));
7300 constraint (!inst.operands[0].preind,
7301 _("unindexed addressing used in preload instruction"));
7302 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7303 }
7304
7305 /* ARMv7: PLI <addr_mode> */
7306 static void
7307 do_pli (void)
7308 {
7309 constraint (!inst.operands[0].isreg,
7310 _("'[' expected after PLI mnemonic"));
7311 constraint (inst.operands[0].postind,
7312 _("post-indexed expression used in preload instruction"));
7313 constraint (inst.operands[0].writeback,
7314 _("writeback used in preload instruction"));
7315 constraint (!inst.operands[0].preind,
7316 _("unindexed addressing used in preload instruction"));
7317 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7318 inst.instruction &= ~PRE_INDEX;
7319 }
7320
7321 static void
7322 do_push_pop (void)
7323 {
7324 inst.operands[1] = inst.operands[0];
7325 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7326 inst.operands[0].isreg = 1;
7327 inst.operands[0].writeback = 1;
7328 inst.operands[0].reg = REG_SP;
7329 do_ldmstm ();
7330 }
7331
7332 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7333 word at the specified address and the following word
7334 respectively.
7335 Unconditionally executed.
7336 Error if Rn is R15. */
7337
7338 static void
7339 do_rfe (void)
7340 {
7341 inst.instruction |= inst.operands[0].reg << 16;
7342 if (inst.operands[0].writeback)
7343 inst.instruction |= WRITE_BACK;
7344 }
7345
7346 /* ARM V6 ssat (argument parse). */
7347
7348 static void
7349 do_ssat (void)
7350 {
7351 inst.instruction |= inst.operands[0].reg << 12;
7352 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7353 inst.instruction |= inst.operands[2].reg;
7354
7355 if (inst.operands[3].present)
7356 encode_arm_shift (3);
7357 }
7358
7359 /* ARM V6 usat (argument parse). */
7360
7361 static void
7362 do_usat (void)
7363 {
7364 inst.instruction |= inst.operands[0].reg << 12;
7365 inst.instruction |= inst.operands[1].imm << 16;
7366 inst.instruction |= inst.operands[2].reg;
7367
7368 if (inst.operands[3].present)
7369 encode_arm_shift (3);
7370 }
7371
7372 /* ARM V6 ssat16 (argument parse). */
7373
7374 static void
7375 do_ssat16 (void)
7376 {
7377 inst.instruction |= inst.operands[0].reg << 12;
7378 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7379 inst.instruction |= inst.operands[2].reg;
7380 }
7381
7382 static void
7383 do_usat16 (void)
7384 {
7385 inst.instruction |= inst.operands[0].reg << 12;
7386 inst.instruction |= inst.operands[1].imm << 16;
7387 inst.instruction |= inst.operands[2].reg;
7388 }
7389
7390 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7391 preserving the other bits.
7392
7393 setend <endian_specifier>, where <endian_specifier> is either
7394 BE or LE. */
7395
7396 static void
7397 do_setend (void)
7398 {
7399 if (inst.operands[0].imm)
7400 inst.instruction |= 0x200;
7401 }
7402
7403 static void
7404 do_shift (void)
7405 {
7406 unsigned int Rm = (inst.operands[1].present
7407 ? inst.operands[1].reg
7408 : inst.operands[0].reg);
7409
7410 inst.instruction |= inst.operands[0].reg << 12;
7411 inst.instruction |= Rm;
7412 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
7413 {
7414 inst.instruction |= inst.operands[2].reg << 8;
7415 inst.instruction |= SHIFT_BY_REG;
7416 }
7417 else
7418 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7419 }
7420
7421 static void
7422 do_smc (void)
7423 {
7424 inst.reloc.type = BFD_RELOC_ARM_SMC;
7425 inst.reloc.pc_rel = 0;
7426 }
7427
7428 static void
7429 do_swi (void)
7430 {
7431 inst.reloc.type = BFD_RELOC_ARM_SWI;
7432 inst.reloc.pc_rel = 0;
7433 }
7434
7435 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7436 SMLAxy{cond} Rd,Rm,Rs,Rn
7437 SMLAWy{cond} Rd,Rm,Rs,Rn
7438 Error if any register is R15. */
7439
7440 static void
7441 do_smla (void)
7442 {
7443 inst.instruction |= inst.operands[0].reg << 16;
7444 inst.instruction |= inst.operands[1].reg;
7445 inst.instruction |= inst.operands[2].reg << 8;
7446 inst.instruction |= inst.operands[3].reg << 12;
7447 }
7448
7449 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7450 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7451 Error if any register is R15.
7452 Warning if Rdlo == Rdhi. */
7453
7454 static void
7455 do_smlal (void)
7456 {
7457 inst.instruction |= inst.operands[0].reg << 12;
7458 inst.instruction |= inst.operands[1].reg << 16;
7459 inst.instruction |= inst.operands[2].reg;
7460 inst.instruction |= inst.operands[3].reg << 8;
7461
7462 if (inst.operands[0].reg == inst.operands[1].reg)
7463 as_tsktsk (_("rdhi and rdlo must be different"));
7464 }
7465
7466 /* ARM V5E (El Segundo) signed-multiply (argument parse)
7467 SMULxy{cond} Rd,Rm,Rs
7468 Error if any register is R15. */
7469
7470 static void
7471 do_smul (void)
7472 {
7473 inst.instruction |= inst.operands[0].reg << 16;
7474 inst.instruction |= inst.operands[1].reg;
7475 inst.instruction |= inst.operands[2].reg << 8;
7476 }
7477
7478 /* ARM V6 srs (argument parse). The variable fields in the encoding are
7479 the same for both ARM and Thumb-2. */
7480
7481 static void
7482 do_srs (void)
7483 {
7484 int reg;
7485
7486 if (inst.operands[0].present)
7487 {
7488 reg = inst.operands[0].reg;
7489 constraint (reg != 13, _("SRS base register must be r13"));
7490 }
7491 else
7492 reg = 13;
7493
7494 inst.instruction |= reg << 16;
7495 inst.instruction |= inst.operands[1].imm;
7496 if (inst.operands[0].writeback || inst.operands[1].writeback)
7497 inst.instruction |= WRITE_BACK;
7498 }
7499
7500 /* ARM V6 strex (argument parse). */
7501
7502 static void
7503 do_strex (void)
7504 {
7505 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7506 || inst.operands[2].postind || inst.operands[2].writeback
7507 || inst.operands[2].immisreg || inst.operands[2].shifted
7508 || inst.operands[2].negative
7509 /* See comment in do_ldrex(). */
7510 || (inst.operands[2].reg == REG_PC),
7511 BAD_ADDR_MODE);
7512
7513 constraint (inst.operands[0].reg == inst.operands[1].reg
7514 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
7515
7516 constraint (inst.reloc.exp.X_op != O_constant
7517 || inst.reloc.exp.X_add_number != 0,
7518 _("offset must be zero in ARM encoding"));
7519
7520 inst.instruction |= inst.operands[0].reg << 12;
7521 inst.instruction |= inst.operands[1].reg;
7522 inst.instruction |= inst.operands[2].reg << 16;
7523 inst.reloc.type = BFD_RELOC_UNUSED;
7524 }
7525
7526 static void
7527 do_strexd (void)
7528 {
7529 constraint (inst.operands[1].reg % 2 != 0,
7530 _("even register required"));
7531 constraint (inst.operands[2].present
7532 && inst.operands[2].reg != inst.operands[1].reg + 1,
7533 _("can only store two consecutive registers"));
7534 /* If op 2 were present and equal to PC, this function wouldn't
7535 have been called in the first place. */
7536 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
7537
7538 constraint (inst.operands[0].reg == inst.operands[1].reg
7539 || inst.operands[0].reg == inst.operands[1].reg + 1
7540 || inst.operands[0].reg == inst.operands[3].reg,
7541 BAD_OVERLAP);
7542
7543 inst.instruction |= inst.operands[0].reg << 12;
7544 inst.instruction |= inst.operands[1].reg;
7545 inst.instruction |= inst.operands[3].reg << 16;
7546 }
7547
7548 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
7549 extends it to 32-bits, and adds the result to a value in another
7550 register. You can specify a rotation by 0, 8, 16, or 24 bits
7551 before extracting the 16-bit value.
7552 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
7553 Condition defaults to COND_ALWAYS.
7554 Error if any register uses R15. */
7555
7556 static void
7557 do_sxtah (void)
7558 {
7559 inst.instruction |= inst.operands[0].reg << 12;
7560 inst.instruction |= inst.operands[1].reg << 16;
7561 inst.instruction |= inst.operands[2].reg;
7562 inst.instruction |= inst.operands[3].imm << 10;
7563 }
7564
7565 /* ARM V6 SXTH.
7566
7567 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
7568 Condition defaults to COND_ALWAYS.
7569 Error if any register uses R15. */
7570
7571 static void
7572 do_sxth (void)
7573 {
7574 inst.instruction |= inst.operands[0].reg << 12;
7575 inst.instruction |= inst.operands[1].reg;
7576 inst.instruction |= inst.operands[2].imm << 10;
7577 }
7578 \f
7579 /* VFP instructions. In a logical order: SP variant first, monad
7580 before dyad, arithmetic then move then load/store. */
7581
7582 static void
7583 do_vfp_sp_monadic (void)
7584 {
7585 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7586 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
7587 }
7588
7589 static void
7590 do_vfp_sp_dyadic (void)
7591 {
7592 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7593 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7594 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
7595 }
7596
7597 static void
7598 do_vfp_sp_compare_z (void)
7599 {
7600 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7601 }
7602
7603 static void
7604 do_vfp_dp_sp_cvt (void)
7605 {
7606 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7607 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
7608 }
7609
7610 static void
7611 do_vfp_sp_dp_cvt (void)
7612 {
7613 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7614 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7615 }
7616
7617 static void
7618 do_vfp_reg_from_sp (void)
7619 {
7620 inst.instruction |= inst.operands[0].reg << 12;
7621 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7622 }
7623
7624 static void
7625 do_vfp_reg2_from_sp2 (void)
7626 {
7627 constraint (inst.operands[2].imm != 2,
7628 _("only two consecutive VFP SP registers allowed here"));
7629 inst.instruction |= inst.operands[0].reg << 12;
7630 inst.instruction |= inst.operands[1].reg << 16;
7631 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
7632 }
7633
7634 static void
7635 do_vfp_sp_from_reg (void)
7636 {
7637 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
7638 inst.instruction |= inst.operands[1].reg << 12;
7639 }
7640
7641 static void
7642 do_vfp_sp2_from_reg2 (void)
7643 {
7644 constraint (inst.operands[0].imm != 2,
7645 _("only two consecutive VFP SP registers allowed here"));
7646 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
7647 inst.instruction |= inst.operands[1].reg << 12;
7648 inst.instruction |= inst.operands[2].reg << 16;
7649 }
7650
7651 static void
7652 do_vfp_sp_ldst (void)
7653 {
7654 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7655 encode_arm_cp_address (1, FALSE, TRUE, 0);
7656 }
7657
7658 static void
7659 do_vfp_dp_ldst (void)
7660 {
7661 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7662 encode_arm_cp_address (1, FALSE, TRUE, 0);
7663 }
7664
7665
7666 static void
7667 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
7668 {
7669 if (inst.operands[0].writeback)
7670 inst.instruction |= WRITE_BACK;
7671 else
7672 constraint (ldstm_type != VFP_LDSTMIA,
7673 _("this addressing mode requires base-register writeback"));
7674 inst.instruction |= inst.operands[0].reg << 16;
7675 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
7676 inst.instruction |= inst.operands[1].imm;
7677 }
7678
7679 static void
7680 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
7681 {
7682 int count;
7683
7684 if (inst.operands[0].writeback)
7685 inst.instruction |= WRITE_BACK;
7686 else
7687 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
7688 _("this addressing mode requires base-register writeback"));
7689
7690 inst.instruction |= inst.operands[0].reg << 16;
7691 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7692
7693 count = inst.operands[1].imm << 1;
7694 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
7695 count += 1;
7696
7697 inst.instruction |= count;
7698 }
7699
7700 static void
7701 do_vfp_sp_ldstmia (void)
7702 {
7703 vfp_sp_ldstm (VFP_LDSTMIA);
7704 }
7705
7706 static void
7707 do_vfp_sp_ldstmdb (void)
7708 {
7709 vfp_sp_ldstm (VFP_LDSTMDB);
7710 }
7711
7712 static void
7713 do_vfp_dp_ldstmia (void)
7714 {
7715 vfp_dp_ldstm (VFP_LDSTMIA);
7716 }
7717
7718 static void
7719 do_vfp_dp_ldstmdb (void)
7720 {
7721 vfp_dp_ldstm (VFP_LDSTMDB);
7722 }
7723
7724 static void
7725 do_vfp_xp_ldstmia (void)
7726 {
7727 vfp_dp_ldstm (VFP_LDSTMIAX);
7728 }
7729
7730 static void
7731 do_vfp_xp_ldstmdb (void)
7732 {
7733 vfp_dp_ldstm (VFP_LDSTMDBX);
7734 }
7735
7736 static void
7737 do_vfp_dp_rd_rm (void)
7738 {
7739 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7740 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7741 }
7742
7743 static void
7744 do_vfp_dp_rn_rd (void)
7745 {
7746 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
7747 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7748 }
7749
7750 static void
7751 do_vfp_dp_rd_rn (void)
7752 {
7753 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7754 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7755 }
7756
7757 static void
7758 do_vfp_dp_rd_rn_rm (void)
7759 {
7760 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7761 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7762 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
7763 }
7764
7765 static void
7766 do_vfp_dp_rd (void)
7767 {
7768 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7769 }
7770
7771 static void
7772 do_vfp_dp_rm_rd_rn (void)
7773 {
7774 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
7775 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7776 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
7777 }
7778
7779 /* VFPv3 instructions. */
7780 static void
7781 do_vfp_sp_const (void)
7782 {
7783 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7784 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7785 inst.instruction |= (inst.operands[1].imm & 0x0f);
7786 }
7787
7788 static void
7789 do_vfp_dp_const (void)
7790 {
7791 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7792 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7793 inst.instruction |= (inst.operands[1].imm & 0x0f);
7794 }
7795
7796 static void
7797 vfp_conv (int srcsize)
7798 {
7799 unsigned immbits = srcsize - inst.operands[1].imm;
7800 inst.instruction |= (immbits & 1) << 5;
7801 inst.instruction |= (immbits >> 1);
7802 }
7803
7804 static void
7805 do_vfp_sp_conv_16 (void)
7806 {
7807 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7808 vfp_conv (16);
7809 }
7810
7811 static void
7812 do_vfp_dp_conv_16 (void)
7813 {
7814 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7815 vfp_conv (16);
7816 }
7817
7818 static void
7819 do_vfp_sp_conv_32 (void)
7820 {
7821 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7822 vfp_conv (32);
7823 }
7824
7825 static void
7826 do_vfp_dp_conv_32 (void)
7827 {
7828 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7829 vfp_conv (32);
7830 }
7831 \f
7832 /* FPA instructions. Also in a logical order. */
7833
7834 static void
7835 do_fpa_cmp (void)
7836 {
7837 inst.instruction |= inst.operands[0].reg << 16;
7838 inst.instruction |= inst.operands[1].reg;
7839 }
7840
7841 static void
7842 do_fpa_ldmstm (void)
7843 {
7844 inst.instruction |= inst.operands[0].reg << 12;
7845 switch (inst.operands[1].imm)
7846 {
7847 case 1: inst.instruction |= CP_T_X; break;
7848 case 2: inst.instruction |= CP_T_Y; break;
7849 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
7850 case 4: break;
7851 default: abort ();
7852 }
7853
7854 if (inst.instruction & (PRE_INDEX | INDEX_UP))
7855 {
7856 /* The instruction specified "ea" or "fd", so we can only accept
7857 [Rn]{!}. The instruction does not really support stacking or
7858 unstacking, so we have to emulate these by setting appropriate
7859 bits and offsets. */
7860 constraint (inst.reloc.exp.X_op != O_constant
7861 || inst.reloc.exp.X_add_number != 0,
7862 _("this instruction does not support indexing"));
7863
7864 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
7865 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
7866
7867 if (!(inst.instruction & INDEX_UP))
7868 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
7869
7870 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
7871 {
7872 inst.operands[2].preind = 0;
7873 inst.operands[2].postind = 1;
7874 }
7875 }
7876
7877 encode_arm_cp_address (2, TRUE, TRUE, 0);
7878 }
7879 \f
7880 /* iWMMXt instructions: strictly in alphabetical order. */
7881
7882 static void
7883 do_iwmmxt_tandorc (void)
7884 {
7885 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
7886 }
7887
7888 static void
7889 do_iwmmxt_textrc (void)
7890 {
7891 inst.instruction |= inst.operands[0].reg << 12;
7892 inst.instruction |= inst.operands[1].imm;
7893 }
7894
7895 static void
7896 do_iwmmxt_textrm (void)
7897 {
7898 inst.instruction |= inst.operands[0].reg << 12;
7899 inst.instruction |= inst.operands[1].reg << 16;
7900 inst.instruction |= inst.operands[2].imm;
7901 }
7902
7903 static void
7904 do_iwmmxt_tinsr (void)
7905 {
7906 inst.instruction |= inst.operands[0].reg << 16;
7907 inst.instruction |= inst.operands[1].reg << 12;
7908 inst.instruction |= inst.operands[2].imm;
7909 }
7910
7911 static void
7912 do_iwmmxt_tmia (void)
7913 {
7914 inst.instruction |= inst.operands[0].reg << 5;
7915 inst.instruction |= inst.operands[1].reg;
7916 inst.instruction |= inst.operands[2].reg << 12;
7917 }
7918
7919 static void
7920 do_iwmmxt_waligni (void)
7921 {
7922 inst.instruction |= inst.operands[0].reg << 12;
7923 inst.instruction |= inst.operands[1].reg << 16;
7924 inst.instruction |= inst.operands[2].reg;
7925 inst.instruction |= inst.operands[3].imm << 20;
7926 }
7927
7928 static void
7929 do_iwmmxt_wmerge (void)
7930 {
7931 inst.instruction |= inst.operands[0].reg << 12;
7932 inst.instruction |= inst.operands[1].reg << 16;
7933 inst.instruction |= inst.operands[2].reg;
7934 inst.instruction |= inst.operands[3].imm << 21;
7935 }
7936
7937 static void
7938 do_iwmmxt_wmov (void)
7939 {
7940 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
7941 inst.instruction |= inst.operands[0].reg << 12;
7942 inst.instruction |= inst.operands[1].reg << 16;
7943 inst.instruction |= inst.operands[1].reg;
7944 }
7945
7946 static void
7947 do_iwmmxt_wldstbh (void)
7948 {
7949 int reloc;
7950 inst.instruction |= inst.operands[0].reg << 12;
7951 if (thumb_mode)
7952 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
7953 else
7954 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
7955 encode_arm_cp_address (1, TRUE, FALSE, reloc);
7956 }
7957
7958 static void
7959 do_iwmmxt_wldstw (void)
7960 {
7961 /* RIWR_RIWC clears .isreg for a control register. */
7962 if (!inst.operands[0].isreg)
7963 {
7964 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7965 inst.instruction |= 0xf0000000;
7966 }
7967
7968 inst.instruction |= inst.operands[0].reg << 12;
7969 encode_arm_cp_address (1, TRUE, TRUE, 0);
7970 }
7971
7972 static void
7973 do_iwmmxt_wldstd (void)
7974 {
7975 inst.instruction |= inst.operands[0].reg << 12;
7976 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
7977 && inst.operands[1].immisreg)
7978 {
7979 inst.instruction &= ~0x1a000ff;
7980 inst.instruction |= (0xf << 28);
7981 if (inst.operands[1].preind)
7982 inst.instruction |= PRE_INDEX;
7983 if (!inst.operands[1].negative)
7984 inst.instruction |= INDEX_UP;
7985 if (inst.operands[1].writeback)
7986 inst.instruction |= WRITE_BACK;
7987 inst.instruction |= inst.operands[1].reg << 16;
7988 inst.instruction |= inst.reloc.exp.X_add_number << 4;
7989 inst.instruction |= inst.operands[1].imm;
7990 }
7991 else
7992 encode_arm_cp_address (1, TRUE, FALSE, 0);
7993 }
7994
7995 static void
7996 do_iwmmxt_wshufh (void)
7997 {
7998 inst.instruction |= inst.operands[0].reg << 12;
7999 inst.instruction |= inst.operands[1].reg << 16;
8000 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8001 inst.instruction |= (inst.operands[2].imm & 0x0f);
8002 }
8003
8004 static void
8005 do_iwmmxt_wzero (void)
8006 {
8007 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8008 inst.instruction |= inst.operands[0].reg;
8009 inst.instruction |= inst.operands[0].reg << 12;
8010 inst.instruction |= inst.operands[0].reg << 16;
8011 }
8012
8013 static void
8014 do_iwmmxt_wrwrwr_or_imm5 (void)
8015 {
8016 if (inst.operands[2].isreg)
8017 do_rd_rn_rm ();
8018 else {
8019 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8020 _("immediate operand requires iWMMXt2"));
8021 do_rd_rn ();
8022 if (inst.operands[2].imm == 0)
8023 {
8024 switch ((inst.instruction >> 20) & 0xf)
8025 {
8026 case 4:
8027 case 5:
8028 case 6:
8029 case 7:
8030 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8031 inst.operands[2].imm = 16;
8032 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8033 break;
8034 case 8:
8035 case 9:
8036 case 10:
8037 case 11:
8038 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8039 inst.operands[2].imm = 32;
8040 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8041 break;
8042 case 12:
8043 case 13:
8044 case 14:
8045 case 15:
8046 {
8047 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8048 unsigned long wrn;
8049 wrn = (inst.instruction >> 16) & 0xf;
8050 inst.instruction &= 0xff0fff0f;
8051 inst.instruction |= wrn;
8052 /* Bail out here; the instruction is now assembled. */
8053 return;
8054 }
8055 }
8056 }
8057 /* Map 32 -> 0, etc. */
8058 inst.operands[2].imm &= 0x1f;
8059 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8060 }
8061 }
8062 \f
8063 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8064 operations first, then control, shift, and load/store. */
8065
8066 /* Insns like "foo X,Y,Z". */
8067
8068 static void
8069 do_mav_triple (void)
8070 {
8071 inst.instruction |= inst.operands[0].reg << 16;
8072 inst.instruction |= inst.operands[1].reg;
8073 inst.instruction |= inst.operands[2].reg << 12;
8074 }
8075
8076 /* Insns like "foo W,X,Y,Z".
8077 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
8078
8079 static void
8080 do_mav_quad (void)
8081 {
8082 inst.instruction |= inst.operands[0].reg << 5;
8083 inst.instruction |= inst.operands[1].reg << 12;
8084 inst.instruction |= inst.operands[2].reg << 16;
8085 inst.instruction |= inst.operands[3].reg;
8086 }
8087
8088 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8089 static void
8090 do_mav_dspsc (void)
8091 {
8092 inst.instruction |= inst.operands[1].reg << 12;
8093 }
8094
8095 /* Maverick shift immediate instructions.
8096 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8097 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
8098
8099 static void
8100 do_mav_shift (void)
8101 {
8102 int imm = inst.operands[2].imm;
8103
8104 inst.instruction |= inst.operands[0].reg << 12;
8105 inst.instruction |= inst.operands[1].reg << 16;
8106
8107 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8108 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8109 Bit 4 should be 0. */
8110 imm = (imm & 0xf) | ((imm & 0x70) << 1);
8111
8112 inst.instruction |= imm;
8113 }
8114 \f
8115 /* XScale instructions. Also sorted arithmetic before move. */
8116
8117 /* Xscale multiply-accumulate (argument parse)
8118 MIAcc acc0,Rm,Rs
8119 MIAPHcc acc0,Rm,Rs
8120 MIAxycc acc0,Rm,Rs. */
8121
8122 static void
8123 do_xsc_mia (void)
8124 {
8125 inst.instruction |= inst.operands[1].reg;
8126 inst.instruction |= inst.operands[2].reg << 12;
8127 }
8128
8129 /* Xscale move-accumulator-register (argument parse)
8130
8131 MARcc acc0,RdLo,RdHi. */
8132
8133 static void
8134 do_xsc_mar (void)
8135 {
8136 inst.instruction |= inst.operands[1].reg << 12;
8137 inst.instruction |= inst.operands[2].reg << 16;
8138 }
8139
8140 /* Xscale move-register-accumulator (argument parse)
8141
8142 MRAcc RdLo,RdHi,acc0. */
8143
8144 static void
8145 do_xsc_mra (void)
8146 {
8147 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8148 inst.instruction |= inst.operands[0].reg << 12;
8149 inst.instruction |= inst.operands[1].reg << 16;
8150 }
8151 \f
8152 /* Encoding functions relevant only to Thumb. */
8153
8154 /* inst.operands[i] is a shifted-register operand; encode
8155 it into inst.instruction in the format used by Thumb32. */
8156
8157 static void
8158 encode_thumb32_shifted_operand (int i)
8159 {
8160 unsigned int value = inst.reloc.exp.X_add_number;
8161 unsigned int shift = inst.operands[i].shift_kind;
8162
8163 constraint (inst.operands[i].immisreg,
8164 _("shift by register not allowed in thumb mode"));
8165 inst.instruction |= inst.operands[i].reg;
8166 if (shift == SHIFT_RRX)
8167 inst.instruction |= SHIFT_ROR << 4;
8168 else
8169 {
8170 constraint (inst.reloc.exp.X_op != O_constant,
8171 _("expression too complex"));
8172
8173 constraint (value > 32
8174 || (value == 32 && (shift == SHIFT_LSL
8175 || shift == SHIFT_ROR)),
8176 _("shift expression is too large"));
8177
8178 if (value == 0)
8179 shift = SHIFT_LSL;
8180 else if (value == 32)
8181 value = 0;
8182
8183 inst.instruction |= shift << 4;
8184 inst.instruction |= (value & 0x1c) << 10;
8185 inst.instruction |= (value & 0x03) << 6;
8186 }
8187 }
8188
8189
8190 /* inst.operands[i] was set up by parse_address. Encode it into a
8191 Thumb32 format load or store instruction. Reject forms that cannot
8192 be used with such instructions. If is_t is true, reject forms that
8193 cannot be used with a T instruction; if is_d is true, reject forms
8194 that cannot be used with a D instruction. */
8195
8196 static void
8197 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8198 {
8199 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8200
8201 constraint (!inst.operands[i].isreg,
8202 _("Instruction does not support =N addresses"));
8203
8204 inst.instruction |= inst.operands[i].reg << 16;
8205 if (inst.operands[i].immisreg)
8206 {
8207 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
8208 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8209 constraint (inst.operands[i].negative,
8210 _("Thumb does not support negative register indexing"));
8211 constraint (inst.operands[i].postind,
8212 _("Thumb does not support register post-indexing"));
8213 constraint (inst.operands[i].writeback,
8214 _("Thumb does not support register indexing with writeback"));
8215 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8216 _("Thumb supports only LSL in shifted register indexing"));
8217
8218 inst.instruction |= inst.operands[i].imm;
8219 if (inst.operands[i].shifted)
8220 {
8221 constraint (inst.reloc.exp.X_op != O_constant,
8222 _("expression too complex"));
8223 constraint (inst.reloc.exp.X_add_number < 0
8224 || inst.reloc.exp.X_add_number > 3,
8225 _("shift out of range"));
8226 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8227 }
8228 inst.reloc.type = BFD_RELOC_UNUSED;
8229 }
8230 else if (inst.operands[i].preind)
8231 {
8232 constraint (is_pc && inst.operands[i].writeback,
8233 _("cannot use writeback with PC-relative addressing"));
8234 constraint (is_t && inst.operands[i].writeback,
8235 _("cannot use writeback with this instruction"));
8236
8237 if (is_d)
8238 {
8239 inst.instruction |= 0x01000000;
8240 if (inst.operands[i].writeback)
8241 inst.instruction |= 0x00200000;
8242 }
8243 else
8244 {
8245 inst.instruction |= 0x00000c00;
8246 if (inst.operands[i].writeback)
8247 inst.instruction |= 0x00000100;
8248 }
8249 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8250 }
8251 else if (inst.operands[i].postind)
8252 {
8253 assert (inst.operands[i].writeback);
8254 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8255 constraint (is_t, _("cannot use post-indexing with this instruction"));
8256
8257 if (is_d)
8258 inst.instruction |= 0x00200000;
8259 else
8260 inst.instruction |= 0x00000900;
8261 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8262 }
8263 else /* unindexed - only for coprocessor */
8264 inst.error = _("instruction does not accept unindexed addressing");
8265 }
8266
8267 /* Table of Thumb instructions which exist in both 16- and 32-bit
8268 encodings (the latter only in post-V6T2 cores). The index is the
8269 value used in the insns table below. When there is more than one
8270 possible 16-bit encoding for the instruction, this table always
8271 holds variant (1).
8272 Also contains several pseudo-instructions used during relaxation. */
8273 #define T16_32_TAB \
8274 X(adc, 4140, eb400000), \
8275 X(adcs, 4140, eb500000), \
8276 X(add, 1c00, eb000000), \
8277 X(adds, 1c00, eb100000), \
8278 X(addi, 0000, f1000000), \
8279 X(addis, 0000, f1100000), \
8280 X(add_pc,000f, f20f0000), \
8281 X(add_sp,000d, f10d0000), \
8282 X(adr, 000f, f20f0000), \
8283 X(and, 4000, ea000000), \
8284 X(ands, 4000, ea100000), \
8285 X(asr, 1000, fa40f000), \
8286 X(asrs, 1000, fa50f000), \
8287 X(b, e000, f000b000), \
8288 X(bcond, d000, f0008000), \
8289 X(bic, 4380, ea200000), \
8290 X(bics, 4380, ea300000), \
8291 X(cmn, 42c0, eb100f00), \
8292 X(cmp, 2800, ebb00f00), \
8293 X(cpsie, b660, f3af8400), \
8294 X(cpsid, b670, f3af8600), \
8295 X(cpy, 4600, ea4f0000), \
8296 X(dec_sp,80dd, f1ad0d00), \
8297 X(eor, 4040, ea800000), \
8298 X(eors, 4040, ea900000), \
8299 X(inc_sp,00dd, f10d0d00), \
8300 X(ldmia, c800, e8900000), \
8301 X(ldr, 6800, f8500000), \
8302 X(ldrb, 7800, f8100000), \
8303 X(ldrh, 8800, f8300000), \
8304 X(ldrsb, 5600, f9100000), \
8305 X(ldrsh, 5e00, f9300000), \
8306 X(ldr_pc,4800, f85f0000), \
8307 X(ldr_pc2,4800, f85f0000), \
8308 X(ldr_sp,9800, f85d0000), \
8309 X(lsl, 0000, fa00f000), \
8310 X(lsls, 0000, fa10f000), \
8311 X(lsr, 0800, fa20f000), \
8312 X(lsrs, 0800, fa30f000), \
8313 X(mov, 2000, ea4f0000), \
8314 X(movs, 2000, ea5f0000), \
8315 X(mul, 4340, fb00f000), \
8316 X(muls, 4340, ffffffff), /* no 32b muls */ \
8317 X(mvn, 43c0, ea6f0000), \
8318 X(mvns, 43c0, ea7f0000), \
8319 X(neg, 4240, f1c00000), /* rsb #0 */ \
8320 X(negs, 4240, f1d00000), /* rsbs #0 */ \
8321 X(orr, 4300, ea400000), \
8322 X(orrs, 4300, ea500000), \
8323 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8324 X(push, b400, e92d0000), /* stmdb sp!,... */ \
8325 X(rev, ba00, fa90f080), \
8326 X(rev16, ba40, fa90f090), \
8327 X(revsh, bac0, fa90f0b0), \
8328 X(ror, 41c0, fa60f000), \
8329 X(rors, 41c0, fa70f000), \
8330 X(sbc, 4180, eb600000), \
8331 X(sbcs, 4180, eb700000), \
8332 X(stmia, c000, e8800000), \
8333 X(str, 6000, f8400000), \
8334 X(strb, 7000, f8000000), \
8335 X(strh, 8000, f8200000), \
8336 X(str_sp,9000, f84d0000), \
8337 X(sub, 1e00, eba00000), \
8338 X(subs, 1e00, ebb00000), \
8339 X(subi, 8000, f1a00000), \
8340 X(subis, 8000, f1b00000), \
8341 X(sxtb, b240, fa4ff080), \
8342 X(sxth, b200, fa0ff080), \
8343 X(tst, 4200, ea100f00), \
8344 X(uxtb, b2c0, fa5ff080), \
8345 X(uxth, b280, fa1ff080), \
8346 X(nop, bf00, f3af8000), \
8347 X(yield, bf10, f3af8001), \
8348 X(wfe, bf20, f3af8002), \
8349 X(wfi, bf30, f3af8003), \
8350 X(sev, bf40, f3af9004), /* typo, 8004? */
8351
8352 /* To catch errors in encoding functions, the codes are all offset by
8353 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8354 as 16-bit instructions. */
8355 #define X(a,b,c) T_MNEM_##a
8356 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8357 #undef X
8358
8359 #define X(a,b,c) 0x##b
8360 static const unsigned short thumb_op16[] = { T16_32_TAB };
8361 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8362 #undef X
8363
8364 #define X(a,b,c) 0x##c
8365 static const unsigned int thumb_op32[] = { T16_32_TAB };
8366 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8367 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
8368 #undef X
8369 #undef T16_32_TAB
8370
8371 /* Thumb instruction encoders, in alphabetical order. */
8372
8373 /* ADDW or SUBW. */
8374 static void
8375 do_t_add_sub_w (void)
8376 {
8377 int Rd, Rn;
8378
8379 Rd = inst.operands[0].reg;
8380 Rn = inst.operands[1].reg;
8381
8382 constraint (Rd == 15, _("PC not allowed as destination"));
8383 inst.instruction |= (Rn << 16) | (Rd << 8);
8384 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8385 }
8386
8387 /* Parse an add or subtract instruction. We get here with inst.instruction
8388 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8389
8390 static void
8391 do_t_add_sub (void)
8392 {
8393 int Rd, Rs, Rn;
8394
8395 Rd = inst.operands[0].reg;
8396 Rs = (inst.operands[1].present
8397 ? inst.operands[1].reg /* Rd, Rs, foo */
8398 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8399
8400 if (unified_syntax)
8401 {
8402 bfd_boolean flags;
8403 bfd_boolean narrow;
8404 int opcode;
8405
8406 flags = (inst.instruction == T_MNEM_adds
8407 || inst.instruction == T_MNEM_subs);
8408 if (flags)
8409 narrow = (current_it_mask == 0);
8410 else
8411 narrow = (current_it_mask != 0);
8412 if (!inst.operands[2].isreg)
8413 {
8414 int add;
8415
8416 add = (inst.instruction == T_MNEM_add
8417 || inst.instruction == T_MNEM_adds);
8418 opcode = 0;
8419 if (inst.size_req != 4)
8420 {
8421 /* Attempt to use a narrow opcode, with relaxation if
8422 appropriate. */
8423 if (Rd == REG_SP && Rs == REG_SP && !flags)
8424 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8425 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8426 opcode = T_MNEM_add_sp;
8427 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8428 opcode = T_MNEM_add_pc;
8429 else if (Rd <= 7 && Rs <= 7 && narrow)
8430 {
8431 if (flags)
8432 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8433 else
8434 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8435 }
8436 if (opcode)
8437 {
8438 inst.instruction = THUMB_OP16(opcode);
8439 inst.instruction |= (Rd << 4) | Rs;
8440 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8441 if (inst.size_req != 2)
8442 inst.relax = opcode;
8443 }
8444 else
8445 constraint (inst.size_req == 2, BAD_HIREG);
8446 }
8447 if (inst.size_req == 4
8448 || (inst.size_req != 2 && !opcode))
8449 {
8450 if (Rd == REG_PC)
8451 {
8452 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
8453 _("only SUBS PC, LR, #const allowed"));
8454 constraint (inst.reloc.exp.X_op != O_constant,
8455 _("expression too complex"));
8456 constraint (inst.reloc.exp.X_add_number < 0
8457 || inst.reloc.exp.X_add_number > 0xff,
8458 _("immediate value out of range"));
8459 inst.instruction = T2_SUBS_PC_LR
8460 | inst.reloc.exp.X_add_number;
8461 inst.reloc.type = BFD_RELOC_UNUSED;
8462 return;
8463 }
8464 else if (Rs == REG_PC)
8465 {
8466 /* Always use addw/subw. */
8467 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8468 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8469 }
8470 else
8471 {
8472 inst.instruction = THUMB_OP32 (inst.instruction);
8473 inst.instruction = (inst.instruction & 0xe1ffffff)
8474 | 0x10000000;
8475 if (flags)
8476 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8477 else
8478 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
8479 }
8480 inst.instruction |= Rd << 8;
8481 inst.instruction |= Rs << 16;
8482 }
8483 }
8484 else
8485 {
8486 Rn = inst.operands[2].reg;
8487 /* See if we can do this with a 16-bit instruction. */
8488 if (!inst.operands[2].shifted && inst.size_req != 4)
8489 {
8490 if (Rd > 7 || Rs > 7 || Rn > 7)
8491 narrow = FALSE;
8492
8493 if (narrow)
8494 {
8495 inst.instruction = ((inst.instruction == T_MNEM_adds
8496 || inst.instruction == T_MNEM_add)
8497 ? T_OPCODE_ADD_R3
8498 : T_OPCODE_SUB_R3);
8499 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8500 return;
8501 }
8502
8503 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
8504 {
8505 /* Thumb-1 cores (except v6-M) require at least one high
8506 register in a narrow non flag setting add. */
8507 if (Rd > 7 || Rn > 7
8508 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
8509 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
8510 {
8511 if (Rd == Rn)
8512 {
8513 Rn = Rs;
8514 Rs = Rd;
8515 }
8516 inst.instruction = T_OPCODE_ADD_HI;
8517 inst.instruction |= (Rd & 8) << 4;
8518 inst.instruction |= (Rd & 7);
8519 inst.instruction |= Rn << 3;
8520 return;
8521 }
8522 }
8523 }
8524 /* If we get here, it can't be done in 16 bits. */
8525 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
8526 _("shift must be constant"));
8527 inst.instruction = THUMB_OP32 (inst.instruction);
8528 inst.instruction |= Rd << 8;
8529 inst.instruction |= Rs << 16;
8530 encode_thumb32_shifted_operand (2);
8531 }
8532 }
8533 else
8534 {
8535 constraint (inst.instruction == T_MNEM_adds
8536 || inst.instruction == T_MNEM_subs,
8537 BAD_THUMB32);
8538
8539 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
8540 {
8541 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
8542 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
8543 BAD_HIREG);
8544
8545 inst.instruction = (inst.instruction == T_MNEM_add
8546 ? 0x0000 : 0x8000);
8547 inst.instruction |= (Rd << 4) | Rs;
8548 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8549 return;
8550 }
8551
8552 Rn = inst.operands[2].reg;
8553 constraint (inst.operands[2].shifted, _("unshifted register required"));
8554
8555 /* We now have Rd, Rs, and Rn set to registers. */
8556 if (Rd > 7 || Rs > 7 || Rn > 7)
8557 {
8558 /* Can't do this for SUB. */
8559 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
8560 inst.instruction = T_OPCODE_ADD_HI;
8561 inst.instruction |= (Rd & 8) << 4;
8562 inst.instruction |= (Rd & 7);
8563 if (Rs == Rd)
8564 inst.instruction |= Rn << 3;
8565 else if (Rn == Rd)
8566 inst.instruction |= Rs << 3;
8567 else
8568 constraint (1, _("dest must overlap one source register"));
8569 }
8570 else
8571 {
8572 inst.instruction = (inst.instruction == T_MNEM_add
8573 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
8574 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8575 }
8576 }
8577 }
8578
8579 static void
8580 do_t_adr (void)
8581 {
8582 if (unified_syntax && inst.size_req == 0 && inst.operands[0].reg <= 7)
8583 {
8584 /* Defer to section relaxation. */
8585 inst.relax = inst.instruction;
8586 inst.instruction = THUMB_OP16 (inst.instruction);
8587 inst.instruction |= inst.operands[0].reg << 4;
8588 }
8589 else if (unified_syntax && inst.size_req != 2)
8590 {
8591 /* Generate a 32-bit opcode. */
8592 inst.instruction = THUMB_OP32 (inst.instruction);
8593 inst.instruction |= inst.operands[0].reg << 8;
8594 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
8595 inst.reloc.pc_rel = 1;
8596 }
8597 else
8598 {
8599 /* Generate a 16-bit opcode. */
8600 inst.instruction = THUMB_OP16 (inst.instruction);
8601 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8602 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
8603 inst.reloc.pc_rel = 1;
8604
8605 inst.instruction |= inst.operands[0].reg << 4;
8606 }
8607 }
8608
8609 /* Arithmetic instructions for which there is just one 16-bit
8610 instruction encoding, and it allows only two low registers.
8611 For maximal compatibility with ARM syntax, we allow three register
8612 operands even when Thumb-32 instructions are not available, as long
8613 as the first two are identical. For instance, both "sbc r0,r1" and
8614 "sbc r0,r0,r1" are allowed. */
8615 static void
8616 do_t_arit3 (void)
8617 {
8618 int Rd, Rs, Rn;
8619
8620 Rd = inst.operands[0].reg;
8621 Rs = (inst.operands[1].present
8622 ? inst.operands[1].reg /* Rd, Rs, foo */
8623 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8624 Rn = inst.operands[2].reg;
8625
8626 if (unified_syntax)
8627 {
8628 if (!inst.operands[2].isreg)
8629 {
8630 /* For an immediate, we always generate a 32-bit opcode;
8631 section relaxation will shrink it later if possible. */
8632 inst.instruction = THUMB_OP32 (inst.instruction);
8633 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8634 inst.instruction |= Rd << 8;
8635 inst.instruction |= Rs << 16;
8636 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8637 }
8638 else
8639 {
8640 bfd_boolean narrow;
8641
8642 /* See if we can do this with a 16-bit instruction. */
8643 if (THUMB_SETS_FLAGS (inst.instruction))
8644 narrow = current_it_mask == 0;
8645 else
8646 narrow = current_it_mask != 0;
8647
8648 if (Rd > 7 || Rn > 7 || Rs > 7)
8649 narrow = FALSE;
8650 if (inst.operands[2].shifted)
8651 narrow = FALSE;
8652 if (inst.size_req == 4)
8653 narrow = FALSE;
8654
8655 if (narrow
8656 && Rd == Rs)
8657 {
8658 inst.instruction = THUMB_OP16 (inst.instruction);
8659 inst.instruction |= Rd;
8660 inst.instruction |= Rn << 3;
8661 return;
8662 }
8663
8664 /* If we get here, it can't be done in 16 bits. */
8665 constraint (inst.operands[2].shifted
8666 && inst.operands[2].immisreg,
8667 _("shift must be constant"));
8668 inst.instruction = THUMB_OP32 (inst.instruction);
8669 inst.instruction |= Rd << 8;
8670 inst.instruction |= Rs << 16;
8671 encode_thumb32_shifted_operand (2);
8672 }
8673 }
8674 else
8675 {
8676 /* On its face this is a lie - the instruction does set the
8677 flags. However, the only supported mnemonic in this mode
8678 says it doesn't. */
8679 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
8680
8681 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8682 _("unshifted register required"));
8683 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8684 constraint (Rd != Rs,
8685 _("dest and source1 must be the same register"));
8686
8687 inst.instruction = THUMB_OP16 (inst.instruction);
8688 inst.instruction |= Rd;
8689 inst.instruction |= Rn << 3;
8690 }
8691 }
8692
8693 /* Similarly, but for instructions where the arithmetic operation is
8694 commutative, so we can allow either of them to be different from
8695 the destination operand in a 16-bit instruction. For instance, all
8696 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
8697 accepted. */
8698 static void
8699 do_t_arit3c (void)
8700 {
8701 int Rd, Rs, Rn;
8702
8703 Rd = inst.operands[0].reg;
8704 Rs = (inst.operands[1].present
8705 ? inst.operands[1].reg /* Rd, Rs, foo */
8706 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8707 Rn = inst.operands[2].reg;
8708
8709 if (unified_syntax)
8710 {
8711 if (!inst.operands[2].isreg)
8712 {
8713 /* For an immediate, we always generate a 32-bit opcode;
8714 section relaxation will shrink it later if possible. */
8715 inst.instruction = THUMB_OP32 (inst.instruction);
8716 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8717 inst.instruction |= Rd << 8;
8718 inst.instruction |= Rs << 16;
8719 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8720 }
8721 else
8722 {
8723 bfd_boolean narrow;
8724
8725 /* See if we can do this with a 16-bit instruction. */
8726 if (THUMB_SETS_FLAGS (inst.instruction))
8727 narrow = current_it_mask == 0;
8728 else
8729 narrow = current_it_mask != 0;
8730
8731 if (Rd > 7 || Rn > 7 || Rs > 7)
8732 narrow = FALSE;
8733 if (inst.operands[2].shifted)
8734 narrow = FALSE;
8735 if (inst.size_req == 4)
8736 narrow = FALSE;
8737
8738 if (narrow)
8739 {
8740 if (Rd == Rs)
8741 {
8742 inst.instruction = THUMB_OP16 (inst.instruction);
8743 inst.instruction |= Rd;
8744 inst.instruction |= Rn << 3;
8745 return;
8746 }
8747 if (Rd == Rn)
8748 {
8749 inst.instruction = THUMB_OP16 (inst.instruction);
8750 inst.instruction |= Rd;
8751 inst.instruction |= Rs << 3;
8752 return;
8753 }
8754 }
8755
8756 /* If we get here, it can't be done in 16 bits. */
8757 constraint (inst.operands[2].shifted
8758 && inst.operands[2].immisreg,
8759 _("shift must be constant"));
8760 inst.instruction = THUMB_OP32 (inst.instruction);
8761 inst.instruction |= Rd << 8;
8762 inst.instruction |= Rs << 16;
8763 encode_thumb32_shifted_operand (2);
8764 }
8765 }
8766 else
8767 {
8768 /* On its face this is a lie - the instruction does set the
8769 flags. However, the only supported mnemonic in this mode
8770 says it doesn't. */
8771 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
8772
8773 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8774 _("unshifted register required"));
8775 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8776
8777 inst.instruction = THUMB_OP16 (inst.instruction);
8778 inst.instruction |= Rd;
8779
8780 if (Rd == Rs)
8781 inst.instruction |= Rn << 3;
8782 else if (Rd == Rn)
8783 inst.instruction |= Rs << 3;
8784 else
8785 constraint (1, _("dest must overlap one source register"));
8786 }
8787 }
8788
8789 static void
8790 do_t_barrier (void)
8791 {
8792 if (inst.operands[0].present)
8793 {
8794 constraint ((inst.instruction & 0xf0) != 0x40
8795 && inst.operands[0].imm != 0xf,
8796 _("bad barrier type"));
8797 inst.instruction |= inst.operands[0].imm;
8798 }
8799 else
8800 inst.instruction |= 0xf;
8801 }
8802
8803 static void
8804 do_t_bfc (void)
8805 {
8806 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8807 constraint (msb > 32, _("bit-field extends past end of register"));
8808 /* The instruction encoding stores the LSB and MSB,
8809 not the LSB and width. */
8810 inst.instruction |= inst.operands[0].reg << 8;
8811 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
8812 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
8813 inst.instruction |= msb - 1;
8814 }
8815
8816 static void
8817 do_t_bfi (void)
8818 {
8819 unsigned int msb;
8820
8821 /* #0 in second position is alternative syntax for bfc, which is
8822 the same instruction but with REG_PC in the Rm field. */
8823 if (!inst.operands[1].isreg)
8824 inst.operands[1].reg = REG_PC;
8825
8826 msb = inst.operands[2].imm + inst.operands[3].imm;
8827 constraint (msb > 32, _("bit-field extends past end of register"));
8828 /* The instruction encoding stores the LSB and MSB,
8829 not the LSB and width. */
8830 inst.instruction |= inst.operands[0].reg << 8;
8831 inst.instruction |= inst.operands[1].reg << 16;
8832 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8833 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8834 inst.instruction |= msb - 1;
8835 }
8836
8837 static void
8838 do_t_bfx (void)
8839 {
8840 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8841 _("bit-field extends past end of register"));
8842 inst.instruction |= inst.operands[0].reg << 8;
8843 inst.instruction |= inst.operands[1].reg << 16;
8844 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8845 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8846 inst.instruction |= inst.operands[3].imm - 1;
8847 }
8848
8849 /* ARM V5 Thumb BLX (argument parse)
8850 BLX <target_addr> which is BLX(1)
8851 BLX <Rm> which is BLX(2)
8852 Unfortunately, there are two different opcodes for this mnemonic.
8853 So, the insns[].value is not used, and the code here zaps values
8854 into inst.instruction.
8855
8856 ??? How to take advantage of the additional two bits of displacement
8857 available in Thumb32 mode? Need new relocation? */
8858
8859 static void
8860 do_t_blx (void)
8861 {
8862 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8863 if (inst.operands[0].isreg)
8864 /* We have a register, so this is BLX(2). */
8865 inst.instruction |= inst.operands[0].reg << 3;
8866 else
8867 {
8868 /* No register. This must be BLX(1). */
8869 inst.instruction = 0xf000e800;
8870 #ifdef OBJ_ELF
8871 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8872 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
8873 else
8874 #endif
8875 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
8876 inst.reloc.pc_rel = 1;
8877 }
8878 }
8879
8880 static void
8881 do_t_branch (void)
8882 {
8883 int opcode;
8884 int cond;
8885
8886 if (current_it_mask)
8887 {
8888 /* Conditional branches inside IT blocks are encoded as unconditional
8889 branches. */
8890 cond = COND_ALWAYS;
8891 /* A branch must be the last instruction in an IT block. */
8892 constraint (current_it_mask != 0x10, BAD_BRANCH);
8893 }
8894 else
8895 cond = inst.cond;
8896
8897 if (cond != COND_ALWAYS)
8898 opcode = T_MNEM_bcond;
8899 else
8900 opcode = inst.instruction;
8901
8902 if (unified_syntax && inst.size_req == 4)
8903 {
8904 inst.instruction = THUMB_OP32(opcode);
8905 if (cond == COND_ALWAYS)
8906 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
8907 else
8908 {
8909 assert (cond != 0xF);
8910 inst.instruction |= cond << 22;
8911 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
8912 }
8913 }
8914 else
8915 {
8916 inst.instruction = THUMB_OP16(opcode);
8917 if (cond == COND_ALWAYS)
8918 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
8919 else
8920 {
8921 inst.instruction |= cond << 8;
8922 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
8923 }
8924 /* Allow section relaxation. */
8925 if (unified_syntax && inst.size_req != 2)
8926 inst.relax = opcode;
8927 }
8928
8929 inst.reloc.pc_rel = 1;
8930 }
8931
8932 static void
8933 do_t_bkpt (void)
8934 {
8935 constraint (inst.cond != COND_ALWAYS,
8936 _("instruction is always unconditional"));
8937 if (inst.operands[0].present)
8938 {
8939 constraint (inst.operands[0].imm > 255,
8940 _("immediate value out of range"));
8941 inst.instruction |= inst.operands[0].imm;
8942 }
8943 }
8944
8945 static void
8946 do_t_branch23 (void)
8947 {
8948 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8949 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
8950 inst.reloc.pc_rel = 1;
8951
8952 /* If the destination of the branch is a defined symbol which does not have
8953 the THUMB_FUNC attribute, then we must be calling a function which has
8954 the (interfacearm) attribute. We look for the Thumb entry point to that
8955 function and change the branch to refer to that function instead. */
8956 if ( inst.reloc.exp.X_op == O_symbol
8957 && inst.reloc.exp.X_add_symbol != NULL
8958 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8959 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8960 inst.reloc.exp.X_add_symbol =
8961 find_real_start (inst.reloc.exp.X_add_symbol);
8962 }
8963
8964 static void
8965 do_t_bx (void)
8966 {
8967 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8968 inst.instruction |= inst.operands[0].reg << 3;
8969 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
8970 should cause the alignment to be checked once it is known. This is
8971 because BX PC only works if the instruction is word aligned. */
8972 }
8973
8974 static void
8975 do_t_bxj (void)
8976 {
8977 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8978 if (inst.operands[0].reg == REG_PC)
8979 as_tsktsk (_("use of r15 in bxj is not really useful"));
8980
8981 inst.instruction |= inst.operands[0].reg << 16;
8982 }
8983
8984 static void
8985 do_t_clz (void)
8986 {
8987 inst.instruction |= inst.operands[0].reg << 8;
8988 inst.instruction |= inst.operands[1].reg << 16;
8989 inst.instruction |= inst.operands[1].reg;
8990 }
8991
8992 static void
8993 do_t_cps (void)
8994 {
8995 constraint (current_it_mask, BAD_NOT_IT);
8996 inst.instruction |= inst.operands[0].imm;
8997 }
8998
8999 static void
9000 do_t_cpsi (void)
9001 {
9002 constraint (current_it_mask, BAD_NOT_IT);
9003 if (unified_syntax
9004 && (inst.operands[1].present || inst.size_req == 4)
9005 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
9006 {
9007 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9008 inst.instruction = 0xf3af8000;
9009 inst.instruction |= imod << 9;
9010 inst.instruction |= inst.operands[0].imm << 5;
9011 if (inst.operands[1].present)
9012 inst.instruction |= 0x100 | inst.operands[1].imm;
9013 }
9014 else
9015 {
9016 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9017 && (inst.operands[0].imm & 4),
9018 _("selected processor does not support 'A' form "
9019 "of this instruction"));
9020 constraint (inst.operands[1].present || inst.size_req == 4,
9021 _("Thumb does not support the 2-argument "
9022 "form of this instruction"));
9023 inst.instruction |= inst.operands[0].imm;
9024 }
9025 }
9026
9027 /* THUMB CPY instruction (argument parse). */
9028
9029 static void
9030 do_t_cpy (void)
9031 {
9032 if (inst.size_req == 4)
9033 {
9034 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9035 inst.instruction |= inst.operands[0].reg << 8;
9036 inst.instruction |= inst.operands[1].reg;
9037 }
9038 else
9039 {
9040 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9041 inst.instruction |= (inst.operands[0].reg & 0x7);
9042 inst.instruction |= inst.operands[1].reg << 3;
9043 }
9044 }
9045
9046 static void
9047 do_t_cbz (void)
9048 {
9049 constraint (current_it_mask, BAD_NOT_IT);
9050 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9051 inst.instruction |= inst.operands[0].reg;
9052 inst.reloc.pc_rel = 1;
9053 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9054 }
9055
9056 static void
9057 do_t_dbg (void)
9058 {
9059 inst.instruction |= inst.operands[0].imm;
9060 }
9061
9062 static void
9063 do_t_div (void)
9064 {
9065 if (!inst.operands[1].present)
9066 inst.operands[1].reg = inst.operands[0].reg;
9067 inst.instruction |= inst.operands[0].reg << 8;
9068 inst.instruction |= inst.operands[1].reg << 16;
9069 inst.instruction |= inst.operands[2].reg;
9070 }
9071
9072 static void
9073 do_t_hint (void)
9074 {
9075 if (unified_syntax && inst.size_req == 4)
9076 inst.instruction = THUMB_OP32 (inst.instruction);
9077 else
9078 inst.instruction = THUMB_OP16 (inst.instruction);
9079 }
9080
9081 static void
9082 do_t_it (void)
9083 {
9084 unsigned int cond = inst.operands[0].imm;
9085
9086 constraint (current_it_mask, BAD_NOT_IT);
9087 current_it_mask = (inst.instruction & 0xf) | 0x10;
9088 current_cc = cond;
9089
9090 /* If the condition is a negative condition, invert the mask. */
9091 if ((cond & 0x1) == 0x0)
9092 {
9093 unsigned int mask = inst.instruction & 0x000f;
9094
9095 if ((mask & 0x7) == 0)
9096 /* no conversion needed */;
9097 else if ((mask & 0x3) == 0)
9098 mask ^= 0x8;
9099 else if ((mask & 0x1) == 0)
9100 mask ^= 0xC;
9101 else
9102 mask ^= 0xE;
9103
9104 inst.instruction &= 0xfff0;
9105 inst.instruction |= mask;
9106 }
9107
9108 inst.instruction |= cond << 4;
9109 }
9110
9111 /* Helper function used for both push/pop and ldm/stm. */
9112 static void
9113 encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9114 {
9115 bfd_boolean load;
9116
9117 load = (inst.instruction & (1 << 20)) != 0;
9118
9119 if (mask & (1 << 13))
9120 inst.error = _("SP not allowed in register list");
9121 if (load)
9122 {
9123 if (mask & (1 << 14)
9124 && mask & (1 << 15))
9125 inst.error = _("LR and PC should not both be in register list");
9126
9127 if ((mask & (1 << base)) != 0
9128 && writeback)
9129 as_warn (_("base register should not be in register list "
9130 "when written back"));
9131 }
9132 else
9133 {
9134 if (mask & (1 << 15))
9135 inst.error = _("PC not allowed in register list");
9136
9137 if (mask & (1 << base))
9138 as_warn (_("value stored for r%d is UNPREDICTABLE"), base);
9139 }
9140
9141 if ((mask & (mask - 1)) == 0)
9142 {
9143 /* Single register transfers implemented as str/ldr. */
9144 if (writeback)
9145 {
9146 if (inst.instruction & (1 << 23))
9147 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9148 else
9149 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9150 }
9151 else
9152 {
9153 if (inst.instruction & (1 << 23))
9154 inst.instruction = 0x00800000; /* ia -> [base] */
9155 else
9156 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9157 }
9158
9159 inst.instruction |= 0xf8400000;
9160 if (load)
9161 inst.instruction |= 0x00100000;
9162
9163 mask = ffs (mask) - 1;
9164 mask <<= 12;
9165 }
9166 else if (writeback)
9167 inst.instruction |= WRITE_BACK;
9168
9169 inst.instruction |= mask;
9170 inst.instruction |= base << 16;
9171 }
9172
9173 static void
9174 do_t_ldmstm (void)
9175 {
9176 /* This really doesn't seem worth it. */
9177 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9178 _("expression too complex"));
9179 constraint (inst.operands[1].writeback,
9180 _("Thumb load/store multiple does not support {reglist}^"));
9181
9182 if (unified_syntax)
9183 {
9184 bfd_boolean narrow;
9185 unsigned mask;
9186
9187 narrow = FALSE;
9188 /* See if we can use a 16-bit instruction. */
9189 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9190 && inst.size_req != 4
9191 && !(inst.operands[1].imm & ~0xff))
9192 {
9193 mask = 1 << inst.operands[0].reg;
9194
9195 if (inst.operands[0].reg <= 7
9196 && (inst.instruction == T_MNEM_stmia
9197 ? inst.operands[0].writeback
9198 : (inst.operands[0].writeback
9199 == !(inst.operands[1].imm & mask))))
9200 {
9201 if (inst.instruction == T_MNEM_stmia
9202 && (inst.operands[1].imm & mask)
9203 && (inst.operands[1].imm & (mask - 1)))
9204 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9205 inst.operands[0].reg);
9206
9207 inst.instruction = THUMB_OP16 (inst.instruction);
9208 inst.instruction |= inst.operands[0].reg << 8;
9209 inst.instruction |= inst.operands[1].imm;
9210 narrow = TRUE;
9211 }
9212 else if (inst.operands[0] .reg == REG_SP
9213 && inst.operands[0].writeback)
9214 {
9215 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9216 ? T_MNEM_push : T_MNEM_pop);
9217 inst.instruction |= inst.operands[1].imm;
9218 narrow = TRUE;
9219 }
9220 }
9221
9222 if (!narrow)
9223 {
9224 if (inst.instruction < 0xffff)
9225 inst.instruction = THUMB_OP32 (inst.instruction);
9226
9227 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
9228 inst.operands[0].writeback);
9229 }
9230 }
9231 else
9232 {
9233 constraint (inst.operands[0].reg > 7
9234 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
9235 constraint (inst.instruction != T_MNEM_ldmia
9236 && inst.instruction != T_MNEM_stmia,
9237 _("Thumb-2 instruction only valid in unified syntax"));
9238 if (inst.instruction == T_MNEM_stmia)
9239 {
9240 if (!inst.operands[0].writeback)
9241 as_warn (_("this instruction will write back the base register"));
9242 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9243 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9244 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9245 inst.operands[0].reg);
9246 }
9247 else
9248 {
9249 if (!inst.operands[0].writeback
9250 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9251 as_warn (_("this instruction will write back the base register"));
9252 else if (inst.operands[0].writeback
9253 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9254 as_warn (_("this instruction will not write back the base register"));
9255 }
9256
9257 inst.instruction = THUMB_OP16 (inst.instruction);
9258 inst.instruction |= inst.operands[0].reg << 8;
9259 inst.instruction |= inst.operands[1].imm;
9260 }
9261 }
9262
9263 static void
9264 do_t_ldrex (void)
9265 {
9266 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9267 || inst.operands[1].postind || inst.operands[1].writeback
9268 || inst.operands[1].immisreg || inst.operands[1].shifted
9269 || inst.operands[1].negative,
9270 BAD_ADDR_MODE);
9271
9272 inst.instruction |= inst.operands[0].reg << 12;
9273 inst.instruction |= inst.operands[1].reg << 16;
9274 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9275 }
9276
9277 static void
9278 do_t_ldrexd (void)
9279 {
9280 if (!inst.operands[1].present)
9281 {
9282 constraint (inst.operands[0].reg == REG_LR,
9283 _("r14 not allowed as first register "
9284 "when second register is omitted"));
9285 inst.operands[1].reg = inst.operands[0].reg + 1;
9286 }
9287 constraint (inst.operands[0].reg == inst.operands[1].reg,
9288 BAD_OVERLAP);
9289
9290 inst.instruction |= inst.operands[0].reg << 12;
9291 inst.instruction |= inst.operands[1].reg << 8;
9292 inst.instruction |= inst.operands[2].reg << 16;
9293 }
9294
9295 static void
9296 do_t_ldst (void)
9297 {
9298 unsigned long opcode;
9299 int Rn;
9300
9301 opcode = inst.instruction;
9302 if (unified_syntax)
9303 {
9304 if (!inst.operands[1].isreg)
9305 {
9306 if (opcode <= 0xffff)
9307 inst.instruction = THUMB_OP32 (opcode);
9308 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9309 return;
9310 }
9311 if (inst.operands[1].isreg
9312 && !inst.operands[1].writeback
9313 && !inst.operands[1].shifted && !inst.operands[1].postind
9314 && !inst.operands[1].negative && inst.operands[0].reg <= 7
9315 && opcode <= 0xffff
9316 && inst.size_req != 4)
9317 {
9318 /* Insn may have a 16-bit form. */
9319 Rn = inst.operands[1].reg;
9320 if (inst.operands[1].immisreg)
9321 {
9322 inst.instruction = THUMB_OP16 (opcode);
9323 /* [Rn, Rik] */
9324 if (Rn <= 7 && inst.operands[1].imm <= 7)
9325 goto op16;
9326 }
9327 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9328 && opcode != T_MNEM_ldrsb)
9329 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9330 || (Rn == REG_SP && opcode == T_MNEM_str))
9331 {
9332 /* [Rn, #const] */
9333 if (Rn > 7)
9334 {
9335 if (Rn == REG_PC)
9336 {
9337 if (inst.reloc.pc_rel)
9338 opcode = T_MNEM_ldr_pc2;
9339 else
9340 opcode = T_MNEM_ldr_pc;
9341 }
9342 else
9343 {
9344 if (opcode == T_MNEM_ldr)
9345 opcode = T_MNEM_ldr_sp;
9346 else
9347 opcode = T_MNEM_str_sp;
9348 }
9349 inst.instruction = inst.operands[0].reg << 8;
9350 }
9351 else
9352 {
9353 inst.instruction = inst.operands[0].reg;
9354 inst.instruction |= inst.operands[1].reg << 3;
9355 }
9356 inst.instruction |= THUMB_OP16 (opcode);
9357 if (inst.size_req == 2)
9358 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9359 else
9360 inst.relax = opcode;
9361 return;
9362 }
9363 }
9364 /* Definitely a 32-bit variant. */
9365 inst.instruction = THUMB_OP32 (opcode);
9366 inst.instruction |= inst.operands[0].reg << 12;
9367 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
9368 return;
9369 }
9370
9371 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9372
9373 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
9374 {
9375 /* Only [Rn,Rm] is acceptable. */
9376 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
9377 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
9378 || inst.operands[1].postind || inst.operands[1].shifted
9379 || inst.operands[1].negative,
9380 _("Thumb does not support this addressing mode"));
9381 inst.instruction = THUMB_OP16 (inst.instruction);
9382 goto op16;
9383 }
9384
9385 inst.instruction = THUMB_OP16 (inst.instruction);
9386 if (!inst.operands[1].isreg)
9387 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9388 return;
9389
9390 constraint (!inst.operands[1].preind
9391 || inst.operands[1].shifted
9392 || inst.operands[1].writeback,
9393 _("Thumb does not support this addressing mode"));
9394 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
9395 {
9396 constraint (inst.instruction & 0x0600,
9397 _("byte or halfword not valid for base register"));
9398 constraint (inst.operands[1].reg == REG_PC
9399 && !(inst.instruction & THUMB_LOAD_BIT),
9400 _("r15 based store not allowed"));
9401 constraint (inst.operands[1].immisreg,
9402 _("invalid base register for register offset"));
9403
9404 if (inst.operands[1].reg == REG_PC)
9405 inst.instruction = T_OPCODE_LDR_PC;
9406 else if (inst.instruction & THUMB_LOAD_BIT)
9407 inst.instruction = T_OPCODE_LDR_SP;
9408 else
9409 inst.instruction = T_OPCODE_STR_SP;
9410
9411 inst.instruction |= inst.operands[0].reg << 8;
9412 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9413 return;
9414 }
9415
9416 constraint (inst.operands[1].reg > 7, BAD_HIREG);
9417 if (!inst.operands[1].immisreg)
9418 {
9419 /* Immediate offset. */
9420 inst.instruction |= inst.operands[0].reg;
9421 inst.instruction |= inst.operands[1].reg << 3;
9422 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9423 return;
9424 }
9425
9426 /* Register offset. */
9427 constraint (inst.operands[1].imm > 7, BAD_HIREG);
9428 constraint (inst.operands[1].negative,
9429 _("Thumb does not support this addressing mode"));
9430
9431 op16:
9432 switch (inst.instruction)
9433 {
9434 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
9435 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
9436 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
9437 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
9438 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
9439 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
9440 case 0x5600 /* ldrsb */:
9441 case 0x5e00 /* ldrsh */: break;
9442 default: abort ();
9443 }
9444
9445 inst.instruction |= inst.operands[0].reg;
9446 inst.instruction |= inst.operands[1].reg << 3;
9447 inst.instruction |= inst.operands[1].imm << 6;
9448 }
9449
9450 static void
9451 do_t_ldstd (void)
9452 {
9453 if (!inst.operands[1].present)
9454 {
9455 inst.operands[1].reg = inst.operands[0].reg + 1;
9456 constraint (inst.operands[0].reg == REG_LR,
9457 _("r14 not allowed here"));
9458 }
9459 inst.instruction |= inst.operands[0].reg << 12;
9460 inst.instruction |= inst.operands[1].reg << 8;
9461 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
9462 }
9463
9464 static void
9465 do_t_ldstt (void)
9466 {
9467 inst.instruction |= inst.operands[0].reg << 12;
9468 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
9469 }
9470
9471 static void
9472 do_t_mla (void)
9473 {
9474 inst.instruction |= inst.operands[0].reg << 8;
9475 inst.instruction |= inst.operands[1].reg << 16;
9476 inst.instruction |= inst.operands[2].reg;
9477 inst.instruction |= inst.operands[3].reg << 12;
9478 }
9479
9480 static void
9481 do_t_mlal (void)
9482 {
9483 inst.instruction |= inst.operands[0].reg << 12;
9484 inst.instruction |= inst.operands[1].reg << 8;
9485 inst.instruction |= inst.operands[2].reg << 16;
9486 inst.instruction |= inst.operands[3].reg;
9487 }
9488
9489 static void
9490 do_t_mov_cmp (void)
9491 {
9492 if (unified_syntax)
9493 {
9494 int r0off = (inst.instruction == T_MNEM_mov
9495 || inst.instruction == T_MNEM_movs) ? 8 : 16;
9496 unsigned long opcode;
9497 bfd_boolean narrow;
9498 bfd_boolean low_regs;
9499
9500 low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7);
9501 opcode = inst.instruction;
9502 if (current_it_mask)
9503 narrow = opcode != T_MNEM_movs;
9504 else
9505 narrow = opcode != T_MNEM_movs || low_regs;
9506 if (inst.size_req == 4
9507 || inst.operands[1].shifted)
9508 narrow = FALSE;
9509
9510 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
9511 if (opcode == T_MNEM_movs && inst.operands[1].isreg
9512 && !inst.operands[1].shifted
9513 && inst.operands[0].reg == REG_PC
9514 && inst.operands[1].reg == REG_LR)
9515 {
9516 inst.instruction = T2_SUBS_PC_LR;
9517 return;
9518 }
9519
9520 if (!inst.operands[1].isreg)
9521 {
9522 /* Immediate operand. */
9523 if (current_it_mask == 0 && opcode == T_MNEM_mov)
9524 narrow = 0;
9525 if (low_regs && narrow)
9526 {
9527 inst.instruction = THUMB_OP16 (opcode);
9528 inst.instruction |= inst.operands[0].reg << 8;
9529 if (inst.size_req == 2)
9530 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9531 else
9532 inst.relax = opcode;
9533 }
9534 else
9535 {
9536 inst.instruction = THUMB_OP32 (inst.instruction);
9537 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9538 inst.instruction |= inst.operands[0].reg << r0off;
9539 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9540 }
9541 }
9542 else if (inst.operands[1].shifted && inst.operands[1].immisreg
9543 && (inst.instruction == T_MNEM_mov
9544 || inst.instruction == T_MNEM_movs))
9545 {
9546 /* Register shifts are encoded as separate shift instructions. */
9547 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
9548
9549 if (current_it_mask)
9550 narrow = !flags;
9551 else
9552 narrow = flags;
9553
9554 if (inst.size_req == 4)
9555 narrow = FALSE;
9556
9557 if (!low_regs || inst.operands[1].imm > 7)
9558 narrow = FALSE;
9559
9560 if (inst.operands[0].reg != inst.operands[1].reg)
9561 narrow = FALSE;
9562
9563 switch (inst.operands[1].shift_kind)
9564 {
9565 case SHIFT_LSL:
9566 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
9567 break;
9568 case SHIFT_ASR:
9569 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
9570 break;
9571 case SHIFT_LSR:
9572 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
9573 break;
9574 case SHIFT_ROR:
9575 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
9576 break;
9577 default:
9578 abort ();
9579 }
9580
9581 inst.instruction = opcode;
9582 if (narrow)
9583 {
9584 inst.instruction |= inst.operands[0].reg;
9585 inst.instruction |= inst.operands[1].imm << 3;
9586 }
9587 else
9588 {
9589 if (flags)
9590 inst.instruction |= CONDS_BIT;
9591
9592 inst.instruction |= inst.operands[0].reg << 8;
9593 inst.instruction |= inst.operands[1].reg << 16;
9594 inst.instruction |= inst.operands[1].imm;
9595 }
9596 }
9597 else if (!narrow)
9598 {
9599 /* Some mov with immediate shift have narrow variants.
9600 Register shifts are handled above. */
9601 if (low_regs && inst.operands[1].shifted
9602 && (inst.instruction == T_MNEM_mov
9603 || inst.instruction == T_MNEM_movs))
9604 {
9605 if (current_it_mask)
9606 narrow = (inst.instruction == T_MNEM_mov);
9607 else
9608 narrow = (inst.instruction == T_MNEM_movs);
9609 }
9610
9611 if (narrow)
9612 {
9613 switch (inst.operands[1].shift_kind)
9614 {
9615 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
9616 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
9617 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
9618 default: narrow = FALSE; break;
9619 }
9620 }
9621
9622 if (narrow)
9623 {
9624 inst.instruction |= inst.operands[0].reg;
9625 inst.instruction |= inst.operands[1].reg << 3;
9626 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
9627 }
9628 else
9629 {
9630 inst.instruction = THUMB_OP32 (inst.instruction);
9631 inst.instruction |= inst.operands[0].reg << r0off;
9632 encode_thumb32_shifted_operand (1);
9633 }
9634 }
9635 else
9636 switch (inst.instruction)
9637 {
9638 case T_MNEM_mov:
9639 inst.instruction = T_OPCODE_MOV_HR;
9640 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9641 inst.instruction |= (inst.operands[0].reg & 0x7);
9642 inst.instruction |= inst.operands[1].reg << 3;
9643 break;
9644
9645 case T_MNEM_movs:
9646 /* We know we have low registers at this point.
9647 Generate ADD Rd, Rs, #0. */
9648 inst.instruction = T_OPCODE_ADD_I3;
9649 inst.instruction |= inst.operands[0].reg;
9650 inst.instruction |= inst.operands[1].reg << 3;
9651 break;
9652
9653 case T_MNEM_cmp:
9654 if (low_regs)
9655 {
9656 inst.instruction = T_OPCODE_CMP_LR;
9657 inst.instruction |= inst.operands[0].reg;
9658 inst.instruction |= inst.operands[1].reg << 3;
9659 }
9660 else
9661 {
9662 inst.instruction = T_OPCODE_CMP_HR;
9663 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9664 inst.instruction |= (inst.operands[0].reg & 0x7);
9665 inst.instruction |= inst.operands[1].reg << 3;
9666 }
9667 break;
9668 }
9669 return;
9670 }
9671
9672 inst.instruction = THUMB_OP16 (inst.instruction);
9673 if (inst.operands[1].isreg)
9674 {
9675 if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8)
9676 {
9677 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
9678 since a MOV instruction produces unpredictable results. */
9679 if (inst.instruction == T_OPCODE_MOV_I8)
9680 inst.instruction = T_OPCODE_ADD_I3;
9681 else
9682 inst.instruction = T_OPCODE_CMP_LR;
9683
9684 inst.instruction |= inst.operands[0].reg;
9685 inst.instruction |= inst.operands[1].reg << 3;
9686 }
9687 else
9688 {
9689 if (inst.instruction == T_OPCODE_MOV_I8)
9690 inst.instruction = T_OPCODE_MOV_HR;
9691 else
9692 inst.instruction = T_OPCODE_CMP_HR;
9693 do_t_cpy ();
9694 }
9695 }
9696 else
9697 {
9698 constraint (inst.operands[0].reg > 7,
9699 _("only lo regs allowed with immediate"));
9700 inst.instruction |= inst.operands[0].reg << 8;
9701 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9702 }
9703 }
9704
9705 static void
9706 do_t_mov16 (void)
9707 {
9708 bfd_vma imm;
9709 bfd_boolean top;
9710
9711 top = (inst.instruction & 0x00800000) != 0;
9712 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
9713 {
9714 constraint (top, _(":lower16: not allowed this instruction"));
9715 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
9716 }
9717 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
9718 {
9719 constraint (!top, _(":upper16: not allowed this instruction"));
9720 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
9721 }
9722
9723 inst.instruction |= inst.operands[0].reg << 8;
9724 if (inst.reloc.type == BFD_RELOC_UNUSED)
9725 {
9726 imm = inst.reloc.exp.X_add_number;
9727 inst.instruction |= (imm & 0xf000) << 4;
9728 inst.instruction |= (imm & 0x0800) << 15;
9729 inst.instruction |= (imm & 0x0700) << 4;
9730 inst.instruction |= (imm & 0x00ff);
9731 }
9732 }
9733
9734 static void
9735 do_t_mvn_tst (void)
9736 {
9737 if (unified_syntax)
9738 {
9739 int r0off = (inst.instruction == T_MNEM_mvn
9740 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
9741 bfd_boolean narrow;
9742
9743 if (inst.size_req == 4
9744 || inst.instruction > 0xffff
9745 || inst.operands[1].shifted
9746 || inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9747 narrow = FALSE;
9748 else if (inst.instruction == T_MNEM_cmn)
9749 narrow = TRUE;
9750 else if (THUMB_SETS_FLAGS (inst.instruction))
9751 narrow = (current_it_mask == 0);
9752 else
9753 narrow = (current_it_mask != 0);
9754
9755 if (!inst.operands[1].isreg)
9756 {
9757 /* For an immediate, we always generate a 32-bit opcode;
9758 section relaxation will shrink it later if possible. */
9759 if (inst.instruction < 0xffff)
9760 inst.instruction = THUMB_OP32 (inst.instruction);
9761 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9762 inst.instruction |= inst.operands[0].reg << r0off;
9763 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9764 }
9765 else
9766 {
9767 /* See if we can do this with a 16-bit instruction. */
9768 if (narrow)
9769 {
9770 inst.instruction = THUMB_OP16 (inst.instruction);
9771 inst.instruction |= inst.operands[0].reg;
9772 inst.instruction |= inst.operands[1].reg << 3;
9773 }
9774 else
9775 {
9776 constraint (inst.operands[1].shifted
9777 && inst.operands[1].immisreg,
9778 _("shift must be constant"));
9779 if (inst.instruction < 0xffff)
9780 inst.instruction = THUMB_OP32 (inst.instruction);
9781 inst.instruction |= inst.operands[0].reg << r0off;
9782 encode_thumb32_shifted_operand (1);
9783 }
9784 }
9785 }
9786 else
9787 {
9788 constraint (inst.instruction > 0xffff
9789 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
9790 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
9791 _("unshifted register required"));
9792 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9793 BAD_HIREG);
9794
9795 inst.instruction = THUMB_OP16 (inst.instruction);
9796 inst.instruction |= inst.operands[0].reg;
9797 inst.instruction |= inst.operands[1].reg << 3;
9798 }
9799 }
9800
9801 static void
9802 do_t_mrs (void)
9803 {
9804 int flags;
9805
9806 if (do_vfp_nsyn_mrs () == SUCCESS)
9807 return;
9808
9809 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
9810 if (flags == 0)
9811 {
9812 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
9813 _("selected processor does not support "
9814 "requested special purpose register"));
9815 }
9816 else
9817 {
9818 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9819 _("selected processor does not support "
9820 "requested special purpose register %x"));
9821 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9822 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
9823 _("'CPSR' or 'SPSR' expected"));
9824 }
9825
9826 inst.instruction |= inst.operands[0].reg << 8;
9827 inst.instruction |= (flags & SPSR_BIT) >> 2;
9828 inst.instruction |= inst.operands[1].imm & 0xff;
9829 }
9830
9831 static void
9832 do_t_msr (void)
9833 {
9834 int flags;
9835
9836 if (do_vfp_nsyn_msr () == SUCCESS)
9837 return;
9838
9839 constraint (!inst.operands[1].isreg,
9840 _("Thumb encoding does not support an immediate here"));
9841 flags = inst.operands[0].imm;
9842 if (flags & ~0xff)
9843 {
9844 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9845 _("selected processor does not support "
9846 "requested special purpose register"));
9847 }
9848 else
9849 {
9850 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
9851 _("selected processor does not support "
9852 "requested special purpose register"));
9853 flags |= PSR_f;
9854 }
9855 inst.instruction |= (flags & SPSR_BIT) >> 2;
9856 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
9857 inst.instruction |= (flags & 0xff);
9858 inst.instruction |= inst.operands[1].reg << 16;
9859 }
9860
9861 static void
9862 do_t_mul (void)
9863 {
9864 if (!inst.operands[2].present)
9865 inst.operands[2].reg = inst.operands[0].reg;
9866
9867 /* There is no 32-bit MULS and no 16-bit MUL. */
9868 if (unified_syntax && inst.instruction == T_MNEM_mul)
9869 {
9870 inst.instruction = THUMB_OP32 (inst.instruction);
9871 inst.instruction |= inst.operands[0].reg << 8;
9872 inst.instruction |= inst.operands[1].reg << 16;
9873 inst.instruction |= inst.operands[2].reg << 0;
9874 }
9875 else
9876 {
9877 constraint (!unified_syntax
9878 && inst.instruction == T_MNEM_muls, BAD_THUMB32);
9879 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9880 BAD_HIREG);
9881
9882 inst.instruction = THUMB_OP16 (inst.instruction);
9883 inst.instruction |= inst.operands[0].reg;
9884
9885 if (inst.operands[0].reg == inst.operands[1].reg)
9886 inst.instruction |= inst.operands[2].reg << 3;
9887 else if (inst.operands[0].reg == inst.operands[2].reg)
9888 inst.instruction |= inst.operands[1].reg << 3;
9889 else
9890 constraint (1, _("dest must overlap one source register"));
9891 }
9892 }
9893
9894 static void
9895 do_t_mull (void)
9896 {
9897 inst.instruction |= inst.operands[0].reg << 12;
9898 inst.instruction |= inst.operands[1].reg << 8;
9899 inst.instruction |= inst.operands[2].reg << 16;
9900 inst.instruction |= inst.operands[3].reg;
9901
9902 if (inst.operands[0].reg == inst.operands[1].reg)
9903 as_tsktsk (_("rdhi and rdlo must be different"));
9904 }
9905
9906 static void
9907 do_t_nop (void)
9908 {
9909 if (unified_syntax)
9910 {
9911 if (inst.size_req == 4 || inst.operands[0].imm > 15)
9912 {
9913 inst.instruction = THUMB_OP32 (inst.instruction);
9914 inst.instruction |= inst.operands[0].imm;
9915 }
9916 else
9917 {
9918 inst.instruction = THUMB_OP16 (inst.instruction);
9919 inst.instruction |= inst.operands[0].imm << 4;
9920 }
9921 }
9922 else
9923 {
9924 constraint (inst.operands[0].present,
9925 _("Thumb does not support NOP with hints"));
9926 inst.instruction = 0x46c0;
9927 }
9928 }
9929
9930 static void
9931 do_t_neg (void)
9932 {
9933 if (unified_syntax)
9934 {
9935 bfd_boolean narrow;
9936
9937 if (THUMB_SETS_FLAGS (inst.instruction))
9938 narrow = (current_it_mask == 0);
9939 else
9940 narrow = (current_it_mask != 0);
9941 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9942 narrow = FALSE;
9943 if (inst.size_req == 4)
9944 narrow = FALSE;
9945
9946 if (!narrow)
9947 {
9948 inst.instruction = THUMB_OP32 (inst.instruction);
9949 inst.instruction |= inst.operands[0].reg << 8;
9950 inst.instruction |= inst.operands[1].reg << 16;
9951 }
9952 else
9953 {
9954 inst.instruction = THUMB_OP16 (inst.instruction);
9955 inst.instruction |= inst.operands[0].reg;
9956 inst.instruction |= inst.operands[1].reg << 3;
9957 }
9958 }
9959 else
9960 {
9961 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9962 BAD_HIREG);
9963 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9964
9965 inst.instruction = THUMB_OP16 (inst.instruction);
9966 inst.instruction |= inst.operands[0].reg;
9967 inst.instruction |= inst.operands[1].reg << 3;
9968 }
9969 }
9970
9971 static void
9972 do_t_pkhbt (void)
9973 {
9974 inst.instruction |= inst.operands[0].reg << 8;
9975 inst.instruction |= inst.operands[1].reg << 16;
9976 inst.instruction |= inst.operands[2].reg;
9977 if (inst.operands[3].present)
9978 {
9979 unsigned int val = inst.reloc.exp.X_add_number;
9980 constraint (inst.reloc.exp.X_op != O_constant,
9981 _("expression too complex"));
9982 inst.instruction |= (val & 0x1c) << 10;
9983 inst.instruction |= (val & 0x03) << 6;
9984 }
9985 }
9986
9987 static void
9988 do_t_pkhtb (void)
9989 {
9990 if (!inst.operands[3].present)
9991 inst.instruction &= ~0x00000020;
9992 do_t_pkhbt ();
9993 }
9994
9995 static void
9996 do_t_pld (void)
9997 {
9998 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
9999 }
10000
10001 static void
10002 do_t_push_pop (void)
10003 {
10004 unsigned mask;
10005
10006 constraint (inst.operands[0].writeback,
10007 _("push/pop do not support {reglist}^"));
10008 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10009 _("expression too complex"));
10010
10011 mask = inst.operands[0].imm;
10012 if ((mask & ~0xff) == 0)
10013 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
10014 else if ((inst.instruction == T_MNEM_push
10015 && (mask & ~0xff) == 1 << REG_LR)
10016 || (inst.instruction == T_MNEM_pop
10017 && (mask & ~0xff) == 1 << REG_PC))
10018 {
10019 inst.instruction = THUMB_OP16 (inst.instruction);
10020 inst.instruction |= THUMB_PP_PC_LR;
10021 inst.instruction |= mask & 0xff;
10022 }
10023 else if (unified_syntax)
10024 {
10025 inst.instruction = THUMB_OP32 (inst.instruction);
10026 encode_thumb2_ldmstm (13, mask, TRUE);
10027 }
10028 else
10029 {
10030 inst.error = _("invalid register list to push/pop instruction");
10031 return;
10032 }
10033 }
10034
10035 static void
10036 do_t_rbit (void)
10037 {
10038 inst.instruction |= inst.operands[0].reg << 8;
10039 inst.instruction |= inst.operands[1].reg << 16;
10040 }
10041
10042 static void
10043 do_t_rev (void)
10044 {
10045 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10046 && inst.size_req != 4)
10047 {
10048 inst.instruction = THUMB_OP16 (inst.instruction);
10049 inst.instruction |= inst.operands[0].reg;
10050 inst.instruction |= inst.operands[1].reg << 3;
10051 }
10052 else if (unified_syntax)
10053 {
10054 inst.instruction = THUMB_OP32 (inst.instruction);
10055 inst.instruction |= inst.operands[0].reg << 8;
10056 inst.instruction |= inst.operands[1].reg << 16;
10057 inst.instruction |= inst.operands[1].reg;
10058 }
10059 else
10060 inst.error = BAD_HIREG;
10061 }
10062
10063 static void
10064 do_t_rsb (void)
10065 {
10066 int Rd, Rs;
10067
10068 Rd = inst.operands[0].reg;
10069 Rs = (inst.operands[1].present
10070 ? inst.operands[1].reg /* Rd, Rs, foo */
10071 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10072
10073 inst.instruction |= Rd << 8;
10074 inst.instruction |= Rs << 16;
10075 if (!inst.operands[2].isreg)
10076 {
10077 bfd_boolean narrow;
10078
10079 if ((inst.instruction & 0x00100000) != 0)
10080 narrow = (current_it_mask == 0);
10081 else
10082 narrow = (current_it_mask != 0);
10083
10084 if (Rd > 7 || Rs > 7)
10085 narrow = FALSE;
10086
10087 if (inst.size_req == 4 || !unified_syntax)
10088 narrow = FALSE;
10089
10090 if (inst.reloc.exp.X_op != O_constant
10091 || inst.reloc.exp.X_add_number != 0)
10092 narrow = FALSE;
10093
10094 /* Turn rsb #0 into 16-bit neg. We should probably do this via
10095 relaxation, but it doesn't seem worth the hassle. */
10096 if (narrow)
10097 {
10098 inst.reloc.type = BFD_RELOC_UNUSED;
10099 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10100 inst.instruction |= Rs << 3;
10101 inst.instruction |= Rd;
10102 }
10103 else
10104 {
10105 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10106 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10107 }
10108 }
10109 else
10110 encode_thumb32_shifted_operand (2);
10111 }
10112
10113 static void
10114 do_t_setend (void)
10115 {
10116 constraint (current_it_mask, BAD_NOT_IT);
10117 if (inst.operands[0].imm)
10118 inst.instruction |= 0x8;
10119 }
10120
10121 static void
10122 do_t_shift (void)
10123 {
10124 if (!inst.operands[1].present)
10125 inst.operands[1].reg = inst.operands[0].reg;
10126
10127 if (unified_syntax)
10128 {
10129 bfd_boolean narrow;
10130 int shift_kind;
10131
10132 switch (inst.instruction)
10133 {
10134 case T_MNEM_asr:
10135 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
10136 case T_MNEM_lsl:
10137 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
10138 case T_MNEM_lsr:
10139 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
10140 case T_MNEM_ror:
10141 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
10142 default: abort ();
10143 }
10144
10145 if (THUMB_SETS_FLAGS (inst.instruction))
10146 narrow = (current_it_mask == 0);
10147 else
10148 narrow = (current_it_mask != 0);
10149 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10150 narrow = FALSE;
10151 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
10152 narrow = FALSE;
10153 if (inst.operands[2].isreg
10154 && (inst.operands[1].reg != inst.operands[0].reg
10155 || inst.operands[2].reg > 7))
10156 narrow = FALSE;
10157 if (inst.size_req == 4)
10158 narrow = FALSE;
10159
10160 if (!narrow)
10161 {
10162 if (inst.operands[2].isreg)
10163 {
10164 inst.instruction = THUMB_OP32 (inst.instruction);
10165 inst.instruction |= inst.operands[0].reg << 8;
10166 inst.instruction |= inst.operands[1].reg << 16;
10167 inst.instruction |= inst.operands[2].reg;
10168 }
10169 else
10170 {
10171 inst.operands[1].shifted = 1;
10172 inst.operands[1].shift_kind = shift_kind;
10173 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
10174 ? T_MNEM_movs : T_MNEM_mov);
10175 inst.instruction |= inst.operands[0].reg << 8;
10176 encode_thumb32_shifted_operand (1);
10177 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
10178 inst.reloc.type = BFD_RELOC_UNUSED;
10179 }
10180 }
10181 else
10182 {
10183 if (inst.operands[2].isreg)
10184 {
10185 switch (shift_kind)
10186 {
10187 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
10188 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
10189 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
10190 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
10191 default: abort ();
10192 }
10193
10194 inst.instruction |= inst.operands[0].reg;
10195 inst.instruction |= inst.operands[2].reg << 3;
10196 }
10197 else
10198 {
10199 switch (shift_kind)
10200 {
10201 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10202 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10203 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10204 default: abort ();
10205 }
10206 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10207 inst.instruction |= inst.operands[0].reg;
10208 inst.instruction |= inst.operands[1].reg << 3;
10209 }
10210 }
10211 }
10212 else
10213 {
10214 constraint (inst.operands[0].reg > 7
10215 || inst.operands[1].reg > 7, BAD_HIREG);
10216 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10217
10218 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
10219 {
10220 constraint (inst.operands[2].reg > 7, BAD_HIREG);
10221 constraint (inst.operands[0].reg != inst.operands[1].reg,
10222 _("source1 and dest must be same register"));
10223
10224 switch (inst.instruction)
10225 {
10226 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
10227 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
10228 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
10229 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
10230 default: abort ();
10231 }
10232
10233 inst.instruction |= inst.operands[0].reg;
10234 inst.instruction |= inst.operands[2].reg << 3;
10235 }
10236 else
10237 {
10238 switch (inst.instruction)
10239 {
10240 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
10241 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
10242 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
10243 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
10244 default: abort ();
10245 }
10246 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10247 inst.instruction |= inst.operands[0].reg;
10248 inst.instruction |= inst.operands[1].reg << 3;
10249 }
10250 }
10251 }
10252
10253 static void
10254 do_t_simd (void)
10255 {
10256 inst.instruction |= inst.operands[0].reg << 8;
10257 inst.instruction |= inst.operands[1].reg << 16;
10258 inst.instruction |= inst.operands[2].reg;
10259 }
10260
10261 static void
10262 do_t_smc (void)
10263 {
10264 unsigned int value = inst.reloc.exp.X_add_number;
10265 constraint (inst.reloc.exp.X_op != O_constant,
10266 _("expression too complex"));
10267 inst.reloc.type = BFD_RELOC_UNUSED;
10268 inst.instruction |= (value & 0xf000) >> 12;
10269 inst.instruction |= (value & 0x0ff0);
10270 inst.instruction |= (value & 0x000f) << 16;
10271 }
10272
10273 static void
10274 do_t_ssat (void)
10275 {
10276 inst.instruction |= inst.operands[0].reg << 8;
10277 inst.instruction |= inst.operands[1].imm - 1;
10278 inst.instruction |= inst.operands[2].reg << 16;
10279
10280 if (inst.operands[3].present)
10281 {
10282 constraint (inst.reloc.exp.X_op != O_constant,
10283 _("expression too complex"));
10284
10285 if (inst.reloc.exp.X_add_number != 0)
10286 {
10287 if (inst.operands[3].shift_kind == SHIFT_ASR)
10288 inst.instruction |= 0x00200000; /* sh bit */
10289 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10290 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10291 }
10292 inst.reloc.type = BFD_RELOC_UNUSED;
10293 }
10294 }
10295
10296 static void
10297 do_t_ssat16 (void)
10298 {
10299 inst.instruction |= inst.operands[0].reg << 8;
10300 inst.instruction |= inst.operands[1].imm - 1;
10301 inst.instruction |= inst.operands[2].reg << 16;
10302 }
10303
10304 static void
10305 do_t_strex (void)
10306 {
10307 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10308 || inst.operands[2].postind || inst.operands[2].writeback
10309 || inst.operands[2].immisreg || inst.operands[2].shifted
10310 || inst.operands[2].negative,
10311 BAD_ADDR_MODE);
10312
10313 inst.instruction |= inst.operands[0].reg << 8;
10314 inst.instruction |= inst.operands[1].reg << 12;
10315 inst.instruction |= inst.operands[2].reg << 16;
10316 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
10317 }
10318
10319 static void
10320 do_t_strexd (void)
10321 {
10322 if (!inst.operands[2].present)
10323 inst.operands[2].reg = inst.operands[1].reg + 1;
10324
10325 constraint (inst.operands[0].reg == inst.operands[1].reg
10326 || inst.operands[0].reg == inst.operands[2].reg
10327 || inst.operands[0].reg == inst.operands[3].reg
10328 || inst.operands[1].reg == inst.operands[2].reg,
10329 BAD_OVERLAP);
10330
10331 inst.instruction |= inst.operands[0].reg;
10332 inst.instruction |= inst.operands[1].reg << 12;
10333 inst.instruction |= inst.operands[2].reg << 8;
10334 inst.instruction |= inst.operands[3].reg << 16;
10335 }
10336
10337 static void
10338 do_t_sxtah (void)
10339 {
10340 inst.instruction |= inst.operands[0].reg << 8;
10341 inst.instruction |= inst.operands[1].reg << 16;
10342 inst.instruction |= inst.operands[2].reg;
10343 inst.instruction |= inst.operands[3].imm << 4;
10344 }
10345
10346 static void
10347 do_t_sxth (void)
10348 {
10349 if (inst.instruction <= 0xffff && inst.size_req != 4
10350 && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10351 && (!inst.operands[2].present || inst.operands[2].imm == 0))
10352 {
10353 inst.instruction = THUMB_OP16 (inst.instruction);
10354 inst.instruction |= inst.operands[0].reg;
10355 inst.instruction |= inst.operands[1].reg << 3;
10356 }
10357 else if (unified_syntax)
10358 {
10359 if (inst.instruction <= 0xffff)
10360 inst.instruction = THUMB_OP32 (inst.instruction);
10361 inst.instruction |= inst.operands[0].reg << 8;
10362 inst.instruction |= inst.operands[1].reg;
10363 inst.instruction |= inst.operands[2].imm << 4;
10364 }
10365 else
10366 {
10367 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
10368 _("Thumb encoding does not support rotation"));
10369 constraint (1, BAD_HIREG);
10370 }
10371 }
10372
10373 static void
10374 do_t_swi (void)
10375 {
10376 inst.reloc.type = BFD_RELOC_ARM_SWI;
10377 }
10378
10379 static void
10380 do_t_tb (void)
10381 {
10382 int half;
10383
10384 half = (inst.instruction & 0x10) != 0;
10385 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
10386 constraint (inst.operands[0].immisreg,
10387 _("instruction requires register index"));
10388 constraint (inst.operands[0].imm == 15,
10389 _("PC is not a valid index register"));
10390 constraint (!half && inst.operands[0].shifted,
10391 _("instruction does not allow shifted index"));
10392 inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm;
10393 }
10394
10395 static void
10396 do_t_usat (void)
10397 {
10398 inst.instruction |= inst.operands[0].reg << 8;
10399 inst.instruction |= inst.operands[1].imm;
10400 inst.instruction |= inst.operands[2].reg << 16;
10401
10402 if (inst.operands[3].present)
10403 {
10404 constraint (inst.reloc.exp.X_op != O_constant,
10405 _("expression too complex"));
10406 if (inst.reloc.exp.X_add_number != 0)
10407 {
10408 if (inst.operands[3].shift_kind == SHIFT_ASR)
10409 inst.instruction |= 0x00200000; /* sh bit */
10410
10411 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10412 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10413 }
10414 inst.reloc.type = BFD_RELOC_UNUSED;
10415 }
10416 }
10417
10418 static void
10419 do_t_usat16 (void)
10420 {
10421 inst.instruction |= inst.operands[0].reg << 8;
10422 inst.instruction |= inst.operands[1].imm;
10423 inst.instruction |= inst.operands[2].reg << 16;
10424 }
10425
10426 /* Neon instruction encoder helpers. */
10427
10428 /* Encodings for the different types for various Neon opcodes. */
10429
10430 /* An "invalid" code for the following tables. */
10431 #define N_INV -1u
10432
10433 struct neon_tab_entry
10434 {
10435 unsigned integer;
10436 unsigned float_or_poly;
10437 unsigned scalar_or_imm;
10438 };
10439
10440 /* Map overloaded Neon opcodes to their respective encodings. */
10441 #define NEON_ENC_TAB \
10442 X(vabd, 0x0000700, 0x1200d00, N_INV), \
10443 X(vmax, 0x0000600, 0x0000f00, N_INV), \
10444 X(vmin, 0x0000610, 0x0200f00, N_INV), \
10445 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
10446 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
10447 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
10448 X(vadd, 0x0000800, 0x0000d00, N_INV), \
10449 X(vsub, 0x1000800, 0x0200d00, N_INV), \
10450 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
10451 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
10452 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
10453 /* Register variants of the following two instructions are encoded as
10454 vcge / vcgt with the operands reversed. */ \
10455 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
10456 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
10457 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
10458 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
10459 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
10460 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
10461 X(vmlal, 0x0800800, N_INV, 0x0800240), \
10462 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
10463 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
10464 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
10465 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
10466 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
10467 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
10468 X(vshl, 0x0000400, N_INV, 0x0800510), \
10469 X(vqshl, 0x0000410, N_INV, 0x0800710), \
10470 X(vand, 0x0000110, N_INV, 0x0800030), \
10471 X(vbic, 0x0100110, N_INV, 0x0800030), \
10472 X(veor, 0x1000110, N_INV, N_INV), \
10473 X(vorn, 0x0300110, N_INV, 0x0800010), \
10474 X(vorr, 0x0200110, N_INV, 0x0800010), \
10475 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
10476 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
10477 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
10478 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
10479 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
10480 X(vst1, 0x0000000, 0x0800000, N_INV), \
10481 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
10482 X(vst2, 0x0000100, 0x0800100, N_INV), \
10483 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
10484 X(vst3, 0x0000200, 0x0800200, N_INV), \
10485 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
10486 X(vst4, 0x0000300, 0x0800300, N_INV), \
10487 X(vmovn, 0x1b20200, N_INV, N_INV), \
10488 X(vtrn, 0x1b20080, N_INV, N_INV), \
10489 X(vqmovn, 0x1b20200, N_INV, N_INV), \
10490 X(vqmovun, 0x1b20240, N_INV, N_INV), \
10491 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
10492 X(vnmla, 0xe000a40, 0xe000b40, N_INV), \
10493 X(vnmls, 0xe100a40, 0xe100b40, N_INV), \
10494 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
10495 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
10496 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
10497 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
10498
10499 enum neon_opc
10500 {
10501 #define X(OPC,I,F,S) N_MNEM_##OPC
10502 NEON_ENC_TAB
10503 #undef X
10504 };
10505
10506 static const struct neon_tab_entry neon_enc_tab[] =
10507 {
10508 #define X(OPC,I,F,S) { (I), (F), (S) }
10509 NEON_ENC_TAB
10510 #undef X
10511 };
10512
10513 #define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10514 #define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10515 #define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10516 #define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10517 #define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10518 #define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10519 #define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10520 #define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10521 #define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10522 #define NEON_ENC_SINGLE(X) \
10523 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
10524 #define NEON_ENC_DOUBLE(X) \
10525 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
10526
10527 /* Define shapes for instruction operands. The following mnemonic characters
10528 are used in this table:
10529
10530 F - VFP S<n> register
10531 D - Neon D<n> register
10532 Q - Neon Q<n> register
10533 I - Immediate
10534 S - Scalar
10535 R - ARM register
10536 L - D<n> register list
10537
10538 This table is used to generate various data:
10539 - enumerations of the form NS_DDR to be used as arguments to
10540 neon_select_shape.
10541 - a table classifying shapes into single, double, quad, mixed.
10542 - a table used to drive neon_select_shape. */
10543
10544 #define NEON_SHAPE_DEF \
10545 X(3, (D, D, D), DOUBLE), \
10546 X(3, (Q, Q, Q), QUAD), \
10547 X(3, (D, D, I), DOUBLE), \
10548 X(3, (Q, Q, I), QUAD), \
10549 X(3, (D, D, S), DOUBLE), \
10550 X(3, (Q, Q, S), QUAD), \
10551 X(2, (D, D), DOUBLE), \
10552 X(2, (Q, Q), QUAD), \
10553 X(2, (D, S), DOUBLE), \
10554 X(2, (Q, S), QUAD), \
10555 X(2, (D, R), DOUBLE), \
10556 X(2, (Q, R), QUAD), \
10557 X(2, (D, I), DOUBLE), \
10558 X(2, (Q, I), QUAD), \
10559 X(3, (D, L, D), DOUBLE), \
10560 X(2, (D, Q), MIXED), \
10561 X(2, (Q, D), MIXED), \
10562 X(3, (D, Q, I), MIXED), \
10563 X(3, (Q, D, I), MIXED), \
10564 X(3, (Q, D, D), MIXED), \
10565 X(3, (D, Q, Q), MIXED), \
10566 X(3, (Q, Q, D), MIXED), \
10567 X(3, (Q, D, S), MIXED), \
10568 X(3, (D, Q, S), MIXED), \
10569 X(4, (D, D, D, I), DOUBLE), \
10570 X(4, (Q, Q, Q, I), QUAD), \
10571 X(2, (F, F), SINGLE), \
10572 X(3, (F, F, F), SINGLE), \
10573 X(2, (F, I), SINGLE), \
10574 X(2, (F, D), MIXED), \
10575 X(2, (D, F), MIXED), \
10576 X(3, (F, F, I), MIXED), \
10577 X(4, (R, R, F, F), SINGLE), \
10578 X(4, (F, F, R, R), SINGLE), \
10579 X(3, (D, R, R), DOUBLE), \
10580 X(3, (R, R, D), DOUBLE), \
10581 X(2, (S, R), SINGLE), \
10582 X(2, (R, S), SINGLE), \
10583 X(2, (F, R), SINGLE), \
10584 X(2, (R, F), SINGLE)
10585
10586 #define S2(A,B) NS_##A##B
10587 #define S3(A,B,C) NS_##A##B##C
10588 #define S4(A,B,C,D) NS_##A##B##C##D
10589
10590 #define X(N, L, C) S##N L
10591
10592 enum neon_shape
10593 {
10594 NEON_SHAPE_DEF,
10595 NS_NULL
10596 };
10597
10598 #undef X
10599 #undef S2
10600 #undef S3
10601 #undef S4
10602
10603 enum neon_shape_class
10604 {
10605 SC_SINGLE,
10606 SC_DOUBLE,
10607 SC_QUAD,
10608 SC_MIXED
10609 };
10610
10611 #define X(N, L, C) SC_##C
10612
10613 static enum neon_shape_class neon_shape_class[] =
10614 {
10615 NEON_SHAPE_DEF
10616 };
10617
10618 #undef X
10619
10620 enum neon_shape_el
10621 {
10622 SE_F,
10623 SE_D,
10624 SE_Q,
10625 SE_I,
10626 SE_S,
10627 SE_R,
10628 SE_L
10629 };
10630
10631 /* Register widths of above. */
10632 static unsigned neon_shape_el_size[] =
10633 {
10634 32,
10635 64,
10636 128,
10637 0,
10638 32,
10639 32,
10640 0
10641 };
10642
10643 struct neon_shape_info
10644 {
10645 unsigned els;
10646 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
10647 };
10648
10649 #define S2(A,B) { SE_##A, SE_##B }
10650 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
10651 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
10652
10653 #define X(N, L, C) { N, S##N L }
10654
10655 static struct neon_shape_info neon_shape_tab[] =
10656 {
10657 NEON_SHAPE_DEF
10658 };
10659
10660 #undef X
10661 #undef S2
10662 #undef S3
10663 #undef S4
10664
10665 /* Bit masks used in type checking given instructions.
10666 'N_EQK' means the type must be the same as (or based on in some way) the key
10667 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
10668 set, various other bits can be set as well in order to modify the meaning of
10669 the type constraint. */
10670
10671 enum neon_type_mask
10672 {
10673 N_S8 = 0x000001,
10674 N_S16 = 0x000002,
10675 N_S32 = 0x000004,
10676 N_S64 = 0x000008,
10677 N_U8 = 0x000010,
10678 N_U16 = 0x000020,
10679 N_U32 = 0x000040,
10680 N_U64 = 0x000080,
10681 N_I8 = 0x000100,
10682 N_I16 = 0x000200,
10683 N_I32 = 0x000400,
10684 N_I64 = 0x000800,
10685 N_8 = 0x001000,
10686 N_16 = 0x002000,
10687 N_32 = 0x004000,
10688 N_64 = 0x008000,
10689 N_P8 = 0x010000,
10690 N_P16 = 0x020000,
10691 N_F32 = 0x040000,
10692 N_F64 = 0x080000,
10693 N_KEY = 0x100000, /* key element (main type specifier). */
10694 N_EQK = 0x200000, /* given operand has the same type & size as the key. */
10695 N_VFP = 0x400000, /* VFP mode: operand size must match register width. */
10696 N_DBL = 0x000001, /* if N_EQK, this operand is twice the size. */
10697 N_HLF = 0x000002, /* if N_EQK, this operand is half the size. */
10698 N_SGN = 0x000004, /* if N_EQK, this operand is forced to be signed. */
10699 N_UNS = 0x000008, /* if N_EQK, this operand is forced to be unsigned. */
10700 N_INT = 0x000010, /* if N_EQK, this operand is forced to be integer. */
10701 N_FLT = 0x000020, /* if N_EQK, this operand is forced to be float. */
10702 N_SIZ = 0x000040, /* if N_EQK, this operand is forced to be size-only. */
10703 N_UTYP = 0,
10704 N_MAX_NONSPECIAL = N_F64
10705 };
10706
10707 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
10708
10709 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
10710 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
10711 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
10712 #define N_SUF_32 (N_SU_32 | N_F32)
10713 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
10714 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
10715
10716 /* Pass this as the first type argument to neon_check_type to ignore types
10717 altogether. */
10718 #define N_IGNORE_TYPE (N_KEY | N_EQK)
10719
10720 /* Select a "shape" for the current instruction (describing register types or
10721 sizes) from a list of alternatives. Return NS_NULL if the current instruction
10722 doesn't fit. For non-polymorphic shapes, checking is usually done as a
10723 function of operand parsing, so this function doesn't need to be called.
10724 Shapes should be listed in order of decreasing length. */
10725
10726 static enum neon_shape
10727 neon_select_shape (enum neon_shape shape, ...)
10728 {
10729 va_list ap;
10730 enum neon_shape first_shape = shape;
10731
10732 /* Fix missing optional operands. FIXME: we don't know at this point how
10733 many arguments we should have, so this makes the assumption that we have
10734 > 1. This is true of all current Neon opcodes, I think, but may not be
10735 true in the future. */
10736 if (!inst.operands[1].present)
10737 inst.operands[1] = inst.operands[0];
10738
10739 va_start (ap, shape);
10740
10741 for (; shape != NS_NULL; shape = va_arg (ap, int))
10742 {
10743 unsigned j;
10744 int matches = 1;
10745
10746 for (j = 0; j < neon_shape_tab[shape].els; j++)
10747 {
10748 if (!inst.operands[j].present)
10749 {
10750 matches = 0;
10751 break;
10752 }
10753
10754 switch (neon_shape_tab[shape].el[j])
10755 {
10756 case SE_F:
10757 if (!(inst.operands[j].isreg
10758 && inst.operands[j].isvec
10759 && inst.operands[j].issingle
10760 && !inst.operands[j].isquad))
10761 matches = 0;
10762 break;
10763
10764 case SE_D:
10765 if (!(inst.operands[j].isreg
10766 && inst.operands[j].isvec
10767 && !inst.operands[j].isquad
10768 && !inst.operands[j].issingle))
10769 matches = 0;
10770 break;
10771
10772 case SE_R:
10773 if (!(inst.operands[j].isreg
10774 && !inst.operands[j].isvec))
10775 matches = 0;
10776 break;
10777
10778 case SE_Q:
10779 if (!(inst.operands[j].isreg
10780 && inst.operands[j].isvec
10781 && inst.operands[j].isquad
10782 && !inst.operands[j].issingle))
10783 matches = 0;
10784 break;
10785
10786 case SE_I:
10787 if (!(!inst.operands[j].isreg
10788 && !inst.operands[j].isscalar))
10789 matches = 0;
10790 break;
10791
10792 case SE_S:
10793 if (!(!inst.operands[j].isreg
10794 && inst.operands[j].isscalar))
10795 matches = 0;
10796 break;
10797
10798 case SE_L:
10799 break;
10800 }
10801 }
10802 if (matches)
10803 break;
10804 }
10805
10806 va_end (ap);
10807
10808 if (shape == NS_NULL && first_shape != NS_NULL)
10809 first_error (_("invalid instruction shape"));
10810
10811 return shape;
10812 }
10813
10814 /* True if SHAPE is predominantly a quadword operation (most of the time, this
10815 means the Q bit should be set). */
10816
10817 static int
10818 neon_quad (enum neon_shape shape)
10819 {
10820 return neon_shape_class[shape] == SC_QUAD;
10821 }
10822
10823 static void
10824 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
10825 unsigned *g_size)
10826 {
10827 /* Allow modification to be made to types which are constrained to be
10828 based on the key element, based on bits set alongside N_EQK. */
10829 if ((typebits & N_EQK) != 0)
10830 {
10831 if ((typebits & N_HLF) != 0)
10832 *g_size /= 2;
10833 else if ((typebits & N_DBL) != 0)
10834 *g_size *= 2;
10835 if ((typebits & N_SGN) != 0)
10836 *g_type = NT_signed;
10837 else if ((typebits & N_UNS) != 0)
10838 *g_type = NT_unsigned;
10839 else if ((typebits & N_INT) != 0)
10840 *g_type = NT_integer;
10841 else if ((typebits & N_FLT) != 0)
10842 *g_type = NT_float;
10843 else if ((typebits & N_SIZ) != 0)
10844 *g_type = NT_untyped;
10845 }
10846 }
10847
10848 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
10849 operand type, i.e. the single type specified in a Neon instruction when it
10850 is the only one given. */
10851
10852 static struct neon_type_el
10853 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
10854 {
10855 struct neon_type_el dest = *key;
10856
10857 assert ((thisarg & N_EQK) != 0);
10858
10859 neon_modify_type_size (thisarg, &dest.type, &dest.size);
10860
10861 return dest;
10862 }
10863
10864 /* Convert Neon type and size into compact bitmask representation. */
10865
10866 static enum neon_type_mask
10867 type_chk_of_el_type (enum neon_el_type type, unsigned size)
10868 {
10869 switch (type)
10870 {
10871 case NT_untyped:
10872 switch (size)
10873 {
10874 case 8: return N_8;
10875 case 16: return N_16;
10876 case 32: return N_32;
10877 case 64: return N_64;
10878 default: ;
10879 }
10880 break;
10881
10882 case NT_integer:
10883 switch (size)
10884 {
10885 case 8: return N_I8;
10886 case 16: return N_I16;
10887 case 32: return N_I32;
10888 case 64: return N_I64;
10889 default: ;
10890 }
10891 break;
10892
10893 case NT_float:
10894 switch (size)
10895 {
10896 case 32: return N_F32;
10897 case 64: return N_F64;
10898 default: ;
10899 }
10900 break;
10901
10902 case NT_poly:
10903 switch (size)
10904 {
10905 case 8: return N_P8;
10906 case 16: return N_P16;
10907 default: ;
10908 }
10909 break;
10910
10911 case NT_signed:
10912 switch (size)
10913 {
10914 case 8: return N_S8;
10915 case 16: return N_S16;
10916 case 32: return N_S32;
10917 case 64: return N_S64;
10918 default: ;
10919 }
10920 break;
10921
10922 case NT_unsigned:
10923 switch (size)
10924 {
10925 case 8: return N_U8;
10926 case 16: return N_U16;
10927 case 32: return N_U32;
10928 case 64: return N_U64;
10929 default: ;
10930 }
10931 break;
10932
10933 default: ;
10934 }
10935
10936 return N_UTYP;
10937 }
10938
10939 /* Convert compact Neon bitmask type representation to a type and size. Only
10940 handles the case where a single bit is set in the mask. */
10941
10942 static int
10943 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
10944 enum neon_type_mask mask)
10945 {
10946 if ((mask & N_EQK) != 0)
10947 return FAIL;
10948
10949 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
10950 *size = 8;
10951 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
10952 *size = 16;
10953 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
10954 *size = 32;
10955 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
10956 *size = 64;
10957 else
10958 return FAIL;
10959
10960 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
10961 *type = NT_signed;
10962 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
10963 *type = NT_unsigned;
10964 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
10965 *type = NT_integer;
10966 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
10967 *type = NT_untyped;
10968 else if ((mask & (N_P8 | N_P16)) != 0)
10969 *type = NT_poly;
10970 else if ((mask & (N_F32 | N_F64)) != 0)
10971 *type = NT_float;
10972 else
10973 return FAIL;
10974
10975 return SUCCESS;
10976 }
10977
10978 /* Modify a bitmask of allowed types. This is only needed for type
10979 relaxation. */
10980
10981 static unsigned
10982 modify_types_allowed (unsigned allowed, unsigned mods)
10983 {
10984 unsigned size;
10985 enum neon_el_type type;
10986 unsigned destmask;
10987 int i;
10988
10989 destmask = 0;
10990
10991 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
10992 {
10993 if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS)
10994 {
10995 neon_modify_type_size (mods, &type, &size);
10996 destmask |= type_chk_of_el_type (type, size);
10997 }
10998 }
10999
11000 return destmask;
11001 }
11002
11003 /* Check type and return type classification.
11004 The manual states (paraphrase): If one datatype is given, it indicates the
11005 type given in:
11006 - the second operand, if there is one
11007 - the operand, if there is no second operand
11008 - the result, if there are no operands.
11009 This isn't quite good enough though, so we use a concept of a "key" datatype
11010 which is set on a per-instruction basis, which is the one which matters when
11011 only one data type is written.
11012 Note: this function has side-effects (e.g. filling in missing operands). All
11013 Neon instructions should call it before performing bit encoding. */
11014
11015 static struct neon_type_el
11016 neon_check_type (unsigned els, enum neon_shape ns, ...)
11017 {
11018 va_list ap;
11019 unsigned i, pass, key_el = 0;
11020 unsigned types[NEON_MAX_TYPE_ELS];
11021 enum neon_el_type k_type = NT_invtype;
11022 unsigned k_size = -1u;
11023 struct neon_type_el badtype = {NT_invtype, -1};
11024 unsigned key_allowed = 0;
11025
11026 /* Optional registers in Neon instructions are always (not) in operand 1.
11027 Fill in the missing operand here, if it was omitted. */
11028 if (els > 1 && !inst.operands[1].present)
11029 inst.operands[1] = inst.operands[0];
11030
11031 /* Suck up all the varargs. */
11032 va_start (ap, ns);
11033 for (i = 0; i < els; i++)
11034 {
11035 unsigned thisarg = va_arg (ap, unsigned);
11036 if (thisarg == N_IGNORE_TYPE)
11037 {
11038 va_end (ap);
11039 return badtype;
11040 }
11041 types[i] = thisarg;
11042 if ((thisarg & N_KEY) != 0)
11043 key_el = i;
11044 }
11045 va_end (ap);
11046
11047 if (inst.vectype.elems > 0)
11048 for (i = 0; i < els; i++)
11049 if (inst.operands[i].vectype.type != NT_invtype)
11050 {
11051 first_error (_("types specified in both the mnemonic and operands"));
11052 return badtype;
11053 }
11054
11055 /* Duplicate inst.vectype elements here as necessary.
11056 FIXME: No idea if this is exactly the same as the ARM assembler,
11057 particularly when an insn takes one register and one non-register
11058 operand. */
11059 if (inst.vectype.elems == 1 && els > 1)
11060 {
11061 unsigned j;
11062 inst.vectype.elems = els;
11063 inst.vectype.el[key_el] = inst.vectype.el[0];
11064 for (j = 0; j < els; j++)
11065 if (j != key_el)
11066 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11067 types[j]);
11068 }
11069 else if (inst.vectype.elems == 0 && els > 0)
11070 {
11071 unsigned j;
11072 /* No types were given after the mnemonic, so look for types specified
11073 after each operand. We allow some flexibility here; as long as the
11074 "key" operand has a type, we can infer the others. */
11075 for (j = 0; j < els; j++)
11076 if (inst.operands[j].vectype.type != NT_invtype)
11077 inst.vectype.el[j] = inst.operands[j].vectype;
11078
11079 if (inst.operands[key_el].vectype.type != NT_invtype)
11080 {
11081 for (j = 0; j < els; j++)
11082 if (inst.operands[j].vectype.type == NT_invtype)
11083 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11084 types[j]);
11085 }
11086 else
11087 {
11088 first_error (_("operand types can't be inferred"));
11089 return badtype;
11090 }
11091 }
11092 else if (inst.vectype.elems != els)
11093 {
11094 first_error (_("type specifier has the wrong number of parts"));
11095 return badtype;
11096 }
11097
11098 for (pass = 0; pass < 2; pass++)
11099 {
11100 for (i = 0; i < els; i++)
11101 {
11102 unsigned thisarg = types[i];
11103 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
11104 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
11105 enum neon_el_type g_type = inst.vectype.el[i].type;
11106 unsigned g_size = inst.vectype.el[i].size;
11107
11108 /* Decay more-specific signed & unsigned types to sign-insensitive
11109 integer types if sign-specific variants are unavailable. */
11110 if ((g_type == NT_signed || g_type == NT_unsigned)
11111 && (types_allowed & N_SU_ALL) == 0)
11112 g_type = NT_integer;
11113
11114 /* If only untyped args are allowed, decay any more specific types to
11115 them. Some instructions only care about signs for some element
11116 sizes, so handle that properly. */
11117 if ((g_size == 8 && (types_allowed & N_8) != 0)
11118 || (g_size == 16 && (types_allowed & N_16) != 0)
11119 || (g_size == 32 && (types_allowed & N_32) != 0)
11120 || (g_size == 64 && (types_allowed & N_64) != 0))
11121 g_type = NT_untyped;
11122
11123 if (pass == 0)
11124 {
11125 if ((thisarg & N_KEY) != 0)
11126 {
11127 k_type = g_type;
11128 k_size = g_size;
11129 key_allowed = thisarg & ~N_KEY;
11130 }
11131 }
11132 else
11133 {
11134 if ((thisarg & N_VFP) != 0)
11135 {
11136 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
11137 unsigned regwidth = neon_shape_el_size[regshape], match;
11138
11139 /* In VFP mode, operands must match register widths. If we
11140 have a key operand, use its width, else use the width of
11141 the current operand. */
11142 if (k_size != -1u)
11143 match = k_size;
11144 else
11145 match = g_size;
11146
11147 if (regwidth != match)
11148 {
11149 first_error (_("operand size must match register width"));
11150 return badtype;
11151 }
11152 }
11153
11154 if ((thisarg & N_EQK) == 0)
11155 {
11156 unsigned given_type = type_chk_of_el_type (g_type, g_size);
11157
11158 if ((given_type & types_allowed) == 0)
11159 {
11160 first_error (_("bad type in Neon instruction"));
11161 return badtype;
11162 }
11163 }
11164 else
11165 {
11166 enum neon_el_type mod_k_type = k_type;
11167 unsigned mod_k_size = k_size;
11168 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
11169 if (g_type != mod_k_type || g_size != mod_k_size)
11170 {
11171 first_error (_("inconsistent types in Neon instruction"));
11172 return badtype;
11173 }
11174 }
11175 }
11176 }
11177 }
11178
11179 return inst.vectype.el[key_el];
11180 }
11181
11182 /* Neon-style VFP instruction forwarding. */
11183
11184 /* Thumb VFP instructions have 0xE in the condition field. */
11185
11186 static void
11187 do_vfp_cond_or_thumb (void)
11188 {
11189 if (thumb_mode)
11190 inst.instruction |= 0xe0000000;
11191 else
11192 inst.instruction |= inst.cond << 28;
11193 }
11194
11195 /* Look up and encode a simple mnemonic, for use as a helper function for the
11196 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
11197 etc. It is assumed that operand parsing has already been done, and that the
11198 operands are in the form expected by the given opcode (this isn't necessarily
11199 the same as the form in which they were parsed, hence some massaging must
11200 take place before this function is called).
11201 Checks current arch version against that in the looked-up opcode. */
11202
11203 static void
11204 do_vfp_nsyn_opcode (const char *opname)
11205 {
11206 const struct asm_opcode *opcode;
11207
11208 opcode = hash_find (arm_ops_hsh, opname);
11209
11210 if (!opcode)
11211 abort ();
11212
11213 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
11214 thumb_mode ? *opcode->tvariant : *opcode->avariant),
11215 _(BAD_FPU));
11216
11217 if (thumb_mode)
11218 {
11219 inst.instruction = opcode->tvalue;
11220 opcode->tencode ();
11221 }
11222 else
11223 {
11224 inst.instruction = (inst.cond << 28) | opcode->avalue;
11225 opcode->aencode ();
11226 }
11227 }
11228
11229 static void
11230 do_vfp_nsyn_add_sub (enum neon_shape rs)
11231 {
11232 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
11233
11234 if (rs == NS_FFF)
11235 {
11236 if (is_add)
11237 do_vfp_nsyn_opcode ("fadds");
11238 else
11239 do_vfp_nsyn_opcode ("fsubs");
11240 }
11241 else
11242 {
11243 if (is_add)
11244 do_vfp_nsyn_opcode ("faddd");
11245 else
11246 do_vfp_nsyn_opcode ("fsubd");
11247 }
11248 }
11249
11250 /* Check operand types to see if this is a VFP instruction, and if so call
11251 PFN (). */
11252
11253 static int
11254 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
11255 {
11256 enum neon_shape rs;
11257 struct neon_type_el et;
11258
11259 switch (args)
11260 {
11261 case 2:
11262 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11263 et = neon_check_type (2, rs,
11264 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11265 break;
11266
11267 case 3:
11268 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11269 et = neon_check_type (3, rs,
11270 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11271 break;
11272
11273 default:
11274 abort ();
11275 }
11276
11277 if (et.type != NT_invtype)
11278 {
11279 pfn (rs);
11280 return SUCCESS;
11281 }
11282 else
11283 inst.error = NULL;
11284
11285 return FAIL;
11286 }
11287
11288 static void
11289 do_vfp_nsyn_mla_mls (enum neon_shape rs)
11290 {
11291 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
11292
11293 if (rs == NS_FFF)
11294 {
11295 if (is_mla)
11296 do_vfp_nsyn_opcode ("fmacs");
11297 else
11298 do_vfp_nsyn_opcode ("fmscs");
11299 }
11300 else
11301 {
11302 if (is_mla)
11303 do_vfp_nsyn_opcode ("fmacd");
11304 else
11305 do_vfp_nsyn_opcode ("fmscd");
11306 }
11307 }
11308
11309 static void
11310 do_vfp_nsyn_mul (enum neon_shape rs)
11311 {
11312 if (rs == NS_FFF)
11313 do_vfp_nsyn_opcode ("fmuls");
11314 else
11315 do_vfp_nsyn_opcode ("fmuld");
11316 }
11317
11318 static void
11319 do_vfp_nsyn_abs_neg (enum neon_shape rs)
11320 {
11321 int is_neg = (inst.instruction & 0x80) != 0;
11322 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
11323
11324 if (rs == NS_FF)
11325 {
11326 if (is_neg)
11327 do_vfp_nsyn_opcode ("fnegs");
11328 else
11329 do_vfp_nsyn_opcode ("fabss");
11330 }
11331 else
11332 {
11333 if (is_neg)
11334 do_vfp_nsyn_opcode ("fnegd");
11335 else
11336 do_vfp_nsyn_opcode ("fabsd");
11337 }
11338 }
11339
11340 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
11341 insns belong to Neon, and are handled elsewhere. */
11342
11343 static void
11344 do_vfp_nsyn_ldm_stm (int is_dbmode)
11345 {
11346 int is_ldm = (inst.instruction & (1 << 20)) != 0;
11347 if (is_ldm)
11348 {
11349 if (is_dbmode)
11350 do_vfp_nsyn_opcode ("fldmdbs");
11351 else
11352 do_vfp_nsyn_opcode ("fldmias");
11353 }
11354 else
11355 {
11356 if (is_dbmode)
11357 do_vfp_nsyn_opcode ("fstmdbs");
11358 else
11359 do_vfp_nsyn_opcode ("fstmias");
11360 }
11361 }
11362
11363 static void
11364 do_vfp_nsyn_sqrt (void)
11365 {
11366 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11367 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11368
11369 if (rs == NS_FF)
11370 do_vfp_nsyn_opcode ("fsqrts");
11371 else
11372 do_vfp_nsyn_opcode ("fsqrtd");
11373 }
11374
11375 static void
11376 do_vfp_nsyn_div (void)
11377 {
11378 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11379 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11380 N_F32 | N_F64 | N_KEY | N_VFP);
11381
11382 if (rs == NS_FFF)
11383 do_vfp_nsyn_opcode ("fdivs");
11384 else
11385 do_vfp_nsyn_opcode ("fdivd");
11386 }
11387
11388 static void
11389 do_vfp_nsyn_nmul (void)
11390 {
11391 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11392 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11393 N_F32 | N_F64 | N_KEY | N_VFP);
11394
11395 if (rs == NS_FFF)
11396 {
11397 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11398 do_vfp_sp_dyadic ();
11399 }
11400 else
11401 {
11402 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11403 do_vfp_dp_rd_rn_rm ();
11404 }
11405 do_vfp_cond_or_thumb ();
11406 }
11407
11408 static void
11409 do_vfp_nsyn_cmp (void)
11410 {
11411 if (inst.operands[1].isreg)
11412 {
11413 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11414 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11415
11416 if (rs == NS_FF)
11417 {
11418 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11419 do_vfp_sp_monadic ();
11420 }
11421 else
11422 {
11423 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11424 do_vfp_dp_rd_rm ();
11425 }
11426 }
11427 else
11428 {
11429 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
11430 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
11431
11432 switch (inst.instruction & 0x0fffffff)
11433 {
11434 case N_MNEM_vcmp:
11435 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
11436 break;
11437 case N_MNEM_vcmpe:
11438 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
11439 break;
11440 default:
11441 abort ();
11442 }
11443
11444 if (rs == NS_FI)
11445 {
11446 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11447 do_vfp_sp_compare_z ();
11448 }
11449 else
11450 {
11451 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11452 do_vfp_dp_rd ();
11453 }
11454 }
11455 do_vfp_cond_or_thumb ();
11456 }
11457
11458 static void
11459 nsyn_insert_sp (void)
11460 {
11461 inst.operands[1] = inst.operands[0];
11462 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
11463 inst.operands[0].reg = 13;
11464 inst.operands[0].isreg = 1;
11465 inst.operands[0].writeback = 1;
11466 inst.operands[0].present = 1;
11467 }
11468
11469 static void
11470 do_vfp_nsyn_push (void)
11471 {
11472 nsyn_insert_sp ();
11473 if (inst.operands[1].issingle)
11474 do_vfp_nsyn_opcode ("fstmdbs");
11475 else
11476 do_vfp_nsyn_opcode ("fstmdbd");
11477 }
11478
11479 static void
11480 do_vfp_nsyn_pop (void)
11481 {
11482 nsyn_insert_sp ();
11483 if (inst.operands[1].issingle)
11484 do_vfp_nsyn_opcode ("fldmias");
11485 else
11486 do_vfp_nsyn_opcode ("fldmiad");
11487 }
11488
11489 /* Fix up Neon data-processing instructions, ORing in the correct bits for
11490 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
11491
11492 static unsigned
11493 neon_dp_fixup (unsigned i)
11494 {
11495 if (thumb_mode)
11496 {
11497 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
11498 if (i & (1 << 24))
11499 i |= 1 << 28;
11500
11501 i &= ~(1 << 24);
11502
11503 i |= 0xef000000;
11504 }
11505 else
11506 i |= 0xf2000000;
11507
11508 return i;
11509 }
11510
11511 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
11512 (0, 1, 2, 3). */
11513
11514 static unsigned
11515 neon_logbits (unsigned x)
11516 {
11517 return ffs (x) - 4;
11518 }
11519
11520 #define LOW4(R) ((R) & 0xf)
11521 #define HI1(R) (((R) >> 4) & 1)
11522
11523 /* Encode insns with bit pattern:
11524
11525 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
11526 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
11527
11528 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
11529 different meaning for some instruction. */
11530
11531 static void
11532 neon_three_same (int isquad, int ubit, int size)
11533 {
11534 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11535 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11536 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
11537 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
11538 inst.instruction |= LOW4 (inst.operands[2].reg);
11539 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
11540 inst.instruction |= (isquad != 0) << 6;
11541 inst.instruction |= (ubit != 0) << 24;
11542 if (size != -1)
11543 inst.instruction |= neon_logbits (size) << 20;
11544
11545 inst.instruction = neon_dp_fixup (inst.instruction);
11546 }
11547
11548 /* Encode instructions of the form:
11549
11550 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
11551 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
11552
11553 Don't write size if SIZE == -1. */
11554
11555 static void
11556 neon_two_same (int qbit, int ubit, int size)
11557 {
11558 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11559 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11560 inst.instruction |= LOW4 (inst.operands[1].reg);
11561 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11562 inst.instruction |= (qbit != 0) << 6;
11563 inst.instruction |= (ubit != 0) << 24;
11564
11565 if (size != -1)
11566 inst.instruction |= neon_logbits (size) << 18;
11567
11568 inst.instruction = neon_dp_fixup (inst.instruction);
11569 }
11570
11571 /* Neon instruction encoders, in approximate order of appearance. */
11572
11573 static void
11574 do_neon_dyadic_i_su (void)
11575 {
11576 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11577 struct neon_type_el et = neon_check_type (3, rs,
11578 N_EQK, N_EQK, N_SU_32 | N_KEY);
11579 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11580 }
11581
11582 static void
11583 do_neon_dyadic_i64_su (void)
11584 {
11585 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11586 struct neon_type_el et = neon_check_type (3, rs,
11587 N_EQK, N_EQK, N_SU_ALL | N_KEY);
11588 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11589 }
11590
11591 static void
11592 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
11593 unsigned immbits)
11594 {
11595 unsigned size = et.size >> 3;
11596 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11597 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11598 inst.instruction |= LOW4 (inst.operands[1].reg);
11599 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11600 inst.instruction |= (isquad != 0) << 6;
11601 inst.instruction |= immbits << 16;
11602 inst.instruction |= (size >> 3) << 7;
11603 inst.instruction |= (size & 0x7) << 19;
11604 if (write_ubit)
11605 inst.instruction |= (uval != 0) << 24;
11606
11607 inst.instruction = neon_dp_fixup (inst.instruction);
11608 }
11609
11610 static void
11611 do_neon_shl_imm (void)
11612 {
11613 if (!inst.operands[2].isreg)
11614 {
11615 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11616 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
11617 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11618 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
11619 }
11620 else
11621 {
11622 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11623 struct neon_type_el et = neon_check_type (3, rs,
11624 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
11625 unsigned int tmp;
11626
11627 /* VSHL/VQSHL 3-register variants have syntax such as:
11628 vshl.xx Dd, Dm, Dn
11629 whereas other 3-register operations encoded by neon_three_same have
11630 syntax like:
11631 vadd.xx Dd, Dn, Dm
11632 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
11633 here. */
11634 tmp = inst.operands[2].reg;
11635 inst.operands[2].reg = inst.operands[1].reg;
11636 inst.operands[1].reg = tmp;
11637 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11638 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11639 }
11640 }
11641
11642 static void
11643 do_neon_qshl_imm (void)
11644 {
11645 if (!inst.operands[2].isreg)
11646 {
11647 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11648 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
11649
11650 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11651 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
11652 inst.operands[2].imm);
11653 }
11654 else
11655 {
11656 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11657 struct neon_type_el et = neon_check_type (3, rs,
11658 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
11659 unsigned int tmp;
11660
11661 /* See note in do_neon_shl_imm. */
11662 tmp = inst.operands[2].reg;
11663 inst.operands[2].reg = inst.operands[1].reg;
11664 inst.operands[1].reg = tmp;
11665 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11666 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11667 }
11668 }
11669
11670 static void
11671 do_neon_rshl (void)
11672 {
11673 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11674 struct neon_type_el et = neon_check_type (3, rs,
11675 N_EQK, N_EQK, N_SU_ALL | N_KEY);
11676 unsigned int tmp;
11677
11678 tmp = inst.operands[2].reg;
11679 inst.operands[2].reg = inst.operands[1].reg;
11680 inst.operands[1].reg = tmp;
11681 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11682 }
11683
11684 static int
11685 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
11686 {
11687 /* Handle .I8 pseudo-instructions. */
11688 if (size == 8)
11689 {
11690 /* Unfortunately, this will make everything apart from zero out-of-range.
11691 FIXME is this the intended semantics? There doesn't seem much point in
11692 accepting .I8 if so. */
11693 immediate |= immediate << 8;
11694 size = 16;
11695 }
11696
11697 if (size >= 32)
11698 {
11699 if (immediate == (immediate & 0x000000ff))
11700 {
11701 *immbits = immediate;
11702 return 0x1;
11703 }
11704 else if (immediate == (immediate & 0x0000ff00))
11705 {
11706 *immbits = immediate >> 8;
11707 return 0x3;
11708 }
11709 else if (immediate == (immediate & 0x00ff0000))
11710 {
11711 *immbits = immediate >> 16;
11712 return 0x5;
11713 }
11714 else if (immediate == (immediate & 0xff000000))
11715 {
11716 *immbits = immediate >> 24;
11717 return 0x7;
11718 }
11719 if ((immediate & 0xffff) != (immediate >> 16))
11720 goto bad_immediate;
11721 immediate &= 0xffff;
11722 }
11723
11724 if (immediate == (immediate & 0x000000ff))
11725 {
11726 *immbits = immediate;
11727 return 0x9;
11728 }
11729 else if (immediate == (immediate & 0x0000ff00))
11730 {
11731 *immbits = immediate >> 8;
11732 return 0xb;
11733 }
11734
11735 bad_immediate:
11736 first_error (_("immediate value out of range"));
11737 return FAIL;
11738 }
11739
11740 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
11741 A, B, C, D. */
11742
11743 static int
11744 neon_bits_same_in_bytes (unsigned imm)
11745 {
11746 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
11747 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
11748 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
11749 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
11750 }
11751
11752 /* For immediate of above form, return 0bABCD. */
11753
11754 static unsigned
11755 neon_squash_bits (unsigned imm)
11756 {
11757 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
11758 | ((imm & 0x01000000) >> 21);
11759 }
11760
11761 /* Compress quarter-float representation to 0b...000 abcdefgh. */
11762
11763 static unsigned
11764 neon_qfloat_bits (unsigned imm)
11765 {
11766 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
11767 }
11768
11769 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
11770 the instruction. *OP is passed as the initial value of the op field, and
11771 may be set to a different value depending on the constant (i.e.
11772 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
11773 MVN). If the immediate looks like a repeated pattern then also
11774 try smaller element sizes. */
11775
11776 static int
11777 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
11778 unsigned *immbits, int *op, int size,
11779 enum neon_el_type type)
11780 {
11781 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
11782 float. */
11783 if (type == NT_float && !float_p)
11784 return FAIL;
11785
11786 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
11787 {
11788 if (size != 32 || *op == 1)
11789 return FAIL;
11790 *immbits = neon_qfloat_bits (immlo);
11791 return 0xf;
11792 }
11793
11794 if (size == 64)
11795 {
11796 if (neon_bits_same_in_bytes (immhi)
11797 && neon_bits_same_in_bytes (immlo))
11798 {
11799 if (*op == 1)
11800 return FAIL;
11801 *immbits = (neon_squash_bits (immhi) << 4)
11802 | neon_squash_bits (immlo);
11803 *op = 1;
11804 return 0xe;
11805 }
11806
11807 if (immhi != immlo)
11808 return FAIL;
11809 }
11810
11811 if (size >= 32)
11812 {
11813 if (immlo == (immlo & 0x000000ff))
11814 {
11815 *immbits = immlo;
11816 return 0x0;
11817 }
11818 else if (immlo == (immlo & 0x0000ff00))
11819 {
11820 *immbits = immlo >> 8;
11821 return 0x2;
11822 }
11823 else if (immlo == (immlo & 0x00ff0000))
11824 {
11825 *immbits = immlo >> 16;
11826 return 0x4;
11827 }
11828 else if (immlo == (immlo & 0xff000000))
11829 {
11830 *immbits = immlo >> 24;
11831 return 0x6;
11832 }
11833 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
11834 {
11835 *immbits = (immlo >> 8) & 0xff;
11836 return 0xc;
11837 }
11838 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
11839 {
11840 *immbits = (immlo >> 16) & 0xff;
11841 return 0xd;
11842 }
11843
11844 if ((immlo & 0xffff) != (immlo >> 16))
11845 return FAIL;
11846 immlo &= 0xffff;
11847 }
11848
11849 if (size >= 16)
11850 {
11851 if (immlo == (immlo & 0x000000ff))
11852 {
11853 *immbits = immlo;
11854 return 0x8;
11855 }
11856 else if (immlo == (immlo & 0x0000ff00))
11857 {
11858 *immbits = immlo >> 8;
11859 return 0xa;
11860 }
11861
11862 if ((immlo & 0xff) != (immlo >> 8))
11863 return FAIL;
11864 immlo &= 0xff;
11865 }
11866
11867 if (immlo == (immlo & 0x000000ff))
11868 {
11869 /* Don't allow MVN with 8-bit immediate. */
11870 if (*op == 1)
11871 return FAIL;
11872 *immbits = immlo;
11873 return 0xe;
11874 }
11875
11876 return FAIL;
11877 }
11878
11879 /* Write immediate bits [7:0] to the following locations:
11880
11881 |28/24|23 19|18 16|15 4|3 0|
11882 | 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|
11883
11884 This function is used by VMOV/VMVN/VORR/VBIC. */
11885
11886 static void
11887 neon_write_immbits (unsigned immbits)
11888 {
11889 inst.instruction |= immbits & 0xf;
11890 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
11891 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
11892 }
11893
11894 /* Invert low-order SIZE bits of XHI:XLO. */
11895
11896 static void
11897 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
11898 {
11899 unsigned immlo = xlo ? *xlo : 0;
11900 unsigned immhi = xhi ? *xhi : 0;
11901
11902 switch (size)
11903 {
11904 case 8:
11905 immlo = (~immlo) & 0xff;
11906 break;
11907
11908 case 16:
11909 immlo = (~immlo) & 0xffff;
11910 break;
11911
11912 case 64:
11913 immhi = (~immhi) & 0xffffffff;
11914 /* fall through. */
11915
11916 case 32:
11917 immlo = (~immlo) & 0xffffffff;
11918 break;
11919
11920 default:
11921 abort ();
11922 }
11923
11924 if (xlo)
11925 *xlo = immlo;
11926
11927 if (xhi)
11928 *xhi = immhi;
11929 }
11930
11931 static void
11932 do_neon_logic (void)
11933 {
11934 if (inst.operands[2].present && inst.operands[2].isreg)
11935 {
11936 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11937 neon_check_type (3, rs, N_IGNORE_TYPE);
11938 /* U bit and size field were set as part of the bitmask. */
11939 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11940 neon_three_same (neon_quad (rs), 0, -1);
11941 }
11942 else
11943 {
11944 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
11945 struct neon_type_el et = neon_check_type (2, rs,
11946 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
11947 enum neon_opc opcode = inst.instruction & 0x0fffffff;
11948 unsigned immbits;
11949 int cmode;
11950
11951 if (et.type == NT_invtype)
11952 return;
11953
11954 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11955
11956 immbits = inst.operands[1].imm;
11957 if (et.size == 64)
11958 {
11959 /* .i64 is a pseudo-op, so the immediate must be a repeating
11960 pattern. */
11961 if (immbits != (inst.operands[1].regisimm ?
11962 inst.operands[1].reg : 0))
11963 {
11964 /* Set immbits to an invalid constant. */
11965 immbits = 0xdeadbeef;
11966 }
11967 }
11968
11969 switch (opcode)
11970 {
11971 case N_MNEM_vbic:
11972 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11973 break;
11974
11975 case N_MNEM_vorr:
11976 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11977 break;
11978
11979 case N_MNEM_vand:
11980 /* Pseudo-instruction for VBIC. */
11981 neon_invert_size (&immbits, 0, et.size);
11982 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11983 break;
11984
11985 case N_MNEM_vorn:
11986 /* Pseudo-instruction for VORR. */
11987 neon_invert_size (&immbits, 0, et.size);
11988 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11989 break;
11990
11991 default:
11992 abort ();
11993 }
11994
11995 if (cmode == FAIL)
11996 return;
11997
11998 inst.instruction |= neon_quad (rs) << 6;
11999 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12000 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12001 inst.instruction |= cmode << 8;
12002 neon_write_immbits (immbits);
12003
12004 inst.instruction = neon_dp_fixup (inst.instruction);
12005 }
12006 }
12007
12008 static void
12009 do_neon_bitfield (void)
12010 {
12011 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12012 neon_check_type (3, rs, N_IGNORE_TYPE);
12013 neon_three_same (neon_quad (rs), 0, -1);
12014 }
12015
12016 static void
12017 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
12018 unsigned destbits)
12019 {
12020 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12021 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
12022 types | N_KEY);
12023 if (et.type == NT_float)
12024 {
12025 inst.instruction = NEON_ENC_FLOAT (inst.instruction);
12026 neon_three_same (neon_quad (rs), 0, -1);
12027 }
12028 else
12029 {
12030 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12031 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
12032 }
12033 }
12034
12035 static void
12036 do_neon_dyadic_if_su (void)
12037 {
12038 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
12039 }
12040
12041 static void
12042 do_neon_dyadic_if_su_d (void)
12043 {
12044 /* This version only allow D registers, but that constraint is enforced during
12045 operand parsing so we don't need to do anything extra here. */
12046 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
12047 }
12048
12049 static void
12050 do_neon_dyadic_if_i_d (void)
12051 {
12052 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12053 affected if we specify unsigned args. */
12054 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12055 }
12056
12057 enum vfp_or_neon_is_neon_bits
12058 {
12059 NEON_CHECK_CC = 1,
12060 NEON_CHECK_ARCH = 2
12061 };
12062
12063 /* Call this function if an instruction which may have belonged to the VFP or
12064 Neon instruction sets, but turned out to be a Neon instruction (due to the
12065 operand types involved, etc.). We have to check and/or fix-up a couple of
12066 things:
12067
12068 - Make sure the user hasn't attempted to make a Neon instruction
12069 conditional.
12070 - Alter the value in the condition code field if necessary.
12071 - Make sure that the arch supports Neon instructions.
12072
12073 Which of these operations take place depends on bits from enum
12074 vfp_or_neon_is_neon_bits.
12075
12076 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
12077 current instruction's condition is COND_ALWAYS, the condition field is
12078 changed to inst.uncond_value. This is necessary because instructions shared
12079 between VFP and Neon may be conditional for the VFP variants only, and the
12080 unconditional Neon version must have, e.g., 0xF in the condition field. */
12081
12082 static int
12083 vfp_or_neon_is_neon (unsigned check)
12084 {
12085 /* Conditions are always legal in Thumb mode (IT blocks). */
12086 if (!thumb_mode && (check & NEON_CHECK_CC))
12087 {
12088 if (inst.cond != COND_ALWAYS)
12089 {
12090 first_error (_(BAD_COND));
12091 return FAIL;
12092 }
12093 if (inst.uncond_value != -1)
12094 inst.instruction |= inst.uncond_value << 28;
12095 }
12096
12097 if ((check & NEON_CHECK_ARCH)
12098 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
12099 {
12100 first_error (_(BAD_FPU));
12101 return FAIL;
12102 }
12103
12104 return SUCCESS;
12105 }
12106
12107 static void
12108 do_neon_addsub_if_i (void)
12109 {
12110 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
12111 return;
12112
12113 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12114 return;
12115
12116 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12117 affected if we specify unsigned args. */
12118 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
12119 }
12120
12121 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
12122 result to be:
12123 V<op> A,B (A is operand 0, B is operand 2)
12124 to mean:
12125 V<op> A,B,A
12126 not:
12127 V<op> A,B,B
12128 so handle that case specially. */
12129
12130 static void
12131 neon_exchange_operands (void)
12132 {
12133 void *scratch = alloca (sizeof (inst.operands[0]));
12134 if (inst.operands[1].present)
12135 {
12136 /* Swap operands[1] and operands[2]. */
12137 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
12138 inst.operands[1] = inst.operands[2];
12139 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
12140 }
12141 else
12142 {
12143 inst.operands[1] = inst.operands[2];
12144 inst.operands[2] = inst.operands[0];
12145 }
12146 }
12147
12148 static void
12149 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
12150 {
12151 if (inst.operands[2].isreg)
12152 {
12153 if (invert)
12154 neon_exchange_operands ();
12155 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
12156 }
12157 else
12158 {
12159 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12160 struct neon_type_el et = neon_check_type (2, rs,
12161 N_EQK | N_SIZ, immtypes | N_KEY);
12162
12163 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12164 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12165 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12166 inst.instruction |= LOW4 (inst.operands[1].reg);
12167 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12168 inst.instruction |= neon_quad (rs) << 6;
12169 inst.instruction |= (et.type == NT_float) << 10;
12170 inst.instruction |= neon_logbits (et.size) << 18;
12171
12172 inst.instruction = neon_dp_fixup (inst.instruction);
12173 }
12174 }
12175
12176 static void
12177 do_neon_cmp (void)
12178 {
12179 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
12180 }
12181
12182 static void
12183 do_neon_cmp_inv (void)
12184 {
12185 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
12186 }
12187
12188 static void
12189 do_neon_ceq (void)
12190 {
12191 neon_compare (N_IF_32, N_IF_32, FALSE);
12192 }
12193
12194 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
12195 scalars, which are encoded in 5 bits, M : Rm.
12196 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
12197 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
12198 index in M. */
12199
12200 static unsigned
12201 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
12202 {
12203 unsigned regno = NEON_SCALAR_REG (scalar);
12204 unsigned elno = NEON_SCALAR_INDEX (scalar);
12205
12206 switch (elsize)
12207 {
12208 case 16:
12209 if (regno > 7 || elno > 3)
12210 goto bad_scalar;
12211 return regno | (elno << 3);
12212
12213 case 32:
12214 if (regno > 15 || elno > 1)
12215 goto bad_scalar;
12216 return regno | (elno << 4);
12217
12218 default:
12219 bad_scalar:
12220 first_error (_("scalar out of range for multiply instruction"));
12221 }
12222
12223 return 0;
12224 }
12225
12226 /* Encode multiply / multiply-accumulate scalar instructions. */
12227
12228 static void
12229 neon_mul_mac (struct neon_type_el et, int ubit)
12230 {
12231 unsigned scalar;
12232
12233 /* Give a more helpful error message if we have an invalid type. */
12234 if (et.type == NT_invtype)
12235 return;
12236
12237 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
12238 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12239 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12240 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12241 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12242 inst.instruction |= LOW4 (scalar);
12243 inst.instruction |= HI1 (scalar) << 5;
12244 inst.instruction |= (et.type == NT_float) << 8;
12245 inst.instruction |= neon_logbits (et.size) << 20;
12246 inst.instruction |= (ubit != 0) << 24;
12247
12248 inst.instruction = neon_dp_fixup (inst.instruction);
12249 }
12250
12251 static void
12252 do_neon_mac_maybe_scalar (void)
12253 {
12254 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
12255 return;
12256
12257 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12258 return;
12259
12260 if (inst.operands[2].isscalar)
12261 {
12262 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
12263 struct neon_type_el et = neon_check_type (3, rs,
12264 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
12265 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12266 neon_mul_mac (et, neon_quad (rs));
12267 }
12268 else
12269 {
12270 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12271 affected if we specify unsigned args. */
12272 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12273 }
12274 }
12275
12276 static void
12277 do_neon_tst (void)
12278 {
12279 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12280 struct neon_type_el et = neon_check_type (3, rs,
12281 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
12282 neon_three_same (neon_quad (rs), 0, et.size);
12283 }
12284
12285 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
12286 same types as the MAC equivalents. The polynomial type for this instruction
12287 is encoded the same as the integer type. */
12288
12289 static void
12290 do_neon_mul (void)
12291 {
12292 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
12293 return;
12294
12295 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12296 return;
12297
12298 if (inst.operands[2].isscalar)
12299 do_neon_mac_maybe_scalar ();
12300 else
12301 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
12302 }
12303
12304 static void
12305 do_neon_qdmulh (void)
12306 {
12307 if (inst.operands[2].isscalar)
12308 {
12309 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
12310 struct neon_type_el et = neon_check_type (3, rs,
12311 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12312 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12313 neon_mul_mac (et, neon_quad (rs));
12314 }
12315 else
12316 {
12317 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12318 struct neon_type_el et = neon_check_type (3, rs,
12319 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12320 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12321 /* The U bit (rounding) comes from bit mask. */
12322 neon_three_same (neon_quad (rs), 0, et.size);
12323 }
12324 }
12325
12326 static void
12327 do_neon_fcmp_absolute (void)
12328 {
12329 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12330 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12331 /* Size field comes from bit mask. */
12332 neon_three_same (neon_quad (rs), 1, -1);
12333 }
12334
12335 static void
12336 do_neon_fcmp_absolute_inv (void)
12337 {
12338 neon_exchange_operands ();
12339 do_neon_fcmp_absolute ();
12340 }
12341
12342 static void
12343 do_neon_step (void)
12344 {
12345 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12346 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12347 neon_three_same (neon_quad (rs), 0, -1);
12348 }
12349
12350 static void
12351 do_neon_abs_neg (void)
12352 {
12353 enum neon_shape rs;
12354 struct neon_type_el et;
12355
12356 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
12357 return;
12358
12359 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12360 return;
12361
12362 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12363 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
12364
12365 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12366 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12367 inst.instruction |= LOW4 (inst.operands[1].reg);
12368 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12369 inst.instruction |= neon_quad (rs) << 6;
12370 inst.instruction |= (et.type == NT_float) << 10;
12371 inst.instruction |= neon_logbits (et.size) << 18;
12372
12373 inst.instruction = neon_dp_fixup (inst.instruction);
12374 }
12375
12376 static void
12377 do_neon_sli (void)
12378 {
12379 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12380 struct neon_type_el et = neon_check_type (2, rs,
12381 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12382 int imm = inst.operands[2].imm;
12383 constraint (imm < 0 || (unsigned)imm >= et.size,
12384 _("immediate out of range for insert"));
12385 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
12386 }
12387
12388 static void
12389 do_neon_sri (void)
12390 {
12391 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12392 struct neon_type_el et = neon_check_type (2, rs,
12393 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12394 int imm = inst.operands[2].imm;
12395 constraint (imm < 1 || (unsigned)imm > et.size,
12396 _("immediate out of range for insert"));
12397 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
12398 }
12399
12400 static void
12401 do_neon_qshlu_imm (void)
12402 {
12403 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12404 struct neon_type_el et = neon_check_type (2, rs,
12405 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
12406 int imm = inst.operands[2].imm;
12407 constraint (imm < 0 || (unsigned)imm >= et.size,
12408 _("immediate out of range for shift"));
12409 /* Only encodes the 'U present' variant of the instruction.
12410 In this case, signed types have OP (bit 8) set to 0.
12411 Unsigned types have OP set to 1. */
12412 inst.instruction |= (et.type == NT_unsigned) << 8;
12413 /* The rest of the bits are the same as other immediate shifts. */
12414 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
12415 }
12416
12417 static void
12418 do_neon_qmovn (void)
12419 {
12420 struct neon_type_el et = neon_check_type (2, NS_DQ,
12421 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12422 /* Saturating move where operands can be signed or unsigned, and the
12423 destination has the same signedness. */
12424 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12425 if (et.type == NT_unsigned)
12426 inst.instruction |= 0xc0;
12427 else
12428 inst.instruction |= 0x80;
12429 neon_two_same (0, 1, et.size / 2);
12430 }
12431
12432 static void
12433 do_neon_qmovun (void)
12434 {
12435 struct neon_type_el et = neon_check_type (2, NS_DQ,
12436 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12437 /* Saturating move with unsigned results. Operands must be signed. */
12438 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12439 neon_two_same (0, 1, et.size / 2);
12440 }
12441
12442 static void
12443 do_neon_rshift_sat_narrow (void)
12444 {
12445 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12446 or unsigned. If operands are unsigned, results must also be unsigned. */
12447 struct neon_type_el et = neon_check_type (2, NS_DQI,
12448 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12449 int imm = inst.operands[2].imm;
12450 /* This gets the bounds check, size encoding and immediate bits calculation
12451 right. */
12452 et.size /= 2;
12453
12454 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
12455 VQMOVN.I<size> <Dd>, <Qm>. */
12456 if (imm == 0)
12457 {
12458 inst.operands[2].present = 0;
12459 inst.instruction = N_MNEM_vqmovn;
12460 do_neon_qmovn ();
12461 return;
12462 }
12463
12464 constraint (imm < 1 || (unsigned)imm > et.size,
12465 _("immediate out of range"));
12466 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
12467 }
12468
12469 static void
12470 do_neon_rshift_sat_narrow_u (void)
12471 {
12472 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12473 or unsigned. If operands are unsigned, results must also be unsigned. */
12474 struct neon_type_el et = neon_check_type (2, NS_DQI,
12475 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12476 int imm = inst.operands[2].imm;
12477 /* This gets the bounds check, size encoding and immediate bits calculation
12478 right. */
12479 et.size /= 2;
12480
12481 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
12482 VQMOVUN.I<size> <Dd>, <Qm>. */
12483 if (imm == 0)
12484 {
12485 inst.operands[2].present = 0;
12486 inst.instruction = N_MNEM_vqmovun;
12487 do_neon_qmovun ();
12488 return;
12489 }
12490
12491 constraint (imm < 1 || (unsigned)imm > et.size,
12492 _("immediate out of range"));
12493 /* FIXME: The manual is kind of unclear about what value U should have in
12494 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
12495 must be 1. */
12496 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
12497 }
12498
12499 static void
12500 do_neon_movn (void)
12501 {
12502 struct neon_type_el et = neon_check_type (2, NS_DQ,
12503 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12504 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12505 neon_two_same (0, 1, et.size / 2);
12506 }
12507
12508 static void
12509 do_neon_rshift_narrow (void)
12510 {
12511 struct neon_type_el et = neon_check_type (2, NS_DQI,
12512 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12513 int imm = inst.operands[2].imm;
12514 /* This gets the bounds check, size encoding and immediate bits calculation
12515 right. */
12516 et.size /= 2;
12517
12518 /* If immediate is zero then we are a pseudo-instruction for
12519 VMOVN.I<size> <Dd>, <Qm> */
12520 if (imm == 0)
12521 {
12522 inst.operands[2].present = 0;
12523 inst.instruction = N_MNEM_vmovn;
12524 do_neon_movn ();
12525 return;
12526 }
12527
12528 constraint (imm < 1 || (unsigned)imm > et.size,
12529 _("immediate out of range for narrowing operation"));
12530 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
12531 }
12532
12533 static void
12534 do_neon_shll (void)
12535 {
12536 /* FIXME: Type checking when lengthening. */
12537 struct neon_type_el et = neon_check_type (2, NS_QDI,
12538 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
12539 unsigned imm = inst.operands[2].imm;
12540
12541 if (imm == et.size)
12542 {
12543 /* Maximum shift variant. */
12544 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12545 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12546 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12547 inst.instruction |= LOW4 (inst.operands[1].reg);
12548 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12549 inst.instruction |= neon_logbits (et.size) << 18;
12550
12551 inst.instruction = neon_dp_fixup (inst.instruction);
12552 }
12553 else
12554 {
12555 /* A more-specific type check for non-max versions. */
12556 et = neon_check_type (2, NS_QDI,
12557 N_EQK | N_DBL, N_SU_32 | N_KEY);
12558 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12559 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
12560 }
12561 }
12562
12563 /* Check the various types for the VCVT instruction, and return which version
12564 the current instruction is. */
12565
12566 static int
12567 neon_cvt_flavour (enum neon_shape rs)
12568 {
12569 #define CVT_VAR(C,X,Y) \
12570 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
12571 if (et.type != NT_invtype) \
12572 { \
12573 inst.error = NULL; \
12574 return (C); \
12575 }
12576 struct neon_type_el et;
12577 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
12578 || rs == NS_FF) ? N_VFP : 0;
12579 /* The instruction versions which take an immediate take one register
12580 argument, which is extended to the width of the full register. Thus the
12581 "source" and "destination" registers must have the same width. Hack that
12582 here by making the size equal to the key (wider, in this case) operand. */
12583 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
12584
12585 CVT_VAR (0, N_S32, N_F32);
12586 CVT_VAR (1, N_U32, N_F32);
12587 CVT_VAR (2, N_F32, N_S32);
12588 CVT_VAR (3, N_F32, N_U32);
12589
12590 whole_reg = N_VFP;
12591
12592 /* VFP instructions. */
12593 CVT_VAR (4, N_F32, N_F64);
12594 CVT_VAR (5, N_F64, N_F32);
12595 CVT_VAR (6, N_S32, N_F64 | key);
12596 CVT_VAR (7, N_U32, N_F64 | key);
12597 CVT_VAR (8, N_F64 | key, N_S32);
12598 CVT_VAR (9, N_F64 | key, N_U32);
12599 /* VFP instructions with bitshift. */
12600 CVT_VAR (10, N_F32 | key, N_S16);
12601 CVT_VAR (11, N_F32 | key, N_U16);
12602 CVT_VAR (12, N_F64 | key, N_S16);
12603 CVT_VAR (13, N_F64 | key, N_U16);
12604 CVT_VAR (14, N_S16, N_F32 | key);
12605 CVT_VAR (15, N_U16, N_F32 | key);
12606 CVT_VAR (16, N_S16, N_F64 | key);
12607 CVT_VAR (17, N_U16, N_F64 | key);
12608
12609 return -1;
12610 #undef CVT_VAR
12611 }
12612
12613 /* Neon-syntax VFP conversions. */
12614
12615 static void
12616 do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
12617 {
12618 const char *opname = 0;
12619
12620 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
12621 {
12622 /* Conversions with immediate bitshift. */
12623 const char *enc[] =
12624 {
12625 "ftosls",
12626 "ftouls",
12627 "fsltos",
12628 "fultos",
12629 NULL,
12630 NULL,
12631 "ftosld",
12632 "ftould",
12633 "fsltod",
12634 "fultod",
12635 "fshtos",
12636 "fuhtos",
12637 "fshtod",
12638 "fuhtod",
12639 "ftoshs",
12640 "ftouhs",
12641 "ftoshd",
12642 "ftouhd"
12643 };
12644
12645 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12646 {
12647 opname = enc[flavour];
12648 constraint (inst.operands[0].reg != inst.operands[1].reg,
12649 _("operands 0 and 1 must be the same register"));
12650 inst.operands[1] = inst.operands[2];
12651 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
12652 }
12653 }
12654 else
12655 {
12656 /* Conversions without bitshift. */
12657 const char *enc[] =
12658 {
12659 "ftosis",
12660 "ftouis",
12661 "fsitos",
12662 "fuitos",
12663 "fcvtsd",
12664 "fcvtds",
12665 "ftosid",
12666 "ftouid",
12667 "fsitod",
12668 "fuitod"
12669 };
12670
12671 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12672 opname = enc[flavour];
12673 }
12674
12675 if (opname)
12676 do_vfp_nsyn_opcode (opname);
12677 }
12678
12679 static void
12680 do_vfp_nsyn_cvtz (void)
12681 {
12682 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
12683 int flavour = neon_cvt_flavour (rs);
12684 const char *enc[] =
12685 {
12686 "ftosizs",
12687 "ftouizs",
12688 NULL,
12689 NULL,
12690 NULL,
12691 NULL,
12692 "ftosizd",
12693 "ftouizd"
12694 };
12695
12696 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
12697 do_vfp_nsyn_opcode (enc[flavour]);
12698 }
12699
12700 static void
12701 do_neon_cvt (void)
12702 {
12703 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
12704 NS_FD, NS_DF, NS_FF, NS_NULL);
12705 int flavour = neon_cvt_flavour (rs);
12706
12707 /* VFP rather than Neon conversions. */
12708 if (flavour >= 4)
12709 {
12710 do_vfp_nsyn_cvt (rs, flavour);
12711 return;
12712 }
12713
12714 switch (rs)
12715 {
12716 case NS_DDI:
12717 case NS_QQI:
12718 {
12719 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12720 return;
12721
12722 /* Fixed-point conversion with #0 immediate is encoded as an
12723 integer conversion. */
12724 if (inst.operands[2].present && inst.operands[2].imm == 0)
12725 goto int_encode;
12726 unsigned immbits = 32 - inst.operands[2].imm;
12727 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
12728 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12729 if (flavour != -1)
12730 inst.instruction |= enctab[flavour];
12731 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12732 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12733 inst.instruction |= LOW4 (inst.operands[1].reg);
12734 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12735 inst.instruction |= neon_quad (rs) << 6;
12736 inst.instruction |= 1 << 21;
12737 inst.instruction |= immbits << 16;
12738
12739 inst.instruction = neon_dp_fixup (inst.instruction);
12740 }
12741 break;
12742
12743 case NS_DD:
12744 case NS_QQ:
12745 int_encode:
12746 {
12747 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
12748
12749 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12750
12751 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12752 return;
12753
12754 if (flavour != -1)
12755 inst.instruction |= enctab[flavour];
12756
12757 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12758 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12759 inst.instruction |= LOW4 (inst.operands[1].reg);
12760 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12761 inst.instruction |= neon_quad (rs) << 6;
12762 inst.instruction |= 2 << 18;
12763
12764 inst.instruction = neon_dp_fixup (inst.instruction);
12765 }
12766 break;
12767
12768 default:
12769 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
12770 do_vfp_nsyn_cvt (rs, flavour);
12771 }
12772 }
12773
12774 static void
12775 neon_move_immediate (void)
12776 {
12777 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
12778 struct neon_type_el et = neon_check_type (2, rs,
12779 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
12780 unsigned immlo, immhi = 0, immbits;
12781 int op, cmode, float_p;
12782
12783 constraint (et.type == NT_invtype,
12784 _("operand size must be specified for immediate VMOV"));
12785
12786 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
12787 op = (inst.instruction & (1 << 5)) != 0;
12788
12789 immlo = inst.operands[1].imm;
12790 if (inst.operands[1].regisimm)
12791 immhi = inst.operands[1].reg;
12792
12793 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
12794 _("immediate has bits set outside the operand size"));
12795
12796 float_p = inst.operands[1].immisfloat;
12797
12798 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
12799 et.size, et.type)) == FAIL)
12800 {
12801 /* Invert relevant bits only. */
12802 neon_invert_size (&immlo, &immhi, et.size);
12803 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
12804 with one or the other; those cases are caught by
12805 neon_cmode_for_move_imm. */
12806 op = !op;
12807 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
12808 &op, et.size, et.type)) == FAIL)
12809 {
12810 first_error (_("immediate out of range"));
12811 return;
12812 }
12813 }
12814
12815 inst.instruction &= ~(1 << 5);
12816 inst.instruction |= op << 5;
12817
12818 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12819 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12820 inst.instruction |= neon_quad (rs) << 6;
12821 inst.instruction |= cmode << 8;
12822
12823 neon_write_immbits (immbits);
12824 }
12825
12826 static void
12827 do_neon_mvn (void)
12828 {
12829 if (inst.operands[1].isreg)
12830 {
12831 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12832
12833 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12834 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12835 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12836 inst.instruction |= LOW4 (inst.operands[1].reg);
12837 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12838 inst.instruction |= neon_quad (rs) << 6;
12839 }
12840 else
12841 {
12842 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12843 neon_move_immediate ();
12844 }
12845
12846 inst.instruction = neon_dp_fixup (inst.instruction);
12847 }
12848
12849 /* Encode instructions of form:
12850
12851 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12852 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
12853
12854 static void
12855 neon_mixed_length (struct neon_type_el et, unsigned size)
12856 {
12857 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12858 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12859 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12860 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12861 inst.instruction |= LOW4 (inst.operands[2].reg);
12862 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12863 inst.instruction |= (et.type == NT_unsigned) << 24;
12864 inst.instruction |= neon_logbits (size) << 20;
12865
12866 inst.instruction = neon_dp_fixup (inst.instruction);
12867 }
12868
12869 static void
12870 do_neon_dyadic_long (void)
12871 {
12872 /* FIXME: Type checking for lengthening op. */
12873 struct neon_type_el et = neon_check_type (3, NS_QDD,
12874 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
12875 neon_mixed_length (et, et.size);
12876 }
12877
12878 static void
12879 do_neon_abal (void)
12880 {
12881 struct neon_type_el et = neon_check_type (3, NS_QDD,
12882 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
12883 neon_mixed_length (et, et.size);
12884 }
12885
12886 static void
12887 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
12888 {
12889 if (inst.operands[2].isscalar)
12890 {
12891 struct neon_type_el et = neon_check_type (3, NS_QDS,
12892 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
12893 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12894 neon_mul_mac (et, et.type == NT_unsigned);
12895 }
12896 else
12897 {
12898 struct neon_type_el et = neon_check_type (3, NS_QDD,
12899 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
12900 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12901 neon_mixed_length (et, et.size);
12902 }
12903 }
12904
12905 static void
12906 do_neon_mac_maybe_scalar_long (void)
12907 {
12908 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
12909 }
12910
12911 static void
12912 do_neon_dyadic_wide (void)
12913 {
12914 struct neon_type_el et = neon_check_type (3, NS_QQD,
12915 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
12916 neon_mixed_length (et, et.size);
12917 }
12918
12919 static void
12920 do_neon_dyadic_narrow (void)
12921 {
12922 struct neon_type_el et = neon_check_type (3, NS_QDD,
12923 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
12924 /* Operand sign is unimportant, and the U bit is part of the opcode,
12925 so force the operand type to integer. */
12926 et.type = NT_integer;
12927 neon_mixed_length (et, et.size / 2);
12928 }
12929
12930 static void
12931 do_neon_mul_sat_scalar_long (void)
12932 {
12933 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
12934 }
12935
12936 static void
12937 do_neon_vmull (void)
12938 {
12939 if (inst.operands[2].isscalar)
12940 do_neon_mac_maybe_scalar_long ();
12941 else
12942 {
12943 struct neon_type_el et = neon_check_type (3, NS_QDD,
12944 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
12945 if (et.type == NT_poly)
12946 inst.instruction = NEON_ENC_POLY (inst.instruction);
12947 else
12948 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12949 /* For polynomial encoding, size field must be 0b00 and the U bit must be
12950 zero. Should be OK as-is. */
12951 neon_mixed_length (et, et.size);
12952 }
12953 }
12954
12955 static void
12956 do_neon_ext (void)
12957 {
12958 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
12959 struct neon_type_el et = neon_check_type (3, rs,
12960 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12961 unsigned imm = (inst.operands[3].imm * et.size) / 8;
12962 constraint (imm >= (neon_quad (rs) ? 16 : 8), _("shift out of range"));
12963 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12964 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12965 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12966 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12967 inst.instruction |= LOW4 (inst.operands[2].reg);
12968 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12969 inst.instruction |= neon_quad (rs) << 6;
12970 inst.instruction |= imm << 8;
12971
12972 inst.instruction = neon_dp_fixup (inst.instruction);
12973 }
12974
12975 static void
12976 do_neon_rev (void)
12977 {
12978 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12979 struct neon_type_el et = neon_check_type (2, rs,
12980 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12981 unsigned op = (inst.instruction >> 7) & 3;
12982 /* N (width of reversed regions) is encoded as part of the bitmask. We
12983 extract it here to check the elements to be reversed are smaller.
12984 Otherwise we'd get a reserved instruction. */
12985 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
12986 assert (elsize != 0);
12987 constraint (et.size >= elsize,
12988 _("elements must be smaller than reversal region"));
12989 neon_two_same (neon_quad (rs), 1, et.size);
12990 }
12991
12992 static void
12993 do_neon_dup (void)
12994 {
12995 if (inst.operands[1].isscalar)
12996 {
12997 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
12998 struct neon_type_el et = neon_check_type (2, rs,
12999 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13000 unsigned sizebits = et.size >> 3;
13001 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
13002 int logsize = neon_logbits (et.size);
13003 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
13004
13005 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
13006 return;
13007
13008 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13009 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13010 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13011 inst.instruction |= LOW4 (dm);
13012 inst.instruction |= HI1 (dm) << 5;
13013 inst.instruction |= neon_quad (rs) << 6;
13014 inst.instruction |= x << 17;
13015 inst.instruction |= sizebits << 16;
13016
13017 inst.instruction = neon_dp_fixup (inst.instruction);
13018 }
13019 else
13020 {
13021 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
13022 struct neon_type_el et = neon_check_type (2, rs,
13023 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13024 /* Duplicate ARM register to lanes of vector. */
13025 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
13026 switch (et.size)
13027 {
13028 case 8: inst.instruction |= 0x400000; break;
13029 case 16: inst.instruction |= 0x000020; break;
13030 case 32: inst.instruction |= 0x000000; break;
13031 default: break;
13032 }
13033 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13034 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
13035 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
13036 inst.instruction |= neon_quad (rs) << 21;
13037 /* The encoding for this instruction is identical for the ARM and Thumb
13038 variants, except for the condition field. */
13039 do_vfp_cond_or_thumb ();
13040 }
13041 }
13042
13043 /* VMOV has particularly many variations. It can be one of:
13044 0. VMOV<c><q> <Qd>, <Qm>
13045 1. VMOV<c><q> <Dd>, <Dm>
13046 (Register operations, which are VORR with Rm = Rn.)
13047 2. VMOV<c><q>.<dt> <Qd>, #<imm>
13048 3. VMOV<c><q>.<dt> <Dd>, #<imm>
13049 (Immediate loads.)
13050 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
13051 (ARM register to scalar.)
13052 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
13053 (Two ARM registers to vector.)
13054 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
13055 (Scalar to ARM register.)
13056 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
13057 (Vector to two ARM registers.)
13058 8. VMOV.F32 <Sd>, <Sm>
13059 9. VMOV.F64 <Dd>, <Dm>
13060 (VFP register moves.)
13061 10. VMOV.F32 <Sd>, #imm
13062 11. VMOV.F64 <Dd>, #imm
13063 (VFP float immediate load.)
13064 12. VMOV <Rd>, <Sm>
13065 (VFP single to ARM reg.)
13066 13. VMOV <Sd>, <Rm>
13067 (ARM reg to VFP single.)
13068 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
13069 (Two ARM regs to two VFP singles.)
13070 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
13071 (Two VFP singles to two ARM regs.)
13072
13073 These cases can be disambiguated using neon_select_shape, except cases 1/9
13074 and 3/11 which depend on the operand type too.
13075
13076 All the encoded bits are hardcoded by this function.
13077
13078 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
13079 Cases 5, 7 may be used with VFPv2 and above.
13080
13081 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
13082 can specify a type where it doesn't make sense to, and is ignored). */
13083
13084 static void
13085 do_neon_mov (void)
13086 {
13087 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
13088 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
13089 NS_NULL);
13090 struct neon_type_el et;
13091 const char *ldconst = 0;
13092
13093 switch (rs)
13094 {
13095 case NS_DD: /* case 1/9. */
13096 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13097 /* It is not an error here if no type is given. */
13098 inst.error = NULL;
13099 if (et.type == NT_float && et.size == 64)
13100 {
13101 do_vfp_nsyn_opcode ("fcpyd");
13102 break;
13103 }
13104 /* fall through. */
13105
13106 case NS_QQ: /* case 0/1. */
13107 {
13108 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13109 return;
13110 /* The architecture manual I have doesn't explicitly state which
13111 value the U bit should have for register->register moves, but
13112 the equivalent VORR instruction has U = 0, so do that. */
13113 inst.instruction = 0x0200110;
13114 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13115 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13116 inst.instruction |= LOW4 (inst.operands[1].reg);
13117 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13118 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13119 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13120 inst.instruction |= neon_quad (rs) << 6;
13121
13122 inst.instruction = neon_dp_fixup (inst.instruction);
13123 }
13124 break;
13125
13126 case NS_DI: /* case 3/11. */
13127 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13128 inst.error = NULL;
13129 if (et.type == NT_float && et.size == 64)
13130 {
13131 /* case 11 (fconstd). */
13132 ldconst = "fconstd";
13133 goto encode_fconstd;
13134 }
13135 /* fall through. */
13136
13137 case NS_QI: /* case 2/3. */
13138 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13139 return;
13140 inst.instruction = 0x0800010;
13141 neon_move_immediate ();
13142 inst.instruction = neon_dp_fixup (inst.instruction);
13143 break;
13144
13145 case NS_SR: /* case 4. */
13146 {
13147 unsigned bcdebits = 0;
13148 struct neon_type_el et = neon_check_type (2, NS_NULL,
13149 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13150 int logsize = neon_logbits (et.size);
13151 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
13152 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
13153
13154 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13155 _(BAD_FPU));
13156 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13157 && et.size != 32, _(BAD_FPU));
13158 constraint (et.type == NT_invtype, _("bad type for scalar"));
13159 constraint (x >= 64 / et.size, _("scalar index out of range"));
13160
13161 switch (et.size)
13162 {
13163 case 8: bcdebits = 0x8; break;
13164 case 16: bcdebits = 0x1; break;
13165 case 32: bcdebits = 0x0; break;
13166 default: ;
13167 }
13168
13169 bcdebits |= x << logsize;
13170
13171 inst.instruction = 0xe000b10;
13172 do_vfp_cond_or_thumb ();
13173 inst.instruction |= LOW4 (dn) << 16;
13174 inst.instruction |= HI1 (dn) << 7;
13175 inst.instruction |= inst.operands[1].reg << 12;
13176 inst.instruction |= (bcdebits & 3) << 5;
13177 inst.instruction |= (bcdebits >> 2) << 21;
13178 }
13179 break;
13180
13181 case NS_DRR: /* case 5 (fmdrr). */
13182 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13183 _(BAD_FPU));
13184
13185 inst.instruction = 0xc400b10;
13186 do_vfp_cond_or_thumb ();
13187 inst.instruction |= LOW4 (inst.operands[0].reg);
13188 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
13189 inst.instruction |= inst.operands[1].reg << 12;
13190 inst.instruction |= inst.operands[2].reg << 16;
13191 break;
13192
13193 case NS_RS: /* case 6. */
13194 {
13195 struct neon_type_el et = neon_check_type (2, NS_NULL,
13196 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
13197 unsigned logsize = neon_logbits (et.size);
13198 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
13199 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
13200 unsigned abcdebits = 0;
13201
13202 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13203 _(BAD_FPU));
13204 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13205 && et.size != 32, _(BAD_FPU));
13206 constraint (et.type == NT_invtype, _("bad type for scalar"));
13207 constraint (x >= 64 / et.size, _("scalar index out of range"));
13208
13209 switch (et.size)
13210 {
13211 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
13212 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
13213 case 32: abcdebits = 0x00; break;
13214 default: ;
13215 }
13216
13217 abcdebits |= x << logsize;
13218 inst.instruction = 0xe100b10;
13219 do_vfp_cond_or_thumb ();
13220 inst.instruction |= LOW4 (dn) << 16;
13221 inst.instruction |= HI1 (dn) << 7;
13222 inst.instruction |= inst.operands[0].reg << 12;
13223 inst.instruction |= (abcdebits & 3) << 5;
13224 inst.instruction |= (abcdebits >> 2) << 21;
13225 }
13226 break;
13227
13228 case NS_RRD: /* case 7 (fmrrd). */
13229 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13230 _(BAD_FPU));
13231
13232 inst.instruction = 0xc500b10;
13233 do_vfp_cond_or_thumb ();
13234 inst.instruction |= inst.operands[0].reg << 12;
13235 inst.instruction |= inst.operands[1].reg << 16;
13236 inst.instruction |= LOW4 (inst.operands[2].reg);
13237 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13238 break;
13239
13240 case NS_FF: /* case 8 (fcpys). */
13241 do_vfp_nsyn_opcode ("fcpys");
13242 break;
13243
13244 case NS_FI: /* case 10 (fconsts). */
13245 ldconst = "fconsts";
13246 encode_fconstd:
13247 if (is_quarter_float (inst.operands[1].imm))
13248 {
13249 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
13250 do_vfp_nsyn_opcode (ldconst);
13251 }
13252 else
13253 first_error (_("immediate out of range"));
13254 break;
13255
13256 case NS_RF: /* case 12 (fmrs). */
13257 do_vfp_nsyn_opcode ("fmrs");
13258 break;
13259
13260 case NS_FR: /* case 13 (fmsr). */
13261 do_vfp_nsyn_opcode ("fmsr");
13262 break;
13263
13264 /* The encoders for the fmrrs and fmsrr instructions expect three operands
13265 (one of which is a list), but we have parsed four. Do some fiddling to
13266 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
13267 expect. */
13268 case NS_RRFF: /* case 14 (fmrrs). */
13269 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
13270 _("VFP registers must be adjacent"));
13271 inst.operands[2].imm = 2;
13272 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13273 do_vfp_nsyn_opcode ("fmrrs");
13274 break;
13275
13276 case NS_FFRR: /* case 15 (fmsrr). */
13277 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
13278 _("VFP registers must be adjacent"));
13279 inst.operands[1] = inst.operands[2];
13280 inst.operands[2] = inst.operands[3];
13281 inst.operands[0].imm = 2;
13282 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13283 do_vfp_nsyn_opcode ("fmsrr");
13284 break;
13285
13286 default:
13287 abort ();
13288 }
13289 }
13290
13291 static void
13292 do_neon_rshift_round_imm (void)
13293 {
13294 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13295 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
13296 int imm = inst.operands[2].imm;
13297
13298 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
13299 if (imm == 0)
13300 {
13301 inst.operands[2].present = 0;
13302 do_neon_mov ();
13303 return;
13304 }
13305
13306 constraint (imm < 1 || (unsigned)imm > et.size,
13307 _("immediate out of range for shift"));
13308 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
13309 et.size - imm);
13310 }
13311
13312 static void
13313 do_neon_movl (void)
13314 {
13315 struct neon_type_el et = neon_check_type (2, NS_QD,
13316 N_EQK | N_DBL, N_SU_32 | N_KEY);
13317 unsigned sizebits = et.size >> 3;
13318 inst.instruction |= sizebits << 19;
13319 neon_two_same (0, et.type == NT_unsigned, -1);
13320 }
13321
13322 static void
13323 do_neon_trn (void)
13324 {
13325 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13326 struct neon_type_el et = neon_check_type (2, rs,
13327 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13328 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13329 neon_two_same (neon_quad (rs), 1, et.size);
13330 }
13331
13332 static void
13333 do_neon_zip_uzp (void)
13334 {
13335 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13336 struct neon_type_el et = neon_check_type (2, rs,
13337 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13338 if (rs == NS_DD && et.size == 32)
13339 {
13340 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
13341 inst.instruction = N_MNEM_vtrn;
13342 do_neon_trn ();
13343 return;
13344 }
13345 neon_two_same (neon_quad (rs), 1, et.size);
13346 }
13347
13348 static void
13349 do_neon_sat_abs_neg (void)
13350 {
13351 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13352 struct neon_type_el et = neon_check_type (2, rs,
13353 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
13354 neon_two_same (neon_quad (rs), 1, et.size);
13355 }
13356
13357 static void
13358 do_neon_pair_long (void)
13359 {
13360 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13361 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
13362 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
13363 inst.instruction |= (et.type == NT_unsigned) << 7;
13364 neon_two_same (neon_quad (rs), 1, et.size);
13365 }
13366
13367 static void
13368 do_neon_recip_est (void)
13369 {
13370 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13371 struct neon_type_el et = neon_check_type (2, rs,
13372 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
13373 inst.instruction |= (et.type == NT_float) << 8;
13374 neon_two_same (neon_quad (rs), 1, et.size);
13375 }
13376
13377 static void
13378 do_neon_cls (void)
13379 {
13380 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13381 struct neon_type_el et = neon_check_type (2, rs,
13382 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
13383 neon_two_same (neon_quad (rs), 1, et.size);
13384 }
13385
13386 static void
13387 do_neon_clz (void)
13388 {
13389 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13390 struct neon_type_el et = neon_check_type (2, rs,
13391 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
13392 neon_two_same (neon_quad (rs), 1, et.size);
13393 }
13394
13395 static void
13396 do_neon_cnt (void)
13397 {
13398 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13399 struct neon_type_el et = neon_check_type (2, rs,
13400 N_EQK | N_INT, N_8 | N_KEY);
13401 neon_two_same (neon_quad (rs), 1, et.size);
13402 }
13403
13404 static void
13405 do_neon_swp (void)
13406 {
13407 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13408 neon_two_same (neon_quad (rs), 1, -1);
13409 }
13410
13411 static void
13412 do_neon_tbl_tbx (void)
13413 {
13414 unsigned listlenbits;
13415 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
13416
13417 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
13418 {
13419 first_error (_("bad list length for table lookup"));
13420 return;
13421 }
13422
13423 listlenbits = inst.operands[1].imm - 1;
13424 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13425 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13426 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13427 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13428 inst.instruction |= LOW4 (inst.operands[2].reg);
13429 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13430 inst.instruction |= listlenbits << 8;
13431
13432 inst.instruction = neon_dp_fixup (inst.instruction);
13433 }
13434
13435 static void
13436 do_neon_ldm_stm (void)
13437 {
13438 /* P, U and L bits are part of bitmask. */
13439 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
13440 unsigned offsetbits = inst.operands[1].imm * 2;
13441
13442 if (inst.operands[1].issingle)
13443 {
13444 do_vfp_nsyn_ldm_stm (is_dbmode);
13445 return;
13446 }
13447
13448 constraint (is_dbmode && !inst.operands[0].writeback,
13449 _("writeback (!) must be used for VLDMDB and VSTMDB"));
13450
13451 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
13452 _("register list must contain at least 1 and at most 16 "
13453 "registers"));
13454
13455 inst.instruction |= inst.operands[0].reg << 16;
13456 inst.instruction |= inst.operands[0].writeback << 21;
13457 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13458 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
13459
13460 inst.instruction |= offsetbits;
13461
13462 do_vfp_cond_or_thumb ();
13463 }
13464
13465 static void
13466 do_neon_ldr_str (void)
13467 {
13468 int is_ldr = (inst.instruction & (1 << 20)) != 0;
13469
13470 if (inst.operands[0].issingle)
13471 {
13472 if (is_ldr)
13473 do_vfp_nsyn_opcode ("flds");
13474 else
13475 do_vfp_nsyn_opcode ("fsts");
13476 }
13477 else
13478 {
13479 if (is_ldr)
13480 do_vfp_nsyn_opcode ("fldd");
13481 else
13482 do_vfp_nsyn_opcode ("fstd");
13483 }
13484 }
13485
13486 /* "interleave" version also handles non-interleaving register VLD1/VST1
13487 instructions. */
13488
13489 static void
13490 do_neon_ld_st_interleave (void)
13491 {
13492 struct neon_type_el et = neon_check_type (1, NS_NULL,
13493 N_8 | N_16 | N_32 | N_64);
13494 unsigned alignbits = 0;
13495 unsigned idx;
13496 /* The bits in this table go:
13497 0: register stride of one (0) or two (1)
13498 1,2: register list length, minus one (1, 2, 3, 4).
13499 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
13500 We use -1 for invalid entries. */
13501 const int typetable[] =
13502 {
13503 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
13504 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
13505 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
13506 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
13507 };
13508 int typebits;
13509
13510 if (et.type == NT_invtype)
13511 return;
13512
13513 if (inst.operands[1].immisalign)
13514 switch (inst.operands[1].imm >> 8)
13515 {
13516 case 64: alignbits = 1; break;
13517 case 128:
13518 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13519 goto bad_alignment;
13520 alignbits = 2;
13521 break;
13522 case 256:
13523 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13524 goto bad_alignment;
13525 alignbits = 3;
13526 break;
13527 default:
13528 bad_alignment:
13529 first_error (_("bad alignment"));
13530 return;
13531 }
13532
13533 inst.instruction |= alignbits << 4;
13534 inst.instruction |= neon_logbits (et.size) << 6;
13535
13536 /* Bits [4:6] of the immediate in a list specifier encode register stride
13537 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
13538 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
13539 up the right value for "type" in a table based on this value and the given
13540 list style, then stick it back. */
13541 idx = ((inst.operands[0].imm >> 4) & 7)
13542 | (((inst.instruction >> 8) & 3) << 3);
13543
13544 typebits = typetable[idx];
13545
13546 constraint (typebits == -1, _("bad list type for instruction"));
13547
13548 inst.instruction &= ~0xf00;
13549 inst.instruction |= typebits << 8;
13550 }
13551
13552 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
13553 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
13554 otherwise. The variable arguments are a list of pairs of legal (size, align)
13555 values, terminated with -1. */
13556
13557 static int
13558 neon_alignment_bit (int size, int align, int *do_align, ...)
13559 {
13560 va_list ap;
13561 int result = FAIL, thissize, thisalign;
13562
13563 if (!inst.operands[1].immisalign)
13564 {
13565 *do_align = 0;
13566 return SUCCESS;
13567 }
13568
13569 va_start (ap, do_align);
13570
13571 do
13572 {
13573 thissize = va_arg (ap, int);
13574 if (thissize == -1)
13575 break;
13576 thisalign = va_arg (ap, int);
13577
13578 if (size == thissize && align == thisalign)
13579 result = SUCCESS;
13580 }
13581 while (result != SUCCESS);
13582
13583 va_end (ap);
13584
13585 if (result == SUCCESS)
13586 *do_align = 1;
13587 else
13588 first_error (_("unsupported alignment for instruction"));
13589
13590 return result;
13591 }
13592
13593 static void
13594 do_neon_ld_st_lane (void)
13595 {
13596 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
13597 int align_good, do_align = 0;
13598 int logsize = neon_logbits (et.size);
13599 int align = inst.operands[1].imm >> 8;
13600 int n = (inst.instruction >> 8) & 3;
13601 int max_el = 64 / et.size;
13602
13603 if (et.type == NT_invtype)
13604 return;
13605
13606 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
13607 _("bad list length"));
13608 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
13609 _("scalar index out of range"));
13610 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
13611 && et.size == 8,
13612 _("stride of 2 unavailable when element size is 8"));
13613
13614 switch (n)
13615 {
13616 case 0: /* VLD1 / VST1. */
13617 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
13618 32, 32, -1);
13619 if (align_good == FAIL)
13620 return;
13621 if (do_align)
13622 {
13623 unsigned alignbits = 0;
13624 switch (et.size)
13625 {
13626 case 16: alignbits = 0x1; break;
13627 case 32: alignbits = 0x3; break;
13628 default: ;
13629 }
13630 inst.instruction |= alignbits << 4;
13631 }
13632 break;
13633
13634 case 1: /* VLD2 / VST2. */
13635 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
13636 32, 64, -1);
13637 if (align_good == FAIL)
13638 return;
13639 if (do_align)
13640 inst.instruction |= 1 << 4;
13641 break;
13642
13643 case 2: /* VLD3 / VST3. */
13644 constraint (inst.operands[1].immisalign,
13645 _("can't use alignment with this instruction"));
13646 break;
13647
13648 case 3: /* VLD4 / VST4. */
13649 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13650 16, 64, 32, 64, 32, 128, -1);
13651 if (align_good == FAIL)
13652 return;
13653 if (do_align)
13654 {
13655 unsigned alignbits = 0;
13656 switch (et.size)
13657 {
13658 case 8: alignbits = 0x1; break;
13659 case 16: alignbits = 0x1; break;
13660 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
13661 default: ;
13662 }
13663 inst.instruction |= alignbits << 4;
13664 }
13665 break;
13666
13667 default: ;
13668 }
13669
13670 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
13671 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13672 inst.instruction |= 1 << (4 + logsize);
13673
13674 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
13675 inst.instruction |= logsize << 10;
13676 }
13677
13678 /* Encode single n-element structure to all lanes VLD<n> instructions. */
13679
13680 static void
13681 do_neon_ld_dup (void)
13682 {
13683 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
13684 int align_good, do_align = 0;
13685
13686 if (et.type == NT_invtype)
13687 return;
13688
13689 switch ((inst.instruction >> 8) & 3)
13690 {
13691 case 0: /* VLD1. */
13692 assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
13693 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13694 &do_align, 16, 16, 32, 32, -1);
13695 if (align_good == FAIL)
13696 return;
13697 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
13698 {
13699 case 1: break;
13700 case 2: inst.instruction |= 1 << 5; break;
13701 default: first_error (_("bad list length")); return;
13702 }
13703 inst.instruction |= neon_logbits (et.size) << 6;
13704 break;
13705
13706 case 1: /* VLD2. */
13707 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13708 &do_align, 8, 16, 16, 32, 32, 64, -1);
13709 if (align_good == FAIL)
13710 return;
13711 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
13712 _("bad list length"));
13713 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13714 inst.instruction |= 1 << 5;
13715 inst.instruction |= neon_logbits (et.size) << 6;
13716 break;
13717
13718 case 2: /* VLD3. */
13719 constraint (inst.operands[1].immisalign,
13720 _("can't use alignment with this instruction"));
13721 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
13722 _("bad list length"));
13723 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13724 inst.instruction |= 1 << 5;
13725 inst.instruction |= neon_logbits (et.size) << 6;
13726 break;
13727
13728 case 3: /* VLD4. */
13729 {
13730 int align = inst.operands[1].imm >> 8;
13731 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13732 16, 64, 32, 64, 32, 128, -1);
13733 if (align_good == FAIL)
13734 return;
13735 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
13736 _("bad list length"));
13737 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13738 inst.instruction |= 1 << 5;
13739 if (et.size == 32 && align == 128)
13740 inst.instruction |= 0x3 << 6;
13741 else
13742 inst.instruction |= neon_logbits (et.size) << 6;
13743 }
13744 break;
13745
13746 default: ;
13747 }
13748
13749 inst.instruction |= do_align << 4;
13750 }
13751
13752 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
13753 apart from bits [11:4]. */
13754
13755 static void
13756 do_neon_ldx_stx (void)
13757 {
13758 switch (NEON_LANE (inst.operands[0].imm))
13759 {
13760 case NEON_INTERLEAVE_LANES:
13761 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
13762 do_neon_ld_st_interleave ();
13763 break;
13764
13765 case NEON_ALL_LANES:
13766 inst.instruction = NEON_ENC_DUP (inst.instruction);
13767 do_neon_ld_dup ();
13768 break;
13769
13770 default:
13771 inst.instruction = NEON_ENC_LANE (inst.instruction);
13772 do_neon_ld_st_lane ();
13773 }
13774
13775 /* L bit comes from bit mask. */
13776 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13777 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13778 inst.instruction |= inst.operands[1].reg << 16;
13779
13780 if (inst.operands[1].postind)
13781 {
13782 int postreg = inst.operands[1].imm & 0xf;
13783 constraint (!inst.operands[1].immisreg,
13784 _("post-index must be a register"));
13785 constraint (postreg == 0xd || postreg == 0xf,
13786 _("bad register for post-index"));
13787 inst.instruction |= postreg;
13788 }
13789 else if (inst.operands[1].writeback)
13790 {
13791 inst.instruction |= 0xd;
13792 }
13793 else
13794 inst.instruction |= 0xf;
13795
13796 if (thumb_mode)
13797 inst.instruction |= 0xf9000000;
13798 else
13799 inst.instruction |= 0xf4000000;
13800 }
13801 \f
13802 /* Overall per-instruction processing. */
13803
13804 /* We need to be able to fix up arbitrary expressions in some statements.
13805 This is so that we can handle symbols that are an arbitrary distance from
13806 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
13807 which returns part of an address in a form which will be valid for
13808 a data instruction. We do this by pushing the expression into a symbol
13809 in the expr_section, and creating a fix for that. */
13810
13811 static void
13812 fix_new_arm (fragS * frag,
13813 int where,
13814 short int size,
13815 expressionS * exp,
13816 int pc_rel,
13817 int reloc)
13818 {
13819 fixS * new_fix;
13820
13821 switch (exp->X_op)
13822 {
13823 case O_constant:
13824 case O_symbol:
13825 case O_add:
13826 case O_subtract:
13827 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
13828 break;
13829
13830 default:
13831 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
13832 pc_rel, reloc);
13833 break;
13834 }
13835
13836 /* Mark whether the fix is to a THUMB instruction, or an ARM
13837 instruction. */
13838 new_fix->tc_fix_data = thumb_mode;
13839 }
13840
13841 /* Create a frg for an instruction requiring relaxation. */
13842 static void
13843 output_relax_insn (void)
13844 {
13845 char * to;
13846 symbolS *sym;
13847 int offset;
13848
13849 /* The size of the instruction is unknown, so tie the debug info to the
13850 start of the instruction. */
13851 dwarf2_emit_insn (0);
13852
13853 switch (inst.reloc.exp.X_op)
13854 {
13855 case O_symbol:
13856 sym = inst.reloc.exp.X_add_symbol;
13857 offset = inst.reloc.exp.X_add_number;
13858 break;
13859 case O_constant:
13860 sym = NULL;
13861 offset = inst.reloc.exp.X_add_number;
13862 break;
13863 default:
13864 sym = make_expr_symbol (&inst.reloc.exp);
13865 offset = 0;
13866 break;
13867 }
13868 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
13869 inst.relax, sym, offset, NULL/*offset, opcode*/);
13870 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
13871 }
13872
13873 /* Write a 32-bit thumb instruction to buf. */
13874 static void
13875 put_thumb32_insn (char * buf, unsigned long insn)
13876 {
13877 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
13878 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
13879 }
13880
13881 static void
13882 output_inst (const char * str)
13883 {
13884 char * to = NULL;
13885
13886 if (inst.error)
13887 {
13888 as_bad ("%s -- `%s'", inst.error, str);
13889 return;
13890 }
13891 if (inst.relax)
13892 {
13893 output_relax_insn ();
13894 return;
13895 }
13896 if (inst.size == 0)
13897 return;
13898
13899 to = frag_more (inst.size);
13900
13901 if (thumb_mode && (inst.size > THUMB_SIZE))
13902 {
13903 assert (inst.size == (2 * THUMB_SIZE));
13904 put_thumb32_insn (to, inst.instruction);
13905 }
13906 else if (inst.size > INSN_SIZE)
13907 {
13908 assert (inst.size == (2 * INSN_SIZE));
13909 md_number_to_chars (to, inst.instruction, INSN_SIZE);
13910 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
13911 }
13912 else
13913 md_number_to_chars (to, inst.instruction, inst.size);
13914
13915 if (inst.reloc.type != BFD_RELOC_UNUSED)
13916 fix_new_arm (frag_now, to - frag_now->fr_literal,
13917 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
13918 inst.reloc.type);
13919
13920 dwarf2_emit_insn (inst.size);
13921 }
13922
13923 /* Tag values used in struct asm_opcode's tag field. */
13924 enum opcode_tag
13925 {
13926 OT_unconditional, /* Instruction cannot be conditionalized.
13927 The ARM condition field is still 0xE. */
13928 OT_unconditionalF, /* Instruction cannot be conditionalized
13929 and carries 0xF in its ARM condition field. */
13930 OT_csuffix, /* Instruction takes a conditional suffix. */
13931 OT_csuffixF, /* Some forms of the instruction take a conditional
13932 suffix, others place 0xF where the condition field
13933 would be. */
13934 OT_cinfix3, /* Instruction takes a conditional infix,
13935 beginning at character index 3. (In
13936 unified mode, it becomes a suffix.) */
13937 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
13938 tsts, cmps, cmns, and teqs. */
13939 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
13940 character index 3, even in unified mode. Used for
13941 legacy instructions where suffix and infix forms
13942 may be ambiguous. */
13943 OT_csuf_or_in3, /* Instruction takes either a conditional
13944 suffix or an infix at character index 3. */
13945 OT_odd_infix_unc, /* This is the unconditional variant of an
13946 instruction that takes a conditional infix
13947 at an unusual position. In unified mode,
13948 this variant will accept a suffix. */
13949 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
13950 are the conditional variants of instructions that
13951 take conditional infixes in unusual positions.
13952 The infix appears at character index
13953 (tag - OT_odd_infix_0). These are not accepted
13954 in unified mode. */
13955 };
13956
13957 /* Subroutine of md_assemble, responsible for looking up the primary
13958 opcode from the mnemonic the user wrote. STR points to the
13959 beginning of the mnemonic.
13960
13961 This is not simply a hash table lookup, because of conditional
13962 variants. Most instructions have conditional variants, which are
13963 expressed with a _conditional affix_ to the mnemonic. If we were
13964 to encode each conditional variant as a literal string in the opcode
13965 table, it would have approximately 20,000 entries.
13966
13967 Most mnemonics take this affix as a suffix, and in unified syntax,
13968 'most' is upgraded to 'all'. However, in the divided syntax, some
13969 instructions take the affix as an infix, notably the s-variants of
13970 the arithmetic instructions. Of those instructions, all but six
13971 have the infix appear after the third character of the mnemonic.
13972
13973 Accordingly, the algorithm for looking up primary opcodes given
13974 an identifier is:
13975
13976 1. Look up the identifier in the opcode table.
13977 If we find a match, go to step U.
13978
13979 2. Look up the last two characters of the identifier in the
13980 conditions table. If we find a match, look up the first N-2
13981 characters of the identifier in the opcode table. If we
13982 find a match, go to step CE.
13983
13984 3. Look up the fourth and fifth characters of the identifier in
13985 the conditions table. If we find a match, extract those
13986 characters from the identifier, and look up the remaining
13987 characters in the opcode table. If we find a match, go
13988 to step CM.
13989
13990 4. Fail.
13991
13992 U. Examine the tag field of the opcode structure, in case this is
13993 one of the six instructions with its conditional infix in an
13994 unusual place. If it is, the tag tells us where to find the
13995 infix; look it up in the conditions table and set inst.cond
13996 accordingly. Otherwise, this is an unconditional instruction.
13997 Again set inst.cond accordingly. Return the opcode structure.
13998
13999 CE. Examine the tag field to make sure this is an instruction that
14000 should receive a conditional suffix. If it is not, fail.
14001 Otherwise, set inst.cond from the suffix we already looked up,
14002 and return the opcode structure.
14003
14004 CM. Examine the tag field to make sure this is an instruction that
14005 should receive a conditional infix after the third character.
14006 If it is not, fail. Otherwise, undo the edits to the current
14007 line of input and proceed as for case CE. */
14008
14009 static const struct asm_opcode *
14010 opcode_lookup (char **str)
14011 {
14012 char *end, *base;
14013 char *affix;
14014 const struct asm_opcode *opcode;
14015 const struct asm_cond *cond;
14016 char save[2];
14017 bfd_boolean neon_supported;
14018
14019 neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1);
14020
14021 /* Scan up to the end of the mnemonic, which must end in white space,
14022 '.' (in unified mode, or for Neon instructions), or end of string. */
14023 for (base = end = *str; *end != '\0'; end++)
14024 if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.'))
14025 break;
14026
14027 if (end == base)
14028 return 0;
14029
14030 /* Handle a possible width suffix and/or Neon type suffix. */
14031 if (end[0] == '.')
14032 {
14033 int offset = 2;
14034
14035 /* The .w and .n suffixes are only valid if the unified syntax is in
14036 use. */
14037 if (unified_syntax && end[1] == 'w')
14038 inst.size_req = 4;
14039 else if (unified_syntax && end[1] == 'n')
14040 inst.size_req = 2;
14041 else
14042 offset = 0;
14043
14044 inst.vectype.elems = 0;
14045
14046 *str = end + offset;
14047
14048 if (end[offset] == '.')
14049 {
14050 /* See if we have a Neon type suffix (possible in either unified or
14051 non-unified ARM syntax mode). */
14052 if (parse_neon_type (&inst.vectype, str) == FAIL)
14053 return 0;
14054 }
14055 else if (end[offset] != '\0' && end[offset] != ' ')
14056 return 0;
14057 }
14058 else
14059 *str = end;
14060
14061 /* Look for unaffixed or special-case affixed mnemonic. */
14062 opcode = hash_find_n (arm_ops_hsh, base, end - base);
14063 if (opcode)
14064 {
14065 /* step U */
14066 if (opcode->tag < OT_odd_infix_0)
14067 {
14068 inst.cond = COND_ALWAYS;
14069 return opcode;
14070 }
14071
14072 if (unified_syntax)
14073 as_warn (_("conditional infixes are deprecated in unified syntax"));
14074 affix = base + (opcode->tag - OT_odd_infix_0);
14075 cond = hash_find_n (arm_cond_hsh, affix, 2);
14076 assert (cond);
14077
14078 inst.cond = cond->value;
14079 return opcode;
14080 }
14081
14082 /* Cannot have a conditional suffix on a mnemonic of less than two
14083 characters. */
14084 if (end - base < 3)
14085 return 0;
14086
14087 /* Look for suffixed mnemonic. */
14088 affix = end - 2;
14089 cond = hash_find_n (arm_cond_hsh, affix, 2);
14090 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
14091 if (opcode && cond)
14092 {
14093 /* step CE */
14094 switch (opcode->tag)
14095 {
14096 case OT_cinfix3_legacy:
14097 /* Ignore conditional suffixes matched on infix only mnemonics. */
14098 break;
14099
14100 case OT_cinfix3:
14101 case OT_cinfix3_deprecated:
14102 case OT_odd_infix_unc:
14103 if (!unified_syntax)
14104 return 0;
14105 /* else fall through */
14106
14107 case OT_csuffix:
14108 case OT_csuffixF:
14109 case OT_csuf_or_in3:
14110 inst.cond = cond->value;
14111 return opcode;
14112
14113 case OT_unconditional:
14114 case OT_unconditionalF:
14115 if (thumb_mode)
14116 {
14117 inst.cond = cond->value;
14118 }
14119 else
14120 {
14121 /* delayed diagnostic */
14122 inst.error = BAD_COND;
14123 inst.cond = COND_ALWAYS;
14124 }
14125 return opcode;
14126
14127 default:
14128 return 0;
14129 }
14130 }
14131
14132 /* Cannot have a usual-position infix on a mnemonic of less than
14133 six characters (five would be a suffix). */
14134 if (end - base < 6)
14135 return 0;
14136
14137 /* Look for infixed mnemonic in the usual position. */
14138 affix = base + 3;
14139 cond = hash_find_n (arm_cond_hsh, affix, 2);
14140 if (!cond)
14141 return 0;
14142
14143 memcpy (save, affix, 2);
14144 memmove (affix, affix + 2, (end - affix) - 2);
14145 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
14146 memmove (affix + 2, affix, (end - affix) - 2);
14147 memcpy (affix, save, 2);
14148
14149 if (opcode
14150 && (opcode->tag == OT_cinfix3
14151 || opcode->tag == OT_cinfix3_deprecated
14152 || opcode->tag == OT_csuf_or_in3
14153 || opcode->tag == OT_cinfix3_legacy))
14154 {
14155 /* step CM */
14156 if (unified_syntax
14157 && (opcode->tag == OT_cinfix3
14158 || opcode->tag == OT_cinfix3_deprecated))
14159 as_warn (_("conditional infixes are deprecated in unified syntax"));
14160
14161 inst.cond = cond->value;
14162 return opcode;
14163 }
14164
14165 return 0;
14166 }
14167
14168 void
14169 md_assemble (char *str)
14170 {
14171 char *p = str;
14172 const struct asm_opcode * opcode;
14173
14174 /* Align the previous label if needed. */
14175 if (last_label_seen != NULL)
14176 {
14177 symbol_set_frag (last_label_seen, frag_now);
14178 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
14179 S_SET_SEGMENT (last_label_seen, now_seg);
14180 }
14181
14182 memset (&inst, '\0', sizeof (inst));
14183 inst.reloc.type = BFD_RELOC_UNUSED;
14184
14185 opcode = opcode_lookup (&p);
14186 if (!opcode)
14187 {
14188 /* It wasn't an instruction, but it might be a register alias of
14189 the form alias .req reg, or a Neon .dn/.qn directive. */
14190 if (!create_register_alias (str, p)
14191 && !create_neon_reg_alias (str, p))
14192 as_bad (_("bad instruction `%s'"), str);
14193
14194 return;
14195 }
14196
14197 if (opcode->tag == OT_cinfix3_deprecated)
14198 as_warn (_("s suffix on comparison instruction is deprecated"));
14199
14200 /* The value which unconditional instructions should have in place of the
14201 condition field. */
14202 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
14203
14204 if (thumb_mode)
14205 {
14206 arm_feature_set variant;
14207
14208 variant = cpu_variant;
14209 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
14210 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
14211 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
14212 /* Check that this instruction is supported for this CPU. */
14213 if (!opcode->tvariant
14214 || (thumb_mode == 1
14215 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
14216 {
14217 as_bad (_("selected processor does not support `%s'"), str);
14218 return;
14219 }
14220 if (inst.cond != COND_ALWAYS && !unified_syntax
14221 && opcode->tencode != do_t_branch)
14222 {
14223 as_bad (_("Thumb does not support conditional execution"));
14224 return;
14225 }
14226
14227 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) && !inst.size_req)
14228 {
14229 /* Implicit require narrow instructions on Thumb-1. This avoids
14230 relaxation accidentally introducing Thumb-2 instructions. */
14231 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
14232 && !ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr))
14233 inst.size_req = 2;
14234 }
14235
14236 /* Check conditional suffixes. */
14237 if (current_it_mask)
14238 {
14239 int cond;
14240 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
14241 current_it_mask <<= 1;
14242 current_it_mask &= 0x1f;
14243 /* The BKPT instruction is unconditional even in an IT block. */
14244 if (!inst.error
14245 && cond != inst.cond && opcode->tencode != do_t_bkpt)
14246 {
14247 as_bad (_("incorrect condition in IT block"));
14248 return;
14249 }
14250 }
14251 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
14252 {
14253 as_bad (_("thumb conditional instruction not in IT block"));
14254 return;
14255 }
14256
14257 mapping_state (MAP_THUMB);
14258 inst.instruction = opcode->tvalue;
14259
14260 if (!parse_operands (p, opcode->operands))
14261 opcode->tencode ();
14262
14263 /* Clear current_it_mask at the end of an IT block. */
14264 if (current_it_mask == 0x10)
14265 current_it_mask = 0;
14266
14267 if (!(inst.error || inst.relax))
14268 {
14269 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
14270 inst.size = (inst.instruction > 0xffff ? 4 : 2);
14271 if (inst.size_req && inst.size_req != inst.size)
14272 {
14273 as_bad (_("cannot honor width suffix -- `%s'"), str);
14274 return;
14275 }
14276 }
14277
14278 /* Something has gone badly wrong if we try to relax a fixed size
14279 instruction. */
14280 assert (inst.size_req == 0 || !inst.relax);
14281
14282 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14283 *opcode->tvariant);
14284 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
14285 set those bits when Thumb-2 32-bit instructions are seen. ie.
14286 anything other than bl/blx and v6-M instructions.
14287 This is overly pessimistic for relaxable instructions. */
14288 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
14289 || inst.relax)
14290 && !ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr))
14291 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14292 arm_ext_v6t2);
14293 }
14294 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
14295 {
14296 bfd_boolean is_bx;
14297
14298 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
14299 is_bx = (opcode->aencode == do_bx);
14300
14301 /* Check that this instruction is supported for this CPU. */
14302 if (!(is_bx && fix_v4bx)
14303 && !(opcode->avariant &&
14304 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
14305 {
14306 as_bad (_("selected processor does not support `%s'"), str);
14307 return;
14308 }
14309 if (inst.size_req)
14310 {
14311 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
14312 return;
14313 }
14314
14315 mapping_state (MAP_ARM);
14316 inst.instruction = opcode->avalue;
14317 if (opcode->tag == OT_unconditionalF)
14318 inst.instruction |= 0xF << 28;
14319 else
14320 inst.instruction |= inst.cond << 28;
14321 inst.size = INSN_SIZE;
14322 if (!parse_operands (p, opcode->operands))
14323 opcode->aencode ();
14324 /* Arm mode bx is marked as both v4T and v5 because it's still required
14325 on a hypothetical non-thumb v5 core. */
14326 if (is_bx)
14327 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
14328 else
14329 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
14330 *opcode->avariant);
14331 }
14332 else
14333 {
14334 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
14335 "-- `%s'"), str);
14336 return;
14337 }
14338 output_inst (str);
14339 }
14340
14341 /* Various frobbings of labels and their addresses. */
14342
14343 void
14344 arm_start_line_hook (void)
14345 {
14346 last_label_seen = NULL;
14347 }
14348
14349 void
14350 arm_frob_label (symbolS * sym)
14351 {
14352 last_label_seen = sym;
14353
14354 ARM_SET_THUMB (sym, thumb_mode);
14355
14356 #if defined OBJ_COFF || defined OBJ_ELF
14357 ARM_SET_INTERWORK (sym, support_interwork);
14358 #endif
14359
14360 /* Note - do not allow local symbols (.Lxxx) to be labelled
14361 as Thumb functions. This is because these labels, whilst
14362 they exist inside Thumb code, are not the entry points for
14363 possible ARM->Thumb calls. Also, these labels can be used
14364 as part of a computed goto or switch statement. eg gcc
14365 can generate code that looks like this:
14366
14367 ldr r2, [pc, .Laaa]
14368 lsl r3, r3, #2
14369 ldr r2, [r3, r2]
14370 mov pc, r2
14371
14372 .Lbbb: .word .Lxxx
14373 .Lccc: .word .Lyyy
14374 ..etc...
14375 .Laaa: .word Lbbb
14376
14377 The first instruction loads the address of the jump table.
14378 The second instruction converts a table index into a byte offset.
14379 The third instruction gets the jump address out of the table.
14380 The fourth instruction performs the jump.
14381
14382 If the address stored at .Laaa is that of a symbol which has the
14383 Thumb_Func bit set, then the linker will arrange for this address
14384 to have the bottom bit set, which in turn would mean that the
14385 address computation performed by the third instruction would end
14386 up with the bottom bit set. Since the ARM is capable of unaligned
14387 word loads, the instruction would then load the incorrect address
14388 out of the jump table, and chaos would ensue. */
14389 if (label_is_thumb_function_name
14390 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
14391 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
14392 {
14393 /* When the address of a Thumb function is taken the bottom
14394 bit of that address should be set. This will allow
14395 interworking between Arm and Thumb functions to work
14396 correctly. */
14397
14398 THUMB_SET_FUNC (sym, 1);
14399
14400 label_is_thumb_function_name = FALSE;
14401 }
14402
14403 dwarf2_emit_label (sym);
14404 }
14405
14406 int
14407 arm_data_in_code (void)
14408 {
14409 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
14410 {
14411 *input_line_pointer = '/';
14412 input_line_pointer += 5;
14413 *input_line_pointer = 0;
14414 return 1;
14415 }
14416
14417 return 0;
14418 }
14419
14420 char *
14421 arm_canonicalize_symbol_name (char * name)
14422 {
14423 int len;
14424
14425 if (thumb_mode && (len = strlen (name)) > 5
14426 && streq (name + len - 5, "/data"))
14427 *(name + len - 5) = 0;
14428
14429 return name;
14430 }
14431 \f
14432 /* Table of all register names defined by default. The user can
14433 define additional names with .req. Note that all register names
14434 should appear in both upper and lowercase variants. Some registers
14435 also have mixed-case names. */
14436
14437 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
14438 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
14439 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
14440 #define REGSET(p,t) \
14441 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
14442 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
14443 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
14444 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
14445 #define REGSETH(p,t) \
14446 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
14447 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
14448 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
14449 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
14450 #define REGSET2(p,t) \
14451 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
14452 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
14453 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
14454 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
14455
14456 static const struct reg_entry reg_names[] =
14457 {
14458 /* ARM integer registers. */
14459 REGSET(r, RN), REGSET(R, RN),
14460
14461 /* ATPCS synonyms. */
14462 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
14463 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
14464 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
14465
14466 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
14467 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
14468 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
14469
14470 /* Well-known aliases. */
14471 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
14472 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
14473
14474 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
14475 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
14476
14477 /* Coprocessor numbers. */
14478 REGSET(p, CP), REGSET(P, CP),
14479
14480 /* Coprocessor register numbers. The "cr" variants are for backward
14481 compatibility. */
14482 REGSET(c, CN), REGSET(C, CN),
14483 REGSET(cr, CN), REGSET(CR, CN),
14484
14485 /* FPA registers. */
14486 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
14487 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
14488
14489 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
14490 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
14491
14492 /* VFP SP registers. */
14493 REGSET(s,VFS), REGSET(S,VFS),
14494 REGSETH(s,VFS), REGSETH(S,VFS),
14495
14496 /* VFP DP Registers. */
14497 REGSET(d,VFD), REGSET(D,VFD),
14498 /* Extra Neon DP registers. */
14499 REGSETH(d,VFD), REGSETH(D,VFD),
14500
14501 /* Neon QP registers. */
14502 REGSET2(q,NQ), REGSET2(Q,NQ),
14503
14504 /* VFP control registers. */
14505 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
14506 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
14507 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
14508 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
14509 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
14510 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
14511
14512 /* Maverick DSP coprocessor registers. */
14513 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
14514 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
14515
14516 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
14517 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
14518 REGDEF(dspsc,0,DSPSC),
14519
14520 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
14521 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
14522 REGDEF(DSPSC,0,DSPSC),
14523
14524 /* iWMMXt data registers - p0, c0-15. */
14525 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
14526
14527 /* iWMMXt control registers - p1, c0-3. */
14528 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
14529 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
14530 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
14531 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
14532
14533 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
14534 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
14535 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
14536 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
14537 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
14538
14539 /* XScale accumulator registers. */
14540 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
14541 };
14542 #undef REGDEF
14543 #undef REGNUM
14544 #undef REGSET
14545
14546 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
14547 within psr_required_here. */
14548 static const struct asm_psr psrs[] =
14549 {
14550 /* Backward compatibility notation. Note that "all" is no longer
14551 truly all possible PSR bits. */
14552 {"all", PSR_c | PSR_f},
14553 {"flg", PSR_f},
14554 {"ctl", PSR_c},
14555
14556 /* Individual flags. */
14557 {"f", PSR_f},
14558 {"c", PSR_c},
14559 {"x", PSR_x},
14560 {"s", PSR_s},
14561 /* Combinations of flags. */
14562 {"fs", PSR_f | PSR_s},
14563 {"fx", PSR_f | PSR_x},
14564 {"fc", PSR_f | PSR_c},
14565 {"sf", PSR_s | PSR_f},
14566 {"sx", PSR_s | PSR_x},
14567 {"sc", PSR_s | PSR_c},
14568 {"xf", PSR_x | PSR_f},
14569 {"xs", PSR_x | PSR_s},
14570 {"xc", PSR_x | PSR_c},
14571 {"cf", PSR_c | PSR_f},
14572 {"cs", PSR_c | PSR_s},
14573 {"cx", PSR_c | PSR_x},
14574 {"fsx", PSR_f | PSR_s | PSR_x},
14575 {"fsc", PSR_f | PSR_s | PSR_c},
14576 {"fxs", PSR_f | PSR_x | PSR_s},
14577 {"fxc", PSR_f | PSR_x | PSR_c},
14578 {"fcs", PSR_f | PSR_c | PSR_s},
14579 {"fcx", PSR_f | PSR_c | PSR_x},
14580 {"sfx", PSR_s | PSR_f | PSR_x},
14581 {"sfc", PSR_s | PSR_f | PSR_c},
14582 {"sxf", PSR_s | PSR_x | PSR_f},
14583 {"sxc", PSR_s | PSR_x | PSR_c},
14584 {"scf", PSR_s | PSR_c | PSR_f},
14585 {"scx", PSR_s | PSR_c | PSR_x},
14586 {"xfs", PSR_x | PSR_f | PSR_s},
14587 {"xfc", PSR_x | PSR_f | PSR_c},
14588 {"xsf", PSR_x | PSR_s | PSR_f},
14589 {"xsc", PSR_x | PSR_s | PSR_c},
14590 {"xcf", PSR_x | PSR_c | PSR_f},
14591 {"xcs", PSR_x | PSR_c | PSR_s},
14592 {"cfs", PSR_c | PSR_f | PSR_s},
14593 {"cfx", PSR_c | PSR_f | PSR_x},
14594 {"csf", PSR_c | PSR_s | PSR_f},
14595 {"csx", PSR_c | PSR_s | PSR_x},
14596 {"cxf", PSR_c | PSR_x | PSR_f},
14597 {"cxs", PSR_c | PSR_x | PSR_s},
14598 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
14599 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
14600 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
14601 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
14602 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
14603 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
14604 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
14605 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
14606 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
14607 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
14608 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
14609 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
14610 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
14611 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
14612 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
14613 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
14614 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
14615 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
14616 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
14617 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
14618 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
14619 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
14620 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
14621 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
14622 };
14623
14624 /* Table of V7M psr names. */
14625 static const struct asm_psr v7m_psrs[] =
14626 {
14627 {"apsr", 0 }, {"APSR", 0 },
14628 {"iapsr", 1 }, {"IAPSR", 1 },
14629 {"eapsr", 2 }, {"EAPSR", 2 },
14630 {"psr", 3 }, {"PSR", 3 },
14631 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
14632 {"ipsr", 5 }, {"IPSR", 5 },
14633 {"epsr", 6 }, {"EPSR", 6 },
14634 {"iepsr", 7 }, {"IEPSR", 7 },
14635 {"msp", 8 }, {"MSP", 8 },
14636 {"psp", 9 }, {"PSP", 9 },
14637 {"primask", 16}, {"PRIMASK", 16},
14638 {"basepri", 17}, {"BASEPRI", 17},
14639 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
14640 {"faultmask", 19}, {"FAULTMASK", 19},
14641 {"control", 20}, {"CONTROL", 20}
14642 };
14643
14644 /* Table of all shift-in-operand names. */
14645 static const struct asm_shift_name shift_names [] =
14646 {
14647 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
14648 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
14649 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
14650 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
14651 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
14652 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
14653 };
14654
14655 /* Table of all explicit relocation names. */
14656 #ifdef OBJ_ELF
14657 static struct reloc_entry reloc_names[] =
14658 {
14659 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
14660 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
14661 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
14662 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
14663 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
14664 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
14665 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
14666 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
14667 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
14668 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
14669 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
14670 };
14671 #endif
14672
14673 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
14674 static const struct asm_cond conds[] =
14675 {
14676 {"eq", 0x0},
14677 {"ne", 0x1},
14678 {"cs", 0x2}, {"hs", 0x2},
14679 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
14680 {"mi", 0x4},
14681 {"pl", 0x5},
14682 {"vs", 0x6},
14683 {"vc", 0x7},
14684 {"hi", 0x8},
14685 {"ls", 0x9},
14686 {"ge", 0xa},
14687 {"lt", 0xb},
14688 {"gt", 0xc},
14689 {"le", 0xd},
14690 {"al", 0xe}
14691 };
14692
14693 static struct asm_barrier_opt barrier_opt_names[] =
14694 {
14695 { "sy", 0xf },
14696 { "un", 0x7 },
14697 { "st", 0xe },
14698 { "unst", 0x6 }
14699 };
14700
14701 /* Table of ARM-format instructions. */
14702
14703 /* Macros for gluing together operand strings. N.B. In all cases
14704 other than OPS0, the trailing OP_stop comes from default
14705 zero-initialization of the unspecified elements of the array. */
14706 #define OPS0() { OP_stop, }
14707 #define OPS1(a) { OP_##a, }
14708 #define OPS2(a,b) { OP_##a,OP_##b, }
14709 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
14710 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
14711 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
14712 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
14713
14714 /* These macros abstract out the exact format of the mnemonic table and
14715 save some repeated characters. */
14716
14717 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
14718 #define TxCE(mnem, op, top, nops, ops, ae, te) \
14719 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
14720 THUMB_VARIANT, do_##ae, do_##te }
14721
14722 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
14723 a T_MNEM_xyz enumerator. */
14724 #define TCE(mnem, aop, top, nops, ops, ae, te) \
14725 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
14726 #define tCE(mnem, aop, top, nops, ops, ae, te) \
14727 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14728
14729 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
14730 infix after the third character. */
14731 #define TxC3(mnem, op, top, nops, ops, ae, te) \
14732 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
14733 THUMB_VARIANT, do_##ae, do_##te }
14734 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
14735 { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
14736 THUMB_VARIANT, do_##ae, do_##te }
14737 #define TC3(mnem, aop, top, nops, ops, ae, te) \
14738 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
14739 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
14740 TxC3w(mnem, aop, 0x##top, nops, ops, ae, te)
14741 #define tC3(mnem, aop, top, nops, ops, ae, te) \
14742 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14743 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
14744 TxC3w(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14745
14746 /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
14747 appear in the condition table. */
14748 #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
14749 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14750 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
14751
14752 #define TxCM(m1, m2, op, top, nops, ops, ae, te) \
14753 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
14754 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
14755 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
14756 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
14757 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
14758 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
14759 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
14760 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
14761 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
14762 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
14763 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
14764 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
14765 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
14766 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
14767 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
14768 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
14769 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
14770 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
14771 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
14772
14773 #define TCM(m1,m2, aop, top, nops, ops, ae, te) \
14774 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
14775 #define tCM(m1,m2, aop, top, nops, ops, ae, te) \
14776 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
14777
14778 /* Mnemonic that cannot be conditionalized. The ARM condition-code
14779 field is still 0xE. Many of the Thumb variants can be executed
14780 conditionally, so this is checked separately. */
14781 #define TUE(mnem, op, top, nops, ops, ae, te) \
14782 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
14783 THUMB_VARIANT, do_##ae, do_##te }
14784
14785 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
14786 condition code field. */
14787 #define TUF(mnem, op, top, nops, ops, ae, te) \
14788 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
14789 THUMB_VARIANT, do_##ae, do_##te }
14790
14791 /* ARM-only variants of all the above. */
14792 #define CE(mnem, op, nops, ops, ae) \
14793 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14794
14795 #define C3(mnem, op, nops, ops, ae) \
14796 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14797
14798 /* Legacy mnemonics that always have conditional infix after the third
14799 character. */
14800 #define CL(mnem, op, nops, ops, ae) \
14801 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14802 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14803
14804 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
14805 #define cCE(mnem, op, nops, ops, ae) \
14806 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14807
14808 /* Legacy coprocessor instructions where conditional infix and conditional
14809 suffix are ambiguous. For consistency this includes all FPA instructions,
14810 not just the potentially ambiguous ones. */
14811 #define cCL(mnem, op, nops, ops, ae) \
14812 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14813 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14814
14815 /* Coprocessor, takes either a suffix or a position-3 infix
14816 (for an FPA corner case). */
14817 #define C3E(mnem, op, nops, ops, ae) \
14818 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
14819 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14820
14821 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
14822 { #m1 #m2 #m3, OPS##nops ops, \
14823 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14824 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14825
14826 #define CM(m1, m2, op, nops, ops, ae) \
14827 xCM_(m1, , m2, op, nops, ops, ae), \
14828 xCM_(m1, eq, m2, op, nops, ops, ae), \
14829 xCM_(m1, ne, m2, op, nops, ops, ae), \
14830 xCM_(m1, cs, m2, op, nops, ops, ae), \
14831 xCM_(m1, hs, m2, op, nops, ops, ae), \
14832 xCM_(m1, cc, m2, op, nops, ops, ae), \
14833 xCM_(m1, ul, m2, op, nops, ops, ae), \
14834 xCM_(m1, lo, m2, op, nops, ops, ae), \
14835 xCM_(m1, mi, m2, op, nops, ops, ae), \
14836 xCM_(m1, pl, m2, op, nops, ops, ae), \
14837 xCM_(m1, vs, m2, op, nops, ops, ae), \
14838 xCM_(m1, vc, m2, op, nops, ops, ae), \
14839 xCM_(m1, hi, m2, op, nops, ops, ae), \
14840 xCM_(m1, ls, m2, op, nops, ops, ae), \
14841 xCM_(m1, ge, m2, op, nops, ops, ae), \
14842 xCM_(m1, lt, m2, op, nops, ops, ae), \
14843 xCM_(m1, gt, m2, op, nops, ops, ae), \
14844 xCM_(m1, le, m2, op, nops, ops, ae), \
14845 xCM_(m1, al, m2, op, nops, ops, ae)
14846
14847 #define UE(mnem, op, nops, ops, ae) \
14848 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14849
14850 #define UF(mnem, op, nops, ops, ae) \
14851 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14852
14853 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
14854 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
14855 use the same encoding function for each. */
14856 #define NUF(mnem, op, nops, ops, enc) \
14857 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
14858 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14859
14860 /* Neon data processing, version which indirects through neon_enc_tab for
14861 the various overloaded versions of opcodes. */
14862 #define nUF(mnem, op, nops, ops, enc) \
14863 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \
14864 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14865
14866 /* Neon insn with conditional suffix for the ARM version, non-overloaded
14867 version. */
14868 #define NCE_tag(mnem, op, nops, ops, enc, tag) \
14869 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
14870 THUMB_VARIANT, do_##enc, do_##enc }
14871
14872 #define NCE(mnem, op, nops, ops, enc) \
14873 NCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14874
14875 #define NCEF(mnem, op, nops, ops, enc) \
14876 NCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14877
14878 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
14879 #define nCE_tag(mnem, op, nops, ops, enc, tag) \
14880 { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \
14881 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14882
14883 #define nCE(mnem, op, nops, ops, enc) \
14884 nCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14885
14886 #define nCEF(mnem, op, nops, ops, enc) \
14887 nCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14888
14889 #define do_0 0
14890
14891 /* Thumb-only, unconditional. */
14892 #define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
14893
14894 static const struct asm_opcode insns[] =
14895 {
14896 #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
14897 #define THUMB_VARIANT &arm_ext_v4t
14898 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
14899 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
14900 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
14901 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
14902 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
14903 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
14904 tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub),
14905 tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub),
14906 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
14907 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
14908 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
14909 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
14910 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
14911 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
14912 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
14913 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
14914
14915 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
14916 for setting PSR flag bits. They are obsolete in V6 and do not
14917 have Thumb equivalents. */
14918 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
14919 tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
14920 CL(tstp, 110f000, 2, (RR, SH), cmp),
14921 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
14922 tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
14923 CL(cmpp, 150f000, 2, (RR, SH), cmp),
14924 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
14925 tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
14926 CL(cmnp, 170f000, 2, (RR, SH), cmp),
14927
14928 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
14929 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
14930 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
14931 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
14932
14933 tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
14934 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
14935 tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst),
14936 tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
14937
14938 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14939 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14940 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14941 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14942 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14943 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14944
14945 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
14946 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
14947 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
14948 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
14949
14950 /* Pseudo ops. */
14951 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
14952 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
14953 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
14954
14955 /* Thumb-compatibility pseudo ops. */
14956 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
14957 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
14958 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
14959 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
14960 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
14961 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
14962 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
14963 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
14964 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
14965 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
14966 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
14967 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
14968
14969 /* These may simplify to neg. */
14970 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
14971 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
14972
14973 #undef THUMB_VARIANT
14974 #define THUMB_VARIANT &arm_ext_v6
14975 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
14976
14977 /* V1 instructions with no Thumb analogue prior to V6T2. */
14978 #undef THUMB_VARIANT
14979 #define THUMB_VARIANT &arm_ext_v6t2
14980 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
14981 TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
14982 CL(teqp, 130f000, 2, (RR, SH), cmp),
14983
14984 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
14985 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
14986 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
14987 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
14988
14989 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14990 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14991
14992 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14993 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14994
14995 /* V1 instructions with no Thumb analogue at all. */
14996 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
14997 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
14998
14999 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
15000 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
15001 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
15002 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
15003 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
15004 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
15005 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
15006 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
15007
15008 #undef ARM_VARIANT
15009 #define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
15010 #undef THUMB_VARIANT
15011 #define THUMB_VARIANT &arm_ext_v4t
15012 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15013 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15014
15015 #undef THUMB_VARIANT
15016 #define THUMB_VARIANT &arm_ext_v6t2
15017 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
15018 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
15019
15020 /* Generic coprocessor instructions. */
15021 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
15022 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15023 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15024 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15025 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15026 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15027 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15028
15029 #undef ARM_VARIANT
15030 #define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
15031 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15032 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15033
15034 #undef ARM_VARIANT
15035 #define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
15036 #undef THUMB_VARIANT
15037 #define THUMB_VARIANT &arm_ext_msr
15038 TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
15039 TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
15040
15041 #undef ARM_VARIANT
15042 #define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
15043 #undef THUMB_VARIANT
15044 #define THUMB_VARIANT &arm_ext_v6t2
15045 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15046 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15047 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15048 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15049 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15050 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15051 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15052 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15053
15054 #undef ARM_VARIANT
15055 #define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
15056 #undef THUMB_VARIANT
15057 #define THUMB_VARIANT &arm_ext_v4t
15058 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15059 tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15060 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15061 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15062 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15063 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15064
15065 #undef ARM_VARIANT
15066 #define ARM_VARIANT &arm_ext_v4t_5
15067 /* ARM Architecture 4T. */
15068 /* Note: bx (and blx) are required on V5, even if the processor does
15069 not support Thumb. */
15070 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
15071
15072 #undef ARM_VARIANT
15073 #define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
15074 #undef THUMB_VARIANT
15075 #define THUMB_VARIANT &arm_ext_v5t
15076 /* Note: blx has 2 variants; the .value coded here is for
15077 BLX(2). Only this variant has conditional execution. */
15078 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
15079 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
15080
15081 #undef THUMB_VARIANT
15082 #define THUMB_VARIANT &arm_ext_v6t2
15083 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
15084 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15085 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15086 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15087 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15088 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
15089 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15090 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15091
15092 #undef ARM_VARIANT
15093 #define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
15094 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15095 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15096 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15097 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15098
15099 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15100 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15101
15102 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15103 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15104 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15105 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15106
15107 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15108 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15109 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15110 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15111
15112 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15113 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15114
15115 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15116 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15117 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15118 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15119
15120 #undef ARM_VARIANT
15121 #define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
15122 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
15123 TC3(ldrd, 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
15124 TC3(strd, 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
15125
15126 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15127 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15128
15129 #undef ARM_VARIANT
15130 #define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
15131 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
15132
15133 #undef ARM_VARIANT
15134 #define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
15135 #undef THUMB_VARIANT
15136 #define THUMB_VARIANT &arm_ext_v6
15137 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
15138 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
15139 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15140 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15141 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15142 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15143 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15144 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15145 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15146 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
15147
15148 #undef THUMB_VARIANT
15149 #define THUMB_VARIANT &arm_ext_v6t2
15150 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
15151 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
15152 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15153 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15154
15155 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
15156 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
15157
15158 /* ARM V6 not included in V7M (eg. integer SIMD). */
15159 #undef THUMB_VARIANT
15160 #define THUMB_VARIANT &arm_ext_v6_notm
15161 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
15162 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
15163 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
15164 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15165 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15166 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15167 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15168 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15169 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15170 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15171 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15172 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15173 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15174 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15175 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15176 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15177 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15178 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15179 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15180 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15181 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15182 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15183 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15184 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15185 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15186 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15187 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15188 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15189 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15190 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15191 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15192 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15193 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15194 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15195 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15196 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15197 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15198 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15199 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15200 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15201 UF(rfeib, 9900a00, 1, (RRw), rfe),
15202 UF(rfeda, 8100a00, 1, (RRw), rfe),
15203 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15204 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15205 UF(rfefa, 9900a00, 1, (RRw), rfe),
15206 UF(rfeea, 8100a00, 1, (RRw), rfe),
15207 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15208 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15209 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15210 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15211 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15212 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15213 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15214 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15215 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15216 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15217 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15218 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15219 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15220 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15221 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15222 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15223 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15224 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15225 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15226 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15227 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15228 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15229 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15230 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15231 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15232 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15233 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15234 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15235 TUF(srsia, 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
15236 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
15237 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
15238 TUF(srsdb, 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
15239 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
15240 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
15241 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15242 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15243 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
15244
15245 #undef ARM_VARIANT
15246 #define ARM_VARIANT &arm_ext_v6k
15247 #undef THUMB_VARIANT
15248 #define THUMB_VARIANT &arm_ext_v6k
15249 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
15250 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
15251 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
15252 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
15253
15254 #undef THUMB_VARIANT
15255 #define THUMB_VARIANT &arm_ext_v6_notm
15256 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
15257 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
15258
15259 #undef THUMB_VARIANT
15260 #define THUMB_VARIANT &arm_ext_v6t2
15261 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15262 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15263 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15264 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15265 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
15266
15267 #undef ARM_VARIANT
15268 #define ARM_VARIANT &arm_ext_v6z
15269 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
15270
15271 #undef ARM_VARIANT
15272 #define ARM_VARIANT &arm_ext_v6t2
15273 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
15274 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
15275 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15276 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15277
15278 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
15279 TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
15280 TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
15281 TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
15282
15283 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15284 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15285 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15286 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15287
15288 UT(cbnz, b900, 2, (RR, EXP), t_cbz),
15289 UT(cbz, b100, 2, (RR, EXP), t_cbz),
15290 /* ARM does not really have an IT instruction, so always allow it. */
15291 #undef ARM_VARIANT
15292 #define ARM_VARIANT &arm_ext_v1
15293 TUE(it, 0, bf08, 1, (COND), it, t_it),
15294 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
15295 TUE(ite, 0, bf04, 1, (COND), it, t_it),
15296 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
15297 TUE(itet, 0, bf06, 1, (COND), it, t_it),
15298 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
15299 TUE(itee, 0, bf02, 1, (COND), it, t_it),
15300 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
15301 TUE(itett, 0, bf07, 1, (COND), it, t_it),
15302 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
15303 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
15304 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
15305 TUE(itete, 0, bf05, 1, (COND), it, t_it),
15306 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
15307 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
15308
15309 /* Thumb2 only instructions. */
15310 #undef ARM_VARIANT
15311 #define ARM_VARIANT NULL
15312
15313 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15314 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15315 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
15316 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
15317
15318 /* Thumb-2 hardware division instructions (R and M profiles only). */
15319 #undef THUMB_VARIANT
15320 #define THUMB_VARIANT &arm_ext_div
15321 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
15322 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
15323
15324 /* ARM V6M/V7 instructions. */
15325 #undef ARM_VARIANT
15326 #define ARM_VARIANT &arm_ext_barrier
15327 #undef THUMB_VARIANT
15328 #define THUMB_VARIANT &arm_ext_barrier
15329 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
15330 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
15331 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
15332
15333 /* ARM V7 instructions. */
15334 #undef ARM_VARIANT
15335 #define ARM_VARIANT &arm_ext_v7
15336 #undef THUMB_VARIANT
15337 #define THUMB_VARIANT &arm_ext_v7
15338 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
15339 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
15340
15341 #undef ARM_VARIANT
15342 #define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
15343 cCE(wfs, e200110, 1, (RR), rd),
15344 cCE(rfs, e300110, 1, (RR), rd),
15345 cCE(wfc, e400110, 1, (RR), rd),
15346 cCE(rfc, e500110, 1, (RR), rd),
15347
15348 cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
15349 cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
15350 cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
15351 cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
15352
15353 cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
15354 cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
15355 cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
15356 cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
15357
15358 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
15359 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
15360 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
15361 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
15362 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
15363 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
15364 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
15365 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
15366 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
15367 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
15368 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
15369 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
15370
15371 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
15372 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
15373 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
15374 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
15375 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
15376 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
15377 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
15378 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
15379 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
15380 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
15381 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
15382 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
15383
15384 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
15385 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
15386 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
15387 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
15388 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
15389 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
15390 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
15391 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
15392 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
15393 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
15394 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
15395 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
15396
15397 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
15398 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
15399 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
15400 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
15401 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
15402 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
15403 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
15404 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
15405 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
15406 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
15407 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
15408 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
15409
15410 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
15411 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
15412 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
15413 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
15414 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
15415 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
15416 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
15417 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
15418 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
15419 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
15420 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
15421 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
15422
15423 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
15424 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
15425 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
15426 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
15427 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
15428 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
15429 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
15430 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
15431 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
15432 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
15433 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
15434 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
15435
15436 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
15437 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
15438 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
15439 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
15440 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
15441 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
15442 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
15443 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
15444 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
15445 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
15446 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
15447 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
15448
15449 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
15450 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
15451 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
15452 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
15453 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
15454 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
15455 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
15456 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
15457 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
15458 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
15459 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
15460 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
15461
15462 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
15463 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
15464 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
15465 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
15466 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
15467 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
15468 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
15469 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
15470 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
15471 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
15472 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
15473 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
15474
15475 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
15476 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
15477 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
15478 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
15479 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
15480 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
15481 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
15482 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
15483 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
15484 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
15485 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
15486 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
15487
15488 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
15489 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
15490 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
15491 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
15492 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
15493 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
15494 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
15495 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
15496 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
15497 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
15498 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
15499 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
15500
15501 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
15502 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
15503 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
15504 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
15505 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
15506 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
15507 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
15508 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
15509 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
15510 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
15511 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
15512 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
15513
15514 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
15515 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
15516 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
15517 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
15518 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
15519 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
15520 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
15521 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
15522 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
15523 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
15524 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
15525 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
15526
15527 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
15528 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
15529 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
15530 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
15531 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
15532 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
15533 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
15534 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
15535 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
15536 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
15537 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
15538 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
15539
15540 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
15541 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
15542 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
15543 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
15544 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
15545 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
15546 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
15547 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
15548 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
15549 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
15550 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
15551 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
15552
15553 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
15554 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
15555 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
15556 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
15557 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
15558 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
15559 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
15560 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
15561 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
15562 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
15563 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
15564 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
15565
15566 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
15567 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
15568 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
15569 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
15570 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
15571 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15572 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15573 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15574 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
15575 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
15576 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
15577 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
15578
15579 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
15580 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
15581 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
15582 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
15583 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
15584 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15585 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15586 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15587 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
15588 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
15589 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
15590 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
15591
15592 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
15593 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
15594 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
15595 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
15596 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
15597 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15598 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15599 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15600 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
15601 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
15602 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
15603 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
15604
15605 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
15606 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
15607 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
15608 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
15609 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
15610 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15611 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15612 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15613 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
15614 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
15615 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
15616 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
15617
15618 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
15619 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
15620 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
15621 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
15622 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
15623 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15624 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15625 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15626 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
15627 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
15628 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
15629 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
15630
15631 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
15632 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
15633 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
15634 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
15635 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
15636 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15637 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15638 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15639 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
15640 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
15641 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
15642 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
15643
15644 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
15645 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
15646 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
15647 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
15648 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
15649 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15650 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15651 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15652 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
15653 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
15654 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
15655 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
15656
15657 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
15658 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
15659 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
15660 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
15661 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
15662 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15663 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15664 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15665 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
15666 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
15667 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
15668 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
15669
15670 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
15671 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
15672 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
15673 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
15674 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
15675 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15676 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15677 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15678 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
15679 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
15680 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
15681 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
15682
15683 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
15684 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
15685 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
15686 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
15687 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
15688 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15689 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15690 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15691 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
15692 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
15693 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
15694 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
15695
15696 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15697 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15698 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15699 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15700 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15701 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15702 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15703 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15704 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15705 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15706 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15707 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15708
15709 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15710 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15711 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15712 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15713 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15714 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15715 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15716 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15717 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15718 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15719 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15720 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15721
15722 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15723 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15724 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15725 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15726 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15727 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15728 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15729 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15730 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15731 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15732 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15733 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15734
15735 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
15736 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
15737 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
15738 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
15739
15740 cCL(flts, e000110, 2, (RF, RR), rn_rd),
15741 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
15742 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
15743 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
15744 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
15745 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
15746 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
15747 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
15748 cCL(flte, e080110, 2, (RF, RR), rn_rd),
15749 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
15750 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
15751 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
15752
15753 /* The implementation of the FIX instruction is broken on some
15754 assemblers, in that it accepts a precision specifier as well as a
15755 rounding specifier, despite the fact that this is meaningless.
15756 To be more compatible, we accept it as well, though of course it
15757 does not set any bits. */
15758 cCE(fix, e100110, 2, (RR, RF), rd_rm),
15759 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
15760 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
15761 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
15762 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
15763 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
15764 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
15765 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
15766 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
15767 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
15768 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
15769 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
15770 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
15771
15772 /* Instructions that were new with the real FPA, call them V2. */
15773 #undef ARM_VARIANT
15774 #define ARM_VARIANT &fpu_fpa_ext_v2
15775 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15776 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15777 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15778 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15779 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15780 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15781
15782 #undef ARM_VARIANT
15783 #define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
15784 /* Moves and type conversions. */
15785 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
15786 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
15787 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
15788 cCE(fmstat, ef1fa10, 0, (), noargs),
15789 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
15790 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
15791 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
15792 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15793 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
15794 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15795 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
15796 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
15797
15798 /* Memory operations. */
15799 cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15800 cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15801 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15802 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15803 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15804 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15805 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15806 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15807 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15808 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15809 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15810 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15811 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15812 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15813 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15814 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15815 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15816 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15817
15818 /* Monadic operations. */
15819 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
15820 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
15821 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
15822
15823 /* Dyadic operations. */
15824 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15825 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15826 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15827 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15828 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15829 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15830 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15831 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15832 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15833
15834 /* Comparisons. */
15835 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
15836 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
15837 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
15838 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
15839
15840 #undef ARM_VARIANT
15841 #define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
15842 /* Moves and type conversions. */
15843 cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15844 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15845 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15846 cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
15847 cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
15848 cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
15849 cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
15850 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15851 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
15852 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15853 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15854 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15855 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15856
15857 /* Memory operations. */
15858 cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
15859 cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
15860 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15861 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15862 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15863 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15864 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15865 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15866 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15867 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15868
15869 /* Monadic operations. */
15870 cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15871 cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15872 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15873
15874 /* Dyadic operations. */
15875 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15876 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15877 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15878 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15879 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15880 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15881 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15882 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15883 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15884
15885 /* Comparisons. */
15886 cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15887 cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd),
15888 cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15889 cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd),
15890
15891 #undef ARM_VARIANT
15892 #define ARM_VARIANT &fpu_vfp_ext_v2
15893 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
15894 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
15895 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
15896 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
15897
15898 /* Instructions which may belong to either the Neon or VFP instruction sets.
15899 Individual encoder functions perform additional architecture checks. */
15900 #undef ARM_VARIANT
15901 #define ARM_VARIANT &fpu_vfp_ext_v1xd
15902 #undef THUMB_VARIANT
15903 #define THUMB_VARIANT &fpu_vfp_ext_v1xd
15904 /* These mnemonics are unique to VFP. */
15905 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
15906 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
15907 nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15908 nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15909 nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15910 nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15911 nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15912 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
15913 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
15914 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
15915
15916 /* Mnemonics shared by Neon and VFP. */
15917 nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
15918 nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15919 nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15920
15921 nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15922 nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15923
15924 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15925 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15926
15927 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15928 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15929 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15930 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15931 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15932 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15933 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
15934 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
15935
15936 nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
15937
15938 /* NOTE: All VMOV encoding is special-cased! */
15939 NCE(vmov, 0, 1, (VMOV), neon_mov),
15940 NCE(vmovq, 0, 1, (VMOV), neon_mov),
15941
15942 #undef THUMB_VARIANT
15943 #define THUMB_VARIANT &fpu_neon_ext_v1
15944 #undef ARM_VARIANT
15945 #define ARM_VARIANT &fpu_neon_ext_v1
15946 /* Data processing with three registers of the same length. */
15947 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
15948 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
15949 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
15950 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15951 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15952 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15953 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15954 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15955 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15956 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
15957 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15958 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15959 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15960 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15961 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15962 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
15963 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15964 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
15965 /* If not immediate, fall back to neon_dyadic_i64_su.
15966 shl_imm should accept I8 I16 I32 I64,
15967 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
15968 nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
15969 nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
15970 nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
15971 nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
15972 /* Logic ops, types optional & ignored. */
15973 nUF(vand, vand, 2, (RNDQ, NILO), neon_logic),
15974 nUF(vandq, vand, 2, (RNQ, NILO), neon_logic),
15975 nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic),
15976 nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic),
15977 nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic),
15978 nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic),
15979 nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic),
15980 nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic),
15981 nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
15982 nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
15983 /* Bitfield ops, untyped. */
15984 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15985 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15986 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15987 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15988 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15989 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15990 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
15991 nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15992 nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15993 nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15994 nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15995 nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15996 nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15997 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
15998 back to neon_dyadic_if_su. */
15999 nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
16000 nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
16001 nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
16002 nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
16003 nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16004 nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
16005 nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16006 nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
16007 /* Comparison. Type I8 I16 I32 F32. */
16008 nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
16009 nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
16010 /* As above, D registers only. */
16011 nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16012 nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16013 /* Int and float variants, signedness unimportant. */
16014 nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
16015 nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
16016 nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
16017 /* Add/sub take types I8 I16 I32 I64 F32. */
16018 nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
16019 nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
16020 /* vtst takes sizes 8, 16, 32. */
16021 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
16022 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
16023 /* VMUL takes I8 I16 I32 F32 P8. */
16024 nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
16025 /* VQD{R}MULH takes S16 S32. */
16026 nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16027 nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16028 nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16029 nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16030 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16031 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
16032 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16033 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
16034 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16035 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
16036 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16037 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
16038 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16039 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16040 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16041 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16042
16043 /* Two address, int/float. Types S8 S16 S32 F32. */
16044 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
16045 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
16046
16047 /* Data processing with two registers and a shift amount. */
16048 /* Right shifts, and variants with rounding.
16049 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
16050 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16051 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16052 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16053 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16054 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16055 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16056 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16057 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16058 /* Shift and insert. Sizes accepted 8 16 32 64. */
16059 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
16060 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
16061 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
16062 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
16063 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
16064 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
16065 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
16066 /* Right shift immediate, saturating & narrowing, with rounding variants.
16067 Types accepted S16 S32 S64 U16 U32 U64. */
16068 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16069 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16070 /* As above, unsigned. Types accepted S16 S32 S64. */
16071 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16072 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16073 /* Right shift narrowing. Types accepted I16 I32 I64. */
16074 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16075 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16076 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
16077 nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll),
16078 /* CVT with optional immediate for fixed-point variant. */
16079 nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
16080
16081 nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
16082 nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
16083
16084 /* Data processing, three registers of different lengths. */
16085 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
16086 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
16087 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
16088 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
16089 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
16090 /* If not scalar, fall back to neon_dyadic_long.
16091 Vector types as above, scalar types S16 S32 U16 U32. */
16092 nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16093 nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16094 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
16095 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16096 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16097 /* Dyadic, narrowing insns. Types I16 I32 I64. */
16098 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16099 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16100 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16101 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16102 /* Saturating doubling multiplies. Types S16 S32. */
16103 nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16104 nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16105 nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16106 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
16107 S16 S32 U16 U32. */
16108 nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
16109
16110 /* Extract. Size 8. */
16111 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
16112 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
16113
16114 /* Two registers, miscellaneous. */
16115 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
16116 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
16117 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
16118 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
16119 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
16120 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
16121 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
16122 /* Vector replicate. Sizes 8 16 32. */
16123 nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup),
16124 nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup),
16125 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
16126 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
16127 /* VMOVN. Types I16 I32 I64. */
16128 nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn),
16129 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
16130 nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn),
16131 /* VQMOVUN. Types S16 S32 S64. */
16132 nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun),
16133 /* VZIP / VUZP. Sizes 8 16 32. */
16134 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
16135 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
16136 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
16137 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
16138 /* VQABS / VQNEG. Types S8 S16 S32. */
16139 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16140 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
16141 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16142 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
16143 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
16144 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
16145 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
16146 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
16147 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
16148 /* Reciprocal estimates. Types U32 F32. */
16149 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
16150 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
16151 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
16152 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
16153 /* VCLS. Types S8 S16 S32. */
16154 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
16155 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
16156 /* VCLZ. Types I8 I16 I32. */
16157 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
16158 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
16159 /* VCNT. Size 8. */
16160 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
16161 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
16162 /* Two address, untyped. */
16163 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
16164 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
16165 /* VTRN. Sizes 8 16 32. */
16166 nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn),
16167 nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn),
16168
16169 /* Table lookup. Size 8. */
16170 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16171 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16172
16173 #undef THUMB_VARIANT
16174 #define THUMB_VARIANT &fpu_vfp_v3_or_neon_ext
16175 #undef ARM_VARIANT
16176 #define ARM_VARIANT &fpu_vfp_v3_or_neon_ext
16177 /* Neon element/structure load/store. */
16178 nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16179 nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16180 nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16181 nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16182 nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16183 nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16184 nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16185 nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16186
16187 #undef THUMB_VARIANT
16188 #define THUMB_VARIANT &fpu_vfp_ext_v3
16189 #undef ARM_VARIANT
16190 #define ARM_VARIANT &fpu_vfp_ext_v3
16191 cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const),
16192 cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const),
16193 cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16194 cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16195 cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16196 cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16197 cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16198 cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16199 cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16200 cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16201 cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16202 cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16203 cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16204 cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16205 cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16206 cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16207 cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16208 cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16209
16210 #undef THUMB_VARIANT
16211 #undef ARM_VARIANT
16212 #define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
16213 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16214 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16215 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16216 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16217 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16218 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16219 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
16220 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
16221
16222 #undef ARM_VARIANT
16223 #define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
16224 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
16225 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
16226 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
16227 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
16228 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
16229 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
16230 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
16231 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
16232 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
16233 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16234 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16235 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16236 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16237 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16238 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16239 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16240 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16241 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16242 cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd),
16243 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
16244 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16245 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16246 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16247 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16248 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16249 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16250 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
16251 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
16252 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
16253 cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn),
16254 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
16255 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
16256 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
16257 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
16258 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
16259 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
16260 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
16261 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16262 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16263 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16264 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16265 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16266 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16267 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16268 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16269 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16270 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
16271 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16272 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16273 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16274 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16275 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16276 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16277 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16278 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16279 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16280 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16281 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16282 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16283 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16284 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16285 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16286 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16287 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16288 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16289 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16290 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16291 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16292 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16293 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16294 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16295 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16296 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16297 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16298 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16299 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16300 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16301 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16302 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16303 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16304 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16305 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16306 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16307 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16308 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16309 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16310 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16311 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16312 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
16313 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16314 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16315 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16316 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16317 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16318 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16319 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16320 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16321 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16322 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16323 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16324 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16325 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16326 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16327 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16328 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16329 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16330 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16331 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16332 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16333 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16334 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
16335 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16336 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16337 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16338 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16339 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16340 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16341 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16342 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16343 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16344 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16345 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16346 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16347 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16348 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16349 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16350 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16351 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16352 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16353 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16354 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16355 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16356 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16357 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16358 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16359 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16360 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16361 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16362 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16363 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16364 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16365 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16366 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
16367 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
16368 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
16369 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
16370 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
16371 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
16372 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16373 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16374 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16375 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
16376 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
16377 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
16378 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
16379 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
16380 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
16381 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16382 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16383 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16384 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16385 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
16386
16387 #undef ARM_VARIANT
16388 #define ARM_VARIANT &arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
16389 cCE(torvscb, e13f190, 1, (RR), iwmmxt_tandorc),
16390 cCE(torvsch, e53f190, 1, (RR), iwmmxt_tandorc),
16391 cCE(torvscw, e93f190, 1, (RR), iwmmxt_tandorc),
16392 cCE(wabsb, e2001c0, 2, (RIWR, RIWR), rd_rn),
16393 cCE(wabsh, e6001c0, 2, (RIWR, RIWR), rd_rn),
16394 cCE(wabsw, ea001c0, 2, (RIWR, RIWR), rd_rn),
16395 cCE(wabsdiffb, e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16396 cCE(wabsdiffh, e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16397 cCE(wabsdiffw, e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16398 cCE(waddbhusl, e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16399 cCE(waddbhusm, e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16400 cCE(waddhc, e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16401 cCE(waddwc, ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16402 cCE(waddsubhx, ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16403 cCE(wavg4, e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16404 cCE(wavg4r, e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16405 cCE(wmaddsn, ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16406 cCE(wmaddsx, eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16407 cCE(wmaddun, ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16408 cCE(wmaddux, e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16409 cCE(wmerge, e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
16410 cCE(wmiabb, e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16411 cCE(wmiabt, e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16412 cCE(wmiatb, e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16413 cCE(wmiatt, e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16414 cCE(wmiabbn, e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16415 cCE(wmiabtn, e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16416 cCE(wmiatbn, e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16417 cCE(wmiattn, e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16418 cCE(wmiawbb, e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16419 cCE(wmiawbt, e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16420 cCE(wmiawtb, ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16421 cCE(wmiawtt, eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16422 cCE(wmiawbbn, ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16423 cCE(wmiawbtn, ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16424 cCE(wmiawtbn, ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16425 cCE(wmiawttn, ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16426 cCE(wmulsmr, ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16427 cCE(wmulumr, ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16428 cCE(wmulwumr, ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16429 cCE(wmulwsmr, ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16430 cCE(wmulwum, ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16431 cCE(wmulwsm, ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16432 cCE(wmulwl, eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16433 cCE(wqmiabb, e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16434 cCE(wqmiabt, e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16435 cCE(wqmiatb, ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16436 cCE(wqmiatt, eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16437 cCE(wqmiabbn, ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16438 cCE(wqmiabtn, ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16439 cCE(wqmiatbn, ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16440 cCE(wqmiattn, ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16441 cCE(wqmulm, e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16442 cCE(wqmulmr, e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16443 cCE(wqmulwm, ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16444 cCE(wqmulwmr, ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16445 cCE(wsubaddhx, ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16446
16447 #undef ARM_VARIANT
16448 #define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
16449 cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16450 cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16451 cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16452 cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
16453 cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16454 cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16455 cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16456 cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
16457 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
16458 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
16459 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
16460 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
16461 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
16462 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
16463 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
16464 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
16465 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
16466 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
16467 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
16468 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
16469 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
16470 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
16471 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
16472 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
16473 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
16474 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
16475 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
16476 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
16477 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
16478 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
16479 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
16480 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
16481 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
16482 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
16483 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
16484 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
16485 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
16486 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
16487 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
16488 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
16489 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
16490 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
16491 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
16492 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
16493 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
16494 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
16495 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
16496 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
16497 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
16498 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
16499 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
16500 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
16501 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
16502 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
16503 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
16504 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
16505 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
16506 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
16507 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
16508 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
16509 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
16510 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
16511 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
16512 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
16513 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16514 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16515 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16516 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16517 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16518 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16519 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16520 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16521 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16522 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16523 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
16524 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
16525 };
16526 #undef ARM_VARIANT
16527 #undef THUMB_VARIANT
16528 #undef TCE
16529 #undef TCM
16530 #undef TUE
16531 #undef TUF
16532 #undef TCC
16533 #undef cCE
16534 #undef cCL
16535 #undef C3E
16536 #undef CE
16537 #undef CM
16538 #undef UE
16539 #undef UF
16540 #undef UT
16541 #undef NUF
16542 #undef nUF
16543 #undef NCE
16544 #undef nCE
16545 #undef OPS0
16546 #undef OPS1
16547 #undef OPS2
16548 #undef OPS3
16549 #undef OPS4
16550 #undef OPS5
16551 #undef OPS6
16552 #undef do_0
16553 \f
16554 /* MD interface: bits in the object file. */
16555
16556 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
16557 for use in the a.out file, and stores them in the array pointed to by buf.
16558 This knows about the endian-ness of the target machine and does
16559 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
16560 2 (short) and 4 (long) Floating numbers are put out as a series of
16561 LITTLENUMS (shorts, here at least). */
16562
16563 void
16564 md_number_to_chars (char * buf, valueT val, int n)
16565 {
16566 if (target_big_endian)
16567 number_to_chars_bigendian (buf, val, n);
16568 else
16569 number_to_chars_littleendian (buf, val, n);
16570 }
16571
16572 static valueT
16573 md_chars_to_number (char * buf, int n)
16574 {
16575 valueT result = 0;
16576 unsigned char * where = (unsigned char *) buf;
16577
16578 if (target_big_endian)
16579 {
16580 while (n--)
16581 {
16582 result <<= 8;
16583 result |= (*where++ & 255);
16584 }
16585 }
16586 else
16587 {
16588 while (n--)
16589 {
16590 result <<= 8;
16591 result |= (where[n] & 255);
16592 }
16593 }
16594
16595 return result;
16596 }
16597
16598 /* MD interface: Sections. */
16599
16600 /* Estimate the size of a frag before relaxing. Assume everything fits in
16601 2 bytes. */
16602
16603 int
16604 md_estimate_size_before_relax (fragS * fragp,
16605 segT segtype ATTRIBUTE_UNUSED)
16606 {
16607 fragp->fr_var = 2;
16608 return 2;
16609 }
16610
16611 /* Convert a machine dependent frag. */
16612
16613 void
16614 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
16615 {
16616 unsigned long insn;
16617 unsigned long old_op;
16618 char *buf;
16619 expressionS exp;
16620 fixS *fixp;
16621 int reloc_type;
16622 int pc_rel;
16623 int opcode;
16624
16625 buf = fragp->fr_literal + fragp->fr_fix;
16626
16627 old_op = bfd_get_16(abfd, buf);
16628 if (fragp->fr_symbol)
16629 {
16630 exp.X_op = O_symbol;
16631 exp.X_add_symbol = fragp->fr_symbol;
16632 }
16633 else
16634 {
16635 exp.X_op = O_constant;
16636 }
16637 exp.X_add_number = fragp->fr_offset;
16638 opcode = fragp->fr_subtype;
16639 switch (opcode)
16640 {
16641 case T_MNEM_ldr_pc:
16642 case T_MNEM_ldr_pc2:
16643 case T_MNEM_ldr_sp:
16644 case T_MNEM_str_sp:
16645 case T_MNEM_ldr:
16646 case T_MNEM_ldrb:
16647 case T_MNEM_ldrh:
16648 case T_MNEM_str:
16649 case T_MNEM_strb:
16650 case T_MNEM_strh:
16651 if (fragp->fr_var == 4)
16652 {
16653 insn = THUMB_OP32 (opcode);
16654 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
16655 {
16656 insn |= (old_op & 0x700) << 4;
16657 }
16658 else
16659 {
16660 insn |= (old_op & 7) << 12;
16661 insn |= (old_op & 0x38) << 13;
16662 }
16663 insn |= 0x00000c00;
16664 put_thumb32_insn (buf, insn);
16665 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
16666 }
16667 else
16668 {
16669 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
16670 }
16671 pc_rel = (opcode == T_MNEM_ldr_pc2);
16672 break;
16673 case T_MNEM_adr:
16674 if (fragp->fr_var == 4)
16675 {
16676 insn = THUMB_OP32 (opcode);
16677 insn |= (old_op & 0xf0) << 4;
16678 put_thumb32_insn (buf, insn);
16679 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
16680 }
16681 else
16682 {
16683 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16684 exp.X_add_number -= 4;
16685 }
16686 pc_rel = 1;
16687 break;
16688 case T_MNEM_mov:
16689 case T_MNEM_movs:
16690 case T_MNEM_cmp:
16691 case T_MNEM_cmn:
16692 if (fragp->fr_var == 4)
16693 {
16694 int r0off = (opcode == T_MNEM_mov
16695 || opcode == T_MNEM_movs) ? 0 : 8;
16696 insn = THUMB_OP32 (opcode);
16697 insn = (insn & 0xe1ffffff) | 0x10000000;
16698 insn |= (old_op & 0x700) << r0off;
16699 put_thumb32_insn (buf, insn);
16700 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16701 }
16702 else
16703 {
16704 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
16705 }
16706 pc_rel = 0;
16707 break;
16708 case T_MNEM_b:
16709 if (fragp->fr_var == 4)
16710 {
16711 insn = THUMB_OP32(opcode);
16712 put_thumb32_insn (buf, insn);
16713 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
16714 }
16715 else
16716 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
16717 pc_rel = 1;
16718 break;
16719 case T_MNEM_bcond:
16720 if (fragp->fr_var == 4)
16721 {
16722 insn = THUMB_OP32(opcode);
16723 insn |= (old_op & 0xf00) << 14;
16724 put_thumb32_insn (buf, insn);
16725 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
16726 }
16727 else
16728 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
16729 pc_rel = 1;
16730 break;
16731 case T_MNEM_add_sp:
16732 case T_MNEM_add_pc:
16733 case T_MNEM_inc_sp:
16734 case T_MNEM_dec_sp:
16735 if (fragp->fr_var == 4)
16736 {
16737 /* ??? Choose between add and addw. */
16738 insn = THUMB_OP32 (opcode);
16739 insn |= (old_op & 0xf0) << 4;
16740 put_thumb32_insn (buf, insn);
16741 if (opcode == T_MNEM_add_pc)
16742 reloc_type = BFD_RELOC_ARM_T32_IMM12;
16743 else
16744 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16745 }
16746 else
16747 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16748 pc_rel = 0;
16749 break;
16750
16751 case T_MNEM_addi:
16752 case T_MNEM_addis:
16753 case T_MNEM_subi:
16754 case T_MNEM_subis:
16755 if (fragp->fr_var == 4)
16756 {
16757 insn = THUMB_OP32 (opcode);
16758 insn |= (old_op & 0xf0) << 4;
16759 insn |= (old_op & 0xf) << 16;
16760 put_thumb32_insn (buf, insn);
16761 if (insn & (1 << 20))
16762 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16763 else
16764 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16765 }
16766 else
16767 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16768 pc_rel = 0;
16769 break;
16770 default:
16771 abort ();
16772 }
16773 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
16774 reloc_type);
16775 fixp->fx_file = fragp->fr_file;
16776 fixp->fx_line = fragp->fr_line;
16777 fragp->fr_fix += fragp->fr_var;
16778 }
16779
16780 /* Return the size of a relaxable immediate operand instruction.
16781 SHIFT and SIZE specify the form of the allowable immediate. */
16782 static int
16783 relax_immediate (fragS *fragp, int size, int shift)
16784 {
16785 offsetT offset;
16786 offsetT mask;
16787 offsetT low;
16788
16789 /* ??? Should be able to do better than this. */
16790 if (fragp->fr_symbol)
16791 return 4;
16792
16793 low = (1 << shift) - 1;
16794 mask = (1 << (shift + size)) - (1 << shift);
16795 offset = fragp->fr_offset;
16796 /* Force misaligned offsets to 32-bit variant. */
16797 if (offset & low)
16798 return 4;
16799 if (offset & ~mask)
16800 return 4;
16801 return 2;
16802 }
16803
16804 /* Get the address of a symbol during relaxation. */
16805 static addressT
16806 relaxed_symbol_addr (fragS *fragp, long stretch)
16807 {
16808 fragS *sym_frag;
16809 addressT addr;
16810 symbolS *sym;
16811
16812 sym = fragp->fr_symbol;
16813 sym_frag = symbol_get_frag (sym);
16814 know (S_GET_SEGMENT (sym) != absolute_section
16815 || sym_frag == &zero_address_frag);
16816 addr = S_GET_VALUE (sym) + fragp->fr_offset;
16817
16818 /* If frag has yet to be reached on this pass, assume it will
16819 move by STRETCH just as we did. If this is not so, it will
16820 be because some frag between grows, and that will force
16821 another pass. */
16822
16823 if (stretch != 0
16824 && sym_frag->relax_marker != fragp->relax_marker)
16825 {
16826 fragS *f;
16827
16828 /* Adjust stretch for any alignment frag. Note that if have
16829 been expanding the earlier code, the symbol may be
16830 defined in what appears to be an earlier frag. FIXME:
16831 This doesn't handle the fr_subtype field, which specifies
16832 a maximum number of bytes to skip when doing an
16833 alignment. */
16834 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
16835 {
16836 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
16837 {
16838 if (stretch < 0)
16839 stretch = - ((- stretch)
16840 & ~ ((1 << (int) f->fr_offset) - 1));
16841 else
16842 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
16843 if (stretch == 0)
16844 break;
16845 }
16846 }
16847 if (f != NULL)
16848 addr += stretch;
16849 }
16850
16851 return addr;
16852 }
16853
16854 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
16855 load. */
16856 static int
16857 relax_adr (fragS *fragp, asection *sec, long stretch)
16858 {
16859 addressT addr;
16860 offsetT val;
16861
16862 /* Assume worst case for symbols not known to be in the same section. */
16863 if (!S_IS_DEFINED (fragp->fr_symbol)
16864 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16865 return 4;
16866
16867 val = relaxed_symbol_addr (fragp, stretch);
16868 addr = fragp->fr_address + fragp->fr_fix;
16869 addr = (addr + 4) & ~3;
16870 /* Force misaligned targets to 32-bit variant. */
16871 if (val & 3)
16872 return 4;
16873 val -= addr;
16874 if (val < 0 || val > 1020)
16875 return 4;
16876 return 2;
16877 }
16878
16879 /* Return the size of a relaxable add/sub immediate instruction. */
16880 static int
16881 relax_addsub (fragS *fragp, asection *sec)
16882 {
16883 char *buf;
16884 int op;
16885
16886 buf = fragp->fr_literal + fragp->fr_fix;
16887 op = bfd_get_16(sec->owner, buf);
16888 if ((op & 0xf) == ((op >> 4) & 0xf))
16889 return relax_immediate (fragp, 8, 0);
16890 else
16891 return relax_immediate (fragp, 3, 0);
16892 }
16893
16894
16895 /* Return the size of a relaxable branch instruction. BITS is the
16896 size of the offset field in the narrow instruction. */
16897
16898 static int
16899 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
16900 {
16901 addressT addr;
16902 offsetT val;
16903 offsetT limit;
16904
16905 /* Assume worst case for symbols not known to be in the same section. */
16906 if (!S_IS_DEFINED (fragp->fr_symbol)
16907 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16908 return 4;
16909
16910 val = relaxed_symbol_addr (fragp, stretch);
16911 addr = fragp->fr_address + fragp->fr_fix + 4;
16912 val -= addr;
16913
16914 /* Offset is a signed value *2 */
16915 limit = 1 << bits;
16916 if (val >= limit || val < -limit)
16917 return 4;
16918 return 2;
16919 }
16920
16921
16922 /* Relax a machine dependent frag. This returns the amount by which
16923 the current size of the frag should change. */
16924
16925 int
16926 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
16927 {
16928 int oldsize;
16929 int newsize;
16930
16931 oldsize = fragp->fr_var;
16932 switch (fragp->fr_subtype)
16933 {
16934 case T_MNEM_ldr_pc2:
16935 newsize = relax_adr (fragp, sec, stretch);
16936 break;
16937 case T_MNEM_ldr_pc:
16938 case T_MNEM_ldr_sp:
16939 case T_MNEM_str_sp:
16940 newsize = relax_immediate (fragp, 8, 2);
16941 break;
16942 case T_MNEM_ldr:
16943 case T_MNEM_str:
16944 newsize = relax_immediate (fragp, 5, 2);
16945 break;
16946 case T_MNEM_ldrh:
16947 case T_MNEM_strh:
16948 newsize = relax_immediate (fragp, 5, 1);
16949 break;
16950 case T_MNEM_ldrb:
16951 case T_MNEM_strb:
16952 newsize = relax_immediate (fragp, 5, 0);
16953 break;
16954 case T_MNEM_adr:
16955 newsize = relax_adr (fragp, sec, stretch);
16956 break;
16957 case T_MNEM_mov:
16958 case T_MNEM_movs:
16959 case T_MNEM_cmp:
16960 case T_MNEM_cmn:
16961 newsize = relax_immediate (fragp, 8, 0);
16962 break;
16963 case T_MNEM_b:
16964 newsize = relax_branch (fragp, sec, 11, stretch);
16965 break;
16966 case T_MNEM_bcond:
16967 newsize = relax_branch (fragp, sec, 8, stretch);
16968 break;
16969 case T_MNEM_add_sp:
16970 case T_MNEM_add_pc:
16971 newsize = relax_immediate (fragp, 8, 2);
16972 break;
16973 case T_MNEM_inc_sp:
16974 case T_MNEM_dec_sp:
16975 newsize = relax_immediate (fragp, 7, 2);
16976 break;
16977 case T_MNEM_addi:
16978 case T_MNEM_addis:
16979 case T_MNEM_subi:
16980 case T_MNEM_subis:
16981 newsize = relax_addsub (fragp, sec);
16982 break;
16983 default:
16984 abort ();
16985 }
16986
16987 fragp->fr_var = newsize;
16988 /* Freeze wide instructions that are at or before the same location as
16989 in the previous pass. This avoids infinite loops.
16990 Don't freeze them unconditionally because targets may be artificially
16991 misaligned by the expansion of preceding frags. */
16992 if (stretch <= 0 && newsize > 2)
16993 {
16994 md_convert_frag (sec->owner, sec, fragp);
16995 frag_wane (fragp);
16996 }
16997
16998 return newsize - oldsize;
16999 }
17000
17001 /* Round up a section size to the appropriate boundary. */
17002
17003 valueT
17004 md_section_align (segT segment ATTRIBUTE_UNUSED,
17005 valueT size)
17006 {
17007 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
17008 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
17009 {
17010 /* For a.out, force the section size to be aligned. If we don't do
17011 this, BFD will align it for us, but it will not write out the
17012 final bytes of the section. This may be a bug in BFD, but it is
17013 easier to fix it here since that is how the other a.out targets
17014 work. */
17015 int align;
17016
17017 align = bfd_get_section_alignment (stdoutput, segment);
17018 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
17019 }
17020 #endif
17021
17022 return size;
17023 }
17024
17025 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
17026 of an rs_align_code fragment. */
17027
17028 void
17029 arm_handle_align (fragS * fragP)
17030 {
17031 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
17032 static char const thumb_noop[2] = { 0xc0, 0x46 };
17033 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
17034 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
17035
17036 int bytes, fix, noop_size;
17037 char * p;
17038 const char * noop;
17039
17040 if (fragP->fr_type != rs_align_code)
17041 return;
17042
17043 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
17044 p = fragP->fr_literal + fragP->fr_fix;
17045 fix = 0;
17046
17047 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
17048 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
17049
17050 if (fragP->tc_frag_data)
17051 {
17052 if (target_big_endian)
17053 noop = thumb_bigend_noop;
17054 else
17055 noop = thumb_noop;
17056 noop_size = sizeof (thumb_noop);
17057 }
17058 else
17059 {
17060 if (target_big_endian)
17061 noop = arm_bigend_noop;
17062 else
17063 noop = arm_noop;
17064 noop_size = sizeof (arm_noop);
17065 }
17066
17067 if (bytes & (noop_size - 1))
17068 {
17069 fix = bytes & (noop_size - 1);
17070 memset (p, 0, fix);
17071 p += fix;
17072 bytes -= fix;
17073 }
17074
17075 while (bytes >= noop_size)
17076 {
17077 memcpy (p, noop, noop_size);
17078 p += noop_size;
17079 bytes -= noop_size;
17080 fix += noop_size;
17081 }
17082
17083 fragP->fr_fix += fix;
17084 fragP->fr_var = noop_size;
17085 }
17086
17087 /* Called from md_do_align. Used to create an alignment
17088 frag in a code section. */
17089
17090 void
17091 arm_frag_align_code (int n, int max)
17092 {
17093 char * p;
17094
17095 /* We assume that there will never be a requirement
17096 to support alignments greater than 32 bytes. */
17097 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
17098 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
17099
17100 p = frag_var (rs_align_code,
17101 MAX_MEM_FOR_RS_ALIGN_CODE,
17102 1,
17103 (relax_substateT) max,
17104 (symbolS *) NULL,
17105 (offsetT) n,
17106 (char *) NULL);
17107 *p = 0;
17108 }
17109
17110 /* Perform target specific initialisation of a frag. */
17111
17112 void
17113 arm_init_frag (fragS * fragP)
17114 {
17115 /* Record whether this frag is in an ARM or a THUMB area. */
17116 fragP->tc_frag_data = thumb_mode;
17117 }
17118
17119 #ifdef OBJ_ELF
17120 /* When we change sections we need to issue a new mapping symbol. */
17121
17122 void
17123 arm_elf_change_section (void)
17124 {
17125 flagword flags;
17126 segment_info_type *seginfo;
17127
17128 /* Link an unlinked unwind index table section to the .text section. */
17129 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
17130 && elf_linked_to_section (now_seg) == NULL)
17131 elf_linked_to_section (now_seg) = text_section;
17132
17133 if (!SEG_NORMAL (now_seg))
17134 return;
17135
17136 flags = bfd_get_section_flags (stdoutput, now_seg);
17137
17138 /* We can ignore sections that only contain debug info. */
17139 if ((flags & SEC_ALLOC) == 0)
17140 return;
17141
17142 seginfo = seg_info (now_seg);
17143 mapstate = seginfo->tc_segment_info_data.mapstate;
17144 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
17145 }
17146
17147 int
17148 arm_elf_section_type (const char * str, size_t len)
17149 {
17150 if (len == 5 && strncmp (str, "exidx", 5) == 0)
17151 return SHT_ARM_EXIDX;
17152
17153 return -1;
17154 }
17155 \f
17156 /* Code to deal with unwinding tables. */
17157
17158 static void add_unwind_adjustsp (offsetT);
17159
17160 /* Generate any deferred unwind frame offset. */
17161
17162 static void
17163 flush_pending_unwind (void)
17164 {
17165 offsetT offset;
17166
17167 offset = unwind.pending_offset;
17168 unwind.pending_offset = 0;
17169 if (offset != 0)
17170 add_unwind_adjustsp (offset);
17171 }
17172
17173 /* Add an opcode to this list for this function. Two-byte opcodes should
17174 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
17175 order. */
17176
17177 static void
17178 add_unwind_opcode (valueT op, int length)
17179 {
17180 /* Add any deferred stack adjustment. */
17181 if (unwind.pending_offset)
17182 flush_pending_unwind ();
17183
17184 unwind.sp_restored = 0;
17185
17186 if (unwind.opcode_count + length > unwind.opcode_alloc)
17187 {
17188 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
17189 if (unwind.opcodes)
17190 unwind.opcodes = xrealloc (unwind.opcodes,
17191 unwind.opcode_alloc);
17192 else
17193 unwind.opcodes = xmalloc (unwind.opcode_alloc);
17194 }
17195 while (length > 0)
17196 {
17197 length--;
17198 unwind.opcodes[unwind.opcode_count] = op & 0xff;
17199 op >>= 8;
17200 unwind.opcode_count++;
17201 }
17202 }
17203
17204 /* Add unwind opcodes to adjust the stack pointer. */
17205
17206 static void
17207 add_unwind_adjustsp (offsetT offset)
17208 {
17209 valueT op;
17210
17211 if (offset > 0x200)
17212 {
17213 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
17214 char bytes[5];
17215 int n;
17216 valueT o;
17217
17218 /* Long form: 0xb2, uleb128. */
17219 /* This might not fit in a word so add the individual bytes,
17220 remembering the list is built in reverse order. */
17221 o = (valueT) ((offset - 0x204) >> 2);
17222 if (o == 0)
17223 add_unwind_opcode (0, 1);
17224
17225 /* Calculate the uleb128 encoding of the offset. */
17226 n = 0;
17227 while (o)
17228 {
17229 bytes[n] = o & 0x7f;
17230 o >>= 7;
17231 if (o)
17232 bytes[n] |= 0x80;
17233 n++;
17234 }
17235 /* Add the insn. */
17236 for (; n; n--)
17237 add_unwind_opcode (bytes[n - 1], 1);
17238 add_unwind_opcode (0xb2, 1);
17239 }
17240 else if (offset > 0x100)
17241 {
17242 /* Two short opcodes. */
17243 add_unwind_opcode (0x3f, 1);
17244 op = (offset - 0x104) >> 2;
17245 add_unwind_opcode (op, 1);
17246 }
17247 else if (offset > 0)
17248 {
17249 /* Short opcode. */
17250 op = (offset - 4) >> 2;
17251 add_unwind_opcode (op, 1);
17252 }
17253 else if (offset < 0)
17254 {
17255 offset = -offset;
17256 while (offset > 0x100)
17257 {
17258 add_unwind_opcode (0x7f, 1);
17259 offset -= 0x100;
17260 }
17261 op = ((offset - 4) >> 2) | 0x40;
17262 add_unwind_opcode (op, 1);
17263 }
17264 }
17265
17266 /* Finish the list of unwind opcodes for this function. */
17267 static void
17268 finish_unwind_opcodes (void)
17269 {
17270 valueT op;
17271
17272 if (unwind.fp_used)
17273 {
17274 /* Adjust sp as necessary. */
17275 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
17276 flush_pending_unwind ();
17277
17278 /* After restoring sp from the frame pointer. */
17279 op = 0x90 | unwind.fp_reg;
17280 add_unwind_opcode (op, 1);
17281 }
17282 else
17283 flush_pending_unwind ();
17284 }
17285
17286
17287 /* Start an exception table entry. If idx is nonzero this is an index table
17288 entry. */
17289
17290 static void
17291 start_unwind_section (const segT text_seg, int idx)
17292 {
17293 const char * text_name;
17294 const char * prefix;
17295 const char * prefix_once;
17296 const char * group_name;
17297 size_t prefix_len;
17298 size_t text_len;
17299 char * sec_name;
17300 size_t sec_name_len;
17301 int type;
17302 int flags;
17303 int linkonce;
17304
17305 if (idx)
17306 {
17307 prefix = ELF_STRING_ARM_unwind;
17308 prefix_once = ELF_STRING_ARM_unwind_once;
17309 type = SHT_ARM_EXIDX;
17310 }
17311 else
17312 {
17313 prefix = ELF_STRING_ARM_unwind_info;
17314 prefix_once = ELF_STRING_ARM_unwind_info_once;
17315 type = SHT_PROGBITS;
17316 }
17317
17318 text_name = segment_name (text_seg);
17319 if (streq (text_name, ".text"))
17320 text_name = "";
17321
17322 if (strncmp (text_name, ".gnu.linkonce.t.",
17323 strlen (".gnu.linkonce.t.")) == 0)
17324 {
17325 prefix = prefix_once;
17326 text_name += strlen (".gnu.linkonce.t.");
17327 }
17328
17329 prefix_len = strlen (prefix);
17330 text_len = strlen (text_name);
17331 sec_name_len = prefix_len + text_len;
17332 sec_name = xmalloc (sec_name_len + 1);
17333 memcpy (sec_name, prefix, prefix_len);
17334 memcpy (sec_name + prefix_len, text_name, text_len);
17335 sec_name[prefix_len + text_len] = '\0';
17336
17337 flags = SHF_ALLOC;
17338 linkonce = 0;
17339 group_name = 0;
17340
17341 /* Handle COMDAT group. */
17342 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
17343 {
17344 group_name = elf_group_name (text_seg);
17345 if (group_name == NULL)
17346 {
17347 as_bad (_("Group section `%s' has no group signature"),
17348 segment_name (text_seg));
17349 ignore_rest_of_line ();
17350 return;
17351 }
17352 flags |= SHF_GROUP;
17353 linkonce = 1;
17354 }
17355
17356 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
17357
17358 /* Set the section link for index tables. */
17359 if (idx)
17360 elf_linked_to_section (now_seg) = text_seg;
17361 }
17362
17363
17364 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
17365 personality routine data. Returns zero, or the index table value for
17366 and inline entry. */
17367
17368 static valueT
17369 create_unwind_entry (int have_data)
17370 {
17371 int size;
17372 addressT where;
17373 char *ptr;
17374 /* The current word of data. */
17375 valueT data;
17376 /* The number of bytes left in this word. */
17377 int n;
17378
17379 finish_unwind_opcodes ();
17380
17381 /* Remember the current text section. */
17382 unwind.saved_seg = now_seg;
17383 unwind.saved_subseg = now_subseg;
17384
17385 start_unwind_section (now_seg, 0);
17386
17387 if (unwind.personality_routine == NULL)
17388 {
17389 if (unwind.personality_index == -2)
17390 {
17391 if (have_data)
17392 as_bad (_("handlerdata in cantunwind frame"));
17393 return 1; /* EXIDX_CANTUNWIND. */
17394 }
17395
17396 /* Use a default personality routine if none is specified. */
17397 if (unwind.personality_index == -1)
17398 {
17399 if (unwind.opcode_count > 3)
17400 unwind.personality_index = 1;
17401 else
17402 unwind.personality_index = 0;
17403 }
17404
17405 /* Space for the personality routine entry. */
17406 if (unwind.personality_index == 0)
17407 {
17408 if (unwind.opcode_count > 3)
17409 as_bad (_("too many unwind opcodes for personality routine 0"));
17410
17411 if (!have_data)
17412 {
17413 /* All the data is inline in the index table. */
17414 data = 0x80;
17415 n = 3;
17416 while (unwind.opcode_count > 0)
17417 {
17418 unwind.opcode_count--;
17419 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17420 n--;
17421 }
17422
17423 /* Pad with "finish" opcodes. */
17424 while (n--)
17425 data = (data << 8) | 0xb0;
17426
17427 return data;
17428 }
17429 size = 0;
17430 }
17431 else
17432 /* We get two opcodes "free" in the first word. */
17433 size = unwind.opcode_count - 2;
17434 }
17435 else
17436 /* An extra byte is required for the opcode count. */
17437 size = unwind.opcode_count + 1;
17438
17439 size = (size + 3) >> 2;
17440 if (size > 0xff)
17441 as_bad (_("too many unwind opcodes"));
17442
17443 frag_align (2, 0, 0);
17444 record_alignment (now_seg, 2);
17445 unwind.table_entry = expr_build_dot ();
17446
17447 /* Allocate the table entry. */
17448 ptr = frag_more ((size << 2) + 4);
17449 where = frag_now_fix () - ((size << 2) + 4);
17450
17451 switch (unwind.personality_index)
17452 {
17453 case -1:
17454 /* ??? Should this be a PLT generating relocation? */
17455 /* Custom personality routine. */
17456 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
17457 BFD_RELOC_ARM_PREL31);
17458
17459 where += 4;
17460 ptr += 4;
17461
17462 /* Set the first byte to the number of additional words. */
17463 data = size - 1;
17464 n = 3;
17465 break;
17466
17467 /* ABI defined personality routines. */
17468 case 0:
17469 /* Three opcodes bytes are packed into the first word. */
17470 data = 0x80;
17471 n = 3;
17472 break;
17473
17474 case 1:
17475 case 2:
17476 /* The size and first two opcode bytes go in the first word. */
17477 data = ((0x80 + unwind.personality_index) << 8) | size;
17478 n = 2;
17479 break;
17480
17481 default:
17482 /* Should never happen. */
17483 abort ();
17484 }
17485
17486 /* Pack the opcodes into words (MSB first), reversing the list at the same
17487 time. */
17488 while (unwind.opcode_count > 0)
17489 {
17490 if (n == 0)
17491 {
17492 md_number_to_chars (ptr, data, 4);
17493 ptr += 4;
17494 n = 4;
17495 data = 0;
17496 }
17497 unwind.opcode_count--;
17498 n--;
17499 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17500 }
17501
17502 /* Finish off the last word. */
17503 if (n < 4)
17504 {
17505 /* Pad with "finish" opcodes. */
17506 while (n--)
17507 data = (data << 8) | 0xb0;
17508
17509 md_number_to_chars (ptr, data, 4);
17510 }
17511
17512 if (!have_data)
17513 {
17514 /* Add an empty descriptor if there is no user-specified data. */
17515 ptr = frag_more (4);
17516 md_number_to_chars (ptr, 0, 4);
17517 }
17518
17519 return 0;
17520 }
17521
17522
17523 /* Initialize the DWARF-2 unwind information for this procedure. */
17524
17525 void
17526 tc_arm_frame_initial_instructions (void)
17527 {
17528 cfi_add_CFA_def_cfa (REG_SP, 0);
17529 }
17530 #endif /* OBJ_ELF */
17531
17532 /* Convert REGNAME to a DWARF-2 register number. */
17533
17534 int
17535 tc_arm_regname_to_dw2regnum (char *regname)
17536 {
17537 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
17538
17539 if (reg == FAIL)
17540 return -1;
17541
17542 return reg;
17543 }
17544
17545 #ifdef TE_PE
17546 void
17547 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
17548 {
17549 expressionS expr;
17550
17551 expr.X_op = O_secrel;
17552 expr.X_add_symbol = symbol;
17553 expr.X_add_number = 0;
17554 emit_expr (&expr, size);
17555 }
17556 #endif
17557
17558 /* MD interface: Symbol and relocation handling. */
17559
17560 /* Return the address within the segment that a PC-relative fixup is
17561 relative to. For ARM, PC-relative fixups applied to instructions
17562 are generally relative to the location of the fixup plus 8 bytes.
17563 Thumb branches are offset by 4, and Thumb loads relative to PC
17564 require special handling. */
17565
17566 long
17567 md_pcrel_from_section (fixS * fixP, segT seg)
17568 {
17569 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
17570
17571 /* If this is pc-relative and we are going to emit a relocation
17572 then we just want to put out any pipeline compensation that the linker
17573 will need. Otherwise we want to use the calculated base.
17574 For WinCE we skip the bias for externals as well, since this
17575 is how the MS ARM-CE assembler behaves and we want to be compatible. */
17576 if (fixP->fx_pcrel
17577 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
17578 || (arm_force_relocation (fixP)
17579 #ifdef TE_WINCE
17580 && !S_IS_EXTERNAL (fixP->fx_addsy)
17581 #endif
17582 )))
17583 base = 0;
17584
17585 switch (fixP->fx_r_type)
17586 {
17587 /* PC relative addressing on the Thumb is slightly odd as the
17588 bottom two bits of the PC are forced to zero for the
17589 calculation. This happens *after* application of the
17590 pipeline offset. However, Thumb adrl already adjusts for
17591 this, so we need not do it again. */
17592 case BFD_RELOC_ARM_THUMB_ADD:
17593 return base & ~3;
17594
17595 case BFD_RELOC_ARM_THUMB_OFFSET:
17596 case BFD_RELOC_ARM_T32_OFFSET_IMM:
17597 case BFD_RELOC_ARM_T32_ADD_PC12:
17598 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
17599 return (base + 4) & ~3;
17600
17601 /* Thumb branches are simply offset by +4. */
17602 case BFD_RELOC_THUMB_PCREL_BRANCH7:
17603 case BFD_RELOC_THUMB_PCREL_BRANCH9:
17604 case BFD_RELOC_THUMB_PCREL_BRANCH12:
17605 case BFD_RELOC_THUMB_PCREL_BRANCH20:
17606 case BFD_RELOC_THUMB_PCREL_BRANCH23:
17607 case BFD_RELOC_THUMB_PCREL_BRANCH25:
17608 case BFD_RELOC_THUMB_PCREL_BLX:
17609 return base + 4;
17610
17611 /* ARM mode branches are offset by +8. However, the Windows CE
17612 loader expects the relocation not to take this into account. */
17613 case BFD_RELOC_ARM_PCREL_BRANCH:
17614 case BFD_RELOC_ARM_PCREL_CALL:
17615 case BFD_RELOC_ARM_PCREL_JUMP:
17616 case BFD_RELOC_ARM_PCREL_BLX:
17617 case BFD_RELOC_ARM_PLT32:
17618 #ifdef TE_WINCE
17619 /* When handling fixups immediately, because we have already
17620 discovered the value of a symbol, or the address of the frag involved
17621 we must account for the offset by +8, as the OS loader will never see the reloc.
17622 see fixup_segment() in write.c
17623 The S_IS_EXTERNAL test handles the case of global symbols.
17624 Those need the calculated base, not just the pipe compensation the linker will need. */
17625 if (fixP->fx_pcrel
17626 && fixP->fx_addsy != NULL
17627 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
17628 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
17629 return base + 8;
17630 return base;
17631 #else
17632 return base + 8;
17633 #endif
17634
17635 /* ARM mode loads relative to PC are also offset by +8. Unlike
17636 branches, the Windows CE loader *does* expect the relocation
17637 to take this into account. */
17638 case BFD_RELOC_ARM_OFFSET_IMM:
17639 case BFD_RELOC_ARM_OFFSET_IMM8:
17640 case BFD_RELOC_ARM_HWLITERAL:
17641 case BFD_RELOC_ARM_LITERAL:
17642 case BFD_RELOC_ARM_CP_OFF_IMM:
17643 return base + 8;
17644
17645
17646 /* Other PC-relative relocations are un-offset. */
17647 default:
17648 return base;
17649 }
17650 }
17651
17652 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
17653 Otherwise we have no need to default values of symbols. */
17654
17655 symbolS *
17656 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
17657 {
17658 #ifdef OBJ_ELF
17659 if (name[0] == '_' && name[1] == 'G'
17660 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
17661 {
17662 if (!GOT_symbol)
17663 {
17664 if (symbol_find (name))
17665 as_bad (_("GOT already in the symbol table"));
17666
17667 GOT_symbol = symbol_new (name, undefined_section,
17668 (valueT) 0, & zero_address_frag);
17669 }
17670
17671 return GOT_symbol;
17672 }
17673 #endif
17674
17675 return 0;
17676 }
17677
17678 /* Subroutine of md_apply_fix. Check to see if an immediate can be
17679 computed as two separate immediate values, added together. We
17680 already know that this value cannot be computed by just one ARM
17681 instruction. */
17682
17683 static unsigned int
17684 validate_immediate_twopart (unsigned int val,
17685 unsigned int * highpart)
17686 {
17687 unsigned int a;
17688 unsigned int i;
17689
17690 for (i = 0; i < 32; i += 2)
17691 if (((a = rotate_left (val, i)) & 0xff) != 0)
17692 {
17693 if (a & 0xff00)
17694 {
17695 if (a & ~ 0xffff)
17696 continue;
17697 * highpart = (a >> 8) | ((i + 24) << 7);
17698 }
17699 else if (a & 0xff0000)
17700 {
17701 if (a & 0xff000000)
17702 continue;
17703 * highpart = (a >> 16) | ((i + 16) << 7);
17704 }
17705 else
17706 {
17707 assert (a & 0xff000000);
17708 * highpart = (a >> 24) | ((i + 8) << 7);
17709 }
17710
17711 return (a & 0xff) | (i << 7);
17712 }
17713
17714 return FAIL;
17715 }
17716
17717 static int
17718 validate_offset_imm (unsigned int val, int hwse)
17719 {
17720 if ((hwse && val > 255) || val > 4095)
17721 return FAIL;
17722 return val;
17723 }
17724
17725 /* Subroutine of md_apply_fix. Do those data_ops which can take a
17726 negative immediate constant by altering the instruction. A bit of
17727 a hack really.
17728 MOV <-> MVN
17729 AND <-> BIC
17730 ADC <-> SBC
17731 by inverting the second operand, and
17732 ADD <-> SUB
17733 CMP <-> CMN
17734 by negating the second operand. */
17735
17736 static int
17737 negate_data_op (unsigned long * instruction,
17738 unsigned long value)
17739 {
17740 int op, new_inst;
17741 unsigned long negated, inverted;
17742
17743 negated = encode_arm_immediate (-value);
17744 inverted = encode_arm_immediate (~value);
17745
17746 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
17747 switch (op)
17748 {
17749 /* First negates. */
17750 case OPCODE_SUB: /* ADD <-> SUB */
17751 new_inst = OPCODE_ADD;
17752 value = negated;
17753 break;
17754
17755 case OPCODE_ADD:
17756 new_inst = OPCODE_SUB;
17757 value = negated;
17758 break;
17759
17760 case OPCODE_CMP: /* CMP <-> CMN */
17761 new_inst = OPCODE_CMN;
17762 value = negated;
17763 break;
17764
17765 case OPCODE_CMN:
17766 new_inst = OPCODE_CMP;
17767 value = negated;
17768 break;
17769
17770 /* Now Inverted ops. */
17771 case OPCODE_MOV: /* MOV <-> MVN */
17772 new_inst = OPCODE_MVN;
17773 value = inverted;
17774 break;
17775
17776 case OPCODE_MVN:
17777 new_inst = OPCODE_MOV;
17778 value = inverted;
17779 break;
17780
17781 case OPCODE_AND: /* AND <-> BIC */
17782 new_inst = OPCODE_BIC;
17783 value = inverted;
17784 break;
17785
17786 case OPCODE_BIC:
17787 new_inst = OPCODE_AND;
17788 value = inverted;
17789 break;
17790
17791 case OPCODE_ADC: /* ADC <-> SBC */
17792 new_inst = OPCODE_SBC;
17793 value = inverted;
17794 break;
17795
17796 case OPCODE_SBC:
17797 new_inst = OPCODE_ADC;
17798 value = inverted;
17799 break;
17800
17801 /* We cannot do anything. */
17802 default:
17803 return FAIL;
17804 }
17805
17806 if (value == (unsigned) FAIL)
17807 return FAIL;
17808
17809 *instruction &= OPCODE_MASK;
17810 *instruction |= new_inst << DATA_OP_SHIFT;
17811 return value;
17812 }
17813
17814 /* Like negate_data_op, but for Thumb-2. */
17815
17816 static unsigned int
17817 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
17818 {
17819 int op, new_inst;
17820 int rd;
17821 unsigned int negated, inverted;
17822
17823 negated = encode_thumb32_immediate (-value);
17824 inverted = encode_thumb32_immediate (~value);
17825
17826 rd = (*instruction >> 8) & 0xf;
17827 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
17828 switch (op)
17829 {
17830 /* ADD <-> SUB. Includes CMP <-> CMN. */
17831 case T2_OPCODE_SUB:
17832 new_inst = T2_OPCODE_ADD;
17833 value = negated;
17834 break;
17835
17836 case T2_OPCODE_ADD:
17837 new_inst = T2_OPCODE_SUB;
17838 value = negated;
17839 break;
17840
17841 /* ORR <-> ORN. Includes MOV <-> MVN. */
17842 case T2_OPCODE_ORR:
17843 new_inst = T2_OPCODE_ORN;
17844 value = inverted;
17845 break;
17846
17847 case T2_OPCODE_ORN:
17848 new_inst = T2_OPCODE_ORR;
17849 value = inverted;
17850 break;
17851
17852 /* AND <-> BIC. TST has no inverted equivalent. */
17853 case T2_OPCODE_AND:
17854 new_inst = T2_OPCODE_BIC;
17855 if (rd == 15)
17856 value = FAIL;
17857 else
17858 value = inverted;
17859 break;
17860
17861 case T2_OPCODE_BIC:
17862 new_inst = T2_OPCODE_AND;
17863 value = inverted;
17864 break;
17865
17866 /* ADC <-> SBC */
17867 case T2_OPCODE_ADC:
17868 new_inst = T2_OPCODE_SBC;
17869 value = inverted;
17870 break;
17871
17872 case T2_OPCODE_SBC:
17873 new_inst = T2_OPCODE_ADC;
17874 value = inverted;
17875 break;
17876
17877 /* We cannot do anything. */
17878 default:
17879 return FAIL;
17880 }
17881
17882 if (value == (unsigned int)FAIL)
17883 return FAIL;
17884
17885 *instruction &= T2_OPCODE_MASK;
17886 *instruction |= new_inst << T2_DATA_OP_SHIFT;
17887 return value;
17888 }
17889
17890 /* Read a 32-bit thumb instruction from buf. */
17891 static unsigned long
17892 get_thumb32_insn (char * buf)
17893 {
17894 unsigned long insn;
17895 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
17896 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
17897
17898 return insn;
17899 }
17900
17901
17902 /* We usually want to set the low bit on the address of thumb function
17903 symbols. In particular .word foo - . should have the low bit set.
17904 Generic code tries to fold the difference of two symbols to
17905 a constant. Prevent this and force a relocation when the first symbols
17906 is a thumb function. */
17907 int
17908 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
17909 {
17910 if (op == O_subtract
17911 && l->X_op == O_symbol
17912 && r->X_op == O_symbol
17913 && THUMB_IS_FUNC (l->X_add_symbol))
17914 {
17915 l->X_op = O_subtract;
17916 l->X_op_symbol = r->X_add_symbol;
17917 l->X_add_number -= r->X_add_number;
17918 return 1;
17919 }
17920 /* Process as normal. */
17921 return 0;
17922 }
17923
17924 void
17925 md_apply_fix (fixS * fixP,
17926 valueT * valP,
17927 segT seg)
17928 {
17929 offsetT value = * valP;
17930 offsetT newval;
17931 unsigned int newimm;
17932 unsigned long temp;
17933 int sign;
17934 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
17935
17936 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
17937
17938 /* Note whether this will delete the relocation. */
17939
17940 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
17941 fixP->fx_done = 1;
17942
17943 /* On a 64-bit host, silently truncate 'value' to 32 bits for
17944 consistency with the behaviour on 32-bit hosts. Remember value
17945 for emit_reloc. */
17946 value &= 0xffffffff;
17947 value ^= 0x80000000;
17948 value -= 0x80000000;
17949
17950 *valP = value;
17951 fixP->fx_addnumber = value;
17952
17953 /* Same treatment for fixP->fx_offset. */
17954 fixP->fx_offset &= 0xffffffff;
17955 fixP->fx_offset ^= 0x80000000;
17956 fixP->fx_offset -= 0x80000000;
17957
17958 switch (fixP->fx_r_type)
17959 {
17960 case BFD_RELOC_NONE:
17961 /* This will need to go in the object file. */
17962 fixP->fx_done = 0;
17963 break;
17964
17965 case BFD_RELOC_ARM_IMMEDIATE:
17966 /* We claim that this fixup has been processed here,
17967 even if in fact we generate an error because we do
17968 not have a reloc for it, so tc_gen_reloc will reject it. */
17969 fixP->fx_done = 1;
17970
17971 if (fixP->fx_addsy
17972 && ! S_IS_DEFINED (fixP->fx_addsy))
17973 {
17974 as_bad_where (fixP->fx_file, fixP->fx_line,
17975 _("undefined symbol %s used as an immediate value"),
17976 S_GET_NAME (fixP->fx_addsy));
17977 break;
17978 }
17979
17980 newimm = encode_arm_immediate (value);
17981 temp = md_chars_to_number (buf, INSN_SIZE);
17982
17983 /* If the instruction will fail, see if we can fix things up by
17984 changing the opcode. */
17985 if (newimm == (unsigned int) FAIL
17986 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
17987 {
17988 as_bad_where (fixP->fx_file, fixP->fx_line,
17989 _("invalid constant (%lx) after fixup"),
17990 (unsigned long) value);
17991 break;
17992 }
17993
17994 newimm |= (temp & 0xfffff000);
17995 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
17996 break;
17997
17998 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
17999 {
18000 unsigned int highpart = 0;
18001 unsigned int newinsn = 0xe1a00000; /* nop. */
18002
18003 newimm = encode_arm_immediate (value);
18004 temp = md_chars_to_number (buf, INSN_SIZE);
18005
18006 /* If the instruction will fail, see if we can fix things up by
18007 changing the opcode. */
18008 if (newimm == (unsigned int) FAIL
18009 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
18010 {
18011 /* No ? OK - try using two ADD instructions to generate
18012 the value. */
18013 newimm = validate_immediate_twopart (value, & highpart);
18014
18015 /* Yes - then make sure that the second instruction is
18016 also an add. */
18017 if (newimm != (unsigned int) FAIL)
18018 newinsn = temp;
18019 /* Still No ? Try using a negated value. */
18020 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
18021 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
18022 /* Otherwise - give up. */
18023 else
18024 {
18025 as_bad_where (fixP->fx_file, fixP->fx_line,
18026 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
18027 (long) value);
18028 break;
18029 }
18030
18031 /* Replace the first operand in the 2nd instruction (which
18032 is the PC) with the destination register. We have
18033 already added in the PC in the first instruction and we
18034 do not want to do it again. */
18035 newinsn &= ~ 0xf0000;
18036 newinsn |= ((newinsn & 0x0f000) << 4);
18037 }
18038
18039 newimm |= (temp & 0xfffff000);
18040 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
18041
18042 highpart |= (newinsn & 0xfffff000);
18043 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
18044 }
18045 break;
18046
18047 case BFD_RELOC_ARM_OFFSET_IMM:
18048 if (!fixP->fx_done && seg->use_rela_p)
18049 value = 0;
18050
18051 case BFD_RELOC_ARM_LITERAL:
18052 sign = value >= 0;
18053
18054 if (value < 0)
18055 value = - value;
18056
18057 if (validate_offset_imm (value, 0) == FAIL)
18058 {
18059 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
18060 as_bad_where (fixP->fx_file, fixP->fx_line,
18061 _("invalid literal constant: pool needs to be closer"));
18062 else
18063 as_bad_where (fixP->fx_file, fixP->fx_line,
18064 _("bad immediate value for offset (%ld)"),
18065 (long) value);
18066 break;
18067 }
18068
18069 newval = md_chars_to_number (buf, INSN_SIZE);
18070 newval &= 0xff7ff000;
18071 newval |= value | (sign ? INDEX_UP : 0);
18072 md_number_to_chars (buf, newval, INSN_SIZE);
18073 break;
18074
18075 case BFD_RELOC_ARM_OFFSET_IMM8:
18076 case BFD_RELOC_ARM_HWLITERAL:
18077 sign = value >= 0;
18078
18079 if (value < 0)
18080 value = - value;
18081
18082 if (validate_offset_imm (value, 1) == FAIL)
18083 {
18084 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
18085 as_bad_where (fixP->fx_file, fixP->fx_line,
18086 _("invalid literal constant: pool needs to be closer"));
18087 else
18088 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
18089 (long) value);
18090 break;
18091 }
18092
18093 newval = md_chars_to_number (buf, INSN_SIZE);
18094 newval &= 0xff7ff0f0;
18095 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
18096 md_number_to_chars (buf, newval, INSN_SIZE);
18097 break;
18098
18099 case BFD_RELOC_ARM_T32_OFFSET_U8:
18100 if (value < 0 || value > 1020 || value % 4 != 0)
18101 as_bad_where (fixP->fx_file, fixP->fx_line,
18102 _("bad immediate value for offset (%ld)"), (long) value);
18103 value /= 4;
18104
18105 newval = md_chars_to_number (buf+2, THUMB_SIZE);
18106 newval |= value;
18107 md_number_to_chars (buf+2, newval, THUMB_SIZE);
18108 break;
18109
18110 case BFD_RELOC_ARM_T32_OFFSET_IMM:
18111 /* This is a complicated relocation used for all varieties of Thumb32
18112 load/store instruction with immediate offset:
18113
18114 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
18115 *4, optional writeback(W)
18116 (doubleword load/store)
18117
18118 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
18119 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
18120 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
18121 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
18122 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
18123
18124 Uppercase letters indicate bits that are already encoded at
18125 this point. Lowercase letters are our problem. For the
18126 second block of instructions, the secondary opcode nybble
18127 (bits 8..11) is present, and bit 23 is zero, even if this is
18128 a PC-relative operation. */
18129 newval = md_chars_to_number (buf, THUMB_SIZE);
18130 newval <<= 16;
18131 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
18132
18133 if ((newval & 0xf0000000) == 0xe0000000)
18134 {
18135 /* Doubleword load/store: 8-bit offset, scaled by 4. */
18136 if (value >= 0)
18137 newval |= (1 << 23);
18138 else
18139 value = -value;
18140 if (value % 4 != 0)
18141 {
18142 as_bad_where (fixP->fx_file, fixP->fx_line,
18143 _("offset not a multiple of 4"));
18144 break;
18145 }
18146 value /= 4;
18147 if (value > 0xff)
18148 {
18149 as_bad_where (fixP->fx_file, fixP->fx_line,
18150 _("offset out of range"));
18151 break;
18152 }
18153 newval &= ~0xff;
18154 }
18155 else if ((newval & 0x000f0000) == 0x000f0000)
18156 {
18157 /* PC-relative, 12-bit offset. */
18158 if (value >= 0)
18159 newval |= (1 << 23);
18160 else
18161 value = -value;
18162 if (value > 0xfff)
18163 {
18164 as_bad_where (fixP->fx_file, fixP->fx_line,
18165 _("offset out of range"));
18166 break;
18167 }
18168 newval &= ~0xfff;
18169 }
18170 else if ((newval & 0x00000100) == 0x00000100)
18171 {
18172 /* Writeback: 8-bit, +/- offset. */
18173 if (value >= 0)
18174 newval |= (1 << 9);
18175 else
18176 value = -value;
18177 if (value > 0xff)
18178 {
18179 as_bad_where (fixP->fx_file, fixP->fx_line,
18180 _("offset out of range"));
18181 break;
18182 }
18183 newval &= ~0xff;
18184 }
18185 else if ((newval & 0x00000f00) == 0x00000e00)
18186 {
18187 /* T-instruction: positive 8-bit offset. */
18188 if (value < 0 || value > 0xff)
18189 {
18190 as_bad_where (fixP->fx_file, fixP->fx_line,
18191 _("offset out of range"));
18192 break;
18193 }
18194 newval &= ~0xff;
18195 newval |= value;
18196 }
18197 else
18198 {
18199 /* Positive 12-bit or negative 8-bit offset. */
18200 int limit;
18201 if (value >= 0)
18202 {
18203 newval |= (1 << 23);
18204 limit = 0xfff;
18205 }
18206 else
18207 {
18208 value = -value;
18209 limit = 0xff;
18210 }
18211 if (value > limit)
18212 {
18213 as_bad_where (fixP->fx_file, fixP->fx_line,
18214 _("offset out of range"));
18215 break;
18216 }
18217 newval &= ~limit;
18218 }
18219
18220 newval |= value;
18221 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
18222 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
18223 break;
18224
18225 case BFD_RELOC_ARM_SHIFT_IMM:
18226 newval = md_chars_to_number (buf, INSN_SIZE);
18227 if (((unsigned long) value) > 32
18228 || (value == 32
18229 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
18230 {
18231 as_bad_where (fixP->fx_file, fixP->fx_line,
18232 _("shift expression is too large"));
18233 break;
18234 }
18235
18236 if (value == 0)
18237 /* Shifts of zero must be done as lsl. */
18238 newval &= ~0x60;
18239 else if (value == 32)
18240 value = 0;
18241 newval &= 0xfffff07f;
18242 newval |= (value & 0x1f) << 7;
18243 md_number_to_chars (buf, newval, INSN_SIZE);
18244 break;
18245
18246 case BFD_RELOC_ARM_T32_IMMEDIATE:
18247 case BFD_RELOC_ARM_T32_ADD_IMM:
18248 case BFD_RELOC_ARM_T32_IMM12:
18249 case BFD_RELOC_ARM_T32_ADD_PC12:
18250 /* We claim that this fixup has been processed here,
18251 even if in fact we generate an error because we do
18252 not have a reloc for it, so tc_gen_reloc will reject it. */
18253 fixP->fx_done = 1;
18254
18255 if (fixP->fx_addsy
18256 && ! S_IS_DEFINED (fixP->fx_addsy))
18257 {
18258 as_bad_where (fixP->fx_file, fixP->fx_line,
18259 _("undefined symbol %s used as an immediate value"),
18260 S_GET_NAME (fixP->fx_addsy));
18261 break;
18262 }
18263
18264 newval = md_chars_to_number (buf, THUMB_SIZE);
18265 newval <<= 16;
18266 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
18267
18268 newimm = FAIL;
18269 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
18270 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18271 {
18272 newimm = encode_thumb32_immediate (value);
18273 if (newimm == (unsigned int) FAIL)
18274 newimm = thumb32_negate_data_op (&newval, value);
18275 }
18276 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
18277 && newimm == (unsigned int) FAIL)
18278 {
18279 /* Turn add/sum into addw/subw. */
18280 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18281 newval = (newval & 0xfeffffff) | 0x02000000;
18282
18283 /* 12 bit immediate for addw/subw. */
18284 if (value < 0)
18285 {
18286 value = -value;
18287 newval ^= 0x00a00000;
18288 }
18289 if (value > 0xfff)
18290 newimm = (unsigned int) FAIL;
18291 else
18292 newimm = value;
18293 }
18294
18295 if (newimm == (unsigned int)FAIL)
18296 {
18297 as_bad_where (fixP->fx_file, fixP->fx_line,
18298 _("invalid constant (%lx) after fixup"),
18299 (unsigned long) value);
18300 break;
18301 }
18302
18303 newval |= (newimm & 0x800) << 15;
18304 newval |= (newimm & 0x700) << 4;
18305 newval |= (newimm & 0x0ff);
18306
18307 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
18308 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
18309 break;
18310
18311 case BFD_RELOC_ARM_SMC:
18312 if (((unsigned long) value) > 0xffff)
18313 as_bad_where (fixP->fx_file, fixP->fx_line,
18314 _("invalid smc expression"));
18315 newval = md_chars_to_number (buf, INSN_SIZE);
18316 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
18317 md_number_to_chars (buf, newval, INSN_SIZE);
18318 break;
18319
18320 case BFD_RELOC_ARM_SWI:
18321 if (fixP->tc_fix_data != 0)
18322 {
18323 if (((unsigned long) value) > 0xff)
18324 as_bad_where (fixP->fx_file, fixP->fx_line,
18325 _("invalid swi expression"));
18326 newval = md_chars_to_number (buf, THUMB_SIZE);
18327 newval |= value;
18328 md_number_to_chars (buf, newval, THUMB_SIZE);
18329 }
18330 else
18331 {
18332 if (((unsigned long) value) > 0x00ffffff)
18333 as_bad_where (fixP->fx_file, fixP->fx_line,
18334 _("invalid swi expression"));
18335 newval = md_chars_to_number (buf, INSN_SIZE);
18336 newval |= value;
18337 md_number_to_chars (buf, newval, INSN_SIZE);
18338 }
18339 break;
18340
18341 case BFD_RELOC_ARM_MULTI:
18342 if (((unsigned long) value) > 0xffff)
18343 as_bad_where (fixP->fx_file, fixP->fx_line,
18344 _("invalid expression in load/store multiple"));
18345 newval = value | md_chars_to_number (buf, INSN_SIZE);
18346 md_number_to_chars (buf, newval, INSN_SIZE);
18347 break;
18348
18349 #ifdef OBJ_ELF
18350 case BFD_RELOC_ARM_PCREL_CALL:
18351 newval = md_chars_to_number (buf, INSN_SIZE);
18352 if ((newval & 0xf0000000) == 0xf0000000)
18353 temp = 1;
18354 else
18355 temp = 3;
18356 goto arm_branch_common;
18357
18358 case BFD_RELOC_ARM_PCREL_JUMP:
18359 case BFD_RELOC_ARM_PLT32:
18360 #endif
18361 case BFD_RELOC_ARM_PCREL_BRANCH:
18362 temp = 3;
18363 goto arm_branch_common;
18364
18365 case BFD_RELOC_ARM_PCREL_BLX:
18366 temp = 1;
18367 arm_branch_common:
18368 /* We are going to store value (shifted right by two) in the
18369 instruction, in a 24 bit, signed field. Bits 26 through 32 either
18370 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
18371 also be be clear. */
18372 if (value & temp)
18373 as_bad_where (fixP->fx_file, fixP->fx_line,
18374 _("misaligned branch destination"));
18375 if ((value & (offsetT)0xfe000000) != (offsetT)0
18376 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
18377 as_bad_where (fixP->fx_file, fixP->fx_line,
18378 _("branch out of range"));
18379
18380 if (fixP->fx_done || !seg->use_rela_p)
18381 {
18382 newval = md_chars_to_number (buf, INSN_SIZE);
18383 newval |= (value >> 2) & 0x00ffffff;
18384 /* Set the H bit on BLX instructions. */
18385 if (temp == 1)
18386 {
18387 if (value & 2)
18388 newval |= 0x01000000;
18389 else
18390 newval &= ~0x01000000;
18391 }
18392 md_number_to_chars (buf, newval, INSN_SIZE);
18393 }
18394 break;
18395
18396 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
18397 /* CBZ can only branch forward. */
18398
18399 /* Attempts to use CBZ to branch to the next instruction
18400 (which, strictly speaking, are prohibited) will be turned into
18401 no-ops.
18402
18403 FIXME: It may be better to remove the instruction completely and
18404 perform relaxation. */
18405 if (value == -2)
18406 {
18407 newval = md_chars_to_number (buf, THUMB_SIZE);
18408 newval = 0xbf00; /* NOP encoding T1 */
18409 md_number_to_chars (buf, newval, THUMB_SIZE);
18410 }
18411 else
18412 {
18413 if (value & ~0x7e)
18414 as_bad_where (fixP->fx_file, fixP->fx_line,
18415 _("branch out of range"));
18416
18417 if (fixP->fx_done || !seg->use_rela_p)
18418 {
18419 newval = md_chars_to_number (buf, THUMB_SIZE);
18420 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
18421 md_number_to_chars (buf, newval, THUMB_SIZE);
18422 }
18423 }
18424 break;
18425
18426 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
18427 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
18428 as_bad_where (fixP->fx_file, fixP->fx_line,
18429 _("branch out of range"));
18430
18431 if (fixP->fx_done || !seg->use_rela_p)
18432 {
18433 newval = md_chars_to_number (buf, THUMB_SIZE);
18434 newval |= (value & 0x1ff) >> 1;
18435 md_number_to_chars (buf, newval, THUMB_SIZE);
18436 }
18437 break;
18438
18439 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
18440 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
18441 as_bad_where (fixP->fx_file, fixP->fx_line,
18442 _("branch out of range"));
18443
18444 if (fixP->fx_done || !seg->use_rela_p)
18445 {
18446 newval = md_chars_to_number (buf, THUMB_SIZE);
18447 newval |= (value & 0xfff) >> 1;
18448 md_number_to_chars (buf, newval, THUMB_SIZE);
18449 }
18450 break;
18451
18452 case BFD_RELOC_THUMB_PCREL_BRANCH20:
18453 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
18454 as_bad_where (fixP->fx_file, fixP->fx_line,
18455 _("conditional branch out of range"));
18456
18457 if (fixP->fx_done || !seg->use_rela_p)
18458 {
18459 offsetT newval2;
18460 addressT S, J1, J2, lo, hi;
18461
18462 S = (value & 0x00100000) >> 20;
18463 J2 = (value & 0x00080000) >> 19;
18464 J1 = (value & 0x00040000) >> 18;
18465 hi = (value & 0x0003f000) >> 12;
18466 lo = (value & 0x00000ffe) >> 1;
18467
18468 newval = md_chars_to_number (buf, THUMB_SIZE);
18469 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18470 newval |= (S << 10) | hi;
18471 newval2 |= (J1 << 13) | (J2 << 11) | lo;
18472 md_number_to_chars (buf, newval, THUMB_SIZE);
18473 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18474 }
18475 break;
18476
18477 case BFD_RELOC_THUMB_PCREL_BLX:
18478 case BFD_RELOC_THUMB_PCREL_BRANCH23:
18479 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
18480 as_bad_where (fixP->fx_file, fixP->fx_line,
18481 _("branch out of range"));
18482
18483 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
18484 /* For a BLX instruction, make sure that the relocation is rounded up
18485 to a word boundary. This follows the semantics of the instruction
18486 which specifies that bit 1 of the target address will come from bit
18487 1 of the base address. */
18488 value = (value + 1) & ~ 1;
18489
18490 if (fixP->fx_done || !seg->use_rela_p)
18491 {
18492 offsetT newval2;
18493
18494 newval = md_chars_to_number (buf, THUMB_SIZE);
18495 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18496 newval |= (value & 0x7fffff) >> 12;
18497 newval2 |= (value & 0xfff) >> 1;
18498 md_number_to_chars (buf, newval, THUMB_SIZE);
18499 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18500 }
18501 break;
18502
18503 case BFD_RELOC_THUMB_PCREL_BRANCH25:
18504 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
18505 as_bad_where (fixP->fx_file, fixP->fx_line,
18506 _("branch out of range"));
18507
18508 if (fixP->fx_done || !seg->use_rela_p)
18509 {
18510 offsetT newval2;
18511 addressT S, I1, I2, lo, hi;
18512
18513 S = (value & 0x01000000) >> 24;
18514 I1 = (value & 0x00800000) >> 23;
18515 I2 = (value & 0x00400000) >> 22;
18516 hi = (value & 0x003ff000) >> 12;
18517 lo = (value & 0x00000ffe) >> 1;
18518
18519 I1 = !(I1 ^ S);
18520 I2 = !(I2 ^ S);
18521
18522 newval = md_chars_to_number (buf, THUMB_SIZE);
18523 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18524 newval |= (S << 10) | hi;
18525 newval2 |= (I1 << 13) | (I2 << 11) | lo;
18526 md_number_to_chars (buf, newval, THUMB_SIZE);
18527 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18528 }
18529 break;
18530
18531 case BFD_RELOC_8:
18532 if (fixP->fx_done || !seg->use_rela_p)
18533 md_number_to_chars (buf, value, 1);
18534 break;
18535
18536 case BFD_RELOC_16:
18537 if (fixP->fx_done || !seg->use_rela_p)
18538 md_number_to_chars (buf, value, 2);
18539 break;
18540
18541 #ifdef OBJ_ELF
18542 case BFD_RELOC_ARM_TLS_GD32:
18543 case BFD_RELOC_ARM_TLS_LE32:
18544 case BFD_RELOC_ARM_TLS_IE32:
18545 case BFD_RELOC_ARM_TLS_LDM32:
18546 case BFD_RELOC_ARM_TLS_LDO32:
18547 S_SET_THREAD_LOCAL (fixP->fx_addsy);
18548 /* fall through */
18549
18550 case BFD_RELOC_ARM_GOT32:
18551 case BFD_RELOC_ARM_GOTOFF:
18552 case BFD_RELOC_ARM_TARGET2:
18553 if (fixP->fx_done || !seg->use_rela_p)
18554 md_number_to_chars (buf, 0, 4);
18555 break;
18556 #endif
18557
18558 case BFD_RELOC_RVA:
18559 case BFD_RELOC_32:
18560 case BFD_RELOC_ARM_TARGET1:
18561 case BFD_RELOC_ARM_ROSEGREL32:
18562 case BFD_RELOC_ARM_SBREL32:
18563 case BFD_RELOC_32_PCREL:
18564 #ifdef TE_PE
18565 case BFD_RELOC_32_SECREL:
18566 #endif
18567 if (fixP->fx_done || !seg->use_rela_p)
18568 #ifdef TE_WINCE
18569 /* For WinCE we only do this for pcrel fixups. */
18570 if (fixP->fx_done || fixP->fx_pcrel)
18571 #endif
18572 md_number_to_chars (buf, value, 4);
18573 break;
18574
18575 #ifdef OBJ_ELF
18576 case BFD_RELOC_ARM_PREL31:
18577 if (fixP->fx_done || !seg->use_rela_p)
18578 {
18579 newval = md_chars_to_number (buf, 4) & 0x80000000;
18580 if ((value ^ (value >> 1)) & 0x40000000)
18581 {
18582 as_bad_where (fixP->fx_file, fixP->fx_line,
18583 _("rel31 relocation overflow"));
18584 }
18585 newval |= value & 0x7fffffff;
18586 md_number_to_chars (buf, newval, 4);
18587 }
18588 break;
18589 #endif
18590
18591 case BFD_RELOC_ARM_CP_OFF_IMM:
18592 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
18593 if (value < -1023 || value > 1023 || (value & 3))
18594 as_bad_where (fixP->fx_file, fixP->fx_line,
18595 _("co-processor offset out of range"));
18596 cp_off_common:
18597 sign = value >= 0;
18598 if (value < 0)
18599 value = -value;
18600 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18601 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18602 newval = md_chars_to_number (buf, INSN_SIZE);
18603 else
18604 newval = get_thumb32_insn (buf);
18605 newval &= 0xff7fff00;
18606 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
18607 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18608 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18609 md_number_to_chars (buf, newval, INSN_SIZE);
18610 else
18611 put_thumb32_insn (buf, newval);
18612 break;
18613
18614 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
18615 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
18616 if (value < -255 || value > 255)
18617 as_bad_where (fixP->fx_file, fixP->fx_line,
18618 _("co-processor offset out of range"));
18619 value *= 4;
18620 goto cp_off_common;
18621
18622 case BFD_RELOC_ARM_THUMB_OFFSET:
18623 newval = md_chars_to_number (buf, THUMB_SIZE);
18624 /* Exactly what ranges, and where the offset is inserted depends
18625 on the type of instruction, we can establish this from the
18626 top 4 bits. */
18627 switch (newval >> 12)
18628 {
18629 case 4: /* PC load. */
18630 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
18631 forced to zero for these loads; md_pcrel_from has already
18632 compensated for this. */
18633 if (value & 3)
18634 as_bad_where (fixP->fx_file, fixP->fx_line,
18635 _("invalid offset, target not word aligned (0x%08lX)"),
18636 (((unsigned long) fixP->fx_frag->fr_address
18637 + (unsigned long) fixP->fx_where) & ~3)
18638 + (unsigned long) value);
18639
18640 if (value & ~0x3fc)
18641 as_bad_where (fixP->fx_file, fixP->fx_line,
18642 _("invalid offset, value too big (0x%08lX)"),
18643 (long) value);
18644
18645 newval |= value >> 2;
18646 break;
18647
18648 case 9: /* SP load/store. */
18649 if (value & ~0x3fc)
18650 as_bad_where (fixP->fx_file, fixP->fx_line,
18651 _("invalid offset, value too big (0x%08lX)"),
18652 (long) value);
18653 newval |= value >> 2;
18654 break;
18655
18656 case 6: /* Word load/store. */
18657 if (value & ~0x7c)
18658 as_bad_where (fixP->fx_file, fixP->fx_line,
18659 _("invalid offset, value too big (0x%08lX)"),
18660 (long) value);
18661 newval |= value << 4; /* 6 - 2. */
18662 break;
18663
18664 case 7: /* Byte load/store. */
18665 if (value & ~0x1f)
18666 as_bad_where (fixP->fx_file, fixP->fx_line,
18667 _("invalid offset, value too big (0x%08lX)"),
18668 (long) value);
18669 newval |= value << 6;
18670 break;
18671
18672 case 8: /* Halfword load/store. */
18673 if (value & ~0x3e)
18674 as_bad_where (fixP->fx_file, fixP->fx_line,
18675 _("invalid offset, value too big (0x%08lX)"),
18676 (long) value);
18677 newval |= value << 5; /* 6 - 1. */
18678 break;
18679
18680 default:
18681 as_bad_where (fixP->fx_file, fixP->fx_line,
18682 "Unable to process relocation for thumb opcode: %lx",
18683 (unsigned long) newval);
18684 break;
18685 }
18686 md_number_to_chars (buf, newval, THUMB_SIZE);
18687 break;
18688
18689 case BFD_RELOC_ARM_THUMB_ADD:
18690 /* This is a complicated relocation, since we use it for all of
18691 the following immediate relocations:
18692
18693 3bit ADD/SUB
18694 8bit ADD/SUB
18695 9bit ADD/SUB SP word-aligned
18696 10bit ADD PC/SP word-aligned
18697
18698 The type of instruction being processed is encoded in the
18699 instruction field:
18700
18701 0x8000 SUB
18702 0x00F0 Rd
18703 0x000F Rs
18704 */
18705 newval = md_chars_to_number (buf, THUMB_SIZE);
18706 {
18707 int rd = (newval >> 4) & 0xf;
18708 int rs = newval & 0xf;
18709 int subtract = !!(newval & 0x8000);
18710
18711 /* Check for HI regs, only very restricted cases allowed:
18712 Adjusting SP, and using PC or SP to get an address. */
18713 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
18714 || (rs > 7 && rs != REG_SP && rs != REG_PC))
18715 as_bad_where (fixP->fx_file, fixP->fx_line,
18716 _("invalid Hi register with immediate"));
18717
18718 /* If value is negative, choose the opposite instruction. */
18719 if (value < 0)
18720 {
18721 value = -value;
18722 subtract = !subtract;
18723 if (value < 0)
18724 as_bad_where (fixP->fx_file, fixP->fx_line,
18725 _("immediate value out of range"));
18726 }
18727
18728 if (rd == REG_SP)
18729 {
18730 if (value & ~0x1fc)
18731 as_bad_where (fixP->fx_file, fixP->fx_line,
18732 _("invalid immediate for stack address calculation"));
18733 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
18734 newval |= value >> 2;
18735 }
18736 else if (rs == REG_PC || rs == REG_SP)
18737 {
18738 if (subtract || value & ~0x3fc)
18739 as_bad_where (fixP->fx_file, fixP->fx_line,
18740 _("invalid immediate for address calculation (value = 0x%08lX)"),
18741 (unsigned long) value);
18742 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
18743 newval |= rd << 8;
18744 newval |= value >> 2;
18745 }
18746 else if (rs == rd)
18747 {
18748 if (value & ~0xff)
18749 as_bad_where (fixP->fx_file, fixP->fx_line,
18750 _("immediate value out of range"));
18751 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
18752 newval |= (rd << 8) | value;
18753 }
18754 else
18755 {
18756 if (value & ~0x7)
18757 as_bad_where (fixP->fx_file, fixP->fx_line,
18758 _("immediate value out of range"));
18759 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
18760 newval |= rd | (rs << 3) | (value << 6);
18761 }
18762 }
18763 md_number_to_chars (buf, newval, THUMB_SIZE);
18764 break;
18765
18766 case BFD_RELOC_ARM_THUMB_IMM:
18767 newval = md_chars_to_number (buf, THUMB_SIZE);
18768 if (value < 0 || value > 255)
18769 as_bad_where (fixP->fx_file, fixP->fx_line,
18770 _("invalid immediate: %ld is out of range"),
18771 (long) value);
18772 newval |= value;
18773 md_number_to_chars (buf, newval, THUMB_SIZE);
18774 break;
18775
18776 case BFD_RELOC_ARM_THUMB_SHIFT:
18777 /* 5bit shift value (0..32). LSL cannot take 32. */
18778 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
18779 temp = newval & 0xf800;
18780 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
18781 as_bad_where (fixP->fx_file, fixP->fx_line,
18782 _("invalid shift value: %ld"), (long) value);
18783 /* Shifts of zero must be encoded as LSL. */
18784 if (value == 0)
18785 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
18786 /* Shifts of 32 are encoded as zero. */
18787 else if (value == 32)
18788 value = 0;
18789 newval |= value << 6;
18790 md_number_to_chars (buf, newval, THUMB_SIZE);
18791 break;
18792
18793 case BFD_RELOC_VTABLE_INHERIT:
18794 case BFD_RELOC_VTABLE_ENTRY:
18795 fixP->fx_done = 0;
18796 return;
18797
18798 case BFD_RELOC_ARM_MOVW:
18799 case BFD_RELOC_ARM_MOVT:
18800 case BFD_RELOC_ARM_THUMB_MOVW:
18801 case BFD_RELOC_ARM_THUMB_MOVT:
18802 if (fixP->fx_done || !seg->use_rela_p)
18803 {
18804 /* REL format relocations are limited to a 16-bit addend. */
18805 if (!fixP->fx_done)
18806 {
18807 if (value < -0x1000 || value > 0xffff)
18808 as_bad_where (fixP->fx_file, fixP->fx_line,
18809 _("offset out of range"));
18810 }
18811 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
18812 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18813 {
18814 value >>= 16;
18815 }
18816
18817 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
18818 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18819 {
18820 newval = get_thumb32_insn (buf);
18821 newval &= 0xfbf08f00;
18822 newval |= (value & 0xf000) << 4;
18823 newval |= (value & 0x0800) << 15;
18824 newval |= (value & 0x0700) << 4;
18825 newval |= (value & 0x00ff);
18826 put_thumb32_insn (buf, newval);
18827 }
18828 else
18829 {
18830 newval = md_chars_to_number (buf, 4);
18831 newval &= 0xfff0f000;
18832 newval |= value & 0x0fff;
18833 newval |= (value & 0xf000) << 4;
18834 md_number_to_chars (buf, newval, 4);
18835 }
18836 }
18837 return;
18838
18839 case BFD_RELOC_ARM_ALU_PC_G0_NC:
18840 case BFD_RELOC_ARM_ALU_PC_G0:
18841 case BFD_RELOC_ARM_ALU_PC_G1_NC:
18842 case BFD_RELOC_ARM_ALU_PC_G1:
18843 case BFD_RELOC_ARM_ALU_PC_G2:
18844 case BFD_RELOC_ARM_ALU_SB_G0_NC:
18845 case BFD_RELOC_ARM_ALU_SB_G0:
18846 case BFD_RELOC_ARM_ALU_SB_G1_NC:
18847 case BFD_RELOC_ARM_ALU_SB_G1:
18848 case BFD_RELOC_ARM_ALU_SB_G2:
18849 assert (!fixP->fx_done);
18850 if (!seg->use_rela_p)
18851 {
18852 bfd_vma insn;
18853 bfd_vma encoded_addend;
18854 bfd_vma addend_abs = abs (value);
18855
18856 /* Check that the absolute value of the addend can be
18857 expressed as an 8-bit constant plus a rotation. */
18858 encoded_addend = encode_arm_immediate (addend_abs);
18859 if (encoded_addend == (unsigned int) FAIL)
18860 as_bad_where (fixP->fx_file, fixP->fx_line,
18861 _("the offset 0x%08lX is not representable"),
18862 (unsigned long) addend_abs);
18863
18864 /* Extract the instruction. */
18865 insn = md_chars_to_number (buf, INSN_SIZE);
18866
18867 /* If the addend is positive, use an ADD instruction.
18868 Otherwise use a SUB. Take care not to destroy the S bit. */
18869 insn &= 0xff1fffff;
18870 if (value < 0)
18871 insn |= 1 << 22;
18872 else
18873 insn |= 1 << 23;
18874
18875 /* Place the encoded addend into the first 12 bits of the
18876 instruction. */
18877 insn &= 0xfffff000;
18878 insn |= encoded_addend;
18879
18880 /* Update the instruction. */
18881 md_number_to_chars (buf, insn, INSN_SIZE);
18882 }
18883 break;
18884
18885 case BFD_RELOC_ARM_LDR_PC_G0:
18886 case BFD_RELOC_ARM_LDR_PC_G1:
18887 case BFD_RELOC_ARM_LDR_PC_G2:
18888 case BFD_RELOC_ARM_LDR_SB_G0:
18889 case BFD_RELOC_ARM_LDR_SB_G1:
18890 case BFD_RELOC_ARM_LDR_SB_G2:
18891 assert (!fixP->fx_done);
18892 if (!seg->use_rela_p)
18893 {
18894 bfd_vma insn;
18895 bfd_vma addend_abs = abs (value);
18896
18897 /* Check that the absolute value of the addend can be
18898 encoded in 12 bits. */
18899 if (addend_abs >= 0x1000)
18900 as_bad_where (fixP->fx_file, fixP->fx_line,
18901 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
18902 (unsigned long) addend_abs);
18903
18904 /* Extract the instruction. */
18905 insn = md_chars_to_number (buf, INSN_SIZE);
18906
18907 /* If the addend is negative, clear bit 23 of the instruction.
18908 Otherwise set it. */
18909 if (value < 0)
18910 insn &= ~(1 << 23);
18911 else
18912 insn |= 1 << 23;
18913
18914 /* Place the absolute value of the addend into the first 12 bits
18915 of the instruction. */
18916 insn &= 0xfffff000;
18917 insn |= addend_abs;
18918
18919 /* Update the instruction. */
18920 md_number_to_chars (buf, insn, INSN_SIZE);
18921 }
18922 break;
18923
18924 case BFD_RELOC_ARM_LDRS_PC_G0:
18925 case BFD_RELOC_ARM_LDRS_PC_G1:
18926 case BFD_RELOC_ARM_LDRS_PC_G2:
18927 case BFD_RELOC_ARM_LDRS_SB_G0:
18928 case BFD_RELOC_ARM_LDRS_SB_G1:
18929 case BFD_RELOC_ARM_LDRS_SB_G2:
18930 assert (!fixP->fx_done);
18931 if (!seg->use_rela_p)
18932 {
18933 bfd_vma insn;
18934 bfd_vma addend_abs = abs (value);
18935
18936 /* Check that the absolute value of the addend can be
18937 encoded in 8 bits. */
18938 if (addend_abs >= 0x100)
18939 as_bad_where (fixP->fx_file, fixP->fx_line,
18940 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
18941 (unsigned long) addend_abs);
18942
18943 /* Extract the instruction. */
18944 insn = md_chars_to_number (buf, INSN_SIZE);
18945
18946 /* If the addend is negative, clear bit 23 of the instruction.
18947 Otherwise set it. */
18948 if (value < 0)
18949 insn &= ~(1 << 23);
18950 else
18951 insn |= 1 << 23;
18952
18953 /* Place the first four bits of the absolute value of the addend
18954 into the first 4 bits of the instruction, and the remaining
18955 four into bits 8 .. 11. */
18956 insn &= 0xfffff0f0;
18957 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
18958
18959 /* Update the instruction. */
18960 md_number_to_chars (buf, insn, INSN_SIZE);
18961 }
18962 break;
18963
18964 case BFD_RELOC_ARM_LDC_PC_G0:
18965 case BFD_RELOC_ARM_LDC_PC_G1:
18966 case BFD_RELOC_ARM_LDC_PC_G2:
18967 case BFD_RELOC_ARM_LDC_SB_G0:
18968 case BFD_RELOC_ARM_LDC_SB_G1:
18969 case BFD_RELOC_ARM_LDC_SB_G2:
18970 assert (!fixP->fx_done);
18971 if (!seg->use_rela_p)
18972 {
18973 bfd_vma insn;
18974 bfd_vma addend_abs = abs (value);
18975
18976 /* Check that the absolute value of the addend is a multiple of
18977 four and, when divided by four, fits in 8 bits. */
18978 if (addend_abs & 0x3)
18979 as_bad_where (fixP->fx_file, fixP->fx_line,
18980 _("bad offset 0x%08lX (must be word-aligned)"),
18981 (unsigned long) addend_abs);
18982
18983 if ((addend_abs >> 2) > 0xff)
18984 as_bad_where (fixP->fx_file, fixP->fx_line,
18985 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
18986 (unsigned long) addend_abs);
18987
18988 /* Extract the instruction. */
18989 insn = md_chars_to_number (buf, INSN_SIZE);
18990
18991 /* If the addend is negative, clear bit 23 of the instruction.
18992 Otherwise set it. */
18993 if (value < 0)
18994 insn &= ~(1 << 23);
18995 else
18996 insn |= 1 << 23;
18997
18998 /* Place the addend (divided by four) into the first eight
18999 bits of the instruction. */
19000 insn &= 0xfffffff0;
19001 insn |= addend_abs >> 2;
19002
19003 /* Update the instruction. */
19004 md_number_to_chars (buf, insn, INSN_SIZE);
19005 }
19006 break;
19007
19008 case BFD_RELOC_ARM_V4BX:
19009 /* This will need to go in the object file. */
19010 fixP->fx_done = 0;
19011 break;
19012
19013 case BFD_RELOC_UNUSED:
19014 default:
19015 as_bad_where (fixP->fx_file, fixP->fx_line,
19016 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
19017 }
19018 }
19019
19020 /* Translate internal representation of relocation info to BFD target
19021 format. */
19022
19023 arelent *
19024 tc_gen_reloc (asection *section, fixS *fixp)
19025 {
19026 arelent * reloc;
19027 bfd_reloc_code_real_type code;
19028
19029 reloc = xmalloc (sizeof (arelent));
19030
19031 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
19032 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
19033 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
19034
19035 if (fixp->fx_pcrel)
19036 {
19037 if (section->use_rela_p)
19038 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
19039 else
19040 fixp->fx_offset = reloc->address;
19041 }
19042 reloc->addend = fixp->fx_offset;
19043
19044 switch (fixp->fx_r_type)
19045 {
19046 case BFD_RELOC_8:
19047 if (fixp->fx_pcrel)
19048 {
19049 code = BFD_RELOC_8_PCREL;
19050 break;
19051 }
19052
19053 case BFD_RELOC_16:
19054 if (fixp->fx_pcrel)
19055 {
19056 code = BFD_RELOC_16_PCREL;
19057 break;
19058 }
19059
19060 case BFD_RELOC_32:
19061 if (fixp->fx_pcrel)
19062 {
19063 code = BFD_RELOC_32_PCREL;
19064 break;
19065 }
19066
19067 case BFD_RELOC_ARM_MOVW:
19068 if (fixp->fx_pcrel)
19069 {
19070 code = BFD_RELOC_ARM_MOVW_PCREL;
19071 break;
19072 }
19073
19074 case BFD_RELOC_ARM_MOVT:
19075 if (fixp->fx_pcrel)
19076 {
19077 code = BFD_RELOC_ARM_MOVT_PCREL;
19078 break;
19079 }
19080
19081 case BFD_RELOC_ARM_THUMB_MOVW:
19082 if (fixp->fx_pcrel)
19083 {
19084 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
19085 break;
19086 }
19087
19088 case BFD_RELOC_ARM_THUMB_MOVT:
19089 if (fixp->fx_pcrel)
19090 {
19091 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
19092 break;
19093 }
19094
19095 case BFD_RELOC_NONE:
19096 case BFD_RELOC_ARM_PCREL_BRANCH:
19097 case BFD_RELOC_ARM_PCREL_BLX:
19098 case BFD_RELOC_RVA:
19099 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19100 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19101 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19102 case BFD_RELOC_THUMB_PCREL_BRANCH20:
19103 case BFD_RELOC_THUMB_PCREL_BRANCH23:
19104 case BFD_RELOC_THUMB_PCREL_BRANCH25:
19105 case BFD_RELOC_THUMB_PCREL_BLX:
19106 case BFD_RELOC_VTABLE_ENTRY:
19107 case BFD_RELOC_VTABLE_INHERIT:
19108 #ifdef TE_PE
19109 case BFD_RELOC_32_SECREL:
19110 #endif
19111 code = fixp->fx_r_type;
19112 break;
19113
19114 case BFD_RELOC_ARM_LITERAL:
19115 case BFD_RELOC_ARM_HWLITERAL:
19116 /* If this is called then the a literal has
19117 been referenced across a section boundary. */
19118 as_bad_where (fixp->fx_file, fixp->fx_line,
19119 _("literal referenced across section boundary"));
19120 return NULL;
19121
19122 #ifdef OBJ_ELF
19123 case BFD_RELOC_ARM_GOT32:
19124 case BFD_RELOC_ARM_GOTOFF:
19125 case BFD_RELOC_ARM_PLT32:
19126 case BFD_RELOC_ARM_TARGET1:
19127 case BFD_RELOC_ARM_ROSEGREL32:
19128 case BFD_RELOC_ARM_SBREL32:
19129 case BFD_RELOC_ARM_PREL31:
19130 case BFD_RELOC_ARM_TARGET2:
19131 case BFD_RELOC_ARM_TLS_LE32:
19132 case BFD_RELOC_ARM_TLS_LDO32:
19133 case BFD_RELOC_ARM_PCREL_CALL:
19134 case BFD_RELOC_ARM_PCREL_JUMP:
19135 case BFD_RELOC_ARM_ALU_PC_G0_NC:
19136 case BFD_RELOC_ARM_ALU_PC_G0:
19137 case BFD_RELOC_ARM_ALU_PC_G1_NC:
19138 case BFD_RELOC_ARM_ALU_PC_G1:
19139 case BFD_RELOC_ARM_ALU_PC_G2:
19140 case BFD_RELOC_ARM_LDR_PC_G0:
19141 case BFD_RELOC_ARM_LDR_PC_G1:
19142 case BFD_RELOC_ARM_LDR_PC_G2:
19143 case BFD_RELOC_ARM_LDRS_PC_G0:
19144 case BFD_RELOC_ARM_LDRS_PC_G1:
19145 case BFD_RELOC_ARM_LDRS_PC_G2:
19146 case BFD_RELOC_ARM_LDC_PC_G0:
19147 case BFD_RELOC_ARM_LDC_PC_G1:
19148 case BFD_RELOC_ARM_LDC_PC_G2:
19149 case BFD_RELOC_ARM_ALU_SB_G0_NC:
19150 case BFD_RELOC_ARM_ALU_SB_G0:
19151 case BFD_RELOC_ARM_ALU_SB_G1_NC:
19152 case BFD_RELOC_ARM_ALU_SB_G1:
19153 case BFD_RELOC_ARM_ALU_SB_G2:
19154 case BFD_RELOC_ARM_LDR_SB_G0:
19155 case BFD_RELOC_ARM_LDR_SB_G1:
19156 case BFD_RELOC_ARM_LDR_SB_G2:
19157 case BFD_RELOC_ARM_LDRS_SB_G0:
19158 case BFD_RELOC_ARM_LDRS_SB_G1:
19159 case BFD_RELOC_ARM_LDRS_SB_G2:
19160 case BFD_RELOC_ARM_LDC_SB_G0:
19161 case BFD_RELOC_ARM_LDC_SB_G1:
19162 case BFD_RELOC_ARM_LDC_SB_G2:
19163 case BFD_RELOC_ARM_V4BX:
19164 code = fixp->fx_r_type;
19165 break;
19166
19167 case BFD_RELOC_ARM_TLS_GD32:
19168 case BFD_RELOC_ARM_TLS_IE32:
19169 case BFD_RELOC_ARM_TLS_LDM32:
19170 /* BFD will include the symbol's address in the addend.
19171 But we don't want that, so subtract it out again here. */
19172 if (!S_IS_COMMON (fixp->fx_addsy))
19173 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
19174 code = fixp->fx_r_type;
19175 break;
19176 #endif
19177
19178 case BFD_RELOC_ARM_IMMEDIATE:
19179 as_bad_where (fixp->fx_file, fixp->fx_line,
19180 _("internal relocation (type: IMMEDIATE) not fixed up"));
19181 return NULL;
19182
19183 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19184 as_bad_where (fixp->fx_file, fixp->fx_line,
19185 _("ADRL used for a symbol not defined in the same file"));
19186 return NULL;
19187
19188 case BFD_RELOC_ARM_OFFSET_IMM:
19189 if (section->use_rela_p)
19190 {
19191 code = fixp->fx_r_type;
19192 break;
19193 }
19194
19195 if (fixp->fx_addsy != NULL
19196 && !S_IS_DEFINED (fixp->fx_addsy)
19197 && S_IS_LOCAL (fixp->fx_addsy))
19198 {
19199 as_bad_where (fixp->fx_file, fixp->fx_line,
19200 _("undefined local label `%s'"),
19201 S_GET_NAME (fixp->fx_addsy));
19202 return NULL;
19203 }
19204
19205 as_bad_where (fixp->fx_file, fixp->fx_line,
19206 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
19207 return NULL;
19208
19209 default:
19210 {
19211 char * type;
19212
19213 switch (fixp->fx_r_type)
19214 {
19215 case BFD_RELOC_NONE: type = "NONE"; break;
19216 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
19217 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
19218 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
19219 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
19220 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
19221 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
19222 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
19223 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
19224 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
19225 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
19226 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
19227 default: type = _("<unknown>"); break;
19228 }
19229 as_bad_where (fixp->fx_file, fixp->fx_line,
19230 _("cannot represent %s relocation in this object file format"),
19231 type);
19232 return NULL;
19233 }
19234 }
19235
19236 #ifdef OBJ_ELF
19237 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
19238 && GOT_symbol
19239 && fixp->fx_addsy == GOT_symbol)
19240 {
19241 code = BFD_RELOC_ARM_GOTPC;
19242 reloc->addend = fixp->fx_offset = reloc->address;
19243 }
19244 #endif
19245
19246 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
19247
19248 if (reloc->howto == NULL)
19249 {
19250 as_bad_where (fixp->fx_file, fixp->fx_line,
19251 _("cannot represent %s relocation in this object file format"),
19252 bfd_get_reloc_code_name (code));
19253 return NULL;
19254 }
19255
19256 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
19257 vtable entry to be used in the relocation's section offset. */
19258 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19259 reloc->address = fixp->fx_offset;
19260
19261 return reloc;
19262 }
19263
19264 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
19265
19266 void
19267 cons_fix_new_arm (fragS * frag,
19268 int where,
19269 int size,
19270 expressionS * exp)
19271 {
19272 bfd_reloc_code_real_type type;
19273 int pcrel = 0;
19274
19275 /* Pick a reloc.
19276 FIXME: @@ Should look at CPU word size. */
19277 switch (size)
19278 {
19279 case 1:
19280 type = BFD_RELOC_8;
19281 break;
19282 case 2:
19283 type = BFD_RELOC_16;
19284 break;
19285 case 4:
19286 default:
19287 type = BFD_RELOC_32;
19288 break;
19289 case 8:
19290 type = BFD_RELOC_64;
19291 break;
19292 }
19293
19294 #ifdef TE_PE
19295 if (exp->X_op == O_secrel)
19296 {
19297 exp->X_op = O_symbol;
19298 type = BFD_RELOC_32_SECREL;
19299 }
19300 #endif
19301
19302 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
19303 }
19304
19305 #if defined OBJ_COFF || defined OBJ_ELF
19306 void
19307 arm_validate_fix (fixS * fixP)
19308 {
19309 /* If the destination of the branch is a defined symbol which does not have
19310 the THUMB_FUNC attribute, then we must be calling a function which has
19311 the (interfacearm) attribute. We look for the Thumb entry point to that
19312 function and change the branch to refer to that function instead. */
19313 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
19314 && fixP->fx_addsy != NULL
19315 && S_IS_DEFINED (fixP->fx_addsy)
19316 && ! THUMB_IS_FUNC (fixP->fx_addsy))
19317 {
19318 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
19319 }
19320 }
19321 #endif
19322
19323 int
19324 arm_force_relocation (struct fix * fixp)
19325 {
19326 #if defined (OBJ_COFF) && defined (TE_PE)
19327 if (fixp->fx_r_type == BFD_RELOC_RVA)
19328 return 1;
19329 #endif
19330
19331 /* Resolve these relocations even if the symbol is extern or weak. */
19332 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
19333 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
19334 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
19335 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
19336 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
19337 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
19338 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
19339 return 0;
19340
19341 /* Always leave these relocations for the linker. */
19342 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19343 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19344 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19345 return 1;
19346
19347 /* Always generate relocations against function symbols. */
19348 if (fixp->fx_r_type == BFD_RELOC_32
19349 && fixp->fx_addsy
19350 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
19351 return 1;
19352
19353 return generic_force_reloc (fixp);
19354 }
19355
19356 #if defined (OBJ_ELF) || defined (OBJ_COFF)
19357 /* Relocations against function names must be left unadjusted,
19358 so that the linker can use this information to generate interworking
19359 stubs. The MIPS version of this function
19360 also prevents relocations that are mips-16 specific, but I do not
19361 know why it does this.
19362
19363 FIXME:
19364 There is one other problem that ought to be addressed here, but
19365 which currently is not: Taking the address of a label (rather
19366 than a function) and then later jumping to that address. Such
19367 addresses also ought to have their bottom bit set (assuming that
19368 they reside in Thumb code), but at the moment they will not. */
19369
19370 bfd_boolean
19371 arm_fix_adjustable (fixS * fixP)
19372 {
19373 if (fixP->fx_addsy == NULL)
19374 return 1;
19375
19376 /* Preserve relocations against symbols with function type. */
19377 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
19378 return 0;
19379
19380 if (THUMB_IS_FUNC (fixP->fx_addsy)
19381 && fixP->fx_subsy == NULL)
19382 return 0;
19383
19384 /* We need the symbol name for the VTABLE entries. */
19385 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
19386 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19387 return 0;
19388
19389 /* Don't allow symbols to be discarded on GOT related relocs. */
19390 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
19391 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
19392 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
19393 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
19394 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
19395 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
19396 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
19397 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
19398 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
19399 return 0;
19400
19401 /* Similarly for group relocations. */
19402 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19403 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19404 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19405 return 0;
19406
19407 return 1;
19408 }
19409 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
19410
19411 #ifdef OBJ_ELF
19412
19413 const char *
19414 elf32_arm_target_format (void)
19415 {
19416 #ifdef TE_SYMBIAN
19417 return (target_big_endian
19418 ? "elf32-bigarm-symbian"
19419 : "elf32-littlearm-symbian");
19420 #elif defined (TE_VXWORKS)
19421 return (target_big_endian
19422 ? "elf32-bigarm-vxworks"
19423 : "elf32-littlearm-vxworks");
19424 #else
19425 if (target_big_endian)
19426 return "elf32-bigarm";
19427 else
19428 return "elf32-littlearm";
19429 #endif
19430 }
19431
19432 void
19433 armelf_frob_symbol (symbolS * symp,
19434 int * puntp)
19435 {
19436 elf_frob_symbol (symp, puntp);
19437 }
19438 #endif
19439
19440 /* MD interface: Finalization. */
19441
19442 /* A good place to do this, although this was probably not intended
19443 for this kind of use. We need to dump the literal pool before
19444 references are made to a null symbol pointer. */
19445
19446 void
19447 arm_cleanup (void)
19448 {
19449 literal_pool * pool;
19450
19451 for (pool = list_of_pools; pool; pool = pool->next)
19452 {
19453 /* Put it at the end of the relevant section. */
19454 subseg_set (pool->section, pool->sub_section);
19455 #ifdef OBJ_ELF
19456 arm_elf_change_section ();
19457 #endif
19458 s_ltorg (0);
19459 }
19460 }
19461
19462 /* Adjust the symbol table. This marks Thumb symbols as distinct from
19463 ARM ones. */
19464
19465 void
19466 arm_adjust_symtab (void)
19467 {
19468 #ifdef OBJ_COFF
19469 symbolS * sym;
19470
19471 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
19472 {
19473 if (ARM_IS_THUMB (sym))
19474 {
19475 if (THUMB_IS_FUNC (sym))
19476 {
19477 /* Mark the symbol as a Thumb function. */
19478 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
19479 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
19480 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
19481
19482 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
19483 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
19484 else
19485 as_bad (_("%s: unexpected function type: %d"),
19486 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
19487 }
19488 else switch (S_GET_STORAGE_CLASS (sym))
19489 {
19490 case C_EXT:
19491 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
19492 break;
19493 case C_STAT:
19494 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
19495 break;
19496 case C_LABEL:
19497 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
19498 break;
19499 default:
19500 /* Do nothing. */
19501 break;
19502 }
19503 }
19504
19505 if (ARM_IS_INTERWORK (sym))
19506 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
19507 }
19508 #endif
19509 #ifdef OBJ_ELF
19510 symbolS * sym;
19511 char bind;
19512
19513 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
19514 {
19515 if (ARM_IS_THUMB (sym))
19516 {
19517 elf_symbol_type * elf_sym;
19518
19519 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
19520 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
19521
19522 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
19523 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
19524 {
19525 /* If it's a .thumb_func, declare it as so,
19526 otherwise tag label as .code 16. */
19527 if (THUMB_IS_FUNC (sym))
19528 elf_sym->internal_elf_sym.st_info =
19529 ELF_ST_INFO (bind, STT_ARM_TFUNC);
19530 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
19531 elf_sym->internal_elf_sym.st_info =
19532 ELF_ST_INFO (bind, STT_ARM_16BIT);
19533 }
19534 }
19535 }
19536 #endif
19537 }
19538
19539 /* MD interface: Initialization. */
19540
19541 static void
19542 set_constant_flonums (void)
19543 {
19544 int i;
19545
19546 for (i = 0; i < NUM_FLOAT_VALS; i++)
19547 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
19548 abort ();
19549 }
19550
19551 /* Auto-select Thumb mode if it's the only available instruction set for the
19552 given architecture. */
19553
19554 static void
19555 autoselect_thumb_from_cpu_variant (void)
19556 {
19557 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
19558 opcode_select (16);
19559 }
19560
19561 void
19562 md_begin (void)
19563 {
19564 unsigned mach;
19565 unsigned int i;
19566
19567 if ( (arm_ops_hsh = hash_new ()) == NULL
19568 || (arm_cond_hsh = hash_new ()) == NULL
19569 || (arm_shift_hsh = hash_new ()) == NULL
19570 || (arm_psr_hsh = hash_new ()) == NULL
19571 || (arm_v7m_psr_hsh = hash_new ()) == NULL
19572 || (arm_reg_hsh = hash_new ()) == NULL
19573 || (arm_reloc_hsh = hash_new ()) == NULL
19574 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
19575 as_fatal (_("virtual memory exhausted"));
19576
19577 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
19578 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
19579 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
19580 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
19581 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
19582 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
19583 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
19584 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
19585 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
19586 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (PTR) (v7m_psrs + i));
19587 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
19588 hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i));
19589 for (i = 0;
19590 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
19591 i++)
19592 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
19593 (PTR) (barrier_opt_names + i));
19594 #ifdef OBJ_ELF
19595 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
19596 hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i));
19597 #endif
19598
19599 set_constant_flonums ();
19600
19601 /* Set the cpu variant based on the command-line options. We prefer
19602 -mcpu= over -march= if both are set (as for GCC); and we prefer
19603 -mfpu= over any other way of setting the floating point unit.
19604 Use of legacy options with new options are faulted. */
19605 if (legacy_cpu)
19606 {
19607 if (mcpu_cpu_opt || march_cpu_opt)
19608 as_bad (_("use of old and new-style options to set CPU type"));
19609
19610 mcpu_cpu_opt = legacy_cpu;
19611 }
19612 else if (!mcpu_cpu_opt)
19613 mcpu_cpu_opt = march_cpu_opt;
19614
19615 if (legacy_fpu)
19616 {
19617 if (mfpu_opt)
19618 as_bad (_("use of old and new-style options to set FPU type"));
19619
19620 mfpu_opt = legacy_fpu;
19621 }
19622 else if (!mfpu_opt)
19623 {
19624 #if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
19625 /* Some environments specify a default FPU. If they don't, infer it
19626 from the processor. */
19627 if (mcpu_fpu_opt)
19628 mfpu_opt = mcpu_fpu_opt;
19629 else
19630 mfpu_opt = march_fpu_opt;
19631 #else
19632 mfpu_opt = &fpu_default;
19633 #endif
19634 }
19635
19636 if (!mfpu_opt)
19637 {
19638 if (mcpu_cpu_opt != NULL)
19639 mfpu_opt = &fpu_default;
19640 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
19641 mfpu_opt = &fpu_arch_vfp_v2;
19642 else
19643 mfpu_opt = &fpu_arch_fpa;
19644 }
19645
19646 #ifdef CPU_DEFAULT
19647 if (!mcpu_cpu_opt)
19648 {
19649 mcpu_cpu_opt = &cpu_default;
19650 selected_cpu = cpu_default;
19651 }
19652 #else
19653 if (mcpu_cpu_opt)
19654 selected_cpu = *mcpu_cpu_opt;
19655 else
19656 mcpu_cpu_opt = &arm_arch_any;
19657 #endif
19658
19659 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
19660
19661 autoselect_thumb_from_cpu_variant ();
19662
19663 arm_arch_used = thumb_arch_used = arm_arch_none;
19664
19665 #if defined OBJ_COFF || defined OBJ_ELF
19666 {
19667 unsigned int flags = 0;
19668
19669 #if defined OBJ_ELF
19670 flags = meabi_flags;
19671
19672 switch (meabi_flags)
19673 {
19674 case EF_ARM_EABI_UNKNOWN:
19675 #endif
19676 /* Set the flags in the private structure. */
19677 if (uses_apcs_26) flags |= F_APCS26;
19678 if (support_interwork) flags |= F_INTERWORK;
19679 if (uses_apcs_float) flags |= F_APCS_FLOAT;
19680 if (pic_code) flags |= F_PIC;
19681 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
19682 flags |= F_SOFT_FLOAT;
19683
19684 switch (mfloat_abi_opt)
19685 {
19686 case ARM_FLOAT_ABI_SOFT:
19687 case ARM_FLOAT_ABI_SOFTFP:
19688 flags |= F_SOFT_FLOAT;
19689 break;
19690
19691 case ARM_FLOAT_ABI_HARD:
19692 if (flags & F_SOFT_FLOAT)
19693 as_bad (_("hard-float conflicts with specified fpu"));
19694 break;
19695 }
19696
19697 /* Using pure-endian doubles (even if soft-float). */
19698 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
19699 flags |= F_VFP_FLOAT;
19700
19701 #if defined OBJ_ELF
19702 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
19703 flags |= EF_ARM_MAVERICK_FLOAT;
19704 break;
19705
19706 case EF_ARM_EABI_VER4:
19707 case EF_ARM_EABI_VER5:
19708 /* No additional flags to set. */
19709 break;
19710
19711 default:
19712 abort ();
19713 }
19714 #endif
19715 bfd_set_private_flags (stdoutput, flags);
19716
19717 /* We have run out flags in the COFF header to encode the
19718 status of ATPCS support, so instead we create a dummy,
19719 empty, debug section called .arm.atpcs. */
19720 if (atpcs)
19721 {
19722 asection * sec;
19723
19724 sec = bfd_make_section (stdoutput, ".arm.atpcs");
19725
19726 if (sec != NULL)
19727 {
19728 bfd_set_section_flags
19729 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
19730 bfd_set_section_size (stdoutput, sec, 0);
19731 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
19732 }
19733 }
19734 }
19735 #endif
19736
19737 /* Record the CPU type as well. */
19738 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
19739 mach = bfd_mach_arm_iWMMXt2;
19740 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
19741 mach = bfd_mach_arm_iWMMXt;
19742 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
19743 mach = bfd_mach_arm_XScale;
19744 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
19745 mach = bfd_mach_arm_ep9312;
19746 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
19747 mach = bfd_mach_arm_5TE;
19748 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
19749 {
19750 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
19751 mach = bfd_mach_arm_5T;
19752 else
19753 mach = bfd_mach_arm_5;
19754 }
19755 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
19756 {
19757 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
19758 mach = bfd_mach_arm_4T;
19759 else
19760 mach = bfd_mach_arm_4;
19761 }
19762 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
19763 mach = bfd_mach_arm_3M;
19764 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
19765 mach = bfd_mach_arm_3;
19766 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
19767 mach = bfd_mach_arm_2a;
19768 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
19769 mach = bfd_mach_arm_2;
19770 else
19771 mach = bfd_mach_arm_unknown;
19772
19773 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
19774 }
19775
19776 /* Command line processing. */
19777
19778 /* md_parse_option
19779 Invocation line includes a switch not recognized by the base assembler.
19780 See if it's a processor-specific option.
19781
19782 This routine is somewhat complicated by the need for backwards
19783 compatibility (since older releases of gcc can't be changed).
19784 The new options try to make the interface as compatible as
19785 possible with GCC.
19786
19787 New options (supported) are:
19788
19789 -mcpu=<cpu name> Assemble for selected processor
19790 -march=<architecture name> Assemble for selected architecture
19791 -mfpu=<fpu architecture> Assemble for selected FPU.
19792 -EB/-mbig-endian Big-endian
19793 -EL/-mlittle-endian Little-endian
19794 -k Generate PIC code
19795 -mthumb Start in Thumb mode
19796 -mthumb-interwork Code supports ARM/Thumb interworking
19797
19798 For now we will also provide support for:
19799
19800 -mapcs-32 32-bit Program counter
19801 -mapcs-26 26-bit Program counter
19802 -macps-float Floats passed in FP registers
19803 -mapcs-reentrant Reentrant code
19804 -matpcs
19805 (sometime these will probably be replaced with -mapcs=<list of options>
19806 and -matpcs=<list of options>)
19807
19808 The remaining options are only supported for back-wards compatibility.
19809 Cpu variants, the arm part is optional:
19810 -m[arm]1 Currently not supported.
19811 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
19812 -m[arm]3 Arm 3 processor
19813 -m[arm]6[xx], Arm 6 processors
19814 -m[arm]7[xx][t][[d]m] Arm 7 processors
19815 -m[arm]8[10] Arm 8 processors
19816 -m[arm]9[20][tdmi] Arm 9 processors
19817 -mstrongarm[110[0]] StrongARM processors
19818 -mxscale XScale processors
19819 -m[arm]v[2345[t[e]]] Arm architectures
19820 -mall All (except the ARM1)
19821 FP variants:
19822 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
19823 -mfpe-old (No float load/store multiples)
19824 -mvfpxd VFP Single precision
19825 -mvfp All VFP
19826 -mno-fpu Disable all floating point instructions
19827
19828 The following CPU names are recognized:
19829 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
19830 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
19831 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
19832 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
19833 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
19834 arm10t arm10e, arm1020t, arm1020e, arm10200e,
19835 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
19836
19837 */
19838
19839 const char * md_shortopts = "m:k";
19840
19841 #ifdef ARM_BI_ENDIAN
19842 #define OPTION_EB (OPTION_MD_BASE + 0)
19843 #define OPTION_EL (OPTION_MD_BASE + 1)
19844 #else
19845 #if TARGET_BYTES_BIG_ENDIAN
19846 #define OPTION_EB (OPTION_MD_BASE + 0)
19847 #else
19848 #define OPTION_EL (OPTION_MD_BASE + 1)
19849 #endif
19850 #endif
19851 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
19852
19853 struct option md_longopts[] =
19854 {
19855 #ifdef OPTION_EB
19856 {"EB", no_argument, NULL, OPTION_EB},
19857 #endif
19858 #ifdef OPTION_EL
19859 {"EL", no_argument, NULL, OPTION_EL},
19860 #endif
19861 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
19862 {NULL, no_argument, NULL, 0}
19863 };
19864
19865 size_t md_longopts_size = sizeof (md_longopts);
19866
19867 struct arm_option_table
19868 {
19869 char *option; /* Option name to match. */
19870 char *help; /* Help information. */
19871 int *var; /* Variable to change. */
19872 int value; /* What to change it to. */
19873 char *deprecated; /* If non-null, print this message. */
19874 };
19875
19876 struct arm_option_table arm_opts[] =
19877 {
19878 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
19879 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
19880 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
19881 &support_interwork, 1, NULL},
19882 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
19883 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
19884 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
19885 1, NULL},
19886 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
19887 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
19888 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
19889 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
19890 NULL},
19891
19892 /* These are recognized by the assembler, but have no affect on code. */
19893 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
19894 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
19895 {NULL, NULL, NULL, 0, NULL}
19896 };
19897
19898 struct arm_legacy_option_table
19899 {
19900 char *option; /* Option name to match. */
19901 const arm_feature_set **var; /* Variable to change. */
19902 const arm_feature_set value; /* What to change it to. */
19903 char *deprecated; /* If non-null, print this message. */
19904 };
19905
19906 const struct arm_legacy_option_table arm_legacy_opts[] =
19907 {
19908 /* DON'T add any new processors to this list -- we want the whole list
19909 to go away... Add them to the processors table instead. */
19910 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19911 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19912 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19913 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19914 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19915 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19916 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19917 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19918 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19919 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19920 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19921 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19922 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19923 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19924 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19925 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19926 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19927 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19928 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19929 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19930 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19931 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19932 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19933 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19934 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19935 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19936 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19937 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19938 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19939 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19940 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19941 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19942 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19943 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19944 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19945 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19946 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19947 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19948 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19949 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19950 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19951 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19952 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19953 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19954 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19955 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19956 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19957 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19958 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19959 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19960 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19961 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19962 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19963 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19964 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19965 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19966 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19967 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19968 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19969 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19970 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19971 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19972 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19973 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19974 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19975 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19976 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19977 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19978 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
19979 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
19980 N_("use -mcpu=strongarm110")},
19981 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
19982 N_("use -mcpu=strongarm1100")},
19983 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
19984 N_("use -mcpu=strongarm1110")},
19985 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
19986 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
19987 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
19988
19989 /* Architecture variants -- don't add any more to this list either. */
19990 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19991 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19992 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19993 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19994 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19995 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19996 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
19997 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
19998 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
19999 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
20000 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
20001 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
20002 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
20003 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
20004 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
20005 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
20006 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
20007 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
20008
20009 /* Floating point variants -- don't add any more to this list either. */
20010 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
20011 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
20012 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
20013 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
20014 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
20015
20016 {NULL, NULL, ARM_ARCH_NONE, NULL}
20017 };
20018
20019 struct arm_cpu_option_table
20020 {
20021 char *name;
20022 const arm_feature_set value;
20023 /* For some CPUs we assume an FPU unless the user explicitly sets
20024 -mfpu=... */
20025 const arm_feature_set default_fpu;
20026 /* The canonical name of the CPU, or NULL to use NAME converted to upper
20027 case. */
20028 const char *canonical_name;
20029 };
20030
20031 /* This list should, at a minimum, contain all the cpu names
20032 recognized by GCC. */
20033 static const struct arm_cpu_option_table arm_cpus[] =
20034 {
20035 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
20036 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
20037 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
20038 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20039 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20040 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20041 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20042 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20043 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20044 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20045 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20046 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20047 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20048 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20049 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20050 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20051 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20052 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20053 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20054 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20055 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20056 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20057 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20058 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20059 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20060 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20061 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20062 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20063 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20064 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20065 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20066 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20067 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20068 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20069 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20070 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20071 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20072 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20073 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20074 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
20075 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20076 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20077 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20078 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20079 /* For V5 or later processors we default to using VFP; but the user
20080 should really set the FPU type explicitly. */
20081 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20082 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20083 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20084 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20085 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20086 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20087 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
20088 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20089 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20090 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
20091 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20092 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20093 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20094 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20095 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20096 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
20097 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20098 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20099 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20100 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
20101 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20102 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
20103 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
20104 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
20105 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
20106 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
20107 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
20108 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
20109 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
20110 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
20111 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
20112 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
20113 | FPU_NEON_EXT_V1),
20114 NULL},
20115 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
20116 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
20117 {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL},
20118 /* ??? XSCALE is really an architecture. */
20119 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
20120 /* ??? iwmmxt is not a processor. */
20121 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
20122 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
20123 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
20124 /* Maverick */
20125 {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
20126 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
20127 };
20128
20129 struct arm_arch_option_table
20130 {
20131 char *name;
20132 const arm_feature_set value;
20133 const arm_feature_set default_fpu;
20134 };
20135
20136 /* This list should, at a minimum, contain all the architecture names
20137 recognized by GCC. */
20138 static const struct arm_arch_option_table arm_archs[] =
20139 {
20140 {"all", ARM_ANY, FPU_ARCH_FPA},
20141 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
20142 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
20143 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
20144 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
20145 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
20146 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
20147 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
20148 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
20149 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
20150 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
20151 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
20152 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
20153 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
20154 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
20155 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
20156 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
20157 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
20158 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
20159 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
20160 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
20161 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
20162 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
20163 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
20164 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
20165 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
20166 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
20167 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
20168 /* The official spelling of the ARMv7 profile variants is the dashed form.
20169 Accept the non-dashed form for compatibility with old toolchains. */
20170 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20171 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20172 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
20173 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20174 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20175 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
20176 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
20177 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
20178 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
20179 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
20180 };
20181
20182 /* ISA extensions in the co-processor space. */
20183 struct arm_option_cpu_value_table
20184 {
20185 char *name;
20186 const arm_feature_set value;
20187 };
20188
20189 static const struct arm_option_cpu_value_table arm_extensions[] =
20190 {
20191 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
20192 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
20193 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
20194 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
20195 {NULL, ARM_ARCH_NONE}
20196 };
20197
20198 /* This list should, at a minimum, contain all the fpu names
20199 recognized by GCC. */
20200 static const struct arm_option_cpu_value_table arm_fpus[] =
20201 {
20202 {"softfpa", FPU_NONE},
20203 {"fpe", FPU_ARCH_FPE},
20204 {"fpe2", FPU_ARCH_FPE},
20205 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
20206 {"fpa", FPU_ARCH_FPA},
20207 {"fpa10", FPU_ARCH_FPA},
20208 {"fpa11", FPU_ARCH_FPA},
20209 {"arm7500fe", FPU_ARCH_FPA},
20210 {"softvfp", FPU_ARCH_VFP},
20211 {"softvfp+vfp", FPU_ARCH_VFP_V2},
20212 {"vfp", FPU_ARCH_VFP_V2},
20213 {"vfp9", FPU_ARCH_VFP_V2},
20214 {"vfp3", FPU_ARCH_VFP_V3},
20215 {"vfp10", FPU_ARCH_VFP_V2},
20216 {"vfp10-r0", FPU_ARCH_VFP_V1},
20217 {"vfpxd", FPU_ARCH_VFP_V1xD},
20218 {"arm1020t", FPU_ARCH_VFP_V1},
20219 {"arm1020e", FPU_ARCH_VFP_V2},
20220 {"arm1136jfs", FPU_ARCH_VFP_V2},
20221 {"arm1136jf-s", FPU_ARCH_VFP_V2},
20222 {"maverick", FPU_ARCH_MAVERICK},
20223 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
20224 {NULL, ARM_ARCH_NONE}
20225 };
20226
20227 struct arm_option_value_table
20228 {
20229 char *name;
20230 long value;
20231 };
20232
20233 static const struct arm_option_value_table arm_float_abis[] =
20234 {
20235 {"hard", ARM_FLOAT_ABI_HARD},
20236 {"softfp", ARM_FLOAT_ABI_SOFTFP},
20237 {"soft", ARM_FLOAT_ABI_SOFT},
20238 {NULL, 0}
20239 };
20240
20241 #ifdef OBJ_ELF
20242 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
20243 static const struct arm_option_value_table arm_eabis[] =
20244 {
20245 {"gnu", EF_ARM_EABI_UNKNOWN},
20246 {"4", EF_ARM_EABI_VER4},
20247 {"5", EF_ARM_EABI_VER5},
20248 {NULL, 0}
20249 };
20250 #endif
20251
20252 struct arm_long_option_table
20253 {
20254 char * option; /* Substring to match. */
20255 char * help; /* Help information. */
20256 int (* func) (char * subopt); /* Function to decode sub-option. */
20257 char * deprecated; /* If non-null, print this message. */
20258 };
20259
20260 static int
20261 arm_parse_extension (char * str, const arm_feature_set **opt_p)
20262 {
20263 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
20264
20265 /* Copy the feature set, so that we can modify it. */
20266 *ext_set = **opt_p;
20267 *opt_p = ext_set;
20268
20269 while (str != NULL && *str != 0)
20270 {
20271 const struct arm_option_cpu_value_table * opt;
20272 char * ext;
20273 int optlen;
20274
20275 if (*str != '+')
20276 {
20277 as_bad (_("invalid architectural extension"));
20278 return 0;
20279 }
20280
20281 str++;
20282 ext = strchr (str, '+');
20283
20284 if (ext != NULL)
20285 optlen = ext - str;
20286 else
20287 optlen = strlen (str);
20288
20289 if (optlen == 0)
20290 {
20291 as_bad (_("missing architectural extension"));
20292 return 0;
20293 }
20294
20295 for (opt = arm_extensions; opt->name != NULL; opt++)
20296 if (strncmp (opt->name, str, optlen) == 0)
20297 {
20298 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
20299 break;
20300 }
20301
20302 if (opt->name == NULL)
20303 {
20304 as_bad (_("unknown architectural extension `%s'"), str);
20305 return 0;
20306 }
20307
20308 str = ext;
20309 };
20310
20311 return 1;
20312 }
20313
20314 static int
20315 arm_parse_cpu (char * str)
20316 {
20317 const struct arm_cpu_option_table * opt;
20318 char * ext = strchr (str, '+');
20319 int optlen;
20320
20321 if (ext != NULL)
20322 optlen = ext - str;
20323 else
20324 optlen = strlen (str);
20325
20326 if (optlen == 0)
20327 {
20328 as_bad (_("missing cpu name `%s'"), str);
20329 return 0;
20330 }
20331
20332 for (opt = arm_cpus; opt->name != NULL; opt++)
20333 if (strncmp (opt->name, str, optlen) == 0)
20334 {
20335 mcpu_cpu_opt = &opt->value;
20336 mcpu_fpu_opt = &opt->default_fpu;
20337 if (opt->canonical_name)
20338 strcpy (selected_cpu_name, opt->canonical_name);
20339 else
20340 {
20341 int i;
20342 for (i = 0; i < optlen; i++)
20343 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20344 selected_cpu_name[i] = 0;
20345 }
20346
20347 if (ext != NULL)
20348 return arm_parse_extension (ext, &mcpu_cpu_opt);
20349
20350 return 1;
20351 }
20352
20353 as_bad (_("unknown cpu `%s'"), str);
20354 return 0;
20355 }
20356
20357 static int
20358 arm_parse_arch (char * str)
20359 {
20360 const struct arm_arch_option_table *opt;
20361 char *ext = strchr (str, '+');
20362 int optlen;
20363
20364 if (ext != NULL)
20365 optlen = ext - str;
20366 else
20367 optlen = strlen (str);
20368
20369 if (optlen == 0)
20370 {
20371 as_bad (_("missing architecture name `%s'"), str);
20372 return 0;
20373 }
20374
20375 for (opt = arm_archs; opt->name != NULL; opt++)
20376 if (streq (opt->name, str))
20377 {
20378 march_cpu_opt = &opt->value;
20379 march_fpu_opt = &opt->default_fpu;
20380 strcpy (selected_cpu_name, opt->name);
20381
20382 if (ext != NULL)
20383 return arm_parse_extension (ext, &march_cpu_opt);
20384
20385 return 1;
20386 }
20387
20388 as_bad (_("unknown architecture `%s'\n"), str);
20389 return 0;
20390 }
20391
20392 static int
20393 arm_parse_fpu (char * str)
20394 {
20395 const struct arm_option_cpu_value_table * opt;
20396
20397 for (opt = arm_fpus; opt->name != NULL; opt++)
20398 if (streq (opt->name, str))
20399 {
20400 mfpu_opt = &opt->value;
20401 return 1;
20402 }
20403
20404 as_bad (_("unknown floating point format `%s'\n"), str);
20405 return 0;
20406 }
20407
20408 static int
20409 arm_parse_float_abi (char * str)
20410 {
20411 const struct arm_option_value_table * opt;
20412
20413 for (opt = arm_float_abis; opt->name != NULL; opt++)
20414 if (streq (opt->name, str))
20415 {
20416 mfloat_abi_opt = opt->value;
20417 return 1;
20418 }
20419
20420 as_bad (_("unknown floating point abi `%s'\n"), str);
20421 return 0;
20422 }
20423
20424 #ifdef OBJ_ELF
20425 static int
20426 arm_parse_eabi (char * str)
20427 {
20428 const struct arm_option_value_table *opt;
20429
20430 for (opt = arm_eabis; opt->name != NULL; opt++)
20431 if (streq (opt->name, str))
20432 {
20433 meabi_flags = opt->value;
20434 return 1;
20435 }
20436 as_bad (_("unknown EABI `%s'\n"), str);
20437 return 0;
20438 }
20439 #endif
20440
20441 struct arm_long_option_table arm_long_opts[] =
20442 {
20443 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
20444 arm_parse_cpu, NULL},
20445 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
20446 arm_parse_arch, NULL},
20447 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
20448 arm_parse_fpu, NULL},
20449 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
20450 arm_parse_float_abi, NULL},
20451 #ifdef OBJ_ELF
20452 {"meabi=", N_("<ver>\t assemble for eabi version <ver>"),
20453 arm_parse_eabi, NULL},
20454 #endif
20455 {NULL, NULL, 0, NULL}
20456 };
20457
20458 int
20459 md_parse_option (int c, char * arg)
20460 {
20461 struct arm_option_table *opt;
20462 const struct arm_legacy_option_table *fopt;
20463 struct arm_long_option_table *lopt;
20464
20465 switch (c)
20466 {
20467 #ifdef OPTION_EB
20468 case OPTION_EB:
20469 target_big_endian = 1;
20470 break;
20471 #endif
20472
20473 #ifdef OPTION_EL
20474 case OPTION_EL:
20475 target_big_endian = 0;
20476 break;
20477 #endif
20478
20479 case OPTION_FIX_V4BX:
20480 fix_v4bx = TRUE;
20481 break;
20482
20483 case 'a':
20484 /* Listing option. Just ignore these, we don't support additional
20485 ones. */
20486 return 0;
20487
20488 default:
20489 for (opt = arm_opts; opt->option != NULL; opt++)
20490 {
20491 if (c == opt->option[0]
20492 && ((arg == NULL && opt->option[1] == 0)
20493 || streq (arg, opt->option + 1)))
20494 {
20495 #if WARN_DEPRECATED
20496 /* If the option is deprecated, tell the user. */
20497 if (opt->deprecated != NULL)
20498 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20499 arg ? arg : "", _(opt->deprecated));
20500 #endif
20501
20502 if (opt->var != NULL)
20503 *opt->var = opt->value;
20504
20505 return 1;
20506 }
20507 }
20508
20509 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
20510 {
20511 if (c == fopt->option[0]
20512 && ((arg == NULL && fopt->option[1] == 0)
20513 || streq (arg, fopt->option + 1)))
20514 {
20515 #if WARN_DEPRECATED
20516 /* If the option is deprecated, tell the user. */
20517 if (fopt->deprecated != NULL)
20518 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20519 arg ? arg : "", _(fopt->deprecated));
20520 #endif
20521
20522 if (fopt->var != NULL)
20523 *fopt->var = &fopt->value;
20524
20525 return 1;
20526 }
20527 }
20528
20529 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20530 {
20531 /* These options are expected to have an argument. */
20532 if (c == lopt->option[0]
20533 && arg != NULL
20534 && strncmp (arg, lopt->option + 1,
20535 strlen (lopt->option + 1)) == 0)
20536 {
20537 #if WARN_DEPRECATED
20538 /* If the option is deprecated, tell the user. */
20539 if (lopt->deprecated != NULL)
20540 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
20541 _(lopt->deprecated));
20542 #endif
20543
20544 /* Call the sup-option parser. */
20545 return lopt->func (arg + strlen (lopt->option) - 1);
20546 }
20547 }
20548
20549 return 0;
20550 }
20551
20552 return 1;
20553 }
20554
20555 void
20556 md_show_usage (FILE * fp)
20557 {
20558 struct arm_option_table *opt;
20559 struct arm_long_option_table *lopt;
20560
20561 fprintf (fp, _(" ARM-specific assembler options:\n"));
20562
20563 for (opt = arm_opts; opt->option != NULL; opt++)
20564 if (opt->help != NULL)
20565 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
20566
20567 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20568 if (lopt->help != NULL)
20569 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
20570
20571 #ifdef OPTION_EB
20572 fprintf (fp, _("\
20573 -EB assemble code for a big-endian cpu\n"));
20574 #endif
20575
20576 #ifdef OPTION_EL
20577 fprintf (fp, _("\
20578 -EL assemble code for a little-endian cpu\n"));
20579 #endif
20580
20581 fprintf (fp, _("\
20582 --fix-v4bx Allow BX in ARMv4 code\n"));
20583 }
20584
20585
20586 #ifdef OBJ_ELF
20587 typedef struct
20588 {
20589 int val;
20590 arm_feature_set flags;
20591 } cpu_arch_ver_table;
20592
20593 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
20594 least features first. */
20595 static const cpu_arch_ver_table cpu_arch_ver[] =
20596 {
20597 {1, ARM_ARCH_V4},
20598 {2, ARM_ARCH_V4T},
20599 {3, ARM_ARCH_V5},
20600 {4, ARM_ARCH_V5TE},
20601 {5, ARM_ARCH_V5TEJ},
20602 {6, ARM_ARCH_V6},
20603 {7, ARM_ARCH_V6Z},
20604 {9, ARM_ARCH_V6K},
20605 {9, ARM_ARCH_V6M},
20606 {8, ARM_ARCH_V6T2},
20607 {10, ARM_ARCH_V7A},
20608 {10, ARM_ARCH_V7R},
20609 {10, ARM_ARCH_V7M},
20610 {0, ARM_ARCH_NONE}
20611 };
20612
20613 /* Set the public EABI object attributes. */
20614 static void
20615 aeabi_set_public_attributes (void)
20616 {
20617 int arch;
20618 arm_feature_set flags;
20619 arm_feature_set tmp;
20620 const cpu_arch_ver_table *p;
20621
20622 /* Choose the architecture based on the capabilities of the requested cpu
20623 (if any) and/or the instructions actually used. */
20624 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
20625 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
20626 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
20627 /*Allow the user to override the reported architecture. */
20628 if (object_arch)
20629 {
20630 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
20631 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
20632 }
20633
20634 tmp = flags;
20635 arch = 0;
20636 for (p = cpu_arch_ver; p->val; p++)
20637 {
20638 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
20639 {
20640 arch = p->val;
20641 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
20642 }
20643 }
20644
20645 /* Tag_CPU_name. */
20646 if (selected_cpu_name[0])
20647 {
20648 char *p;
20649
20650 p = selected_cpu_name;
20651 if (strncmp (p, "armv", 4) == 0)
20652 {
20653 int i;
20654
20655 p += 4;
20656 for (i = 0; p[i]; i++)
20657 p[i] = TOUPPER (p[i]);
20658 }
20659 bfd_elf_add_proc_attr_string (stdoutput, 5, p);
20660 }
20661 /* Tag_CPU_arch. */
20662 bfd_elf_add_proc_attr_int (stdoutput, 6, arch);
20663 /* Tag_CPU_arch_profile. */
20664 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
20665 bfd_elf_add_proc_attr_int (stdoutput, 7, 'A');
20666 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
20667 bfd_elf_add_proc_attr_int (stdoutput, 7, 'R');
20668 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
20669 bfd_elf_add_proc_attr_int (stdoutput, 7, 'M');
20670 /* Tag_ARM_ISA_use. */
20671 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_full))
20672 bfd_elf_add_proc_attr_int (stdoutput, 8, 1);
20673 /* Tag_THUMB_ISA_use. */
20674 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_full))
20675 bfd_elf_add_proc_attr_int (stdoutput, 9,
20676 ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2) ? 2 : 1);
20677 /* Tag_VFP_arch. */
20678 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v3)
20679 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v3))
20680 bfd_elf_add_proc_attr_int (stdoutput, 10, 3);
20681 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v2)
20682 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v2))
20683 bfd_elf_add_proc_attr_int (stdoutput, 10, 2);
20684 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1)
20685 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1)
20686 || ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1xd)
20687 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1xd))
20688 bfd_elf_add_proc_attr_int (stdoutput, 10, 1);
20689 /* Tag_WMMX_arch. */
20690 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_cext_iwmmxt)
20691 || ARM_CPU_HAS_FEATURE (arm_arch_used, arm_cext_iwmmxt))
20692 bfd_elf_add_proc_attr_int (stdoutput, 11, 1);
20693 /* Tag_NEON_arch. */
20694 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_neon_ext_v1)
20695 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_neon_ext_v1))
20696 bfd_elf_add_proc_attr_int (stdoutput, 12, 1);
20697 }
20698
20699 /* Add the default contents for the .ARM.attributes section. */
20700 void
20701 arm_md_end (void)
20702 {
20703 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
20704 return;
20705
20706 aeabi_set_public_attributes ();
20707 }
20708 #endif /* OBJ_ELF */
20709
20710
20711 /* Parse a .cpu directive. */
20712
20713 static void
20714 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
20715 {
20716 const struct arm_cpu_option_table *opt;
20717 char *name;
20718 char saved_char;
20719
20720 name = input_line_pointer;
20721 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
20722 input_line_pointer++;
20723 saved_char = *input_line_pointer;
20724 *input_line_pointer = 0;
20725
20726 /* Skip the first "all" entry. */
20727 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
20728 if (streq (opt->name, name))
20729 {
20730 mcpu_cpu_opt = &opt->value;
20731 selected_cpu = opt->value;
20732 if (opt->canonical_name)
20733 strcpy (selected_cpu_name, opt->canonical_name);
20734 else
20735 {
20736 int i;
20737 for (i = 0; opt->name[i]; i++)
20738 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20739 selected_cpu_name[i] = 0;
20740 }
20741 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20742 *input_line_pointer = saved_char;
20743 demand_empty_rest_of_line ();
20744 return;
20745 }
20746 as_bad (_("unknown cpu `%s'"), name);
20747 *input_line_pointer = saved_char;
20748 ignore_rest_of_line ();
20749 }
20750
20751
20752 /* Parse a .arch directive. */
20753
20754 static void
20755 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
20756 {
20757 const struct arm_arch_option_table *opt;
20758 char saved_char;
20759 char *name;
20760
20761 name = input_line_pointer;
20762 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
20763 input_line_pointer++;
20764 saved_char = *input_line_pointer;
20765 *input_line_pointer = 0;
20766
20767 /* Skip the first "all" entry. */
20768 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20769 if (streq (opt->name, name))
20770 {
20771 mcpu_cpu_opt = &opt->value;
20772 selected_cpu = opt->value;
20773 strcpy (selected_cpu_name, opt->name);
20774 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20775 *input_line_pointer = saved_char;
20776 demand_empty_rest_of_line ();
20777 return;
20778 }
20779
20780 as_bad (_("unknown architecture `%s'\n"), name);
20781 *input_line_pointer = saved_char;
20782 ignore_rest_of_line ();
20783 }
20784
20785
20786 /* Parse a .object_arch directive. */
20787
20788 static void
20789 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
20790 {
20791 const struct arm_arch_option_table *opt;
20792 char saved_char;
20793 char *name;
20794
20795 name = input_line_pointer;
20796 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
20797 input_line_pointer++;
20798 saved_char = *input_line_pointer;
20799 *input_line_pointer = 0;
20800
20801 /* Skip the first "all" entry. */
20802 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20803 if (streq (opt->name, name))
20804 {
20805 object_arch = &opt->value;
20806 *input_line_pointer = saved_char;
20807 demand_empty_rest_of_line ();
20808 return;
20809 }
20810
20811 as_bad (_("unknown architecture `%s'\n"), name);
20812 *input_line_pointer = saved_char;
20813 ignore_rest_of_line ();
20814 }
20815
20816
20817 /* Parse a .fpu directive. */
20818
20819 static void
20820 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
20821 {
20822 const struct arm_option_cpu_value_table *opt;
20823 char saved_char;
20824 char *name;
20825
20826 name = input_line_pointer;
20827 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
20828 input_line_pointer++;
20829 saved_char = *input_line_pointer;
20830 *input_line_pointer = 0;
20831
20832 for (opt = arm_fpus; opt->name != NULL; opt++)
20833 if (streq (opt->name, name))
20834 {
20835 mfpu_opt = &opt->value;
20836 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20837 *input_line_pointer = saved_char;
20838 demand_empty_rest_of_line ();
20839 return;
20840 }
20841
20842 as_bad (_("unknown floating point format `%s'\n"), name);
20843 *input_line_pointer = saved_char;
20844 ignore_rest_of_line ();
20845 }
20846
20847 /* Copy symbol information. */
20848 void
20849 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
20850 {
20851 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
20852 }
This page took 0.557923 seconds and 5 git commands to generate.