* config/tc-arm.c (do_bx): Only test EF_ARM_EABI_VERSION on ELF
[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_div = ARM_FEATURE (ARM_EXT_DIV, 0);
196 static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
197 static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
198 static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
199 static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
200
201 static const arm_feature_set arm_arch_any = ARM_ANY;
202 static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
203 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
204 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
205
206 static const arm_feature_set arm_cext_iwmmxt2 =
207 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
208 static const arm_feature_set arm_cext_iwmmxt =
209 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
210 static const arm_feature_set arm_cext_xscale =
211 ARM_FEATURE (0, ARM_CEXT_XSCALE);
212 static const arm_feature_set arm_cext_maverick =
213 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
214 static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
215 static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
216 static const arm_feature_set fpu_vfp_ext_v1xd =
217 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
218 static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
219 static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
220 static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
221 static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
222 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
223 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
224
225 static int mfloat_abi_opt = -1;
226 /* Record user cpu selection for object attributes. */
227 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
228 /* Must be long enough to hold any of the names in arm_cpus. */
229 static char selected_cpu_name[16];
230 #ifdef OBJ_ELF
231 # ifdef EABI_DEFAULT
232 static int meabi_flags = EABI_DEFAULT;
233 # else
234 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
235 # endif
236
237 bfd_boolean
238 arm_is_eabi (void)
239 {
240 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
241 }
242 #endif
243
244 #ifdef OBJ_ELF
245 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
246 symbolS * GOT_symbol;
247 #endif
248
249 /* 0: assemble for ARM,
250 1: assemble for Thumb,
251 2: assemble for Thumb even though target CPU does not support thumb
252 instructions. */
253 static int thumb_mode = 0;
254
255 /* If unified_syntax is true, we are processing the new unified
256 ARM/Thumb syntax. Important differences from the old ARM mode:
257
258 - Immediate operands do not require a # prefix.
259 - Conditional affixes always appear at the end of the
260 instruction. (For backward compatibility, those instructions
261 that formerly had them in the middle, continue to accept them
262 there.)
263 - The IT instruction may appear, and if it does is validated
264 against subsequent conditional affixes. It does not generate
265 machine code.
266
267 Important differences from the old Thumb mode:
268
269 - Immediate operands do not require a # prefix.
270 - Most of the V6T2 instructions are only available in unified mode.
271 - The .N and .W suffixes are recognized and honored (it is an error
272 if they cannot be honored).
273 - All instructions set the flags if and only if they have an 's' affix.
274 - Conditional affixes may be used. They are validated against
275 preceding IT instructions. Unlike ARM mode, you cannot use a
276 conditional affix except in the scope of an IT instruction. */
277
278 static bfd_boolean unified_syntax = FALSE;
279
280 enum neon_el_type
281 {
282 NT_invtype,
283 NT_untyped,
284 NT_integer,
285 NT_float,
286 NT_poly,
287 NT_signed,
288 NT_unsigned
289 };
290
291 struct neon_type_el
292 {
293 enum neon_el_type type;
294 unsigned size;
295 };
296
297 #define NEON_MAX_TYPE_ELS 4
298
299 struct neon_type
300 {
301 struct neon_type_el el[NEON_MAX_TYPE_ELS];
302 unsigned elems;
303 };
304
305 struct arm_it
306 {
307 const char * error;
308 unsigned long instruction;
309 int size;
310 int size_req;
311 int cond;
312 /* "uncond_value" is set to the value in place of the conditional field in
313 unconditional versions of the instruction, or -1 if nothing is
314 appropriate. */
315 int uncond_value;
316 struct neon_type vectype;
317 /* Set to the opcode if the instruction needs relaxation.
318 Zero if the instruction is not relaxed. */
319 unsigned long relax;
320 struct
321 {
322 bfd_reloc_code_real_type type;
323 expressionS exp;
324 int pc_rel;
325 } reloc;
326
327 struct
328 {
329 unsigned reg;
330 signed int imm;
331 struct neon_type_el vectype;
332 unsigned present : 1; /* Operand present. */
333 unsigned isreg : 1; /* Operand was a register. */
334 unsigned immisreg : 1; /* .imm field is a second register. */
335 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
336 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
337 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
338 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
339 instructions. This allows us to disambiguate ARM <-> vector insns. */
340 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
341 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
342 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
343 unsigned issingle : 1; /* Operand is VFP single-precision register. */
344 unsigned hasreloc : 1; /* Operand has relocation suffix. */
345 unsigned writeback : 1; /* Operand has trailing ! */
346 unsigned preind : 1; /* Preindexed address. */
347 unsigned postind : 1; /* Postindexed address. */
348 unsigned negative : 1; /* Index register was negated. */
349 unsigned shifted : 1; /* Shift applied to operation. */
350 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
351 } operands[6];
352 };
353
354 static struct arm_it inst;
355
356 #define NUM_FLOAT_VALS 8
357
358 const char * fp_const[] =
359 {
360 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
361 };
362
363 /* Number of littlenums required to hold an extended precision number. */
364 #define MAX_LITTLENUMS 6
365
366 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
367
368 #define FAIL (-1)
369 #define SUCCESS (0)
370
371 #define SUFF_S 1
372 #define SUFF_D 2
373 #define SUFF_E 3
374 #define SUFF_P 4
375
376 #define CP_T_X 0x00008000
377 #define CP_T_Y 0x00400000
378
379 #define CONDS_BIT 0x00100000
380 #define LOAD_BIT 0x00100000
381
382 #define DOUBLE_LOAD_FLAG 0x00000001
383
384 struct asm_cond
385 {
386 const char * template;
387 unsigned long value;
388 };
389
390 #define COND_ALWAYS 0xE
391
392 struct asm_psr
393 {
394 const char *template;
395 unsigned long field;
396 };
397
398 struct asm_barrier_opt
399 {
400 const char *template;
401 unsigned long value;
402 };
403
404 /* The bit that distinguishes CPSR and SPSR. */
405 #define SPSR_BIT (1 << 22)
406
407 /* The individual PSR flag bits. */
408 #define PSR_c (1 << 16)
409 #define PSR_x (1 << 17)
410 #define PSR_s (1 << 18)
411 #define PSR_f (1 << 19)
412
413 struct reloc_entry
414 {
415 char *name;
416 bfd_reloc_code_real_type reloc;
417 };
418
419 enum vfp_reg_pos
420 {
421 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
422 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
423 };
424
425 enum vfp_ldstm_type
426 {
427 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
428 };
429
430 /* Bits for DEFINED field in neon_typed_alias. */
431 #define NTA_HASTYPE 1
432 #define NTA_HASINDEX 2
433
434 struct neon_typed_alias
435 {
436 unsigned char defined;
437 unsigned char index;
438 struct neon_type_el eltype;
439 };
440
441 /* ARM register categories. This includes coprocessor numbers and various
442 architecture extensions' registers. */
443 enum arm_reg_type
444 {
445 REG_TYPE_RN,
446 REG_TYPE_CP,
447 REG_TYPE_CN,
448 REG_TYPE_FN,
449 REG_TYPE_VFS,
450 REG_TYPE_VFD,
451 REG_TYPE_NQ,
452 REG_TYPE_VFSD,
453 REG_TYPE_NDQ,
454 REG_TYPE_NSDQ,
455 REG_TYPE_VFC,
456 REG_TYPE_MVF,
457 REG_TYPE_MVD,
458 REG_TYPE_MVFX,
459 REG_TYPE_MVDX,
460 REG_TYPE_MVAX,
461 REG_TYPE_DSPSC,
462 REG_TYPE_MMXWR,
463 REG_TYPE_MMXWC,
464 REG_TYPE_MMXWCG,
465 REG_TYPE_XSCALE,
466 };
467
468 /* Structure for a hash table entry for a register.
469 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
470 information which states whether a vector type or index is specified (for a
471 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
472 struct reg_entry
473 {
474 const char *name;
475 unsigned char number;
476 unsigned char type;
477 unsigned char builtin;
478 struct neon_typed_alias *neon;
479 };
480
481 /* Diagnostics used when we don't get a register of the expected type. */
482 const char *const reg_expected_msgs[] =
483 {
484 N_("ARM register expected"),
485 N_("bad or missing co-processor number"),
486 N_("co-processor register expected"),
487 N_("FPA register expected"),
488 N_("VFP single precision register expected"),
489 N_("VFP/Neon double precision register expected"),
490 N_("Neon quad precision register expected"),
491 N_("VFP single or double precision register expected"),
492 N_("Neon double or quad precision register expected"),
493 N_("VFP single, double or Neon quad precision register expected"),
494 N_("VFP system register expected"),
495 N_("Maverick MVF register expected"),
496 N_("Maverick MVD register expected"),
497 N_("Maverick MVFX register expected"),
498 N_("Maverick MVDX register expected"),
499 N_("Maverick MVAX register expected"),
500 N_("Maverick DSPSC register expected"),
501 N_("iWMMXt data register expected"),
502 N_("iWMMXt control register expected"),
503 N_("iWMMXt scalar register expected"),
504 N_("XScale accumulator register expected"),
505 };
506
507 /* Some well known registers that we refer to directly elsewhere. */
508 #define REG_SP 13
509 #define REG_LR 14
510 #define REG_PC 15
511
512 /* ARM instructions take 4bytes in the object file, Thumb instructions
513 take 2: */
514 #define INSN_SIZE 4
515
516 struct asm_opcode
517 {
518 /* Basic string to match. */
519 const char *template;
520
521 /* Parameters to instruction. */
522 unsigned char operands[8];
523
524 /* Conditional tag - see opcode_lookup. */
525 unsigned int tag : 4;
526
527 /* Basic instruction code. */
528 unsigned int avalue : 28;
529
530 /* Thumb-format instruction code. */
531 unsigned int tvalue;
532
533 /* Which architecture variant provides this instruction. */
534 const arm_feature_set *avariant;
535 const arm_feature_set *tvariant;
536
537 /* Function to call to encode instruction in ARM format. */
538 void (* aencode) (void);
539
540 /* Function to call to encode instruction in Thumb format. */
541 void (* tencode) (void);
542 };
543
544 /* Defines for various bits that we will want to toggle. */
545 #define INST_IMMEDIATE 0x02000000
546 #define OFFSET_REG 0x02000000
547 #define HWOFFSET_IMM 0x00400000
548 #define SHIFT_BY_REG 0x00000010
549 #define PRE_INDEX 0x01000000
550 #define INDEX_UP 0x00800000
551 #define WRITE_BACK 0x00200000
552 #define LDM_TYPE_2_OR_3 0x00400000
553 #define CPSI_MMOD 0x00020000
554
555 #define LITERAL_MASK 0xf000f000
556 #define OPCODE_MASK 0xfe1fffff
557 #define V4_STR_BIT 0x00000020
558
559 #define T2_SUBS_PC_LR 0xf3de8f00
560
561 #define DATA_OP_SHIFT 21
562
563 #define T2_OPCODE_MASK 0xfe1fffff
564 #define T2_DATA_OP_SHIFT 21
565
566 /* Codes to distinguish the arithmetic instructions. */
567 #define OPCODE_AND 0
568 #define OPCODE_EOR 1
569 #define OPCODE_SUB 2
570 #define OPCODE_RSB 3
571 #define OPCODE_ADD 4
572 #define OPCODE_ADC 5
573 #define OPCODE_SBC 6
574 #define OPCODE_RSC 7
575 #define OPCODE_TST 8
576 #define OPCODE_TEQ 9
577 #define OPCODE_CMP 10
578 #define OPCODE_CMN 11
579 #define OPCODE_ORR 12
580 #define OPCODE_MOV 13
581 #define OPCODE_BIC 14
582 #define OPCODE_MVN 15
583
584 #define T2_OPCODE_AND 0
585 #define T2_OPCODE_BIC 1
586 #define T2_OPCODE_ORR 2
587 #define T2_OPCODE_ORN 3
588 #define T2_OPCODE_EOR 4
589 #define T2_OPCODE_ADD 8
590 #define T2_OPCODE_ADC 10
591 #define T2_OPCODE_SBC 11
592 #define T2_OPCODE_SUB 13
593 #define T2_OPCODE_RSB 14
594
595 #define T_OPCODE_MUL 0x4340
596 #define T_OPCODE_TST 0x4200
597 #define T_OPCODE_CMN 0x42c0
598 #define T_OPCODE_NEG 0x4240
599 #define T_OPCODE_MVN 0x43c0
600
601 #define T_OPCODE_ADD_R3 0x1800
602 #define T_OPCODE_SUB_R3 0x1a00
603 #define T_OPCODE_ADD_HI 0x4400
604 #define T_OPCODE_ADD_ST 0xb000
605 #define T_OPCODE_SUB_ST 0xb080
606 #define T_OPCODE_ADD_SP 0xa800
607 #define T_OPCODE_ADD_PC 0xa000
608 #define T_OPCODE_ADD_I8 0x3000
609 #define T_OPCODE_SUB_I8 0x3800
610 #define T_OPCODE_ADD_I3 0x1c00
611 #define T_OPCODE_SUB_I3 0x1e00
612
613 #define T_OPCODE_ASR_R 0x4100
614 #define T_OPCODE_LSL_R 0x4080
615 #define T_OPCODE_LSR_R 0x40c0
616 #define T_OPCODE_ROR_R 0x41c0
617 #define T_OPCODE_ASR_I 0x1000
618 #define T_OPCODE_LSL_I 0x0000
619 #define T_OPCODE_LSR_I 0x0800
620
621 #define T_OPCODE_MOV_I8 0x2000
622 #define T_OPCODE_CMP_I8 0x2800
623 #define T_OPCODE_CMP_LR 0x4280
624 #define T_OPCODE_MOV_HR 0x4600
625 #define T_OPCODE_CMP_HR 0x4500
626
627 #define T_OPCODE_LDR_PC 0x4800
628 #define T_OPCODE_LDR_SP 0x9800
629 #define T_OPCODE_STR_SP 0x9000
630 #define T_OPCODE_LDR_IW 0x6800
631 #define T_OPCODE_STR_IW 0x6000
632 #define T_OPCODE_LDR_IH 0x8800
633 #define T_OPCODE_STR_IH 0x8000
634 #define T_OPCODE_LDR_IB 0x7800
635 #define T_OPCODE_STR_IB 0x7000
636 #define T_OPCODE_LDR_RW 0x5800
637 #define T_OPCODE_STR_RW 0x5000
638 #define T_OPCODE_LDR_RH 0x5a00
639 #define T_OPCODE_STR_RH 0x5200
640 #define T_OPCODE_LDR_RB 0x5c00
641 #define T_OPCODE_STR_RB 0x5400
642
643 #define T_OPCODE_PUSH 0xb400
644 #define T_OPCODE_POP 0xbc00
645
646 #define T_OPCODE_BRANCH 0xe000
647
648 #define THUMB_SIZE 2 /* Size of thumb instruction. */
649 #define THUMB_PP_PC_LR 0x0100
650 #define THUMB_LOAD_BIT 0x0800
651 #define THUMB2_LOAD_BIT 0x00100000
652
653 #define BAD_ARGS _("bad arguments to instruction")
654 #define BAD_PC _("r15 not allowed here")
655 #define BAD_COND _("instruction cannot be conditional")
656 #define BAD_OVERLAP _("registers may not be the same")
657 #define BAD_HIREG _("lo register required")
658 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
659 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
660 #define BAD_BRANCH _("branch must be last instruction in IT block")
661 #define BAD_NOT_IT _("instruction not allowed in IT block")
662 #define BAD_FPU _("selected FPU does not support instruction")
663
664 static struct hash_control *arm_ops_hsh;
665 static struct hash_control *arm_cond_hsh;
666 static struct hash_control *arm_shift_hsh;
667 static struct hash_control *arm_psr_hsh;
668 static struct hash_control *arm_v7m_psr_hsh;
669 static struct hash_control *arm_reg_hsh;
670 static struct hash_control *arm_reloc_hsh;
671 static struct hash_control *arm_barrier_opt_hsh;
672
673 /* Stuff needed to resolve the label ambiguity
674 As:
675 ...
676 label: <insn>
677 may differ from:
678 ...
679 label:
680 <insn> */
681
682 symbolS * last_label_seen;
683 static int label_is_thumb_function_name = FALSE;
684 \f
685 /* Literal pool structure. Held on a per-section
686 and per-sub-section basis. */
687
688 #define MAX_LITERAL_POOL_SIZE 1024
689 typedef struct literal_pool
690 {
691 expressionS literals [MAX_LITERAL_POOL_SIZE];
692 unsigned int next_free_entry;
693 unsigned int id;
694 symbolS * symbol;
695 segT section;
696 subsegT sub_section;
697 struct literal_pool * next;
698 } literal_pool;
699
700 /* Pointer to a linked list of literal pools. */
701 literal_pool * list_of_pools = NULL;
702
703 /* State variables for IT block handling. */
704 static bfd_boolean current_it_mask = 0;
705 static int current_cc;
706 \f
707 /* Pure syntax. */
708
709 /* This array holds the chars that always start a comment. If the
710 pre-processor is disabled, these aren't very useful. */
711 const char comment_chars[] = "@";
712
713 /* This array holds the chars that only start a comment at the beginning of
714 a line. If the line seems to have the form '# 123 filename'
715 .line and .file directives will appear in the pre-processed output. */
716 /* Note that input_file.c hand checks for '#' at the beginning of the
717 first line of the input file. This is because the compiler outputs
718 #NO_APP at the beginning of its output. */
719 /* Also note that comments like this one will always work. */
720 const char line_comment_chars[] = "#";
721
722 const char line_separator_chars[] = ";";
723
724 /* Chars that can be used to separate mant
725 from exp in floating point numbers. */
726 const char EXP_CHARS[] = "eE";
727
728 /* Chars that mean this number is a floating point constant. */
729 /* As in 0f12.456 */
730 /* or 0d1.2345e12 */
731
732 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
733
734 /* Prefix characters that indicate the start of an immediate
735 value. */
736 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
737
738 /* Separator character handling. */
739
740 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
741
742 static inline int
743 skip_past_char (char ** str, char c)
744 {
745 if (**str == c)
746 {
747 (*str)++;
748 return SUCCESS;
749 }
750 else
751 return FAIL;
752 }
753 #define skip_past_comma(str) skip_past_char (str, ',')
754
755 /* Arithmetic expressions (possibly involving symbols). */
756
757 /* Return TRUE if anything in the expression is a bignum. */
758
759 static int
760 walk_no_bignums (symbolS * sp)
761 {
762 if (symbol_get_value_expression (sp)->X_op == O_big)
763 return 1;
764
765 if (symbol_get_value_expression (sp)->X_add_symbol)
766 {
767 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
768 || (symbol_get_value_expression (sp)->X_op_symbol
769 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
770 }
771
772 return 0;
773 }
774
775 static int in_my_get_expression = 0;
776
777 /* Third argument to my_get_expression. */
778 #define GE_NO_PREFIX 0
779 #define GE_IMM_PREFIX 1
780 #define GE_OPT_PREFIX 2
781 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
782 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
783 #define GE_OPT_PREFIX_BIG 3
784
785 static int
786 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
787 {
788 char * save_in;
789 segT seg;
790
791 /* In unified syntax, all prefixes are optional. */
792 if (unified_syntax)
793 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
794 : GE_OPT_PREFIX;
795
796 switch (prefix_mode)
797 {
798 case GE_NO_PREFIX: break;
799 case GE_IMM_PREFIX:
800 if (!is_immediate_prefix (**str))
801 {
802 inst.error = _("immediate expression requires a # prefix");
803 return FAIL;
804 }
805 (*str)++;
806 break;
807 case GE_OPT_PREFIX:
808 case GE_OPT_PREFIX_BIG:
809 if (is_immediate_prefix (**str))
810 (*str)++;
811 break;
812 default: abort ();
813 }
814
815 memset (ep, 0, sizeof (expressionS));
816
817 save_in = input_line_pointer;
818 input_line_pointer = *str;
819 in_my_get_expression = 1;
820 seg = expression (ep);
821 in_my_get_expression = 0;
822
823 if (ep->X_op == O_illegal)
824 {
825 /* We found a bad expression in md_operand(). */
826 *str = input_line_pointer;
827 input_line_pointer = save_in;
828 if (inst.error == NULL)
829 inst.error = _("bad expression");
830 return 1;
831 }
832
833 #ifdef OBJ_AOUT
834 if (seg != absolute_section
835 && seg != text_section
836 && seg != data_section
837 && seg != bss_section
838 && seg != undefined_section)
839 {
840 inst.error = _("bad segment");
841 *str = input_line_pointer;
842 input_line_pointer = save_in;
843 return 1;
844 }
845 #endif
846
847 /* Get rid of any bignums now, so that we don't generate an error for which
848 we can't establish a line number later on. Big numbers are never valid
849 in instructions, which is where this routine is always called. */
850 if (prefix_mode != GE_OPT_PREFIX_BIG
851 && (ep->X_op == O_big
852 || (ep->X_add_symbol
853 && (walk_no_bignums (ep->X_add_symbol)
854 || (ep->X_op_symbol
855 && walk_no_bignums (ep->X_op_symbol))))))
856 {
857 inst.error = _("invalid constant");
858 *str = input_line_pointer;
859 input_line_pointer = save_in;
860 return 1;
861 }
862
863 *str = input_line_pointer;
864 input_line_pointer = save_in;
865 return 0;
866 }
867
868 /* Turn a string in input_line_pointer into a floating point constant
869 of type TYPE, and store the appropriate bytes in *LITP. The number
870 of LITTLENUMS emitted is stored in *SIZEP. An error message is
871 returned, or NULL on OK.
872
873 Note that fp constants aren't represent in the normal way on the ARM.
874 In big endian mode, things are as expected. However, in little endian
875 mode fp constants are big-endian word-wise, and little-endian byte-wise
876 within the words. For example, (double) 1.1 in big endian mode is
877 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
878 the byte sequence 99 99 f1 3f 9a 99 99 99.
879
880 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
881
882 char *
883 md_atof (int type, char * litP, int * sizeP)
884 {
885 int prec;
886 LITTLENUM_TYPE words[MAX_LITTLENUMS];
887 char *t;
888 int i;
889
890 switch (type)
891 {
892 case 'f':
893 case 'F':
894 case 's':
895 case 'S':
896 prec = 2;
897 break;
898
899 case 'd':
900 case 'D':
901 case 'r':
902 case 'R':
903 prec = 4;
904 break;
905
906 case 'x':
907 case 'X':
908 prec = 5;
909 break;
910
911 case 'p':
912 case 'P':
913 prec = 5;
914 break;
915
916 default:
917 *sizeP = 0;
918 return _("Unrecognized or unsupported floating point constant");
919 }
920
921 t = atof_ieee (input_line_pointer, type, words);
922 if (t)
923 input_line_pointer = t;
924 *sizeP = prec * sizeof (LITTLENUM_TYPE);
925
926 if (target_big_endian)
927 {
928 for (i = 0; i < prec; i++)
929 {
930 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
931 litP += sizeof (LITTLENUM_TYPE);
932 }
933 }
934 else
935 {
936 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
937 for (i = prec - 1; i >= 0; i--)
938 {
939 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
940 litP += sizeof (LITTLENUM_TYPE);
941 }
942 else
943 /* For a 4 byte float the order of elements in `words' is 1 0.
944 For an 8 byte float the order is 1 0 3 2. */
945 for (i = 0; i < prec; i += 2)
946 {
947 md_number_to_chars (litP, (valueT) words[i + 1],
948 sizeof (LITTLENUM_TYPE));
949 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
950 (valueT) words[i], sizeof (LITTLENUM_TYPE));
951 litP += 2 * sizeof (LITTLENUM_TYPE);
952 }
953 }
954
955 return NULL;
956 }
957
958 /* We handle all bad expressions here, so that we can report the faulty
959 instruction in the error message. */
960 void
961 md_operand (expressionS * expr)
962 {
963 if (in_my_get_expression)
964 expr->X_op = O_illegal;
965 }
966
967 /* Immediate values. */
968
969 /* Generic immediate-value read function for use in directives.
970 Accepts anything that 'expression' can fold to a constant.
971 *val receives the number. */
972 #ifdef OBJ_ELF
973 static int
974 immediate_for_directive (int *val)
975 {
976 expressionS exp;
977 exp.X_op = O_illegal;
978
979 if (is_immediate_prefix (*input_line_pointer))
980 {
981 input_line_pointer++;
982 expression (&exp);
983 }
984
985 if (exp.X_op != O_constant)
986 {
987 as_bad (_("expected #constant"));
988 ignore_rest_of_line ();
989 return FAIL;
990 }
991 *val = exp.X_add_number;
992 return SUCCESS;
993 }
994 #endif
995
996 /* Register parsing. */
997
998 /* Generic register parser. CCP points to what should be the
999 beginning of a register name. If it is indeed a valid register
1000 name, advance CCP over it and return the reg_entry structure;
1001 otherwise return NULL. Does not issue diagnostics. */
1002
1003 static struct reg_entry *
1004 arm_reg_parse_multi (char **ccp)
1005 {
1006 char *start = *ccp;
1007 char *p;
1008 struct reg_entry *reg;
1009
1010 #ifdef REGISTER_PREFIX
1011 if (*start != REGISTER_PREFIX)
1012 return NULL;
1013 start++;
1014 #endif
1015 #ifdef OPTIONAL_REGISTER_PREFIX
1016 if (*start == OPTIONAL_REGISTER_PREFIX)
1017 start++;
1018 #endif
1019
1020 p = start;
1021 if (!ISALPHA (*p) || !is_name_beginner (*p))
1022 return NULL;
1023
1024 do
1025 p++;
1026 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1027
1028 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1029
1030 if (!reg)
1031 return NULL;
1032
1033 *ccp = p;
1034 return reg;
1035 }
1036
1037 static int
1038 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1039 enum arm_reg_type type)
1040 {
1041 /* Alternative syntaxes are accepted for a few register classes. */
1042 switch (type)
1043 {
1044 case REG_TYPE_MVF:
1045 case REG_TYPE_MVD:
1046 case REG_TYPE_MVFX:
1047 case REG_TYPE_MVDX:
1048 /* Generic coprocessor register names are allowed for these. */
1049 if (reg && reg->type == REG_TYPE_CN)
1050 return reg->number;
1051 break;
1052
1053 case REG_TYPE_CP:
1054 /* For backward compatibility, a bare number is valid here. */
1055 {
1056 unsigned long processor = strtoul (start, ccp, 10);
1057 if (*ccp != start && processor <= 15)
1058 return processor;
1059 }
1060
1061 case REG_TYPE_MMXWC:
1062 /* WC includes WCG. ??? I'm not sure this is true for all
1063 instructions that take WC registers. */
1064 if (reg && reg->type == REG_TYPE_MMXWCG)
1065 return reg->number;
1066 break;
1067
1068 default:
1069 break;
1070 }
1071
1072 return FAIL;
1073 }
1074
1075 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1076 return value is the register number or FAIL. */
1077
1078 static int
1079 arm_reg_parse (char **ccp, enum arm_reg_type type)
1080 {
1081 char *start = *ccp;
1082 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1083 int ret;
1084
1085 /* Do not allow a scalar (reg+index) to parse as a register. */
1086 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1087 return FAIL;
1088
1089 if (reg && reg->type == type)
1090 return reg->number;
1091
1092 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1093 return ret;
1094
1095 *ccp = start;
1096 return FAIL;
1097 }
1098
1099 /* Parse a Neon type specifier. *STR should point at the leading '.'
1100 character. Does no verification at this stage that the type fits the opcode
1101 properly. E.g.,
1102
1103 .i32.i32.s16
1104 .s32.f32
1105 .u16
1106
1107 Can all be legally parsed by this function.
1108
1109 Fills in neon_type struct pointer with parsed information, and updates STR
1110 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1111 type, FAIL if not. */
1112
1113 static int
1114 parse_neon_type (struct neon_type *type, char **str)
1115 {
1116 char *ptr = *str;
1117
1118 if (type)
1119 type->elems = 0;
1120
1121 while (type->elems < NEON_MAX_TYPE_ELS)
1122 {
1123 enum neon_el_type thistype = NT_untyped;
1124 unsigned thissize = -1u;
1125
1126 if (*ptr != '.')
1127 break;
1128
1129 ptr++;
1130
1131 /* Just a size without an explicit type. */
1132 if (ISDIGIT (*ptr))
1133 goto parsesize;
1134
1135 switch (TOLOWER (*ptr))
1136 {
1137 case 'i': thistype = NT_integer; break;
1138 case 'f': thistype = NT_float; break;
1139 case 'p': thistype = NT_poly; break;
1140 case 's': thistype = NT_signed; break;
1141 case 'u': thistype = NT_unsigned; break;
1142 case 'd':
1143 thistype = NT_float;
1144 thissize = 64;
1145 ptr++;
1146 goto done;
1147 default:
1148 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1149 return FAIL;
1150 }
1151
1152 ptr++;
1153
1154 /* .f is an abbreviation for .f32. */
1155 if (thistype == NT_float && !ISDIGIT (*ptr))
1156 thissize = 32;
1157 else
1158 {
1159 parsesize:
1160 thissize = strtoul (ptr, &ptr, 10);
1161
1162 if (thissize != 8 && thissize != 16 && thissize != 32
1163 && thissize != 64)
1164 {
1165 as_bad (_("bad size %d in type specifier"), thissize);
1166 return FAIL;
1167 }
1168 }
1169
1170 done:
1171 if (type)
1172 {
1173 type->el[type->elems].type = thistype;
1174 type->el[type->elems].size = thissize;
1175 type->elems++;
1176 }
1177 }
1178
1179 /* Empty/missing type is not a successful parse. */
1180 if (type->elems == 0)
1181 return FAIL;
1182
1183 *str = ptr;
1184
1185 return SUCCESS;
1186 }
1187
1188 /* Errors may be set multiple times during parsing or bit encoding
1189 (particularly in the Neon bits), but usually the earliest error which is set
1190 will be the most meaningful. Avoid overwriting it with later (cascading)
1191 errors by calling this function. */
1192
1193 static void
1194 first_error (const char *err)
1195 {
1196 if (!inst.error)
1197 inst.error = err;
1198 }
1199
1200 /* Parse a single type, e.g. ".s32", leading period included. */
1201 static int
1202 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1203 {
1204 char *str = *ccp;
1205 struct neon_type optype;
1206
1207 if (*str == '.')
1208 {
1209 if (parse_neon_type (&optype, &str) == SUCCESS)
1210 {
1211 if (optype.elems == 1)
1212 *vectype = optype.el[0];
1213 else
1214 {
1215 first_error (_("only one type should be specified for operand"));
1216 return FAIL;
1217 }
1218 }
1219 else
1220 {
1221 first_error (_("vector type expected"));
1222 return FAIL;
1223 }
1224 }
1225 else
1226 return FAIL;
1227
1228 *ccp = str;
1229
1230 return SUCCESS;
1231 }
1232
1233 /* Special meanings for indices (which have a range of 0-7), which will fit into
1234 a 4-bit integer. */
1235
1236 #define NEON_ALL_LANES 15
1237 #define NEON_INTERLEAVE_LANES 14
1238
1239 /* Parse either a register or a scalar, with an optional type. Return the
1240 register number, and optionally fill in the actual type of the register
1241 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1242 type/index information in *TYPEINFO. */
1243
1244 static int
1245 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1246 enum arm_reg_type *rtype,
1247 struct neon_typed_alias *typeinfo)
1248 {
1249 char *str = *ccp;
1250 struct reg_entry *reg = arm_reg_parse_multi (&str);
1251 struct neon_typed_alias atype;
1252 struct neon_type_el parsetype;
1253
1254 atype.defined = 0;
1255 atype.index = -1;
1256 atype.eltype.type = NT_invtype;
1257 atype.eltype.size = -1;
1258
1259 /* Try alternate syntax for some types of register. Note these are mutually
1260 exclusive with the Neon syntax extensions. */
1261 if (reg == NULL)
1262 {
1263 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1264 if (altreg != FAIL)
1265 *ccp = str;
1266 if (typeinfo)
1267 *typeinfo = atype;
1268 return altreg;
1269 }
1270
1271 /* Undo polymorphism when a set of register types may be accepted. */
1272 if ((type == REG_TYPE_NDQ
1273 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1274 || (type == REG_TYPE_VFSD
1275 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1276 || (type == REG_TYPE_NSDQ
1277 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1278 || reg->type == REG_TYPE_NQ))
1279 || (type == REG_TYPE_MMXWC
1280 && (reg->type == REG_TYPE_MMXWCG)))
1281 type = reg->type;
1282
1283 if (type != reg->type)
1284 return FAIL;
1285
1286 if (reg->neon)
1287 atype = *reg->neon;
1288
1289 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1290 {
1291 if ((atype.defined & NTA_HASTYPE) != 0)
1292 {
1293 first_error (_("can't redefine type for operand"));
1294 return FAIL;
1295 }
1296 atype.defined |= NTA_HASTYPE;
1297 atype.eltype = parsetype;
1298 }
1299
1300 if (skip_past_char (&str, '[') == SUCCESS)
1301 {
1302 if (type != REG_TYPE_VFD)
1303 {
1304 first_error (_("only D registers may be indexed"));
1305 return FAIL;
1306 }
1307
1308 if ((atype.defined & NTA_HASINDEX) != 0)
1309 {
1310 first_error (_("can't change index for operand"));
1311 return FAIL;
1312 }
1313
1314 atype.defined |= NTA_HASINDEX;
1315
1316 if (skip_past_char (&str, ']') == SUCCESS)
1317 atype.index = NEON_ALL_LANES;
1318 else
1319 {
1320 expressionS exp;
1321
1322 my_get_expression (&exp, &str, GE_NO_PREFIX);
1323
1324 if (exp.X_op != O_constant)
1325 {
1326 first_error (_("constant expression required"));
1327 return FAIL;
1328 }
1329
1330 if (skip_past_char (&str, ']') == FAIL)
1331 return FAIL;
1332
1333 atype.index = exp.X_add_number;
1334 }
1335 }
1336
1337 if (typeinfo)
1338 *typeinfo = atype;
1339
1340 if (rtype)
1341 *rtype = type;
1342
1343 *ccp = str;
1344
1345 return reg->number;
1346 }
1347
1348 /* Like arm_reg_parse, but allow allow the following extra features:
1349 - If RTYPE is non-zero, return the (possibly restricted) type of the
1350 register (e.g. Neon double or quad reg when either has been requested).
1351 - If this is a Neon vector type with additional type information, fill
1352 in the struct pointed to by VECTYPE (if non-NULL).
1353 This function will fault on encountering a scalar. */
1354
1355 static int
1356 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1357 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1358 {
1359 struct neon_typed_alias atype;
1360 char *str = *ccp;
1361 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1362
1363 if (reg == FAIL)
1364 return FAIL;
1365
1366 /* Do not allow a scalar (reg+index) to parse as a register. */
1367 if ((atype.defined & NTA_HASINDEX) != 0)
1368 {
1369 first_error (_("register operand expected, but got scalar"));
1370 return FAIL;
1371 }
1372
1373 if (vectype)
1374 *vectype = atype.eltype;
1375
1376 *ccp = str;
1377
1378 return reg;
1379 }
1380
1381 #define NEON_SCALAR_REG(X) ((X) >> 4)
1382 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1383
1384 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1385 have enough information to be able to do a good job bounds-checking. So, we
1386 just do easy checks here, and do further checks later. */
1387
1388 static int
1389 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1390 {
1391 int reg;
1392 char *str = *ccp;
1393 struct neon_typed_alias atype;
1394
1395 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
1396
1397 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1398 return FAIL;
1399
1400 if (atype.index == NEON_ALL_LANES)
1401 {
1402 first_error (_("scalar must have an index"));
1403 return FAIL;
1404 }
1405 else if (atype.index >= 64 / elsize)
1406 {
1407 first_error (_("scalar index out of range"));
1408 return FAIL;
1409 }
1410
1411 if (type)
1412 *type = atype.eltype;
1413
1414 *ccp = str;
1415
1416 return reg * 16 + atype.index;
1417 }
1418
1419 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1420 static long
1421 parse_reg_list (char ** strp)
1422 {
1423 char * str = * strp;
1424 long range = 0;
1425 int another_range;
1426
1427 /* We come back here if we get ranges concatenated by '+' or '|'. */
1428 do
1429 {
1430 another_range = 0;
1431
1432 if (*str == '{')
1433 {
1434 int in_range = 0;
1435 int cur_reg = -1;
1436
1437 str++;
1438 do
1439 {
1440 int reg;
1441
1442 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1443 {
1444 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
1445 return FAIL;
1446 }
1447
1448 if (in_range)
1449 {
1450 int i;
1451
1452 if (reg <= cur_reg)
1453 {
1454 first_error (_("bad range in register list"));
1455 return FAIL;
1456 }
1457
1458 for (i = cur_reg + 1; i < reg; i++)
1459 {
1460 if (range & (1 << i))
1461 as_tsktsk
1462 (_("Warning: duplicated register (r%d) in register list"),
1463 i);
1464 else
1465 range |= 1 << i;
1466 }
1467 in_range = 0;
1468 }
1469
1470 if (range & (1 << reg))
1471 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1472 reg);
1473 else if (reg <= cur_reg)
1474 as_tsktsk (_("Warning: register range not in ascending order"));
1475
1476 range |= 1 << reg;
1477 cur_reg = reg;
1478 }
1479 while (skip_past_comma (&str) != FAIL
1480 || (in_range = 1, *str++ == '-'));
1481 str--;
1482
1483 if (*str++ != '}')
1484 {
1485 first_error (_("missing `}'"));
1486 return FAIL;
1487 }
1488 }
1489 else
1490 {
1491 expressionS expr;
1492
1493 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1494 return FAIL;
1495
1496 if (expr.X_op == O_constant)
1497 {
1498 if (expr.X_add_number
1499 != (expr.X_add_number & 0x0000ffff))
1500 {
1501 inst.error = _("invalid register mask");
1502 return FAIL;
1503 }
1504
1505 if ((range & expr.X_add_number) != 0)
1506 {
1507 int regno = range & expr.X_add_number;
1508
1509 regno &= -regno;
1510 regno = (1 << regno) - 1;
1511 as_tsktsk
1512 (_("Warning: duplicated register (r%d) in register list"),
1513 regno);
1514 }
1515
1516 range |= expr.X_add_number;
1517 }
1518 else
1519 {
1520 if (inst.reloc.type != 0)
1521 {
1522 inst.error = _("expression too complex");
1523 return FAIL;
1524 }
1525
1526 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1527 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1528 inst.reloc.pc_rel = 0;
1529 }
1530 }
1531
1532 if (*str == '|' || *str == '+')
1533 {
1534 str++;
1535 another_range = 1;
1536 }
1537 }
1538 while (another_range);
1539
1540 *strp = str;
1541 return range;
1542 }
1543
1544 /* Types of registers in a list. */
1545
1546 enum reg_list_els
1547 {
1548 REGLIST_VFP_S,
1549 REGLIST_VFP_D,
1550 REGLIST_NEON_D
1551 };
1552
1553 /* Parse a VFP register list. If the string is invalid return FAIL.
1554 Otherwise return the number of registers, and set PBASE to the first
1555 register. Parses registers of type ETYPE.
1556 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1557 - Q registers can be used to specify pairs of D registers
1558 - { } can be omitted from around a singleton register list
1559 FIXME: This is not implemented, as it would require backtracking in
1560 some cases, e.g.:
1561 vtbl.8 d3,d4,d5
1562 This could be done (the meaning isn't really ambiguous), but doesn't
1563 fit in well with the current parsing framework.
1564 - 32 D registers may be used (also true for VFPv3).
1565 FIXME: Types are ignored in these register lists, which is probably a
1566 bug. */
1567
1568 static int
1569 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
1570 {
1571 char *str = *ccp;
1572 int base_reg;
1573 int new_base;
1574 enum arm_reg_type regtype = 0;
1575 int max_regs = 0;
1576 int count = 0;
1577 int warned = 0;
1578 unsigned long mask = 0;
1579 int i;
1580
1581 if (*str != '{')
1582 {
1583 inst.error = _("expecting {");
1584 return FAIL;
1585 }
1586
1587 str++;
1588
1589 switch (etype)
1590 {
1591 case REGLIST_VFP_S:
1592 regtype = REG_TYPE_VFS;
1593 max_regs = 32;
1594 break;
1595
1596 case REGLIST_VFP_D:
1597 regtype = REG_TYPE_VFD;
1598 break;
1599
1600 case REGLIST_NEON_D:
1601 regtype = REG_TYPE_NDQ;
1602 break;
1603 }
1604
1605 if (etype != REGLIST_VFP_S)
1606 {
1607 /* VFPv3 allows 32 D registers. */
1608 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
1609 {
1610 max_regs = 32;
1611 if (thumb_mode)
1612 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1613 fpu_vfp_ext_v3);
1614 else
1615 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1616 fpu_vfp_ext_v3);
1617 }
1618 else
1619 max_regs = 16;
1620 }
1621
1622 base_reg = max_regs;
1623
1624 do
1625 {
1626 int setmask = 1, addregs = 1;
1627
1628 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
1629
1630 if (new_base == FAIL)
1631 {
1632 first_error (_(reg_expected_msgs[regtype]));
1633 return FAIL;
1634 }
1635
1636 if (new_base >= max_regs)
1637 {
1638 first_error (_("register out of range in list"));
1639 return FAIL;
1640 }
1641
1642 /* Note: a value of 2 * n is returned for the register Q<n>. */
1643 if (regtype == REG_TYPE_NQ)
1644 {
1645 setmask = 3;
1646 addregs = 2;
1647 }
1648
1649 if (new_base < base_reg)
1650 base_reg = new_base;
1651
1652 if (mask & (setmask << new_base))
1653 {
1654 first_error (_("invalid register list"));
1655 return FAIL;
1656 }
1657
1658 if ((mask >> new_base) != 0 && ! warned)
1659 {
1660 as_tsktsk (_("register list not in ascending order"));
1661 warned = 1;
1662 }
1663
1664 mask |= setmask << new_base;
1665 count += addregs;
1666
1667 if (*str == '-') /* We have the start of a range expression */
1668 {
1669 int high_range;
1670
1671 str++;
1672
1673 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
1674 == FAIL)
1675 {
1676 inst.error = gettext (reg_expected_msgs[regtype]);
1677 return FAIL;
1678 }
1679
1680 if (high_range >= max_regs)
1681 {
1682 first_error (_("register out of range in list"));
1683 return FAIL;
1684 }
1685
1686 if (regtype == REG_TYPE_NQ)
1687 high_range = high_range + 1;
1688
1689 if (high_range <= new_base)
1690 {
1691 inst.error = _("register range not in ascending order");
1692 return FAIL;
1693 }
1694
1695 for (new_base += addregs; new_base <= high_range; new_base += addregs)
1696 {
1697 if (mask & (setmask << new_base))
1698 {
1699 inst.error = _("invalid register list");
1700 return FAIL;
1701 }
1702
1703 mask |= setmask << new_base;
1704 count += addregs;
1705 }
1706 }
1707 }
1708 while (skip_past_comma (&str) != FAIL);
1709
1710 str++;
1711
1712 /* Sanity check -- should have raised a parse error above. */
1713 if (count == 0 || count > max_regs)
1714 abort ();
1715
1716 *pbase = base_reg;
1717
1718 /* Final test -- the registers must be consecutive. */
1719 mask >>= base_reg;
1720 for (i = 0; i < count; i++)
1721 {
1722 if ((mask & (1u << i)) == 0)
1723 {
1724 inst.error = _("non-contiguous register range");
1725 return FAIL;
1726 }
1727 }
1728
1729 *ccp = str;
1730
1731 return count;
1732 }
1733
1734 /* True if two alias types are the same. */
1735
1736 static int
1737 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1738 {
1739 if (!a && !b)
1740 return 1;
1741
1742 if (!a || !b)
1743 return 0;
1744
1745 if (a->defined != b->defined)
1746 return 0;
1747
1748 if ((a->defined & NTA_HASTYPE) != 0
1749 && (a->eltype.type != b->eltype.type
1750 || a->eltype.size != b->eltype.size))
1751 return 0;
1752
1753 if ((a->defined & NTA_HASINDEX) != 0
1754 && (a->index != b->index))
1755 return 0;
1756
1757 return 1;
1758 }
1759
1760 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1761 The base register is put in *PBASE.
1762 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
1763 the return value.
1764 The register stride (minus one) is put in bit 4 of the return value.
1765 Bits [6:5] encode the list length (minus one).
1766 The type of the list elements is put in *ELTYPE, if non-NULL. */
1767
1768 #define NEON_LANE(X) ((X) & 0xf)
1769 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
1770 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1771
1772 static int
1773 parse_neon_el_struct_list (char **str, unsigned *pbase,
1774 struct neon_type_el *eltype)
1775 {
1776 char *ptr = *str;
1777 int base_reg = -1;
1778 int reg_incr = -1;
1779 int count = 0;
1780 int lane = -1;
1781 int leading_brace = 0;
1782 enum arm_reg_type rtype = REG_TYPE_NDQ;
1783 int addregs = 1;
1784 const char *const incr_error = "register stride must be 1 or 2";
1785 const char *const type_error = "mismatched element/structure types in list";
1786 struct neon_typed_alias firsttype;
1787
1788 if (skip_past_char (&ptr, '{') == SUCCESS)
1789 leading_brace = 1;
1790
1791 do
1792 {
1793 struct neon_typed_alias atype;
1794 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1795
1796 if (getreg == FAIL)
1797 {
1798 first_error (_(reg_expected_msgs[rtype]));
1799 return FAIL;
1800 }
1801
1802 if (base_reg == -1)
1803 {
1804 base_reg = getreg;
1805 if (rtype == REG_TYPE_NQ)
1806 {
1807 reg_incr = 1;
1808 addregs = 2;
1809 }
1810 firsttype = atype;
1811 }
1812 else if (reg_incr == -1)
1813 {
1814 reg_incr = getreg - base_reg;
1815 if (reg_incr < 1 || reg_incr > 2)
1816 {
1817 first_error (_(incr_error));
1818 return FAIL;
1819 }
1820 }
1821 else if (getreg != base_reg + reg_incr * count)
1822 {
1823 first_error (_(incr_error));
1824 return FAIL;
1825 }
1826
1827 if (!neon_alias_types_same (&atype, &firsttype))
1828 {
1829 first_error (_(type_error));
1830 return FAIL;
1831 }
1832
1833 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1834 modes. */
1835 if (ptr[0] == '-')
1836 {
1837 struct neon_typed_alias htype;
1838 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1839 if (lane == -1)
1840 lane = NEON_INTERLEAVE_LANES;
1841 else if (lane != NEON_INTERLEAVE_LANES)
1842 {
1843 first_error (_(type_error));
1844 return FAIL;
1845 }
1846 if (reg_incr == -1)
1847 reg_incr = 1;
1848 else if (reg_incr != 1)
1849 {
1850 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
1851 return FAIL;
1852 }
1853 ptr++;
1854 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
1855 if (hireg == FAIL)
1856 {
1857 first_error (_(reg_expected_msgs[rtype]));
1858 return FAIL;
1859 }
1860 if (!neon_alias_types_same (&htype, &firsttype))
1861 {
1862 first_error (_(type_error));
1863 return FAIL;
1864 }
1865 count += hireg + dregs - getreg;
1866 continue;
1867 }
1868
1869 /* If we're using Q registers, we can't use [] or [n] syntax. */
1870 if (rtype == REG_TYPE_NQ)
1871 {
1872 count += 2;
1873 continue;
1874 }
1875
1876 if ((atype.defined & NTA_HASINDEX) != 0)
1877 {
1878 if (lane == -1)
1879 lane = atype.index;
1880 else if (lane != atype.index)
1881 {
1882 first_error (_(type_error));
1883 return FAIL;
1884 }
1885 }
1886 else if (lane == -1)
1887 lane = NEON_INTERLEAVE_LANES;
1888 else if (lane != NEON_INTERLEAVE_LANES)
1889 {
1890 first_error (_(type_error));
1891 return FAIL;
1892 }
1893 count++;
1894 }
1895 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
1896
1897 /* No lane set by [x]. We must be interleaving structures. */
1898 if (lane == -1)
1899 lane = NEON_INTERLEAVE_LANES;
1900
1901 /* Sanity check. */
1902 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
1903 || (count > 1 && reg_incr == -1))
1904 {
1905 first_error (_("error parsing element/structure list"));
1906 return FAIL;
1907 }
1908
1909 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
1910 {
1911 first_error (_("expected }"));
1912 return FAIL;
1913 }
1914
1915 if (reg_incr == -1)
1916 reg_incr = 1;
1917
1918 if (eltype)
1919 *eltype = firsttype.eltype;
1920
1921 *pbase = base_reg;
1922 *str = ptr;
1923
1924 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
1925 }
1926
1927 /* Parse an explicit relocation suffix on an expression. This is
1928 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1929 arm_reloc_hsh contains no entries, so this function can only
1930 succeed if there is no () after the word. Returns -1 on error,
1931 BFD_RELOC_UNUSED if there wasn't any suffix. */
1932 static int
1933 parse_reloc (char **str)
1934 {
1935 struct reloc_entry *r;
1936 char *p, *q;
1937
1938 if (**str != '(')
1939 return BFD_RELOC_UNUSED;
1940
1941 p = *str + 1;
1942 q = p;
1943
1944 while (*q && *q != ')' && *q != ',')
1945 q++;
1946 if (*q != ')')
1947 return -1;
1948
1949 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1950 return -1;
1951
1952 *str = q + 1;
1953 return r->reloc;
1954 }
1955
1956 /* Directives: register aliases. */
1957
1958 static struct reg_entry *
1959 insert_reg_alias (char *str, int number, int type)
1960 {
1961 struct reg_entry *new;
1962 const char *name;
1963
1964 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1965 {
1966 if (new->builtin)
1967 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
1968
1969 /* Only warn about a redefinition if it's not defined as the
1970 same register. */
1971 else if (new->number != number || new->type != type)
1972 as_warn (_("ignoring redefinition of register alias '%s'"), str);
1973
1974 return NULL;
1975 }
1976
1977 name = xstrdup (str);
1978 new = xmalloc (sizeof (struct reg_entry));
1979
1980 new->name = name;
1981 new->number = number;
1982 new->type = type;
1983 new->builtin = FALSE;
1984 new->neon = NULL;
1985
1986 if (hash_insert (arm_reg_hsh, name, (PTR) new))
1987 abort ();
1988
1989 return new;
1990 }
1991
1992 static void
1993 insert_neon_reg_alias (char *str, int number, int type,
1994 struct neon_typed_alias *atype)
1995 {
1996 struct reg_entry *reg = insert_reg_alias (str, number, type);
1997
1998 if (!reg)
1999 {
2000 first_error (_("attempt to redefine typed alias"));
2001 return;
2002 }
2003
2004 if (atype)
2005 {
2006 reg->neon = xmalloc (sizeof (struct neon_typed_alias));
2007 *reg->neon = *atype;
2008 }
2009 }
2010
2011 /* Look for the .req directive. This is of the form:
2012
2013 new_register_name .req existing_register_name
2014
2015 If we find one, or if it looks sufficiently like one that we want to
2016 handle any error here, return TRUE. Otherwise return FALSE. */
2017
2018 static bfd_boolean
2019 create_register_alias (char * newname, char *p)
2020 {
2021 struct reg_entry *old;
2022 char *oldname, *nbuf;
2023 size_t nlen;
2024
2025 /* The input scrubber ensures that whitespace after the mnemonic is
2026 collapsed to single spaces. */
2027 oldname = p;
2028 if (strncmp (oldname, " .req ", 6) != 0)
2029 return FALSE;
2030
2031 oldname += 6;
2032 if (*oldname == '\0')
2033 return FALSE;
2034
2035 old = hash_find (arm_reg_hsh, oldname);
2036 if (!old)
2037 {
2038 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2039 return TRUE;
2040 }
2041
2042 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2043 the desired alias name, and p points to its end. If not, then
2044 the desired alias name is in the global original_case_string. */
2045 #ifdef TC_CASE_SENSITIVE
2046 nlen = p - newname;
2047 #else
2048 newname = original_case_string;
2049 nlen = strlen (newname);
2050 #endif
2051
2052 nbuf = alloca (nlen + 1);
2053 memcpy (nbuf, newname, nlen);
2054 nbuf[nlen] = '\0';
2055
2056 /* Create aliases under the new name as stated; an all-lowercase
2057 version of the new name; and an all-uppercase version of the new
2058 name. */
2059 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2060 {
2061 for (p = nbuf; *p; p++)
2062 *p = TOUPPER (*p);
2063
2064 if (strncmp (nbuf, newname, nlen))
2065 {
2066 /* If this attempt to create an additional alias fails, do not bother
2067 trying to create the all-lower case alias. We will fail and issue
2068 a second, duplicate error message. This situation arises when the
2069 programmer does something like:
2070 foo .req r0
2071 Foo .req r1
2072 The second .req creates the "Foo" alias but then fails to create
2073 the artificial FOO alias because it has already been created by the
2074 first .req. */
2075 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2076 return TRUE;
2077 }
2078
2079 for (p = nbuf; *p; p++)
2080 *p = TOLOWER (*p);
2081
2082 if (strncmp (nbuf, newname, nlen))
2083 insert_reg_alias (nbuf, old->number, old->type);
2084 }
2085
2086 return TRUE;
2087 }
2088
2089 /* Create a Neon typed/indexed register alias using directives, e.g.:
2090 X .dn d5.s32[1]
2091 Y .qn 6.s16
2092 Z .dn d7
2093 T .dn Z[0]
2094 These typed registers can be used instead of the types specified after the
2095 Neon mnemonic, so long as all operands given have types. Types can also be
2096 specified directly, e.g.:
2097 vadd d0.s32, d1.s32, d2.s32 */
2098
2099 static int
2100 create_neon_reg_alias (char *newname, char *p)
2101 {
2102 enum arm_reg_type basetype;
2103 struct reg_entry *basereg;
2104 struct reg_entry mybasereg;
2105 struct neon_type ntype;
2106 struct neon_typed_alias typeinfo;
2107 char *namebuf, *nameend;
2108 int namelen;
2109
2110 typeinfo.defined = 0;
2111 typeinfo.eltype.type = NT_invtype;
2112 typeinfo.eltype.size = -1;
2113 typeinfo.index = -1;
2114
2115 nameend = p;
2116
2117 if (strncmp (p, " .dn ", 5) == 0)
2118 basetype = REG_TYPE_VFD;
2119 else if (strncmp (p, " .qn ", 5) == 0)
2120 basetype = REG_TYPE_NQ;
2121 else
2122 return 0;
2123
2124 p += 5;
2125
2126 if (*p == '\0')
2127 return 0;
2128
2129 basereg = arm_reg_parse_multi (&p);
2130
2131 if (basereg && basereg->type != basetype)
2132 {
2133 as_bad (_("bad type for register"));
2134 return 0;
2135 }
2136
2137 if (basereg == NULL)
2138 {
2139 expressionS exp;
2140 /* Try parsing as an integer. */
2141 my_get_expression (&exp, &p, GE_NO_PREFIX);
2142 if (exp.X_op != O_constant)
2143 {
2144 as_bad (_("expression must be constant"));
2145 return 0;
2146 }
2147 basereg = &mybasereg;
2148 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2149 : exp.X_add_number;
2150 basereg->neon = 0;
2151 }
2152
2153 if (basereg->neon)
2154 typeinfo = *basereg->neon;
2155
2156 if (parse_neon_type (&ntype, &p) == SUCCESS)
2157 {
2158 /* We got a type. */
2159 if (typeinfo.defined & NTA_HASTYPE)
2160 {
2161 as_bad (_("can't redefine the type of a register alias"));
2162 return 0;
2163 }
2164
2165 typeinfo.defined |= NTA_HASTYPE;
2166 if (ntype.elems != 1)
2167 {
2168 as_bad (_("you must specify a single type only"));
2169 return 0;
2170 }
2171 typeinfo.eltype = ntype.el[0];
2172 }
2173
2174 if (skip_past_char (&p, '[') == SUCCESS)
2175 {
2176 expressionS exp;
2177 /* We got a scalar index. */
2178
2179 if (typeinfo.defined & NTA_HASINDEX)
2180 {
2181 as_bad (_("can't redefine the index of a scalar alias"));
2182 return 0;
2183 }
2184
2185 my_get_expression (&exp, &p, GE_NO_PREFIX);
2186
2187 if (exp.X_op != O_constant)
2188 {
2189 as_bad (_("scalar index must be constant"));
2190 return 0;
2191 }
2192
2193 typeinfo.defined |= NTA_HASINDEX;
2194 typeinfo.index = exp.X_add_number;
2195
2196 if (skip_past_char (&p, ']') == FAIL)
2197 {
2198 as_bad (_("expecting ]"));
2199 return 0;
2200 }
2201 }
2202
2203 namelen = nameend - newname;
2204 namebuf = alloca (namelen + 1);
2205 strncpy (namebuf, newname, namelen);
2206 namebuf[namelen] = '\0';
2207
2208 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2209 typeinfo.defined != 0 ? &typeinfo : NULL);
2210
2211 /* Insert name in all uppercase. */
2212 for (p = namebuf; *p; p++)
2213 *p = TOUPPER (*p);
2214
2215 if (strncmp (namebuf, newname, namelen))
2216 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2217 typeinfo.defined != 0 ? &typeinfo : NULL);
2218
2219 /* Insert name in all lowercase. */
2220 for (p = namebuf; *p; p++)
2221 *p = TOLOWER (*p);
2222
2223 if (strncmp (namebuf, newname, namelen))
2224 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2225 typeinfo.defined != 0 ? &typeinfo : NULL);
2226
2227 return 1;
2228 }
2229
2230 /* Should never be called, as .req goes between the alias and the
2231 register name, not at the beginning of the line. */
2232 static void
2233 s_req (int a ATTRIBUTE_UNUSED)
2234 {
2235 as_bad (_("invalid syntax for .req directive"));
2236 }
2237
2238 static void
2239 s_dn (int a ATTRIBUTE_UNUSED)
2240 {
2241 as_bad (_("invalid syntax for .dn directive"));
2242 }
2243
2244 static void
2245 s_qn (int a ATTRIBUTE_UNUSED)
2246 {
2247 as_bad (_("invalid syntax for .qn directive"));
2248 }
2249
2250 /* The .unreq directive deletes an alias which was previously defined
2251 by .req. For example:
2252
2253 my_alias .req r11
2254 .unreq my_alias */
2255
2256 static void
2257 s_unreq (int a ATTRIBUTE_UNUSED)
2258 {
2259 char * name;
2260 char saved_char;
2261
2262 name = input_line_pointer;
2263
2264 while (*input_line_pointer != 0
2265 && *input_line_pointer != ' '
2266 && *input_line_pointer != '\n')
2267 ++input_line_pointer;
2268
2269 saved_char = *input_line_pointer;
2270 *input_line_pointer = 0;
2271
2272 if (!*name)
2273 as_bad (_("invalid syntax for .unreq directive"));
2274 else
2275 {
2276 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
2277
2278 if (!reg)
2279 as_bad (_("unknown register alias '%s'"), name);
2280 else if (reg->builtin)
2281 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2282 name);
2283 else
2284 {
2285 char * p;
2286 char * nbuf;
2287
2288 hash_delete (arm_reg_hsh, name);
2289 free ((char *) reg->name);
2290 if (reg->neon)
2291 free (reg->neon);
2292 free (reg);
2293
2294 /* Also locate the all upper case and all lower case versions.
2295 Do not complain if we cannot find one or the other as it
2296 was probably deleted above. */
2297
2298 nbuf = strdup (name);
2299 for (p = nbuf; *p; p++)
2300 *p = TOUPPER (*p);
2301 reg = hash_find (arm_reg_hsh, nbuf);
2302 if (reg)
2303 {
2304 hash_delete (arm_reg_hsh, nbuf);
2305 free ((char *) reg->name);
2306 if (reg->neon)
2307 free (reg->neon);
2308 free (reg);
2309 }
2310
2311 for (p = nbuf; *p; p++)
2312 *p = TOLOWER (*p);
2313 reg = hash_find (arm_reg_hsh, nbuf);
2314 if (reg)
2315 {
2316 hash_delete (arm_reg_hsh, nbuf);
2317 free ((char *) reg->name);
2318 if (reg->neon)
2319 free (reg->neon);
2320 free (reg);
2321 }
2322
2323 free (nbuf);
2324 }
2325 }
2326
2327 *input_line_pointer = saved_char;
2328 demand_empty_rest_of_line ();
2329 }
2330
2331 /* Directives: Instruction set selection. */
2332
2333 #ifdef OBJ_ELF
2334 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2335 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2336 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2337 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2338
2339 static enum mstate mapstate = MAP_UNDEFINED;
2340
2341 void
2342 mapping_state (enum mstate state)
2343 {
2344 symbolS * symbolP;
2345 const char * symname;
2346 int type;
2347
2348 if (mapstate == state)
2349 /* The mapping symbol has already been emitted.
2350 There is nothing else to do. */
2351 return;
2352
2353 mapstate = state;
2354
2355 switch (state)
2356 {
2357 case MAP_DATA:
2358 symname = "$d";
2359 type = BSF_NO_FLAGS;
2360 break;
2361 case MAP_ARM:
2362 symname = "$a";
2363 type = BSF_NO_FLAGS;
2364 break;
2365 case MAP_THUMB:
2366 symname = "$t";
2367 type = BSF_NO_FLAGS;
2368 break;
2369 case MAP_UNDEFINED:
2370 return;
2371 default:
2372 abort ();
2373 }
2374
2375 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2376
2377 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
2378 symbol_table_insert (symbolP);
2379 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2380
2381 switch (state)
2382 {
2383 case MAP_ARM:
2384 THUMB_SET_FUNC (symbolP, 0);
2385 ARM_SET_THUMB (symbolP, 0);
2386 ARM_SET_INTERWORK (symbolP, support_interwork);
2387 break;
2388
2389 case MAP_THUMB:
2390 THUMB_SET_FUNC (symbolP, 1);
2391 ARM_SET_THUMB (symbolP, 1);
2392 ARM_SET_INTERWORK (symbolP, support_interwork);
2393 break;
2394
2395 case MAP_DATA:
2396 default:
2397 return;
2398 }
2399 }
2400 #else
2401 #define mapping_state(x) /* nothing */
2402 #endif
2403
2404 /* Find the real, Thumb encoded start of a Thumb function. */
2405
2406 static symbolS *
2407 find_real_start (symbolS * symbolP)
2408 {
2409 char * real_start;
2410 const char * name = S_GET_NAME (symbolP);
2411 symbolS * new_target;
2412
2413 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2414 #define STUB_NAME ".real_start_of"
2415
2416 if (name == NULL)
2417 abort ();
2418
2419 /* The compiler may generate BL instructions to local labels because
2420 it needs to perform a branch to a far away location. These labels
2421 do not have a corresponding ".real_start_of" label. We check
2422 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2423 the ".real_start_of" convention for nonlocal branches. */
2424 if (S_IS_LOCAL (symbolP) || name[0] == '.')
2425 return symbolP;
2426
2427 real_start = ACONCAT ((STUB_NAME, name, NULL));
2428 new_target = symbol_find (real_start);
2429
2430 if (new_target == NULL)
2431 {
2432 as_warn (_("Failed to find real start of function: %s\n"), name);
2433 new_target = symbolP;
2434 }
2435
2436 return new_target;
2437 }
2438
2439 static void
2440 opcode_select (int width)
2441 {
2442 switch (width)
2443 {
2444 case 16:
2445 if (! thumb_mode)
2446 {
2447 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
2448 as_bad (_("selected processor does not support THUMB opcodes"));
2449
2450 thumb_mode = 1;
2451 /* No need to force the alignment, since we will have been
2452 coming from ARM mode, which is word-aligned. */
2453 record_alignment (now_seg, 1);
2454 }
2455 mapping_state (MAP_THUMB);
2456 break;
2457
2458 case 32:
2459 if (thumb_mode)
2460 {
2461 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
2462 as_bad (_("selected processor does not support ARM opcodes"));
2463
2464 thumb_mode = 0;
2465
2466 if (!need_pass_2)
2467 frag_align (2, 0, 0);
2468
2469 record_alignment (now_seg, 1);
2470 }
2471 mapping_state (MAP_ARM);
2472 break;
2473
2474 default:
2475 as_bad (_("invalid instruction size selected (%d)"), width);
2476 }
2477 }
2478
2479 static void
2480 s_arm (int ignore ATTRIBUTE_UNUSED)
2481 {
2482 opcode_select (32);
2483 demand_empty_rest_of_line ();
2484 }
2485
2486 static void
2487 s_thumb (int ignore ATTRIBUTE_UNUSED)
2488 {
2489 opcode_select (16);
2490 demand_empty_rest_of_line ();
2491 }
2492
2493 static void
2494 s_code (int unused ATTRIBUTE_UNUSED)
2495 {
2496 int temp;
2497
2498 temp = get_absolute_expression ();
2499 switch (temp)
2500 {
2501 case 16:
2502 case 32:
2503 opcode_select (temp);
2504 break;
2505
2506 default:
2507 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2508 }
2509 }
2510
2511 static void
2512 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2513 {
2514 /* If we are not already in thumb mode go into it, EVEN if
2515 the target processor does not support thumb instructions.
2516 This is used by gcc/config/arm/lib1funcs.asm for example
2517 to compile interworking support functions even if the
2518 target processor should not support interworking. */
2519 if (! thumb_mode)
2520 {
2521 thumb_mode = 2;
2522 record_alignment (now_seg, 1);
2523 }
2524
2525 demand_empty_rest_of_line ();
2526 }
2527
2528 static void
2529 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2530 {
2531 s_thumb (0);
2532
2533 /* The following label is the name/address of the start of a Thumb function.
2534 We need to know this for the interworking support. */
2535 label_is_thumb_function_name = TRUE;
2536 }
2537
2538 /* Perform a .set directive, but also mark the alias as
2539 being a thumb function. */
2540
2541 static void
2542 s_thumb_set (int equiv)
2543 {
2544 /* XXX the following is a duplicate of the code for s_set() in read.c
2545 We cannot just call that code as we need to get at the symbol that
2546 is created. */
2547 char * name;
2548 char delim;
2549 char * end_name;
2550 symbolS * symbolP;
2551
2552 /* Especial apologies for the random logic:
2553 This just grew, and could be parsed much more simply!
2554 Dean - in haste. */
2555 name = input_line_pointer;
2556 delim = get_symbol_end ();
2557 end_name = input_line_pointer;
2558 *end_name = delim;
2559
2560 if (*input_line_pointer != ',')
2561 {
2562 *end_name = 0;
2563 as_bad (_("expected comma after name \"%s\""), name);
2564 *end_name = delim;
2565 ignore_rest_of_line ();
2566 return;
2567 }
2568
2569 input_line_pointer++;
2570 *end_name = 0;
2571
2572 if (name[0] == '.' && name[1] == '\0')
2573 {
2574 /* XXX - this should not happen to .thumb_set. */
2575 abort ();
2576 }
2577
2578 if ((symbolP = symbol_find (name)) == NULL
2579 && (symbolP = md_undefined_symbol (name)) == NULL)
2580 {
2581 #ifndef NO_LISTING
2582 /* When doing symbol listings, play games with dummy fragments living
2583 outside the normal fragment chain to record the file and line info
2584 for this symbol. */
2585 if (listing & LISTING_SYMBOLS)
2586 {
2587 extern struct list_info_struct * listing_tail;
2588 fragS * dummy_frag = xmalloc (sizeof (fragS));
2589
2590 memset (dummy_frag, 0, sizeof (fragS));
2591 dummy_frag->fr_type = rs_fill;
2592 dummy_frag->line = listing_tail;
2593 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2594 dummy_frag->fr_symbol = symbolP;
2595 }
2596 else
2597 #endif
2598 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2599
2600 #ifdef OBJ_COFF
2601 /* "set" symbols are local unless otherwise specified. */
2602 SF_SET_LOCAL (symbolP);
2603 #endif /* OBJ_COFF */
2604 } /* Make a new symbol. */
2605
2606 symbol_table_insert (symbolP);
2607
2608 * end_name = delim;
2609
2610 if (equiv
2611 && S_IS_DEFINED (symbolP)
2612 && S_GET_SEGMENT (symbolP) != reg_section)
2613 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2614
2615 pseudo_set (symbolP);
2616
2617 demand_empty_rest_of_line ();
2618
2619 /* XXX Now we come to the Thumb specific bit of code. */
2620
2621 THUMB_SET_FUNC (symbolP, 1);
2622 ARM_SET_THUMB (symbolP, 1);
2623 #if defined OBJ_ELF || defined OBJ_COFF
2624 ARM_SET_INTERWORK (symbolP, support_interwork);
2625 #endif
2626 }
2627
2628 /* Directives: Mode selection. */
2629
2630 /* .syntax [unified|divided] - choose the new unified syntax
2631 (same for Arm and Thumb encoding, modulo slight differences in what
2632 can be represented) or the old divergent syntax for each mode. */
2633 static void
2634 s_syntax (int unused ATTRIBUTE_UNUSED)
2635 {
2636 char *name, delim;
2637
2638 name = input_line_pointer;
2639 delim = get_symbol_end ();
2640
2641 if (!strcasecmp (name, "unified"))
2642 unified_syntax = TRUE;
2643 else if (!strcasecmp (name, "divided"))
2644 unified_syntax = FALSE;
2645 else
2646 {
2647 as_bad (_("unrecognized syntax mode \"%s\""), name);
2648 return;
2649 }
2650 *input_line_pointer = delim;
2651 demand_empty_rest_of_line ();
2652 }
2653
2654 /* Directives: sectioning and alignment. */
2655
2656 /* Same as s_align_ptwo but align 0 => align 2. */
2657
2658 static void
2659 s_align (int unused ATTRIBUTE_UNUSED)
2660 {
2661 int temp;
2662 bfd_boolean fill_p;
2663 long temp_fill;
2664 long max_alignment = 15;
2665
2666 temp = get_absolute_expression ();
2667 if (temp > max_alignment)
2668 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2669 else if (temp < 0)
2670 {
2671 as_bad (_("alignment negative. 0 assumed."));
2672 temp = 0;
2673 }
2674
2675 if (*input_line_pointer == ',')
2676 {
2677 input_line_pointer++;
2678 temp_fill = get_absolute_expression ();
2679 fill_p = TRUE;
2680 }
2681 else
2682 {
2683 fill_p = FALSE;
2684 temp_fill = 0;
2685 }
2686
2687 if (!temp)
2688 temp = 2;
2689
2690 /* Only make a frag if we HAVE to. */
2691 if (temp && !need_pass_2)
2692 {
2693 if (!fill_p && subseg_text_p (now_seg))
2694 frag_align_code (temp, 0);
2695 else
2696 frag_align (temp, (int) temp_fill, 0);
2697 }
2698 demand_empty_rest_of_line ();
2699
2700 record_alignment (now_seg, temp);
2701 }
2702
2703 static void
2704 s_bss (int ignore ATTRIBUTE_UNUSED)
2705 {
2706 /* We don't support putting frags in the BSS segment, we fake it by
2707 marking in_bss, then looking at s_skip for clues. */
2708 subseg_set (bss_section, 0);
2709 demand_empty_rest_of_line ();
2710 mapping_state (MAP_DATA);
2711 }
2712
2713 static void
2714 s_even (int ignore ATTRIBUTE_UNUSED)
2715 {
2716 /* Never make frag if expect extra pass. */
2717 if (!need_pass_2)
2718 frag_align (1, 0, 0);
2719
2720 record_alignment (now_seg, 1);
2721
2722 demand_empty_rest_of_line ();
2723 }
2724
2725 /* Directives: Literal pools. */
2726
2727 static literal_pool *
2728 find_literal_pool (void)
2729 {
2730 literal_pool * pool;
2731
2732 for (pool = list_of_pools; pool != NULL; pool = pool->next)
2733 {
2734 if (pool->section == now_seg
2735 && pool->sub_section == now_subseg)
2736 break;
2737 }
2738
2739 return pool;
2740 }
2741
2742 static literal_pool *
2743 find_or_make_literal_pool (void)
2744 {
2745 /* Next literal pool ID number. */
2746 static unsigned int latest_pool_num = 1;
2747 literal_pool * pool;
2748
2749 pool = find_literal_pool ();
2750
2751 if (pool == NULL)
2752 {
2753 /* Create a new pool. */
2754 pool = xmalloc (sizeof (* pool));
2755 if (! pool)
2756 return NULL;
2757
2758 pool->next_free_entry = 0;
2759 pool->section = now_seg;
2760 pool->sub_section = now_subseg;
2761 pool->next = list_of_pools;
2762 pool->symbol = NULL;
2763
2764 /* Add it to the list. */
2765 list_of_pools = pool;
2766 }
2767
2768 /* New pools, and emptied pools, will have a NULL symbol. */
2769 if (pool->symbol == NULL)
2770 {
2771 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2772 (valueT) 0, &zero_address_frag);
2773 pool->id = latest_pool_num ++;
2774 }
2775
2776 /* Done. */
2777 return pool;
2778 }
2779
2780 /* Add the literal in the global 'inst'
2781 structure to the relevant literal pool. */
2782
2783 static int
2784 add_to_lit_pool (void)
2785 {
2786 literal_pool * pool;
2787 unsigned int entry;
2788
2789 pool = find_or_make_literal_pool ();
2790
2791 /* Check if this literal value is already in the pool. */
2792 for (entry = 0; entry < pool->next_free_entry; entry ++)
2793 {
2794 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2795 && (inst.reloc.exp.X_op == O_constant)
2796 && (pool->literals[entry].X_add_number
2797 == inst.reloc.exp.X_add_number)
2798 && (pool->literals[entry].X_unsigned
2799 == inst.reloc.exp.X_unsigned))
2800 break;
2801
2802 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2803 && (inst.reloc.exp.X_op == O_symbol)
2804 && (pool->literals[entry].X_add_number
2805 == inst.reloc.exp.X_add_number)
2806 && (pool->literals[entry].X_add_symbol
2807 == inst.reloc.exp.X_add_symbol)
2808 && (pool->literals[entry].X_op_symbol
2809 == inst.reloc.exp.X_op_symbol))
2810 break;
2811 }
2812
2813 /* Do we need to create a new entry? */
2814 if (entry == pool->next_free_entry)
2815 {
2816 if (entry >= MAX_LITERAL_POOL_SIZE)
2817 {
2818 inst.error = _("literal pool overflow");
2819 return FAIL;
2820 }
2821
2822 pool->literals[entry] = inst.reloc.exp;
2823 pool->next_free_entry += 1;
2824 }
2825
2826 inst.reloc.exp.X_op = O_symbol;
2827 inst.reloc.exp.X_add_number = ((int) entry) * 4;
2828 inst.reloc.exp.X_add_symbol = pool->symbol;
2829
2830 return SUCCESS;
2831 }
2832
2833 /* Can't use symbol_new here, so have to create a symbol and then at
2834 a later date assign it a value. Thats what these functions do. */
2835
2836 static void
2837 symbol_locate (symbolS * symbolP,
2838 const char * name, /* It is copied, the caller can modify. */
2839 segT segment, /* Segment identifier (SEG_<something>). */
2840 valueT valu, /* Symbol value. */
2841 fragS * frag) /* Associated fragment. */
2842 {
2843 unsigned int name_length;
2844 char * preserved_copy_of_name;
2845
2846 name_length = strlen (name) + 1; /* +1 for \0. */
2847 obstack_grow (&notes, name, name_length);
2848 preserved_copy_of_name = obstack_finish (&notes);
2849
2850 #ifdef tc_canonicalize_symbol_name
2851 preserved_copy_of_name =
2852 tc_canonicalize_symbol_name (preserved_copy_of_name);
2853 #endif
2854
2855 S_SET_NAME (symbolP, preserved_copy_of_name);
2856
2857 S_SET_SEGMENT (symbolP, segment);
2858 S_SET_VALUE (symbolP, valu);
2859 symbol_clear_list_pointers (symbolP);
2860
2861 symbol_set_frag (symbolP, frag);
2862
2863 /* Link to end of symbol chain. */
2864 {
2865 extern int symbol_table_frozen;
2866
2867 if (symbol_table_frozen)
2868 abort ();
2869 }
2870
2871 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
2872
2873 obj_symbol_new_hook (symbolP);
2874
2875 #ifdef tc_symbol_new_hook
2876 tc_symbol_new_hook (symbolP);
2877 #endif
2878
2879 #ifdef DEBUG_SYMS
2880 verify_symbol_chain (symbol_rootP, symbol_lastP);
2881 #endif /* DEBUG_SYMS */
2882 }
2883
2884
2885 static void
2886 s_ltorg (int ignored ATTRIBUTE_UNUSED)
2887 {
2888 unsigned int entry;
2889 literal_pool * pool;
2890 char sym_name[20];
2891
2892 pool = find_literal_pool ();
2893 if (pool == NULL
2894 || pool->symbol == NULL
2895 || pool->next_free_entry == 0)
2896 return;
2897
2898 mapping_state (MAP_DATA);
2899
2900 /* Align pool as you have word accesses.
2901 Only make a frag if we have to. */
2902 if (!need_pass_2)
2903 frag_align (2, 0, 0);
2904
2905 record_alignment (now_seg, 2);
2906
2907 sprintf (sym_name, "$$lit_\002%x", pool->id);
2908
2909 symbol_locate (pool->symbol, sym_name, now_seg,
2910 (valueT) frag_now_fix (), frag_now);
2911 symbol_table_insert (pool->symbol);
2912
2913 ARM_SET_THUMB (pool->symbol, thumb_mode);
2914
2915 #if defined OBJ_COFF || defined OBJ_ELF
2916 ARM_SET_INTERWORK (pool->symbol, support_interwork);
2917 #endif
2918
2919 for (entry = 0; entry < pool->next_free_entry; entry ++)
2920 /* First output the expression in the instruction to the pool. */
2921 emit_expr (&(pool->literals[entry]), 4); /* .word */
2922
2923 /* Mark the pool as empty. */
2924 pool->next_free_entry = 0;
2925 pool->symbol = NULL;
2926 }
2927
2928 #ifdef OBJ_ELF
2929 /* Forward declarations for functions below, in the MD interface
2930 section. */
2931 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
2932 static valueT create_unwind_entry (int);
2933 static void start_unwind_section (const segT, int);
2934 static void add_unwind_opcode (valueT, int);
2935 static void flush_pending_unwind (void);
2936
2937 /* Directives: Data. */
2938
2939 static void
2940 s_arm_elf_cons (int nbytes)
2941 {
2942 expressionS exp;
2943
2944 #ifdef md_flush_pending_output
2945 md_flush_pending_output ();
2946 #endif
2947
2948 if (is_it_end_of_statement ())
2949 {
2950 demand_empty_rest_of_line ();
2951 return;
2952 }
2953
2954 #ifdef md_cons_align
2955 md_cons_align (nbytes);
2956 #endif
2957
2958 mapping_state (MAP_DATA);
2959 do
2960 {
2961 int reloc;
2962 char *base = input_line_pointer;
2963
2964 expression (& exp);
2965
2966 if (exp.X_op != O_symbol)
2967 emit_expr (&exp, (unsigned int) nbytes);
2968 else
2969 {
2970 char *before_reloc = input_line_pointer;
2971 reloc = parse_reloc (&input_line_pointer);
2972 if (reloc == -1)
2973 {
2974 as_bad (_("unrecognized relocation suffix"));
2975 ignore_rest_of_line ();
2976 return;
2977 }
2978 else if (reloc == BFD_RELOC_UNUSED)
2979 emit_expr (&exp, (unsigned int) nbytes);
2980 else
2981 {
2982 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
2983 int size = bfd_get_reloc_size (howto);
2984
2985 if (reloc == BFD_RELOC_ARM_PLT32)
2986 {
2987 as_bad (_("(plt) is only valid on branch targets"));
2988 reloc = BFD_RELOC_UNUSED;
2989 size = 0;
2990 }
2991
2992 if (size > nbytes)
2993 as_bad (_("%s relocations do not fit in %d bytes"),
2994 howto->name, nbytes);
2995 else
2996 {
2997 /* We've parsed an expression stopping at O_symbol.
2998 But there may be more expression left now that we
2999 have parsed the relocation marker. Parse it again.
3000 XXX Surely there is a cleaner way to do this. */
3001 char *p = input_line_pointer;
3002 int offset;
3003 char *save_buf = alloca (input_line_pointer - base);
3004 memcpy (save_buf, base, input_line_pointer - base);
3005 memmove (base + (input_line_pointer - before_reloc),
3006 base, before_reloc - base);
3007
3008 input_line_pointer = base + (input_line_pointer-before_reloc);
3009 expression (&exp);
3010 memcpy (base, save_buf, p - base);
3011
3012 offset = nbytes - size;
3013 p = frag_more ((int) nbytes);
3014 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3015 size, &exp, 0, reloc);
3016 }
3017 }
3018 }
3019 }
3020 while (*input_line_pointer++ == ',');
3021
3022 /* Put terminator back into stream. */
3023 input_line_pointer --;
3024 demand_empty_rest_of_line ();
3025 }
3026
3027
3028 /* Parse a .rel31 directive. */
3029
3030 static void
3031 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3032 {
3033 expressionS exp;
3034 char *p;
3035 valueT highbit;
3036
3037 highbit = 0;
3038 if (*input_line_pointer == '1')
3039 highbit = 0x80000000;
3040 else if (*input_line_pointer != '0')
3041 as_bad (_("expected 0 or 1"));
3042
3043 input_line_pointer++;
3044 if (*input_line_pointer != ',')
3045 as_bad (_("missing comma"));
3046 input_line_pointer++;
3047
3048 #ifdef md_flush_pending_output
3049 md_flush_pending_output ();
3050 #endif
3051
3052 #ifdef md_cons_align
3053 md_cons_align (4);
3054 #endif
3055
3056 mapping_state (MAP_DATA);
3057
3058 expression (&exp);
3059
3060 p = frag_more (4);
3061 md_number_to_chars (p, highbit, 4);
3062 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3063 BFD_RELOC_ARM_PREL31);
3064
3065 demand_empty_rest_of_line ();
3066 }
3067
3068 /* Directives: AEABI stack-unwind tables. */
3069
3070 /* Parse an unwind_fnstart directive. Simply records the current location. */
3071
3072 static void
3073 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3074 {
3075 demand_empty_rest_of_line ();
3076 /* Mark the start of the function. */
3077 unwind.proc_start = expr_build_dot ();
3078
3079 /* Reset the rest of the unwind info. */
3080 unwind.opcode_count = 0;
3081 unwind.table_entry = NULL;
3082 unwind.personality_routine = NULL;
3083 unwind.personality_index = -1;
3084 unwind.frame_size = 0;
3085 unwind.fp_offset = 0;
3086 unwind.fp_reg = 13;
3087 unwind.fp_used = 0;
3088 unwind.sp_restored = 0;
3089 }
3090
3091
3092 /* Parse a handlerdata directive. Creates the exception handling table entry
3093 for the function. */
3094
3095 static void
3096 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3097 {
3098 demand_empty_rest_of_line ();
3099 if (unwind.table_entry)
3100 as_bad (_("duplicate .handlerdata directive"));
3101
3102 create_unwind_entry (1);
3103 }
3104
3105 /* Parse an unwind_fnend directive. Generates the index table entry. */
3106
3107 static void
3108 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3109 {
3110 long where;
3111 char *ptr;
3112 valueT val;
3113
3114 demand_empty_rest_of_line ();
3115
3116 /* Add eh table entry. */
3117 if (unwind.table_entry == NULL)
3118 val = create_unwind_entry (0);
3119 else
3120 val = 0;
3121
3122 /* Add index table entry. This is two words. */
3123 start_unwind_section (unwind.saved_seg, 1);
3124 frag_align (2, 0, 0);
3125 record_alignment (now_seg, 2);
3126
3127 ptr = frag_more (8);
3128 where = frag_now_fix () - 8;
3129
3130 /* Self relative offset of the function start. */
3131 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3132 BFD_RELOC_ARM_PREL31);
3133
3134 /* Indicate dependency on EHABI-defined personality routines to the
3135 linker, if it hasn't been done already. */
3136 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3137 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3138 {
3139 static const char *const name[] =
3140 {
3141 "__aeabi_unwind_cpp_pr0",
3142 "__aeabi_unwind_cpp_pr1",
3143 "__aeabi_unwind_cpp_pr2"
3144 };
3145 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3146 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3147 marked_pr_dependency |= 1 << unwind.personality_index;
3148 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3149 = marked_pr_dependency;
3150 }
3151
3152 if (val)
3153 /* Inline exception table entry. */
3154 md_number_to_chars (ptr + 4, val, 4);
3155 else
3156 /* Self relative offset of the table entry. */
3157 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3158 BFD_RELOC_ARM_PREL31);
3159
3160 /* Restore the original section. */
3161 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3162 }
3163
3164
3165 /* Parse an unwind_cantunwind directive. */
3166
3167 static void
3168 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3169 {
3170 demand_empty_rest_of_line ();
3171 if (unwind.personality_routine || unwind.personality_index != -1)
3172 as_bad (_("personality routine specified for cantunwind frame"));
3173
3174 unwind.personality_index = -2;
3175 }
3176
3177
3178 /* Parse a personalityindex directive. */
3179
3180 static void
3181 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3182 {
3183 expressionS exp;
3184
3185 if (unwind.personality_routine || unwind.personality_index != -1)
3186 as_bad (_("duplicate .personalityindex directive"));
3187
3188 expression (&exp);
3189
3190 if (exp.X_op != O_constant
3191 || exp.X_add_number < 0 || exp.X_add_number > 15)
3192 {
3193 as_bad (_("bad personality routine number"));
3194 ignore_rest_of_line ();
3195 return;
3196 }
3197
3198 unwind.personality_index = exp.X_add_number;
3199
3200 demand_empty_rest_of_line ();
3201 }
3202
3203
3204 /* Parse a personality directive. */
3205
3206 static void
3207 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3208 {
3209 char *name, *p, c;
3210
3211 if (unwind.personality_routine || unwind.personality_index != -1)
3212 as_bad (_("duplicate .personality directive"));
3213
3214 name = input_line_pointer;
3215 c = get_symbol_end ();
3216 p = input_line_pointer;
3217 unwind.personality_routine = symbol_find_or_make (name);
3218 *p = c;
3219 demand_empty_rest_of_line ();
3220 }
3221
3222
3223 /* Parse a directive saving core registers. */
3224
3225 static void
3226 s_arm_unwind_save_core (void)
3227 {
3228 valueT op;
3229 long range;
3230 int n;
3231
3232 range = parse_reg_list (&input_line_pointer);
3233 if (range == FAIL)
3234 {
3235 as_bad (_("expected register list"));
3236 ignore_rest_of_line ();
3237 return;
3238 }
3239
3240 demand_empty_rest_of_line ();
3241
3242 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3243 into .unwind_save {..., sp...}. We aren't bothered about the value of
3244 ip because it is clobbered by calls. */
3245 if (unwind.sp_restored && unwind.fp_reg == 12
3246 && (range & 0x3000) == 0x1000)
3247 {
3248 unwind.opcode_count--;
3249 unwind.sp_restored = 0;
3250 range = (range | 0x2000) & ~0x1000;
3251 unwind.pending_offset = 0;
3252 }
3253
3254 /* Pop r4-r15. */
3255 if (range & 0xfff0)
3256 {
3257 /* See if we can use the short opcodes. These pop a block of up to 8
3258 registers starting with r4, plus maybe r14. */
3259 for (n = 0; n < 8; n++)
3260 {
3261 /* Break at the first non-saved register. */
3262 if ((range & (1 << (n + 4))) == 0)
3263 break;
3264 }
3265 /* See if there are any other bits set. */
3266 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3267 {
3268 /* Use the long form. */
3269 op = 0x8000 | ((range >> 4) & 0xfff);
3270 add_unwind_opcode (op, 2);
3271 }
3272 else
3273 {
3274 /* Use the short form. */
3275 if (range & 0x4000)
3276 op = 0xa8; /* Pop r14. */
3277 else
3278 op = 0xa0; /* Do not pop r14. */
3279 op |= (n - 1);
3280 add_unwind_opcode (op, 1);
3281 }
3282 }
3283
3284 /* Pop r0-r3. */
3285 if (range & 0xf)
3286 {
3287 op = 0xb100 | (range & 0xf);
3288 add_unwind_opcode (op, 2);
3289 }
3290
3291 /* Record the number of bytes pushed. */
3292 for (n = 0; n < 16; n++)
3293 {
3294 if (range & (1 << n))
3295 unwind.frame_size += 4;
3296 }
3297 }
3298
3299
3300 /* Parse a directive saving FPA registers. */
3301
3302 static void
3303 s_arm_unwind_save_fpa (int reg)
3304 {
3305 expressionS exp;
3306 int num_regs;
3307 valueT op;
3308
3309 /* Get Number of registers to transfer. */
3310 if (skip_past_comma (&input_line_pointer) != FAIL)
3311 expression (&exp);
3312 else
3313 exp.X_op = O_illegal;
3314
3315 if (exp.X_op != O_constant)
3316 {
3317 as_bad (_("expected , <constant>"));
3318 ignore_rest_of_line ();
3319 return;
3320 }
3321
3322 num_regs = exp.X_add_number;
3323
3324 if (num_regs < 1 || num_regs > 4)
3325 {
3326 as_bad (_("number of registers must be in the range [1:4]"));
3327 ignore_rest_of_line ();
3328 return;
3329 }
3330
3331 demand_empty_rest_of_line ();
3332
3333 if (reg == 4)
3334 {
3335 /* Short form. */
3336 op = 0xb4 | (num_regs - 1);
3337 add_unwind_opcode (op, 1);
3338 }
3339 else
3340 {
3341 /* Long form. */
3342 op = 0xc800 | (reg << 4) | (num_regs - 1);
3343 add_unwind_opcode (op, 2);
3344 }
3345 unwind.frame_size += num_regs * 12;
3346 }
3347
3348
3349 /* Parse a directive saving VFP registers for ARMv6 and above. */
3350
3351 static void
3352 s_arm_unwind_save_vfp_armv6 (void)
3353 {
3354 int count;
3355 unsigned int start;
3356 valueT op;
3357 int num_vfpv3_regs = 0;
3358 int num_regs_below_16;
3359
3360 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3361 if (count == FAIL)
3362 {
3363 as_bad (_("expected register list"));
3364 ignore_rest_of_line ();
3365 return;
3366 }
3367
3368 demand_empty_rest_of_line ();
3369
3370 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3371 than FSTMX/FLDMX-style ones). */
3372
3373 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3374 if (start >= 16)
3375 num_vfpv3_regs = count;
3376 else if (start + count > 16)
3377 num_vfpv3_regs = start + count - 16;
3378
3379 if (num_vfpv3_regs > 0)
3380 {
3381 int start_offset = start > 16 ? start - 16 : 0;
3382 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3383 add_unwind_opcode (op, 2);
3384 }
3385
3386 /* Generate opcode for registers numbered in the range 0 .. 15. */
3387 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3388 assert (num_regs_below_16 + num_vfpv3_regs == count);
3389 if (num_regs_below_16 > 0)
3390 {
3391 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3392 add_unwind_opcode (op, 2);
3393 }
3394
3395 unwind.frame_size += count * 8;
3396 }
3397
3398
3399 /* Parse a directive saving VFP registers for pre-ARMv6. */
3400
3401 static void
3402 s_arm_unwind_save_vfp (void)
3403 {
3404 int count;
3405 unsigned int reg;
3406 valueT op;
3407
3408 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
3409 if (count == FAIL)
3410 {
3411 as_bad (_("expected register list"));
3412 ignore_rest_of_line ();
3413 return;
3414 }
3415
3416 demand_empty_rest_of_line ();
3417
3418 if (reg == 8)
3419 {
3420 /* Short form. */
3421 op = 0xb8 | (count - 1);
3422 add_unwind_opcode (op, 1);
3423 }
3424 else
3425 {
3426 /* Long form. */
3427 op = 0xb300 | (reg << 4) | (count - 1);
3428 add_unwind_opcode (op, 2);
3429 }
3430 unwind.frame_size += count * 8 + 4;
3431 }
3432
3433
3434 /* Parse a directive saving iWMMXt data registers. */
3435
3436 static void
3437 s_arm_unwind_save_mmxwr (void)
3438 {
3439 int reg;
3440 int hi_reg;
3441 int i;
3442 unsigned mask = 0;
3443 valueT op;
3444
3445 if (*input_line_pointer == '{')
3446 input_line_pointer++;
3447
3448 do
3449 {
3450 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3451
3452 if (reg == FAIL)
3453 {
3454 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3455 goto error;
3456 }
3457
3458 if (mask >> reg)
3459 as_tsktsk (_("register list not in ascending order"));
3460 mask |= 1 << reg;
3461
3462 if (*input_line_pointer == '-')
3463 {
3464 input_line_pointer++;
3465 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3466 if (hi_reg == FAIL)
3467 {
3468 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3469 goto error;
3470 }
3471 else if (reg >= hi_reg)
3472 {
3473 as_bad (_("bad register range"));
3474 goto error;
3475 }
3476 for (; reg < hi_reg; reg++)
3477 mask |= 1 << reg;
3478 }
3479 }
3480 while (skip_past_comma (&input_line_pointer) != FAIL);
3481
3482 if (*input_line_pointer == '}')
3483 input_line_pointer++;
3484
3485 demand_empty_rest_of_line ();
3486
3487 /* Generate any deferred opcodes because we're going to be looking at
3488 the list. */
3489 flush_pending_unwind ();
3490
3491 for (i = 0; i < 16; i++)
3492 {
3493 if (mask & (1 << i))
3494 unwind.frame_size += 8;
3495 }
3496
3497 /* Attempt to combine with a previous opcode. We do this because gcc
3498 likes to output separate unwind directives for a single block of
3499 registers. */
3500 if (unwind.opcode_count > 0)
3501 {
3502 i = unwind.opcodes[unwind.opcode_count - 1];
3503 if ((i & 0xf8) == 0xc0)
3504 {
3505 i &= 7;
3506 /* Only merge if the blocks are contiguous. */
3507 if (i < 6)
3508 {
3509 if ((mask & 0xfe00) == (1 << 9))
3510 {
3511 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3512 unwind.opcode_count--;
3513 }
3514 }
3515 else if (i == 6 && unwind.opcode_count >= 2)
3516 {
3517 i = unwind.opcodes[unwind.opcode_count - 2];
3518 reg = i >> 4;
3519 i &= 0xf;
3520
3521 op = 0xffff << (reg - 1);
3522 if (reg > 0
3523 && ((mask & op) == (1u << (reg - 1))))
3524 {
3525 op = (1 << (reg + i + 1)) - 1;
3526 op &= ~((1 << reg) - 1);
3527 mask |= op;
3528 unwind.opcode_count -= 2;
3529 }
3530 }
3531 }
3532 }
3533
3534 hi_reg = 15;
3535 /* We want to generate opcodes in the order the registers have been
3536 saved, ie. descending order. */
3537 for (reg = 15; reg >= -1; reg--)
3538 {
3539 /* Save registers in blocks. */
3540 if (reg < 0
3541 || !(mask & (1 << reg)))
3542 {
3543 /* We found an unsaved reg. Generate opcodes to save the
3544 preceding block. */
3545 if (reg != hi_reg)
3546 {
3547 if (reg == 9)
3548 {
3549 /* Short form. */
3550 op = 0xc0 | (hi_reg - 10);
3551 add_unwind_opcode (op, 1);
3552 }
3553 else
3554 {
3555 /* Long form. */
3556 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3557 add_unwind_opcode (op, 2);
3558 }
3559 }
3560 hi_reg = reg - 1;
3561 }
3562 }
3563
3564 return;
3565 error:
3566 ignore_rest_of_line ();
3567 }
3568
3569 static void
3570 s_arm_unwind_save_mmxwcg (void)
3571 {
3572 int reg;
3573 int hi_reg;
3574 unsigned mask = 0;
3575 valueT op;
3576
3577 if (*input_line_pointer == '{')
3578 input_line_pointer++;
3579
3580 do
3581 {
3582 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3583
3584 if (reg == FAIL)
3585 {
3586 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3587 goto error;
3588 }
3589
3590 reg -= 8;
3591 if (mask >> reg)
3592 as_tsktsk (_("register list not in ascending order"));
3593 mask |= 1 << reg;
3594
3595 if (*input_line_pointer == '-')
3596 {
3597 input_line_pointer++;
3598 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3599 if (hi_reg == FAIL)
3600 {
3601 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3602 goto error;
3603 }
3604 else if (reg >= hi_reg)
3605 {
3606 as_bad (_("bad register range"));
3607 goto error;
3608 }
3609 for (; reg < hi_reg; reg++)
3610 mask |= 1 << reg;
3611 }
3612 }
3613 while (skip_past_comma (&input_line_pointer) != FAIL);
3614
3615 if (*input_line_pointer == '}')
3616 input_line_pointer++;
3617
3618 demand_empty_rest_of_line ();
3619
3620 /* Generate any deferred opcodes because we're going to be looking at
3621 the list. */
3622 flush_pending_unwind ();
3623
3624 for (reg = 0; reg < 16; reg++)
3625 {
3626 if (mask & (1 << reg))
3627 unwind.frame_size += 4;
3628 }
3629 op = 0xc700 | mask;
3630 add_unwind_opcode (op, 2);
3631 return;
3632 error:
3633 ignore_rest_of_line ();
3634 }
3635
3636
3637 /* Parse an unwind_save directive.
3638 If the argument is non-zero, this is a .vsave directive. */
3639
3640 static void
3641 s_arm_unwind_save (int arch_v6)
3642 {
3643 char *peek;
3644 struct reg_entry *reg;
3645 bfd_boolean had_brace = FALSE;
3646
3647 /* Figure out what sort of save we have. */
3648 peek = input_line_pointer;
3649
3650 if (*peek == '{')
3651 {
3652 had_brace = TRUE;
3653 peek++;
3654 }
3655
3656 reg = arm_reg_parse_multi (&peek);
3657
3658 if (!reg)
3659 {
3660 as_bad (_("register expected"));
3661 ignore_rest_of_line ();
3662 return;
3663 }
3664
3665 switch (reg->type)
3666 {
3667 case REG_TYPE_FN:
3668 if (had_brace)
3669 {
3670 as_bad (_("FPA .unwind_save does not take a register list"));
3671 ignore_rest_of_line ();
3672 return;
3673 }
3674 input_line_pointer = peek;
3675 s_arm_unwind_save_fpa (reg->number);
3676 return;
3677
3678 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
3679 case REG_TYPE_VFD:
3680 if (arch_v6)
3681 s_arm_unwind_save_vfp_armv6 ();
3682 else
3683 s_arm_unwind_save_vfp ();
3684 return;
3685 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
3686 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
3687
3688 default:
3689 as_bad (_(".unwind_save does not support this kind of register"));
3690 ignore_rest_of_line ();
3691 }
3692 }
3693
3694
3695 /* Parse an unwind_movsp directive. */
3696
3697 static void
3698 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
3699 {
3700 int reg;
3701 valueT op;
3702 int offset;
3703
3704 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3705 if (reg == FAIL)
3706 {
3707 as_bad (_(reg_expected_msgs[REG_TYPE_RN]));
3708 ignore_rest_of_line ();
3709 return;
3710 }
3711
3712 /* Optional constant. */
3713 if (skip_past_comma (&input_line_pointer) != FAIL)
3714 {
3715 if (immediate_for_directive (&offset) == FAIL)
3716 return;
3717 }
3718 else
3719 offset = 0;
3720
3721 demand_empty_rest_of_line ();
3722
3723 if (reg == REG_SP || reg == REG_PC)
3724 {
3725 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
3726 return;
3727 }
3728
3729 if (unwind.fp_reg != REG_SP)
3730 as_bad (_("unexpected .unwind_movsp directive"));
3731
3732 /* Generate opcode to restore the value. */
3733 op = 0x90 | reg;
3734 add_unwind_opcode (op, 1);
3735
3736 /* Record the information for later. */
3737 unwind.fp_reg = reg;
3738 unwind.fp_offset = unwind.frame_size - offset;
3739 unwind.sp_restored = 1;
3740 }
3741
3742 /* Parse an unwind_pad directive. */
3743
3744 static void
3745 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
3746 {
3747 int offset;
3748
3749 if (immediate_for_directive (&offset) == FAIL)
3750 return;
3751
3752 if (offset & 3)
3753 {
3754 as_bad (_("stack increment must be multiple of 4"));
3755 ignore_rest_of_line ();
3756 return;
3757 }
3758
3759 /* Don't generate any opcodes, just record the details for later. */
3760 unwind.frame_size += offset;
3761 unwind.pending_offset += offset;
3762
3763 demand_empty_rest_of_line ();
3764 }
3765
3766 /* Parse an unwind_setfp directive. */
3767
3768 static void
3769 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
3770 {
3771 int sp_reg;
3772 int fp_reg;
3773 int offset;
3774
3775 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3776 if (skip_past_comma (&input_line_pointer) == FAIL)
3777 sp_reg = FAIL;
3778 else
3779 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3780
3781 if (fp_reg == FAIL || sp_reg == FAIL)
3782 {
3783 as_bad (_("expected <reg>, <reg>"));
3784 ignore_rest_of_line ();
3785 return;
3786 }
3787
3788 /* Optional constant. */
3789 if (skip_past_comma (&input_line_pointer) != FAIL)
3790 {
3791 if (immediate_for_directive (&offset) == FAIL)
3792 return;
3793 }
3794 else
3795 offset = 0;
3796
3797 demand_empty_rest_of_line ();
3798
3799 if (sp_reg != 13 && sp_reg != unwind.fp_reg)
3800 {
3801 as_bad (_("register must be either sp or set by a previous"
3802 "unwind_movsp directive"));
3803 return;
3804 }
3805
3806 /* Don't generate any opcodes, just record the information for later. */
3807 unwind.fp_reg = fp_reg;
3808 unwind.fp_used = 1;
3809 if (sp_reg == 13)
3810 unwind.fp_offset = unwind.frame_size - offset;
3811 else
3812 unwind.fp_offset -= offset;
3813 }
3814
3815 /* Parse an unwind_raw directive. */
3816
3817 static void
3818 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
3819 {
3820 expressionS exp;
3821 /* This is an arbitrary limit. */
3822 unsigned char op[16];
3823 int count;
3824
3825 expression (&exp);
3826 if (exp.X_op == O_constant
3827 && skip_past_comma (&input_line_pointer) != FAIL)
3828 {
3829 unwind.frame_size += exp.X_add_number;
3830 expression (&exp);
3831 }
3832 else
3833 exp.X_op = O_illegal;
3834
3835 if (exp.X_op != O_constant)
3836 {
3837 as_bad (_("expected <offset>, <opcode>"));
3838 ignore_rest_of_line ();
3839 return;
3840 }
3841
3842 count = 0;
3843
3844 /* Parse the opcode. */
3845 for (;;)
3846 {
3847 if (count >= 16)
3848 {
3849 as_bad (_("unwind opcode too long"));
3850 ignore_rest_of_line ();
3851 }
3852 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
3853 {
3854 as_bad (_("invalid unwind opcode"));
3855 ignore_rest_of_line ();
3856 return;
3857 }
3858 op[count++] = exp.X_add_number;
3859
3860 /* Parse the next byte. */
3861 if (skip_past_comma (&input_line_pointer) == FAIL)
3862 break;
3863
3864 expression (&exp);
3865 }
3866
3867 /* Add the opcode bytes in reverse order. */
3868 while (count--)
3869 add_unwind_opcode (op[count], 1);
3870
3871 demand_empty_rest_of_line ();
3872 }
3873
3874
3875 /* Parse a .eabi_attribute directive. */
3876
3877 static void
3878 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
3879 {
3880 s_vendor_attribute (OBJ_ATTR_PROC);
3881 }
3882 #endif /* OBJ_ELF */
3883
3884 static void s_arm_arch (int);
3885 static void s_arm_object_arch (int);
3886 static void s_arm_cpu (int);
3887 static void s_arm_fpu (int);
3888
3889 #ifdef TE_PE
3890
3891 static void
3892 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
3893 {
3894 expressionS exp;
3895
3896 do
3897 {
3898 expression (&exp);
3899 if (exp.X_op == O_symbol)
3900 exp.X_op = O_secrel;
3901
3902 emit_expr (&exp, 4);
3903 }
3904 while (*input_line_pointer++ == ',');
3905
3906 input_line_pointer--;
3907 demand_empty_rest_of_line ();
3908 }
3909 #endif /* TE_PE */
3910
3911 /* This table describes all the machine specific pseudo-ops the assembler
3912 has to support. The fields are:
3913 pseudo-op name without dot
3914 function to call to execute this pseudo-op
3915 Integer arg to pass to the function. */
3916
3917 const pseudo_typeS md_pseudo_table[] =
3918 {
3919 /* Never called because '.req' does not start a line. */
3920 { "req", s_req, 0 },
3921 /* Following two are likewise never called. */
3922 { "dn", s_dn, 0 },
3923 { "qn", s_qn, 0 },
3924 { "unreq", s_unreq, 0 },
3925 { "bss", s_bss, 0 },
3926 { "align", s_align, 0 },
3927 { "arm", s_arm, 0 },
3928 { "thumb", s_thumb, 0 },
3929 { "code", s_code, 0 },
3930 { "force_thumb", s_force_thumb, 0 },
3931 { "thumb_func", s_thumb_func, 0 },
3932 { "thumb_set", s_thumb_set, 0 },
3933 { "even", s_even, 0 },
3934 { "ltorg", s_ltorg, 0 },
3935 { "pool", s_ltorg, 0 },
3936 { "syntax", s_syntax, 0 },
3937 { "cpu", s_arm_cpu, 0 },
3938 { "arch", s_arm_arch, 0 },
3939 { "object_arch", s_arm_object_arch, 0 },
3940 { "fpu", s_arm_fpu, 0 },
3941 #ifdef OBJ_ELF
3942 { "word", s_arm_elf_cons, 4 },
3943 { "long", s_arm_elf_cons, 4 },
3944 { "rel31", s_arm_rel31, 0 },
3945 { "fnstart", s_arm_unwind_fnstart, 0 },
3946 { "fnend", s_arm_unwind_fnend, 0 },
3947 { "cantunwind", s_arm_unwind_cantunwind, 0 },
3948 { "personality", s_arm_unwind_personality, 0 },
3949 { "personalityindex", s_arm_unwind_personalityindex, 0 },
3950 { "handlerdata", s_arm_unwind_handlerdata, 0 },
3951 { "save", s_arm_unwind_save, 0 },
3952 { "vsave", s_arm_unwind_save, 1 },
3953 { "movsp", s_arm_unwind_movsp, 0 },
3954 { "pad", s_arm_unwind_pad, 0 },
3955 { "setfp", s_arm_unwind_setfp, 0 },
3956 { "unwind_raw", s_arm_unwind_raw, 0 },
3957 { "eabi_attribute", s_arm_eabi_attribute, 0 },
3958 #else
3959 { "word", cons, 4},
3960
3961 /* These are used for dwarf. */
3962 {"2byte", cons, 2},
3963 {"4byte", cons, 4},
3964 {"8byte", cons, 8},
3965 /* These are used for dwarf2. */
3966 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
3967 { "loc", dwarf2_directive_loc, 0 },
3968 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
3969 #endif
3970 { "extend", float_cons, 'x' },
3971 { "ldouble", float_cons, 'x' },
3972 { "packed", float_cons, 'p' },
3973 #ifdef TE_PE
3974 {"secrel32", pe_directive_secrel, 0},
3975 #endif
3976 { 0, 0, 0 }
3977 };
3978 \f
3979 /* Parser functions used exclusively in instruction operands. */
3980
3981 /* Generic immediate-value read function for use in insn parsing.
3982 STR points to the beginning of the immediate (the leading #);
3983 VAL receives the value; if the value is outside [MIN, MAX]
3984 issue an error. PREFIX_OPT is true if the immediate prefix is
3985 optional. */
3986
3987 static int
3988 parse_immediate (char **str, int *val, int min, int max,
3989 bfd_boolean prefix_opt)
3990 {
3991 expressionS exp;
3992 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
3993 if (exp.X_op != O_constant)
3994 {
3995 inst.error = _("constant expression required");
3996 return FAIL;
3997 }
3998
3999 if (exp.X_add_number < min || exp.X_add_number > max)
4000 {
4001 inst.error = _("immediate value out of range");
4002 return FAIL;
4003 }
4004
4005 *val = exp.X_add_number;
4006 return SUCCESS;
4007 }
4008
4009 /* Less-generic immediate-value read function with the possibility of loading a
4010 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
4011 instructions. Puts the result directly in inst.operands[i]. */
4012
4013 static int
4014 parse_big_immediate (char **str, int i)
4015 {
4016 expressionS exp;
4017 char *ptr = *str;
4018
4019 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4020
4021 if (exp.X_op == O_constant)
4022 {
4023 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4024 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4025 O_constant. We have to be careful not to break compilation for
4026 32-bit X_add_number, though. */
4027 if ((exp.X_add_number & ~0xffffffffl) != 0)
4028 {
4029 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4030 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4031 inst.operands[i].regisimm = 1;
4032 }
4033 }
4034 else if (exp.X_op == O_big
4035 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4036 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4037 {
4038 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4039 /* Bignums have their least significant bits in
4040 generic_bignum[0]. Make sure we put 32 bits in imm and
4041 32 bits in reg, in a (hopefully) portable way. */
4042 assert (parts != 0);
4043 inst.operands[i].imm = 0;
4044 for (j = 0; j < parts; j++, idx++)
4045 inst.operands[i].imm |= generic_bignum[idx]
4046 << (LITTLENUM_NUMBER_OF_BITS * j);
4047 inst.operands[i].reg = 0;
4048 for (j = 0; j < parts; j++, idx++)
4049 inst.operands[i].reg |= generic_bignum[idx]
4050 << (LITTLENUM_NUMBER_OF_BITS * j);
4051 inst.operands[i].regisimm = 1;
4052 }
4053 else
4054 return FAIL;
4055
4056 *str = ptr;
4057
4058 return SUCCESS;
4059 }
4060
4061 /* Returns the pseudo-register number of an FPA immediate constant,
4062 or FAIL if there isn't a valid constant here. */
4063
4064 static int
4065 parse_fpa_immediate (char ** str)
4066 {
4067 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4068 char * save_in;
4069 expressionS exp;
4070 int i;
4071 int j;
4072
4073 /* First try and match exact strings, this is to guarantee
4074 that some formats will work even for cross assembly. */
4075
4076 for (i = 0; fp_const[i]; i++)
4077 {
4078 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4079 {
4080 char *start = *str;
4081
4082 *str += strlen (fp_const[i]);
4083 if (is_end_of_line[(unsigned char) **str])
4084 return i + 8;
4085 *str = start;
4086 }
4087 }
4088
4089 /* Just because we didn't get a match doesn't mean that the constant
4090 isn't valid, just that it is in a format that we don't
4091 automatically recognize. Try parsing it with the standard
4092 expression routines. */
4093
4094 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
4095
4096 /* Look for a raw floating point number. */
4097 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4098 && is_end_of_line[(unsigned char) *save_in])
4099 {
4100 for (i = 0; i < NUM_FLOAT_VALS; i++)
4101 {
4102 for (j = 0; j < MAX_LITTLENUMS; j++)
4103 {
4104 if (words[j] != fp_values[i][j])
4105 break;
4106 }
4107
4108 if (j == MAX_LITTLENUMS)
4109 {
4110 *str = save_in;
4111 return i + 8;
4112 }
4113 }
4114 }
4115
4116 /* Try and parse a more complex expression, this will probably fail
4117 unless the code uses a floating point prefix (eg "0f"). */
4118 save_in = input_line_pointer;
4119 input_line_pointer = *str;
4120 if (expression (&exp) == absolute_section
4121 && exp.X_op == O_big
4122 && exp.X_add_number < 0)
4123 {
4124 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4125 Ditto for 15. */
4126 if (gen_to_words (words, 5, (long) 15) == 0)
4127 {
4128 for (i = 0; i < NUM_FLOAT_VALS; i++)
4129 {
4130 for (j = 0; j < MAX_LITTLENUMS; j++)
4131 {
4132 if (words[j] != fp_values[i][j])
4133 break;
4134 }
4135
4136 if (j == MAX_LITTLENUMS)
4137 {
4138 *str = input_line_pointer;
4139 input_line_pointer = save_in;
4140 return i + 8;
4141 }
4142 }
4143 }
4144 }
4145
4146 *str = input_line_pointer;
4147 input_line_pointer = save_in;
4148 inst.error = _("invalid FPA immediate expression");
4149 return FAIL;
4150 }
4151
4152 /* Returns 1 if a number has "quarter-precision" float format
4153 0baBbbbbbc defgh000 00000000 00000000. */
4154
4155 static int
4156 is_quarter_float (unsigned imm)
4157 {
4158 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4159 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4160 }
4161
4162 /* Parse an 8-bit "quarter-precision" floating point number of the form:
4163 0baBbbbbbc defgh000 00000000 00000000.
4164 The zero and minus-zero cases need special handling, since they can't be
4165 encoded in the "quarter-precision" float format, but can nonetheless be
4166 loaded as integer constants. */
4167
4168 static unsigned
4169 parse_qfloat_immediate (char **ccp, int *immed)
4170 {
4171 char *str = *ccp;
4172 char *fpnum;
4173 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4174 int found_fpchar = 0;
4175
4176 skip_past_char (&str, '#');
4177
4178 /* We must not accidentally parse an integer as a floating-point number. Make
4179 sure that the value we parse is not an integer by checking for special
4180 characters '.' or 'e'.
4181 FIXME: This is a horrible hack, but doing better is tricky because type
4182 information isn't in a very usable state at parse time. */
4183 fpnum = str;
4184 skip_whitespace (fpnum);
4185
4186 if (strncmp (fpnum, "0x", 2) == 0)
4187 return FAIL;
4188 else
4189 {
4190 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4191 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4192 {
4193 found_fpchar = 1;
4194 break;
4195 }
4196
4197 if (!found_fpchar)
4198 return FAIL;
4199 }
4200
4201 if ((str = atof_ieee (str, 's', words)) != NULL)
4202 {
4203 unsigned fpword = 0;
4204 int i;
4205
4206 /* Our FP word must be 32 bits (single-precision FP). */
4207 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4208 {
4209 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4210 fpword |= words[i];
4211 }
4212
4213 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
4214 *immed = fpword;
4215 else
4216 return FAIL;
4217
4218 *ccp = str;
4219
4220 return SUCCESS;
4221 }
4222
4223 return FAIL;
4224 }
4225
4226 /* Shift operands. */
4227 enum shift_kind
4228 {
4229 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4230 };
4231
4232 struct asm_shift_name
4233 {
4234 const char *name;
4235 enum shift_kind kind;
4236 };
4237
4238 /* Third argument to parse_shift. */
4239 enum parse_shift_mode
4240 {
4241 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4242 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4243 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4244 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4245 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4246 };
4247
4248 /* Parse a <shift> specifier on an ARM data processing instruction.
4249 This has three forms:
4250
4251 (LSL|LSR|ASL|ASR|ROR) Rs
4252 (LSL|LSR|ASL|ASR|ROR) #imm
4253 RRX
4254
4255 Note that ASL is assimilated to LSL in the instruction encoding, and
4256 RRX to ROR #0 (which cannot be written as such). */
4257
4258 static int
4259 parse_shift (char **str, int i, enum parse_shift_mode mode)
4260 {
4261 const struct asm_shift_name *shift_name;
4262 enum shift_kind shift;
4263 char *s = *str;
4264 char *p = s;
4265 int reg;
4266
4267 for (p = *str; ISALPHA (*p); p++)
4268 ;
4269
4270 if (p == *str)
4271 {
4272 inst.error = _("shift expression expected");
4273 return FAIL;
4274 }
4275
4276 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
4277
4278 if (shift_name == NULL)
4279 {
4280 inst.error = _("shift expression expected");
4281 return FAIL;
4282 }
4283
4284 shift = shift_name->kind;
4285
4286 switch (mode)
4287 {
4288 case NO_SHIFT_RESTRICT:
4289 case SHIFT_IMMEDIATE: break;
4290
4291 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4292 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4293 {
4294 inst.error = _("'LSL' or 'ASR' required");
4295 return FAIL;
4296 }
4297 break;
4298
4299 case SHIFT_LSL_IMMEDIATE:
4300 if (shift != SHIFT_LSL)
4301 {
4302 inst.error = _("'LSL' required");
4303 return FAIL;
4304 }
4305 break;
4306
4307 case SHIFT_ASR_IMMEDIATE:
4308 if (shift != SHIFT_ASR)
4309 {
4310 inst.error = _("'ASR' required");
4311 return FAIL;
4312 }
4313 break;
4314
4315 default: abort ();
4316 }
4317
4318 if (shift != SHIFT_RRX)
4319 {
4320 /* Whitespace can appear here if the next thing is a bare digit. */
4321 skip_whitespace (p);
4322
4323 if (mode == NO_SHIFT_RESTRICT
4324 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4325 {
4326 inst.operands[i].imm = reg;
4327 inst.operands[i].immisreg = 1;
4328 }
4329 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4330 return FAIL;
4331 }
4332 inst.operands[i].shift_kind = shift;
4333 inst.operands[i].shifted = 1;
4334 *str = p;
4335 return SUCCESS;
4336 }
4337
4338 /* Parse a <shifter_operand> for an ARM data processing instruction:
4339
4340 #<immediate>
4341 #<immediate>, <rotate>
4342 <Rm>
4343 <Rm>, <shift>
4344
4345 where <shift> is defined by parse_shift above, and <rotate> is a
4346 multiple of 2 between 0 and 30. Validation of immediate operands
4347 is deferred to md_apply_fix. */
4348
4349 static int
4350 parse_shifter_operand (char **str, int i)
4351 {
4352 int value;
4353 expressionS expr;
4354
4355 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
4356 {
4357 inst.operands[i].reg = value;
4358 inst.operands[i].isreg = 1;
4359
4360 /* parse_shift will override this if appropriate */
4361 inst.reloc.exp.X_op = O_constant;
4362 inst.reloc.exp.X_add_number = 0;
4363
4364 if (skip_past_comma (str) == FAIL)
4365 return SUCCESS;
4366
4367 /* Shift operation on register. */
4368 return parse_shift (str, i, NO_SHIFT_RESTRICT);
4369 }
4370
4371 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4372 return FAIL;
4373
4374 if (skip_past_comma (str) == SUCCESS)
4375 {
4376 /* #x, y -- ie explicit rotation by Y. */
4377 if (my_get_expression (&expr, str, GE_NO_PREFIX))
4378 return FAIL;
4379
4380 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4381 {
4382 inst.error = _("constant expression expected");
4383 return FAIL;
4384 }
4385
4386 value = expr.X_add_number;
4387 if (value < 0 || value > 30 || value % 2 != 0)
4388 {
4389 inst.error = _("invalid rotation");
4390 return FAIL;
4391 }
4392 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4393 {
4394 inst.error = _("invalid constant");
4395 return FAIL;
4396 }
4397
4398 /* Convert to decoded value. md_apply_fix will put it back. */
4399 inst.reloc.exp.X_add_number
4400 = (((inst.reloc.exp.X_add_number << (32 - value))
4401 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
4402 }
4403
4404 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4405 inst.reloc.pc_rel = 0;
4406 return SUCCESS;
4407 }
4408
4409 /* Group relocation information. Each entry in the table contains the
4410 textual name of the relocation as may appear in assembler source
4411 and must end with a colon.
4412 Along with this textual name are the relocation codes to be used if
4413 the corresponding instruction is an ALU instruction (ADD or SUB only),
4414 an LDR, an LDRS, or an LDC. */
4415
4416 struct group_reloc_table_entry
4417 {
4418 const char *name;
4419 int alu_code;
4420 int ldr_code;
4421 int ldrs_code;
4422 int ldc_code;
4423 };
4424
4425 typedef enum
4426 {
4427 /* Varieties of non-ALU group relocation. */
4428
4429 GROUP_LDR,
4430 GROUP_LDRS,
4431 GROUP_LDC
4432 } group_reloc_type;
4433
4434 static struct group_reloc_table_entry group_reloc_table[] =
4435 { /* Program counter relative: */
4436 { "pc_g0_nc",
4437 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4438 0, /* LDR */
4439 0, /* LDRS */
4440 0 }, /* LDC */
4441 { "pc_g0",
4442 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4443 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4444 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4445 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4446 { "pc_g1_nc",
4447 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4448 0, /* LDR */
4449 0, /* LDRS */
4450 0 }, /* LDC */
4451 { "pc_g1",
4452 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4453 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4454 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4455 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4456 { "pc_g2",
4457 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4458 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4459 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4460 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4461 /* Section base relative */
4462 { "sb_g0_nc",
4463 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4464 0, /* LDR */
4465 0, /* LDRS */
4466 0 }, /* LDC */
4467 { "sb_g0",
4468 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4469 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4470 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4471 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4472 { "sb_g1_nc",
4473 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4474 0, /* LDR */
4475 0, /* LDRS */
4476 0 }, /* LDC */
4477 { "sb_g1",
4478 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4479 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4480 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4481 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4482 { "sb_g2",
4483 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4484 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4485 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4486 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4487
4488 /* Given the address of a pointer pointing to the textual name of a group
4489 relocation as may appear in assembler source, attempt to find its details
4490 in group_reloc_table. The pointer will be updated to the character after
4491 the trailing colon. On failure, FAIL will be returned; SUCCESS
4492 otherwise. On success, *entry will be updated to point at the relevant
4493 group_reloc_table entry. */
4494
4495 static int
4496 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4497 {
4498 unsigned int i;
4499 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4500 {
4501 int length = strlen (group_reloc_table[i].name);
4502
4503 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4504 && (*str)[length] == ':')
4505 {
4506 *out = &group_reloc_table[i];
4507 *str += (length + 1);
4508 return SUCCESS;
4509 }
4510 }
4511
4512 return FAIL;
4513 }
4514
4515 /* Parse a <shifter_operand> for an ARM data processing instruction
4516 (as for parse_shifter_operand) where group relocations are allowed:
4517
4518 #<immediate>
4519 #<immediate>, <rotate>
4520 #:<group_reloc>:<expression>
4521 <Rm>
4522 <Rm>, <shift>
4523
4524 where <group_reloc> is one of the strings defined in group_reloc_table.
4525 The hashes are optional.
4526
4527 Everything else is as for parse_shifter_operand. */
4528
4529 static parse_operand_result
4530 parse_shifter_operand_group_reloc (char **str, int i)
4531 {
4532 /* Determine if we have the sequence of characters #: or just :
4533 coming next. If we do, then we check for a group relocation.
4534 If we don't, punt the whole lot to parse_shifter_operand. */
4535
4536 if (((*str)[0] == '#' && (*str)[1] == ':')
4537 || (*str)[0] == ':')
4538 {
4539 struct group_reloc_table_entry *entry;
4540
4541 if ((*str)[0] == '#')
4542 (*str) += 2;
4543 else
4544 (*str)++;
4545
4546 /* Try to parse a group relocation. Anything else is an error. */
4547 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4548 {
4549 inst.error = _("unknown group relocation");
4550 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4551 }
4552
4553 /* We now have the group relocation table entry corresponding to
4554 the name in the assembler source. Next, we parse the expression. */
4555 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4556 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4557
4558 /* Record the relocation type (always the ALU variant here). */
4559 inst.reloc.type = entry->alu_code;
4560 assert (inst.reloc.type != 0);
4561
4562 return PARSE_OPERAND_SUCCESS;
4563 }
4564 else
4565 return parse_shifter_operand (str, i) == SUCCESS
4566 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4567
4568 /* Never reached. */
4569 }
4570
4571 /* Parse all forms of an ARM address expression. Information is written
4572 to inst.operands[i] and/or inst.reloc.
4573
4574 Preindexed addressing (.preind=1):
4575
4576 [Rn, #offset] .reg=Rn .reloc.exp=offset
4577 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4578 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4579 .shift_kind=shift .reloc.exp=shift_imm
4580
4581 These three may have a trailing ! which causes .writeback to be set also.
4582
4583 Postindexed addressing (.postind=1, .writeback=1):
4584
4585 [Rn], #offset .reg=Rn .reloc.exp=offset
4586 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4587 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4588 .shift_kind=shift .reloc.exp=shift_imm
4589
4590 Unindexed addressing (.preind=0, .postind=0):
4591
4592 [Rn], {option} .reg=Rn .imm=option .immisreg=0
4593
4594 Other:
4595
4596 [Rn]{!} shorthand for [Rn,#0]{!}
4597 =immediate .isreg=0 .reloc.exp=immediate
4598 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
4599
4600 It is the caller's responsibility to check for addressing modes not
4601 supported by the instruction, and to set inst.reloc.type. */
4602
4603 static parse_operand_result
4604 parse_address_main (char **str, int i, int group_relocations,
4605 group_reloc_type group_type)
4606 {
4607 char *p = *str;
4608 int reg;
4609
4610 if (skip_past_char (&p, '[') == FAIL)
4611 {
4612 if (skip_past_char (&p, '=') == FAIL)
4613 {
4614 /* bare address - translate to PC-relative offset */
4615 inst.reloc.pc_rel = 1;
4616 inst.operands[i].reg = REG_PC;
4617 inst.operands[i].isreg = 1;
4618 inst.operands[i].preind = 1;
4619 }
4620 /* else a load-constant pseudo op, no special treatment needed here */
4621
4622 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4623 return PARSE_OPERAND_FAIL;
4624
4625 *str = p;
4626 return PARSE_OPERAND_SUCCESS;
4627 }
4628
4629 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
4630 {
4631 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4632 return PARSE_OPERAND_FAIL;
4633 }
4634 inst.operands[i].reg = reg;
4635 inst.operands[i].isreg = 1;
4636
4637 if (skip_past_comma (&p) == SUCCESS)
4638 {
4639 inst.operands[i].preind = 1;
4640
4641 if (*p == '+') p++;
4642 else if (*p == '-') p++, inst.operands[i].negative = 1;
4643
4644 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4645 {
4646 inst.operands[i].imm = reg;
4647 inst.operands[i].immisreg = 1;
4648
4649 if (skip_past_comma (&p) == SUCCESS)
4650 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4651 return PARSE_OPERAND_FAIL;
4652 }
4653 else if (skip_past_char (&p, ':') == SUCCESS)
4654 {
4655 /* FIXME: '@' should be used here, but it's filtered out by generic
4656 code before we get to see it here. This may be subject to
4657 change. */
4658 expressionS exp;
4659 my_get_expression (&exp, &p, GE_NO_PREFIX);
4660 if (exp.X_op != O_constant)
4661 {
4662 inst.error = _("alignment must be constant");
4663 return PARSE_OPERAND_FAIL;
4664 }
4665 inst.operands[i].imm = exp.X_add_number << 8;
4666 inst.operands[i].immisalign = 1;
4667 /* Alignments are not pre-indexes. */
4668 inst.operands[i].preind = 0;
4669 }
4670 else
4671 {
4672 if (inst.operands[i].negative)
4673 {
4674 inst.operands[i].negative = 0;
4675 p--;
4676 }
4677
4678 if (group_relocations
4679 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4680 {
4681 struct group_reloc_table_entry *entry;
4682
4683 /* Skip over the #: or : sequence. */
4684 if (*p == '#')
4685 p += 2;
4686 else
4687 p++;
4688
4689 /* Try to parse a group relocation. Anything else is an
4690 error. */
4691 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
4692 {
4693 inst.error = _("unknown group relocation");
4694 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4695 }
4696
4697 /* We now have the group relocation table entry corresponding to
4698 the name in the assembler source. Next, we parse the
4699 expression. */
4700 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4701 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4702
4703 /* Record the relocation type. */
4704 switch (group_type)
4705 {
4706 case GROUP_LDR:
4707 inst.reloc.type = entry->ldr_code;
4708 break;
4709
4710 case GROUP_LDRS:
4711 inst.reloc.type = entry->ldrs_code;
4712 break;
4713
4714 case GROUP_LDC:
4715 inst.reloc.type = entry->ldc_code;
4716 break;
4717
4718 default:
4719 assert (0);
4720 }
4721
4722 if (inst.reloc.type == 0)
4723 {
4724 inst.error = _("this group relocation is not allowed on this instruction");
4725 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4726 }
4727 }
4728 else
4729 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4730 return PARSE_OPERAND_FAIL;
4731 }
4732 }
4733
4734 if (skip_past_char (&p, ']') == FAIL)
4735 {
4736 inst.error = _("']' expected");
4737 return PARSE_OPERAND_FAIL;
4738 }
4739
4740 if (skip_past_char (&p, '!') == SUCCESS)
4741 inst.operands[i].writeback = 1;
4742
4743 else if (skip_past_comma (&p) == SUCCESS)
4744 {
4745 if (skip_past_char (&p, '{') == SUCCESS)
4746 {
4747 /* [Rn], {expr} - unindexed, with option */
4748 if (parse_immediate (&p, &inst.operands[i].imm,
4749 0, 255, TRUE) == FAIL)
4750 return PARSE_OPERAND_FAIL;
4751
4752 if (skip_past_char (&p, '}') == FAIL)
4753 {
4754 inst.error = _("'}' expected at end of 'option' field");
4755 return PARSE_OPERAND_FAIL;
4756 }
4757 if (inst.operands[i].preind)
4758 {
4759 inst.error = _("cannot combine index with option");
4760 return PARSE_OPERAND_FAIL;
4761 }
4762 *str = p;
4763 return PARSE_OPERAND_SUCCESS;
4764 }
4765 else
4766 {
4767 inst.operands[i].postind = 1;
4768 inst.operands[i].writeback = 1;
4769
4770 if (inst.operands[i].preind)
4771 {
4772 inst.error = _("cannot combine pre- and post-indexing");
4773 return PARSE_OPERAND_FAIL;
4774 }
4775
4776 if (*p == '+') p++;
4777 else if (*p == '-') p++, inst.operands[i].negative = 1;
4778
4779 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4780 {
4781 /* We might be using the immediate for alignment already. If we
4782 are, OR the register number into the low-order bits. */
4783 if (inst.operands[i].immisalign)
4784 inst.operands[i].imm |= reg;
4785 else
4786 inst.operands[i].imm = reg;
4787 inst.operands[i].immisreg = 1;
4788
4789 if (skip_past_comma (&p) == SUCCESS)
4790 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4791 return PARSE_OPERAND_FAIL;
4792 }
4793 else
4794 {
4795 if (inst.operands[i].negative)
4796 {
4797 inst.operands[i].negative = 0;
4798 p--;
4799 }
4800 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4801 return PARSE_OPERAND_FAIL;
4802 }
4803 }
4804 }
4805
4806 /* If at this point neither .preind nor .postind is set, we have a
4807 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
4808 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
4809 {
4810 inst.operands[i].preind = 1;
4811 inst.reloc.exp.X_op = O_constant;
4812 inst.reloc.exp.X_add_number = 0;
4813 }
4814 *str = p;
4815 return PARSE_OPERAND_SUCCESS;
4816 }
4817
4818 static int
4819 parse_address (char **str, int i)
4820 {
4821 return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS
4822 ? SUCCESS : FAIL;
4823 }
4824
4825 static parse_operand_result
4826 parse_address_group_reloc (char **str, int i, group_reloc_type type)
4827 {
4828 return parse_address_main (str, i, 1, type);
4829 }
4830
4831 /* Parse an operand for a MOVW or MOVT instruction. */
4832 static int
4833 parse_half (char **str)
4834 {
4835 char * p;
4836
4837 p = *str;
4838 skip_past_char (&p, '#');
4839 if (strncasecmp (p, ":lower16:", 9) == 0)
4840 inst.reloc.type = BFD_RELOC_ARM_MOVW;
4841 else if (strncasecmp (p, ":upper16:", 9) == 0)
4842 inst.reloc.type = BFD_RELOC_ARM_MOVT;
4843
4844 if (inst.reloc.type != BFD_RELOC_UNUSED)
4845 {
4846 p += 9;
4847 skip_whitespace (p);
4848 }
4849
4850 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4851 return FAIL;
4852
4853 if (inst.reloc.type == BFD_RELOC_UNUSED)
4854 {
4855 if (inst.reloc.exp.X_op != O_constant)
4856 {
4857 inst.error = _("constant expression expected");
4858 return FAIL;
4859 }
4860 if (inst.reloc.exp.X_add_number < 0
4861 || inst.reloc.exp.X_add_number > 0xffff)
4862 {
4863 inst.error = _("immediate value out of range");
4864 return FAIL;
4865 }
4866 }
4867 *str = p;
4868 return SUCCESS;
4869 }
4870
4871 /* Miscellaneous. */
4872
4873 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
4874 or a bitmask suitable to be or-ed into the ARM msr instruction. */
4875 static int
4876 parse_psr (char **str)
4877 {
4878 char *p;
4879 unsigned long psr_field;
4880 const struct asm_psr *psr;
4881 char *start;
4882
4883 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
4884 feature for ease of use and backwards compatibility. */
4885 p = *str;
4886 if (strncasecmp (p, "SPSR", 4) == 0)
4887 psr_field = SPSR_BIT;
4888 else if (strncasecmp (p, "CPSR", 4) == 0)
4889 psr_field = 0;
4890 else
4891 {
4892 start = p;
4893 do
4894 p++;
4895 while (ISALNUM (*p) || *p == '_');
4896
4897 psr = hash_find_n (arm_v7m_psr_hsh, start, p - start);
4898 if (!psr)
4899 return FAIL;
4900
4901 *str = p;
4902 return psr->field;
4903 }
4904
4905 p += 4;
4906 if (*p == '_')
4907 {
4908 /* A suffix follows. */
4909 p++;
4910 start = p;
4911
4912 do
4913 p++;
4914 while (ISALNUM (*p) || *p == '_');
4915
4916 psr = hash_find_n (arm_psr_hsh, start, p - start);
4917 if (!psr)
4918 goto error;
4919
4920 psr_field |= psr->field;
4921 }
4922 else
4923 {
4924 if (ISALNUM (*p))
4925 goto error; /* Garbage after "[CS]PSR". */
4926
4927 psr_field |= (PSR_c | PSR_f);
4928 }
4929 *str = p;
4930 return psr_field;
4931
4932 error:
4933 inst.error = _("flag for {c}psr instruction expected");
4934 return FAIL;
4935 }
4936
4937 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
4938 value suitable for splatting into the AIF field of the instruction. */
4939
4940 static int
4941 parse_cps_flags (char **str)
4942 {
4943 int val = 0;
4944 int saw_a_flag = 0;
4945 char *s = *str;
4946
4947 for (;;)
4948 switch (*s++)
4949 {
4950 case '\0': case ',':
4951 goto done;
4952
4953 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
4954 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
4955 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
4956
4957 default:
4958 inst.error = _("unrecognized CPS flag");
4959 return FAIL;
4960 }
4961
4962 done:
4963 if (saw_a_flag == 0)
4964 {
4965 inst.error = _("missing CPS flags");
4966 return FAIL;
4967 }
4968
4969 *str = s - 1;
4970 return val;
4971 }
4972
4973 /* Parse an endian specifier ("BE" or "LE", case insensitive);
4974 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
4975
4976 static int
4977 parse_endian_specifier (char **str)
4978 {
4979 int little_endian;
4980 char *s = *str;
4981
4982 if (strncasecmp (s, "BE", 2))
4983 little_endian = 0;
4984 else if (strncasecmp (s, "LE", 2))
4985 little_endian = 1;
4986 else
4987 {
4988 inst.error = _("valid endian specifiers are be or le");
4989 return FAIL;
4990 }
4991
4992 if (ISALNUM (s[2]) || s[2] == '_')
4993 {
4994 inst.error = _("valid endian specifiers are be or le");
4995 return FAIL;
4996 }
4997
4998 *str = s + 2;
4999 return little_endian;
5000 }
5001
5002 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5003 value suitable for poking into the rotate field of an sxt or sxta
5004 instruction, or FAIL on error. */
5005
5006 static int
5007 parse_ror (char **str)
5008 {
5009 int rot;
5010 char *s = *str;
5011
5012 if (strncasecmp (s, "ROR", 3) == 0)
5013 s += 3;
5014 else
5015 {
5016 inst.error = _("missing rotation field after comma");
5017 return FAIL;
5018 }
5019
5020 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5021 return FAIL;
5022
5023 switch (rot)
5024 {
5025 case 0: *str = s; return 0x0;
5026 case 8: *str = s; return 0x1;
5027 case 16: *str = s; return 0x2;
5028 case 24: *str = s; return 0x3;
5029
5030 default:
5031 inst.error = _("rotation can only be 0, 8, 16, or 24");
5032 return FAIL;
5033 }
5034 }
5035
5036 /* Parse a conditional code (from conds[] below). The value returned is in the
5037 range 0 .. 14, or FAIL. */
5038 static int
5039 parse_cond (char **str)
5040 {
5041 char *p, *q;
5042 const struct asm_cond *c;
5043
5044 p = q = *str;
5045 while (ISALPHA (*q))
5046 q++;
5047
5048 c = hash_find_n (arm_cond_hsh, p, q - p);
5049 if (!c)
5050 {
5051 inst.error = _("condition required");
5052 return FAIL;
5053 }
5054
5055 *str = q;
5056 return c->value;
5057 }
5058
5059 /* Parse an option for a barrier instruction. Returns the encoding for the
5060 option, or FAIL. */
5061 static int
5062 parse_barrier (char **str)
5063 {
5064 char *p, *q;
5065 const struct asm_barrier_opt *o;
5066
5067 p = q = *str;
5068 while (ISALPHA (*q))
5069 q++;
5070
5071 o = hash_find_n (arm_barrier_opt_hsh, p, q - p);
5072 if (!o)
5073 return FAIL;
5074
5075 *str = q;
5076 return o->value;
5077 }
5078
5079 /* Parse the operands of a table branch instruction. Similar to a memory
5080 operand. */
5081 static int
5082 parse_tb (char **str)
5083 {
5084 char * p = *str;
5085 int reg;
5086
5087 if (skip_past_char (&p, '[') == FAIL)
5088 {
5089 inst.error = _("'[' expected");
5090 return FAIL;
5091 }
5092
5093 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5094 {
5095 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5096 return FAIL;
5097 }
5098 inst.operands[0].reg = reg;
5099
5100 if (skip_past_comma (&p) == FAIL)
5101 {
5102 inst.error = _("',' expected");
5103 return FAIL;
5104 }
5105
5106 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5107 {
5108 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5109 return FAIL;
5110 }
5111 inst.operands[0].imm = reg;
5112
5113 if (skip_past_comma (&p) == SUCCESS)
5114 {
5115 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5116 return FAIL;
5117 if (inst.reloc.exp.X_add_number != 1)
5118 {
5119 inst.error = _("invalid shift");
5120 return FAIL;
5121 }
5122 inst.operands[0].shifted = 1;
5123 }
5124
5125 if (skip_past_char (&p, ']') == FAIL)
5126 {
5127 inst.error = _("']' expected");
5128 return FAIL;
5129 }
5130 *str = p;
5131 return SUCCESS;
5132 }
5133
5134 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5135 information on the types the operands can take and how they are encoded.
5136 Up to four operands may be read; this function handles setting the
5137 ".present" field for each read operand itself.
5138 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5139 else returns FAIL. */
5140
5141 static int
5142 parse_neon_mov (char **str, int *which_operand)
5143 {
5144 int i = *which_operand, val;
5145 enum arm_reg_type rtype;
5146 char *ptr = *str;
5147 struct neon_type_el optype;
5148
5149 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5150 {
5151 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5152 inst.operands[i].reg = val;
5153 inst.operands[i].isscalar = 1;
5154 inst.operands[i].vectype = optype;
5155 inst.operands[i++].present = 1;
5156
5157 if (skip_past_comma (&ptr) == FAIL)
5158 goto wanted_comma;
5159
5160 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5161 goto wanted_arm;
5162
5163 inst.operands[i].reg = val;
5164 inst.operands[i].isreg = 1;
5165 inst.operands[i].present = 1;
5166 }
5167 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
5168 != FAIL)
5169 {
5170 /* Cases 0, 1, 2, 3, 5 (D only). */
5171 if (skip_past_comma (&ptr) == FAIL)
5172 goto wanted_comma;
5173
5174 inst.operands[i].reg = val;
5175 inst.operands[i].isreg = 1;
5176 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5177 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5178 inst.operands[i].isvec = 1;
5179 inst.operands[i].vectype = optype;
5180 inst.operands[i++].present = 1;
5181
5182 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5183 {
5184 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5185 Case 13: VMOV <Sd>, <Rm> */
5186 inst.operands[i].reg = val;
5187 inst.operands[i].isreg = 1;
5188 inst.operands[i].present = 1;
5189
5190 if (rtype == REG_TYPE_NQ)
5191 {
5192 first_error (_("can't use Neon quad register here"));
5193 return FAIL;
5194 }
5195 else if (rtype != REG_TYPE_VFS)
5196 {
5197 i++;
5198 if (skip_past_comma (&ptr) == FAIL)
5199 goto wanted_comma;
5200 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5201 goto wanted_arm;
5202 inst.operands[i].reg = val;
5203 inst.operands[i].isreg = 1;
5204 inst.operands[i].present = 1;
5205 }
5206 }
5207 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5208 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5209 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5210 Case 10: VMOV.F32 <Sd>, #<imm>
5211 Case 11: VMOV.F64 <Dd>, #<imm> */
5212 inst.operands[i].immisfloat = 1;
5213 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5214 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5215 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5216 ;
5217 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5218 &optype)) != FAIL)
5219 {
5220 /* Case 0: VMOV<c><q> <Qd>, <Qm>
5221 Case 1: VMOV<c><q> <Dd>, <Dm>
5222 Case 8: VMOV.F32 <Sd>, <Sm>
5223 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5224
5225 inst.operands[i].reg = val;
5226 inst.operands[i].isreg = 1;
5227 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5228 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5229 inst.operands[i].isvec = 1;
5230 inst.operands[i].vectype = optype;
5231 inst.operands[i].present = 1;
5232
5233 if (skip_past_comma (&ptr) == SUCCESS)
5234 {
5235 /* Case 15. */
5236 i++;
5237
5238 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5239 goto wanted_arm;
5240
5241 inst.operands[i].reg = val;
5242 inst.operands[i].isreg = 1;
5243 inst.operands[i++].present = 1;
5244
5245 if (skip_past_comma (&ptr) == FAIL)
5246 goto wanted_comma;
5247
5248 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5249 goto wanted_arm;
5250
5251 inst.operands[i].reg = val;
5252 inst.operands[i].isreg = 1;
5253 inst.operands[i++].present = 1;
5254 }
5255 }
5256 else
5257 {
5258 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5259 return FAIL;
5260 }
5261 }
5262 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5263 {
5264 /* Cases 6, 7. */
5265 inst.operands[i].reg = val;
5266 inst.operands[i].isreg = 1;
5267 inst.operands[i++].present = 1;
5268
5269 if (skip_past_comma (&ptr) == FAIL)
5270 goto wanted_comma;
5271
5272 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5273 {
5274 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5275 inst.operands[i].reg = val;
5276 inst.operands[i].isscalar = 1;
5277 inst.operands[i].present = 1;
5278 inst.operands[i].vectype = optype;
5279 }
5280 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5281 {
5282 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5283 inst.operands[i].reg = val;
5284 inst.operands[i].isreg = 1;
5285 inst.operands[i++].present = 1;
5286
5287 if (skip_past_comma (&ptr) == FAIL)
5288 goto wanted_comma;
5289
5290 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
5291 == FAIL)
5292 {
5293 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5294 return FAIL;
5295 }
5296
5297 inst.operands[i].reg = val;
5298 inst.operands[i].isreg = 1;
5299 inst.operands[i].isvec = 1;
5300 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5301 inst.operands[i].vectype = optype;
5302 inst.operands[i].present = 1;
5303
5304 if (rtype == REG_TYPE_VFS)
5305 {
5306 /* Case 14. */
5307 i++;
5308 if (skip_past_comma (&ptr) == FAIL)
5309 goto wanted_comma;
5310 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5311 &optype)) == FAIL)
5312 {
5313 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5314 return FAIL;
5315 }
5316 inst.operands[i].reg = val;
5317 inst.operands[i].isreg = 1;
5318 inst.operands[i].isvec = 1;
5319 inst.operands[i].issingle = 1;
5320 inst.operands[i].vectype = optype;
5321 inst.operands[i].present = 1;
5322 }
5323 }
5324 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5325 != FAIL)
5326 {
5327 /* Case 13. */
5328 inst.operands[i].reg = val;
5329 inst.operands[i].isreg = 1;
5330 inst.operands[i].isvec = 1;
5331 inst.operands[i].issingle = 1;
5332 inst.operands[i].vectype = optype;
5333 inst.operands[i++].present = 1;
5334 }
5335 }
5336 else
5337 {
5338 first_error (_("parse error"));
5339 return FAIL;
5340 }
5341
5342 /* Successfully parsed the operands. Update args. */
5343 *which_operand = i;
5344 *str = ptr;
5345 return SUCCESS;
5346
5347 wanted_comma:
5348 first_error (_("expected comma"));
5349 return FAIL;
5350
5351 wanted_arm:
5352 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5353 return FAIL;
5354 }
5355
5356 /* Matcher codes for parse_operands. */
5357 enum operand_parse_code
5358 {
5359 OP_stop, /* end of line */
5360
5361 OP_RR, /* ARM register */
5362 OP_RRnpc, /* ARM register, not r15 */
5363 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5364 OP_RRw, /* ARM register, not r15, optional trailing ! */
5365 OP_RCP, /* Coprocessor number */
5366 OP_RCN, /* Coprocessor register */
5367 OP_RF, /* FPA register */
5368 OP_RVS, /* VFP single precision register */
5369 OP_RVD, /* VFP double precision register (0..15) */
5370 OP_RND, /* Neon double precision register (0..31) */
5371 OP_RNQ, /* Neon quad precision register */
5372 OP_RVSD, /* VFP single or double precision register */
5373 OP_RNDQ, /* Neon double or quad precision register */
5374 OP_RNSDQ, /* Neon single, double or quad precision register */
5375 OP_RNSC, /* Neon scalar D[X] */
5376 OP_RVC, /* VFP control register */
5377 OP_RMF, /* Maverick F register */
5378 OP_RMD, /* Maverick D register */
5379 OP_RMFX, /* Maverick FX register */
5380 OP_RMDX, /* Maverick DX register */
5381 OP_RMAX, /* Maverick AX register */
5382 OP_RMDS, /* Maverick DSPSC register */
5383 OP_RIWR, /* iWMMXt wR register */
5384 OP_RIWC, /* iWMMXt wC register */
5385 OP_RIWG, /* iWMMXt wCG register */
5386 OP_RXA, /* XScale accumulator register */
5387
5388 OP_REGLST, /* ARM register list */
5389 OP_VRSLST, /* VFP single-precision register list */
5390 OP_VRDLST, /* VFP double-precision register list */
5391 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5392 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5393 OP_NSTRLST, /* Neon element/structure list */
5394
5395 OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */
5396 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
5397 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5398 OP_RR_RNSC, /* ARM reg or Neon scalar. */
5399 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5400 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5401 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5402 OP_VMOV, /* Neon VMOV operands. */
5403 OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */
5404 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
5405 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5406
5407 OP_I0, /* immediate zero */
5408 OP_I7, /* immediate value 0 .. 7 */
5409 OP_I15, /* 0 .. 15 */
5410 OP_I16, /* 1 .. 16 */
5411 OP_I16z, /* 0 .. 16 */
5412 OP_I31, /* 0 .. 31 */
5413 OP_I31w, /* 0 .. 31, optional trailing ! */
5414 OP_I32, /* 1 .. 32 */
5415 OP_I32z, /* 0 .. 32 */
5416 OP_I63, /* 0 .. 63 */
5417 OP_I63s, /* -64 .. 63 */
5418 OP_I64, /* 1 .. 64 */
5419 OP_I64z, /* 0 .. 64 */
5420 OP_I255, /* 0 .. 255 */
5421
5422 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5423 OP_I7b, /* 0 .. 7 */
5424 OP_I15b, /* 0 .. 15 */
5425 OP_I31b, /* 0 .. 31 */
5426
5427 OP_SH, /* shifter operand */
5428 OP_SHG, /* shifter operand with possible group relocation */
5429 OP_ADDR, /* Memory address expression (any mode) */
5430 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5431 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5432 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
5433 OP_EXP, /* arbitrary expression */
5434 OP_EXPi, /* same, with optional immediate prefix */
5435 OP_EXPr, /* same, with optional relocation suffix */
5436 OP_HALF, /* 0 .. 65535 or low/high reloc. */
5437
5438 OP_CPSF, /* CPS flags */
5439 OP_ENDI, /* Endianness specifier */
5440 OP_PSR, /* CPSR/SPSR mask for msr */
5441 OP_COND, /* conditional code */
5442 OP_TB, /* Table branch. */
5443
5444 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5445 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5446
5447 OP_RRnpc_I0, /* ARM register or literal 0 */
5448 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5449 OP_RR_EXi, /* ARM register or expression with imm prefix */
5450 OP_RF_IF, /* FPA register or immediate */
5451 OP_RIWR_RIWC, /* iWMMXt R or C reg */
5452 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
5453
5454 /* Optional operands. */
5455 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5456 OP_oI31b, /* 0 .. 31 */
5457 OP_oI32b, /* 1 .. 32 */
5458 OP_oIffffb, /* 0 .. 65535 */
5459 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5460
5461 OP_oRR, /* ARM register */
5462 OP_oRRnpc, /* ARM register, not the PC */
5463 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5464 OP_oRND, /* Optional Neon double precision register */
5465 OP_oRNQ, /* Optional Neon quad precision register */
5466 OP_oRNDQ, /* Optional Neon double or quad precision register */
5467 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
5468 OP_oSHll, /* LSL immediate */
5469 OP_oSHar, /* ASR immediate */
5470 OP_oSHllar, /* LSL or ASR immediate */
5471 OP_oROR, /* ROR 0/8/16/24 */
5472 OP_oBARRIER, /* Option argument for a barrier instruction. */
5473
5474 OP_FIRST_OPTIONAL = OP_oI7b
5475 };
5476
5477 /* Generic instruction operand parser. This does no encoding and no
5478 semantic validation; it merely squirrels values away in the inst
5479 structure. Returns SUCCESS or FAIL depending on whether the
5480 specified grammar matched. */
5481 static int
5482 parse_operands (char *str, const unsigned char *pattern)
5483 {
5484 unsigned const char *upat = pattern;
5485 char *backtrack_pos = 0;
5486 const char *backtrack_error = 0;
5487 int i, val, backtrack_index = 0;
5488 enum arm_reg_type rtype;
5489 parse_operand_result result;
5490
5491 #define po_char_or_fail(chr) do { \
5492 if (skip_past_char (&str, chr) == FAIL) \
5493 goto bad_args; \
5494 } while (0)
5495
5496 #define po_reg_or_fail(regtype) do { \
5497 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5498 &inst.operands[i].vectype); \
5499 if (val == FAIL) \
5500 { \
5501 first_error (_(reg_expected_msgs[regtype])); \
5502 goto failure; \
5503 } \
5504 inst.operands[i].reg = val; \
5505 inst.operands[i].isreg = 1; \
5506 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5507 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5508 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5509 || rtype == REG_TYPE_VFD \
5510 || rtype == REG_TYPE_NQ); \
5511 } while (0)
5512
5513 #define po_reg_or_goto(regtype, label) do { \
5514 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5515 &inst.operands[i].vectype); \
5516 if (val == FAIL) \
5517 goto label; \
5518 \
5519 inst.operands[i].reg = val; \
5520 inst.operands[i].isreg = 1; \
5521 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5522 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5523 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5524 || rtype == REG_TYPE_VFD \
5525 || rtype == REG_TYPE_NQ); \
5526 } while (0)
5527
5528 #define po_imm_or_fail(min, max, popt) do { \
5529 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5530 goto failure; \
5531 inst.operands[i].imm = val; \
5532 } while (0)
5533
5534 #define po_scalar_or_goto(elsz, label) do { \
5535 val = parse_scalar (&str, elsz, &inst.operands[i].vectype); \
5536 if (val == FAIL) \
5537 goto label; \
5538 inst.operands[i].reg = val; \
5539 inst.operands[i].isscalar = 1; \
5540 } while (0)
5541
5542 #define po_misc_or_fail(expr) do { \
5543 if (expr) \
5544 goto failure; \
5545 } while (0)
5546
5547 #define po_misc_or_fail_no_backtrack(expr) do { \
5548 result = expr; \
5549 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK)\
5550 backtrack_pos = 0; \
5551 if (result != PARSE_OPERAND_SUCCESS) \
5552 goto failure; \
5553 } while (0)
5554
5555 skip_whitespace (str);
5556
5557 for (i = 0; upat[i] != OP_stop; i++)
5558 {
5559 if (upat[i] >= OP_FIRST_OPTIONAL)
5560 {
5561 /* Remember where we are in case we need to backtrack. */
5562 assert (!backtrack_pos);
5563 backtrack_pos = str;
5564 backtrack_error = inst.error;
5565 backtrack_index = i;
5566 }
5567
5568 if (i > 0 && (i > 1 || inst.operands[0].present))
5569 po_char_or_fail (',');
5570
5571 switch (upat[i])
5572 {
5573 /* Registers */
5574 case OP_oRRnpc:
5575 case OP_RRnpc:
5576 case OP_oRR:
5577 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5578 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5579 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
5580 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
5581 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
5582 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5583 case OP_oRND:
5584 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
5585 case OP_RVC:
5586 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
5587 break;
5588 /* Also accept generic coprocessor regs for unknown registers. */
5589 coproc_reg:
5590 po_reg_or_fail (REG_TYPE_CN);
5591 break;
5592 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
5593 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
5594 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
5595 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
5596 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
5597 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
5598 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
5599 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
5600 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
5601 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5602 case OP_oRNQ:
5603 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
5604 case OP_oRNDQ:
5605 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
5606 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
5607 case OP_oRNSDQ:
5608 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5609
5610 /* Neon scalar. Using an element size of 8 means that some invalid
5611 scalars are accepted here, so deal with those in later code. */
5612 case OP_RNSC: po_scalar_or_goto (8, failure); break;
5613
5614 /* WARNING: We can expand to two operands here. This has the potential
5615 to totally confuse the backtracking mechanism! It will be OK at
5616 least as long as we don't try to use optional args as well,
5617 though. */
5618 case OP_NILO:
5619 {
5620 po_reg_or_goto (REG_TYPE_NDQ, try_imm);
5621 inst.operands[i].present = 1;
5622 i++;
5623 skip_past_comma (&str);
5624 po_reg_or_goto (REG_TYPE_NDQ, one_reg_only);
5625 break;
5626 one_reg_only:
5627 /* Optional register operand was omitted. Unfortunately, it's in
5628 operands[i-1] and we need it to be in inst.operands[i]. Fix that
5629 here (this is a bit grotty). */
5630 inst.operands[i] = inst.operands[i-1];
5631 inst.operands[i-1].present = 0;
5632 break;
5633 try_imm:
5634 /* There's a possibility of getting a 64-bit immediate here, so
5635 we need special handling. */
5636 if (parse_big_immediate (&str, i) == FAIL)
5637 {
5638 inst.error = _("immediate value is out of range");
5639 goto failure;
5640 }
5641 }
5642 break;
5643
5644 case OP_RNDQ_I0:
5645 {
5646 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
5647 break;
5648 try_imm0:
5649 po_imm_or_fail (0, 0, TRUE);
5650 }
5651 break;
5652
5653 case OP_RVSD_I0:
5654 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
5655 break;
5656
5657 case OP_RR_RNSC:
5658 {
5659 po_scalar_or_goto (8, try_rr);
5660 break;
5661 try_rr:
5662 po_reg_or_fail (REG_TYPE_RN);
5663 }
5664 break;
5665
5666 case OP_RNSDQ_RNSC:
5667 {
5668 po_scalar_or_goto (8, try_nsdq);
5669 break;
5670 try_nsdq:
5671 po_reg_or_fail (REG_TYPE_NSDQ);
5672 }
5673 break;
5674
5675 case OP_RNDQ_RNSC:
5676 {
5677 po_scalar_or_goto (8, try_ndq);
5678 break;
5679 try_ndq:
5680 po_reg_or_fail (REG_TYPE_NDQ);
5681 }
5682 break;
5683
5684 case OP_RND_RNSC:
5685 {
5686 po_scalar_or_goto (8, try_vfd);
5687 break;
5688 try_vfd:
5689 po_reg_or_fail (REG_TYPE_VFD);
5690 }
5691 break;
5692
5693 case OP_VMOV:
5694 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
5695 not careful then bad things might happen. */
5696 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
5697 break;
5698
5699 case OP_RNDQ_IMVNb:
5700 {
5701 po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm);
5702 break;
5703 try_mvnimm:
5704 /* There's a possibility of getting a 64-bit immediate here, so
5705 we need special handling. */
5706 if (parse_big_immediate (&str, i) == FAIL)
5707 {
5708 inst.error = _("immediate value is out of range");
5709 goto failure;
5710 }
5711 }
5712 break;
5713
5714 case OP_RNDQ_I63b:
5715 {
5716 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
5717 break;
5718 try_shimm:
5719 po_imm_or_fail (0, 63, TRUE);
5720 }
5721 break;
5722
5723 case OP_RRnpcb:
5724 po_char_or_fail ('[');
5725 po_reg_or_fail (REG_TYPE_RN);
5726 po_char_or_fail (']');
5727 break;
5728
5729 case OP_RRw:
5730 case OP_oRRw:
5731 po_reg_or_fail (REG_TYPE_RN);
5732 if (skip_past_char (&str, '!') == SUCCESS)
5733 inst.operands[i].writeback = 1;
5734 break;
5735
5736 /* Immediates */
5737 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
5738 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
5739 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5740 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
5741 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
5742 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5743 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
5744 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5745 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
5746 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
5747 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
5748 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
5749
5750 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
5751 case OP_oI7b:
5752 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
5753 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
5754 case OP_oI31b:
5755 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5756 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
5757 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
5758
5759 /* Immediate variants */
5760 case OP_oI255c:
5761 po_char_or_fail ('{');
5762 po_imm_or_fail (0, 255, TRUE);
5763 po_char_or_fail ('}');
5764 break;
5765
5766 case OP_I31w:
5767 /* The expression parser chokes on a trailing !, so we have
5768 to find it first and zap it. */
5769 {
5770 char *s = str;
5771 while (*s && *s != ',')
5772 s++;
5773 if (s[-1] == '!')
5774 {
5775 s[-1] = '\0';
5776 inst.operands[i].writeback = 1;
5777 }
5778 po_imm_or_fail (0, 31, TRUE);
5779 if (str == s - 1)
5780 str = s;
5781 }
5782 break;
5783
5784 /* Expressions */
5785 case OP_EXPi: EXPi:
5786 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5787 GE_OPT_PREFIX));
5788 break;
5789
5790 case OP_EXP:
5791 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5792 GE_NO_PREFIX));
5793 break;
5794
5795 case OP_EXPr: EXPr:
5796 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5797 GE_NO_PREFIX));
5798 if (inst.reloc.exp.X_op == O_symbol)
5799 {
5800 val = parse_reloc (&str);
5801 if (val == -1)
5802 {
5803 inst.error = _("unrecognized relocation suffix");
5804 goto failure;
5805 }
5806 else if (val != BFD_RELOC_UNUSED)
5807 {
5808 inst.operands[i].imm = val;
5809 inst.operands[i].hasreloc = 1;
5810 }
5811 }
5812 break;
5813
5814 /* Operand for MOVW or MOVT. */
5815 case OP_HALF:
5816 po_misc_or_fail (parse_half (&str));
5817 break;
5818
5819 /* Register or expression */
5820 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
5821 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
5822
5823 /* Register or immediate */
5824 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
5825 I0: po_imm_or_fail (0, 0, FALSE); break;
5826
5827 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
5828 IF:
5829 if (!is_immediate_prefix (*str))
5830 goto bad_args;
5831 str++;
5832 val = parse_fpa_immediate (&str);
5833 if (val == FAIL)
5834 goto failure;
5835 /* FPA immediates are encoded as registers 8-15.
5836 parse_fpa_immediate has already applied the offset. */
5837 inst.operands[i].reg = val;
5838 inst.operands[i].isreg = 1;
5839 break;
5840
5841 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
5842 I32z: po_imm_or_fail (0, 32, FALSE); break;
5843
5844 /* Two kinds of register */
5845 case OP_RIWR_RIWC:
5846 {
5847 struct reg_entry *rege = arm_reg_parse_multi (&str);
5848 if (!rege
5849 || (rege->type != REG_TYPE_MMXWR
5850 && rege->type != REG_TYPE_MMXWC
5851 && rege->type != REG_TYPE_MMXWCG))
5852 {
5853 inst.error = _("iWMMXt data or control register expected");
5854 goto failure;
5855 }
5856 inst.operands[i].reg = rege->number;
5857 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
5858 }
5859 break;
5860
5861 case OP_RIWC_RIWG:
5862 {
5863 struct reg_entry *rege = arm_reg_parse_multi (&str);
5864 if (!rege
5865 || (rege->type != REG_TYPE_MMXWC
5866 && rege->type != REG_TYPE_MMXWCG))
5867 {
5868 inst.error = _("iWMMXt control register expected");
5869 goto failure;
5870 }
5871 inst.operands[i].reg = rege->number;
5872 inst.operands[i].isreg = 1;
5873 }
5874 break;
5875
5876 /* Misc */
5877 case OP_CPSF: val = parse_cps_flags (&str); break;
5878 case OP_ENDI: val = parse_endian_specifier (&str); break;
5879 case OP_oROR: val = parse_ror (&str); break;
5880 case OP_PSR: val = parse_psr (&str); break;
5881 case OP_COND: val = parse_cond (&str); break;
5882 case OP_oBARRIER:val = parse_barrier (&str); break;
5883
5884 case OP_RVC_PSR:
5885 po_reg_or_goto (REG_TYPE_VFC, try_psr);
5886 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
5887 break;
5888 try_psr:
5889 val = parse_psr (&str);
5890 break;
5891
5892 case OP_APSR_RR:
5893 po_reg_or_goto (REG_TYPE_RN, try_apsr);
5894 break;
5895 try_apsr:
5896 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
5897 instruction). */
5898 if (strncasecmp (str, "APSR_", 5) == 0)
5899 {
5900 unsigned found = 0;
5901 str += 5;
5902 while (found < 15)
5903 switch (*str++)
5904 {
5905 case 'c': found = (found & 1) ? 16 : found | 1; break;
5906 case 'n': found = (found & 2) ? 16 : found | 2; break;
5907 case 'z': found = (found & 4) ? 16 : found | 4; break;
5908 case 'v': found = (found & 8) ? 16 : found | 8; break;
5909 default: found = 16;
5910 }
5911 if (found != 15)
5912 goto failure;
5913 inst.operands[i].isvec = 1;
5914 }
5915 else
5916 goto failure;
5917 break;
5918
5919 case OP_TB:
5920 po_misc_or_fail (parse_tb (&str));
5921 break;
5922
5923 /* Register lists */
5924 case OP_REGLST:
5925 val = parse_reg_list (&str);
5926 if (*str == '^')
5927 {
5928 inst.operands[1].writeback = 1;
5929 str++;
5930 }
5931 break;
5932
5933 case OP_VRSLST:
5934 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
5935 break;
5936
5937 case OP_VRDLST:
5938 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
5939 break;
5940
5941 case OP_VRSDLST:
5942 /* Allow Q registers too. */
5943 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5944 REGLIST_NEON_D);
5945 if (val == FAIL)
5946 {
5947 inst.error = NULL;
5948 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5949 REGLIST_VFP_S);
5950 inst.operands[i].issingle = 1;
5951 }
5952 break;
5953
5954 case OP_NRDLST:
5955 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5956 REGLIST_NEON_D);
5957 break;
5958
5959 case OP_NSTRLST:
5960 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
5961 &inst.operands[i].vectype);
5962 break;
5963
5964 /* Addressing modes */
5965 case OP_ADDR:
5966 po_misc_or_fail (parse_address (&str, i));
5967 break;
5968
5969 case OP_ADDRGLDR:
5970 po_misc_or_fail_no_backtrack (
5971 parse_address_group_reloc (&str, i, GROUP_LDR));
5972 break;
5973
5974 case OP_ADDRGLDRS:
5975 po_misc_or_fail_no_backtrack (
5976 parse_address_group_reloc (&str, i, GROUP_LDRS));
5977 break;
5978
5979 case OP_ADDRGLDC:
5980 po_misc_or_fail_no_backtrack (
5981 parse_address_group_reloc (&str, i, GROUP_LDC));
5982 break;
5983
5984 case OP_SH:
5985 po_misc_or_fail (parse_shifter_operand (&str, i));
5986 break;
5987
5988 case OP_SHG:
5989 po_misc_or_fail_no_backtrack (
5990 parse_shifter_operand_group_reloc (&str, i));
5991 break;
5992
5993 case OP_oSHll:
5994 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
5995 break;
5996
5997 case OP_oSHar:
5998 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
5999 break;
6000
6001 case OP_oSHllar:
6002 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6003 break;
6004
6005 default:
6006 as_fatal (_("unhandled operand code %d"), upat[i]);
6007 }
6008
6009 /* Various value-based sanity checks and shared operations. We
6010 do not signal immediate failures for the register constraints;
6011 this allows a syntax error to take precedence. */
6012 switch (upat[i])
6013 {
6014 case OP_oRRnpc:
6015 case OP_RRnpc:
6016 case OP_RRnpcb:
6017 case OP_RRw:
6018 case OP_oRRw:
6019 case OP_RRnpc_I0:
6020 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6021 inst.error = BAD_PC;
6022 break;
6023
6024 case OP_CPSF:
6025 case OP_ENDI:
6026 case OP_oROR:
6027 case OP_PSR:
6028 case OP_RVC_PSR:
6029 case OP_COND:
6030 case OP_oBARRIER:
6031 case OP_REGLST:
6032 case OP_VRSLST:
6033 case OP_VRDLST:
6034 case OP_VRSDLST:
6035 case OP_NRDLST:
6036 case OP_NSTRLST:
6037 if (val == FAIL)
6038 goto failure;
6039 inst.operands[i].imm = val;
6040 break;
6041
6042 default:
6043 break;
6044 }
6045
6046 /* If we get here, this operand was successfully parsed. */
6047 inst.operands[i].present = 1;
6048 continue;
6049
6050 bad_args:
6051 inst.error = BAD_ARGS;
6052
6053 failure:
6054 if (!backtrack_pos)
6055 {
6056 /* The parse routine should already have set inst.error, but set a
6057 default here just in case. */
6058 if (!inst.error)
6059 inst.error = _("syntax error");
6060 return FAIL;
6061 }
6062
6063 /* Do not backtrack over a trailing optional argument that
6064 absorbed some text. We will only fail again, with the
6065 'garbage following instruction' error message, which is
6066 probably less helpful than the current one. */
6067 if (backtrack_index == i && backtrack_pos != str
6068 && upat[i+1] == OP_stop)
6069 {
6070 if (!inst.error)
6071 inst.error = _("syntax error");
6072 return FAIL;
6073 }
6074
6075 /* Try again, skipping the optional argument at backtrack_pos. */
6076 str = backtrack_pos;
6077 inst.error = backtrack_error;
6078 inst.operands[backtrack_index].present = 0;
6079 i = backtrack_index;
6080 backtrack_pos = 0;
6081 }
6082
6083 /* Check that we have parsed all the arguments. */
6084 if (*str != '\0' && !inst.error)
6085 inst.error = _("garbage following instruction");
6086
6087 return inst.error ? FAIL : SUCCESS;
6088 }
6089
6090 #undef po_char_or_fail
6091 #undef po_reg_or_fail
6092 #undef po_reg_or_goto
6093 #undef po_imm_or_fail
6094 #undef po_scalar_or_fail
6095 \f
6096 /* Shorthand macro for instruction encoding functions issuing errors. */
6097 #define constraint(expr, err) do { \
6098 if (expr) \
6099 { \
6100 inst.error = err; \
6101 return; \
6102 } \
6103 } while (0)
6104
6105 /* Functions for operand encoding. ARM, then Thumb. */
6106
6107 #define rotate_left(v, n) (v << n | v >> (32 - n))
6108
6109 /* If VAL can be encoded in the immediate field of an ARM instruction,
6110 return the encoded form. Otherwise, return FAIL. */
6111
6112 static unsigned int
6113 encode_arm_immediate (unsigned int val)
6114 {
6115 unsigned int a, i;
6116
6117 for (i = 0; i < 32; i += 2)
6118 if ((a = rotate_left (val, i)) <= 0xff)
6119 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6120
6121 return FAIL;
6122 }
6123
6124 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6125 return the encoded form. Otherwise, return FAIL. */
6126 static unsigned int
6127 encode_thumb32_immediate (unsigned int val)
6128 {
6129 unsigned int a, i;
6130
6131 if (val <= 0xff)
6132 return val;
6133
6134 for (i = 1; i <= 24; i++)
6135 {
6136 a = val >> i;
6137 if ((val & ~(0xff << i)) == 0)
6138 return ((val >> i) & 0x7f) | ((32 - i) << 7);
6139 }
6140
6141 a = val & 0xff;
6142 if (val == ((a << 16) | a))
6143 return 0x100 | a;
6144 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6145 return 0x300 | a;
6146
6147 a = val & 0xff00;
6148 if (val == ((a << 16) | a))
6149 return 0x200 | (a >> 8);
6150
6151 return FAIL;
6152 }
6153 /* Encode a VFP SP or DP register number into inst.instruction. */
6154
6155 static void
6156 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6157 {
6158 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6159 && reg > 15)
6160 {
6161 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
6162 {
6163 if (thumb_mode)
6164 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
6165 fpu_vfp_ext_v3);
6166 else
6167 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
6168 fpu_vfp_ext_v3);
6169 }
6170 else
6171 {
6172 first_error (_("D register out of range for selected VFP version"));
6173 return;
6174 }
6175 }
6176
6177 switch (pos)
6178 {
6179 case VFP_REG_Sd:
6180 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6181 break;
6182
6183 case VFP_REG_Sn:
6184 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6185 break;
6186
6187 case VFP_REG_Sm:
6188 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6189 break;
6190
6191 case VFP_REG_Dd:
6192 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6193 break;
6194
6195 case VFP_REG_Dn:
6196 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6197 break;
6198
6199 case VFP_REG_Dm:
6200 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6201 break;
6202
6203 default:
6204 abort ();
6205 }
6206 }
6207
6208 /* Encode a <shift> in an ARM-format instruction. The immediate,
6209 if any, is handled by md_apply_fix. */
6210 static void
6211 encode_arm_shift (int i)
6212 {
6213 if (inst.operands[i].shift_kind == SHIFT_RRX)
6214 inst.instruction |= SHIFT_ROR << 5;
6215 else
6216 {
6217 inst.instruction |= inst.operands[i].shift_kind << 5;
6218 if (inst.operands[i].immisreg)
6219 {
6220 inst.instruction |= SHIFT_BY_REG;
6221 inst.instruction |= inst.operands[i].imm << 8;
6222 }
6223 else
6224 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6225 }
6226 }
6227
6228 static void
6229 encode_arm_shifter_operand (int i)
6230 {
6231 if (inst.operands[i].isreg)
6232 {
6233 inst.instruction |= inst.operands[i].reg;
6234 encode_arm_shift (i);
6235 }
6236 else
6237 inst.instruction |= INST_IMMEDIATE;
6238 }
6239
6240 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
6241 static void
6242 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
6243 {
6244 assert (inst.operands[i].isreg);
6245 inst.instruction |= inst.operands[i].reg << 16;
6246
6247 if (inst.operands[i].preind)
6248 {
6249 if (is_t)
6250 {
6251 inst.error = _("instruction does not accept preindexed addressing");
6252 return;
6253 }
6254 inst.instruction |= PRE_INDEX;
6255 if (inst.operands[i].writeback)
6256 inst.instruction |= WRITE_BACK;
6257
6258 }
6259 else if (inst.operands[i].postind)
6260 {
6261 assert (inst.operands[i].writeback);
6262 if (is_t)
6263 inst.instruction |= WRITE_BACK;
6264 }
6265 else /* unindexed - only for coprocessor */
6266 {
6267 inst.error = _("instruction does not accept unindexed addressing");
6268 return;
6269 }
6270
6271 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6272 && (((inst.instruction & 0x000f0000) >> 16)
6273 == ((inst.instruction & 0x0000f000) >> 12)))
6274 as_warn ((inst.instruction & LOAD_BIT)
6275 ? _("destination register same as write-back base")
6276 : _("source register same as write-back base"));
6277 }
6278
6279 /* inst.operands[i] was set up by parse_address. Encode it into an
6280 ARM-format mode 2 load or store instruction. If is_t is true,
6281 reject forms that cannot be used with a T instruction (i.e. not
6282 post-indexed). */
6283 static void
6284 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
6285 {
6286 encode_arm_addr_mode_common (i, is_t);
6287
6288 if (inst.operands[i].immisreg)
6289 {
6290 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6291 inst.instruction |= inst.operands[i].imm;
6292 if (!inst.operands[i].negative)
6293 inst.instruction |= INDEX_UP;
6294 if (inst.operands[i].shifted)
6295 {
6296 if (inst.operands[i].shift_kind == SHIFT_RRX)
6297 inst.instruction |= SHIFT_ROR << 5;
6298 else
6299 {
6300 inst.instruction |= inst.operands[i].shift_kind << 5;
6301 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6302 }
6303 }
6304 }
6305 else /* immediate offset in inst.reloc */
6306 {
6307 if (inst.reloc.type == BFD_RELOC_UNUSED)
6308 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
6309 }
6310 }
6311
6312 /* inst.operands[i] was set up by parse_address. Encode it into an
6313 ARM-format mode 3 load or store instruction. Reject forms that
6314 cannot be used with such instructions. If is_t is true, reject
6315 forms that cannot be used with a T instruction (i.e. not
6316 post-indexed). */
6317 static void
6318 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
6319 {
6320 if (inst.operands[i].immisreg && inst.operands[i].shifted)
6321 {
6322 inst.error = _("instruction does not accept scaled register index");
6323 return;
6324 }
6325
6326 encode_arm_addr_mode_common (i, is_t);
6327
6328 if (inst.operands[i].immisreg)
6329 {
6330 inst.instruction |= inst.operands[i].imm;
6331 if (!inst.operands[i].negative)
6332 inst.instruction |= INDEX_UP;
6333 }
6334 else /* immediate offset in inst.reloc */
6335 {
6336 inst.instruction |= HWOFFSET_IMM;
6337 if (inst.reloc.type == BFD_RELOC_UNUSED)
6338 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
6339 }
6340 }
6341
6342 /* inst.operands[i] was set up by parse_address. Encode it into an
6343 ARM-format instruction. Reject all forms which cannot be encoded
6344 into a coprocessor load/store instruction. If wb_ok is false,
6345 reject use of writeback; if unind_ok is false, reject use of
6346 unindexed addressing. If reloc_override is not 0, use it instead
6347 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6348 (in which case it is preserved). */
6349
6350 static int
6351 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
6352 {
6353 inst.instruction |= inst.operands[i].reg << 16;
6354
6355 assert (!(inst.operands[i].preind && inst.operands[i].postind));
6356
6357 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
6358 {
6359 assert (!inst.operands[i].writeback);
6360 if (!unind_ok)
6361 {
6362 inst.error = _("instruction does not support unindexed addressing");
6363 return FAIL;
6364 }
6365 inst.instruction |= inst.operands[i].imm;
6366 inst.instruction |= INDEX_UP;
6367 return SUCCESS;
6368 }
6369
6370 if (inst.operands[i].preind)
6371 inst.instruction |= PRE_INDEX;
6372
6373 if (inst.operands[i].writeback)
6374 {
6375 if (inst.operands[i].reg == REG_PC)
6376 {
6377 inst.error = _("pc may not be used with write-back");
6378 return FAIL;
6379 }
6380 if (!wb_ok)
6381 {
6382 inst.error = _("instruction does not support writeback");
6383 return FAIL;
6384 }
6385 inst.instruction |= WRITE_BACK;
6386 }
6387
6388 if (reloc_override)
6389 inst.reloc.type = reloc_override;
6390 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6391 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6392 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6393 {
6394 if (thumb_mode)
6395 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6396 else
6397 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6398 }
6399
6400 return SUCCESS;
6401 }
6402
6403 /* inst.reloc.exp describes an "=expr" load pseudo-operation.
6404 Determine whether it can be performed with a move instruction; if
6405 it can, convert inst.instruction to that move instruction and
6406 return 1; if it can't, convert inst.instruction to a literal-pool
6407 load and return 0. If this is not a valid thing to do in the
6408 current context, set inst.error and return 1.
6409
6410 inst.operands[i] describes the destination register. */
6411
6412 static int
6413 move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6414 {
6415 unsigned long tbit;
6416
6417 if (thumb_p)
6418 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6419 else
6420 tbit = LOAD_BIT;
6421
6422 if ((inst.instruction & tbit) == 0)
6423 {
6424 inst.error = _("invalid pseudo operation");
6425 return 1;
6426 }
6427 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
6428 {
6429 inst.error = _("constant expression expected");
6430 return 1;
6431 }
6432 if (inst.reloc.exp.X_op == O_constant)
6433 {
6434 if (thumb_p)
6435 {
6436 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
6437 {
6438 /* This can be done with a mov(1) instruction. */
6439 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6440 inst.instruction |= inst.reloc.exp.X_add_number;
6441 return 1;
6442 }
6443 }
6444 else
6445 {
6446 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6447 if (value != FAIL)
6448 {
6449 /* This can be done with a mov instruction. */
6450 inst.instruction &= LITERAL_MASK;
6451 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6452 inst.instruction |= value & 0xfff;
6453 return 1;
6454 }
6455
6456 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6457 if (value != FAIL)
6458 {
6459 /* This can be done with a mvn instruction. */
6460 inst.instruction &= LITERAL_MASK;
6461 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6462 inst.instruction |= value & 0xfff;
6463 return 1;
6464 }
6465 }
6466 }
6467
6468 if (add_to_lit_pool () == FAIL)
6469 {
6470 inst.error = _("literal pool insertion failed");
6471 return 1;
6472 }
6473 inst.operands[1].reg = REG_PC;
6474 inst.operands[1].isreg = 1;
6475 inst.operands[1].preind = 1;
6476 inst.reloc.pc_rel = 1;
6477 inst.reloc.type = (thumb_p
6478 ? BFD_RELOC_ARM_THUMB_OFFSET
6479 : (mode_3
6480 ? BFD_RELOC_ARM_HWLITERAL
6481 : BFD_RELOC_ARM_LITERAL));
6482 return 0;
6483 }
6484
6485 /* Functions for instruction encoding, sorted by sub-architecture.
6486 First some generics; their names are taken from the conventional
6487 bit positions for register arguments in ARM format instructions. */
6488
6489 static void
6490 do_noargs (void)
6491 {
6492 }
6493
6494 static void
6495 do_rd (void)
6496 {
6497 inst.instruction |= inst.operands[0].reg << 12;
6498 }
6499
6500 static void
6501 do_rd_rm (void)
6502 {
6503 inst.instruction |= inst.operands[0].reg << 12;
6504 inst.instruction |= inst.operands[1].reg;
6505 }
6506
6507 static void
6508 do_rd_rn (void)
6509 {
6510 inst.instruction |= inst.operands[0].reg << 12;
6511 inst.instruction |= inst.operands[1].reg << 16;
6512 }
6513
6514 static void
6515 do_rn_rd (void)
6516 {
6517 inst.instruction |= inst.operands[0].reg << 16;
6518 inst.instruction |= inst.operands[1].reg << 12;
6519 }
6520
6521 static void
6522 do_rd_rm_rn (void)
6523 {
6524 unsigned Rn = inst.operands[2].reg;
6525 /* Enforce restrictions on SWP instruction. */
6526 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6527 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6528 _("Rn must not overlap other operands"));
6529 inst.instruction |= inst.operands[0].reg << 12;
6530 inst.instruction |= inst.operands[1].reg;
6531 inst.instruction |= Rn << 16;
6532 }
6533
6534 static void
6535 do_rd_rn_rm (void)
6536 {
6537 inst.instruction |= inst.operands[0].reg << 12;
6538 inst.instruction |= inst.operands[1].reg << 16;
6539 inst.instruction |= inst.operands[2].reg;
6540 }
6541
6542 static void
6543 do_rm_rd_rn (void)
6544 {
6545 inst.instruction |= inst.operands[0].reg;
6546 inst.instruction |= inst.operands[1].reg << 12;
6547 inst.instruction |= inst.operands[2].reg << 16;
6548 }
6549
6550 static void
6551 do_imm0 (void)
6552 {
6553 inst.instruction |= inst.operands[0].imm;
6554 }
6555
6556 static void
6557 do_rd_cpaddr (void)
6558 {
6559 inst.instruction |= inst.operands[0].reg << 12;
6560 encode_arm_cp_address (1, TRUE, TRUE, 0);
6561 }
6562
6563 /* ARM instructions, in alphabetical order by function name (except
6564 that wrapper functions appear immediately after the function they
6565 wrap). */
6566
6567 /* This is a pseudo-op of the form "adr rd, label" to be converted
6568 into a relative address of the form "add rd, pc, #label-.-8". */
6569
6570 static void
6571 do_adr (void)
6572 {
6573 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
6574
6575 /* Frag hacking will turn this into a sub instruction if the offset turns
6576 out to be negative. */
6577 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
6578 inst.reloc.pc_rel = 1;
6579 inst.reloc.exp.X_add_number -= 8;
6580 }
6581
6582 /* This is a pseudo-op of the form "adrl rd, label" to be converted
6583 into a relative address of the form:
6584 add rd, pc, #low(label-.-8)"
6585 add rd, rd, #high(label-.-8)" */
6586
6587 static void
6588 do_adrl (void)
6589 {
6590 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
6591
6592 /* Frag hacking will turn this into a sub instruction if the offset turns
6593 out to be negative. */
6594 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
6595 inst.reloc.pc_rel = 1;
6596 inst.size = INSN_SIZE * 2;
6597 inst.reloc.exp.X_add_number -= 8;
6598 }
6599
6600 static void
6601 do_arit (void)
6602 {
6603 if (!inst.operands[1].present)
6604 inst.operands[1].reg = inst.operands[0].reg;
6605 inst.instruction |= inst.operands[0].reg << 12;
6606 inst.instruction |= inst.operands[1].reg << 16;
6607 encode_arm_shifter_operand (2);
6608 }
6609
6610 static void
6611 do_barrier (void)
6612 {
6613 if (inst.operands[0].present)
6614 {
6615 constraint ((inst.instruction & 0xf0) != 0x40
6616 && inst.operands[0].imm != 0xf,
6617 _("bad barrier type"));
6618 inst.instruction |= inst.operands[0].imm;
6619 }
6620 else
6621 inst.instruction |= 0xf;
6622 }
6623
6624 static void
6625 do_bfc (void)
6626 {
6627 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6628 constraint (msb > 32, _("bit-field extends past end of register"));
6629 /* The instruction encoding stores the LSB and MSB,
6630 not the LSB and width. */
6631 inst.instruction |= inst.operands[0].reg << 12;
6632 inst.instruction |= inst.operands[1].imm << 7;
6633 inst.instruction |= (msb - 1) << 16;
6634 }
6635
6636 static void
6637 do_bfi (void)
6638 {
6639 unsigned int msb;
6640
6641 /* #0 in second position is alternative syntax for bfc, which is
6642 the same instruction but with REG_PC in the Rm field. */
6643 if (!inst.operands[1].isreg)
6644 inst.operands[1].reg = REG_PC;
6645
6646 msb = inst.operands[2].imm + inst.operands[3].imm;
6647 constraint (msb > 32, _("bit-field extends past end of register"));
6648 /* The instruction encoding stores the LSB and MSB,
6649 not the LSB and width. */
6650 inst.instruction |= inst.operands[0].reg << 12;
6651 inst.instruction |= inst.operands[1].reg;
6652 inst.instruction |= inst.operands[2].imm << 7;
6653 inst.instruction |= (msb - 1) << 16;
6654 }
6655
6656 static void
6657 do_bfx (void)
6658 {
6659 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6660 _("bit-field extends past end of register"));
6661 inst.instruction |= inst.operands[0].reg << 12;
6662 inst.instruction |= inst.operands[1].reg;
6663 inst.instruction |= inst.operands[2].imm << 7;
6664 inst.instruction |= (inst.operands[3].imm - 1) << 16;
6665 }
6666
6667 /* ARM V5 breakpoint instruction (argument parse)
6668 BKPT <16 bit unsigned immediate>
6669 Instruction is not conditional.
6670 The bit pattern given in insns[] has the COND_ALWAYS condition,
6671 and it is an error if the caller tried to override that. */
6672
6673 static void
6674 do_bkpt (void)
6675 {
6676 /* Top 12 of 16 bits to bits 19:8. */
6677 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
6678
6679 /* Bottom 4 of 16 bits to bits 3:0. */
6680 inst.instruction |= inst.operands[0].imm & 0xf;
6681 }
6682
6683 static void
6684 encode_branch (int default_reloc)
6685 {
6686 if (inst.operands[0].hasreloc)
6687 {
6688 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
6689 _("the only suffix valid here is '(plt)'"));
6690 inst.reloc.type = BFD_RELOC_ARM_PLT32;
6691 }
6692 else
6693 {
6694 inst.reloc.type = default_reloc;
6695 }
6696 inst.reloc.pc_rel = 1;
6697 }
6698
6699 static void
6700 do_branch (void)
6701 {
6702 #ifdef OBJ_ELF
6703 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6704 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6705 else
6706 #endif
6707 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6708 }
6709
6710 static void
6711 do_bl (void)
6712 {
6713 #ifdef OBJ_ELF
6714 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6715 {
6716 if (inst.cond == COND_ALWAYS)
6717 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6718 else
6719 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6720 }
6721 else
6722 #endif
6723 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6724 }
6725
6726 /* ARM V5 branch-link-exchange instruction (argument parse)
6727 BLX <target_addr> ie BLX(1)
6728 BLX{<condition>} <Rm> ie BLX(2)
6729 Unfortunately, there are two different opcodes for this mnemonic.
6730 So, the insns[].value is not used, and the code here zaps values
6731 into inst.instruction.
6732 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
6733
6734 static void
6735 do_blx (void)
6736 {
6737 if (inst.operands[0].isreg)
6738 {
6739 /* Arg is a register; the opcode provided by insns[] is correct.
6740 It is not illegal to do "blx pc", just useless. */
6741 if (inst.operands[0].reg == REG_PC)
6742 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
6743
6744 inst.instruction |= inst.operands[0].reg;
6745 }
6746 else
6747 {
6748 /* Arg is an address; this instruction cannot be executed
6749 conditionally, and the opcode must be adjusted. */
6750 constraint (inst.cond != COND_ALWAYS, BAD_COND);
6751 inst.instruction = 0xfa000000;
6752 #ifdef OBJ_ELF
6753 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6754 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6755 else
6756 #endif
6757 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
6758 }
6759 }
6760
6761 static void
6762 do_bx (void)
6763 {
6764 bfd_boolean want_reloc;
6765
6766 if (inst.operands[0].reg == REG_PC)
6767 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
6768
6769 inst.instruction |= inst.operands[0].reg;
6770 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
6771 it is for ARMv4t or earlier. */
6772 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
6773 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
6774 want_reloc = TRUE;
6775
6776 #ifdef OBJ_ELF
6777 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
6778 want_reloc = FALSE;
6779 #endif
6780
6781 if (want_reloc)
6782 inst.reloc.type = BFD_RELOC_ARM_V4BX;
6783 }
6784
6785
6786 /* ARM v5TEJ. Jump to Jazelle code. */
6787
6788 static void
6789 do_bxj (void)
6790 {
6791 if (inst.operands[0].reg == REG_PC)
6792 as_tsktsk (_("use of r15 in bxj is not really useful"));
6793
6794 inst.instruction |= inst.operands[0].reg;
6795 }
6796
6797 /* Co-processor data operation:
6798 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
6799 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
6800 static void
6801 do_cdp (void)
6802 {
6803 inst.instruction |= inst.operands[0].reg << 8;
6804 inst.instruction |= inst.operands[1].imm << 20;
6805 inst.instruction |= inst.operands[2].reg << 12;
6806 inst.instruction |= inst.operands[3].reg << 16;
6807 inst.instruction |= inst.operands[4].reg;
6808 inst.instruction |= inst.operands[5].imm << 5;
6809 }
6810
6811 static void
6812 do_cmp (void)
6813 {
6814 inst.instruction |= inst.operands[0].reg << 16;
6815 encode_arm_shifter_operand (1);
6816 }
6817
6818 /* Transfer between coprocessor and ARM registers.
6819 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
6820 MRC2
6821 MCR{cond}
6822 MCR2
6823
6824 No special properties. */
6825
6826 static void
6827 do_co_reg (void)
6828 {
6829 inst.instruction |= inst.operands[0].reg << 8;
6830 inst.instruction |= inst.operands[1].imm << 21;
6831 inst.instruction |= inst.operands[2].reg << 12;
6832 inst.instruction |= inst.operands[3].reg << 16;
6833 inst.instruction |= inst.operands[4].reg;
6834 inst.instruction |= inst.operands[5].imm << 5;
6835 }
6836
6837 /* Transfer between coprocessor register and pair of ARM registers.
6838 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
6839 MCRR2
6840 MRRC{cond}
6841 MRRC2
6842
6843 Two XScale instructions are special cases of these:
6844
6845 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
6846 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
6847
6848 Result unpredictable if Rd or Rn is R15. */
6849
6850 static void
6851 do_co_reg2c (void)
6852 {
6853 inst.instruction |= inst.operands[0].reg << 8;
6854 inst.instruction |= inst.operands[1].imm << 4;
6855 inst.instruction |= inst.operands[2].reg << 12;
6856 inst.instruction |= inst.operands[3].reg << 16;
6857 inst.instruction |= inst.operands[4].reg;
6858 }
6859
6860 static void
6861 do_cpsi (void)
6862 {
6863 inst.instruction |= inst.operands[0].imm << 6;
6864 if (inst.operands[1].present)
6865 {
6866 inst.instruction |= CPSI_MMOD;
6867 inst.instruction |= inst.operands[1].imm;
6868 }
6869 }
6870
6871 static void
6872 do_dbg (void)
6873 {
6874 inst.instruction |= inst.operands[0].imm;
6875 }
6876
6877 static void
6878 do_it (void)
6879 {
6880 /* There is no IT instruction in ARM mode. We
6881 process it but do not generate code for it. */
6882 inst.size = 0;
6883 }
6884
6885 static void
6886 do_ldmstm (void)
6887 {
6888 int base_reg = inst.operands[0].reg;
6889 int range = inst.operands[1].imm;
6890
6891 inst.instruction |= base_reg << 16;
6892 inst.instruction |= range;
6893
6894 if (inst.operands[1].writeback)
6895 inst.instruction |= LDM_TYPE_2_OR_3;
6896
6897 if (inst.operands[0].writeback)
6898 {
6899 inst.instruction |= WRITE_BACK;
6900 /* Check for unpredictable uses of writeback. */
6901 if (inst.instruction & LOAD_BIT)
6902 {
6903 /* Not allowed in LDM type 2. */
6904 if ((inst.instruction & LDM_TYPE_2_OR_3)
6905 && ((range & (1 << REG_PC)) == 0))
6906 as_warn (_("writeback of base register is UNPREDICTABLE"));
6907 /* Only allowed if base reg not in list for other types. */
6908 else if (range & (1 << base_reg))
6909 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
6910 }
6911 else /* STM. */
6912 {
6913 /* Not allowed for type 2. */
6914 if (inst.instruction & LDM_TYPE_2_OR_3)
6915 as_warn (_("writeback of base register is UNPREDICTABLE"));
6916 /* Only allowed if base reg not in list, or first in list. */
6917 else if ((range & (1 << base_reg))
6918 && (range & ((1 << base_reg) - 1)))
6919 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
6920 }
6921 }
6922 }
6923
6924 /* ARMv5TE load-consecutive (argument parse)
6925 Mode is like LDRH.
6926
6927 LDRccD R, mode
6928 STRccD R, mode. */
6929
6930 static void
6931 do_ldrd (void)
6932 {
6933 constraint (inst.operands[0].reg % 2 != 0,
6934 _("first destination register must be even"));
6935 constraint (inst.operands[1].present
6936 && inst.operands[1].reg != inst.operands[0].reg + 1,
6937 _("can only load two consecutive registers"));
6938 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
6939 constraint (!inst.operands[2].isreg, _("'[' expected"));
6940
6941 if (!inst.operands[1].present)
6942 inst.operands[1].reg = inst.operands[0].reg + 1;
6943
6944 if (inst.instruction & LOAD_BIT)
6945 {
6946 /* encode_arm_addr_mode_3 will diagnose overlap between the base
6947 register and the first register written; we have to diagnose
6948 overlap between the base and the second register written here. */
6949
6950 if (inst.operands[2].reg == inst.operands[1].reg
6951 && (inst.operands[2].writeback || inst.operands[2].postind))
6952 as_warn (_("base register written back, and overlaps "
6953 "second destination register"));
6954
6955 /* For an index-register load, the index register must not overlap the
6956 destination (even if not write-back). */
6957 else if (inst.operands[2].immisreg
6958 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
6959 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
6960 as_warn (_("index register overlaps destination register"));
6961 }
6962
6963 inst.instruction |= inst.operands[0].reg << 12;
6964 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
6965 }
6966
6967 static void
6968 do_ldrex (void)
6969 {
6970 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
6971 || inst.operands[1].postind || inst.operands[1].writeback
6972 || inst.operands[1].immisreg || inst.operands[1].shifted
6973 || inst.operands[1].negative
6974 /* This can arise if the programmer has written
6975 strex rN, rM, foo
6976 or if they have mistakenly used a register name as the last
6977 operand, eg:
6978 strex rN, rM, rX
6979 It is very difficult to distinguish between these two cases
6980 because "rX" might actually be a label. ie the register
6981 name has been occluded by a symbol of the same name. So we
6982 just generate a general 'bad addressing mode' type error
6983 message and leave it up to the programmer to discover the
6984 true cause and fix their mistake. */
6985 || (inst.operands[1].reg == REG_PC),
6986 BAD_ADDR_MODE);
6987
6988 constraint (inst.reloc.exp.X_op != O_constant
6989 || inst.reloc.exp.X_add_number != 0,
6990 _("offset must be zero in ARM encoding"));
6991
6992 inst.instruction |= inst.operands[0].reg << 12;
6993 inst.instruction |= inst.operands[1].reg << 16;
6994 inst.reloc.type = BFD_RELOC_UNUSED;
6995 }
6996
6997 static void
6998 do_ldrexd (void)
6999 {
7000 constraint (inst.operands[0].reg % 2 != 0,
7001 _("even register required"));
7002 constraint (inst.operands[1].present
7003 && inst.operands[1].reg != inst.operands[0].reg + 1,
7004 _("can only load two consecutive registers"));
7005 /* If op 1 were present and equal to PC, this function wouldn't
7006 have been called in the first place. */
7007 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7008
7009 inst.instruction |= inst.operands[0].reg << 12;
7010 inst.instruction |= inst.operands[2].reg << 16;
7011 }
7012
7013 static void
7014 do_ldst (void)
7015 {
7016 inst.instruction |= inst.operands[0].reg << 12;
7017 if (!inst.operands[1].isreg)
7018 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
7019 return;
7020 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
7021 }
7022
7023 static void
7024 do_ldstt (void)
7025 {
7026 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7027 reject [Rn,...]. */
7028 if (inst.operands[1].preind)
7029 {
7030 constraint (inst.reloc.exp.X_op != O_constant
7031 || inst.reloc.exp.X_add_number != 0,
7032 _("this instruction requires a post-indexed address"));
7033
7034 inst.operands[1].preind = 0;
7035 inst.operands[1].postind = 1;
7036 inst.operands[1].writeback = 1;
7037 }
7038 inst.instruction |= inst.operands[0].reg << 12;
7039 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7040 }
7041
7042 /* Halfword and signed-byte load/store operations. */
7043
7044 static void
7045 do_ldstv4 (void)
7046 {
7047 inst.instruction |= inst.operands[0].reg << 12;
7048 if (!inst.operands[1].isreg)
7049 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
7050 return;
7051 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
7052 }
7053
7054 static void
7055 do_ldsttv4 (void)
7056 {
7057 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7058 reject [Rn,...]. */
7059 if (inst.operands[1].preind)
7060 {
7061 constraint (inst.reloc.exp.X_op != O_constant
7062 || inst.reloc.exp.X_add_number != 0,
7063 _("this instruction requires a post-indexed address"));
7064
7065 inst.operands[1].preind = 0;
7066 inst.operands[1].postind = 1;
7067 inst.operands[1].writeback = 1;
7068 }
7069 inst.instruction |= inst.operands[0].reg << 12;
7070 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7071 }
7072
7073 /* Co-processor register load/store.
7074 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7075 static void
7076 do_lstc (void)
7077 {
7078 inst.instruction |= inst.operands[0].reg << 8;
7079 inst.instruction |= inst.operands[1].reg << 12;
7080 encode_arm_cp_address (2, TRUE, TRUE, 0);
7081 }
7082
7083 static void
7084 do_mlas (void)
7085 {
7086 /* This restriction does not apply to mls (nor to mla in v6 or later). */
7087 if (inst.operands[0].reg == inst.operands[1].reg
7088 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
7089 && !(inst.instruction & 0x00400000))
7090 as_tsktsk (_("Rd and Rm should be different in mla"));
7091
7092 inst.instruction |= inst.operands[0].reg << 16;
7093 inst.instruction |= inst.operands[1].reg;
7094 inst.instruction |= inst.operands[2].reg << 8;
7095 inst.instruction |= inst.operands[3].reg << 12;
7096 }
7097
7098 static void
7099 do_mov (void)
7100 {
7101 inst.instruction |= inst.operands[0].reg << 12;
7102 encode_arm_shifter_operand (1);
7103 }
7104
7105 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7106 static void
7107 do_mov16 (void)
7108 {
7109 bfd_vma imm;
7110 bfd_boolean top;
7111
7112 top = (inst.instruction & 0x00400000) != 0;
7113 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7114 _(":lower16: not allowed this instruction"));
7115 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7116 _(":upper16: not allowed instruction"));
7117 inst.instruction |= inst.operands[0].reg << 12;
7118 if (inst.reloc.type == BFD_RELOC_UNUSED)
7119 {
7120 imm = inst.reloc.exp.X_add_number;
7121 /* The value is in two pieces: 0:11, 16:19. */
7122 inst.instruction |= (imm & 0x00000fff);
7123 inst.instruction |= (imm & 0x0000f000) << 4;
7124 }
7125 }
7126
7127 static void do_vfp_nsyn_opcode (const char *);
7128
7129 static int
7130 do_vfp_nsyn_mrs (void)
7131 {
7132 if (inst.operands[0].isvec)
7133 {
7134 if (inst.operands[1].reg != 1)
7135 first_error (_("operand 1 must be FPSCR"));
7136 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7137 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7138 do_vfp_nsyn_opcode ("fmstat");
7139 }
7140 else if (inst.operands[1].isvec)
7141 do_vfp_nsyn_opcode ("fmrx");
7142 else
7143 return FAIL;
7144
7145 return SUCCESS;
7146 }
7147
7148 static int
7149 do_vfp_nsyn_msr (void)
7150 {
7151 if (inst.operands[0].isvec)
7152 do_vfp_nsyn_opcode ("fmxr");
7153 else
7154 return FAIL;
7155
7156 return SUCCESS;
7157 }
7158
7159 static void
7160 do_mrs (void)
7161 {
7162 if (do_vfp_nsyn_mrs () == SUCCESS)
7163 return;
7164
7165 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7166 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7167 != (PSR_c|PSR_f),
7168 _("'CPSR' or 'SPSR' expected"));
7169 inst.instruction |= inst.operands[0].reg << 12;
7170 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7171 }
7172
7173 /* Two possible forms:
7174 "{C|S}PSR_<field>, Rm",
7175 "{C|S}PSR_f, #expression". */
7176
7177 static void
7178 do_msr (void)
7179 {
7180 if (do_vfp_nsyn_msr () == SUCCESS)
7181 return;
7182
7183 inst.instruction |= inst.operands[0].imm;
7184 if (inst.operands[1].isreg)
7185 inst.instruction |= inst.operands[1].reg;
7186 else
7187 {
7188 inst.instruction |= INST_IMMEDIATE;
7189 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7190 inst.reloc.pc_rel = 0;
7191 }
7192 }
7193
7194 static void
7195 do_mul (void)
7196 {
7197 if (!inst.operands[2].present)
7198 inst.operands[2].reg = inst.operands[0].reg;
7199 inst.instruction |= inst.operands[0].reg << 16;
7200 inst.instruction |= inst.operands[1].reg;
7201 inst.instruction |= inst.operands[2].reg << 8;
7202
7203 if (inst.operands[0].reg == inst.operands[1].reg
7204 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7205 as_tsktsk (_("Rd and Rm should be different in mul"));
7206 }
7207
7208 /* Long Multiply Parser
7209 UMULL RdLo, RdHi, Rm, Rs
7210 SMULL RdLo, RdHi, Rm, Rs
7211 UMLAL RdLo, RdHi, Rm, Rs
7212 SMLAL RdLo, RdHi, Rm, Rs. */
7213
7214 static void
7215 do_mull (void)
7216 {
7217 inst.instruction |= inst.operands[0].reg << 12;
7218 inst.instruction |= inst.operands[1].reg << 16;
7219 inst.instruction |= inst.operands[2].reg;
7220 inst.instruction |= inst.operands[3].reg << 8;
7221
7222 /* rdhi and rdlo must be different. */
7223 if (inst.operands[0].reg == inst.operands[1].reg)
7224 as_tsktsk (_("rdhi and rdlo must be different"));
7225
7226 /* rdhi, rdlo and rm must all be different before armv6. */
7227 if ((inst.operands[0].reg == inst.operands[2].reg
7228 || inst.operands[1].reg == inst.operands[2].reg)
7229 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7230 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7231 }
7232
7233 static void
7234 do_nop (void)
7235 {
7236 if (inst.operands[0].present)
7237 {
7238 /* Architectural NOP hints are CPSR sets with no bits selected. */
7239 inst.instruction &= 0xf0000000;
7240 inst.instruction |= 0x0320f000 + inst.operands[0].imm;
7241 }
7242 }
7243
7244 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7245 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7246 Condition defaults to COND_ALWAYS.
7247 Error if Rd, Rn or Rm are R15. */
7248
7249 static void
7250 do_pkhbt (void)
7251 {
7252 inst.instruction |= inst.operands[0].reg << 12;
7253 inst.instruction |= inst.operands[1].reg << 16;
7254 inst.instruction |= inst.operands[2].reg;
7255 if (inst.operands[3].present)
7256 encode_arm_shift (3);
7257 }
7258
7259 /* ARM V6 PKHTB (Argument Parse). */
7260
7261 static void
7262 do_pkhtb (void)
7263 {
7264 if (!inst.operands[3].present)
7265 {
7266 /* If the shift specifier is omitted, turn the instruction
7267 into pkhbt rd, rm, rn. */
7268 inst.instruction &= 0xfff00010;
7269 inst.instruction |= inst.operands[0].reg << 12;
7270 inst.instruction |= inst.operands[1].reg;
7271 inst.instruction |= inst.operands[2].reg << 16;
7272 }
7273 else
7274 {
7275 inst.instruction |= inst.operands[0].reg << 12;
7276 inst.instruction |= inst.operands[1].reg << 16;
7277 inst.instruction |= inst.operands[2].reg;
7278 encode_arm_shift (3);
7279 }
7280 }
7281
7282 /* ARMv5TE: Preload-Cache
7283
7284 PLD <addr_mode>
7285
7286 Syntactically, like LDR with B=1, W=0, L=1. */
7287
7288 static void
7289 do_pld (void)
7290 {
7291 constraint (!inst.operands[0].isreg,
7292 _("'[' expected after PLD mnemonic"));
7293 constraint (inst.operands[0].postind,
7294 _("post-indexed expression used in preload instruction"));
7295 constraint (inst.operands[0].writeback,
7296 _("writeback used in preload instruction"));
7297 constraint (!inst.operands[0].preind,
7298 _("unindexed addressing used in preload instruction"));
7299 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7300 }
7301
7302 /* ARMv7: PLI <addr_mode> */
7303 static void
7304 do_pli (void)
7305 {
7306 constraint (!inst.operands[0].isreg,
7307 _("'[' expected after PLI mnemonic"));
7308 constraint (inst.operands[0].postind,
7309 _("post-indexed expression used in preload instruction"));
7310 constraint (inst.operands[0].writeback,
7311 _("writeback used in preload instruction"));
7312 constraint (!inst.operands[0].preind,
7313 _("unindexed addressing used in preload instruction"));
7314 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7315 inst.instruction &= ~PRE_INDEX;
7316 }
7317
7318 static void
7319 do_push_pop (void)
7320 {
7321 inst.operands[1] = inst.operands[0];
7322 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7323 inst.operands[0].isreg = 1;
7324 inst.operands[0].writeback = 1;
7325 inst.operands[0].reg = REG_SP;
7326 do_ldmstm ();
7327 }
7328
7329 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7330 word at the specified address and the following word
7331 respectively.
7332 Unconditionally executed.
7333 Error if Rn is R15. */
7334
7335 static void
7336 do_rfe (void)
7337 {
7338 inst.instruction |= inst.operands[0].reg << 16;
7339 if (inst.operands[0].writeback)
7340 inst.instruction |= WRITE_BACK;
7341 }
7342
7343 /* ARM V6 ssat (argument parse). */
7344
7345 static void
7346 do_ssat (void)
7347 {
7348 inst.instruction |= inst.operands[0].reg << 12;
7349 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7350 inst.instruction |= inst.operands[2].reg;
7351
7352 if (inst.operands[3].present)
7353 encode_arm_shift (3);
7354 }
7355
7356 /* ARM V6 usat (argument parse). */
7357
7358 static void
7359 do_usat (void)
7360 {
7361 inst.instruction |= inst.operands[0].reg << 12;
7362 inst.instruction |= inst.operands[1].imm << 16;
7363 inst.instruction |= inst.operands[2].reg;
7364
7365 if (inst.operands[3].present)
7366 encode_arm_shift (3);
7367 }
7368
7369 /* ARM V6 ssat16 (argument parse). */
7370
7371 static void
7372 do_ssat16 (void)
7373 {
7374 inst.instruction |= inst.operands[0].reg << 12;
7375 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7376 inst.instruction |= inst.operands[2].reg;
7377 }
7378
7379 static void
7380 do_usat16 (void)
7381 {
7382 inst.instruction |= inst.operands[0].reg << 12;
7383 inst.instruction |= inst.operands[1].imm << 16;
7384 inst.instruction |= inst.operands[2].reg;
7385 }
7386
7387 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7388 preserving the other bits.
7389
7390 setend <endian_specifier>, where <endian_specifier> is either
7391 BE or LE. */
7392
7393 static void
7394 do_setend (void)
7395 {
7396 if (inst.operands[0].imm)
7397 inst.instruction |= 0x200;
7398 }
7399
7400 static void
7401 do_shift (void)
7402 {
7403 unsigned int Rm = (inst.operands[1].present
7404 ? inst.operands[1].reg
7405 : inst.operands[0].reg);
7406
7407 inst.instruction |= inst.operands[0].reg << 12;
7408 inst.instruction |= Rm;
7409 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
7410 {
7411 inst.instruction |= inst.operands[2].reg << 8;
7412 inst.instruction |= SHIFT_BY_REG;
7413 }
7414 else
7415 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7416 }
7417
7418 static void
7419 do_smc (void)
7420 {
7421 inst.reloc.type = BFD_RELOC_ARM_SMC;
7422 inst.reloc.pc_rel = 0;
7423 }
7424
7425 static void
7426 do_swi (void)
7427 {
7428 inst.reloc.type = BFD_RELOC_ARM_SWI;
7429 inst.reloc.pc_rel = 0;
7430 }
7431
7432 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7433 SMLAxy{cond} Rd,Rm,Rs,Rn
7434 SMLAWy{cond} Rd,Rm,Rs,Rn
7435 Error if any register is R15. */
7436
7437 static void
7438 do_smla (void)
7439 {
7440 inst.instruction |= inst.operands[0].reg << 16;
7441 inst.instruction |= inst.operands[1].reg;
7442 inst.instruction |= inst.operands[2].reg << 8;
7443 inst.instruction |= inst.operands[3].reg << 12;
7444 }
7445
7446 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7447 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7448 Error if any register is R15.
7449 Warning if Rdlo == Rdhi. */
7450
7451 static void
7452 do_smlal (void)
7453 {
7454 inst.instruction |= inst.operands[0].reg << 12;
7455 inst.instruction |= inst.operands[1].reg << 16;
7456 inst.instruction |= inst.operands[2].reg;
7457 inst.instruction |= inst.operands[3].reg << 8;
7458
7459 if (inst.operands[0].reg == inst.operands[1].reg)
7460 as_tsktsk (_("rdhi and rdlo must be different"));
7461 }
7462
7463 /* ARM V5E (El Segundo) signed-multiply (argument parse)
7464 SMULxy{cond} Rd,Rm,Rs
7465 Error if any register is R15. */
7466
7467 static void
7468 do_smul (void)
7469 {
7470 inst.instruction |= inst.operands[0].reg << 16;
7471 inst.instruction |= inst.operands[1].reg;
7472 inst.instruction |= inst.operands[2].reg << 8;
7473 }
7474
7475 /* ARM V6 srs (argument parse). The variable fields in the encoding are
7476 the same for both ARM and Thumb-2. */
7477
7478 static void
7479 do_srs (void)
7480 {
7481 int reg;
7482
7483 if (inst.operands[0].present)
7484 {
7485 reg = inst.operands[0].reg;
7486 constraint (reg != 13, _("SRS base register must be r13"));
7487 }
7488 else
7489 reg = 13;
7490
7491 inst.instruction |= reg << 16;
7492 inst.instruction |= inst.operands[1].imm;
7493 if (inst.operands[0].writeback || inst.operands[1].writeback)
7494 inst.instruction |= WRITE_BACK;
7495 }
7496
7497 /* ARM V6 strex (argument parse). */
7498
7499 static void
7500 do_strex (void)
7501 {
7502 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7503 || inst.operands[2].postind || inst.operands[2].writeback
7504 || inst.operands[2].immisreg || inst.operands[2].shifted
7505 || inst.operands[2].negative
7506 /* See comment in do_ldrex(). */
7507 || (inst.operands[2].reg == REG_PC),
7508 BAD_ADDR_MODE);
7509
7510 constraint (inst.operands[0].reg == inst.operands[1].reg
7511 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
7512
7513 constraint (inst.reloc.exp.X_op != O_constant
7514 || inst.reloc.exp.X_add_number != 0,
7515 _("offset must be zero in ARM encoding"));
7516
7517 inst.instruction |= inst.operands[0].reg << 12;
7518 inst.instruction |= inst.operands[1].reg;
7519 inst.instruction |= inst.operands[2].reg << 16;
7520 inst.reloc.type = BFD_RELOC_UNUSED;
7521 }
7522
7523 static void
7524 do_strexd (void)
7525 {
7526 constraint (inst.operands[1].reg % 2 != 0,
7527 _("even register required"));
7528 constraint (inst.operands[2].present
7529 && inst.operands[2].reg != inst.operands[1].reg + 1,
7530 _("can only store two consecutive registers"));
7531 /* If op 2 were present and equal to PC, this function wouldn't
7532 have been called in the first place. */
7533 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
7534
7535 constraint (inst.operands[0].reg == inst.operands[1].reg
7536 || inst.operands[0].reg == inst.operands[1].reg + 1
7537 || inst.operands[0].reg == inst.operands[3].reg,
7538 BAD_OVERLAP);
7539
7540 inst.instruction |= inst.operands[0].reg << 12;
7541 inst.instruction |= inst.operands[1].reg;
7542 inst.instruction |= inst.operands[3].reg << 16;
7543 }
7544
7545 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
7546 extends it to 32-bits, and adds the result to a value in another
7547 register. You can specify a rotation by 0, 8, 16, or 24 bits
7548 before extracting the 16-bit value.
7549 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
7550 Condition defaults to COND_ALWAYS.
7551 Error if any register uses R15. */
7552
7553 static void
7554 do_sxtah (void)
7555 {
7556 inst.instruction |= inst.operands[0].reg << 12;
7557 inst.instruction |= inst.operands[1].reg << 16;
7558 inst.instruction |= inst.operands[2].reg;
7559 inst.instruction |= inst.operands[3].imm << 10;
7560 }
7561
7562 /* ARM V6 SXTH.
7563
7564 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
7565 Condition defaults to COND_ALWAYS.
7566 Error if any register uses R15. */
7567
7568 static void
7569 do_sxth (void)
7570 {
7571 inst.instruction |= inst.operands[0].reg << 12;
7572 inst.instruction |= inst.operands[1].reg;
7573 inst.instruction |= inst.operands[2].imm << 10;
7574 }
7575 \f
7576 /* VFP instructions. In a logical order: SP variant first, monad
7577 before dyad, arithmetic then move then load/store. */
7578
7579 static void
7580 do_vfp_sp_monadic (void)
7581 {
7582 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7583 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
7584 }
7585
7586 static void
7587 do_vfp_sp_dyadic (void)
7588 {
7589 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7590 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7591 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
7592 }
7593
7594 static void
7595 do_vfp_sp_compare_z (void)
7596 {
7597 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7598 }
7599
7600 static void
7601 do_vfp_dp_sp_cvt (void)
7602 {
7603 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7604 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
7605 }
7606
7607 static void
7608 do_vfp_sp_dp_cvt (void)
7609 {
7610 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7611 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7612 }
7613
7614 static void
7615 do_vfp_reg_from_sp (void)
7616 {
7617 inst.instruction |= inst.operands[0].reg << 12;
7618 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7619 }
7620
7621 static void
7622 do_vfp_reg2_from_sp2 (void)
7623 {
7624 constraint (inst.operands[2].imm != 2,
7625 _("only two consecutive VFP SP registers allowed here"));
7626 inst.instruction |= inst.operands[0].reg << 12;
7627 inst.instruction |= inst.operands[1].reg << 16;
7628 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
7629 }
7630
7631 static void
7632 do_vfp_sp_from_reg (void)
7633 {
7634 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
7635 inst.instruction |= inst.operands[1].reg << 12;
7636 }
7637
7638 static void
7639 do_vfp_sp2_from_reg2 (void)
7640 {
7641 constraint (inst.operands[0].imm != 2,
7642 _("only two consecutive VFP SP registers allowed here"));
7643 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
7644 inst.instruction |= inst.operands[1].reg << 12;
7645 inst.instruction |= inst.operands[2].reg << 16;
7646 }
7647
7648 static void
7649 do_vfp_sp_ldst (void)
7650 {
7651 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7652 encode_arm_cp_address (1, FALSE, TRUE, 0);
7653 }
7654
7655 static void
7656 do_vfp_dp_ldst (void)
7657 {
7658 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7659 encode_arm_cp_address (1, FALSE, TRUE, 0);
7660 }
7661
7662
7663 static void
7664 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
7665 {
7666 if (inst.operands[0].writeback)
7667 inst.instruction |= WRITE_BACK;
7668 else
7669 constraint (ldstm_type != VFP_LDSTMIA,
7670 _("this addressing mode requires base-register writeback"));
7671 inst.instruction |= inst.operands[0].reg << 16;
7672 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
7673 inst.instruction |= inst.operands[1].imm;
7674 }
7675
7676 static void
7677 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
7678 {
7679 int count;
7680
7681 if (inst.operands[0].writeback)
7682 inst.instruction |= WRITE_BACK;
7683 else
7684 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
7685 _("this addressing mode requires base-register writeback"));
7686
7687 inst.instruction |= inst.operands[0].reg << 16;
7688 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7689
7690 count = inst.operands[1].imm << 1;
7691 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
7692 count += 1;
7693
7694 inst.instruction |= count;
7695 }
7696
7697 static void
7698 do_vfp_sp_ldstmia (void)
7699 {
7700 vfp_sp_ldstm (VFP_LDSTMIA);
7701 }
7702
7703 static void
7704 do_vfp_sp_ldstmdb (void)
7705 {
7706 vfp_sp_ldstm (VFP_LDSTMDB);
7707 }
7708
7709 static void
7710 do_vfp_dp_ldstmia (void)
7711 {
7712 vfp_dp_ldstm (VFP_LDSTMIA);
7713 }
7714
7715 static void
7716 do_vfp_dp_ldstmdb (void)
7717 {
7718 vfp_dp_ldstm (VFP_LDSTMDB);
7719 }
7720
7721 static void
7722 do_vfp_xp_ldstmia (void)
7723 {
7724 vfp_dp_ldstm (VFP_LDSTMIAX);
7725 }
7726
7727 static void
7728 do_vfp_xp_ldstmdb (void)
7729 {
7730 vfp_dp_ldstm (VFP_LDSTMDBX);
7731 }
7732
7733 static void
7734 do_vfp_dp_rd_rm (void)
7735 {
7736 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7737 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7738 }
7739
7740 static void
7741 do_vfp_dp_rn_rd (void)
7742 {
7743 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
7744 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7745 }
7746
7747 static void
7748 do_vfp_dp_rd_rn (void)
7749 {
7750 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7751 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7752 }
7753
7754 static void
7755 do_vfp_dp_rd_rn_rm (void)
7756 {
7757 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7758 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7759 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
7760 }
7761
7762 static void
7763 do_vfp_dp_rd (void)
7764 {
7765 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7766 }
7767
7768 static void
7769 do_vfp_dp_rm_rd_rn (void)
7770 {
7771 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
7772 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7773 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
7774 }
7775
7776 /* VFPv3 instructions. */
7777 static void
7778 do_vfp_sp_const (void)
7779 {
7780 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7781 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7782 inst.instruction |= (inst.operands[1].imm & 0x0f);
7783 }
7784
7785 static void
7786 do_vfp_dp_const (void)
7787 {
7788 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7789 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7790 inst.instruction |= (inst.operands[1].imm & 0x0f);
7791 }
7792
7793 static void
7794 vfp_conv (int srcsize)
7795 {
7796 unsigned immbits = srcsize - inst.operands[1].imm;
7797 inst.instruction |= (immbits & 1) << 5;
7798 inst.instruction |= (immbits >> 1);
7799 }
7800
7801 static void
7802 do_vfp_sp_conv_16 (void)
7803 {
7804 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7805 vfp_conv (16);
7806 }
7807
7808 static void
7809 do_vfp_dp_conv_16 (void)
7810 {
7811 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7812 vfp_conv (16);
7813 }
7814
7815 static void
7816 do_vfp_sp_conv_32 (void)
7817 {
7818 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7819 vfp_conv (32);
7820 }
7821
7822 static void
7823 do_vfp_dp_conv_32 (void)
7824 {
7825 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7826 vfp_conv (32);
7827 }
7828 \f
7829 /* FPA instructions. Also in a logical order. */
7830
7831 static void
7832 do_fpa_cmp (void)
7833 {
7834 inst.instruction |= inst.operands[0].reg << 16;
7835 inst.instruction |= inst.operands[1].reg;
7836 }
7837
7838 static void
7839 do_fpa_ldmstm (void)
7840 {
7841 inst.instruction |= inst.operands[0].reg << 12;
7842 switch (inst.operands[1].imm)
7843 {
7844 case 1: inst.instruction |= CP_T_X; break;
7845 case 2: inst.instruction |= CP_T_Y; break;
7846 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
7847 case 4: break;
7848 default: abort ();
7849 }
7850
7851 if (inst.instruction & (PRE_INDEX | INDEX_UP))
7852 {
7853 /* The instruction specified "ea" or "fd", so we can only accept
7854 [Rn]{!}. The instruction does not really support stacking or
7855 unstacking, so we have to emulate these by setting appropriate
7856 bits and offsets. */
7857 constraint (inst.reloc.exp.X_op != O_constant
7858 || inst.reloc.exp.X_add_number != 0,
7859 _("this instruction does not support indexing"));
7860
7861 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
7862 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
7863
7864 if (!(inst.instruction & INDEX_UP))
7865 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
7866
7867 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
7868 {
7869 inst.operands[2].preind = 0;
7870 inst.operands[2].postind = 1;
7871 }
7872 }
7873
7874 encode_arm_cp_address (2, TRUE, TRUE, 0);
7875 }
7876 \f
7877 /* iWMMXt instructions: strictly in alphabetical order. */
7878
7879 static void
7880 do_iwmmxt_tandorc (void)
7881 {
7882 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
7883 }
7884
7885 static void
7886 do_iwmmxt_textrc (void)
7887 {
7888 inst.instruction |= inst.operands[0].reg << 12;
7889 inst.instruction |= inst.operands[1].imm;
7890 }
7891
7892 static void
7893 do_iwmmxt_textrm (void)
7894 {
7895 inst.instruction |= inst.operands[0].reg << 12;
7896 inst.instruction |= inst.operands[1].reg << 16;
7897 inst.instruction |= inst.operands[2].imm;
7898 }
7899
7900 static void
7901 do_iwmmxt_tinsr (void)
7902 {
7903 inst.instruction |= inst.operands[0].reg << 16;
7904 inst.instruction |= inst.operands[1].reg << 12;
7905 inst.instruction |= inst.operands[2].imm;
7906 }
7907
7908 static void
7909 do_iwmmxt_tmia (void)
7910 {
7911 inst.instruction |= inst.operands[0].reg << 5;
7912 inst.instruction |= inst.operands[1].reg;
7913 inst.instruction |= inst.operands[2].reg << 12;
7914 }
7915
7916 static void
7917 do_iwmmxt_waligni (void)
7918 {
7919 inst.instruction |= inst.operands[0].reg << 12;
7920 inst.instruction |= inst.operands[1].reg << 16;
7921 inst.instruction |= inst.operands[2].reg;
7922 inst.instruction |= inst.operands[3].imm << 20;
7923 }
7924
7925 static void
7926 do_iwmmxt_wmerge (void)
7927 {
7928 inst.instruction |= inst.operands[0].reg << 12;
7929 inst.instruction |= inst.operands[1].reg << 16;
7930 inst.instruction |= inst.operands[2].reg;
7931 inst.instruction |= inst.operands[3].imm << 21;
7932 }
7933
7934 static void
7935 do_iwmmxt_wmov (void)
7936 {
7937 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
7938 inst.instruction |= inst.operands[0].reg << 12;
7939 inst.instruction |= inst.operands[1].reg << 16;
7940 inst.instruction |= inst.operands[1].reg;
7941 }
7942
7943 static void
7944 do_iwmmxt_wldstbh (void)
7945 {
7946 int reloc;
7947 inst.instruction |= inst.operands[0].reg << 12;
7948 if (thumb_mode)
7949 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
7950 else
7951 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
7952 encode_arm_cp_address (1, TRUE, FALSE, reloc);
7953 }
7954
7955 static void
7956 do_iwmmxt_wldstw (void)
7957 {
7958 /* RIWR_RIWC clears .isreg for a control register. */
7959 if (!inst.operands[0].isreg)
7960 {
7961 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7962 inst.instruction |= 0xf0000000;
7963 }
7964
7965 inst.instruction |= inst.operands[0].reg << 12;
7966 encode_arm_cp_address (1, TRUE, TRUE, 0);
7967 }
7968
7969 static void
7970 do_iwmmxt_wldstd (void)
7971 {
7972 inst.instruction |= inst.operands[0].reg << 12;
7973 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
7974 && inst.operands[1].immisreg)
7975 {
7976 inst.instruction &= ~0x1a000ff;
7977 inst.instruction |= (0xf << 28);
7978 if (inst.operands[1].preind)
7979 inst.instruction |= PRE_INDEX;
7980 if (!inst.operands[1].negative)
7981 inst.instruction |= INDEX_UP;
7982 if (inst.operands[1].writeback)
7983 inst.instruction |= WRITE_BACK;
7984 inst.instruction |= inst.operands[1].reg << 16;
7985 inst.instruction |= inst.reloc.exp.X_add_number << 4;
7986 inst.instruction |= inst.operands[1].imm;
7987 }
7988 else
7989 encode_arm_cp_address (1, TRUE, FALSE, 0);
7990 }
7991
7992 static void
7993 do_iwmmxt_wshufh (void)
7994 {
7995 inst.instruction |= inst.operands[0].reg << 12;
7996 inst.instruction |= inst.operands[1].reg << 16;
7997 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
7998 inst.instruction |= (inst.operands[2].imm & 0x0f);
7999 }
8000
8001 static void
8002 do_iwmmxt_wzero (void)
8003 {
8004 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8005 inst.instruction |= inst.operands[0].reg;
8006 inst.instruction |= inst.operands[0].reg << 12;
8007 inst.instruction |= inst.operands[0].reg << 16;
8008 }
8009
8010 static void
8011 do_iwmmxt_wrwrwr_or_imm5 (void)
8012 {
8013 if (inst.operands[2].isreg)
8014 do_rd_rn_rm ();
8015 else {
8016 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8017 _("immediate operand requires iWMMXt2"));
8018 do_rd_rn ();
8019 if (inst.operands[2].imm == 0)
8020 {
8021 switch ((inst.instruction >> 20) & 0xf)
8022 {
8023 case 4:
8024 case 5:
8025 case 6:
8026 case 7:
8027 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8028 inst.operands[2].imm = 16;
8029 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8030 break;
8031 case 8:
8032 case 9:
8033 case 10:
8034 case 11:
8035 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8036 inst.operands[2].imm = 32;
8037 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8038 break;
8039 case 12:
8040 case 13:
8041 case 14:
8042 case 15:
8043 {
8044 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8045 unsigned long wrn;
8046 wrn = (inst.instruction >> 16) & 0xf;
8047 inst.instruction &= 0xff0fff0f;
8048 inst.instruction |= wrn;
8049 /* Bail out here; the instruction is now assembled. */
8050 return;
8051 }
8052 }
8053 }
8054 /* Map 32 -> 0, etc. */
8055 inst.operands[2].imm &= 0x1f;
8056 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8057 }
8058 }
8059 \f
8060 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8061 operations first, then control, shift, and load/store. */
8062
8063 /* Insns like "foo X,Y,Z". */
8064
8065 static void
8066 do_mav_triple (void)
8067 {
8068 inst.instruction |= inst.operands[0].reg << 16;
8069 inst.instruction |= inst.operands[1].reg;
8070 inst.instruction |= inst.operands[2].reg << 12;
8071 }
8072
8073 /* Insns like "foo W,X,Y,Z".
8074 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
8075
8076 static void
8077 do_mav_quad (void)
8078 {
8079 inst.instruction |= inst.operands[0].reg << 5;
8080 inst.instruction |= inst.operands[1].reg << 12;
8081 inst.instruction |= inst.operands[2].reg << 16;
8082 inst.instruction |= inst.operands[3].reg;
8083 }
8084
8085 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8086 static void
8087 do_mav_dspsc (void)
8088 {
8089 inst.instruction |= inst.operands[1].reg << 12;
8090 }
8091
8092 /* Maverick shift immediate instructions.
8093 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8094 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
8095
8096 static void
8097 do_mav_shift (void)
8098 {
8099 int imm = inst.operands[2].imm;
8100
8101 inst.instruction |= inst.operands[0].reg << 12;
8102 inst.instruction |= inst.operands[1].reg << 16;
8103
8104 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8105 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8106 Bit 4 should be 0. */
8107 imm = (imm & 0xf) | ((imm & 0x70) << 1);
8108
8109 inst.instruction |= imm;
8110 }
8111 \f
8112 /* XScale instructions. Also sorted arithmetic before move. */
8113
8114 /* Xscale multiply-accumulate (argument parse)
8115 MIAcc acc0,Rm,Rs
8116 MIAPHcc acc0,Rm,Rs
8117 MIAxycc acc0,Rm,Rs. */
8118
8119 static void
8120 do_xsc_mia (void)
8121 {
8122 inst.instruction |= inst.operands[1].reg;
8123 inst.instruction |= inst.operands[2].reg << 12;
8124 }
8125
8126 /* Xscale move-accumulator-register (argument parse)
8127
8128 MARcc acc0,RdLo,RdHi. */
8129
8130 static void
8131 do_xsc_mar (void)
8132 {
8133 inst.instruction |= inst.operands[1].reg << 12;
8134 inst.instruction |= inst.operands[2].reg << 16;
8135 }
8136
8137 /* Xscale move-register-accumulator (argument parse)
8138
8139 MRAcc RdLo,RdHi,acc0. */
8140
8141 static void
8142 do_xsc_mra (void)
8143 {
8144 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8145 inst.instruction |= inst.operands[0].reg << 12;
8146 inst.instruction |= inst.operands[1].reg << 16;
8147 }
8148 \f
8149 /* Encoding functions relevant only to Thumb. */
8150
8151 /* inst.operands[i] is a shifted-register operand; encode
8152 it into inst.instruction in the format used by Thumb32. */
8153
8154 static void
8155 encode_thumb32_shifted_operand (int i)
8156 {
8157 unsigned int value = inst.reloc.exp.X_add_number;
8158 unsigned int shift = inst.operands[i].shift_kind;
8159
8160 constraint (inst.operands[i].immisreg,
8161 _("shift by register not allowed in thumb mode"));
8162 inst.instruction |= inst.operands[i].reg;
8163 if (shift == SHIFT_RRX)
8164 inst.instruction |= SHIFT_ROR << 4;
8165 else
8166 {
8167 constraint (inst.reloc.exp.X_op != O_constant,
8168 _("expression too complex"));
8169
8170 constraint (value > 32
8171 || (value == 32 && (shift == SHIFT_LSL
8172 || shift == SHIFT_ROR)),
8173 _("shift expression is too large"));
8174
8175 if (value == 0)
8176 shift = SHIFT_LSL;
8177 else if (value == 32)
8178 value = 0;
8179
8180 inst.instruction |= shift << 4;
8181 inst.instruction |= (value & 0x1c) << 10;
8182 inst.instruction |= (value & 0x03) << 6;
8183 }
8184 }
8185
8186
8187 /* inst.operands[i] was set up by parse_address. Encode it into a
8188 Thumb32 format load or store instruction. Reject forms that cannot
8189 be used with such instructions. If is_t is true, reject forms that
8190 cannot be used with a T instruction; if is_d is true, reject forms
8191 that cannot be used with a D instruction. */
8192
8193 static void
8194 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8195 {
8196 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8197
8198 constraint (!inst.operands[i].isreg,
8199 _("Instruction does not support =N addresses"));
8200
8201 inst.instruction |= inst.operands[i].reg << 16;
8202 if (inst.operands[i].immisreg)
8203 {
8204 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
8205 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8206 constraint (inst.operands[i].negative,
8207 _("Thumb does not support negative register indexing"));
8208 constraint (inst.operands[i].postind,
8209 _("Thumb does not support register post-indexing"));
8210 constraint (inst.operands[i].writeback,
8211 _("Thumb does not support register indexing with writeback"));
8212 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8213 _("Thumb supports only LSL in shifted register indexing"));
8214
8215 inst.instruction |= inst.operands[i].imm;
8216 if (inst.operands[i].shifted)
8217 {
8218 constraint (inst.reloc.exp.X_op != O_constant,
8219 _("expression too complex"));
8220 constraint (inst.reloc.exp.X_add_number < 0
8221 || inst.reloc.exp.X_add_number > 3,
8222 _("shift out of range"));
8223 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8224 }
8225 inst.reloc.type = BFD_RELOC_UNUSED;
8226 }
8227 else if (inst.operands[i].preind)
8228 {
8229 constraint (is_pc && inst.operands[i].writeback,
8230 _("cannot use writeback with PC-relative addressing"));
8231 constraint (is_t && inst.operands[i].writeback,
8232 _("cannot use writeback with this instruction"));
8233
8234 if (is_d)
8235 {
8236 inst.instruction |= 0x01000000;
8237 if (inst.operands[i].writeback)
8238 inst.instruction |= 0x00200000;
8239 }
8240 else
8241 {
8242 inst.instruction |= 0x00000c00;
8243 if (inst.operands[i].writeback)
8244 inst.instruction |= 0x00000100;
8245 }
8246 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8247 }
8248 else if (inst.operands[i].postind)
8249 {
8250 assert (inst.operands[i].writeback);
8251 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8252 constraint (is_t, _("cannot use post-indexing with this instruction"));
8253
8254 if (is_d)
8255 inst.instruction |= 0x00200000;
8256 else
8257 inst.instruction |= 0x00000900;
8258 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8259 }
8260 else /* unindexed - only for coprocessor */
8261 inst.error = _("instruction does not accept unindexed addressing");
8262 }
8263
8264 /* Table of Thumb instructions which exist in both 16- and 32-bit
8265 encodings (the latter only in post-V6T2 cores). The index is the
8266 value used in the insns table below. When there is more than one
8267 possible 16-bit encoding for the instruction, this table always
8268 holds variant (1).
8269 Also contains several pseudo-instructions used during relaxation. */
8270 #define T16_32_TAB \
8271 X(adc, 4140, eb400000), \
8272 X(adcs, 4140, eb500000), \
8273 X(add, 1c00, eb000000), \
8274 X(adds, 1c00, eb100000), \
8275 X(addi, 0000, f1000000), \
8276 X(addis, 0000, f1100000), \
8277 X(add_pc,000f, f20f0000), \
8278 X(add_sp,000d, f10d0000), \
8279 X(adr, 000f, f20f0000), \
8280 X(and, 4000, ea000000), \
8281 X(ands, 4000, ea100000), \
8282 X(asr, 1000, fa40f000), \
8283 X(asrs, 1000, fa50f000), \
8284 X(b, e000, f000b000), \
8285 X(bcond, d000, f0008000), \
8286 X(bic, 4380, ea200000), \
8287 X(bics, 4380, ea300000), \
8288 X(cmn, 42c0, eb100f00), \
8289 X(cmp, 2800, ebb00f00), \
8290 X(cpsie, b660, f3af8400), \
8291 X(cpsid, b670, f3af8600), \
8292 X(cpy, 4600, ea4f0000), \
8293 X(dec_sp,80dd, f1ad0d00), \
8294 X(eor, 4040, ea800000), \
8295 X(eors, 4040, ea900000), \
8296 X(inc_sp,00dd, f10d0d00), \
8297 X(ldmia, c800, e8900000), \
8298 X(ldr, 6800, f8500000), \
8299 X(ldrb, 7800, f8100000), \
8300 X(ldrh, 8800, f8300000), \
8301 X(ldrsb, 5600, f9100000), \
8302 X(ldrsh, 5e00, f9300000), \
8303 X(ldr_pc,4800, f85f0000), \
8304 X(ldr_pc2,4800, f85f0000), \
8305 X(ldr_sp,9800, f85d0000), \
8306 X(lsl, 0000, fa00f000), \
8307 X(lsls, 0000, fa10f000), \
8308 X(lsr, 0800, fa20f000), \
8309 X(lsrs, 0800, fa30f000), \
8310 X(mov, 2000, ea4f0000), \
8311 X(movs, 2000, ea5f0000), \
8312 X(mul, 4340, fb00f000), \
8313 X(muls, 4340, ffffffff), /* no 32b muls */ \
8314 X(mvn, 43c0, ea6f0000), \
8315 X(mvns, 43c0, ea7f0000), \
8316 X(neg, 4240, f1c00000), /* rsb #0 */ \
8317 X(negs, 4240, f1d00000), /* rsbs #0 */ \
8318 X(orr, 4300, ea400000), \
8319 X(orrs, 4300, ea500000), \
8320 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8321 X(push, b400, e92d0000), /* stmdb sp!,... */ \
8322 X(rev, ba00, fa90f080), \
8323 X(rev16, ba40, fa90f090), \
8324 X(revsh, bac0, fa90f0b0), \
8325 X(ror, 41c0, fa60f000), \
8326 X(rors, 41c0, fa70f000), \
8327 X(sbc, 4180, eb600000), \
8328 X(sbcs, 4180, eb700000), \
8329 X(stmia, c000, e8800000), \
8330 X(str, 6000, f8400000), \
8331 X(strb, 7000, f8000000), \
8332 X(strh, 8000, f8200000), \
8333 X(str_sp,9000, f84d0000), \
8334 X(sub, 1e00, eba00000), \
8335 X(subs, 1e00, ebb00000), \
8336 X(subi, 8000, f1a00000), \
8337 X(subis, 8000, f1b00000), \
8338 X(sxtb, b240, fa4ff080), \
8339 X(sxth, b200, fa0ff080), \
8340 X(tst, 4200, ea100f00), \
8341 X(uxtb, b2c0, fa5ff080), \
8342 X(uxth, b280, fa1ff080), \
8343 X(nop, bf00, f3af8000), \
8344 X(yield, bf10, f3af8001), \
8345 X(wfe, bf20, f3af8002), \
8346 X(wfi, bf30, f3af8003), \
8347 X(sev, bf40, f3af9004), /* typo, 8004? */
8348
8349 /* To catch errors in encoding functions, the codes are all offset by
8350 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8351 as 16-bit instructions. */
8352 #define X(a,b,c) T_MNEM_##a
8353 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8354 #undef X
8355
8356 #define X(a,b,c) 0x##b
8357 static const unsigned short thumb_op16[] = { T16_32_TAB };
8358 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8359 #undef X
8360
8361 #define X(a,b,c) 0x##c
8362 static const unsigned int thumb_op32[] = { T16_32_TAB };
8363 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8364 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
8365 #undef X
8366 #undef T16_32_TAB
8367
8368 /* Thumb instruction encoders, in alphabetical order. */
8369
8370 /* ADDW or SUBW. */
8371 static void
8372 do_t_add_sub_w (void)
8373 {
8374 int Rd, Rn;
8375
8376 Rd = inst.operands[0].reg;
8377 Rn = inst.operands[1].reg;
8378
8379 constraint (Rd == 15, _("PC not allowed as destination"));
8380 inst.instruction |= (Rn << 16) | (Rd << 8);
8381 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8382 }
8383
8384 /* Parse an add or subtract instruction. We get here with inst.instruction
8385 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8386
8387 static void
8388 do_t_add_sub (void)
8389 {
8390 int Rd, Rs, Rn;
8391
8392 Rd = inst.operands[0].reg;
8393 Rs = (inst.operands[1].present
8394 ? inst.operands[1].reg /* Rd, Rs, foo */
8395 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8396
8397 if (unified_syntax)
8398 {
8399 bfd_boolean flags;
8400 bfd_boolean narrow;
8401 int opcode;
8402
8403 flags = (inst.instruction == T_MNEM_adds
8404 || inst.instruction == T_MNEM_subs);
8405 if (flags)
8406 narrow = (current_it_mask == 0);
8407 else
8408 narrow = (current_it_mask != 0);
8409 if (!inst.operands[2].isreg)
8410 {
8411 int add;
8412
8413 add = (inst.instruction == T_MNEM_add
8414 || inst.instruction == T_MNEM_adds);
8415 opcode = 0;
8416 if (inst.size_req != 4)
8417 {
8418 /* Attempt to use a narrow opcode, with relaxation if
8419 appropriate. */
8420 if (Rd == REG_SP && Rs == REG_SP && !flags)
8421 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8422 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8423 opcode = T_MNEM_add_sp;
8424 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8425 opcode = T_MNEM_add_pc;
8426 else if (Rd <= 7 && Rs <= 7 && narrow)
8427 {
8428 if (flags)
8429 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8430 else
8431 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8432 }
8433 if (opcode)
8434 {
8435 inst.instruction = THUMB_OP16(opcode);
8436 inst.instruction |= (Rd << 4) | Rs;
8437 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8438 if (inst.size_req != 2)
8439 inst.relax = opcode;
8440 }
8441 else
8442 constraint (inst.size_req == 2, BAD_HIREG);
8443 }
8444 if (inst.size_req == 4
8445 || (inst.size_req != 2 && !opcode))
8446 {
8447 if (Rd == REG_PC)
8448 {
8449 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
8450 _("only SUBS PC, LR, #const allowed"));
8451 constraint (inst.reloc.exp.X_op != O_constant,
8452 _("expression too complex"));
8453 constraint (inst.reloc.exp.X_add_number < 0
8454 || inst.reloc.exp.X_add_number > 0xff,
8455 _("immediate value out of range"));
8456 inst.instruction = T2_SUBS_PC_LR
8457 | inst.reloc.exp.X_add_number;
8458 inst.reloc.type = BFD_RELOC_UNUSED;
8459 return;
8460 }
8461 else if (Rs == REG_PC)
8462 {
8463 /* Always use addw/subw. */
8464 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8465 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8466 }
8467 else
8468 {
8469 inst.instruction = THUMB_OP32 (inst.instruction);
8470 inst.instruction = (inst.instruction & 0xe1ffffff)
8471 | 0x10000000;
8472 if (flags)
8473 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8474 else
8475 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
8476 }
8477 inst.instruction |= Rd << 8;
8478 inst.instruction |= Rs << 16;
8479 }
8480 }
8481 else
8482 {
8483 Rn = inst.operands[2].reg;
8484 /* See if we can do this with a 16-bit instruction. */
8485 if (!inst.operands[2].shifted && inst.size_req != 4)
8486 {
8487 if (Rd > 7 || Rs > 7 || Rn > 7)
8488 narrow = FALSE;
8489
8490 if (narrow)
8491 {
8492 inst.instruction = ((inst.instruction == T_MNEM_adds
8493 || inst.instruction == T_MNEM_add)
8494 ? T_OPCODE_ADD_R3
8495 : T_OPCODE_SUB_R3);
8496 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8497 return;
8498 }
8499
8500 if (inst.instruction == T_MNEM_add)
8501 {
8502 if (Rd == Rs)
8503 {
8504 inst.instruction = T_OPCODE_ADD_HI;
8505 inst.instruction |= (Rd & 8) << 4;
8506 inst.instruction |= (Rd & 7);
8507 inst.instruction |= Rn << 3;
8508 return;
8509 }
8510 /* ... because addition is commutative! */
8511 else if (Rd == Rn)
8512 {
8513 inst.instruction = T_OPCODE_ADD_HI;
8514 inst.instruction |= (Rd & 8) << 4;
8515 inst.instruction |= (Rd & 7);
8516 inst.instruction |= Rs << 3;
8517 return;
8518 }
8519 }
8520 }
8521 /* If we get here, it can't be done in 16 bits. */
8522 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
8523 _("shift must be constant"));
8524 inst.instruction = THUMB_OP32 (inst.instruction);
8525 inst.instruction |= Rd << 8;
8526 inst.instruction |= Rs << 16;
8527 encode_thumb32_shifted_operand (2);
8528 }
8529 }
8530 else
8531 {
8532 constraint (inst.instruction == T_MNEM_adds
8533 || inst.instruction == T_MNEM_subs,
8534 BAD_THUMB32);
8535
8536 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
8537 {
8538 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
8539 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
8540 BAD_HIREG);
8541
8542 inst.instruction = (inst.instruction == T_MNEM_add
8543 ? 0x0000 : 0x8000);
8544 inst.instruction |= (Rd << 4) | Rs;
8545 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8546 return;
8547 }
8548
8549 Rn = inst.operands[2].reg;
8550 constraint (inst.operands[2].shifted, _("unshifted register required"));
8551
8552 /* We now have Rd, Rs, and Rn set to registers. */
8553 if (Rd > 7 || Rs > 7 || Rn > 7)
8554 {
8555 /* Can't do this for SUB. */
8556 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
8557 inst.instruction = T_OPCODE_ADD_HI;
8558 inst.instruction |= (Rd & 8) << 4;
8559 inst.instruction |= (Rd & 7);
8560 if (Rs == Rd)
8561 inst.instruction |= Rn << 3;
8562 else if (Rn == Rd)
8563 inst.instruction |= Rs << 3;
8564 else
8565 constraint (1, _("dest must overlap one source register"));
8566 }
8567 else
8568 {
8569 inst.instruction = (inst.instruction == T_MNEM_add
8570 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
8571 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8572 }
8573 }
8574 }
8575
8576 static void
8577 do_t_adr (void)
8578 {
8579 if (unified_syntax && inst.size_req == 0 && inst.operands[0].reg <= 7)
8580 {
8581 /* Defer to section relaxation. */
8582 inst.relax = inst.instruction;
8583 inst.instruction = THUMB_OP16 (inst.instruction);
8584 inst.instruction |= inst.operands[0].reg << 4;
8585 }
8586 else if (unified_syntax && inst.size_req != 2)
8587 {
8588 /* Generate a 32-bit opcode. */
8589 inst.instruction = THUMB_OP32 (inst.instruction);
8590 inst.instruction |= inst.operands[0].reg << 8;
8591 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
8592 inst.reloc.pc_rel = 1;
8593 }
8594 else
8595 {
8596 /* Generate a 16-bit opcode. */
8597 inst.instruction = THUMB_OP16 (inst.instruction);
8598 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8599 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
8600 inst.reloc.pc_rel = 1;
8601
8602 inst.instruction |= inst.operands[0].reg << 4;
8603 }
8604 }
8605
8606 /* Arithmetic instructions for which there is just one 16-bit
8607 instruction encoding, and it allows only two low registers.
8608 For maximal compatibility with ARM syntax, we allow three register
8609 operands even when Thumb-32 instructions are not available, as long
8610 as the first two are identical. For instance, both "sbc r0,r1" and
8611 "sbc r0,r0,r1" are allowed. */
8612 static void
8613 do_t_arit3 (void)
8614 {
8615 int Rd, Rs, Rn;
8616
8617 Rd = inst.operands[0].reg;
8618 Rs = (inst.operands[1].present
8619 ? inst.operands[1].reg /* Rd, Rs, foo */
8620 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8621 Rn = inst.operands[2].reg;
8622
8623 if (unified_syntax)
8624 {
8625 if (!inst.operands[2].isreg)
8626 {
8627 /* For an immediate, we always generate a 32-bit opcode;
8628 section relaxation will shrink it later if possible. */
8629 inst.instruction = THUMB_OP32 (inst.instruction);
8630 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8631 inst.instruction |= Rd << 8;
8632 inst.instruction |= Rs << 16;
8633 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8634 }
8635 else
8636 {
8637 bfd_boolean narrow;
8638
8639 /* See if we can do this with a 16-bit instruction. */
8640 if (THUMB_SETS_FLAGS (inst.instruction))
8641 narrow = current_it_mask == 0;
8642 else
8643 narrow = current_it_mask != 0;
8644
8645 if (Rd > 7 || Rn > 7 || Rs > 7)
8646 narrow = FALSE;
8647 if (inst.operands[2].shifted)
8648 narrow = FALSE;
8649 if (inst.size_req == 4)
8650 narrow = FALSE;
8651
8652 if (narrow
8653 && Rd == Rs)
8654 {
8655 inst.instruction = THUMB_OP16 (inst.instruction);
8656 inst.instruction |= Rd;
8657 inst.instruction |= Rn << 3;
8658 return;
8659 }
8660
8661 /* If we get here, it can't be done in 16 bits. */
8662 constraint (inst.operands[2].shifted
8663 && inst.operands[2].immisreg,
8664 _("shift must be constant"));
8665 inst.instruction = THUMB_OP32 (inst.instruction);
8666 inst.instruction |= Rd << 8;
8667 inst.instruction |= Rs << 16;
8668 encode_thumb32_shifted_operand (2);
8669 }
8670 }
8671 else
8672 {
8673 /* On its face this is a lie - the instruction does set the
8674 flags. However, the only supported mnemonic in this mode
8675 says it doesn't. */
8676 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
8677
8678 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8679 _("unshifted register required"));
8680 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8681 constraint (Rd != Rs,
8682 _("dest and source1 must be the same register"));
8683
8684 inst.instruction = THUMB_OP16 (inst.instruction);
8685 inst.instruction |= Rd;
8686 inst.instruction |= Rn << 3;
8687 }
8688 }
8689
8690 /* Similarly, but for instructions where the arithmetic operation is
8691 commutative, so we can allow either of them to be different from
8692 the destination operand in a 16-bit instruction. For instance, all
8693 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
8694 accepted. */
8695 static void
8696 do_t_arit3c (void)
8697 {
8698 int Rd, Rs, Rn;
8699
8700 Rd = inst.operands[0].reg;
8701 Rs = (inst.operands[1].present
8702 ? inst.operands[1].reg /* Rd, Rs, foo */
8703 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8704 Rn = inst.operands[2].reg;
8705
8706 if (unified_syntax)
8707 {
8708 if (!inst.operands[2].isreg)
8709 {
8710 /* For an immediate, we always generate a 32-bit opcode;
8711 section relaxation will shrink it later if possible. */
8712 inst.instruction = THUMB_OP32 (inst.instruction);
8713 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8714 inst.instruction |= Rd << 8;
8715 inst.instruction |= Rs << 16;
8716 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8717 }
8718 else
8719 {
8720 bfd_boolean narrow;
8721
8722 /* See if we can do this with a 16-bit instruction. */
8723 if (THUMB_SETS_FLAGS (inst.instruction))
8724 narrow = current_it_mask == 0;
8725 else
8726 narrow = current_it_mask != 0;
8727
8728 if (Rd > 7 || Rn > 7 || Rs > 7)
8729 narrow = FALSE;
8730 if (inst.operands[2].shifted)
8731 narrow = FALSE;
8732 if (inst.size_req == 4)
8733 narrow = FALSE;
8734
8735 if (narrow)
8736 {
8737 if (Rd == Rs)
8738 {
8739 inst.instruction = THUMB_OP16 (inst.instruction);
8740 inst.instruction |= Rd;
8741 inst.instruction |= Rn << 3;
8742 return;
8743 }
8744 if (Rd == Rn)
8745 {
8746 inst.instruction = THUMB_OP16 (inst.instruction);
8747 inst.instruction |= Rd;
8748 inst.instruction |= Rs << 3;
8749 return;
8750 }
8751 }
8752
8753 /* If we get here, it can't be done in 16 bits. */
8754 constraint (inst.operands[2].shifted
8755 && inst.operands[2].immisreg,
8756 _("shift must be constant"));
8757 inst.instruction = THUMB_OP32 (inst.instruction);
8758 inst.instruction |= Rd << 8;
8759 inst.instruction |= Rs << 16;
8760 encode_thumb32_shifted_operand (2);
8761 }
8762 }
8763 else
8764 {
8765 /* On its face this is a lie - the instruction does set the
8766 flags. However, the only supported mnemonic in this mode
8767 says it doesn't. */
8768 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
8769
8770 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8771 _("unshifted register required"));
8772 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8773
8774 inst.instruction = THUMB_OP16 (inst.instruction);
8775 inst.instruction |= Rd;
8776
8777 if (Rd == Rs)
8778 inst.instruction |= Rn << 3;
8779 else if (Rd == Rn)
8780 inst.instruction |= Rs << 3;
8781 else
8782 constraint (1, _("dest must overlap one source register"));
8783 }
8784 }
8785
8786 static void
8787 do_t_barrier (void)
8788 {
8789 if (inst.operands[0].present)
8790 {
8791 constraint ((inst.instruction & 0xf0) != 0x40
8792 && inst.operands[0].imm != 0xf,
8793 _("bad barrier type"));
8794 inst.instruction |= inst.operands[0].imm;
8795 }
8796 else
8797 inst.instruction |= 0xf;
8798 }
8799
8800 static void
8801 do_t_bfc (void)
8802 {
8803 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8804 constraint (msb > 32, _("bit-field extends past end of register"));
8805 /* The instruction encoding stores the LSB and MSB,
8806 not the LSB and width. */
8807 inst.instruction |= inst.operands[0].reg << 8;
8808 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
8809 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
8810 inst.instruction |= msb - 1;
8811 }
8812
8813 static void
8814 do_t_bfi (void)
8815 {
8816 unsigned int msb;
8817
8818 /* #0 in second position is alternative syntax for bfc, which is
8819 the same instruction but with REG_PC in the Rm field. */
8820 if (!inst.operands[1].isreg)
8821 inst.operands[1].reg = REG_PC;
8822
8823 msb = inst.operands[2].imm + inst.operands[3].imm;
8824 constraint (msb > 32, _("bit-field extends past end of register"));
8825 /* The instruction encoding stores the LSB and MSB,
8826 not the LSB and width. */
8827 inst.instruction |= inst.operands[0].reg << 8;
8828 inst.instruction |= inst.operands[1].reg << 16;
8829 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8830 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8831 inst.instruction |= msb - 1;
8832 }
8833
8834 static void
8835 do_t_bfx (void)
8836 {
8837 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8838 _("bit-field extends past end of register"));
8839 inst.instruction |= inst.operands[0].reg << 8;
8840 inst.instruction |= inst.operands[1].reg << 16;
8841 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8842 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8843 inst.instruction |= inst.operands[3].imm - 1;
8844 }
8845
8846 /* ARM V5 Thumb BLX (argument parse)
8847 BLX <target_addr> which is BLX(1)
8848 BLX <Rm> which is BLX(2)
8849 Unfortunately, there are two different opcodes for this mnemonic.
8850 So, the insns[].value is not used, and the code here zaps values
8851 into inst.instruction.
8852
8853 ??? How to take advantage of the additional two bits of displacement
8854 available in Thumb32 mode? Need new relocation? */
8855
8856 static void
8857 do_t_blx (void)
8858 {
8859 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8860 if (inst.operands[0].isreg)
8861 /* We have a register, so this is BLX(2). */
8862 inst.instruction |= inst.operands[0].reg << 3;
8863 else
8864 {
8865 /* No register. This must be BLX(1). */
8866 inst.instruction = 0xf000e800;
8867 #ifdef OBJ_ELF
8868 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8869 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
8870 else
8871 #endif
8872 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
8873 inst.reloc.pc_rel = 1;
8874 }
8875 }
8876
8877 static void
8878 do_t_branch (void)
8879 {
8880 int opcode;
8881 int cond;
8882
8883 if (current_it_mask)
8884 {
8885 /* Conditional branches inside IT blocks are encoded as unconditional
8886 branches. */
8887 cond = COND_ALWAYS;
8888 /* A branch must be the last instruction in an IT block. */
8889 constraint (current_it_mask != 0x10, BAD_BRANCH);
8890 }
8891 else
8892 cond = inst.cond;
8893
8894 if (cond != COND_ALWAYS)
8895 opcode = T_MNEM_bcond;
8896 else
8897 opcode = inst.instruction;
8898
8899 if (unified_syntax && inst.size_req == 4)
8900 {
8901 inst.instruction = THUMB_OP32(opcode);
8902 if (cond == COND_ALWAYS)
8903 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
8904 else
8905 {
8906 assert (cond != 0xF);
8907 inst.instruction |= cond << 22;
8908 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
8909 }
8910 }
8911 else
8912 {
8913 inst.instruction = THUMB_OP16(opcode);
8914 if (cond == COND_ALWAYS)
8915 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
8916 else
8917 {
8918 inst.instruction |= cond << 8;
8919 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
8920 }
8921 /* Allow section relaxation. */
8922 if (unified_syntax && inst.size_req != 2)
8923 inst.relax = opcode;
8924 }
8925
8926 inst.reloc.pc_rel = 1;
8927 }
8928
8929 static void
8930 do_t_bkpt (void)
8931 {
8932 constraint (inst.cond != COND_ALWAYS,
8933 _("instruction is always unconditional"));
8934 if (inst.operands[0].present)
8935 {
8936 constraint (inst.operands[0].imm > 255,
8937 _("immediate value out of range"));
8938 inst.instruction |= inst.operands[0].imm;
8939 }
8940 }
8941
8942 static void
8943 do_t_branch23 (void)
8944 {
8945 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8946 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
8947 inst.reloc.pc_rel = 1;
8948
8949 /* If the destination of the branch is a defined symbol which does not have
8950 the THUMB_FUNC attribute, then we must be calling a function which has
8951 the (interfacearm) attribute. We look for the Thumb entry point to that
8952 function and change the branch to refer to that function instead. */
8953 if ( inst.reloc.exp.X_op == O_symbol
8954 && inst.reloc.exp.X_add_symbol != NULL
8955 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8956 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8957 inst.reloc.exp.X_add_symbol =
8958 find_real_start (inst.reloc.exp.X_add_symbol);
8959 }
8960
8961 static void
8962 do_t_bx (void)
8963 {
8964 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8965 inst.instruction |= inst.operands[0].reg << 3;
8966 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
8967 should cause the alignment to be checked once it is known. This is
8968 because BX PC only works if the instruction is word aligned. */
8969 }
8970
8971 static void
8972 do_t_bxj (void)
8973 {
8974 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8975 if (inst.operands[0].reg == REG_PC)
8976 as_tsktsk (_("use of r15 in bxj is not really useful"));
8977
8978 inst.instruction |= inst.operands[0].reg << 16;
8979 }
8980
8981 static void
8982 do_t_clz (void)
8983 {
8984 inst.instruction |= inst.operands[0].reg << 8;
8985 inst.instruction |= inst.operands[1].reg << 16;
8986 inst.instruction |= inst.operands[1].reg;
8987 }
8988
8989 static void
8990 do_t_cps (void)
8991 {
8992 constraint (current_it_mask, BAD_NOT_IT);
8993 inst.instruction |= inst.operands[0].imm;
8994 }
8995
8996 static void
8997 do_t_cpsi (void)
8998 {
8999 constraint (current_it_mask, BAD_NOT_IT);
9000 if (unified_syntax
9001 && (inst.operands[1].present || inst.size_req == 4)
9002 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
9003 {
9004 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9005 inst.instruction = 0xf3af8000;
9006 inst.instruction |= imod << 9;
9007 inst.instruction |= inst.operands[0].imm << 5;
9008 if (inst.operands[1].present)
9009 inst.instruction |= 0x100 | inst.operands[1].imm;
9010 }
9011 else
9012 {
9013 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9014 && (inst.operands[0].imm & 4),
9015 _("selected processor does not support 'A' form "
9016 "of this instruction"));
9017 constraint (inst.operands[1].present || inst.size_req == 4,
9018 _("Thumb does not support the 2-argument "
9019 "form of this instruction"));
9020 inst.instruction |= inst.operands[0].imm;
9021 }
9022 }
9023
9024 /* THUMB CPY instruction (argument parse). */
9025
9026 static void
9027 do_t_cpy (void)
9028 {
9029 if (inst.size_req == 4)
9030 {
9031 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9032 inst.instruction |= inst.operands[0].reg << 8;
9033 inst.instruction |= inst.operands[1].reg;
9034 }
9035 else
9036 {
9037 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9038 inst.instruction |= (inst.operands[0].reg & 0x7);
9039 inst.instruction |= inst.operands[1].reg << 3;
9040 }
9041 }
9042
9043 static void
9044 do_t_cbz (void)
9045 {
9046 constraint (current_it_mask, BAD_NOT_IT);
9047 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9048 inst.instruction |= inst.operands[0].reg;
9049 inst.reloc.pc_rel = 1;
9050 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9051 }
9052
9053 static void
9054 do_t_dbg (void)
9055 {
9056 inst.instruction |= inst.operands[0].imm;
9057 }
9058
9059 static void
9060 do_t_div (void)
9061 {
9062 if (!inst.operands[1].present)
9063 inst.operands[1].reg = inst.operands[0].reg;
9064 inst.instruction |= inst.operands[0].reg << 8;
9065 inst.instruction |= inst.operands[1].reg << 16;
9066 inst.instruction |= inst.operands[2].reg;
9067 }
9068
9069 static void
9070 do_t_hint (void)
9071 {
9072 if (unified_syntax && inst.size_req == 4)
9073 inst.instruction = THUMB_OP32 (inst.instruction);
9074 else
9075 inst.instruction = THUMB_OP16 (inst.instruction);
9076 }
9077
9078 static void
9079 do_t_it (void)
9080 {
9081 unsigned int cond = inst.operands[0].imm;
9082
9083 constraint (current_it_mask, BAD_NOT_IT);
9084 current_it_mask = (inst.instruction & 0xf) | 0x10;
9085 current_cc = cond;
9086
9087 /* If the condition is a negative condition, invert the mask. */
9088 if ((cond & 0x1) == 0x0)
9089 {
9090 unsigned int mask = inst.instruction & 0x000f;
9091
9092 if ((mask & 0x7) == 0)
9093 /* no conversion needed */;
9094 else if ((mask & 0x3) == 0)
9095 mask ^= 0x8;
9096 else if ((mask & 0x1) == 0)
9097 mask ^= 0xC;
9098 else
9099 mask ^= 0xE;
9100
9101 inst.instruction &= 0xfff0;
9102 inst.instruction |= mask;
9103 }
9104
9105 inst.instruction |= cond << 4;
9106 }
9107
9108 /* Helper function used for both push/pop and ldm/stm. */
9109 static void
9110 encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9111 {
9112 bfd_boolean load;
9113
9114 load = (inst.instruction & (1 << 20)) != 0;
9115
9116 if (mask & (1 << 13))
9117 inst.error = _("SP not allowed in register list");
9118 if (load)
9119 {
9120 if (mask & (1 << 14)
9121 && mask & (1 << 15))
9122 inst.error = _("LR and PC should not both be in register list");
9123
9124 if ((mask & (1 << base)) != 0
9125 && writeback)
9126 as_warn (_("base register should not be in register list "
9127 "when written back"));
9128 }
9129 else
9130 {
9131 if (mask & (1 << 15))
9132 inst.error = _("PC not allowed in register list");
9133
9134 if (mask & (1 << base))
9135 as_warn (_("value stored for r%d is UNPREDICTABLE"), base);
9136 }
9137
9138 if ((mask & (mask - 1)) == 0)
9139 {
9140 /* Single register transfers implemented as str/ldr. */
9141 if (writeback)
9142 {
9143 if (inst.instruction & (1 << 23))
9144 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9145 else
9146 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9147 }
9148 else
9149 {
9150 if (inst.instruction & (1 << 23))
9151 inst.instruction = 0x00800000; /* ia -> [base] */
9152 else
9153 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9154 }
9155
9156 inst.instruction |= 0xf8400000;
9157 if (load)
9158 inst.instruction |= 0x00100000;
9159
9160 mask = ffs (mask) - 1;
9161 mask <<= 12;
9162 }
9163 else if (writeback)
9164 inst.instruction |= WRITE_BACK;
9165
9166 inst.instruction |= mask;
9167 inst.instruction |= base << 16;
9168 }
9169
9170 static void
9171 do_t_ldmstm (void)
9172 {
9173 /* This really doesn't seem worth it. */
9174 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9175 _("expression too complex"));
9176 constraint (inst.operands[1].writeback,
9177 _("Thumb load/store multiple does not support {reglist}^"));
9178
9179 if (unified_syntax)
9180 {
9181 bfd_boolean narrow;
9182 unsigned mask;
9183
9184 narrow = FALSE;
9185 /* See if we can use a 16-bit instruction. */
9186 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9187 && inst.size_req != 4
9188 && !(inst.operands[1].imm & ~0xff))
9189 {
9190 mask = 1 << inst.operands[0].reg;
9191
9192 if (inst.operands[0].reg <= 7
9193 && (inst.instruction == T_MNEM_stmia
9194 ? inst.operands[0].writeback
9195 : (inst.operands[0].writeback
9196 == !(inst.operands[1].imm & mask))))
9197 {
9198 if (inst.instruction == T_MNEM_stmia
9199 && (inst.operands[1].imm & mask)
9200 && (inst.operands[1].imm & (mask - 1)))
9201 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9202 inst.operands[0].reg);
9203
9204 inst.instruction = THUMB_OP16 (inst.instruction);
9205 inst.instruction |= inst.operands[0].reg << 8;
9206 inst.instruction |= inst.operands[1].imm;
9207 narrow = TRUE;
9208 }
9209 else if (inst.operands[0] .reg == REG_SP
9210 && inst.operands[0].writeback)
9211 {
9212 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9213 ? T_MNEM_push : T_MNEM_pop);
9214 inst.instruction |= inst.operands[1].imm;
9215 narrow = TRUE;
9216 }
9217 }
9218
9219 if (!narrow)
9220 {
9221 if (inst.instruction < 0xffff)
9222 inst.instruction = THUMB_OP32 (inst.instruction);
9223
9224 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
9225 inst.operands[0].writeback);
9226 }
9227 }
9228 else
9229 {
9230 constraint (inst.operands[0].reg > 7
9231 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
9232 constraint (inst.instruction != T_MNEM_ldmia
9233 && inst.instruction != T_MNEM_stmia,
9234 _("Thumb-2 instruction only valid in unified syntax"));
9235 if (inst.instruction == T_MNEM_stmia)
9236 {
9237 if (!inst.operands[0].writeback)
9238 as_warn (_("this instruction will write back the base register"));
9239 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9240 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9241 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9242 inst.operands[0].reg);
9243 }
9244 else
9245 {
9246 if (!inst.operands[0].writeback
9247 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9248 as_warn (_("this instruction will write back the base register"));
9249 else if (inst.operands[0].writeback
9250 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9251 as_warn (_("this instruction will not write back the base register"));
9252 }
9253
9254 inst.instruction = THUMB_OP16 (inst.instruction);
9255 inst.instruction |= inst.operands[0].reg << 8;
9256 inst.instruction |= inst.operands[1].imm;
9257 }
9258 }
9259
9260 static void
9261 do_t_ldrex (void)
9262 {
9263 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9264 || inst.operands[1].postind || inst.operands[1].writeback
9265 || inst.operands[1].immisreg || inst.operands[1].shifted
9266 || inst.operands[1].negative,
9267 BAD_ADDR_MODE);
9268
9269 inst.instruction |= inst.operands[0].reg << 12;
9270 inst.instruction |= inst.operands[1].reg << 16;
9271 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9272 }
9273
9274 static void
9275 do_t_ldrexd (void)
9276 {
9277 if (!inst.operands[1].present)
9278 {
9279 constraint (inst.operands[0].reg == REG_LR,
9280 _("r14 not allowed as first register "
9281 "when second register is omitted"));
9282 inst.operands[1].reg = inst.operands[0].reg + 1;
9283 }
9284 constraint (inst.operands[0].reg == inst.operands[1].reg,
9285 BAD_OVERLAP);
9286
9287 inst.instruction |= inst.operands[0].reg << 12;
9288 inst.instruction |= inst.operands[1].reg << 8;
9289 inst.instruction |= inst.operands[2].reg << 16;
9290 }
9291
9292 static void
9293 do_t_ldst (void)
9294 {
9295 unsigned long opcode;
9296 int Rn;
9297
9298 opcode = inst.instruction;
9299 if (unified_syntax)
9300 {
9301 if (!inst.operands[1].isreg)
9302 {
9303 if (opcode <= 0xffff)
9304 inst.instruction = THUMB_OP32 (opcode);
9305 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9306 return;
9307 }
9308 if (inst.operands[1].isreg
9309 && !inst.operands[1].writeback
9310 && !inst.operands[1].shifted && !inst.operands[1].postind
9311 && !inst.operands[1].negative && inst.operands[0].reg <= 7
9312 && opcode <= 0xffff
9313 && inst.size_req != 4)
9314 {
9315 /* Insn may have a 16-bit form. */
9316 Rn = inst.operands[1].reg;
9317 if (inst.operands[1].immisreg)
9318 {
9319 inst.instruction = THUMB_OP16 (opcode);
9320 /* [Rn, Rik] */
9321 if (Rn <= 7 && inst.operands[1].imm <= 7)
9322 goto op16;
9323 }
9324 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9325 && opcode != T_MNEM_ldrsb)
9326 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9327 || (Rn == REG_SP && opcode == T_MNEM_str))
9328 {
9329 /* [Rn, #const] */
9330 if (Rn > 7)
9331 {
9332 if (Rn == REG_PC)
9333 {
9334 if (inst.reloc.pc_rel)
9335 opcode = T_MNEM_ldr_pc2;
9336 else
9337 opcode = T_MNEM_ldr_pc;
9338 }
9339 else
9340 {
9341 if (opcode == T_MNEM_ldr)
9342 opcode = T_MNEM_ldr_sp;
9343 else
9344 opcode = T_MNEM_str_sp;
9345 }
9346 inst.instruction = inst.operands[0].reg << 8;
9347 }
9348 else
9349 {
9350 inst.instruction = inst.operands[0].reg;
9351 inst.instruction |= inst.operands[1].reg << 3;
9352 }
9353 inst.instruction |= THUMB_OP16 (opcode);
9354 if (inst.size_req == 2)
9355 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9356 else
9357 inst.relax = opcode;
9358 return;
9359 }
9360 }
9361 /* Definitely a 32-bit variant. */
9362 inst.instruction = THUMB_OP32 (opcode);
9363 inst.instruction |= inst.operands[0].reg << 12;
9364 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
9365 return;
9366 }
9367
9368 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9369
9370 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
9371 {
9372 /* Only [Rn,Rm] is acceptable. */
9373 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
9374 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
9375 || inst.operands[1].postind || inst.operands[1].shifted
9376 || inst.operands[1].negative,
9377 _("Thumb does not support this addressing mode"));
9378 inst.instruction = THUMB_OP16 (inst.instruction);
9379 goto op16;
9380 }
9381
9382 inst.instruction = THUMB_OP16 (inst.instruction);
9383 if (!inst.operands[1].isreg)
9384 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9385 return;
9386
9387 constraint (!inst.operands[1].preind
9388 || inst.operands[1].shifted
9389 || inst.operands[1].writeback,
9390 _("Thumb does not support this addressing mode"));
9391 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
9392 {
9393 constraint (inst.instruction & 0x0600,
9394 _("byte or halfword not valid for base register"));
9395 constraint (inst.operands[1].reg == REG_PC
9396 && !(inst.instruction & THUMB_LOAD_BIT),
9397 _("r15 based store not allowed"));
9398 constraint (inst.operands[1].immisreg,
9399 _("invalid base register for register offset"));
9400
9401 if (inst.operands[1].reg == REG_PC)
9402 inst.instruction = T_OPCODE_LDR_PC;
9403 else if (inst.instruction & THUMB_LOAD_BIT)
9404 inst.instruction = T_OPCODE_LDR_SP;
9405 else
9406 inst.instruction = T_OPCODE_STR_SP;
9407
9408 inst.instruction |= inst.operands[0].reg << 8;
9409 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9410 return;
9411 }
9412
9413 constraint (inst.operands[1].reg > 7, BAD_HIREG);
9414 if (!inst.operands[1].immisreg)
9415 {
9416 /* Immediate offset. */
9417 inst.instruction |= inst.operands[0].reg;
9418 inst.instruction |= inst.operands[1].reg << 3;
9419 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9420 return;
9421 }
9422
9423 /* Register offset. */
9424 constraint (inst.operands[1].imm > 7, BAD_HIREG);
9425 constraint (inst.operands[1].negative,
9426 _("Thumb does not support this addressing mode"));
9427
9428 op16:
9429 switch (inst.instruction)
9430 {
9431 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
9432 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
9433 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
9434 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
9435 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
9436 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
9437 case 0x5600 /* ldrsb */:
9438 case 0x5e00 /* ldrsh */: break;
9439 default: abort ();
9440 }
9441
9442 inst.instruction |= inst.operands[0].reg;
9443 inst.instruction |= inst.operands[1].reg << 3;
9444 inst.instruction |= inst.operands[1].imm << 6;
9445 }
9446
9447 static void
9448 do_t_ldstd (void)
9449 {
9450 if (!inst.operands[1].present)
9451 {
9452 inst.operands[1].reg = inst.operands[0].reg + 1;
9453 constraint (inst.operands[0].reg == REG_LR,
9454 _("r14 not allowed here"));
9455 }
9456 inst.instruction |= inst.operands[0].reg << 12;
9457 inst.instruction |= inst.operands[1].reg << 8;
9458 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
9459 }
9460
9461 static void
9462 do_t_ldstt (void)
9463 {
9464 inst.instruction |= inst.operands[0].reg << 12;
9465 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
9466 }
9467
9468 static void
9469 do_t_mla (void)
9470 {
9471 inst.instruction |= inst.operands[0].reg << 8;
9472 inst.instruction |= inst.operands[1].reg << 16;
9473 inst.instruction |= inst.operands[2].reg;
9474 inst.instruction |= inst.operands[3].reg << 12;
9475 }
9476
9477 static void
9478 do_t_mlal (void)
9479 {
9480 inst.instruction |= inst.operands[0].reg << 12;
9481 inst.instruction |= inst.operands[1].reg << 8;
9482 inst.instruction |= inst.operands[2].reg << 16;
9483 inst.instruction |= inst.operands[3].reg;
9484 }
9485
9486 static void
9487 do_t_mov_cmp (void)
9488 {
9489 if (unified_syntax)
9490 {
9491 int r0off = (inst.instruction == T_MNEM_mov
9492 || inst.instruction == T_MNEM_movs) ? 8 : 16;
9493 unsigned long opcode;
9494 bfd_boolean narrow;
9495 bfd_boolean low_regs;
9496
9497 low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7);
9498 opcode = inst.instruction;
9499 if (current_it_mask)
9500 narrow = opcode != T_MNEM_movs;
9501 else
9502 narrow = opcode != T_MNEM_movs || low_regs;
9503 if (inst.size_req == 4
9504 || inst.operands[1].shifted)
9505 narrow = FALSE;
9506
9507 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
9508 if (opcode == T_MNEM_movs && inst.operands[1].isreg
9509 && !inst.operands[1].shifted
9510 && inst.operands[0].reg == REG_PC
9511 && inst.operands[1].reg == REG_LR)
9512 {
9513 inst.instruction = T2_SUBS_PC_LR;
9514 return;
9515 }
9516
9517 if (!inst.operands[1].isreg)
9518 {
9519 /* Immediate operand. */
9520 if (current_it_mask == 0 && opcode == T_MNEM_mov)
9521 narrow = 0;
9522 if (low_regs && narrow)
9523 {
9524 inst.instruction = THUMB_OP16 (opcode);
9525 inst.instruction |= inst.operands[0].reg << 8;
9526 if (inst.size_req == 2)
9527 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9528 else
9529 inst.relax = opcode;
9530 }
9531 else
9532 {
9533 inst.instruction = THUMB_OP32 (inst.instruction);
9534 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9535 inst.instruction |= inst.operands[0].reg << r0off;
9536 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9537 }
9538 }
9539 else if (inst.operands[1].shifted && inst.operands[1].immisreg
9540 && (inst.instruction == T_MNEM_mov
9541 || inst.instruction == T_MNEM_movs))
9542 {
9543 /* Register shifts are encoded as separate shift instructions. */
9544 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
9545
9546 if (current_it_mask)
9547 narrow = !flags;
9548 else
9549 narrow = flags;
9550
9551 if (inst.size_req == 4)
9552 narrow = FALSE;
9553
9554 if (!low_regs || inst.operands[1].imm > 7)
9555 narrow = FALSE;
9556
9557 if (inst.operands[0].reg != inst.operands[1].reg)
9558 narrow = FALSE;
9559
9560 switch (inst.operands[1].shift_kind)
9561 {
9562 case SHIFT_LSL:
9563 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
9564 break;
9565 case SHIFT_ASR:
9566 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
9567 break;
9568 case SHIFT_LSR:
9569 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
9570 break;
9571 case SHIFT_ROR:
9572 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
9573 break;
9574 default:
9575 abort ();
9576 }
9577
9578 inst.instruction = opcode;
9579 if (narrow)
9580 {
9581 inst.instruction |= inst.operands[0].reg;
9582 inst.instruction |= inst.operands[1].imm << 3;
9583 }
9584 else
9585 {
9586 if (flags)
9587 inst.instruction |= CONDS_BIT;
9588
9589 inst.instruction |= inst.operands[0].reg << 8;
9590 inst.instruction |= inst.operands[1].reg << 16;
9591 inst.instruction |= inst.operands[1].imm;
9592 }
9593 }
9594 else if (!narrow)
9595 {
9596 /* Some mov with immediate shift have narrow variants.
9597 Register shifts are handled above. */
9598 if (low_regs && inst.operands[1].shifted
9599 && (inst.instruction == T_MNEM_mov
9600 || inst.instruction == T_MNEM_movs))
9601 {
9602 if (current_it_mask)
9603 narrow = (inst.instruction == T_MNEM_mov);
9604 else
9605 narrow = (inst.instruction == T_MNEM_movs);
9606 }
9607
9608 if (narrow)
9609 {
9610 switch (inst.operands[1].shift_kind)
9611 {
9612 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
9613 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
9614 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
9615 default: narrow = FALSE; break;
9616 }
9617 }
9618
9619 if (narrow)
9620 {
9621 inst.instruction |= inst.operands[0].reg;
9622 inst.instruction |= inst.operands[1].reg << 3;
9623 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
9624 }
9625 else
9626 {
9627 inst.instruction = THUMB_OP32 (inst.instruction);
9628 inst.instruction |= inst.operands[0].reg << r0off;
9629 encode_thumb32_shifted_operand (1);
9630 }
9631 }
9632 else
9633 switch (inst.instruction)
9634 {
9635 case T_MNEM_mov:
9636 inst.instruction = T_OPCODE_MOV_HR;
9637 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9638 inst.instruction |= (inst.operands[0].reg & 0x7);
9639 inst.instruction |= inst.operands[1].reg << 3;
9640 break;
9641
9642 case T_MNEM_movs:
9643 /* We know we have low registers at this point.
9644 Generate ADD Rd, Rs, #0. */
9645 inst.instruction = T_OPCODE_ADD_I3;
9646 inst.instruction |= inst.operands[0].reg;
9647 inst.instruction |= inst.operands[1].reg << 3;
9648 break;
9649
9650 case T_MNEM_cmp:
9651 if (low_regs)
9652 {
9653 inst.instruction = T_OPCODE_CMP_LR;
9654 inst.instruction |= inst.operands[0].reg;
9655 inst.instruction |= inst.operands[1].reg << 3;
9656 }
9657 else
9658 {
9659 inst.instruction = T_OPCODE_CMP_HR;
9660 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9661 inst.instruction |= (inst.operands[0].reg & 0x7);
9662 inst.instruction |= inst.operands[1].reg << 3;
9663 }
9664 break;
9665 }
9666 return;
9667 }
9668
9669 inst.instruction = THUMB_OP16 (inst.instruction);
9670 if (inst.operands[1].isreg)
9671 {
9672 if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8)
9673 {
9674 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
9675 since a MOV instruction produces unpredictable results. */
9676 if (inst.instruction == T_OPCODE_MOV_I8)
9677 inst.instruction = T_OPCODE_ADD_I3;
9678 else
9679 inst.instruction = T_OPCODE_CMP_LR;
9680
9681 inst.instruction |= inst.operands[0].reg;
9682 inst.instruction |= inst.operands[1].reg << 3;
9683 }
9684 else
9685 {
9686 if (inst.instruction == T_OPCODE_MOV_I8)
9687 inst.instruction = T_OPCODE_MOV_HR;
9688 else
9689 inst.instruction = T_OPCODE_CMP_HR;
9690 do_t_cpy ();
9691 }
9692 }
9693 else
9694 {
9695 constraint (inst.operands[0].reg > 7,
9696 _("only lo regs allowed with immediate"));
9697 inst.instruction |= inst.operands[0].reg << 8;
9698 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9699 }
9700 }
9701
9702 static void
9703 do_t_mov16 (void)
9704 {
9705 bfd_vma imm;
9706 bfd_boolean top;
9707
9708 top = (inst.instruction & 0x00800000) != 0;
9709 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
9710 {
9711 constraint (top, _(":lower16: not allowed this instruction"));
9712 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
9713 }
9714 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
9715 {
9716 constraint (!top, _(":upper16: not allowed this instruction"));
9717 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
9718 }
9719
9720 inst.instruction |= inst.operands[0].reg << 8;
9721 if (inst.reloc.type == BFD_RELOC_UNUSED)
9722 {
9723 imm = inst.reloc.exp.X_add_number;
9724 inst.instruction |= (imm & 0xf000) << 4;
9725 inst.instruction |= (imm & 0x0800) << 15;
9726 inst.instruction |= (imm & 0x0700) << 4;
9727 inst.instruction |= (imm & 0x00ff);
9728 }
9729 }
9730
9731 static void
9732 do_t_mvn_tst (void)
9733 {
9734 if (unified_syntax)
9735 {
9736 int r0off = (inst.instruction == T_MNEM_mvn
9737 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
9738 bfd_boolean narrow;
9739
9740 if (inst.size_req == 4
9741 || inst.instruction > 0xffff
9742 || inst.operands[1].shifted
9743 || inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9744 narrow = FALSE;
9745 else if (inst.instruction == T_MNEM_cmn)
9746 narrow = TRUE;
9747 else if (THUMB_SETS_FLAGS (inst.instruction))
9748 narrow = (current_it_mask == 0);
9749 else
9750 narrow = (current_it_mask != 0);
9751
9752 if (!inst.operands[1].isreg)
9753 {
9754 /* For an immediate, we always generate a 32-bit opcode;
9755 section relaxation will shrink it later if possible. */
9756 if (inst.instruction < 0xffff)
9757 inst.instruction = THUMB_OP32 (inst.instruction);
9758 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9759 inst.instruction |= inst.operands[0].reg << r0off;
9760 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9761 }
9762 else
9763 {
9764 /* See if we can do this with a 16-bit instruction. */
9765 if (narrow)
9766 {
9767 inst.instruction = THUMB_OP16 (inst.instruction);
9768 inst.instruction |= inst.operands[0].reg;
9769 inst.instruction |= inst.operands[1].reg << 3;
9770 }
9771 else
9772 {
9773 constraint (inst.operands[1].shifted
9774 && inst.operands[1].immisreg,
9775 _("shift must be constant"));
9776 if (inst.instruction < 0xffff)
9777 inst.instruction = THUMB_OP32 (inst.instruction);
9778 inst.instruction |= inst.operands[0].reg << r0off;
9779 encode_thumb32_shifted_operand (1);
9780 }
9781 }
9782 }
9783 else
9784 {
9785 constraint (inst.instruction > 0xffff
9786 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
9787 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
9788 _("unshifted register required"));
9789 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9790 BAD_HIREG);
9791
9792 inst.instruction = THUMB_OP16 (inst.instruction);
9793 inst.instruction |= inst.operands[0].reg;
9794 inst.instruction |= inst.operands[1].reg << 3;
9795 }
9796 }
9797
9798 static void
9799 do_t_mrs (void)
9800 {
9801 int flags;
9802
9803 if (do_vfp_nsyn_mrs () == SUCCESS)
9804 return;
9805
9806 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
9807 if (flags == 0)
9808 {
9809 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m),
9810 _("selected processor does not support "
9811 "requested special purpose register"));
9812 }
9813 else
9814 {
9815 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9816 _("selected processor does not support "
9817 "requested special purpose register %x"));
9818 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9819 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
9820 _("'CPSR' or 'SPSR' expected"));
9821 }
9822
9823 inst.instruction |= inst.operands[0].reg << 8;
9824 inst.instruction |= (flags & SPSR_BIT) >> 2;
9825 inst.instruction |= inst.operands[1].imm & 0xff;
9826 }
9827
9828 static void
9829 do_t_msr (void)
9830 {
9831 int flags;
9832
9833 if (do_vfp_nsyn_msr () == SUCCESS)
9834 return;
9835
9836 constraint (!inst.operands[1].isreg,
9837 _("Thumb encoding does not support an immediate here"));
9838 flags = inst.operands[0].imm;
9839 if (flags & ~0xff)
9840 {
9841 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9842 _("selected processor does not support "
9843 "requested special purpose register"));
9844 }
9845 else
9846 {
9847 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m),
9848 _("selected processor does not support "
9849 "requested special purpose register"));
9850 flags |= PSR_f;
9851 }
9852 inst.instruction |= (flags & SPSR_BIT) >> 2;
9853 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
9854 inst.instruction |= (flags & 0xff);
9855 inst.instruction |= inst.operands[1].reg << 16;
9856 }
9857
9858 static void
9859 do_t_mul (void)
9860 {
9861 if (!inst.operands[2].present)
9862 inst.operands[2].reg = inst.operands[0].reg;
9863
9864 /* There is no 32-bit MULS and no 16-bit MUL. */
9865 if (unified_syntax && inst.instruction == T_MNEM_mul)
9866 {
9867 inst.instruction = THUMB_OP32 (inst.instruction);
9868 inst.instruction |= inst.operands[0].reg << 8;
9869 inst.instruction |= inst.operands[1].reg << 16;
9870 inst.instruction |= inst.operands[2].reg << 0;
9871 }
9872 else
9873 {
9874 constraint (!unified_syntax
9875 && inst.instruction == T_MNEM_muls, BAD_THUMB32);
9876 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9877 BAD_HIREG);
9878
9879 inst.instruction = THUMB_OP16 (inst.instruction);
9880 inst.instruction |= inst.operands[0].reg;
9881
9882 if (inst.operands[0].reg == inst.operands[1].reg)
9883 inst.instruction |= inst.operands[2].reg << 3;
9884 else if (inst.operands[0].reg == inst.operands[2].reg)
9885 inst.instruction |= inst.operands[1].reg << 3;
9886 else
9887 constraint (1, _("dest must overlap one source register"));
9888 }
9889 }
9890
9891 static void
9892 do_t_mull (void)
9893 {
9894 inst.instruction |= inst.operands[0].reg << 12;
9895 inst.instruction |= inst.operands[1].reg << 8;
9896 inst.instruction |= inst.operands[2].reg << 16;
9897 inst.instruction |= inst.operands[3].reg;
9898
9899 if (inst.operands[0].reg == inst.operands[1].reg)
9900 as_tsktsk (_("rdhi and rdlo must be different"));
9901 }
9902
9903 static void
9904 do_t_nop (void)
9905 {
9906 if (unified_syntax)
9907 {
9908 if (inst.size_req == 4 || inst.operands[0].imm > 15)
9909 {
9910 inst.instruction = THUMB_OP32 (inst.instruction);
9911 inst.instruction |= inst.operands[0].imm;
9912 }
9913 else
9914 {
9915 inst.instruction = THUMB_OP16 (inst.instruction);
9916 inst.instruction |= inst.operands[0].imm << 4;
9917 }
9918 }
9919 else
9920 {
9921 constraint (inst.operands[0].present,
9922 _("Thumb does not support NOP with hints"));
9923 inst.instruction = 0x46c0;
9924 }
9925 }
9926
9927 static void
9928 do_t_neg (void)
9929 {
9930 if (unified_syntax)
9931 {
9932 bfd_boolean narrow;
9933
9934 if (THUMB_SETS_FLAGS (inst.instruction))
9935 narrow = (current_it_mask == 0);
9936 else
9937 narrow = (current_it_mask != 0);
9938 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9939 narrow = FALSE;
9940 if (inst.size_req == 4)
9941 narrow = FALSE;
9942
9943 if (!narrow)
9944 {
9945 inst.instruction = THUMB_OP32 (inst.instruction);
9946 inst.instruction |= inst.operands[0].reg << 8;
9947 inst.instruction |= inst.operands[1].reg << 16;
9948 }
9949 else
9950 {
9951 inst.instruction = THUMB_OP16 (inst.instruction);
9952 inst.instruction |= inst.operands[0].reg;
9953 inst.instruction |= inst.operands[1].reg << 3;
9954 }
9955 }
9956 else
9957 {
9958 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9959 BAD_HIREG);
9960 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9961
9962 inst.instruction = THUMB_OP16 (inst.instruction);
9963 inst.instruction |= inst.operands[0].reg;
9964 inst.instruction |= inst.operands[1].reg << 3;
9965 }
9966 }
9967
9968 static void
9969 do_t_pkhbt (void)
9970 {
9971 inst.instruction |= inst.operands[0].reg << 8;
9972 inst.instruction |= inst.operands[1].reg << 16;
9973 inst.instruction |= inst.operands[2].reg;
9974 if (inst.operands[3].present)
9975 {
9976 unsigned int val = inst.reloc.exp.X_add_number;
9977 constraint (inst.reloc.exp.X_op != O_constant,
9978 _("expression too complex"));
9979 inst.instruction |= (val & 0x1c) << 10;
9980 inst.instruction |= (val & 0x03) << 6;
9981 }
9982 }
9983
9984 static void
9985 do_t_pkhtb (void)
9986 {
9987 if (!inst.operands[3].present)
9988 inst.instruction &= ~0x00000020;
9989 do_t_pkhbt ();
9990 }
9991
9992 static void
9993 do_t_pld (void)
9994 {
9995 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
9996 }
9997
9998 static void
9999 do_t_push_pop (void)
10000 {
10001 unsigned mask;
10002
10003 constraint (inst.operands[0].writeback,
10004 _("push/pop do not support {reglist}^"));
10005 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10006 _("expression too complex"));
10007
10008 mask = inst.operands[0].imm;
10009 if ((mask & ~0xff) == 0)
10010 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
10011 else if ((inst.instruction == T_MNEM_push
10012 && (mask & ~0xff) == 1 << REG_LR)
10013 || (inst.instruction == T_MNEM_pop
10014 && (mask & ~0xff) == 1 << REG_PC))
10015 {
10016 inst.instruction = THUMB_OP16 (inst.instruction);
10017 inst.instruction |= THUMB_PP_PC_LR;
10018 inst.instruction |= mask & 0xff;
10019 }
10020 else if (unified_syntax)
10021 {
10022 inst.instruction = THUMB_OP32 (inst.instruction);
10023 encode_thumb2_ldmstm (13, mask, TRUE);
10024 }
10025 else
10026 {
10027 inst.error = _("invalid register list to push/pop instruction");
10028 return;
10029 }
10030 }
10031
10032 static void
10033 do_t_rbit (void)
10034 {
10035 inst.instruction |= inst.operands[0].reg << 8;
10036 inst.instruction |= inst.operands[1].reg << 16;
10037 }
10038
10039 static void
10040 do_t_rev (void)
10041 {
10042 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10043 && inst.size_req != 4)
10044 {
10045 inst.instruction = THUMB_OP16 (inst.instruction);
10046 inst.instruction |= inst.operands[0].reg;
10047 inst.instruction |= inst.operands[1].reg << 3;
10048 }
10049 else if (unified_syntax)
10050 {
10051 inst.instruction = THUMB_OP32 (inst.instruction);
10052 inst.instruction |= inst.operands[0].reg << 8;
10053 inst.instruction |= inst.operands[1].reg << 16;
10054 inst.instruction |= inst.operands[1].reg;
10055 }
10056 else
10057 inst.error = BAD_HIREG;
10058 }
10059
10060 static void
10061 do_t_rsb (void)
10062 {
10063 int Rd, Rs;
10064
10065 Rd = inst.operands[0].reg;
10066 Rs = (inst.operands[1].present
10067 ? inst.operands[1].reg /* Rd, Rs, foo */
10068 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10069
10070 inst.instruction |= Rd << 8;
10071 inst.instruction |= Rs << 16;
10072 if (!inst.operands[2].isreg)
10073 {
10074 bfd_boolean narrow;
10075
10076 if ((inst.instruction & 0x00100000) != 0)
10077 narrow = (current_it_mask == 0);
10078 else
10079 narrow = (current_it_mask != 0);
10080
10081 if (Rd > 7 || Rs > 7)
10082 narrow = FALSE;
10083
10084 if (inst.size_req == 4 || !unified_syntax)
10085 narrow = FALSE;
10086
10087 if (inst.reloc.exp.X_op != O_constant
10088 || inst.reloc.exp.X_add_number != 0)
10089 narrow = FALSE;
10090
10091 /* Turn rsb #0 into 16-bit neg. We should probably do this via
10092 relaxation, but it doesn't seem worth the hassle. */
10093 if (narrow)
10094 {
10095 inst.reloc.type = BFD_RELOC_UNUSED;
10096 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10097 inst.instruction |= Rs << 3;
10098 inst.instruction |= Rd;
10099 }
10100 else
10101 {
10102 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10103 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10104 }
10105 }
10106 else
10107 encode_thumb32_shifted_operand (2);
10108 }
10109
10110 static void
10111 do_t_setend (void)
10112 {
10113 constraint (current_it_mask, BAD_NOT_IT);
10114 if (inst.operands[0].imm)
10115 inst.instruction |= 0x8;
10116 }
10117
10118 static void
10119 do_t_shift (void)
10120 {
10121 if (!inst.operands[1].present)
10122 inst.operands[1].reg = inst.operands[0].reg;
10123
10124 if (unified_syntax)
10125 {
10126 bfd_boolean narrow;
10127 int shift_kind;
10128
10129 switch (inst.instruction)
10130 {
10131 case T_MNEM_asr:
10132 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
10133 case T_MNEM_lsl:
10134 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
10135 case T_MNEM_lsr:
10136 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
10137 case T_MNEM_ror:
10138 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
10139 default: abort ();
10140 }
10141
10142 if (THUMB_SETS_FLAGS (inst.instruction))
10143 narrow = (current_it_mask == 0);
10144 else
10145 narrow = (current_it_mask != 0);
10146 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10147 narrow = FALSE;
10148 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
10149 narrow = FALSE;
10150 if (inst.operands[2].isreg
10151 && (inst.operands[1].reg != inst.operands[0].reg
10152 || inst.operands[2].reg > 7))
10153 narrow = FALSE;
10154 if (inst.size_req == 4)
10155 narrow = FALSE;
10156
10157 if (!narrow)
10158 {
10159 if (inst.operands[2].isreg)
10160 {
10161 inst.instruction = THUMB_OP32 (inst.instruction);
10162 inst.instruction |= inst.operands[0].reg << 8;
10163 inst.instruction |= inst.operands[1].reg << 16;
10164 inst.instruction |= inst.operands[2].reg;
10165 }
10166 else
10167 {
10168 inst.operands[1].shifted = 1;
10169 inst.operands[1].shift_kind = shift_kind;
10170 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
10171 ? T_MNEM_movs : T_MNEM_mov);
10172 inst.instruction |= inst.operands[0].reg << 8;
10173 encode_thumb32_shifted_operand (1);
10174 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
10175 inst.reloc.type = BFD_RELOC_UNUSED;
10176 }
10177 }
10178 else
10179 {
10180 if (inst.operands[2].isreg)
10181 {
10182 switch (shift_kind)
10183 {
10184 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
10185 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
10186 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
10187 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
10188 default: abort ();
10189 }
10190
10191 inst.instruction |= inst.operands[0].reg;
10192 inst.instruction |= inst.operands[2].reg << 3;
10193 }
10194 else
10195 {
10196 switch (shift_kind)
10197 {
10198 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10199 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10200 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10201 default: abort ();
10202 }
10203 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10204 inst.instruction |= inst.operands[0].reg;
10205 inst.instruction |= inst.operands[1].reg << 3;
10206 }
10207 }
10208 }
10209 else
10210 {
10211 constraint (inst.operands[0].reg > 7
10212 || inst.operands[1].reg > 7, BAD_HIREG);
10213 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10214
10215 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
10216 {
10217 constraint (inst.operands[2].reg > 7, BAD_HIREG);
10218 constraint (inst.operands[0].reg != inst.operands[1].reg,
10219 _("source1 and dest must be same register"));
10220
10221 switch (inst.instruction)
10222 {
10223 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
10224 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
10225 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
10226 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
10227 default: abort ();
10228 }
10229
10230 inst.instruction |= inst.operands[0].reg;
10231 inst.instruction |= inst.operands[2].reg << 3;
10232 }
10233 else
10234 {
10235 switch (inst.instruction)
10236 {
10237 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
10238 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
10239 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
10240 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
10241 default: abort ();
10242 }
10243 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10244 inst.instruction |= inst.operands[0].reg;
10245 inst.instruction |= inst.operands[1].reg << 3;
10246 }
10247 }
10248 }
10249
10250 static void
10251 do_t_simd (void)
10252 {
10253 inst.instruction |= inst.operands[0].reg << 8;
10254 inst.instruction |= inst.operands[1].reg << 16;
10255 inst.instruction |= inst.operands[2].reg;
10256 }
10257
10258 static void
10259 do_t_smc (void)
10260 {
10261 unsigned int value = inst.reloc.exp.X_add_number;
10262 constraint (inst.reloc.exp.X_op != O_constant,
10263 _("expression too complex"));
10264 inst.reloc.type = BFD_RELOC_UNUSED;
10265 inst.instruction |= (value & 0xf000) >> 12;
10266 inst.instruction |= (value & 0x0ff0);
10267 inst.instruction |= (value & 0x000f) << 16;
10268 }
10269
10270 static void
10271 do_t_ssat (void)
10272 {
10273 inst.instruction |= inst.operands[0].reg << 8;
10274 inst.instruction |= inst.operands[1].imm - 1;
10275 inst.instruction |= inst.operands[2].reg << 16;
10276
10277 if (inst.operands[3].present)
10278 {
10279 constraint (inst.reloc.exp.X_op != O_constant,
10280 _("expression too complex"));
10281
10282 if (inst.reloc.exp.X_add_number != 0)
10283 {
10284 if (inst.operands[3].shift_kind == SHIFT_ASR)
10285 inst.instruction |= 0x00200000; /* sh bit */
10286 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10287 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10288 }
10289 inst.reloc.type = BFD_RELOC_UNUSED;
10290 }
10291 }
10292
10293 static void
10294 do_t_ssat16 (void)
10295 {
10296 inst.instruction |= inst.operands[0].reg << 8;
10297 inst.instruction |= inst.operands[1].imm - 1;
10298 inst.instruction |= inst.operands[2].reg << 16;
10299 }
10300
10301 static void
10302 do_t_strex (void)
10303 {
10304 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10305 || inst.operands[2].postind || inst.operands[2].writeback
10306 || inst.operands[2].immisreg || inst.operands[2].shifted
10307 || inst.operands[2].negative,
10308 BAD_ADDR_MODE);
10309
10310 inst.instruction |= inst.operands[0].reg << 8;
10311 inst.instruction |= inst.operands[1].reg << 12;
10312 inst.instruction |= inst.operands[2].reg << 16;
10313 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
10314 }
10315
10316 static void
10317 do_t_strexd (void)
10318 {
10319 if (!inst.operands[2].present)
10320 inst.operands[2].reg = inst.operands[1].reg + 1;
10321
10322 constraint (inst.operands[0].reg == inst.operands[1].reg
10323 || inst.operands[0].reg == inst.operands[2].reg
10324 || inst.operands[0].reg == inst.operands[3].reg
10325 || inst.operands[1].reg == inst.operands[2].reg,
10326 BAD_OVERLAP);
10327
10328 inst.instruction |= inst.operands[0].reg;
10329 inst.instruction |= inst.operands[1].reg << 12;
10330 inst.instruction |= inst.operands[2].reg << 8;
10331 inst.instruction |= inst.operands[3].reg << 16;
10332 }
10333
10334 static void
10335 do_t_sxtah (void)
10336 {
10337 inst.instruction |= inst.operands[0].reg << 8;
10338 inst.instruction |= inst.operands[1].reg << 16;
10339 inst.instruction |= inst.operands[2].reg;
10340 inst.instruction |= inst.operands[3].imm << 4;
10341 }
10342
10343 static void
10344 do_t_sxth (void)
10345 {
10346 if (inst.instruction <= 0xffff && inst.size_req != 4
10347 && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10348 && (!inst.operands[2].present || inst.operands[2].imm == 0))
10349 {
10350 inst.instruction = THUMB_OP16 (inst.instruction);
10351 inst.instruction |= inst.operands[0].reg;
10352 inst.instruction |= inst.operands[1].reg << 3;
10353 }
10354 else if (unified_syntax)
10355 {
10356 if (inst.instruction <= 0xffff)
10357 inst.instruction = THUMB_OP32 (inst.instruction);
10358 inst.instruction |= inst.operands[0].reg << 8;
10359 inst.instruction |= inst.operands[1].reg;
10360 inst.instruction |= inst.operands[2].imm << 4;
10361 }
10362 else
10363 {
10364 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
10365 _("Thumb encoding does not support rotation"));
10366 constraint (1, BAD_HIREG);
10367 }
10368 }
10369
10370 static void
10371 do_t_swi (void)
10372 {
10373 inst.reloc.type = BFD_RELOC_ARM_SWI;
10374 }
10375
10376 static void
10377 do_t_tb (void)
10378 {
10379 int half;
10380
10381 half = (inst.instruction & 0x10) != 0;
10382 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
10383 constraint (inst.operands[0].immisreg,
10384 _("instruction requires register index"));
10385 constraint (inst.operands[0].imm == 15,
10386 _("PC is not a valid index register"));
10387 constraint (!half && inst.operands[0].shifted,
10388 _("instruction does not allow shifted index"));
10389 inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm;
10390 }
10391
10392 static void
10393 do_t_usat (void)
10394 {
10395 inst.instruction |= inst.operands[0].reg << 8;
10396 inst.instruction |= inst.operands[1].imm;
10397 inst.instruction |= inst.operands[2].reg << 16;
10398
10399 if (inst.operands[3].present)
10400 {
10401 constraint (inst.reloc.exp.X_op != O_constant,
10402 _("expression too complex"));
10403 if (inst.reloc.exp.X_add_number != 0)
10404 {
10405 if (inst.operands[3].shift_kind == SHIFT_ASR)
10406 inst.instruction |= 0x00200000; /* sh bit */
10407
10408 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10409 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10410 }
10411 inst.reloc.type = BFD_RELOC_UNUSED;
10412 }
10413 }
10414
10415 static void
10416 do_t_usat16 (void)
10417 {
10418 inst.instruction |= inst.operands[0].reg << 8;
10419 inst.instruction |= inst.operands[1].imm;
10420 inst.instruction |= inst.operands[2].reg << 16;
10421 }
10422
10423 /* Neon instruction encoder helpers. */
10424
10425 /* Encodings for the different types for various Neon opcodes. */
10426
10427 /* An "invalid" code for the following tables. */
10428 #define N_INV -1u
10429
10430 struct neon_tab_entry
10431 {
10432 unsigned integer;
10433 unsigned float_or_poly;
10434 unsigned scalar_or_imm;
10435 };
10436
10437 /* Map overloaded Neon opcodes to their respective encodings. */
10438 #define NEON_ENC_TAB \
10439 X(vabd, 0x0000700, 0x1200d00, N_INV), \
10440 X(vmax, 0x0000600, 0x0000f00, N_INV), \
10441 X(vmin, 0x0000610, 0x0200f00, N_INV), \
10442 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
10443 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
10444 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
10445 X(vadd, 0x0000800, 0x0000d00, N_INV), \
10446 X(vsub, 0x1000800, 0x0200d00, N_INV), \
10447 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
10448 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
10449 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
10450 /* Register variants of the following two instructions are encoded as
10451 vcge / vcgt with the operands reversed. */ \
10452 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
10453 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
10454 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
10455 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
10456 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
10457 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
10458 X(vmlal, 0x0800800, N_INV, 0x0800240), \
10459 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
10460 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
10461 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
10462 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
10463 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
10464 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
10465 X(vshl, 0x0000400, N_INV, 0x0800510), \
10466 X(vqshl, 0x0000410, N_INV, 0x0800710), \
10467 X(vand, 0x0000110, N_INV, 0x0800030), \
10468 X(vbic, 0x0100110, N_INV, 0x0800030), \
10469 X(veor, 0x1000110, N_INV, N_INV), \
10470 X(vorn, 0x0300110, N_INV, 0x0800010), \
10471 X(vorr, 0x0200110, N_INV, 0x0800010), \
10472 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
10473 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
10474 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
10475 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
10476 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
10477 X(vst1, 0x0000000, 0x0800000, N_INV), \
10478 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
10479 X(vst2, 0x0000100, 0x0800100, N_INV), \
10480 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
10481 X(vst3, 0x0000200, 0x0800200, N_INV), \
10482 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
10483 X(vst4, 0x0000300, 0x0800300, N_INV), \
10484 X(vmovn, 0x1b20200, N_INV, N_INV), \
10485 X(vtrn, 0x1b20080, N_INV, N_INV), \
10486 X(vqmovn, 0x1b20200, N_INV, N_INV), \
10487 X(vqmovun, 0x1b20240, N_INV, N_INV), \
10488 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
10489 X(vnmla, 0xe000a40, 0xe000b40, N_INV), \
10490 X(vnmls, 0xe100a40, 0xe100b40, N_INV), \
10491 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
10492 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
10493 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
10494 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
10495
10496 enum neon_opc
10497 {
10498 #define X(OPC,I,F,S) N_MNEM_##OPC
10499 NEON_ENC_TAB
10500 #undef X
10501 };
10502
10503 static const struct neon_tab_entry neon_enc_tab[] =
10504 {
10505 #define X(OPC,I,F,S) { (I), (F), (S) }
10506 NEON_ENC_TAB
10507 #undef X
10508 };
10509
10510 #define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10511 #define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10512 #define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10513 #define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10514 #define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10515 #define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10516 #define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10517 #define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10518 #define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10519 #define NEON_ENC_SINGLE(X) \
10520 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
10521 #define NEON_ENC_DOUBLE(X) \
10522 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
10523
10524 /* Define shapes for instruction operands. The following mnemonic characters
10525 are used in this table:
10526
10527 F - VFP S<n> register
10528 D - Neon D<n> register
10529 Q - Neon Q<n> register
10530 I - Immediate
10531 S - Scalar
10532 R - ARM register
10533 L - D<n> register list
10534
10535 This table is used to generate various data:
10536 - enumerations of the form NS_DDR to be used as arguments to
10537 neon_select_shape.
10538 - a table classifying shapes into single, double, quad, mixed.
10539 - a table used to drive neon_select_shape. */
10540
10541 #define NEON_SHAPE_DEF \
10542 X(3, (D, D, D), DOUBLE), \
10543 X(3, (Q, Q, Q), QUAD), \
10544 X(3, (D, D, I), DOUBLE), \
10545 X(3, (Q, Q, I), QUAD), \
10546 X(3, (D, D, S), DOUBLE), \
10547 X(3, (Q, Q, S), QUAD), \
10548 X(2, (D, D), DOUBLE), \
10549 X(2, (Q, Q), QUAD), \
10550 X(2, (D, S), DOUBLE), \
10551 X(2, (Q, S), QUAD), \
10552 X(2, (D, R), DOUBLE), \
10553 X(2, (Q, R), QUAD), \
10554 X(2, (D, I), DOUBLE), \
10555 X(2, (Q, I), QUAD), \
10556 X(3, (D, L, D), DOUBLE), \
10557 X(2, (D, Q), MIXED), \
10558 X(2, (Q, D), MIXED), \
10559 X(3, (D, Q, I), MIXED), \
10560 X(3, (Q, D, I), MIXED), \
10561 X(3, (Q, D, D), MIXED), \
10562 X(3, (D, Q, Q), MIXED), \
10563 X(3, (Q, Q, D), MIXED), \
10564 X(3, (Q, D, S), MIXED), \
10565 X(3, (D, Q, S), MIXED), \
10566 X(4, (D, D, D, I), DOUBLE), \
10567 X(4, (Q, Q, Q, I), QUAD), \
10568 X(2, (F, F), SINGLE), \
10569 X(3, (F, F, F), SINGLE), \
10570 X(2, (F, I), SINGLE), \
10571 X(2, (F, D), MIXED), \
10572 X(2, (D, F), MIXED), \
10573 X(3, (F, F, I), MIXED), \
10574 X(4, (R, R, F, F), SINGLE), \
10575 X(4, (F, F, R, R), SINGLE), \
10576 X(3, (D, R, R), DOUBLE), \
10577 X(3, (R, R, D), DOUBLE), \
10578 X(2, (S, R), SINGLE), \
10579 X(2, (R, S), SINGLE), \
10580 X(2, (F, R), SINGLE), \
10581 X(2, (R, F), SINGLE)
10582
10583 #define S2(A,B) NS_##A##B
10584 #define S3(A,B,C) NS_##A##B##C
10585 #define S4(A,B,C,D) NS_##A##B##C##D
10586
10587 #define X(N, L, C) S##N L
10588
10589 enum neon_shape
10590 {
10591 NEON_SHAPE_DEF,
10592 NS_NULL
10593 };
10594
10595 #undef X
10596 #undef S2
10597 #undef S3
10598 #undef S4
10599
10600 enum neon_shape_class
10601 {
10602 SC_SINGLE,
10603 SC_DOUBLE,
10604 SC_QUAD,
10605 SC_MIXED
10606 };
10607
10608 #define X(N, L, C) SC_##C
10609
10610 static enum neon_shape_class neon_shape_class[] =
10611 {
10612 NEON_SHAPE_DEF
10613 };
10614
10615 #undef X
10616
10617 enum neon_shape_el
10618 {
10619 SE_F,
10620 SE_D,
10621 SE_Q,
10622 SE_I,
10623 SE_S,
10624 SE_R,
10625 SE_L
10626 };
10627
10628 /* Register widths of above. */
10629 static unsigned neon_shape_el_size[] =
10630 {
10631 32,
10632 64,
10633 128,
10634 0,
10635 32,
10636 32,
10637 0
10638 };
10639
10640 struct neon_shape_info
10641 {
10642 unsigned els;
10643 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
10644 };
10645
10646 #define S2(A,B) { SE_##A, SE_##B }
10647 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
10648 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
10649
10650 #define X(N, L, C) { N, S##N L }
10651
10652 static struct neon_shape_info neon_shape_tab[] =
10653 {
10654 NEON_SHAPE_DEF
10655 };
10656
10657 #undef X
10658 #undef S2
10659 #undef S3
10660 #undef S4
10661
10662 /* Bit masks used in type checking given instructions.
10663 'N_EQK' means the type must be the same as (or based on in some way) the key
10664 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
10665 set, various other bits can be set as well in order to modify the meaning of
10666 the type constraint. */
10667
10668 enum neon_type_mask
10669 {
10670 N_S8 = 0x000001,
10671 N_S16 = 0x000002,
10672 N_S32 = 0x000004,
10673 N_S64 = 0x000008,
10674 N_U8 = 0x000010,
10675 N_U16 = 0x000020,
10676 N_U32 = 0x000040,
10677 N_U64 = 0x000080,
10678 N_I8 = 0x000100,
10679 N_I16 = 0x000200,
10680 N_I32 = 0x000400,
10681 N_I64 = 0x000800,
10682 N_8 = 0x001000,
10683 N_16 = 0x002000,
10684 N_32 = 0x004000,
10685 N_64 = 0x008000,
10686 N_P8 = 0x010000,
10687 N_P16 = 0x020000,
10688 N_F32 = 0x040000,
10689 N_F64 = 0x080000,
10690 N_KEY = 0x100000, /* key element (main type specifier). */
10691 N_EQK = 0x200000, /* given operand has the same type & size as the key. */
10692 N_VFP = 0x400000, /* VFP mode: operand size must match register width. */
10693 N_DBL = 0x000001, /* if N_EQK, this operand is twice the size. */
10694 N_HLF = 0x000002, /* if N_EQK, this operand is half the size. */
10695 N_SGN = 0x000004, /* if N_EQK, this operand is forced to be signed. */
10696 N_UNS = 0x000008, /* if N_EQK, this operand is forced to be unsigned. */
10697 N_INT = 0x000010, /* if N_EQK, this operand is forced to be integer. */
10698 N_FLT = 0x000020, /* if N_EQK, this operand is forced to be float. */
10699 N_SIZ = 0x000040, /* if N_EQK, this operand is forced to be size-only. */
10700 N_UTYP = 0,
10701 N_MAX_NONSPECIAL = N_F64
10702 };
10703
10704 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
10705
10706 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
10707 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
10708 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
10709 #define N_SUF_32 (N_SU_32 | N_F32)
10710 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
10711 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
10712
10713 /* Pass this as the first type argument to neon_check_type to ignore types
10714 altogether. */
10715 #define N_IGNORE_TYPE (N_KEY | N_EQK)
10716
10717 /* Select a "shape" for the current instruction (describing register types or
10718 sizes) from a list of alternatives. Return NS_NULL if the current instruction
10719 doesn't fit. For non-polymorphic shapes, checking is usually done as a
10720 function of operand parsing, so this function doesn't need to be called.
10721 Shapes should be listed in order of decreasing length. */
10722
10723 static enum neon_shape
10724 neon_select_shape (enum neon_shape shape, ...)
10725 {
10726 va_list ap;
10727 enum neon_shape first_shape = shape;
10728
10729 /* Fix missing optional operands. FIXME: we don't know at this point how
10730 many arguments we should have, so this makes the assumption that we have
10731 > 1. This is true of all current Neon opcodes, I think, but may not be
10732 true in the future. */
10733 if (!inst.operands[1].present)
10734 inst.operands[1] = inst.operands[0];
10735
10736 va_start (ap, shape);
10737
10738 for (; shape != NS_NULL; shape = va_arg (ap, int))
10739 {
10740 unsigned j;
10741 int matches = 1;
10742
10743 for (j = 0; j < neon_shape_tab[shape].els; j++)
10744 {
10745 if (!inst.operands[j].present)
10746 {
10747 matches = 0;
10748 break;
10749 }
10750
10751 switch (neon_shape_tab[shape].el[j])
10752 {
10753 case SE_F:
10754 if (!(inst.operands[j].isreg
10755 && inst.operands[j].isvec
10756 && inst.operands[j].issingle
10757 && !inst.operands[j].isquad))
10758 matches = 0;
10759 break;
10760
10761 case SE_D:
10762 if (!(inst.operands[j].isreg
10763 && inst.operands[j].isvec
10764 && !inst.operands[j].isquad
10765 && !inst.operands[j].issingle))
10766 matches = 0;
10767 break;
10768
10769 case SE_R:
10770 if (!(inst.operands[j].isreg
10771 && !inst.operands[j].isvec))
10772 matches = 0;
10773 break;
10774
10775 case SE_Q:
10776 if (!(inst.operands[j].isreg
10777 && inst.operands[j].isvec
10778 && inst.operands[j].isquad
10779 && !inst.operands[j].issingle))
10780 matches = 0;
10781 break;
10782
10783 case SE_I:
10784 if (!(!inst.operands[j].isreg
10785 && !inst.operands[j].isscalar))
10786 matches = 0;
10787 break;
10788
10789 case SE_S:
10790 if (!(!inst.operands[j].isreg
10791 && inst.operands[j].isscalar))
10792 matches = 0;
10793 break;
10794
10795 case SE_L:
10796 break;
10797 }
10798 }
10799 if (matches)
10800 break;
10801 }
10802
10803 va_end (ap);
10804
10805 if (shape == NS_NULL && first_shape != NS_NULL)
10806 first_error (_("invalid instruction shape"));
10807
10808 return shape;
10809 }
10810
10811 /* True if SHAPE is predominantly a quadword operation (most of the time, this
10812 means the Q bit should be set). */
10813
10814 static int
10815 neon_quad (enum neon_shape shape)
10816 {
10817 return neon_shape_class[shape] == SC_QUAD;
10818 }
10819
10820 static void
10821 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
10822 unsigned *g_size)
10823 {
10824 /* Allow modification to be made to types which are constrained to be
10825 based on the key element, based on bits set alongside N_EQK. */
10826 if ((typebits & N_EQK) != 0)
10827 {
10828 if ((typebits & N_HLF) != 0)
10829 *g_size /= 2;
10830 else if ((typebits & N_DBL) != 0)
10831 *g_size *= 2;
10832 if ((typebits & N_SGN) != 0)
10833 *g_type = NT_signed;
10834 else if ((typebits & N_UNS) != 0)
10835 *g_type = NT_unsigned;
10836 else if ((typebits & N_INT) != 0)
10837 *g_type = NT_integer;
10838 else if ((typebits & N_FLT) != 0)
10839 *g_type = NT_float;
10840 else if ((typebits & N_SIZ) != 0)
10841 *g_type = NT_untyped;
10842 }
10843 }
10844
10845 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
10846 operand type, i.e. the single type specified in a Neon instruction when it
10847 is the only one given. */
10848
10849 static struct neon_type_el
10850 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
10851 {
10852 struct neon_type_el dest = *key;
10853
10854 assert ((thisarg & N_EQK) != 0);
10855
10856 neon_modify_type_size (thisarg, &dest.type, &dest.size);
10857
10858 return dest;
10859 }
10860
10861 /* Convert Neon type and size into compact bitmask representation. */
10862
10863 static enum neon_type_mask
10864 type_chk_of_el_type (enum neon_el_type type, unsigned size)
10865 {
10866 switch (type)
10867 {
10868 case NT_untyped:
10869 switch (size)
10870 {
10871 case 8: return N_8;
10872 case 16: return N_16;
10873 case 32: return N_32;
10874 case 64: return N_64;
10875 default: ;
10876 }
10877 break;
10878
10879 case NT_integer:
10880 switch (size)
10881 {
10882 case 8: return N_I8;
10883 case 16: return N_I16;
10884 case 32: return N_I32;
10885 case 64: return N_I64;
10886 default: ;
10887 }
10888 break;
10889
10890 case NT_float:
10891 switch (size)
10892 {
10893 case 32: return N_F32;
10894 case 64: return N_F64;
10895 default: ;
10896 }
10897 break;
10898
10899 case NT_poly:
10900 switch (size)
10901 {
10902 case 8: return N_P8;
10903 case 16: return N_P16;
10904 default: ;
10905 }
10906 break;
10907
10908 case NT_signed:
10909 switch (size)
10910 {
10911 case 8: return N_S8;
10912 case 16: return N_S16;
10913 case 32: return N_S32;
10914 case 64: return N_S64;
10915 default: ;
10916 }
10917 break;
10918
10919 case NT_unsigned:
10920 switch (size)
10921 {
10922 case 8: return N_U8;
10923 case 16: return N_U16;
10924 case 32: return N_U32;
10925 case 64: return N_U64;
10926 default: ;
10927 }
10928 break;
10929
10930 default: ;
10931 }
10932
10933 return N_UTYP;
10934 }
10935
10936 /* Convert compact Neon bitmask type representation to a type and size. Only
10937 handles the case where a single bit is set in the mask. */
10938
10939 static int
10940 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
10941 enum neon_type_mask mask)
10942 {
10943 if ((mask & N_EQK) != 0)
10944 return FAIL;
10945
10946 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
10947 *size = 8;
10948 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
10949 *size = 16;
10950 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
10951 *size = 32;
10952 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
10953 *size = 64;
10954 else
10955 return FAIL;
10956
10957 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
10958 *type = NT_signed;
10959 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
10960 *type = NT_unsigned;
10961 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
10962 *type = NT_integer;
10963 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
10964 *type = NT_untyped;
10965 else if ((mask & (N_P8 | N_P16)) != 0)
10966 *type = NT_poly;
10967 else if ((mask & (N_F32 | N_F64)) != 0)
10968 *type = NT_float;
10969 else
10970 return FAIL;
10971
10972 return SUCCESS;
10973 }
10974
10975 /* Modify a bitmask of allowed types. This is only needed for type
10976 relaxation. */
10977
10978 static unsigned
10979 modify_types_allowed (unsigned allowed, unsigned mods)
10980 {
10981 unsigned size;
10982 enum neon_el_type type;
10983 unsigned destmask;
10984 int i;
10985
10986 destmask = 0;
10987
10988 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
10989 {
10990 if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS)
10991 {
10992 neon_modify_type_size (mods, &type, &size);
10993 destmask |= type_chk_of_el_type (type, size);
10994 }
10995 }
10996
10997 return destmask;
10998 }
10999
11000 /* Check type and return type classification.
11001 The manual states (paraphrase): If one datatype is given, it indicates the
11002 type given in:
11003 - the second operand, if there is one
11004 - the operand, if there is no second operand
11005 - the result, if there are no operands.
11006 This isn't quite good enough though, so we use a concept of a "key" datatype
11007 which is set on a per-instruction basis, which is the one which matters when
11008 only one data type is written.
11009 Note: this function has side-effects (e.g. filling in missing operands). All
11010 Neon instructions should call it before performing bit encoding. */
11011
11012 static struct neon_type_el
11013 neon_check_type (unsigned els, enum neon_shape ns, ...)
11014 {
11015 va_list ap;
11016 unsigned i, pass, key_el = 0;
11017 unsigned types[NEON_MAX_TYPE_ELS];
11018 enum neon_el_type k_type = NT_invtype;
11019 unsigned k_size = -1u;
11020 struct neon_type_el badtype = {NT_invtype, -1};
11021 unsigned key_allowed = 0;
11022
11023 /* Optional registers in Neon instructions are always (not) in operand 1.
11024 Fill in the missing operand here, if it was omitted. */
11025 if (els > 1 && !inst.operands[1].present)
11026 inst.operands[1] = inst.operands[0];
11027
11028 /* Suck up all the varargs. */
11029 va_start (ap, ns);
11030 for (i = 0; i < els; i++)
11031 {
11032 unsigned thisarg = va_arg (ap, unsigned);
11033 if (thisarg == N_IGNORE_TYPE)
11034 {
11035 va_end (ap);
11036 return badtype;
11037 }
11038 types[i] = thisarg;
11039 if ((thisarg & N_KEY) != 0)
11040 key_el = i;
11041 }
11042 va_end (ap);
11043
11044 if (inst.vectype.elems > 0)
11045 for (i = 0; i < els; i++)
11046 if (inst.operands[i].vectype.type != NT_invtype)
11047 {
11048 first_error (_("types specified in both the mnemonic and operands"));
11049 return badtype;
11050 }
11051
11052 /* Duplicate inst.vectype elements here as necessary.
11053 FIXME: No idea if this is exactly the same as the ARM assembler,
11054 particularly when an insn takes one register and one non-register
11055 operand. */
11056 if (inst.vectype.elems == 1 && els > 1)
11057 {
11058 unsigned j;
11059 inst.vectype.elems = els;
11060 inst.vectype.el[key_el] = inst.vectype.el[0];
11061 for (j = 0; j < els; j++)
11062 if (j != key_el)
11063 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11064 types[j]);
11065 }
11066 else if (inst.vectype.elems == 0 && els > 0)
11067 {
11068 unsigned j;
11069 /* No types were given after the mnemonic, so look for types specified
11070 after each operand. We allow some flexibility here; as long as the
11071 "key" operand has a type, we can infer the others. */
11072 for (j = 0; j < els; j++)
11073 if (inst.operands[j].vectype.type != NT_invtype)
11074 inst.vectype.el[j] = inst.operands[j].vectype;
11075
11076 if (inst.operands[key_el].vectype.type != NT_invtype)
11077 {
11078 for (j = 0; j < els; j++)
11079 if (inst.operands[j].vectype.type == NT_invtype)
11080 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11081 types[j]);
11082 }
11083 else
11084 {
11085 first_error (_("operand types can't be inferred"));
11086 return badtype;
11087 }
11088 }
11089 else if (inst.vectype.elems != els)
11090 {
11091 first_error (_("type specifier has the wrong number of parts"));
11092 return badtype;
11093 }
11094
11095 for (pass = 0; pass < 2; pass++)
11096 {
11097 for (i = 0; i < els; i++)
11098 {
11099 unsigned thisarg = types[i];
11100 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
11101 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
11102 enum neon_el_type g_type = inst.vectype.el[i].type;
11103 unsigned g_size = inst.vectype.el[i].size;
11104
11105 /* Decay more-specific signed & unsigned types to sign-insensitive
11106 integer types if sign-specific variants are unavailable. */
11107 if ((g_type == NT_signed || g_type == NT_unsigned)
11108 && (types_allowed & N_SU_ALL) == 0)
11109 g_type = NT_integer;
11110
11111 /* If only untyped args are allowed, decay any more specific types to
11112 them. Some instructions only care about signs for some element
11113 sizes, so handle that properly. */
11114 if ((g_size == 8 && (types_allowed & N_8) != 0)
11115 || (g_size == 16 && (types_allowed & N_16) != 0)
11116 || (g_size == 32 && (types_allowed & N_32) != 0)
11117 || (g_size == 64 && (types_allowed & N_64) != 0))
11118 g_type = NT_untyped;
11119
11120 if (pass == 0)
11121 {
11122 if ((thisarg & N_KEY) != 0)
11123 {
11124 k_type = g_type;
11125 k_size = g_size;
11126 key_allowed = thisarg & ~N_KEY;
11127 }
11128 }
11129 else
11130 {
11131 if ((thisarg & N_VFP) != 0)
11132 {
11133 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
11134 unsigned regwidth = neon_shape_el_size[regshape], match;
11135
11136 /* In VFP mode, operands must match register widths. If we
11137 have a key operand, use its width, else use the width of
11138 the current operand. */
11139 if (k_size != -1u)
11140 match = k_size;
11141 else
11142 match = g_size;
11143
11144 if (regwidth != match)
11145 {
11146 first_error (_("operand size must match register width"));
11147 return badtype;
11148 }
11149 }
11150
11151 if ((thisarg & N_EQK) == 0)
11152 {
11153 unsigned given_type = type_chk_of_el_type (g_type, g_size);
11154
11155 if ((given_type & types_allowed) == 0)
11156 {
11157 first_error (_("bad type in Neon instruction"));
11158 return badtype;
11159 }
11160 }
11161 else
11162 {
11163 enum neon_el_type mod_k_type = k_type;
11164 unsigned mod_k_size = k_size;
11165 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
11166 if (g_type != mod_k_type || g_size != mod_k_size)
11167 {
11168 first_error (_("inconsistent types in Neon instruction"));
11169 return badtype;
11170 }
11171 }
11172 }
11173 }
11174 }
11175
11176 return inst.vectype.el[key_el];
11177 }
11178
11179 /* Neon-style VFP instruction forwarding. */
11180
11181 /* Thumb VFP instructions have 0xE in the condition field. */
11182
11183 static void
11184 do_vfp_cond_or_thumb (void)
11185 {
11186 if (thumb_mode)
11187 inst.instruction |= 0xe0000000;
11188 else
11189 inst.instruction |= inst.cond << 28;
11190 }
11191
11192 /* Look up and encode a simple mnemonic, for use as a helper function for the
11193 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
11194 etc. It is assumed that operand parsing has already been done, and that the
11195 operands are in the form expected by the given opcode (this isn't necessarily
11196 the same as the form in which they were parsed, hence some massaging must
11197 take place before this function is called).
11198 Checks current arch version against that in the looked-up opcode. */
11199
11200 static void
11201 do_vfp_nsyn_opcode (const char *opname)
11202 {
11203 const struct asm_opcode *opcode;
11204
11205 opcode = hash_find (arm_ops_hsh, opname);
11206
11207 if (!opcode)
11208 abort ();
11209
11210 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
11211 thumb_mode ? *opcode->tvariant : *opcode->avariant),
11212 _(BAD_FPU));
11213
11214 if (thumb_mode)
11215 {
11216 inst.instruction = opcode->tvalue;
11217 opcode->tencode ();
11218 }
11219 else
11220 {
11221 inst.instruction = (inst.cond << 28) | opcode->avalue;
11222 opcode->aencode ();
11223 }
11224 }
11225
11226 static void
11227 do_vfp_nsyn_add_sub (enum neon_shape rs)
11228 {
11229 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
11230
11231 if (rs == NS_FFF)
11232 {
11233 if (is_add)
11234 do_vfp_nsyn_opcode ("fadds");
11235 else
11236 do_vfp_nsyn_opcode ("fsubs");
11237 }
11238 else
11239 {
11240 if (is_add)
11241 do_vfp_nsyn_opcode ("faddd");
11242 else
11243 do_vfp_nsyn_opcode ("fsubd");
11244 }
11245 }
11246
11247 /* Check operand types to see if this is a VFP instruction, and if so call
11248 PFN (). */
11249
11250 static int
11251 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
11252 {
11253 enum neon_shape rs;
11254 struct neon_type_el et;
11255
11256 switch (args)
11257 {
11258 case 2:
11259 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11260 et = neon_check_type (2, rs,
11261 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11262 break;
11263
11264 case 3:
11265 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11266 et = neon_check_type (3, rs,
11267 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11268 break;
11269
11270 default:
11271 abort ();
11272 }
11273
11274 if (et.type != NT_invtype)
11275 {
11276 pfn (rs);
11277 return SUCCESS;
11278 }
11279 else
11280 inst.error = NULL;
11281
11282 return FAIL;
11283 }
11284
11285 static void
11286 do_vfp_nsyn_mla_mls (enum neon_shape rs)
11287 {
11288 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
11289
11290 if (rs == NS_FFF)
11291 {
11292 if (is_mla)
11293 do_vfp_nsyn_opcode ("fmacs");
11294 else
11295 do_vfp_nsyn_opcode ("fmscs");
11296 }
11297 else
11298 {
11299 if (is_mla)
11300 do_vfp_nsyn_opcode ("fmacd");
11301 else
11302 do_vfp_nsyn_opcode ("fmscd");
11303 }
11304 }
11305
11306 static void
11307 do_vfp_nsyn_mul (enum neon_shape rs)
11308 {
11309 if (rs == NS_FFF)
11310 do_vfp_nsyn_opcode ("fmuls");
11311 else
11312 do_vfp_nsyn_opcode ("fmuld");
11313 }
11314
11315 static void
11316 do_vfp_nsyn_abs_neg (enum neon_shape rs)
11317 {
11318 int is_neg = (inst.instruction & 0x80) != 0;
11319 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
11320
11321 if (rs == NS_FF)
11322 {
11323 if (is_neg)
11324 do_vfp_nsyn_opcode ("fnegs");
11325 else
11326 do_vfp_nsyn_opcode ("fabss");
11327 }
11328 else
11329 {
11330 if (is_neg)
11331 do_vfp_nsyn_opcode ("fnegd");
11332 else
11333 do_vfp_nsyn_opcode ("fabsd");
11334 }
11335 }
11336
11337 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
11338 insns belong to Neon, and are handled elsewhere. */
11339
11340 static void
11341 do_vfp_nsyn_ldm_stm (int is_dbmode)
11342 {
11343 int is_ldm = (inst.instruction & (1 << 20)) != 0;
11344 if (is_ldm)
11345 {
11346 if (is_dbmode)
11347 do_vfp_nsyn_opcode ("fldmdbs");
11348 else
11349 do_vfp_nsyn_opcode ("fldmias");
11350 }
11351 else
11352 {
11353 if (is_dbmode)
11354 do_vfp_nsyn_opcode ("fstmdbs");
11355 else
11356 do_vfp_nsyn_opcode ("fstmias");
11357 }
11358 }
11359
11360 static void
11361 do_vfp_nsyn_sqrt (void)
11362 {
11363 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11364 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11365
11366 if (rs == NS_FF)
11367 do_vfp_nsyn_opcode ("fsqrts");
11368 else
11369 do_vfp_nsyn_opcode ("fsqrtd");
11370 }
11371
11372 static void
11373 do_vfp_nsyn_div (void)
11374 {
11375 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11376 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11377 N_F32 | N_F64 | N_KEY | N_VFP);
11378
11379 if (rs == NS_FFF)
11380 do_vfp_nsyn_opcode ("fdivs");
11381 else
11382 do_vfp_nsyn_opcode ("fdivd");
11383 }
11384
11385 static void
11386 do_vfp_nsyn_nmul (void)
11387 {
11388 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11389 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11390 N_F32 | N_F64 | N_KEY | N_VFP);
11391
11392 if (rs == NS_FFF)
11393 {
11394 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11395 do_vfp_sp_dyadic ();
11396 }
11397 else
11398 {
11399 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11400 do_vfp_dp_rd_rn_rm ();
11401 }
11402 do_vfp_cond_or_thumb ();
11403 }
11404
11405 static void
11406 do_vfp_nsyn_cmp (void)
11407 {
11408 if (inst.operands[1].isreg)
11409 {
11410 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11411 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11412
11413 if (rs == NS_FF)
11414 {
11415 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11416 do_vfp_sp_monadic ();
11417 }
11418 else
11419 {
11420 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11421 do_vfp_dp_rd_rm ();
11422 }
11423 }
11424 else
11425 {
11426 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
11427 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
11428
11429 switch (inst.instruction & 0x0fffffff)
11430 {
11431 case N_MNEM_vcmp:
11432 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
11433 break;
11434 case N_MNEM_vcmpe:
11435 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
11436 break;
11437 default:
11438 abort ();
11439 }
11440
11441 if (rs == NS_FI)
11442 {
11443 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11444 do_vfp_sp_compare_z ();
11445 }
11446 else
11447 {
11448 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11449 do_vfp_dp_rd ();
11450 }
11451 }
11452 do_vfp_cond_or_thumb ();
11453 }
11454
11455 static void
11456 nsyn_insert_sp (void)
11457 {
11458 inst.operands[1] = inst.operands[0];
11459 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
11460 inst.operands[0].reg = 13;
11461 inst.operands[0].isreg = 1;
11462 inst.operands[0].writeback = 1;
11463 inst.operands[0].present = 1;
11464 }
11465
11466 static void
11467 do_vfp_nsyn_push (void)
11468 {
11469 nsyn_insert_sp ();
11470 if (inst.operands[1].issingle)
11471 do_vfp_nsyn_opcode ("fstmdbs");
11472 else
11473 do_vfp_nsyn_opcode ("fstmdbd");
11474 }
11475
11476 static void
11477 do_vfp_nsyn_pop (void)
11478 {
11479 nsyn_insert_sp ();
11480 if (inst.operands[1].issingle)
11481 do_vfp_nsyn_opcode ("fldmias");
11482 else
11483 do_vfp_nsyn_opcode ("fldmiad");
11484 }
11485
11486 /* Fix up Neon data-processing instructions, ORing in the correct bits for
11487 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
11488
11489 static unsigned
11490 neon_dp_fixup (unsigned i)
11491 {
11492 if (thumb_mode)
11493 {
11494 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
11495 if (i & (1 << 24))
11496 i |= 1 << 28;
11497
11498 i &= ~(1 << 24);
11499
11500 i |= 0xef000000;
11501 }
11502 else
11503 i |= 0xf2000000;
11504
11505 return i;
11506 }
11507
11508 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
11509 (0, 1, 2, 3). */
11510
11511 static unsigned
11512 neon_logbits (unsigned x)
11513 {
11514 return ffs (x) - 4;
11515 }
11516
11517 #define LOW4(R) ((R) & 0xf)
11518 #define HI1(R) (((R) >> 4) & 1)
11519
11520 /* Encode insns with bit pattern:
11521
11522 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
11523 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
11524
11525 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
11526 different meaning for some instruction. */
11527
11528 static void
11529 neon_three_same (int isquad, int ubit, int size)
11530 {
11531 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11532 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11533 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
11534 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
11535 inst.instruction |= LOW4 (inst.operands[2].reg);
11536 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
11537 inst.instruction |= (isquad != 0) << 6;
11538 inst.instruction |= (ubit != 0) << 24;
11539 if (size != -1)
11540 inst.instruction |= neon_logbits (size) << 20;
11541
11542 inst.instruction = neon_dp_fixup (inst.instruction);
11543 }
11544
11545 /* Encode instructions of the form:
11546
11547 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
11548 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
11549
11550 Don't write size if SIZE == -1. */
11551
11552 static void
11553 neon_two_same (int qbit, int ubit, int size)
11554 {
11555 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11556 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11557 inst.instruction |= LOW4 (inst.operands[1].reg);
11558 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11559 inst.instruction |= (qbit != 0) << 6;
11560 inst.instruction |= (ubit != 0) << 24;
11561
11562 if (size != -1)
11563 inst.instruction |= neon_logbits (size) << 18;
11564
11565 inst.instruction = neon_dp_fixup (inst.instruction);
11566 }
11567
11568 /* Neon instruction encoders, in approximate order of appearance. */
11569
11570 static void
11571 do_neon_dyadic_i_su (void)
11572 {
11573 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11574 struct neon_type_el et = neon_check_type (3, rs,
11575 N_EQK, N_EQK, N_SU_32 | N_KEY);
11576 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11577 }
11578
11579 static void
11580 do_neon_dyadic_i64_su (void)
11581 {
11582 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11583 struct neon_type_el et = neon_check_type (3, rs,
11584 N_EQK, N_EQK, N_SU_ALL | N_KEY);
11585 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11586 }
11587
11588 static void
11589 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
11590 unsigned immbits)
11591 {
11592 unsigned size = et.size >> 3;
11593 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11594 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11595 inst.instruction |= LOW4 (inst.operands[1].reg);
11596 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11597 inst.instruction |= (isquad != 0) << 6;
11598 inst.instruction |= immbits << 16;
11599 inst.instruction |= (size >> 3) << 7;
11600 inst.instruction |= (size & 0x7) << 19;
11601 if (write_ubit)
11602 inst.instruction |= (uval != 0) << 24;
11603
11604 inst.instruction = neon_dp_fixup (inst.instruction);
11605 }
11606
11607 static void
11608 do_neon_shl_imm (void)
11609 {
11610 if (!inst.operands[2].isreg)
11611 {
11612 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11613 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
11614 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11615 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
11616 }
11617 else
11618 {
11619 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11620 struct neon_type_el et = neon_check_type (3, rs,
11621 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
11622 unsigned int tmp;
11623
11624 /* VSHL/VQSHL 3-register variants have syntax such as:
11625 vshl.xx Dd, Dm, Dn
11626 whereas other 3-register operations encoded by neon_three_same have
11627 syntax like:
11628 vadd.xx Dd, Dn, Dm
11629 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
11630 here. */
11631 tmp = inst.operands[2].reg;
11632 inst.operands[2].reg = inst.operands[1].reg;
11633 inst.operands[1].reg = tmp;
11634 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11635 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11636 }
11637 }
11638
11639 static void
11640 do_neon_qshl_imm (void)
11641 {
11642 if (!inst.operands[2].isreg)
11643 {
11644 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11645 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
11646
11647 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11648 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
11649 inst.operands[2].imm);
11650 }
11651 else
11652 {
11653 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11654 struct neon_type_el et = neon_check_type (3, rs,
11655 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
11656 unsigned int tmp;
11657
11658 /* See note in do_neon_shl_imm. */
11659 tmp = inst.operands[2].reg;
11660 inst.operands[2].reg = inst.operands[1].reg;
11661 inst.operands[1].reg = tmp;
11662 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11663 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11664 }
11665 }
11666
11667 static void
11668 do_neon_rshl (void)
11669 {
11670 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11671 struct neon_type_el et = neon_check_type (3, rs,
11672 N_EQK, N_EQK, N_SU_ALL | N_KEY);
11673 unsigned int tmp;
11674
11675 tmp = inst.operands[2].reg;
11676 inst.operands[2].reg = inst.operands[1].reg;
11677 inst.operands[1].reg = tmp;
11678 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11679 }
11680
11681 static int
11682 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
11683 {
11684 /* Handle .I8 pseudo-instructions. */
11685 if (size == 8)
11686 {
11687 /* Unfortunately, this will make everything apart from zero out-of-range.
11688 FIXME is this the intended semantics? There doesn't seem much point in
11689 accepting .I8 if so. */
11690 immediate |= immediate << 8;
11691 size = 16;
11692 }
11693
11694 if (size >= 32)
11695 {
11696 if (immediate == (immediate & 0x000000ff))
11697 {
11698 *immbits = immediate;
11699 return 0x1;
11700 }
11701 else if (immediate == (immediate & 0x0000ff00))
11702 {
11703 *immbits = immediate >> 8;
11704 return 0x3;
11705 }
11706 else if (immediate == (immediate & 0x00ff0000))
11707 {
11708 *immbits = immediate >> 16;
11709 return 0x5;
11710 }
11711 else if (immediate == (immediate & 0xff000000))
11712 {
11713 *immbits = immediate >> 24;
11714 return 0x7;
11715 }
11716 if ((immediate & 0xffff) != (immediate >> 16))
11717 goto bad_immediate;
11718 immediate &= 0xffff;
11719 }
11720
11721 if (immediate == (immediate & 0x000000ff))
11722 {
11723 *immbits = immediate;
11724 return 0x9;
11725 }
11726 else if (immediate == (immediate & 0x0000ff00))
11727 {
11728 *immbits = immediate >> 8;
11729 return 0xb;
11730 }
11731
11732 bad_immediate:
11733 first_error (_("immediate value out of range"));
11734 return FAIL;
11735 }
11736
11737 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
11738 A, B, C, D. */
11739
11740 static int
11741 neon_bits_same_in_bytes (unsigned imm)
11742 {
11743 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
11744 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
11745 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
11746 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
11747 }
11748
11749 /* For immediate of above form, return 0bABCD. */
11750
11751 static unsigned
11752 neon_squash_bits (unsigned imm)
11753 {
11754 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
11755 | ((imm & 0x01000000) >> 21);
11756 }
11757
11758 /* Compress quarter-float representation to 0b...000 abcdefgh. */
11759
11760 static unsigned
11761 neon_qfloat_bits (unsigned imm)
11762 {
11763 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
11764 }
11765
11766 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
11767 the instruction. *OP is passed as the initial value of the op field, and
11768 may be set to a different value depending on the constant (i.e.
11769 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
11770 MVN). If the immediate looks like a repeated pattern then also
11771 try smaller element sizes. */
11772
11773 static int
11774 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
11775 unsigned *immbits, int *op, int size,
11776 enum neon_el_type type)
11777 {
11778 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
11779 float. */
11780 if (type == NT_float && !float_p)
11781 return FAIL;
11782
11783 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
11784 {
11785 if (size != 32 || *op == 1)
11786 return FAIL;
11787 *immbits = neon_qfloat_bits (immlo);
11788 return 0xf;
11789 }
11790
11791 if (size == 64)
11792 {
11793 if (neon_bits_same_in_bytes (immhi)
11794 && neon_bits_same_in_bytes (immlo))
11795 {
11796 if (*op == 1)
11797 return FAIL;
11798 *immbits = (neon_squash_bits (immhi) << 4)
11799 | neon_squash_bits (immlo);
11800 *op = 1;
11801 return 0xe;
11802 }
11803
11804 if (immhi != immlo)
11805 return FAIL;
11806 }
11807
11808 if (size >= 32)
11809 {
11810 if (immlo == (immlo & 0x000000ff))
11811 {
11812 *immbits = immlo;
11813 return 0x0;
11814 }
11815 else if (immlo == (immlo & 0x0000ff00))
11816 {
11817 *immbits = immlo >> 8;
11818 return 0x2;
11819 }
11820 else if (immlo == (immlo & 0x00ff0000))
11821 {
11822 *immbits = immlo >> 16;
11823 return 0x4;
11824 }
11825 else if (immlo == (immlo & 0xff000000))
11826 {
11827 *immbits = immlo >> 24;
11828 return 0x6;
11829 }
11830 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
11831 {
11832 *immbits = (immlo >> 8) & 0xff;
11833 return 0xc;
11834 }
11835 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
11836 {
11837 *immbits = (immlo >> 16) & 0xff;
11838 return 0xd;
11839 }
11840
11841 if ((immlo & 0xffff) != (immlo >> 16))
11842 return FAIL;
11843 immlo &= 0xffff;
11844 }
11845
11846 if (size >= 16)
11847 {
11848 if (immlo == (immlo & 0x000000ff))
11849 {
11850 *immbits = immlo;
11851 return 0x8;
11852 }
11853 else if (immlo == (immlo & 0x0000ff00))
11854 {
11855 *immbits = immlo >> 8;
11856 return 0xa;
11857 }
11858
11859 if ((immlo & 0xff) != (immlo >> 8))
11860 return FAIL;
11861 immlo &= 0xff;
11862 }
11863
11864 if (immlo == (immlo & 0x000000ff))
11865 {
11866 /* Don't allow MVN with 8-bit immediate. */
11867 if (*op == 1)
11868 return FAIL;
11869 *immbits = immlo;
11870 return 0xe;
11871 }
11872
11873 return FAIL;
11874 }
11875
11876 /* Write immediate bits [7:0] to the following locations:
11877
11878 |28/24|23 19|18 16|15 4|3 0|
11879 | 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|
11880
11881 This function is used by VMOV/VMVN/VORR/VBIC. */
11882
11883 static void
11884 neon_write_immbits (unsigned immbits)
11885 {
11886 inst.instruction |= immbits & 0xf;
11887 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
11888 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
11889 }
11890
11891 /* Invert low-order SIZE bits of XHI:XLO. */
11892
11893 static void
11894 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
11895 {
11896 unsigned immlo = xlo ? *xlo : 0;
11897 unsigned immhi = xhi ? *xhi : 0;
11898
11899 switch (size)
11900 {
11901 case 8:
11902 immlo = (~immlo) & 0xff;
11903 break;
11904
11905 case 16:
11906 immlo = (~immlo) & 0xffff;
11907 break;
11908
11909 case 64:
11910 immhi = (~immhi) & 0xffffffff;
11911 /* fall through. */
11912
11913 case 32:
11914 immlo = (~immlo) & 0xffffffff;
11915 break;
11916
11917 default:
11918 abort ();
11919 }
11920
11921 if (xlo)
11922 *xlo = immlo;
11923
11924 if (xhi)
11925 *xhi = immhi;
11926 }
11927
11928 static void
11929 do_neon_logic (void)
11930 {
11931 if (inst.operands[2].present && inst.operands[2].isreg)
11932 {
11933 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11934 neon_check_type (3, rs, N_IGNORE_TYPE);
11935 /* U bit and size field were set as part of the bitmask. */
11936 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11937 neon_three_same (neon_quad (rs), 0, -1);
11938 }
11939 else
11940 {
11941 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
11942 struct neon_type_el et = neon_check_type (2, rs,
11943 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
11944 enum neon_opc opcode = inst.instruction & 0x0fffffff;
11945 unsigned immbits;
11946 int cmode;
11947
11948 if (et.type == NT_invtype)
11949 return;
11950
11951 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11952
11953 immbits = inst.operands[1].imm;
11954 if (et.size == 64)
11955 {
11956 /* .i64 is a pseudo-op, so the immediate must be a repeating
11957 pattern. */
11958 if (immbits != (inst.operands[1].regisimm ?
11959 inst.operands[1].reg : 0))
11960 {
11961 /* Set immbits to an invalid constant. */
11962 immbits = 0xdeadbeef;
11963 }
11964 }
11965
11966 switch (opcode)
11967 {
11968 case N_MNEM_vbic:
11969 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11970 break;
11971
11972 case N_MNEM_vorr:
11973 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11974 break;
11975
11976 case N_MNEM_vand:
11977 /* Pseudo-instruction for VBIC. */
11978 neon_invert_size (&immbits, 0, et.size);
11979 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11980 break;
11981
11982 case N_MNEM_vorn:
11983 /* Pseudo-instruction for VORR. */
11984 neon_invert_size (&immbits, 0, et.size);
11985 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11986 break;
11987
11988 default:
11989 abort ();
11990 }
11991
11992 if (cmode == FAIL)
11993 return;
11994
11995 inst.instruction |= neon_quad (rs) << 6;
11996 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11997 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11998 inst.instruction |= cmode << 8;
11999 neon_write_immbits (immbits);
12000
12001 inst.instruction = neon_dp_fixup (inst.instruction);
12002 }
12003 }
12004
12005 static void
12006 do_neon_bitfield (void)
12007 {
12008 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12009 neon_check_type (3, rs, N_IGNORE_TYPE);
12010 neon_three_same (neon_quad (rs), 0, -1);
12011 }
12012
12013 static void
12014 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
12015 unsigned destbits)
12016 {
12017 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12018 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
12019 types | N_KEY);
12020 if (et.type == NT_float)
12021 {
12022 inst.instruction = NEON_ENC_FLOAT (inst.instruction);
12023 neon_three_same (neon_quad (rs), 0, -1);
12024 }
12025 else
12026 {
12027 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12028 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
12029 }
12030 }
12031
12032 static void
12033 do_neon_dyadic_if_su (void)
12034 {
12035 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
12036 }
12037
12038 static void
12039 do_neon_dyadic_if_su_d (void)
12040 {
12041 /* This version only allow D registers, but that constraint is enforced during
12042 operand parsing so we don't need to do anything extra here. */
12043 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
12044 }
12045
12046 static void
12047 do_neon_dyadic_if_i_d (void)
12048 {
12049 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12050 affected if we specify unsigned args. */
12051 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12052 }
12053
12054 enum vfp_or_neon_is_neon_bits
12055 {
12056 NEON_CHECK_CC = 1,
12057 NEON_CHECK_ARCH = 2
12058 };
12059
12060 /* Call this function if an instruction which may have belonged to the VFP or
12061 Neon instruction sets, but turned out to be a Neon instruction (due to the
12062 operand types involved, etc.). We have to check and/or fix-up a couple of
12063 things:
12064
12065 - Make sure the user hasn't attempted to make a Neon instruction
12066 conditional.
12067 - Alter the value in the condition code field if necessary.
12068 - Make sure that the arch supports Neon instructions.
12069
12070 Which of these operations take place depends on bits from enum
12071 vfp_or_neon_is_neon_bits.
12072
12073 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
12074 current instruction's condition is COND_ALWAYS, the condition field is
12075 changed to inst.uncond_value. This is necessary because instructions shared
12076 between VFP and Neon may be conditional for the VFP variants only, and the
12077 unconditional Neon version must have, e.g., 0xF in the condition field. */
12078
12079 static int
12080 vfp_or_neon_is_neon (unsigned check)
12081 {
12082 /* Conditions are always legal in Thumb mode (IT blocks). */
12083 if (!thumb_mode && (check & NEON_CHECK_CC))
12084 {
12085 if (inst.cond != COND_ALWAYS)
12086 {
12087 first_error (_(BAD_COND));
12088 return FAIL;
12089 }
12090 if (inst.uncond_value != -1)
12091 inst.instruction |= inst.uncond_value << 28;
12092 }
12093
12094 if ((check & NEON_CHECK_ARCH)
12095 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
12096 {
12097 first_error (_(BAD_FPU));
12098 return FAIL;
12099 }
12100
12101 return SUCCESS;
12102 }
12103
12104 static void
12105 do_neon_addsub_if_i (void)
12106 {
12107 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
12108 return;
12109
12110 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12111 return;
12112
12113 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12114 affected if we specify unsigned args. */
12115 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
12116 }
12117
12118 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
12119 result to be:
12120 V<op> A,B (A is operand 0, B is operand 2)
12121 to mean:
12122 V<op> A,B,A
12123 not:
12124 V<op> A,B,B
12125 so handle that case specially. */
12126
12127 static void
12128 neon_exchange_operands (void)
12129 {
12130 void *scratch = alloca (sizeof (inst.operands[0]));
12131 if (inst.operands[1].present)
12132 {
12133 /* Swap operands[1] and operands[2]. */
12134 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
12135 inst.operands[1] = inst.operands[2];
12136 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
12137 }
12138 else
12139 {
12140 inst.operands[1] = inst.operands[2];
12141 inst.operands[2] = inst.operands[0];
12142 }
12143 }
12144
12145 static void
12146 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
12147 {
12148 if (inst.operands[2].isreg)
12149 {
12150 if (invert)
12151 neon_exchange_operands ();
12152 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
12153 }
12154 else
12155 {
12156 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12157 struct neon_type_el et = neon_check_type (2, rs,
12158 N_EQK | N_SIZ, immtypes | N_KEY);
12159
12160 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12161 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12162 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12163 inst.instruction |= LOW4 (inst.operands[1].reg);
12164 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12165 inst.instruction |= neon_quad (rs) << 6;
12166 inst.instruction |= (et.type == NT_float) << 10;
12167 inst.instruction |= neon_logbits (et.size) << 18;
12168
12169 inst.instruction = neon_dp_fixup (inst.instruction);
12170 }
12171 }
12172
12173 static void
12174 do_neon_cmp (void)
12175 {
12176 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
12177 }
12178
12179 static void
12180 do_neon_cmp_inv (void)
12181 {
12182 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
12183 }
12184
12185 static void
12186 do_neon_ceq (void)
12187 {
12188 neon_compare (N_IF_32, N_IF_32, FALSE);
12189 }
12190
12191 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
12192 scalars, which are encoded in 5 bits, M : Rm.
12193 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
12194 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
12195 index in M. */
12196
12197 static unsigned
12198 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
12199 {
12200 unsigned regno = NEON_SCALAR_REG (scalar);
12201 unsigned elno = NEON_SCALAR_INDEX (scalar);
12202
12203 switch (elsize)
12204 {
12205 case 16:
12206 if (regno > 7 || elno > 3)
12207 goto bad_scalar;
12208 return regno | (elno << 3);
12209
12210 case 32:
12211 if (regno > 15 || elno > 1)
12212 goto bad_scalar;
12213 return regno | (elno << 4);
12214
12215 default:
12216 bad_scalar:
12217 first_error (_("scalar out of range for multiply instruction"));
12218 }
12219
12220 return 0;
12221 }
12222
12223 /* Encode multiply / multiply-accumulate scalar instructions. */
12224
12225 static void
12226 neon_mul_mac (struct neon_type_el et, int ubit)
12227 {
12228 unsigned scalar;
12229
12230 /* Give a more helpful error message if we have an invalid type. */
12231 if (et.type == NT_invtype)
12232 return;
12233
12234 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
12235 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12236 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12237 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12238 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12239 inst.instruction |= LOW4 (scalar);
12240 inst.instruction |= HI1 (scalar) << 5;
12241 inst.instruction |= (et.type == NT_float) << 8;
12242 inst.instruction |= neon_logbits (et.size) << 20;
12243 inst.instruction |= (ubit != 0) << 24;
12244
12245 inst.instruction = neon_dp_fixup (inst.instruction);
12246 }
12247
12248 static void
12249 do_neon_mac_maybe_scalar (void)
12250 {
12251 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
12252 return;
12253
12254 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12255 return;
12256
12257 if (inst.operands[2].isscalar)
12258 {
12259 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
12260 struct neon_type_el et = neon_check_type (3, rs,
12261 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
12262 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12263 neon_mul_mac (et, neon_quad (rs));
12264 }
12265 else
12266 {
12267 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12268 affected if we specify unsigned args. */
12269 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12270 }
12271 }
12272
12273 static void
12274 do_neon_tst (void)
12275 {
12276 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12277 struct neon_type_el et = neon_check_type (3, rs,
12278 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
12279 neon_three_same (neon_quad (rs), 0, et.size);
12280 }
12281
12282 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
12283 same types as the MAC equivalents. The polynomial type for this instruction
12284 is encoded the same as the integer type. */
12285
12286 static void
12287 do_neon_mul (void)
12288 {
12289 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
12290 return;
12291
12292 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12293 return;
12294
12295 if (inst.operands[2].isscalar)
12296 do_neon_mac_maybe_scalar ();
12297 else
12298 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
12299 }
12300
12301 static void
12302 do_neon_qdmulh (void)
12303 {
12304 if (inst.operands[2].isscalar)
12305 {
12306 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
12307 struct neon_type_el et = neon_check_type (3, rs,
12308 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12309 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12310 neon_mul_mac (et, neon_quad (rs));
12311 }
12312 else
12313 {
12314 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12315 struct neon_type_el et = neon_check_type (3, rs,
12316 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12317 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12318 /* The U bit (rounding) comes from bit mask. */
12319 neon_three_same (neon_quad (rs), 0, et.size);
12320 }
12321 }
12322
12323 static void
12324 do_neon_fcmp_absolute (void)
12325 {
12326 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12327 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12328 /* Size field comes from bit mask. */
12329 neon_three_same (neon_quad (rs), 1, -1);
12330 }
12331
12332 static void
12333 do_neon_fcmp_absolute_inv (void)
12334 {
12335 neon_exchange_operands ();
12336 do_neon_fcmp_absolute ();
12337 }
12338
12339 static void
12340 do_neon_step (void)
12341 {
12342 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12343 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12344 neon_three_same (neon_quad (rs), 0, -1);
12345 }
12346
12347 static void
12348 do_neon_abs_neg (void)
12349 {
12350 enum neon_shape rs;
12351 struct neon_type_el et;
12352
12353 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
12354 return;
12355
12356 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12357 return;
12358
12359 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12360 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
12361
12362 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12363 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12364 inst.instruction |= LOW4 (inst.operands[1].reg);
12365 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12366 inst.instruction |= neon_quad (rs) << 6;
12367 inst.instruction |= (et.type == NT_float) << 10;
12368 inst.instruction |= neon_logbits (et.size) << 18;
12369
12370 inst.instruction = neon_dp_fixup (inst.instruction);
12371 }
12372
12373 static void
12374 do_neon_sli (void)
12375 {
12376 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12377 struct neon_type_el et = neon_check_type (2, rs,
12378 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12379 int imm = inst.operands[2].imm;
12380 constraint (imm < 0 || (unsigned)imm >= et.size,
12381 _("immediate out of range for insert"));
12382 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
12383 }
12384
12385 static void
12386 do_neon_sri (void)
12387 {
12388 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12389 struct neon_type_el et = neon_check_type (2, rs,
12390 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12391 int imm = inst.operands[2].imm;
12392 constraint (imm < 1 || (unsigned)imm > et.size,
12393 _("immediate out of range for insert"));
12394 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
12395 }
12396
12397 static void
12398 do_neon_qshlu_imm (void)
12399 {
12400 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12401 struct neon_type_el et = neon_check_type (2, rs,
12402 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
12403 int imm = inst.operands[2].imm;
12404 constraint (imm < 0 || (unsigned)imm >= et.size,
12405 _("immediate out of range for shift"));
12406 /* Only encodes the 'U present' variant of the instruction.
12407 In this case, signed types have OP (bit 8) set to 0.
12408 Unsigned types have OP set to 1. */
12409 inst.instruction |= (et.type == NT_unsigned) << 8;
12410 /* The rest of the bits are the same as other immediate shifts. */
12411 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
12412 }
12413
12414 static void
12415 do_neon_qmovn (void)
12416 {
12417 struct neon_type_el et = neon_check_type (2, NS_DQ,
12418 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12419 /* Saturating move where operands can be signed or unsigned, and the
12420 destination has the same signedness. */
12421 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12422 if (et.type == NT_unsigned)
12423 inst.instruction |= 0xc0;
12424 else
12425 inst.instruction |= 0x80;
12426 neon_two_same (0, 1, et.size / 2);
12427 }
12428
12429 static void
12430 do_neon_qmovun (void)
12431 {
12432 struct neon_type_el et = neon_check_type (2, NS_DQ,
12433 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12434 /* Saturating move with unsigned results. Operands must be signed. */
12435 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12436 neon_two_same (0, 1, et.size / 2);
12437 }
12438
12439 static void
12440 do_neon_rshift_sat_narrow (void)
12441 {
12442 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12443 or unsigned. If operands are unsigned, results must also be unsigned. */
12444 struct neon_type_el et = neon_check_type (2, NS_DQI,
12445 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12446 int imm = inst.operands[2].imm;
12447 /* This gets the bounds check, size encoding and immediate bits calculation
12448 right. */
12449 et.size /= 2;
12450
12451 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
12452 VQMOVN.I<size> <Dd>, <Qm>. */
12453 if (imm == 0)
12454 {
12455 inst.operands[2].present = 0;
12456 inst.instruction = N_MNEM_vqmovn;
12457 do_neon_qmovn ();
12458 return;
12459 }
12460
12461 constraint (imm < 1 || (unsigned)imm > et.size,
12462 _("immediate out of range"));
12463 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
12464 }
12465
12466 static void
12467 do_neon_rshift_sat_narrow_u (void)
12468 {
12469 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12470 or unsigned. If operands are unsigned, results must also be unsigned. */
12471 struct neon_type_el et = neon_check_type (2, NS_DQI,
12472 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12473 int imm = inst.operands[2].imm;
12474 /* This gets the bounds check, size encoding and immediate bits calculation
12475 right. */
12476 et.size /= 2;
12477
12478 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
12479 VQMOVUN.I<size> <Dd>, <Qm>. */
12480 if (imm == 0)
12481 {
12482 inst.operands[2].present = 0;
12483 inst.instruction = N_MNEM_vqmovun;
12484 do_neon_qmovun ();
12485 return;
12486 }
12487
12488 constraint (imm < 1 || (unsigned)imm > et.size,
12489 _("immediate out of range"));
12490 /* FIXME: The manual is kind of unclear about what value U should have in
12491 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
12492 must be 1. */
12493 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
12494 }
12495
12496 static void
12497 do_neon_movn (void)
12498 {
12499 struct neon_type_el et = neon_check_type (2, NS_DQ,
12500 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12501 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12502 neon_two_same (0, 1, et.size / 2);
12503 }
12504
12505 static void
12506 do_neon_rshift_narrow (void)
12507 {
12508 struct neon_type_el et = neon_check_type (2, NS_DQI,
12509 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12510 int imm = inst.operands[2].imm;
12511 /* This gets the bounds check, size encoding and immediate bits calculation
12512 right. */
12513 et.size /= 2;
12514
12515 /* If immediate is zero then we are a pseudo-instruction for
12516 VMOVN.I<size> <Dd>, <Qm> */
12517 if (imm == 0)
12518 {
12519 inst.operands[2].present = 0;
12520 inst.instruction = N_MNEM_vmovn;
12521 do_neon_movn ();
12522 return;
12523 }
12524
12525 constraint (imm < 1 || (unsigned)imm > et.size,
12526 _("immediate out of range for narrowing operation"));
12527 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
12528 }
12529
12530 static void
12531 do_neon_shll (void)
12532 {
12533 /* FIXME: Type checking when lengthening. */
12534 struct neon_type_el et = neon_check_type (2, NS_QDI,
12535 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
12536 unsigned imm = inst.operands[2].imm;
12537
12538 if (imm == et.size)
12539 {
12540 /* Maximum shift variant. */
12541 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12542 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12543 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12544 inst.instruction |= LOW4 (inst.operands[1].reg);
12545 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12546 inst.instruction |= neon_logbits (et.size) << 18;
12547
12548 inst.instruction = neon_dp_fixup (inst.instruction);
12549 }
12550 else
12551 {
12552 /* A more-specific type check for non-max versions. */
12553 et = neon_check_type (2, NS_QDI,
12554 N_EQK | N_DBL, N_SU_32 | N_KEY);
12555 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12556 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
12557 }
12558 }
12559
12560 /* Check the various types for the VCVT instruction, and return which version
12561 the current instruction is. */
12562
12563 static int
12564 neon_cvt_flavour (enum neon_shape rs)
12565 {
12566 #define CVT_VAR(C,X,Y) \
12567 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
12568 if (et.type != NT_invtype) \
12569 { \
12570 inst.error = NULL; \
12571 return (C); \
12572 }
12573 struct neon_type_el et;
12574 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
12575 || rs == NS_FF) ? N_VFP : 0;
12576 /* The instruction versions which take an immediate take one register
12577 argument, which is extended to the width of the full register. Thus the
12578 "source" and "destination" registers must have the same width. Hack that
12579 here by making the size equal to the key (wider, in this case) operand. */
12580 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
12581
12582 CVT_VAR (0, N_S32, N_F32);
12583 CVT_VAR (1, N_U32, N_F32);
12584 CVT_VAR (2, N_F32, N_S32);
12585 CVT_VAR (3, N_F32, N_U32);
12586
12587 whole_reg = N_VFP;
12588
12589 /* VFP instructions. */
12590 CVT_VAR (4, N_F32, N_F64);
12591 CVT_VAR (5, N_F64, N_F32);
12592 CVT_VAR (6, N_S32, N_F64 | key);
12593 CVT_VAR (7, N_U32, N_F64 | key);
12594 CVT_VAR (8, N_F64 | key, N_S32);
12595 CVT_VAR (9, N_F64 | key, N_U32);
12596 /* VFP instructions with bitshift. */
12597 CVT_VAR (10, N_F32 | key, N_S16);
12598 CVT_VAR (11, N_F32 | key, N_U16);
12599 CVT_VAR (12, N_F64 | key, N_S16);
12600 CVT_VAR (13, N_F64 | key, N_U16);
12601 CVT_VAR (14, N_S16, N_F32 | key);
12602 CVT_VAR (15, N_U16, N_F32 | key);
12603 CVT_VAR (16, N_S16, N_F64 | key);
12604 CVT_VAR (17, N_U16, N_F64 | key);
12605
12606 return -1;
12607 #undef CVT_VAR
12608 }
12609
12610 /* Neon-syntax VFP conversions. */
12611
12612 static void
12613 do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
12614 {
12615 const char *opname = 0;
12616
12617 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
12618 {
12619 /* Conversions with immediate bitshift. */
12620 const char *enc[] =
12621 {
12622 "ftosls",
12623 "ftouls",
12624 "fsltos",
12625 "fultos",
12626 NULL,
12627 NULL,
12628 "ftosld",
12629 "ftould",
12630 "fsltod",
12631 "fultod",
12632 "fshtos",
12633 "fuhtos",
12634 "fshtod",
12635 "fuhtod",
12636 "ftoshs",
12637 "ftouhs",
12638 "ftoshd",
12639 "ftouhd"
12640 };
12641
12642 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12643 {
12644 opname = enc[flavour];
12645 constraint (inst.operands[0].reg != inst.operands[1].reg,
12646 _("operands 0 and 1 must be the same register"));
12647 inst.operands[1] = inst.operands[2];
12648 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
12649 }
12650 }
12651 else
12652 {
12653 /* Conversions without bitshift. */
12654 const char *enc[] =
12655 {
12656 "ftosis",
12657 "ftouis",
12658 "fsitos",
12659 "fuitos",
12660 "fcvtsd",
12661 "fcvtds",
12662 "ftosid",
12663 "ftouid",
12664 "fsitod",
12665 "fuitod"
12666 };
12667
12668 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12669 opname = enc[flavour];
12670 }
12671
12672 if (opname)
12673 do_vfp_nsyn_opcode (opname);
12674 }
12675
12676 static void
12677 do_vfp_nsyn_cvtz (void)
12678 {
12679 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
12680 int flavour = neon_cvt_flavour (rs);
12681 const char *enc[] =
12682 {
12683 "ftosizs",
12684 "ftouizs",
12685 NULL,
12686 NULL,
12687 NULL,
12688 NULL,
12689 "ftosizd",
12690 "ftouizd"
12691 };
12692
12693 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
12694 do_vfp_nsyn_opcode (enc[flavour]);
12695 }
12696
12697 static void
12698 do_neon_cvt (void)
12699 {
12700 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
12701 NS_FD, NS_DF, NS_FF, NS_NULL);
12702 int flavour = neon_cvt_flavour (rs);
12703
12704 /* VFP rather than Neon conversions. */
12705 if (flavour >= 4)
12706 {
12707 do_vfp_nsyn_cvt (rs, flavour);
12708 return;
12709 }
12710
12711 switch (rs)
12712 {
12713 case NS_DDI:
12714 case NS_QQI:
12715 {
12716 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12717 return;
12718
12719 /* Fixed-point conversion with #0 immediate is encoded as an
12720 integer conversion. */
12721 if (inst.operands[2].present && inst.operands[2].imm == 0)
12722 goto int_encode;
12723 unsigned immbits = 32 - inst.operands[2].imm;
12724 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
12725 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12726 if (flavour != -1)
12727 inst.instruction |= enctab[flavour];
12728 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12729 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12730 inst.instruction |= LOW4 (inst.operands[1].reg);
12731 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12732 inst.instruction |= neon_quad (rs) << 6;
12733 inst.instruction |= 1 << 21;
12734 inst.instruction |= immbits << 16;
12735
12736 inst.instruction = neon_dp_fixup (inst.instruction);
12737 }
12738 break;
12739
12740 case NS_DD:
12741 case NS_QQ:
12742 int_encode:
12743 {
12744 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
12745
12746 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12747
12748 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12749 return;
12750
12751 if (flavour != -1)
12752 inst.instruction |= enctab[flavour];
12753
12754 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12755 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12756 inst.instruction |= LOW4 (inst.operands[1].reg);
12757 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12758 inst.instruction |= neon_quad (rs) << 6;
12759 inst.instruction |= 2 << 18;
12760
12761 inst.instruction = neon_dp_fixup (inst.instruction);
12762 }
12763 break;
12764
12765 default:
12766 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
12767 do_vfp_nsyn_cvt (rs, flavour);
12768 }
12769 }
12770
12771 static void
12772 neon_move_immediate (void)
12773 {
12774 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
12775 struct neon_type_el et = neon_check_type (2, rs,
12776 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
12777 unsigned immlo, immhi = 0, immbits;
12778 int op, cmode, float_p;
12779
12780 constraint (et.type == NT_invtype,
12781 _("operand size must be specified for immediate VMOV"));
12782
12783 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
12784 op = (inst.instruction & (1 << 5)) != 0;
12785
12786 immlo = inst.operands[1].imm;
12787 if (inst.operands[1].regisimm)
12788 immhi = inst.operands[1].reg;
12789
12790 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
12791 _("immediate has bits set outside the operand size"));
12792
12793 float_p = inst.operands[1].immisfloat;
12794
12795 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
12796 et.size, et.type)) == FAIL)
12797 {
12798 /* Invert relevant bits only. */
12799 neon_invert_size (&immlo, &immhi, et.size);
12800 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
12801 with one or the other; those cases are caught by
12802 neon_cmode_for_move_imm. */
12803 op = !op;
12804 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
12805 &op, et.size, et.type)) == FAIL)
12806 {
12807 first_error (_("immediate out of range"));
12808 return;
12809 }
12810 }
12811
12812 inst.instruction &= ~(1 << 5);
12813 inst.instruction |= op << 5;
12814
12815 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12816 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12817 inst.instruction |= neon_quad (rs) << 6;
12818 inst.instruction |= cmode << 8;
12819
12820 neon_write_immbits (immbits);
12821 }
12822
12823 static void
12824 do_neon_mvn (void)
12825 {
12826 if (inst.operands[1].isreg)
12827 {
12828 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12829
12830 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12831 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12832 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12833 inst.instruction |= LOW4 (inst.operands[1].reg);
12834 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12835 inst.instruction |= neon_quad (rs) << 6;
12836 }
12837 else
12838 {
12839 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12840 neon_move_immediate ();
12841 }
12842
12843 inst.instruction = neon_dp_fixup (inst.instruction);
12844 }
12845
12846 /* Encode instructions of form:
12847
12848 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12849 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
12850
12851 static void
12852 neon_mixed_length (struct neon_type_el et, unsigned size)
12853 {
12854 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12855 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12856 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12857 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12858 inst.instruction |= LOW4 (inst.operands[2].reg);
12859 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12860 inst.instruction |= (et.type == NT_unsigned) << 24;
12861 inst.instruction |= neon_logbits (size) << 20;
12862
12863 inst.instruction = neon_dp_fixup (inst.instruction);
12864 }
12865
12866 static void
12867 do_neon_dyadic_long (void)
12868 {
12869 /* FIXME: Type checking for lengthening op. */
12870 struct neon_type_el et = neon_check_type (3, NS_QDD,
12871 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
12872 neon_mixed_length (et, et.size);
12873 }
12874
12875 static void
12876 do_neon_abal (void)
12877 {
12878 struct neon_type_el et = neon_check_type (3, NS_QDD,
12879 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
12880 neon_mixed_length (et, et.size);
12881 }
12882
12883 static void
12884 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
12885 {
12886 if (inst.operands[2].isscalar)
12887 {
12888 struct neon_type_el et = neon_check_type (3, NS_QDS,
12889 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
12890 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12891 neon_mul_mac (et, et.type == NT_unsigned);
12892 }
12893 else
12894 {
12895 struct neon_type_el et = neon_check_type (3, NS_QDD,
12896 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
12897 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12898 neon_mixed_length (et, et.size);
12899 }
12900 }
12901
12902 static void
12903 do_neon_mac_maybe_scalar_long (void)
12904 {
12905 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
12906 }
12907
12908 static void
12909 do_neon_dyadic_wide (void)
12910 {
12911 struct neon_type_el et = neon_check_type (3, NS_QQD,
12912 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
12913 neon_mixed_length (et, et.size);
12914 }
12915
12916 static void
12917 do_neon_dyadic_narrow (void)
12918 {
12919 struct neon_type_el et = neon_check_type (3, NS_QDD,
12920 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
12921 /* Operand sign is unimportant, and the U bit is part of the opcode,
12922 so force the operand type to integer. */
12923 et.type = NT_integer;
12924 neon_mixed_length (et, et.size / 2);
12925 }
12926
12927 static void
12928 do_neon_mul_sat_scalar_long (void)
12929 {
12930 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
12931 }
12932
12933 static void
12934 do_neon_vmull (void)
12935 {
12936 if (inst.operands[2].isscalar)
12937 do_neon_mac_maybe_scalar_long ();
12938 else
12939 {
12940 struct neon_type_el et = neon_check_type (3, NS_QDD,
12941 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
12942 if (et.type == NT_poly)
12943 inst.instruction = NEON_ENC_POLY (inst.instruction);
12944 else
12945 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12946 /* For polynomial encoding, size field must be 0b00 and the U bit must be
12947 zero. Should be OK as-is. */
12948 neon_mixed_length (et, et.size);
12949 }
12950 }
12951
12952 static void
12953 do_neon_ext (void)
12954 {
12955 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
12956 struct neon_type_el et = neon_check_type (3, rs,
12957 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12958 unsigned imm = (inst.operands[3].imm * et.size) / 8;
12959 constraint (imm >= (neon_quad (rs) ? 16 : 8), _("shift out of range"));
12960 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12961 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12962 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12963 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12964 inst.instruction |= LOW4 (inst.operands[2].reg);
12965 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12966 inst.instruction |= neon_quad (rs) << 6;
12967 inst.instruction |= imm << 8;
12968
12969 inst.instruction = neon_dp_fixup (inst.instruction);
12970 }
12971
12972 static void
12973 do_neon_rev (void)
12974 {
12975 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12976 struct neon_type_el et = neon_check_type (2, rs,
12977 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12978 unsigned op = (inst.instruction >> 7) & 3;
12979 /* N (width of reversed regions) is encoded as part of the bitmask. We
12980 extract it here to check the elements to be reversed are smaller.
12981 Otherwise we'd get a reserved instruction. */
12982 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
12983 assert (elsize != 0);
12984 constraint (et.size >= elsize,
12985 _("elements must be smaller than reversal region"));
12986 neon_two_same (neon_quad (rs), 1, et.size);
12987 }
12988
12989 static void
12990 do_neon_dup (void)
12991 {
12992 if (inst.operands[1].isscalar)
12993 {
12994 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
12995 struct neon_type_el et = neon_check_type (2, rs,
12996 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12997 unsigned sizebits = et.size >> 3;
12998 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
12999 int logsize = neon_logbits (et.size);
13000 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
13001
13002 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
13003 return;
13004
13005 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13006 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13007 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13008 inst.instruction |= LOW4 (dm);
13009 inst.instruction |= HI1 (dm) << 5;
13010 inst.instruction |= neon_quad (rs) << 6;
13011 inst.instruction |= x << 17;
13012 inst.instruction |= sizebits << 16;
13013
13014 inst.instruction = neon_dp_fixup (inst.instruction);
13015 }
13016 else
13017 {
13018 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
13019 struct neon_type_el et = neon_check_type (2, rs,
13020 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13021 /* Duplicate ARM register to lanes of vector. */
13022 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
13023 switch (et.size)
13024 {
13025 case 8: inst.instruction |= 0x400000; break;
13026 case 16: inst.instruction |= 0x000020; break;
13027 case 32: inst.instruction |= 0x000000; break;
13028 default: break;
13029 }
13030 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13031 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
13032 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
13033 inst.instruction |= neon_quad (rs) << 21;
13034 /* The encoding for this instruction is identical for the ARM and Thumb
13035 variants, except for the condition field. */
13036 do_vfp_cond_or_thumb ();
13037 }
13038 }
13039
13040 /* VMOV has particularly many variations. It can be one of:
13041 0. VMOV<c><q> <Qd>, <Qm>
13042 1. VMOV<c><q> <Dd>, <Dm>
13043 (Register operations, which are VORR with Rm = Rn.)
13044 2. VMOV<c><q>.<dt> <Qd>, #<imm>
13045 3. VMOV<c><q>.<dt> <Dd>, #<imm>
13046 (Immediate loads.)
13047 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
13048 (ARM register to scalar.)
13049 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
13050 (Two ARM registers to vector.)
13051 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
13052 (Scalar to ARM register.)
13053 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
13054 (Vector to two ARM registers.)
13055 8. VMOV.F32 <Sd>, <Sm>
13056 9. VMOV.F64 <Dd>, <Dm>
13057 (VFP register moves.)
13058 10. VMOV.F32 <Sd>, #imm
13059 11. VMOV.F64 <Dd>, #imm
13060 (VFP float immediate load.)
13061 12. VMOV <Rd>, <Sm>
13062 (VFP single to ARM reg.)
13063 13. VMOV <Sd>, <Rm>
13064 (ARM reg to VFP single.)
13065 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
13066 (Two ARM regs to two VFP singles.)
13067 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
13068 (Two VFP singles to two ARM regs.)
13069
13070 These cases can be disambiguated using neon_select_shape, except cases 1/9
13071 and 3/11 which depend on the operand type too.
13072
13073 All the encoded bits are hardcoded by this function.
13074
13075 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
13076 Cases 5, 7 may be used with VFPv2 and above.
13077
13078 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
13079 can specify a type where it doesn't make sense to, and is ignored). */
13080
13081 static void
13082 do_neon_mov (void)
13083 {
13084 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
13085 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
13086 NS_NULL);
13087 struct neon_type_el et;
13088 const char *ldconst = 0;
13089
13090 switch (rs)
13091 {
13092 case NS_DD: /* case 1/9. */
13093 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13094 /* It is not an error here if no type is given. */
13095 inst.error = NULL;
13096 if (et.type == NT_float && et.size == 64)
13097 {
13098 do_vfp_nsyn_opcode ("fcpyd");
13099 break;
13100 }
13101 /* fall through. */
13102
13103 case NS_QQ: /* case 0/1. */
13104 {
13105 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13106 return;
13107 /* The architecture manual I have doesn't explicitly state which
13108 value the U bit should have for register->register moves, but
13109 the equivalent VORR instruction has U = 0, so do that. */
13110 inst.instruction = 0x0200110;
13111 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13112 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13113 inst.instruction |= LOW4 (inst.operands[1].reg);
13114 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13115 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13116 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13117 inst.instruction |= neon_quad (rs) << 6;
13118
13119 inst.instruction = neon_dp_fixup (inst.instruction);
13120 }
13121 break;
13122
13123 case NS_DI: /* case 3/11. */
13124 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13125 inst.error = NULL;
13126 if (et.type == NT_float && et.size == 64)
13127 {
13128 /* case 11 (fconstd). */
13129 ldconst = "fconstd";
13130 goto encode_fconstd;
13131 }
13132 /* fall through. */
13133
13134 case NS_QI: /* case 2/3. */
13135 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13136 return;
13137 inst.instruction = 0x0800010;
13138 neon_move_immediate ();
13139 inst.instruction = neon_dp_fixup (inst.instruction);
13140 break;
13141
13142 case NS_SR: /* case 4. */
13143 {
13144 unsigned bcdebits = 0;
13145 struct neon_type_el et = neon_check_type (2, NS_NULL,
13146 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13147 int logsize = neon_logbits (et.size);
13148 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
13149 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
13150
13151 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13152 _(BAD_FPU));
13153 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13154 && et.size != 32, _(BAD_FPU));
13155 constraint (et.type == NT_invtype, _("bad type for scalar"));
13156 constraint (x >= 64 / et.size, _("scalar index out of range"));
13157
13158 switch (et.size)
13159 {
13160 case 8: bcdebits = 0x8; break;
13161 case 16: bcdebits = 0x1; break;
13162 case 32: bcdebits = 0x0; break;
13163 default: ;
13164 }
13165
13166 bcdebits |= x << logsize;
13167
13168 inst.instruction = 0xe000b10;
13169 do_vfp_cond_or_thumb ();
13170 inst.instruction |= LOW4 (dn) << 16;
13171 inst.instruction |= HI1 (dn) << 7;
13172 inst.instruction |= inst.operands[1].reg << 12;
13173 inst.instruction |= (bcdebits & 3) << 5;
13174 inst.instruction |= (bcdebits >> 2) << 21;
13175 }
13176 break;
13177
13178 case NS_DRR: /* case 5 (fmdrr). */
13179 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13180 _(BAD_FPU));
13181
13182 inst.instruction = 0xc400b10;
13183 do_vfp_cond_or_thumb ();
13184 inst.instruction |= LOW4 (inst.operands[0].reg);
13185 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
13186 inst.instruction |= inst.operands[1].reg << 12;
13187 inst.instruction |= inst.operands[2].reg << 16;
13188 break;
13189
13190 case NS_RS: /* case 6. */
13191 {
13192 struct neon_type_el et = neon_check_type (2, NS_NULL,
13193 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
13194 unsigned logsize = neon_logbits (et.size);
13195 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
13196 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
13197 unsigned abcdebits = 0;
13198
13199 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13200 _(BAD_FPU));
13201 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13202 && et.size != 32, _(BAD_FPU));
13203 constraint (et.type == NT_invtype, _("bad type for scalar"));
13204 constraint (x >= 64 / et.size, _("scalar index out of range"));
13205
13206 switch (et.size)
13207 {
13208 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
13209 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
13210 case 32: abcdebits = 0x00; break;
13211 default: ;
13212 }
13213
13214 abcdebits |= x << logsize;
13215 inst.instruction = 0xe100b10;
13216 do_vfp_cond_or_thumb ();
13217 inst.instruction |= LOW4 (dn) << 16;
13218 inst.instruction |= HI1 (dn) << 7;
13219 inst.instruction |= inst.operands[0].reg << 12;
13220 inst.instruction |= (abcdebits & 3) << 5;
13221 inst.instruction |= (abcdebits >> 2) << 21;
13222 }
13223 break;
13224
13225 case NS_RRD: /* case 7 (fmrrd). */
13226 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13227 _(BAD_FPU));
13228
13229 inst.instruction = 0xc500b10;
13230 do_vfp_cond_or_thumb ();
13231 inst.instruction |= inst.operands[0].reg << 12;
13232 inst.instruction |= inst.operands[1].reg << 16;
13233 inst.instruction |= LOW4 (inst.operands[2].reg);
13234 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13235 break;
13236
13237 case NS_FF: /* case 8 (fcpys). */
13238 do_vfp_nsyn_opcode ("fcpys");
13239 break;
13240
13241 case NS_FI: /* case 10 (fconsts). */
13242 ldconst = "fconsts";
13243 encode_fconstd:
13244 if (is_quarter_float (inst.operands[1].imm))
13245 {
13246 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
13247 do_vfp_nsyn_opcode (ldconst);
13248 }
13249 else
13250 first_error (_("immediate out of range"));
13251 break;
13252
13253 case NS_RF: /* case 12 (fmrs). */
13254 do_vfp_nsyn_opcode ("fmrs");
13255 break;
13256
13257 case NS_FR: /* case 13 (fmsr). */
13258 do_vfp_nsyn_opcode ("fmsr");
13259 break;
13260
13261 /* The encoders for the fmrrs and fmsrr instructions expect three operands
13262 (one of which is a list), but we have parsed four. Do some fiddling to
13263 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
13264 expect. */
13265 case NS_RRFF: /* case 14 (fmrrs). */
13266 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
13267 _("VFP registers must be adjacent"));
13268 inst.operands[2].imm = 2;
13269 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13270 do_vfp_nsyn_opcode ("fmrrs");
13271 break;
13272
13273 case NS_FFRR: /* case 15 (fmsrr). */
13274 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
13275 _("VFP registers must be adjacent"));
13276 inst.operands[1] = inst.operands[2];
13277 inst.operands[2] = inst.operands[3];
13278 inst.operands[0].imm = 2;
13279 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13280 do_vfp_nsyn_opcode ("fmsrr");
13281 break;
13282
13283 default:
13284 abort ();
13285 }
13286 }
13287
13288 static void
13289 do_neon_rshift_round_imm (void)
13290 {
13291 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13292 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
13293 int imm = inst.operands[2].imm;
13294
13295 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
13296 if (imm == 0)
13297 {
13298 inst.operands[2].present = 0;
13299 do_neon_mov ();
13300 return;
13301 }
13302
13303 constraint (imm < 1 || (unsigned)imm > et.size,
13304 _("immediate out of range for shift"));
13305 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
13306 et.size - imm);
13307 }
13308
13309 static void
13310 do_neon_movl (void)
13311 {
13312 struct neon_type_el et = neon_check_type (2, NS_QD,
13313 N_EQK | N_DBL, N_SU_32 | N_KEY);
13314 unsigned sizebits = et.size >> 3;
13315 inst.instruction |= sizebits << 19;
13316 neon_two_same (0, et.type == NT_unsigned, -1);
13317 }
13318
13319 static void
13320 do_neon_trn (void)
13321 {
13322 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13323 struct neon_type_el et = neon_check_type (2, rs,
13324 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13325 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13326 neon_two_same (neon_quad (rs), 1, et.size);
13327 }
13328
13329 static void
13330 do_neon_zip_uzp (void)
13331 {
13332 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13333 struct neon_type_el et = neon_check_type (2, rs,
13334 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13335 if (rs == NS_DD && et.size == 32)
13336 {
13337 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
13338 inst.instruction = N_MNEM_vtrn;
13339 do_neon_trn ();
13340 return;
13341 }
13342 neon_two_same (neon_quad (rs), 1, et.size);
13343 }
13344
13345 static void
13346 do_neon_sat_abs_neg (void)
13347 {
13348 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13349 struct neon_type_el et = neon_check_type (2, rs,
13350 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
13351 neon_two_same (neon_quad (rs), 1, et.size);
13352 }
13353
13354 static void
13355 do_neon_pair_long (void)
13356 {
13357 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13358 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
13359 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
13360 inst.instruction |= (et.type == NT_unsigned) << 7;
13361 neon_two_same (neon_quad (rs), 1, et.size);
13362 }
13363
13364 static void
13365 do_neon_recip_est (void)
13366 {
13367 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13368 struct neon_type_el et = neon_check_type (2, rs,
13369 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
13370 inst.instruction |= (et.type == NT_float) << 8;
13371 neon_two_same (neon_quad (rs), 1, et.size);
13372 }
13373
13374 static void
13375 do_neon_cls (void)
13376 {
13377 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13378 struct neon_type_el et = neon_check_type (2, rs,
13379 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
13380 neon_two_same (neon_quad (rs), 1, et.size);
13381 }
13382
13383 static void
13384 do_neon_clz (void)
13385 {
13386 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13387 struct neon_type_el et = neon_check_type (2, rs,
13388 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
13389 neon_two_same (neon_quad (rs), 1, et.size);
13390 }
13391
13392 static void
13393 do_neon_cnt (void)
13394 {
13395 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13396 struct neon_type_el et = neon_check_type (2, rs,
13397 N_EQK | N_INT, N_8 | N_KEY);
13398 neon_two_same (neon_quad (rs), 1, et.size);
13399 }
13400
13401 static void
13402 do_neon_swp (void)
13403 {
13404 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13405 neon_two_same (neon_quad (rs), 1, -1);
13406 }
13407
13408 static void
13409 do_neon_tbl_tbx (void)
13410 {
13411 unsigned listlenbits;
13412 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
13413
13414 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
13415 {
13416 first_error (_("bad list length for table lookup"));
13417 return;
13418 }
13419
13420 listlenbits = inst.operands[1].imm - 1;
13421 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13422 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13423 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13424 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13425 inst.instruction |= LOW4 (inst.operands[2].reg);
13426 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13427 inst.instruction |= listlenbits << 8;
13428
13429 inst.instruction = neon_dp_fixup (inst.instruction);
13430 }
13431
13432 static void
13433 do_neon_ldm_stm (void)
13434 {
13435 /* P, U and L bits are part of bitmask. */
13436 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
13437 unsigned offsetbits = inst.operands[1].imm * 2;
13438
13439 if (inst.operands[1].issingle)
13440 {
13441 do_vfp_nsyn_ldm_stm (is_dbmode);
13442 return;
13443 }
13444
13445 constraint (is_dbmode && !inst.operands[0].writeback,
13446 _("writeback (!) must be used for VLDMDB and VSTMDB"));
13447
13448 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
13449 _("register list must contain at least 1 and at most 16 "
13450 "registers"));
13451
13452 inst.instruction |= inst.operands[0].reg << 16;
13453 inst.instruction |= inst.operands[0].writeback << 21;
13454 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13455 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
13456
13457 inst.instruction |= offsetbits;
13458
13459 do_vfp_cond_or_thumb ();
13460 }
13461
13462 static void
13463 do_neon_ldr_str (void)
13464 {
13465 int is_ldr = (inst.instruction & (1 << 20)) != 0;
13466
13467 if (inst.operands[0].issingle)
13468 {
13469 if (is_ldr)
13470 do_vfp_nsyn_opcode ("flds");
13471 else
13472 do_vfp_nsyn_opcode ("fsts");
13473 }
13474 else
13475 {
13476 if (is_ldr)
13477 do_vfp_nsyn_opcode ("fldd");
13478 else
13479 do_vfp_nsyn_opcode ("fstd");
13480 }
13481 }
13482
13483 /* "interleave" version also handles non-interleaving register VLD1/VST1
13484 instructions. */
13485
13486 static void
13487 do_neon_ld_st_interleave (void)
13488 {
13489 struct neon_type_el et = neon_check_type (1, NS_NULL,
13490 N_8 | N_16 | N_32 | N_64);
13491 unsigned alignbits = 0;
13492 unsigned idx;
13493 /* The bits in this table go:
13494 0: register stride of one (0) or two (1)
13495 1,2: register list length, minus one (1, 2, 3, 4).
13496 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
13497 We use -1 for invalid entries. */
13498 const int typetable[] =
13499 {
13500 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
13501 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
13502 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
13503 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
13504 };
13505 int typebits;
13506
13507 if (et.type == NT_invtype)
13508 return;
13509
13510 if (inst.operands[1].immisalign)
13511 switch (inst.operands[1].imm >> 8)
13512 {
13513 case 64: alignbits = 1; break;
13514 case 128:
13515 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13516 goto bad_alignment;
13517 alignbits = 2;
13518 break;
13519 case 256:
13520 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13521 goto bad_alignment;
13522 alignbits = 3;
13523 break;
13524 default:
13525 bad_alignment:
13526 first_error (_("bad alignment"));
13527 return;
13528 }
13529
13530 inst.instruction |= alignbits << 4;
13531 inst.instruction |= neon_logbits (et.size) << 6;
13532
13533 /* Bits [4:6] of the immediate in a list specifier encode register stride
13534 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
13535 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
13536 up the right value for "type" in a table based on this value and the given
13537 list style, then stick it back. */
13538 idx = ((inst.operands[0].imm >> 4) & 7)
13539 | (((inst.instruction >> 8) & 3) << 3);
13540
13541 typebits = typetable[idx];
13542
13543 constraint (typebits == -1, _("bad list type for instruction"));
13544
13545 inst.instruction &= ~0xf00;
13546 inst.instruction |= typebits << 8;
13547 }
13548
13549 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
13550 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
13551 otherwise. The variable arguments are a list of pairs of legal (size, align)
13552 values, terminated with -1. */
13553
13554 static int
13555 neon_alignment_bit (int size, int align, int *do_align, ...)
13556 {
13557 va_list ap;
13558 int result = FAIL, thissize, thisalign;
13559
13560 if (!inst.operands[1].immisalign)
13561 {
13562 *do_align = 0;
13563 return SUCCESS;
13564 }
13565
13566 va_start (ap, do_align);
13567
13568 do
13569 {
13570 thissize = va_arg (ap, int);
13571 if (thissize == -1)
13572 break;
13573 thisalign = va_arg (ap, int);
13574
13575 if (size == thissize && align == thisalign)
13576 result = SUCCESS;
13577 }
13578 while (result != SUCCESS);
13579
13580 va_end (ap);
13581
13582 if (result == SUCCESS)
13583 *do_align = 1;
13584 else
13585 first_error (_("unsupported alignment for instruction"));
13586
13587 return result;
13588 }
13589
13590 static void
13591 do_neon_ld_st_lane (void)
13592 {
13593 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
13594 int align_good, do_align = 0;
13595 int logsize = neon_logbits (et.size);
13596 int align = inst.operands[1].imm >> 8;
13597 int n = (inst.instruction >> 8) & 3;
13598 int max_el = 64 / et.size;
13599
13600 if (et.type == NT_invtype)
13601 return;
13602
13603 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
13604 _("bad list length"));
13605 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
13606 _("scalar index out of range"));
13607 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
13608 && et.size == 8,
13609 _("stride of 2 unavailable when element size is 8"));
13610
13611 switch (n)
13612 {
13613 case 0: /* VLD1 / VST1. */
13614 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
13615 32, 32, -1);
13616 if (align_good == FAIL)
13617 return;
13618 if (do_align)
13619 {
13620 unsigned alignbits = 0;
13621 switch (et.size)
13622 {
13623 case 16: alignbits = 0x1; break;
13624 case 32: alignbits = 0x3; break;
13625 default: ;
13626 }
13627 inst.instruction |= alignbits << 4;
13628 }
13629 break;
13630
13631 case 1: /* VLD2 / VST2. */
13632 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
13633 32, 64, -1);
13634 if (align_good == FAIL)
13635 return;
13636 if (do_align)
13637 inst.instruction |= 1 << 4;
13638 break;
13639
13640 case 2: /* VLD3 / VST3. */
13641 constraint (inst.operands[1].immisalign,
13642 _("can't use alignment with this instruction"));
13643 break;
13644
13645 case 3: /* VLD4 / VST4. */
13646 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13647 16, 64, 32, 64, 32, 128, -1);
13648 if (align_good == FAIL)
13649 return;
13650 if (do_align)
13651 {
13652 unsigned alignbits = 0;
13653 switch (et.size)
13654 {
13655 case 8: alignbits = 0x1; break;
13656 case 16: alignbits = 0x1; break;
13657 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
13658 default: ;
13659 }
13660 inst.instruction |= alignbits << 4;
13661 }
13662 break;
13663
13664 default: ;
13665 }
13666
13667 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
13668 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13669 inst.instruction |= 1 << (4 + logsize);
13670
13671 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
13672 inst.instruction |= logsize << 10;
13673 }
13674
13675 /* Encode single n-element structure to all lanes VLD<n> instructions. */
13676
13677 static void
13678 do_neon_ld_dup (void)
13679 {
13680 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
13681 int align_good, do_align = 0;
13682
13683 if (et.type == NT_invtype)
13684 return;
13685
13686 switch ((inst.instruction >> 8) & 3)
13687 {
13688 case 0: /* VLD1. */
13689 assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
13690 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13691 &do_align, 16, 16, 32, 32, -1);
13692 if (align_good == FAIL)
13693 return;
13694 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
13695 {
13696 case 1: break;
13697 case 2: inst.instruction |= 1 << 5; break;
13698 default: first_error (_("bad list length")); return;
13699 }
13700 inst.instruction |= neon_logbits (et.size) << 6;
13701 break;
13702
13703 case 1: /* VLD2. */
13704 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13705 &do_align, 8, 16, 16, 32, 32, 64, -1);
13706 if (align_good == FAIL)
13707 return;
13708 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
13709 _("bad list length"));
13710 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13711 inst.instruction |= 1 << 5;
13712 inst.instruction |= neon_logbits (et.size) << 6;
13713 break;
13714
13715 case 2: /* VLD3. */
13716 constraint (inst.operands[1].immisalign,
13717 _("can't use alignment with this instruction"));
13718 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
13719 _("bad list length"));
13720 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13721 inst.instruction |= 1 << 5;
13722 inst.instruction |= neon_logbits (et.size) << 6;
13723 break;
13724
13725 case 3: /* VLD4. */
13726 {
13727 int align = inst.operands[1].imm >> 8;
13728 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13729 16, 64, 32, 64, 32, 128, -1);
13730 if (align_good == FAIL)
13731 return;
13732 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
13733 _("bad list length"));
13734 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13735 inst.instruction |= 1 << 5;
13736 if (et.size == 32 && align == 128)
13737 inst.instruction |= 0x3 << 6;
13738 else
13739 inst.instruction |= neon_logbits (et.size) << 6;
13740 }
13741 break;
13742
13743 default: ;
13744 }
13745
13746 inst.instruction |= do_align << 4;
13747 }
13748
13749 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
13750 apart from bits [11:4]. */
13751
13752 static void
13753 do_neon_ldx_stx (void)
13754 {
13755 switch (NEON_LANE (inst.operands[0].imm))
13756 {
13757 case NEON_INTERLEAVE_LANES:
13758 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
13759 do_neon_ld_st_interleave ();
13760 break;
13761
13762 case NEON_ALL_LANES:
13763 inst.instruction = NEON_ENC_DUP (inst.instruction);
13764 do_neon_ld_dup ();
13765 break;
13766
13767 default:
13768 inst.instruction = NEON_ENC_LANE (inst.instruction);
13769 do_neon_ld_st_lane ();
13770 }
13771
13772 /* L bit comes from bit mask. */
13773 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13774 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13775 inst.instruction |= inst.operands[1].reg << 16;
13776
13777 if (inst.operands[1].postind)
13778 {
13779 int postreg = inst.operands[1].imm & 0xf;
13780 constraint (!inst.operands[1].immisreg,
13781 _("post-index must be a register"));
13782 constraint (postreg == 0xd || postreg == 0xf,
13783 _("bad register for post-index"));
13784 inst.instruction |= postreg;
13785 }
13786 else if (inst.operands[1].writeback)
13787 {
13788 inst.instruction |= 0xd;
13789 }
13790 else
13791 inst.instruction |= 0xf;
13792
13793 if (thumb_mode)
13794 inst.instruction |= 0xf9000000;
13795 else
13796 inst.instruction |= 0xf4000000;
13797 }
13798 \f
13799 /* Overall per-instruction processing. */
13800
13801 /* We need to be able to fix up arbitrary expressions in some statements.
13802 This is so that we can handle symbols that are an arbitrary distance from
13803 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
13804 which returns part of an address in a form which will be valid for
13805 a data instruction. We do this by pushing the expression into a symbol
13806 in the expr_section, and creating a fix for that. */
13807
13808 static void
13809 fix_new_arm (fragS * frag,
13810 int where,
13811 short int size,
13812 expressionS * exp,
13813 int pc_rel,
13814 int reloc)
13815 {
13816 fixS * new_fix;
13817
13818 switch (exp->X_op)
13819 {
13820 case O_constant:
13821 case O_symbol:
13822 case O_add:
13823 case O_subtract:
13824 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
13825 break;
13826
13827 default:
13828 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
13829 pc_rel, reloc);
13830 break;
13831 }
13832
13833 /* Mark whether the fix is to a THUMB instruction, or an ARM
13834 instruction. */
13835 new_fix->tc_fix_data = thumb_mode;
13836 }
13837
13838 /* Create a frg for an instruction requiring relaxation. */
13839 static void
13840 output_relax_insn (void)
13841 {
13842 char * to;
13843 symbolS *sym;
13844 int offset;
13845
13846 /* The size of the instruction is unknown, so tie the debug info to the
13847 start of the instruction. */
13848 dwarf2_emit_insn (0);
13849
13850 switch (inst.reloc.exp.X_op)
13851 {
13852 case O_symbol:
13853 sym = inst.reloc.exp.X_add_symbol;
13854 offset = inst.reloc.exp.X_add_number;
13855 break;
13856 case O_constant:
13857 sym = NULL;
13858 offset = inst.reloc.exp.X_add_number;
13859 break;
13860 default:
13861 sym = make_expr_symbol (&inst.reloc.exp);
13862 offset = 0;
13863 break;
13864 }
13865 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
13866 inst.relax, sym, offset, NULL/*offset, opcode*/);
13867 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
13868 }
13869
13870 /* Write a 32-bit thumb instruction to buf. */
13871 static void
13872 put_thumb32_insn (char * buf, unsigned long insn)
13873 {
13874 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
13875 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
13876 }
13877
13878 static void
13879 output_inst (const char * str)
13880 {
13881 char * to = NULL;
13882
13883 if (inst.error)
13884 {
13885 as_bad ("%s -- `%s'", inst.error, str);
13886 return;
13887 }
13888 if (inst.relax)
13889 {
13890 output_relax_insn ();
13891 return;
13892 }
13893 if (inst.size == 0)
13894 return;
13895
13896 to = frag_more (inst.size);
13897
13898 if (thumb_mode && (inst.size > THUMB_SIZE))
13899 {
13900 assert (inst.size == (2 * THUMB_SIZE));
13901 put_thumb32_insn (to, inst.instruction);
13902 }
13903 else if (inst.size > INSN_SIZE)
13904 {
13905 assert (inst.size == (2 * INSN_SIZE));
13906 md_number_to_chars (to, inst.instruction, INSN_SIZE);
13907 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
13908 }
13909 else
13910 md_number_to_chars (to, inst.instruction, inst.size);
13911
13912 if (inst.reloc.type != BFD_RELOC_UNUSED)
13913 fix_new_arm (frag_now, to - frag_now->fr_literal,
13914 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
13915 inst.reloc.type);
13916
13917 dwarf2_emit_insn (inst.size);
13918 }
13919
13920 /* Tag values used in struct asm_opcode's tag field. */
13921 enum opcode_tag
13922 {
13923 OT_unconditional, /* Instruction cannot be conditionalized.
13924 The ARM condition field is still 0xE. */
13925 OT_unconditionalF, /* Instruction cannot be conditionalized
13926 and carries 0xF in its ARM condition field. */
13927 OT_csuffix, /* Instruction takes a conditional suffix. */
13928 OT_csuffixF, /* Some forms of the instruction take a conditional
13929 suffix, others place 0xF where the condition field
13930 would be. */
13931 OT_cinfix3, /* Instruction takes a conditional infix,
13932 beginning at character index 3. (In
13933 unified mode, it becomes a suffix.) */
13934 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
13935 tsts, cmps, cmns, and teqs. */
13936 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
13937 character index 3, even in unified mode. Used for
13938 legacy instructions where suffix and infix forms
13939 may be ambiguous. */
13940 OT_csuf_or_in3, /* Instruction takes either a conditional
13941 suffix or an infix at character index 3. */
13942 OT_odd_infix_unc, /* This is the unconditional variant of an
13943 instruction that takes a conditional infix
13944 at an unusual position. In unified mode,
13945 this variant will accept a suffix. */
13946 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
13947 are the conditional variants of instructions that
13948 take conditional infixes in unusual positions.
13949 The infix appears at character index
13950 (tag - OT_odd_infix_0). These are not accepted
13951 in unified mode. */
13952 };
13953
13954 /* Subroutine of md_assemble, responsible for looking up the primary
13955 opcode from the mnemonic the user wrote. STR points to the
13956 beginning of the mnemonic.
13957
13958 This is not simply a hash table lookup, because of conditional
13959 variants. Most instructions have conditional variants, which are
13960 expressed with a _conditional affix_ to the mnemonic. If we were
13961 to encode each conditional variant as a literal string in the opcode
13962 table, it would have approximately 20,000 entries.
13963
13964 Most mnemonics take this affix as a suffix, and in unified syntax,
13965 'most' is upgraded to 'all'. However, in the divided syntax, some
13966 instructions take the affix as an infix, notably the s-variants of
13967 the arithmetic instructions. Of those instructions, all but six
13968 have the infix appear after the third character of the mnemonic.
13969
13970 Accordingly, the algorithm for looking up primary opcodes given
13971 an identifier is:
13972
13973 1. Look up the identifier in the opcode table.
13974 If we find a match, go to step U.
13975
13976 2. Look up the last two characters of the identifier in the
13977 conditions table. If we find a match, look up the first N-2
13978 characters of the identifier in the opcode table. If we
13979 find a match, go to step CE.
13980
13981 3. Look up the fourth and fifth characters of the identifier in
13982 the conditions table. If we find a match, extract those
13983 characters from the identifier, and look up the remaining
13984 characters in the opcode table. If we find a match, go
13985 to step CM.
13986
13987 4. Fail.
13988
13989 U. Examine the tag field of the opcode structure, in case this is
13990 one of the six instructions with its conditional infix in an
13991 unusual place. If it is, the tag tells us where to find the
13992 infix; look it up in the conditions table and set inst.cond
13993 accordingly. Otherwise, this is an unconditional instruction.
13994 Again set inst.cond accordingly. Return the opcode structure.
13995
13996 CE. Examine the tag field to make sure this is an instruction that
13997 should receive a conditional suffix. If it is not, fail.
13998 Otherwise, set inst.cond from the suffix we already looked up,
13999 and return the opcode structure.
14000
14001 CM. Examine the tag field to make sure this is an instruction that
14002 should receive a conditional infix after the third character.
14003 If it is not, fail. Otherwise, undo the edits to the current
14004 line of input and proceed as for case CE. */
14005
14006 static const struct asm_opcode *
14007 opcode_lookup (char **str)
14008 {
14009 char *end, *base;
14010 char *affix;
14011 const struct asm_opcode *opcode;
14012 const struct asm_cond *cond;
14013 char save[2];
14014 bfd_boolean neon_supported;
14015
14016 neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1);
14017
14018 /* Scan up to the end of the mnemonic, which must end in white space,
14019 '.' (in unified mode, or for Neon instructions), or end of string. */
14020 for (base = end = *str; *end != '\0'; end++)
14021 if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.'))
14022 break;
14023
14024 if (end == base)
14025 return 0;
14026
14027 /* Handle a possible width suffix and/or Neon type suffix. */
14028 if (end[0] == '.')
14029 {
14030 int offset = 2;
14031
14032 /* The .w and .n suffixes are only valid if the unified syntax is in
14033 use. */
14034 if (unified_syntax && end[1] == 'w')
14035 inst.size_req = 4;
14036 else if (unified_syntax && end[1] == 'n')
14037 inst.size_req = 2;
14038 else
14039 offset = 0;
14040
14041 inst.vectype.elems = 0;
14042
14043 *str = end + offset;
14044
14045 if (end[offset] == '.')
14046 {
14047 /* See if we have a Neon type suffix (possible in either unified or
14048 non-unified ARM syntax mode). */
14049 if (parse_neon_type (&inst.vectype, str) == FAIL)
14050 return 0;
14051 }
14052 else if (end[offset] != '\0' && end[offset] != ' ')
14053 return 0;
14054 }
14055 else
14056 *str = end;
14057
14058 /* Look for unaffixed or special-case affixed mnemonic. */
14059 opcode = hash_find_n (arm_ops_hsh, base, end - base);
14060 if (opcode)
14061 {
14062 /* step U */
14063 if (opcode->tag < OT_odd_infix_0)
14064 {
14065 inst.cond = COND_ALWAYS;
14066 return opcode;
14067 }
14068
14069 if (unified_syntax)
14070 as_warn (_("conditional infixes are deprecated in unified syntax"));
14071 affix = base + (opcode->tag - OT_odd_infix_0);
14072 cond = hash_find_n (arm_cond_hsh, affix, 2);
14073 assert (cond);
14074
14075 inst.cond = cond->value;
14076 return opcode;
14077 }
14078
14079 /* Cannot have a conditional suffix on a mnemonic of less than two
14080 characters. */
14081 if (end - base < 3)
14082 return 0;
14083
14084 /* Look for suffixed mnemonic. */
14085 affix = end - 2;
14086 cond = hash_find_n (arm_cond_hsh, affix, 2);
14087 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
14088 if (opcode && cond)
14089 {
14090 /* step CE */
14091 switch (opcode->tag)
14092 {
14093 case OT_cinfix3_legacy:
14094 /* Ignore conditional suffixes matched on infix only mnemonics. */
14095 break;
14096
14097 case OT_cinfix3:
14098 case OT_cinfix3_deprecated:
14099 case OT_odd_infix_unc:
14100 if (!unified_syntax)
14101 return 0;
14102 /* else fall through */
14103
14104 case OT_csuffix:
14105 case OT_csuffixF:
14106 case OT_csuf_or_in3:
14107 inst.cond = cond->value;
14108 return opcode;
14109
14110 case OT_unconditional:
14111 case OT_unconditionalF:
14112 if (thumb_mode)
14113 {
14114 inst.cond = cond->value;
14115 }
14116 else
14117 {
14118 /* delayed diagnostic */
14119 inst.error = BAD_COND;
14120 inst.cond = COND_ALWAYS;
14121 }
14122 return opcode;
14123
14124 default:
14125 return 0;
14126 }
14127 }
14128
14129 /* Cannot have a usual-position infix on a mnemonic of less than
14130 six characters (five would be a suffix). */
14131 if (end - base < 6)
14132 return 0;
14133
14134 /* Look for infixed mnemonic in the usual position. */
14135 affix = base + 3;
14136 cond = hash_find_n (arm_cond_hsh, affix, 2);
14137 if (!cond)
14138 return 0;
14139
14140 memcpy (save, affix, 2);
14141 memmove (affix, affix + 2, (end - affix) - 2);
14142 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
14143 memmove (affix + 2, affix, (end - affix) - 2);
14144 memcpy (affix, save, 2);
14145
14146 if (opcode
14147 && (opcode->tag == OT_cinfix3
14148 || opcode->tag == OT_cinfix3_deprecated
14149 || opcode->tag == OT_csuf_or_in3
14150 || opcode->tag == OT_cinfix3_legacy))
14151 {
14152 /* step CM */
14153 if (unified_syntax
14154 && (opcode->tag == OT_cinfix3
14155 || opcode->tag == OT_cinfix3_deprecated))
14156 as_warn (_("conditional infixes are deprecated in unified syntax"));
14157
14158 inst.cond = cond->value;
14159 return opcode;
14160 }
14161
14162 return 0;
14163 }
14164
14165 void
14166 md_assemble (char *str)
14167 {
14168 char *p = str;
14169 const struct asm_opcode * opcode;
14170
14171 /* Align the previous label if needed. */
14172 if (last_label_seen != NULL)
14173 {
14174 symbol_set_frag (last_label_seen, frag_now);
14175 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
14176 S_SET_SEGMENT (last_label_seen, now_seg);
14177 }
14178
14179 memset (&inst, '\0', sizeof (inst));
14180 inst.reloc.type = BFD_RELOC_UNUSED;
14181
14182 opcode = opcode_lookup (&p);
14183 if (!opcode)
14184 {
14185 /* It wasn't an instruction, but it might be a register alias of
14186 the form alias .req reg, or a Neon .dn/.qn directive. */
14187 if (!create_register_alias (str, p)
14188 && !create_neon_reg_alias (str, p))
14189 as_bad (_("bad instruction `%s'"), str);
14190
14191 return;
14192 }
14193
14194 if (opcode->tag == OT_cinfix3_deprecated)
14195 as_warn (_("s suffix on comparison instruction is deprecated"));
14196
14197 /* The value which unconditional instructions should have in place of the
14198 condition field. */
14199 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
14200
14201 if (thumb_mode)
14202 {
14203 arm_feature_set variant;
14204
14205 variant = cpu_variant;
14206 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
14207 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
14208 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
14209 /* Check that this instruction is supported for this CPU. */
14210 if (!opcode->tvariant
14211 || (thumb_mode == 1
14212 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
14213 {
14214 as_bad (_("selected processor does not support `%s'"), str);
14215 return;
14216 }
14217 if (inst.cond != COND_ALWAYS && !unified_syntax
14218 && opcode->tencode != do_t_branch)
14219 {
14220 as_bad (_("Thumb does not support conditional execution"));
14221 return;
14222 }
14223
14224 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) && !inst.size_req)
14225 {
14226 /* Implicit require narrow instructions on Thumb-1. This avoids
14227 relaxation accidentally introducing Thumb-2 instructions. */
14228 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23)
14229 inst.size_req = 2;
14230 }
14231
14232 /* Check conditional suffixes. */
14233 if (current_it_mask)
14234 {
14235 int cond;
14236 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
14237 current_it_mask <<= 1;
14238 current_it_mask &= 0x1f;
14239 /* The BKPT instruction is unconditional even in an IT block. */
14240 if (!inst.error
14241 && cond != inst.cond && opcode->tencode != do_t_bkpt)
14242 {
14243 as_bad (_("incorrect condition in IT block"));
14244 return;
14245 }
14246 }
14247 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
14248 {
14249 as_bad (_("thumb conditional instruction not in IT block"));
14250 return;
14251 }
14252
14253 mapping_state (MAP_THUMB);
14254 inst.instruction = opcode->tvalue;
14255
14256 if (!parse_operands (p, opcode->operands))
14257 opcode->tencode ();
14258
14259 /* Clear current_it_mask at the end of an IT block. */
14260 if (current_it_mask == 0x10)
14261 current_it_mask = 0;
14262
14263 if (!(inst.error || inst.relax))
14264 {
14265 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
14266 inst.size = (inst.instruction > 0xffff ? 4 : 2);
14267 if (inst.size_req && inst.size_req != inst.size)
14268 {
14269 as_bad (_("cannot honor width suffix -- `%s'"), str);
14270 return;
14271 }
14272 }
14273
14274 /* Something has gone badly wrong if we try to relax a fixed size
14275 instruction. */
14276 assert (inst.size_req == 0 || !inst.relax);
14277
14278 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14279 *opcode->tvariant);
14280 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
14281 set those bits when Thumb-2 32-bit instructions are seen. ie.
14282 anything other than bl/blx.
14283 This is overly pessimistic for relaxable instructions. */
14284 if ((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
14285 || inst.relax)
14286 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14287 arm_ext_v6t2);
14288 }
14289 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
14290 {
14291 bfd_boolean is_bx;
14292
14293 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
14294 is_bx = (opcode->aencode == do_bx);
14295
14296 /* Check that this instruction is supported for this CPU. */
14297 if (!(is_bx && fix_v4bx)
14298 && !(opcode->avariant &&
14299 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
14300 {
14301 as_bad (_("selected processor does not support `%s'"), str);
14302 return;
14303 }
14304 if (inst.size_req)
14305 {
14306 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
14307 return;
14308 }
14309
14310 mapping_state (MAP_ARM);
14311 inst.instruction = opcode->avalue;
14312 if (opcode->tag == OT_unconditionalF)
14313 inst.instruction |= 0xF << 28;
14314 else
14315 inst.instruction |= inst.cond << 28;
14316 inst.size = INSN_SIZE;
14317 if (!parse_operands (p, opcode->operands))
14318 opcode->aencode ();
14319 /* Arm mode bx is marked as both v4T and v5 because it's still required
14320 on a hypothetical non-thumb v5 core. */
14321 if (is_bx)
14322 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
14323 else
14324 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
14325 *opcode->avariant);
14326 }
14327 else
14328 {
14329 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
14330 "-- `%s'"), str);
14331 return;
14332 }
14333 output_inst (str);
14334 }
14335
14336 /* Various frobbings of labels and their addresses. */
14337
14338 void
14339 arm_start_line_hook (void)
14340 {
14341 last_label_seen = NULL;
14342 }
14343
14344 void
14345 arm_frob_label (symbolS * sym)
14346 {
14347 last_label_seen = sym;
14348
14349 ARM_SET_THUMB (sym, thumb_mode);
14350
14351 #if defined OBJ_COFF || defined OBJ_ELF
14352 ARM_SET_INTERWORK (sym, support_interwork);
14353 #endif
14354
14355 /* Note - do not allow local symbols (.Lxxx) to be labelled
14356 as Thumb functions. This is because these labels, whilst
14357 they exist inside Thumb code, are not the entry points for
14358 possible ARM->Thumb calls. Also, these labels can be used
14359 as part of a computed goto or switch statement. eg gcc
14360 can generate code that looks like this:
14361
14362 ldr r2, [pc, .Laaa]
14363 lsl r3, r3, #2
14364 ldr r2, [r3, r2]
14365 mov pc, r2
14366
14367 .Lbbb: .word .Lxxx
14368 .Lccc: .word .Lyyy
14369 ..etc...
14370 .Laaa: .word Lbbb
14371
14372 The first instruction loads the address of the jump table.
14373 The second instruction converts a table index into a byte offset.
14374 The third instruction gets the jump address out of the table.
14375 The fourth instruction performs the jump.
14376
14377 If the address stored at .Laaa is that of a symbol which has the
14378 Thumb_Func bit set, then the linker will arrange for this address
14379 to have the bottom bit set, which in turn would mean that the
14380 address computation performed by the third instruction would end
14381 up with the bottom bit set. Since the ARM is capable of unaligned
14382 word loads, the instruction would then load the incorrect address
14383 out of the jump table, and chaos would ensue. */
14384 if (label_is_thumb_function_name
14385 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
14386 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
14387 {
14388 /* When the address of a Thumb function is taken the bottom
14389 bit of that address should be set. This will allow
14390 interworking between Arm and Thumb functions to work
14391 correctly. */
14392
14393 THUMB_SET_FUNC (sym, 1);
14394
14395 label_is_thumb_function_name = FALSE;
14396 }
14397
14398 dwarf2_emit_label (sym);
14399 }
14400
14401 int
14402 arm_data_in_code (void)
14403 {
14404 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
14405 {
14406 *input_line_pointer = '/';
14407 input_line_pointer += 5;
14408 *input_line_pointer = 0;
14409 return 1;
14410 }
14411
14412 return 0;
14413 }
14414
14415 char *
14416 arm_canonicalize_symbol_name (char * name)
14417 {
14418 int len;
14419
14420 if (thumb_mode && (len = strlen (name)) > 5
14421 && streq (name + len - 5, "/data"))
14422 *(name + len - 5) = 0;
14423
14424 return name;
14425 }
14426 \f
14427 /* Table of all register names defined by default. The user can
14428 define additional names with .req. Note that all register names
14429 should appear in both upper and lowercase variants. Some registers
14430 also have mixed-case names. */
14431
14432 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
14433 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
14434 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
14435 #define REGSET(p,t) \
14436 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
14437 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
14438 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
14439 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
14440 #define REGSETH(p,t) \
14441 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
14442 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
14443 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
14444 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
14445 #define REGSET2(p,t) \
14446 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
14447 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
14448 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
14449 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
14450
14451 static const struct reg_entry reg_names[] =
14452 {
14453 /* ARM integer registers. */
14454 REGSET(r, RN), REGSET(R, RN),
14455
14456 /* ATPCS synonyms. */
14457 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
14458 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
14459 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
14460
14461 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
14462 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
14463 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
14464
14465 /* Well-known aliases. */
14466 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
14467 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
14468
14469 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
14470 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
14471
14472 /* Coprocessor numbers. */
14473 REGSET(p, CP), REGSET(P, CP),
14474
14475 /* Coprocessor register numbers. The "cr" variants are for backward
14476 compatibility. */
14477 REGSET(c, CN), REGSET(C, CN),
14478 REGSET(cr, CN), REGSET(CR, CN),
14479
14480 /* FPA registers. */
14481 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
14482 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
14483
14484 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
14485 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
14486
14487 /* VFP SP registers. */
14488 REGSET(s,VFS), REGSET(S,VFS),
14489 REGSETH(s,VFS), REGSETH(S,VFS),
14490
14491 /* VFP DP Registers. */
14492 REGSET(d,VFD), REGSET(D,VFD),
14493 /* Extra Neon DP registers. */
14494 REGSETH(d,VFD), REGSETH(D,VFD),
14495
14496 /* Neon QP registers. */
14497 REGSET2(q,NQ), REGSET2(Q,NQ),
14498
14499 /* VFP control registers. */
14500 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
14501 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
14502 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
14503 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
14504 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
14505 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
14506
14507 /* Maverick DSP coprocessor registers. */
14508 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
14509 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
14510
14511 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
14512 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
14513 REGDEF(dspsc,0,DSPSC),
14514
14515 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
14516 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
14517 REGDEF(DSPSC,0,DSPSC),
14518
14519 /* iWMMXt data registers - p0, c0-15. */
14520 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
14521
14522 /* iWMMXt control registers - p1, c0-3. */
14523 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
14524 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
14525 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
14526 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
14527
14528 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
14529 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
14530 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
14531 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
14532 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
14533
14534 /* XScale accumulator registers. */
14535 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
14536 };
14537 #undef REGDEF
14538 #undef REGNUM
14539 #undef REGSET
14540
14541 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
14542 within psr_required_here. */
14543 static const struct asm_psr psrs[] =
14544 {
14545 /* Backward compatibility notation. Note that "all" is no longer
14546 truly all possible PSR bits. */
14547 {"all", PSR_c | PSR_f},
14548 {"flg", PSR_f},
14549 {"ctl", PSR_c},
14550
14551 /* Individual flags. */
14552 {"f", PSR_f},
14553 {"c", PSR_c},
14554 {"x", PSR_x},
14555 {"s", PSR_s},
14556 /* Combinations of flags. */
14557 {"fs", PSR_f | PSR_s},
14558 {"fx", PSR_f | PSR_x},
14559 {"fc", PSR_f | PSR_c},
14560 {"sf", PSR_s | PSR_f},
14561 {"sx", PSR_s | PSR_x},
14562 {"sc", PSR_s | PSR_c},
14563 {"xf", PSR_x | PSR_f},
14564 {"xs", PSR_x | PSR_s},
14565 {"xc", PSR_x | PSR_c},
14566 {"cf", PSR_c | PSR_f},
14567 {"cs", PSR_c | PSR_s},
14568 {"cx", PSR_c | PSR_x},
14569 {"fsx", PSR_f | PSR_s | PSR_x},
14570 {"fsc", PSR_f | PSR_s | PSR_c},
14571 {"fxs", PSR_f | PSR_x | PSR_s},
14572 {"fxc", PSR_f | PSR_x | PSR_c},
14573 {"fcs", PSR_f | PSR_c | PSR_s},
14574 {"fcx", PSR_f | PSR_c | PSR_x},
14575 {"sfx", PSR_s | PSR_f | PSR_x},
14576 {"sfc", PSR_s | PSR_f | PSR_c},
14577 {"sxf", PSR_s | PSR_x | PSR_f},
14578 {"sxc", PSR_s | PSR_x | PSR_c},
14579 {"scf", PSR_s | PSR_c | PSR_f},
14580 {"scx", PSR_s | PSR_c | PSR_x},
14581 {"xfs", PSR_x | PSR_f | PSR_s},
14582 {"xfc", PSR_x | PSR_f | PSR_c},
14583 {"xsf", PSR_x | PSR_s | PSR_f},
14584 {"xsc", PSR_x | PSR_s | PSR_c},
14585 {"xcf", PSR_x | PSR_c | PSR_f},
14586 {"xcs", PSR_x | PSR_c | PSR_s},
14587 {"cfs", PSR_c | PSR_f | PSR_s},
14588 {"cfx", PSR_c | PSR_f | PSR_x},
14589 {"csf", PSR_c | PSR_s | PSR_f},
14590 {"csx", PSR_c | PSR_s | PSR_x},
14591 {"cxf", PSR_c | PSR_x | PSR_f},
14592 {"cxs", PSR_c | PSR_x | PSR_s},
14593 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
14594 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
14595 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
14596 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
14597 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
14598 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
14599 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
14600 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
14601 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
14602 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
14603 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
14604 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
14605 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
14606 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
14607 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
14608 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
14609 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
14610 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
14611 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
14612 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
14613 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
14614 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
14615 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
14616 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
14617 };
14618
14619 /* Table of V7M psr names. */
14620 static const struct asm_psr v7m_psrs[] =
14621 {
14622 {"apsr", 0 }, {"APSR", 0 },
14623 {"iapsr", 1 }, {"IAPSR", 1 },
14624 {"eapsr", 2 }, {"EAPSR", 2 },
14625 {"psr", 3 }, {"PSR", 3 },
14626 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
14627 {"ipsr", 5 }, {"IPSR", 5 },
14628 {"epsr", 6 }, {"EPSR", 6 },
14629 {"iepsr", 7 }, {"IEPSR", 7 },
14630 {"msp", 8 }, {"MSP", 8 },
14631 {"psp", 9 }, {"PSP", 9 },
14632 {"primask", 16}, {"PRIMASK", 16},
14633 {"basepri", 17}, {"BASEPRI", 17},
14634 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
14635 {"faultmask", 19}, {"FAULTMASK", 19},
14636 {"control", 20}, {"CONTROL", 20}
14637 };
14638
14639 /* Table of all shift-in-operand names. */
14640 static const struct asm_shift_name shift_names [] =
14641 {
14642 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
14643 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
14644 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
14645 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
14646 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
14647 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
14648 };
14649
14650 /* Table of all explicit relocation names. */
14651 #ifdef OBJ_ELF
14652 static struct reloc_entry reloc_names[] =
14653 {
14654 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
14655 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
14656 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
14657 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
14658 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
14659 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
14660 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
14661 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
14662 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
14663 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
14664 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
14665 };
14666 #endif
14667
14668 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
14669 static const struct asm_cond conds[] =
14670 {
14671 {"eq", 0x0},
14672 {"ne", 0x1},
14673 {"cs", 0x2}, {"hs", 0x2},
14674 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
14675 {"mi", 0x4},
14676 {"pl", 0x5},
14677 {"vs", 0x6},
14678 {"vc", 0x7},
14679 {"hi", 0x8},
14680 {"ls", 0x9},
14681 {"ge", 0xa},
14682 {"lt", 0xb},
14683 {"gt", 0xc},
14684 {"le", 0xd},
14685 {"al", 0xe}
14686 };
14687
14688 static struct asm_barrier_opt barrier_opt_names[] =
14689 {
14690 { "sy", 0xf },
14691 { "un", 0x7 },
14692 { "st", 0xe },
14693 { "unst", 0x6 }
14694 };
14695
14696 /* Table of ARM-format instructions. */
14697
14698 /* Macros for gluing together operand strings. N.B. In all cases
14699 other than OPS0, the trailing OP_stop comes from default
14700 zero-initialization of the unspecified elements of the array. */
14701 #define OPS0() { OP_stop, }
14702 #define OPS1(a) { OP_##a, }
14703 #define OPS2(a,b) { OP_##a,OP_##b, }
14704 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
14705 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
14706 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
14707 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
14708
14709 /* These macros abstract out the exact format of the mnemonic table and
14710 save some repeated characters. */
14711
14712 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
14713 #define TxCE(mnem, op, top, nops, ops, ae, te) \
14714 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
14715 THUMB_VARIANT, do_##ae, do_##te }
14716
14717 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
14718 a T_MNEM_xyz enumerator. */
14719 #define TCE(mnem, aop, top, nops, ops, ae, te) \
14720 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
14721 #define tCE(mnem, aop, top, nops, ops, ae, te) \
14722 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14723
14724 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
14725 infix after the third character. */
14726 #define TxC3(mnem, op, top, nops, ops, ae, te) \
14727 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
14728 THUMB_VARIANT, do_##ae, do_##te }
14729 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
14730 { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
14731 THUMB_VARIANT, do_##ae, do_##te }
14732 #define TC3(mnem, aop, top, nops, ops, ae, te) \
14733 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
14734 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
14735 TxC3w(mnem, aop, 0x##top, nops, ops, ae, te)
14736 #define tC3(mnem, aop, top, nops, ops, ae, te) \
14737 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14738 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
14739 TxC3w(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14740
14741 /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
14742 appear in the condition table. */
14743 #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
14744 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14745 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
14746
14747 #define TxCM(m1, m2, op, top, nops, ops, ae, te) \
14748 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
14749 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
14750 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
14751 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
14752 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
14753 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
14754 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
14755 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
14756 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
14757 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
14758 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
14759 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
14760 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
14761 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
14762 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
14763 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
14764 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
14765 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
14766 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
14767
14768 #define TCM(m1,m2, aop, top, nops, ops, ae, te) \
14769 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
14770 #define tCM(m1,m2, aop, top, nops, ops, ae, te) \
14771 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
14772
14773 /* Mnemonic that cannot be conditionalized. The ARM condition-code
14774 field is still 0xE. Many of the Thumb variants can be executed
14775 conditionally, so this is checked separately. */
14776 #define TUE(mnem, op, top, nops, ops, ae, te) \
14777 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
14778 THUMB_VARIANT, do_##ae, do_##te }
14779
14780 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
14781 condition code field. */
14782 #define TUF(mnem, op, top, nops, ops, ae, te) \
14783 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
14784 THUMB_VARIANT, do_##ae, do_##te }
14785
14786 /* ARM-only variants of all the above. */
14787 #define CE(mnem, op, nops, ops, ae) \
14788 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14789
14790 #define C3(mnem, op, nops, ops, ae) \
14791 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14792
14793 /* Legacy mnemonics that always have conditional infix after the third
14794 character. */
14795 #define CL(mnem, op, nops, ops, ae) \
14796 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14797 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14798
14799 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
14800 #define cCE(mnem, op, nops, ops, ae) \
14801 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14802
14803 /* Legacy coprocessor instructions where conditional infix and conditional
14804 suffix are ambiguous. For consistency this includes all FPA instructions,
14805 not just the potentially ambiguous ones. */
14806 #define cCL(mnem, op, nops, ops, ae) \
14807 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14808 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14809
14810 /* Coprocessor, takes either a suffix or a position-3 infix
14811 (for an FPA corner case). */
14812 #define C3E(mnem, op, nops, ops, ae) \
14813 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
14814 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14815
14816 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
14817 { #m1 #m2 #m3, OPS##nops ops, \
14818 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14819 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14820
14821 #define CM(m1, m2, op, nops, ops, ae) \
14822 xCM_(m1, , m2, op, nops, ops, ae), \
14823 xCM_(m1, eq, m2, op, nops, ops, ae), \
14824 xCM_(m1, ne, m2, op, nops, ops, ae), \
14825 xCM_(m1, cs, m2, op, nops, ops, ae), \
14826 xCM_(m1, hs, m2, op, nops, ops, ae), \
14827 xCM_(m1, cc, m2, op, nops, ops, ae), \
14828 xCM_(m1, ul, m2, op, nops, ops, ae), \
14829 xCM_(m1, lo, m2, op, nops, ops, ae), \
14830 xCM_(m1, mi, m2, op, nops, ops, ae), \
14831 xCM_(m1, pl, m2, op, nops, ops, ae), \
14832 xCM_(m1, vs, m2, op, nops, ops, ae), \
14833 xCM_(m1, vc, m2, op, nops, ops, ae), \
14834 xCM_(m1, hi, m2, op, nops, ops, ae), \
14835 xCM_(m1, ls, m2, op, nops, ops, ae), \
14836 xCM_(m1, ge, m2, op, nops, ops, ae), \
14837 xCM_(m1, lt, m2, op, nops, ops, ae), \
14838 xCM_(m1, gt, m2, op, nops, ops, ae), \
14839 xCM_(m1, le, m2, op, nops, ops, ae), \
14840 xCM_(m1, al, m2, op, nops, ops, ae)
14841
14842 #define UE(mnem, op, nops, ops, ae) \
14843 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14844
14845 #define UF(mnem, op, nops, ops, ae) \
14846 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14847
14848 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
14849 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
14850 use the same encoding function for each. */
14851 #define NUF(mnem, op, nops, ops, enc) \
14852 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
14853 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14854
14855 /* Neon data processing, version which indirects through neon_enc_tab for
14856 the various overloaded versions of opcodes. */
14857 #define nUF(mnem, op, nops, ops, enc) \
14858 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \
14859 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14860
14861 /* Neon insn with conditional suffix for the ARM version, non-overloaded
14862 version. */
14863 #define NCE_tag(mnem, op, nops, ops, enc, tag) \
14864 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
14865 THUMB_VARIANT, do_##enc, do_##enc }
14866
14867 #define NCE(mnem, op, nops, ops, enc) \
14868 NCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14869
14870 #define NCEF(mnem, op, nops, ops, enc) \
14871 NCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14872
14873 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
14874 #define nCE_tag(mnem, op, nops, ops, enc, tag) \
14875 { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \
14876 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14877
14878 #define nCE(mnem, op, nops, ops, enc) \
14879 nCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14880
14881 #define nCEF(mnem, op, nops, ops, enc) \
14882 nCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14883
14884 #define do_0 0
14885
14886 /* Thumb-only, unconditional. */
14887 #define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
14888
14889 static const struct asm_opcode insns[] =
14890 {
14891 #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
14892 #define THUMB_VARIANT &arm_ext_v4t
14893 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
14894 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
14895 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
14896 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
14897 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
14898 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
14899 tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub),
14900 tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub),
14901 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
14902 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
14903 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
14904 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
14905 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
14906 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
14907 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
14908 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
14909
14910 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
14911 for setting PSR flag bits. They are obsolete in V6 and do not
14912 have Thumb equivalents. */
14913 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
14914 tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
14915 CL(tstp, 110f000, 2, (RR, SH), cmp),
14916 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
14917 tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
14918 CL(cmpp, 150f000, 2, (RR, SH), cmp),
14919 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
14920 tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
14921 CL(cmnp, 170f000, 2, (RR, SH), cmp),
14922
14923 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
14924 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
14925 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
14926 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
14927
14928 tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
14929 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
14930 tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst),
14931 tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
14932
14933 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14934 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14935 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14936 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14937 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14938 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14939
14940 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
14941 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
14942 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
14943 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
14944
14945 /* Pseudo ops. */
14946 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
14947 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
14948 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
14949
14950 /* Thumb-compatibility pseudo ops. */
14951 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
14952 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
14953 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
14954 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
14955 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
14956 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
14957 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
14958 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
14959 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
14960 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
14961 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
14962 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
14963
14964 /* These may simplify to neg. */
14965 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
14966 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
14967
14968 #undef THUMB_VARIANT
14969 #define THUMB_VARIANT &arm_ext_v6
14970 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
14971
14972 /* V1 instructions with no Thumb analogue prior to V6T2. */
14973 #undef THUMB_VARIANT
14974 #define THUMB_VARIANT &arm_ext_v6t2
14975 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
14976 TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
14977 CL(teqp, 130f000, 2, (RR, SH), cmp),
14978
14979 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
14980 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
14981 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
14982 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
14983
14984 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14985 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14986
14987 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14988 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14989
14990 /* V1 instructions with no Thumb analogue at all. */
14991 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
14992 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
14993
14994 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
14995 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
14996 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
14997 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
14998 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
14999 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
15000 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
15001 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
15002
15003 #undef ARM_VARIANT
15004 #define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
15005 #undef THUMB_VARIANT
15006 #define THUMB_VARIANT &arm_ext_v4t
15007 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15008 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15009
15010 #undef THUMB_VARIANT
15011 #define THUMB_VARIANT &arm_ext_v6t2
15012 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
15013 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
15014
15015 /* Generic coprocessor instructions. */
15016 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
15017 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15018 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15019 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15020 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15021 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15022 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15023
15024 #undef ARM_VARIANT
15025 #define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
15026 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15027 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15028
15029 #undef ARM_VARIANT
15030 #define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
15031 TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
15032 TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
15033
15034 #undef ARM_VARIANT
15035 #define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
15036 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15037 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15038 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15039 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15040 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15041 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15042 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15043 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15044
15045 #undef ARM_VARIANT
15046 #define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
15047 #undef THUMB_VARIANT
15048 #define THUMB_VARIANT &arm_ext_v4t
15049 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15050 tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15051 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15052 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15053 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15054 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15055
15056 #undef ARM_VARIANT
15057 #define ARM_VARIANT &arm_ext_v4t_5
15058 /* ARM Architecture 4T. */
15059 /* Note: bx (and blx) are required on V5, even if the processor does
15060 not support Thumb. */
15061 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
15062
15063 #undef ARM_VARIANT
15064 #define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
15065 #undef THUMB_VARIANT
15066 #define THUMB_VARIANT &arm_ext_v5t
15067 /* Note: blx has 2 variants; the .value coded here is for
15068 BLX(2). Only this variant has conditional execution. */
15069 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
15070 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
15071
15072 #undef THUMB_VARIANT
15073 #define THUMB_VARIANT &arm_ext_v6t2
15074 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
15075 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15076 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15077 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15078 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15079 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
15080 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15081 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15082
15083 #undef ARM_VARIANT
15084 #define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
15085 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15086 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15087 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15088 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15089
15090 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15091 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15092
15093 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15094 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15095 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15096 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15097
15098 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15099 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15100 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15101 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15102
15103 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15104 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15105
15106 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15107 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15108 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15109 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15110
15111 #undef ARM_VARIANT
15112 #define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
15113 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
15114 TC3(ldrd, 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
15115 TC3(strd, 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
15116
15117 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15118 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15119
15120 #undef ARM_VARIANT
15121 #define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
15122 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
15123
15124 #undef ARM_VARIANT
15125 #define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
15126 #undef THUMB_VARIANT
15127 #define THUMB_VARIANT &arm_ext_v6
15128 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
15129 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
15130 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15131 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15132 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15133 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15134 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15135 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15136 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15137 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
15138
15139 #undef THUMB_VARIANT
15140 #define THUMB_VARIANT &arm_ext_v6t2
15141 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
15142 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
15143 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15144 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15145
15146 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
15147 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
15148
15149 /* ARM V6 not included in V7M (eg. integer SIMD). */
15150 #undef THUMB_VARIANT
15151 #define THUMB_VARIANT &arm_ext_v6_notm
15152 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
15153 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
15154 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
15155 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15156 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15157 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15158 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15159 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15160 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15161 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15162 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15163 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15164 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15165 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15166 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15167 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15168 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15169 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15170 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15171 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15172 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15173 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15174 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15175 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15176 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15177 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15178 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15179 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15180 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15181 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15182 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15183 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15184 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15185 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15186 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15187 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15188 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15189 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15190 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15191 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15192 UF(rfeib, 9900a00, 1, (RRw), rfe),
15193 UF(rfeda, 8100a00, 1, (RRw), rfe),
15194 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15195 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15196 UF(rfefa, 9900a00, 1, (RRw), rfe),
15197 UF(rfeea, 8100a00, 1, (RRw), rfe),
15198 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15199 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15200 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15201 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15202 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15203 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15204 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15205 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15206 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15207 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15208 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15209 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15210 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15211 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15212 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15213 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15214 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15215 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15216 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15217 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15218 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15219 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15220 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15221 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15222 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15223 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15224 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15225 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15226 TUF(srsia, 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
15227 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
15228 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
15229 TUF(srsdb, 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
15230 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
15231 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
15232 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15233 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15234 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
15235
15236 #undef ARM_VARIANT
15237 #define ARM_VARIANT &arm_ext_v6k
15238 #undef THUMB_VARIANT
15239 #define THUMB_VARIANT &arm_ext_v6k
15240 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
15241 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
15242 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
15243 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
15244
15245 #undef THUMB_VARIANT
15246 #define THUMB_VARIANT &arm_ext_v6_notm
15247 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
15248 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
15249
15250 #undef THUMB_VARIANT
15251 #define THUMB_VARIANT &arm_ext_v6t2
15252 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15253 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15254 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15255 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15256 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
15257
15258 #undef ARM_VARIANT
15259 #define ARM_VARIANT &arm_ext_v6z
15260 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
15261
15262 #undef ARM_VARIANT
15263 #define ARM_VARIANT &arm_ext_v6t2
15264 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
15265 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
15266 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15267 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15268
15269 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
15270 TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
15271 TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
15272 TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
15273
15274 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15275 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15276 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15277 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15278
15279 UT(cbnz, b900, 2, (RR, EXP), t_cbz),
15280 UT(cbz, b100, 2, (RR, EXP), t_cbz),
15281 /* ARM does not really have an IT instruction, so always allow it. */
15282 #undef ARM_VARIANT
15283 #define ARM_VARIANT &arm_ext_v1
15284 TUE(it, 0, bf08, 1, (COND), it, t_it),
15285 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
15286 TUE(ite, 0, bf04, 1, (COND), it, t_it),
15287 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
15288 TUE(itet, 0, bf06, 1, (COND), it, t_it),
15289 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
15290 TUE(itee, 0, bf02, 1, (COND), it, t_it),
15291 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
15292 TUE(itett, 0, bf07, 1, (COND), it, t_it),
15293 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
15294 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
15295 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
15296 TUE(itete, 0, bf05, 1, (COND), it, t_it),
15297 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
15298 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
15299
15300 /* Thumb2 only instructions. */
15301 #undef ARM_VARIANT
15302 #define ARM_VARIANT NULL
15303
15304 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15305 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15306 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
15307 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
15308
15309 /* Thumb-2 hardware division instructions (R and M profiles only). */
15310 #undef THUMB_VARIANT
15311 #define THUMB_VARIANT &arm_ext_div
15312 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
15313 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
15314
15315 /* ARM V7 instructions. */
15316 #undef ARM_VARIANT
15317 #define ARM_VARIANT &arm_ext_v7
15318 #undef THUMB_VARIANT
15319 #define THUMB_VARIANT &arm_ext_v7
15320 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
15321 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
15322 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
15323 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
15324 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
15325
15326 #undef ARM_VARIANT
15327 #define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
15328 cCE(wfs, e200110, 1, (RR), rd),
15329 cCE(rfs, e300110, 1, (RR), rd),
15330 cCE(wfc, e400110, 1, (RR), rd),
15331 cCE(rfc, e500110, 1, (RR), rd),
15332
15333 cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
15334 cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
15335 cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
15336 cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
15337
15338 cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
15339 cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
15340 cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
15341 cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
15342
15343 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
15344 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
15345 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
15346 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
15347 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
15348 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
15349 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
15350 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
15351 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
15352 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
15353 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
15354 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
15355
15356 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
15357 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
15358 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
15359 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
15360 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
15361 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
15362 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
15363 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
15364 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
15365 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
15366 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
15367 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
15368
15369 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
15370 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
15371 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
15372 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
15373 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
15374 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
15375 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
15376 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
15377 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
15378 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
15379 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
15380 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
15381
15382 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
15383 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
15384 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
15385 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
15386 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
15387 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
15388 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
15389 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
15390 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
15391 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
15392 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
15393 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
15394
15395 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
15396 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
15397 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
15398 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
15399 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
15400 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
15401 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
15402 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
15403 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
15404 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
15405 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
15406 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
15407
15408 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
15409 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
15410 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
15411 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
15412 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
15413 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
15414 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
15415 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
15416 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
15417 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
15418 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
15419 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
15420
15421 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
15422 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
15423 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
15424 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
15425 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
15426 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
15427 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
15428 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
15429 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
15430 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
15431 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
15432 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
15433
15434 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
15435 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
15436 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
15437 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
15438 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
15439 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
15440 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
15441 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
15442 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
15443 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
15444 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
15445 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
15446
15447 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
15448 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
15449 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
15450 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
15451 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
15452 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
15453 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
15454 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
15455 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
15456 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
15457 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
15458 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
15459
15460 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
15461 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
15462 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
15463 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
15464 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
15465 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
15466 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
15467 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
15468 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
15469 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
15470 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
15471 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
15472
15473 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
15474 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
15475 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
15476 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
15477 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
15478 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
15479 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
15480 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
15481 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
15482 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
15483 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
15484 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
15485
15486 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
15487 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
15488 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
15489 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
15490 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
15491 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
15492 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
15493 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
15494 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
15495 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
15496 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
15497 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
15498
15499 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
15500 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
15501 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
15502 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
15503 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
15504 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
15505 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
15506 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
15507 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
15508 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
15509 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
15510 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
15511
15512 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
15513 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
15514 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
15515 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
15516 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
15517 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
15518 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
15519 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
15520 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
15521 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
15522 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
15523 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
15524
15525 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
15526 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
15527 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
15528 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
15529 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
15530 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
15531 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
15532 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
15533 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
15534 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
15535 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
15536 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
15537
15538 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
15539 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
15540 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
15541 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
15542 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
15543 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
15544 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
15545 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
15546 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
15547 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
15548 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
15549 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
15550
15551 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
15552 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
15553 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
15554 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
15555 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
15556 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15557 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15558 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15559 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
15560 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
15561 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
15562 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
15563
15564 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
15565 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
15566 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
15567 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
15568 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
15569 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15570 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15571 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15572 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
15573 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
15574 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
15575 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
15576
15577 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
15578 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
15579 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
15580 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
15581 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
15582 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15583 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15584 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15585 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
15586 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
15587 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
15588 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
15589
15590 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
15591 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
15592 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
15593 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
15594 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
15595 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15596 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15597 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15598 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
15599 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
15600 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
15601 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
15602
15603 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
15604 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
15605 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
15606 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
15607 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
15608 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15609 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15610 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15611 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
15612 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
15613 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
15614 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
15615
15616 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
15617 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
15618 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
15619 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
15620 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
15621 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15622 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15623 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15624 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
15625 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
15626 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
15627 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
15628
15629 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
15630 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
15631 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
15632 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
15633 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
15634 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15635 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15636 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15637 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
15638 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
15639 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
15640 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
15641
15642 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
15643 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
15644 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
15645 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
15646 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
15647 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15648 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15649 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15650 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
15651 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
15652 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
15653 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
15654
15655 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
15656 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
15657 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
15658 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
15659 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
15660 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15661 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15662 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15663 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
15664 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
15665 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
15666 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
15667
15668 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
15669 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
15670 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
15671 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
15672 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
15673 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15674 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15675 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15676 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
15677 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
15678 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
15679 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
15680
15681 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15682 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15683 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15684 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15685 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15686 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15687 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15688 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15689 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15690 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15691 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15692 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15693
15694 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15695 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15696 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15697 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15698 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15699 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15700 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15701 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15702 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15703 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15704 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15705 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15706
15707 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15708 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15709 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15710 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15711 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15712 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15713 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15714 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15715 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15716 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15717 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15718 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15719
15720 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
15721 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
15722 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
15723 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
15724
15725 cCL(flts, e000110, 2, (RF, RR), rn_rd),
15726 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
15727 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
15728 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
15729 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
15730 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
15731 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
15732 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
15733 cCL(flte, e080110, 2, (RF, RR), rn_rd),
15734 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
15735 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
15736 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
15737
15738 /* The implementation of the FIX instruction is broken on some
15739 assemblers, in that it accepts a precision specifier as well as a
15740 rounding specifier, despite the fact that this is meaningless.
15741 To be more compatible, we accept it as well, though of course it
15742 does not set any bits. */
15743 cCE(fix, e100110, 2, (RR, RF), rd_rm),
15744 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
15745 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
15746 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
15747 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
15748 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
15749 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
15750 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
15751 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
15752 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
15753 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
15754 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
15755 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
15756
15757 /* Instructions that were new with the real FPA, call them V2. */
15758 #undef ARM_VARIANT
15759 #define ARM_VARIANT &fpu_fpa_ext_v2
15760 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15761 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15762 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15763 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15764 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15765 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15766
15767 #undef ARM_VARIANT
15768 #define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
15769 /* Moves and type conversions. */
15770 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
15771 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
15772 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
15773 cCE(fmstat, ef1fa10, 0, (), noargs),
15774 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
15775 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
15776 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
15777 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15778 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
15779 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15780 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
15781 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
15782
15783 /* Memory operations. */
15784 cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15785 cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15786 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15787 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15788 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15789 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15790 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15791 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15792 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15793 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15794 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15795 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15796 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15797 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15798 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15799 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15800 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15801 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15802
15803 /* Monadic operations. */
15804 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
15805 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
15806 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
15807
15808 /* Dyadic operations. */
15809 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15810 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15811 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15812 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15813 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15814 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15815 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15816 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15817 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15818
15819 /* Comparisons. */
15820 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
15821 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
15822 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
15823 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
15824
15825 #undef ARM_VARIANT
15826 #define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
15827 /* Moves and type conversions. */
15828 cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15829 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15830 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15831 cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
15832 cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
15833 cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
15834 cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
15835 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15836 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
15837 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15838 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15839 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15840 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15841
15842 /* Memory operations. */
15843 cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
15844 cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
15845 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15846 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15847 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15848 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15849 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15850 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15851 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15852 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15853
15854 /* Monadic operations. */
15855 cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15856 cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15857 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15858
15859 /* Dyadic operations. */
15860 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15861 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15862 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15863 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15864 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15865 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15866 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15867 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15868 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15869
15870 /* Comparisons. */
15871 cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15872 cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd),
15873 cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15874 cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd),
15875
15876 #undef ARM_VARIANT
15877 #define ARM_VARIANT &fpu_vfp_ext_v2
15878 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
15879 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
15880 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
15881 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
15882
15883 /* Instructions which may belong to either the Neon or VFP instruction sets.
15884 Individual encoder functions perform additional architecture checks. */
15885 #undef ARM_VARIANT
15886 #define ARM_VARIANT &fpu_vfp_ext_v1xd
15887 #undef THUMB_VARIANT
15888 #define THUMB_VARIANT &fpu_vfp_ext_v1xd
15889 /* These mnemonics are unique to VFP. */
15890 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
15891 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
15892 nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15893 nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15894 nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15895 nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15896 nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15897 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
15898 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
15899 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
15900
15901 /* Mnemonics shared by Neon and VFP. */
15902 nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
15903 nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15904 nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15905
15906 nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15907 nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15908
15909 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15910 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15911
15912 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15913 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15914 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15915 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15916 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15917 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15918 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
15919 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
15920
15921 nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
15922
15923 /* NOTE: All VMOV encoding is special-cased! */
15924 NCE(vmov, 0, 1, (VMOV), neon_mov),
15925 NCE(vmovq, 0, 1, (VMOV), neon_mov),
15926
15927 #undef THUMB_VARIANT
15928 #define THUMB_VARIANT &fpu_neon_ext_v1
15929 #undef ARM_VARIANT
15930 #define ARM_VARIANT &fpu_neon_ext_v1
15931 /* Data processing with three registers of the same length. */
15932 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
15933 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
15934 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
15935 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15936 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15937 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15938 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15939 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15940 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15941 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
15942 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15943 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15944 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15945 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15946 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15947 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
15948 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15949 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
15950 /* If not immediate, fall back to neon_dyadic_i64_su.
15951 shl_imm should accept I8 I16 I32 I64,
15952 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
15953 nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
15954 nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
15955 nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
15956 nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
15957 /* Logic ops, types optional & ignored. */
15958 nUF(vand, vand, 2, (RNDQ, NILO), neon_logic),
15959 nUF(vandq, vand, 2, (RNQ, NILO), neon_logic),
15960 nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic),
15961 nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic),
15962 nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic),
15963 nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic),
15964 nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic),
15965 nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic),
15966 nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
15967 nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
15968 /* Bitfield ops, untyped. */
15969 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15970 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15971 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15972 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15973 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15974 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15975 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
15976 nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15977 nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15978 nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15979 nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15980 nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15981 nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15982 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
15983 back to neon_dyadic_if_su. */
15984 nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
15985 nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
15986 nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
15987 nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
15988 nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
15989 nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
15990 nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
15991 nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
15992 /* Comparison. Type I8 I16 I32 F32. */
15993 nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
15994 nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
15995 /* As above, D registers only. */
15996 nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
15997 nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
15998 /* Int and float variants, signedness unimportant. */
15999 nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
16000 nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
16001 nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
16002 /* Add/sub take types I8 I16 I32 I64 F32. */
16003 nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
16004 nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
16005 /* vtst takes sizes 8, 16, 32. */
16006 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
16007 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
16008 /* VMUL takes I8 I16 I32 F32 P8. */
16009 nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
16010 /* VQD{R}MULH takes S16 S32. */
16011 nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16012 nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16013 nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16014 nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16015 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16016 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
16017 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16018 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
16019 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16020 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
16021 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16022 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
16023 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16024 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16025 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16026 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16027
16028 /* Two address, int/float. Types S8 S16 S32 F32. */
16029 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
16030 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
16031
16032 /* Data processing with two registers and a shift amount. */
16033 /* Right shifts, and variants with rounding.
16034 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
16035 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16036 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16037 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16038 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16039 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16040 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16041 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16042 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16043 /* Shift and insert. Sizes accepted 8 16 32 64. */
16044 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
16045 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
16046 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
16047 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
16048 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
16049 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
16050 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
16051 /* Right shift immediate, saturating & narrowing, with rounding variants.
16052 Types accepted S16 S32 S64 U16 U32 U64. */
16053 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16054 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16055 /* As above, unsigned. Types accepted S16 S32 S64. */
16056 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16057 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16058 /* Right shift narrowing. Types accepted I16 I32 I64. */
16059 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16060 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16061 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
16062 nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll),
16063 /* CVT with optional immediate for fixed-point variant. */
16064 nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
16065
16066 nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
16067 nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
16068
16069 /* Data processing, three registers of different lengths. */
16070 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
16071 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
16072 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
16073 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
16074 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
16075 /* If not scalar, fall back to neon_dyadic_long.
16076 Vector types as above, scalar types S16 S32 U16 U32. */
16077 nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16078 nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16079 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
16080 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16081 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16082 /* Dyadic, narrowing insns. Types I16 I32 I64. */
16083 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16084 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16085 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16086 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16087 /* Saturating doubling multiplies. Types S16 S32. */
16088 nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16089 nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16090 nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16091 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
16092 S16 S32 U16 U32. */
16093 nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
16094
16095 /* Extract. Size 8. */
16096 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
16097 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
16098
16099 /* Two registers, miscellaneous. */
16100 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
16101 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
16102 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
16103 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
16104 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
16105 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
16106 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
16107 /* Vector replicate. Sizes 8 16 32. */
16108 nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup),
16109 nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup),
16110 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
16111 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
16112 /* VMOVN. Types I16 I32 I64. */
16113 nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn),
16114 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
16115 nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn),
16116 /* VQMOVUN. Types S16 S32 S64. */
16117 nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun),
16118 /* VZIP / VUZP. Sizes 8 16 32. */
16119 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
16120 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
16121 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
16122 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
16123 /* VQABS / VQNEG. Types S8 S16 S32. */
16124 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16125 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
16126 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16127 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
16128 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
16129 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
16130 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
16131 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
16132 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
16133 /* Reciprocal estimates. Types U32 F32. */
16134 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
16135 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
16136 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
16137 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
16138 /* VCLS. Types S8 S16 S32. */
16139 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
16140 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
16141 /* VCLZ. Types I8 I16 I32. */
16142 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
16143 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
16144 /* VCNT. Size 8. */
16145 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
16146 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
16147 /* Two address, untyped. */
16148 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
16149 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
16150 /* VTRN. Sizes 8 16 32. */
16151 nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn),
16152 nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn),
16153
16154 /* Table lookup. Size 8. */
16155 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16156 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16157
16158 #undef THUMB_VARIANT
16159 #define THUMB_VARIANT &fpu_vfp_v3_or_neon_ext
16160 #undef ARM_VARIANT
16161 #define ARM_VARIANT &fpu_vfp_v3_or_neon_ext
16162 /* Neon element/structure load/store. */
16163 nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16164 nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16165 nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16166 nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16167 nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16168 nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16169 nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16170 nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16171
16172 #undef THUMB_VARIANT
16173 #define THUMB_VARIANT &fpu_vfp_ext_v3
16174 #undef ARM_VARIANT
16175 #define ARM_VARIANT &fpu_vfp_ext_v3
16176 cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const),
16177 cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const),
16178 cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16179 cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16180 cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16181 cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16182 cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16183 cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16184 cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16185 cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16186 cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16187 cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16188 cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16189 cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16190 cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16191 cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16192 cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16193 cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16194
16195 #undef THUMB_VARIANT
16196 #undef ARM_VARIANT
16197 #define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
16198 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16199 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16200 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16201 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16202 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16203 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16204 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
16205 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
16206
16207 #undef ARM_VARIANT
16208 #define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
16209 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
16210 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
16211 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
16212 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
16213 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
16214 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
16215 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
16216 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
16217 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
16218 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16219 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16220 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16221 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16222 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16223 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16224 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16225 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16226 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16227 cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd),
16228 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
16229 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16230 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16231 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16232 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16233 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16234 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16235 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
16236 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
16237 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
16238 cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn),
16239 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
16240 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
16241 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
16242 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
16243 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
16244 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
16245 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
16246 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16247 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16248 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16249 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16250 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16251 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16252 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16253 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16254 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16255 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
16256 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16257 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16258 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16259 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16260 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16261 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16262 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16263 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16264 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16265 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16266 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16267 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16268 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16269 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16270 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16271 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16272 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16273 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16274 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16275 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16276 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16277 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16278 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16279 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16280 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16281 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16282 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16283 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16284 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16285 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16286 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16287 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16288 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16289 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16290 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16291 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16292 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16293 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16294 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16295 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16296 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16297 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
16298 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16299 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16300 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16301 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16302 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16303 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16304 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16305 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16306 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16307 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16308 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16309 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16310 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16311 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16312 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16313 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16314 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16315 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16316 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16317 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16318 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16319 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
16320 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16321 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16322 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16323 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16324 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16325 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16326 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16327 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16328 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16329 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16330 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16331 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16332 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16333 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16334 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16335 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16336 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16337 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16338 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16339 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16340 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16341 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16342 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16343 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16344 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16345 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16346 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16347 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16348 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16349 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16350 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16351 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
16352 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
16353 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
16354 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
16355 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
16356 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
16357 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16358 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16359 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16360 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
16361 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
16362 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
16363 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
16364 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
16365 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
16366 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16367 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16368 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16369 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16370 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
16371
16372 #undef ARM_VARIANT
16373 #define ARM_VARIANT &arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
16374 cCE(torvscb, e13f190, 1, (RR), iwmmxt_tandorc),
16375 cCE(torvsch, e53f190, 1, (RR), iwmmxt_tandorc),
16376 cCE(torvscw, e93f190, 1, (RR), iwmmxt_tandorc),
16377 cCE(wabsb, e2001c0, 2, (RIWR, RIWR), rd_rn),
16378 cCE(wabsh, e6001c0, 2, (RIWR, RIWR), rd_rn),
16379 cCE(wabsw, ea001c0, 2, (RIWR, RIWR), rd_rn),
16380 cCE(wabsdiffb, e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16381 cCE(wabsdiffh, e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16382 cCE(wabsdiffw, e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16383 cCE(waddbhusl, e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16384 cCE(waddbhusm, e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16385 cCE(waddhc, e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16386 cCE(waddwc, ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16387 cCE(waddsubhx, ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16388 cCE(wavg4, e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16389 cCE(wavg4r, e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16390 cCE(wmaddsn, ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16391 cCE(wmaddsx, eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16392 cCE(wmaddun, ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16393 cCE(wmaddux, e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16394 cCE(wmerge, e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
16395 cCE(wmiabb, e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16396 cCE(wmiabt, e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16397 cCE(wmiatb, e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16398 cCE(wmiatt, e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16399 cCE(wmiabbn, e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16400 cCE(wmiabtn, e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16401 cCE(wmiatbn, e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16402 cCE(wmiattn, e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16403 cCE(wmiawbb, e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16404 cCE(wmiawbt, e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16405 cCE(wmiawtb, ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16406 cCE(wmiawtt, eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16407 cCE(wmiawbbn, ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16408 cCE(wmiawbtn, ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16409 cCE(wmiawtbn, ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16410 cCE(wmiawttn, ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16411 cCE(wmulsmr, ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16412 cCE(wmulumr, ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16413 cCE(wmulwumr, ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16414 cCE(wmulwsmr, ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16415 cCE(wmulwum, ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16416 cCE(wmulwsm, ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16417 cCE(wmulwl, eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16418 cCE(wqmiabb, e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16419 cCE(wqmiabt, e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16420 cCE(wqmiatb, ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16421 cCE(wqmiatt, eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16422 cCE(wqmiabbn, ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16423 cCE(wqmiabtn, ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16424 cCE(wqmiatbn, ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16425 cCE(wqmiattn, ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16426 cCE(wqmulm, e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16427 cCE(wqmulmr, e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16428 cCE(wqmulwm, ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16429 cCE(wqmulwmr, ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16430 cCE(wsubaddhx, ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16431
16432 #undef ARM_VARIANT
16433 #define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
16434 cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16435 cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16436 cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16437 cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
16438 cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16439 cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16440 cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16441 cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
16442 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
16443 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
16444 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
16445 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
16446 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
16447 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
16448 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
16449 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
16450 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
16451 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
16452 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
16453 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
16454 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
16455 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
16456 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
16457 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
16458 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
16459 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
16460 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
16461 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
16462 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
16463 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
16464 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
16465 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
16466 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
16467 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
16468 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
16469 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
16470 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
16471 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
16472 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
16473 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
16474 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
16475 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
16476 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
16477 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
16478 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
16479 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
16480 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
16481 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
16482 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
16483 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
16484 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
16485 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
16486 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
16487 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
16488 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
16489 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
16490 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
16491 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
16492 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
16493 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
16494 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
16495 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
16496 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
16497 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
16498 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16499 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16500 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16501 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16502 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16503 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16504 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16505 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16506 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16507 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16508 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
16509 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
16510 };
16511 #undef ARM_VARIANT
16512 #undef THUMB_VARIANT
16513 #undef TCE
16514 #undef TCM
16515 #undef TUE
16516 #undef TUF
16517 #undef TCC
16518 #undef cCE
16519 #undef cCL
16520 #undef C3E
16521 #undef CE
16522 #undef CM
16523 #undef UE
16524 #undef UF
16525 #undef UT
16526 #undef NUF
16527 #undef nUF
16528 #undef NCE
16529 #undef nCE
16530 #undef OPS0
16531 #undef OPS1
16532 #undef OPS2
16533 #undef OPS3
16534 #undef OPS4
16535 #undef OPS5
16536 #undef OPS6
16537 #undef do_0
16538 \f
16539 /* MD interface: bits in the object file. */
16540
16541 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
16542 for use in the a.out file, and stores them in the array pointed to by buf.
16543 This knows about the endian-ness of the target machine and does
16544 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
16545 2 (short) and 4 (long) Floating numbers are put out as a series of
16546 LITTLENUMS (shorts, here at least). */
16547
16548 void
16549 md_number_to_chars (char * buf, valueT val, int n)
16550 {
16551 if (target_big_endian)
16552 number_to_chars_bigendian (buf, val, n);
16553 else
16554 number_to_chars_littleendian (buf, val, n);
16555 }
16556
16557 static valueT
16558 md_chars_to_number (char * buf, int n)
16559 {
16560 valueT result = 0;
16561 unsigned char * where = (unsigned char *) buf;
16562
16563 if (target_big_endian)
16564 {
16565 while (n--)
16566 {
16567 result <<= 8;
16568 result |= (*where++ & 255);
16569 }
16570 }
16571 else
16572 {
16573 while (n--)
16574 {
16575 result <<= 8;
16576 result |= (where[n] & 255);
16577 }
16578 }
16579
16580 return result;
16581 }
16582
16583 /* MD interface: Sections. */
16584
16585 /* Estimate the size of a frag before relaxing. Assume everything fits in
16586 2 bytes. */
16587
16588 int
16589 md_estimate_size_before_relax (fragS * fragp,
16590 segT segtype ATTRIBUTE_UNUSED)
16591 {
16592 fragp->fr_var = 2;
16593 return 2;
16594 }
16595
16596 /* Convert a machine dependent frag. */
16597
16598 void
16599 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
16600 {
16601 unsigned long insn;
16602 unsigned long old_op;
16603 char *buf;
16604 expressionS exp;
16605 fixS *fixp;
16606 int reloc_type;
16607 int pc_rel;
16608 int opcode;
16609
16610 buf = fragp->fr_literal + fragp->fr_fix;
16611
16612 old_op = bfd_get_16(abfd, buf);
16613 if (fragp->fr_symbol)
16614 {
16615 exp.X_op = O_symbol;
16616 exp.X_add_symbol = fragp->fr_symbol;
16617 }
16618 else
16619 {
16620 exp.X_op = O_constant;
16621 }
16622 exp.X_add_number = fragp->fr_offset;
16623 opcode = fragp->fr_subtype;
16624 switch (opcode)
16625 {
16626 case T_MNEM_ldr_pc:
16627 case T_MNEM_ldr_pc2:
16628 case T_MNEM_ldr_sp:
16629 case T_MNEM_str_sp:
16630 case T_MNEM_ldr:
16631 case T_MNEM_ldrb:
16632 case T_MNEM_ldrh:
16633 case T_MNEM_str:
16634 case T_MNEM_strb:
16635 case T_MNEM_strh:
16636 if (fragp->fr_var == 4)
16637 {
16638 insn = THUMB_OP32 (opcode);
16639 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
16640 {
16641 insn |= (old_op & 0x700) << 4;
16642 }
16643 else
16644 {
16645 insn |= (old_op & 7) << 12;
16646 insn |= (old_op & 0x38) << 13;
16647 }
16648 insn |= 0x00000c00;
16649 put_thumb32_insn (buf, insn);
16650 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
16651 }
16652 else
16653 {
16654 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
16655 }
16656 pc_rel = (opcode == T_MNEM_ldr_pc2);
16657 break;
16658 case T_MNEM_adr:
16659 if (fragp->fr_var == 4)
16660 {
16661 insn = THUMB_OP32 (opcode);
16662 insn |= (old_op & 0xf0) << 4;
16663 put_thumb32_insn (buf, insn);
16664 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
16665 }
16666 else
16667 {
16668 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16669 exp.X_add_number -= 4;
16670 }
16671 pc_rel = 1;
16672 break;
16673 case T_MNEM_mov:
16674 case T_MNEM_movs:
16675 case T_MNEM_cmp:
16676 case T_MNEM_cmn:
16677 if (fragp->fr_var == 4)
16678 {
16679 int r0off = (opcode == T_MNEM_mov
16680 || opcode == T_MNEM_movs) ? 0 : 8;
16681 insn = THUMB_OP32 (opcode);
16682 insn = (insn & 0xe1ffffff) | 0x10000000;
16683 insn |= (old_op & 0x700) << r0off;
16684 put_thumb32_insn (buf, insn);
16685 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16686 }
16687 else
16688 {
16689 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
16690 }
16691 pc_rel = 0;
16692 break;
16693 case T_MNEM_b:
16694 if (fragp->fr_var == 4)
16695 {
16696 insn = THUMB_OP32(opcode);
16697 put_thumb32_insn (buf, insn);
16698 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
16699 }
16700 else
16701 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
16702 pc_rel = 1;
16703 break;
16704 case T_MNEM_bcond:
16705 if (fragp->fr_var == 4)
16706 {
16707 insn = THUMB_OP32(opcode);
16708 insn |= (old_op & 0xf00) << 14;
16709 put_thumb32_insn (buf, insn);
16710 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
16711 }
16712 else
16713 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
16714 pc_rel = 1;
16715 break;
16716 case T_MNEM_add_sp:
16717 case T_MNEM_add_pc:
16718 case T_MNEM_inc_sp:
16719 case T_MNEM_dec_sp:
16720 if (fragp->fr_var == 4)
16721 {
16722 /* ??? Choose between add and addw. */
16723 insn = THUMB_OP32 (opcode);
16724 insn |= (old_op & 0xf0) << 4;
16725 put_thumb32_insn (buf, insn);
16726 if (opcode == T_MNEM_add_pc)
16727 reloc_type = BFD_RELOC_ARM_T32_IMM12;
16728 else
16729 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16730 }
16731 else
16732 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16733 pc_rel = 0;
16734 break;
16735
16736 case T_MNEM_addi:
16737 case T_MNEM_addis:
16738 case T_MNEM_subi:
16739 case T_MNEM_subis:
16740 if (fragp->fr_var == 4)
16741 {
16742 insn = THUMB_OP32 (opcode);
16743 insn |= (old_op & 0xf0) << 4;
16744 insn |= (old_op & 0xf) << 16;
16745 put_thumb32_insn (buf, insn);
16746 if (insn & (1 << 20))
16747 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16748 else
16749 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16750 }
16751 else
16752 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16753 pc_rel = 0;
16754 break;
16755 default:
16756 abort ();
16757 }
16758 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
16759 reloc_type);
16760 fixp->fx_file = fragp->fr_file;
16761 fixp->fx_line = fragp->fr_line;
16762 fragp->fr_fix += fragp->fr_var;
16763 }
16764
16765 /* Return the size of a relaxable immediate operand instruction.
16766 SHIFT and SIZE specify the form of the allowable immediate. */
16767 static int
16768 relax_immediate (fragS *fragp, int size, int shift)
16769 {
16770 offsetT offset;
16771 offsetT mask;
16772 offsetT low;
16773
16774 /* ??? Should be able to do better than this. */
16775 if (fragp->fr_symbol)
16776 return 4;
16777
16778 low = (1 << shift) - 1;
16779 mask = (1 << (shift + size)) - (1 << shift);
16780 offset = fragp->fr_offset;
16781 /* Force misaligned offsets to 32-bit variant. */
16782 if (offset & low)
16783 return 4;
16784 if (offset & ~mask)
16785 return 4;
16786 return 2;
16787 }
16788
16789 /* Get the address of a symbol during relaxation. */
16790 static addressT
16791 relaxed_symbol_addr (fragS *fragp, long stretch)
16792 {
16793 fragS *sym_frag;
16794 addressT addr;
16795 symbolS *sym;
16796
16797 sym = fragp->fr_symbol;
16798 sym_frag = symbol_get_frag (sym);
16799 know (S_GET_SEGMENT (sym) != absolute_section
16800 || sym_frag == &zero_address_frag);
16801 addr = S_GET_VALUE (sym) + fragp->fr_offset;
16802
16803 /* If frag has yet to be reached on this pass, assume it will
16804 move by STRETCH just as we did. If this is not so, it will
16805 be because some frag between grows, and that will force
16806 another pass. */
16807
16808 if (stretch != 0
16809 && sym_frag->relax_marker != fragp->relax_marker)
16810 {
16811 fragS *f;
16812
16813 /* Adjust stretch for any alignment frag. Note that if have
16814 been expanding the earlier code, the symbol may be
16815 defined in what appears to be an earlier frag. FIXME:
16816 This doesn't handle the fr_subtype field, which specifies
16817 a maximum number of bytes to skip when doing an
16818 alignment. */
16819 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
16820 {
16821 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
16822 {
16823 if (stretch < 0)
16824 stretch = - ((- stretch)
16825 & ~ ((1 << (int) f->fr_offset) - 1));
16826 else
16827 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
16828 if (stretch == 0)
16829 break;
16830 }
16831 }
16832 if (f != NULL)
16833 addr += stretch;
16834 }
16835
16836 return addr;
16837 }
16838
16839 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
16840 load. */
16841 static int
16842 relax_adr (fragS *fragp, asection *sec, long stretch)
16843 {
16844 addressT addr;
16845 offsetT val;
16846
16847 /* Assume worst case for symbols not known to be in the same section. */
16848 if (!S_IS_DEFINED (fragp->fr_symbol)
16849 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16850 return 4;
16851
16852 val = relaxed_symbol_addr (fragp, stretch);
16853 addr = fragp->fr_address + fragp->fr_fix;
16854 addr = (addr + 4) & ~3;
16855 /* Force misaligned targets to 32-bit variant. */
16856 if (val & 3)
16857 return 4;
16858 val -= addr;
16859 if (val < 0 || val > 1020)
16860 return 4;
16861 return 2;
16862 }
16863
16864 /* Return the size of a relaxable add/sub immediate instruction. */
16865 static int
16866 relax_addsub (fragS *fragp, asection *sec)
16867 {
16868 char *buf;
16869 int op;
16870
16871 buf = fragp->fr_literal + fragp->fr_fix;
16872 op = bfd_get_16(sec->owner, buf);
16873 if ((op & 0xf) == ((op >> 4) & 0xf))
16874 return relax_immediate (fragp, 8, 0);
16875 else
16876 return relax_immediate (fragp, 3, 0);
16877 }
16878
16879
16880 /* Return the size of a relaxable branch instruction. BITS is the
16881 size of the offset field in the narrow instruction. */
16882
16883 static int
16884 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
16885 {
16886 addressT addr;
16887 offsetT val;
16888 offsetT limit;
16889
16890 /* Assume worst case for symbols not known to be in the same section. */
16891 if (!S_IS_DEFINED (fragp->fr_symbol)
16892 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16893 return 4;
16894
16895 val = relaxed_symbol_addr (fragp, stretch);
16896 addr = fragp->fr_address + fragp->fr_fix + 4;
16897 val -= addr;
16898
16899 /* Offset is a signed value *2 */
16900 limit = 1 << bits;
16901 if (val >= limit || val < -limit)
16902 return 4;
16903 return 2;
16904 }
16905
16906
16907 /* Relax a machine dependent frag. This returns the amount by which
16908 the current size of the frag should change. */
16909
16910 int
16911 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
16912 {
16913 int oldsize;
16914 int newsize;
16915
16916 oldsize = fragp->fr_var;
16917 switch (fragp->fr_subtype)
16918 {
16919 case T_MNEM_ldr_pc2:
16920 newsize = relax_adr (fragp, sec, stretch);
16921 break;
16922 case T_MNEM_ldr_pc:
16923 case T_MNEM_ldr_sp:
16924 case T_MNEM_str_sp:
16925 newsize = relax_immediate (fragp, 8, 2);
16926 break;
16927 case T_MNEM_ldr:
16928 case T_MNEM_str:
16929 newsize = relax_immediate (fragp, 5, 2);
16930 break;
16931 case T_MNEM_ldrh:
16932 case T_MNEM_strh:
16933 newsize = relax_immediate (fragp, 5, 1);
16934 break;
16935 case T_MNEM_ldrb:
16936 case T_MNEM_strb:
16937 newsize = relax_immediate (fragp, 5, 0);
16938 break;
16939 case T_MNEM_adr:
16940 newsize = relax_adr (fragp, sec, stretch);
16941 break;
16942 case T_MNEM_mov:
16943 case T_MNEM_movs:
16944 case T_MNEM_cmp:
16945 case T_MNEM_cmn:
16946 newsize = relax_immediate (fragp, 8, 0);
16947 break;
16948 case T_MNEM_b:
16949 newsize = relax_branch (fragp, sec, 11, stretch);
16950 break;
16951 case T_MNEM_bcond:
16952 newsize = relax_branch (fragp, sec, 8, stretch);
16953 break;
16954 case T_MNEM_add_sp:
16955 case T_MNEM_add_pc:
16956 newsize = relax_immediate (fragp, 8, 2);
16957 break;
16958 case T_MNEM_inc_sp:
16959 case T_MNEM_dec_sp:
16960 newsize = relax_immediate (fragp, 7, 2);
16961 break;
16962 case T_MNEM_addi:
16963 case T_MNEM_addis:
16964 case T_MNEM_subi:
16965 case T_MNEM_subis:
16966 newsize = relax_addsub (fragp, sec);
16967 break;
16968 default:
16969 abort ();
16970 }
16971
16972 fragp->fr_var = newsize;
16973 /* Freeze wide instructions that are at or before the same location as
16974 in the previous pass. This avoids infinite loops.
16975 Don't freeze them unconditionally because targets may be artificially
16976 misaligned by the expansion of preceding frags. */
16977 if (stretch <= 0 && newsize > 2)
16978 {
16979 md_convert_frag (sec->owner, sec, fragp);
16980 frag_wane (fragp);
16981 }
16982
16983 return newsize - oldsize;
16984 }
16985
16986 /* Round up a section size to the appropriate boundary. */
16987
16988 valueT
16989 md_section_align (segT segment ATTRIBUTE_UNUSED,
16990 valueT size)
16991 {
16992 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
16993 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
16994 {
16995 /* For a.out, force the section size to be aligned. If we don't do
16996 this, BFD will align it for us, but it will not write out the
16997 final bytes of the section. This may be a bug in BFD, but it is
16998 easier to fix it here since that is how the other a.out targets
16999 work. */
17000 int align;
17001
17002 align = bfd_get_section_alignment (stdoutput, segment);
17003 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
17004 }
17005 #endif
17006
17007 return size;
17008 }
17009
17010 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
17011 of an rs_align_code fragment. */
17012
17013 void
17014 arm_handle_align (fragS * fragP)
17015 {
17016 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
17017 static char const thumb_noop[2] = { 0xc0, 0x46 };
17018 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
17019 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
17020
17021 int bytes, fix, noop_size;
17022 char * p;
17023 const char * noop;
17024
17025 if (fragP->fr_type != rs_align_code)
17026 return;
17027
17028 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
17029 p = fragP->fr_literal + fragP->fr_fix;
17030 fix = 0;
17031
17032 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
17033 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
17034
17035 if (fragP->tc_frag_data)
17036 {
17037 if (target_big_endian)
17038 noop = thumb_bigend_noop;
17039 else
17040 noop = thumb_noop;
17041 noop_size = sizeof (thumb_noop);
17042 }
17043 else
17044 {
17045 if (target_big_endian)
17046 noop = arm_bigend_noop;
17047 else
17048 noop = arm_noop;
17049 noop_size = sizeof (arm_noop);
17050 }
17051
17052 if (bytes & (noop_size - 1))
17053 {
17054 fix = bytes & (noop_size - 1);
17055 memset (p, 0, fix);
17056 p += fix;
17057 bytes -= fix;
17058 }
17059
17060 while (bytes >= noop_size)
17061 {
17062 memcpy (p, noop, noop_size);
17063 p += noop_size;
17064 bytes -= noop_size;
17065 fix += noop_size;
17066 }
17067
17068 fragP->fr_fix += fix;
17069 fragP->fr_var = noop_size;
17070 }
17071
17072 /* Called from md_do_align. Used to create an alignment
17073 frag in a code section. */
17074
17075 void
17076 arm_frag_align_code (int n, int max)
17077 {
17078 char * p;
17079
17080 /* We assume that there will never be a requirement
17081 to support alignments greater than 32 bytes. */
17082 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
17083 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
17084
17085 p = frag_var (rs_align_code,
17086 MAX_MEM_FOR_RS_ALIGN_CODE,
17087 1,
17088 (relax_substateT) max,
17089 (symbolS *) NULL,
17090 (offsetT) n,
17091 (char *) NULL);
17092 *p = 0;
17093 }
17094
17095 /* Perform target specific initialisation of a frag. */
17096
17097 void
17098 arm_init_frag (fragS * fragP)
17099 {
17100 /* Record whether this frag is in an ARM or a THUMB area. */
17101 fragP->tc_frag_data = thumb_mode;
17102 }
17103
17104 #ifdef OBJ_ELF
17105 /* When we change sections we need to issue a new mapping symbol. */
17106
17107 void
17108 arm_elf_change_section (void)
17109 {
17110 flagword flags;
17111 segment_info_type *seginfo;
17112
17113 /* Link an unlinked unwind index table section to the .text section. */
17114 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
17115 && elf_linked_to_section (now_seg) == NULL)
17116 elf_linked_to_section (now_seg) = text_section;
17117
17118 if (!SEG_NORMAL (now_seg))
17119 return;
17120
17121 flags = bfd_get_section_flags (stdoutput, now_seg);
17122
17123 /* We can ignore sections that only contain debug info. */
17124 if ((flags & SEC_ALLOC) == 0)
17125 return;
17126
17127 seginfo = seg_info (now_seg);
17128 mapstate = seginfo->tc_segment_info_data.mapstate;
17129 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
17130 }
17131
17132 int
17133 arm_elf_section_type (const char * str, size_t len)
17134 {
17135 if (len == 5 && strncmp (str, "exidx", 5) == 0)
17136 return SHT_ARM_EXIDX;
17137
17138 return -1;
17139 }
17140 \f
17141 /* Code to deal with unwinding tables. */
17142
17143 static void add_unwind_adjustsp (offsetT);
17144
17145 /* Generate any deferred unwind frame offset. */
17146
17147 static void
17148 flush_pending_unwind (void)
17149 {
17150 offsetT offset;
17151
17152 offset = unwind.pending_offset;
17153 unwind.pending_offset = 0;
17154 if (offset != 0)
17155 add_unwind_adjustsp (offset);
17156 }
17157
17158 /* Add an opcode to this list for this function. Two-byte opcodes should
17159 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
17160 order. */
17161
17162 static void
17163 add_unwind_opcode (valueT op, int length)
17164 {
17165 /* Add any deferred stack adjustment. */
17166 if (unwind.pending_offset)
17167 flush_pending_unwind ();
17168
17169 unwind.sp_restored = 0;
17170
17171 if (unwind.opcode_count + length > unwind.opcode_alloc)
17172 {
17173 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
17174 if (unwind.opcodes)
17175 unwind.opcodes = xrealloc (unwind.opcodes,
17176 unwind.opcode_alloc);
17177 else
17178 unwind.opcodes = xmalloc (unwind.opcode_alloc);
17179 }
17180 while (length > 0)
17181 {
17182 length--;
17183 unwind.opcodes[unwind.opcode_count] = op & 0xff;
17184 op >>= 8;
17185 unwind.opcode_count++;
17186 }
17187 }
17188
17189 /* Add unwind opcodes to adjust the stack pointer. */
17190
17191 static void
17192 add_unwind_adjustsp (offsetT offset)
17193 {
17194 valueT op;
17195
17196 if (offset > 0x200)
17197 {
17198 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
17199 char bytes[5];
17200 int n;
17201 valueT o;
17202
17203 /* Long form: 0xb2, uleb128. */
17204 /* This might not fit in a word so add the individual bytes,
17205 remembering the list is built in reverse order. */
17206 o = (valueT) ((offset - 0x204) >> 2);
17207 if (o == 0)
17208 add_unwind_opcode (0, 1);
17209
17210 /* Calculate the uleb128 encoding of the offset. */
17211 n = 0;
17212 while (o)
17213 {
17214 bytes[n] = o & 0x7f;
17215 o >>= 7;
17216 if (o)
17217 bytes[n] |= 0x80;
17218 n++;
17219 }
17220 /* Add the insn. */
17221 for (; n; n--)
17222 add_unwind_opcode (bytes[n - 1], 1);
17223 add_unwind_opcode (0xb2, 1);
17224 }
17225 else if (offset > 0x100)
17226 {
17227 /* Two short opcodes. */
17228 add_unwind_opcode (0x3f, 1);
17229 op = (offset - 0x104) >> 2;
17230 add_unwind_opcode (op, 1);
17231 }
17232 else if (offset > 0)
17233 {
17234 /* Short opcode. */
17235 op = (offset - 4) >> 2;
17236 add_unwind_opcode (op, 1);
17237 }
17238 else if (offset < 0)
17239 {
17240 offset = -offset;
17241 while (offset > 0x100)
17242 {
17243 add_unwind_opcode (0x7f, 1);
17244 offset -= 0x100;
17245 }
17246 op = ((offset - 4) >> 2) | 0x40;
17247 add_unwind_opcode (op, 1);
17248 }
17249 }
17250
17251 /* Finish the list of unwind opcodes for this function. */
17252 static void
17253 finish_unwind_opcodes (void)
17254 {
17255 valueT op;
17256
17257 if (unwind.fp_used)
17258 {
17259 /* Adjust sp as necessary. */
17260 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
17261 flush_pending_unwind ();
17262
17263 /* After restoring sp from the frame pointer. */
17264 op = 0x90 | unwind.fp_reg;
17265 add_unwind_opcode (op, 1);
17266 }
17267 else
17268 flush_pending_unwind ();
17269 }
17270
17271
17272 /* Start an exception table entry. If idx is nonzero this is an index table
17273 entry. */
17274
17275 static void
17276 start_unwind_section (const segT text_seg, int idx)
17277 {
17278 const char * text_name;
17279 const char * prefix;
17280 const char * prefix_once;
17281 const char * group_name;
17282 size_t prefix_len;
17283 size_t text_len;
17284 char * sec_name;
17285 size_t sec_name_len;
17286 int type;
17287 int flags;
17288 int linkonce;
17289
17290 if (idx)
17291 {
17292 prefix = ELF_STRING_ARM_unwind;
17293 prefix_once = ELF_STRING_ARM_unwind_once;
17294 type = SHT_ARM_EXIDX;
17295 }
17296 else
17297 {
17298 prefix = ELF_STRING_ARM_unwind_info;
17299 prefix_once = ELF_STRING_ARM_unwind_info_once;
17300 type = SHT_PROGBITS;
17301 }
17302
17303 text_name = segment_name (text_seg);
17304 if (streq (text_name, ".text"))
17305 text_name = "";
17306
17307 if (strncmp (text_name, ".gnu.linkonce.t.",
17308 strlen (".gnu.linkonce.t.")) == 0)
17309 {
17310 prefix = prefix_once;
17311 text_name += strlen (".gnu.linkonce.t.");
17312 }
17313
17314 prefix_len = strlen (prefix);
17315 text_len = strlen (text_name);
17316 sec_name_len = prefix_len + text_len;
17317 sec_name = xmalloc (sec_name_len + 1);
17318 memcpy (sec_name, prefix, prefix_len);
17319 memcpy (sec_name + prefix_len, text_name, text_len);
17320 sec_name[prefix_len + text_len] = '\0';
17321
17322 flags = SHF_ALLOC;
17323 linkonce = 0;
17324 group_name = 0;
17325
17326 /* Handle COMDAT group. */
17327 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
17328 {
17329 group_name = elf_group_name (text_seg);
17330 if (group_name == NULL)
17331 {
17332 as_bad (_("Group section `%s' has no group signature"),
17333 segment_name (text_seg));
17334 ignore_rest_of_line ();
17335 return;
17336 }
17337 flags |= SHF_GROUP;
17338 linkonce = 1;
17339 }
17340
17341 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
17342
17343 /* Set the section link for index tables. */
17344 if (idx)
17345 elf_linked_to_section (now_seg) = text_seg;
17346 }
17347
17348
17349 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
17350 personality routine data. Returns zero, or the index table value for
17351 and inline entry. */
17352
17353 static valueT
17354 create_unwind_entry (int have_data)
17355 {
17356 int size;
17357 addressT where;
17358 char *ptr;
17359 /* The current word of data. */
17360 valueT data;
17361 /* The number of bytes left in this word. */
17362 int n;
17363
17364 finish_unwind_opcodes ();
17365
17366 /* Remember the current text section. */
17367 unwind.saved_seg = now_seg;
17368 unwind.saved_subseg = now_subseg;
17369
17370 start_unwind_section (now_seg, 0);
17371
17372 if (unwind.personality_routine == NULL)
17373 {
17374 if (unwind.personality_index == -2)
17375 {
17376 if (have_data)
17377 as_bad (_("handlerdata in cantunwind frame"));
17378 return 1; /* EXIDX_CANTUNWIND. */
17379 }
17380
17381 /* Use a default personality routine if none is specified. */
17382 if (unwind.personality_index == -1)
17383 {
17384 if (unwind.opcode_count > 3)
17385 unwind.personality_index = 1;
17386 else
17387 unwind.personality_index = 0;
17388 }
17389
17390 /* Space for the personality routine entry. */
17391 if (unwind.personality_index == 0)
17392 {
17393 if (unwind.opcode_count > 3)
17394 as_bad (_("too many unwind opcodes for personality routine 0"));
17395
17396 if (!have_data)
17397 {
17398 /* All the data is inline in the index table. */
17399 data = 0x80;
17400 n = 3;
17401 while (unwind.opcode_count > 0)
17402 {
17403 unwind.opcode_count--;
17404 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17405 n--;
17406 }
17407
17408 /* Pad with "finish" opcodes. */
17409 while (n--)
17410 data = (data << 8) | 0xb0;
17411
17412 return data;
17413 }
17414 size = 0;
17415 }
17416 else
17417 /* We get two opcodes "free" in the first word. */
17418 size = unwind.opcode_count - 2;
17419 }
17420 else
17421 /* An extra byte is required for the opcode count. */
17422 size = unwind.opcode_count + 1;
17423
17424 size = (size + 3) >> 2;
17425 if (size > 0xff)
17426 as_bad (_("too many unwind opcodes"));
17427
17428 frag_align (2, 0, 0);
17429 record_alignment (now_seg, 2);
17430 unwind.table_entry = expr_build_dot ();
17431
17432 /* Allocate the table entry. */
17433 ptr = frag_more ((size << 2) + 4);
17434 where = frag_now_fix () - ((size << 2) + 4);
17435
17436 switch (unwind.personality_index)
17437 {
17438 case -1:
17439 /* ??? Should this be a PLT generating relocation? */
17440 /* Custom personality routine. */
17441 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
17442 BFD_RELOC_ARM_PREL31);
17443
17444 where += 4;
17445 ptr += 4;
17446
17447 /* Set the first byte to the number of additional words. */
17448 data = size - 1;
17449 n = 3;
17450 break;
17451
17452 /* ABI defined personality routines. */
17453 case 0:
17454 /* Three opcodes bytes are packed into the first word. */
17455 data = 0x80;
17456 n = 3;
17457 break;
17458
17459 case 1:
17460 case 2:
17461 /* The size and first two opcode bytes go in the first word. */
17462 data = ((0x80 + unwind.personality_index) << 8) | size;
17463 n = 2;
17464 break;
17465
17466 default:
17467 /* Should never happen. */
17468 abort ();
17469 }
17470
17471 /* Pack the opcodes into words (MSB first), reversing the list at the same
17472 time. */
17473 while (unwind.opcode_count > 0)
17474 {
17475 if (n == 0)
17476 {
17477 md_number_to_chars (ptr, data, 4);
17478 ptr += 4;
17479 n = 4;
17480 data = 0;
17481 }
17482 unwind.opcode_count--;
17483 n--;
17484 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17485 }
17486
17487 /* Finish off the last word. */
17488 if (n < 4)
17489 {
17490 /* Pad with "finish" opcodes. */
17491 while (n--)
17492 data = (data << 8) | 0xb0;
17493
17494 md_number_to_chars (ptr, data, 4);
17495 }
17496
17497 if (!have_data)
17498 {
17499 /* Add an empty descriptor if there is no user-specified data. */
17500 ptr = frag_more (4);
17501 md_number_to_chars (ptr, 0, 4);
17502 }
17503
17504 return 0;
17505 }
17506
17507
17508 /* Initialize the DWARF-2 unwind information for this procedure. */
17509
17510 void
17511 tc_arm_frame_initial_instructions (void)
17512 {
17513 cfi_add_CFA_def_cfa (REG_SP, 0);
17514 }
17515 #endif /* OBJ_ELF */
17516
17517 /* Convert REGNAME to a DWARF-2 register number. */
17518
17519 int
17520 tc_arm_regname_to_dw2regnum (char *regname)
17521 {
17522 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
17523
17524 if (reg == FAIL)
17525 return -1;
17526
17527 return reg;
17528 }
17529
17530 #ifdef TE_PE
17531 void
17532 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
17533 {
17534 expressionS expr;
17535
17536 expr.X_op = O_secrel;
17537 expr.X_add_symbol = symbol;
17538 expr.X_add_number = 0;
17539 emit_expr (&expr, size);
17540 }
17541 #endif
17542
17543 /* MD interface: Symbol and relocation handling. */
17544
17545 /* Return the address within the segment that a PC-relative fixup is
17546 relative to. For ARM, PC-relative fixups applied to instructions
17547 are generally relative to the location of the fixup plus 8 bytes.
17548 Thumb branches are offset by 4, and Thumb loads relative to PC
17549 require special handling. */
17550
17551 long
17552 md_pcrel_from_section (fixS * fixP, segT seg)
17553 {
17554 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
17555
17556 /* If this is pc-relative and we are going to emit a relocation
17557 then we just want to put out any pipeline compensation that the linker
17558 will need. Otherwise we want to use the calculated base.
17559 For WinCE we skip the bias for externals as well, since this
17560 is how the MS ARM-CE assembler behaves and we want to be compatible. */
17561 if (fixP->fx_pcrel
17562 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
17563 || (arm_force_relocation (fixP)
17564 #ifdef TE_WINCE
17565 && !S_IS_EXTERNAL (fixP->fx_addsy)
17566 #endif
17567 )))
17568 base = 0;
17569
17570 switch (fixP->fx_r_type)
17571 {
17572 /* PC relative addressing on the Thumb is slightly odd as the
17573 bottom two bits of the PC are forced to zero for the
17574 calculation. This happens *after* application of the
17575 pipeline offset. However, Thumb adrl already adjusts for
17576 this, so we need not do it again. */
17577 case BFD_RELOC_ARM_THUMB_ADD:
17578 return base & ~3;
17579
17580 case BFD_RELOC_ARM_THUMB_OFFSET:
17581 case BFD_RELOC_ARM_T32_OFFSET_IMM:
17582 case BFD_RELOC_ARM_T32_ADD_PC12:
17583 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
17584 return (base + 4) & ~3;
17585
17586 /* Thumb branches are simply offset by +4. */
17587 case BFD_RELOC_THUMB_PCREL_BRANCH7:
17588 case BFD_RELOC_THUMB_PCREL_BRANCH9:
17589 case BFD_RELOC_THUMB_PCREL_BRANCH12:
17590 case BFD_RELOC_THUMB_PCREL_BRANCH20:
17591 case BFD_RELOC_THUMB_PCREL_BRANCH23:
17592 case BFD_RELOC_THUMB_PCREL_BRANCH25:
17593 case BFD_RELOC_THUMB_PCREL_BLX:
17594 return base + 4;
17595
17596 /* ARM mode branches are offset by +8. However, the Windows CE
17597 loader expects the relocation not to take this into account. */
17598 case BFD_RELOC_ARM_PCREL_BRANCH:
17599 case BFD_RELOC_ARM_PCREL_CALL:
17600 case BFD_RELOC_ARM_PCREL_JUMP:
17601 case BFD_RELOC_ARM_PCREL_BLX:
17602 case BFD_RELOC_ARM_PLT32:
17603 #ifdef TE_WINCE
17604 /* When handling fixups immediately, because we have already
17605 discovered the value of a symbol, or the address of the frag involved
17606 we must account for the offset by +8, as the OS loader will never see the reloc.
17607 see fixup_segment() in write.c
17608 The S_IS_EXTERNAL test handles the case of global symbols.
17609 Those need the calculated base, not just the pipe compensation the linker will need. */
17610 if (fixP->fx_pcrel
17611 && fixP->fx_addsy != NULL
17612 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
17613 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
17614 return base + 8;
17615 return base;
17616 #else
17617 return base + 8;
17618 #endif
17619
17620 /* ARM mode loads relative to PC are also offset by +8. Unlike
17621 branches, the Windows CE loader *does* expect the relocation
17622 to take this into account. */
17623 case BFD_RELOC_ARM_OFFSET_IMM:
17624 case BFD_RELOC_ARM_OFFSET_IMM8:
17625 case BFD_RELOC_ARM_HWLITERAL:
17626 case BFD_RELOC_ARM_LITERAL:
17627 case BFD_RELOC_ARM_CP_OFF_IMM:
17628 return base + 8;
17629
17630
17631 /* Other PC-relative relocations are un-offset. */
17632 default:
17633 return base;
17634 }
17635 }
17636
17637 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
17638 Otherwise we have no need to default values of symbols. */
17639
17640 symbolS *
17641 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
17642 {
17643 #ifdef OBJ_ELF
17644 if (name[0] == '_' && name[1] == 'G'
17645 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
17646 {
17647 if (!GOT_symbol)
17648 {
17649 if (symbol_find (name))
17650 as_bad (_("GOT already in the symbol table"));
17651
17652 GOT_symbol = symbol_new (name, undefined_section,
17653 (valueT) 0, & zero_address_frag);
17654 }
17655
17656 return GOT_symbol;
17657 }
17658 #endif
17659
17660 return 0;
17661 }
17662
17663 /* Subroutine of md_apply_fix. Check to see if an immediate can be
17664 computed as two separate immediate values, added together. We
17665 already know that this value cannot be computed by just one ARM
17666 instruction. */
17667
17668 static unsigned int
17669 validate_immediate_twopart (unsigned int val,
17670 unsigned int * highpart)
17671 {
17672 unsigned int a;
17673 unsigned int i;
17674
17675 for (i = 0; i < 32; i += 2)
17676 if (((a = rotate_left (val, i)) & 0xff) != 0)
17677 {
17678 if (a & 0xff00)
17679 {
17680 if (a & ~ 0xffff)
17681 continue;
17682 * highpart = (a >> 8) | ((i + 24) << 7);
17683 }
17684 else if (a & 0xff0000)
17685 {
17686 if (a & 0xff000000)
17687 continue;
17688 * highpart = (a >> 16) | ((i + 16) << 7);
17689 }
17690 else
17691 {
17692 assert (a & 0xff000000);
17693 * highpart = (a >> 24) | ((i + 8) << 7);
17694 }
17695
17696 return (a & 0xff) | (i << 7);
17697 }
17698
17699 return FAIL;
17700 }
17701
17702 static int
17703 validate_offset_imm (unsigned int val, int hwse)
17704 {
17705 if ((hwse && val > 255) || val > 4095)
17706 return FAIL;
17707 return val;
17708 }
17709
17710 /* Subroutine of md_apply_fix. Do those data_ops which can take a
17711 negative immediate constant by altering the instruction. A bit of
17712 a hack really.
17713 MOV <-> MVN
17714 AND <-> BIC
17715 ADC <-> SBC
17716 by inverting the second operand, and
17717 ADD <-> SUB
17718 CMP <-> CMN
17719 by negating the second operand. */
17720
17721 static int
17722 negate_data_op (unsigned long * instruction,
17723 unsigned long value)
17724 {
17725 int op, new_inst;
17726 unsigned long negated, inverted;
17727
17728 negated = encode_arm_immediate (-value);
17729 inverted = encode_arm_immediate (~value);
17730
17731 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
17732 switch (op)
17733 {
17734 /* First negates. */
17735 case OPCODE_SUB: /* ADD <-> SUB */
17736 new_inst = OPCODE_ADD;
17737 value = negated;
17738 break;
17739
17740 case OPCODE_ADD:
17741 new_inst = OPCODE_SUB;
17742 value = negated;
17743 break;
17744
17745 case OPCODE_CMP: /* CMP <-> CMN */
17746 new_inst = OPCODE_CMN;
17747 value = negated;
17748 break;
17749
17750 case OPCODE_CMN:
17751 new_inst = OPCODE_CMP;
17752 value = negated;
17753 break;
17754
17755 /* Now Inverted ops. */
17756 case OPCODE_MOV: /* MOV <-> MVN */
17757 new_inst = OPCODE_MVN;
17758 value = inverted;
17759 break;
17760
17761 case OPCODE_MVN:
17762 new_inst = OPCODE_MOV;
17763 value = inverted;
17764 break;
17765
17766 case OPCODE_AND: /* AND <-> BIC */
17767 new_inst = OPCODE_BIC;
17768 value = inverted;
17769 break;
17770
17771 case OPCODE_BIC:
17772 new_inst = OPCODE_AND;
17773 value = inverted;
17774 break;
17775
17776 case OPCODE_ADC: /* ADC <-> SBC */
17777 new_inst = OPCODE_SBC;
17778 value = inverted;
17779 break;
17780
17781 case OPCODE_SBC:
17782 new_inst = OPCODE_ADC;
17783 value = inverted;
17784 break;
17785
17786 /* We cannot do anything. */
17787 default:
17788 return FAIL;
17789 }
17790
17791 if (value == (unsigned) FAIL)
17792 return FAIL;
17793
17794 *instruction &= OPCODE_MASK;
17795 *instruction |= new_inst << DATA_OP_SHIFT;
17796 return value;
17797 }
17798
17799 /* Like negate_data_op, but for Thumb-2. */
17800
17801 static unsigned int
17802 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
17803 {
17804 int op, new_inst;
17805 int rd;
17806 unsigned int negated, inverted;
17807
17808 negated = encode_thumb32_immediate (-value);
17809 inverted = encode_thumb32_immediate (~value);
17810
17811 rd = (*instruction >> 8) & 0xf;
17812 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
17813 switch (op)
17814 {
17815 /* ADD <-> SUB. Includes CMP <-> CMN. */
17816 case T2_OPCODE_SUB:
17817 new_inst = T2_OPCODE_ADD;
17818 value = negated;
17819 break;
17820
17821 case T2_OPCODE_ADD:
17822 new_inst = T2_OPCODE_SUB;
17823 value = negated;
17824 break;
17825
17826 /* ORR <-> ORN. Includes MOV <-> MVN. */
17827 case T2_OPCODE_ORR:
17828 new_inst = T2_OPCODE_ORN;
17829 value = inverted;
17830 break;
17831
17832 case T2_OPCODE_ORN:
17833 new_inst = T2_OPCODE_ORR;
17834 value = inverted;
17835 break;
17836
17837 /* AND <-> BIC. TST has no inverted equivalent. */
17838 case T2_OPCODE_AND:
17839 new_inst = T2_OPCODE_BIC;
17840 if (rd == 15)
17841 value = FAIL;
17842 else
17843 value = inverted;
17844 break;
17845
17846 case T2_OPCODE_BIC:
17847 new_inst = T2_OPCODE_AND;
17848 value = inverted;
17849 break;
17850
17851 /* ADC <-> SBC */
17852 case T2_OPCODE_ADC:
17853 new_inst = T2_OPCODE_SBC;
17854 value = inverted;
17855 break;
17856
17857 case T2_OPCODE_SBC:
17858 new_inst = T2_OPCODE_ADC;
17859 value = inverted;
17860 break;
17861
17862 /* We cannot do anything. */
17863 default:
17864 return FAIL;
17865 }
17866
17867 if (value == (unsigned int)FAIL)
17868 return FAIL;
17869
17870 *instruction &= T2_OPCODE_MASK;
17871 *instruction |= new_inst << T2_DATA_OP_SHIFT;
17872 return value;
17873 }
17874
17875 /* Read a 32-bit thumb instruction from buf. */
17876 static unsigned long
17877 get_thumb32_insn (char * buf)
17878 {
17879 unsigned long insn;
17880 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
17881 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
17882
17883 return insn;
17884 }
17885
17886
17887 /* We usually want to set the low bit on the address of thumb function
17888 symbols. In particular .word foo - . should have the low bit set.
17889 Generic code tries to fold the difference of two symbols to
17890 a constant. Prevent this and force a relocation when the first symbols
17891 is a thumb function. */
17892 int
17893 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
17894 {
17895 if (op == O_subtract
17896 && l->X_op == O_symbol
17897 && r->X_op == O_symbol
17898 && THUMB_IS_FUNC (l->X_add_symbol))
17899 {
17900 l->X_op = O_subtract;
17901 l->X_op_symbol = r->X_add_symbol;
17902 l->X_add_number -= r->X_add_number;
17903 return 1;
17904 }
17905 /* Process as normal. */
17906 return 0;
17907 }
17908
17909 void
17910 md_apply_fix (fixS * fixP,
17911 valueT * valP,
17912 segT seg)
17913 {
17914 offsetT value = * valP;
17915 offsetT newval;
17916 unsigned int newimm;
17917 unsigned long temp;
17918 int sign;
17919 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
17920
17921 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
17922
17923 /* Note whether this will delete the relocation. */
17924
17925 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
17926 fixP->fx_done = 1;
17927
17928 /* On a 64-bit host, silently truncate 'value' to 32 bits for
17929 consistency with the behaviour on 32-bit hosts. Remember value
17930 for emit_reloc. */
17931 value &= 0xffffffff;
17932 value ^= 0x80000000;
17933 value -= 0x80000000;
17934
17935 *valP = value;
17936 fixP->fx_addnumber = value;
17937
17938 /* Same treatment for fixP->fx_offset. */
17939 fixP->fx_offset &= 0xffffffff;
17940 fixP->fx_offset ^= 0x80000000;
17941 fixP->fx_offset -= 0x80000000;
17942
17943 switch (fixP->fx_r_type)
17944 {
17945 case BFD_RELOC_NONE:
17946 /* This will need to go in the object file. */
17947 fixP->fx_done = 0;
17948 break;
17949
17950 case BFD_RELOC_ARM_IMMEDIATE:
17951 /* We claim that this fixup has been processed here,
17952 even if in fact we generate an error because we do
17953 not have a reloc for it, so tc_gen_reloc will reject it. */
17954 fixP->fx_done = 1;
17955
17956 if (fixP->fx_addsy
17957 && ! S_IS_DEFINED (fixP->fx_addsy))
17958 {
17959 as_bad_where (fixP->fx_file, fixP->fx_line,
17960 _("undefined symbol %s used as an immediate value"),
17961 S_GET_NAME (fixP->fx_addsy));
17962 break;
17963 }
17964
17965 newimm = encode_arm_immediate (value);
17966 temp = md_chars_to_number (buf, INSN_SIZE);
17967
17968 /* If the instruction will fail, see if we can fix things up by
17969 changing the opcode. */
17970 if (newimm == (unsigned int) FAIL
17971 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
17972 {
17973 as_bad_where (fixP->fx_file, fixP->fx_line,
17974 _("invalid constant (%lx) after fixup"),
17975 (unsigned long) value);
17976 break;
17977 }
17978
17979 newimm |= (temp & 0xfffff000);
17980 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
17981 break;
17982
17983 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
17984 {
17985 unsigned int highpart = 0;
17986 unsigned int newinsn = 0xe1a00000; /* nop. */
17987
17988 newimm = encode_arm_immediate (value);
17989 temp = md_chars_to_number (buf, INSN_SIZE);
17990
17991 /* If the instruction will fail, see if we can fix things up by
17992 changing the opcode. */
17993 if (newimm == (unsigned int) FAIL
17994 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
17995 {
17996 /* No ? OK - try using two ADD instructions to generate
17997 the value. */
17998 newimm = validate_immediate_twopart (value, & highpart);
17999
18000 /* Yes - then make sure that the second instruction is
18001 also an add. */
18002 if (newimm != (unsigned int) FAIL)
18003 newinsn = temp;
18004 /* Still No ? Try using a negated value. */
18005 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
18006 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
18007 /* Otherwise - give up. */
18008 else
18009 {
18010 as_bad_where (fixP->fx_file, fixP->fx_line,
18011 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
18012 (long) value);
18013 break;
18014 }
18015
18016 /* Replace the first operand in the 2nd instruction (which
18017 is the PC) with the destination register. We have
18018 already added in the PC in the first instruction and we
18019 do not want to do it again. */
18020 newinsn &= ~ 0xf0000;
18021 newinsn |= ((newinsn & 0x0f000) << 4);
18022 }
18023
18024 newimm |= (temp & 0xfffff000);
18025 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
18026
18027 highpart |= (newinsn & 0xfffff000);
18028 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
18029 }
18030 break;
18031
18032 case BFD_RELOC_ARM_OFFSET_IMM:
18033 if (!fixP->fx_done && seg->use_rela_p)
18034 value = 0;
18035
18036 case BFD_RELOC_ARM_LITERAL:
18037 sign = value >= 0;
18038
18039 if (value < 0)
18040 value = - value;
18041
18042 if (validate_offset_imm (value, 0) == FAIL)
18043 {
18044 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
18045 as_bad_where (fixP->fx_file, fixP->fx_line,
18046 _("invalid literal constant: pool needs to be closer"));
18047 else
18048 as_bad_where (fixP->fx_file, fixP->fx_line,
18049 _("bad immediate value for offset (%ld)"),
18050 (long) value);
18051 break;
18052 }
18053
18054 newval = md_chars_to_number (buf, INSN_SIZE);
18055 newval &= 0xff7ff000;
18056 newval |= value | (sign ? INDEX_UP : 0);
18057 md_number_to_chars (buf, newval, INSN_SIZE);
18058 break;
18059
18060 case BFD_RELOC_ARM_OFFSET_IMM8:
18061 case BFD_RELOC_ARM_HWLITERAL:
18062 sign = value >= 0;
18063
18064 if (value < 0)
18065 value = - value;
18066
18067 if (validate_offset_imm (value, 1) == FAIL)
18068 {
18069 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
18070 as_bad_where (fixP->fx_file, fixP->fx_line,
18071 _("invalid literal constant: pool needs to be closer"));
18072 else
18073 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
18074 (long) value);
18075 break;
18076 }
18077
18078 newval = md_chars_to_number (buf, INSN_SIZE);
18079 newval &= 0xff7ff0f0;
18080 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
18081 md_number_to_chars (buf, newval, INSN_SIZE);
18082 break;
18083
18084 case BFD_RELOC_ARM_T32_OFFSET_U8:
18085 if (value < 0 || value > 1020 || value % 4 != 0)
18086 as_bad_where (fixP->fx_file, fixP->fx_line,
18087 _("bad immediate value for offset (%ld)"), (long) value);
18088 value /= 4;
18089
18090 newval = md_chars_to_number (buf+2, THUMB_SIZE);
18091 newval |= value;
18092 md_number_to_chars (buf+2, newval, THUMB_SIZE);
18093 break;
18094
18095 case BFD_RELOC_ARM_T32_OFFSET_IMM:
18096 /* This is a complicated relocation used for all varieties of Thumb32
18097 load/store instruction with immediate offset:
18098
18099 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
18100 *4, optional writeback(W)
18101 (doubleword load/store)
18102
18103 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
18104 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
18105 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
18106 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
18107 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
18108
18109 Uppercase letters indicate bits that are already encoded at
18110 this point. Lowercase letters are our problem. For the
18111 second block of instructions, the secondary opcode nybble
18112 (bits 8..11) is present, and bit 23 is zero, even if this is
18113 a PC-relative operation. */
18114 newval = md_chars_to_number (buf, THUMB_SIZE);
18115 newval <<= 16;
18116 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
18117
18118 if ((newval & 0xf0000000) == 0xe0000000)
18119 {
18120 /* Doubleword load/store: 8-bit offset, scaled by 4. */
18121 if (value >= 0)
18122 newval |= (1 << 23);
18123 else
18124 value = -value;
18125 if (value % 4 != 0)
18126 {
18127 as_bad_where (fixP->fx_file, fixP->fx_line,
18128 _("offset not a multiple of 4"));
18129 break;
18130 }
18131 value /= 4;
18132 if (value > 0xff)
18133 {
18134 as_bad_where (fixP->fx_file, fixP->fx_line,
18135 _("offset out of range"));
18136 break;
18137 }
18138 newval &= ~0xff;
18139 }
18140 else if ((newval & 0x000f0000) == 0x000f0000)
18141 {
18142 /* PC-relative, 12-bit offset. */
18143 if (value >= 0)
18144 newval |= (1 << 23);
18145 else
18146 value = -value;
18147 if (value > 0xfff)
18148 {
18149 as_bad_where (fixP->fx_file, fixP->fx_line,
18150 _("offset out of range"));
18151 break;
18152 }
18153 newval &= ~0xfff;
18154 }
18155 else if ((newval & 0x00000100) == 0x00000100)
18156 {
18157 /* Writeback: 8-bit, +/- offset. */
18158 if (value >= 0)
18159 newval |= (1 << 9);
18160 else
18161 value = -value;
18162 if (value > 0xff)
18163 {
18164 as_bad_where (fixP->fx_file, fixP->fx_line,
18165 _("offset out of range"));
18166 break;
18167 }
18168 newval &= ~0xff;
18169 }
18170 else if ((newval & 0x00000f00) == 0x00000e00)
18171 {
18172 /* T-instruction: positive 8-bit offset. */
18173 if (value < 0 || value > 0xff)
18174 {
18175 as_bad_where (fixP->fx_file, fixP->fx_line,
18176 _("offset out of range"));
18177 break;
18178 }
18179 newval &= ~0xff;
18180 newval |= value;
18181 }
18182 else
18183 {
18184 /* Positive 12-bit or negative 8-bit offset. */
18185 int limit;
18186 if (value >= 0)
18187 {
18188 newval |= (1 << 23);
18189 limit = 0xfff;
18190 }
18191 else
18192 {
18193 value = -value;
18194 limit = 0xff;
18195 }
18196 if (value > limit)
18197 {
18198 as_bad_where (fixP->fx_file, fixP->fx_line,
18199 _("offset out of range"));
18200 break;
18201 }
18202 newval &= ~limit;
18203 }
18204
18205 newval |= value;
18206 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
18207 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
18208 break;
18209
18210 case BFD_RELOC_ARM_SHIFT_IMM:
18211 newval = md_chars_to_number (buf, INSN_SIZE);
18212 if (((unsigned long) value) > 32
18213 || (value == 32
18214 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
18215 {
18216 as_bad_where (fixP->fx_file, fixP->fx_line,
18217 _("shift expression is too large"));
18218 break;
18219 }
18220
18221 if (value == 0)
18222 /* Shifts of zero must be done as lsl. */
18223 newval &= ~0x60;
18224 else if (value == 32)
18225 value = 0;
18226 newval &= 0xfffff07f;
18227 newval |= (value & 0x1f) << 7;
18228 md_number_to_chars (buf, newval, INSN_SIZE);
18229 break;
18230
18231 case BFD_RELOC_ARM_T32_IMMEDIATE:
18232 case BFD_RELOC_ARM_T32_ADD_IMM:
18233 case BFD_RELOC_ARM_T32_IMM12:
18234 case BFD_RELOC_ARM_T32_ADD_PC12:
18235 /* We claim that this fixup has been processed here,
18236 even if in fact we generate an error because we do
18237 not have a reloc for it, so tc_gen_reloc will reject it. */
18238 fixP->fx_done = 1;
18239
18240 if (fixP->fx_addsy
18241 && ! S_IS_DEFINED (fixP->fx_addsy))
18242 {
18243 as_bad_where (fixP->fx_file, fixP->fx_line,
18244 _("undefined symbol %s used as an immediate value"),
18245 S_GET_NAME (fixP->fx_addsy));
18246 break;
18247 }
18248
18249 newval = md_chars_to_number (buf, THUMB_SIZE);
18250 newval <<= 16;
18251 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
18252
18253 newimm = FAIL;
18254 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
18255 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18256 {
18257 newimm = encode_thumb32_immediate (value);
18258 if (newimm == (unsigned int) FAIL)
18259 newimm = thumb32_negate_data_op (&newval, value);
18260 }
18261 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
18262 && newimm == (unsigned int) FAIL)
18263 {
18264 /* Turn add/sum into addw/subw. */
18265 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18266 newval = (newval & 0xfeffffff) | 0x02000000;
18267
18268 /* 12 bit immediate for addw/subw. */
18269 if (value < 0)
18270 {
18271 value = -value;
18272 newval ^= 0x00a00000;
18273 }
18274 if (value > 0xfff)
18275 newimm = (unsigned int) FAIL;
18276 else
18277 newimm = value;
18278 }
18279
18280 if (newimm == (unsigned int)FAIL)
18281 {
18282 as_bad_where (fixP->fx_file, fixP->fx_line,
18283 _("invalid constant (%lx) after fixup"),
18284 (unsigned long) value);
18285 break;
18286 }
18287
18288 newval |= (newimm & 0x800) << 15;
18289 newval |= (newimm & 0x700) << 4;
18290 newval |= (newimm & 0x0ff);
18291
18292 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
18293 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
18294 break;
18295
18296 case BFD_RELOC_ARM_SMC:
18297 if (((unsigned long) value) > 0xffff)
18298 as_bad_where (fixP->fx_file, fixP->fx_line,
18299 _("invalid smc expression"));
18300 newval = md_chars_to_number (buf, INSN_SIZE);
18301 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
18302 md_number_to_chars (buf, newval, INSN_SIZE);
18303 break;
18304
18305 case BFD_RELOC_ARM_SWI:
18306 if (fixP->tc_fix_data != 0)
18307 {
18308 if (((unsigned long) value) > 0xff)
18309 as_bad_where (fixP->fx_file, fixP->fx_line,
18310 _("invalid swi expression"));
18311 newval = md_chars_to_number (buf, THUMB_SIZE);
18312 newval |= value;
18313 md_number_to_chars (buf, newval, THUMB_SIZE);
18314 }
18315 else
18316 {
18317 if (((unsigned long) value) > 0x00ffffff)
18318 as_bad_where (fixP->fx_file, fixP->fx_line,
18319 _("invalid swi expression"));
18320 newval = md_chars_to_number (buf, INSN_SIZE);
18321 newval |= value;
18322 md_number_to_chars (buf, newval, INSN_SIZE);
18323 }
18324 break;
18325
18326 case BFD_RELOC_ARM_MULTI:
18327 if (((unsigned long) value) > 0xffff)
18328 as_bad_where (fixP->fx_file, fixP->fx_line,
18329 _("invalid expression in load/store multiple"));
18330 newval = value | md_chars_to_number (buf, INSN_SIZE);
18331 md_number_to_chars (buf, newval, INSN_SIZE);
18332 break;
18333
18334 #ifdef OBJ_ELF
18335 case BFD_RELOC_ARM_PCREL_CALL:
18336 newval = md_chars_to_number (buf, INSN_SIZE);
18337 if ((newval & 0xf0000000) == 0xf0000000)
18338 temp = 1;
18339 else
18340 temp = 3;
18341 goto arm_branch_common;
18342
18343 case BFD_RELOC_ARM_PCREL_JUMP:
18344 case BFD_RELOC_ARM_PLT32:
18345 #endif
18346 case BFD_RELOC_ARM_PCREL_BRANCH:
18347 temp = 3;
18348 goto arm_branch_common;
18349
18350 case BFD_RELOC_ARM_PCREL_BLX:
18351 temp = 1;
18352 arm_branch_common:
18353 /* We are going to store value (shifted right by two) in the
18354 instruction, in a 24 bit, signed field. Bits 26 through 32 either
18355 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
18356 also be be clear. */
18357 if (value & temp)
18358 as_bad_where (fixP->fx_file, fixP->fx_line,
18359 _("misaligned branch destination"));
18360 if ((value & (offsetT)0xfe000000) != (offsetT)0
18361 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
18362 as_bad_where (fixP->fx_file, fixP->fx_line,
18363 _("branch out of range"));
18364
18365 if (fixP->fx_done || !seg->use_rela_p)
18366 {
18367 newval = md_chars_to_number (buf, INSN_SIZE);
18368 newval |= (value >> 2) & 0x00ffffff;
18369 /* Set the H bit on BLX instructions. */
18370 if (temp == 1)
18371 {
18372 if (value & 2)
18373 newval |= 0x01000000;
18374 else
18375 newval &= ~0x01000000;
18376 }
18377 md_number_to_chars (buf, newval, INSN_SIZE);
18378 }
18379 break;
18380
18381 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
18382 /* CBZ can only branch forward. */
18383
18384 /* Attempts to use CBZ to branch to the next instruction
18385 (which, strictly speaking, are prohibited) will be turned into
18386 no-ops.
18387
18388 FIXME: It may be better to remove the instruction completely and
18389 perform relaxation. */
18390 if (value == -2)
18391 {
18392 newval = md_chars_to_number (buf, THUMB_SIZE);
18393 newval = 0xbf00; /* NOP encoding T1 */
18394 md_number_to_chars (buf, newval, THUMB_SIZE);
18395 }
18396 else
18397 {
18398 if (value & ~0x7e)
18399 as_bad_where (fixP->fx_file, fixP->fx_line,
18400 _("branch out of range"));
18401
18402 if (fixP->fx_done || !seg->use_rela_p)
18403 {
18404 newval = md_chars_to_number (buf, THUMB_SIZE);
18405 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
18406 md_number_to_chars (buf, newval, THUMB_SIZE);
18407 }
18408 }
18409 break;
18410
18411 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
18412 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
18413 as_bad_where (fixP->fx_file, fixP->fx_line,
18414 _("branch out of range"));
18415
18416 if (fixP->fx_done || !seg->use_rela_p)
18417 {
18418 newval = md_chars_to_number (buf, THUMB_SIZE);
18419 newval |= (value & 0x1ff) >> 1;
18420 md_number_to_chars (buf, newval, THUMB_SIZE);
18421 }
18422 break;
18423
18424 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
18425 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
18426 as_bad_where (fixP->fx_file, fixP->fx_line,
18427 _("branch out of range"));
18428
18429 if (fixP->fx_done || !seg->use_rela_p)
18430 {
18431 newval = md_chars_to_number (buf, THUMB_SIZE);
18432 newval |= (value & 0xfff) >> 1;
18433 md_number_to_chars (buf, newval, THUMB_SIZE);
18434 }
18435 break;
18436
18437 case BFD_RELOC_THUMB_PCREL_BRANCH20:
18438 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
18439 as_bad_where (fixP->fx_file, fixP->fx_line,
18440 _("conditional branch out of range"));
18441
18442 if (fixP->fx_done || !seg->use_rela_p)
18443 {
18444 offsetT newval2;
18445 addressT S, J1, J2, lo, hi;
18446
18447 S = (value & 0x00100000) >> 20;
18448 J2 = (value & 0x00080000) >> 19;
18449 J1 = (value & 0x00040000) >> 18;
18450 hi = (value & 0x0003f000) >> 12;
18451 lo = (value & 0x00000ffe) >> 1;
18452
18453 newval = md_chars_to_number (buf, THUMB_SIZE);
18454 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18455 newval |= (S << 10) | hi;
18456 newval2 |= (J1 << 13) | (J2 << 11) | lo;
18457 md_number_to_chars (buf, newval, THUMB_SIZE);
18458 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18459 }
18460 break;
18461
18462 case BFD_RELOC_THUMB_PCREL_BLX:
18463 case BFD_RELOC_THUMB_PCREL_BRANCH23:
18464 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
18465 as_bad_where (fixP->fx_file, fixP->fx_line,
18466 _("branch out of range"));
18467
18468 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
18469 /* For a BLX instruction, make sure that the relocation is rounded up
18470 to a word boundary. This follows the semantics of the instruction
18471 which specifies that bit 1 of the target address will come from bit
18472 1 of the base address. */
18473 value = (value + 1) & ~ 1;
18474
18475 if (fixP->fx_done || !seg->use_rela_p)
18476 {
18477 offsetT newval2;
18478
18479 newval = md_chars_to_number (buf, THUMB_SIZE);
18480 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18481 newval |= (value & 0x7fffff) >> 12;
18482 newval2 |= (value & 0xfff) >> 1;
18483 md_number_to_chars (buf, newval, THUMB_SIZE);
18484 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18485 }
18486 break;
18487
18488 case BFD_RELOC_THUMB_PCREL_BRANCH25:
18489 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
18490 as_bad_where (fixP->fx_file, fixP->fx_line,
18491 _("branch out of range"));
18492
18493 if (fixP->fx_done || !seg->use_rela_p)
18494 {
18495 offsetT newval2;
18496 addressT S, I1, I2, lo, hi;
18497
18498 S = (value & 0x01000000) >> 24;
18499 I1 = (value & 0x00800000) >> 23;
18500 I2 = (value & 0x00400000) >> 22;
18501 hi = (value & 0x003ff000) >> 12;
18502 lo = (value & 0x00000ffe) >> 1;
18503
18504 I1 = !(I1 ^ S);
18505 I2 = !(I2 ^ S);
18506
18507 newval = md_chars_to_number (buf, THUMB_SIZE);
18508 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18509 newval |= (S << 10) | hi;
18510 newval2 |= (I1 << 13) | (I2 << 11) | lo;
18511 md_number_to_chars (buf, newval, THUMB_SIZE);
18512 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18513 }
18514 break;
18515
18516 case BFD_RELOC_8:
18517 if (fixP->fx_done || !seg->use_rela_p)
18518 md_number_to_chars (buf, value, 1);
18519 break;
18520
18521 case BFD_RELOC_16:
18522 if (fixP->fx_done || !seg->use_rela_p)
18523 md_number_to_chars (buf, value, 2);
18524 break;
18525
18526 #ifdef OBJ_ELF
18527 case BFD_RELOC_ARM_TLS_GD32:
18528 case BFD_RELOC_ARM_TLS_LE32:
18529 case BFD_RELOC_ARM_TLS_IE32:
18530 case BFD_RELOC_ARM_TLS_LDM32:
18531 case BFD_RELOC_ARM_TLS_LDO32:
18532 S_SET_THREAD_LOCAL (fixP->fx_addsy);
18533 /* fall through */
18534
18535 case BFD_RELOC_ARM_GOT32:
18536 case BFD_RELOC_ARM_GOTOFF:
18537 case BFD_RELOC_ARM_TARGET2:
18538 if (fixP->fx_done || !seg->use_rela_p)
18539 md_number_to_chars (buf, 0, 4);
18540 break;
18541 #endif
18542
18543 case BFD_RELOC_RVA:
18544 case BFD_RELOC_32:
18545 case BFD_RELOC_ARM_TARGET1:
18546 case BFD_RELOC_ARM_ROSEGREL32:
18547 case BFD_RELOC_ARM_SBREL32:
18548 case BFD_RELOC_32_PCREL:
18549 #ifdef TE_PE
18550 case BFD_RELOC_32_SECREL:
18551 #endif
18552 if (fixP->fx_done || !seg->use_rela_p)
18553 #ifdef TE_WINCE
18554 /* For WinCE we only do this for pcrel fixups. */
18555 if (fixP->fx_done || fixP->fx_pcrel)
18556 #endif
18557 md_number_to_chars (buf, value, 4);
18558 break;
18559
18560 #ifdef OBJ_ELF
18561 case BFD_RELOC_ARM_PREL31:
18562 if (fixP->fx_done || !seg->use_rela_p)
18563 {
18564 newval = md_chars_to_number (buf, 4) & 0x80000000;
18565 if ((value ^ (value >> 1)) & 0x40000000)
18566 {
18567 as_bad_where (fixP->fx_file, fixP->fx_line,
18568 _("rel31 relocation overflow"));
18569 }
18570 newval |= value & 0x7fffffff;
18571 md_number_to_chars (buf, newval, 4);
18572 }
18573 break;
18574 #endif
18575
18576 case BFD_RELOC_ARM_CP_OFF_IMM:
18577 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
18578 if (value < -1023 || value > 1023 || (value & 3))
18579 as_bad_where (fixP->fx_file, fixP->fx_line,
18580 _("co-processor offset out of range"));
18581 cp_off_common:
18582 sign = value >= 0;
18583 if (value < 0)
18584 value = -value;
18585 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18586 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18587 newval = md_chars_to_number (buf, INSN_SIZE);
18588 else
18589 newval = get_thumb32_insn (buf);
18590 newval &= 0xff7fff00;
18591 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
18592 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18593 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18594 md_number_to_chars (buf, newval, INSN_SIZE);
18595 else
18596 put_thumb32_insn (buf, newval);
18597 break;
18598
18599 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
18600 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
18601 if (value < -255 || value > 255)
18602 as_bad_where (fixP->fx_file, fixP->fx_line,
18603 _("co-processor offset out of range"));
18604 value *= 4;
18605 goto cp_off_common;
18606
18607 case BFD_RELOC_ARM_THUMB_OFFSET:
18608 newval = md_chars_to_number (buf, THUMB_SIZE);
18609 /* Exactly what ranges, and where the offset is inserted depends
18610 on the type of instruction, we can establish this from the
18611 top 4 bits. */
18612 switch (newval >> 12)
18613 {
18614 case 4: /* PC load. */
18615 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
18616 forced to zero for these loads; md_pcrel_from has already
18617 compensated for this. */
18618 if (value & 3)
18619 as_bad_where (fixP->fx_file, fixP->fx_line,
18620 _("invalid offset, target not word aligned (0x%08lX)"),
18621 (((unsigned long) fixP->fx_frag->fr_address
18622 + (unsigned long) fixP->fx_where) & ~3)
18623 + (unsigned long) value);
18624
18625 if (value & ~0x3fc)
18626 as_bad_where (fixP->fx_file, fixP->fx_line,
18627 _("invalid offset, value too big (0x%08lX)"),
18628 (long) value);
18629
18630 newval |= value >> 2;
18631 break;
18632
18633 case 9: /* SP load/store. */
18634 if (value & ~0x3fc)
18635 as_bad_where (fixP->fx_file, fixP->fx_line,
18636 _("invalid offset, value too big (0x%08lX)"),
18637 (long) value);
18638 newval |= value >> 2;
18639 break;
18640
18641 case 6: /* Word load/store. */
18642 if (value & ~0x7c)
18643 as_bad_where (fixP->fx_file, fixP->fx_line,
18644 _("invalid offset, value too big (0x%08lX)"),
18645 (long) value);
18646 newval |= value << 4; /* 6 - 2. */
18647 break;
18648
18649 case 7: /* Byte load/store. */
18650 if (value & ~0x1f)
18651 as_bad_where (fixP->fx_file, fixP->fx_line,
18652 _("invalid offset, value too big (0x%08lX)"),
18653 (long) value);
18654 newval |= value << 6;
18655 break;
18656
18657 case 8: /* Halfword load/store. */
18658 if (value & ~0x3e)
18659 as_bad_where (fixP->fx_file, fixP->fx_line,
18660 _("invalid offset, value too big (0x%08lX)"),
18661 (long) value);
18662 newval |= value << 5; /* 6 - 1. */
18663 break;
18664
18665 default:
18666 as_bad_where (fixP->fx_file, fixP->fx_line,
18667 "Unable to process relocation for thumb opcode: %lx",
18668 (unsigned long) newval);
18669 break;
18670 }
18671 md_number_to_chars (buf, newval, THUMB_SIZE);
18672 break;
18673
18674 case BFD_RELOC_ARM_THUMB_ADD:
18675 /* This is a complicated relocation, since we use it for all of
18676 the following immediate relocations:
18677
18678 3bit ADD/SUB
18679 8bit ADD/SUB
18680 9bit ADD/SUB SP word-aligned
18681 10bit ADD PC/SP word-aligned
18682
18683 The type of instruction being processed is encoded in the
18684 instruction field:
18685
18686 0x8000 SUB
18687 0x00F0 Rd
18688 0x000F Rs
18689 */
18690 newval = md_chars_to_number (buf, THUMB_SIZE);
18691 {
18692 int rd = (newval >> 4) & 0xf;
18693 int rs = newval & 0xf;
18694 int subtract = !!(newval & 0x8000);
18695
18696 /* Check for HI regs, only very restricted cases allowed:
18697 Adjusting SP, and using PC or SP to get an address. */
18698 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
18699 || (rs > 7 && rs != REG_SP && rs != REG_PC))
18700 as_bad_where (fixP->fx_file, fixP->fx_line,
18701 _("invalid Hi register with immediate"));
18702
18703 /* If value is negative, choose the opposite instruction. */
18704 if (value < 0)
18705 {
18706 value = -value;
18707 subtract = !subtract;
18708 if (value < 0)
18709 as_bad_where (fixP->fx_file, fixP->fx_line,
18710 _("immediate value out of range"));
18711 }
18712
18713 if (rd == REG_SP)
18714 {
18715 if (value & ~0x1fc)
18716 as_bad_where (fixP->fx_file, fixP->fx_line,
18717 _("invalid immediate for stack address calculation"));
18718 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
18719 newval |= value >> 2;
18720 }
18721 else if (rs == REG_PC || rs == REG_SP)
18722 {
18723 if (subtract || value & ~0x3fc)
18724 as_bad_where (fixP->fx_file, fixP->fx_line,
18725 _("invalid immediate for address calculation (value = 0x%08lX)"),
18726 (unsigned long) value);
18727 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
18728 newval |= rd << 8;
18729 newval |= value >> 2;
18730 }
18731 else if (rs == rd)
18732 {
18733 if (value & ~0xff)
18734 as_bad_where (fixP->fx_file, fixP->fx_line,
18735 _("immediate value out of range"));
18736 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
18737 newval |= (rd << 8) | value;
18738 }
18739 else
18740 {
18741 if (value & ~0x7)
18742 as_bad_where (fixP->fx_file, fixP->fx_line,
18743 _("immediate value out of range"));
18744 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
18745 newval |= rd | (rs << 3) | (value << 6);
18746 }
18747 }
18748 md_number_to_chars (buf, newval, THUMB_SIZE);
18749 break;
18750
18751 case BFD_RELOC_ARM_THUMB_IMM:
18752 newval = md_chars_to_number (buf, THUMB_SIZE);
18753 if (value < 0 || value > 255)
18754 as_bad_where (fixP->fx_file, fixP->fx_line,
18755 _("invalid immediate: %ld is out of range"),
18756 (long) value);
18757 newval |= value;
18758 md_number_to_chars (buf, newval, THUMB_SIZE);
18759 break;
18760
18761 case BFD_RELOC_ARM_THUMB_SHIFT:
18762 /* 5bit shift value (0..32). LSL cannot take 32. */
18763 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
18764 temp = newval & 0xf800;
18765 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
18766 as_bad_where (fixP->fx_file, fixP->fx_line,
18767 _("invalid shift value: %ld"), (long) value);
18768 /* Shifts of zero must be encoded as LSL. */
18769 if (value == 0)
18770 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
18771 /* Shifts of 32 are encoded as zero. */
18772 else if (value == 32)
18773 value = 0;
18774 newval |= value << 6;
18775 md_number_to_chars (buf, newval, THUMB_SIZE);
18776 break;
18777
18778 case BFD_RELOC_VTABLE_INHERIT:
18779 case BFD_RELOC_VTABLE_ENTRY:
18780 fixP->fx_done = 0;
18781 return;
18782
18783 case BFD_RELOC_ARM_MOVW:
18784 case BFD_RELOC_ARM_MOVT:
18785 case BFD_RELOC_ARM_THUMB_MOVW:
18786 case BFD_RELOC_ARM_THUMB_MOVT:
18787 if (fixP->fx_done || !seg->use_rela_p)
18788 {
18789 /* REL format relocations are limited to a 16-bit addend. */
18790 if (!fixP->fx_done)
18791 {
18792 if (value < -0x1000 || value > 0xffff)
18793 as_bad_where (fixP->fx_file, fixP->fx_line,
18794 _("offset out of range"));
18795 }
18796 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
18797 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18798 {
18799 value >>= 16;
18800 }
18801
18802 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
18803 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18804 {
18805 newval = get_thumb32_insn (buf);
18806 newval &= 0xfbf08f00;
18807 newval |= (value & 0xf000) << 4;
18808 newval |= (value & 0x0800) << 15;
18809 newval |= (value & 0x0700) << 4;
18810 newval |= (value & 0x00ff);
18811 put_thumb32_insn (buf, newval);
18812 }
18813 else
18814 {
18815 newval = md_chars_to_number (buf, 4);
18816 newval &= 0xfff0f000;
18817 newval |= value & 0x0fff;
18818 newval |= (value & 0xf000) << 4;
18819 md_number_to_chars (buf, newval, 4);
18820 }
18821 }
18822 return;
18823
18824 case BFD_RELOC_ARM_ALU_PC_G0_NC:
18825 case BFD_RELOC_ARM_ALU_PC_G0:
18826 case BFD_RELOC_ARM_ALU_PC_G1_NC:
18827 case BFD_RELOC_ARM_ALU_PC_G1:
18828 case BFD_RELOC_ARM_ALU_PC_G2:
18829 case BFD_RELOC_ARM_ALU_SB_G0_NC:
18830 case BFD_RELOC_ARM_ALU_SB_G0:
18831 case BFD_RELOC_ARM_ALU_SB_G1_NC:
18832 case BFD_RELOC_ARM_ALU_SB_G1:
18833 case BFD_RELOC_ARM_ALU_SB_G2:
18834 assert (!fixP->fx_done);
18835 if (!seg->use_rela_p)
18836 {
18837 bfd_vma insn;
18838 bfd_vma encoded_addend;
18839 bfd_vma addend_abs = abs (value);
18840
18841 /* Check that the absolute value of the addend can be
18842 expressed as an 8-bit constant plus a rotation. */
18843 encoded_addend = encode_arm_immediate (addend_abs);
18844 if (encoded_addend == (unsigned int) FAIL)
18845 as_bad_where (fixP->fx_file, fixP->fx_line,
18846 _("the offset 0x%08lX is not representable"),
18847 (unsigned long) addend_abs);
18848
18849 /* Extract the instruction. */
18850 insn = md_chars_to_number (buf, INSN_SIZE);
18851
18852 /* If the addend is positive, use an ADD instruction.
18853 Otherwise use a SUB. Take care not to destroy the S bit. */
18854 insn &= 0xff1fffff;
18855 if (value < 0)
18856 insn |= 1 << 22;
18857 else
18858 insn |= 1 << 23;
18859
18860 /* Place the encoded addend into the first 12 bits of the
18861 instruction. */
18862 insn &= 0xfffff000;
18863 insn |= encoded_addend;
18864
18865 /* Update the instruction. */
18866 md_number_to_chars (buf, insn, INSN_SIZE);
18867 }
18868 break;
18869
18870 case BFD_RELOC_ARM_LDR_PC_G0:
18871 case BFD_RELOC_ARM_LDR_PC_G1:
18872 case BFD_RELOC_ARM_LDR_PC_G2:
18873 case BFD_RELOC_ARM_LDR_SB_G0:
18874 case BFD_RELOC_ARM_LDR_SB_G1:
18875 case BFD_RELOC_ARM_LDR_SB_G2:
18876 assert (!fixP->fx_done);
18877 if (!seg->use_rela_p)
18878 {
18879 bfd_vma insn;
18880 bfd_vma addend_abs = abs (value);
18881
18882 /* Check that the absolute value of the addend can be
18883 encoded in 12 bits. */
18884 if (addend_abs >= 0x1000)
18885 as_bad_where (fixP->fx_file, fixP->fx_line,
18886 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
18887 (unsigned long) addend_abs);
18888
18889 /* Extract the instruction. */
18890 insn = md_chars_to_number (buf, INSN_SIZE);
18891
18892 /* If the addend is negative, clear bit 23 of the instruction.
18893 Otherwise set it. */
18894 if (value < 0)
18895 insn &= ~(1 << 23);
18896 else
18897 insn |= 1 << 23;
18898
18899 /* Place the absolute value of the addend into the first 12 bits
18900 of the instruction. */
18901 insn &= 0xfffff000;
18902 insn |= addend_abs;
18903
18904 /* Update the instruction. */
18905 md_number_to_chars (buf, insn, INSN_SIZE);
18906 }
18907 break;
18908
18909 case BFD_RELOC_ARM_LDRS_PC_G0:
18910 case BFD_RELOC_ARM_LDRS_PC_G1:
18911 case BFD_RELOC_ARM_LDRS_PC_G2:
18912 case BFD_RELOC_ARM_LDRS_SB_G0:
18913 case BFD_RELOC_ARM_LDRS_SB_G1:
18914 case BFD_RELOC_ARM_LDRS_SB_G2:
18915 assert (!fixP->fx_done);
18916 if (!seg->use_rela_p)
18917 {
18918 bfd_vma insn;
18919 bfd_vma addend_abs = abs (value);
18920
18921 /* Check that the absolute value of the addend can be
18922 encoded in 8 bits. */
18923 if (addend_abs >= 0x100)
18924 as_bad_where (fixP->fx_file, fixP->fx_line,
18925 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
18926 (unsigned long) addend_abs);
18927
18928 /* Extract the instruction. */
18929 insn = md_chars_to_number (buf, INSN_SIZE);
18930
18931 /* If the addend is negative, clear bit 23 of the instruction.
18932 Otherwise set it. */
18933 if (value < 0)
18934 insn &= ~(1 << 23);
18935 else
18936 insn |= 1 << 23;
18937
18938 /* Place the first four bits of the absolute value of the addend
18939 into the first 4 bits of the instruction, and the remaining
18940 four into bits 8 .. 11. */
18941 insn &= 0xfffff0f0;
18942 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
18943
18944 /* Update the instruction. */
18945 md_number_to_chars (buf, insn, INSN_SIZE);
18946 }
18947 break;
18948
18949 case BFD_RELOC_ARM_LDC_PC_G0:
18950 case BFD_RELOC_ARM_LDC_PC_G1:
18951 case BFD_RELOC_ARM_LDC_PC_G2:
18952 case BFD_RELOC_ARM_LDC_SB_G0:
18953 case BFD_RELOC_ARM_LDC_SB_G1:
18954 case BFD_RELOC_ARM_LDC_SB_G2:
18955 assert (!fixP->fx_done);
18956 if (!seg->use_rela_p)
18957 {
18958 bfd_vma insn;
18959 bfd_vma addend_abs = abs (value);
18960
18961 /* Check that the absolute value of the addend is a multiple of
18962 four and, when divided by four, fits in 8 bits. */
18963 if (addend_abs & 0x3)
18964 as_bad_where (fixP->fx_file, fixP->fx_line,
18965 _("bad offset 0x%08lX (must be word-aligned)"),
18966 (unsigned long) addend_abs);
18967
18968 if ((addend_abs >> 2) > 0xff)
18969 as_bad_where (fixP->fx_file, fixP->fx_line,
18970 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
18971 (unsigned long) addend_abs);
18972
18973 /* Extract the instruction. */
18974 insn = md_chars_to_number (buf, INSN_SIZE);
18975
18976 /* If the addend is negative, clear bit 23 of the instruction.
18977 Otherwise set it. */
18978 if (value < 0)
18979 insn &= ~(1 << 23);
18980 else
18981 insn |= 1 << 23;
18982
18983 /* Place the addend (divided by four) into the first eight
18984 bits of the instruction. */
18985 insn &= 0xfffffff0;
18986 insn |= addend_abs >> 2;
18987
18988 /* Update the instruction. */
18989 md_number_to_chars (buf, insn, INSN_SIZE);
18990 }
18991 break;
18992
18993 case BFD_RELOC_ARM_V4BX:
18994 /* This will need to go in the object file. */
18995 fixP->fx_done = 0;
18996 break;
18997
18998 case BFD_RELOC_UNUSED:
18999 default:
19000 as_bad_where (fixP->fx_file, fixP->fx_line,
19001 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
19002 }
19003 }
19004
19005 /* Translate internal representation of relocation info to BFD target
19006 format. */
19007
19008 arelent *
19009 tc_gen_reloc (asection *section, fixS *fixp)
19010 {
19011 arelent * reloc;
19012 bfd_reloc_code_real_type code;
19013
19014 reloc = xmalloc (sizeof (arelent));
19015
19016 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
19017 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
19018 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
19019
19020 if (fixp->fx_pcrel)
19021 {
19022 if (section->use_rela_p)
19023 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
19024 else
19025 fixp->fx_offset = reloc->address;
19026 }
19027 reloc->addend = fixp->fx_offset;
19028
19029 switch (fixp->fx_r_type)
19030 {
19031 case BFD_RELOC_8:
19032 if (fixp->fx_pcrel)
19033 {
19034 code = BFD_RELOC_8_PCREL;
19035 break;
19036 }
19037
19038 case BFD_RELOC_16:
19039 if (fixp->fx_pcrel)
19040 {
19041 code = BFD_RELOC_16_PCREL;
19042 break;
19043 }
19044
19045 case BFD_RELOC_32:
19046 if (fixp->fx_pcrel)
19047 {
19048 code = BFD_RELOC_32_PCREL;
19049 break;
19050 }
19051
19052 case BFD_RELOC_ARM_MOVW:
19053 if (fixp->fx_pcrel)
19054 {
19055 code = BFD_RELOC_ARM_MOVW_PCREL;
19056 break;
19057 }
19058
19059 case BFD_RELOC_ARM_MOVT:
19060 if (fixp->fx_pcrel)
19061 {
19062 code = BFD_RELOC_ARM_MOVT_PCREL;
19063 break;
19064 }
19065
19066 case BFD_RELOC_ARM_THUMB_MOVW:
19067 if (fixp->fx_pcrel)
19068 {
19069 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
19070 break;
19071 }
19072
19073 case BFD_RELOC_ARM_THUMB_MOVT:
19074 if (fixp->fx_pcrel)
19075 {
19076 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
19077 break;
19078 }
19079
19080 case BFD_RELOC_NONE:
19081 case BFD_RELOC_ARM_PCREL_BRANCH:
19082 case BFD_RELOC_ARM_PCREL_BLX:
19083 case BFD_RELOC_RVA:
19084 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19085 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19086 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19087 case BFD_RELOC_THUMB_PCREL_BRANCH20:
19088 case BFD_RELOC_THUMB_PCREL_BRANCH23:
19089 case BFD_RELOC_THUMB_PCREL_BRANCH25:
19090 case BFD_RELOC_THUMB_PCREL_BLX:
19091 case BFD_RELOC_VTABLE_ENTRY:
19092 case BFD_RELOC_VTABLE_INHERIT:
19093 #ifdef TE_PE
19094 case BFD_RELOC_32_SECREL:
19095 #endif
19096 code = fixp->fx_r_type;
19097 break;
19098
19099 case BFD_RELOC_ARM_LITERAL:
19100 case BFD_RELOC_ARM_HWLITERAL:
19101 /* If this is called then the a literal has
19102 been referenced across a section boundary. */
19103 as_bad_where (fixp->fx_file, fixp->fx_line,
19104 _("literal referenced across section boundary"));
19105 return NULL;
19106
19107 #ifdef OBJ_ELF
19108 case BFD_RELOC_ARM_GOT32:
19109 case BFD_RELOC_ARM_GOTOFF:
19110 case BFD_RELOC_ARM_PLT32:
19111 case BFD_RELOC_ARM_TARGET1:
19112 case BFD_RELOC_ARM_ROSEGREL32:
19113 case BFD_RELOC_ARM_SBREL32:
19114 case BFD_RELOC_ARM_PREL31:
19115 case BFD_RELOC_ARM_TARGET2:
19116 case BFD_RELOC_ARM_TLS_LE32:
19117 case BFD_RELOC_ARM_TLS_LDO32:
19118 case BFD_RELOC_ARM_PCREL_CALL:
19119 case BFD_RELOC_ARM_PCREL_JUMP:
19120 case BFD_RELOC_ARM_ALU_PC_G0_NC:
19121 case BFD_RELOC_ARM_ALU_PC_G0:
19122 case BFD_RELOC_ARM_ALU_PC_G1_NC:
19123 case BFD_RELOC_ARM_ALU_PC_G1:
19124 case BFD_RELOC_ARM_ALU_PC_G2:
19125 case BFD_RELOC_ARM_LDR_PC_G0:
19126 case BFD_RELOC_ARM_LDR_PC_G1:
19127 case BFD_RELOC_ARM_LDR_PC_G2:
19128 case BFD_RELOC_ARM_LDRS_PC_G0:
19129 case BFD_RELOC_ARM_LDRS_PC_G1:
19130 case BFD_RELOC_ARM_LDRS_PC_G2:
19131 case BFD_RELOC_ARM_LDC_PC_G0:
19132 case BFD_RELOC_ARM_LDC_PC_G1:
19133 case BFD_RELOC_ARM_LDC_PC_G2:
19134 case BFD_RELOC_ARM_ALU_SB_G0_NC:
19135 case BFD_RELOC_ARM_ALU_SB_G0:
19136 case BFD_RELOC_ARM_ALU_SB_G1_NC:
19137 case BFD_RELOC_ARM_ALU_SB_G1:
19138 case BFD_RELOC_ARM_ALU_SB_G2:
19139 case BFD_RELOC_ARM_LDR_SB_G0:
19140 case BFD_RELOC_ARM_LDR_SB_G1:
19141 case BFD_RELOC_ARM_LDR_SB_G2:
19142 case BFD_RELOC_ARM_LDRS_SB_G0:
19143 case BFD_RELOC_ARM_LDRS_SB_G1:
19144 case BFD_RELOC_ARM_LDRS_SB_G2:
19145 case BFD_RELOC_ARM_LDC_SB_G0:
19146 case BFD_RELOC_ARM_LDC_SB_G1:
19147 case BFD_RELOC_ARM_LDC_SB_G2:
19148 case BFD_RELOC_ARM_V4BX:
19149 code = fixp->fx_r_type;
19150 break;
19151
19152 case BFD_RELOC_ARM_TLS_GD32:
19153 case BFD_RELOC_ARM_TLS_IE32:
19154 case BFD_RELOC_ARM_TLS_LDM32:
19155 /* BFD will include the symbol's address in the addend.
19156 But we don't want that, so subtract it out again here. */
19157 if (!S_IS_COMMON (fixp->fx_addsy))
19158 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
19159 code = fixp->fx_r_type;
19160 break;
19161 #endif
19162
19163 case BFD_RELOC_ARM_IMMEDIATE:
19164 as_bad_where (fixp->fx_file, fixp->fx_line,
19165 _("internal relocation (type: IMMEDIATE) not fixed up"));
19166 return NULL;
19167
19168 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19169 as_bad_where (fixp->fx_file, fixp->fx_line,
19170 _("ADRL used for a symbol not defined in the same file"));
19171 return NULL;
19172
19173 case BFD_RELOC_ARM_OFFSET_IMM:
19174 if (section->use_rela_p)
19175 {
19176 code = fixp->fx_r_type;
19177 break;
19178 }
19179
19180 if (fixp->fx_addsy != NULL
19181 && !S_IS_DEFINED (fixp->fx_addsy)
19182 && S_IS_LOCAL (fixp->fx_addsy))
19183 {
19184 as_bad_where (fixp->fx_file, fixp->fx_line,
19185 _("undefined local label `%s'"),
19186 S_GET_NAME (fixp->fx_addsy));
19187 return NULL;
19188 }
19189
19190 as_bad_where (fixp->fx_file, fixp->fx_line,
19191 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
19192 return NULL;
19193
19194 default:
19195 {
19196 char * type;
19197
19198 switch (fixp->fx_r_type)
19199 {
19200 case BFD_RELOC_NONE: type = "NONE"; break;
19201 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
19202 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
19203 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
19204 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
19205 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
19206 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
19207 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
19208 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
19209 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
19210 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
19211 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
19212 default: type = _("<unknown>"); break;
19213 }
19214 as_bad_where (fixp->fx_file, fixp->fx_line,
19215 _("cannot represent %s relocation in this object file format"),
19216 type);
19217 return NULL;
19218 }
19219 }
19220
19221 #ifdef OBJ_ELF
19222 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
19223 && GOT_symbol
19224 && fixp->fx_addsy == GOT_symbol)
19225 {
19226 code = BFD_RELOC_ARM_GOTPC;
19227 reloc->addend = fixp->fx_offset = reloc->address;
19228 }
19229 #endif
19230
19231 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
19232
19233 if (reloc->howto == NULL)
19234 {
19235 as_bad_where (fixp->fx_file, fixp->fx_line,
19236 _("cannot represent %s relocation in this object file format"),
19237 bfd_get_reloc_code_name (code));
19238 return NULL;
19239 }
19240
19241 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
19242 vtable entry to be used in the relocation's section offset. */
19243 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19244 reloc->address = fixp->fx_offset;
19245
19246 return reloc;
19247 }
19248
19249 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
19250
19251 void
19252 cons_fix_new_arm (fragS * frag,
19253 int where,
19254 int size,
19255 expressionS * exp)
19256 {
19257 bfd_reloc_code_real_type type;
19258 int pcrel = 0;
19259
19260 /* Pick a reloc.
19261 FIXME: @@ Should look at CPU word size. */
19262 switch (size)
19263 {
19264 case 1:
19265 type = BFD_RELOC_8;
19266 break;
19267 case 2:
19268 type = BFD_RELOC_16;
19269 break;
19270 case 4:
19271 default:
19272 type = BFD_RELOC_32;
19273 break;
19274 case 8:
19275 type = BFD_RELOC_64;
19276 break;
19277 }
19278
19279 #ifdef TE_PE
19280 if (exp->X_op == O_secrel)
19281 {
19282 exp->X_op = O_symbol;
19283 type = BFD_RELOC_32_SECREL;
19284 }
19285 #endif
19286
19287 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
19288 }
19289
19290 #if defined OBJ_COFF || defined OBJ_ELF
19291 void
19292 arm_validate_fix (fixS * fixP)
19293 {
19294 /* If the destination of the branch is a defined symbol which does not have
19295 the THUMB_FUNC attribute, then we must be calling a function which has
19296 the (interfacearm) attribute. We look for the Thumb entry point to that
19297 function and change the branch to refer to that function instead. */
19298 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
19299 && fixP->fx_addsy != NULL
19300 && S_IS_DEFINED (fixP->fx_addsy)
19301 && ! THUMB_IS_FUNC (fixP->fx_addsy))
19302 {
19303 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
19304 }
19305 }
19306 #endif
19307
19308 int
19309 arm_force_relocation (struct fix * fixp)
19310 {
19311 #if defined (OBJ_COFF) && defined (TE_PE)
19312 if (fixp->fx_r_type == BFD_RELOC_RVA)
19313 return 1;
19314 #endif
19315
19316 /* Resolve these relocations even if the symbol is extern or weak. */
19317 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
19318 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
19319 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
19320 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
19321 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
19322 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
19323 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
19324 return 0;
19325
19326 /* Always leave these relocations for the linker. */
19327 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19328 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19329 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19330 return 1;
19331
19332 /* Always generate relocations against function symbols. */
19333 if (fixp->fx_r_type == BFD_RELOC_32
19334 && fixp->fx_addsy
19335 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
19336 return 1;
19337
19338 return generic_force_reloc (fixp);
19339 }
19340
19341 #if defined (OBJ_ELF) || defined (OBJ_COFF)
19342 /* Relocations against function names must be left unadjusted,
19343 so that the linker can use this information to generate interworking
19344 stubs. The MIPS version of this function
19345 also prevents relocations that are mips-16 specific, but I do not
19346 know why it does this.
19347
19348 FIXME:
19349 There is one other problem that ought to be addressed here, but
19350 which currently is not: Taking the address of a label (rather
19351 than a function) and then later jumping to that address. Such
19352 addresses also ought to have their bottom bit set (assuming that
19353 they reside in Thumb code), but at the moment they will not. */
19354
19355 bfd_boolean
19356 arm_fix_adjustable (fixS * fixP)
19357 {
19358 if (fixP->fx_addsy == NULL)
19359 return 1;
19360
19361 /* Preserve relocations against symbols with function type. */
19362 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
19363 return 0;
19364
19365 if (THUMB_IS_FUNC (fixP->fx_addsy)
19366 && fixP->fx_subsy == NULL)
19367 return 0;
19368
19369 /* We need the symbol name for the VTABLE entries. */
19370 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
19371 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19372 return 0;
19373
19374 /* Don't allow symbols to be discarded on GOT related relocs. */
19375 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
19376 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
19377 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
19378 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
19379 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
19380 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
19381 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
19382 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
19383 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
19384 return 0;
19385
19386 /* Similarly for group relocations. */
19387 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19388 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19389 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19390 return 0;
19391
19392 return 1;
19393 }
19394 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
19395
19396 #ifdef OBJ_ELF
19397
19398 const char *
19399 elf32_arm_target_format (void)
19400 {
19401 #ifdef TE_SYMBIAN
19402 return (target_big_endian
19403 ? "elf32-bigarm-symbian"
19404 : "elf32-littlearm-symbian");
19405 #elif defined (TE_VXWORKS)
19406 return (target_big_endian
19407 ? "elf32-bigarm-vxworks"
19408 : "elf32-littlearm-vxworks");
19409 #else
19410 if (target_big_endian)
19411 return "elf32-bigarm";
19412 else
19413 return "elf32-littlearm";
19414 #endif
19415 }
19416
19417 void
19418 armelf_frob_symbol (symbolS * symp,
19419 int * puntp)
19420 {
19421 elf_frob_symbol (symp, puntp);
19422 }
19423 #endif
19424
19425 /* MD interface: Finalization. */
19426
19427 /* A good place to do this, although this was probably not intended
19428 for this kind of use. We need to dump the literal pool before
19429 references are made to a null symbol pointer. */
19430
19431 void
19432 arm_cleanup (void)
19433 {
19434 literal_pool * pool;
19435
19436 for (pool = list_of_pools; pool; pool = pool->next)
19437 {
19438 /* Put it at the end of the relevant section. */
19439 subseg_set (pool->section, pool->sub_section);
19440 #ifdef OBJ_ELF
19441 arm_elf_change_section ();
19442 #endif
19443 s_ltorg (0);
19444 }
19445 }
19446
19447 /* Adjust the symbol table. This marks Thumb symbols as distinct from
19448 ARM ones. */
19449
19450 void
19451 arm_adjust_symtab (void)
19452 {
19453 #ifdef OBJ_COFF
19454 symbolS * sym;
19455
19456 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
19457 {
19458 if (ARM_IS_THUMB (sym))
19459 {
19460 if (THUMB_IS_FUNC (sym))
19461 {
19462 /* Mark the symbol as a Thumb function. */
19463 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
19464 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
19465 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
19466
19467 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
19468 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
19469 else
19470 as_bad (_("%s: unexpected function type: %d"),
19471 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
19472 }
19473 else switch (S_GET_STORAGE_CLASS (sym))
19474 {
19475 case C_EXT:
19476 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
19477 break;
19478 case C_STAT:
19479 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
19480 break;
19481 case C_LABEL:
19482 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
19483 break;
19484 default:
19485 /* Do nothing. */
19486 break;
19487 }
19488 }
19489
19490 if (ARM_IS_INTERWORK (sym))
19491 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
19492 }
19493 #endif
19494 #ifdef OBJ_ELF
19495 symbolS * sym;
19496 char bind;
19497
19498 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
19499 {
19500 if (ARM_IS_THUMB (sym))
19501 {
19502 elf_symbol_type * elf_sym;
19503
19504 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
19505 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
19506
19507 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
19508 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
19509 {
19510 /* If it's a .thumb_func, declare it as so,
19511 otherwise tag label as .code 16. */
19512 if (THUMB_IS_FUNC (sym))
19513 elf_sym->internal_elf_sym.st_info =
19514 ELF_ST_INFO (bind, STT_ARM_TFUNC);
19515 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
19516 elf_sym->internal_elf_sym.st_info =
19517 ELF_ST_INFO (bind, STT_ARM_16BIT);
19518 }
19519 }
19520 }
19521 #endif
19522 }
19523
19524 /* MD interface: Initialization. */
19525
19526 static void
19527 set_constant_flonums (void)
19528 {
19529 int i;
19530
19531 for (i = 0; i < NUM_FLOAT_VALS; i++)
19532 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
19533 abort ();
19534 }
19535
19536 /* Auto-select Thumb mode if it's the only available instruction set for the
19537 given architecture. */
19538
19539 static void
19540 autoselect_thumb_from_cpu_variant (void)
19541 {
19542 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
19543 opcode_select (16);
19544 }
19545
19546 void
19547 md_begin (void)
19548 {
19549 unsigned mach;
19550 unsigned int i;
19551
19552 if ( (arm_ops_hsh = hash_new ()) == NULL
19553 || (arm_cond_hsh = hash_new ()) == NULL
19554 || (arm_shift_hsh = hash_new ()) == NULL
19555 || (arm_psr_hsh = hash_new ()) == NULL
19556 || (arm_v7m_psr_hsh = hash_new ()) == NULL
19557 || (arm_reg_hsh = hash_new ()) == NULL
19558 || (arm_reloc_hsh = hash_new ()) == NULL
19559 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
19560 as_fatal (_("virtual memory exhausted"));
19561
19562 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
19563 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
19564 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
19565 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
19566 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
19567 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
19568 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
19569 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
19570 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
19571 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (PTR) (v7m_psrs + i));
19572 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
19573 hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i));
19574 for (i = 0;
19575 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
19576 i++)
19577 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
19578 (PTR) (barrier_opt_names + i));
19579 #ifdef OBJ_ELF
19580 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
19581 hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i));
19582 #endif
19583
19584 set_constant_flonums ();
19585
19586 /* Set the cpu variant based on the command-line options. We prefer
19587 -mcpu= over -march= if both are set (as for GCC); and we prefer
19588 -mfpu= over any other way of setting the floating point unit.
19589 Use of legacy options with new options are faulted. */
19590 if (legacy_cpu)
19591 {
19592 if (mcpu_cpu_opt || march_cpu_opt)
19593 as_bad (_("use of old and new-style options to set CPU type"));
19594
19595 mcpu_cpu_opt = legacy_cpu;
19596 }
19597 else if (!mcpu_cpu_opt)
19598 mcpu_cpu_opt = march_cpu_opt;
19599
19600 if (legacy_fpu)
19601 {
19602 if (mfpu_opt)
19603 as_bad (_("use of old and new-style options to set FPU type"));
19604
19605 mfpu_opt = legacy_fpu;
19606 }
19607 else if (!mfpu_opt)
19608 {
19609 #if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
19610 /* Some environments specify a default FPU. If they don't, infer it
19611 from the processor. */
19612 if (mcpu_fpu_opt)
19613 mfpu_opt = mcpu_fpu_opt;
19614 else
19615 mfpu_opt = march_fpu_opt;
19616 #else
19617 mfpu_opt = &fpu_default;
19618 #endif
19619 }
19620
19621 if (!mfpu_opt)
19622 {
19623 if (mcpu_cpu_opt != NULL)
19624 mfpu_opt = &fpu_default;
19625 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
19626 mfpu_opt = &fpu_arch_vfp_v2;
19627 else
19628 mfpu_opt = &fpu_arch_fpa;
19629 }
19630
19631 #ifdef CPU_DEFAULT
19632 if (!mcpu_cpu_opt)
19633 {
19634 mcpu_cpu_opt = &cpu_default;
19635 selected_cpu = cpu_default;
19636 }
19637 #else
19638 if (mcpu_cpu_opt)
19639 selected_cpu = *mcpu_cpu_opt;
19640 else
19641 mcpu_cpu_opt = &arm_arch_any;
19642 #endif
19643
19644 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
19645
19646 autoselect_thumb_from_cpu_variant ();
19647
19648 arm_arch_used = thumb_arch_used = arm_arch_none;
19649
19650 #if defined OBJ_COFF || defined OBJ_ELF
19651 {
19652 unsigned int flags = 0;
19653
19654 #if defined OBJ_ELF
19655 flags = meabi_flags;
19656
19657 switch (meabi_flags)
19658 {
19659 case EF_ARM_EABI_UNKNOWN:
19660 #endif
19661 /* Set the flags in the private structure. */
19662 if (uses_apcs_26) flags |= F_APCS26;
19663 if (support_interwork) flags |= F_INTERWORK;
19664 if (uses_apcs_float) flags |= F_APCS_FLOAT;
19665 if (pic_code) flags |= F_PIC;
19666 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
19667 flags |= F_SOFT_FLOAT;
19668
19669 switch (mfloat_abi_opt)
19670 {
19671 case ARM_FLOAT_ABI_SOFT:
19672 case ARM_FLOAT_ABI_SOFTFP:
19673 flags |= F_SOFT_FLOAT;
19674 break;
19675
19676 case ARM_FLOAT_ABI_HARD:
19677 if (flags & F_SOFT_FLOAT)
19678 as_bad (_("hard-float conflicts with specified fpu"));
19679 break;
19680 }
19681
19682 /* Using pure-endian doubles (even if soft-float). */
19683 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
19684 flags |= F_VFP_FLOAT;
19685
19686 #if defined OBJ_ELF
19687 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
19688 flags |= EF_ARM_MAVERICK_FLOAT;
19689 break;
19690
19691 case EF_ARM_EABI_VER4:
19692 case EF_ARM_EABI_VER5:
19693 /* No additional flags to set. */
19694 break;
19695
19696 default:
19697 abort ();
19698 }
19699 #endif
19700 bfd_set_private_flags (stdoutput, flags);
19701
19702 /* We have run out flags in the COFF header to encode the
19703 status of ATPCS support, so instead we create a dummy,
19704 empty, debug section called .arm.atpcs. */
19705 if (atpcs)
19706 {
19707 asection * sec;
19708
19709 sec = bfd_make_section (stdoutput, ".arm.atpcs");
19710
19711 if (sec != NULL)
19712 {
19713 bfd_set_section_flags
19714 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
19715 bfd_set_section_size (stdoutput, sec, 0);
19716 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
19717 }
19718 }
19719 }
19720 #endif
19721
19722 /* Record the CPU type as well. */
19723 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
19724 mach = bfd_mach_arm_iWMMXt2;
19725 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
19726 mach = bfd_mach_arm_iWMMXt;
19727 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
19728 mach = bfd_mach_arm_XScale;
19729 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
19730 mach = bfd_mach_arm_ep9312;
19731 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
19732 mach = bfd_mach_arm_5TE;
19733 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
19734 {
19735 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
19736 mach = bfd_mach_arm_5T;
19737 else
19738 mach = bfd_mach_arm_5;
19739 }
19740 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
19741 {
19742 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
19743 mach = bfd_mach_arm_4T;
19744 else
19745 mach = bfd_mach_arm_4;
19746 }
19747 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
19748 mach = bfd_mach_arm_3M;
19749 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
19750 mach = bfd_mach_arm_3;
19751 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
19752 mach = bfd_mach_arm_2a;
19753 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
19754 mach = bfd_mach_arm_2;
19755 else
19756 mach = bfd_mach_arm_unknown;
19757
19758 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
19759 }
19760
19761 /* Command line processing. */
19762
19763 /* md_parse_option
19764 Invocation line includes a switch not recognized by the base assembler.
19765 See if it's a processor-specific option.
19766
19767 This routine is somewhat complicated by the need for backwards
19768 compatibility (since older releases of gcc can't be changed).
19769 The new options try to make the interface as compatible as
19770 possible with GCC.
19771
19772 New options (supported) are:
19773
19774 -mcpu=<cpu name> Assemble for selected processor
19775 -march=<architecture name> Assemble for selected architecture
19776 -mfpu=<fpu architecture> Assemble for selected FPU.
19777 -EB/-mbig-endian Big-endian
19778 -EL/-mlittle-endian Little-endian
19779 -k Generate PIC code
19780 -mthumb Start in Thumb mode
19781 -mthumb-interwork Code supports ARM/Thumb interworking
19782
19783 For now we will also provide support for:
19784
19785 -mapcs-32 32-bit Program counter
19786 -mapcs-26 26-bit Program counter
19787 -macps-float Floats passed in FP registers
19788 -mapcs-reentrant Reentrant code
19789 -matpcs
19790 (sometime these will probably be replaced with -mapcs=<list of options>
19791 and -matpcs=<list of options>)
19792
19793 The remaining options are only supported for back-wards compatibility.
19794 Cpu variants, the arm part is optional:
19795 -m[arm]1 Currently not supported.
19796 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
19797 -m[arm]3 Arm 3 processor
19798 -m[arm]6[xx], Arm 6 processors
19799 -m[arm]7[xx][t][[d]m] Arm 7 processors
19800 -m[arm]8[10] Arm 8 processors
19801 -m[arm]9[20][tdmi] Arm 9 processors
19802 -mstrongarm[110[0]] StrongARM processors
19803 -mxscale XScale processors
19804 -m[arm]v[2345[t[e]]] Arm architectures
19805 -mall All (except the ARM1)
19806 FP variants:
19807 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
19808 -mfpe-old (No float load/store multiples)
19809 -mvfpxd VFP Single precision
19810 -mvfp All VFP
19811 -mno-fpu Disable all floating point instructions
19812
19813 The following CPU names are recognized:
19814 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
19815 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
19816 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
19817 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
19818 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
19819 arm10t arm10e, arm1020t, arm1020e, arm10200e,
19820 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
19821
19822 */
19823
19824 const char * md_shortopts = "m:k";
19825
19826 #ifdef ARM_BI_ENDIAN
19827 #define OPTION_EB (OPTION_MD_BASE + 0)
19828 #define OPTION_EL (OPTION_MD_BASE + 1)
19829 #else
19830 #if TARGET_BYTES_BIG_ENDIAN
19831 #define OPTION_EB (OPTION_MD_BASE + 0)
19832 #else
19833 #define OPTION_EL (OPTION_MD_BASE + 1)
19834 #endif
19835 #endif
19836 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
19837
19838 struct option md_longopts[] =
19839 {
19840 #ifdef OPTION_EB
19841 {"EB", no_argument, NULL, OPTION_EB},
19842 #endif
19843 #ifdef OPTION_EL
19844 {"EL", no_argument, NULL, OPTION_EL},
19845 #endif
19846 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
19847 {NULL, no_argument, NULL, 0}
19848 };
19849
19850 size_t md_longopts_size = sizeof (md_longopts);
19851
19852 struct arm_option_table
19853 {
19854 char *option; /* Option name to match. */
19855 char *help; /* Help information. */
19856 int *var; /* Variable to change. */
19857 int value; /* What to change it to. */
19858 char *deprecated; /* If non-null, print this message. */
19859 };
19860
19861 struct arm_option_table arm_opts[] =
19862 {
19863 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
19864 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
19865 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
19866 &support_interwork, 1, NULL},
19867 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
19868 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
19869 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
19870 1, NULL},
19871 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
19872 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
19873 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
19874 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
19875 NULL},
19876
19877 /* These are recognized by the assembler, but have no affect on code. */
19878 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
19879 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
19880 {NULL, NULL, NULL, 0, NULL}
19881 };
19882
19883 struct arm_legacy_option_table
19884 {
19885 char *option; /* Option name to match. */
19886 const arm_feature_set **var; /* Variable to change. */
19887 const arm_feature_set value; /* What to change it to. */
19888 char *deprecated; /* If non-null, print this message. */
19889 };
19890
19891 const struct arm_legacy_option_table arm_legacy_opts[] =
19892 {
19893 /* DON'T add any new processors to this list -- we want the whole list
19894 to go away... Add them to the processors table instead. */
19895 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19896 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19897 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19898 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19899 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19900 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19901 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19902 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19903 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19904 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19905 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19906 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19907 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19908 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19909 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19910 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19911 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19912 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19913 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19914 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19915 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19916 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19917 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19918 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19919 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19920 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19921 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19922 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19923 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19924 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19925 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19926 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19927 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19928 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19929 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19930 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19931 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19932 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19933 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19934 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19935 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19936 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19937 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19938 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19939 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19940 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19941 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19942 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19943 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19944 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19945 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19946 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19947 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19948 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19949 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19950 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19951 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19952 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19953 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19954 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19955 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19956 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19957 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19958 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19959 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19960 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19961 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19962 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19963 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
19964 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
19965 N_("use -mcpu=strongarm110")},
19966 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
19967 N_("use -mcpu=strongarm1100")},
19968 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
19969 N_("use -mcpu=strongarm1110")},
19970 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
19971 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
19972 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
19973
19974 /* Architecture variants -- don't add any more to this list either. */
19975 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19976 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19977 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19978 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19979 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19980 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19981 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
19982 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
19983 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
19984 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
19985 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
19986 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
19987 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
19988 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
19989 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
19990 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
19991 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
19992 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
19993
19994 /* Floating point variants -- don't add any more to this list either. */
19995 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
19996 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
19997 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
19998 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
19999 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
20000
20001 {NULL, NULL, ARM_ARCH_NONE, NULL}
20002 };
20003
20004 struct arm_cpu_option_table
20005 {
20006 char *name;
20007 const arm_feature_set value;
20008 /* For some CPUs we assume an FPU unless the user explicitly sets
20009 -mfpu=... */
20010 const arm_feature_set default_fpu;
20011 /* The canonical name of the CPU, or NULL to use NAME converted to upper
20012 case. */
20013 const char *canonical_name;
20014 };
20015
20016 /* This list should, at a minimum, contain all the cpu names
20017 recognized by GCC. */
20018 static const struct arm_cpu_option_table arm_cpus[] =
20019 {
20020 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
20021 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
20022 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
20023 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20024 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20025 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20026 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20027 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20028 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20029 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20030 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20031 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20032 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20033 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20034 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20035 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20036 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20037 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20038 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20039 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20040 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20041 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20042 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20043 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20044 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20045 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20046 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20047 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20048 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20049 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20050 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20051 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20052 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20053 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20054 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20055 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20056 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20057 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20058 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20059 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
20060 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20061 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20062 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20063 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20064 /* For V5 or later processors we default to using VFP; but the user
20065 should really set the FPU type explicitly. */
20066 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20067 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20068 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20069 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20070 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20071 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20072 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
20073 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20074 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20075 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
20076 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20077 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20078 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20079 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20080 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20081 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
20082 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20083 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20084 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20085 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
20086 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20087 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
20088 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
20089 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
20090 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
20091 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
20092 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
20093 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
20094 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
20095 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
20096 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
20097 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
20098 | FPU_NEON_EXT_V1),
20099 NULL},
20100 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
20101 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
20102 /* ??? XSCALE is really an architecture. */
20103 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
20104 /* ??? iwmmxt is not a processor. */
20105 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
20106 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
20107 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
20108 /* Maverick */
20109 {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
20110 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
20111 };
20112
20113 struct arm_arch_option_table
20114 {
20115 char *name;
20116 const arm_feature_set value;
20117 const arm_feature_set default_fpu;
20118 };
20119
20120 /* This list should, at a minimum, contain all the architecture names
20121 recognized by GCC. */
20122 static const struct arm_arch_option_table arm_archs[] =
20123 {
20124 {"all", ARM_ANY, FPU_ARCH_FPA},
20125 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
20126 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
20127 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
20128 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
20129 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
20130 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
20131 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
20132 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
20133 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
20134 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
20135 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
20136 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
20137 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
20138 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
20139 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
20140 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
20141 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
20142 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
20143 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
20144 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
20145 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
20146 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
20147 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
20148 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
20149 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
20150 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
20151 /* The official spelling of the ARMv7 profile variants is the dashed form.
20152 Accept the non-dashed form for compatibility with old toolchains. */
20153 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20154 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20155 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
20156 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20157 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20158 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
20159 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
20160 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
20161 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
20162 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
20163 };
20164
20165 /* ISA extensions in the co-processor space. */
20166 struct arm_option_cpu_value_table
20167 {
20168 char *name;
20169 const arm_feature_set value;
20170 };
20171
20172 static const struct arm_option_cpu_value_table arm_extensions[] =
20173 {
20174 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
20175 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
20176 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
20177 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
20178 {NULL, ARM_ARCH_NONE}
20179 };
20180
20181 /* This list should, at a minimum, contain all the fpu names
20182 recognized by GCC. */
20183 static const struct arm_option_cpu_value_table arm_fpus[] =
20184 {
20185 {"softfpa", FPU_NONE},
20186 {"fpe", FPU_ARCH_FPE},
20187 {"fpe2", FPU_ARCH_FPE},
20188 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
20189 {"fpa", FPU_ARCH_FPA},
20190 {"fpa10", FPU_ARCH_FPA},
20191 {"fpa11", FPU_ARCH_FPA},
20192 {"arm7500fe", FPU_ARCH_FPA},
20193 {"softvfp", FPU_ARCH_VFP},
20194 {"softvfp+vfp", FPU_ARCH_VFP_V2},
20195 {"vfp", FPU_ARCH_VFP_V2},
20196 {"vfp9", FPU_ARCH_VFP_V2},
20197 {"vfp3", FPU_ARCH_VFP_V3},
20198 {"vfp10", FPU_ARCH_VFP_V2},
20199 {"vfp10-r0", FPU_ARCH_VFP_V1},
20200 {"vfpxd", FPU_ARCH_VFP_V1xD},
20201 {"arm1020t", FPU_ARCH_VFP_V1},
20202 {"arm1020e", FPU_ARCH_VFP_V2},
20203 {"arm1136jfs", FPU_ARCH_VFP_V2},
20204 {"arm1136jf-s", FPU_ARCH_VFP_V2},
20205 {"maverick", FPU_ARCH_MAVERICK},
20206 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
20207 {NULL, ARM_ARCH_NONE}
20208 };
20209
20210 struct arm_option_value_table
20211 {
20212 char *name;
20213 long value;
20214 };
20215
20216 static const struct arm_option_value_table arm_float_abis[] =
20217 {
20218 {"hard", ARM_FLOAT_ABI_HARD},
20219 {"softfp", ARM_FLOAT_ABI_SOFTFP},
20220 {"soft", ARM_FLOAT_ABI_SOFT},
20221 {NULL, 0}
20222 };
20223
20224 #ifdef OBJ_ELF
20225 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
20226 static const struct arm_option_value_table arm_eabis[] =
20227 {
20228 {"gnu", EF_ARM_EABI_UNKNOWN},
20229 {"4", EF_ARM_EABI_VER4},
20230 {"5", EF_ARM_EABI_VER5},
20231 {NULL, 0}
20232 };
20233 #endif
20234
20235 struct arm_long_option_table
20236 {
20237 char * option; /* Substring to match. */
20238 char * help; /* Help information. */
20239 int (* func) (char * subopt); /* Function to decode sub-option. */
20240 char * deprecated; /* If non-null, print this message. */
20241 };
20242
20243 static int
20244 arm_parse_extension (char * str, const arm_feature_set **opt_p)
20245 {
20246 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
20247
20248 /* Copy the feature set, so that we can modify it. */
20249 *ext_set = **opt_p;
20250 *opt_p = ext_set;
20251
20252 while (str != NULL && *str != 0)
20253 {
20254 const struct arm_option_cpu_value_table * opt;
20255 char * ext;
20256 int optlen;
20257
20258 if (*str != '+')
20259 {
20260 as_bad (_("invalid architectural extension"));
20261 return 0;
20262 }
20263
20264 str++;
20265 ext = strchr (str, '+');
20266
20267 if (ext != NULL)
20268 optlen = ext - str;
20269 else
20270 optlen = strlen (str);
20271
20272 if (optlen == 0)
20273 {
20274 as_bad (_("missing architectural extension"));
20275 return 0;
20276 }
20277
20278 for (opt = arm_extensions; opt->name != NULL; opt++)
20279 if (strncmp (opt->name, str, optlen) == 0)
20280 {
20281 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
20282 break;
20283 }
20284
20285 if (opt->name == NULL)
20286 {
20287 as_bad (_("unknown architectural extension `%s'"), str);
20288 return 0;
20289 }
20290
20291 str = ext;
20292 };
20293
20294 return 1;
20295 }
20296
20297 static int
20298 arm_parse_cpu (char * str)
20299 {
20300 const struct arm_cpu_option_table * opt;
20301 char * ext = strchr (str, '+');
20302 int optlen;
20303
20304 if (ext != NULL)
20305 optlen = ext - str;
20306 else
20307 optlen = strlen (str);
20308
20309 if (optlen == 0)
20310 {
20311 as_bad (_("missing cpu name `%s'"), str);
20312 return 0;
20313 }
20314
20315 for (opt = arm_cpus; opt->name != NULL; opt++)
20316 if (strncmp (opt->name, str, optlen) == 0)
20317 {
20318 mcpu_cpu_opt = &opt->value;
20319 mcpu_fpu_opt = &opt->default_fpu;
20320 if (opt->canonical_name)
20321 strcpy (selected_cpu_name, opt->canonical_name);
20322 else
20323 {
20324 int i;
20325 for (i = 0; i < optlen; i++)
20326 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20327 selected_cpu_name[i] = 0;
20328 }
20329
20330 if (ext != NULL)
20331 return arm_parse_extension (ext, &mcpu_cpu_opt);
20332
20333 return 1;
20334 }
20335
20336 as_bad (_("unknown cpu `%s'"), str);
20337 return 0;
20338 }
20339
20340 static int
20341 arm_parse_arch (char * str)
20342 {
20343 const struct arm_arch_option_table *opt;
20344 char *ext = strchr (str, '+');
20345 int optlen;
20346
20347 if (ext != NULL)
20348 optlen = ext - str;
20349 else
20350 optlen = strlen (str);
20351
20352 if (optlen == 0)
20353 {
20354 as_bad (_("missing architecture name `%s'"), str);
20355 return 0;
20356 }
20357
20358 for (opt = arm_archs; opt->name != NULL; opt++)
20359 if (streq (opt->name, str))
20360 {
20361 march_cpu_opt = &opt->value;
20362 march_fpu_opt = &opt->default_fpu;
20363 strcpy (selected_cpu_name, opt->name);
20364
20365 if (ext != NULL)
20366 return arm_parse_extension (ext, &march_cpu_opt);
20367
20368 return 1;
20369 }
20370
20371 as_bad (_("unknown architecture `%s'\n"), str);
20372 return 0;
20373 }
20374
20375 static int
20376 arm_parse_fpu (char * str)
20377 {
20378 const struct arm_option_cpu_value_table * opt;
20379
20380 for (opt = arm_fpus; opt->name != NULL; opt++)
20381 if (streq (opt->name, str))
20382 {
20383 mfpu_opt = &opt->value;
20384 return 1;
20385 }
20386
20387 as_bad (_("unknown floating point format `%s'\n"), str);
20388 return 0;
20389 }
20390
20391 static int
20392 arm_parse_float_abi (char * str)
20393 {
20394 const struct arm_option_value_table * opt;
20395
20396 for (opt = arm_float_abis; opt->name != NULL; opt++)
20397 if (streq (opt->name, str))
20398 {
20399 mfloat_abi_opt = opt->value;
20400 return 1;
20401 }
20402
20403 as_bad (_("unknown floating point abi `%s'\n"), str);
20404 return 0;
20405 }
20406
20407 #ifdef OBJ_ELF
20408 static int
20409 arm_parse_eabi (char * str)
20410 {
20411 const struct arm_option_value_table *opt;
20412
20413 for (opt = arm_eabis; opt->name != NULL; opt++)
20414 if (streq (opt->name, str))
20415 {
20416 meabi_flags = opt->value;
20417 return 1;
20418 }
20419 as_bad (_("unknown EABI `%s'\n"), str);
20420 return 0;
20421 }
20422 #endif
20423
20424 struct arm_long_option_table arm_long_opts[] =
20425 {
20426 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
20427 arm_parse_cpu, NULL},
20428 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
20429 arm_parse_arch, NULL},
20430 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
20431 arm_parse_fpu, NULL},
20432 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
20433 arm_parse_float_abi, NULL},
20434 #ifdef OBJ_ELF
20435 {"meabi=", N_("<ver>\t assemble for eabi version <ver>"),
20436 arm_parse_eabi, NULL},
20437 #endif
20438 {NULL, NULL, 0, NULL}
20439 };
20440
20441 int
20442 md_parse_option (int c, char * arg)
20443 {
20444 struct arm_option_table *opt;
20445 const struct arm_legacy_option_table *fopt;
20446 struct arm_long_option_table *lopt;
20447
20448 switch (c)
20449 {
20450 #ifdef OPTION_EB
20451 case OPTION_EB:
20452 target_big_endian = 1;
20453 break;
20454 #endif
20455
20456 #ifdef OPTION_EL
20457 case OPTION_EL:
20458 target_big_endian = 0;
20459 break;
20460 #endif
20461
20462 case OPTION_FIX_V4BX:
20463 fix_v4bx = TRUE;
20464 break;
20465
20466 case 'a':
20467 /* Listing option. Just ignore these, we don't support additional
20468 ones. */
20469 return 0;
20470
20471 default:
20472 for (opt = arm_opts; opt->option != NULL; opt++)
20473 {
20474 if (c == opt->option[0]
20475 && ((arg == NULL && opt->option[1] == 0)
20476 || streq (arg, opt->option + 1)))
20477 {
20478 #if WARN_DEPRECATED
20479 /* If the option is deprecated, tell the user. */
20480 if (opt->deprecated != NULL)
20481 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20482 arg ? arg : "", _(opt->deprecated));
20483 #endif
20484
20485 if (opt->var != NULL)
20486 *opt->var = opt->value;
20487
20488 return 1;
20489 }
20490 }
20491
20492 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
20493 {
20494 if (c == fopt->option[0]
20495 && ((arg == NULL && fopt->option[1] == 0)
20496 || streq (arg, fopt->option + 1)))
20497 {
20498 #if WARN_DEPRECATED
20499 /* If the option is deprecated, tell the user. */
20500 if (fopt->deprecated != NULL)
20501 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20502 arg ? arg : "", _(fopt->deprecated));
20503 #endif
20504
20505 if (fopt->var != NULL)
20506 *fopt->var = &fopt->value;
20507
20508 return 1;
20509 }
20510 }
20511
20512 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20513 {
20514 /* These options are expected to have an argument. */
20515 if (c == lopt->option[0]
20516 && arg != NULL
20517 && strncmp (arg, lopt->option + 1,
20518 strlen (lopt->option + 1)) == 0)
20519 {
20520 #if WARN_DEPRECATED
20521 /* If the option is deprecated, tell the user. */
20522 if (lopt->deprecated != NULL)
20523 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
20524 _(lopt->deprecated));
20525 #endif
20526
20527 /* Call the sup-option parser. */
20528 return lopt->func (arg + strlen (lopt->option) - 1);
20529 }
20530 }
20531
20532 return 0;
20533 }
20534
20535 return 1;
20536 }
20537
20538 void
20539 md_show_usage (FILE * fp)
20540 {
20541 struct arm_option_table *opt;
20542 struct arm_long_option_table *lopt;
20543
20544 fprintf (fp, _(" ARM-specific assembler options:\n"));
20545
20546 for (opt = arm_opts; opt->option != NULL; opt++)
20547 if (opt->help != NULL)
20548 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
20549
20550 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20551 if (lopt->help != NULL)
20552 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
20553
20554 #ifdef OPTION_EB
20555 fprintf (fp, _("\
20556 -EB assemble code for a big-endian cpu\n"));
20557 #endif
20558
20559 #ifdef OPTION_EL
20560 fprintf (fp, _("\
20561 -EL assemble code for a little-endian cpu\n"));
20562 #endif
20563
20564 fprintf (fp, _("\
20565 --fix-v4bx Allow BX in ARMv4 code\n"));
20566 }
20567
20568
20569 #ifdef OBJ_ELF
20570 typedef struct
20571 {
20572 int val;
20573 arm_feature_set flags;
20574 } cpu_arch_ver_table;
20575
20576 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
20577 least features first. */
20578 static const cpu_arch_ver_table cpu_arch_ver[] =
20579 {
20580 {1, ARM_ARCH_V4},
20581 {2, ARM_ARCH_V4T},
20582 {3, ARM_ARCH_V5},
20583 {4, ARM_ARCH_V5TE},
20584 {5, ARM_ARCH_V5TEJ},
20585 {6, ARM_ARCH_V6},
20586 {7, ARM_ARCH_V6Z},
20587 {8, ARM_ARCH_V6K},
20588 {9, ARM_ARCH_V6T2},
20589 {10, ARM_ARCH_V7A},
20590 {10, ARM_ARCH_V7R},
20591 {10, ARM_ARCH_V7M},
20592 {0, ARM_ARCH_NONE}
20593 };
20594
20595 /* Set the public EABI object attributes. */
20596 static void
20597 aeabi_set_public_attributes (void)
20598 {
20599 int arch;
20600 arm_feature_set flags;
20601 arm_feature_set tmp;
20602 const cpu_arch_ver_table *p;
20603
20604 /* Choose the architecture based on the capabilities of the requested cpu
20605 (if any) and/or the instructions actually used. */
20606 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
20607 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
20608 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
20609 /*Allow the user to override the reported architecture. */
20610 if (object_arch)
20611 {
20612 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
20613 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
20614 }
20615
20616 tmp = flags;
20617 arch = 0;
20618 for (p = cpu_arch_ver; p->val; p++)
20619 {
20620 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
20621 {
20622 arch = p->val;
20623 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
20624 }
20625 }
20626
20627 /* Tag_CPU_name. */
20628 if (selected_cpu_name[0])
20629 {
20630 char *p;
20631
20632 p = selected_cpu_name;
20633 if (strncmp (p, "armv", 4) == 0)
20634 {
20635 int i;
20636
20637 p += 4;
20638 for (i = 0; p[i]; i++)
20639 p[i] = TOUPPER (p[i]);
20640 }
20641 bfd_elf_add_proc_attr_string (stdoutput, 5, p);
20642 }
20643 /* Tag_CPU_arch. */
20644 bfd_elf_add_proc_attr_int (stdoutput, 6, arch);
20645 /* Tag_CPU_arch_profile. */
20646 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
20647 bfd_elf_add_proc_attr_int (stdoutput, 7, 'A');
20648 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
20649 bfd_elf_add_proc_attr_int (stdoutput, 7, 'R');
20650 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m))
20651 bfd_elf_add_proc_attr_int (stdoutput, 7, 'M');
20652 /* Tag_ARM_ISA_use. */
20653 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_full))
20654 bfd_elf_add_proc_attr_int (stdoutput, 8, 1);
20655 /* Tag_THUMB_ISA_use. */
20656 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_full))
20657 bfd_elf_add_proc_attr_int (stdoutput, 9,
20658 ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2) ? 2 : 1);
20659 /* Tag_VFP_arch. */
20660 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v3)
20661 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v3))
20662 bfd_elf_add_proc_attr_int (stdoutput, 10, 3);
20663 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v2)
20664 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v2))
20665 bfd_elf_add_proc_attr_int (stdoutput, 10, 2);
20666 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1)
20667 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1)
20668 || ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1xd)
20669 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1xd))
20670 bfd_elf_add_proc_attr_int (stdoutput, 10, 1);
20671 /* Tag_WMMX_arch. */
20672 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_cext_iwmmxt)
20673 || ARM_CPU_HAS_FEATURE (arm_arch_used, arm_cext_iwmmxt))
20674 bfd_elf_add_proc_attr_int (stdoutput, 11, 1);
20675 /* Tag_NEON_arch. */
20676 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_neon_ext_v1)
20677 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_neon_ext_v1))
20678 bfd_elf_add_proc_attr_int (stdoutput, 12, 1);
20679 }
20680
20681 /* Add the default contents for the .ARM.attributes section. */
20682 void
20683 arm_md_end (void)
20684 {
20685 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
20686 return;
20687
20688 aeabi_set_public_attributes ();
20689 }
20690 #endif /* OBJ_ELF */
20691
20692
20693 /* Parse a .cpu directive. */
20694
20695 static void
20696 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
20697 {
20698 const struct arm_cpu_option_table *opt;
20699 char *name;
20700 char saved_char;
20701
20702 name = input_line_pointer;
20703 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
20704 input_line_pointer++;
20705 saved_char = *input_line_pointer;
20706 *input_line_pointer = 0;
20707
20708 /* Skip the first "all" entry. */
20709 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
20710 if (streq (opt->name, name))
20711 {
20712 mcpu_cpu_opt = &opt->value;
20713 selected_cpu = opt->value;
20714 if (opt->canonical_name)
20715 strcpy (selected_cpu_name, opt->canonical_name);
20716 else
20717 {
20718 int i;
20719 for (i = 0; opt->name[i]; i++)
20720 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20721 selected_cpu_name[i] = 0;
20722 }
20723 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20724 *input_line_pointer = saved_char;
20725 demand_empty_rest_of_line ();
20726 return;
20727 }
20728 as_bad (_("unknown cpu `%s'"), name);
20729 *input_line_pointer = saved_char;
20730 ignore_rest_of_line ();
20731 }
20732
20733
20734 /* Parse a .arch directive. */
20735
20736 static void
20737 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
20738 {
20739 const struct arm_arch_option_table *opt;
20740 char saved_char;
20741 char *name;
20742
20743 name = input_line_pointer;
20744 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
20745 input_line_pointer++;
20746 saved_char = *input_line_pointer;
20747 *input_line_pointer = 0;
20748
20749 /* Skip the first "all" entry. */
20750 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20751 if (streq (opt->name, name))
20752 {
20753 mcpu_cpu_opt = &opt->value;
20754 selected_cpu = opt->value;
20755 strcpy (selected_cpu_name, opt->name);
20756 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20757 *input_line_pointer = saved_char;
20758 demand_empty_rest_of_line ();
20759 return;
20760 }
20761
20762 as_bad (_("unknown architecture `%s'\n"), name);
20763 *input_line_pointer = saved_char;
20764 ignore_rest_of_line ();
20765 }
20766
20767
20768 /* Parse a .object_arch directive. */
20769
20770 static void
20771 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
20772 {
20773 const struct arm_arch_option_table *opt;
20774 char saved_char;
20775 char *name;
20776
20777 name = input_line_pointer;
20778 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
20779 input_line_pointer++;
20780 saved_char = *input_line_pointer;
20781 *input_line_pointer = 0;
20782
20783 /* Skip the first "all" entry. */
20784 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20785 if (streq (opt->name, name))
20786 {
20787 object_arch = &opt->value;
20788 *input_line_pointer = saved_char;
20789 demand_empty_rest_of_line ();
20790 return;
20791 }
20792
20793 as_bad (_("unknown architecture `%s'\n"), name);
20794 *input_line_pointer = saved_char;
20795 ignore_rest_of_line ();
20796 }
20797
20798
20799 /* Parse a .fpu directive. */
20800
20801 static void
20802 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
20803 {
20804 const struct arm_option_cpu_value_table *opt;
20805 char saved_char;
20806 char *name;
20807
20808 name = input_line_pointer;
20809 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
20810 input_line_pointer++;
20811 saved_char = *input_line_pointer;
20812 *input_line_pointer = 0;
20813
20814 for (opt = arm_fpus; opt->name != NULL; opt++)
20815 if (streq (opt->name, name))
20816 {
20817 mfpu_opt = &opt->value;
20818 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20819 *input_line_pointer = saved_char;
20820 demand_empty_rest_of_line ();
20821 return;
20822 }
20823
20824 as_bad (_("unknown floating point format `%s'\n"), name);
20825 *input_line_pointer = saved_char;
20826 ignore_rest_of_line ();
20827 }
20828
20829 /* Copy symbol information. */
20830 void
20831 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
20832 {
20833 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
20834 }