2008-05-22 Paul Brook <paul@codesourcery.com>
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
1 /* tc-arm.c -- Assemble for the ARM
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008
4 Free Software Foundation, Inc.
5 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
6 Modified by David Taylor (dtaylor@armltd.co.uk)
7 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
8 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
9 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
10
11 This file is part of GAS, the GNU Assembler.
12
13 GAS is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 3, or (at your option)
16 any later version.
17
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with GAS; see the file COPYING. If not, write to the Free
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 02110-1301, USA. */
27
28 #include <limits.h>
29 #include <stdarg.h>
30 #define NO_RELOC 0
31 #include "as.h"
32 #include "safe-ctype.h"
33 #include "subsegs.h"
34 #include "obstack.h"
35
36 #include "opcode/arm.h"
37
38 #ifdef OBJ_ELF
39 #include "elf/arm.h"
40 #include "dw2gencfi.h"
41 #endif
42
43 #include "dwarf2dbg.h"
44
45 #define WARN_DEPRECATED 1
46
47 #ifdef OBJ_ELF
48 /* Must be at least the size of the largest unwind opcode (currently two). */
49 #define ARM_OPCODE_CHUNK_SIZE 8
50
51 /* This structure holds the unwinding state. */
52
53 static struct
54 {
55 symbolS * proc_start;
56 symbolS * table_entry;
57 symbolS * personality_routine;
58 int personality_index;
59 /* The segment containing the function. */
60 segT saved_seg;
61 subsegT saved_subseg;
62 /* Opcodes generated from this function. */
63 unsigned char * opcodes;
64 int opcode_count;
65 int opcode_alloc;
66 /* The number of bytes pushed to the stack. */
67 offsetT frame_size;
68 /* We don't add stack adjustment opcodes immediately so that we can merge
69 multiple adjustments. We can also omit the final adjustment
70 when using a frame pointer. */
71 offsetT pending_offset;
72 /* These two fields are set by both unwind_movsp and unwind_setfp. They
73 hold the reg+offset to use when restoring sp from a frame pointer. */
74 offsetT fp_offset;
75 int fp_reg;
76 /* Nonzero if an unwind_setfp directive has been seen. */
77 unsigned fp_used:1;
78 /* Nonzero if the last opcode restores sp from fp_reg. */
79 unsigned sp_restored:1;
80 } unwind;
81
82 /* Bit N indicates that an R_ARM_NONE relocation has been output for
83 __aeabi_unwind_cpp_prN already if set. This enables dependencies to be
84 emitted only once per section, to save unnecessary bloat. */
85 static unsigned int marked_pr_dependency = 0;
86
87 #endif /* OBJ_ELF */
88
89 /* Results from operand parsing worker functions. */
90
91 typedef enum
92 {
93 PARSE_OPERAND_SUCCESS,
94 PARSE_OPERAND_FAIL,
95 PARSE_OPERAND_FAIL_NO_BACKTRACK
96 } parse_operand_result;
97
98 enum arm_float_abi
99 {
100 ARM_FLOAT_ABI_HARD,
101 ARM_FLOAT_ABI_SOFTFP,
102 ARM_FLOAT_ABI_SOFT
103 };
104
105 /* Types of processor to assemble for. */
106 #ifndef CPU_DEFAULT
107 #if defined __XSCALE__
108 #define CPU_DEFAULT ARM_ARCH_XSCALE
109 #else
110 #if defined __thumb__
111 #define CPU_DEFAULT ARM_ARCH_V5T
112 #endif
113 #endif
114 #endif
115
116 #ifndef FPU_DEFAULT
117 # ifdef TE_LINUX
118 # define FPU_DEFAULT FPU_ARCH_FPA
119 # elif defined (TE_NetBSD)
120 # ifdef OBJ_ELF
121 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
122 # else
123 /* Legacy a.out format. */
124 # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
125 # endif
126 # elif defined (TE_VXWORKS)
127 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
128 # else
129 /* For backwards compatibility, default to FPA. */
130 # define FPU_DEFAULT FPU_ARCH_FPA
131 # endif
132 #endif /* ifndef FPU_DEFAULT */
133
134 #define streq(a, b) (strcmp (a, b) == 0)
135
136 static arm_feature_set cpu_variant;
137 static arm_feature_set arm_arch_used;
138 static arm_feature_set thumb_arch_used;
139
140 /* Flags stored in private area of BFD structure. */
141 static int uses_apcs_26 = FALSE;
142 static int atpcs = FALSE;
143 static int support_interwork = FALSE;
144 static int uses_apcs_float = FALSE;
145 static int pic_code = FALSE;
146 static int fix_v4bx = FALSE;
147
148 /* Variables that we set while parsing command-line options. Once all
149 options have been read we re-process these values to set the real
150 assembly flags. */
151 static const arm_feature_set *legacy_cpu = NULL;
152 static const arm_feature_set *legacy_fpu = NULL;
153
154 static const arm_feature_set *mcpu_cpu_opt = NULL;
155 static const arm_feature_set *mcpu_fpu_opt = NULL;
156 static const arm_feature_set *march_cpu_opt = NULL;
157 static const arm_feature_set *march_fpu_opt = NULL;
158 static const arm_feature_set *mfpu_opt = NULL;
159 static const arm_feature_set *object_arch = NULL;
160
161 /* Constants for known architecture features. */
162 static const arm_feature_set fpu_default = FPU_DEFAULT;
163 static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
164 static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
165 static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
166 static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
167 static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
168 static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
169 static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
170 static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
171
172 #ifdef CPU_DEFAULT
173 static const arm_feature_set cpu_default = CPU_DEFAULT;
174 #endif
175
176 static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
177 static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
178 static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
179 static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
180 static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
181 static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
182 static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
183 static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
184 static const arm_feature_set arm_ext_v4t_5 =
185 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
186 static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
187 static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
188 static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
189 static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
190 static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
191 static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
192 static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
193 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
194 static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
195 static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
196 static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
197 static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
198 static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
199 static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
200 static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
201 static const arm_feature_set arm_ext_m =
202 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_V7M, 0);
203
204 static const arm_feature_set arm_arch_any = ARM_ANY;
205 static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
206 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
207 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
208
209 static const arm_feature_set arm_cext_iwmmxt2 =
210 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
211 static const arm_feature_set arm_cext_iwmmxt =
212 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
213 static const arm_feature_set arm_cext_xscale =
214 ARM_FEATURE (0, ARM_CEXT_XSCALE);
215 static const arm_feature_set arm_cext_maverick =
216 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
217 static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
218 static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
219 static const arm_feature_set fpu_vfp_ext_v1xd =
220 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
221 static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
222 static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
223 static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
224 static const arm_feature_set fpu_vfp_ext_d32 =
225 ARM_FEATURE (0, FPU_VFP_EXT_D32);
226 static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
227 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
228 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
229
230 static int mfloat_abi_opt = -1;
231 /* Record user cpu selection for object attributes. */
232 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
233 /* Must be long enough to hold any of the names in arm_cpus. */
234 static char selected_cpu_name[16];
235 #ifdef OBJ_ELF
236 # ifdef EABI_DEFAULT
237 static int meabi_flags = EABI_DEFAULT;
238 # else
239 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
240 # endif
241
242 bfd_boolean
243 arm_is_eabi (void)
244 {
245 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
246 }
247 #endif
248
249 #ifdef OBJ_ELF
250 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
251 symbolS * GOT_symbol;
252 #endif
253
254 /* 0: assemble for ARM,
255 1: assemble for Thumb,
256 2: assemble for Thumb even though target CPU does not support thumb
257 instructions. */
258 static int thumb_mode = 0;
259
260 /* If unified_syntax is true, we are processing the new unified
261 ARM/Thumb syntax. Important differences from the old ARM mode:
262
263 - Immediate operands do not require a # prefix.
264 - Conditional affixes always appear at the end of the
265 instruction. (For backward compatibility, those instructions
266 that formerly had them in the middle, continue to accept them
267 there.)
268 - The IT instruction may appear, and if it does is validated
269 against subsequent conditional affixes. It does not generate
270 machine code.
271
272 Important differences from the old Thumb mode:
273
274 - Immediate operands do not require a # prefix.
275 - Most of the V6T2 instructions are only available in unified mode.
276 - The .N and .W suffixes are recognized and honored (it is an error
277 if they cannot be honored).
278 - All instructions set the flags if and only if they have an 's' affix.
279 - Conditional affixes may be used. They are validated against
280 preceding IT instructions. Unlike ARM mode, you cannot use a
281 conditional affix except in the scope of an IT instruction. */
282
283 static bfd_boolean unified_syntax = FALSE;
284
285 enum neon_el_type
286 {
287 NT_invtype,
288 NT_untyped,
289 NT_integer,
290 NT_float,
291 NT_poly,
292 NT_signed,
293 NT_unsigned
294 };
295
296 struct neon_type_el
297 {
298 enum neon_el_type type;
299 unsigned size;
300 };
301
302 #define NEON_MAX_TYPE_ELS 4
303
304 struct neon_type
305 {
306 struct neon_type_el el[NEON_MAX_TYPE_ELS];
307 unsigned elems;
308 };
309
310 struct arm_it
311 {
312 const char * error;
313 unsigned long instruction;
314 int size;
315 int size_req;
316 int cond;
317 /* "uncond_value" is set to the value in place of the conditional field in
318 unconditional versions of the instruction, or -1 if nothing is
319 appropriate. */
320 int uncond_value;
321 struct neon_type vectype;
322 /* Set to the opcode if the instruction needs relaxation.
323 Zero if the instruction is not relaxed. */
324 unsigned long relax;
325 struct
326 {
327 bfd_reloc_code_real_type type;
328 expressionS exp;
329 int pc_rel;
330 } reloc;
331
332 struct
333 {
334 unsigned reg;
335 signed int imm;
336 struct neon_type_el vectype;
337 unsigned present : 1; /* Operand present. */
338 unsigned isreg : 1; /* Operand was a register. */
339 unsigned immisreg : 1; /* .imm field is a second register. */
340 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
341 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
342 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
343 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
344 instructions. This allows us to disambiguate ARM <-> vector insns. */
345 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
346 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
347 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
348 unsigned issingle : 1; /* Operand is VFP single-precision register. */
349 unsigned hasreloc : 1; /* Operand has relocation suffix. */
350 unsigned writeback : 1; /* Operand has trailing ! */
351 unsigned preind : 1; /* Preindexed address. */
352 unsigned postind : 1; /* Postindexed address. */
353 unsigned negative : 1; /* Index register was negated. */
354 unsigned shifted : 1; /* Shift applied to operation. */
355 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
356 } operands[6];
357 };
358
359 static struct arm_it inst;
360
361 #define NUM_FLOAT_VALS 8
362
363 const char * fp_const[] =
364 {
365 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
366 };
367
368 /* Number of littlenums required to hold an extended precision number. */
369 #define MAX_LITTLENUMS 6
370
371 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
372
373 #define FAIL (-1)
374 #define SUCCESS (0)
375
376 #define SUFF_S 1
377 #define SUFF_D 2
378 #define SUFF_E 3
379 #define SUFF_P 4
380
381 #define CP_T_X 0x00008000
382 #define CP_T_Y 0x00400000
383
384 #define CONDS_BIT 0x00100000
385 #define LOAD_BIT 0x00100000
386
387 #define DOUBLE_LOAD_FLAG 0x00000001
388
389 struct asm_cond
390 {
391 const char * template;
392 unsigned long value;
393 };
394
395 #define COND_ALWAYS 0xE
396
397 struct asm_psr
398 {
399 const char *template;
400 unsigned long field;
401 };
402
403 struct asm_barrier_opt
404 {
405 const char *template;
406 unsigned long value;
407 };
408
409 /* The bit that distinguishes CPSR and SPSR. */
410 #define SPSR_BIT (1 << 22)
411
412 /* The individual PSR flag bits. */
413 #define PSR_c (1 << 16)
414 #define PSR_x (1 << 17)
415 #define PSR_s (1 << 18)
416 #define PSR_f (1 << 19)
417
418 struct reloc_entry
419 {
420 char *name;
421 bfd_reloc_code_real_type reloc;
422 };
423
424 enum vfp_reg_pos
425 {
426 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
427 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
428 };
429
430 enum vfp_ldstm_type
431 {
432 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
433 };
434
435 /* Bits for DEFINED field in neon_typed_alias. */
436 #define NTA_HASTYPE 1
437 #define NTA_HASINDEX 2
438
439 struct neon_typed_alias
440 {
441 unsigned char defined;
442 unsigned char index;
443 struct neon_type_el eltype;
444 };
445
446 /* ARM register categories. This includes coprocessor numbers and various
447 architecture extensions' registers. */
448 enum arm_reg_type
449 {
450 REG_TYPE_RN,
451 REG_TYPE_CP,
452 REG_TYPE_CN,
453 REG_TYPE_FN,
454 REG_TYPE_VFS,
455 REG_TYPE_VFD,
456 REG_TYPE_NQ,
457 REG_TYPE_VFSD,
458 REG_TYPE_NDQ,
459 REG_TYPE_NSDQ,
460 REG_TYPE_VFC,
461 REG_TYPE_MVF,
462 REG_TYPE_MVD,
463 REG_TYPE_MVFX,
464 REG_TYPE_MVDX,
465 REG_TYPE_MVAX,
466 REG_TYPE_DSPSC,
467 REG_TYPE_MMXWR,
468 REG_TYPE_MMXWC,
469 REG_TYPE_MMXWCG,
470 REG_TYPE_XSCALE,
471 };
472
473 /* Structure for a hash table entry for a register.
474 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
475 information which states whether a vector type or index is specified (for a
476 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
477 struct reg_entry
478 {
479 const char *name;
480 unsigned char number;
481 unsigned char type;
482 unsigned char builtin;
483 struct neon_typed_alias *neon;
484 };
485
486 /* Diagnostics used when we don't get a register of the expected type. */
487 const char *const reg_expected_msgs[] =
488 {
489 N_("ARM register expected"),
490 N_("bad or missing co-processor number"),
491 N_("co-processor register expected"),
492 N_("FPA register expected"),
493 N_("VFP single precision register expected"),
494 N_("VFP/Neon double precision register expected"),
495 N_("Neon quad precision register expected"),
496 N_("VFP single or double precision register expected"),
497 N_("Neon double or quad precision register expected"),
498 N_("VFP single, double or Neon quad precision register expected"),
499 N_("VFP system register expected"),
500 N_("Maverick MVF register expected"),
501 N_("Maverick MVD register expected"),
502 N_("Maverick MVFX register expected"),
503 N_("Maverick MVDX register expected"),
504 N_("Maverick MVAX register expected"),
505 N_("Maverick DSPSC register expected"),
506 N_("iWMMXt data register expected"),
507 N_("iWMMXt control register expected"),
508 N_("iWMMXt scalar register expected"),
509 N_("XScale accumulator register expected"),
510 };
511
512 /* Some well known registers that we refer to directly elsewhere. */
513 #define REG_SP 13
514 #define REG_LR 14
515 #define REG_PC 15
516
517 /* ARM instructions take 4bytes in the object file, Thumb instructions
518 take 2: */
519 #define INSN_SIZE 4
520
521 struct asm_opcode
522 {
523 /* Basic string to match. */
524 const char *template;
525
526 /* Parameters to instruction. */
527 unsigned char operands[8];
528
529 /* Conditional tag - see opcode_lookup. */
530 unsigned int tag : 4;
531
532 /* Basic instruction code. */
533 unsigned int avalue : 28;
534
535 /* Thumb-format instruction code. */
536 unsigned int tvalue;
537
538 /* Which architecture variant provides this instruction. */
539 const arm_feature_set *avariant;
540 const arm_feature_set *tvariant;
541
542 /* Function to call to encode instruction in ARM format. */
543 void (* aencode) (void);
544
545 /* Function to call to encode instruction in Thumb format. */
546 void (* tencode) (void);
547 };
548
549 /* Defines for various bits that we will want to toggle. */
550 #define INST_IMMEDIATE 0x02000000
551 #define OFFSET_REG 0x02000000
552 #define HWOFFSET_IMM 0x00400000
553 #define SHIFT_BY_REG 0x00000010
554 #define PRE_INDEX 0x01000000
555 #define INDEX_UP 0x00800000
556 #define WRITE_BACK 0x00200000
557 #define LDM_TYPE_2_OR_3 0x00400000
558 #define CPSI_MMOD 0x00020000
559
560 #define LITERAL_MASK 0xf000f000
561 #define OPCODE_MASK 0xfe1fffff
562 #define V4_STR_BIT 0x00000020
563
564 #define T2_SUBS_PC_LR 0xf3de8f00
565
566 #define DATA_OP_SHIFT 21
567
568 #define T2_OPCODE_MASK 0xfe1fffff
569 #define T2_DATA_OP_SHIFT 21
570
571 /* Codes to distinguish the arithmetic instructions. */
572 #define OPCODE_AND 0
573 #define OPCODE_EOR 1
574 #define OPCODE_SUB 2
575 #define OPCODE_RSB 3
576 #define OPCODE_ADD 4
577 #define OPCODE_ADC 5
578 #define OPCODE_SBC 6
579 #define OPCODE_RSC 7
580 #define OPCODE_TST 8
581 #define OPCODE_TEQ 9
582 #define OPCODE_CMP 10
583 #define OPCODE_CMN 11
584 #define OPCODE_ORR 12
585 #define OPCODE_MOV 13
586 #define OPCODE_BIC 14
587 #define OPCODE_MVN 15
588
589 #define T2_OPCODE_AND 0
590 #define T2_OPCODE_BIC 1
591 #define T2_OPCODE_ORR 2
592 #define T2_OPCODE_ORN 3
593 #define T2_OPCODE_EOR 4
594 #define T2_OPCODE_ADD 8
595 #define T2_OPCODE_ADC 10
596 #define T2_OPCODE_SBC 11
597 #define T2_OPCODE_SUB 13
598 #define T2_OPCODE_RSB 14
599
600 #define T_OPCODE_MUL 0x4340
601 #define T_OPCODE_TST 0x4200
602 #define T_OPCODE_CMN 0x42c0
603 #define T_OPCODE_NEG 0x4240
604 #define T_OPCODE_MVN 0x43c0
605
606 #define T_OPCODE_ADD_R3 0x1800
607 #define T_OPCODE_SUB_R3 0x1a00
608 #define T_OPCODE_ADD_HI 0x4400
609 #define T_OPCODE_ADD_ST 0xb000
610 #define T_OPCODE_SUB_ST 0xb080
611 #define T_OPCODE_ADD_SP 0xa800
612 #define T_OPCODE_ADD_PC 0xa000
613 #define T_OPCODE_ADD_I8 0x3000
614 #define T_OPCODE_SUB_I8 0x3800
615 #define T_OPCODE_ADD_I3 0x1c00
616 #define T_OPCODE_SUB_I3 0x1e00
617
618 #define T_OPCODE_ASR_R 0x4100
619 #define T_OPCODE_LSL_R 0x4080
620 #define T_OPCODE_LSR_R 0x40c0
621 #define T_OPCODE_ROR_R 0x41c0
622 #define T_OPCODE_ASR_I 0x1000
623 #define T_OPCODE_LSL_I 0x0000
624 #define T_OPCODE_LSR_I 0x0800
625
626 #define T_OPCODE_MOV_I8 0x2000
627 #define T_OPCODE_CMP_I8 0x2800
628 #define T_OPCODE_CMP_LR 0x4280
629 #define T_OPCODE_MOV_HR 0x4600
630 #define T_OPCODE_CMP_HR 0x4500
631
632 #define T_OPCODE_LDR_PC 0x4800
633 #define T_OPCODE_LDR_SP 0x9800
634 #define T_OPCODE_STR_SP 0x9000
635 #define T_OPCODE_LDR_IW 0x6800
636 #define T_OPCODE_STR_IW 0x6000
637 #define T_OPCODE_LDR_IH 0x8800
638 #define T_OPCODE_STR_IH 0x8000
639 #define T_OPCODE_LDR_IB 0x7800
640 #define T_OPCODE_STR_IB 0x7000
641 #define T_OPCODE_LDR_RW 0x5800
642 #define T_OPCODE_STR_RW 0x5000
643 #define T_OPCODE_LDR_RH 0x5a00
644 #define T_OPCODE_STR_RH 0x5200
645 #define T_OPCODE_LDR_RB 0x5c00
646 #define T_OPCODE_STR_RB 0x5400
647
648 #define T_OPCODE_PUSH 0xb400
649 #define T_OPCODE_POP 0xbc00
650
651 #define T_OPCODE_BRANCH 0xe000
652
653 #define THUMB_SIZE 2 /* Size of thumb instruction. */
654 #define THUMB_PP_PC_LR 0x0100
655 #define THUMB_LOAD_BIT 0x0800
656 #define THUMB2_LOAD_BIT 0x00100000
657
658 #define BAD_ARGS _("bad arguments to instruction")
659 #define BAD_PC _("r15 not allowed here")
660 #define BAD_COND _("instruction cannot be conditional")
661 #define BAD_OVERLAP _("registers may not be the same")
662 #define BAD_HIREG _("lo register required")
663 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
664 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
665 #define BAD_BRANCH _("branch must be last instruction in IT block")
666 #define BAD_NOT_IT _("instruction not allowed in IT block")
667 #define BAD_FPU _("selected FPU does not support instruction")
668
669 static struct hash_control *arm_ops_hsh;
670 static struct hash_control *arm_cond_hsh;
671 static struct hash_control *arm_shift_hsh;
672 static struct hash_control *arm_psr_hsh;
673 static struct hash_control *arm_v7m_psr_hsh;
674 static struct hash_control *arm_reg_hsh;
675 static struct hash_control *arm_reloc_hsh;
676 static struct hash_control *arm_barrier_opt_hsh;
677
678 /* Stuff needed to resolve the label ambiguity
679 As:
680 ...
681 label: <insn>
682 may differ from:
683 ...
684 label:
685 <insn> */
686
687 symbolS * last_label_seen;
688 static int label_is_thumb_function_name = FALSE;
689 \f
690 /* Literal pool structure. Held on a per-section
691 and per-sub-section basis. */
692
693 #define MAX_LITERAL_POOL_SIZE 1024
694 typedef struct literal_pool
695 {
696 expressionS literals [MAX_LITERAL_POOL_SIZE];
697 unsigned int next_free_entry;
698 unsigned int id;
699 symbolS * symbol;
700 segT section;
701 subsegT sub_section;
702 struct literal_pool * next;
703 } literal_pool;
704
705 /* Pointer to a linked list of literal pools. */
706 literal_pool * list_of_pools = NULL;
707
708 /* State variables for IT block handling. */
709 static bfd_boolean current_it_mask = 0;
710 static int current_cc;
711 \f
712 /* Pure syntax. */
713
714 /* This array holds the chars that always start a comment. If the
715 pre-processor is disabled, these aren't very useful. */
716 const char comment_chars[] = "@";
717
718 /* This array holds the chars that only start a comment at the beginning of
719 a line. If the line seems to have the form '# 123 filename'
720 .line and .file directives will appear in the pre-processed output. */
721 /* Note that input_file.c hand checks for '#' at the beginning of the
722 first line of the input file. This is because the compiler outputs
723 #NO_APP at the beginning of its output. */
724 /* Also note that comments like this one will always work. */
725 const char line_comment_chars[] = "#";
726
727 const char line_separator_chars[] = ";";
728
729 /* Chars that can be used to separate mant
730 from exp in floating point numbers. */
731 const char EXP_CHARS[] = "eE";
732
733 /* Chars that mean this number is a floating point constant. */
734 /* As in 0f12.456 */
735 /* or 0d1.2345e12 */
736
737 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
738
739 /* Prefix characters that indicate the start of an immediate
740 value. */
741 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
742
743 /* Separator character handling. */
744
745 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
746
747 static inline int
748 skip_past_char (char ** str, char c)
749 {
750 if (**str == c)
751 {
752 (*str)++;
753 return SUCCESS;
754 }
755 else
756 return FAIL;
757 }
758 #define skip_past_comma(str) skip_past_char (str, ',')
759
760 /* Arithmetic expressions (possibly involving symbols). */
761
762 /* Return TRUE if anything in the expression is a bignum. */
763
764 static int
765 walk_no_bignums (symbolS * sp)
766 {
767 if (symbol_get_value_expression (sp)->X_op == O_big)
768 return 1;
769
770 if (symbol_get_value_expression (sp)->X_add_symbol)
771 {
772 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
773 || (symbol_get_value_expression (sp)->X_op_symbol
774 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
775 }
776
777 return 0;
778 }
779
780 static int in_my_get_expression = 0;
781
782 /* Third argument to my_get_expression. */
783 #define GE_NO_PREFIX 0
784 #define GE_IMM_PREFIX 1
785 #define GE_OPT_PREFIX 2
786 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
787 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
788 #define GE_OPT_PREFIX_BIG 3
789
790 static int
791 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
792 {
793 char * save_in;
794 segT seg;
795
796 /* In unified syntax, all prefixes are optional. */
797 if (unified_syntax)
798 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
799 : GE_OPT_PREFIX;
800
801 switch (prefix_mode)
802 {
803 case GE_NO_PREFIX: break;
804 case GE_IMM_PREFIX:
805 if (!is_immediate_prefix (**str))
806 {
807 inst.error = _("immediate expression requires a # prefix");
808 return FAIL;
809 }
810 (*str)++;
811 break;
812 case GE_OPT_PREFIX:
813 case GE_OPT_PREFIX_BIG:
814 if (is_immediate_prefix (**str))
815 (*str)++;
816 break;
817 default: abort ();
818 }
819
820 memset (ep, 0, sizeof (expressionS));
821
822 save_in = input_line_pointer;
823 input_line_pointer = *str;
824 in_my_get_expression = 1;
825 seg = expression (ep);
826 in_my_get_expression = 0;
827
828 if (ep->X_op == O_illegal)
829 {
830 /* We found a bad expression in md_operand(). */
831 *str = input_line_pointer;
832 input_line_pointer = save_in;
833 if (inst.error == NULL)
834 inst.error = _("bad expression");
835 return 1;
836 }
837
838 #ifdef OBJ_AOUT
839 if (seg != absolute_section
840 && seg != text_section
841 && seg != data_section
842 && seg != bss_section
843 && seg != undefined_section)
844 {
845 inst.error = _("bad segment");
846 *str = input_line_pointer;
847 input_line_pointer = save_in;
848 return 1;
849 }
850 #endif
851
852 /* Get rid of any bignums now, so that we don't generate an error for which
853 we can't establish a line number later on. Big numbers are never valid
854 in instructions, which is where this routine is always called. */
855 if (prefix_mode != GE_OPT_PREFIX_BIG
856 && (ep->X_op == O_big
857 || (ep->X_add_symbol
858 && (walk_no_bignums (ep->X_add_symbol)
859 || (ep->X_op_symbol
860 && walk_no_bignums (ep->X_op_symbol))))))
861 {
862 inst.error = _("invalid constant");
863 *str = input_line_pointer;
864 input_line_pointer = save_in;
865 return 1;
866 }
867
868 *str = input_line_pointer;
869 input_line_pointer = save_in;
870 return 0;
871 }
872
873 /* Turn a string in input_line_pointer into a floating point constant
874 of type TYPE, and store the appropriate bytes in *LITP. The number
875 of LITTLENUMS emitted is stored in *SIZEP. An error message is
876 returned, or NULL on OK.
877
878 Note that fp constants aren't represent in the normal way on the ARM.
879 In big endian mode, things are as expected. However, in little endian
880 mode fp constants are big-endian word-wise, and little-endian byte-wise
881 within the words. For example, (double) 1.1 in big endian mode is
882 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
883 the byte sequence 99 99 f1 3f 9a 99 99 99.
884
885 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
886
887 char *
888 md_atof (int type, char * litP, int * sizeP)
889 {
890 int prec;
891 LITTLENUM_TYPE words[MAX_LITTLENUMS];
892 char *t;
893 int i;
894
895 switch (type)
896 {
897 case 'f':
898 case 'F':
899 case 's':
900 case 'S':
901 prec = 2;
902 break;
903
904 case 'd':
905 case 'D':
906 case 'r':
907 case 'R':
908 prec = 4;
909 break;
910
911 case 'x':
912 case 'X':
913 prec = 5;
914 break;
915
916 case 'p':
917 case 'P':
918 prec = 5;
919 break;
920
921 default:
922 *sizeP = 0;
923 return _("Unrecognized or unsupported floating point constant");
924 }
925
926 t = atof_ieee (input_line_pointer, type, words);
927 if (t)
928 input_line_pointer = t;
929 *sizeP = prec * sizeof (LITTLENUM_TYPE);
930
931 if (target_big_endian)
932 {
933 for (i = 0; i < prec; i++)
934 {
935 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
936 litP += sizeof (LITTLENUM_TYPE);
937 }
938 }
939 else
940 {
941 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
942 for (i = prec - 1; i >= 0; i--)
943 {
944 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
945 litP += sizeof (LITTLENUM_TYPE);
946 }
947 else
948 /* For a 4 byte float the order of elements in `words' is 1 0.
949 For an 8 byte float the order is 1 0 3 2. */
950 for (i = 0; i < prec; i += 2)
951 {
952 md_number_to_chars (litP, (valueT) words[i + 1],
953 sizeof (LITTLENUM_TYPE));
954 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
955 (valueT) words[i], sizeof (LITTLENUM_TYPE));
956 litP += 2 * sizeof (LITTLENUM_TYPE);
957 }
958 }
959
960 return NULL;
961 }
962
963 /* We handle all bad expressions here, so that we can report the faulty
964 instruction in the error message. */
965 void
966 md_operand (expressionS * expr)
967 {
968 if (in_my_get_expression)
969 expr->X_op = O_illegal;
970 }
971
972 /* Immediate values. */
973
974 /* Generic immediate-value read function for use in directives.
975 Accepts anything that 'expression' can fold to a constant.
976 *val receives the number. */
977 #ifdef OBJ_ELF
978 static int
979 immediate_for_directive (int *val)
980 {
981 expressionS exp;
982 exp.X_op = O_illegal;
983
984 if (is_immediate_prefix (*input_line_pointer))
985 {
986 input_line_pointer++;
987 expression (&exp);
988 }
989
990 if (exp.X_op != O_constant)
991 {
992 as_bad (_("expected #constant"));
993 ignore_rest_of_line ();
994 return FAIL;
995 }
996 *val = exp.X_add_number;
997 return SUCCESS;
998 }
999 #endif
1000
1001 /* Register parsing. */
1002
1003 /* Generic register parser. CCP points to what should be the
1004 beginning of a register name. If it is indeed a valid register
1005 name, advance CCP over it and return the reg_entry structure;
1006 otherwise return NULL. Does not issue diagnostics. */
1007
1008 static struct reg_entry *
1009 arm_reg_parse_multi (char **ccp)
1010 {
1011 char *start = *ccp;
1012 char *p;
1013 struct reg_entry *reg;
1014
1015 #ifdef REGISTER_PREFIX
1016 if (*start != REGISTER_PREFIX)
1017 return NULL;
1018 start++;
1019 #endif
1020 #ifdef OPTIONAL_REGISTER_PREFIX
1021 if (*start == OPTIONAL_REGISTER_PREFIX)
1022 start++;
1023 #endif
1024
1025 p = start;
1026 if (!ISALPHA (*p) || !is_name_beginner (*p))
1027 return NULL;
1028
1029 do
1030 p++;
1031 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1032
1033 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1034
1035 if (!reg)
1036 return NULL;
1037
1038 *ccp = p;
1039 return reg;
1040 }
1041
1042 static int
1043 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1044 enum arm_reg_type type)
1045 {
1046 /* Alternative syntaxes are accepted for a few register classes. */
1047 switch (type)
1048 {
1049 case REG_TYPE_MVF:
1050 case REG_TYPE_MVD:
1051 case REG_TYPE_MVFX:
1052 case REG_TYPE_MVDX:
1053 /* Generic coprocessor register names are allowed for these. */
1054 if (reg && reg->type == REG_TYPE_CN)
1055 return reg->number;
1056 break;
1057
1058 case REG_TYPE_CP:
1059 /* For backward compatibility, a bare number is valid here. */
1060 {
1061 unsigned long processor = strtoul (start, ccp, 10);
1062 if (*ccp != start && processor <= 15)
1063 return processor;
1064 }
1065
1066 case REG_TYPE_MMXWC:
1067 /* WC includes WCG. ??? I'm not sure this is true for all
1068 instructions that take WC registers. */
1069 if (reg && reg->type == REG_TYPE_MMXWCG)
1070 return reg->number;
1071 break;
1072
1073 default:
1074 break;
1075 }
1076
1077 return FAIL;
1078 }
1079
1080 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1081 return value is the register number or FAIL. */
1082
1083 static int
1084 arm_reg_parse (char **ccp, enum arm_reg_type type)
1085 {
1086 char *start = *ccp;
1087 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1088 int ret;
1089
1090 /* Do not allow a scalar (reg+index) to parse as a register. */
1091 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1092 return FAIL;
1093
1094 if (reg && reg->type == type)
1095 return reg->number;
1096
1097 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1098 return ret;
1099
1100 *ccp = start;
1101 return FAIL;
1102 }
1103
1104 /* Parse a Neon type specifier. *STR should point at the leading '.'
1105 character. Does no verification at this stage that the type fits the opcode
1106 properly. E.g.,
1107
1108 .i32.i32.s16
1109 .s32.f32
1110 .u16
1111
1112 Can all be legally parsed by this function.
1113
1114 Fills in neon_type struct pointer with parsed information, and updates STR
1115 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1116 type, FAIL if not. */
1117
1118 static int
1119 parse_neon_type (struct neon_type *type, char **str)
1120 {
1121 char *ptr = *str;
1122
1123 if (type)
1124 type->elems = 0;
1125
1126 while (type->elems < NEON_MAX_TYPE_ELS)
1127 {
1128 enum neon_el_type thistype = NT_untyped;
1129 unsigned thissize = -1u;
1130
1131 if (*ptr != '.')
1132 break;
1133
1134 ptr++;
1135
1136 /* Just a size without an explicit type. */
1137 if (ISDIGIT (*ptr))
1138 goto parsesize;
1139
1140 switch (TOLOWER (*ptr))
1141 {
1142 case 'i': thistype = NT_integer; break;
1143 case 'f': thistype = NT_float; break;
1144 case 'p': thistype = NT_poly; break;
1145 case 's': thistype = NT_signed; break;
1146 case 'u': thistype = NT_unsigned; break;
1147 case 'd':
1148 thistype = NT_float;
1149 thissize = 64;
1150 ptr++;
1151 goto done;
1152 default:
1153 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1154 return FAIL;
1155 }
1156
1157 ptr++;
1158
1159 /* .f is an abbreviation for .f32. */
1160 if (thistype == NT_float && !ISDIGIT (*ptr))
1161 thissize = 32;
1162 else
1163 {
1164 parsesize:
1165 thissize = strtoul (ptr, &ptr, 10);
1166
1167 if (thissize != 8 && thissize != 16 && thissize != 32
1168 && thissize != 64)
1169 {
1170 as_bad (_("bad size %d in type specifier"), thissize);
1171 return FAIL;
1172 }
1173 }
1174
1175 done:
1176 if (type)
1177 {
1178 type->el[type->elems].type = thistype;
1179 type->el[type->elems].size = thissize;
1180 type->elems++;
1181 }
1182 }
1183
1184 /* Empty/missing type is not a successful parse. */
1185 if (type->elems == 0)
1186 return FAIL;
1187
1188 *str = ptr;
1189
1190 return SUCCESS;
1191 }
1192
1193 /* Errors may be set multiple times during parsing or bit encoding
1194 (particularly in the Neon bits), but usually the earliest error which is set
1195 will be the most meaningful. Avoid overwriting it with later (cascading)
1196 errors by calling this function. */
1197
1198 static void
1199 first_error (const char *err)
1200 {
1201 if (!inst.error)
1202 inst.error = err;
1203 }
1204
1205 /* Parse a single type, e.g. ".s32", leading period included. */
1206 static int
1207 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1208 {
1209 char *str = *ccp;
1210 struct neon_type optype;
1211
1212 if (*str == '.')
1213 {
1214 if (parse_neon_type (&optype, &str) == SUCCESS)
1215 {
1216 if (optype.elems == 1)
1217 *vectype = optype.el[0];
1218 else
1219 {
1220 first_error (_("only one type should be specified for operand"));
1221 return FAIL;
1222 }
1223 }
1224 else
1225 {
1226 first_error (_("vector type expected"));
1227 return FAIL;
1228 }
1229 }
1230 else
1231 return FAIL;
1232
1233 *ccp = str;
1234
1235 return SUCCESS;
1236 }
1237
1238 /* Special meanings for indices (which have a range of 0-7), which will fit into
1239 a 4-bit integer. */
1240
1241 #define NEON_ALL_LANES 15
1242 #define NEON_INTERLEAVE_LANES 14
1243
1244 /* Parse either a register or a scalar, with an optional type. Return the
1245 register number, and optionally fill in the actual type of the register
1246 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1247 type/index information in *TYPEINFO. */
1248
1249 static int
1250 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1251 enum arm_reg_type *rtype,
1252 struct neon_typed_alias *typeinfo)
1253 {
1254 char *str = *ccp;
1255 struct reg_entry *reg = arm_reg_parse_multi (&str);
1256 struct neon_typed_alias atype;
1257 struct neon_type_el parsetype;
1258
1259 atype.defined = 0;
1260 atype.index = -1;
1261 atype.eltype.type = NT_invtype;
1262 atype.eltype.size = -1;
1263
1264 /* Try alternate syntax for some types of register. Note these are mutually
1265 exclusive with the Neon syntax extensions. */
1266 if (reg == NULL)
1267 {
1268 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1269 if (altreg != FAIL)
1270 *ccp = str;
1271 if (typeinfo)
1272 *typeinfo = atype;
1273 return altreg;
1274 }
1275
1276 /* Undo polymorphism when a set of register types may be accepted. */
1277 if ((type == REG_TYPE_NDQ
1278 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1279 || (type == REG_TYPE_VFSD
1280 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1281 || (type == REG_TYPE_NSDQ
1282 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1283 || reg->type == REG_TYPE_NQ))
1284 || (type == REG_TYPE_MMXWC
1285 && (reg->type == REG_TYPE_MMXWCG)))
1286 type = reg->type;
1287
1288 if (type != reg->type)
1289 return FAIL;
1290
1291 if (reg->neon)
1292 atype = *reg->neon;
1293
1294 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1295 {
1296 if ((atype.defined & NTA_HASTYPE) != 0)
1297 {
1298 first_error (_("can't redefine type for operand"));
1299 return FAIL;
1300 }
1301 atype.defined |= NTA_HASTYPE;
1302 atype.eltype = parsetype;
1303 }
1304
1305 if (skip_past_char (&str, '[') == SUCCESS)
1306 {
1307 if (type != REG_TYPE_VFD)
1308 {
1309 first_error (_("only D registers may be indexed"));
1310 return FAIL;
1311 }
1312
1313 if ((atype.defined & NTA_HASINDEX) != 0)
1314 {
1315 first_error (_("can't change index for operand"));
1316 return FAIL;
1317 }
1318
1319 atype.defined |= NTA_HASINDEX;
1320
1321 if (skip_past_char (&str, ']') == SUCCESS)
1322 atype.index = NEON_ALL_LANES;
1323 else
1324 {
1325 expressionS exp;
1326
1327 my_get_expression (&exp, &str, GE_NO_PREFIX);
1328
1329 if (exp.X_op != O_constant)
1330 {
1331 first_error (_("constant expression required"));
1332 return FAIL;
1333 }
1334
1335 if (skip_past_char (&str, ']') == FAIL)
1336 return FAIL;
1337
1338 atype.index = exp.X_add_number;
1339 }
1340 }
1341
1342 if (typeinfo)
1343 *typeinfo = atype;
1344
1345 if (rtype)
1346 *rtype = type;
1347
1348 *ccp = str;
1349
1350 return reg->number;
1351 }
1352
1353 /* Like arm_reg_parse, but allow allow the following extra features:
1354 - If RTYPE is non-zero, return the (possibly restricted) type of the
1355 register (e.g. Neon double or quad reg when either has been requested).
1356 - If this is a Neon vector type with additional type information, fill
1357 in the struct pointed to by VECTYPE (if non-NULL).
1358 This function will fault on encountering a scalar. */
1359
1360 static int
1361 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1362 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1363 {
1364 struct neon_typed_alias atype;
1365 char *str = *ccp;
1366 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1367
1368 if (reg == FAIL)
1369 return FAIL;
1370
1371 /* Do not allow a scalar (reg+index) to parse as a register. */
1372 if ((atype.defined & NTA_HASINDEX) != 0)
1373 {
1374 first_error (_("register operand expected, but got scalar"));
1375 return FAIL;
1376 }
1377
1378 if (vectype)
1379 *vectype = atype.eltype;
1380
1381 *ccp = str;
1382
1383 return reg;
1384 }
1385
1386 #define NEON_SCALAR_REG(X) ((X) >> 4)
1387 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1388
1389 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1390 have enough information to be able to do a good job bounds-checking. So, we
1391 just do easy checks here, and do further checks later. */
1392
1393 static int
1394 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1395 {
1396 int reg;
1397 char *str = *ccp;
1398 struct neon_typed_alias atype;
1399
1400 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
1401
1402 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1403 return FAIL;
1404
1405 if (atype.index == NEON_ALL_LANES)
1406 {
1407 first_error (_("scalar must have an index"));
1408 return FAIL;
1409 }
1410 else if (atype.index >= 64 / elsize)
1411 {
1412 first_error (_("scalar index out of range"));
1413 return FAIL;
1414 }
1415
1416 if (type)
1417 *type = atype.eltype;
1418
1419 *ccp = str;
1420
1421 return reg * 16 + atype.index;
1422 }
1423
1424 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1425 static long
1426 parse_reg_list (char ** strp)
1427 {
1428 char * str = * strp;
1429 long range = 0;
1430 int another_range;
1431
1432 /* We come back here if we get ranges concatenated by '+' or '|'. */
1433 do
1434 {
1435 another_range = 0;
1436
1437 if (*str == '{')
1438 {
1439 int in_range = 0;
1440 int cur_reg = -1;
1441
1442 str++;
1443 do
1444 {
1445 int reg;
1446
1447 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1448 {
1449 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
1450 return FAIL;
1451 }
1452
1453 if (in_range)
1454 {
1455 int i;
1456
1457 if (reg <= cur_reg)
1458 {
1459 first_error (_("bad range in register list"));
1460 return FAIL;
1461 }
1462
1463 for (i = cur_reg + 1; i < reg; i++)
1464 {
1465 if (range & (1 << i))
1466 as_tsktsk
1467 (_("Warning: duplicated register (r%d) in register list"),
1468 i);
1469 else
1470 range |= 1 << i;
1471 }
1472 in_range = 0;
1473 }
1474
1475 if (range & (1 << reg))
1476 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1477 reg);
1478 else if (reg <= cur_reg)
1479 as_tsktsk (_("Warning: register range not in ascending order"));
1480
1481 range |= 1 << reg;
1482 cur_reg = reg;
1483 }
1484 while (skip_past_comma (&str) != FAIL
1485 || (in_range = 1, *str++ == '-'));
1486 str--;
1487
1488 if (*str++ != '}')
1489 {
1490 first_error (_("missing `}'"));
1491 return FAIL;
1492 }
1493 }
1494 else
1495 {
1496 expressionS expr;
1497
1498 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1499 return FAIL;
1500
1501 if (expr.X_op == O_constant)
1502 {
1503 if (expr.X_add_number
1504 != (expr.X_add_number & 0x0000ffff))
1505 {
1506 inst.error = _("invalid register mask");
1507 return FAIL;
1508 }
1509
1510 if ((range & expr.X_add_number) != 0)
1511 {
1512 int regno = range & expr.X_add_number;
1513
1514 regno &= -regno;
1515 regno = (1 << regno) - 1;
1516 as_tsktsk
1517 (_("Warning: duplicated register (r%d) in register list"),
1518 regno);
1519 }
1520
1521 range |= expr.X_add_number;
1522 }
1523 else
1524 {
1525 if (inst.reloc.type != 0)
1526 {
1527 inst.error = _("expression too complex");
1528 return FAIL;
1529 }
1530
1531 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1532 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1533 inst.reloc.pc_rel = 0;
1534 }
1535 }
1536
1537 if (*str == '|' || *str == '+')
1538 {
1539 str++;
1540 another_range = 1;
1541 }
1542 }
1543 while (another_range);
1544
1545 *strp = str;
1546 return range;
1547 }
1548
1549 /* Types of registers in a list. */
1550
1551 enum reg_list_els
1552 {
1553 REGLIST_VFP_S,
1554 REGLIST_VFP_D,
1555 REGLIST_NEON_D
1556 };
1557
1558 /* Parse a VFP register list. If the string is invalid return FAIL.
1559 Otherwise return the number of registers, and set PBASE to the first
1560 register. Parses registers of type ETYPE.
1561 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1562 - Q registers can be used to specify pairs of D registers
1563 - { } can be omitted from around a singleton register list
1564 FIXME: This is not implemented, as it would require backtracking in
1565 some cases, e.g.:
1566 vtbl.8 d3,d4,d5
1567 This could be done (the meaning isn't really ambiguous), but doesn't
1568 fit in well with the current parsing framework.
1569 - 32 D registers may be used (also true for VFPv3).
1570 FIXME: Types are ignored in these register lists, which is probably a
1571 bug. */
1572
1573 static int
1574 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
1575 {
1576 char *str = *ccp;
1577 int base_reg;
1578 int new_base;
1579 enum arm_reg_type regtype = 0;
1580 int max_regs = 0;
1581 int count = 0;
1582 int warned = 0;
1583 unsigned long mask = 0;
1584 int i;
1585
1586 if (*str != '{')
1587 {
1588 inst.error = _("expecting {");
1589 return FAIL;
1590 }
1591
1592 str++;
1593
1594 switch (etype)
1595 {
1596 case REGLIST_VFP_S:
1597 regtype = REG_TYPE_VFS;
1598 max_regs = 32;
1599 break;
1600
1601 case REGLIST_VFP_D:
1602 regtype = REG_TYPE_VFD;
1603 break;
1604
1605 case REGLIST_NEON_D:
1606 regtype = REG_TYPE_NDQ;
1607 break;
1608 }
1609
1610 if (etype != REGLIST_VFP_S)
1611 {
1612 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1613 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
1614 {
1615 max_regs = 32;
1616 if (thumb_mode)
1617 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1618 fpu_vfp_ext_d32);
1619 else
1620 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1621 fpu_vfp_ext_d32);
1622 }
1623 else
1624 max_regs = 16;
1625 }
1626
1627 base_reg = max_regs;
1628
1629 do
1630 {
1631 int setmask = 1, addregs = 1;
1632
1633 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
1634
1635 if (new_base == FAIL)
1636 {
1637 first_error (_(reg_expected_msgs[regtype]));
1638 return FAIL;
1639 }
1640
1641 if (new_base >= max_regs)
1642 {
1643 first_error (_("register out of range in list"));
1644 return FAIL;
1645 }
1646
1647 /* Note: a value of 2 * n is returned for the register Q<n>. */
1648 if (regtype == REG_TYPE_NQ)
1649 {
1650 setmask = 3;
1651 addregs = 2;
1652 }
1653
1654 if (new_base < base_reg)
1655 base_reg = new_base;
1656
1657 if (mask & (setmask << new_base))
1658 {
1659 first_error (_("invalid register list"));
1660 return FAIL;
1661 }
1662
1663 if ((mask >> new_base) != 0 && ! warned)
1664 {
1665 as_tsktsk (_("register list not in ascending order"));
1666 warned = 1;
1667 }
1668
1669 mask |= setmask << new_base;
1670 count += addregs;
1671
1672 if (*str == '-') /* We have the start of a range expression */
1673 {
1674 int high_range;
1675
1676 str++;
1677
1678 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
1679 == FAIL)
1680 {
1681 inst.error = gettext (reg_expected_msgs[regtype]);
1682 return FAIL;
1683 }
1684
1685 if (high_range >= max_regs)
1686 {
1687 first_error (_("register out of range in list"));
1688 return FAIL;
1689 }
1690
1691 if (regtype == REG_TYPE_NQ)
1692 high_range = high_range + 1;
1693
1694 if (high_range <= new_base)
1695 {
1696 inst.error = _("register range not in ascending order");
1697 return FAIL;
1698 }
1699
1700 for (new_base += addregs; new_base <= high_range; new_base += addregs)
1701 {
1702 if (mask & (setmask << new_base))
1703 {
1704 inst.error = _("invalid register list");
1705 return FAIL;
1706 }
1707
1708 mask |= setmask << new_base;
1709 count += addregs;
1710 }
1711 }
1712 }
1713 while (skip_past_comma (&str) != FAIL);
1714
1715 str++;
1716
1717 /* Sanity check -- should have raised a parse error above. */
1718 if (count == 0 || count > max_regs)
1719 abort ();
1720
1721 *pbase = base_reg;
1722
1723 /* Final test -- the registers must be consecutive. */
1724 mask >>= base_reg;
1725 for (i = 0; i < count; i++)
1726 {
1727 if ((mask & (1u << i)) == 0)
1728 {
1729 inst.error = _("non-contiguous register range");
1730 return FAIL;
1731 }
1732 }
1733
1734 *ccp = str;
1735
1736 return count;
1737 }
1738
1739 /* True if two alias types are the same. */
1740
1741 static int
1742 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1743 {
1744 if (!a && !b)
1745 return 1;
1746
1747 if (!a || !b)
1748 return 0;
1749
1750 if (a->defined != b->defined)
1751 return 0;
1752
1753 if ((a->defined & NTA_HASTYPE) != 0
1754 && (a->eltype.type != b->eltype.type
1755 || a->eltype.size != b->eltype.size))
1756 return 0;
1757
1758 if ((a->defined & NTA_HASINDEX) != 0
1759 && (a->index != b->index))
1760 return 0;
1761
1762 return 1;
1763 }
1764
1765 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1766 The base register is put in *PBASE.
1767 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
1768 the return value.
1769 The register stride (minus one) is put in bit 4 of the return value.
1770 Bits [6:5] encode the list length (minus one).
1771 The type of the list elements is put in *ELTYPE, if non-NULL. */
1772
1773 #define NEON_LANE(X) ((X) & 0xf)
1774 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
1775 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1776
1777 static int
1778 parse_neon_el_struct_list (char **str, unsigned *pbase,
1779 struct neon_type_el *eltype)
1780 {
1781 char *ptr = *str;
1782 int base_reg = -1;
1783 int reg_incr = -1;
1784 int count = 0;
1785 int lane = -1;
1786 int leading_brace = 0;
1787 enum arm_reg_type rtype = REG_TYPE_NDQ;
1788 int addregs = 1;
1789 const char *const incr_error = "register stride must be 1 or 2";
1790 const char *const type_error = "mismatched element/structure types in list";
1791 struct neon_typed_alias firsttype;
1792
1793 if (skip_past_char (&ptr, '{') == SUCCESS)
1794 leading_brace = 1;
1795
1796 do
1797 {
1798 struct neon_typed_alias atype;
1799 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1800
1801 if (getreg == FAIL)
1802 {
1803 first_error (_(reg_expected_msgs[rtype]));
1804 return FAIL;
1805 }
1806
1807 if (base_reg == -1)
1808 {
1809 base_reg = getreg;
1810 if (rtype == REG_TYPE_NQ)
1811 {
1812 reg_incr = 1;
1813 addregs = 2;
1814 }
1815 firsttype = atype;
1816 }
1817 else if (reg_incr == -1)
1818 {
1819 reg_incr = getreg - base_reg;
1820 if (reg_incr < 1 || reg_incr > 2)
1821 {
1822 first_error (_(incr_error));
1823 return FAIL;
1824 }
1825 }
1826 else if (getreg != base_reg + reg_incr * count)
1827 {
1828 first_error (_(incr_error));
1829 return FAIL;
1830 }
1831
1832 if (!neon_alias_types_same (&atype, &firsttype))
1833 {
1834 first_error (_(type_error));
1835 return FAIL;
1836 }
1837
1838 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1839 modes. */
1840 if (ptr[0] == '-')
1841 {
1842 struct neon_typed_alias htype;
1843 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1844 if (lane == -1)
1845 lane = NEON_INTERLEAVE_LANES;
1846 else if (lane != NEON_INTERLEAVE_LANES)
1847 {
1848 first_error (_(type_error));
1849 return FAIL;
1850 }
1851 if (reg_incr == -1)
1852 reg_incr = 1;
1853 else if (reg_incr != 1)
1854 {
1855 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
1856 return FAIL;
1857 }
1858 ptr++;
1859 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
1860 if (hireg == FAIL)
1861 {
1862 first_error (_(reg_expected_msgs[rtype]));
1863 return FAIL;
1864 }
1865 if (!neon_alias_types_same (&htype, &firsttype))
1866 {
1867 first_error (_(type_error));
1868 return FAIL;
1869 }
1870 count += hireg + dregs - getreg;
1871 continue;
1872 }
1873
1874 /* If we're using Q registers, we can't use [] or [n] syntax. */
1875 if (rtype == REG_TYPE_NQ)
1876 {
1877 count += 2;
1878 continue;
1879 }
1880
1881 if ((atype.defined & NTA_HASINDEX) != 0)
1882 {
1883 if (lane == -1)
1884 lane = atype.index;
1885 else if (lane != atype.index)
1886 {
1887 first_error (_(type_error));
1888 return FAIL;
1889 }
1890 }
1891 else if (lane == -1)
1892 lane = NEON_INTERLEAVE_LANES;
1893 else if (lane != NEON_INTERLEAVE_LANES)
1894 {
1895 first_error (_(type_error));
1896 return FAIL;
1897 }
1898 count++;
1899 }
1900 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
1901
1902 /* No lane set by [x]. We must be interleaving structures. */
1903 if (lane == -1)
1904 lane = NEON_INTERLEAVE_LANES;
1905
1906 /* Sanity check. */
1907 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
1908 || (count > 1 && reg_incr == -1))
1909 {
1910 first_error (_("error parsing element/structure list"));
1911 return FAIL;
1912 }
1913
1914 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
1915 {
1916 first_error (_("expected }"));
1917 return FAIL;
1918 }
1919
1920 if (reg_incr == -1)
1921 reg_incr = 1;
1922
1923 if (eltype)
1924 *eltype = firsttype.eltype;
1925
1926 *pbase = base_reg;
1927 *str = ptr;
1928
1929 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
1930 }
1931
1932 /* Parse an explicit relocation suffix on an expression. This is
1933 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1934 arm_reloc_hsh contains no entries, so this function can only
1935 succeed if there is no () after the word. Returns -1 on error,
1936 BFD_RELOC_UNUSED if there wasn't any suffix. */
1937 static int
1938 parse_reloc (char **str)
1939 {
1940 struct reloc_entry *r;
1941 char *p, *q;
1942
1943 if (**str != '(')
1944 return BFD_RELOC_UNUSED;
1945
1946 p = *str + 1;
1947 q = p;
1948
1949 while (*q && *q != ')' && *q != ',')
1950 q++;
1951 if (*q != ')')
1952 return -1;
1953
1954 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1955 return -1;
1956
1957 *str = q + 1;
1958 return r->reloc;
1959 }
1960
1961 /* Directives: register aliases. */
1962
1963 static struct reg_entry *
1964 insert_reg_alias (char *str, int number, int type)
1965 {
1966 struct reg_entry *new;
1967 const char *name;
1968
1969 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1970 {
1971 if (new->builtin)
1972 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
1973
1974 /* Only warn about a redefinition if it's not defined as the
1975 same register. */
1976 else if (new->number != number || new->type != type)
1977 as_warn (_("ignoring redefinition of register alias '%s'"), str);
1978
1979 return NULL;
1980 }
1981
1982 name = xstrdup (str);
1983 new = xmalloc (sizeof (struct reg_entry));
1984
1985 new->name = name;
1986 new->number = number;
1987 new->type = type;
1988 new->builtin = FALSE;
1989 new->neon = NULL;
1990
1991 if (hash_insert (arm_reg_hsh, name, (PTR) new))
1992 abort ();
1993
1994 return new;
1995 }
1996
1997 static void
1998 insert_neon_reg_alias (char *str, int number, int type,
1999 struct neon_typed_alias *atype)
2000 {
2001 struct reg_entry *reg = insert_reg_alias (str, number, type);
2002
2003 if (!reg)
2004 {
2005 first_error (_("attempt to redefine typed alias"));
2006 return;
2007 }
2008
2009 if (atype)
2010 {
2011 reg->neon = xmalloc (sizeof (struct neon_typed_alias));
2012 *reg->neon = *atype;
2013 }
2014 }
2015
2016 /* Look for the .req directive. This is of the form:
2017
2018 new_register_name .req existing_register_name
2019
2020 If we find one, or if it looks sufficiently like one that we want to
2021 handle any error here, return TRUE. Otherwise return FALSE. */
2022
2023 static bfd_boolean
2024 create_register_alias (char * newname, char *p)
2025 {
2026 struct reg_entry *old;
2027 char *oldname, *nbuf;
2028 size_t nlen;
2029
2030 /* The input scrubber ensures that whitespace after the mnemonic is
2031 collapsed to single spaces. */
2032 oldname = p;
2033 if (strncmp (oldname, " .req ", 6) != 0)
2034 return FALSE;
2035
2036 oldname += 6;
2037 if (*oldname == '\0')
2038 return FALSE;
2039
2040 old = hash_find (arm_reg_hsh, oldname);
2041 if (!old)
2042 {
2043 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2044 return TRUE;
2045 }
2046
2047 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2048 the desired alias name, and p points to its end. If not, then
2049 the desired alias name is in the global original_case_string. */
2050 #ifdef TC_CASE_SENSITIVE
2051 nlen = p - newname;
2052 #else
2053 newname = original_case_string;
2054 nlen = strlen (newname);
2055 #endif
2056
2057 nbuf = alloca (nlen + 1);
2058 memcpy (nbuf, newname, nlen);
2059 nbuf[nlen] = '\0';
2060
2061 /* Create aliases under the new name as stated; an all-lowercase
2062 version of the new name; and an all-uppercase version of the new
2063 name. */
2064 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2065 {
2066 for (p = nbuf; *p; p++)
2067 *p = TOUPPER (*p);
2068
2069 if (strncmp (nbuf, newname, nlen))
2070 {
2071 /* If this attempt to create an additional alias fails, do not bother
2072 trying to create the all-lower case alias. We will fail and issue
2073 a second, duplicate error message. This situation arises when the
2074 programmer does something like:
2075 foo .req r0
2076 Foo .req r1
2077 The second .req creates the "Foo" alias but then fails to create
2078 the artificial FOO alias because it has already been created by the
2079 first .req. */
2080 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2081 return TRUE;
2082 }
2083
2084 for (p = nbuf; *p; p++)
2085 *p = TOLOWER (*p);
2086
2087 if (strncmp (nbuf, newname, nlen))
2088 insert_reg_alias (nbuf, old->number, old->type);
2089 }
2090
2091 return TRUE;
2092 }
2093
2094 /* Create a Neon typed/indexed register alias using directives, e.g.:
2095 X .dn d5.s32[1]
2096 Y .qn 6.s16
2097 Z .dn d7
2098 T .dn Z[0]
2099 These typed registers can be used instead of the types specified after the
2100 Neon mnemonic, so long as all operands given have types. Types can also be
2101 specified directly, e.g.:
2102 vadd d0.s32, d1.s32, d2.s32 */
2103
2104 static int
2105 create_neon_reg_alias (char *newname, char *p)
2106 {
2107 enum arm_reg_type basetype;
2108 struct reg_entry *basereg;
2109 struct reg_entry mybasereg;
2110 struct neon_type ntype;
2111 struct neon_typed_alias typeinfo;
2112 char *namebuf, *nameend;
2113 int namelen;
2114
2115 typeinfo.defined = 0;
2116 typeinfo.eltype.type = NT_invtype;
2117 typeinfo.eltype.size = -1;
2118 typeinfo.index = -1;
2119
2120 nameend = p;
2121
2122 if (strncmp (p, " .dn ", 5) == 0)
2123 basetype = REG_TYPE_VFD;
2124 else if (strncmp (p, " .qn ", 5) == 0)
2125 basetype = REG_TYPE_NQ;
2126 else
2127 return 0;
2128
2129 p += 5;
2130
2131 if (*p == '\0')
2132 return 0;
2133
2134 basereg = arm_reg_parse_multi (&p);
2135
2136 if (basereg && basereg->type != basetype)
2137 {
2138 as_bad (_("bad type for register"));
2139 return 0;
2140 }
2141
2142 if (basereg == NULL)
2143 {
2144 expressionS exp;
2145 /* Try parsing as an integer. */
2146 my_get_expression (&exp, &p, GE_NO_PREFIX);
2147 if (exp.X_op != O_constant)
2148 {
2149 as_bad (_("expression must be constant"));
2150 return 0;
2151 }
2152 basereg = &mybasereg;
2153 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2154 : exp.X_add_number;
2155 basereg->neon = 0;
2156 }
2157
2158 if (basereg->neon)
2159 typeinfo = *basereg->neon;
2160
2161 if (parse_neon_type (&ntype, &p) == SUCCESS)
2162 {
2163 /* We got a type. */
2164 if (typeinfo.defined & NTA_HASTYPE)
2165 {
2166 as_bad (_("can't redefine the type of a register alias"));
2167 return 0;
2168 }
2169
2170 typeinfo.defined |= NTA_HASTYPE;
2171 if (ntype.elems != 1)
2172 {
2173 as_bad (_("you must specify a single type only"));
2174 return 0;
2175 }
2176 typeinfo.eltype = ntype.el[0];
2177 }
2178
2179 if (skip_past_char (&p, '[') == SUCCESS)
2180 {
2181 expressionS exp;
2182 /* We got a scalar index. */
2183
2184 if (typeinfo.defined & NTA_HASINDEX)
2185 {
2186 as_bad (_("can't redefine the index of a scalar alias"));
2187 return 0;
2188 }
2189
2190 my_get_expression (&exp, &p, GE_NO_PREFIX);
2191
2192 if (exp.X_op != O_constant)
2193 {
2194 as_bad (_("scalar index must be constant"));
2195 return 0;
2196 }
2197
2198 typeinfo.defined |= NTA_HASINDEX;
2199 typeinfo.index = exp.X_add_number;
2200
2201 if (skip_past_char (&p, ']') == FAIL)
2202 {
2203 as_bad (_("expecting ]"));
2204 return 0;
2205 }
2206 }
2207
2208 namelen = nameend - newname;
2209 namebuf = alloca (namelen + 1);
2210 strncpy (namebuf, newname, namelen);
2211 namebuf[namelen] = '\0';
2212
2213 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2214 typeinfo.defined != 0 ? &typeinfo : NULL);
2215
2216 /* Insert name in all uppercase. */
2217 for (p = namebuf; *p; p++)
2218 *p = TOUPPER (*p);
2219
2220 if (strncmp (namebuf, newname, namelen))
2221 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2222 typeinfo.defined != 0 ? &typeinfo : NULL);
2223
2224 /* Insert name in all lowercase. */
2225 for (p = namebuf; *p; p++)
2226 *p = TOLOWER (*p);
2227
2228 if (strncmp (namebuf, newname, namelen))
2229 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2230 typeinfo.defined != 0 ? &typeinfo : NULL);
2231
2232 return 1;
2233 }
2234
2235 /* Should never be called, as .req goes between the alias and the
2236 register name, not at the beginning of the line. */
2237 static void
2238 s_req (int a ATTRIBUTE_UNUSED)
2239 {
2240 as_bad (_("invalid syntax for .req directive"));
2241 }
2242
2243 static void
2244 s_dn (int a ATTRIBUTE_UNUSED)
2245 {
2246 as_bad (_("invalid syntax for .dn directive"));
2247 }
2248
2249 static void
2250 s_qn (int a ATTRIBUTE_UNUSED)
2251 {
2252 as_bad (_("invalid syntax for .qn directive"));
2253 }
2254
2255 /* The .unreq directive deletes an alias which was previously defined
2256 by .req. For example:
2257
2258 my_alias .req r11
2259 .unreq my_alias */
2260
2261 static void
2262 s_unreq (int a ATTRIBUTE_UNUSED)
2263 {
2264 char * name;
2265 char saved_char;
2266
2267 name = input_line_pointer;
2268
2269 while (*input_line_pointer != 0
2270 && *input_line_pointer != ' '
2271 && *input_line_pointer != '\n')
2272 ++input_line_pointer;
2273
2274 saved_char = *input_line_pointer;
2275 *input_line_pointer = 0;
2276
2277 if (!*name)
2278 as_bad (_("invalid syntax for .unreq directive"));
2279 else
2280 {
2281 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
2282
2283 if (!reg)
2284 as_bad (_("unknown register alias '%s'"), name);
2285 else if (reg->builtin)
2286 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2287 name);
2288 else
2289 {
2290 char * p;
2291 char * nbuf;
2292
2293 hash_delete (arm_reg_hsh, name);
2294 free ((char *) reg->name);
2295 if (reg->neon)
2296 free (reg->neon);
2297 free (reg);
2298
2299 /* Also locate the all upper case and all lower case versions.
2300 Do not complain if we cannot find one or the other as it
2301 was probably deleted above. */
2302
2303 nbuf = strdup (name);
2304 for (p = nbuf; *p; p++)
2305 *p = TOUPPER (*p);
2306 reg = hash_find (arm_reg_hsh, nbuf);
2307 if (reg)
2308 {
2309 hash_delete (arm_reg_hsh, nbuf);
2310 free ((char *) reg->name);
2311 if (reg->neon)
2312 free (reg->neon);
2313 free (reg);
2314 }
2315
2316 for (p = nbuf; *p; p++)
2317 *p = TOLOWER (*p);
2318 reg = hash_find (arm_reg_hsh, nbuf);
2319 if (reg)
2320 {
2321 hash_delete (arm_reg_hsh, nbuf);
2322 free ((char *) reg->name);
2323 if (reg->neon)
2324 free (reg->neon);
2325 free (reg);
2326 }
2327
2328 free (nbuf);
2329 }
2330 }
2331
2332 *input_line_pointer = saved_char;
2333 demand_empty_rest_of_line ();
2334 }
2335
2336 /* Directives: Instruction set selection. */
2337
2338 #ifdef OBJ_ELF
2339 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2340 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2341 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2342 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2343
2344 static enum mstate mapstate = MAP_UNDEFINED;
2345
2346 void
2347 mapping_state (enum mstate state)
2348 {
2349 symbolS * symbolP;
2350 const char * symname;
2351 int type;
2352
2353 if (mapstate == state)
2354 /* The mapping symbol has already been emitted.
2355 There is nothing else to do. */
2356 return;
2357
2358 mapstate = state;
2359
2360 switch (state)
2361 {
2362 case MAP_DATA:
2363 symname = "$d";
2364 type = BSF_NO_FLAGS;
2365 break;
2366 case MAP_ARM:
2367 symname = "$a";
2368 type = BSF_NO_FLAGS;
2369 break;
2370 case MAP_THUMB:
2371 symname = "$t";
2372 type = BSF_NO_FLAGS;
2373 break;
2374 case MAP_UNDEFINED:
2375 return;
2376 default:
2377 abort ();
2378 }
2379
2380 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2381
2382 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
2383 symbol_table_insert (symbolP);
2384 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2385
2386 switch (state)
2387 {
2388 case MAP_ARM:
2389 THUMB_SET_FUNC (symbolP, 0);
2390 ARM_SET_THUMB (symbolP, 0);
2391 ARM_SET_INTERWORK (symbolP, support_interwork);
2392 break;
2393
2394 case MAP_THUMB:
2395 THUMB_SET_FUNC (symbolP, 1);
2396 ARM_SET_THUMB (symbolP, 1);
2397 ARM_SET_INTERWORK (symbolP, support_interwork);
2398 break;
2399
2400 case MAP_DATA:
2401 default:
2402 return;
2403 }
2404 }
2405 #else
2406 #define mapping_state(x) /* nothing */
2407 #endif
2408
2409 /* Find the real, Thumb encoded start of a Thumb function. */
2410
2411 static symbolS *
2412 find_real_start (symbolS * symbolP)
2413 {
2414 char * real_start;
2415 const char * name = S_GET_NAME (symbolP);
2416 symbolS * new_target;
2417
2418 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2419 #define STUB_NAME ".real_start_of"
2420
2421 if (name == NULL)
2422 abort ();
2423
2424 /* The compiler may generate BL instructions to local labels because
2425 it needs to perform a branch to a far away location. These labels
2426 do not have a corresponding ".real_start_of" label. We check
2427 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2428 the ".real_start_of" convention for nonlocal branches. */
2429 if (S_IS_LOCAL (symbolP) || name[0] == '.')
2430 return symbolP;
2431
2432 real_start = ACONCAT ((STUB_NAME, name, NULL));
2433 new_target = symbol_find (real_start);
2434
2435 if (new_target == NULL)
2436 {
2437 as_warn (_("Failed to find real start of function: %s\n"), name);
2438 new_target = symbolP;
2439 }
2440
2441 return new_target;
2442 }
2443
2444 static void
2445 opcode_select (int width)
2446 {
2447 switch (width)
2448 {
2449 case 16:
2450 if (! thumb_mode)
2451 {
2452 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
2453 as_bad (_("selected processor does not support THUMB opcodes"));
2454
2455 thumb_mode = 1;
2456 /* No need to force the alignment, since we will have been
2457 coming from ARM mode, which is word-aligned. */
2458 record_alignment (now_seg, 1);
2459 }
2460 mapping_state (MAP_THUMB);
2461 break;
2462
2463 case 32:
2464 if (thumb_mode)
2465 {
2466 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
2467 as_bad (_("selected processor does not support ARM opcodes"));
2468
2469 thumb_mode = 0;
2470
2471 if (!need_pass_2)
2472 frag_align (2, 0, 0);
2473
2474 record_alignment (now_seg, 1);
2475 }
2476 mapping_state (MAP_ARM);
2477 break;
2478
2479 default:
2480 as_bad (_("invalid instruction size selected (%d)"), width);
2481 }
2482 }
2483
2484 static void
2485 s_arm (int ignore ATTRIBUTE_UNUSED)
2486 {
2487 opcode_select (32);
2488 demand_empty_rest_of_line ();
2489 }
2490
2491 static void
2492 s_thumb (int ignore ATTRIBUTE_UNUSED)
2493 {
2494 opcode_select (16);
2495 demand_empty_rest_of_line ();
2496 }
2497
2498 static void
2499 s_code (int unused ATTRIBUTE_UNUSED)
2500 {
2501 int temp;
2502
2503 temp = get_absolute_expression ();
2504 switch (temp)
2505 {
2506 case 16:
2507 case 32:
2508 opcode_select (temp);
2509 break;
2510
2511 default:
2512 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2513 }
2514 }
2515
2516 static void
2517 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2518 {
2519 /* If we are not already in thumb mode go into it, EVEN if
2520 the target processor does not support thumb instructions.
2521 This is used by gcc/config/arm/lib1funcs.asm for example
2522 to compile interworking support functions even if the
2523 target processor should not support interworking. */
2524 if (! thumb_mode)
2525 {
2526 thumb_mode = 2;
2527 record_alignment (now_seg, 1);
2528 }
2529
2530 demand_empty_rest_of_line ();
2531 }
2532
2533 static void
2534 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2535 {
2536 s_thumb (0);
2537
2538 /* The following label is the name/address of the start of a Thumb function.
2539 We need to know this for the interworking support. */
2540 label_is_thumb_function_name = TRUE;
2541 }
2542
2543 /* Perform a .set directive, but also mark the alias as
2544 being a thumb function. */
2545
2546 static void
2547 s_thumb_set (int equiv)
2548 {
2549 /* XXX the following is a duplicate of the code for s_set() in read.c
2550 We cannot just call that code as we need to get at the symbol that
2551 is created. */
2552 char * name;
2553 char delim;
2554 char * end_name;
2555 symbolS * symbolP;
2556
2557 /* Especial apologies for the random logic:
2558 This just grew, and could be parsed much more simply!
2559 Dean - in haste. */
2560 name = input_line_pointer;
2561 delim = get_symbol_end ();
2562 end_name = input_line_pointer;
2563 *end_name = delim;
2564
2565 if (*input_line_pointer != ',')
2566 {
2567 *end_name = 0;
2568 as_bad (_("expected comma after name \"%s\""), name);
2569 *end_name = delim;
2570 ignore_rest_of_line ();
2571 return;
2572 }
2573
2574 input_line_pointer++;
2575 *end_name = 0;
2576
2577 if (name[0] == '.' && name[1] == '\0')
2578 {
2579 /* XXX - this should not happen to .thumb_set. */
2580 abort ();
2581 }
2582
2583 if ((symbolP = symbol_find (name)) == NULL
2584 && (symbolP = md_undefined_symbol (name)) == NULL)
2585 {
2586 #ifndef NO_LISTING
2587 /* When doing symbol listings, play games with dummy fragments living
2588 outside the normal fragment chain to record the file and line info
2589 for this symbol. */
2590 if (listing & LISTING_SYMBOLS)
2591 {
2592 extern struct list_info_struct * listing_tail;
2593 fragS * dummy_frag = xmalloc (sizeof (fragS));
2594
2595 memset (dummy_frag, 0, sizeof (fragS));
2596 dummy_frag->fr_type = rs_fill;
2597 dummy_frag->line = listing_tail;
2598 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2599 dummy_frag->fr_symbol = symbolP;
2600 }
2601 else
2602 #endif
2603 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2604
2605 #ifdef OBJ_COFF
2606 /* "set" symbols are local unless otherwise specified. */
2607 SF_SET_LOCAL (symbolP);
2608 #endif /* OBJ_COFF */
2609 } /* Make a new symbol. */
2610
2611 symbol_table_insert (symbolP);
2612
2613 * end_name = delim;
2614
2615 if (equiv
2616 && S_IS_DEFINED (symbolP)
2617 && S_GET_SEGMENT (symbolP) != reg_section)
2618 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2619
2620 pseudo_set (symbolP);
2621
2622 demand_empty_rest_of_line ();
2623
2624 /* XXX Now we come to the Thumb specific bit of code. */
2625
2626 THUMB_SET_FUNC (symbolP, 1);
2627 ARM_SET_THUMB (symbolP, 1);
2628 #if defined OBJ_ELF || defined OBJ_COFF
2629 ARM_SET_INTERWORK (symbolP, support_interwork);
2630 #endif
2631 }
2632
2633 /* Directives: Mode selection. */
2634
2635 /* .syntax [unified|divided] - choose the new unified syntax
2636 (same for Arm and Thumb encoding, modulo slight differences in what
2637 can be represented) or the old divergent syntax for each mode. */
2638 static void
2639 s_syntax (int unused ATTRIBUTE_UNUSED)
2640 {
2641 char *name, delim;
2642
2643 name = input_line_pointer;
2644 delim = get_symbol_end ();
2645
2646 if (!strcasecmp (name, "unified"))
2647 unified_syntax = TRUE;
2648 else if (!strcasecmp (name, "divided"))
2649 unified_syntax = FALSE;
2650 else
2651 {
2652 as_bad (_("unrecognized syntax mode \"%s\""), name);
2653 return;
2654 }
2655 *input_line_pointer = delim;
2656 demand_empty_rest_of_line ();
2657 }
2658
2659 /* Directives: sectioning and alignment. */
2660
2661 /* Same as s_align_ptwo but align 0 => align 2. */
2662
2663 static void
2664 s_align (int unused ATTRIBUTE_UNUSED)
2665 {
2666 int temp;
2667 bfd_boolean fill_p;
2668 long temp_fill;
2669 long max_alignment = 15;
2670
2671 temp = get_absolute_expression ();
2672 if (temp > max_alignment)
2673 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2674 else if (temp < 0)
2675 {
2676 as_bad (_("alignment negative. 0 assumed."));
2677 temp = 0;
2678 }
2679
2680 if (*input_line_pointer == ',')
2681 {
2682 input_line_pointer++;
2683 temp_fill = get_absolute_expression ();
2684 fill_p = TRUE;
2685 }
2686 else
2687 {
2688 fill_p = FALSE;
2689 temp_fill = 0;
2690 }
2691
2692 if (!temp)
2693 temp = 2;
2694
2695 /* Only make a frag if we HAVE to. */
2696 if (temp && !need_pass_2)
2697 {
2698 if (!fill_p && subseg_text_p (now_seg))
2699 frag_align_code (temp, 0);
2700 else
2701 frag_align (temp, (int) temp_fill, 0);
2702 }
2703 demand_empty_rest_of_line ();
2704
2705 record_alignment (now_seg, temp);
2706 }
2707
2708 static void
2709 s_bss (int ignore ATTRIBUTE_UNUSED)
2710 {
2711 /* We don't support putting frags in the BSS segment, we fake it by
2712 marking in_bss, then looking at s_skip for clues. */
2713 subseg_set (bss_section, 0);
2714 demand_empty_rest_of_line ();
2715 mapping_state (MAP_DATA);
2716 }
2717
2718 static void
2719 s_even (int ignore ATTRIBUTE_UNUSED)
2720 {
2721 /* Never make frag if expect extra pass. */
2722 if (!need_pass_2)
2723 frag_align (1, 0, 0);
2724
2725 record_alignment (now_seg, 1);
2726
2727 demand_empty_rest_of_line ();
2728 }
2729
2730 /* Directives: Literal pools. */
2731
2732 static literal_pool *
2733 find_literal_pool (void)
2734 {
2735 literal_pool * pool;
2736
2737 for (pool = list_of_pools; pool != NULL; pool = pool->next)
2738 {
2739 if (pool->section == now_seg
2740 && pool->sub_section == now_subseg)
2741 break;
2742 }
2743
2744 return pool;
2745 }
2746
2747 static literal_pool *
2748 find_or_make_literal_pool (void)
2749 {
2750 /* Next literal pool ID number. */
2751 static unsigned int latest_pool_num = 1;
2752 literal_pool * pool;
2753
2754 pool = find_literal_pool ();
2755
2756 if (pool == NULL)
2757 {
2758 /* Create a new pool. */
2759 pool = xmalloc (sizeof (* pool));
2760 if (! pool)
2761 return NULL;
2762
2763 pool->next_free_entry = 0;
2764 pool->section = now_seg;
2765 pool->sub_section = now_subseg;
2766 pool->next = list_of_pools;
2767 pool->symbol = NULL;
2768
2769 /* Add it to the list. */
2770 list_of_pools = pool;
2771 }
2772
2773 /* New pools, and emptied pools, will have a NULL symbol. */
2774 if (pool->symbol == NULL)
2775 {
2776 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2777 (valueT) 0, &zero_address_frag);
2778 pool->id = latest_pool_num ++;
2779 }
2780
2781 /* Done. */
2782 return pool;
2783 }
2784
2785 /* Add the literal in the global 'inst'
2786 structure to the relevant literal pool. */
2787
2788 static int
2789 add_to_lit_pool (void)
2790 {
2791 literal_pool * pool;
2792 unsigned int entry;
2793
2794 pool = find_or_make_literal_pool ();
2795
2796 /* Check if this literal value is already in the pool. */
2797 for (entry = 0; entry < pool->next_free_entry; entry ++)
2798 {
2799 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2800 && (inst.reloc.exp.X_op == O_constant)
2801 && (pool->literals[entry].X_add_number
2802 == inst.reloc.exp.X_add_number)
2803 && (pool->literals[entry].X_unsigned
2804 == inst.reloc.exp.X_unsigned))
2805 break;
2806
2807 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2808 && (inst.reloc.exp.X_op == O_symbol)
2809 && (pool->literals[entry].X_add_number
2810 == inst.reloc.exp.X_add_number)
2811 && (pool->literals[entry].X_add_symbol
2812 == inst.reloc.exp.X_add_symbol)
2813 && (pool->literals[entry].X_op_symbol
2814 == inst.reloc.exp.X_op_symbol))
2815 break;
2816 }
2817
2818 /* Do we need to create a new entry? */
2819 if (entry == pool->next_free_entry)
2820 {
2821 if (entry >= MAX_LITERAL_POOL_SIZE)
2822 {
2823 inst.error = _("literal pool overflow");
2824 return FAIL;
2825 }
2826
2827 pool->literals[entry] = inst.reloc.exp;
2828 pool->next_free_entry += 1;
2829 }
2830
2831 inst.reloc.exp.X_op = O_symbol;
2832 inst.reloc.exp.X_add_number = ((int) entry) * 4;
2833 inst.reloc.exp.X_add_symbol = pool->symbol;
2834
2835 return SUCCESS;
2836 }
2837
2838 /* Can't use symbol_new here, so have to create a symbol and then at
2839 a later date assign it a value. Thats what these functions do. */
2840
2841 static void
2842 symbol_locate (symbolS * symbolP,
2843 const char * name, /* It is copied, the caller can modify. */
2844 segT segment, /* Segment identifier (SEG_<something>). */
2845 valueT valu, /* Symbol value. */
2846 fragS * frag) /* Associated fragment. */
2847 {
2848 unsigned int name_length;
2849 char * preserved_copy_of_name;
2850
2851 name_length = strlen (name) + 1; /* +1 for \0. */
2852 obstack_grow (&notes, name, name_length);
2853 preserved_copy_of_name = obstack_finish (&notes);
2854
2855 #ifdef tc_canonicalize_symbol_name
2856 preserved_copy_of_name =
2857 tc_canonicalize_symbol_name (preserved_copy_of_name);
2858 #endif
2859
2860 S_SET_NAME (symbolP, preserved_copy_of_name);
2861
2862 S_SET_SEGMENT (symbolP, segment);
2863 S_SET_VALUE (symbolP, valu);
2864 symbol_clear_list_pointers (symbolP);
2865
2866 symbol_set_frag (symbolP, frag);
2867
2868 /* Link to end of symbol chain. */
2869 {
2870 extern int symbol_table_frozen;
2871
2872 if (symbol_table_frozen)
2873 abort ();
2874 }
2875
2876 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
2877
2878 obj_symbol_new_hook (symbolP);
2879
2880 #ifdef tc_symbol_new_hook
2881 tc_symbol_new_hook (symbolP);
2882 #endif
2883
2884 #ifdef DEBUG_SYMS
2885 verify_symbol_chain (symbol_rootP, symbol_lastP);
2886 #endif /* DEBUG_SYMS */
2887 }
2888
2889
2890 static void
2891 s_ltorg (int ignored ATTRIBUTE_UNUSED)
2892 {
2893 unsigned int entry;
2894 literal_pool * pool;
2895 char sym_name[20];
2896
2897 pool = find_literal_pool ();
2898 if (pool == NULL
2899 || pool->symbol == NULL
2900 || pool->next_free_entry == 0)
2901 return;
2902
2903 mapping_state (MAP_DATA);
2904
2905 /* Align pool as you have word accesses.
2906 Only make a frag if we have to. */
2907 if (!need_pass_2)
2908 frag_align (2, 0, 0);
2909
2910 record_alignment (now_seg, 2);
2911
2912 sprintf (sym_name, "$$lit_\002%x", pool->id);
2913
2914 symbol_locate (pool->symbol, sym_name, now_seg,
2915 (valueT) frag_now_fix (), frag_now);
2916 symbol_table_insert (pool->symbol);
2917
2918 ARM_SET_THUMB (pool->symbol, thumb_mode);
2919
2920 #if defined OBJ_COFF || defined OBJ_ELF
2921 ARM_SET_INTERWORK (pool->symbol, support_interwork);
2922 #endif
2923
2924 for (entry = 0; entry < pool->next_free_entry; entry ++)
2925 /* First output the expression in the instruction to the pool. */
2926 emit_expr (&(pool->literals[entry]), 4); /* .word */
2927
2928 /* Mark the pool as empty. */
2929 pool->next_free_entry = 0;
2930 pool->symbol = NULL;
2931 }
2932
2933 #ifdef OBJ_ELF
2934 /* Forward declarations for functions below, in the MD interface
2935 section. */
2936 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
2937 static valueT create_unwind_entry (int);
2938 static void start_unwind_section (const segT, int);
2939 static void add_unwind_opcode (valueT, int);
2940 static void flush_pending_unwind (void);
2941
2942 /* Directives: Data. */
2943
2944 static void
2945 s_arm_elf_cons (int nbytes)
2946 {
2947 expressionS exp;
2948
2949 #ifdef md_flush_pending_output
2950 md_flush_pending_output ();
2951 #endif
2952
2953 if (is_it_end_of_statement ())
2954 {
2955 demand_empty_rest_of_line ();
2956 return;
2957 }
2958
2959 #ifdef md_cons_align
2960 md_cons_align (nbytes);
2961 #endif
2962
2963 mapping_state (MAP_DATA);
2964 do
2965 {
2966 int reloc;
2967 char *base = input_line_pointer;
2968
2969 expression (& exp);
2970
2971 if (exp.X_op != O_symbol)
2972 emit_expr (&exp, (unsigned int) nbytes);
2973 else
2974 {
2975 char *before_reloc = input_line_pointer;
2976 reloc = parse_reloc (&input_line_pointer);
2977 if (reloc == -1)
2978 {
2979 as_bad (_("unrecognized relocation suffix"));
2980 ignore_rest_of_line ();
2981 return;
2982 }
2983 else if (reloc == BFD_RELOC_UNUSED)
2984 emit_expr (&exp, (unsigned int) nbytes);
2985 else
2986 {
2987 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
2988 int size = bfd_get_reloc_size (howto);
2989
2990 if (reloc == BFD_RELOC_ARM_PLT32)
2991 {
2992 as_bad (_("(plt) is only valid on branch targets"));
2993 reloc = BFD_RELOC_UNUSED;
2994 size = 0;
2995 }
2996
2997 if (size > nbytes)
2998 as_bad (_("%s relocations do not fit in %d bytes"),
2999 howto->name, nbytes);
3000 else
3001 {
3002 /* We've parsed an expression stopping at O_symbol.
3003 But there may be more expression left now that we
3004 have parsed the relocation marker. Parse it again.
3005 XXX Surely there is a cleaner way to do this. */
3006 char *p = input_line_pointer;
3007 int offset;
3008 char *save_buf = alloca (input_line_pointer - base);
3009 memcpy (save_buf, base, input_line_pointer - base);
3010 memmove (base + (input_line_pointer - before_reloc),
3011 base, before_reloc - base);
3012
3013 input_line_pointer = base + (input_line_pointer-before_reloc);
3014 expression (&exp);
3015 memcpy (base, save_buf, p - base);
3016
3017 offset = nbytes - size;
3018 p = frag_more ((int) nbytes);
3019 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3020 size, &exp, 0, reloc);
3021 }
3022 }
3023 }
3024 }
3025 while (*input_line_pointer++ == ',');
3026
3027 /* Put terminator back into stream. */
3028 input_line_pointer --;
3029 demand_empty_rest_of_line ();
3030 }
3031
3032
3033 /* Parse a .rel31 directive. */
3034
3035 static void
3036 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3037 {
3038 expressionS exp;
3039 char *p;
3040 valueT highbit;
3041
3042 highbit = 0;
3043 if (*input_line_pointer == '1')
3044 highbit = 0x80000000;
3045 else if (*input_line_pointer != '0')
3046 as_bad (_("expected 0 or 1"));
3047
3048 input_line_pointer++;
3049 if (*input_line_pointer != ',')
3050 as_bad (_("missing comma"));
3051 input_line_pointer++;
3052
3053 #ifdef md_flush_pending_output
3054 md_flush_pending_output ();
3055 #endif
3056
3057 #ifdef md_cons_align
3058 md_cons_align (4);
3059 #endif
3060
3061 mapping_state (MAP_DATA);
3062
3063 expression (&exp);
3064
3065 p = frag_more (4);
3066 md_number_to_chars (p, highbit, 4);
3067 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3068 BFD_RELOC_ARM_PREL31);
3069
3070 demand_empty_rest_of_line ();
3071 }
3072
3073 /* Directives: AEABI stack-unwind tables. */
3074
3075 /* Parse an unwind_fnstart directive. Simply records the current location. */
3076
3077 static void
3078 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3079 {
3080 demand_empty_rest_of_line ();
3081 /* Mark the start of the function. */
3082 unwind.proc_start = expr_build_dot ();
3083
3084 /* Reset the rest of the unwind info. */
3085 unwind.opcode_count = 0;
3086 unwind.table_entry = NULL;
3087 unwind.personality_routine = NULL;
3088 unwind.personality_index = -1;
3089 unwind.frame_size = 0;
3090 unwind.fp_offset = 0;
3091 unwind.fp_reg = 13;
3092 unwind.fp_used = 0;
3093 unwind.sp_restored = 0;
3094 }
3095
3096
3097 /* Parse a handlerdata directive. Creates the exception handling table entry
3098 for the function. */
3099
3100 static void
3101 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3102 {
3103 demand_empty_rest_of_line ();
3104 if (unwind.table_entry)
3105 as_bad (_("duplicate .handlerdata directive"));
3106
3107 create_unwind_entry (1);
3108 }
3109
3110 /* Parse an unwind_fnend directive. Generates the index table entry. */
3111
3112 static void
3113 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3114 {
3115 long where;
3116 char *ptr;
3117 valueT val;
3118
3119 demand_empty_rest_of_line ();
3120
3121 /* Add eh table entry. */
3122 if (unwind.table_entry == NULL)
3123 val = create_unwind_entry (0);
3124 else
3125 val = 0;
3126
3127 /* Add index table entry. This is two words. */
3128 start_unwind_section (unwind.saved_seg, 1);
3129 frag_align (2, 0, 0);
3130 record_alignment (now_seg, 2);
3131
3132 ptr = frag_more (8);
3133 where = frag_now_fix () - 8;
3134
3135 /* Self relative offset of the function start. */
3136 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3137 BFD_RELOC_ARM_PREL31);
3138
3139 /* Indicate dependency on EHABI-defined personality routines to the
3140 linker, if it hasn't been done already. */
3141 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3142 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3143 {
3144 static const char *const name[] =
3145 {
3146 "__aeabi_unwind_cpp_pr0",
3147 "__aeabi_unwind_cpp_pr1",
3148 "__aeabi_unwind_cpp_pr2"
3149 };
3150 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3151 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3152 marked_pr_dependency |= 1 << unwind.personality_index;
3153 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3154 = marked_pr_dependency;
3155 }
3156
3157 if (val)
3158 /* Inline exception table entry. */
3159 md_number_to_chars (ptr + 4, val, 4);
3160 else
3161 /* Self relative offset of the table entry. */
3162 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3163 BFD_RELOC_ARM_PREL31);
3164
3165 /* Restore the original section. */
3166 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3167 }
3168
3169
3170 /* Parse an unwind_cantunwind directive. */
3171
3172 static void
3173 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3174 {
3175 demand_empty_rest_of_line ();
3176 if (unwind.personality_routine || unwind.personality_index != -1)
3177 as_bad (_("personality routine specified for cantunwind frame"));
3178
3179 unwind.personality_index = -2;
3180 }
3181
3182
3183 /* Parse a personalityindex directive. */
3184
3185 static void
3186 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3187 {
3188 expressionS exp;
3189
3190 if (unwind.personality_routine || unwind.personality_index != -1)
3191 as_bad (_("duplicate .personalityindex directive"));
3192
3193 expression (&exp);
3194
3195 if (exp.X_op != O_constant
3196 || exp.X_add_number < 0 || exp.X_add_number > 15)
3197 {
3198 as_bad (_("bad personality routine number"));
3199 ignore_rest_of_line ();
3200 return;
3201 }
3202
3203 unwind.personality_index = exp.X_add_number;
3204
3205 demand_empty_rest_of_line ();
3206 }
3207
3208
3209 /* Parse a personality directive. */
3210
3211 static void
3212 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3213 {
3214 char *name, *p, c;
3215
3216 if (unwind.personality_routine || unwind.personality_index != -1)
3217 as_bad (_("duplicate .personality directive"));
3218
3219 name = input_line_pointer;
3220 c = get_symbol_end ();
3221 p = input_line_pointer;
3222 unwind.personality_routine = symbol_find_or_make (name);
3223 *p = c;
3224 demand_empty_rest_of_line ();
3225 }
3226
3227
3228 /* Parse a directive saving core registers. */
3229
3230 static void
3231 s_arm_unwind_save_core (void)
3232 {
3233 valueT op;
3234 long range;
3235 int n;
3236
3237 range = parse_reg_list (&input_line_pointer);
3238 if (range == FAIL)
3239 {
3240 as_bad (_("expected register list"));
3241 ignore_rest_of_line ();
3242 return;
3243 }
3244
3245 demand_empty_rest_of_line ();
3246
3247 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3248 into .unwind_save {..., sp...}. We aren't bothered about the value of
3249 ip because it is clobbered by calls. */
3250 if (unwind.sp_restored && unwind.fp_reg == 12
3251 && (range & 0x3000) == 0x1000)
3252 {
3253 unwind.opcode_count--;
3254 unwind.sp_restored = 0;
3255 range = (range | 0x2000) & ~0x1000;
3256 unwind.pending_offset = 0;
3257 }
3258
3259 /* Pop r4-r15. */
3260 if (range & 0xfff0)
3261 {
3262 /* See if we can use the short opcodes. These pop a block of up to 8
3263 registers starting with r4, plus maybe r14. */
3264 for (n = 0; n < 8; n++)
3265 {
3266 /* Break at the first non-saved register. */
3267 if ((range & (1 << (n + 4))) == 0)
3268 break;
3269 }
3270 /* See if there are any other bits set. */
3271 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3272 {
3273 /* Use the long form. */
3274 op = 0x8000 | ((range >> 4) & 0xfff);
3275 add_unwind_opcode (op, 2);
3276 }
3277 else
3278 {
3279 /* Use the short form. */
3280 if (range & 0x4000)
3281 op = 0xa8; /* Pop r14. */
3282 else
3283 op = 0xa0; /* Do not pop r14. */
3284 op |= (n - 1);
3285 add_unwind_opcode (op, 1);
3286 }
3287 }
3288
3289 /* Pop r0-r3. */
3290 if (range & 0xf)
3291 {
3292 op = 0xb100 | (range & 0xf);
3293 add_unwind_opcode (op, 2);
3294 }
3295
3296 /* Record the number of bytes pushed. */
3297 for (n = 0; n < 16; n++)
3298 {
3299 if (range & (1 << n))
3300 unwind.frame_size += 4;
3301 }
3302 }
3303
3304
3305 /* Parse a directive saving FPA registers. */
3306
3307 static void
3308 s_arm_unwind_save_fpa (int reg)
3309 {
3310 expressionS exp;
3311 int num_regs;
3312 valueT op;
3313
3314 /* Get Number of registers to transfer. */
3315 if (skip_past_comma (&input_line_pointer) != FAIL)
3316 expression (&exp);
3317 else
3318 exp.X_op = O_illegal;
3319
3320 if (exp.X_op != O_constant)
3321 {
3322 as_bad (_("expected , <constant>"));
3323 ignore_rest_of_line ();
3324 return;
3325 }
3326
3327 num_regs = exp.X_add_number;
3328
3329 if (num_regs < 1 || num_regs > 4)
3330 {
3331 as_bad (_("number of registers must be in the range [1:4]"));
3332 ignore_rest_of_line ();
3333 return;
3334 }
3335
3336 demand_empty_rest_of_line ();
3337
3338 if (reg == 4)
3339 {
3340 /* Short form. */
3341 op = 0xb4 | (num_regs - 1);
3342 add_unwind_opcode (op, 1);
3343 }
3344 else
3345 {
3346 /* Long form. */
3347 op = 0xc800 | (reg << 4) | (num_regs - 1);
3348 add_unwind_opcode (op, 2);
3349 }
3350 unwind.frame_size += num_regs * 12;
3351 }
3352
3353
3354 /* Parse a directive saving VFP registers for ARMv6 and above. */
3355
3356 static void
3357 s_arm_unwind_save_vfp_armv6 (void)
3358 {
3359 int count;
3360 unsigned int start;
3361 valueT op;
3362 int num_vfpv3_regs = 0;
3363 int num_regs_below_16;
3364
3365 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3366 if (count == FAIL)
3367 {
3368 as_bad (_("expected register list"));
3369 ignore_rest_of_line ();
3370 return;
3371 }
3372
3373 demand_empty_rest_of_line ();
3374
3375 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3376 than FSTMX/FLDMX-style ones). */
3377
3378 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3379 if (start >= 16)
3380 num_vfpv3_regs = count;
3381 else if (start + count > 16)
3382 num_vfpv3_regs = start + count - 16;
3383
3384 if (num_vfpv3_regs > 0)
3385 {
3386 int start_offset = start > 16 ? start - 16 : 0;
3387 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3388 add_unwind_opcode (op, 2);
3389 }
3390
3391 /* Generate opcode for registers numbered in the range 0 .. 15. */
3392 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3393 assert (num_regs_below_16 + num_vfpv3_regs == count);
3394 if (num_regs_below_16 > 0)
3395 {
3396 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3397 add_unwind_opcode (op, 2);
3398 }
3399
3400 unwind.frame_size += count * 8;
3401 }
3402
3403
3404 /* Parse a directive saving VFP registers for pre-ARMv6. */
3405
3406 static void
3407 s_arm_unwind_save_vfp (void)
3408 {
3409 int count;
3410 unsigned int reg;
3411 valueT op;
3412
3413 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
3414 if (count == FAIL)
3415 {
3416 as_bad (_("expected register list"));
3417 ignore_rest_of_line ();
3418 return;
3419 }
3420
3421 demand_empty_rest_of_line ();
3422
3423 if (reg == 8)
3424 {
3425 /* Short form. */
3426 op = 0xb8 | (count - 1);
3427 add_unwind_opcode (op, 1);
3428 }
3429 else
3430 {
3431 /* Long form. */
3432 op = 0xb300 | (reg << 4) | (count - 1);
3433 add_unwind_opcode (op, 2);
3434 }
3435 unwind.frame_size += count * 8 + 4;
3436 }
3437
3438
3439 /* Parse a directive saving iWMMXt data registers. */
3440
3441 static void
3442 s_arm_unwind_save_mmxwr (void)
3443 {
3444 int reg;
3445 int hi_reg;
3446 int i;
3447 unsigned mask = 0;
3448 valueT op;
3449
3450 if (*input_line_pointer == '{')
3451 input_line_pointer++;
3452
3453 do
3454 {
3455 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3456
3457 if (reg == FAIL)
3458 {
3459 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3460 goto error;
3461 }
3462
3463 if (mask >> reg)
3464 as_tsktsk (_("register list not in ascending order"));
3465 mask |= 1 << reg;
3466
3467 if (*input_line_pointer == '-')
3468 {
3469 input_line_pointer++;
3470 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3471 if (hi_reg == FAIL)
3472 {
3473 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3474 goto error;
3475 }
3476 else if (reg >= hi_reg)
3477 {
3478 as_bad (_("bad register range"));
3479 goto error;
3480 }
3481 for (; reg < hi_reg; reg++)
3482 mask |= 1 << reg;
3483 }
3484 }
3485 while (skip_past_comma (&input_line_pointer) != FAIL);
3486
3487 if (*input_line_pointer == '}')
3488 input_line_pointer++;
3489
3490 demand_empty_rest_of_line ();
3491
3492 /* Generate any deferred opcodes because we're going to be looking at
3493 the list. */
3494 flush_pending_unwind ();
3495
3496 for (i = 0; i < 16; i++)
3497 {
3498 if (mask & (1 << i))
3499 unwind.frame_size += 8;
3500 }
3501
3502 /* Attempt to combine with a previous opcode. We do this because gcc
3503 likes to output separate unwind directives for a single block of
3504 registers. */
3505 if (unwind.opcode_count > 0)
3506 {
3507 i = unwind.opcodes[unwind.opcode_count - 1];
3508 if ((i & 0xf8) == 0xc0)
3509 {
3510 i &= 7;
3511 /* Only merge if the blocks are contiguous. */
3512 if (i < 6)
3513 {
3514 if ((mask & 0xfe00) == (1 << 9))
3515 {
3516 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3517 unwind.opcode_count--;
3518 }
3519 }
3520 else if (i == 6 && unwind.opcode_count >= 2)
3521 {
3522 i = unwind.opcodes[unwind.opcode_count - 2];
3523 reg = i >> 4;
3524 i &= 0xf;
3525
3526 op = 0xffff << (reg - 1);
3527 if (reg > 0
3528 && ((mask & op) == (1u << (reg - 1))))
3529 {
3530 op = (1 << (reg + i + 1)) - 1;
3531 op &= ~((1 << reg) - 1);
3532 mask |= op;
3533 unwind.opcode_count -= 2;
3534 }
3535 }
3536 }
3537 }
3538
3539 hi_reg = 15;
3540 /* We want to generate opcodes in the order the registers have been
3541 saved, ie. descending order. */
3542 for (reg = 15; reg >= -1; reg--)
3543 {
3544 /* Save registers in blocks. */
3545 if (reg < 0
3546 || !(mask & (1 << reg)))
3547 {
3548 /* We found an unsaved reg. Generate opcodes to save the
3549 preceding block. */
3550 if (reg != hi_reg)
3551 {
3552 if (reg == 9)
3553 {
3554 /* Short form. */
3555 op = 0xc0 | (hi_reg - 10);
3556 add_unwind_opcode (op, 1);
3557 }
3558 else
3559 {
3560 /* Long form. */
3561 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3562 add_unwind_opcode (op, 2);
3563 }
3564 }
3565 hi_reg = reg - 1;
3566 }
3567 }
3568
3569 return;
3570 error:
3571 ignore_rest_of_line ();
3572 }
3573
3574 static void
3575 s_arm_unwind_save_mmxwcg (void)
3576 {
3577 int reg;
3578 int hi_reg;
3579 unsigned mask = 0;
3580 valueT op;
3581
3582 if (*input_line_pointer == '{')
3583 input_line_pointer++;
3584
3585 do
3586 {
3587 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3588
3589 if (reg == FAIL)
3590 {
3591 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3592 goto error;
3593 }
3594
3595 reg -= 8;
3596 if (mask >> reg)
3597 as_tsktsk (_("register list not in ascending order"));
3598 mask |= 1 << reg;
3599
3600 if (*input_line_pointer == '-')
3601 {
3602 input_line_pointer++;
3603 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3604 if (hi_reg == FAIL)
3605 {
3606 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3607 goto error;
3608 }
3609 else if (reg >= hi_reg)
3610 {
3611 as_bad (_("bad register range"));
3612 goto error;
3613 }
3614 for (; reg < hi_reg; reg++)
3615 mask |= 1 << reg;
3616 }
3617 }
3618 while (skip_past_comma (&input_line_pointer) != FAIL);
3619
3620 if (*input_line_pointer == '}')
3621 input_line_pointer++;
3622
3623 demand_empty_rest_of_line ();
3624
3625 /* Generate any deferred opcodes because we're going to be looking at
3626 the list. */
3627 flush_pending_unwind ();
3628
3629 for (reg = 0; reg < 16; reg++)
3630 {
3631 if (mask & (1 << reg))
3632 unwind.frame_size += 4;
3633 }
3634 op = 0xc700 | mask;
3635 add_unwind_opcode (op, 2);
3636 return;
3637 error:
3638 ignore_rest_of_line ();
3639 }
3640
3641
3642 /* Parse an unwind_save directive.
3643 If the argument is non-zero, this is a .vsave directive. */
3644
3645 static void
3646 s_arm_unwind_save (int arch_v6)
3647 {
3648 char *peek;
3649 struct reg_entry *reg;
3650 bfd_boolean had_brace = FALSE;
3651
3652 /* Figure out what sort of save we have. */
3653 peek = input_line_pointer;
3654
3655 if (*peek == '{')
3656 {
3657 had_brace = TRUE;
3658 peek++;
3659 }
3660
3661 reg = arm_reg_parse_multi (&peek);
3662
3663 if (!reg)
3664 {
3665 as_bad (_("register expected"));
3666 ignore_rest_of_line ();
3667 return;
3668 }
3669
3670 switch (reg->type)
3671 {
3672 case REG_TYPE_FN:
3673 if (had_brace)
3674 {
3675 as_bad (_("FPA .unwind_save does not take a register list"));
3676 ignore_rest_of_line ();
3677 return;
3678 }
3679 input_line_pointer = peek;
3680 s_arm_unwind_save_fpa (reg->number);
3681 return;
3682
3683 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
3684 case REG_TYPE_VFD:
3685 if (arch_v6)
3686 s_arm_unwind_save_vfp_armv6 ();
3687 else
3688 s_arm_unwind_save_vfp ();
3689 return;
3690 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
3691 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
3692
3693 default:
3694 as_bad (_(".unwind_save does not support this kind of register"));
3695 ignore_rest_of_line ();
3696 }
3697 }
3698
3699
3700 /* Parse an unwind_movsp directive. */
3701
3702 static void
3703 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
3704 {
3705 int reg;
3706 valueT op;
3707 int offset;
3708
3709 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3710 if (reg == FAIL)
3711 {
3712 as_bad (_(reg_expected_msgs[REG_TYPE_RN]));
3713 ignore_rest_of_line ();
3714 return;
3715 }
3716
3717 /* Optional constant. */
3718 if (skip_past_comma (&input_line_pointer) != FAIL)
3719 {
3720 if (immediate_for_directive (&offset) == FAIL)
3721 return;
3722 }
3723 else
3724 offset = 0;
3725
3726 demand_empty_rest_of_line ();
3727
3728 if (reg == REG_SP || reg == REG_PC)
3729 {
3730 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
3731 return;
3732 }
3733
3734 if (unwind.fp_reg != REG_SP)
3735 as_bad (_("unexpected .unwind_movsp directive"));
3736
3737 /* Generate opcode to restore the value. */
3738 op = 0x90 | reg;
3739 add_unwind_opcode (op, 1);
3740
3741 /* Record the information for later. */
3742 unwind.fp_reg = reg;
3743 unwind.fp_offset = unwind.frame_size - offset;
3744 unwind.sp_restored = 1;
3745 }
3746
3747 /* Parse an unwind_pad directive. */
3748
3749 static void
3750 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
3751 {
3752 int offset;
3753
3754 if (immediate_for_directive (&offset) == FAIL)
3755 return;
3756
3757 if (offset & 3)
3758 {
3759 as_bad (_("stack increment must be multiple of 4"));
3760 ignore_rest_of_line ();
3761 return;
3762 }
3763
3764 /* Don't generate any opcodes, just record the details for later. */
3765 unwind.frame_size += offset;
3766 unwind.pending_offset += offset;
3767
3768 demand_empty_rest_of_line ();
3769 }
3770
3771 /* Parse an unwind_setfp directive. */
3772
3773 static void
3774 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
3775 {
3776 int sp_reg;
3777 int fp_reg;
3778 int offset;
3779
3780 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3781 if (skip_past_comma (&input_line_pointer) == FAIL)
3782 sp_reg = FAIL;
3783 else
3784 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3785
3786 if (fp_reg == FAIL || sp_reg == FAIL)
3787 {
3788 as_bad (_("expected <reg>, <reg>"));
3789 ignore_rest_of_line ();
3790 return;
3791 }
3792
3793 /* Optional constant. */
3794 if (skip_past_comma (&input_line_pointer) != FAIL)
3795 {
3796 if (immediate_for_directive (&offset) == FAIL)
3797 return;
3798 }
3799 else
3800 offset = 0;
3801
3802 demand_empty_rest_of_line ();
3803
3804 if (sp_reg != 13 && sp_reg != unwind.fp_reg)
3805 {
3806 as_bad (_("register must be either sp or set by a previous"
3807 "unwind_movsp directive"));
3808 return;
3809 }
3810
3811 /* Don't generate any opcodes, just record the information for later. */
3812 unwind.fp_reg = fp_reg;
3813 unwind.fp_used = 1;
3814 if (sp_reg == 13)
3815 unwind.fp_offset = unwind.frame_size - offset;
3816 else
3817 unwind.fp_offset -= offset;
3818 }
3819
3820 /* Parse an unwind_raw directive. */
3821
3822 static void
3823 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
3824 {
3825 expressionS exp;
3826 /* This is an arbitrary limit. */
3827 unsigned char op[16];
3828 int count;
3829
3830 expression (&exp);
3831 if (exp.X_op == O_constant
3832 && skip_past_comma (&input_line_pointer) != FAIL)
3833 {
3834 unwind.frame_size += exp.X_add_number;
3835 expression (&exp);
3836 }
3837 else
3838 exp.X_op = O_illegal;
3839
3840 if (exp.X_op != O_constant)
3841 {
3842 as_bad (_("expected <offset>, <opcode>"));
3843 ignore_rest_of_line ();
3844 return;
3845 }
3846
3847 count = 0;
3848
3849 /* Parse the opcode. */
3850 for (;;)
3851 {
3852 if (count >= 16)
3853 {
3854 as_bad (_("unwind opcode too long"));
3855 ignore_rest_of_line ();
3856 }
3857 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
3858 {
3859 as_bad (_("invalid unwind opcode"));
3860 ignore_rest_of_line ();
3861 return;
3862 }
3863 op[count++] = exp.X_add_number;
3864
3865 /* Parse the next byte. */
3866 if (skip_past_comma (&input_line_pointer) == FAIL)
3867 break;
3868
3869 expression (&exp);
3870 }
3871
3872 /* Add the opcode bytes in reverse order. */
3873 while (count--)
3874 add_unwind_opcode (op[count], 1);
3875
3876 demand_empty_rest_of_line ();
3877 }
3878
3879
3880 /* Parse a .eabi_attribute directive. */
3881
3882 static void
3883 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
3884 {
3885 s_vendor_attribute (OBJ_ATTR_PROC);
3886 }
3887 #endif /* OBJ_ELF */
3888
3889 static void s_arm_arch (int);
3890 static void s_arm_object_arch (int);
3891 static void s_arm_cpu (int);
3892 static void s_arm_fpu (int);
3893
3894 #ifdef TE_PE
3895
3896 static void
3897 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
3898 {
3899 expressionS exp;
3900
3901 do
3902 {
3903 expression (&exp);
3904 if (exp.X_op == O_symbol)
3905 exp.X_op = O_secrel;
3906
3907 emit_expr (&exp, 4);
3908 }
3909 while (*input_line_pointer++ == ',');
3910
3911 input_line_pointer--;
3912 demand_empty_rest_of_line ();
3913 }
3914 #endif /* TE_PE */
3915
3916 /* This table describes all the machine specific pseudo-ops the assembler
3917 has to support. The fields are:
3918 pseudo-op name without dot
3919 function to call to execute this pseudo-op
3920 Integer arg to pass to the function. */
3921
3922 const pseudo_typeS md_pseudo_table[] =
3923 {
3924 /* Never called because '.req' does not start a line. */
3925 { "req", s_req, 0 },
3926 /* Following two are likewise never called. */
3927 { "dn", s_dn, 0 },
3928 { "qn", s_qn, 0 },
3929 { "unreq", s_unreq, 0 },
3930 { "bss", s_bss, 0 },
3931 { "align", s_align, 0 },
3932 { "arm", s_arm, 0 },
3933 { "thumb", s_thumb, 0 },
3934 { "code", s_code, 0 },
3935 { "force_thumb", s_force_thumb, 0 },
3936 { "thumb_func", s_thumb_func, 0 },
3937 { "thumb_set", s_thumb_set, 0 },
3938 { "even", s_even, 0 },
3939 { "ltorg", s_ltorg, 0 },
3940 { "pool", s_ltorg, 0 },
3941 { "syntax", s_syntax, 0 },
3942 { "cpu", s_arm_cpu, 0 },
3943 { "arch", s_arm_arch, 0 },
3944 { "object_arch", s_arm_object_arch, 0 },
3945 { "fpu", s_arm_fpu, 0 },
3946 #ifdef OBJ_ELF
3947 { "word", s_arm_elf_cons, 4 },
3948 { "long", s_arm_elf_cons, 4 },
3949 { "rel31", s_arm_rel31, 0 },
3950 { "fnstart", s_arm_unwind_fnstart, 0 },
3951 { "fnend", s_arm_unwind_fnend, 0 },
3952 { "cantunwind", s_arm_unwind_cantunwind, 0 },
3953 { "personality", s_arm_unwind_personality, 0 },
3954 { "personalityindex", s_arm_unwind_personalityindex, 0 },
3955 { "handlerdata", s_arm_unwind_handlerdata, 0 },
3956 { "save", s_arm_unwind_save, 0 },
3957 { "vsave", s_arm_unwind_save, 1 },
3958 { "movsp", s_arm_unwind_movsp, 0 },
3959 { "pad", s_arm_unwind_pad, 0 },
3960 { "setfp", s_arm_unwind_setfp, 0 },
3961 { "unwind_raw", s_arm_unwind_raw, 0 },
3962 { "eabi_attribute", s_arm_eabi_attribute, 0 },
3963 #else
3964 { "word", cons, 4},
3965
3966 /* These are used for dwarf. */
3967 {"2byte", cons, 2},
3968 {"4byte", cons, 4},
3969 {"8byte", cons, 8},
3970 /* These are used for dwarf2. */
3971 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
3972 { "loc", dwarf2_directive_loc, 0 },
3973 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
3974 #endif
3975 { "extend", float_cons, 'x' },
3976 { "ldouble", float_cons, 'x' },
3977 { "packed", float_cons, 'p' },
3978 #ifdef TE_PE
3979 {"secrel32", pe_directive_secrel, 0},
3980 #endif
3981 { 0, 0, 0 }
3982 };
3983 \f
3984 /* Parser functions used exclusively in instruction operands. */
3985
3986 /* Generic immediate-value read function for use in insn parsing.
3987 STR points to the beginning of the immediate (the leading #);
3988 VAL receives the value; if the value is outside [MIN, MAX]
3989 issue an error. PREFIX_OPT is true if the immediate prefix is
3990 optional. */
3991
3992 static int
3993 parse_immediate (char **str, int *val, int min, int max,
3994 bfd_boolean prefix_opt)
3995 {
3996 expressionS exp;
3997 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
3998 if (exp.X_op != O_constant)
3999 {
4000 inst.error = _("constant expression required");
4001 return FAIL;
4002 }
4003
4004 if (exp.X_add_number < min || exp.X_add_number > max)
4005 {
4006 inst.error = _("immediate value out of range");
4007 return FAIL;
4008 }
4009
4010 *val = exp.X_add_number;
4011 return SUCCESS;
4012 }
4013
4014 /* Less-generic immediate-value read function with the possibility of loading a
4015 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
4016 instructions. Puts the result directly in inst.operands[i]. */
4017
4018 static int
4019 parse_big_immediate (char **str, int i)
4020 {
4021 expressionS exp;
4022 char *ptr = *str;
4023
4024 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4025
4026 if (exp.X_op == O_constant)
4027 {
4028 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4029 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4030 O_constant. We have to be careful not to break compilation for
4031 32-bit X_add_number, though. */
4032 if ((exp.X_add_number & ~0xffffffffl) != 0)
4033 {
4034 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4035 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4036 inst.operands[i].regisimm = 1;
4037 }
4038 }
4039 else if (exp.X_op == O_big
4040 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4041 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4042 {
4043 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4044 /* Bignums have their least significant bits in
4045 generic_bignum[0]. Make sure we put 32 bits in imm and
4046 32 bits in reg, in a (hopefully) portable way. */
4047 assert (parts != 0);
4048 inst.operands[i].imm = 0;
4049 for (j = 0; j < parts; j++, idx++)
4050 inst.operands[i].imm |= generic_bignum[idx]
4051 << (LITTLENUM_NUMBER_OF_BITS * j);
4052 inst.operands[i].reg = 0;
4053 for (j = 0; j < parts; j++, idx++)
4054 inst.operands[i].reg |= generic_bignum[idx]
4055 << (LITTLENUM_NUMBER_OF_BITS * j);
4056 inst.operands[i].regisimm = 1;
4057 }
4058 else
4059 return FAIL;
4060
4061 *str = ptr;
4062
4063 return SUCCESS;
4064 }
4065
4066 /* Returns the pseudo-register number of an FPA immediate constant,
4067 or FAIL if there isn't a valid constant here. */
4068
4069 static int
4070 parse_fpa_immediate (char ** str)
4071 {
4072 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4073 char * save_in;
4074 expressionS exp;
4075 int i;
4076 int j;
4077
4078 /* First try and match exact strings, this is to guarantee
4079 that some formats will work even for cross assembly. */
4080
4081 for (i = 0; fp_const[i]; i++)
4082 {
4083 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4084 {
4085 char *start = *str;
4086
4087 *str += strlen (fp_const[i]);
4088 if (is_end_of_line[(unsigned char) **str])
4089 return i + 8;
4090 *str = start;
4091 }
4092 }
4093
4094 /* Just because we didn't get a match doesn't mean that the constant
4095 isn't valid, just that it is in a format that we don't
4096 automatically recognize. Try parsing it with the standard
4097 expression routines. */
4098
4099 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
4100
4101 /* Look for a raw floating point number. */
4102 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4103 && is_end_of_line[(unsigned char) *save_in])
4104 {
4105 for (i = 0; i < NUM_FLOAT_VALS; i++)
4106 {
4107 for (j = 0; j < MAX_LITTLENUMS; j++)
4108 {
4109 if (words[j] != fp_values[i][j])
4110 break;
4111 }
4112
4113 if (j == MAX_LITTLENUMS)
4114 {
4115 *str = save_in;
4116 return i + 8;
4117 }
4118 }
4119 }
4120
4121 /* Try and parse a more complex expression, this will probably fail
4122 unless the code uses a floating point prefix (eg "0f"). */
4123 save_in = input_line_pointer;
4124 input_line_pointer = *str;
4125 if (expression (&exp) == absolute_section
4126 && exp.X_op == O_big
4127 && exp.X_add_number < 0)
4128 {
4129 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4130 Ditto for 15. */
4131 if (gen_to_words (words, 5, (long) 15) == 0)
4132 {
4133 for (i = 0; i < NUM_FLOAT_VALS; i++)
4134 {
4135 for (j = 0; j < MAX_LITTLENUMS; j++)
4136 {
4137 if (words[j] != fp_values[i][j])
4138 break;
4139 }
4140
4141 if (j == MAX_LITTLENUMS)
4142 {
4143 *str = input_line_pointer;
4144 input_line_pointer = save_in;
4145 return i + 8;
4146 }
4147 }
4148 }
4149 }
4150
4151 *str = input_line_pointer;
4152 input_line_pointer = save_in;
4153 inst.error = _("invalid FPA immediate expression");
4154 return FAIL;
4155 }
4156
4157 /* Returns 1 if a number has "quarter-precision" float format
4158 0baBbbbbbc defgh000 00000000 00000000. */
4159
4160 static int
4161 is_quarter_float (unsigned imm)
4162 {
4163 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4164 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4165 }
4166
4167 /* Parse an 8-bit "quarter-precision" floating point number of the form:
4168 0baBbbbbbc defgh000 00000000 00000000.
4169 The zero and minus-zero cases need special handling, since they can't be
4170 encoded in the "quarter-precision" float format, but can nonetheless be
4171 loaded as integer constants. */
4172
4173 static unsigned
4174 parse_qfloat_immediate (char **ccp, int *immed)
4175 {
4176 char *str = *ccp;
4177 char *fpnum;
4178 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4179 int found_fpchar = 0;
4180
4181 skip_past_char (&str, '#');
4182
4183 /* We must not accidentally parse an integer as a floating-point number. Make
4184 sure that the value we parse is not an integer by checking for special
4185 characters '.' or 'e'.
4186 FIXME: This is a horrible hack, but doing better is tricky because type
4187 information isn't in a very usable state at parse time. */
4188 fpnum = str;
4189 skip_whitespace (fpnum);
4190
4191 if (strncmp (fpnum, "0x", 2) == 0)
4192 return FAIL;
4193 else
4194 {
4195 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4196 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4197 {
4198 found_fpchar = 1;
4199 break;
4200 }
4201
4202 if (!found_fpchar)
4203 return FAIL;
4204 }
4205
4206 if ((str = atof_ieee (str, 's', words)) != NULL)
4207 {
4208 unsigned fpword = 0;
4209 int i;
4210
4211 /* Our FP word must be 32 bits (single-precision FP). */
4212 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4213 {
4214 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4215 fpword |= words[i];
4216 }
4217
4218 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
4219 *immed = fpword;
4220 else
4221 return FAIL;
4222
4223 *ccp = str;
4224
4225 return SUCCESS;
4226 }
4227
4228 return FAIL;
4229 }
4230
4231 /* Shift operands. */
4232 enum shift_kind
4233 {
4234 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4235 };
4236
4237 struct asm_shift_name
4238 {
4239 const char *name;
4240 enum shift_kind kind;
4241 };
4242
4243 /* Third argument to parse_shift. */
4244 enum parse_shift_mode
4245 {
4246 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4247 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4248 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4249 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4250 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4251 };
4252
4253 /* Parse a <shift> specifier on an ARM data processing instruction.
4254 This has three forms:
4255
4256 (LSL|LSR|ASL|ASR|ROR) Rs
4257 (LSL|LSR|ASL|ASR|ROR) #imm
4258 RRX
4259
4260 Note that ASL is assimilated to LSL in the instruction encoding, and
4261 RRX to ROR #0 (which cannot be written as such). */
4262
4263 static int
4264 parse_shift (char **str, int i, enum parse_shift_mode mode)
4265 {
4266 const struct asm_shift_name *shift_name;
4267 enum shift_kind shift;
4268 char *s = *str;
4269 char *p = s;
4270 int reg;
4271
4272 for (p = *str; ISALPHA (*p); p++)
4273 ;
4274
4275 if (p == *str)
4276 {
4277 inst.error = _("shift expression expected");
4278 return FAIL;
4279 }
4280
4281 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
4282
4283 if (shift_name == NULL)
4284 {
4285 inst.error = _("shift expression expected");
4286 return FAIL;
4287 }
4288
4289 shift = shift_name->kind;
4290
4291 switch (mode)
4292 {
4293 case NO_SHIFT_RESTRICT:
4294 case SHIFT_IMMEDIATE: break;
4295
4296 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4297 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4298 {
4299 inst.error = _("'LSL' or 'ASR' required");
4300 return FAIL;
4301 }
4302 break;
4303
4304 case SHIFT_LSL_IMMEDIATE:
4305 if (shift != SHIFT_LSL)
4306 {
4307 inst.error = _("'LSL' required");
4308 return FAIL;
4309 }
4310 break;
4311
4312 case SHIFT_ASR_IMMEDIATE:
4313 if (shift != SHIFT_ASR)
4314 {
4315 inst.error = _("'ASR' required");
4316 return FAIL;
4317 }
4318 break;
4319
4320 default: abort ();
4321 }
4322
4323 if (shift != SHIFT_RRX)
4324 {
4325 /* Whitespace can appear here if the next thing is a bare digit. */
4326 skip_whitespace (p);
4327
4328 if (mode == NO_SHIFT_RESTRICT
4329 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4330 {
4331 inst.operands[i].imm = reg;
4332 inst.operands[i].immisreg = 1;
4333 }
4334 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4335 return FAIL;
4336 }
4337 inst.operands[i].shift_kind = shift;
4338 inst.operands[i].shifted = 1;
4339 *str = p;
4340 return SUCCESS;
4341 }
4342
4343 /* Parse a <shifter_operand> for an ARM data processing instruction:
4344
4345 #<immediate>
4346 #<immediate>, <rotate>
4347 <Rm>
4348 <Rm>, <shift>
4349
4350 where <shift> is defined by parse_shift above, and <rotate> is a
4351 multiple of 2 between 0 and 30. Validation of immediate operands
4352 is deferred to md_apply_fix. */
4353
4354 static int
4355 parse_shifter_operand (char **str, int i)
4356 {
4357 int value;
4358 expressionS expr;
4359
4360 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
4361 {
4362 inst.operands[i].reg = value;
4363 inst.operands[i].isreg = 1;
4364
4365 /* parse_shift will override this if appropriate */
4366 inst.reloc.exp.X_op = O_constant;
4367 inst.reloc.exp.X_add_number = 0;
4368
4369 if (skip_past_comma (str) == FAIL)
4370 return SUCCESS;
4371
4372 /* Shift operation on register. */
4373 return parse_shift (str, i, NO_SHIFT_RESTRICT);
4374 }
4375
4376 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4377 return FAIL;
4378
4379 if (skip_past_comma (str) == SUCCESS)
4380 {
4381 /* #x, y -- ie explicit rotation by Y. */
4382 if (my_get_expression (&expr, str, GE_NO_PREFIX))
4383 return FAIL;
4384
4385 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4386 {
4387 inst.error = _("constant expression expected");
4388 return FAIL;
4389 }
4390
4391 value = expr.X_add_number;
4392 if (value < 0 || value > 30 || value % 2 != 0)
4393 {
4394 inst.error = _("invalid rotation");
4395 return FAIL;
4396 }
4397 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4398 {
4399 inst.error = _("invalid constant");
4400 return FAIL;
4401 }
4402
4403 /* Convert to decoded value. md_apply_fix will put it back. */
4404 inst.reloc.exp.X_add_number
4405 = (((inst.reloc.exp.X_add_number << (32 - value))
4406 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
4407 }
4408
4409 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4410 inst.reloc.pc_rel = 0;
4411 return SUCCESS;
4412 }
4413
4414 /* Group relocation information. Each entry in the table contains the
4415 textual name of the relocation as may appear in assembler source
4416 and must end with a colon.
4417 Along with this textual name are the relocation codes to be used if
4418 the corresponding instruction is an ALU instruction (ADD or SUB only),
4419 an LDR, an LDRS, or an LDC. */
4420
4421 struct group_reloc_table_entry
4422 {
4423 const char *name;
4424 int alu_code;
4425 int ldr_code;
4426 int ldrs_code;
4427 int ldc_code;
4428 };
4429
4430 typedef enum
4431 {
4432 /* Varieties of non-ALU group relocation. */
4433
4434 GROUP_LDR,
4435 GROUP_LDRS,
4436 GROUP_LDC
4437 } group_reloc_type;
4438
4439 static struct group_reloc_table_entry group_reloc_table[] =
4440 { /* Program counter relative: */
4441 { "pc_g0_nc",
4442 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4443 0, /* LDR */
4444 0, /* LDRS */
4445 0 }, /* LDC */
4446 { "pc_g0",
4447 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4448 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4449 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4450 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4451 { "pc_g1_nc",
4452 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4453 0, /* LDR */
4454 0, /* LDRS */
4455 0 }, /* LDC */
4456 { "pc_g1",
4457 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4458 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4459 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4460 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4461 { "pc_g2",
4462 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4463 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4464 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4465 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4466 /* Section base relative */
4467 { "sb_g0_nc",
4468 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4469 0, /* LDR */
4470 0, /* LDRS */
4471 0 }, /* LDC */
4472 { "sb_g0",
4473 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4474 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4475 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4476 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4477 { "sb_g1_nc",
4478 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4479 0, /* LDR */
4480 0, /* LDRS */
4481 0 }, /* LDC */
4482 { "sb_g1",
4483 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4484 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4485 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4486 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4487 { "sb_g2",
4488 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4489 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4490 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4491 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4492
4493 /* Given the address of a pointer pointing to the textual name of a group
4494 relocation as may appear in assembler source, attempt to find its details
4495 in group_reloc_table. The pointer will be updated to the character after
4496 the trailing colon. On failure, FAIL will be returned; SUCCESS
4497 otherwise. On success, *entry will be updated to point at the relevant
4498 group_reloc_table entry. */
4499
4500 static int
4501 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4502 {
4503 unsigned int i;
4504 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4505 {
4506 int length = strlen (group_reloc_table[i].name);
4507
4508 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4509 && (*str)[length] == ':')
4510 {
4511 *out = &group_reloc_table[i];
4512 *str += (length + 1);
4513 return SUCCESS;
4514 }
4515 }
4516
4517 return FAIL;
4518 }
4519
4520 /* Parse a <shifter_operand> for an ARM data processing instruction
4521 (as for parse_shifter_operand) where group relocations are allowed:
4522
4523 #<immediate>
4524 #<immediate>, <rotate>
4525 #:<group_reloc>:<expression>
4526 <Rm>
4527 <Rm>, <shift>
4528
4529 where <group_reloc> is one of the strings defined in group_reloc_table.
4530 The hashes are optional.
4531
4532 Everything else is as for parse_shifter_operand. */
4533
4534 static parse_operand_result
4535 parse_shifter_operand_group_reloc (char **str, int i)
4536 {
4537 /* Determine if we have the sequence of characters #: or just :
4538 coming next. If we do, then we check for a group relocation.
4539 If we don't, punt the whole lot to parse_shifter_operand. */
4540
4541 if (((*str)[0] == '#' && (*str)[1] == ':')
4542 || (*str)[0] == ':')
4543 {
4544 struct group_reloc_table_entry *entry;
4545
4546 if ((*str)[0] == '#')
4547 (*str) += 2;
4548 else
4549 (*str)++;
4550
4551 /* Try to parse a group relocation. Anything else is an error. */
4552 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4553 {
4554 inst.error = _("unknown group relocation");
4555 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4556 }
4557
4558 /* We now have the group relocation table entry corresponding to
4559 the name in the assembler source. Next, we parse the expression. */
4560 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4561 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4562
4563 /* Record the relocation type (always the ALU variant here). */
4564 inst.reloc.type = entry->alu_code;
4565 assert (inst.reloc.type != 0);
4566
4567 return PARSE_OPERAND_SUCCESS;
4568 }
4569 else
4570 return parse_shifter_operand (str, i) == SUCCESS
4571 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4572
4573 /* Never reached. */
4574 }
4575
4576 /* Parse all forms of an ARM address expression. Information is written
4577 to inst.operands[i] and/or inst.reloc.
4578
4579 Preindexed addressing (.preind=1):
4580
4581 [Rn, #offset] .reg=Rn .reloc.exp=offset
4582 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4583 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4584 .shift_kind=shift .reloc.exp=shift_imm
4585
4586 These three may have a trailing ! which causes .writeback to be set also.
4587
4588 Postindexed addressing (.postind=1, .writeback=1):
4589
4590 [Rn], #offset .reg=Rn .reloc.exp=offset
4591 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4592 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4593 .shift_kind=shift .reloc.exp=shift_imm
4594
4595 Unindexed addressing (.preind=0, .postind=0):
4596
4597 [Rn], {option} .reg=Rn .imm=option .immisreg=0
4598
4599 Other:
4600
4601 [Rn]{!} shorthand for [Rn,#0]{!}
4602 =immediate .isreg=0 .reloc.exp=immediate
4603 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
4604
4605 It is the caller's responsibility to check for addressing modes not
4606 supported by the instruction, and to set inst.reloc.type. */
4607
4608 static parse_operand_result
4609 parse_address_main (char **str, int i, int group_relocations,
4610 group_reloc_type group_type)
4611 {
4612 char *p = *str;
4613 int reg;
4614
4615 if (skip_past_char (&p, '[') == FAIL)
4616 {
4617 if (skip_past_char (&p, '=') == FAIL)
4618 {
4619 /* bare address - translate to PC-relative offset */
4620 inst.reloc.pc_rel = 1;
4621 inst.operands[i].reg = REG_PC;
4622 inst.operands[i].isreg = 1;
4623 inst.operands[i].preind = 1;
4624 }
4625 /* else a load-constant pseudo op, no special treatment needed here */
4626
4627 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4628 return PARSE_OPERAND_FAIL;
4629
4630 *str = p;
4631 return PARSE_OPERAND_SUCCESS;
4632 }
4633
4634 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
4635 {
4636 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4637 return PARSE_OPERAND_FAIL;
4638 }
4639 inst.operands[i].reg = reg;
4640 inst.operands[i].isreg = 1;
4641
4642 if (skip_past_comma (&p) == SUCCESS)
4643 {
4644 inst.operands[i].preind = 1;
4645
4646 if (*p == '+') p++;
4647 else if (*p == '-') p++, inst.operands[i].negative = 1;
4648
4649 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4650 {
4651 inst.operands[i].imm = reg;
4652 inst.operands[i].immisreg = 1;
4653
4654 if (skip_past_comma (&p) == SUCCESS)
4655 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4656 return PARSE_OPERAND_FAIL;
4657 }
4658 else if (skip_past_char (&p, ':') == SUCCESS)
4659 {
4660 /* FIXME: '@' should be used here, but it's filtered out by generic
4661 code before we get to see it here. This may be subject to
4662 change. */
4663 expressionS exp;
4664 my_get_expression (&exp, &p, GE_NO_PREFIX);
4665 if (exp.X_op != O_constant)
4666 {
4667 inst.error = _("alignment must be constant");
4668 return PARSE_OPERAND_FAIL;
4669 }
4670 inst.operands[i].imm = exp.X_add_number << 8;
4671 inst.operands[i].immisalign = 1;
4672 /* Alignments are not pre-indexes. */
4673 inst.operands[i].preind = 0;
4674 }
4675 else
4676 {
4677 if (inst.operands[i].negative)
4678 {
4679 inst.operands[i].negative = 0;
4680 p--;
4681 }
4682
4683 if (group_relocations
4684 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4685 {
4686 struct group_reloc_table_entry *entry;
4687
4688 /* Skip over the #: or : sequence. */
4689 if (*p == '#')
4690 p += 2;
4691 else
4692 p++;
4693
4694 /* Try to parse a group relocation. Anything else is an
4695 error. */
4696 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
4697 {
4698 inst.error = _("unknown group relocation");
4699 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4700 }
4701
4702 /* We now have the group relocation table entry corresponding to
4703 the name in the assembler source. Next, we parse the
4704 expression. */
4705 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4706 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4707
4708 /* Record the relocation type. */
4709 switch (group_type)
4710 {
4711 case GROUP_LDR:
4712 inst.reloc.type = entry->ldr_code;
4713 break;
4714
4715 case GROUP_LDRS:
4716 inst.reloc.type = entry->ldrs_code;
4717 break;
4718
4719 case GROUP_LDC:
4720 inst.reloc.type = entry->ldc_code;
4721 break;
4722
4723 default:
4724 assert (0);
4725 }
4726
4727 if (inst.reloc.type == 0)
4728 {
4729 inst.error = _("this group relocation is not allowed on this instruction");
4730 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4731 }
4732 }
4733 else
4734 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4735 return PARSE_OPERAND_FAIL;
4736 }
4737 }
4738
4739 if (skip_past_char (&p, ']') == FAIL)
4740 {
4741 inst.error = _("']' expected");
4742 return PARSE_OPERAND_FAIL;
4743 }
4744
4745 if (skip_past_char (&p, '!') == SUCCESS)
4746 inst.operands[i].writeback = 1;
4747
4748 else if (skip_past_comma (&p) == SUCCESS)
4749 {
4750 if (skip_past_char (&p, '{') == SUCCESS)
4751 {
4752 /* [Rn], {expr} - unindexed, with option */
4753 if (parse_immediate (&p, &inst.operands[i].imm,
4754 0, 255, TRUE) == FAIL)
4755 return PARSE_OPERAND_FAIL;
4756
4757 if (skip_past_char (&p, '}') == FAIL)
4758 {
4759 inst.error = _("'}' expected at end of 'option' field");
4760 return PARSE_OPERAND_FAIL;
4761 }
4762 if (inst.operands[i].preind)
4763 {
4764 inst.error = _("cannot combine index with option");
4765 return PARSE_OPERAND_FAIL;
4766 }
4767 *str = p;
4768 return PARSE_OPERAND_SUCCESS;
4769 }
4770 else
4771 {
4772 inst.operands[i].postind = 1;
4773 inst.operands[i].writeback = 1;
4774
4775 if (inst.operands[i].preind)
4776 {
4777 inst.error = _("cannot combine pre- and post-indexing");
4778 return PARSE_OPERAND_FAIL;
4779 }
4780
4781 if (*p == '+') p++;
4782 else if (*p == '-') p++, inst.operands[i].negative = 1;
4783
4784 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4785 {
4786 /* We might be using the immediate for alignment already. If we
4787 are, OR the register number into the low-order bits. */
4788 if (inst.operands[i].immisalign)
4789 inst.operands[i].imm |= reg;
4790 else
4791 inst.operands[i].imm = reg;
4792 inst.operands[i].immisreg = 1;
4793
4794 if (skip_past_comma (&p) == SUCCESS)
4795 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4796 return PARSE_OPERAND_FAIL;
4797 }
4798 else
4799 {
4800 if (inst.operands[i].negative)
4801 {
4802 inst.operands[i].negative = 0;
4803 p--;
4804 }
4805 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4806 return PARSE_OPERAND_FAIL;
4807 }
4808 }
4809 }
4810
4811 /* If at this point neither .preind nor .postind is set, we have a
4812 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
4813 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
4814 {
4815 inst.operands[i].preind = 1;
4816 inst.reloc.exp.X_op = O_constant;
4817 inst.reloc.exp.X_add_number = 0;
4818 }
4819 *str = p;
4820 return PARSE_OPERAND_SUCCESS;
4821 }
4822
4823 static int
4824 parse_address (char **str, int i)
4825 {
4826 return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS
4827 ? SUCCESS : FAIL;
4828 }
4829
4830 static parse_operand_result
4831 parse_address_group_reloc (char **str, int i, group_reloc_type type)
4832 {
4833 return parse_address_main (str, i, 1, type);
4834 }
4835
4836 /* Parse an operand for a MOVW or MOVT instruction. */
4837 static int
4838 parse_half (char **str)
4839 {
4840 char * p;
4841
4842 p = *str;
4843 skip_past_char (&p, '#');
4844 if (strncasecmp (p, ":lower16:", 9) == 0)
4845 inst.reloc.type = BFD_RELOC_ARM_MOVW;
4846 else if (strncasecmp (p, ":upper16:", 9) == 0)
4847 inst.reloc.type = BFD_RELOC_ARM_MOVT;
4848
4849 if (inst.reloc.type != BFD_RELOC_UNUSED)
4850 {
4851 p += 9;
4852 skip_whitespace (p);
4853 }
4854
4855 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4856 return FAIL;
4857
4858 if (inst.reloc.type == BFD_RELOC_UNUSED)
4859 {
4860 if (inst.reloc.exp.X_op != O_constant)
4861 {
4862 inst.error = _("constant expression expected");
4863 return FAIL;
4864 }
4865 if (inst.reloc.exp.X_add_number < 0
4866 || inst.reloc.exp.X_add_number > 0xffff)
4867 {
4868 inst.error = _("immediate value out of range");
4869 return FAIL;
4870 }
4871 }
4872 *str = p;
4873 return SUCCESS;
4874 }
4875
4876 /* Miscellaneous. */
4877
4878 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
4879 or a bitmask suitable to be or-ed into the ARM msr instruction. */
4880 static int
4881 parse_psr (char **str)
4882 {
4883 char *p;
4884 unsigned long psr_field;
4885 const struct asm_psr *psr;
4886 char *start;
4887
4888 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
4889 feature for ease of use and backwards compatibility. */
4890 p = *str;
4891 if (strncasecmp (p, "SPSR", 4) == 0)
4892 psr_field = SPSR_BIT;
4893 else if (strncasecmp (p, "CPSR", 4) == 0)
4894 psr_field = 0;
4895 else
4896 {
4897 start = p;
4898 do
4899 p++;
4900 while (ISALNUM (*p) || *p == '_');
4901
4902 psr = hash_find_n (arm_v7m_psr_hsh, start, p - start);
4903 if (!psr)
4904 return FAIL;
4905
4906 *str = p;
4907 return psr->field;
4908 }
4909
4910 p += 4;
4911 if (*p == '_')
4912 {
4913 /* A suffix follows. */
4914 p++;
4915 start = p;
4916
4917 do
4918 p++;
4919 while (ISALNUM (*p) || *p == '_');
4920
4921 psr = hash_find_n (arm_psr_hsh, start, p - start);
4922 if (!psr)
4923 goto error;
4924
4925 psr_field |= psr->field;
4926 }
4927 else
4928 {
4929 if (ISALNUM (*p))
4930 goto error; /* Garbage after "[CS]PSR". */
4931
4932 psr_field |= (PSR_c | PSR_f);
4933 }
4934 *str = p;
4935 return psr_field;
4936
4937 error:
4938 inst.error = _("flag for {c}psr instruction expected");
4939 return FAIL;
4940 }
4941
4942 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
4943 value suitable for splatting into the AIF field of the instruction. */
4944
4945 static int
4946 parse_cps_flags (char **str)
4947 {
4948 int val = 0;
4949 int saw_a_flag = 0;
4950 char *s = *str;
4951
4952 for (;;)
4953 switch (*s++)
4954 {
4955 case '\0': case ',':
4956 goto done;
4957
4958 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
4959 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
4960 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
4961
4962 default:
4963 inst.error = _("unrecognized CPS flag");
4964 return FAIL;
4965 }
4966
4967 done:
4968 if (saw_a_flag == 0)
4969 {
4970 inst.error = _("missing CPS flags");
4971 return FAIL;
4972 }
4973
4974 *str = s - 1;
4975 return val;
4976 }
4977
4978 /* Parse an endian specifier ("BE" or "LE", case insensitive);
4979 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
4980
4981 static int
4982 parse_endian_specifier (char **str)
4983 {
4984 int little_endian;
4985 char *s = *str;
4986
4987 if (strncasecmp (s, "BE", 2))
4988 little_endian = 0;
4989 else if (strncasecmp (s, "LE", 2))
4990 little_endian = 1;
4991 else
4992 {
4993 inst.error = _("valid endian specifiers are be or le");
4994 return FAIL;
4995 }
4996
4997 if (ISALNUM (s[2]) || s[2] == '_')
4998 {
4999 inst.error = _("valid endian specifiers are be or le");
5000 return FAIL;
5001 }
5002
5003 *str = s + 2;
5004 return little_endian;
5005 }
5006
5007 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5008 value suitable for poking into the rotate field of an sxt or sxta
5009 instruction, or FAIL on error. */
5010
5011 static int
5012 parse_ror (char **str)
5013 {
5014 int rot;
5015 char *s = *str;
5016
5017 if (strncasecmp (s, "ROR", 3) == 0)
5018 s += 3;
5019 else
5020 {
5021 inst.error = _("missing rotation field after comma");
5022 return FAIL;
5023 }
5024
5025 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5026 return FAIL;
5027
5028 switch (rot)
5029 {
5030 case 0: *str = s; return 0x0;
5031 case 8: *str = s; return 0x1;
5032 case 16: *str = s; return 0x2;
5033 case 24: *str = s; return 0x3;
5034
5035 default:
5036 inst.error = _("rotation can only be 0, 8, 16, or 24");
5037 return FAIL;
5038 }
5039 }
5040
5041 /* Parse a conditional code (from conds[] below). The value returned is in the
5042 range 0 .. 14, or FAIL. */
5043 static int
5044 parse_cond (char **str)
5045 {
5046 char *q;
5047 const struct asm_cond *c;
5048 int n;
5049 /* Condition codes are always 2 characters, so matching up to
5050 3 characters is sufficient. */
5051 char cond[3];
5052
5053 q = *str;
5054 n = 0;
5055 while (ISALPHA (*q) && n < 3)
5056 {
5057 cond[n] = TOLOWER(*q);
5058 q++;
5059 n++;
5060 }
5061
5062 c = hash_find_n (arm_cond_hsh, cond, n);
5063 if (!c)
5064 {
5065 inst.error = _("condition required");
5066 return FAIL;
5067 }
5068
5069 *str = q;
5070 return c->value;
5071 }
5072
5073 /* Parse an option for a barrier instruction. Returns the encoding for the
5074 option, or FAIL. */
5075 static int
5076 parse_barrier (char **str)
5077 {
5078 char *p, *q;
5079 const struct asm_barrier_opt *o;
5080
5081 p = q = *str;
5082 while (ISALPHA (*q))
5083 q++;
5084
5085 o = hash_find_n (arm_barrier_opt_hsh, p, q - p);
5086 if (!o)
5087 return FAIL;
5088
5089 *str = q;
5090 return o->value;
5091 }
5092
5093 /* Parse the operands of a table branch instruction. Similar to a memory
5094 operand. */
5095 static int
5096 parse_tb (char **str)
5097 {
5098 char * p = *str;
5099 int reg;
5100
5101 if (skip_past_char (&p, '[') == FAIL)
5102 {
5103 inst.error = _("'[' expected");
5104 return FAIL;
5105 }
5106
5107 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5108 {
5109 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5110 return FAIL;
5111 }
5112 inst.operands[0].reg = reg;
5113
5114 if (skip_past_comma (&p) == FAIL)
5115 {
5116 inst.error = _("',' expected");
5117 return FAIL;
5118 }
5119
5120 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5121 {
5122 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5123 return FAIL;
5124 }
5125 inst.operands[0].imm = reg;
5126
5127 if (skip_past_comma (&p) == SUCCESS)
5128 {
5129 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5130 return FAIL;
5131 if (inst.reloc.exp.X_add_number != 1)
5132 {
5133 inst.error = _("invalid shift");
5134 return FAIL;
5135 }
5136 inst.operands[0].shifted = 1;
5137 }
5138
5139 if (skip_past_char (&p, ']') == FAIL)
5140 {
5141 inst.error = _("']' expected");
5142 return FAIL;
5143 }
5144 *str = p;
5145 return SUCCESS;
5146 }
5147
5148 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5149 information on the types the operands can take and how they are encoded.
5150 Up to four operands may be read; this function handles setting the
5151 ".present" field for each read operand itself.
5152 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5153 else returns FAIL. */
5154
5155 static int
5156 parse_neon_mov (char **str, int *which_operand)
5157 {
5158 int i = *which_operand, val;
5159 enum arm_reg_type rtype;
5160 char *ptr = *str;
5161 struct neon_type_el optype;
5162
5163 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5164 {
5165 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5166 inst.operands[i].reg = val;
5167 inst.operands[i].isscalar = 1;
5168 inst.operands[i].vectype = optype;
5169 inst.operands[i++].present = 1;
5170
5171 if (skip_past_comma (&ptr) == FAIL)
5172 goto wanted_comma;
5173
5174 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5175 goto wanted_arm;
5176
5177 inst.operands[i].reg = val;
5178 inst.operands[i].isreg = 1;
5179 inst.operands[i].present = 1;
5180 }
5181 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
5182 != FAIL)
5183 {
5184 /* Cases 0, 1, 2, 3, 5 (D only). */
5185 if (skip_past_comma (&ptr) == FAIL)
5186 goto wanted_comma;
5187
5188 inst.operands[i].reg = val;
5189 inst.operands[i].isreg = 1;
5190 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5191 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5192 inst.operands[i].isvec = 1;
5193 inst.operands[i].vectype = optype;
5194 inst.operands[i++].present = 1;
5195
5196 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5197 {
5198 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5199 Case 13: VMOV <Sd>, <Rm> */
5200 inst.operands[i].reg = val;
5201 inst.operands[i].isreg = 1;
5202 inst.operands[i].present = 1;
5203
5204 if (rtype == REG_TYPE_NQ)
5205 {
5206 first_error (_("can't use Neon quad register here"));
5207 return FAIL;
5208 }
5209 else if (rtype != REG_TYPE_VFS)
5210 {
5211 i++;
5212 if (skip_past_comma (&ptr) == FAIL)
5213 goto wanted_comma;
5214 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5215 goto wanted_arm;
5216 inst.operands[i].reg = val;
5217 inst.operands[i].isreg = 1;
5218 inst.operands[i].present = 1;
5219 }
5220 }
5221 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5222 &optype)) != FAIL)
5223 {
5224 /* Case 0: VMOV<c><q> <Qd>, <Qm>
5225 Case 1: VMOV<c><q> <Dd>, <Dm>
5226 Case 8: VMOV.F32 <Sd>, <Sm>
5227 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5228
5229 inst.operands[i].reg = val;
5230 inst.operands[i].isreg = 1;
5231 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5232 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5233 inst.operands[i].isvec = 1;
5234 inst.operands[i].vectype = optype;
5235 inst.operands[i].present = 1;
5236
5237 if (skip_past_comma (&ptr) == SUCCESS)
5238 {
5239 /* Case 15. */
5240 i++;
5241
5242 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5243 goto wanted_arm;
5244
5245 inst.operands[i].reg = val;
5246 inst.operands[i].isreg = 1;
5247 inst.operands[i++].present = 1;
5248
5249 if (skip_past_comma (&ptr) == FAIL)
5250 goto wanted_comma;
5251
5252 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5253 goto wanted_arm;
5254
5255 inst.operands[i].reg = val;
5256 inst.operands[i].isreg = 1;
5257 inst.operands[i++].present = 1;
5258 }
5259 }
5260 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5261 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5262 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5263 Case 10: VMOV.F32 <Sd>, #<imm>
5264 Case 11: VMOV.F64 <Dd>, #<imm> */
5265 inst.operands[i].immisfloat = 1;
5266 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5267 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5268 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5269 ;
5270 else
5271 {
5272 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5273 return FAIL;
5274 }
5275 }
5276 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5277 {
5278 /* Cases 6, 7. */
5279 inst.operands[i].reg = val;
5280 inst.operands[i].isreg = 1;
5281 inst.operands[i++].present = 1;
5282
5283 if (skip_past_comma (&ptr) == FAIL)
5284 goto wanted_comma;
5285
5286 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287 {
5288 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5289 inst.operands[i].reg = val;
5290 inst.operands[i].isscalar = 1;
5291 inst.operands[i].present = 1;
5292 inst.operands[i].vectype = optype;
5293 }
5294 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5295 {
5296 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5297 inst.operands[i].reg = val;
5298 inst.operands[i].isreg = 1;
5299 inst.operands[i++].present = 1;
5300
5301 if (skip_past_comma (&ptr) == FAIL)
5302 goto wanted_comma;
5303
5304 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
5305 == FAIL)
5306 {
5307 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5308 return FAIL;
5309 }
5310
5311 inst.operands[i].reg = val;
5312 inst.operands[i].isreg = 1;
5313 inst.operands[i].isvec = 1;
5314 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5315 inst.operands[i].vectype = optype;
5316 inst.operands[i].present = 1;
5317
5318 if (rtype == REG_TYPE_VFS)
5319 {
5320 /* Case 14. */
5321 i++;
5322 if (skip_past_comma (&ptr) == FAIL)
5323 goto wanted_comma;
5324 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5325 &optype)) == FAIL)
5326 {
5327 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5328 return FAIL;
5329 }
5330 inst.operands[i].reg = val;
5331 inst.operands[i].isreg = 1;
5332 inst.operands[i].isvec = 1;
5333 inst.operands[i].issingle = 1;
5334 inst.operands[i].vectype = optype;
5335 inst.operands[i].present = 1;
5336 }
5337 }
5338 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5339 != FAIL)
5340 {
5341 /* Case 13. */
5342 inst.operands[i].reg = val;
5343 inst.operands[i].isreg = 1;
5344 inst.operands[i].isvec = 1;
5345 inst.operands[i].issingle = 1;
5346 inst.operands[i].vectype = optype;
5347 inst.operands[i++].present = 1;
5348 }
5349 }
5350 else
5351 {
5352 first_error (_("parse error"));
5353 return FAIL;
5354 }
5355
5356 /* Successfully parsed the operands. Update args. */
5357 *which_operand = i;
5358 *str = ptr;
5359 return SUCCESS;
5360
5361 wanted_comma:
5362 first_error (_("expected comma"));
5363 return FAIL;
5364
5365 wanted_arm:
5366 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5367 return FAIL;
5368 }
5369
5370 /* Matcher codes for parse_operands. */
5371 enum operand_parse_code
5372 {
5373 OP_stop, /* end of line */
5374
5375 OP_RR, /* ARM register */
5376 OP_RRnpc, /* ARM register, not r15 */
5377 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5378 OP_RRw, /* ARM register, not r15, optional trailing ! */
5379 OP_RCP, /* Coprocessor number */
5380 OP_RCN, /* Coprocessor register */
5381 OP_RF, /* FPA register */
5382 OP_RVS, /* VFP single precision register */
5383 OP_RVD, /* VFP double precision register (0..15) */
5384 OP_RND, /* Neon double precision register (0..31) */
5385 OP_RNQ, /* Neon quad precision register */
5386 OP_RVSD, /* VFP single or double precision register */
5387 OP_RNDQ, /* Neon double or quad precision register */
5388 OP_RNSDQ, /* Neon single, double or quad precision register */
5389 OP_RNSC, /* Neon scalar D[X] */
5390 OP_RVC, /* VFP control register */
5391 OP_RMF, /* Maverick F register */
5392 OP_RMD, /* Maverick D register */
5393 OP_RMFX, /* Maverick FX register */
5394 OP_RMDX, /* Maverick DX register */
5395 OP_RMAX, /* Maverick AX register */
5396 OP_RMDS, /* Maverick DSPSC register */
5397 OP_RIWR, /* iWMMXt wR register */
5398 OP_RIWC, /* iWMMXt wC register */
5399 OP_RIWG, /* iWMMXt wCG register */
5400 OP_RXA, /* XScale accumulator register */
5401
5402 OP_REGLST, /* ARM register list */
5403 OP_VRSLST, /* VFP single-precision register list */
5404 OP_VRDLST, /* VFP double-precision register list */
5405 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5406 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5407 OP_NSTRLST, /* Neon element/structure list */
5408
5409 OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */
5410 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
5411 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5412 OP_RR_RNSC, /* ARM reg or Neon scalar. */
5413 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5414 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5415 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5416 OP_VMOV, /* Neon VMOV operands. */
5417 OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */
5418 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
5419 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5420
5421 OP_I0, /* immediate zero */
5422 OP_I7, /* immediate value 0 .. 7 */
5423 OP_I15, /* 0 .. 15 */
5424 OP_I16, /* 1 .. 16 */
5425 OP_I16z, /* 0 .. 16 */
5426 OP_I31, /* 0 .. 31 */
5427 OP_I31w, /* 0 .. 31, optional trailing ! */
5428 OP_I32, /* 1 .. 32 */
5429 OP_I32z, /* 0 .. 32 */
5430 OP_I63, /* 0 .. 63 */
5431 OP_I63s, /* -64 .. 63 */
5432 OP_I64, /* 1 .. 64 */
5433 OP_I64z, /* 0 .. 64 */
5434 OP_I255, /* 0 .. 255 */
5435
5436 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5437 OP_I7b, /* 0 .. 7 */
5438 OP_I15b, /* 0 .. 15 */
5439 OP_I31b, /* 0 .. 31 */
5440
5441 OP_SH, /* shifter operand */
5442 OP_SHG, /* shifter operand with possible group relocation */
5443 OP_ADDR, /* Memory address expression (any mode) */
5444 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5445 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5446 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
5447 OP_EXP, /* arbitrary expression */
5448 OP_EXPi, /* same, with optional immediate prefix */
5449 OP_EXPr, /* same, with optional relocation suffix */
5450 OP_HALF, /* 0 .. 65535 or low/high reloc. */
5451
5452 OP_CPSF, /* CPS flags */
5453 OP_ENDI, /* Endianness specifier */
5454 OP_PSR, /* CPSR/SPSR mask for msr */
5455 OP_COND, /* conditional code */
5456 OP_TB, /* Table branch. */
5457
5458 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5459 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5460
5461 OP_RRnpc_I0, /* ARM register or literal 0 */
5462 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5463 OP_RR_EXi, /* ARM register or expression with imm prefix */
5464 OP_RF_IF, /* FPA register or immediate */
5465 OP_RIWR_RIWC, /* iWMMXt R or C reg */
5466 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
5467
5468 /* Optional operands. */
5469 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5470 OP_oI31b, /* 0 .. 31 */
5471 OP_oI32b, /* 1 .. 32 */
5472 OP_oIffffb, /* 0 .. 65535 */
5473 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5474
5475 OP_oRR, /* ARM register */
5476 OP_oRRnpc, /* ARM register, not the PC */
5477 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5478 OP_oRND, /* Optional Neon double precision register */
5479 OP_oRNQ, /* Optional Neon quad precision register */
5480 OP_oRNDQ, /* Optional Neon double or quad precision register */
5481 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
5482 OP_oSHll, /* LSL immediate */
5483 OP_oSHar, /* ASR immediate */
5484 OP_oSHllar, /* LSL or ASR immediate */
5485 OP_oROR, /* ROR 0/8/16/24 */
5486 OP_oBARRIER, /* Option argument for a barrier instruction. */
5487
5488 OP_FIRST_OPTIONAL = OP_oI7b
5489 };
5490
5491 /* Generic instruction operand parser. This does no encoding and no
5492 semantic validation; it merely squirrels values away in the inst
5493 structure. Returns SUCCESS or FAIL depending on whether the
5494 specified grammar matched. */
5495 static int
5496 parse_operands (char *str, const unsigned char *pattern)
5497 {
5498 unsigned const char *upat = pattern;
5499 char *backtrack_pos = 0;
5500 const char *backtrack_error = 0;
5501 int i, val, backtrack_index = 0;
5502 enum arm_reg_type rtype;
5503 parse_operand_result result;
5504
5505 #define po_char_or_fail(chr) do { \
5506 if (skip_past_char (&str, chr) == FAIL) \
5507 goto bad_args; \
5508 } while (0)
5509
5510 #define po_reg_or_fail(regtype) do { \
5511 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5512 &inst.operands[i].vectype); \
5513 if (val == FAIL) \
5514 { \
5515 first_error (_(reg_expected_msgs[regtype])); \
5516 goto failure; \
5517 } \
5518 inst.operands[i].reg = val; \
5519 inst.operands[i].isreg = 1; \
5520 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5521 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5522 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5523 || rtype == REG_TYPE_VFD \
5524 || rtype == REG_TYPE_NQ); \
5525 } while (0)
5526
5527 #define po_reg_or_goto(regtype, label) do { \
5528 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5529 &inst.operands[i].vectype); \
5530 if (val == FAIL) \
5531 goto label; \
5532 \
5533 inst.operands[i].reg = val; \
5534 inst.operands[i].isreg = 1; \
5535 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5536 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5537 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5538 || rtype == REG_TYPE_VFD \
5539 || rtype == REG_TYPE_NQ); \
5540 } while (0)
5541
5542 #define po_imm_or_fail(min, max, popt) do { \
5543 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5544 goto failure; \
5545 inst.operands[i].imm = val; \
5546 } while (0)
5547
5548 #define po_scalar_or_goto(elsz, label) do { \
5549 val = parse_scalar (&str, elsz, &inst.operands[i].vectype); \
5550 if (val == FAIL) \
5551 goto label; \
5552 inst.operands[i].reg = val; \
5553 inst.operands[i].isscalar = 1; \
5554 } while (0)
5555
5556 #define po_misc_or_fail(expr) do { \
5557 if (expr) \
5558 goto failure; \
5559 } while (0)
5560
5561 #define po_misc_or_fail_no_backtrack(expr) do { \
5562 result = expr; \
5563 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK)\
5564 backtrack_pos = 0; \
5565 if (result != PARSE_OPERAND_SUCCESS) \
5566 goto failure; \
5567 } while (0)
5568
5569 skip_whitespace (str);
5570
5571 for (i = 0; upat[i] != OP_stop; i++)
5572 {
5573 if (upat[i] >= OP_FIRST_OPTIONAL)
5574 {
5575 /* Remember where we are in case we need to backtrack. */
5576 assert (!backtrack_pos);
5577 backtrack_pos = str;
5578 backtrack_error = inst.error;
5579 backtrack_index = i;
5580 }
5581
5582 if (i > 0 && (i > 1 || inst.operands[0].present))
5583 po_char_or_fail (',');
5584
5585 switch (upat[i])
5586 {
5587 /* Registers */
5588 case OP_oRRnpc:
5589 case OP_RRnpc:
5590 case OP_oRR:
5591 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5592 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5593 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
5594 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
5595 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
5596 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5597 case OP_oRND:
5598 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
5599 case OP_RVC:
5600 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
5601 break;
5602 /* Also accept generic coprocessor regs for unknown registers. */
5603 coproc_reg:
5604 po_reg_or_fail (REG_TYPE_CN);
5605 break;
5606 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
5607 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
5608 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
5609 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
5610 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
5611 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
5612 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
5613 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
5614 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
5615 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5616 case OP_oRNQ:
5617 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
5618 case OP_oRNDQ:
5619 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
5620 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
5621 case OP_oRNSDQ:
5622 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5623
5624 /* Neon scalar. Using an element size of 8 means that some invalid
5625 scalars are accepted here, so deal with those in later code. */
5626 case OP_RNSC: po_scalar_or_goto (8, failure); break;
5627
5628 /* WARNING: We can expand to two operands here. This has the potential
5629 to totally confuse the backtracking mechanism! It will be OK at
5630 least as long as we don't try to use optional args as well,
5631 though. */
5632 case OP_NILO:
5633 {
5634 po_reg_or_goto (REG_TYPE_NDQ, try_imm);
5635 inst.operands[i].present = 1;
5636 i++;
5637 skip_past_comma (&str);
5638 po_reg_or_goto (REG_TYPE_NDQ, one_reg_only);
5639 break;
5640 one_reg_only:
5641 /* Optional register operand was omitted. Unfortunately, it's in
5642 operands[i-1] and we need it to be in inst.operands[i]. Fix that
5643 here (this is a bit grotty). */
5644 inst.operands[i] = inst.operands[i-1];
5645 inst.operands[i-1].present = 0;
5646 break;
5647 try_imm:
5648 /* There's a possibility of getting a 64-bit immediate here, so
5649 we need special handling. */
5650 if (parse_big_immediate (&str, i) == FAIL)
5651 {
5652 inst.error = _("immediate value is out of range");
5653 goto failure;
5654 }
5655 }
5656 break;
5657
5658 case OP_RNDQ_I0:
5659 {
5660 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
5661 break;
5662 try_imm0:
5663 po_imm_or_fail (0, 0, TRUE);
5664 }
5665 break;
5666
5667 case OP_RVSD_I0:
5668 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
5669 break;
5670
5671 case OP_RR_RNSC:
5672 {
5673 po_scalar_or_goto (8, try_rr);
5674 break;
5675 try_rr:
5676 po_reg_or_fail (REG_TYPE_RN);
5677 }
5678 break;
5679
5680 case OP_RNSDQ_RNSC:
5681 {
5682 po_scalar_or_goto (8, try_nsdq);
5683 break;
5684 try_nsdq:
5685 po_reg_or_fail (REG_TYPE_NSDQ);
5686 }
5687 break;
5688
5689 case OP_RNDQ_RNSC:
5690 {
5691 po_scalar_or_goto (8, try_ndq);
5692 break;
5693 try_ndq:
5694 po_reg_or_fail (REG_TYPE_NDQ);
5695 }
5696 break;
5697
5698 case OP_RND_RNSC:
5699 {
5700 po_scalar_or_goto (8, try_vfd);
5701 break;
5702 try_vfd:
5703 po_reg_or_fail (REG_TYPE_VFD);
5704 }
5705 break;
5706
5707 case OP_VMOV:
5708 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
5709 not careful then bad things might happen. */
5710 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
5711 break;
5712
5713 case OP_RNDQ_IMVNb:
5714 {
5715 po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm);
5716 break;
5717 try_mvnimm:
5718 /* There's a possibility of getting a 64-bit immediate here, so
5719 we need special handling. */
5720 if (parse_big_immediate (&str, i) == FAIL)
5721 {
5722 inst.error = _("immediate value is out of range");
5723 goto failure;
5724 }
5725 }
5726 break;
5727
5728 case OP_RNDQ_I63b:
5729 {
5730 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
5731 break;
5732 try_shimm:
5733 po_imm_or_fail (0, 63, TRUE);
5734 }
5735 break;
5736
5737 case OP_RRnpcb:
5738 po_char_or_fail ('[');
5739 po_reg_or_fail (REG_TYPE_RN);
5740 po_char_or_fail (']');
5741 break;
5742
5743 case OP_RRw:
5744 case OP_oRRw:
5745 po_reg_or_fail (REG_TYPE_RN);
5746 if (skip_past_char (&str, '!') == SUCCESS)
5747 inst.operands[i].writeback = 1;
5748 break;
5749
5750 /* Immediates */
5751 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
5752 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
5753 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5754 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
5755 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
5756 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5757 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
5758 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5759 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
5760 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
5761 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
5762 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
5763
5764 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
5765 case OP_oI7b:
5766 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
5767 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
5768 case OP_oI31b:
5769 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5770 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
5771 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
5772
5773 /* Immediate variants */
5774 case OP_oI255c:
5775 po_char_or_fail ('{');
5776 po_imm_or_fail (0, 255, TRUE);
5777 po_char_or_fail ('}');
5778 break;
5779
5780 case OP_I31w:
5781 /* The expression parser chokes on a trailing !, so we have
5782 to find it first and zap it. */
5783 {
5784 char *s = str;
5785 while (*s && *s != ',')
5786 s++;
5787 if (s[-1] == '!')
5788 {
5789 s[-1] = '\0';
5790 inst.operands[i].writeback = 1;
5791 }
5792 po_imm_or_fail (0, 31, TRUE);
5793 if (str == s - 1)
5794 str = s;
5795 }
5796 break;
5797
5798 /* Expressions */
5799 case OP_EXPi: EXPi:
5800 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5801 GE_OPT_PREFIX));
5802 break;
5803
5804 case OP_EXP:
5805 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5806 GE_NO_PREFIX));
5807 break;
5808
5809 case OP_EXPr: EXPr:
5810 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5811 GE_NO_PREFIX));
5812 if (inst.reloc.exp.X_op == O_symbol)
5813 {
5814 val = parse_reloc (&str);
5815 if (val == -1)
5816 {
5817 inst.error = _("unrecognized relocation suffix");
5818 goto failure;
5819 }
5820 else if (val != BFD_RELOC_UNUSED)
5821 {
5822 inst.operands[i].imm = val;
5823 inst.operands[i].hasreloc = 1;
5824 }
5825 }
5826 break;
5827
5828 /* Operand for MOVW or MOVT. */
5829 case OP_HALF:
5830 po_misc_or_fail (parse_half (&str));
5831 break;
5832
5833 /* Register or expression */
5834 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
5835 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
5836
5837 /* Register or immediate */
5838 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
5839 I0: po_imm_or_fail (0, 0, FALSE); break;
5840
5841 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
5842 IF:
5843 if (!is_immediate_prefix (*str))
5844 goto bad_args;
5845 str++;
5846 val = parse_fpa_immediate (&str);
5847 if (val == FAIL)
5848 goto failure;
5849 /* FPA immediates are encoded as registers 8-15.
5850 parse_fpa_immediate has already applied the offset. */
5851 inst.operands[i].reg = val;
5852 inst.operands[i].isreg = 1;
5853 break;
5854
5855 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
5856 I32z: po_imm_or_fail (0, 32, FALSE); break;
5857
5858 /* Two kinds of register */
5859 case OP_RIWR_RIWC:
5860 {
5861 struct reg_entry *rege = arm_reg_parse_multi (&str);
5862 if (!rege
5863 || (rege->type != REG_TYPE_MMXWR
5864 && rege->type != REG_TYPE_MMXWC
5865 && rege->type != REG_TYPE_MMXWCG))
5866 {
5867 inst.error = _("iWMMXt data or control register expected");
5868 goto failure;
5869 }
5870 inst.operands[i].reg = rege->number;
5871 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
5872 }
5873 break;
5874
5875 case OP_RIWC_RIWG:
5876 {
5877 struct reg_entry *rege = arm_reg_parse_multi (&str);
5878 if (!rege
5879 || (rege->type != REG_TYPE_MMXWC
5880 && rege->type != REG_TYPE_MMXWCG))
5881 {
5882 inst.error = _("iWMMXt control register expected");
5883 goto failure;
5884 }
5885 inst.operands[i].reg = rege->number;
5886 inst.operands[i].isreg = 1;
5887 }
5888 break;
5889
5890 /* Misc */
5891 case OP_CPSF: val = parse_cps_flags (&str); break;
5892 case OP_ENDI: val = parse_endian_specifier (&str); break;
5893 case OP_oROR: val = parse_ror (&str); break;
5894 case OP_PSR: val = parse_psr (&str); break;
5895 case OP_COND: val = parse_cond (&str); break;
5896 case OP_oBARRIER:val = parse_barrier (&str); break;
5897
5898 case OP_RVC_PSR:
5899 po_reg_or_goto (REG_TYPE_VFC, try_psr);
5900 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
5901 break;
5902 try_psr:
5903 val = parse_psr (&str);
5904 break;
5905
5906 case OP_APSR_RR:
5907 po_reg_or_goto (REG_TYPE_RN, try_apsr);
5908 break;
5909 try_apsr:
5910 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
5911 instruction). */
5912 if (strncasecmp (str, "APSR_", 5) == 0)
5913 {
5914 unsigned found = 0;
5915 str += 5;
5916 while (found < 15)
5917 switch (*str++)
5918 {
5919 case 'c': found = (found & 1) ? 16 : found | 1; break;
5920 case 'n': found = (found & 2) ? 16 : found | 2; break;
5921 case 'z': found = (found & 4) ? 16 : found | 4; break;
5922 case 'v': found = (found & 8) ? 16 : found | 8; break;
5923 default: found = 16;
5924 }
5925 if (found != 15)
5926 goto failure;
5927 inst.operands[i].isvec = 1;
5928 }
5929 else
5930 goto failure;
5931 break;
5932
5933 case OP_TB:
5934 po_misc_or_fail (parse_tb (&str));
5935 break;
5936
5937 /* Register lists */
5938 case OP_REGLST:
5939 val = parse_reg_list (&str);
5940 if (*str == '^')
5941 {
5942 inst.operands[1].writeback = 1;
5943 str++;
5944 }
5945 break;
5946
5947 case OP_VRSLST:
5948 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
5949 break;
5950
5951 case OP_VRDLST:
5952 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
5953 break;
5954
5955 case OP_VRSDLST:
5956 /* Allow Q registers too. */
5957 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5958 REGLIST_NEON_D);
5959 if (val == FAIL)
5960 {
5961 inst.error = NULL;
5962 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5963 REGLIST_VFP_S);
5964 inst.operands[i].issingle = 1;
5965 }
5966 break;
5967
5968 case OP_NRDLST:
5969 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5970 REGLIST_NEON_D);
5971 break;
5972
5973 case OP_NSTRLST:
5974 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
5975 &inst.operands[i].vectype);
5976 break;
5977
5978 /* Addressing modes */
5979 case OP_ADDR:
5980 po_misc_or_fail (parse_address (&str, i));
5981 break;
5982
5983 case OP_ADDRGLDR:
5984 po_misc_or_fail_no_backtrack (
5985 parse_address_group_reloc (&str, i, GROUP_LDR));
5986 break;
5987
5988 case OP_ADDRGLDRS:
5989 po_misc_or_fail_no_backtrack (
5990 parse_address_group_reloc (&str, i, GROUP_LDRS));
5991 break;
5992
5993 case OP_ADDRGLDC:
5994 po_misc_or_fail_no_backtrack (
5995 parse_address_group_reloc (&str, i, GROUP_LDC));
5996 break;
5997
5998 case OP_SH:
5999 po_misc_or_fail (parse_shifter_operand (&str, i));
6000 break;
6001
6002 case OP_SHG:
6003 po_misc_or_fail_no_backtrack (
6004 parse_shifter_operand_group_reloc (&str, i));
6005 break;
6006
6007 case OP_oSHll:
6008 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6009 break;
6010
6011 case OP_oSHar:
6012 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6013 break;
6014
6015 case OP_oSHllar:
6016 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6017 break;
6018
6019 default:
6020 as_fatal (_("unhandled operand code %d"), upat[i]);
6021 }
6022
6023 /* Various value-based sanity checks and shared operations. We
6024 do not signal immediate failures for the register constraints;
6025 this allows a syntax error to take precedence. */
6026 switch (upat[i])
6027 {
6028 case OP_oRRnpc:
6029 case OP_RRnpc:
6030 case OP_RRnpcb:
6031 case OP_RRw:
6032 case OP_oRRw:
6033 case OP_RRnpc_I0:
6034 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6035 inst.error = BAD_PC;
6036 break;
6037
6038 case OP_CPSF:
6039 case OP_ENDI:
6040 case OP_oROR:
6041 case OP_PSR:
6042 case OP_RVC_PSR:
6043 case OP_COND:
6044 case OP_oBARRIER:
6045 case OP_REGLST:
6046 case OP_VRSLST:
6047 case OP_VRDLST:
6048 case OP_VRSDLST:
6049 case OP_NRDLST:
6050 case OP_NSTRLST:
6051 if (val == FAIL)
6052 goto failure;
6053 inst.operands[i].imm = val;
6054 break;
6055
6056 default:
6057 break;
6058 }
6059
6060 /* If we get here, this operand was successfully parsed. */
6061 inst.operands[i].present = 1;
6062 continue;
6063
6064 bad_args:
6065 inst.error = BAD_ARGS;
6066
6067 failure:
6068 if (!backtrack_pos)
6069 {
6070 /* The parse routine should already have set inst.error, but set a
6071 default here just in case. */
6072 if (!inst.error)
6073 inst.error = _("syntax error");
6074 return FAIL;
6075 }
6076
6077 /* Do not backtrack over a trailing optional argument that
6078 absorbed some text. We will only fail again, with the
6079 'garbage following instruction' error message, which is
6080 probably less helpful than the current one. */
6081 if (backtrack_index == i && backtrack_pos != str
6082 && upat[i+1] == OP_stop)
6083 {
6084 if (!inst.error)
6085 inst.error = _("syntax error");
6086 return FAIL;
6087 }
6088
6089 /* Try again, skipping the optional argument at backtrack_pos. */
6090 str = backtrack_pos;
6091 inst.error = backtrack_error;
6092 inst.operands[backtrack_index].present = 0;
6093 i = backtrack_index;
6094 backtrack_pos = 0;
6095 }
6096
6097 /* Check that we have parsed all the arguments. */
6098 if (*str != '\0' && !inst.error)
6099 inst.error = _("garbage following instruction");
6100
6101 return inst.error ? FAIL : SUCCESS;
6102 }
6103
6104 #undef po_char_or_fail
6105 #undef po_reg_or_fail
6106 #undef po_reg_or_goto
6107 #undef po_imm_or_fail
6108 #undef po_scalar_or_fail
6109 \f
6110 /* Shorthand macro for instruction encoding functions issuing errors. */
6111 #define constraint(expr, err) do { \
6112 if (expr) \
6113 { \
6114 inst.error = err; \
6115 return; \
6116 } \
6117 } while (0)
6118
6119 /* Functions for operand encoding. ARM, then Thumb. */
6120
6121 #define rotate_left(v, n) (v << n | v >> (32 - n))
6122
6123 /* If VAL can be encoded in the immediate field of an ARM instruction,
6124 return the encoded form. Otherwise, return FAIL. */
6125
6126 static unsigned int
6127 encode_arm_immediate (unsigned int val)
6128 {
6129 unsigned int a, i;
6130
6131 for (i = 0; i < 32; i += 2)
6132 if ((a = rotate_left (val, i)) <= 0xff)
6133 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6134
6135 return FAIL;
6136 }
6137
6138 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6139 return the encoded form. Otherwise, return FAIL. */
6140 static unsigned int
6141 encode_thumb32_immediate (unsigned int val)
6142 {
6143 unsigned int a, i;
6144
6145 if (val <= 0xff)
6146 return val;
6147
6148 for (i = 1; i <= 24; i++)
6149 {
6150 a = val >> i;
6151 if ((val & ~(0xff << i)) == 0)
6152 return ((val >> i) & 0x7f) | ((32 - i) << 7);
6153 }
6154
6155 a = val & 0xff;
6156 if (val == ((a << 16) | a))
6157 return 0x100 | a;
6158 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6159 return 0x300 | a;
6160
6161 a = val & 0xff00;
6162 if (val == ((a << 16) | a))
6163 return 0x200 | (a >> 8);
6164
6165 return FAIL;
6166 }
6167 /* Encode a VFP SP or DP register number into inst.instruction. */
6168
6169 static void
6170 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6171 {
6172 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6173 && reg > 15)
6174 {
6175 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
6176 {
6177 if (thumb_mode)
6178 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
6179 fpu_vfp_ext_d32);
6180 else
6181 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
6182 fpu_vfp_ext_d32);
6183 }
6184 else
6185 {
6186 first_error (_("D register out of range for selected VFP version"));
6187 return;
6188 }
6189 }
6190
6191 switch (pos)
6192 {
6193 case VFP_REG_Sd:
6194 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6195 break;
6196
6197 case VFP_REG_Sn:
6198 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6199 break;
6200
6201 case VFP_REG_Sm:
6202 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6203 break;
6204
6205 case VFP_REG_Dd:
6206 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6207 break;
6208
6209 case VFP_REG_Dn:
6210 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6211 break;
6212
6213 case VFP_REG_Dm:
6214 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6215 break;
6216
6217 default:
6218 abort ();
6219 }
6220 }
6221
6222 /* Encode a <shift> in an ARM-format instruction. The immediate,
6223 if any, is handled by md_apply_fix. */
6224 static void
6225 encode_arm_shift (int i)
6226 {
6227 if (inst.operands[i].shift_kind == SHIFT_RRX)
6228 inst.instruction |= SHIFT_ROR << 5;
6229 else
6230 {
6231 inst.instruction |= inst.operands[i].shift_kind << 5;
6232 if (inst.operands[i].immisreg)
6233 {
6234 inst.instruction |= SHIFT_BY_REG;
6235 inst.instruction |= inst.operands[i].imm << 8;
6236 }
6237 else
6238 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6239 }
6240 }
6241
6242 static void
6243 encode_arm_shifter_operand (int i)
6244 {
6245 if (inst.operands[i].isreg)
6246 {
6247 inst.instruction |= inst.operands[i].reg;
6248 encode_arm_shift (i);
6249 }
6250 else
6251 inst.instruction |= INST_IMMEDIATE;
6252 }
6253
6254 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
6255 static void
6256 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
6257 {
6258 assert (inst.operands[i].isreg);
6259 inst.instruction |= inst.operands[i].reg << 16;
6260
6261 if (inst.operands[i].preind)
6262 {
6263 if (is_t)
6264 {
6265 inst.error = _("instruction does not accept preindexed addressing");
6266 return;
6267 }
6268 inst.instruction |= PRE_INDEX;
6269 if (inst.operands[i].writeback)
6270 inst.instruction |= WRITE_BACK;
6271
6272 }
6273 else if (inst.operands[i].postind)
6274 {
6275 assert (inst.operands[i].writeback);
6276 if (is_t)
6277 inst.instruction |= WRITE_BACK;
6278 }
6279 else /* unindexed - only for coprocessor */
6280 {
6281 inst.error = _("instruction does not accept unindexed addressing");
6282 return;
6283 }
6284
6285 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6286 && (((inst.instruction & 0x000f0000) >> 16)
6287 == ((inst.instruction & 0x0000f000) >> 12)))
6288 as_warn ((inst.instruction & LOAD_BIT)
6289 ? _("destination register same as write-back base")
6290 : _("source register same as write-back base"));
6291 }
6292
6293 /* inst.operands[i] was set up by parse_address. Encode it into an
6294 ARM-format mode 2 load or store instruction. If is_t is true,
6295 reject forms that cannot be used with a T instruction (i.e. not
6296 post-indexed). */
6297 static void
6298 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
6299 {
6300 encode_arm_addr_mode_common (i, is_t);
6301
6302 if (inst.operands[i].immisreg)
6303 {
6304 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6305 inst.instruction |= inst.operands[i].imm;
6306 if (!inst.operands[i].negative)
6307 inst.instruction |= INDEX_UP;
6308 if (inst.operands[i].shifted)
6309 {
6310 if (inst.operands[i].shift_kind == SHIFT_RRX)
6311 inst.instruction |= SHIFT_ROR << 5;
6312 else
6313 {
6314 inst.instruction |= inst.operands[i].shift_kind << 5;
6315 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6316 }
6317 }
6318 }
6319 else /* immediate offset in inst.reloc */
6320 {
6321 if (inst.reloc.type == BFD_RELOC_UNUSED)
6322 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
6323 }
6324 }
6325
6326 /* inst.operands[i] was set up by parse_address. Encode it into an
6327 ARM-format mode 3 load or store instruction. Reject forms that
6328 cannot be used with such instructions. If is_t is true, reject
6329 forms that cannot be used with a T instruction (i.e. not
6330 post-indexed). */
6331 static void
6332 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
6333 {
6334 if (inst.operands[i].immisreg && inst.operands[i].shifted)
6335 {
6336 inst.error = _("instruction does not accept scaled register index");
6337 return;
6338 }
6339
6340 encode_arm_addr_mode_common (i, is_t);
6341
6342 if (inst.operands[i].immisreg)
6343 {
6344 inst.instruction |= inst.operands[i].imm;
6345 if (!inst.operands[i].negative)
6346 inst.instruction |= INDEX_UP;
6347 }
6348 else /* immediate offset in inst.reloc */
6349 {
6350 inst.instruction |= HWOFFSET_IMM;
6351 if (inst.reloc.type == BFD_RELOC_UNUSED)
6352 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
6353 }
6354 }
6355
6356 /* inst.operands[i] was set up by parse_address. Encode it into an
6357 ARM-format instruction. Reject all forms which cannot be encoded
6358 into a coprocessor load/store instruction. If wb_ok is false,
6359 reject use of writeback; if unind_ok is false, reject use of
6360 unindexed addressing. If reloc_override is not 0, use it instead
6361 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6362 (in which case it is preserved). */
6363
6364 static int
6365 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
6366 {
6367 inst.instruction |= inst.operands[i].reg << 16;
6368
6369 assert (!(inst.operands[i].preind && inst.operands[i].postind));
6370
6371 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
6372 {
6373 assert (!inst.operands[i].writeback);
6374 if (!unind_ok)
6375 {
6376 inst.error = _("instruction does not support unindexed addressing");
6377 return FAIL;
6378 }
6379 inst.instruction |= inst.operands[i].imm;
6380 inst.instruction |= INDEX_UP;
6381 return SUCCESS;
6382 }
6383
6384 if (inst.operands[i].preind)
6385 inst.instruction |= PRE_INDEX;
6386
6387 if (inst.operands[i].writeback)
6388 {
6389 if (inst.operands[i].reg == REG_PC)
6390 {
6391 inst.error = _("pc may not be used with write-back");
6392 return FAIL;
6393 }
6394 if (!wb_ok)
6395 {
6396 inst.error = _("instruction does not support writeback");
6397 return FAIL;
6398 }
6399 inst.instruction |= WRITE_BACK;
6400 }
6401
6402 if (reloc_override)
6403 inst.reloc.type = reloc_override;
6404 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6405 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6406 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6407 {
6408 if (thumb_mode)
6409 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6410 else
6411 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6412 }
6413
6414 return SUCCESS;
6415 }
6416
6417 /* inst.reloc.exp describes an "=expr" load pseudo-operation.
6418 Determine whether it can be performed with a move instruction; if
6419 it can, convert inst.instruction to that move instruction and
6420 return 1; if it can't, convert inst.instruction to a literal-pool
6421 load and return 0. If this is not a valid thing to do in the
6422 current context, set inst.error and return 1.
6423
6424 inst.operands[i] describes the destination register. */
6425
6426 static int
6427 move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6428 {
6429 unsigned long tbit;
6430
6431 if (thumb_p)
6432 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6433 else
6434 tbit = LOAD_BIT;
6435
6436 if ((inst.instruction & tbit) == 0)
6437 {
6438 inst.error = _("invalid pseudo operation");
6439 return 1;
6440 }
6441 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
6442 {
6443 inst.error = _("constant expression expected");
6444 return 1;
6445 }
6446 if (inst.reloc.exp.X_op == O_constant)
6447 {
6448 if (thumb_p)
6449 {
6450 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
6451 {
6452 /* This can be done with a mov(1) instruction. */
6453 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6454 inst.instruction |= inst.reloc.exp.X_add_number;
6455 return 1;
6456 }
6457 }
6458 else
6459 {
6460 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6461 if (value != FAIL)
6462 {
6463 /* This can be done with a mov instruction. */
6464 inst.instruction &= LITERAL_MASK;
6465 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6466 inst.instruction |= value & 0xfff;
6467 return 1;
6468 }
6469
6470 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6471 if (value != FAIL)
6472 {
6473 /* This can be done with a mvn instruction. */
6474 inst.instruction &= LITERAL_MASK;
6475 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6476 inst.instruction |= value & 0xfff;
6477 return 1;
6478 }
6479 }
6480 }
6481
6482 if (add_to_lit_pool () == FAIL)
6483 {
6484 inst.error = _("literal pool insertion failed");
6485 return 1;
6486 }
6487 inst.operands[1].reg = REG_PC;
6488 inst.operands[1].isreg = 1;
6489 inst.operands[1].preind = 1;
6490 inst.reloc.pc_rel = 1;
6491 inst.reloc.type = (thumb_p
6492 ? BFD_RELOC_ARM_THUMB_OFFSET
6493 : (mode_3
6494 ? BFD_RELOC_ARM_HWLITERAL
6495 : BFD_RELOC_ARM_LITERAL));
6496 return 0;
6497 }
6498
6499 /* Functions for instruction encoding, sorted by sub-architecture.
6500 First some generics; their names are taken from the conventional
6501 bit positions for register arguments in ARM format instructions. */
6502
6503 static void
6504 do_noargs (void)
6505 {
6506 }
6507
6508 static void
6509 do_rd (void)
6510 {
6511 inst.instruction |= inst.operands[0].reg << 12;
6512 }
6513
6514 static void
6515 do_rd_rm (void)
6516 {
6517 inst.instruction |= inst.operands[0].reg << 12;
6518 inst.instruction |= inst.operands[1].reg;
6519 }
6520
6521 static void
6522 do_rd_rn (void)
6523 {
6524 inst.instruction |= inst.operands[0].reg << 12;
6525 inst.instruction |= inst.operands[1].reg << 16;
6526 }
6527
6528 static void
6529 do_rn_rd (void)
6530 {
6531 inst.instruction |= inst.operands[0].reg << 16;
6532 inst.instruction |= inst.operands[1].reg << 12;
6533 }
6534
6535 static void
6536 do_rd_rm_rn (void)
6537 {
6538 unsigned Rn = inst.operands[2].reg;
6539 /* Enforce restrictions on SWP instruction. */
6540 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6541 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6542 _("Rn must not overlap other operands"));
6543 inst.instruction |= inst.operands[0].reg << 12;
6544 inst.instruction |= inst.operands[1].reg;
6545 inst.instruction |= Rn << 16;
6546 }
6547
6548 static void
6549 do_rd_rn_rm (void)
6550 {
6551 inst.instruction |= inst.operands[0].reg << 12;
6552 inst.instruction |= inst.operands[1].reg << 16;
6553 inst.instruction |= inst.operands[2].reg;
6554 }
6555
6556 static void
6557 do_rm_rd_rn (void)
6558 {
6559 inst.instruction |= inst.operands[0].reg;
6560 inst.instruction |= inst.operands[1].reg << 12;
6561 inst.instruction |= inst.operands[2].reg << 16;
6562 }
6563
6564 static void
6565 do_imm0 (void)
6566 {
6567 inst.instruction |= inst.operands[0].imm;
6568 }
6569
6570 static void
6571 do_rd_cpaddr (void)
6572 {
6573 inst.instruction |= inst.operands[0].reg << 12;
6574 encode_arm_cp_address (1, TRUE, TRUE, 0);
6575 }
6576
6577 /* ARM instructions, in alphabetical order by function name (except
6578 that wrapper functions appear immediately after the function they
6579 wrap). */
6580
6581 /* This is a pseudo-op of the form "adr rd, label" to be converted
6582 into a relative address of the form "add rd, pc, #label-.-8". */
6583
6584 static void
6585 do_adr (void)
6586 {
6587 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
6588
6589 /* Frag hacking will turn this into a sub instruction if the offset turns
6590 out to be negative. */
6591 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
6592 inst.reloc.pc_rel = 1;
6593 inst.reloc.exp.X_add_number -= 8;
6594 }
6595
6596 /* This is a pseudo-op of the form "adrl rd, label" to be converted
6597 into a relative address of the form:
6598 add rd, pc, #low(label-.-8)"
6599 add rd, rd, #high(label-.-8)" */
6600
6601 static void
6602 do_adrl (void)
6603 {
6604 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
6605
6606 /* Frag hacking will turn this into a sub instruction if the offset turns
6607 out to be negative. */
6608 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
6609 inst.reloc.pc_rel = 1;
6610 inst.size = INSN_SIZE * 2;
6611 inst.reloc.exp.X_add_number -= 8;
6612 }
6613
6614 static void
6615 do_arit (void)
6616 {
6617 if (!inst.operands[1].present)
6618 inst.operands[1].reg = inst.operands[0].reg;
6619 inst.instruction |= inst.operands[0].reg << 12;
6620 inst.instruction |= inst.operands[1].reg << 16;
6621 encode_arm_shifter_operand (2);
6622 }
6623
6624 static void
6625 do_barrier (void)
6626 {
6627 if (inst.operands[0].present)
6628 {
6629 constraint ((inst.instruction & 0xf0) != 0x40
6630 && inst.operands[0].imm != 0xf,
6631 _("bad barrier type"));
6632 inst.instruction |= inst.operands[0].imm;
6633 }
6634 else
6635 inst.instruction |= 0xf;
6636 }
6637
6638 static void
6639 do_bfc (void)
6640 {
6641 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6642 constraint (msb > 32, _("bit-field extends past end of register"));
6643 /* The instruction encoding stores the LSB and MSB,
6644 not the LSB and width. */
6645 inst.instruction |= inst.operands[0].reg << 12;
6646 inst.instruction |= inst.operands[1].imm << 7;
6647 inst.instruction |= (msb - 1) << 16;
6648 }
6649
6650 static void
6651 do_bfi (void)
6652 {
6653 unsigned int msb;
6654
6655 /* #0 in second position is alternative syntax for bfc, which is
6656 the same instruction but with REG_PC in the Rm field. */
6657 if (!inst.operands[1].isreg)
6658 inst.operands[1].reg = REG_PC;
6659
6660 msb = inst.operands[2].imm + inst.operands[3].imm;
6661 constraint (msb > 32, _("bit-field extends past end of register"));
6662 /* The instruction encoding stores the LSB and MSB,
6663 not the LSB and width. */
6664 inst.instruction |= inst.operands[0].reg << 12;
6665 inst.instruction |= inst.operands[1].reg;
6666 inst.instruction |= inst.operands[2].imm << 7;
6667 inst.instruction |= (msb - 1) << 16;
6668 }
6669
6670 static void
6671 do_bfx (void)
6672 {
6673 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6674 _("bit-field extends past end of register"));
6675 inst.instruction |= inst.operands[0].reg << 12;
6676 inst.instruction |= inst.operands[1].reg;
6677 inst.instruction |= inst.operands[2].imm << 7;
6678 inst.instruction |= (inst.operands[3].imm - 1) << 16;
6679 }
6680
6681 /* ARM V5 breakpoint instruction (argument parse)
6682 BKPT <16 bit unsigned immediate>
6683 Instruction is not conditional.
6684 The bit pattern given in insns[] has the COND_ALWAYS condition,
6685 and it is an error if the caller tried to override that. */
6686
6687 static void
6688 do_bkpt (void)
6689 {
6690 /* Top 12 of 16 bits to bits 19:8. */
6691 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
6692
6693 /* Bottom 4 of 16 bits to bits 3:0. */
6694 inst.instruction |= inst.operands[0].imm & 0xf;
6695 }
6696
6697 static void
6698 encode_branch (int default_reloc)
6699 {
6700 if (inst.operands[0].hasreloc)
6701 {
6702 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
6703 _("the only suffix valid here is '(plt)'"));
6704 inst.reloc.type = BFD_RELOC_ARM_PLT32;
6705 }
6706 else
6707 {
6708 inst.reloc.type = default_reloc;
6709 }
6710 inst.reloc.pc_rel = 1;
6711 }
6712
6713 static void
6714 do_branch (void)
6715 {
6716 #ifdef OBJ_ELF
6717 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6718 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6719 else
6720 #endif
6721 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6722 }
6723
6724 static void
6725 do_bl (void)
6726 {
6727 #ifdef OBJ_ELF
6728 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6729 {
6730 if (inst.cond == COND_ALWAYS)
6731 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6732 else
6733 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6734 }
6735 else
6736 #endif
6737 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6738 }
6739
6740 /* ARM V5 branch-link-exchange instruction (argument parse)
6741 BLX <target_addr> ie BLX(1)
6742 BLX{<condition>} <Rm> ie BLX(2)
6743 Unfortunately, there are two different opcodes for this mnemonic.
6744 So, the insns[].value is not used, and the code here zaps values
6745 into inst.instruction.
6746 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
6747
6748 static void
6749 do_blx (void)
6750 {
6751 if (inst.operands[0].isreg)
6752 {
6753 /* Arg is a register; the opcode provided by insns[] is correct.
6754 It is not illegal to do "blx pc", just useless. */
6755 if (inst.operands[0].reg == REG_PC)
6756 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
6757
6758 inst.instruction |= inst.operands[0].reg;
6759 }
6760 else
6761 {
6762 /* Arg is an address; this instruction cannot be executed
6763 conditionally, and the opcode must be adjusted. */
6764 constraint (inst.cond != COND_ALWAYS, BAD_COND);
6765 inst.instruction = 0xfa000000;
6766 #ifdef OBJ_ELF
6767 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6768 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6769 else
6770 #endif
6771 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
6772 }
6773 }
6774
6775 static void
6776 do_bx (void)
6777 {
6778 bfd_boolean want_reloc;
6779
6780 if (inst.operands[0].reg == REG_PC)
6781 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
6782
6783 inst.instruction |= inst.operands[0].reg;
6784 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
6785 it is for ARMv4t or earlier. */
6786 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
6787 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
6788 want_reloc = TRUE;
6789
6790 #ifdef OBJ_ELF
6791 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
6792 #endif
6793 want_reloc = FALSE;
6794
6795 if (want_reloc)
6796 inst.reloc.type = BFD_RELOC_ARM_V4BX;
6797 }
6798
6799
6800 /* ARM v5TEJ. Jump to Jazelle code. */
6801
6802 static void
6803 do_bxj (void)
6804 {
6805 if (inst.operands[0].reg == REG_PC)
6806 as_tsktsk (_("use of r15 in bxj is not really useful"));
6807
6808 inst.instruction |= inst.operands[0].reg;
6809 }
6810
6811 /* Co-processor data operation:
6812 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
6813 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
6814 static void
6815 do_cdp (void)
6816 {
6817 inst.instruction |= inst.operands[0].reg << 8;
6818 inst.instruction |= inst.operands[1].imm << 20;
6819 inst.instruction |= inst.operands[2].reg << 12;
6820 inst.instruction |= inst.operands[3].reg << 16;
6821 inst.instruction |= inst.operands[4].reg;
6822 inst.instruction |= inst.operands[5].imm << 5;
6823 }
6824
6825 static void
6826 do_cmp (void)
6827 {
6828 inst.instruction |= inst.operands[0].reg << 16;
6829 encode_arm_shifter_operand (1);
6830 }
6831
6832 /* Transfer between coprocessor and ARM registers.
6833 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
6834 MRC2
6835 MCR{cond}
6836 MCR2
6837
6838 No special properties. */
6839
6840 static void
6841 do_co_reg (void)
6842 {
6843 inst.instruction |= inst.operands[0].reg << 8;
6844 inst.instruction |= inst.operands[1].imm << 21;
6845 inst.instruction |= inst.operands[2].reg << 12;
6846 inst.instruction |= inst.operands[3].reg << 16;
6847 inst.instruction |= inst.operands[4].reg;
6848 inst.instruction |= inst.operands[5].imm << 5;
6849 }
6850
6851 /* Transfer between coprocessor register and pair of ARM registers.
6852 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
6853 MCRR2
6854 MRRC{cond}
6855 MRRC2
6856
6857 Two XScale instructions are special cases of these:
6858
6859 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
6860 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
6861
6862 Result unpredictable if Rd or Rn is R15. */
6863
6864 static void
6865 do_co_reg2c (void)
6866 {
6867 inst.instruction |= inst.operands[0].reg << 8;
6868 inst.instruction |= inst.operands[1].imm << 4;
6869 inst.instruction |= inst.operands[2].reg << 12;
6870 inst.instruction |= inst.operands[3].reg << 16;
6871 inst.instruction |= inst.operands[4].reg;
6872 }
6873
6874 static void
6875 do_cpsi (void)
6876 {
6877 inst.instruction |= inst.operands[0].imm << 6;
6878 if (inst.operands[1].present)
6879 {
6880 inst.instruction |= CPSI_MMOD;
6881 inst.instruction |= inst.operands[1].imm;
6882 }
6883 }
6884
6885 static void
6886 do_dbg (void)
6887 {
6888 inst.instruction |= inst.operands[0].imm;
6889 }
6890
6891 static void
6892 do_it (void)
6893 {
6894 /* There is no IT instruction in ARM mode. We
6895 process it but do not generate code for it. */
6896 inst.size = 0;
6897 }
6898
6899 static void
6900 do_ldmstm (void)
6901 {
6902 int base_reg = inst.operands[0].reg;
6903 int range = inst.operands[1].imm;
6904
6905 inst.instruction |= base_reg << 16;
6906 inst.instruction |= range;
6907
6908 if (inst.operands[1].writeback)
6909 inst.instruction |= LDM_TYPE_2_OR_3;
6910
6911 if (inst.operands[0].writeback)
6912 {
6913 inst.instruction |= WRITE_BACK;
6914 /* Check for unpredictable uses of writeback. */
6915 if (inst.instruction & LOAD_BIT)
6916 {
6917 /* Not allowed in LDM type 2. */
6918 if ((inst.instruction & LDM_TYPE_2_OR_3)
6919 && ((range & (1 << REG_PC)) == 0))
6920 as_warn (_("writeback of base register is UNPREDICTABLE"));
6921 /* Only allowed if base reg not in list for other types. */
6922 else if (range & (1 << base_reg))
6923 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
6924 }
6925 else /* STM. */
6926 {
6927 /* Not allowed for type 2. */
6928 if (inst.instruction & LDM_TYPE_2_OR_3)
6929 as_warn (_("writeback of base register is UNPREDICTABLE"));
6930 /* Only allowed if base reg not in list, or first in list. */
6931 else if ((range & (1 << base_reg))
6932 && (range & ((1 << base_reg) - 1)))
6933 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
6934 }
6935 }
6936 }
6937
6938 /* ARMv5TE load-consecutive (argument parse)
6939 Mode is like LDRH.
6940
6941 LDRccD R, mode
6942 STRccD R, mode. */
6943
6944 static void
6945 do_ldrd (void)
6946 {
6947 constraint (inst.operands[0].reg % 2 != 0,
6948 _("first destination register must be even"));
6949 constraint (inst.operands[1].present
6950 && inst.operands[1].reg != inst.operands[0].reg + 1,
6951 _("can only load two consecutive registers"));
6952 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
6953 constraint (!inst.operands[2].isreg, _("'[' expected"));
6954
6955 if (!inst.operands[1].present)
6956 inst.operands[1].reg = inst.operands[0].reg + 1;
6957
6958 if (inst.instruction & LOAD_BIT)
6959 {
6960 /* encode_arm_addr_mode_3 will diagnose overlap between the base
6961 register and the first register written; we have to diagnose
6962 overlap between the base and the second register written here. */
6963
6964 if (inst.operands[2].reg == inst.operands[1].reg
6965 && (inst.operands[2].writeback || inst.operands[2].postind))
6966 as_warn (_("base register written back, and overlaps "
6967 "second destination register"));
6968
6969 /* For an index-register load, the index register must not overlap the
6970 destination (even if not write-back). */
6971 else if (inst.operands[2].immisreg
6972 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
6973 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
6974 as_warn (_("index register overlaps destination register"));
6975 }
6976
6977 inst.instruction |= inst.operands[0].reg << 12;
6978 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
6979 }
6980
6981 static void
6982 do_ldrex (void)
6983 {
6984 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
6985 || inst.operands[1].postind || inst.operands[1].writeback
6986 || inst.operands[1].immisreg || inst.operands[1].shifted
6987 || inst.operands[1].negative
6988 /* This can arise if the programmer has written
6989 strex rN, rM, foo
6990 or if they have mistakenly used a register name as the last
6991 operand, eg:
6992 strex rN, rM, rX
6993 It is very difficult to distinguish between these two cases
6994 because "rX" might actually be a label. ie the register
6995 name has been occluded by a symbol of the same name. So we
6996 just generate a general 'bad addressing mode' type error
6997 message and leave it up to the programmer to discover the
6998 true cause and fix their mistake. */
6999 || (inst.operands[1].reg == REG_PC),
7000 BAD_ADDR_MODE);
7001
7002 constraint (inst.reloc.exp.X_op != O_constant
7003 || inst.reloc.exp.X_add_number != 0,
7004 _("offset must be zero in ARM encoding"));
7005
7006 inst.instruction |= inst.operands[0].reg << 12;
7007 inst.instruction |= inst.operands[1].reg << 16;
7008 inst.reloc.type = BFD_RELOC_UNUSED;
7009 }
7010
7011 static void
7012 do_ldrexd (void)
7013 {
7014 constraint (inst.operands[0].reg % 2 != 0,
7015 _("even register required"));
7016 constraint (inst.operands[1].present
7017 && inst.operands[1].reg != inst.operands[0].reg + 1,
7018 _("can only load two consecutive registers"));
7019 /* If op 1 were present and equal to PC, this function wouldn't
7020 have been called in the first place. */
7021 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7022
7023 inst.instruction |= inst.operands[0].reg << 12;
7024 inst.instruction |= inst.operands[2].reg << 16;
7025 }
7026
7027 static void
7028 do_ldst (void)
7029 {
7030 inst.instruction |= inst.operands[0].reg << 12;
7031 if (!inst.operands[1].isreg)
7032 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
7033 return;
7034 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
7035 }
7036
7037 static void
7038 do_ldstt (void)
7039 {
7040 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7041 reject [Rn,...]. */
7042 if (inst.operands[1].preind)
7043 {
7044 constraint (inst.reloc.exp.X_op != O_constant
7045 || inst.reloc.exp.X_add_number != 0,
7046 _("this instruction requires a post-indexed address"));
7047
7048 inst.operands[1].preind = 0;
7049 inst.operands[1].postind = 1;
7050 inst.operands[1].writeback = 1;
7051 }
7052 inst.instruction |= inst.operands[0].reg << 12;
7053 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7054 }
7055
7056 /* Halfword and signed-byte load/store operations. */
7057
7058 static void
7059 do_ldstv4 (void)
7060 {
7061 inst.instruction |= inst.operands[0].reg << 12;
7062 if (!inst.operands[1].isreg)
7063 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
7064 return;
7065 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
7066 }
7067
7068 static void
7069 do_ldsttv4 (void)
7070 {
7071 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7072 reject [Rn,...]. */
7073 if (inst.operands[1].preind)
7074 {
7075 constraint (inst.reloc.exp.X_op != O_constant
7076 || inst.reloc.exp.X_add_number != 0,
7077 _("this instruction requires a post-indexed address"));
7078
7079 inst.operands[1].preind = 0;
7080 inst.operands[1].postind = 1;
7081 inst.operands[1].writeback = 1;
7082 }
7083 inst.instruction |= inst.operands[0].reg << 12;
7084 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7085 }
7086
7087 /* Co-processor register load/store.
7088 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7089 static void
7090 do_lstc (void)
7091 {
7092 inst.instruction |= inst.operands[0].reg << 8;
7093 inst.instruction |= inst.operands[1].reg << 12;
7094 encode_arm_cp_address (2, TRUE, TRUE, 0);
7095 }
7096
7097 static void
7098 do_mlas (void)
7099 {
7100 /* This restriction does not apply to mls (nor to mla in v6 or later). */
7101 if (inst.operands[0].reg == inst.operands[1].reg
7102 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
7103 && !(inst.instruction & 0x00400000))
7104 as_tsktsk (_("Rd and Rm should be different in mla"));
7105
7106 inst.instruction |= inst.operands[0].reg << 16;
7107 inst.instruction |= inst.operands[1].reg;
7108 inst.instruction |= inst.operands[2].reg << 8;
7109 inst.instruction |= inst.operands[3].reg << 12;
7110 }
7111
7112 static void
7113 do_mov (void)
7114 {
7115 inst.instruction |= inst.operands[0].reg << 12;
7116 encode_arm_shifter_operand (1);
7117 }
7118
7119 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7120 static void
7121 do_mov16 (void)
7122 {
7123 bfd_vma imm;
7124 bfd_boolean top;
7125
7126 top = (inst.instruction & 0x00400000) != 0;
7127 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7128 _(":lower16: not allowed this instruction"));
7129 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7130 _(":upper16: not allowed instruction"));
7131 inst.instruction |= inst.operands[0].reg << 12;
7132 if (inst.reloc.type == BFD_RELOC_UNUSED)
7133 {
7134 imm = inst.reloc.exp.X_add_number;
7135 /* The value is in two pieces: 0:11, 16:19. */
7136 inst.instruction |= (imm & 0x00000fff);
7137 inst.instruction |= (imm & 0x0000f000) << 4;
7138 }
7139 }
7140
7141 static void do_vfp_nsyn_opcode (const char *);
7142
7143 static int
7144 do_vfp_nsyn_mrs (void)
7145 {
7146 if (inst.operands[0].isvec)
7147 {
7148 if (inst.operands[1].reg != 1)
7149 first_error (_("operand 1 must be FPSCR"));
7150 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7151 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7152 do_vfp_nsyn_opcode ("fmstat");
7153 }
7154 else if (inst.operands[1].isvec)
7155 do_vfp_nsyn_opcode ("fmrx");
7156 else
7157 return FAIL;
7158
7159 return SUCCESS;
7160 }
7161
7162 static int
7163 do_vfp_nsyn_msr (void)
7164 {
7165 if (inst.operands[0].isvec)
7166 do_vfp_nsyn_opcode ("fmxr");
7167 else
7168 return FAIL;
7169
7170 return SUCCESS;
7171 }
7172
7173 static void
7174 do_mrs (void)
7175 {
7176 if (do_vfp_nsyn_mrs () == SUCCESS)
7177 return;
7178
7179 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7180 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7181 != (PSR_c|PSR_f),
7182 _("'CPSR' or 'SPSR' expected"));
7183 inst.instruction |= inst.operands[0].reg << 12;
7184 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7185 }
7186
7187 /* Two possible forms:
7188 "{C|S}PSR_<field>, Rm",
7189 "{C|S}PSR_f, #expression". */
7190
7191 static void
7192 do_msr (void)
7193 {
7194 if (do_vfp_nsyn_msr () == SUCCESS)
7195 return;
7196
7197 inst.instruction |= inst.operands[0].imm;
7198 if (inst.operands[1].isreg)
7199 inst.instruction |= inst.operands[1].reg;
7200 else
7201 {
7202 inst.instruction |= INST_IMMEDIATE;
7203 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7204 inst.reloc.pc_rel = 0;
7205 }
7206 }
7207
7208 static void
7209 do_mul (void)
7210 {
7211 if (!inst.operands[2].present)
7212 inst.operands[2].reg = inst.operands[0].reg;
7213 inst.instruction |= inst.operands[0].reg << 16;
7214 inst.instruction |= inst.operands[1].reg;
7215 inst.instruction |= inst.operands[2].reg << 8;
7216
7217 if (inst.operands[0].reg == inst.operands[1].reg
7218 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7219 as_tsktsk (_("Rd and Rm should be different in mul"));
7220 }
7221
7222 /* Long Multiply Parser
7223 UMULL RdLo, RdHi, Rm, Rs
7224 SMULL RdLo, RdHi, Rm, Rs
7225 UMLAL RdLo, RdHi, Rm, Rs
7226 SMLAL RdLo, RdHi, Rm, Rs. */
7227
7228 static void
7229 do_mull (void)
7230 {
7231 inst.instruction |= inst.operands[0].reg << 12;
7232 inst.instruction |= inst.operands[1].reg << 16;
7233 inst.instruction |= inst.operands[2].reg;
7234 inst.instruction |= inst.operands[3].reg << 8;
7235
7236 /* rdhi and rdlo must be different. */
7237 if (inst.operands[0].reg == inst.operands[1].reg)
7238 as_tsktsk (_("rdhi and rdlo must be different"));
7239
7240 /* rdhi, rdlo and rm must all be different before armv6. */
7241 if ((inst.operands[0].reg == inst.operands[2].reg
7242 || inst.operands[1].reg == inst.operands[2].reg)
7243 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7244 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7245 }
7246
7247 static void
7248 do_nop (void)
7249 {
7250 if (inst.operands[0].present)
7251 {
7252 /* Architectural NOP hints are CPSR sets with no bits selected. */
7253 inst.instruction &= 0xf0000000;
7254 inst.instruction |= 0x0320f000 + inst.operands[0].imm;
7255 }
7256 }
7257
7258 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7259 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7260 Condition defaults to COND_ALWAYS.
7261 Error if Rd, Rn or Rm are R15. */
7262
7263 static void
7264 do_pkhbt (void)
7265 {
7266 inst.instruction |= inst.operands[0].reg << 12;
7267 inst.instruction |= inst.operands[1].reg << 16;
7268 inst.instruction |= inst.operands[2].reg;
7269 if (inst.operands[3].present)
7270 encode_arm_shift (3);
7271 }
7272
7273 /* ARM V6 PKHTB (Argument Parse). */
7274
7275 static void
7276 do_pkhtb (void)
7277 {
7278 if (!inst.operands[3].present)
7279 {
7280 /* If the shift specifier is omitted, turn the instruction
7281 into pkhbt rd, rm, rn. */
7282 inst.instruction &= 0xfff00010;
7283 inst.instruction |= inst.operands[0].reg << 12;
7284 inst.instruction |= inst.operands[1].reg;
7285 inst.instruction |= inst.operands[2].reg << 16;
7286 }
7287 else
7288 {
7289 inst.instruction |= inst.operands[0].reg << 12;
7290 inst.instruction |= inst.operands[1].reg << 16;
7291 inst.instruction |= inst.operands[2].reg;
7292 encode_arm_shift (3);
7293 }
7294 }
7295
7296 /* ARMv5TE: Preload-Cache
7297
7298 PLD <addr_mode>
7299
7300 Syntactically, like LDR with B=1, W=0, L=1. */
7301
7302 static void
7303 do_pld (void)
7304 {
7305 constraint (!inst.operands[0].isreg,
7306 _("'[' expected after PLD mnemonic"));
7307 constraint (inst.operands[0].postind,
7308 _("post-indexed expression used in preload instruction"));
7309 constraint (inst.operands[0].writeback,
7310 _("writeback used in preload instruction"));
7311 constraint (!inst.operands[0].preind,
7312 _("unindexed addressing used in preload instruction"));
7313 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7314 }
7315
7316 /* ARMv7: PLI <addr_mode> */
7317 static void
7318 do_pli (void)
7319 {
7320 constraint (!inst.operands[0].isreg,
7321 _("'[' expected after PLI mnemonic"));
7322 constraint (inst.operands[0].postind,
7323 _("post-indexed expression used in preload instruction"));
7324 constraint (inst.operands[0].writeback,
7325 _("writeback used in preload instruction"));
7326 constraint (!inst.operands[0].preind,
7327 _("unindexed addressing used in preload instruction"));
7328 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7329 inst.instruction &= ~PRE_INDEX;
7330 }
7331
7332 static void
7333 do_push_pop (void)
7334 {
7335 inst.operands[1] = inst.operands[0];
7336 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7337 inst.operands[0].isreg = 1;
7338 inst.operands[0].writeback = 1;
7339 inst.operands[0].reg = REG_SP;
7340 do_ldmstm ();
7341 }
7342
7343 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7344 word at the specified address and the following word
7345 respectively.
7346 Unconditionally executed.
7347 Error if Rn is R15. */
7348
7349 static void
7350 do_rfe (void)
7351 {
7352 inst.instruction |= inst.operands[0].reg << 16;
7353 if (inst.operands[0].writeback)
7354 inst.instruction |= WRITE_BACK;
7355 }
7356
7357 /* ARM V6 ssat (argument parse). */
7358
7359 static void
7360 do_ssat (void)
7361 {
7362 inst.instruction |= inst.operands[0].reg << 12;
7363 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7364 inst.instruction |= inst.operands[2].reg;
7365
7366 if (inst.operands[3].present)
7367 encode_arm_shift (3);
7368 }
7369
7370 /* ARM V6 usat (argument parse). */
7371
7372 static void
7373 do_usat (void)
7374 {
7375 inst.instruction |= inst.operands[0].reg << 12;
7376 inst.instruction |= inst.operands[1].imm << 16;
7377 inst.instruction |= inst.operands[2].reg;
7378
7379 if (inst.operands[3].present)
7380 encode_arm_shift (3);
7381 }
7382
7383 /* ARM V6 ssat16 (argument parse). */
7384
7385 static void
7386 do_ssat16 (void)
7387 {
7388 inst.instruction |= inst.operands[0].reg << 12;
7389 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7390 inst.instruction |= inst.operands[2].reg;
7391 }
7392
7393 static void
7394 do_usat16 (void)
7395 {
7396 inst.instruction |= inst.operands[0].reg << 12;
7397 inst.instruction |= inst.operands[1].imm << 16;
7398 inst.instruction |= inst.operands[2].reg;
7399 }
7400
7401 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7402 preserving the other bits.
7403
7404 setend <endian_specifier>, where <endian_specifier> is either
7405 BE or LE. */
7406
7407 static void
7408 do_setend (void)
7409 {
7410 if (inst.operands[0].imm)
7411 inst.instruction |= 0x200;
7412 }
7413
7414 static void
7415 do_shift (void)
7416 {
7417 unsigned int Rm = (inst.operands[1].present
7418 ? inst.operands[1].reg
7419 : inst.operands[0].reg);
7420
7421 inst.instruction |= inst.operands[0].reg << 12;
7422 inst.instruction |= Rm;
7423 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
7424 {
7425 inst.instruction |= inst.operands[2].reg << 8;
7426 inst.instruction |= SHIFT_BY_REG;
7427 }
7428 else
7429 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7430 }
7431
7432 static void
7433 do_smc (void)
7434 {
7435 inst.reloc.type = BFD_RELOC_ARM_SMC;
7436 inst.reloc.pc_rel = 0;
7437 }
7438
7439 static void
7440 do_swi (void)
7441 {
7442 inst.reloc.type = BFD_RELOC_ARM_SWI;
7443 inst.reloc.pc_rel = 0;
7444 }
7445
7446 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7447 SMLAxy{cond} Rd,Rm,Rs,Rn
7448 SMLAWy{cond} Rd,Rm,Rs,Rn
7449 Error if any register is R15. */
7450
7451 static void
7452 do_smla (void)
7453 {
7454 inst.instruction |= inst.operands[0].reg << 16;
7455 inst.instruction |= inst.operands[1].reg;
7456 inst.instruction |= inst.operands[2].reg << 8;
7457 inst.instruction |= inst.operands[3].reg << 12;
7458 }
7459
7460 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7461 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7462 Error if any register is R15.
7463 Warning if Rdlo == Rdhi. */
7464
7465 static void
7466 do_smlal (void)
7467 {
7468 inst.instruction |= inst.operands[0].reg << 12;
7469 inst.instruction |= inst.operands[1].reg << 16;
7470 inst.instruction |= inst.operands[2].reg;
7471 inst.instruction |= inst.operands[3].reg << 8;
7472
7473 if (inst.operands[0].reg == inst.operands[1].reg)
7474 as_tsktsk (_("rdhi and rdlo must be different"));
7475 }
7476
7477 /* ARM V5E (El Segundo) signed-multiply (argument parse)
7478 SMULxy{cond} Rd,Rm,Rs
7479 Error if any register is R15. */
7480
7481 static void
7482 do_smul (void)
7483 {
7484 inst.instruction |= inst.operands[0].reg << 16;
7485 inst.instruction |= inst.operands[1].reg;
7486 inst.instruction |= inst.operands[2].reg << 8;
7487 }
7488
7489 /* ARM V6 srs (argument parse). The variable fields in the encoding are
7490 the same for both ARM and Thumb-2. */
7491
7492 static void
7493 do_srs (void)
7494 {
7495 int reg;
7496
7497 if (inst.operands[0].present)
7498 {
7499 reg = inst.operands[0].reg;
7500 constraint (reg != 13, _("SRS base register must be r13"));
7501 }
7502 else
7503 reg = 13;
7504
7505 inst.instruction |= reg << 16;
7506 inst.instruction |= inst.operands[1].imm;
7507 if (inst.operands[0].writeback || inst.operands[1].writeback)
7508 inst.instruction |= WRITE_BACK;
7509 }
7510
7511 /* ARM V6 strex (argument parse). */
7512
7513 static void
7514 do_strex (void)
7515 {
7516 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7517 || inst.operands[2].postind || inst.operands[2].writeback
7518 || inst.operands[2].immisreg || inst.operands[2].shifted
7519 || inst.operands[2].negative
7520 /* See comment in do_ldrex(). */
7521 || (inst.operands[2].reg == REG_PC),
7522 BAD_ADDR_MODE);
7523
7524 constraint (inst.operands[0].reg == inst.operands[1].reg
7525 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
7526
7527 constraint (inst.reloc.exp.X_op != O_constant
7528 || inst.reloc.exp.X_add_number != 0,
7529 _("offset must be zero in ARM encoding"));
7530
7531 inst.instruction |= inst.operands[0].reg << 12;
7532 inst.instruction |= inst.operands[1].reg;
7533 inst.instruction |= inst.operands[2].reg << 16;
7534 inst.reloc.type = BFD_RELOC_UNUSED;
7535 }
7536
7537 static void
7538 do_strexd (void)
7539 {
7540 constraint (inst.operands[1].reg % 2 != 0,
7541 _("even register required"));
7542 constraint (inst.operands[2].present
7543 && inst.operands[2].reg != inst.operands[1].reg + 1,
7544 _("can only store two consecutive registers"));
7545 /* If op 2 were present and equal to PC, this function wouldn't
7546 have been called in the first place. */
7547 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
7548
7549 constraint (inst.operands[0].reg == inst.operands[1].reg
7550 || inst.operands[0].reg == inst.operands[1].reg + 1
7551 || inst.operands[0].reg == inst.operands[3].reg,
7552 BAD_OVERLAP);
7553
7554 inst.instruction |= inst.operands[0].reg << 12;
7555 inst.instruction |= inst.operands[1].reg;
7556 inst.instruction |= inst.operands[3].reg << 16;
7557 }
7558
7559 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
7560 extends it to 32-bits, and adds the result to a value in another
7561 register. You can specify a rotation by 0, 8, 16, or 24 bits
7562 before extracting the 16-bit value.
7563 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
7564 Condition defaults to COND_ALWAYS.
7565 Error if any register uses R15. */
7566
7567 static void
7568 do_sxtah (void)
7569 {
7570 inst.instruction |= inst.operands[0].reg << 12;
7571 inst.instruction |= inst.operands[1].reg << 16;
7572 inst.instruction |= inst.operands[2].reg;
7573 inst.instruction |= inst.operands[3].imm << 10;
7574 }
7575
7576 /* ARM V6 SXTH.
7577
7578 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
7579 Condition defaults to COND_ALWAYS.
7580 Error if any register uses R15. */
7581
7582 static void
7583 do_sxth (void)
7584 {
7585 inst.instruction |= inst.operands[0].reg << 12;
7586 inst.instruction |= inst.operands[1].reg;
7587 inst.instruction |= inst.operands[2].imm << 10;
7588 }
7589 \f
7590 /* VFP instructions. In a logical order: SP variant first, monad
7591 before dyad, arithmetic then move then load/store. */
7592
7593 static void
7594 do_vfp_sp_monadic (void)
7595 {
7596 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7597 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
7598 }
7599
7600 static void
7601 do_vfp_sp_dyadic (void)
7602 {
7603 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7604 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7605 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
7606 }
7607
7608 static void
7609 do_vfp_sp_compare_z (void)
7610 {
7611 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7612 }
7613
7614 static void
7615 do_vfp_dp_sp_cvt (void)
7616 {
7617 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7618 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
7619 }
7620
7621 static void
7622 do_vfp_sp_dp_cvt (void)
7623 {
7624 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7625 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7626 }
7627
7628 static void
7629 do_vfp_reg_from_sp (void)
7630 {
7631 inst.instruction |= inst.operands[0].reg << 12;
7632 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7633 }
7634
7635 static void
7636 do_vfp_reg2_from_sp2 (void)
7637 {
7638 constraint (inst.operands[2].imm != 2,
7639 _("only two consecutive VFP SP registers allowed here"));
7640 inst.instruction |= inst.operands[0].reg << 12;
7641 inst.instruction |= inst.operands[1].reg << 16;
7642 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
7643 }
7644
7645 static void
7646 do_vfp_sp_from_reg (void)
7647 {
7648 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
7649 inst.instruction |= inst.operands[1].reg << 12;
7650 }
7651
7652 static void
7653 do_vfp_sp2_from_reg2 (void)
7654 {
7655 constraint (inst.operands[0].imm != 2,
7656 _("only two consecutive VFP SP registers allowed here"));
7657 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
7658 inst.instruction |= inst.operands[1].reg << 12;
7659 inst.instruction |= inst.operands[2].reg << 16;
7660 }
7661
7662 static void
7663 do_vfp_sp_ldst (void)
7664 {
7665 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7666 encode_arm_cp_address (1, FALSE, TRUE, 0);
7667 }
7668
7669 static void
7670 do_vfp_dp_ldst (void)
7671 {
7672 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7673 encode_arm_cp_address (1, FALSE, TRUE, 0);
7674 }
7675
7676
7677 static void
7678 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
7679 {
7680 if (inst.operands[0].writeback)
7681 inst.instruction |= WRITE_BACK;
7682 else
7683 constraint (ldstm_type != VFP_LDSTMIA,
7684 _("this addressing mode requires base-register writeback"));
7685 inst.instruction |= inst.operands[0].reg << 16;
7686 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
7687 inst.instruction |= inst.operands[1].imm;
7688 }
7689
7690 static void
7691 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
7692 {
7693 int count;
7694
7695 if (inst.operands[0].writeback)
7696 inst.instruction |= WRITE_BACK;
7697 else
7698 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
7699 _("this addressing mode requires base-register writeback"));
7700
7701 inst.instruction |= inst.operands[0].reg << 16;
7702 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7703
7704 count = inst.operands[1].imm << 1;
7705 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
7706 count += 1;
7707
7708 inst.instruction |= count;
7709 }
7710
7711 static void
7712 do_vfp_sp_ldstmia (void)
7713 {
7714 vfp_sp_ldstm (VFP_LDSTMIA);
7715 }
7716
7717 static void
7718 do_vfp_sp_ldstmdb (void)
7719 {
7720 vfp_sp_ldstm (VFP_LDSTMDB);
7721 }
7722
7723 static void
7724 do_vfp_dp_ldstmia (void)
7725 {
7726 vfp_dp_ldstm (VFP_LDSTMIA);
7727 }
7728
7729 static void
7730 do_vfp_dp_ldstmdb (void)
7731 {
7732 vfp_dp_ldstm (VFP_LDSTMDB);
7733 }
7734
7735 static void
7736 do_vfp_xp_ldstmia (void)
7737 {
7738 vfp_dp_ldstm (VFP_LDSTMIAX);
7739 }
7740
7741 static void
7742 do_vfp_xp_ldstmdb (void)
7743 {
7744 vfp_dp_ldstm (VFP_LDSTMDBX);
7745 }
7746
7747 static void
7748 do_vfp_dp_rd_rm (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_Dm);
7752 }
7753
7754 static void
7755 do_vfp_dp_rn_rd (void)
7756 {
7757 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
7758 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7759 }
7760
7761 static void
7762 do_vfp_dp_rd_rn (void)
7763 {
7764 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7765 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7766 }
7767
7768 static void
7769 do_vfp_dp_rd_rn_rm (void)
7770 {
7771 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7772 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7773 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
7774 }
7775
7776 static void
7777 do_vfp_dp_rd (void)
7778 {
7779 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7780 }
7781
7782 static void
7783 do_vfp_dp_rm_rd_rn (void)
7784 {
7785 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
7786 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7787 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
7788 }
7789
7790 /* VFPv3 instructions. */
7791 static void
7792 do_vfp_sp_const (void)
7793 {
7794 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7795 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7796 inst.instruction |= (inst.operands[1].imm & 0x0f);
7797 }
7798
7799 static void
7800 do_vfp_dp_const (void)
7801 {
7802 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7803 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7804 inst.instruction |= (inst.operands[1].imm & 0x0f);
7805 }
7806
7807 static void
7808 vfp_conv (int srcsize)
7809 {
7810 unsigned immbits = srcsize - inst.operands[1].imm;
7811 inst.instruction |= (immbits & 1) << 5;
7812 inst.instruction |= (immbits >> 1);
7813 }
7814
7815 static void
7816 do_vfp_sp_conv_16 (void)
7817 {
7818 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7819 vfp_conv (16);
7820 }
7821
7822 static void
7823 do_vfp_dp_conv_16 (void)
7824 {
7825 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7826 vfp_conv (16);
7827 }
7828
7829 static void
7830 do_vfp_sp_conv_32 (void)
7831 {
7832 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7833 vfp_conv (32);
7834 }
7835
7836 static void
7837 do_vfp_dp_conv_32 (void)
7838 {
7839 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7840 vfp_conv (32);
7841 }
7842 \f
7843 /* FPA instructions. Also in a logical order. */
7844
7845 static void
7846 do_fpa_cmp (void)
7847 {
7848 inst.instruction |= inst.operands[0].reg << 16;
7849 inst.instruction |= inst.operands[1].reg;
7850 }
7851
7852 static void
7853 do_fpa_ldmstm (void)
7854 {
7855 inst.instruction |= inst.operands[0].reg << 12;
7856 switch (inst.operands[1].imm)
7857 {
7858 case 1: inst.instruction |= CP_T_X; break;
7859 case 2: inst.instruction |= CP_T_Y; break;
7860 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
7861 case 4: break;
7862 default: abort ();
7863 }
7864
7865 if (inst.instruction & (PRE_INDEX | INDEX_UP))
7866 {
7867 /* The instruction specified "ea" or "fd", so we can only accept
7868 [Rn]{!}. The instruction does not really support stacking or
7869 unstacking, so we have to emulate these by setting appropriate
7870 bits and offsets. */
7871 constraint (inst.reloc.exp.X_op != O_constant
7872 || inst.reloc.exp.X_add_number != 0,
7873 _("this instruction does not support indexing"));
7874
7875 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
7876 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
7877
7878 if (!(inst.instruction & INDEX_UP))
7879 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
7880
7881 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
7882 {
7883 inst.operands[2].preind = 0;
7884 inst.operands[2].postind = 1;
7885 }
7886 }
7887
7888 encode_arm_cp_address (2, TRUE, TRUE, 0);
7889 }
7890 \f
7891 /* iWMMXt instructions: strictly in alphabetical order. */
7892
7893 static void
7894 do_iwmmxt_tandorc (void)
7895 {
7896 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
7897 }
7898
7899 static void
7900 do_iwmmxt_textrc (void)
7901 {
7902 inst.instruction |= inst.operands[0].reg << 12;
7903 inst.instruction |= inst.operands[1].imm;
7904 }
7905
7906 static void
7907 do_iwmmxt_textrm (void)
7908 {
7909 inst.instruction |= inst.operands[0].reg << 12;
7910 inst.instruction |= inst.operands[1].reg << 16;
7911 inst.instruction |= inst.operands[2].imm;
7912 }
7913
7914 static void
7915 do_iwmmxt_tinsr (void)
7916 {
7917 inst.instruction |= inst.operands[0].reg << 16;
7918 inst.instruction |= inst.operands[1].reg << 12;
7919 inst.instruction |= inst.operands[2].imm;
7920 }
7921
7922 static void
7923 do_iwmmxt_tmia (void)
7924 {
7925 inst.instruction |= inst.operands[0].reg << 5;
7926 inst.instruction |= inst.operands[1].reg;
7927 inst.instruction |= inst.operands[2].reg << 12;
7928 }
7929
7930 static void
7931 do_iwmmxt_waligni (void)
7932 {
7933 inst.instruction |= inst.operands[0].reg << 12;
7934 inst.instruction |= inst.operands[1].reg << 16;
7935 inst.instruction |= inst.operands[2].reg;
7936 inst.instruction |= inst.operands[3].imm << 20;
7937 }
7938
7939 static void
7940 do_iwmmxt_wmerge (void)
7941 {
7942 inst.instruction |= inst.operands[0].reg << 12;
7943 inst.instruction |= inst.operands[1].reg << 16;
7944 inst.instruction |= inst.operands[2].reg;
7945 inst.instruction |= inst.operands[3].imm << 21;
7946 }
7947
7948 static void
7949 do_iwmmxt_wmov (void)
7950 {
7951 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
7952 inst.instruction |= inst.operands[0].reg << 12;
7953 inst.instruction |= inst.operands[1].reg << 16;
7954 inst.instruction |= inst.operands[1].reg;
7955 }
7956
7957 static void
7958 do_iwmmxt_wldstbh (void)
7959 {
7960 int reloc;
7961 inst.instruction |= inst.operands[0].reg << 12;
7962 if (thumb_mode)
7963 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
7964 else
7965 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
7966 encode_arm_cp_address (1, TRUE, FALSE, reloc);
7967 }
7968
7969 static void
7970 do_iwmmxt_wldstw (void)
7971 {
7972 /* RIWR_RIWC clears .isreg for a control register. */
7973 if (!inst.operands[0].isreg)
7974 {
7975 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7976 inst.instruction |= 0xf0000000;
7977 }
7978
7979 inst.instruction |= inst.operands[0].reg << 12;
7980 encode_arm_cp_address (1, TRUE, TRUE, 0);
7981 }
7982
7983 static void
7984 do_iwmmxt_wldstd (void)
7985 {
7986 inst.instruction |= inst.operands[0].reg << 12;
7987 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
7988 && inst.operands[1].immisreg)
7989 {
7990 inst.instruction &= ~0x1a000ff;
7991 inst.instruction |= (0xf << 28);
7992 if (inst.operands[1].preind)
7993 inst.instruction |= PRE_INDEX;
7994 if (!inst.operands[1].negative)
7995 inst.instruction |= INDEX_UP;
7996 if (inst.operands[1].writeback)
7997 inst.instruction |= WRITE_BACK;
7998 inst.instruction |= inst.operands[1].reg << 16;
7999 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8000 inst.instruction |= inst.operands[1].imm;
8001 }
8002 else
8003 encode_arm_cp_address (1, TRUE, FALSE, 0);
8004 }
8005
8006 static void
8007 do_iwmmxt_wshufh (void)
8008 {
8009 inst.instruction |= inst.operands[0].reg << 12;
8010 inst.instruction |= inst.operands[1].reg << 16;
8011 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8012 inst.instruction |= (inst.operands[2].imm & 0x0f);
8013 }
8014
8015 static void
8016 do_iwmmxt_wzero (void)
8017 {
8018 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8019 inst.instruction |= inst.operands[0].reg;
8020 inst.instruction |= inst.operands[0].reg << 12;
8021 inst.instruction |= inst.operands[0].reg << 16;
8022 }
8023
8024 static void
8025 do_iwmmxt_wrwrwr_or_imm5 (void)
8026 {
8027 if (inst.operands[2].isreg)
8028 do_rd_rn_rm ();
8029 else {
8030 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8031 _("immediate operand requires iWMMXt2"));
8032 do_rd_rn ();
8033 if (inst.operands[2].imm == 0)
8034 {
8035 switch ((inst.instruction >> 20) & 0xf)
8036 {
8037 case 4:
8038 case 5:
8039 case 6:
8040 case 7:
8041 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8042 inst.operands[2].imm = 16;
8043 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8044 break;
8045 case 8:
8046 case 9:
8047 case 10:
8048 case 11:
8049 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8050 inst.operands[2].imm = 32;
8051 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8052 break;
8053 case 12:
8054 case 13:
8055 case 14:
8056 case 15:
8057 {
8058 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8059 unsigned long wrn;
8060 wrn = (inst.instruction >> 16) & 0xf;
8061 inst.instruction &= 0xff0fff0f;
8062 inst.instruction |= wrn;
8063 /* Bail out here; the instruction is now assembled. */
8064 return;
8065 }
8066 }
8067 }
8068 /* Map 32 -> 0, etc. */
8069 inst.operands[2].imm &= 0x1f;
8070 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8071 }
8072 }
8073 \f
8074 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8075 operations first, then control, shift, and load/store. */
8076
8077 /* Insns like "foo X,Y,Z". */
8078
8079 static void
8080 do_mav_triple (void)
8081 {
8082 inst.instruction |= inst.operands[0].reg << 16;
8083 inst.instruction |= inst.operands[1].reg;
8084 inst.instruction |= inst.operands[2].reg << 12;
8085 }
8086
8087 /* Insns like "foo W,X,Y,Z".
8088 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
8089
8090 static void
8091 do_mav_quad (void)
8092 {
8093 inst.instruction |= inst.operands[0].reg << 5;
8094 inst.instruction |= inst.operands[1].reg << 12;
8095 inst.instruction |= inst.operands[2].reg << 16;
8096 inst.instruction |= inst.operands[3].reg;
8097 }
8098
8099 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8100 static void
8101 do_mav_dspsc (void)
8102 {
8103 inst.instruction |= inst.operands[1].reg << 12;
8104 }
8105
8106 /* Maverick shift immediate instructions.
8107 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8108 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
8109
8110 static void
8111 do_mav_shift (void)
8112 {
8113 int imm = inst.operands[2].imm;
8114
8115 inst.instruction |= inst.operands[0].reg << 12;
8116 inst.instruction |= inst.operands[1].reg << 16;
8117
8118 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8119 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8120 Bit 4 should be 0. */
8121 imm = (imm & 0xf) | ((imm & 0x70) << 1);
8122
8123 inst.instruction |= imm;
8124 }
8125 \f
8126 /* XScale instructions. Also sorted arithmetic before move. */
8127
8128 /* Xscale multiply-accumulate (argument parse)
8129 MIAcc acc0,Rm,Rs
8130 MIAPHcc acc0,Rm,Rs
8131 MIAxycc acc0,Rm,Rs. */
8132
8133 static void
8134 do_xsc_mia (void)
8135 {
8136 inst.instruction |= inst.operands[1].reg;
8137 inst.instruction |= inst.operands[2].reg << 12;
8138 }
8139
8140 /* Xscale move-accumulator-register (argument parse)
8141
8142 MARcc acc0,RdLo,RdHi. */
8143
8144 static void
8145 do_xsc_mar (void)
8146 {
8147 inst.instruction |= inst.operands[1].reg << 12;
8148 inst.instruction |= inst.operands[2].reg << 16;
8149 }
8150
8151 /* Xscale move-register-accumulator (argument parse)
8152
8153 MRAcc RdLo,RdHi,acc0. */
8154
8155 static void
8156 do_xsc_mra (void)
8157 {
8158 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8159 inst.instruction |= inst.operands[0].reg << 12;
8160 inst.instruction |= inst.operands[1].reg << 16;
8161 }
8162 \f
8163 /* Encoding functions relevant only to Thumb. */
8164
8165 /* inst.operands[i] is a shifted-register operand; encode
8166 it into inst.instruction in the format used by Thumb32. */
8167
8168 static void
8169 encode_thumb32_shifted_operand (int i)
8170 {
8171 unsigned int value = inst.reloc.exp.X_add_number;
8172 unsigned int shift = inst.operands[i].shift_kind;
8173
8174 constraint (inst.operands[i].immisreg,
8175 _("shift by register not allowed in thumb mode"));
8176 inst.instruction |= inst.operands[i].reg;
8177 if (shift == SHIFT_RRX)
8178 inst.instruction |= SHIFT_ROR << 4;
8179 else
8180 {
8181 constraint (inst.reloc.exp.X_op != O_constant,
8182 _("expression too complex"));
8183
8184 constraint (value > 32
8185 || (value == 32 && (shift == SHIFT_LSL
8186 || shift == SHIFT_ROR)),
8187 _("shift expression is too large"));
8188
8189 if (value == 0)
8190 shift = SHIFT_LSL;
8191 else if (value == 32)
8192 value = 0;
8193
8194 inst.instruction |= shift << 4;
8195 inst.instruction |= (value & 0x1c) << 10;
8196 inst.instruction |= (value & 0x03) << 6;
8197 }
8198 }
8199
8200
8201 /* inst.operands[i] was set up by parse_address. Encode it into a
8202 Thumb32 format load or store instruction. Reject forms that cannot
8203 be used with such instructions. If is_t is true, reject forms that
8204 cannot be used with a T instruction; if is_d is true, reject forms
8205 that cannot be used with a D instruction. */
8206
8207 static void
8208 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8209 {
8210 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8211
8212 constraint (!inst.operands[i].isreg,
8213 _("Instruction does not support =N addresses"));
8214
8215 inst.instruction |= inst.operands[i].reg << 16;
8216 if (inst.operands[i].immisreg)
8217 {
8218 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
8219 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8220 constraint (inst.operands[i].negative,
8221 _("Thumb does not support negative register indexing"));
8222 constraint (inst.operands[i].postind,
8223 _("Thumb does not support register post-indexing"));
8224 constraint (inst.operands[i].writeback,
8225 _("Thumb does not support register indexing with writeback"));
8226 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8227 _("Thumb supports only LSL in shifted register indexing"));
8228
8229 inst.instruction |= inst.operands[i].imm;
8230 if (inst.operands[i].shifted)
8231 {
8232 constraint (inst.reloc.exp.X_op != O_constant,
8233 _("expression too complex"));
8234 constraint (inst.reloc.exp.X_add_number < 0
8235 || inst.reloc.exp.X_add_number > 3,
8236 _("shift out of range"));
8237 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8238 }
8239 inst.reloc.type = BFD_RELOC_UNUSED;
8240 }
8241 else if (inst.operands[i].preind)
8242 {
8243 constraint (is_pc && inst.operands[i].writeback,
8244 _("cannot use writeback with PC-relative addressing"));
8245 constraint (is_t && inst.operands[i].writeback,
8246 _("cannot use writeback with this instruction"));
8247
8248 if (is_d)
8249 {
8250 inst.instruction |= 0x01000000;
8251 if (inst.operands[i].writeback)
8252 inst.instruction |= 0x00200000;
8253 }
8254 else
8255 {
8256 inst.instruction |= 0x00000c00;
8257 if (inst.operands[i].writeback)
8258 inst.instruction |= 0x00000100;
8259 }
8260 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8261 }
8262 else if (inst.operands[i].postind)
8263 {
8264 assert (inst.operands[i].writeback);
8265 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8266 constraint (is_t, _("cannot use post-indexing with this instruction"));
8267
8268 if (is_d)
8269 inst.instruction |= 0x00200000;
8270 else
8271 inst.instruction |= 0x00000900;
8272 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8273 }
8274 else /* unindexed - only for coprocessor */
8275 inst.error = _("instruction does not accept unindexed addressing");
8276 }
8277
8278 /* Table of Thumb instructions which exist in both 16- and 32-bit
8279 encodings (the latter only in post-V6T2 cores). The index is the
8280 value used in the insns table below. When there is more than one
8281 possible 16-bit encoding for the instruction, this table always
8282 holds variant (1).
8283 Also contains several pseudo-instructions used during relaxation. */
8284 #define T16_32_TAB \
8285 X(adc, 4140, eb400000), \
8286 X(adcs, 4140, eb500000), \
8287 X(add, 1c00, eb000000), \
8288 X(adds, 1c00, eb100000), \
8289 X(addi, 0000, f1000000), \
8290 X(addis, 0000, f1100000), \
8291 X(add_pc,000f, f20f0000), \
8292 X(add_sp,000d, f10d0000), \
8293 X(adr, 000f, f20f0000), \
8294 X(and, 4000, ea000000), \
8295 X(ands, 4000, ea100000), \
8296 X(asr, 1000, fa40f000), \
8297 X(asrs, 1000, fa50f000), \
8298 X(b, e000, f000b000), \
8299 X(bcond, d000, f0008000), \
8300 X(bic, 4380, ea200000), \
8301 X(bics, 4380, ea300000), \
8302 X(cmn, 42c0, eb100f00), \
8303 X(cmp, 2800, ebb00f00), \
8304 X(cpsie, b660, f3af8400), \
8305 X(cpsid, b670, f3af8600), \
8306 X(cpy, 4600, ea4f0000), \
8307 X(dec_sp,80dd, f1ad0d00), \
8308 X(eor, 4040, ea800000), \
8309 X(eors, 4040, ea900000), \
8310 X(inc_sp,00dd, f10d0d00), \
8311 X(ldmia, c800, e8900000), \
8312 X(ldr, 6800, f8500000), \
8313 X(ldrb, 7800, f8100000), \
8314 X(ldrh, 8800, f8300000), \
8315 X(ldrsb, 5600, f9100000), \
8316 X(ldrsh, 5e00, f9300000), \
8317 X(ldr_pc,4800, f85f0000), \
8318 X(ldr_pc2,4800, f85f0000), \
8319 X(ldr_sp,9800, f85d0000), \
8320 X(lsl, 0000, fa00f000), \
8321 X(lsls, 0000, fa10f000), \
8322 X(lsr, 0800, fa20f000), \
8323 X(lsrs, 0800, fa30f000), \
8324 X(mov, 2000, ea4f0000), \
8325 X(movs, 2000, ea5f0000), \
8326 X(mul, 4340, fb00f000), \
8327 X(muls, 4340, ffffffff), /* no 32b muls */ \
8328 X(mvn, 43c0, ea6f0000), \
8329 X(mvns, 43c0, ea7f0000), \
8330 X(neg, 4240, f1c00000), /* rsb #0 */ \
8331 X(negs, 4240, f1d00000), /* rsbs #0 */ \
8332 X(orr, 4300, ea400000), \
8333 X(orrs, 4300, ea500000), \
8334 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8335 X(push, b400, e92d0000), /* stmdb sp!,... */ \
8336 X(rev, ba00, fa90f080), \
8337 X(rev16, ba40, fa90f090), \
8338 X(revsh, bac0, fa90f0b0), \
8339 X(ror, 41c0, fa60f000), \
8340 X(rors, 41c0, fa70f000), \
8341 X(sbc, 4180, eb600000), \
8342 X(sbcs, 4180, eb700000), \
8343 X(stmia, c000, e8800000), \
8344 X(str, 6000, f8400000), \
8345 X(strb, 7000, f8000000), \
8346 X(strh, 8000, f8200000), \
8347 X(str_sp,9000, f84d0000), \
8348 X(sub, 1e00, eba00000), \
8349 X(subs, 1e00, ebb00000), \
8350 X(subi, 8000, f1a00000), \
8351 X(subis, 8000, f1b00000), \
8352 X(sxtb, b240, fa4ff080), \
8353 X(sxth, b200, fa0ff080), \
8354 X(tst, 4200, ea100f00), \
8355 X(uxtb, b2c0, fa5ff080), \
8356 X(uxth, b280, fa1ff080), \
8357 X(nop, bf00, f3af8000), \
8358 X(yield, bf10, f3af8001), \
8359 X(wfe, bf20, f3af8002), \
8360 X(wfi, bf30, f3af8003), \
8361 X(sev, bf40, f3af9004), /* typo, 8004? */
8362
8363 /* To catch errors in encoding functions, the codes are all offset by
8364 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8365 as 16-bit instructions. */
8366 #define X(a,b,c) T_MNEM_##a
8367 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8368 #undef X
8369
8370 #define X(a,b,c) 0x##b
8371 static const unsigned short thumb_op16[] = { T16_32_TAB };
8372 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8373 #undef X
8374
8375 #define X(a,b,c) 0x##c
8376 static const unsigned int thumb_op32[] = { T16_32_TAB };
8377 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8378 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
8379 #undef X
8380 #undef T16_32_TAB
8381
8382 /* Thumb instruction encoders, in alphabetical order. */
8383
8384 /* ADDW or SUBW. */
8385 static void
8386 do_t_add_sub_w (void)
8387 {
8388 int Rd, Rn;
8389
8390 Rd = inst.operands[0].reg;
8391 Rn = inst.operands[1].reg;
8392
8393 constraint (Rd == 15, _("PC not allowed as destination"));
8394 inst.instruction |= (Rn << 16) | (Rd << 8);
8395 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8396 }
8397
8398 /* Parse an add or subtract instruction. We get here with inst.instruction
8399 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8400
8401 static void
8402 do_t_add_sub (void)
8403 {
8404 int Rd, Rs, Rn;
8405
8406 Rd = inst.operands[0].reg;
8407 Rs = (inst.operands[1].present
8408 ? inst.operands[1].reg /* Rd, Rs, foo */
8409 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8410
8411 if (unified_syntax)
8412 {
8413 bfd_boolean flags;
8414 bfd_boolean narrow;
8415 int opcode;
8416
8417 flags = (inst.instruction == T_MNEM_adds
8418 || inst.instruction == T_MNEM_subs);
8419 if (flags)
8420 narrow = (current_it_mask == 0);
8421 else
8422 narrow = (current_it_mask != 0);
8423 if (!inst.operands[2].isreg)
8424 {
8425 int add;
8426
8427 add = (inst.instruction == T_MNEM_add
8428 || inst.instruction == T_MNEM_adds);
8429 opcode = 0;
8430 if (inst.size_req != 4)
8431 {
8432 /* Attempt to use a narrow opcode, with relaxation if
8433 appropriate. */
8434 if (Rd == REG_SP && Rs == REG_SP && !flags)
8435 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8436 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8437 opcode = T_MNEM_add_sp;
8438 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8439 opcode = T_MNEM_add_pc;
8440 else if (Rd <= 7 && Rs <= 7 && narrow)
8441 {
8442 if (flags)
8443 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8444 else
8445 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8446 }
8447 if (opcode)
8448 {
8449 inst.instruction = THUMB_OP16(opcode);
8450 inst.instruction |= (Rd << 4) | Rs;
8451 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8452 if (inst.size_req != 2)
8453 inst.relax = opcode;
8454 }
8455 else
8456 constraint (inst.size_req == 2, BAD_HIREG);
8457 }
8458 if (inst.size_req == 4
8459 || (inst.size_req != 2 && !opcode))
8460 {
8461 if (Rd == REG_PC)
8462 {
8463 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
8464 _("only SUBS PC, LR, #const allowed"));
8465 constraint (inst.reloc.exp.X_op != O_constant,
8466 _("expression too complex"));
8467 constraint (inst.reloc.exp.X_add_number < 0
8468 || inst.reloc.exp.X_add_number > 0xff,
8469 _("immediate value out of range"));
8470 inst.instruction = T2_SUBS_PC_LR
8471 | inst.reloc.exp.X_add_number;
8472 inst.reloc.type = BFD_RELOC_UNUSED;
8473 return;
8474 }
8475 else if (Rs == REG_PC)
8476 {
8477 /* Always use addw/subw. */
8478 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8479 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8480 }
8481 else
8482 {
8483 inst.instruction = THUMB_OP32 (inst.instruction);
8484 inst.instruction = (inst.instruction & 0xe1ffffff)
8485 | 0x10000000;
8486 if (flags)
8487 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8488 else
8489 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
8490 }
8491 inst.instruction |= Rd << 8;
8492 inst.instruction |= Rs << 16;
8493 }
8494 }
8495 else
8496 {
8497 Rn = inst.operands[2].reg;
8498 /* See if we can do this with a 16-bit instruction. */
8499 if (!inst.operands[2].shifted && inst.size_req != 4)
8500 {
8501 if (Rd > 7 || Rs > 7 || Rn > 7)
8502 narrow = FALSE;
8503
8504 if (narrow)
8505 {
8506 inst.instruction = ((inst.instruction == T_MNEM_adds
8507 || inst.instruction == T_MNEM_add)
8508 ? T_OPCODE_ADD_R3
8509 : T_OPCODE_SUB_R3);
8510 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8511 return;
8512 }
8513
8514 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
8515 {
8516 /* Thumb-1 cores (except v6-M) require at least one high
8517 register in a narrow non flag setting add. */
8518 if (Rd > 7 || Rn > 7
8519 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
8520 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
8521 {
8522 if (Rd == Rn)
8523 {
8524 Rn = Rs;
8525 Rs = Rd;
8526 }
8527 inst.instruction = T_OPCODE_ADD_HI;
8528 inst.instruction |= (Rd & 8) << 4;
8529 inst.instruction |= (Rd & 7);
8530 inst.instruction |= Rn << 3;
8531 return;
8532 }
8533 }
8534 }
8535 /* If we get here, it can't be done in 16 bits. */
8536 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
8537 _("shift must be constant"));
8538 inst.instruction = THUMB_OP32 (inst.instruction);
8539 inst.instruction |= Rd << 8;
8540 inst.instruction |= Rs << 16;
8541 encode_thumb32_shifted_operand (2);
8542 }
8543 }
8544 else
8545 {
8546 constraint (inst.instruction == T_MNEM_adds
8547 || inst.instruction == T_MNEM_subs,
8548 BAD_THUMB32);
8549
8550 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
8551 {
8552 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
8553 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
8554 BAD_HIREG);
8555
8556 inst.instruction = (inst.instruction == T_MNEM_add
8557 ? 0x0000 : 0x8000);
8558 inst.instruction |= (Rd << 4) | Rs;
8559 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8560 return;
8561 }
8562
8563 Rn = inst.operands[2].reg;
8564 constraint (inst.operands[2].shifted, _("unshifted register required"));
8565
8566 /* We now have Rd, Rs, and Rn set to registers. */
8567 if (Rd > 7 || Rs > 7 || Rn > 7)
8568 {
8569 /* Can't do this for SUB. */
8570 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
8571 inst.instruction = T_OPCODE_ADD_HI;
8572 inst.instruction |= (Rd & 8) << 4;
8573 inst.instruction |= (Rd & 7);
8574 if (Rs == Rd)
8575 inst.instruction |= Rn << 3;
8576 else if (Rn == Rd)
8577 inst.instruction |= Rs << 3;
8578 else
8579 constraint (1, _("dest must overlap one source register"));
8580 }
8581 else
8582 {
8583 inst.instruction = (inst.instruction == T_MNEM_add
8584 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
8585 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8586 }
8587 }
8588 }
8589
8590 static void
8591 do_t_adr (void)
8592 {
8593 if (unified_syntax && inst.size_req == 0 && inst.operands[0].reg <= 7)
8594 {
8595 /* Defer to section relaxation. */
8596 inst.relax = inst.instruction;
8597 inst.instruction = THUMB_OP16 (inst.instruction);
8598 inst.instruction |= inst.operands[0].reg << 4;
8599 }
8600 else if (unified_syntax && inst.size_req != 2)
8601 {
8602 /* Generate a 32-bit opcode. */
8603 inst.instruction = THUMB_OP32 (inst.instruction);
8604 inst.instruction |= inst.operands[0].reg << 8;
8605 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
8606 inst.reloc.pc_rel = 1;
8607 }
8608 else
8609 {
8610 /* Generate a 16-bit opcode. */
8611 inst.instruction = THUMB_OP16 (inst.instruction);
8612 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8613 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
8614 inst.reloc.pc_rel = 1;
8615
8616 inst.instruction |= inst.operands[0].reg << 4;
8617 }
8618 }
8619
8620 /* Arithmetic instructions for which there is just one 16-bit
8621 instruction encoding, and it allows only two low registers.
8622 For maximal compatibility with ARM syntax, we allow three register
8623 operands even when Thumb-32 instructions are not available, as long
8624 as the first two are identical. For instance, both "sbc r0,r1" and
8625 "sbc r0,r0,r1" are allowed. */
8626 static void
8627 do_t_arit3 (void)
8628 {
8629 int Rd, Rs, Rn;
8630
8631 Rd = inst.operands[0].reg;
8632 Rs = (inst.operands[1].present
8633 ? inst.operands[1].reg /* Rd, Rs, foo */
8634 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8635 Rn = inst.operands[2].reg;
8636
8637 if (unified_syntax)
8638 {
8639 if (!inst.operands[2].isreg)
8640 {
8641 /* For an immediate, we always generate a 32-bit opcode;
8642 section relaxation will shrink it later if possible. */
8643 inst.instruction = THUMB_OP32 (inst.instruction);
8644 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8645 inst.instruction |= Rd << 8;
8646 inst.instruction |= Rs << 16;
8647 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8648 }
8649 else
8650 {
8651 bfd_boolean narrow;
8652
8653 /* See if we can do this with a 16-bit instruction. */
8654 if (THUMB_SETS_FLAGS (inst.instruction))
8655 narrow = current_it_mask == 0;
8656 else
8657 narrow = current_it_mask != 0;
8658
8659 if (Rd > 7 || Rn > 7 || Rs > 7)
8660 narrow = FALSE;
8661 if (inst.operands[2].shifted)
8662 narrow = FALSE;
8663 if (inst.size_req == 4)
8664 narrow = FALSE;
8665
8666 if (narrow
8667 && Rd == Rs)
8668 {
8669 inst.instruction = THUMB_OP16 (inst.instruction);
8670 inst.instruction |= Rd;
8671 inst.instruction |= Rn << 3;
8672 return;
8673 }
8674
8675 /* If we get here, it can't be done in 16 bits. */
8676 constraint (inst.operands[2].shifted
8677 && inst.operands[2].immisreg,
8678 _("shift must be constant"));
8679 inst.instruction = THUMB_OP32 (inst.instruction);
8680 inst.instruction |= Rd << 8;
8681 inst.instruction |= Rs << 16;
8682 encode_thumb32_shifted_operand (2);
8683 }
8684 }
8685 else
8686 {
8687 /* On its face this is a lie - the instruction does set the
8688 flags. However, the only supported mnemonic in this mode
8689 says it doesn't. */
8690 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
8691
8692 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8693 _("unshifted register required"));
8694 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8695 constraint (Rd != Rs,
8696 _("dest and source1 must be the same register"));
8697
8698 inst.instruction = THUMB_OP16 (inst.instruction);
8699 inst.instruction |= Rd;
8700 inst.instruction |= Rn << 3;
8701 }
8702 }
8703
8704 /* Similarly, but for instructions where the arithmetic operation is
8705 commutative, so we can allow either of them to be different from
8706 the destination operand in a 16-bit instruction. For instance, all
8707 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
8708 accepted. */
8709 static void
8710 do_t_arit3c (void)
8711 {
8712 int Rd, Rs, Rn;
8713
8714 Rd = inst.operands[0].reg;
8715 Rs = (inst.operands[1].present
8716 ? inst.operands[1].reg /* Rd, Rs, foo */
8717 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8718 Rn = inst.operands[2].reg;
8719
8720 if (unified_syntax)
8721 {
8722 if (!inst.operands[2].isreg)
8723 {
8724 /* For an immediate, we always generate a 32-bit opcode;
8725 section relaxation will shrink it later if possible. */
8726 inst.instruction = THUMB_OP32 (inst.instruction);
8727 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8728 inst.instruction |= Rd << 8;
8729 inst.instruction |= Rs << 16;
8730 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8731 }
8732 else
8733 {
8734 bfd_boolean narrow;
8735
8736 /* See if we can do this with a 16-bit instruction. */
8737 if (THUMB_SETS_FLAGS (inst.instruction))
8738 narrow = current_it_mask == 0;
8739 else
8740 narrow = current_it_mask != 0;
8741
8742 if (Rd > 7 || Rn > 7 || Rs > 7)
8743 narrow = FALSE;
8744 if (inst.operands[2].shifted)
8745 narrow = FALSE;
8746 if (inst.size_req == 4)
8747 narrow = FALSE;
8748
8749 if (narrow)
8750 {
8751 if (Rd == Rs)
8752 {
8753 inst.instruction = THUMB_OP16 (inst.instruction);
8754 inst.instruction |= Rd;
8755 inst.instruction |= Rn << 3;
8756 return;
8757 }
8758 if (Rd == Rn)
8759 {
8760 inst.instruction = THUMB_OP16 (inst.instruction);
8761 inst.instruction |= Rd;
8762 inst.instruction |= Rs << 3;
8763 return;
8764 }
8765 }
8766
8767 /* If we get here, it can't be done in 16 bits. */
8768 constraint (inst.operands[2].shifted
8769 && inst.operands[2].immisreg,
8770 _("shift must be constant"));
8771 inst.instruction = THUMB_OP32 (inst.instruction);
8772 inst.instruction |= Rd << 8;
8773 inst.instruction |= Rs << 16;
8774 encode_thumb32_shifted_operand (2);
8775 }
8776 }
8777 else
8778 {
8779 /* On its face this is a lie - the instruction does set the
8780 flags. However, the only supported mnemonic in this mode
8781 says it doesn't. */
8782 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
8783
8784 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8785 _("unshifted register required"));
8786 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8787
8788 inst.instruction = THUMB_OP16 (inst.instruction);
8789 inst.instruction |= Rd;
8790
8791 if (Rd == Rs)
8792 inst.instruction |= Rn << 3;
8793 else if (Rd == Rn)
8794 inst.instruction |= Rs << 3;
8795 else
8796 constraint (1, _("dest must overlap one source register"));
8797 }
8798 }
8799
8800 static void
8801 do_t_barrier (void)
8802 {
8803 if (inst.operands[0].present)
8804 {
8805 constraint ((inst.instruction & 0xf0) != 0x40
8806 && inst.operands[0].imm != 0xf,
8807 _("bad barrier type"));
8808 inst.instruction |= inst.operands[0].imm;
8809 }
8810 else
8811 inst.instruction |= 0xf;
8812 }
8813
8814 static void
8815 do_t_bfc (void)
8816 {
8817 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8818 constraint (msb > 32, _("bit-field extends past end of register"));
8819 /* The instruction encoding stores the LSB and MSB,
8820 not the LSB and width. */
8821 inst.instruction |= inst.operands[0].reg << 8;
8822 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
8823 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
8824 inst.instruction |= msb - 1;
8825 }
8826
8827 static void
8828 do_t_bfi (void)
8829 {
8830 unsigned int msb;
8831
8832 /* #0 in second position is alternative syntax for bfc, which is
8833 the same instruction but with REG_PC in the Rm field. */
8834 if (!inst.operands[1].isreg)
8835 inst.operands[1].reg = REG_PC;
8836
8837 msb = inst.operands[2].imm + inst.operands[3].imm;
8838 constraint (msb > 32, _("bit-field extends past end of register"));
8839 /* The instruction encoding stores the LSB and MSB,
8840 not the LSB and width. */
8841 inst.instruction |= inst.operands[0].reg << 8;
8842 inst.instruction |= inst.operands[1].reg << 16;
8843 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8844 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8845 inst.instruction |= msb - 1;
8846 }
8847
8848 static void
8849 do_t_bfx (void)
8850 {
8851 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8852 _("bit-field extends past end of register"));
8853 inst.instruction |= inst.operands[0].reg << 8;
8854 inst.instruction |= inst.operands[1].reg << 16;
8855 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8856 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8857 inst.instruction |= inst.operands[3].imm - 1;
8858 }
8859
8860 /* ARM V5 Thumb BLX (argument parse)
8861 BLX <target_addr> which is BLX(1)
8862 BLX <Rm> which is BLX(2)
8863 Unfortunately, there are two different opcodes for this mnemonic.
8864 So, the insns[].value is not used, and the code here zaps values
8865 into inst.instruction.
8866
8867 ??? How to take advantage of the additional two bits of displacement
8868 available in Thumb32 mode? Need new relocation? */
8869
8870 static void
8871 do_t_blx (void)
8872 {
8873 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8874 if (inst.operands[0].isreg)
8875 /* We have a register, so this is BLX(2). */
8876 inst.instruction |= inst.operands[0].reg << 3;
8877 else
8878 {
8879 /* No register. This must be BLX(1). */
8880 inst.instruction = 0xf000e800;
8881 #ifdef OBJ_ELF
8882 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8883 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
8884 else
8885 #endif
8886 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
8887 inst.reloc.pc_rel = 1;
8888 }
8889 }
8890
8891 static void
8892 do_t_branch (void)
8893 {
8894 int opcode;
8895 int cond;
8896
8897 if (current_it_mask)
8898 {
8899 /* Conditional branches inside IT blocks are encoded as unconditional
8900 branches. */
8901 cond = COND_ALWAYS;
8902 /* A branch must be the last instruction in an IT block. */
8903 constraint (current_it_mask != 0x10, BAD_BRANCH);
8904 }
8905 else
8906 cond = inst.cond;
8907
8908 if (cond != COND_ALWAYS)
8909 opcode = T_MNEM_bcond;
8910 else
8911 opcode = inst.instruction;
8912
8913 if (unified_syntax && inst.size_req == 4)
8914 {
8915 inst.instruction = THUMB_OP32(opcode);
8916 if (cond == COND_ALWAYS)
8917 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
8918 else
8919 {
8920 assert (cond != 0xF);
8921 inst.instruction |= cond << 22;
8922 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
8923 }
8924 }
8925 else
8926 {
8927 inst.instruction = THUMB_OP16(opcode);
8928 if (cond == COND_ALWAYS)
8929 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
8930 else
8931 {
8932 inst.instruction |= cond << 8;
8933 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
8934 }
8935 /* Allow section relaxation. */
8936 if (unified_syntax && inst.size_req != 2)
8937 inst.relax = opcode;
8938 }
8939
8940 inst.reloc.pc_rel = 1;
8941 }
8942
8943 static void
8944 do_t_bkpt (void)
8945 {
8946 constraint (inst.cond != COND_ALWAYS,
8947 _("instruction is always unconditional"));
8948 if (inst.operands[0].present)
8949 {
8950 constraint (inst.operands[0].imm > 255,
8951 _("immediate value out of range"));
8952 inst.instruction |= inst.operands[0].imm;
8953 }
8954 }
8955
8956 static void
8957 do_t_branch23 (void)
8958 {
8959 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8960 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
8961 inst.reloc.pc_rel = 1;
8962
8963 /* If the destination of the branch is a defined symbol which does not have
8964 the THUMB_FUNC attribute, then we must be calling a function which has
8965 the (interfacearm) attribute. We look for the Thumb entry point to that
8966 function and change the branch to refer to that function instead. */
8967 if ( inst.reloc.exp.X_op == O_symbol
8968 && inst.reloc.exp.X_add_symbol != NULL
8969 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8970 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8971 inst.reloc.exp.X_add_symbol =
8972 find_real_start (inst.reloc.exp.X_add_symbol);
8973 }
8974
8975 static void
8976 do_t_bx (void)
8977 {
8978 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8979 inst.instruction |= inst.operands[0].reg << 3;
8980 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
8981 should cause the alignment to be checked once it is known. This is
8982 because BX PC only works if the instruction is word aligned. */
8983 }
8984
8985 static void
8986 do_t_bxj (void)
8987 {
8988 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8989 if (inst.operands[0].reg == REG_PC)
8990 as_tsktsk (_("use of r15 in bxj is not really useful"));
8991
8992 inst.instruction |= inst.operands[0].reg << 16;
8993 }
8994
8995 static void
8996 do_t_clz (void)
8997 {
8998 inst.instruction |= inst.operands[0].reg << 8;
8999 inst.instruction |= inst.operands[1].reg << 16;
9000 inst.instruction |= inst.operands[1].reg;
9001 }
9002
9003 static void
9004 do_t_cps (void)
9005 {
9006 constraint (current_it_mask, BAD_NOT_IT);
9007 inst.instruction |= inst.operands[0].imm;
9008 }
9009
9010 static void
9011 do_t_cpsi (void)
9012 {
9013 constraint (current_it_mask, BAD_NOT_IT);
9014 if (unified_syntax
9015 && (inst.operands[1].present || inst.size_req == 4)
9016 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
9017 {
9018 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9019 inst.instruction = 0xf3af8000;
9020 inst.instruction |= imod << 9;
9021 inst.instruction |= inst.operands[0].imm << 5;
9022 if (inst.operands[1].present)
9023 inst.instruction |= 0x100 | inst.operands[1].imm;
9024 }
9025 else
9026 {
9027 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9028 && (inst.operands[0].imm & 4),
9029 _("selected processor does not support 'A' form "
9030 "of this instruction"));
9031 constraint (inst.operands[1].present || inst.size_req == 4,
9032 _("Thumb does not support the 2-argument "
9033 "form of this instruction"));
9034 inst.instruction |= inst.operands[0].imm;
9035 }
9036 }
9037
9038 /* THUMB CPY instruction (argument parse). */
9039
9040 static void
9041 do_t_cpy (void)
9042 {
9043 if (inst.size_req == 4)
9044 {
9045 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9046 inst.instruction |= inst.operands[0].reg << 8;
9047 inst.instruction |= inst.operands[1].reg;
9048 }
9049 else
9050 {
9051 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9052 inst.instruction |= (inst.operands[0].reg & 0x7);
9053 inst.instruction |= inst.operands[1].reg << 3;
9054 }
9055 }
9056
9057 static void
9058 do_t_cbz (void)
9059 {
9060 constraint (current_it_mask, BAD_NOT_IT);
9061 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9062 inst.instruction |= inst.operands[0].reg;
9063 inst.reloc.pc_rel = 1;
9064 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9065 }
9066
9067 static void
9068 do_t_dbg (void)
9069 {
9070 inst.instruction |= inst.operands[0].imm;
9071 }
9072
9073 static void
9074 do_t_div (void)
9075 {
9076 if (!inst.operands[1].present)
9077 inst.operands[1].reg = inst.operands[0].reg;
9078 inst.instruction |= inst.operands[0].reg << 8;
9079 inst.instruction |= inst.operands[1].reg << 16;
9080 inst.instruction |= inst.operands[2].reg;
9081 }
9082
9083 static void
9084 do_t_hint (void)
9085 {
9086 if (unified_syntax && inst.size_req == 4)
9087 inst.instruction = THUMB_OP32 (inst.instruction);
9088 else
9089 inst.instruction = THUMB_OP16 (inst.instruction);
9090 }
9091
9092 static void
9093 do_t_it (void)
9094 {
9095 unsigned int cond = inst.operands[0].imm;
9096
9097 constraint (current_it_mask, BAD_NOT_IT);
9098 current_it_mask = (inst.instruction & 0xf) | 0x10;
9099 current_cc = cond;
9100
9101 /* If the condition is a negative condition, invert the mask. */
9102 if ((cond & 0x1) == 0x0)
9103 {
9104 unsigned int mask = inst.instruction & 0x000f;
9105
9106 if ((mask & 0x7) == 0)
9107 /* no conversion needed */;
9108 else if ((mask & 0x3) == 0)
9109 mask ^= 0x8;
9110 else if ((mask & 0x1) == 0)
9111 mask ^= 0xC;
9112 else
9113 mask ^= 0xE;
9114
9115 inst.instruction &= 0xfff0;
9116 inst.instruction |= mask;
9117 }
9118
9119 inst.instruction |= cond << 4;
9120 }
9121
9122 /* Helper function used for both push/pop and ldm/stm. */
9123 static void
9124 encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9125 {
9126 bfd_boolean load;
9127
9128 load = (inst.instruction & (1 << 20)) != 0;
9129
9130 if (mask & (1 << 13))
9131 inst.error = _("SP not allowed in register list");
9132 if (load)
9133 {
9134 if (mask & (1 << 14)
9135 && mask & (1 << 15))
9136 inst.error = _("LR and PC should not both be in register list");
9137
9138 if ((mask & (1 << base)) != 0
9139 && writeback)
9140 as_warn (_("base register should not be in register list "
9141 "when written back"));
9142 }
9143 else
9144 {
9145 if (mask & (1 << 15))
9146 inst.error = _("PC not allowed in register list");
9147
9148 if (mask & (1 << base))
9149 as_warn (_("value stored for r%d is UNPREDICTABLE"), base);
9150 }
9151
9152 if ((mask & (mask - 1)) == 0)
9153 {
9154 /* Single register transfers implemented as str/ldr. */
9155 if (writeback)
9156 {
9157 if (inst.instruction & (1 << 23))
9158 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9159 else
9160 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9161 }
9162 else
9163 {
9164 if (inst.instruction & (1 << 23))
9165 inst.instruction = 0x00800000; /* ia -> [base] */
9166 else
9167 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9168 }
9169
9170 inst.instruction |= 0xf8400000;
9171 if (load)
9172 inst.instruction |= 0x00100000;
9173
9174 mask = ffs (mask) - 1;
9175 mask <<= 12;
9176 }
9177 else if (writeback)
9178 inst.instruction |= WRITE_BACK;
9179
9180 inst.instruction |= mask;
9181 inst.instruction |= base << 16;
9182 }
9183
9184 static void
9185 do_t_ldmstm (void)
9186 {
9187 /* This really doesn't seem worth it. */
9188 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9189 _("expression too complex"));
9190 constraint (inst.operands[1].writeback,
9191 _("Thumb load/store multiple does not support {reglist}^"));
9192
9193 if (unified_syntax)
9194 {
9195 bfd_boolean narrow;
9196 unsigned mask;
9197
9198 narrow = FALSE;
9199 /* See if we can use a 16-bit instruction. */
9200 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9201 && inst.size_req != 4
9202 && !(inst.operands[1].imm & ~0xff))
9203 {
9204 mask = 1 << inst.operands[0].reg;
9205
9206 if (inst.operands[0].reg <= 7
9207 && (inst.instruction == T_MNEM_stmia
9208 ? inst.operands[0].writeback
9209 : (inst.operands[0].writeback
9210 == !(inst.operands[1].imm & mask))))
9211 {
9212 if (inst.instruction == T_MNEM_stmia
9213 && (inst.operands[1].imm & mask)
9214 && (inst.operands[1].imm & (mask - 1)))
9215 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9216 inst.operands[0].reg);
9217
9218 inst.instruction = THUMB_OP16 (inst.instruction);
9219 inst.instruction |= inst.operands[0].reg << 8;
9220 inst.instruction |= inst.operands[1].imm;
9221 narrow = TRUE;
9222 }
9223 else if (inst.operands[0] .reg == REG_SP
9224 && inst.operands[0].writeback)
9225 {
9226 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9227 ? T_MNEM_push : T_MNEM_pop);
9228 inst.instruction |= inst.operands[1].imm;
9229 narrow = TRUE;
9230 }
9231 }
9232
9233 if (!narrow)
9234 {
9235 if (inst.instruction < 0xffff)
9236 inst.instruction = THUMB_OP32 (inst.instruction);
9237
9238 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
9239 inst.operands[0].writeback);
9240 }
9241 }
9242 else
9243 {
9244 constraint (inst.operands[0].reg > 7
9245 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
9246 constraint (inst.instruction != T_MNEM_ldmia
9247 && inst.instruction != T_MNEM_stmia,
9248 _("Thumb-2 instruction only valid in unified syntax"));
9249 if (inst.instruction == T_MNEM_stmia)
9250 {
9251 if (!inst.operands[0].writeback)
9252 as_warn (_("this instruction will write back the base register"));
9253 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9254 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9255 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9256 inst.operands[0].reg);
9257 }
9258 else
9259 {
9260 if (!inst.operands[0].writeback
9261 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9262 as_warn (_("this instruction will write back the base register"));
9263 else if (inst.operands[0].writeback
9264 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9265 as_warn (_("this instruction will not write back the base register"));
9266 }
9267
9268 inst.instruction = THUMB_OP16 (inst.instruction);
9269 inst.instruction |= inst.operands[0].reg << 8;
9270 inst.instruction |= inst.operands[1].imm;
9271 }
9272 }
9273
9274 static void
9275 do_t_ldrex (void)
9276 {
9277 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9278 || inst.operands[1].postind || inst.operands[1].writeback
9279 || inst.operands[1].immisreg || inst.operands[1].shifted
9280 || inst.operands[1].negative,
9281 BAD_ADDR_MODE);
9282
9283 inst.instruction |= inst.operands[0].reg << 12;
9284 inst.instruction |= inst.operands[1].reg << 16;
9285 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9286 }
9287
9288 static void
9289 do_t_ldrexd (void)
9290 {
9291 if (!inst.operands[1].present)
9292 {
9293 constraint (inst.operands[0].reg == REG_LR,
9294 _("r14 not allowed as first register "
9295 "when second register is omitted"));
9296 inst.operands[1].reg = inst.operands[0].reg + 1;
9297 }
9298 constraint (inst.operands[0].reg == inst.operands[1].reg,
9299 BAD_OVERLAP);
9300
9301 inst.instruction |= inst.operands[0].reg << 12;
9302 inst.instruction |= inst.operands[1].reg << 8;
9303 inst.instruction |= inst.operands[2].reg << 16;
9304 }
9305
9306 static void
9307 do_t_ldst (void)
9308 {
9309 unsigned long opcode;
9310 int Rn;
9311
9312 opcode = inst.instruction;
9313 if (unified_syntax)
9314 {
9315 if (!inst.operands[1].isreg)
9316 {
9317 if (opcode <= 0xffff)
9318 inst.instruction = THUMB_OP32 (opcode);
9319 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9320 return;
9321 }
9322 if (inst.operands[1].isreg
9323 && !inst.operands[1].writeback
9324 && !inst.operands[1].shifted && !inst.operands[1].postind
9325 && !inst.operands[1].negative && inst.operands[0].reg <= 7
9326 && opcode <= 0xffff
9327 && inst.size_req != 4)
9328 {
9329 /* Insn may have a 16-bit form. */
9330 Rn = inst.operands[1].reg;
9331 if (inst.operands[1].immisreg)
9332 {
9333 inst.instruction = THUMB_OP16 (opcode);
9334 /* [Rn, Rik] */
9335 if (Rn <= 7 && inst.operands[1].imm <= 7)
9336 goto op16;
9337 }
9338 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9339 && opcode != T_MNEM_ldrsb)
9340 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9341 || (Rn == REG_SP && opcode == T_MNEM_str))
9342 {
9343 /* [Rn, #const] */
9344 if (Rn > 7)
9345 {
9346 if (Rn == REG_PC)
9347 {
9348 if (inst.reloc.pc_rel)
9349 opcode = T_MNEM_ldr_pc2;
9350 else
9351 opcode = T_MNEM_ldr_pc;
9352 }
9353 else
9354 {
9355 if (opcode == T_MNEM_ldr)
9356 opcode = T_MNEM_ldr_sp;
9357 else
9358 opcode = T_MNEM_str_sp;
9359 }
9360 inst.instruction = inst.operands[0].reg << 8;
9361 }
9362 else
9363 {
9364 inst.instruction = inst.operands[0].reg;
9365 inst.instruction |= inst.operands[1].reg << 3;
9366 }
9367 inst.instruction |= THUMB_OP16 (opcode);
9368 if (inst.size_req == 2)
9369 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9370 else
9371 inst.relax = opcode;
9372 return;
9373 }
9374 }
9375 /* Definitely a 32-bit variant. */
9376 inst.instruction = THUMB_OP32 (opcode);
9377 inst.instruction |= inst.operands[0].reg << 12;
9378 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
9379 return;
9380 }
9381
9382 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9383
9384 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
9385 {
9386 /* Only [Rn,Rm] is acceptable. */
9387 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
9388 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
9389 || inst.operands[1].postind || inst.operands[1].shifted
9390 || inst.operands[1].negative,
9391 _("Thumb does not support this addressing mode"));
9392 inst.instruction = THUMB_OP16 (inst.instruction);
9393 goto op16;
9394 }
9395
9396 inst.instruction = THUMB_OP16 (inst.instruction);
9397 if (!inst.operands[1].isreg)
9398 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9399 return;
9400
9401 constraint (!inst.operands[1].preind
9402 || inst.operands[1].shifted
9403 || inst.operands[1].writeback,
9404 _("Thumb does not support this addressing mode"));
9405 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
9406 {
9407 constraint (inst.instruction & 0x0600,
9408 _("byte or halfword not valid for base register"));
9409 constraint (inst.operands[1].reg == REG_PC
9410 && !(inst.instruction & THUMB_LOAD_BIT),
9411 _("r15 based store not allowed"));
9412 constraint (inst.operands[1].immisreg,
9413 _("invalid base register for register offset"));
9414
9415 if (inst.operands[1].reg == REG_PC)
9416 inst.instruction = T_OPCODE_LDR_PC;
9417 else if (inst.instruction & THUMB_LOAD_BIT)
9418 inst.instruction = T_OPCODE_LDR_SP;
9419 else
9420 inst.instruction = T_OPCODE_STR_SP;
9421
9422 inst.instruction |= inst.operands[0].reg << 8;
9423 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9424 return;
9425 }
9426
9427 constraint (inst.operands[1].reg > 7, BAD_HIREG);
9428 if (!inst.operands[1].immisreg)
9429 {
9430 /* Immediate offset. */
9431 inst.instruction |= inst.operands[0].reg;
9432 inst.instruction |= inst.operands[1].reg << 3;
9433 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9434 return;
9435 }
9436
9437 /* Register offset. */
9438 constraint (inst.operands[1].imm > 7, BAD_HIREG);
9439 constraint (inst.operands[1].negative,
9440 _("Thumb does not support this addressing mode"));
9441
9442 op16:
9443 switch (inst.instruction)
9444 {
9445 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
9446 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
9447 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
9448 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
9449 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
9450 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
9451 case 0x5600 /* ldrsb */:
9452 case 0x5e00 /* ldrsh */: break;
9453 default: abort ();
9454 }
9455
9456 inst.instruction |= inst.operands[0].reg;
9457 inst.instruction |= inst.operands[1].reg << 3;
9458 inst.instruction |= inst.operands[1].imm << 6;
9459 }
9460
9461 static void
9462 do_t_ldstd (void)
9463 {
9464 if (!inst.operands[1].present)
9465 {
9466 inst.operands[1].reg = inst.operands[0].reg + 1;
9467 constraint (inst.operands[0].reg == REG_LR,
9468 _("r14 not allowed here"));
9469 }
9470 inst.instruction |= inst.operands[0].reg << 12;
9471 inst.instruction |= inst.operands[1].reg << 8;
9472 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
9473 }
9474
9475 static void
9476 do_t_ldstt (void)
9477 {
9478 inst.instruction |= inst.operands[0].reg << 12;
9479 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
9480 }
9481
9482 static void
9483 do_t_mla (void)
9484 {
9485 inst.instruction |= inst.operands[0].reg << 8;
9486 inst.instruction |= inst.operands[1].reg << 16;
9487 inst.instruction |= inst.operands[2].reg;
9488 inst.instruction |= inst.operands[3].reg << 12;
9489 }
9490
9491 static void
9492 do_t_mlal (void)
9493 {
9494 inst.instruction |= inst.operands[0].reg << 12;
9495 inst.instruction |= inst.operands[1].reg << 8;
9496 inst.instruction |= inst.operands[2].reg << 16;
9497 inst.instruction |= inst.operands[3].reg;
9498 }
9499
9500 static void
9501 do_t_mov_cmp (void)
9502 {
9503 if (unified_syntax)
9504 {
9505 int r0off = (inst.instruction == T_MNEM_mov
9506 || inst.instruction == T_MNEM_movs) ? 8 : 16;
9507 unsigned long opcode;
9508 bfd_boolean narrow;
9509 bfd_boolean low_regs;
9510
9511 low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7);
9512 opcode = inst.instruction;
9513 if (current_it_mask)
9514 narrow = opcode != T_MNEM_movs;
9515 else
9516 narrow = opcode != T_MNEM_movs || low_regs;
9517 if (inst.size_req == 4
9518 || inst.operands[1].shifted)
9519 narrow = FALSE;
9520
9521 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
9522 if (opcode == T_MNEM_movs && inst.operands[1].isreg
9523 && !inst.operands[1].shifted
9524 && inst.operands[0].reg == REG_PC
9525 && inst.operands[1].reg == REG_LR)
9526 {
9527 inst.instruction = T2_SUBS_PC_LR;
9528 return;
9529 }
9530
9531 if (!inst.operands[1].isreg)
9532 {
9533 /* Immediate operand. */
9534 if (current_it_mask == 0 && opcode == T_MNEM_mov)
9535 narrow = 0;
9536 if (low_regs && narrow)
9537 {
9538 inst.instruction = THUMB_OP16 (opcode);
9539 inst.instruction |= inst.operands[0].reg << 8;
9540 if (inst.size_req == 2)
9541 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9542 else
9543 inst.relax = opcode;
9544 }
9545 else
9546 {
9547 inst.instruction = THUMB_OP32 (inst.instruction);
9548 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9549 inst.instruction |= inst.operands[0].reg << r0off;
9550 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9551 }
9552 }
9553 else if (inst.operands[1].shifted && inst.operands[1].immisreg
9554 && (inst.instruction == T_MNEM_mov
9555 || inst.instruction == T_MNEM_movs))
9556 {
9557 /* Register shifts are encoded as separate shift instructions. */
9558 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
9559
9560 if (current_it_mask)
9561 narrow = !flags;
9562 else
9563 narrow = flags;
9564
9565 if (inst.size_req == 4)
9566 narrow = FALSE;
9567
9568 if (!low_regs || inst.operands[1].imm > 7)
9569 narrow = FALSE;
9570
9571 if (inst.operands[0].reg != inst.operands[1].reg)
9572 narrow = FALSE;
9573
9574 switch (inst.operands[1].shift_kind)
9575 {
9576 case SHIFT_LSL:
9577 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
9578 break;
9579 case SHIFT_ASR:
9580 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
9581 break;
9582 case SHIFT_LSR:
9583 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
9584 break;
9585 case SHIFT_ROR:
9586 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
9587 break;
9588 default:
9589 abort ();
9590 }
9591
9592 inst.instruction = opcode;
9593 if (narrow)
9594 {
9595 inst.instruction |= inst.operands[0].reg;
9596 inst.instruction |= inst.operands[1].imm << 3;
9597 }
9598 else
9599 {
9600 if (flags)
9601 inst.instruction |= CONDS_BIT;
9602
9603 inst.instruction |= inst.operands[0].reg << 8;
9604 inst.instruction |= inst.operands[1].reg << 16;
9605 inst.instruction |= inst.operands[1].imm;
9606 }
9607 }
9608 else if (!narrow)
9609 {
9610 /* Some mov with immediate shift have narrow variants.
9611 Register shifts are handled above. */
9612 if (low_regs && inst.operands[1].shifted
9613 && (inst.instruction == T_MNEM_mov
9614 || inst.instruction == T_MNEM_movs))
9615 {
9616 if (current_it_mask)
9617 narrow = (inst.instruction == T_MNEM_mov);
9618 else
9619 narrow = (inst.instruction == T_MNEM_movs);
9620 }
9621
9622 if (narrow)
9623 {
9624 switch (inst.operands[1].shift_kind)
9625 {
9626 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
9627 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
9628 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
9629 default: narrow = FALSE; break;
9630 }
9631 }
9632
9633 if (narrow)
9634 {
9635 inst.instruction |= inst.operands[0].reg;
9636 inst.instruction |= inst.operands[1].reg << 3;
9637 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
9638 }
9639 else
9640 {
9641 inst.instruction = THUMB_OP32 (inst.instruction);
9642 inst.instruction |= inst.operands[0].reg << r0off;
9643 encode_thumb32_shifted_operand (1);
9644 }
9645 }
9646 else
9647 switch (inst.instruction)
9648 {
9649 case T_MNEM_mov:
9650 inst.instruction = T_OPCODE_MOV_HR;
9651 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9652 inst.instruction |= (inst.operands[0].reg & 0x7);
9653 inst.instruction |= inst.operands[1].reg << 3;
9654 break;
9655
9656 case T_MNEM_movs:
9657 /* We know we have low registers at this point.
9658 Generate ADD Rd, Rs, #0. */
9659 inst.instruction = T_OPCODE_ADD_I3;
9660 inst.instruction |= inst.operands[0].reg;
9661 inst.instruction |= inst.operands[1].reg << 3;
9662 break;
9663
9664 case T_MNEM_cmp:
9665 if (low_regs)
9666 {
9667 inst.instruction = T_OPCODE_CMP_LR;
9668 inst.instruction |= inst.operands[0].reg;
9669 inst.instruction |= inst.operands[1].reg << 3;
9670 }
9671 else
9672 {
9673 inst.instruction = T_OPCODE_CMP_HR;
9674 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9675 inst.instruction |= (inst.operands[0].reg & 0x7);
9676 inst.instruction |= inst.operands[1].reg << 3;
9677 }
9678 break;
9679 }
9680 return;
9681 }
9682
9683 inst.instruction = THUMB_OP16 (inst.instruction);
9684 if (inst.operands[1].isreg)
9685 {
9686 if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8)
9687 {
9688 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
9689 since a MOV instruction produces unpredictable results. */
9690 if (inst.instruction == T_OPCODE_MOV_I8)
9691 inst.instruction = T_OPCODE_ADD_I3;
9692 else
9693 inst.instruction = T_OPCODE_CMP_LR;
9694
9695 inst.instruction |= inst.operands[0].reg;
9696 inst.instruction |= inst.operands[1].reg << 3;
9697 }
9698 else
9699 {
9700 if (inst.instruction == T_OPCODE_MOV_I8)
9701 inst.instruction = T_OPCODE_MOV_HR;
9702 else
9703 inst.instruction = T_OPCODE_CMP_HR;
9704 do_t_cpy ();
9705 }
9706 }
9707 else
9708 {
9709 constraint (inst.operands[0].reg > 7,
9710 _("only lo regs allowed with immediate"));
9711 inst.instruction |= inst.operands[0].reg << 8;
9712 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9713 }
9714 }
9715
9716 static void
9717 do_t_mov16 (void)
9718 {
9719 bfd_vma imm;
9720 bfd_boolean top;
9721
9722 top = (inst.instruction & 0x00800000) != 0;
9723 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
9724 {
9725 constraint (top, _(":lower16: not allowed this instruction"));
9726 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
9727 }
9728 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
9729 {
9730 constraint (!top, _(":upper16: not allowed this instruction"));
9731 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
9732 }
9733
9734 inst.instruction |= inst.operands[0].reg << 8;
9735 if (inst.reloc.type == BFD_RELOC_UNUSED)
9736 {
9737 imm = inst.reloc.exp.X_add_number;
9738 inst.instruction |= (imm & 0xf000) << 4;
9739 inst.instruction |= (imm & 0x0800) << 15;
9740 inst.instruction |= (imm & 0x0700) << 4;
9741 inst.instruction |= (imm & 0x00ff);
9742 }
9743 }
9744
9745 static void
9746 do_t_mvn_tst (void)
9747 {
9748 if (unified_syntax)
9749 {
9750 int r0off = (inst.instruction == T_MNEM_mvn
9751 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
9752 bfd_boolean narrow;
9753
9754 if (inst.size_req == 4
9755 || inst.instruction > 0xffff
9756 || inst.operands[1].shifted
9757 || inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9758 narrow = FALSE;
9759 else if (inst.instruction == T_MNEM_cmn)
9760 narrow = TRUE;
9761 else if (THUMB_SETS_FLAGS (inst.instruction))
9762 narrow = (current_it_mask == 0);
9763 else
9764 narrow = (current_it_mask != 0);
9765
9766 if (!inst.operands[1].isreg)
9767 {
9768 /* For an immediate, we always generate a 32-bit opcode;
9769 section relaxation will shrink it later if possible. */
9770 if (inst.instruction < 0xffff)
9771 inst.instruction = THUMB_OP32 (inst.instruction);
9772 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9773 inst.instruction |= inst.operands[0].reg << r0off;
9774 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9775 }
9776 else
9777 {
9778 /* See if we can do this with a 16-bit instruction. */
9779 if (narrow)
9780 {
9781 inst.instruction = THUMB_OP16 (inst.instruction);
9782 inst.instruction |= inst.operands[0].reg;
9783 inst.instruction |= inst.operands[1].reg << 3;
9784 }
9785 else
9786 {
9787 constraint (inst.operands[1].shifted
9788 && inst.operands[1].immisreg,
9789 _("shift must be constant"));
9790 if (inst.instruction < 0xffff)
9791 inst.instruction = THUMB_OP32 (inst.instruction);
9792 inst.instruction |= inst.operands[0].reg << r0off;
9793 encode_thumb32_shifted_operand (1);
9794 }
9795 }
9796 }
9797 else
9798 {
9799 constraint (inst.instruction > 0xffff
9800 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
9801 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
9802 _("unshifted register required"));
9803 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9804 BAD_HIREG);
9805
9806 inst.instruction = THUMB_OP16 (inst.instruction);
9807 inst.instruction |= inst.operands[0].reg;
9808 inst.instruction |= inst.operands[1].reg << 3;
9809 }
9810 }
9811
9812 static void
9813 do_t_mrs (void)
9814 {
9815 int flags;
9816
9817 if (do_vfp_nsyn_mrs () == SUCCESS)
9818 return;
9819
9820 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
9821 if (flags == 0)
9822 {
9823 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
9824 _("selected processor does not support "
9825 "requested special purpose register"));
9826 }
9827 else
9828 {
9829 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9830 _("selected processor does not support "
9831 "requested special purpose register"));
9832 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9833 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
9834 _("'CPSR' or 'SPSR' expected"));
9835 }
9836
9837 inst.instruction |= inst.operands[0].reg << 8;
9838 inst.instruction |= (flags & SPSR_BIT) >> 2;
9839 inst.instruction |= inst.operands[1].imm & 0xff;
9840 }
9841
9842 static void
9843 do_t_msr (void)
9844 {
9845 int flags;
9846
9847 if (do_vfp_nsyn_msr () == SUCCESS)
9848 return;
9849
9850 constraint (!inst.operands[1].isreg,
9851 _("Thumb encoding does not support an immediate here"));
9852 flags = inst.operands[0].imm;
9853 if (flags & ~0xff)
9854 {
9855 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9856 _("selected processor does not support "
9857 "requested special purpose register"));
9858 }
9859 else
9860 {
9861 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
9862 _("selected processor does not support "
9863 "requested special purpose register"));
9864 flags |= PSR_f;
9865 }
9866 inst.instruction |= (flags & SPSR_BIT) >> 2;
9867 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
9868 inst.instruction |= (flags & 0xff);
9869 inst.instruction |= inst.operands[1].reg << 16;
9870 }
9871
9872 static void
9873 do_t_mul (void)
9874 {
9875 if (!inst.operands[2].present)
9876 inst.operands[2].reg = inst.operands[0].reg;
9877
9878 /* There is no 32-bit MULS and no 16-bit MUL. */
9879 if (unified_syntax && inst.instruction == T_MNEM_mul)
9880 {
9881 inst.instruction = THUMB_OP32 (inst.instruction);
9882 inst.instruction |= inst.operands[0].reg << 8;
9883 inst.instruction |= inst.operands[1].reg << 16;
9884 inst.instruction |= inst.operands[2].reg << 0;
9885 }
9886 else
9887 {
9888 constraint (!unified_syntax
9889 && inst.instruction == T_MNEM_muls, BAD_THUMB32);
9890 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9891 BAD_HIREG);
9892
9893 inst.instruction = THUMB_OP16 (inst.instruction);
9894 inst.instruction |= inst.operands[0].reg;
9895
9896 if (inst.operands[0].reg == inst.operands[1].reg)
9897 inst.instruction |= inst.operands[2].reg << 3;
9898 else if (inst.operands[0].reg == inst.operands[2].reg)
9899 inst.instruction |= inst.operands[1].reg << 3;
9900 else
9901 constraint (1, _("dest must overlap one source register"));
9902 }
9903 }
9904
9905 static void
9906 do_t_mull (void)
9907 {
9908 inst.instruction |= inst.operands[0].reg << 12;
9909 inst.instruction |= inst.operands[1].reg << 8;
9910 inst.instruction |= inst.operands[2].reg << 16;
9911 inst.instruction |= inst.operands[3].reg;
9912
9913 if (inst.operands[0].reg == inst.operands[1].reg)
9914 as_tsktsk (_("rdhi and rdlo must be different"));
9915 }
9916
9917 static void
9918 do_t_nop (void)
9919 {
9920 if (unified_syntax)
9921 {
9922 if (inst.size_req == 4 || inst.operands[0].imm > 15)
9923 {
9924 inst.instruction = THUMB_OP32 (inst.instruction);
9925 inst.instruction |= inst.operands[0].imm;
9926 }
9927 else
9928 {
9929 inst.instruction = THUMB_OP16 (inst.instruction);
9930 inst.instruction |= inst.operands[0].imm << 4;
9931 }
9932 }
9933 else
9934 {
9935 constraint (inst.operands[0].present,
9936 _("Thumb does not support NOP with hints"));
9937 inst.instruction = 0x46c0;
9938 }
9939 }
9940
9941 static void
9942 do_t_neg (void)
9943 {
9944 if (unified_syntax)
9945 {
9946 bfd_boolean narrow;
9947
9948 if (THUMB_SETS_FLAGS (inst.instruction))
9949 narrow = (current_it_mask == 0);
9950 else
9951 narrow = (current_it_mask != 0);
9952 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9953 narrow = FALSE;
9954 if (inst.size_req == 4)
9955 narrow = FALSE;
9956
9957 if (!narrow)
9958 {
9959 inst.instruction = THUMB_OP32 (inst.instruction);
9960 inst.instruction |= inst.operands[0].reg << 8;
9961 inst.instruction |= inst.operands[1].reg << 16;
9962 }
9963 else
9964 {
9965 inst.instruction = THUMB_OP16 (inst.instruction);
9966 inst.instruction |= inst.operands[0].reg;
9967 inst.instruction |= inst.operands[1].reg << 3;
9968 }
9969 }
9970 else
9971 {
9972 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9973 BAD_HIREG);
9974 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9975
9976 inst.instruction = THUMB_OP16 (inst.instruction);
9977 inst.instruction |= inst.operands[0].reg;
9978 inst.instruction |= inst.operands[1].reg << 3;
9979 }
9980 }
9981
9982 static void
9983 do_t_pkhbt (void)
9984 {
9985 inst.instruction |= inst.operands[0].reg << 8;
9986 inst.instruction |= inst.operands[1].reg << 16;
9987 inst.instruction |= inst.operands[2].reg;
9988 if (inst.operands[3].present)
9989 {
9990 unsigned int val = inst.reloc.exp.X_add_number;
9991 constraint (inst.reloc.exp.X_op != O_constant,
9992 _("expression too complex"));
9993 inst.instruction |= (val & 0x1c) << 10;
9994 inst.instruction |= (val & 0x03) << 6;
9995 }
9996 }
9997
9998 static void
9999 do_t_pkhtb (void)
10000 {
10001 if (!inst.operands[3].present)
10002 inst.instruction &= ~0x00000020;
10003 do_t_pkhbt ();
10004 }
10005
10006 static void
10007 do_t_pld (void)
10008 {
10009 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
10010 }
10011
10012 static void
10013 do_t_push_pop (void)
10014 {
10015 unsigned mask;
10016
10017 constraint (inst.operands[0].writeback,
10018 _("push/pop do not support {reglist}^"));
10019 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10020 _("expression too complex"));
10021
10022 mask = inst.operands[0].imm;
10023 if ((mask & ~0xff) == 0)
10024 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
10025 else if ((inst.instruction == T_MNEM_push
10026 && (mask & ~0xff) == 1 << REG_LR)
10027 || (inst.instruction == T_MNEM_pop
10028 && (mask & ~0xff) == 1 << REG_PC))
10029 {
10030 inst.instruction = THUMB_OP16 (inst.instruction);
10031 inst.instruction |= THUMB_PP_PC_LR;
10032 inst.instruction |= mask & 0xff;
10033 }
10034 else if (unified_syntax)
10035 {
10036 inst.instruction = THUMB_OP32 (inst.instruction);
10037 encode_thumb2_ldmstm (13, mask, TRUE);
10038 }
10039 else
10040 {
10041 inst.error = _("invalid register list to push/pop instruction");
10042 return;
10043 }
10044 }
10045
10046 static void
10047 do_t_rbit (void)
10048 {
10049 inst.instruction |= inst.operands[0].reg << 8;
10050 inst.instruction |= inst.operands[1].reg << 16;
10051 }
10052
10053 static void
10054 do_t_rev (void)
10055 {
10056 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10057 && inst.size_req != 4)
10058 {
10059 inst.instruction = THUMB_OP16 (inst.instruction);
10060 inst.instruction |= inst.operands[0].reg;
10061 inst.instruction |= inst.operands[1].reg << 3;
10062 }
10063 else if (unified_syntax)
10064 {
10065 inst.instruction = THUMB_OP32 (inst.instruction);
10066 inst.instruction |= inst.operands[0].reg << 8;
10067 inst.instruction |= inst.operands[1].reg << 16;
10068 inst.instruction |= inst.operands[1].reg;
10069 }
10070 else
10071 inst.error = BAD_HIREG;
10072 }
10073
10074 static void
10075 do_t_rsb (void)
10076 {
10077 int Rd, Rs;
10078
10079 Rd = inst.operands[0].reg;
10080 Rs = (inst.operands[1].present
10081 ? inst.operands[1].reg /* Rd, Rs, foo */
10082 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10083
10084 inst.instruction |= Rd << 8;
10085 inst.instruction |= Rs << 16;
10086 if (!inst.operands[2].isreg)
10087 {
10088 bfd_boolean narrow;
10089
10090 if ((inst.instruction & 0x00100000) != 0)
10091 narrow = (current_it_mask == 0);
10092 else
10093 narrow = (current_it_mask != 0);
10094
10095 if (Rd > 7 || Rs > 7)
10096 narrow = FALSE;
10097
10098 if (inst.size_req == 4 || !unified_syntax)
10099 narrow = FALSE;
10100
10101 if (inst.reloc.exp.X_op != O_constant
10102 || inst.reloc.exp.X_add_number != 0)
10103 narrow = FALSE;
10104
10105 /* Turn rsb #0 into 16-bit neg. We should probably do this via
10106 relaxation, but it doesn't seem worth the hassle. */
10107 if (narrow)
10108 {
10109 inst.reloc.type = BFD_RELOC_UNUSED;
10110 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10111 inst.instruction |= Rs << 3;
10112 inst.instruction |= Rd;
10113 }
10114 else
10115 {
10116 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10117 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10118 }
10119 }
10120 else
10121 encode_thumb32_shifted_operand (2);
10122 }
10123
10124 static void
10125 do_t_setend (void)
10126 {
10127 constraint (current_it_mask, BAD_NOT_IT);
10128 if (inst.operands[0].imm)
10129 inst.instruction |= 0x8;
10130 }
10131
10132 static void
10133 do_t_shift (void)
10134 {
10135 if (!inst.operands[1].present)
10136 inst.operands[1].reg = inst.operands[0].reg;
10137
10138 if (unified_syntax)
10139 {
10140 bfd_boolean narrow;
10141 int shift_kind;
10142
10143 switch (inst.instruction)
10144 {
10145 case T_MNEM_asr:
10146 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
10147 case T_MNEM_lsl:
10148 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
10149 case T_MNEM_lsr:
10150 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
10151 case T_MNEM_ror:
10152 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
10153 default: abort ();
10154 }
10155
10156 if (THUMB_SETS_FLAGS (inst.instruction))
10157 narrow = (current_it_mask == 0);
10158 else
10159 narrow = (current_it_mask != 0);
10160 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10161 narrow = FALSE;
10162 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
10163 narrow = FALSE;
10164 if (inst.operands[2].isreg
10165 && (inst.operands[1].reg != inst.operands[0].reg
10166 || inst.operands[2].reg > 7))
10167 narrow = FALSE;
10168 if (inst.size_req == 4)
10169 narrow = FALSE;
10170
10171 if (!narrow)
10172 {
10173 if (inst.operands[2].isreg)
10174 {
10175 inst.instruction = THUMB_OP32 (inst.instruction);
10176 inst.instruction |= inst.operands[0].reg << 8;
10177 inst.instruction |= inst.operands[1].reg << 16;
10178 inst.instruction |= inst.operands[2].reg;
10179 }
10180 else
10181 {
10182 inst.operands[1].shifted = 1;
10183 inst.operands[1].shift_kind = shift_kind;
10184 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
10185 ? T_MNEM_movs : T_MNEM_mov);
10186 inst.instruction |= inst.operands[0].reg << 8;
10187 encode_thumb32_shifted_operand (1);
10188 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
10189 inst.reloc.type = BFD_RELOC_UNUSED;
10190 }
10191 }
10192 else
10193 {
10194 if (inst.operands[2].isreg)
10195 {
10196 switch (shift_kind)
10197 {
10198 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
10199 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
10200 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
10201 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
10202 default: abort ();
10203 }
10204
10205 inst.instruction |= inst.operands[0].reg;
10206 inst.instruction |= inst.operands[2].reg << 3;
10207 }
10208 else
10209 {
10210 switch (shift_kind)
10211 {
10212 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10213 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10214 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10215 default: abort ();
10216 }
10217 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10218 inst.instruction |= inst.operands[0].reg;
10219 inst.instruction |= inst.operands[1].reg << 3;
10220 }
10221 }
10222 }
10223 else
10224 {
10225 constraint (inst.operands[0].reg > 7
10226 || inst.operands[1].reg > 7, BAD_HIREG);
10227 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10228
10229 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
10230 {
10231 constraint (inst.operands[2].reg > 7, BAD_HIREG);
10232 constraint (inst.operands[0].reg != inst.operands[1].reg,
10233 _("source1 and dest must be same register"));
10234
10235 switch (inst.instruction)
10236 {
10237 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
10238 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
10239 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
10240 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
10241 default: abort ();
10242 }
10243
10244 inst.instruction |= inst.operands[0].reg;
10245 inst.instruction |= inst.operands[2].reg << 3;
10246 }
10247 else
10248 {
10249 switch (inst.instruction)
10250 {
10251 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
10252 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
10253 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
10254 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
10255 default: abort ();
10256 }
10257 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10258 inst.instruction |= inst.operands[0].reg;
10259 inst.instruction |= inst.operands[1].reg << 3;
10260 }
10261 }
10262 }
10263
10264 static void
10265 do_t_simd (void)
10266 {
10267 inst.instruction |= inst.operands[0].reg << 8;
10268 inst.instruction |= inst.operands[1].reg << 16;
10269 inst.instruction |= inst.operands[2].reg;
10270 }
10271
10272 static void
10273 do_t_smc (void)
10274 {
10275 unsigned int value = inst.reloc.exp.X_add_number;
10276 constraint (inst.reloc.exp.X_op != O_constant,
10277 _("expression too complex"));
10278 inst.reloc.type = BFD_RELOC_UNUSED;
10279 inst.instruction |= (value & 0xf000) >> 12;
10280 inst.instruction |= (value & 0x0ff0);
10281 inst.instruction |= (value & 0x000f) << 16;
10282 }
10283
10284 static void
10285 do_t_ssat (void)
10286 {
10287 inst.instruction |= inst.operands[0].reg << 8;
10288 inst.instruction |= inst.operands[1].imm - 1;
10289 inst.instruction |= inst.operands[2].reg << 16;
10290
10291 if (inst.operands[3].present)
10292 {
10293 constraint (inst.reloc.exp.X_op != O_constant,
10294 _("expression too complex"));
10295
10296 if (inst.reloc.exp.X_add_number != 0)
10297 {
10298 if (inst.operands[3].shift_kind == SHIFT_ASR)
10299 inst.instruction |= 0x00200000; /* sh bit */
10300 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10301 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10302 }
10303 inst.reloc.type = BFD_RELOC_UNUSED;
10304 }
10305 }
10306
10307 static void
10308 do_t_ssat16 (void)
10309 {
10310 inst.instruction |= inst.operands[0].reg << 8;
10311 inst.instruction |= inst.operands[1].imm - 1;
10312 inst.instruction |= inst.operands[2].reg << 16;
10313 }
10314
10315 static void
10316 do_t_strex (void)
10317 {
10318 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10319 || inst.operands[2].postind || inst.operands[2].writeback
10320 || inst.operands[2].immisreg || inst.operands[2].shifted
10321 || inst.operands[2].negative,
10322 BAD_ADDR_MODE);
10323
10324 inst.instruction |= inst.operands[0].reg << 8;
10325 inst.instruction |= inst.operands[1].reg << 12;
10326 inst.instruction |= inst.operands[2].reg << 16;
10327 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
10328 }
10329
10330 static void
10331 do_t_strexd (void)
10332 {
10333 if (!inst.operands[2].present)
10334 inst.operands[2].reg = inst.operands[1].reg + 1;
10335
10336 constraint (inst.operands[0].reg == inst.operands[1].reg
10337 || inst.operands[0].reg == inst.operands[2].reg
10338 || inst.operands[0].reg == inst.operands[3].reg
10339 || inst.operands[1].reg == inst.operands[2].reg,
10340 BAD_OVERLAP);
10341
10342 inst.instruction |= inst.operands[0].reg;
10343 inst.instruction |= inst.operands[1].reg << 12;
10344 inst.instruction |= inst.operands[2].reg << 8;
10345 inst.instruction |= inst.operands[3].reg << 16;
10346 }
10347
10348 static void
10349 do_t_sxtah (void)
10350 {
10351 inst.instruction |= inst.operands[0].reg << 8;
10352 inst.instruction |= inst.operands[1].reg << 16;
10353 inst.instruction |= inst.operands[2].reg;
10354 inst.instruction |= inst.operands[3].imm << 4;
10355 }
10356
10357 static void
10358 do_t_sxth (void)
10359 {
10360 if (inst.instruction <= 0xffff && inst.size_req != 4
10361 && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10362 && (!inst.operands[2].present || inst.operands[2].imm == 0))
10363 {
10364 inst.instruction = THUMB_OP16 (inst.instruction);
10365 inst.instruction |= inst.operands[0].reg;
10366 inst.instruction |= inst.operands[1].reg << 3;
10367 }
10368 else if (unified_syntax)
10369 {
10370 if (inst.instruction <= 0xffff)
10371 inst.instruction = THUMB_OP32 (inst.instruction);
10372 inst.instruction |= inst.operands[0].reg << 8;
10373 inst.instruction |= inst.operands[1].reg;
10374 inst.instruction |= inst.operands[2].imm << 4;
10375 }
10376 else
10377 {
10378 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
10379 _("Thumb encoding does not support rotation"));
10380 constraint (1, BAD_HIREG);
10381 }
10382 }
10383
10384 static void
10385 do_t_swi (void)
10386 {
10387 inst.reloc.type = BFD_RELOC_ARM_SWI;
10388 }
10389
10390 static void
10391 do_t_tb (void)
10392 {
10393 int half;
10394
10395 half = (inst.instruction & 0x10) != 0;
10396 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
10397 constraint (inst.operands[0].immisreg,
10398 _("instruction requires register index"));
10399 constraint (inst.operands[0].imm == 15,
10400 _("PC is not a valid index register"));
10401 constraint (!half && inst.operands[0].shifted,
10402 _("instruction does not allow shifted index"));
10403 inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm;
10404 }
10405
10406 static void
10407 do_t_usat (void)
10408 {
10409 inst.instruction |= inst.operands[0].reg << 8;
10410 inst.instruction |= inst.operands[1].imm;
10411 inst.instruction |= inst.operands[2].reg << 16;
10412
10413 if (inst.operands[3].present)
10414 {
10415 constraint (inst.reloc.exp.X_op != O_constant,
10416 _("expression too complex"));
10417 if (inst.reloc.exp.X_add_number != 0)
10418 {
10419 if (inst.operands[3].shift_kind == SHIFT_ASR)
10420 inst.instruction |= 0x00200000; /* sh bit */
10421
10422 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10423 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10424 }
10425 inst.reloc.type = BFD_RELOC_UNUSED;
10426 }
10427 }
10428
10429 static void
10430 do_t_usat16 (void)
10431 {
10432 inst.instruction |= inst.operands[0].reg << 8;
10433 inst.instruction |= inst.operands[1].imm;
10434 inst.instruction |= inst.operands[2].reg << 16;
10435 }
10436
10437 /* Neon instruction encoder helpers. */
10438
10439 /* Encodings for the different types for various Neon opcodes. */
10440
10441 /* An "invalid" code for the following tables. */
10442 #define N_INV -1u
10443
10444 struct neon_tab_entry
10445 {
10446 unsigned integer;
10447 unsigned float_or_poly;
10448 unsigned scalar_or_imm;
10449 };
10450
10451 /* Map overloaded Neon opcodes to their respective encodings. */
10452 #define NEON_ENC_TAB \
10453 X(vabd, 0x0000700, 0x1200d00, N_INV), \
10454 X(vmax, 0x0000600, 0x0000f00, N_INV), \
10455 X(vmin, 0x0000610, 0x0200f00, N_INV), \
10456 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
10457 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
10458 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
10459 X(vadd, 0x0000800, 0x0000d00, N_INV), \
10460 X(vsub, 0x1000800, 0x0200d00, N_INV), \
10461 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
10462 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
10463 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
10464 /* Register variants of the following two instructions are encoded as
10465 vcge / vcgt with the operands reversed. */ \
10466 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
10467 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
10468 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
10469 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
10470 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
10471 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
10472 X(vmlal, 0x0800800, N_INV, 0x0800240), \
10473 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
10474 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
10475 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
10476 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
10477 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
10478 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
10479 X(vshl, 0x0000400, N_INV, 0x0800510), \
10480 X(vqshl, 0x0000410, N_INV, 0x0800710), \
10481 X(vand, 0x0000110, N_INV, 0x0800030), \
10482 X(vbic, 0x0100110, N_INV, 0x0800030), \
10483 X(veor, 0x1000110, N_INV, N_INV), \
10484 X(vorn, 0x0300110, N_INV, 0x0800010), \
10485 X(vorr, 0x0200110, N_INV, 0x0800010), \
10486 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
10487 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
10488 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
10489 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
10490 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
10491 X(vst1, 0x0000000, 0x0800000, N_INV), \
10492 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
10493 X(vst2, 0x0000100, 0x0800100, N_INV), \
10494 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
10495 X(vst3, 0x0000200, 0x0800200, N_INV), \
10496 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
10497 X(vst4, 0x0000300, 0x0800300, N_INV), \
10498 X(vmovn, 0x1b20200, N_INV, N_INV), \
10499 X(vtrn, 0x1b20080, N_INV, N_INV), \
10500 X(vqmovn, 0x1b20200, N_INV, N_INV), \
10501 X(vqmovun, 0x1b20240, N_INV, N_INV), \
10502 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
10503 X(vnmla, 0xe000a40, 0xe000b40, N_INV), \
10504 X(vnmls, 0xe100a40, 0xe100b40, N_INV), \
10505 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
10506 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
10507 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
10508 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
10509
10510 enum neon_opc
10511 {
10512 #define X(OPC,I,F,S) N_MNEM_##OPC
10513 NEON_ENC_TAB
10514 #undef X
10515 };
10516
10517 static const struct neon_tab_entry neon_enc_tab[] =
10518 {
10519 #define X(OPC,I,F,S) { (I), (F), (S) }
10520 NEON_ENC_TAB
10521 #undef X
10522 };
10523
10524 #define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10525 #define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10526 #define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10527 #define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10528 #define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10529 #define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10530 #define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10531 #define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10532 #define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10533 #define NEON_ENC_SINGLE(X) \
10534 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
10535 #define NEON_ENC_DOUBLE(X) \
10536 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
10537
10538 /* Define shapes for instruction operands. The following mnemonic characters
10539 are used in this table:
10540
10541 F - VFP S<n> register
10542 D - Neon D<n> register
10543 Q - Neon Q<n> register
10544 I - Immediate
10545 S - Scalar
10546 R - ARM register
10547 L - D<n> register list
10548
10549 This table is used to generate various data:
10550 - enumerations of the form NS_DDR to be used as arguments to
10551 neon_select_shape.
10552 - a table classifying shapes into single, double, quad, mixed.
10553 - a table used to drive neon_select_shape. */
10554
10555 #define NEON_SHAPE_DEF \
10556 X(3, (D, D, D), DOUBLE), \
10557 X(3, (Q, Q, Q), QUAD), \
10558 X(3, (D, D, I), DOUBLE), \
10559 X(3, (Q, Q, I), QUAD), \
10560 X(3, (D, D, S), DOUBLE), \
10561 X(3, (Q, Q, S), QUAD), \
10562 X(2, (D, D), DOUBLE), \
10563 X(2, (Q, Q), QUAD), \
10564 X(2, (D, S), DOUBLE), \
10565 X(2, (Q, S), QUAD), \
10566 X(2, (D, R), DOUBLE), \
10567 X(2, (Q, R), QUAD), \
10568 X(2, (D, I), DOUBLE), \
10569 X(2, (Q, I), QUAD), \
10570 X(3, (D, L, D), DOUBLE), \
10571 X(2, (D, Q), MIXED), \
10572 X(2, (Q, D), MIXED), \
10573 X(3, (D, Q, I), MIXED), \
10574 X(3, (Q, D, I), MIXED), \
10575 X(3, (Q, D, D), MIXED), \
10576 X(3, (D, Q, Q), MIXED), \
10577 X(3, (Q, Q, D), MIXED), \
10578 X(3, (Q, D, S), MIXED), \
10579 X(3, (D, Q, S), MIXED), \
10580 X(4, (D, D, D, I), DOUBLE), \
10581 X(4, (Q, Q, Q, I), QUAD), \
10582 X(2, (F, F), SINGLE), \
10583 X(3, (F, F, F), SINGLE), \
10584 X(2, (F, I), SINGLE), \
10585 X(2, (F, D), MIXED), \
10586 X(2, (D, F), MIXED), \
10587 X(3, (F, F, I), MIXED), \
10588 X(4, (R, R, F, F), SINGLE), \
10589 X(4, (F, F, R, R), SINGLE), \
10590 X(3, (D, R, R), DOUBLE), \
10591 X(3, (R, R, D), DOUBLE), \
10592 X(2, (S, R), SINGLE), \
10593 X(2, (R, S), SINGLE), \
10594 X(2, (F, R), SINGLE), \
10595 X(2, (R, F), SINGLE)
10596
10597 #define S2(A,B) NS_##A##B
10598 #define S3(A,B,C) NS_##A##B##C
10599 #define S4(A,B,C,D) NS_##A##B##C##D
10600
10601 #define X(N, L, C) S##N L
10602
10603 enum neon_shape
10604 {
10605 NEON_SHAPE_DEF,
10606 NS_NULL
10607 };
10608
10609 #undef X
10610 #undef S2
10611 #undef S3
10612 #undef S4
10613
10614 enum neon_shape_class
10615 {
10616 SC_SINGLE,
10617 SC_DOUBLE,
10618 SC_QUAD,
10619 SC_MIXED
10620 };
10621
10622 #define X(N, L, C) SC_##C
10623
10624 static enum neon_shape_class neon_shape_class[] =
10625 {
10626 NEON_SHAPE_DEF
10627 };
10628
10629 #undef X
10630
10631 enum neon_shape_el
10632 {
10633 SE_F,
10634 SE_D,
10635 SE_Q,
10636 SE_I,
10637 SE_S,
10638 SE_R,
10639 SE_L
10640 };
10641
10642 /* Register widths of above. */
10643 static unsigned neon_shape_el_size[] =
10644 {
10645 32,
10646 64,
10647 128,
10648 0,
10649 32,
10650 32,
10651 0
10652 };
10653
10654 struct neon_shape_info
10655 {
10656 unsigned els;
10657 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
10658 };
10659
10660 #define S2(A,B) { SE_##A, SE_##B }
10661 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
10662 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
10663
10664 #define X(N, L, C) { N, S##N L }
10665
10666 static struct neon_shape_info neon_shape_tab[] =
10667 {
10668 NEON_SHAPE_DEF
10669 };
10670
10671 #undef X
10672 #undef S2
10673 #undef S3
10674 #undef S4
10675
10676 /* Bit masks used in type checking given instructions.
10677 'N_EQK' means the type must be the same as (or based on in some way) the key
10678 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
10679 set, various other bits can be set as well in order to modify the meaning of
10680 the type constraint. */
10681
10682 enum neon_type_mask
10683 {
10684 N_S8 = 0x000001,
10685 N_S16 = 0x000002,
10686 N_S32 = 0x000004,
10687 N_S64 = 0x000008,
10688 N_U8 = 0x000010,
10689 N_U16 = 0x000020,
10690 N_U32 = 0x000040,
10691 N_U64 = 0x000080,
10692 N_I8 = 0x000100,
10693 N_I16 = 0x000200,
10694 N_I32 = 0x000400,
10695 N_I64 = 0x000800,
10696 N_8 = 0x001000,
10697 N_16 = 0x002000,
10698 N_32 = 0x004000,
10699 N_64 = 0x008000,
10700 N_P8 = 0x010000,
10701 N_P16 = 0x020000,
10702 N_F32 = 0x040000,
10703 N_F64 = 0x080000,
10704 N_KEY = 0x100000, /* key element (main type specifier). */
10705 N_EQK = 0x200000, /* given operand has the same type & size as the key. */
10706 N_VFP = 0x400000, /* VFP mode: operand size must match register width. */
10707 N_DBL = 0x000001, /* if N_EQK, this operand is twice the size. */
10708 N_HLF = 0x000002, /* if N_EQK, this operand is half the size. */
10709 N_SGN = 0x000004, /* if N_EQK, this operand is forced to be signed. */
10710 N_UNS = 0x000008, /* if N_EQK, this operand is forced to be unsigned. */
10711 N_INT = 0x000010, /* if N_EQK, this operand is forced to be integer. */
10712 N_FLT = 0x000020, /* if N_EQK, this operand is forced to be float. */
10713 N_SIZ = 0x000040, /* if N_EQK, this operand is forced to be size-only. */
10714 N_UTYP = 0,
10715 N_MAX_NONSPECIAL = N_F64
10716 };
10717
10718 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
10719
10720 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
10721 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
10722 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
10723 #define N_SUF_32 (N_SU_32 | N_F32)
10724 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
10725 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
10726
10727 /* Pass this as the first type argument to neon_check_type to ignore types
10728 altogether. */
10729 #define N_IGNORE_TYPE (N_KEY | N_EQK)
10730
10731 /* Select a "shape" for the current instruction (describing register types or
10732 sizes) from a list of alternatives. Return NS_NULL if the current instruction
10733 doesn't fit. For non-polymorphic shapes, checking is usually done as a
10734 function of operand parsing, so this function doesn't need to be called.
10735 Shapes should be listed in order of decreasing length. */
10736
10737 static enum neon_shape
10738 neon_select_shape (enum neon_shape shape, ...)
10739 {
10740 va_list ap;
10741 enum neon_shape first_shape = shape;
10742
10743 /* Fix missing optional operands. FIXME: we don't know at this point how
10744 many arguments we should have, so this makes the assumption that we have
10745 > 1. This is true of all current Neon opcodes, I think, but may not be
10746 true in the future. */
10747 if (!inst.operands[1].present)
10748 inst.operands[1] = inst.operands[0];
10749
10750 va_start (ap, shape);
10751
10752 for (; shape != NS_NULL; shape = va_arg (ap, int))
10753 {
10754 unsigned j;
10755 int matches = 1;
10756
10757 for (j = 0; j < neon_shape_tab[shape].els; j++)
10758 {
10759 if (!inst.operands[j].present)
10760 {
10761 matches = 0;
10762 break;
10763 }
10764
10765 switch (neon_shape_tab[shape].el[j])
10766 {
10767 case SE_F:
10768 if (!(inst.operands[j].isreg
10769 && inst.operands[j].isvec
10770 && inst.operands[j].issingle
10771 && !inst.operands[j].isquad))
10772 matches = 0;
10773 break;
10774
10775 case SE_D:
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_R:
10784 if (!(inst.operands[j].isreg
10785 && !inst.operands[j].isvec))
10786 matches = 0;
10787 break;
10788
10789 case SE_Q:
10790 if (!(inst.operands[j].isreg
10791 && inst.operands[j].isvec
10792 && inst.operands[j].isquad
10793 && !inst.operands[j].issingle))
10794 matches = 0;
10795 break;
10796
10797 case SE_I:
10798 if (!(!inst.operands[j].isreg
10799 && !inst.operands[j].isscalar))
10800 matches = 0;
10801 break;
10802
10803 case SE_S:
10804 if (!(!inst.operands[j].isreg
10805 && inst.operands[j].isscalar))
10806 matches = 0;
10807 break;
10808
10809 case SE_L:
10810 break;
10811 }
10812 }
10813 if (matches)
10814 break;
10815 }
10816
10817 va_end (ap);
10818
10819 if (shape == NS_NULL && first_shape != NS_NULL)
10820 first_error (_("invalid instruction shape"));
10821
10822 return shape;
10823 }
10824
10825 /* True if SHAPE is predominantly a quadword operation (most of the time, this
10826 means the Q bit should be set). */
10827
10828 static int
10829 neon_quad (enum neon_shape shape)
10830 {
10831 return neon_shape_class[shape] == SC_QUAD;
10832 }
10833
10834 static void
10835 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
10836 unsigned *g_size)
10837 {
10838 /* Allow modification to be made to types which are constrained to be
10839 based on the key element, based on bits set alongside N_EQK. */
10840 if ((typebits & N_EQK) != 0)
10841 {
10842 if ((typebits & N_HLF) != 0)
10843 *g_size /= 2;
10844 else if ((typebits & N_DBL) != 0)
10845 *g_size *= 2;
10846 if ((typebits & N_SGN) != 0)
10847 *g_type = NT_signed;
10848 else if ((typebits & N_UNS) != 0)
10849 *g_type = NT_unsigned;
10850 else if ((typebits & N_INT) != 0)
10851 *g_type = NT_integer;
10852 else if ((typebits & N_FLT) != 0)
10853 *g_type = NT_float;
10854 else if ((typebits & N_SIZ) != 0)
10855 *g_type = NT_untyped;
10856 }
10857 }
10858
10859 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
10860 operand type, i.e. the single type specified in a Neon instruction when it
10861 is the only one given. */
10862
10863 static struct neon_type_el
10864 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
10865 {
10866 struct neon_type_el dest = *key;
10867
10868 assert ((thisarg & N_EQK) != 0);
10869
10870 neon_modify_type_size (thisarg, &dest.type, &dest.size);
10871
10872 return dest;
10873 }
10874
10875 /* Convert Neon type and size into compact bitmask representation. */
10876
10877 static enum neon_type_mask
10878 type_chk_of_el_type (enum neon_el_type type, unsigned size)
10879 {
10880 switch (type)
10881 {
10882 case NT_untyped:
10883 switch (size)
10884 {
10885 case 8: return N_8;
10886 case 16: return N_16;
10887 case 32: return N_32;
10888 case 64: return N_64;
10889 default: ;
10890 }
10891 break;
10892
10893 case NT_integer:
10894 switch (size)
10895 {
10896 case 8: return N_I8;
10897 case 16: return N_I16;
10898 case 32: return N_I32;
10899 case 64: return N_I64;
10900 default: ;
10901 }
10902 break;
10903
10904 case NT_float:
10905 switch (size)
10906 {
10907 case 32: return N_F32;
10908 case 64: return N_F64;
10909 default: ;
10910 }
10911 break;
10912
10913 case NT_poly:
10914 switch (size)
10915 {
10916 case 8: return N_P8;
10917 case 16: return N_P16;
10918 default: ;
10919 }
10920 break;
10921
10922 case NT_signed:
10923 switch (size)
10924 {
10925 case 8: return N_S8;
10926 case 16: return N_S16;
10927 case 32: return N_S32;
10928 case 64: return N_S64;
10929 default: ;
10930 }
10931 break;
10932
10933 case NT_unsigned:
10934 switch (size)
10935 {
10936 case 8: return N_U8;
10937 case 16: return N_U16;
10938 case 32: return N_U32;
10939 case 64: return N_U64;
10940 default: ;
10941 }
10942 break;
10943
10944 default: ;
10945 }
10946
10947 return N_UTYP;
10948 }
10949
10950 /* Convert compact Neon bitmask type representation to a type and size. Only
10951 handles the case where a single bit is set in the mask. */
10952
10953 static int
10954 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
10955 enum neon_type_mask mask)
10956 {
10957 if ((mask & N_EQK) != 0)
10958 return FAIL;
10959
10960 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
10961 *size = 8;
10962 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
10963 *size = 16;
10964 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
10965 *size = 32;
10966 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
10967 *size = 64;
10968 else
10969 return FAIL;
10970
10971 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
10972 *type = NT_signed;
10973 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
10974 *type = NT_unsigned;
10975 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
10976 *type = NT_integer;
10977 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
10978 *type = NT_untyped;
10979 else if ((mask & (N_P8 | N_P16)) != 0)
10980 *type = NT_poly;
10981 else if ((mask & (N_F32 | N_F64)) != 0)
10982 *type = NT_float;
10983 else
10984 return FAIL;
10985
10986 return SUCCESS;
10987 }
10988
10989 /* Modify a bitmask of allowed types. This is only needed for type
10990 relaxation. */
10991
10992 static unsigned
10993 modify_types_allowed (unsigned allowed, unsigned mods)
10994 {
10995 unsigned size;
10996 enum neon_el_type type;
10997 unsigned destmask;
10998 int i;
10999
11000 destmask = 0;
11001
11002 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
11003 {
11004 if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS)
11005 {
11006 neon_modify_type_size (mods, &type, &size);
11007 destmask |= type_chk_of_el_type (type, size);
11008 }
11009 }
11010
11011 return destmask;
11012 }
11013
11014 /* Check type and return type classification.
11015 The manual states (paraphrase): If one datatype is given, it indicates the
11016 type given in:
11017 - the second operand, if there is one
11018 - the operand, if there is no second operand
11019 - the result, if there are no operands.
11020 This isn't quite good enough though, so we use a concept of a "key" datatype
11021 which is set on a per-instruction basis, which is the one which matters when
11022 only one data type is written.
11023 Note: this function has side-effects (e.g. filling in missing operands). All
11024 Neon instructions should call it before performing bit encoding. */
11025
11026 static struct neon_type_el
11027 neon_check_type (unsigned els, enum neon_shape ns, ...)
11028 {
11029 va_list ap;
11030 unsigned i, pass, key_el = 0;
11031 unsigned types[NEON_MAX_TYPE_ELS];
11032 enum neon_el_type k_type = NT_invtype;
11033 unsigned k_size = -1u;
11034 struct neon_type_el badtype = {NT_invtype, -1};
11035 unsigned key_allowed = 0;
11036
11037 /* Optional registers in Neon instructions are always (not) in operand 1.
11038 Fill in the missing operand here, if it was omitted. */
11039 if (els > 1 && !inst.operands[1].present)
11040 inst.operands[1] = inst.operands[0];
11041
11042 /* Suck up all the varargs. */
11043 va_start (ap, ns);
11044 for (i = 0; i < els; i++)
11045 {
11046 unsigned thisarg = va_arg (ap, unsigned);
11047 if (thisarg == N_IGNORE_TYPE)
11048 {
11049 va_end (ap);
11050 return badtype;
11051 }
11052 types[i] = thisarg;
11053 if ((thisarg & N_KEY) != 0)
11054 key_el = i;
11055 }
11056 va_end (ap);
11057
11058 if (inst.vectype.elems > 0)
11059 for (i = 0; i < els; i++)
11060 if (inst.operands[i].vectype.type != NT_invtype)
11061 {
11062 first_error (_("types specified in both the mnemonic and operands"));
11063 return badtype;
11064 }
11065
11066 /* Duplicate inst.vectype elements here as necessary.
11067 FIXME: No idea if this is exactly the same as the ARM assembler,
11068 particularly when an insn takes one register and one non-register
11069 operand. */
11070 if (inst.vectype.elems == 1 && els > 1)
11071 {
11072 unsigned j;
11073 inst.vectype.elems = els;
11074 inst.vectype.el[key_el] = inst.vectype.el[0];
11075 for (j = 0; j < els; j++)
11076 if (j != key_el)
11077 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11078 types[j]);
11079 }
11080 else if (inst.vectype.elems == 0 && els > 0)
11081 {
11082 unsigned j;
11083 /* No types were given after the mnemonic, so look for types specified
11084 after each operand. We allow some flexibility here; as long as the
11085 "key" operand has a type, we can infer the others. */
11086 for (j = 0; j < els; j++)
11087 if (inst.operands[j].vectype.type != NT_invtype)
11088 inst.vectype.el[j] = inst.operands[j].vectype;
11089
11090 if (inst.operands[key_el].vectype.type != NT_invtype)
11091 {
11092 for (j = 0; j < els; j++)
11093 if (inst.operands[j].vectype.type == NT_invtype)
11094 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11095 types[j]);
11096 }
11097 else
11098 {
11099 first_error (_("operand types can't be inferred"));
11100 return badtype;
11101 }
11102 }
11103 else if (inst.vectype.elems != els)
11104 {
11105 first_error (_("type specifier has the wrong number of parts"));
11106 return badtype;
11107 }
11108
11109 for (pass = 0; pass < 2; pass++)
11110 {
11111 for (i = 0; i < els; i++)
11112 {
11113 unsigned thisarg = types[i];
11114 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
11115 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
11116 enum neon_el_type g_type = inst.vectype.el[i].type;
11117 unsigned g_size = inst.vectype.el[i].size;
11118
11119 /* Decay more-specific signed & unsigned types to sign-insensitive
11120 integer types if sign-specific variants are unavailable. */
11121 if ((g_type == NT_signed || g_type == NT_unsigned)
11122 && (types_allowed & N_SU_ALL) == 0)
11123 g_type = NT_integer;
11124
11125 /* If only untyped args are allowed, decay any more specific types to
11126 them. Some instructions only care about signs for some element
11127 sizes, so handle that properly. */
11128 if ((g_size == 8 && (types_allowed & N_8) != 0)
11129 || (g_size == 16 && (types_allowed & N_16) != 0)
11130 || (g_size == 32 && (types_allowed & N_32) != 0)
11131 || (g_size == 64 && (types_allowed & N_64) != 0))
11132 g_type = NT_untyped;
11133
11134 if (pass == 0)
11135 {
11136 if ((thisarg & N_KEY) != 0)
11137 {
11138 k_type = g_type;
11139 k_size = g_size;
11140 key_allowed = thisarg & ~N_KEY;
11141 }
11142 }
11143 else
11144 {
11145 if ((thisarg & N_VFP) != 0)
11146 {
11147 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
11148 unsigned regwidth = neon_shape_el_size[regshape], match;
11149
11150 /* In VFP mode, operands must match register widths. If we
11151 have a key operand, use its width, else use the width of
11152 the current operand. */
11153 if (k_size != -1u)
11154 match = k_size;
11155 else
11156 match = g_size;
11157
11158 if (regwidth != match)
11159 {
11160 first_error (_("operand size must match register width"));
11161 return badtype;
11162 }
11163 }
11164
11165 if ((thisarg & N_EQK) == 0)
11166 {
11167 unsigned given_type = type_chk_of_el_type (g_type, g_size);
11168
11169 if ((given_type & types_allowed) == 0)
11170 {
11171 first_error (_("bad type in Neon instruction"));
11172 return badtype;
11173 }
11174 }
11175 else
11176 {
11177 enum neon_el_type mod_k_type = k_type;
11178 unsigned mod_k_size = k_size;
11179 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
11180 if (g_type != mod_k_type || g_size != mod_k_size)
11181 {
11182 first_error (_("inconsistent types in Neon instruction"));
11183 return badtype;
11184 }
11185 }
11186 }
11187 }
11188 }
11189
11190 return inst.vectype.el[key_el];
11191 }
11192
11193 /* Neon-style VFP instruction forwarding. */
11194
11195 /* Thumb VFP instructions have 0xE in the condition field. */
11196
11197 static void
11198 do_vfp_cond_or_thumb (void)
11199 {
11200 if (thumb_mode)
11201 inst.instruction |= 0xe0000000;
11202 else
11203 inst.instruction |= inst.cond << 28;
11204 }
11205
11206 /* Look up and encode a simple mnemonic, for use as a helper function for the
11207 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
11208 etc. It is assumed that operand parsing has already been done, and that the
11209 operands are in the form expected by the given opcode (this isn't necessarily
11210 the same as the form in which they were parsed, hence some massaging must
11211 take place before this function is called).
11212 Checks current arch version against that in the looked-up opcode. */
11213
11214 static void
11215 do_vfp_nsyn_opcode (const char *opname)
11216 {
11217 const struct asm_opcode *opcode;
11218
11219 opcode = hash_find (arm_ops_hsh, opname);
11220
11221 if (!opcode)
11222 abort ();
11223
11224 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
11225 thumb_mode ? *opcode->tvariant : *opcode->avariant),
11226 _(BAD_FPU));
11227
11228 if (thumb_mode)
11229 {
11230 inst.instruction = opcode->tvalue;
11231 opcode->tencode ();
11232 }
11233 else
11234 {
11235 inst.instruction = (inst.cond << 28) | opcode->avalue;
11236 opcode->aencode ();
11237 }
11238 }
11239
11240 static void
11241 do_vfp_nsyn_add_sub (enum neon_shape rs)
11242 {
11243 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
11244
11245 if (rs == NS_FFF)
11246 {
11247 if (is_add)
11248 do_vfp_nsyn_opcode ("fadds");
11249 else
11250 do_vfp_nsyn_opcode ("fsubs");
11251 }
11252 else
11253 {
11254 if (is_add)
11255 do_vfp_nsyn_opcode ("faddd");
11256 else
11257 do_vfp_nsyn_opcode ("fsubd");
11258 }
11259 }
11260
11261 /* Check operand types to see if this is a VFP instruction, and if so call
11262 PFN (). */
11263
11264 static int
11265 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
11266 {
11267 enum neon_shape rs;
11268 struct neon_type_el et;
11269
11270 switch (args)
11271 {
11272 case 2:
11273 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11274 et = neon_check_type (2, rs,
11275 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11276 break;
11277
11278 case 3:
11279 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11280 et = neon_check_type (3, rs,
11281 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11282 break;
11283
11284 default:
11285 abort ();
11286 }
11287
11288 if (et.type != NT_invtype)
11289 {
11290 pfn (rs);
11291 return SUCCESS;
11292 }
11293 else
11294 inst.error = NULL;
11295
11296 return FAIL;
11297 }
11298
11299 static void
11300 do_vfp_nsyn_mla_mls (enum neon_shape rs)
11301 {
11302 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
11303
11304 if (rs == NS_FFF)
11305 {
11306 if (is_mla)
11307 do_vfp_nsyn_opcode ("fmacs");
11308 else
11309 do_vfp_nsyn_opcode ("fmscs");
11310 }
11311 else
11312 {
11313 if (is_mla)
11314 do_vfp_nsyn_opcode ("fmacd");
11315 else
11316 do_vfp_nsyn_opcode ("fmscd");
11317 }
11318 }
11319
11320 static void
11321 do_vfp_nsyn_mul (enum neon_shape rs)
11322 {
11323 if (rs == NS_FFF)
11324 do_vfp_nsyn_opcode ("fmuls");
11325 else
11326 do_vfp_nsyn_opcode ("fmuld");
11327 }
11328
11329 static void
11330 do_vfp_nsyn_abs_neg (enum neon_shape rs)
11331 {
11332 int is_neg = (inst.instruction & 0x80) != 0;
11333 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
11334
11335 if (rs == NS_FF)
11336 {
11337 if (is_neg)
11338 do_vfp_nsyn_opcode ("fnegs");
11339 else
11340 do_vfp_nsyn_opcode ("fabss");
11341 }
11342 else
11343 {
11344 if (is_neg)
11345 do_vfp_nsyn_opcode ("fnegd");
11346 else
11347 do_vfp_nsyn_opcode ("fabsd");
11348 }
11349 }
11350
11351 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
11352 insns belong to Neon, and are handled elsewhere. */
11353
11354 static void
11355 do_vfp_nsyn_ldm_stm (int is_dbmode)
11356 {
11357 int is_ldm = (inst.instruction & (1 << 20)) != 0;
11358 if (is_ldm)
11359 {
11360 if (is_dbmode)
11361 do_vfp_nsyn_opcode ("fldmdbs");
11362 else
11363 do_vfp_nsyn_opcode ("fldmias");
11364 }
11365 else
11366 {
11367 if (is_dbmode)
11368 do_vfp_nsyn_opcode ("fstmdbs");
11369 else
11370 do_vfp_nsyn_opcode ("fstmias");
11371 }
11372 }
11373
11374 static void
11375 do_vfp_nsyn_sqrt (void)
11376 {
11377 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11378 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11379
11380 if (rs == NS_FF)
11381 do_vfp_nsyn_opcode ("fsqrts");
11382 else
11383 do_vfp_nsyn_opcode ("fsqrtd");
11384 }
11385
11386 static void
11387 do_vfp_nsyn_div (void)
11388 {
11389 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11390 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11391 N_F32 | N_F64 | N_KEY | N_VFP);
11392
11393 if (rs == NS_FFF)
11394 do_vfp_nsyn_opcode ("fdivs");
11395 else
11396 do_vfp_nsyn_opcode ("fdivd");
11397 }
11398
11399 static void
11400 do_vfp_nsyn_nmul (void)
11401 {
11402 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11403 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11404 N_F32 | N_F64 | N_KEY | N_VFP);
11405
11406 if (rs == NS_FFF)
11407 {
11408 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11409 do_vfp_sp_dyadic ();
11410 }
11411 else
11412 {
11413 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11414 do_vfp_dp_rd_rn_rm ();
11415 }
11416 do_vfp_cond_or_thumb ();
11417 }
11418
11419 static void
11420 do_vfp_nsyn_cmp (void)
11421 {
11422 if (inst.operands[1].isreg)
11423 {
11424 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11425 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11426
11427 if (rs == NS_FF)
11428 {
11429 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11430 do_vfp_sp_monadic ();
11431 }
11432 else
11433 {
11434 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11435 do_vfp_dp_rd_rm ();
11436 }
11437 }
11438 else
11439 {
11440 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
11441 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
11442
11443 switch (inst.instruction & 0x0fffffff)
11444 {
11445 case N_MNEM_vcmp:
11446 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
11447 break;
11448 case N_MNEM_vcmpe:
11449 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
11450 break;
11451 default:
11452 abort ();
11453 }
11454
11455 if (rs == NS_FI)
11456 {
11457 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11458 do_vfp_sp_compare_z ();
11459 }
11460 else
11461 {
11462 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11463 do_vfp_dp_rd ();
11464 }
11465 }
11466 do_vfp_cond_or_thumb ();
11467 }
11468
11469 static void
11470 nsyn_insert_sp (void)
11471 {
11472 inst.operands[1] = inst.operands[0];
11473 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
11474 inst.operands[0].reg = 13;
11475 inst.operands[0].isreg = 1;
11476 inst.operands[0].writeback = 1;
11477 inst.operands[0].present = 1;
11478 }
11479
11480 static void
11481 do_vfp_nsyn_push (void)
11482 {
11483 nsyn_insert_sp ();
11484 if (inst.operands[1].issingle)
11485 do_vfp_nsyn_opcode ("fstmdbs");
11486 else
11487 do_vfp_nsyn_opcode ("fstmdbd");
11488 }
11489
11490 static void
11491 do_vfp_nsyn_pop (void)
11492 {
11493 nsyn_insert_sp ();
11494 if (inst.operands[1].issingle)
11495 do_vfp_nsyn_opcode ("fldmias");
11496 else
11497 do_vfp_nsyn_opcode ("fldmiad");
11498 }
11499
11500 /* Fix up Neon data-processing instructions, ORing in the correct bits for
11501 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
11502
11503 static unsigned
11504 neon_dp_fixup (unsigned i)
11505 {
11506 if (thumb_mode)
11507 {
11508 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
11509 if (i & (1 << 24))
11510 i |= 1 << 28;
11511
11512 i &= ~(1 << 24);
11513
11514 i |= 0xef000000;
11515 }
11516 else
11517 i |= 0xf2000000;
11518
11519 return i;
11520 }
11521
11522 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
11523 (0, 1, 2, 3). */
11524
11525 static unsigned
11526 neon_logbits (unsigned x)
11527 {
11528 return ffs (x) - 4;
11529 }
11530
11531 #define LOW4(R) ((R) & 0xf)
11532 #define HI1(R) (((R) >> 4) & 1)
11533
11534 /* Encode insns with bit pattern:
11535
11536 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
11537 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
11538
11539 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
11540 different meaning for some instruction. */
11541
11542 static void
11543 neon_three_same (int isquad, int ubit, int size)
11544 {
11545 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11546 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11547 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
11548 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
11549 inst.instruction |= LOW4 (inst.operands[2].reg);
11550 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
11551 inst.instruction |= (isquad != 0) << 6;
11552 inst.instruction |= (ubit != 0) << 24;
11553 if (size != -1)
11554 inst.instruction |= neon_logbits (size) << 20;
11555
11556 inst.instruction = neon_dp_fixup (inst.instruction);
11557 }
11558
11559 /* Encode instructions of the form:
11560
11561 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
11562 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
11563
11564 Don't write size if SIZE == -1. */
11565
11566 static void
11567 neon_two_same (int qbit, int ubit, int size)
11568 {
11569 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11570 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11571 inst.instruction |= LOW4 (inst.operands[1].reg);
11572 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11573 inst.instruction |= (qbit != 0) << 6;
11574 inst.instruction |= (ubit != 0) << 24;
11575
11576 if (size != -1)
11577 inst.instruction |= neon_logbits (size) << 18;
11578
11579 inst.instruction = neon_dp_fixup (inst.instruction);
11580 }
11581
11582 /* Neon instruction encoders, in approximate order of appearance. */
11583
11584 static void
11585 do_neon_dyadic_i_su (void)
11586 {
11587 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11588 struct neon_type_el et = neon_check_type (3, rs,
11589 N_EQK, N_EQK, N_SU_32 | N_KEY);
11590 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11591 }
11592
11593 static void
11594 do_neon_dyadic_i64_su (void)
11595 {
11596 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11597 struct neon_type_el et = neon_check_type (3, rs,
11598 N_EQK, N_EQK, N_SU_ALL | N_KEY);
11599 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11600 }
11601
11602 static void
11603 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
11604 unsigned immbits)
11605 {
11606 unsigned size = et.size >> 3;
11607 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11608 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11609 inst.instruction |= LOW4 (inst.operands[1].reg);
11610 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11611 inst.instruction |= (isquad != 0) << 6;
11612 inst.instruction |= immbits << 16;
11613 inst.instruction |= (size >> 3) << 7;
11614 inst.instruction |= (size & 0x7) << 19;
11615 if (write_ubit)
11616 inst.instruction |= (uval != 0) << 24;
11617
11618 inst.instruction = neon_dp_fixup (inst.instruction);
11619 }
11620
11621 static void
11622 do_neon_shl_imm (void)
11623 {
11624 if (!inst.operands[2].isreg)
11625 {
11626 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11627 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
11628 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11629 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
11630 }
11631 else
11632 {
11633 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11634 struct neon_type_el et = neon_check_type (3, rs,
11635 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
11636 unsigned int tmp;
11637
11638 /* VSHL/VQSHL 3-register variants have syntax such as:
11639 vshl.xx Dd, Dm, Dn
11640 whereas other 3-register operations encoded by neon_three_same have
11641 syntax like:
11642 vadd.xx Dd, Dn, Dm
11643 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
11644 here. */
11645 tmp = inst.operands[2].reg;
11646 inst.operands[2].reg = inst.operands[1].reg;
11647 inst.operands[1].reg = tmp;
11648 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11649 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11650 }
11651 }
11652
11653 static void
11654 do_neon_qshl_imm (void)
11655 {
11656 if (!inst.operands[2].isreg)
11657 {
11658 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11659 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
11660
11661 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11662 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
11663 inst.operands[2].imm);
11664 }
11665 else
11666 {
11667 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11668 struct neon_type_el et = neon_check_type (3, rs,
11669 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
11670 unsigned int tmp;
11671
11672 /* See note in do_neon_shl_imm. */
11673 tmp = inst.operands[2].reg;
11674 inst.operands[2].reg = inst.operands[1].reg;
11675 inst.operands[1].reg = tmp;
11676 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11677 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11678 }
11679 }
11680
11681 static void
11682 do_neon_rshl (void)
11683 {
11684 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11685 struct neon_type_el et = neon_check_type (3, rs,
11686 N_EQK, N_EQK, N_SU_ALL | N_KEY);
11687 unsigned int tmp;
11688
11689 tmp = inst.operands[2].reg;
11690 inst.operands[2].reg = inst.operands[1].reg;
11691 inst.operands[1].reg = tmp;
11692 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11693 }
11694
11695 static int
11696 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
11697 {
11698 /* Handle .I8 pseudo-instructions. */
11699 if (size == 8)
11700 {
11701 /* Unfortunately, this will make everything apart from zero out-of-range.
11702 FIXME is this the intended semantics? There doesn't seem much point in
11703 accepting .I8 if so. */
11704 immediate |= immediate << 8;
11705 size = 16;
11706 }
11707
11708 if (size >= 32)
11709 {
11710 if (immediate == (immediate & 0x000000ff))
11711 {
11712 *immbits = immediate;
11713 return 0x1;
11714 }
11715 else if (immediate == (immediate & 0x0000ff00))
11716 {
11717 *immbits = immediate >> 8;
11718 return 0x3;
11719 }
11720 else if (immediate == (immediate & 0x00ff0000))
11721 {
11722 *immbits = immediate >> 16;
11723 return 0x5;
11724 }
11725 else if (immediate == (immediate & 0xff000000))
11726 {
11727 *immbits = immediate >> 24;
11728 return 0x7;
11729 }
11730 if ((immediate & 0xffff) != (immediate >> 16))
11731 goto bad_immediate;
11732 immediate &= 0xffff;
11733 }
11734
11735 if (immediate == (immediate & 0x000000ff))
11736 {
11737 *immbits = immediate;
11738 return 0x9;
11739 }
11740 else if (immediate == (immediate & 0x0000ff00))
11741 {
11742 *immbits = immediate >> 8;
11743 return 0xb;
11744 }
11745
11746 bad_immediate:
11747 first_error (_("immediate value out of range"));
11748 return FAIL;
11749 }
11750
11751 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
11752 A, B, C, D. */
11753
11754 static int
11755 neon_bits_same_in_bytes (unsigned imm)
11756 {
11757 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
11758 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
11759 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
11760 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
11761 }
11762
11763 /* For immediate of above form, return 0bABCD. */
11764
11765 static unsigned
11766 neon_squash_bits (unsigned imm)
11767 {
11768 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
11769 | ((imm & 0x01000000) >> 21);
11770 }
11771
11772 /* Compress quarter-float representation to 0b...000 abcdefgh. */
11773
11774 static unsigned
11775 neon_qfloat_bits (unsigned imm)
11776 {
11777 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
11778 }
11779
11780 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
11781 the instruction. *OP is passed as the initial value of the op field, and
11782 may be set to a different value depending on the constant (i.e.
11783 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
11784 MVN). If the immediate looks like a repeated pattern then also
11785 try smaller element sizes. */
11786
11787 static int
11788 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
11789 unsigned *immbits, int *op, int size,
11790 enum neon_el_type type)
11791 {
11792 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
11793 float. */
11794 if (type == NT_float && !float_p)
11795 return FAIL;
11796
11797 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
11798 {
11799 if (size != 32 || *op == 1)
11800 return FAIL;
11801 *immbits = neon_qfloat_bits (immlo);
11802 return 0xf;
11803 }
11804
11805 if (size == 64)
11806 {
11807 if (neon_bits_same_in_bytes (immhi)
11808 && neon_bits_same_in_bytes (immlo))
11809 {
11810 if (*op == 1)
11811 return FAIL;
11812 *immbits = (neon_squash_bits (immhi) << 4)
11813 | neon_squash_bits (immlo);
11814 *op = 1;
11815 return 0xe;
11816 }
11817
11818 if (immhi != immlo)
11819 return FAIL;
11820 }
11821
11822 if (size >= 32)
11823 {
11824 if (immlo == (immlo & 0x000000ff))
11825 {
11826 *immbits = immlo;
11827 return 0x0;
11828 }
11829 else if (immlo == (immlo & 0x0000ff00))
11830 {
11831 *immbits = immlo >> 8;
11832 return 0x2;
11833 }
11834 else if (immlo == (immlo & 0x00ff0000))
11835 {
11836 *immbits = immlo >> 16;
11837 return 0x4;
11838 }
11839 else if (immlo == (immlo & 0xff000000))
11840 {
11841 *immbits = immlo >> 24;
11842 return 0x6;
11843 }
11844 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
11845 {
11846 *immbits = (immlo >> 8) & 0xff;
11847 return 0xc;
11848 }
11849 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
11850 {
11851 *immbits = (immlo >> 16) & 0xff;
11852 return 0xd;
11853 }
11854
11855 if ((immlo & 0xffff) != (immlo >> 16))
11856 return FAIL;
11857 immlo &= 0xffff;
11858 }
11859
11860 if (size >= 16)
11861 {
11862 if (immlo == (immlo & 0x000000ff))
11863 {
11864 *immbits = immlo;
11865 return 0x8;
11866 }
11867 else if (immlo == (immlo & 0x0000ff00))
11868 {
11869 *immbits = immlo >> 8;
11870 return 0xa;
11871 }
11872
11873 if ((immlo & 0xff) != (immlo >> 8))
11874 return FAIL;
11875 immlo &= 0xff;
11876 }
11877
11878 if (immlo == (immlo & 0x000000ff))
11879 {
11880 /* Don't allow MVN with 8-bit immediate. */
11881 if (*op == 1)
11882 return FAIL;
11883 *immbits = immlo;
11884 return 0xe;
11885 }
11886
11887 return FAIL;
11888 }
11889
11890 /* Write immediate bits [7:0] to the following locations:
11891
11892 |28/24|23 19|18 16|15 4|3 0|
11893 | 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|
11894
11895 This function is used by VMOV/VMVN/VORR/VBIC. */
11896
11897 static void
11898 neon_write_immbits (unsigned immbits)
11899 {
11900 inst.instruction |= immbits & 0xf;
11901 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
11902 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
11903 }
11904
11905 /* Invert low-order SIZE bits of XHI:XLO. */
11906
11907 static void
11908 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
11909 {
11910 unsigned immlo = xlo ? *xlo : 0;
11911 unsigned immhi = xhi ? *xhi : 0;
11912
11913 switch (size)
11914 {
11915 case 8:
11916 immlo = (~immlo) & 0xff;
11917 break;
11918
11919 case 16:
11920 immlo = (~immlo) & 0xffff;
11921 break;
11922
11923 case 64:
11924 immhi = (~immhi) & 0xffffffff;
11925 /* fall through. */
11926
11927 case 32:
11928 immlo = (~immlo) & 0xffffffff;
11929 break;
11930
11931 default:
11932 abort ();
11933 }
11934
11935 if (xlo)
11936 *xlo = immlo;
11937
11938 if (xhi)
11939 *xhi = immhi;
11940 }
11941
11942 static void
11943 do_neon_logic (void)
11944 {
11945 if (inst.operands[2].present && inst.operands[2].isreg)
11946 {
11947 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11948 neon_check_type (3, rs, N_IGNORE_TYPE);
11949 /* U bit and size field were set as part of the bitmask. */
11950 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11951 neon_three_same (neon_quad (rs), 0, -1);
11952 }
11953 else
11954 {
11955 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
11956 struct neon_type_el et = neon_check_type (2, rs,
11957 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
11958 enum neon_opc opcode = inst.instruction & 0x0fffffff;
11959 unsigned immbits;
11960 int cmode;
11961
11962 if (et.type == NT_invtype)
11963 return;
11964
11965 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11966
11967 immbits = inst.operands[1].imm;
11968 if (et.size == 64)
11969 {
11970 /* .i64 is a pseudo-op, so the immediate must be a repeating
11971 pattern. */
11972 if (immbits != (inst.operands[1].regisimm ?
11973 inst.operands[1].reg : 0))
11974 {
11975 /* Set immbits to an invalid constant. */
11976 immbits = 0xdeadbeef;
11977 }
11978 }
11979
11980 switch (opcode)
11981 {
11982 case N_MNEM_vbic:
11983 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11984 break;
11985
11986 case N_MNEM_vorr:
11987 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11988 break;
11989
11990 case N_MNEM_vand:
11991 /* Pseudo-instruction for VBIC. */
11992 neon_invert_size (&immbits, 0, et.size);
11993 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11994 break;
11995
11996 case N_MNEM_vorn:
11997 /* Pseudo-instruction for VORR. */
11998 neon_invert_size (&immbits, 0, et.size);
11999 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12000 break;
12001
12002 default:
12003 abort ();
12004 }
12005
12006 if (cmode == FAIL)
12007 return;
12008
12009 inst.instruction |= neon_quad (rs) << 6;
12010 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12011 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12012 inst.instruction |= cmode << 8;
12013 neon_write_immbits (immbits);
12014
12015 inst.instruction = neon_dp_fixup (inst.instruction);
12016 }
12017 }
12018
12019 static void
12020 do_neon_bitfield (void)
12021 {
12022 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12023 neon_check_type (3, rs, N_IGNORE_TYPE);
12024 neon_three_same (neon_quad (rs), 0, -1);
12025 }
12026
12027 static void
12028 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
12029 unsigned destbits)
12030 {
12031 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12032 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
12033 types | N_KEY);
12034 if (et.type == NT_float)
12035 {
12036 inst.instruction = NEON_ENC_FLOAT (inst.instruction);
12037 neon_three_same (neon_quad (rs), 0, -1);
12038 }
12039 else
12040 {
12041 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12042 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
12043 }
12044 }
12045
12046 static void
12047 do_neon_dyadic_if_su (void)
12048 {
12049 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
12050 }
12051
12052 static void
12053 do_neon_dyadic_if_su_d (void)
12054 {
12055 /* This version only allow D registers, but that constraint is enforced during
12056 operand parsing so we don't need to do anything extra here. */
12057 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
12058 }
12059
12060 static void
12061 do_neon_dyadic_if_i_d (void)
12062 {
12063 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12064 affected if we specify unsigned args. */
12065 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12066 }
12067
12068 enum vfp_or_neon_is_neon_bits
12069 {
12070 NEON_CHECK_CC = 1,
12071 NEON_CHECK_ARCH = 2
12072 };
12073
12074 /* Call this function if an instruction which may have belonged to the VFP or
12075 Neon instruction sets, but turned out to be a Neon instruction (due to the
12076 operand types involved, etc.). We have to check and/or fix-up a couple of
12077 things:
12078
12079 - Make sure the user hasn't attempted to make a Neon instruction
12080 conditional.
12081 - Alter the value in the condition code field if necessary.
12082 - Make sure that the arch supports Neon instructions.
12083
12084 Which of these operations take place depends on bits from enum
12085 vfp_or_neon_is_neon_bits.
12086
12087 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
12088 current instruction's condition is COND_ALWAYS, the condition field is
12089 changed to inst.uncond_value. This is necessary because instructions shared
12090 between VFP and Neon may be conditional for the VFP variants only, and the
12091 unconditional Neon version must have, e.g., 0xF in the condition field. */
12092
12093 static int
12094 vfp_or_neon_is_neon (unsigned check)
12095 {
12096 /* Conditions are always legal in Thumb mode (IT blocks). */
12097 if (!thumb_mode && (check & NEON_CHECK_CC))
12098 {
12099 if (inst.cond != COND_ALWAYS)
12100 {
12101 first_error (_(BAD_COND));
12102 return FAIL;
12103 }
12104 if (inst.uncond_value != -1)
12105 inst.instruction |= inst.uncond_value << 28;
12106 }
12107
12108 if ((check & NEON_CHECK_ARCH)
12109 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
12110 {
12111 first_error (_(BAD_FPU));
12112 return FAIL;
12113 }
12114
12115 return SUCCESS;
12116 }
12117
12118 static void
12119 do_neon_addsub_if_i (void)
12120 {
12121 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
12122 return;
12123
12124 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12125 return;
12126
12127 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12128 affected if we specify unsigned args. */
12129 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
12130 }
12131
12132 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
12133 result to be:
12134 V<op> A,B (A is operand 0, B is operand 2)
12135 to mean:
12136 V<op> A,B,A
12137 not:
12138 V<op> A,B,B
12139 so handle that case specially. */
12140
12141 static void
12142 neon_exchange_operands (void)
12143 {
12144 void *scratch = alloca (sizeof (inst.operands[0]));
12145 if (inst.operands[1].present)
12146 {
12147 /* Swap operands[1] and operands[2]. */
12148 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
12149 inst.operands[1] = inst.operands[2];
12150 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
12151 }
12152 else
12153 {
12154 inst.operands[1] = inst.operands[2];
12155 inst.operands[2] = inst.operands[0];
12156 }
12157 }
12158
12159 static void
12160 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
12161 {
12162 if (inst.operands[2].isreg)
12163 {
12164 if (invert)
12165 neon_exchange_operands ();
12166 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
12167 }
12168 else
12169 {
12170 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12171 struct neon_type_el et = neon_check_type (2, rs,
12172 N_EQK | N_SIZ, immtypes | N_KEY);
12173
12174 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12175 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12176 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12177 inst.instruction |= LOW4 (inst.operands[1].reg);
12178 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12179 inst.instruction |= neon_quad (rs) << 6;
12180 inst.instruction |= (et.type == NT_float) << 10;
12181 inst.instruction |= neon_logbits (et.size) << 18;
12182
12183 inst.instruction = neon_dp_fixup (inst.instruction);
12184 }
12185 }
12186
12187 static void
12188 do_neon_cmp (void)
12189 {
12190 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
12191 }
12192
12193 static void
12194 do_neon_cmp_inv (void)
12195 {
12196 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
12197 }
12198
12199 static void
12200 do_neon_ceq (void)
12201 {
12202 neon_compare (N_IF_32, N_IF_32, FALSE);
12203 }
12204
12205 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
12206 scalars, which are encoded in 5 bits, M : Rm.
12207 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
12208 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
12209 index in M. */
12210
12211 static unsigned
12212 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
12213 {
12214 unsigned regno = NEON_SCALAR_REG (scalar);
12215 unsigned elno = NEON_SCALAR_INDEX (scalar);
12216
12217 switch (elsize)
12218 {
12219 case 16:
12220 if (regno > 7 || elno > 3)
12221 goto bad_scalar;
12222 return regno | (elno << 3);
12223
12224 case 32:
12225 if (regno > 15 || elno > 1)
12226 goto bad_scalar;
12227 return regno | (elno << 4);
12228
12229 default:
12230 bad_scalar:
12231 first_error (_("scalar out of range for multiply instruction"));
12232 }
12233
12234 return 0;
12235 }
12236
12237 /* Encode multiply / multiply-accumulate scalar instructions. */
12238
12239 static void
12240 neon_mul_mac (struct neon_type_el et, int ubit)
12241 {
12242 unsigned scalar;
12243
12244 /* Give a more helpful error message if we have an invalid type. */
12245 if (et.type == NT_invtype)
12246 return;
12247
12248 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
12249 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12250 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12251 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12252 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12253 inst.instruction |= LOW4 (scalar);
12254 inst.instruction |= HI1 (scalar) << 5;
12255 inst.instruction |= (et.type == NT_float) << 8;
12256 inst.instruction |= neon_logbits (et.size) << 20;
12257 inst.instruction |= (ubit != 0) << 24;
12258
12259 inst.instruction = neon_dp_fixup (inst.instruction);
12260 }
12261
12262 static void
12263 do_neon_mac_maybe_scalar (void)
12264 {
12265 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
12266 return;
12267
12268 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12269 return;
12270
12271 if (inst.operands[2].isscalar)
12272 {
12273 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
12274 struct neon_type_el et = neon_check_type (3, rs,
12275 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
12276 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12277 neon_mul_mac (et, neon_quad (rs));
12278 }
12279 else
12280 {
12281 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12282 affected if we specify unsigned args. */
12283 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12284 }
12285 }
12286
12287 static void
12288 do_neon_tst (void)
12289 {
12290 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12291 struct neon_type_el et = neon_check_type (3, rs,
12292 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
12293 neon_three_same (neon_quad (rs), 0, et.size);
12294 }
12295
12296 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
12297 same types as the MAC equivalents. The polynomial type for this instruction
12298 is encoded the same as the integer type. */
12299
12300 static void
12301 do_neon_mul (void)
12302 {
12303 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
12304 return;
12305
12306 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12307 return;
12308
12309 if (inst.operands[2].isscalar)
12310 do_neon_mac_maybe_scalar ();
12311 else
12312 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
12313 }
12314
12315 static void
12316 do_neon_qdmulh (void)
12317 {
12318 if (inst.operands[2].isscalar)
12319 {
12320 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
12321 struct neon_type_el et = neon_check_type (3, rs,
12322 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12323 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12324 neon_mul_mac (et, neon_quad (rs));
12325 }
12326 else
12327 {
12328 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12329 struct neon_type_el et = neon_check_type (3, rs,
12330 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12331 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12332 /* The U bit (rounding) comes from bit mask. */
12333 neon_three_same (neon_quad (rs), 0, et.size);
12334 }
12335 }
12336
12337 static void
12338 do_neon_fcmp_absolute (void)
12339 {
12340 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12341 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12342 /* Size field comes from bit mask. */
12343 neon_three_same (neon_quad (rs), 1, -1);
12344 }
12345
12346 static void
12347 do_neon_fcmp_absolute_inv (void)
12348 {
12349 neon_exchange_operands ();
12350 do_neon_fcmp_absolute ();
12351 }
12352
12353 static void
12354 do_neon_step (void)
12355 {
12356 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12357 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12358 neon_three_same (neon_quad (rs), 0, -1);
12359 }
12360
12361 static void
12362 do_neon_abs_neg (void)
12363 {
12364 enum neon_shape rs;
12365 struct neon_type_el et;
12366
12367 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
12368 return;
12369
12370 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12371 return;
12372
12373 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12374 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
12375
12376 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12377 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12378 inst.instruction |= LOW4 (inst.operands[1].reg);
12379 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12380 inst.instruction |= neon_quad (rs) << 6;
12381 inst.instruction |= (et.type == NT_float) << 10;
12382 inst.instruction |= neon_logbits (et.size) << 18;
12383
12384 inst.instruction = neon_dp_fixup (inst.instruction);
12385 }
12386
12387 static void
12388 do_neon_sli (void)
12389 {
12390 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12391 struct neon_type_el et = neon_check_type (2, rs,
12392 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12393 int imm = inst.operands[2].imm;
12394 constraint (imm < 0 || (unsigned)imm >= et.size,
12395 _("immediate out of range for insert"));
12396 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
12397 }
12398
12399 static void
12400 do_neon_sri (void)
12401 {
12402 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12403 struct neon_type_el et = neon_check_type (2, rs,
12404 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12405 int imm = inst.operands[2].imm;
12406 constraint (imm < 1 || (unsigned)imm > et.size,
12407 _("immediate out of range for insert"));
12408 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
12409 }
12410
12411 static void
12412 do_neon_qshlu_imm (void)
12413 {
12414 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12415 struct neon_type_el et = neon_check_type (2, rs,
12416 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
12417 int imm = inst.operands[2].imm;
12418 constraint (imm < 0 || (unsigned)imm >= et.size,
12419 _("immediate out of range for shift"));
12420 /* Only encodes the 'U present' variant of the instruction.
12421 In this case, signed types have OP (bit 8) set to 0.
12422 Unsigned types have OP set to 1. */
12423 inst.instruction |= (et.type == NT_unsigned) << 8;
12424 /* The rest of the bits are the same as other immediate shifts. */
12425 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
12426 }
12427
12428 static void
12429 do_neon_qmovn (void)
12430 {
12431 struct neon_type_el et = neon_check_type (2, NS_DQ,
12432 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12433 /* Saturating move where operands can be signed or unsigned, and the
12434 destination has the same signedness. */
12435 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12436 if (et.type == NT_unsigned)
12437 inst.instruction |= 0xc0;
12438 else
12439 inst.instruction |= 0x80;
12440 neon_two_same (0, 1, et.size / 2);
12441 }
12442
12443 static void
12444 do_neon_qmovun (void)
12445 {
12446 struct neon_type_el et = neon_check_type (2, NS_DQ,
12447 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12448 /* Saturating move with unsigned results. Operands must be signed. */
12449 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12450 neon_two_same (0, 1, et.size / 2);
12451 }
12452
12453 static void
12454 do_neon_rshift_sat_narrow (void)
12455 {
12456 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12457 or unsigned. If operands are unsigned, results must also be unsigned. */
12458 struct neon_type_el et = neon_check_type (2, NS_DQI,
12459 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12460 int imm = inst.operands[2].imm;
12461 /* This gets the bounds check, size encoding and immediate bits calculation
12462 right. */
12463 et.size /= 2;
12464
12465 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
12466 VQMOVN.I<size> <Dd>, <Qm>. */
12467 if (imm == 0)
12468 {
12469 inst.operands[2].present = 0;
12470 inst.instruction = N_MNEM_vqmovn;
12471 do_neon_qmovn ();
12472 return;
12473 }
12474
12475 constraint (imm < 1 || (unsigned)imm > et.size,
12476 _("immediate out of range"));
12477 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
12478 }
12479
12480 static void
12481 do_neon_rshift_sat_narrow_u (void)
12482 {
12483 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12484 or unsigned. If operands are unsigned, results must also be unsigned. */
12485 struct neon_type_el et = neon_check_type (2, NS_DQI,
12486 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12487 int imm = inst.operands[2].imm;
12488 /* This gets the bounds check, size encoding and immediate bits calculation
12489 right. */
12490 et.size /= 2;
12491
12492 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
12493 VQMOVUN.I<size> <Dd>, <Qm>. */
12494 if (imm == 0)
12495 {
12496 inst.operands[2].present = 0;
12497 inst.instruction = N_MNEM_vqmovun;
12498 do_neon_qmovun ();
12499 return;
12500 }
12501
12502 constraint (imm < 1 || (unsigned)imm > et.size,
12503 _("immediate out of range"));
12504 /* FIXME: The manual is kind of unclear about what value U should have in
12505 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
12506 must be 1. */
12507 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
12508 }
12509
12510 static void
12511 do_neon_movn (void)
12512 {
12513 struct neon_type_el et = neon_check_type (2, NS_DQ,
12514 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12515 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12516 neon_two_same (0, 1, et.size / 2);
12517 }
12518
12519 static void
12520 do_neon_rshift_narrow (void)
12521 {
12522 struct neon_type_el et = neon_check_type (2, NS_DQI,
12523 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12524 int imm = inst.operands[2].imm;
12525 /* This gets the bounds check, size encoding and immediate bits calculation
12526 right. */
12527 et.size /= 2;
12528
12529 /* If immediate is zero then we are a pseudo-instruction for
12530 VMOVN.I<size> <Dd>, <Qm> */
12531 if (imm == 0)
12532 {
12533 inst.operands[2].present = 0;
12534 inst.instruction = N_MNEM_vmovn;
12535 do_neon_movn ();
12536 return;
12537 }
12538
12539 constraint (imm < 1 || (unsigned)imm > et.size,
12540 _("immediate out of range for narrowing operation"));
12541 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
12542 }
12543
12544 static void
12545 do_neon_shll (void)
12546 {
12547 /* FIXME: Type checking when lengthening. */
12548 struct neon_type_el et = neon_check_type (2, NS_QDI,
12549 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
12550 unsigned imm = inst.operands[2].imm;
12551
12552 if (imm == et.size)
12553 {
12554 /* Maximum shift variant. */
12555 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12556 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12557 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12558 inst.instruction |= LOW4 (inst.operands[1].reg);
12559 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12560 inst.instruction |= neon_logbits (et.size) << 18;
12561
12562 inst.instruction = neon_dp_fixup (inst.instruction);
12563 }
12564 else
12565 {
12566 /* A more-specific type check for non-max versions. */
12567 et = neon_check_type (2, NS_QDI,
12568 N_EQK | N_DBL, N_SU_32 | N_KEY);
12569 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12570 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
12571 }
12572 }
12573
12574 /* Check the various types for the VCVT instruction, and return which version
12575 the current instruction is. */
12576
12577 static int
12578 neon_cvt_flavour (enum neon_shape rs)
12579 {
12580 #define CVT_VAR(C,X,Y) \
12581 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
12582 if (et.type != NT_invtype) \
12583 { \
12584 inst.error = NULL; \
12585 return (C); \
12586 }
12587 struct neon_type_el et;
12588 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
12589 || rs == NS_FF) ? N_VFP : 0;
12590 /* The instruction versions which take an immediate take one register
12591 argument, which is extended to the width of the full register. Thus the
12592 "source" and "destination" registers must have the same width. Hack that
12593 here by making the size equal to the key (wider, in this case) operand. */
12594 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
12595
12596 CVT_VAR (0, N_S32, N_F32);
12597 CVT_VAR (1, N_U32, N_F32);
12598 CVT_VAR (2, N_F32, N_S32);
12599 CVT_VAR (3, N_F32, N_U32);
12600
12601 whole_reg = N_VFP;
12602
12603 /* VFP instructions. */
12604 CVT_VAR (4, N_F32, N_F64);
12605 CVT_VAR (5, N_F64, N_F32);
12606 CVT_VAR (6, N_S32, N_F64 | key);
12607 CVT_VAR (7, N_U32, N_F64 | key);
12608 CVT_VAR (8, N_F64 | key, N_S32);
12609 CVT_VAR (9, N_F64 | key, N_U32);
12610 /* VFP instructions with bitshift. */
12611 CVT_VAR (10, N_F32 | key, N_S16);
12612 CVT_VAR (11, N_F32 | key, N_U16);
12613 CVT_VAR (12, N_F64 | key, N_S16);
12614 CVT_VAR (13, N_F64 | key, N_U16);
12615 CVT_VAR (14, N_S16, N_F32 | key);
12616 CVT_VAR (15, N_U16, N_F32 | key);
12617 CVT_VAR (16, N_S16, N_F64 | key);
12618 CVT_VAR (17, N_U16, N_F64 | key);
12619
12620 return -1;
12621 #undef CVT_VAR
12622 }
12623
12624 /* Neon-syntax VFP conversions. */
12625
12626 static void
12627 do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
12628 {
12629 const char *opname = 0;
12630
12631 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
12632 {
12633 /* Conversions with immediate bitshift. */
12634 const char *enc[] =
12635 {
12636 "ftosls",
12637 "ftouls",
12638 "fsltos",
12639 "fultos",
12640 NULL,
12641 NULL,
12642 "ftosld",
12643 "ftould",
12644 "fsltod",
12645 "fultod",
12646 "fshtos",
12647 "fuhtos",
12648 "fshtod",
12649 "fuhtod",
12650 "ftoshs",
12651 "ftouhs",
12652 "ftoshd",
12653 "ftouhd"
12654 };
12655
12656 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12657 {
12658 opname = enc[flavour];
12659 constraint (inst.operands[0].reg != inst.operands[1].reg,
12660 _("operands 0 and 1 must be the same register"));
12661 inst.operands[1] = inst.operands[2];
12662 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
12663 }
12664 }
12665 else
12666 {
12667 /* Conversions without bitshift. */
12668 const char *enc[] =
12669 {
12670 "ftosis",
12671 "ftouis",
12672 "fsitos",
12673 "fuitos",
12674 "fcvtsd",
12675 "fcvtds",
12676 "ftosid",
12677 "ftouid",
12678 "fsitod",
12679 "fuitod"
12680 };
12681
12682 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12683 opname = enc[flavour];
12684 }
12685
12686 if (opname)
12687 do_vfp_nsyn_opcode (opname);
12688 }
12689
12690 static void
12691 do_vfp_nsyn_cvtz (void)
12692 {
12693 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
12694 int flavour = neon_cvt_flavour (rs);
12695 const char *enc[] =
12696 {
12697 "ftosizs",
12698 "ftouizs",
12699 NULL,
12700 NULL,
12701 NULL,
12702 NULL,
12703 "ftosizd",
12704 "ftouizd"
12705 };
12706
12707 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
12708 do_vfp_nsyn_opcode (enc[flavour]);
12709 }
12710
12711 static void
12712 do_neon_cvt (void)
12713 {
12714 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
12715 NS_FD, NS_DF, NS_FF, NS_NULL);
12716 int flavour = neon_cvt_flavour (rs);
12717
12718 /* VFP rather than Neon conversions. */
12719 if (flavour >= 4)
12720 {
12721 do_vfp_nsyn_cvt (rs, flavour);
12722 return;
12723 }
12724
12725 switch (rs)
12726 {
12727 case NS_DDI:
12728 case NS_QQI:
12729 {
12730 unsigned immbits;
12731 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
12732
12733 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12734 return;
12735
12736 /* Fixed-point conversion with #0 immediate is encoded as an
12737 integer conversion. */
12738 if (inst.operands[2].present && inst.operands[2].imm == 0)
12739 goto int_encode;
12740 immbits = 32 - inst.operands[2].imm;
12741 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12742 if (flavour != -1)
12743 inst.instruction |= enctab[flavour];
12744 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12745 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12746 inst.instruction |= LOW4 (inst.operands[1].reg);
12747 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12748 inst.instruction |= neon_quad (rs) << 6;
12749 inst.instruction |= 1 << 21;
12750 inst.instruction |= immbits << 16;
12751
12752 inst.instruction = neon_dp_fixup (inst.instruction);
12753 }
12754 break;
12755
12756 case NS_DD:
12757 case NS_QQ:
12758 int_encode:
12759 {
12760 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
12761
12762 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12763
12764 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12765 return;
12766
12767 if (flavour != -1)
12768 inst.instruction |= enctab[flavour];
12769
12770 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12771 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12772 inst.instruction |= LOW4 (inst.operands[1].reg);
12773 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12774 inst.instruction |= neon_quad (rs) << 6;
12775 inst.instruction |= 2 << 18;
12776
12777 inst.instruction = neon_dp_fixup (inst.instruction);
12778 }
12779 break;
12780
12781 default:
12782 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
12783 do_vfp_nsyn_cvt (rs, flavour);
12784 }
12785 }
12786
12787 static void
12788 neon_move_immediate (void)
12789 {
12790 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
12791 struct neon_type_el et = neon_check_type (2, rs,
12792 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
12793 unsigned immlo, immhi = 0, immbits;
12794 int op, cmode, float_p;
12795
12796 constraint (et.type == NT_invtype,
12797 _("operand size must be specified for immediate VMOV"));
12798
12799 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
12800 op = (inst.instruction & (1 << 5)) != 0;
12801
12802 immlo = inst.operands[1].imm;
12803 if (inst.operands[1].regisimm)
12804 immhi = inst.operands[1].reg;
12805
12806 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
12807 _("immediate has bits set outside the operand size"));
12808
12809 float_p = inst.operands[1].immisfloat;
12810
12811 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
12812 et.size, et.type)) == FAIL)
12813 {
12814 /* Invert relevant bits only. */
12815 neon_invert_size (&immlo, &immhi, et.size);
12816 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
12817 with one or the other; those cases are caught by
12818 neon_cmode_for_move_imm. */
12819 op = !op;
12820 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
12821 &op, et.size, et.type)) == FAIL)
12822 {
12823 first_error (_("immediate out of range"));
12824 return;
12825 }
12826 }
12827
12828 inst.instruction &= ~(1 << 5);
12829 inst.instruction |= op << 5;
12830
12831 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12832 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12833 inst.instruction |= neon_quad (rs) << 6;
12834 inst.instruction |= cmode << 8;
12835
12836 neon_write_immbits (immbits);
12837 }
12838
12839 static void
12840 do_neon_mvn (void)
12841 {
12842 if (inst.operands[1].isreg)
12843 {
12844 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12845
12846 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12847 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12848 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12849 inst.instruction |= LOW4 (inst.operands[1].reg);
12850 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12851 inst.instruction |= neon_quad (rs) << 6;
12852 }
12853 else
12854 {
12855 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12856 neon_move_immediate ();
12857 }
12858
12859 inst.instruction = neon_dp_fixup (inst.instruction);
12860 }
12861
12862 /* Encode instructions of form:
12863
12864 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12865 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
12866
12867 static void
12868 neon_mixed_length (struct neon_type_el et, unsigned size)
12869 {
12870 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12871 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12872 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12873 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12874 inst.instruction |= LOW4 (inst.operands[2].reg);
12875 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12876 inst.instruction |= (et.type == NT_unsigned) << 24;
12877 inst.instruction |= neon_logbits (size) << 20;
12878
12879 inst.instruction = neon_dp_fixup (inst.instruction);
12880 }
12881
12882 static void
12883 do_neon_dyadic_long (void)
12884 {
12885 /* FIXME: Type checking for lengthening op. */
12886 struct neon_type_el et = neon_check_type (3, NS_QDD,
12887 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
12888 neon_mixed_length (et, et.size);
12889 }
12890
12891 static void
12892 do_neon_abal (void)
12893 {
12894 struct neon_type_el et = neon_check_type (3, NS_QDD,
12895 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
12896 neon_mixed_length (et, et.size);
12897 }
12898
12899 static void
12900 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
12901 {
12902 if (inst.operands[2].isscalar)
12903 {
12904 struct neon_type_el et = neon_check_type (3, NS_QDS,
12905 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
12906 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12907 neon_mul_mac (et, et.type == NT_unsigned);
12908 }
12909 else
12910 {
12911 struct neon_type_el et = neon_check_type (3, NS_QDD,
12912 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
12913 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12914 neon_mixed_length (et, et.size);
12915 }
12916 }
12917
12918 static void
12919 do_neon_mac_maybe_scalar_long (void)
12920 {
12921 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
12922 }
12923
12924 static void
12925 do_neon_dyadic_wide (void)
12926 {
12927 struct neon_type_el et = neon_check_type (3, NS_QQD,
12928 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
12929 neon_mixed_length (et, et.size);
12930 }
12931
12932 static void
12933 do_neon_dyadic_narrow (void)
12934 {
12935 struct neon_type_el et = neon_check_type (3, NS_QDD,
12936 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
12937 /* Operand sign is unimportant, and the U bit is part of the opcode,
12938 so force the operand type to integer. */
12939 et.type = NT_integer;
12940 neon_mixed_length (et, et.size / 2);
12941 }
12942
12943 static void
12944 do_neon_mul_sat_scalar_long (void)
12945 {
12946 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
12947 }
12948
12949 static void
12950 do_neon_vmull (void)
12951 {
12952 if (inst.operands[2].isscalar)
12953 do_neon_mac_maybe_scalar_long ();
12954 else
12955 {
12956 struct neon_type_el et = neon_check_type (3, NS_QDD,
12957 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
12958 if (et.type == NT_poly)
12959 inst.instruction = NEON_ENC_POLY (inst.instruction);
12960 else
12961 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12962 /* For polynomial encoding, size field must be 0b00 and the U bit must be
12963 zero. Should be OK as-is. */
12964 neon_mixed_length (et, et.size);
12965 }
12966 }
12967
12968 static void
12969 do_neon_ext (void)
12970 {
12971 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
12972 struct neon_type_el et = neon_check_type (3, rs,
12973 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12974 unsigned imm = (inst.operands[3].imm * et.size) / 8;
12975
12976 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
12977 _("shift out of range"));
12978 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12979 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12980 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12981 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12982 inst.instruction |= LOW4 (inst.operands[2].reg);
12983 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12984 inst.instruction |= neon_quad (rs) << 6;
12985 inst.instruction |= imm << 8;
12986
12987 inst.instruction = neon_dp_fixup (inst.instruction);
12988 }
12989
12990 static void
12991 do_neon_rev (void)
12992 {
12993 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12994 struct neon_type_el et = neon_check_type (2, rs,
12995 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12996 unsigned op = (inst.instruction >> 7) & 3;
12997 /* N (width of reversed regions) is encoded as part of the bitmask. We
12998 extract it here to check the elements to be reversed are smaller.
12999 Otherwise we'd get a reserved instruction. */
13000 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
13001 assert (elsize != 0);
13002 constraint (et.size >= elsize,
13003 _("elements must be smaller than reversal region"));
13004 neon_two_same (neon_quad (rs), 1, et.size);
13005 }
13006
13007 static void
13008 do_neon_dup (void)
13009 {
13010 if (inst.operands[1].isscalar)
13011 {
13012 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
13013 struct neon_type_el et = neon_check_type (2, rs,
13014 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13015 unsigned sizebits = et.size >> 3;
13016 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
13017 int logsize = neon_logbits (et.size);
13018 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
13019
13020 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
13021 return;
13022
13023 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13024 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13025 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13026 inst.instruction |= LOW4 (dm);
13027 inst.instruction |= HI1 (dm) << 5;
13028 inst.instruction |= neon_quad (rs) << 6;
13029 inst.instruction |= x << 17;
13030 inst.instruction |= sizebits << 16;
13031
13032 inst.instruction = neon_dp_fixup (inst.instruction);
13033 }
13034 else
13035 {
13036 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
13037 struct neon_type_el et = neon_check_type (2, rs,
13038 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13039 /* Duplicate ARM register to lanes of vector. */
13040 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
13041 switch (et.size)
13042 {
13043 case 8: inst.instruction |= 0x400000; break;
13044 case 16: inst.instruction |= 0x000020; break;
13045 case 32: inst.instruction |= 0x000000; break;
13046 default: break;
13047 }
13048 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13049 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
13050 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
13051 inst.instruction |= neon_quad (rs) << 21;
13052 /* The encoding for this instruction is identical for the ARM and Thumb
13053 variants, except for the condition field. */
13054 do_vfp_cond_or_thumb ();
13055 }
13056 }
13057
13058 /* VMOV has particularly many variations. It can be one of:
13059 0. VMOV<c><q> <Qd>, <Qm>
13060 1. VMOV<c><q> <Dd>, <Dm>
13061 (Register operations, which are VORR with Rm = Rn.)
13062 2. VMOV<c><q>.<dt> <Qd>, #<imm>
13063 3. VMOV<c><q>.<dt> <Dd>, #<imm>
13064 (Immediate loads.)
13065 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
13066 (ARM register to scalar.)
13067 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
13068 (Two ARM registers to vector.)
13069 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
13070 (Scalar to ARM register.)
13071 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
13072 (Vector to two ARM registers.)
13073 8. VMOV.F32 <Sd>, <Sm>
13074 9. VMOV.F64 <Dd>, <Dm>
13075 (VFP register moves.)
13076 10. VMOV.F32 <Sd>, #imm
13077 11. VMOV.F64 <Dd>, #imm
13078 (VFP float immediate load.)
13079 12. VMOV <Rd>, <Sm>
13080 (VFP single to ARM reg.)
13081 13. VMOV <Sd>, <Rm>
13082 (ARM reg to VFP single.)
13083 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
13084 (Two ARM regs to two VFP singles.)
13085 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
13086 (Two VFP singles to two ARM regs.)
13087
13088 These cases can be disambiguated using neon_select_shape, except cases 1/9
13089 and 3/11 which depend on the operand type too.
13090
13091 All the encoded bits are hardcoded by this function.
13092
13093 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
13094 Cases 5, 7 may be used with VFPv2 and above.
13095
13096 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
13097 can specify a type where it doesn't make sense to, and is ignored). */
13098
13099 static void
13100 do_neon_mov (void)
13101 {
13102 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
13103 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
13104 NS_NULL);
13105 struct neon_type_el et;
13106 const char *ldconst = 0;
13107
13108 switch (rs)
13109 {
13110 case NS_DD: /* case 1/9. */
13111 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13112 /* It is not an error here if no type is given. */
13113 inst.error = NULL;
13114 if (et.type == NT_float && et.size == 64)
13115 {
13116 do_vfp_nsyn_opcode ("fcpyd");
13117 break;
13118 }
13119 /* fall through. */
13120
13121 case NS_QQ: /* case 0/1. */
13122 {
13123 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13124 return;
13125 /* The architecture manual I have doesn't explicitly state which
13126 value the U bit should have for register->register moves, but
13127 the equivalent VORR instruction has U = 0, so do that. */
13128 inst.instruction = 0x0200110;
13129 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13130 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13131 inst.instruction |= LOW4 (inst.operands[1].reg);
13132 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13133 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13134 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13135 inst.instruction |= neon_quad (rs) << 6;
13136
13137 inst.instruction = neon_dp_fixup (inst.instruction);
13138 }
13139 break;
13140
13141 case NS_DI: /* case 3/11. */
13142 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13143 inst.error = NULL;
13144 if (et.type == NT_float && et.size == 64)
13145 {
13146 /* case 11 (fconstd). */
13147 ldconst = "fconstd";
13148 goto encode_fconstd;
13149 }
13150 /* fall through. */
13151
13152 case NS_QI: /* case 2/3. */
13153 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13154 return;
13155 inst.instruction = 0x0800010;
13156 neon_move_immediate ();
13157 inst.instruction = neon_dp_fixup (inst.instruction);
13158 break;
13159
13160 case NS_SR: /* case 4. */
13161 {
13162 unsigned bcdebits = 0;
13163 struct neon_type_el et = neon_check_type (2, NS_NULL,
13164 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13165 int logsize = neon_logbits (et.size);
13166 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
13167 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
13168
13169 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13170 _(BAD_FPU));
13171 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13172 && et.size != 32, _(BAD_FPU));
13173 constraint (et.type == NT_invtype, _("bad type for scalar"));
13174 constraint (x >= 64 / et.size, _("scalar index out of range"));
13175
13176 switch (et.size)
13177 {
13178 case 8: bcdebits = 0x8; break;
13179 case 16: bcdebits = 0x1; break;
13180 case 32: bcdebits = 0x0; break;
13181 default: ;
13182 }
13183
13184 bcdebits |= x << logsize;
13185
13186 inst.instruction = 0xe000b10;
13187 do_vfp_cond_or_thumb ();
13188 inst.instruction |= LOW4 (dn) << 16;
13189 inst.instruction |= HI1 (dn) << 7;
13190 inst.instruction |= inst.operands[1].reg << 12;
13191 inst.instruction |= (bcdebits & 3) << 5;
13192 inst.instruction |= (bcdebits >> 2) << 21;
13193 }
13194 break;
13195
13196 case NS_DRR: /* case 5 (fmdrr). */
13197 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13198 _(BAD_FPU));
13199
13200 inst.instruction = 0xc400b10;
13201 do_vfp_cond_or_thumb ();
13202 inst.instruction |= LOW4 (inst.operands[0].reg);
13203 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
13204 inst.instruction |= inst.operands[1].reg << 12;
13205 inst.instruction |= inst.operands[2].reg << 16;
13206 break;
13207
13208 case NS_RS: /* case 6. */
13209 {
13210 struct neon_type_el et = neon_check_type (2, NS_NULL,
13211 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
13212 unsigned logsize = neon_logbits (et.size);
13213 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
13214 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
13215 unsigned abcdebits = 0;
13216
13217 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13218 _(BAD_FPU));
13219 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13220 && et.size != 32, _(BAD_FPU));
13221 constraint (et.type == NT_invtype, _("bad type for scalar"));
13222 constraint (x >= 64 / et.size, _("scalar index out of range"));
13223
13224 switch (et.size)
13225 {
13226 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
13227 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
13228 case 32: abcdebits = 0x00; break;
13229 default: ;
13230 }
13231
13232 abcdebits |= x << logsize;
13233 inst.instruction = 0xe100b10;
13234 do_vfp_cond_or_thumb ();
13235 inst.instruction |= LOW4 (dn) << 16;
13236 inst.instruction |= HI1 (dn) << 7;
13237 inst.instruction |= inst.operands[0].reg << 12;
13238 inst.instruction |= (abcdebits & 3) << 5;
13239 inst.instruction |= (abcdebits >> 2) << 21;
13240 }
13241 break;
13242
13243 case NS_RRD: /* case 7 (fmrrd). */
13244 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13245 _(BAD_FPU));
13246
13247 inst.instruction = 0xc500b10;
13248 do_vfp_cond_or_thumb ();
13249 inst.instruction |= inst.operands[0].reg << 12;
13250 inst.instruction |= inst.operands[1].reg << 16;
13251 inst.instruction |= LOW4 (inst.operands[2].reg);
13252 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13253 break;
13254
13255 case NS_FF: /* case 8 (fcpys). */
13256 do_vfp_nsyn_opcode ("fcpys");
13257 break;
13258
13259 case NS_FI: /* case 10 (fconsts). */
13260 ldconst = "fconsts";
13261 encode_fconstd:
13262 if (is_quarter_float (inst.operands[1].imm))
13263 {
13264 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
13265 do_vfp_nsyn_opcode (ldconst);
13266 }
13267 else
13268 first_error (_("immediate out of range"));
13269 break;
13270
13271 case NS_RF: /* case 12 (fmrs). */
13272 do_vfp_nsyn_opcode ("fmrs");
13273 break;
13274
13275 case NS_FR: /* case 13 (fmsr). */
13276 do_vfp_nsyn_opcode ("fmsr");
13277 break;
13278
13279 /* The encoders for the fmrrs and fmsrr instructions expect three operands
13280 (one of which is a list), but we have parsed four. Do some fiddling to
13281 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
13282 expect. */
13283 case NS_RRFF: /* case 14 (fmrrs). */
13284 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
13285 _("VFP registers must be adjacent"));
13286 inst.operands[2].imm = 2;
13287 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13288 do_vfp_nsyn_opcode ("fmrrs");
13289 break;
13290
13291 case NS_FFRR: /* case 15 (fmsrr). */
13292 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
13293 _("VFP registers must be adjacent"));
13294 inst.operands[1] = inst.operands[2];
13295 inst.operands[2] = inst.operands[3];
13296 inst.operands[0].imm = 2;
13297 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13298 do_vfp_nsyn_opcode ("fmsrr");
13299 break;
13300
13301 default:
13302 abort ();
13303 }
13304 }
13305
13306 static void
13307 do_neon_rshift_round_imm (void)
13308 {
13309 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13310 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
13311 int imm = inst.operands[2].imm;
13312
13313 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
13314 if (imm == 0)
13315 {
13316 inst.operands[2].present = 0;
13317 do_neon_mov ();
13318 return;
13319 }
13320
13321 constraint (imm < 1 || (unsigned)imm > et.size,
13322 _("immediate out of range for shift"));
13323 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
13324 et.size - imm);
13325 }
13326
13327 static void
13328 do_neon_movl (void)
13329 {
13330 struct neon_type_el et = neon_check_type (2, NS_QD,
13331 N_EQK | N_DBL, N_SU_32 | N_KEY);
13332 unsigned sizebits = et.size >> 3;
13333 inst.instruction |= sizebits << 19;
13334 neon_two_same (0, et.type == NT_unsigned, -1);
13335 }
13336
13337 static void
13338 do_neon_trn (void)
13339 {
13340 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13341 struct neon_type_el et = neon_check_type (2, rs,
13342 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13343 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13344 neon_two_same (neon_quad (rs), 1, et.size);
13345 }
13346
13347 static void
13348 do_neon_zip_uzp (void)
13349 {
13350 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13351 struct neon_type_el et = neon_check_type (2, rs,
13352 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13353 if (rs == NS_DD && et.size == 32)
13354 {
13355 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
13356 inst.instruction = N_MNEM_vtrn;
13357 do_neon_trn ();
13358 return;
13359 }
13360 neon_two_same (neon_quad (rs), 1, et.size);
13361 }
13362
13363 static void
13364 do_neon_sat_abs_neg (void)
13365 {
13366 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13367 struct neon_type_el et = neon_check_type (2, rs,
13368 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
13369 neon_two_same (neon_quad (rs), 1, et.size);
13370 }
13371
13372 static void
13373 do_neon_pair_long (void)
13374 {
13375 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13376 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
13377 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
13378 inst.instruction |= (et.type == NT_unsigned) << 7;
13379 neon_two_same (neon_quad (rs), 1, et.size);
13380 }
13381
13382 static void
13383 do_neon_recip_est (void)
13384 {
13385 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13386 struct neon_type_el et = neon_check_type (2, rs,
13387 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
13388 inst.instruction |= (et.type == NT_float) << 8;
13389 neon_two_same (neon_quad (rs), 1, et.size);
13390 }
13391
13392 static void
13393 do_neon_cls (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_S8 | N_S16 | N_S32 | N_KEY);
13398 neon_two_same (neon_quad (rs), 1, et.size);
13399 }
13400
13401 static void
13402 do_neon_clz (void)
13403 {
13404 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13405 struct neon_type_el et = neon_check_type (2, rs,
13406 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
13407 neon_two_same (neon_quad (rs), 1, et.size);
13408 }
13409
13410 static void
13411 do_neon_cnt (void)
13412 {
13413 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13414 struct neon_type_el et = neon_check_type (2, rs,
13415 N_EQK | N_INT, N_8 | N_KEY);
13416 neon_two_same (neon_quad (rs), 1, et.size);
13417 }
13418
13419 static void
13420 do_neon_swp (void)
13421 {
13422 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13423 neon_two_same (neon_quad (rs), 1, -1);
13424 }
13425
13426 static void
13427 do_neon_tbl_tbx (void)
13428 {
13429 unsigned listlenbits;
13430 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
13431
13432 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
13433 {
13434 first_error (_("bad list length for table lookup"));
13435 return;
13436 }
13437
13438 listlenbits = inst.operands[1].imm - 1;
13439 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13440 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13441 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13442 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13443 inst.instruction |= LOW4 (inst.operands[2].reg);
13444 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13445 inst.instruction |= listlenbits << 8;
13446
13447 inst.instruction = neon_dp_fixup (inst.instruction);
13448 }
13449
13450 static void
13451 do_neon_ldm_stm (void)
13452 {
13453 /* P, U and L bits are part of bitmask. */
13454 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
13455 unsigned offsetbits = inst.operands[1].imm * 2;
13456
13457 if (inst.operands[1].issingle)
13458 {
13459 do_vfp_nsyn_ldm_stm (is_dbmode);
13460 return;
13461 }
13462
13463 constraint (is_dbmode && !inst.operands[0].writeback,
13464 _("writeback (!) must be used for VLDMDB and VSTMDB"));
13465
13466 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
13467 _("register list must contain at least 1 and at most 16 "
13468 "registers"));
13469
13470 inst.instruction |= inst.operands[0].reg << 16;
13471 inst.instruction |= inst.operands[0].writeback << 21;
13472 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13473 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
13474
13475 inst.instruction |= offsetbits;
13476
13477 do_vfp_cond_or_thumb ();
13478 }
13479
13480 static void
13481 do_neon_ldr_str (void)
13482 {
13483 int is_ldr = (inst.instruction & (1 << 20)) != 0;
13484
13485 if (inst.operands[0].issingle)
13486 {
13487 if (is_ldr)
13488 do_vfp_nsyn_opcode ("flds");
13489 else
13490 do_vfp_nsyn_opcode ("fsts");
13491 }
13492 else
13493 {
13494 if (is_ldr)
13495 do_vfp_nsyn_opcode ("fldd");
13496 else
13497 do_vfp_nsyn_opcode ("fstd");
13498 }
13499 }
13500
13501 /* "interleave" version also handles non-interleaving register VLD1/VST1
13502 instructions. */
13503
13504 static void
13505 do_neon_ld_st_interleave (void)
13506 {
13507 struct neon_type_el et = neon_check_type (1, NS_NULL,
13508 N_8 | N_16 | N_32 | N_64);
13509 unsigned alignbits = 0;
13510 unsigned idx;
13511 /* The bits in this table go:
13512 0: register stride of one (0) or two (1)
13513 1,2: register list length, minus one (1, 2, 3, 4).
13514 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
13515 We use -1 for invalid entries. */
13516 const int typetable[] =
13517 {
13518 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
13519 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
13520 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
13521 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
13522 };
13523 int typebits;
13524
13525 if (et.type == NT_invtype)
13526 return;
13527
13528 if (inst.operands[1].immisalign)
13529 switch (inst.operands[1].imm >> 8)
13530 {
13531 case 64: alignbits = 1; break;
13532 case 128:
13533 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13534 goto bad_alignment;
13535 alignbits = 2;
13536 break;
13537 case 256:
13538 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13539 goto bad_alignment;
13540 alignbits = 3;
13541 break;
13542 default:
13543 bad_alignment:
13544 first_error (_("bad alignment"));
13545 return;
13546 }
13547
13548 inst.instruction |= alignbits << 4;
13549 inst.instruction |= neon_logbits (et.size) << 6;
13550
13551 /* Bits [4:6] of the immediate in a list specifier encode register stride
13552 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
13553 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
13554 up the right value for "type" in a table based on this value and the given
13555 list style, then stick it back. */
13556 idx = ((inst.operands[0].imm >> 4) & 7)
13557 | (((inst.instruction >> 8) & 3) << 3);
13558
13559 typebits = typetable[idx];
13560
13561 constraint (typebits == -1, _("bad list type for instruction"));
13562
13563 inst.instruction &= ~0xf00;
13564 inst.instruction |= typebits << 8;
13565 }
13566
13567 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
13568 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
13569 otherwise. The variable arguments are a list of pairs of legal (size, align)
13570 values, terminated with -1. */
13571
13572 static int
13573 neon_alignment_bit (int size, int align, int *do_align, ...)
13574 {
13575 va_list ap;
13576 int result = FAIL, thissize, thisalign;
13577
13578 if (!inst.operands[1].immisalign)
13579 {
13580 *do_align = 0;
13581 return SUCCESS;
13582 }
13583
13584 va_start (ap, do_align);
13585
13586 do
13587 {
13588 thissize = va_arg (ap, int);
13589 if (thissize == -1)
13590 break;
13591 thisalign = va_arg (ap, int);
13592
13593 if (size == thissize && align == thisalign)
13594 result = SUCCESS;
13595 }
13596 while (result != SUCCESS);
13597
13598 va_end (ap);
13599
13600 if (result == SUCCESS)
13601 *do_align = 1;
13602 else
13603 first_error (_("unsupported alignment for instruction"));
13604
13605 return result;
13606 }
13607
13608 static void
13609 do_neon_ld_st_lane (void)
13610 {
13611 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
13612 int align_good, do_align = 0;
13613 int logsize = neon_logbits (et.size);
13614 int align = inst.operands[1].imm >> 8;
13615 int n = (inst.instruction >> 8) & 3;
13616 int max_el = 64 / et.size;
13617
13618 if (et.type == NT_invtype)
13619 return;
13620
13621 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
13622 _("bad list length"));
13623 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
13624 _("scalar index out of range"));
13625 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
13626 && et.size == 8,
13627 _("stride of 2 unavailable when element size is 8"));
13628
13629 switch (n)
13630 {
13631 case 0: /* VLD1 / VST1. */
13632 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
13633 32, 32, -1);
13634 if (align_good == FAIL)
13635 return;
13636 if (do_align)
13637 {
13638 unsigned alignbits = 0;
13639 switch (et.size)
13640 {
13641 case 16: alignbits = 0x1; break;
13642 case 32: alignbits = 0x3; break;
13643 default: ;
13644 }
13645 inst.instruction |= alignbits << 4;
13646 }
13647 break;
13648
13649 case 1: /* VLD2 / VST2. */
13650 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
13651 32, 64, -1);
13652 if (align_good == FAIL)
13653 return;
13654 if (do_align)
13655 inst.instruction |= 1 << 4;
13656 break;
13657
13658 case 2: /* VLD3 / VST3. */
13659 constraint (inst.operands[1].immisalign,
13660 _("can't use alignment with this instruction"));
13661 break;
13662
13663 case 3: /* VLD4 / VST4. */
13664 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13665 16, 64, 32, 64, 32, 128, -1);
13666 if (align_good == FAIL)
13667 return;
13668 if (do_align)
13669 {
13670 unsigned alignbits = 0;
13671 switch (et.size)
13672 {
13673 case 8: alignbits = 0x1; break;
13674 case 16: alignbits = 0x1; break;
13675 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
13676 default: ;
13677 }
13678 inst.instruction |= alignbits << 4;
13679 }
13680 break;
13681
13682 default: ;
13683 }
13684
13685 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
13686 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13687 inst.instruction |= 1 << (4 + logsize);
13688
13689 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
13690 inst.instruction |= logsize << 10;
13691 }
13692
13693 /* Encode single n-element structure to all lanes VLD<n> instructions. */
13694
13695 static void
13696 do_neon_ld_dup (void)
13697 {
13698 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
13699 int align_good, do_align = 0;
13700
13701 if (et.type == NT_invtype)
13702 return;
13703
13704 switch ((inst.instruction >> 8) & 3)
13705 {
13706 case 0: /* VLD1. */
13707 assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
13708 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13709 &do_align, 16, 16, 32, 32, -1);
13710 if (align_good == FAIL)
13711 return;
13712 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
13713 {
13714 case 1: break;
13715 case 2: inst.instruction |= 1 << 5; break;
13716 default: first_error (_("bad list length")); return;
13717 }
13718 inst.instruction |= neon_logbits (et.size) << 6;
13719 break;
13720
13721 case 1: /* VLD2. */
13722 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13723 &do_align, 8, 16, 16, 32, 32, 64, -1);
13724 if (align_good == FAIL)
13725 return;
13726 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
13727 _("bad list length"));
13728 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13729 inst.instruction |= 1 << 5;
13730 inst.instruction |= neon_logbits (et.size) << 6;
13731 break;
13732
13733 case 2: /* VLD3. */
13734 constraint (inst.operands[1].immisalign,
13735 _("can't use alignment with this instruction"));
13736 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
13737 _("bad list length"));
13738 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13739 inst.instruction |= 1 << 5;
13740 inst.instruction |= neon_logbits (et.size) << 6;
13741 break;
13742
13743 case 3: /* VLD4. */
13744 {
13745 int align = inst.operands[1].imm >> 8;
13746 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13747 16, 64, 32, 64, 32, 128, -1);
13748 if (align_good == FAIL)
13749 return;
13750 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
13751 _("bad list length"));
13752 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13753 inst.instruction |= 1 << 5;
13754 if (et.size == 32 && align == 128)
13755 inst.instruction |= 0x3 << 6;
13756 else
13757 inst.instruction |= neon_logbits (et.size) << 6;
13758 }
13759 break;
13760
13761 default: ;
13762 }
13763
13764 inst.instruction |= do_align << 4;
13765 }
13766
13767 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
13768 apart from bits [11:4]. */
13769
13770 static void
13771 do_neon_ldx_stx (void)
13772 {
13773 switch (NEON_LANE (inst.operands[0].imm))
13774 {
13775 case NEON_INTERLEAVE_LANES:
13776 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
13777 do_neon_ld_st_interleave ();
13778 break;
13779
13780 case NEON_ALL_LANES:
13781 inst.instruction = NEON_ENC_DUP (inst.instruction);
13782 do_neon_ld_dup ();
13783 break;
13784
13785 default:
13786 inst.instruction = NEON_ENC_LANE (inst.instruction);
13787 do_neon_ld_st_lane ();
13788 }
13789
13790 /* L bit comes from bit mask. */
13791 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13792 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13793 inst.instruction |= inst.operands[1].reg << 16;
13794
13795 if (inst.operands[1].postind)
13796 {
13797 int postreg = inst.operands[1].imm & 0xf;
13798 constraint (!inst.operands[1].immisreg,
13799 _("post-index must be a register"));
13800 constraint (postreg == 0xd || postreg == 0xf,
13801 _("bad register for post-index"));
13802 inst.instruction |= postreg;
13803 }
13804 else if (inst.operands[1].writeback)
13805 {
13806 inst.instruction |= 0xd;
13807 }
13808 else
13809 inst.instruction |= 0xf;
13810
13811 if (thumb_mode)
13812 inst.instruction |= 0xf9000000;
13813 else
13814 inst.instruction |= 0xf4000000;
13815 }
13816 \f
13817 /* Overall per-instruction processing. */
13818
13819 /* We need to be able to fix up arbitrary expressions in some statements.
13820 This is so that we can handle symbols that are an arbitrary distance from
13821 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
13822 which returns part of an address in a form which will be valid for
13823 a data instruction. We do this by pushing the expression into a symbol
13824 in the expr_section, and creating a fix for that. */
13825
13826 static void
13827 fix_new_arm (fragS * frag,
13828 int where,
13829 short int size,
13830 expressionS * exp,
13831 int pc_rel,
13832 int reloc)
13833 {
13834 fixS * new_fix;
13835
13836 switch (exp->X_op)
13837 {
13838 case O_constant:
13839 case O_symbol:
13840 case O_add:
13841 case O_subtract:
13842 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
13843 break;
13844
13845 default:
13846 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
13847 pc_rel, reloc);
13848 break;
13849 }
13850
13851 /* Mark whether the fix is to a THUMB instruction, or an ARM
13852 instruction. */
13853 new_fix->tc_fix_data = thumb_mode;
13854 }
13855
13856 /* Create a frg for an instruction requiring relaxation. */
13857 static void
13858 output_relax_insn (void)
13859 {
13860 char * to;
13861 symbolS *sym;
13862 int offset;
13863
13864 /* The size of the instruction is unknown, so tie the debug info to the
13865 start of the instruction. */
13866 dwarf2_emit_insn (0);
13867
13868 switch (inst.reloc.exp.X_op)
13869 {
13870 case O_symbol:
13871 sym = inst.reloc.exp.X_add_symbol;
13872 offset = inst.reloc.exp.X_add_number;
13873 break;
13874 case O_constant:
13875 sym = NULL;
13876 offset = inst.reloc.exp.X_add_number;
13877 break;
13878 default:
13879 sym = make_expr_symbol (&inst.reloc.exp);
13880 offset = 0;
13881 break;
13882 }
13883 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
13884 inst.relax, sym, offset, NULL/*offset, opcode*/);
13885 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
13886 }
13887
13888 /* Write a 32-bit thumb instruction to buf. */
13889 static void
13890 put_thumb32_insn (char * buf, unsigned long insn)
13891 {
13892 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
13893 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
13894 }
13895
13896 static void
13897 output_inst (const char * str)
13898 {
13899 char * to = NULL;
13900
13901 if (inst.error)
13902 {
13903 as_bad ("%s -- `%s'", inst.error, str);
13904 return;
13905 }
13906 if (inst.relax)
13907 {
13908 output_relax_insn ();
13909 return;
13910 }
13911 if (inst.size == 0)
13912 return;
13913
13914 to = frag_more (inst.size);
13915
13916 if (thumb_mode && (inst.size > THUMB_SIZE))
13917 {
13918 assert (inst.size == (2 * THUMB_SIZE));
13919 put_thumb32_insn (to, inst.instruction);
13920 }
13921 else if (inst.size > INSN_SIZE)
13922 {
13923 assert (inst.size == (2 * INSN_SIZE));
13924 md_number_to_chars (to, inst.instruction, INSN_SIZE);
13925 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
13926 }
13927 else
13928 md_number_to_chars (to, inst.instruction, inst.size);
13929
13930 if (inst.reloc.type != BFD_RELOC_UNUSED)
13931 fix_new_arm (frag_now, to - frag_now->fr_literal,
13932 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
13933 inst.reloc.type);
13934
13935 dwarf2_emit_insn (inst.size);
13936 }
13937
13938 /* Tag values used in struct asm_opcode's tag field. */
13939 enum opcode_tag
13940 {
13941 OT_unconditional, /* Instruction cannot be conditionalized.
13942 The ARM condition field is still 0xE. */
13943 OT_unconditionalF, /* Instruction cannot be conditionalized
13944 and carries 0xF in its ARM condition field. */
13945 OT_csuffix, /* Instruction takes a conditional suffix. */
13946 OT_csuffixF, /* Some forms of the instruction take a conditional
13947 suffix, others place 0xF where the condition field
13948 would be. */
13949 OT_cinfix3, /* Instruction takes a conditional infix,
13950 beginning at character index 3. (In
13951 unified mode, it becomes a suffix.) */
13952 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
13953 tsts, cmps, cmns, and teqs. */
13954 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
13955 character index 3, even in unified mode. Used for
13956 legacy instructions where suffix and infix forms
13957 may be ambiguous. */
13958 OT_csuf_or_in3, /* Instruction takes either a conditional
13959 suffix or an infix at character index 3. */
13960 OT_odd_infix_unc, /* This is the unconditional variant of an
13961 instruction that takes a conditional infix
13962 at an unusual position. In unified mode,
13963 this variant will accept a suffix. */
13964 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
13965 are the conditional variants of instructions that
13966 take conditional infixes in unusual positions.
13967 The infix appears at character index
13968 (tag - OT_odd_infix_0). These are not accepted
13969 in unified mode. */
13970 };
13971
13972 /* Subroutine of md_assemble, responsible for looking up the primary
13973 opcode from the mnemonic the user wrote. STR points to the
13974 beginning of the mnemonic.
13975
13976 This is not simply a hash table lookup, because of conditional
13977 variants. Most instructions have conditional variants, which are
13978 expressed with a _conditional affix_ to the mnemonic. If we were
13979 to encode each conditional variant as a literal string in the opcode
13980 table, it would have approximately 20,000 entries.
13981
13982 Most mnemonics take this affix as a suffix, and in unified syntax,
13983 'most' is upgraded to 'all'. However, in the divided syntax, some
13984 instructions take the affix as an infix, notably the s-variants of
13985 the arithmetic instructions. Of those instructions, all but six
13986 have the infix appear after the third character of the mnemonic.
13987
13988 Accordingly, the algorithm for looking up primary opcodes given
13989 an identifier is:
13990
13991 1. Look up the identifier in the opcode table.
13992 If we find a match, go to step U.
13993
13994 2. Look up the last two characters of the identifier in the
13995 conditions table. If we find a match, look up the first N-2
13996 characters of the identifier in the opcode table. If we
13997 find a match, go to step CE.
13998
13999 3. Look up the fourth and fifth characters of the identifier in
14000 the conditions table. If we find a match, extract those
14001 characters from the identifier, and look up the remaining
14002 characters in the opcode table. If we find a match, go
14003 to step CM.
14004
14005 4. Fail.
14006
14007 U. Examine the tag field of the opcode structure, in case this is
14008 one of the six instructions with its conditional infix in an
14009 unusual place. If it is, the tag tells us where to find the
14010 infix; look it up in the conditions table and set inst.cond
14011 accordingly. Otherwise, this is an unconditional instruction.
14012 Again set inst.cond accordingly. Return the opcode structure.
14013
14014 CE. Examine the tag field to make sure this is an instruction that
14015 should receive a conditional suffix. If it is not, fail.
14016 Otherwise, set inst.cond from the suffix we already looked up,
14017 and return the opcode structure.
14018
14019 CM. Examine the tag field to make sure this is an instruction that
14020 should receive a conditional infix after the third character.
14021 If it is not, fail. Otherwise, undo the edits to the current
14022 line of input and proceed as for case CE. */
14023
14024 static const struct asm_opcode *
14025 opcode_lookup (char **str)
14026 {
14027 char *end, *base;
14028 char *affix;
14029 const struct asm_opcode *opcode;
14030 const struct asm_cond *cond;
14031 char save[2];
14032 bfd_boolean neon_supported;
14033
14034 neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1);
14035
14036 /* Scan up to the end of the mnemonic, which must end in white space,
14037 '.' (in unified mode, or for Neon instructions), or end of string. */
14038 for (base = end = *str; *end != '\0'; end++)
14039 if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.'))
14040 break;
14041
14042 if (end == base)
14043 return 0;
14044
14045 /* Handle a possible width suffix and/or Neon type suffix. */
14046 if (end[0] == '.')
14047 {
14048 int offset = 2;
14049
14050 /* The .w and .n suffixes are only valid if the unified syntax is in
14051 use. */
14052 if (unified_syntax && end[1] == 'w')
14053 inst.size_req = 4;
14054 else if (unified_syntax && end[1] == 'n')
14055 inst.size_req = 2;
14056 else
14057 offset = 0;
14058
14059 inst.vectype.elems = 0;
14060
14061 *str = end + offset;
14062
14063 if (end[offset] == '.')
14064 {
14065 /* See if we have a Neon type suffix (possible in either unified or
14066 non-unified ARM syntax mode). */
14067 if (parse_neon_type (&inst.vectype, str) == FAIL)
14068 return 0;
14069 }
14070 else if (end[offset] != '\0' && end[offset] != ' ')
14071 return 0;
14072 }
14073 else
14074 *str = end;
14075
14076 /* Look for unaffixed or special-case affixed mnemonic. */
14077 opcode = hash_find_n (arm_ops_hsh, base, end - base);
14078 if (opcode)
14079 {
14080 /* step U */
14081 if (opcode->tag < OT_odd_infix_0)
14082 {
14083 inst.cond = COND_ALWAYS;
14084 return opcode;
14085 }
14086
14087 if (unified_syntax)
14088 as_warn (_("conditional infixes are deprecated in unified syntax"));
14089 affix = base + (opcode->tag - OT_odd_infix_0);
14090 cond = hash_find_n (arm_cond_hsh, affix, 2);
14091 assert (cond);
14092
14093 inst.cond = cond->value;
14094 return opcode;
14095 }
14096
14097 /* Cannot have a conditional suffix on a mnemonic of less than two
14098 characters. */
14099 if (end - base < 3)
14100 return 0;
14101
14102 /* Look for suffixed mnemonic. */
14103 affix = end - 2;
14104 cond = hash_find_n (arm_cond_hsh, affix, 2);
14105 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
14106 if (opcode && cond)
14107 {
14108 /* step CE */
14109 switch (opcode->tag)
14110 {
14111 case OT_cinfix3_legacy:
14112 /* Ignore conditional suffixes matched on infix only mnemonics. */
14113 break;
14114
14115 case OT_cinfix3:
14116 case OT_cinfix3_deprecated:
14117 case OT_odd_infix_unc:
14118 if (!unified_syntax)
14119 return 0;
14120 /* else fall through */
14121
14122 case OT_csuffix:
14123 case OT_csuffixF:
14124 case OT_csuf_or_in3:
14125 inst.cond = cond->value;
14126 return opcode;
14127
14128 case OT_unconditional:
14129 case OT_unconditionalF:
14130 if (thumb_mode)
14131 {
14132 inst.cond = cond->value;
14133 }
14134 else
14135 {
14136 /* delayed diagnostic */
14137 inst.error = BAD_COND;
14138 inst.cond = COND_ALWAYS;
14139 }
14140 return opcode;
14141
14142 default:
14143 return 0;
14144 }
14145 }
14146
14147 /* Cannot have a usual-position infix on a mnemonic of less than
14148 six characters (five would be a suffix). */
14149 if (end - base < 6)
14150 return 0;
14151
14152 /* Look for infixed mnemonic in the usual position. */
14153 affix = base + 3;
14154 cond = hash_find_n (arm_cond_hsh, affix, 2);
14155 if (!cond)
14156 return 0;
14157
14158 memcpy (save, affix, 2);
14159 memmove (affix, affix + 2, (end - affix) - 2);
14160 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
14161 memmove (affix + 2, affix, (end - affix) - 2);
14162 memcpy (affix, save, 2);
14163
14164 if (opcode
14165 && (opcode->tag == OT_cinfix3
14166 || opcode->tag == OT_cinfix3_deprecated
14167 || opcode->tag == OT_csuf_or_in3
14168 || opcode->tag == OT_cinfix3_legacy))
14169 {
14170 /* step CM */
14171 if (unified_syntax
14172 && (opcode->tag == OT_cinfix3
14173 || opcode->tag == OT_cinfix3_deprecated))
14174 as_warn (_("conditional infixes are deprecated in unified syntax"));
14175
14176 inst.cond = cond->value;
14177 return opcode;
14178 }
14179
14180 return 0;
14181 }
14182
14183 void
14184 md_assemble (char *str)
14185 {
14186 char *p = str;
14187 const struct asm_opcode * opcode;
14188
14189 /* Align the previous label if needed. */
14190 if (last_label_seen != NULL)
14191 {
14192 symbol_set_frag (last_label_seen, frag_now);
14193 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
14194 S_SET_SEGMENT (last_label_seen, now_seg);
14195 }
14196
14197 memset (&inst, '\0', sizeof (inst));
14198 inst.reloc.type = BFD_RELOC_UNUSED;
14199
14200 opcode = opcode_lookup (&p);
14201 if (!opcode)
14202 {
14203 /* It wasn't an instruction, but it might be a register alias of
14204 the form alias .req reg, or a Neon .dn/.qn directive. */
14205 if (!create_register_alias (str, p)
14206 && !create_neon_reg_alias (str, p))
14207 as_bad (_("bad instruction `%s'"), str);
14208
14209 return;
14210 }
14211
14212 if (opcode->tag == OT_cinfix3_deprecated)
14213 as_warn (_("s suffix on comparison instruction is deprecated"));
14214
14215 /* The value which unconditional instructions should have in place of the
14216 condition field. */
14217 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
14218
14219 if (thumb_mode)
14220 {
14221 arm_feature_set variant;
14222
14223 variant = cpu_variant;
14224 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
14225 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
14226 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
14227 /* Check that this instruction is supported for this CPU. */
14228 if (!opcode->tvariant
14229 || (thumb_mode == 1
14230 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
14231 {
14232 as_bad (_("selected processor does not support `%s'"), str);
14233 return;
14234 }
14235 if (inst.cond != COND_ALWAYS && !unified_syntax
14236 && opcode->tencode != do_t_branch)
14237 {
14238 as_bad (_("Thumb does not support conditional execution"));
14239 return;
14240 }
14241
14242 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) && !inst.size_req)
14243 {
14244 /* Implicit require narrow instructions on Thumb-1. This avoids
14245 relaxation accidentally introducing Thumb-2 instructions. */
14246 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
14247 && !ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr))
14248 inst.size_req = 2;
14249 }
14250
14251 /* Check conditional suffixes. */
14252 if (current_it_mask)
14253 {
14254 int cond;
14255 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
14256 current_it_mask <<= 1;
14257 current_it_mask &= 0x1f;
14258 /* The BKPT instruction is unconditional even in an IT block. */
14259 if (!inst.error
14260 && cond != inst.cond && opcode->tencode != do_t_bkpt)
14261 {
14262 as_bad (_("incorrect condition in IT block"));
14263 return;
14264 }
14265 }
14266 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
14267 {
14268 as_bad (_("thumb conditional instruction not in IT block"));
14269 return;
14270 }
14271
14272 mapping_state (MAP_THUMB);
14273 inst.instruction = opcode->tvalue;
14274
14275 if (!parse_operands (p, opcode->operands))
14276 opcode->tencode ();
14277
14278 /* Clear current_it_mask at the end of an IT block. */
14279 if (current_it_mask == 0x10)
14280 current_it_mask = 0;
14281
14282 if (!(inst.error || inst.relax))
14283 {
14284 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
14285 inst.size = (inst.instruction > 0xffff ? 4 : 2);
14286 if (inst.size_req && inst.size_req != inst.size)
14287 {
14288 as_bad (_("cannot honor width suffix -- `%s'"), str);
14289 return;
14290 }
14291 }
14292
14293 /* Something has gone badly wrong if we try to relax a fixed size
14294 instruction. */
14295 assert (inst.size_req == 0 || !inst.relax);
14296
14297 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14298 *opcode->tvariant);
14299 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
14300 set those bits when Thumb-2 32-bit instructions are seen. ie.
14301 anything other than bl/blx and v6-M instructions.
14302 This is overly pessimistic for relaxable instructions. */
14303 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
14304 || inst.relax)
14305 && !ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr))
14306 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14307 arm_ext_v6t2);
14308 }
14309 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
14310 {
14311 bfd_boolean is_bx;
14312
14313 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
14314 is_bx = (opcode->aencode == do_bx);
14315
14316 /* Check that this instruction is supported for this CPU. */
14317 if (!(is_bx && fix_v4bx)
14318 && !(opcode->avariant &&
14319 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
14320 {
14321 as_bad (_("selected processor does not support `%s'"), str);
14322 return;
14323 }
14324 if (inst.size_req)
14325 {
14326 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
14327 return;
14328 }
14329
14330 mapping_state (MAP_ARM);
14331 inst.instruction = opcode->avalue;
14332 if (opcode->tag == OT_unconditionalF)
14333 inst.instruction |= 0xF << 28;
14334 else
14335 inst.instruction |= inst.cond << 28;
14336 inst.size = INSN_SIZE;
14337 if (!parse_operands (p, opcode->operands))
14338 opcode->aencode ();
14339 /* Arm mode bx is marked as both v4T and v5 because it's still required
14340 on a hypothetical non-thumb v5 core. */
14341 if (is_bx)
14342 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
14343 else
14344 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
14345 *opcode->avariant);
14346 }
14347 else
14348 {
14349 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
14350 "-- `%s'"), str);
14351 return;
14352 }
14353 output_inst (str);
14354 }
14355
14356 /* Various frobbings of labels and their addresses. */
14357
14358 void
14359 arm_start_line_hook (void)
14360 {
14361 last_label_seen = NULL;
14362 }
14363
14364 void
14365 arm_frob_label (symbolS * sym)
14366 {
14367 last_label_seen = sym;
14368
14369 ARM_SET_THUMB (sym, thumb_mode);
14370
14371 #if defined OBJ_COFF || defined OBJ_ELF
14372 ARM_SET_INTERWORK (sym, support_interwork);
14373 #endif
14374
14375 /* Note - do not allow local symbols (.Lxxx) to be labelled
14376 as Thumb functions. This is because these labels, whilst
14377 they exist inside Thumb code, are not the entry points for
14378 possible ARM->Thumb calls. Also, these labels can be used
14379 as part of a computed goto or switch statement. eg gcc
14380 can generate code that looks like this:
14381
14382 ldr r2, [pc, .Laaa]
14383 lsl r3, r3, #2
14384 ldr r2, [r3, r2]
14385 mov pc, r2
14386
14387 .Lbbb: .word .Lxxx
14388 .Lccc: .word .Lyyy
14389 ..etc...
14390 .Laaa: .word Lbbb
14391
14392 The first instruction loads the address of the jump table.
14393 The second instruction converts a table index into a byte offset.
14394 The third instruction gets the jump address out of the table.
14395 The fourth instruction performs the jump.
14396
14397 If the address stored at .Laaa is that of a symbol which has the
14398 Thumb_Func bit set, then the linker will arrange for this address
14399 to have the bottom bit set, which in turn would mean that the
14400 address computation performed by the third instruction would end
14401 up with the bottom bit set. Since the ARM is capable of unaligned
14402 word loads, the instruction would then load the incorrect address
14403 out of the jump table, and chaos would ensue. */
14404 if (label_is_thumb_function_name
14405 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
14406 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
14407 {
14408 /* When the address of a Thumb function is taken the bottom
14409 bit of that address should be set. This will allow
14410 interworking between Arm and Thumb functions to work
14411 correctly. */
14412
14413 THUMB_SET_FUNC (sym, 1);
14414
14415 label_is_thumb_function_name = FALSE;
14416 }
14417
14418 dwarf2_emit_label (sym);
14419 }
14420
14421 int
14422 arm_data_in_code (void)
14423 {
14424 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
14425 {
14426 *input_line_pointer = '/';
14427 input_line_pointer += 5;
14428 *input_line_pointer = 0;
14429 return 1;
14430 }
14431
14432 return 0;
14433 }
14434
14435 char *
14436 arm_canonicalize_symbol_name (char * name)
14437 {
14438 int len;
14439
14440 if (thumb_mode && (len = strlen (name)) > 5
14441 && streq (name + len - 5, "/data"))
14442 *(name + len - 5) = 0;
14443
14444 return name;
14445 }
14446 \f
14447 /* Table of all register names defined by default. The user can
14448 define additional names with .req. Note that all register names
14449 should appear in both upper and lowercase variants. Some registers
14450 also have mixed-case names. */
14451
14452 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
14453 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
14454 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
14455 #define REGSET(p,t) \
14456 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
14457 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
14458 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
14459 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
14460 #define REGSETH(p,t) \
14461 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
14462 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
14463 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
14464 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
14465 #define REGSET2(p,t) \
14466 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
14467 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
14468 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
14469 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
14470
14471 static const struct reg_entry reg_names[] =
14472 {
14473 /* ARM integer registers. */
14474 REGSET(r, RN), REGSET(R, RN),
14475
14476 /* ATPCS synonyms. */
14477 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
14478 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
14479 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
14480
14481 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
14482 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
14483 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
14484
14485 /* Well-known aliases. */
14486 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
14487 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
14488
14489 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
14490 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
14491
14492 /* Coprocessor numbers. */
14493 REGSET(p, CP), REGSET(P, CP),
14494
14495 /* Coprocessor register numbers. The "cr" variants are for backward
14496 compatibility. */
14497 REGSET(c, CN), REGSET(C, CN),
14498 REGSET(cr, CN), REGSET(CR, CN),
14499
14500 /* FPA registers. */
14501 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
14502 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
14503
14504 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
14505 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
14506
14507 /* VFP SP registers. */
14508 REGSET(s,VFS), REGSET(S,VFS),
14509 REGSETH(s,VFS), REGSETH(S,VFS),
14510
14511 /* VFP DP Registers. */
14512 REGSET(d,VFD), REGSET(D,VFD),
14513 /* Extra Neon DP registers. */
14514 REGSETH(d,VFD), REGSETH(D,VFD),
14515
14516 /* Neon QP registers. */
14517 REGSET2(q,NQ), REGSET2(Q,NQ),
14518
14519 /* VFP control registers. */
14520 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
14521 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
14522 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
14523 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
14524 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
14525 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
14526
14527 /* Maverick DSP coprocessor registers. */
14528 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
14529 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
14530
14531 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
14532 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
14533 REGDEF(dspsc,0,DSPSC),
14534
14535 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
14536 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
14537 REGDEF(DSPSC,0,DSPSC),
14538
14539 /* iWMMXt data registers - p0, c0-15. */
14540 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
14541
14542 /* iWMMXt control registers - p1, c0-3. */
14543 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
14544 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
14545 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
14546 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
14547
14548 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
14549 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
14550 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
14551 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
14552 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
14553
14554 /* XScale accumulator registers. */
14555 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
14556 };
14557 #undef REGDEF
14558 #undef REGNUM
14559 #undef REGSET
14560
14561 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
14562 within psr_required_here. */
14563 static const struct asm_psr psrs[] =
14564 {
14565 /* Backward compatibility notation. Note that "all" is no longer
14566 truly all possible PSR bits. */
14567 {"all", PSR_c | PSR_f},
14568 {"flg", PSR_f},
14569 {"ctl", PSR_c},
14570
14571 /* Individual flags. */
14572 {"f", PSR_f},
14573 {"c", PSR_c},
14574 {"x", PSR_x},
14575 {"s", PSR_s},
14576 /* Combinations of flags. */
14577 {"fs", PSR_f | PSR_s},
14578 {"fx", PSR_f | PSR_x},
14579 {"fc", PSR_f | PSR_c},
14580 {"sf", PSR_s | PSR_f},
14581 {"sx", PSR_s | PSR_x},
14582 {"sc", PSR_s | PSR_c},
14583 {"xf", PSR_x | PSR_f},
14584 {"xs", PSR_x | PSR_s},
14585 {"xc", PSR_x | PSR_c},
14586 {"cf", PSR_c | PSR_f},
14587 {"cs", PSR_c | PSR_s},
14588 {"cx", PSR_c | PSR_x},
14589 {"fsx", PSR_f | PSR_s | PSR_x},
14590 {"fsc", PSR_f | PSR_s | PSR_c},
14591 {"fxs", PSR_f | PSR_x | PSR_s},
14592 {"fxc", PSR_f | PSR_x | PSR_c},
14593 {"fcs", PSR_f | PSR_c | PSR_s},
14594 {"fcx", PSR_f | PSR_c | PSR_x},
14595 {"sfx", PSR_s | PSR_f | PSR_x},
14596 {"sfc", PSR_s | PSR_f | PSR_c},
14597 {"sxf", PSR_s | PSR_x | PSR_f},
14598 {"sxc", PSR_s | PSR_x | PSR_c},
14599 {"scf", PSR_s | PSR_c | PSR_f},
14600 {"scx", PSR_s | PSR_c | PSR_x},
14601 {"xfs", PSR_x | PSR_f | PSR_s},
14602 {"xfc", PSR_x | PSR_f | PSR_c},
14603 {"xsf", PSR_x | PSR_s | PSR_f},
14604 {"xsc", PSR_x | PSR_s | PSR_c},
14605 {"xcf", PSR_x | PSR_c | PSR_f},
14606 {"xcs", PSR_x | PSR_c | PSR_s},
14607 {"cfs", PSR_c | PSR_f | PSR_s},
14608 {"cfx", PSR_c | PSR_f | PSR_x},
14609 {"csf", PSR_c | PSR_s | PSR_f},
14610 {"csx", PSR_c | PSR_s | PSR_x},
14611 {"cxf", PSR_c | PSR_x | PSR_f},
14612 {"cxs", PSR_c | PSR_x | PSR_s},
14613 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
14614 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
14615 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
14616 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
14617 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
14618 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
14619 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
14620 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
14621 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
14622 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
14623 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
14624 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
14625 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
14626 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
14627 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
14628 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
14629 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
14630 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
14631 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
14632 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
14633 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
14634 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
14635 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
14636 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
14637 };
14638
14639 /* Table of V7M psr names. */
14640 static const struct asm_psr v7m_psrs[] =
14641 {
14642 {"apsr", 0 }, {"APSR", 0 },
14643 {"iapsr", 1 }, {"IAPSR", 1 },
14644 {"eapsr", 2 }, {"EAPSR", 2 },
14645 {"psr", 3 }, {"PSR", 3 },
14646 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
14647 {"ipsr", 5 }, {"IPSR", 5 },
14648 {"epsr", 6 }, {"EPSR", 6 },
14649 {"iepsr", 7 }, {"IEPSR", 7 },
14650 {"msp", 8 }, {"MSP", 8 },
14651 {"psp", 9 }, {"PSP", 9 },
14652 {"primask", 16}, {"PRIMASK", 16},
14653 {"basepri", 17}, {"BASEPRI", 17},
14654 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
14655 {"faultmask", 19}, {"FAULTMASK", 19},
14656 {"control", 20}, {"CONTROL", 20}
14657 };
14658
14659 /* Table of all shift-in-operand names. */
14660 static const struct asm_shift_name shift_names [] =
14661 {
14662 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
14663 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
14664 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
14665 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
14666 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
14667 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
14668 };
14669
14670 /* Table of all explicit relocation names. */
14671 #ifdef OBJ_ELF
14672 static struct reloc_entry reloc_names[] =
14673 {
14674 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
14675 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
14676 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
14677 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
14678 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
14679 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
14680 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
14681 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
14682 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
14683 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
14684 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
14685 };
14686 #endif
14687
14688 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
14689 static const struct asm_cond conds[] =
14690 {
14691 {"eq", 0x0},
14692 {"ne", 0x1},
14693 {"cs", 0x2}, {"hs", 0x2},
14694 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
14695 {"mi", 0x4},
14696 {"pl", 0x5},
14697 {"vs", 0x6},
14698 {"vc", 0x7},
14699 {"hi", 0x8},
14700 {"ls", 0x9},
14701 {"ge", 0xa},
14702 {"lt", 0xb},
14703 {"gt", 0xc},
14704 {"le", 0xd},
14705 {"al", 0xe}
14706 };
14707
14708 static struct asm_barrier_opt barrier_opt_names[] =
14709 {
14710 { "sy", 0xf },
14711 { "un", 0x7 },
14712 { "st", 0xe },
14713 { "unst", 0x6 }
14714 };
14715
14716 /* Table of ARM-format instructions. */
14717
14718 /* Macros for gluing together operand strings. N.B. In all cases
14719 other than OPS0, the trailing OP_stop comes from default
14720 zero-initialization of the unspecified elements of the array. */
14721 #define OPS0() { OP_stop, }
14722 #define OPS1(a) { OP_##a, }
14723 #define OPS2(a,b) { OP_##a,OP_##b, }
14724 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
14725 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
14726 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
14727 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
14728
14729 /* These macros abstract out the exact format of the mnemonic table and
14730 save some repeated characters. */
14731
14732 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
14733 #define TxCE(mnem, op, top, nops, ops, ae, te) \
14734 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
14735 THUMB_VARIANT, do_##ae, do_##te }
14736
14737 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
14738 a T_MNEM_xyz enumerator. */
14739 #define TCE(mnem, aop, top, nops, ops, ae, te) \
14740 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
14741 #define tCE(mnem, aop, top, nops, ops, ae, te) \
14742 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14743
14744 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
14745 infix after the third character. */
14746 #define TxC3(mnem, op, top, nops, ops, ae, te) \
14747 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
14748 THUMB_VARIANT, do_##ae, do_##te }
14749 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
14750 { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
14751 THUMB_VARIANT, do_##ae, do_##te }
14752 #define TC3(mnem, aop, top, nops, ops, ae, te) \
14753 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
14754 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
14755 TxC3w(mnem, aop, 0x##top, nops, ops, ae, te)
14756 #define tC3(mnem, aop, top, nops, ops, ae, te) \
14757 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14758 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
14759 TxC3w(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14760
14761 /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
14762 appear in the condition table. */
14763 #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
14764 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14765 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
14766
14767 #define TxCM(m1, m2, op, top, nops, ops, ae, te) \
14768 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
14769 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
14770 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
14771 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
14772 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
14773 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
14774 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
14775 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
14776 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
14777 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
14778 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
14779 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
14780 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
14781 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
14782 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
14783 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
14784 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
14785 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
14786 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
14787
14788 #define TCM(m1,m2, aop, top, nops, ops, ae, te) \
14789 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
14790 #define tCM(m1,m2, aop, top, nops, ops, ae, te) \
14791 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
14792
14793 /* Mnemonic that cannot be conditionalized. The ARM condition-code
14794 field is still 0xE. Many of the Thumb variants can be executed
14795 conditionally, so this is checked separately. */
14796 #define TUE(mnem, op, top, nops, ops, ae, te) \
14797 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
14798 THUMB_VARIANT, do_##ae, do_##te }
14799
14800 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
14801 condition code field. */
14802 #define TUF(mnem, op, top, nops, ops, ae, te) \
14803 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
14804 THUMB_VARIANT, do_##ae, do_##te }
14805
14806 /* ARM-only variants of all the above. */
14807 #define CE(mnem, op, nops, ops, ae) \
14808 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14809
14810 #define C3(mnem, op, nops, ops, ae) \
14811 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14812
14813 /* Legacy mnemonics that always have conditional infix after the third
14814 character. */
14815 #define CL(mnem, op, nops, ops, ae) \
14816 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14817 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14818
14819 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
14820 #define cCE(mnem, op, nops, ops, ae) \
14821 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14822
14823 /* Legacy coprocessor instructions where conditional infix and conditional
14824 suffix are ambiguous. For consistency this includes all FPA instructions,
14825 not just the potentially ambiguous ones. */
14826 #define cCL(mnem, op, nops, ops, ae) \
14827 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14828 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14829
14830 /* Coprocessor, takes either a suffix or a position-3 infix
14831 (for an FPA corner case). */
14832 #define C3E(mnem, op, nops, ops, ae) \
14833 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
14834 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14835
14836 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
14837 { #m1 #m2 #m3, OPS##nops ops, \
14838 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14839 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14840
14841 #define CM(m1, m2, op, nops, ops, ae) \
14842 xCM_(m1, , m2, op, nops, ops, ae), \
14843 xCM_(m1, eq, m2, op, nops, ops, ae), \
14844 xCM_(m1, ne, m2, op, nops, ops, ae), \
14845 xCM_(m1, cs, m2, op, nops, ops, ae), \
14846 xCM_(m1, hs, m2, op, nops, ops, ae), \
14847 xCM_(m1, cc, m2, op, nops, ops, ae), \
14848 xCM_(m1, ul, m2, op, nops, ops, ae), \
14849 xCM_(m1, lo, m2, op, nops, ops, ae), \
14850 xCM_(m1, mi, m2, op, nops, ops, ae), \
14851 xCM_(m1, pl, m2, op, nops, ops, ae), \
14852 xCM_(m1, vs, m2, op, nops, ops, ae), \
14853 xCM_(m1, vc, m2, op, nops, ops, ae), \
14854 xCM_(m1, hi, m2, op, nops, ops, ae), \
14855 xCM_(m1, ls, m2, op, nops, ops, ae), \
14856 xCM_(m1, ge, m2, op, nops, ops, ae), \
14857 xCM_(m1, lt, m2, op, nops, ops, ae), \
14858 xCM_(m1, gt, m2, op, nops, ops, ae), \
14859 xCM_(m1, le, m2, op, nops, ops, ae), \
14860 xCM_(m1, al, m2, op, nops, ops, ae)
14861
14862 #define UE(mnem, op, nops, ops, ae) \
14863 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14864
14865 #define UF(mnem, op, nops, ops, ae) \
14866 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14867
14868 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
14869 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
14870 use the same encoding function for each. */
14871 #define NUF(mnem, op, nops, ops, enc) \
14872 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
14873 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14874
14875 /* Neon data processing, version which indirects through neon_enc_tab for
14876 the various overloaded versions of opcodes. */
14877 #define nUF(mnem, op, nops, ops, enc) \
14878 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \
14879 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14880
14881 /* Neon insn with conditional suffix for the ARM version, non-overloaded
14882 version. */
14883 #define NCE_tag(mnem, op, nops, ops, enc, tag) \
14884 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
14885 THUMB_VARIANT, do_##enc, do_##enc }
14886
14887 #define NCE(mnem, op, nops, ops, enc) \
14888 NCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14889
14890 #define NCEF(mnem, op, nops, ops, enc) \
14891 NCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14892
14893 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
14894 #define nCE_tag(mnem, op, nops, ops, enc, tag) \
14895 { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \
14896 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14897
14898 #define nCE(mnem, op, nops, ops, enc) \
14899 nCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14900
14901 #define nCEF(mnem, op, nops, ops, enc) \
14902 nCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14903
14904 #define do_0 0
14905
14906 /* Thumb-only, unconditional. */
14907 #define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
14908
14909 static const struct asm_opcode insns[] =
14910 {
14911 #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
14912 #define THUMB_VARIANT &arm_ext_v4t
14913 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
14914 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
14915 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
14916 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
14917 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
14918 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
14919 tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub),
14920 tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub),
14921 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
14922 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
14923 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
14924 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
14925 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
14926 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
14927 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
14928 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
14929
14930 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
14931 for setting PSR flag bits. They are obsolete in V6 and do not
14932 have Thumb equivalents. */
14933 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
14934 tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
14935 CL(tstp, 110f000, 2, (RR, SH), cmp),
14936 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
14937 tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
14938 CL(cmpp, 150f000, 2, (RR, SH), cmp),
14939 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
14940 tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
14941 CL(cmnp, 170f000, 2, (RR, SH), cmp),
14942
14943 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
14944 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
14945 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
14946 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
14947
14948 tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
14949 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
14950 tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst),
14951 tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
14952
14953 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14954 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14955 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14956 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14957 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14958 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14959
14960 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
14961 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
14962 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
14963 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
14964
14965 /* Pseudo ops. */
14966 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
14967 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
14968 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
14969
14970 /* Thumb-compatibility pseudo ops. */
14971 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
14972 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
14973 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
14974 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
14975 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
14976 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
14977 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
14978 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
14979 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
14980 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
14981 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
14982 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
14983
14984 /* These may simplify to neg. */
14985 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
14986 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
14987
14988 #undef THUMB_VARIANT
14989 #define THUMB_VARIANT &arm_ext_v6
14990 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
14991
14992 /* V1 instructions with no Thumb analogue prior to V6T2. */
14993 #undef THUMB_VARIANT
14994 #define THUMB_VARIANT &arm_ext_v6t2
14995 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
14996 TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
14997 CL(teqp, 130f000, 2, (RR, SH), cmp),
14998
14999 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
15000 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
15001 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
15002 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
15003
15004 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15005 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15006
15007 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15008 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15009
15010 /* V1 instructions with no Thumb analogue at all. */
15011 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
15012 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
15013
15014 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
15015 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
15016 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
15017 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
15018 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
15019 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
15020 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
15021 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
15022
15023 #undef ARM_VARIANT
15024 #define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
15025 #undef THUMB_VARIANT
15026 #define THUMB_VARIANT &arm_ext_v4t
15027 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15028 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15029
15030 #undef THUMB_VARIANT
15031 #define THUMB_VARIANT &arm_ext_v6t2
15032 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
15033 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
15034
15035 /* Generic coprocessor instructions. */
15036 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
15037 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15038 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15039 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15040 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15041 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15042 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15043
15044 #undef ARM_VARIANT
15045 #define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
15046 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15047 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15048
15049 #undef ARM_VARIANT
15050 #define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
15051 #undef THUMB_VARIANT
15052 #define THUMB_VARIANT &arm_ext_msr
15053 TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
15054 TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
15055
15056 #undef ARM_VARIANT
15057 #define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
15058 #undef THUMB_VARIANT
15059 #define THUMB_VARIANT &arm_ext_v6t2
15060 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15061 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15062 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15063 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15064 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15065 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15066 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15067 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15068
15069 #undef ARM_VARIANT
15070 #define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
15071 #undef THUMB_VARIANT
15072 #define THUMB_VARIANT &arm_ext_v4t
15073 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15074 tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15075 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15076 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15077 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15078 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15079
15080 #undef ARM_VARIANT
15081 #define ARM_VARIANT &arm_ext_v4t_5
15082 /* ARM Architecture 4T. */
15083 /* Note: bx (and blx) are required on V5, even if the processor does
15084 not support Thumb. */
15085 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
15086
15087 #undef ARM_VARIANT
15088 #define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
15089 #undef THUMB_VARIANT
15090 #define THUMB_VARIANT &arm_ext_v5t
15091 /* Note: blx has 2 variants; the .value coded here is for
15092 BLX(2). Only this variant has conditional execution. */
15093 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
15094 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
15095
15096 #undef THUMB_VARIANT
15097 #define THUMB_VARIANT &arm_ext_v6t2
15098 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
15099 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15100 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15101 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15102 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15103 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
15104 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15105 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15106
15107 #undef ARM_VARIANT
15108 #define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
15109 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15110 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15111 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15112 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15113
15114 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15115 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15116
15117 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15118 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15119 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15120 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15121
15122 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15123 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15124 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15125 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15126
15127 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15128 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15129
15130 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15131 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15132 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15133 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15134
15135 #undef ARM_VARIANT
15136 #define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
15137 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
15138 TC3(ldrd, 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
15139 TC3(strd, 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
15140
15141 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15142 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15143
15144 #undef ARM_VARIANT
15145 #define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
15146 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
15147
15148 #undef ARM_VARIANT
15149 #define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
15150 #undef THUMB_VARIANT
15151 #define THUMB_VARIANT &arm_ext_v6
15152 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
15153 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
15154 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15155 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15156 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15157 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15158 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15159 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15160 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15161 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
15162
15163 #undef THUMB_VARIANT
15164 #define THUMB_VARIANT &arm_ext_v6t2
15165 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
15166 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
15167 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15168 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15169
15170 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
15171 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
15172
15173 /* ARM V6 not included in V7M (eg. integer SIMD). */
15174 #undef THUMB_VARIANT
15175 #define THUMB_VARIANT &arm_ext_v6_notm
15176 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
15177 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
15178 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
15179 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15180 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15181 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15182 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15183 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15184 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15185 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15186 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15187 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15188 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15189 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15190 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15191 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15192 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15193 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15194 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15195 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15196 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15197 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15198 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15199 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15200 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15201 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15202 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15203 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15204 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15205 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15206 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15207 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15208 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15209 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15210 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15211 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15212 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15213 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15214 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15215 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15216 UF(rfeib, 9900a00, 1, (RRw), rfe),
15217 UF(rfeda, 8100a00, 1, (RRw), rfe),
15218 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15219 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15220 UF(rfefa, 9900a00, 1, (RRw), rfe),
15221 UF(rfeea, 8100a00, 1, (RRw), rfe),
15222 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15223 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15224 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15225 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15226 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15227 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15228 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15229 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15230 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15231 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15232 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15233 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15234 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15235 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15236 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15237 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15238 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15239 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15240 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15241 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15242 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15243 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15244 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15245 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15246 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15247 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15248 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15249 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15250 TUF(srsia, 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
15251 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
15252 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
15253 TUF(srsdb, 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
15254 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
15255 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
15256 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15257 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15258 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
15259
15260 #undef ARM_VARIANT
15261 #define ARM_VARIANT &arm_ext_v6k
15262 #undef THUMB_VARIANT
15263 #define THUMB_VARIANT &arm_ext_v6k
15264 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
15265 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
15266 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
15267 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
15268
15269 #undef THUMB_VARIANT
15270 #define THUMB_VARIANT &arm_ext_v6_notm
15271 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
15272 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
15273
15274 #undef THUMB_VARIANT
15275 #define THUMB_VARIANT &arm_ext_v6t2
15276 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15277 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15278 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15279 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15280 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
15281
15282 #undef ARM_VARIANT
15283 #define ARM_VARIANT &arm_ext_v6z
15284 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
15285
15286 #undef ARM_VARIANT
15287 #define ARM_VARIANT &arm_ext_v6t2
15288 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
15289 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
15290 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15291 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15292
15293 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
15294 TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
15295 TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
15296 TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
15297
15298 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15299 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15300 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15301 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15302
15303 UT(cbnz, b900, 2, (RR, EXP), t_cbz),
15304 UT(cbz, b100, 2, (RR, EXP), t_cbz),
15305 /* ARM does not really have an IT instruction, so always allow it. */
15306 #undef ARM_VARIANT
15307 #define ARM_VARIANT &arm_ext_v1
15308 TUE(it, 0, bf08, 1, (COND), it, t_it),
15309 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
15310 TUE(ite, 0, bf04, 1, (COND), it, t_it),
15311 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
15312 TUE(itet, 0, bf06, 1, (COND), it, t_it),
15313 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
15314 TUE(itee, 0, bf02, 1, (COND), it, t_it),
15315 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
15316 TUE(itett, 0, bf07, 1, (COND), it, t_it),
15317 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
15318 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
15319 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
15320 TUE(itete, 0, bf05, 1, (COND), it, t_it),
15321 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
15322 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
15323
15324 /* Thumb2 only instructions. */
15325 #undef ARM_VARIANT
15326 #define ARM_VARIANT NULL
15327
15328 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15329 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15330 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
15331 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
15332
15333 /* Thumb-2 hardware division instructions (R and M profiles only). */
15334 #undef THUMB_VARIANT
15335 #define THUMB_VARIANT &arm_ext_div
15336 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
15337 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
15338
15339 /* ARM V6M/V7 instructions. */
15340 #undef ARM_VARIANT
15341 #define ARM_VARIANT &arm_ext_barrier
15342 #undef THUMB_VARIANT
15343 #define THUMB_VARIANT &arm_ext_barrier
15344 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
15345 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
15346 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
15347
15348 /* ARM V7 instructions. */
15349 #undef ARM_VARIANT
15350 #define ARM_VARIANT &arm_ext_v7
15351 #undef THUMB_VARIANT
15352 #define THUMB_VARIANT &arm_ext_v7
15353 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
15354 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
15355
15356 #undef ARM_VARIANT
15357 #define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
15358 cCE(wfs, e200110, 1, (RR), rd),
15359 cCE(rfs, e300110, 1, (RR), rd),
15360 cCE(wfc, e400110, 1, (RR), rd),
15361 cCE(rfc, e500110, 1, (RR), rd),
15362
15363 cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
15364 cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
15365 cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
15366 cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
15367
15368 cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
15369 cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
15370 cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
15371 cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
15372
15373 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
15374 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
15375 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
15376 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
15377 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
15378 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
15379 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
15380 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
15381 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
15382 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
15383 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
15384 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
15385
15386 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
15387 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
15388 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
15389 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
15390 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
15391 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
15392 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
15393 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
15394 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
15395 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
15396 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
15397 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
15398
15399 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
15400 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
15401 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
15402 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
15403 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
15404 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
15405 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
15406 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
15407 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
15408 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
15409 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
15410 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
15411
15412 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
15413 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
15414 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
15415 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
15416 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
15417 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
15418 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
15419 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
15420 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
15421 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
15422 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
15423 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
15424
15425 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
15426 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
15427 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
15428 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
15429 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
15430 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
15431 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
15432 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
15433 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
15434 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
15435 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
15436 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
15437
15438 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
15439 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
15440 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
15441 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
15442 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
15443 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
15444 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
15445 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
15446 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
15447 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
15448 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
15449 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
15450
15451 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
15452 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
15453 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
15454 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
15455 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
15456 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
15457 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
15458 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
15459 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
15460 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
15461 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
15462 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
15463
15464 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
15465 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
15466 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
15467 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
15468 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
15469 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
15470 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
15471 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
15472 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
15473 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
15474 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
15475 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
15476
15477 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
15478 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
15479 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
15480 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
15481 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
15482 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
15483 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
15484 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
15485 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
15486 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
15487 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
15488 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
15489
15490 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
15491 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
15492 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
15493 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
15494 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
15495 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
15496 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
15497 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
15498 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
15499 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
15500 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
15501 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
15502
15503 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
15504 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
15505 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
15506 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
15507 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
15508 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
15509 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
15510 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
15511 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
15512 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
15513 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
15514 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
15515
15516 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
15517 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
15518 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
15519 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
15520 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
15521 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
15522 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
15523 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
15524 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
15525 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
15526 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
15527 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
15528
15529 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
15530 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
15531 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
15532 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
15533 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
15534 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
15535 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
15536 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
15537 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
15538 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
15539 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
15540 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
15541
15542 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
15543 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
15544 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
15545 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
15546 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
15547 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
15548 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
15549 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
15550 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
15551 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
15552 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
15553 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
15554
15555 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
15556 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
15557 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
15558 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
15559 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
15560 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
15561 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
15562 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
15563 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
15564 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
15565 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
15566 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
15567
15568 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
15569 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
15570 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
15571 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
15572 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
15573 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
15574 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
15575 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
15576 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
15577 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
15578 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
15579 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
15580
15581 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
15582 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
15583 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
15584 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
15585 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
15586 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15587 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15588 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15589 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
15590 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
15591 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
15592 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
15593
15594 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
15595 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
15596 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
15597 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
15598 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
15599 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15600 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15601 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15602 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
15603 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
15604 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
15605 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
15606
15607 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
15608 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
15609 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
15610 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
15611 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
15612 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15613 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15614 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15615 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
15616 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
15617 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
15618 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
15619
15620 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
15621 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
15622 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
15623 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
15624 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
15625 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15626 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15627 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15628 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
15629 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
15630 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
15631 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
15632
15633 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
15634 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
15635 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
15636 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
15637 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
15638 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15639 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15640 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15641 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
15642 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
15643 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
15644 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
15645
15646 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
15647 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
15648 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
15649 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
15650 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
15651 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15652 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15653 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15654 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
15655 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
15656 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
15657 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
15658
15659 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
15660 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
15661 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
15662 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
15663 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
15664 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15665 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15666 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15667 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
15668 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
15669 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
15670 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
15671
15672 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
15673 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
15674 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
15675 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
15676 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
15677 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15678 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15679 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15680 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
15681 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
15682 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
15683 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
15684
15685 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
15686 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
15687 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
15688 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
15689 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
15690 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15691 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15692 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15693 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
15694 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
15695 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
15696 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
15697
15698 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
15699 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
15700 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
15701 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
15702 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
15703 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15704 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15705 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15706 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
15707 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
15708 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
15709 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
15710
15711 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15712 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15713 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15714 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15715 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15716 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15717 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15718 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15719 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15720 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15721 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15722 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15723
15724 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15725 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15726 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15727 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15728 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15729 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15730 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15731 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15732 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15733 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15734 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15735 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15736
15737 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15738 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15739 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15740 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15741 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15742 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15743 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15744 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15745 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15746 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15747 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15748 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15749
15750 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
15751 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
15752 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
15753 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
15754
15755 cCL(flts, e000110, 2, (RF, RR), rn_rd),
15756 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
15757 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
15758 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
15759 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
15760 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
15761 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
15762 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
15763 cCL(flte, e080110, 2, (RF, RR), rn_rd),
15764 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
15765 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
15766 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
15767
15768 /* The implementation of the FIX instruction is broken on some
15769 assemblers, in that it accepts a precision specifier as well as a
15770 rounding specifier, despite the fact that this is meaningless.
15771 To be more compatible, we accept it as well, though of course it
15772 does not set any bits. */
15773 cCE(fix, e100110, 2, (RR, RF), rd_rm),
15774 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
15775 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
15776 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
15777 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
15778 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
15779 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
15780 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
15781 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
15782 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
15783 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
15784 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
15785 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
15786
15787 /* Instructions that were new with the real FPA, call them V2. */
15788 #undef ARM_VARIANT
15789 #define ARM_VARIANT &fpu_fpa_ext_v2
15790 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15791 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15792 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15793 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15794 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15795 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15796
15797 #undef ARM_VARIANT
15798 #define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
15799 /* Moves and type conversions. */
15800 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
15801 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
15802 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
15803 cCE(fmstat, ef1fa10, 0, (), noargs),
15804 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
15805 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
15806 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
15807 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15808 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
15809 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15810 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
15811 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
15812
15813 /* Memory operations. */
15814 cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15815 cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15816 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15817 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15818 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15819 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15820 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15821 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15822 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15823 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15824 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15825 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15826 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15827 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15828 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15829 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15830 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15831 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15832
15833 /* Monadic operations. */
15834 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
15835 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
15836 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
15837
15838 /* Dyadic operations. */
15839 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15840 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15841 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15842 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15843 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15844 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15845 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15846 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15847 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15848
15849 /* Comparisons. */
15850 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
15851 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
15852 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
15853 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
15854
15855 #undef ARM_VARIANT
15856 #define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
15857 /* Moves and type conversions. */
15858 cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15859 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15860 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15861 cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
15862 cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
15863 cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
15864 cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
15865 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15866 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
15867 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15868 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15869 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15870 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15871
15872 /* Memory operations. */
15873 cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
15874 cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
15875 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15876 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15877 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15878 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15879 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15880 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15881 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15882 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15883
15884 /* Monadic operations. */
15885 cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15886 cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15887 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15888
15889 /* Dyadic operations. */
15890 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15891 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15892 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15893 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15894 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15895 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15896 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15897 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15898 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15899
15900 /* Comparisons. */
15901 cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15902 cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd),
15903 cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15904 cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd),
15905
15906 #undef ARM_VARIANT
15907 #define ARM_VARIANT &fpu_vfp_ext_v2
15908 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
15909 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
15910 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
15911 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
15912
15913 /* Instructions which may belong to either the Neon or VFP instruction sets.
15914 Individual encoder functions perform additional architecture checks. */
15915 #undef ARM_VARIANT
15916 #define ARM_VARIANT &fpu_vfp_ext_v1xd
15917 #undef THUMB_VARIANT
15918 #define THUMB_VARIANT &fpu_vfp_ext_v1xd
15919 /* These mnemonics are unique to VFP. */
15920 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
15921 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
15922 nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15923 nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15924 nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15925 nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15926 nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15927 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
15928 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
15929 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
15930
15931 /* Mnemonics shared by Neon and VFP. */
15932 nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
15933 nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15934 nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15935
15936 nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15937 nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15938
15939 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15940 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15941
15942 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15943 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15944 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15945 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15946 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15947 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15948 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
15949 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
15950
15951 nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
15952
15953 /* NOTE: All VMOV encoding is special-cased! */
15954 NCE(vmov, 0, 1, (VMOV), neon_mov),
15955 NCE(vmovq, 0, 1, (VMOV), neon_mov),
15956
15957 #undef THUMB_VARIANT
15958 #define THUMB_VARIANT &fpu_neon_ext_v1
15959 #undef ARM_VARIANT
15960 #define ARM_VARIANT &fpu_neon_ext_v1
15961 /* Data processing with three registers of the same length. */
15962 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
15963 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
15964 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
15965 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15966 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15967 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15968 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15969 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15970 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15971 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
15972 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15973 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15974 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15975 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15976 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15977 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
15978 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15979 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
15980 /* If not immediate, fall back to neon_dyadic_i64_su.
15981 shl_imm should accept I8 I16 I32 I64,
15982 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
15983 nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
15984 nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
15985 nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
15986 nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
15987 /* Logic ops, types optional & ignored. */
15988 nUF(vand, vand, 2, (RNDQ, NILO), neon_logic),
15989 nUF(vandq, vand, 2, (RNQ, NILO), neon_logic),
15990 nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic),
15991 nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic),
15992 nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic),
15993 nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic),
15994 nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic),
15995 nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic),
15996 nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
15997 nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
15998 /* Bitfield ops, untyped. */
15999 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
16000 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
16001 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
16002 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
16003 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
16004 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
16005 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
16006 nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
16007 nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
16008 nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
16009 nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
16010 nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
16011 nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
16012 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
16013 back to neon_dyadic_if_su. */
16014 nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
16015 nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
16016 nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
16017 nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
16018 nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16019 nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
16020 nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16021 nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
16022 /* Comparison. Type I8 I16 I32 F32. */
16023 nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
16024 nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
16025 /* As above, D registers only. */
16026 nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16027 nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16028 /* Int and float variants, signedness unimportant. */
16029 nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
16030 nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
16031 nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
16032 /* Add/sub take types I8 I16 I32 I64 F32. */
16033 nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
16034 nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
16035 /* vtst takes sizes 8, 16, 32. */
16036 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
16037 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
16038 /* VMUL takes I8 I16 I32 F32 P8. */
16039 nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
16040 /* VQD{R}MULH takes S16 S32. */
16041 nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16042 nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16043 nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16044 nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16045 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16046 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
16047 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16048 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
16049 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16050 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
16051 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16052 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
16053 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16054 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16055 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16056 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16057
16058 /* Two address, int/float. Types S8 S16 S32 F32. */
16059 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
16060 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
16061
16062 /* Data processing with two registers and a shift amount. */
16063 /* Right shifts, and variants with rounding.
16064 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
16065 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16066 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16067 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16068 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16069 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16070 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16071 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16072 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16073 /* Shift and insert. Sizes accepted 8 16 32 64. */
16074 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
16075 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
16076 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
16077 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
16078 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
16079 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
16080 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
16081 /* Right shift immediate, saturating & narrowing, with rounding variants.
16082 Types accepted S16 S32 S64 U16 U32 U64. */
16083 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16084 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16085 /* As above, unsigned. Types accepted S16 S32 S64. */
16086 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16087 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16088 /* Right shift narrowing. Types accepted I16 I32 I64. */
16089 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16090 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16091 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
16092 nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll),
16093 /* CVT with optional immediate for fixed-point variant. */
16094 nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
16095
16096 nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
16097 nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
16098
16099 /* Data processing, three registers of different lengths. */
16100 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
16101 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
16102 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
16103 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
16104 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
16105 /* If not scalar, fall back to neon_dyadic_long.
16106 Vector types as above, scalar types S16 S32 U16 U32. */
16107 nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16108 nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16109 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
16110 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16111 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16112 /* Dyadic, narrowing insns. Types I16 I32 I64. */
16113 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16114 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16115 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16116 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16117 /* Saturating doubling multiplies. Types S16 S32. */
16118 nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16119 nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16120 nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16121 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
16122 S16 S32 U16 U32. */
16123 nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
16124
16125 /* Extract. Size 8. */
16126 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
16127 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
16128
16129 /* Two registers, miscellaneous. */
16130 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
16131 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
16132 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
16133 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
16134 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
16135 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
16136 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
16137 /* Vector replicate. Sizes 8 16 32. */
16138 nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup),
16139 nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup),
16140 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
16141 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
16142 /* VMOVN. Types I16 I32 I64. */
16143 nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn),
16144 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
16145 nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn),
16146 /* VQMOVUN. Types S16 S32 S64. */
16147 nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun),
16148 /* VZIP / VUZP. Sizes 8 16 32. */
16149 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
16150 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
16151 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
16152 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
16153 /* VQABS / VQNEG. Types S8 S16 S32. */
16154 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16155 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
16156 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16157 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
16158 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
16159 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
16160 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
16161 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
16162 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
16163 /* Reciprocal estimates. Types U32 F32. */
16164 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
16165 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
16166 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
16167 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
16168 /* VCLS. Types S8 S16 S32. */
16169 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
16170 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
16171 /* VCLZ. Types I8 I16 I32. */
16172 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
16173 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
16174 /* VCNT. Size 8. */
16175 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
16176 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
16177 /* Two address, untyped. */
16178 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
16179 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
16180 /* VTRN. Sizes 8 16 32. */
16181 nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn),
16182 nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn),
16183
16184 /* Table lookup. Size 8. */
16185 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16186 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16187
16188 #undef THUMB_VARIANT
16189 #define THUMB_VARIANT &fpu_vfp_v3_or_neon_ext
16190 #undef ARM_VARIANT
16191 #define ARM_VARIANT &fpu_vfp_v3_or_neon_ext
16192 /* Neon element/structure load/store. */
16193 nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16194 nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16195 nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16196 nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16197 nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16198 nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16199 nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16200 nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16201
16202 #undef THUMB_VARIANT
16203 #define THUMB_VARIANT &fpu_vfp_ext_v3
16204 #undef ARM_VARIANT
16205 #define ARM_VARIANT &fpu_vfp_ext_v3
16206 cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const),
16207 cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const),
16208 cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16209 cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16210 cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16211 cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16212 cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16213 cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16214 cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16215 cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16216 cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16217 cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16218 cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16219 cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16220 cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16221 cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16222 cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16223 cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16224
16225 #undef THUMB_VARIANT
16226 #undef ARM_VARIANT
16227 #define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
16228 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16229 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16230 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16231 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16232 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16233 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16234 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
16235 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
16236
16237 #undef ARM_VARIANT
16238 #define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
16239 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
16240 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
16241 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
16242 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
16243 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
16244 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
16245 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
16246 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
16247 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
16248 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16249 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16250 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16251 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16252 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16253 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16254 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16255 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16256 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16257 cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd),
16258 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
16259 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16260 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16261 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16262 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16263 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16264 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16265 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
16266 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
16267 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
16268 cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn),
16269 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
16270 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
16271 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
16272 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
16273 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
16274 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
16275 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
16276 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16277 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16278 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16279 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16280 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16281 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16282 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16283 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16284 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16285 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
16286 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16287 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16288 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16289 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16290 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16291 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16292 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16293 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16294 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16295 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16296 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16297 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16298 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16299 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16300 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16301 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16302 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16303 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16304 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16305 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16306 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16307 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16308 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16309 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16310 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16311 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16312 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16313 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16314 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16315 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16316 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16317 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16318 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16319 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16320 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16321 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16322 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16323 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16324 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16325 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16326 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16327 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
16328 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16329 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16330 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16331 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16332 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16333 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16334 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16335 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16336 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16337 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16338 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16339 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16340 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16341 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16342 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16343 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16344 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16345 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16346 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16347 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16348 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16349 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
16350 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16351 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16352 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16353 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16354 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16355 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16356 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16357 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16358 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16359 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16360 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16361 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16362 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16363 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16364 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16365 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16366 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16367 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16368 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16369 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16370 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16371 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16372 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16373 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16374 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16375 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16376 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16377 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16378 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16379 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16380 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16381 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
16382 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
16383 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
16384 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
16385 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
16386 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
16387 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16388 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16389 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16390 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
16391 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
16392 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
16393 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
16394 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
16395 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
16396 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16397 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16398 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16399 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16400 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
16401
16402 #undef ARM_VARIANT
16403 #define ARM_VARIANT &arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
16404 cCE(torvscb, e13f190, 1, (RR), iwmmxt_tandorc),
16405 cCE(torvsch, e53f190, 1, (RR), iwmmxt_tandorc),
16406 cCE(torvscw, e93f190, 1, (RR), iwmmxt_tandorc),
16407 cCE(wabsb, e2001c0, 2, (RIWR, RIWR), rd_rn),
16408 cCE(wabsh, e6001c0, 2, (RIWR, RIWR), rd_rn),
16409 cCE(wabsw, ea001c0, 2, (RIWR, RIWR), rd_rn),
16410 cCE(wabsdiffb, e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16411 cCE(wabsdiffh, e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16412 cCE(wabsdiffw, e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16413 cCE(waddbhusl, e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16414 cCE(waddbhusm, e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16415 cCE(waddhc, e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16416 cCE(waddwc, ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16417 cCE(waddsubhx, ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16418 cCE(wavg4, e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16419 cCE(wavg4r, e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16420 cCE(wmaddsn, ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16421 cCE(wmaddsx, eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16422 cCE(wmaddun, ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16423 cCE(wmaddux, e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16424 cCE(wmerge, e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
16425 cCE(wmiabb, e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16426 cCE(wmiabt, e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16427 cCE(wmiatb, e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16428 cCE(wmiatt, e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16429 cCE(wmiabbn, e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16430 cCE(wmiabtn, e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16431 cCE(wmiatbn, e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16432 cCE(wmiattn, e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16433 cCE(wmiawbb, e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16434 cCE(wmiawbt, e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16435 cCE(wmiawtb, ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16436 cCE(wmiawtt, eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16437 cCE(wmiawbbn, ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16438 cCE(wmiawbtn, ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16439 cCE(wmiawtbn, ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16440 cCE(wmiawttn, ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16441 cCE(wmulsmr, ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16442 cCE(wmulumr, ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16443 cCE(wmulwumr, ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16444 cCE(wmulwsmr, ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16445 cCE(wmulwum, ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16446 cCE(wmulwsm, ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16447 cCE(wmulwl, eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16448 cCE(wqmiabb, e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16449 cCE(wqmiabt, e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16450 cCE(wqmiatb, ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16451 cCE(wqmiatt, eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16452 cCE(wqmiabbn, ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16453 cCE(wqmiabtn, ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16454 cCE(wqmiatbn, ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16455 cCE(wqmiattn, ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16456 cCE(wqmulm, e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16457 cCE(wqmulmr, e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16458 cCE(wqmulwm, ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16459 cCE(wqmulwmr, ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16460 cCE(wsubaddhx, ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16461
16462 #undef ARM_VARIANT
16463 #define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
16464 cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16465 cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16466 cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16467 cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
16468 cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16469 cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16470 cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16471 cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
16472 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
16473 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
16474 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
16475 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
16476 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
16477 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
16478 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
16479 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
16480 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
16481 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
16482 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
16483 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
16484 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
16485 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
16486 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
16487 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
16488 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
16489 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
16490 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
16491 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
16492 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
16493 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
16494 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
16495 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
16496 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
16497 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
16498 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
16499 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
16500 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
16501 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
16502 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
16503 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
16504 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
16505 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
16506 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
16507 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
16508 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
16509 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
16510 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
16511 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
16512 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
16513 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
16514 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
16515 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
16516 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
16517 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
16518 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
16519 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
16520 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
16521 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
16522 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
16523 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
16524 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
16525 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
16526 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
16527 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
16528 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16529 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16530 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16531 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16532 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16533 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16534 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16535 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16536 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16537 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16538 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
16539 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
16540 };
16541 #undef ARM_VARIANT
16542 #undef THUMB_VARIANT
16543 #undef TCE
16544 #undef TCM
16545 #undef TUE
16546 #undef TUF
16547 #undef TCC
16548 #undef cCE
16549 #undef cCL
16550 #undef C3E
16551 #undef CE
16552 #undef CM
16553 #undef UE
16554 #undef UF
16555 #undef UT
16556 #undef NUF
16557 #undef nUF
16558 #undef NCE
16559 #undef nCE
16560 #undef OPS0
16561 #undef OPS1
16562 #undef OPS2
16563 #undef OPS3
16564 #undef OPS4
16565 #undef OPS5
16566 #undef OPS6
16567 #undef do_0
16568 \f
16569 /* MD interface: bits in the object file. */
16570
16571 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
16572 for use in the a.out file, and stores them in the array pointed to by buf.
16573 This knows about the endian-ness of the target machine and does
16574 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
16575 2 (short) and 4 (long) Floating numbers are put out as a series of
16576 LITTLENUMS (shorts, here at least). */
16577
16578 void
16579 md_number_to_chars (char * buf, valueT val, int n)
16580 {
16581 if (target_big_endian)
16582 number_to_chars_bigendian (buf, val, n);
16583 else
16584 number_to_chars_littleendian (buf, val, n);
16585 }
16586
16587 static valueT
16588 md_chars_to_number (char * buf, int n)
16589 {
16590 valueT result = 0;
16591 unsigned char * where = (unsigned char *) buf;
16592
16593 if (target_big_endian)
16594 {
16595 while (n--)
16596 {
16597 result <<= 8;
16598 result |= (*where++ & 255);
16599 }
16600 }
16601 else
16602 {
16603 while (n--)
16604 {
16605 result <<= 8;
16606 result |= (where[n] & 255);
16607 }
16608 }
16609
16610 return result;
16611 }
16612
16613 /* MD interface: Sections. */
16614
16615 /* Estimate the size of a frag before relaxing. Assume everything fits in
16616 2 bytes. */
16617
16618 int
16619 md_estimate_size_before_relax (fragS * fragp,
16620 segT segtype ATTRIBUTE_UNUSED)
16621 {
16622 fragp->fr_var = 2;
16623 return 2;
16624 }
16625
16626 /* Convert a machine dependent frag. */
16627
16628 void
16629 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
16630 {
16631 unsigned long insn;
16632 unsigned long old_op;
16633 char *buf;
16634 expressionS exp;
16635 fixS *fixp;
16636 int reloc_type;
16637 int pc_rel;
16638 int opcode;
16639
16640 buf = fragp->fr_literal + fragp->fr_fix;
16641
16642 old_op = bfd_get_16(abfd, buf);
16643 if (fragp->fr_symbol)
16644 {
16645 exp.X_op = O_symbol;
16646 exp.X_add_symbol = fragp->fr_symbol;
16647 }
16648 else
16649 {
16650 exp.X_op = O_constant;
16651 }
16652 exp.X_add_number = fragp->fr_offset;
16653 opcode = fragp->fr_subtype;
16654 switch (opcode)
16655 {
16656 case T_MNEM_ldr_pc:
16657 case T_MNEM_ldr_pc2:
16658 case T_MNEM_ldr_sp:
16659 case T_MNEM_str_sp:
16660 case T_MNEM_ldr:
16661 case T_MNEM_ldrb:
16662 case T_MNEM_ldrh:
16663 case T_MNEM_str:
16664 case T_MNEM_strb:
16665 case T_MNEM_strh:
16666 if (fragp->fr_var == 4)
16667 {
16668 insn = THUMB_OP32 (opcode);
16669 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
16670 {
16671 insn |= (old_op & 0x700) << 4;
16672 }
16673 else
16674 {
16675 insn |= (old_op & 7) << 12;
16676 insn |= (old_op & 0x38) << 13;
16677 }
16678 insn |= 0x00000c00;
16679 put_thumb32_insn (buf, insn);
16680 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
16681 }
16682 else
16683 {
16684 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
16685 }
16686 pc_rel = (opcode == T_MNEM_ldr_pc2);
16687 break;
16688 case T_MNEM_adr:
16689 if (fragp->fr_var == 4)
16690 {
16691 insn = THUMB_OP32 (opcode);
16692 insn |= (old_op & 0xf0) << 4;
16693 put_thumb32_insn (buf, insn);
16694 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
16695 }
16696 else
16697 {
16698 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16699 exp.X_add_number -= 4;
16700 }
16701 pc_rel = 1;
16702 break;
16703 case T_MNEM_mov:
16704 case T_MNEM_movs:
16705 case T_MNEM_cmp:
16706 case T_MNEM_cmn:
16707 if (fragp->fr_var == 4)
16708 {
16709 int r0off = (opcode == T_MNEM_mov
16710 || opcode == T_MNEM_movs) ? 0 : 8;
16711 insn = THUMB_OP32 (opcode);
16712 insn = (insn & 0xe1ffffff) | 0x10000000;
16713 insn |= (old_op & 0x700) << r0off;
16714 put_thumb32_insn (buf, insn);
16715 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16716 }
16717 else
16718 {
16719 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
16720 }
16721 pc_rel = 0;
16722 break;
16723 case T_MNEM_b:
16724 if (fragp->fr_var == 4)
16725 {
16726 insn = THUMB_OP32(opcode);
16727 put_thumb32_insn (buf, insn);
16728 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
16729 }
16730 else
16731 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
16732 pc_rel = 1;
16733 break;
16734 case T_MNEM_bcond:
16735 if (fragp->fr_var == 4)
16736 {
16737 insn = THUMB_OP32(opcode);
16738 insn |= (old_op & 0xf00) << 14;
16739 put_thumb32_insn (buf, insn);
16740 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
16741 }
16742 else
16743 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
16744 pc_rel = 1;
16745 break;
16746 case T_MNEM_add_sp:
16747 case T_MNEM_add_pc:
16748 case T_MNEM_inc_sp:
16749 case T_MNEM_dec_sp:
16750 if (fragp->fr_var == 4)
16751 {
16752 /* ??? Choose between add and addw. */
16753 insn = THUMB_OP32 (opcode);
16754 insn |= (old_op & 0xf0) << 4;
16755 put_thumb32_insn (buf, insn);
16756 if (opcode == T_MNEM_add_pc)
16757 reloc_type = BFD_RELOC_ARM_T32_IMM12;
16758 else
16759 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16760 }
16761 else
16762 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16763 pc_rel = 0;
16764 break;
16765
16766 case T_MNEM_addi:
16767 case T_MNEM_addis:
16768 case T_MNEM_subi:
16769 case T_MNEM_subis:
16770 if (fragp->fr_var == 4)
16771 {
16772 insn = THUMB_OP32 (opcode);
16773 insn |= (old_op & 0xf0) << 4;
16774 insn |= (old_op & 0xf) << 16;
16775 put_thumb32_insn (buf, insn);
16776 if (insn & (1 << 20))
16777 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16778 else
16779 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16780 }
16781 else
16782 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16783 pc_rel = 0;
16784 break;
16785 default:
16786 abort ();
16787 }
16788 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
16789 reloc_type);
16790 fixp->fx_file = fragp->fr_file;
16791 fixp->fx_line = fragp->fr_line;
16792 fragp->fr_fix += fragp->fr_var;
16793 }
16794
16795 /* Return the size of a relaxable immediate operand instruction.
16796 SHIFT and SIZE specify the form of the allowable immediate. */
16797 static int
16798 relax_immediate (fragS *fragp, int size, int shift)
16799 {
16800 offsetT offset;
16801 offsetT mask;
16802 offsetT low;
16803
16804 /* ??? Should be able to do better than this. */
16805 if (fragp->fr_symbol)
16806 return 4;
16807
16808 low = (1 << shift) - 1;
16809 mask = (1 << (shift + size)) - (1 << shift);
16810 offset = fragp->fr_offset;
16811 /* Force misaligned offsets to 32-bit variant. */
16812 if (offset & low)
16813 return 4;
16814 if (offset & ~mask)
16815 return 4;
16816 return 2;
16817 }
16818
16819 /* Get the address of a symbol during relaxation. */
16820 static addressT
16821 relaxed_symbol_addr (fragS *fragp, long stretch)
16822 {
16823 fragS *sym_frag;
16824 addressT addr;
16825 symbolS *sym;
16826
16827 sym = fragp->fr_symbol;
16828 sym_frag = symbol_get_frag (sym);
16829 know (S_GET_SEGMENT (sym) != absolute_section
16830 || sym_frag == &zero_address_frag);
16831 addr = S_GET_VALUE (sym) + fragp->fr_offset;
16832
16833 /* If frag has yet to be reached on this pass, assume it will
16834 move by STRETCH just as we did. If this is not so, it will
16835 be because some frag between grows, and that will force
16836 another pass. */
16837
16838 if (stretch != 0
16839 && sym_frag->relax_marker != fragp->relax_marker)
16840 {
16841 fragS *f;
16842
16843 /* Adjust stretch for any alignment frag. Note that if have
16844 been expanding the earlier code, the symbol may be
16845 defined in what appears to be an earlier frag. FIXME:
16846 This doesn't handle the fr_subtype field, which specifies
16847 a maximum number of bytes to skip when doing an
16848 alignment. */
16849 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
16850 {
16851 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
16852 {
16853 if (stretch < 0)
16854 stretch = - ((- stretch)
16855 & ~ ((1 << (int) f->fr_offset) - 1));
16856 else
16857 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
16858 if (stretch == 0)
16859 break;
16860 }
16861 }
16862 if (f != NULL)
16863 addr += stretch;
16864 }
16865
16866 return addr;
16867 }
16868
16869 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
16870 load. */
16871 static int
16872 relax_adr (fragS *fragp, asection *sec, long stretch)
16873 {
16874 addressT addr;
16875 offsetT val;
16876
16877 /* Assume worst case for symbols not known to be in the same section. */
16878 if (!S_IS_DEFINED (fragp->fr_symbol)
16879 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16880 return 4;
16881
16882 val = relaxed_symbol_addr (fragp, stretch);
16883 addr = fragp->fr_address + fragp->fr_fix;
16884 addr = (addr + 4) & ~3;
16885 /* Force misaligned targets to 32-bit variant. */
16886 if (val & 3)
16887 return 4;
16888 val -= addr;
16889 if (val < 0 || val > 1020)
16890 return 4;
16891 return 2;
16892 }
16893
16894 /* Return the size of a relaxable add/sub immediate instruction. */
16895 static int
16896 relax_addsub (fragS *fragp, asection *sec)
16897 {
16898 char *buf;
16899 int op;
16900
16901 buf = fragp->fr_literal + fragp->fr_fix;
16902 op = bfd_get_16(sec->owner, buf);
16903 if ((op & 0xf) == ((op >> 4) & 0xf))
16904 return relax_immediate (fragp, 8, 0);
16905 else
16906 return relax_immediate (fragp, 3, 0);
16907 }
16908
16909
16910 /* Return the size of a relaxable branch instruction. BITS is the
16911 size of the offset field in the narrow instruction. */
16912
16913 static int
16914 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
16915 {
16916 addressT addr;
16917 offsetT val;
16918 offsetT limit;
16919
16920 /* Assume worst case for symbols not known to be in the same section. */
16921 if (!S_IS_DEFINED (fragp->fr_symbol)
16922 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16923 return 4;
16924
16925 val = relaxed_symbol_addr (fragp, stretch);
16926 addr = fragp->fr_address + fragp->fr_fix + 4;
16927 val -= addr;
16928
16929 /* Offset is a signed value *2 */
16930 limit = 1 << bits;
16931 if (val >= limit || val < -limit)
16932 return 4;
16933 return 2;
16934 }
16935
16936
16937 /* Relax a machine dependent frag. This returns the amount by which
16938 the current size of the frag should change. */
16939
16940 int
16941 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
16942 {
16943 int oldsize;
16944 int newsize;
16945
16946 oldsize = fragp->fr_var;
16947 switch (fragp->fr_subtype)
16948 {
16949 case T_MNEM_ldr_pc2:
16950 newsize = relax_adr (fragp, sec, stretch);
16951 break;
16952 case T_MNEM_ldr_pc:
16953 case T_MNEM_ldr_sp:
16954 case T_MNEM_str_sp:
16955 newsize = relax_immediate (fragp, 8, 2);
16956 break;
16957 case T_MNEM_ldr:
16958 case T_MNEM_str:
16959 newsize = relax_immediate (fragp, 5, 2);
16960 break;
16961 case T_MNEM_ldrh:
16962 case T_MNEM_strh:
16963 newsize = relax_immediate (fragp, 5, 1);
16964 break;
16965 case T_MNEM_ldrb:
16966 case T_MNEM_strb:
16967 newsize = relax_immediate (fragp, 5, 0);
16968 break;
16969 case T_MNEM_adr:
16970 newsize = relax_adr (fragp, sec, stretch);
16971 break;
16972 case T_MNEM_mov:
16973 case T_MNEM_movs:
16974 case T_MNEM_cmp:
16975 case T_MNEM_cmn:
16976 newsize = relax_immediate (fragp, 8, 0);
16977 break;
16978 case T_MNEM_b:
16979 newsize = relax_branch (fragp, sec, 11, stretch);
16980 break;
16981 case T_MNEM_bcond:
16982 newsize = relax_branch (fragp, sec, 8, stretch);
16983 break;
16984 case T_MNEM_add_sp:
16985 case T_MNEM_add_pc:
16986 newsize = relax_immediate (fragp, 8, 2);
16987 break;
16988 case T_MNEM_inc_sp:
16989 case T_MNEM_dec_sp:
16990 newsize = relax_immediate (fragp, 7, 2);
16991 break;
16992 case T_MNEM_addi:
16993 case T_MNEM_addis:
16994 case T_MNEM_subi:
16995 case T_MNEM_subis:
16996 newsize = relax_addsub (fragp, sec);
16997 break;
16998 default:
16999 abort ();
17000 }
17001
17002 fragp->fr_var = newsize;
17003 /* Freeze wide instructions that are at or before the same location as
17004 in the previous pass. This avoids infinite loops.
17005 Don't freeze them unconditionally because targets may be artificially
17006 misaligned by the expansion of preceding frags. */
17007 if (stretch <= 0 && newsize > 2)
17008 {
17009 md_convert_frag (sec->owner, sec, fragp);
17010 frag_wane (fragp);
17011 }
17012
17013 return newsize - oldsize;
17014 }
17015
17016 /* Round up a section size to the appropriate boundary. */
17017
17018 valueT
17019 md_section_align (segT segment ATTRIBUTE_UNUSED,
17020 valueT size)
17021 {
17022 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
17023 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
17024 {
17025 /* For a.out, force the section size to be aligned. If we don't do
17026 this, BFD will align it for us, but it will not write out the
17027 final bytes of the section. This may be a bug in BFD, but it is
17028 easier to fix it here since that is how the other a.out targets
17029 work. */
17030 int align;
17031
17032 align = bfd_get_section_alignment (stdoutput, segment);
17033 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
17034 }
17035 #endif
17036
17037 return size;
17038 }
17039
17040 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
17041 of an rs_align_code fragment. */
17042
17043 void
17044 arm_handle_align (fragS * fragP)
17045 {
17046 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
17047 static char const thumb_noop[2] = { 0xc0, 0x46 };
17048 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
17049 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
17050
17051 int bytes, fix, noop_size;
17052 char * p;
17053 const char * noop;
17054
17055 if (fragP->fr_type != rs_align_code)
17056 return;
17057
17058 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
17059 p = fragP->fr_literal + fragP->fr_fix;
17060 fix = 0;
17061
17062 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
17063 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
17064
17065 if (fragP->tc_frag_data)
17066 {
17067 if (target_big_endian)
17068 noop = thumb_bigend_noop;
17069 else
17070 noop = thumb_noop;
17071 noop_size = sizeof (thumb_noop);
17072 }
17073 else
17074 {
17075 if (target_big_endian)
17076 noop = arm_bigend_noop;
17077 else
17078 noop = arm_noop;
17079 noop_size = sizeof (arm_noop);
17080 }
17081
17082 if (bytes & (noop_size - 1))
17083 {
17084 fix = bytes & (noop_size - 1);
17085 memset (p, 0, fix);
17086 p += fix;
17087 bytes -= fix;
17088 }
17089
17090 while (bytes >= noop_size)
17091 {
17092 memcpy (p, noop, noop_size);
17093 p += noop_size;
17094 bytes -= noop_size;
17095 fix += noop_size;
17096 }
17097
17098 fragP->fr_fix += fix;
17099 fragP->fr_var = noop_size;
17100 }
17101
17102 /* Called from md_do_align. Used to create an alignment
17103 frag in a code section. */
17104
17105 void
17106 arm_frag_align_code (int n, int max)
17107 {
17108 char * p;
17109
17110 /* We assume that there will never be a requirement
17111 to support alignments greater than 32 bytes. */
17112 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
17113 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
17114
17115 p = frag_var (rs_align_code,
17116 MAX_MEM_FOR_RS_ALIGN_CODE,
17117 1,
17118 (relax_substateT) max,
17119 (symbolS *) NULL,
17120 (offsetT) n,
17121 (char *) NULL);
17122 *p = 0;
17123 }
17124
17125 /* Perform target specific initialisation of a frag. */
17126
17127 void
17128 arm_init_frag (fragS * fragP)
17129 {
17130 /* Record whether this frag is in an ARM or a THUMB area. */
17131 fragP->tc_frag_data = thumb_mode;
17132 }
17133
17134 #ifdef OBJ_ELF
17135 /* When we change sections we need to issue a new mapping symbol. */
17136
17137 void
17138 arm_elf_change_section (void)
17139 {
17140 flagword flags;
17141 segment_info_type *seginfo;
17142
17143 /* Link an unlinked unwind index table section to the .text section. */
17144 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
17145 && elf_linked_to_section (now_seg) == NULL)
17146 elf_linked_to_section (now_seg) = text_section;
17147
17148 if (!SEG_NORMAL (now_seg))
17149 return;
17150
17151 flags = bfd_get_section_flags (stdoutput, now_seg);
17152
17153 /* We can ignore sections that only contain debug info. */
17154 if ((flags & SEC_ALLOC) == 0)
17155 return;
17156
17157 seginfo = seg_info (now_seg);
17158 mapstate = seginfo->tc_segment_info_data.mapstate;
17159 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
17160 }
17161
17162 int
17163 arm_elf_section_type (const char * str, size_t len)
17164 {
17165 if (len == 5 && strncmp (str, "exidx", 5) == 0)
17166 return SHT_ARM_EXIDX;
17167
17168 return -1;
17169 }
17170 \f
17171 /* Code to deal with unwinding tables. */
17172
17173 static void add_unwind_adjustsp (offsetT);
17174
17175 /* Generate any deferred unwind frame offset. */
17176
17177 static void
17178 flush_pending_unwind (void)
17179 {
17180 offsetT offset;
17181
17182 offset = unwind.pending_offset;
17183 unwind.pending_offset = 0;
17184 if (offset != 0)
17185 add_unwind_adjustsp (offset);
17186 }
17187
17188 /* Add an opcode to this list for this function. Two-byte opcodes should
17189 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
17190 order. */
17191
17192 static void
17193 add_unwind_opcode (valueT op, int length)
17194 {
17195 /* Add any deferred stack adjustment. */
17196 if (unwind.pending_offset)
17197 flush_pending_unwind ();
17198
17199 unwind.sp_restored = 0;
17200
17201 if (unwind.opcode_count + length > unwind.opcode_alloc)
17202 {
17203 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
17204 if (unwind.opcodes)
17205 unwind.opcodes = xrealloc (unwind.opcodes,
17206 unwind.opcode_alloc);
17207 else
17208 unwind.opcodes = xmalloc (unwind.opcode_alloc);
17209 }
17210 while (length > 0)
17211 {
17212 length--;
17213 unwind.opcodes[unwind.opcode_count] = op & 0xff;
17214 op >>= 8;
17215 unwind.opcode_count++;
17216 }
17217 }
17218
17219 /* Add unwind opcodes to adjust the stack pointer. */
17220
17221 static void
17222 add_unwind_adjustsp (offsetT offset)
17223 {
17224 valueT op;
17225
17226 if (offset > 0x200)
17227 {
17228 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
17229 char bytes[5];
17230 int n;
17231 valueT o;
17232
17233 /* Long form: 0xb2, uleb128. */
17234 /* This might not fit in a word so add the individual bytes,
17235 remembering the list is built in reverse order. */
17236 o = (valueT) ((offset - 0x204) >> 2);
17237 if (o == 0)
17238 add_unwind_opcode (0, 1);
17239
17240 /* Calculate the uleb128 encoding of the offset. */
17241 n = 0;
17242 while (o)
17243 {
17244 bytes[n] = o & 0x7f;
17245 o >>= 7;
17246 if (o)
17247 bytes[n] |= 0x80;
17248 n++;
17249 }
17250 /* Add the insn. */
17251 for (; n; n--)
17252 add_unwind_opcode (bytes[n - 1], 1);
17253 add_unwind_opcode (0xb2, 1);
17254 }
17255 else if (offset > 0x100)
17256 {
17257 /* Two short opcodes. */
17258 add_unwind_opcode (0x3f, 1);
17259 op = (offset - 0x104) >> 2;
17260 add_unwind_opcode (op, 1);
17261 }
17262 else if (offset > 0)
17263 {
17264 /* Short opcode. */
17265 op = (offset - 4) >> 2;
17266 add_unwind_opcode (op, 1);
17267 }
17268 else if (offset < 0)
17269 {
17270 offset = -offset;
17271 while (offset > 0x100)
17272 {
17273 add_unwind_opcode (0x7f, 1);
17274 offset -= 0x100;
17275 }
17276 op = ((offset - 4) >> 2) | 0x40;
17277 add_unwind_opcode (op, 1);
17278 }
17279 }
17280
17281 /* Finish the list of unwind opcodes for this function. */
17282 static void
17283 finish_unwind_opcodes (void)
17284 {
17285 valueT op;
17286
17287 if (unwind.fp_used)
17288 {
17289 /* Adjust sp as necessary. */
17290 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
17291 flush_pending_unwind ();
17292
17293 /* After restoring sp from the frame pointer. */
17294 op = 0x90 | unwind.fp_reg;
17295 add_unwind_opcode (op, 1);
17296 }
17297 else
17298 flush_pending_unwind ();
17299 }
17300
17301
17302 /* Start an exception table entry. If idx is nonzero this is an index table
17303 entry. */
17304
17305 static void
17306 start_unwind_section (const segT text_seg, int idx)
17307 {
17308 const char * text_name;
17309 const char * prefix;
17310 const char * prefix_once;
17311 const char * group_name;
17312 size_t prefix_len;
17313 size_t text_len;
17314 char * sec_name;
17315 size_t sec_name_len;
17316 int type;
17317 int flags;
17318 int linkonce;
17319
17320 if (idx)
17321 {
17322 prefix = ELF_STRING_ARM_unwind;
17323 prefix_once = ELF_STRING_ARM_unwind_once;
17324 type = SHT_ARM_EXIDX;
17325 }
17326 else
17327 {
17328 prefix = ELF_STRING_ARM_unwind_info;
17329 prefix_once = ELF_STRING_ARM_unwind_info_once;
17330 type = SHT_PROGBITS;
17331 }
17332
17333 text_name = segment_name (text_seg);
17334 if (streq (text_name, ".text"))
17335 text_name = "";
17336
17337 if (strncmp (text_name, ".gnu.linkonce.t.",
17338 strlen (".gnu.linkonce.t.")) == 0)
17339 {
17340 prefix = prefix_once;
17341 text_name += strlen (".gnu.linkonce.t.");
17342 }
17343
17344 prefix_len = strlen (prefix);
17345 text_len = strlen (text_name);
17346 sec_name_len = prefix_len + text_len;
17347 sec_name = xmalloc (sec_name_len + 1);
17348 memcpy (sec_name, prefix, prefix_len);
17349 memcpy (sec_name + prefix_len, text_name, text_len);
17350 sec_name[prefix_len + text_len] = '\0';
17351
17352 flags = SHF_ALLOC;
17353 linkonce = 0;
17354 group_name = 0;
17355
17356 /* Handle COMDAT group. */
17357 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
17358 {
17359 group_name = elf_group_name (text_seg);
17360 if (group_name == NULL)
17361 {
17362 as_bad (_("Group section `%s' has no group signature"),
17363 segment_name (text_seg));
17364 ignore_rest_of_line ();
17365 return;
17366 }
17367 flags |= SHF_GROUP;
17368 linkonce = 1;
17369 }
17370
17371 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
17372
17373 /* Set the section link for index tables. */
17374 if (idx)
17375 elf_linked_to_section (now_seg) = text_seg;
17376 }
17377
17378
17379 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
17380 personality routine data. Returns zero, or the index table value for
17381 and inline entry. */
17382
17383 static valueT
17384 create_unwind_entry (int have_data)
17385 {
17386 int size;
17387 addressT where;
17388 char *ptr;
17389 /* The current word of data. */
17390 valueT data;
17391 /* The number of bytes left in this word. */
17392 int n;
17393
17394 finish_unwind_opcodes ();
17395
17396 /* Remember the current text section. */
17397 unwind.saved_seg = now_seg;
17398 unwind.saved_subseg = now_subseg;
17399
17400 start_unwind_section (now_seg, 0);
17401
17402 if (unwind.personality_routine == NULL)
17403 {
17404 if (unwind.personality_index == -2)
17405 {
17406 if (have_data)
17407 as_bad (_("handlerdata in cantunwind frame"));
17408 return 1; /* EXIDX_CANTUNWIND. */
17409 }
17410
17411 /* Use a default personality routine if none is specified. */
17412 if (unwind.personality_index == -1)
17413 {
17414 if (unwind.opcode_count > 3)
17415 unwind.personality_index = 1;
17416 else
17417 unwind.personality_index = 0;
17418 }
17419
17420 /* Space for the personality routine entry. */
17421 if (unwind.personality_index == 0)
17422 {
17423 if (unwind.opcode_count > 3)
17424 as_bad (_("too many unwind opcodes for personality routine 0"));
17425
17426 if (!have_data)
17427 {
17428 /* All the data is inline in the index table. */
17429 data = 0x80;
17430 n = 3;
17431 while (unwind.opcode_count > 0)
17432 {
17433 unwind.opcode_count--;
17434 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17435 n--;
17436 }
17437
17438 /* Pad with "finish" opcodes. */
17439 while (n--)
17440 data = (data << 8) | 0xb0;
17441
17442 return data;
17443 }
17444 size = 0;
17445 }
17446 else
17447 /* We get two opcodes "free" in the first word. */
17448 size = unwind.opcode_count - 2;
17449 }
17450 else
17451 /* An extra byte is required for the opcode count. */
17452 size = unwind.opcode_count + 1;
17453
17454 size = (size + 3) >> 2;
17455 if (size > 0xff)
17456 as_bad (_("too many unwind opcodes"));
17457
17458 frag_align (2, 0, 0);
17459 record_alignment (now_seg, 2);
17460 unwind.table_entry = expr_build_dot ();
17461
17462 /* Allocate the table entry. */
17463 ptr = frag_more ((size << 2) + 4);
17464 where = frag_now_fix () - ((size << 2) + 4);
17465
17466 switch (unwind.personality_index)
17467 {
17468 case -1:
17469 /* ??? Should this be a PLT generating relocation? */
17470 /* Custom personality routine. */
17471 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
17472 BFD_RELOC_ARM_PREL31);
17473
17474 where += 4;
17475 ptr += 4;
17476
17477 /* Set the first byte to the number of additional words. */
17478 data = size - 1;
17479 n = 3;
17480 break;
17481
17482 /* ABI defined personality routines. */
17483 case 0:
17484 /* Three opcodes bytes are packed into the first word. */
17485 data = 0x80;
17486 n = 3;
17487 break;
17488
17489 case 1:
17490 case 2:
17491 /* The size and first two opcode bytes go in the first word. */
17492 data = ((0x80 + unwind.personality_index) << 8) | size;
17493 n = 2;
17494 break;
17495
17496 default:
17497 /* Should never happen. */
17498 abort ();
17499 }
17500
17501 /* Pack the opcodes into words (MSB first), reversing the list at the same
17502 time. */
17503 while (unwind.opcode_count > 0)
17504 {
17505 if (n == 0)
17506 {
17507 md_number_to_chars (ptr, data, 4);
17508 ptr += 4;
17509 n = 4;
17510 data = 0;
17511 }
17512 unwind.opcode_count--;
17513 n--;
17514 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17515 }
17516
17517 /* Finish off the last word. */
17518 if (n < 4)
17519 {
17520 /* Pad with "finish" opcodes. */
17521 while (n--)
17522 data = (data << 8) | 0xb0;
17523
17524 md_number_to_chars (ptr, data, 4);
17525 }
17526
17527 if (!have_data)
17528 {
17529 /* Add an empty descriptor if there is no user-specified data. */
17530 ptr = frag_more (4);
17531 md_number_to_chars (ptr, 0, 4);
17532 }
17533
17534 return 0;
17535 }
17536
17537
17538 /* Initialize the DWARF-2 unwind information for this procedure. */
17539
17540 void
17541 tc_arm_frame_initial_instructions (void)
17542 {
17543 cfi_add_CFA_def_cfa (REG_SP, 0);
17544 }
17545 #endif /* OBJ_ELF */
17546
17547 /* Convert REGNAME to a DWARF-2 register number. */
17548
17549 int
17550 tc_arm_regname_to_dw2regnum (char *regname)
17551 {
17552 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
17553
17554 if (reg == FAIL)
17555 return -1;
17556
17557 return reg;
17558 }
17559
17560 #ifdef TE_PE
17561 void
17562 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
17563 {
17564 expressionS expr;
17565
17566 expr.X_op = O_secrel;
17567 expr.X_add_symbol = symbol;
17568 expr.X_add_number = 0;
17569 emit_expr (&expr, size);
17570 }
17571 #endif
17572
17573 /* MD interface: Symbol and relocation handling. */
17574
17575 /* Return the address within the segment that a PC-relative fixup is
17576 relative to. For ARM, PC-relative fixups applied to instructions
17577 are generally relative to the location of the fixup plus 8 bytes.
17578 Thumb branches are offset by 4, and Thumb loads relative to PC
17579 require special handling. */
17580
17581 long
17582 md_pcrel_from_section (fixS * fixP, segT seg)
17583 {
17584 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
17585
17586 /* If this is pc-relative and we are going to emit a relocation
17587 then we just want to put out any pipeline compensation that the linker
17588 will need. Otherwise we want to use the calculated base.
17589 For WinCE we skip the bias for externals as well, since this
17590 is how the MS ARM-CE assembler behaves and we want to be compatible. */
17591 if (fixP->fx_pcrel
17592 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
17593 || (arm_force_relocation (fixP)
17594 #ifdef TE_WINCE
17595 && !S_IS_EXTERNAL (fixP->fx_addsy)
17596 #endif
17597 )))
17598 base = 0;
17599
17600 switch (fixP->fx_r_type)
17601 {
17602 /* PC relative addressing on the Thumb is slightly odd as the
17603 bottom two bits of the PC are forced to zero for the
17604 calculation. This happens *after* application of the
17605 pipeline offset. However, Thumb adrl already adjusts for
17606 this, so we need not do it again. */
17607 case BFD_RELOC_ARM_THUMB_ADD:
17608 return base & ~3;
17609
17610 case BFD_RELOC_ARM_THUMB_OFFSET:
17611 case BFD_RELOC_ARM_T32_OFFSET_IMM:
17612 case BFD_RELOC_ARM_T32_ADD_PC12:
17613 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
17614 return (base + 4) & ~3;
17615
17616 /* Thumb branches are simply offset by +4. */
17617 case BFD_RELOC_THUMB_PCREL_BRANCH7:
17618 case BFD_RELOC_THUMB_PCREL_BRANCH9:
17619 case BFD_RELOC_THUMB_PCREL_BRANCH12:
17620 case BFD_RELOC_THUMB_PCREL_BRANCH20:
17621 case BFD_RELOC_THUMB_PCREL_BRANCH23:
17622 case BFD_RELOC_THUMB_PCREL_BRANCH25:
17623 case BFD_RELOC_THUMB_PCREL_BLX:
17624 return base + 4;
17625
17626 /* ARM mode branches are offset by +8. However, the Windows CE
17627 loader expects the relocation not to take this into account. */
17628 case BFD_RELOC_ARM_PCREL_BRANCH:
17629 case BFD_RELOC_ARM_PCREL_CALL:
17630 case BFD_RELOC_ARM_PCREL_JUMP:
17631 case BFD_RELOC_ARM_PCREL_BLX:
17632 case BFD_RELOC_ARM_PLT32:
17633 #ifdef TE_WINCE
17634 /* When handling fixups immediately, because we have already
17635 discovered the value of a symbol, or the address of the frag involved
17636 we must account for the offset by +8, as the OS loader will never see the reloc.
17637 see fixup_segment() in write.c
17638 The S_IS_EXTERNAL test handles the case of global symbols.
17639 Those need the calculated base, not just the pipe compensation the linker will need. */
17640 if (fixP->fx_pcrel
17641 && fixP->fx_addsy != NULL
17642 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
17643 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
17644 return base + 8;
17645 return base;
17646 #else
17647 return base + 8;
17648 #endif
17649
17650 /* ARM mode loads relative to PC are also offset by +8. Unlike
17651 branches, the Windows CE loader *does* expect the relocation
17652 to take this into account. */
17653 case BFD_RELOC_ARM_OFFSET_IMM:
17654 case BFD_RELOC_ARM_OFFSET_IMM8:
17655 case BFD_RELOC_ARM_HWLITERAL:
17656 case BFD_RELOC_ARM_LITERAL:
17657 case BFD_RELOC_ARM_CP_OFF_IMM:
17658 return base + 8;
17659
17660
17661 /* Other PC-relative relocations are un-offset. */
17662 default:
17663 return base;
17664 }
17665 }
17666
17667 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
17668 Otherwise we have no need to default values of symbols. */
17669
17670 symbolS *
17671 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
17672 {
17673 #ifdef OBJ_ELF
17674 if (name[0] == '_' && name[1] == 'G'
17675 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
17676 {
17677 if (!GOT_symbol)
17678 {
17679 if (symbol_find (name))
17680 as_bad (_("GOT already in the symbol table"));
17681
17682 GOT_symbol = symbol_new (name, undefined_section,
17683 (valueT) 0, & zero_address_frag);
17684 }
17685
17686 return GOT_symbol;
17687 }
17688 #endif
17689
17690 return 0;
17691 }
17692
17693 /* Subroutine of md_apply_fix. Check to see if an immediate can be
17694 computed as two separate immediate values, added together. We
17695 already know that this value cannot be computed by just one ARM
17696 instruction. */
17697
17698 static unsigned int
17699 validate_immediate_twopart (unsigned int val,
17700 unsigned int * highpart)
17701 {
17702 unsigned int a;
17703 unsigned int i;
17704
17705 for (i = 0; i < 32; i += 2)
17706 if (((a = rotate_left (val, i)) & 0xff) != 0)
17707 {
17708 if (a & 0xff00)
17709 {
17710 if (a & ~ 0xffff)
17711 continue;
17712 * highpart = (a >> 8) | ((i + 24) << 7);
17713 }
17714 else if (a & 0xff0000)
17715 {
17716 if (a & 0xff000000)
17717 continue;
17718 * highpart = (a >> 16) | ((i + 16) << 7);
17719 }
17720 else
17721 {
17722 assert (a & 0xff000000);
17723 * highpart = (a >> 24) | ((i + 8) << 7);
17724 }
17725
17726 return (a & 0xff) | (i << 7);
17727 }
17728
17729 return FAIL;
17730 }
17731
17732 static int
17733 validate_offset_imm (unsigned int val, int hwse)
17734 {
17735 if ((hwse && val > 255) || val > 4095)
17736 return FAIL;
17737 return val;
17738 }
17739
17740 /* Subroutine of md_apply_fix. Do those data_ops which can take a
17741 negative immediate constant by altering the instruction. A bit of
17742 a hack really.
17743 MOV <-> MVN
17744 AND <-> BIC
17745 ADC <-> SBC
17746 by inverting the second operand, and
17747 ADD <-> SUB
17748 CMP <-> CMN
17749 by negating the second operand. */
17750
17751 static int
17752 negate_data_op (unsigned long * instruction,
17753 unsigned long value)
17754 {
17755 int op, new_inst;
17756 unsigned long negated, inverted;
17757
17758 negated = encode_arm_immediate (-value);
17759 inverted = encode_arm_immediate (~value);
17760
17761 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
17762 switch (op)
17763 {
17764 /* First negates. */
17765 case OPCODE_SUB: /* ADD <-> SUB */
17766 new_inst = OPCODE_ADD;
17767 value = negated;
17768 break;
17769
17770 case OPCODE_ADD:
17771 new_inst = OPCODE_SUB;
17772 value = negated;
17773 break;
17774
17775 case OPCODE_CMP: /* CMP <-> CMN */
17776 new_inst = OPCODE_CMN;
17777 value = negated;
17778 break;
17779
17780 case OPCODE_CMN:
17781 new_inst = OPCODE_CMP;
17782 value = negated;
17783 break;
17784
17785 /* Now Inverted ops. */
17786 case OPCODE_MOV: /* MOV <-> MVN */
17787 new_inst = OPCODE_MVN;
17788 value = inverted;
17789 break;
17790
17791 case OPCODE_MVN:
17792 new_inst = OPCODE_MOV;
17793 value = inverted;
17794 break;
17795
17796 case OPCODE_AND: /* AND <-> BIC */
17797 new_inst = OPCODE_BIC;
17798 value = inverted;
17799 break;
17800
17801 case OPCODE_BIC:
17802 new_inst = OPCODE_AND;
17803 value = inverted;
17804 break;
17805
17806 case OPCODE_ADC: /* ADC <-> SBC */
17807 new_inst = OPCODE_SBC;
17808 value = inverted;
17809 break;
17810
17811 case OPCODE_SBC:
17812 new_inst = OPCODE_ADC;
17813 value = inverted;
17814 break;
17815
17816 /* We cannot do anything. */
17817 default:
17818 return FAIL;
17819 }
17820
17821 if (value == (unsigned) FAIL)
17822 return FAIL;
17823
17824 *instruction &= OPCODE_MASK;
17825 *instruction |= new_inst << DATA_OP_SHIFT;
17826 return value;
17827 }
17828
17829 /* Like negate_data_op, but for Thumb-2. */
17830
17831 static unsigned int
17832 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
17833 {
17834 int op, new_inst;
17835 int rd;
17836 unsigned int negated, inverted;
17837
17838 negated = encode_thumb32_immediate (-value);
17839 inverted = encode_thumb32_immediate (~value);
17840
17841 rd = (*instruction >> 8) & 0xf;
17842 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
17843 switch (op)
17844 {
17845 /* ADD <-> SUB. Includes CMP <-> CMN. */
17846 case T2_OPCODE_SUB:
17847 new_inst = T2_OPCODE_ADD;
17848 value = negated;
17849 break;
17850
17851 case T2_OPCODE_ADD:
17852 new_inst = T2_OPCODE_SUB;
17853 value = negated;
17854 break;
17855
17856 /* ORR <-> ORN. Includes MOV <-> MVN. */
17857 case T2_OPCODE_ORR:
17858 new_inst = T2_OPCODE_ORN;
17859 value = inverted;
17860 break;
17861
17862 case T2_OPCODE_ORN:
17863 new_inst = T2_OPCODE_ORR;
17864 value = inverted;
17865 break;
17866
17867 /* AND <-> BIC. TST has no inverted equivalent. */
17868 case T2_OPCODE_AND:
17869 new_inst = T2_OPCODE_BIC;
17870 if (rd == 15)
17871 value = FAIL;
17872 else
17873 value = inverted;
17874 break;
17875
17876 case T2_OPCODE_BIC:
17877 new_inst = T2_OPCODE_AND;
17878 value = inverted;
17879 break;
17880
17881 /* ADC <-> SBC */
17882 case T2_OPCODE_ADC:
17883 new_inst = T2_OPCODE_SBC;
17884 value = inverted;
17885 break;
17886
17887 case T2_OPCODE_SBC:
17888 new_inst = T2_OPCODE_ADC;
17889 value = inverted;
17890 break;
17891
17892 /* We cannot do anything. */
17893 default:
17894 return FAIL;
17895 }
17896
17897 if (value == (unsigned int)FAIL)
17898 return FAIL;
17899
17900 *instruction &= T2_OPCODE_MASK;
17901 *instruction |= new_inst << T2_DATA_OP_SHIFT;
17902 return value;
17903 }
17904
17905 /* Read a 32-bit thumb instruction from buf. */
17906 static unsigned long
17907 get_thumb32_insn (char * buf)
17908 {
17909 unsigned long insn;
17910 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
17911 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
17912
17913 return insn;
17914 }
17915
17916
17917 /* We usually want to set the low bit on the address of thumb function
17918 symbols. In particular .word foo - . should have the low bit set.
17919 Generic code tries to fold the difference of two symbols to
17920 a constant. Prevent this and force a relocation when the first symbols
17921 is a thumb function. */
17922 int
17923 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
17924 {
17925 if (op == O_subtract
17926 && l->X_op == O_symbol
17927 && r->X_op == O_symbol
17928 && THUMB_IS_FUNC (l->X_add_symbol))
17929 {
17930 l->X_op = O_subtract;
17931 l->X_op_symbol = r->X_add_symbol;
17932 l->X_add_number -= r->X_add_number;
17933 return 1;
17934 }
17935 /* Process as normal. */
17936 return 0;
17937 }
17938
17939 void
17940 md_apply_fix (fixS * fixP,
17941 valueT * valP,
17942 segT seg)
17943 {
17944 offsetT value = * valP;
17945 offsetT newval;
17946 unsigned int newimm;
17947 unsigned long temp;
17948 int sign;
17949 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
17950
17951 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
17952
17953 /* Note whether this will delete the relocation. */
17954
17955 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
17956 fixP->fx_done = 1;
17957
17958 /* On a 64-bit host, silently truncate 'value' to 32 bits for
17959 consistency with the behaviour on 32-bit hosts. Remember value
17960 for emit_reloc. */
17961 value &= 0xffffffff;
17962 value ^= 0x80000000;
17963 value -= 0x80000000;
17964
17965 *valP = value;
17966 fixP->fx_addnumber = value;
17967
17968 /* Same treatment for fixP->fx_offset. */
17969 fixP->fx_offset &= 0xffffffff;
17970 fixP->fx_offset ^= 0x80000000;
17971 fixP->fx_offset -= 0x80000000;
17972
17973 switch (fixP->fx_r_type)
17974 {
17975 case BFD_RELOC_NONE:
17976 /* This will need to go in the object file. */
17977 fixP->fx_done = 0;
17978 break;
17979
17980 case BFD_RELOC_ARM_IMMEDIATE:
17981 /* We claim that this fixup has been processed here,
17982 even if in fact we generate an error because we do
17983 not have a reloc for it, so tc_gen_reloc will reject it. */
17984 fixP->fx_done = 1;
17985
17986 if (fixP->fx_addsy
17987 && ! S_IS_DEFINED (fixP->fx_addsy))
17988 {
17989 as_bad_where (fixP->fx_file, fixP->fx_line,
17990 _("undefined symbol %s used as an immediate value"),
17991 S_GET_NAME (fixP->fx_addsy));
17992 break;
17993 }
17994
17995 newimm = encode_arm_immediate (value);
17996 temp = md_chars_to_number (buf, INSN_SIZE);
17997
17998 /* If the instruction will fail, see if we can fix things up by
17999 changing the opcode. */
18000 if (newimm == (unsigned int) FAIL
18001 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
18002 {
18003 as_bad_where (fixP->fx_file, fixP->fx_line,
18004 _("invalid constant (%lx) after fixup"),
18005 (unsigned long) value);
18006 break;
18007 }
18008
18009 newimm |= (temp & 0xfffff000);
18010 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
18011 break;
18012
18013 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
18014 {
18015 unsigned int highpart = 0;
18016 unsigned int newinsn = 0xe1a00000; /* nop. */
18017
18018 newimm = encode_arm_immediate (value);
18019 temp = md_chars_to_number (buf, INSN_SIZE);
18020
18021 /* If the instruction will fail, see if we can fix things up by
18022 changing the opcode. */
18023 if (newimm == (unsigned int) FAIL
18024 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
18025 {
18026 /* No ? OK - try using two ADD instructions to generate
18027 the value. */
18028 newimm = validate_immediate_twopart (value, & highpart);
18029
18030 /* Yes - then make sure that the second instruction is
18031 also an add. */
18032 if (newimm != (unsigned int) FAIL)
18033 newinsn = temp;
18034 /* Still No ? Try using a negated value. */
18035 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
18036 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
18037 /* Otherwise - give up. */
18038 else
18039 {
18040 as_bad_where (fixP->fx_file, fixP->fx_line,
18041 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
18042 (long) value);
18043 break;
18044 }
18045
18046 /* Replace the first operand in the 2nd instruction (which
18047 is the PC) with the destination register. We have
18048 already added in the PC in the first instruction and we
18049 do not want to do it again. */
18050 newinsn &= ~ 0xf0000;
18051 newinsn |= ((newinsn & 0x0f000) << 4);
18052 }
18053
18054 newimm |= (temp & 0xfffff000);
18055 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
18056
18057 highpart |= (newinsn & 0xfffff000);
18058 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
18059 }
18060 break;
18061
18062 case BFD_RELOC_ARM_OFFSET_IMM:
18063 if (!fixP->fx_done && seg->use_rela_p)
18064 value = 0;
18065
18066 case BFD_RELOC_ARM_LITERAL:
18067 sign = value >= 0;
18068
18069 if (value < 0)
18070 value = - value;
18071
18072 if (validate_offset_imm (value, 0) == FAIL)
18073 {
18074 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
18075 as_bad_where (fixP->fx_file, fixP->fx_line,
18076 _("invalid literal constant: pool needs to be closer"));
18077 else
18078 as_bad_where (fixP->fx_file, fixP->fx_line,
18079 _("bad immediate value for offset (%ld)"),
18080 (long) value);
18081 break;
18082 }
18083
18084 newval = md_chars_to_number (buf, INSN_SIZE);
18085 newval &= 0xff7ff000;
18086 newval |= value | (sign ? INDEX_UP : 0);
18087 md_number_to_chars (buf, newval, INSN_SIZE);
18088 break;
18089
18090 case BFD_RELOC_ARM_OFFSET_IMM8:
18091 case BFD_RELOC_ARM_HWLITERAL:
18092 sign = value >= 0;
18093
18094 if (value < 0)
18095 value = - value;
18096
18097 if (validate_offset_imm (value, 1) == FAIL)
18098 {
18099 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
18100 as_bad_where (fixP->fx_file, fixP->fx_line,
18101 _("invalid literal constant: pool needs to be closer"));
18102 else
18103 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
18104 (long) value);
18105 break;
18106 }
18107
18108 newval = md_chars_to_number (buf, INSN_SIZE);
18109 newval &= 0xff7ff0f0;
18110 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
18111 md_number_to_chars (buf, newval, INSN_SIZE);
18112 break;
18113
18114 case BFD_RELOC_ARM_T32_OFFSET_U8:
18115 if (value < 0 || value > 1020 || value % 4 != 0)
18116 as_bad_where (fixP->fx_file, fixP->fx_line,
18117 _("bad immediate value for offset (%ld)"), (long) value);
18118 value /= 4;
18119
18120 newval = md_chars_to_number (buf+2, THUMB_SIZE);
18121 newval |= value;
18122 md_number_to_chars (buf+2, newval, THUMB_SIZE);
18123 break;
18124
18125 case BFD_RELOC_ARM_T32_OFFSET_IMM:
18126 /* This is a complicated relocation used for all varieties of Thumb32
18127 load/store instruction with immediate offset:
18128
18129 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
18130 *4, optional writeback(W)
18131 (doubleword load/store)
18132
18133 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
18134 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
18135 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
18136 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
18137 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
18138
18139 Uppercase letters indicate bits that are already encoded at
18140 this point. Lowercase letters are our problem. For the
18141 second block of instructions, the secondary opcode nybble
18142 (bits 8..11) is present, and bit 23 is zero, even if this is
18143 a PC-relative operation. */
18144 newval = md_chars_to_number (buf, THUMB_SIZE);
18145 newval <<= 16;
18146 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
18147
18148 if ((newval & 0xf0000000) == 0xe0000000)
18149 {
18150 /* Doubleword load/store: 8-bit offset, scaled by 4. */
18151 if (value >= 0)
18152 newval |= (1 << 23);
18153 else
18154 value = -value;
18155 if (value % 4 != 0)
18156 {
18157 as_bad_where (fixP->fx_file, fixP->fx_line,
18158 _("offset not a multiple of 4"));
18159 break;
18160 }
18161 value /= 4;
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 & 0x000f0000) == 0x000f0000)
18171 {
18172 /* PC-relative, 12-bit offset. */
18173 if (value >= 0)
18174 newval |= (1 << 23);
18175 else
18176 value = -value;
18177 if (value > 0xfff)
18178 {
18179 as_bad_where (fixP->fx_file, fixP->fx_line,
18180 _("offset out of range"));
18181 break;
18182 }
18183 newval &= ~0xfff;
18184 }
18185 else if ((newval & 0x00000100) == 0x00000100)
18186 {
18187 /* Writeback: 8-bit, +/- offset. */
18188 if (value >= 0)
18189 newval |= (1 << 9);
18190 else
18191 value = -value;
18192 if (value > 0xff)
18193 {
18194 as_bad_where (fixP->fx_file, fixP->fx_line,
18195 _("offset out of range"));
18196 break;
18197 }
18198 newval &= ~0xff;
18199 }
18200 else if ((newval & 0x00000f00) == 0x00000e00)
18201 {
18202 /* T-instruction: positive 8-bit offset. */
18203 if (value < 0 || value > 0xff)
18204 {
18205 as_bad_where (fixP->fx_file, fixP->fx_line,
18206 _("offset out of range"));
18207 break;
18208 }
18209 newval &= ~0xff;
18210 newval |= value;
18211 }
18212 else
18213 {
18214 /* Positive 12-bit or negative 8-bit offset. */
18215 int limit;
18216 if (value >= 0)
18217 {
18218 newval |= (1 << 23);
18219 limit = 0xfff;
18220 }
18221 else
18222 {
18223 value = -value;
18224 limit = 0xff;
18225 }
18226 if (value > limit)
18227 {
18228 as_bad_where (fixP->fx_file, fixP->fx_line,
18229 _("offset out of range"));
18230 break;
18231 }
18232 newval &= ~limit;
18233 }
18234
18235 newval |= value;
18236 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
18237 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
18238 break;
18239
18240 case BFD_RELOC_ARM_SHIFT_IMM:
18241 newval = md_chars_to_number (buf, INSN_SIZE);
18242 if (((unsigned long) value) > 32
18243 || (value == 32
18244 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
18245 {
18246 as_bad_where (fixP->fx_file, fixP->fx_line,
18247 _("shift expression is too large"));
18248 break;
18249 }
18250
18251 if (value == 0)
18252 /* Shifts of zero must be done as lsl. */
18253 newval &= ~0x60;
18254 else if (value == 32)
18255 value = 0;
18256 newval &= 0xfffff07f;
18257 newval |= (value & 0x1f) << 7;
18258 md_number_to_chars (buf, newval, INSN_SIZE);
18259 break;
18260
18261 case BFD_RELOC_ARM_T32_IMMEDIATE:
18262 case BFD_RELOC_ARM_T32_ADD_IMM:
18263 case BFD_RELOC_ARM_T32_IMM12:
18264 case BFD_RELOC_ARM_T32_ADD_PC12:
18265 /* We claim that this fixup has been processed here,
18266 even if in fact we generate an error because we do
18267 not have a reloc for it, so tc_gen_reloc will reject it. */
18268 fixP->fx_done = 1;
18269
18270 if (fixP->fx_addsy
18271 && ! S_IS_DEFINED (fixP->fx_addsy))
18272 {
18273 as_bad_where (fixP->fx_file, fixP->fx_line,
18274 _("undefined symbol %s used as an immediate value"),
18275 S_GET_NAME (fixP->fx_addsy));
18276 break;
18277 }
18278
18279 newval = md_chars_to_number (buf, THUMB_SIZE);
18280 newval <<= 16;
18281 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
18282
18283 newimm = FAIL;
18284 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
18285 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18286 {
18287 newimm = encode_thumb32_immediate (value);
18288 if (newimm == (unsigned int) FAIL)
18289 newimm = thumb32_negate_data_op (&newval, value);
18290 }
18291 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
18292 && newimm == (unsigned int) FAIL)
18293 {
18294 /* Turn add/sum into addw/subw. */
18295 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18296 newval = (newval & 0xfeffffff) | 0x02000000;
18297
18298 /* 12 bit immediate for addw/subw. */
18299 if (value < 0)
18300 {
18301 value = -value;
18302 newval ^= 0x00a00000;
18303 }
18304 if (value > 0xfff)
18305 newimm = (unsigned int) FAIL;
18306 else
18307 newimm = value;
18308 }
18309
18310 if (newimm == (unsigned int)FAIL)
18311 {
18312 as_bad_where (fixP->fx_file, fixP->fx_line,
18313 _("invalid constant (%lx) after fixup"),
18314 (unsigned long) value);
18315 break;
18316 }
18317
18318 newval |= (newimm & 0x800) << 15;
18319 newval |= (newimm & 0x700) << 4;
18320 newval |= (newimm & 0x0ff);
18321
18322 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
18323 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
18324 break;
18325
18326 case BFD_RELOC_ARM_SMC:
18327 if (((unsigned long) value) > 0xffff)
18328 as_bad_where (fixP->fx_file, fixP->fx_line,
18329 _("invalid smc expression"));
18330 newval = md_chars_to_number (buf, INSN_SIZE);
18331 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
18332 md_number_to_chars (buf, newval, INSN_SIZE);
18333 break;
18334
18335 case BFD_RELOC_ARM_SWI:
18336 if (fixP->tc_fix_data != 0)
18337 {
18338 if (((unsigned long) value) > 0xff)
18339 as_bad_where (fixP->fx_file, fixP->fx_line,
18340 _("invalid swi expression"));
18341 newval = md_chars_to_number (buf, THUMB_SIZE);
18342 newval |= value;
18343 md_number_to_chars (buf, newval, THUMB_SIZE);
18344 }
18345 else
18346 {
18347 if (((unsigned long) value) > 0x00ffffff)
18348 as_bad_where (fixP->fx_file, fixP->fx_line,
18349 _("invalid swi expression"));
18350 newval = md_chars_to_number (buf, INSN_SIZE);
18351 newval |= value;
18352 md_number_to_chars (buf, newval, INSN_SIZE);
18353 }
18354 break;
18355
18356 case BFD_RELOC_ARM_MULTI:
18357 if (((unsigned long) value) > 0xffff)
18358 as_bad_where (fixP->fx_file, fixP->fx_line,
18359 _("invalid expression in load/store multiple"));
18360 newval = value | md_chars_to_number (buf, INSN_SIZE);
18361 md_number_to_chars (buf, newval, INSN_SIZE);
18362 break;
18363
18364 #ifdef OBJ_ELF
18365 case BFD_RELOC_ARM_PCREL_CALL:
18366 newval = md_chars_to_number (buf, INSN_SIZE);
18367 if ((newval & 0xf0000000) == 0xf0000000)
18368 temp = 1;
18369 else
18370 temp = 3;
18371 goto arm_branch_common;
18372
18373 case BFD_RELOC_ARM_PCREL_JUMP:
18374 case BFD_RELOC_ARM_PLT32:
18375 #endif
18376 case BFD_RELOC_ARM_PCREL_BRANCH:
18377 temp = 3;
18378 goto arm_branch_common;
18379
18380 case BFD_RELOC_ARM_PCREL_BLX:
18381 temp = 1;
18382 arm_branch_common:
18383 /* We are going to store value (shifted right by two) in the
18384 instruction, in a 24 bit, signed field. Bits 26 through 32 either
18385 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
18386 also be be clear. */
18387 if (value & temp)
18388 as_bad_where (fixP->fx_file, fixP->fx_line,
18389 _("misaligned branch destination"));
18390 if ((value & (offsetT)0xfe000000) != (offsetT)0
18391 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
18392 as_bad_where (fixP->fx_file, fixP->fx_line,
18393 _("branch out of range"));
18394
18395 if (fixP->fx_done || !seg->use_rela_p)
18396 {
18397 newval = md_chars_to_number (buf, INSN_SIZE);
18398 newval |= (value >> 2) & 0x00ffffff;
18399 /* Set the H bit on BLX instructions. */
18400 if (temp == 1)
18401 {
18402 if (value & 2)
18403 newval |= 0x01000000;
18404 else
18405 newval &= ~0x01000000;
18406 }
18407 md_number_to_chars (buf, newval, INSN_SIZE);
18408 }
18409 break;
18410
18411 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
18412 /* CBZ can only branch forward. */
18413
18414 /* Attempts to use CBZ to branch to the next instruction
18415 (which, strictly speaking, are prohibited) will be turned into
18416 no-ops.
18417
18418 FIXME: It may be better to remove the instruction completely and
18419 perform relaxation. */
18420 if (value == -2)
18421 {
18422 newval = md_chars_to_number (buf, THUMB_SIZE);
18423 newval = 0xbf00; /* NOP encoding T1 */
18424 md_number_to_chars (buf, newval, THUMB_SIZE);
18425 }
18426 else
18427 {
18428 if (value & ~0x7e)
18429 as_bad_where (fixP->fx_file, fixP->fx_line,
18430 _("branch out of range"));
18431
18432 if (fixP->fx_done || !seg->use_rela_p)
18433 {
18434 newval = md_chars_to_number (buf, THUMB_SIZE);
18435 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
18436 md_number_to_chars (buf, newval, THUMB_SIZE);
18437 }
18438 }
18439 break;
18440
18441 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
18442 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
18443 as_bad_where (fixP->fx_file, fixP->fx_line,
18444 _("branch out of range"));
18445
18446 if (fixP->fx_done || !seg->use_rela_p)
18447 {
18448 newval = md_chars_to_number (buf, THUMB_SIZE);
18449 newval |= (value & 0x1ff) >> 1;
18450 md_number_to_chars (buf, newval, THUMB_SIZE);
18451 }
18452 break;
18453
18454 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
18455 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
18456 as_bad_where (fixP->fx_file, fixP->fx_line,
18457 _("branch out of range"));
18458
18459 if (fixP->fx_done || !seg->use_rela_p)
18460 {
18461 newval = md_chars_to_number (buf, THUMB_SIZE);
18462 newval |= (value & 0xfff) >> 1;
18463 md_number_to_chars (buf, newval, THUMB_SIZE);
18464 }
18465 break;
18466
18467 case BFD_RELOC_THUMB_PCREL_BRANCH20:
18468 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
18469 as_bad_where (fixP->fx_file, fixP->fx_line,
18470 _("conditional branch out of range"));
18471
18472 if (fixP->fx_done || !seg->use_rela_p)
18473 {
18474 offsetT newval2;
18475 addressT S, J1, J2, lo, hi;
18476
18477 S = (value & 0x00100000) >> 20;
18478 J2 = (value & 0x00080000) >> 19;
18479 J1 = (value & 0x00040000) >> 18;
18480 hi = (value & 0x0003f000) >> 12;
18481 lo = (value & 0x00000ffe) >> 1;
18482
18483 newval = md_chars_to_number (buf, THUMB_SIZE);
18484 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18485 newval |= (S << 10) | hi;
18486 newval2 |= (J1 << 13) | (J2 << 11) | lo;
18487 md_number_to_chars (buf, newval, THUMB_SIZE);
18488 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18489 }
18490 break;
18491
18492 case BFD_RELOC_THUMB_PCREL_BLX:
18493 case BFD_RELOC_THUMB_PCREL_BRANCH23:
18494 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
18495 as_bad_where (fixP->fx_file, fixP->fx_line,
18496 _("branch out of range"));
18497
18498 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
18499 /* For a BLX instruction, make sure that the relocation is rounded up
18500 to a word boundary. This follows the semantics of the instruction
18501 which specifies that bit 1 of the target address will come from bit
18502 1 of the base address. */
18503 value = (value + 1) & ~ 1;
18504
18505 if (fixP->fx_done || !seg->use_rela_p)
18506 {
18507 offsetT newval2;
18508
18509 newval = md_chars_to_number (buf, THUMB_SIZE);
18510 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18511 newval |= (value & 0x7fffff) >> 12;
18512 newval2 |= (value & 0xfff) >> 1;
18513 md_number_to_chars (buf, newval, THUMB_SIZE);
18514 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18515 }
18516 break;
18517
18518 case BFD_RELOC_THUMB_PCREL_BRANCH25:
18519 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
18520 as_bad_where (fixP->fx_file, fixP->fx_line,
18521 _("branch out of range"));
18522
18523 if (fixP->fx_done || !seg->use_rela_p)
18524 {
18525 offsetT newval2;
18526 addressT S, I1, I2, lo, hi;
18527
18528 S = (value & 0x01000000) >> 24;
18529 I1 = (value & 0x00800000) >> 23;
18530 I2 = (value & 0x00400000) >> 22;
18531 hi = (value & 0x003ff000) >> 12;
18532 lo = (value & 0x00000ffe) >> 1;
18533
18534 I1 = !(I1 ^ S);
18535 I2 = !(I2 ^ S);
18536
18537 newval = md_chars_to_number (buf, THUMB_SIZE);
18538 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18539 newval |= (S << 10) | hi;
18540 newval2 |= (I1 << 13) | (I2 << 11) | lo;
18541 md_number_to_chars (buf, newval, THUMB_SIZE);
18542 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18543 }
18544 break;
18545
18546 case BFD_RELOC_8:
18547 if (fixP->fx_done || !seg->use_rela_p)
18548 md_number_to_chars (buf, value, 1);
18549 break;
18550
18551 case BFD_RELOC_16:
18552 if (fixP->fx_done || !seg->use_rela_p)
18553 md_number_to_chars (buf, value, 2);
18554 break;
18555
18556 #ifdef OBJ_ELF
18557 case BFD_RELOC_ARM_TLS_GD32:
18558 case BFD_RELOC_ARM_TLS_LE32:
18559 case BFD_RELOC_ARM_TLS_IE32:
18560 case BFD_RELOC_ARM_TLS_LDM32:
18561 case BFD_RELOC_ARM_TLS_LDO32:
18562 S_SET_THREAD_LOCAL (fixP->fx_addsy);
18563 /* fall through */
18564
18565 case BFD_RELOC_ARM_GOT32:
18566 case BFD_RELOC_ARM_GOTOFF:
18567 case BFD_RELOC_ARM_TARGET2:
18568 if (fixP->fx_done || !seg->use_rela_p)
18569 md_number_to_chars (buf, 0, 4);
18570 break;
18571 #endif
18572
18573 case BFD_RELOC_RVA:
18574 case BFD_RELOC_32:
18575 case BFD_RELOC_ARM_TARGET1:
18576 case BFD_RELOC_ARM_ROSEGREL32:
18577 case BFD_RELOC_ARM_SBREL32:
18578 case BFD_RELOC_32_PCREL:
18579 #ifdef TE_PE
18580 case BFD_RELOC_32_SECREL:
18581 #endif
18582 if (fixP->fx_done || !seg->use_rela_p)
18583 #ifdef TE_WINCE
18584 /* For WinCE we only do this for pcrel fixups. */
18585 if (fixP->fx_done || fixP->fx_pcrel)
18586 #endif
18587 md_number_to_chars (buf, value, 4);
18588 break;
18589
18590 #ifdef OBJ_ELF
18591 case BFD_RELOC_ARM_PREL31:
18592 if (fixP->fx_done || !seg->use_rela_p)
18593 {
18594 newval = md_chars_to_number (buf, 4) & 0x80000000;
18595 if ((value ^ (value >> 1)) & 0x40000000)
18596 {
18597 as_bad_where (fixP->fx_file, fixP->fx_line,
18598 _("rel31 relocation overflow"));
18599 }
18600 newval |= value & 0x7fffffff;
18601 md_number_to_chars (buf, newval, 4);
18602 }
18603 break;
18604 #endif
18605
18606 case BFD_RELOC_ARM_CP_OFF_IMM:
18607 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
18608 if (value < -1023 || value > 1023 || (value & 3))
18609 as_bad_where (fixP->fx_file, fixP->fx_line,
18610 _("co-processor offset out of range"));
18611 cp_off_common:
18612 sign = value >= 0;
18613 if (value < 0)
18614 value = -value;
18615 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18616 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18617 newval = md_chars_to_number (buf, INSN_SIZE);
18618 else
18619 newval = get_thumb32_insn (buf);
18620 newval &= 0xff7fff00;
18621 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
18622 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18623 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18624 md_number_to_chars (buf, newval, INSN_SIZE);
18625 else
18626 put_thumb32_insn (buf, newval);
18627 break;
18628
18629 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
18630 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
18631 if (value < -255 || value > 255)
18632 as_bad_where (fixP->fx_file, fixP->fx_line,
18633 _("co-processor offset out of range"));
18634 value *= 4;
18635 goto cp_off_common;
18636
18637 case BFD_RELOC_ARM_THUMB_OFFSET:
18638 newval = md_chars_to_number (buf, THUMB_SIZE);
18639 /* Exactly what ranges, and where the offset is inserted depends
18640 on the type of instruction, we can establish this from the
18641 top 4 bits. */
18642 switch (newval >> 12)
18643 {
18644 case 4: /* PC load. */
18645 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
18646 forced to zero for these loads; md_pcrel_from has already
18647 compensated for this. */
18648 if (value & 3)
18649 as_bad_where (fixP->fx_file, fixP->fx_line,
18650 _("invalid offset, target not word aligned (0x%08lX)"),
18651 (((unsigned long) fixP->fx_frag->fr_address
18652 + (unsigned long) fixP->fx_where) & ~3)
18653 + (unsigned long) value);
18654
18655 if (value & ~0x3fc)
18656 as_bad_where (fixP->fx_file, fixP->fx_line,
18657 _("invalid offset, value too big (0x%08lX)"),
18658 (long) value);
18659
18660 newval |= value >> 2;
18661 break;
18662
18663 case 9: /* SP load/store. */
18664 if (value & ~0x3fc)
18665 as_bad_where (fixP->fx_file, fixP->fx_line,
18666 _("invalid offset, value too big (0x%08lX)"),
18667 (long) value);
18668 newval |= value >> 2;
18669 break;
18670
18671 case 6: /* Word load/store. */
18672 if (value & ~0x7c)
18673 as_bad_where (fixP->fx_file, fixP->fx_line,
18674 _("invalid offset, value too big (0x%08lX)"),
18675 (long) value);
18676 newval |= value << 4; /* 6 - 2. */
18677 break;
18678
18679 case 7: /* Byte load/store. */
18680 if (value & ~0x1f)
18681 as_bad_where (fixP->fx_file, fixP->fx_line,
18682 _("invalid offset, value too big (0x%08lX)"),
18683 (long) value);
18684 newval |= value << 6;
18685 break;
18686
18687 case 8: /* Halfword load/store. */
18688 if (value & ~0x3e)
18689 as_bad_where (fixP->fx_file, fixP->fx_line,
18690 _("invalid offset, value too big (0x%08lX)"),
18691 (long) value);
18692 newval |= value << 5; /* 6 - 1. */
18693 break;
18694
18695 default:
18696 as_bad_where (fixP->fx_file, fixP->fx_line,
18697 "Unable to process relocation for thumb opcode: %lx",
18698 (unsigned long) newval);
18699 break;
18700 }
18701 md_number_to_chars (buf, newval, THUMB_SIZE);
18702 break;
18703
18704 case BFD_RELOC_ARM_THUMB_ADD:
18705 /* This is a complicated relocation, since we use it for all of
18706 the following immediate relocations:
18707
18708 3bit ADD/SUB
18709 8bit ADD/SUB
18710 9bit ADD/SUB SP word-aligned
18711 10bit ADD PC/SP word-aligned
18712
18713 The type of instruction being processed is encoded in the
18714 instruction field:
18715
18716 0x8000 SUB
18717 0x00F0 Rd
18718 0x000F Rs
18719 */
18720 newval = md_chars_to_number (buf, THUMB_SIZE);
18721 {
18722 int rd = (newval >> 4) & 0xf;
18723 int rs = newval & 0xf;
18724 int subtract = !!(newval & 0x8000);
18725
18726 /* Check for HI regs, only very restricted cases allowed:
18727 Adjusting SP, and using PC or SP to get an address. */
18728 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
18729 || (rs > 7 && rs != REG_SP && rs != REG_PC))
18730 as_bad_where (fixP->fx_file, fixP->fx_line,
18731 _("invalid Hi register with immediate"));
18732
18733 /* If value is negative, choose the opposite instruction. */
18734 if (value < 0)
18735 {
18736 value = -value;
18737 subtract = !subtract;
18738 if (value < 0)
18739 as_bad_where (fixP->fx_file, fixP->fx_line,
18740 _("immediate value out of range"));
18741 }
18742
18743 if (rd == REG_SP)
18744 {
18745 if (value & ~0x1fc)
18746 as_bad_where (fixP->fx_file, fixP->fx_line,
18747 _("invalid immediate for stack address calculation"));
18748 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
18749 newval |= value >> 2;
18750 }
18751 else if (rs == REG_PC || rs == REG_SP)
18752 {
18753 if (subtract || value & ~0x3fc)
18754 as_bad_where (fixP->fx_file, fixP->fx_line,
18755 _("invalid immediate for address calculation (value = 0x%08lX)"),
18756 (unsigned long) value);
18757 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
18758 newval |= rd << 8;
18759 newval |= value >> 2;
18760 }
18761 else if (rs == rd)
18762 {
18763 if (value & ~0xff)
18764 as_bad_where (fixP->fx_file, fixP->fx_line,
18765 _("immediate value out of range"));
18766 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
18767 newval |= (rd << 8) | value;
18768 }
18769 else
18770 {
18771 if (value & ~0x7)
18772 as_bad_where (fixP->fx_file, fixP->fx_line,
18773 _("immediate value out of range"));
18774 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
18775 newval |= rd | (rs << 3) | (value << 6);
18776 }
18777 }
18778 md_number_to_chars (buf, newval, THUMB_SIZE);
18779 break;
18780
18781 case BFD_RELOC_ARM_THUMB_IMM:
18782 newval = md_chars_to_number (buf, THUMB_SIZE);
18783 if (value < 0 || value > 255)
18784 as_bad_where (fixP->fx_file, fixP->fx_line,
18785 _("invalid immediate: %ld is out of range"),
18786 (long) value);
18787 newval |= value;
18788 md_number_to_chars (buf, newval, THUMB_SIZE);
18789 break;
18790
18791 case BFD_RELOC_ARM_THUMB_SHIFT:
18792 /* 5bit shift value (0..32). LSL cannot take 32. */
18793 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
18794 temp = newval & 0xf800;
18795 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
18796 as_bad_where (fixP->fx_file, fixP->fx_line,
18797 _("invalid shift value: %ld"), (long) value);
18798 /* Shifts of zero must be encoded as LSL. */
18799 if (value == 0)
18800 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
18801 /* Shifts of 32 are encoded as zero. */
18802 else if (value == 32)
18803 value = 0;
18804 newval |= value << 6;
18805 md_number_to_chars (buf, newval, THUMB_SIZE);
18806 break;
18807
18808 case BFD_RELOC_VTABLE_INHERIT:
18809 case BFD_RELOC_VTABLE_ENTRY:
18810 fixP->fx_done = 0;
18811 return;
18812
18813 case BFD_RELOC_ARM_MOVW:
18814 case BFD_RELOC_ARM_MOVT:
18815 case BFD_RELOC_ARM_THUMB_MOVW:
18816 case BFD_RELOC_ARM_THUMB_MOVT:
18817 if (fixP->fx_done || !seg->use_rela_p)
18818 {
18819 /* REL format relocations are limited to a 16-bit addend. */
18820 if (!fixP->fx_done)
18821 {
18822 if (value < -0x8000 || value > 0x7fff)
18823 as_bad_where (fixP->fx_file, fixP->fx_line,
18824 _("offset out of range"));
18825 }
18826 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
18827 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18828 {
18829 value >>= 16;
18830 }
18831
18832 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
18833 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18834 {
18835 newval = get_thumb32_insn (buf);
18836 newval &= 0xfbf08f00;
18837 newval |= (value & 0xf000) << 4;
18838 newval |= (value & 0x0800) << 15;
18839 newval |= (value & 0x0700) << 4;
18840 newval |= (value & 0x00ff);
18841 put_thumb32_insn (buf, newval);
18842 }
18843 else
18844 {
18845 newval = md_chars_to_number (buf, 4);
18846 newval &= 0xfff0f000;
18847 newval |= value & 0x0fff;
18848 newval |= (value & 0xf000) << 4;
18849 md_number_to_chars (buf, newval, 4);
18850 }
18851 }
18852 return;
18853
18854 case BFD_RELOC_ARM_ALU_PC_G0_NC:
18855 case BFD_RELOC_ARM_ALU_PC_G0:
18856 case BFD_RELOC_ARM_ALU_PC_G1_NC:
18857 case BFD_RELOC_ARM_ALU_PC_G1:
18858 case BFD_RELOC_ARM_ALU_PC_G2:
18859 case BFD_RELOC_ARM_ALU_SB_G0_NC:
18860 case BFD_RELOC_ARM_ALU_SB_G0:
18861 case BFD_RELOC_ARM_ALU_SB_G1_NC:
18862 case BFD_RELOC_ARM_ALU_SB_G1:
18863 case BFD_RELOC_ARM_ALU_SB_G2:
18864 assert (!fixP->fx_done);
18865 if (!seg->use_rela_p)
18866 {
18867 bfd_vma insn;
18868 bfd_vma encoded_addend;
18869 bfd_vma addend_abs = abs (value);
18870
18871 /* Check that the absolute value of the addend can be
18872 expressed as an 8-bit constant plus a rotation. */
18873 encoded_addend = encode_arm_immediate (addend_abs);
18874 if (encoded_addend == (unsigned int) FAIL)
18875 as_bad_where (fixP->fx_file, fixP->fx_line,
18876 _("the offset 0x%08lX is not representable"),
18877 (unsigned long) addend_abs);
18878
18879 /* Extract the instruction. */
18880 insn = md_chars_to_number (buf, INSN_SIZE);
18881
18882 /* If the addend is positive, use an ADD instruction.
18883 Otherwise use a SUB. Take care not to destroy the S bit. */
18884 insn &= 0xff1fffff;
18885 if (value < 0)
18886 insn |= 1 << 22;
18887 else
18888 insn |= 1 << 23;
18889
18890 /* Place the encoded addend into the first 12 bits of the
18891 instruction. */
18892 insn &= 0xfffff000;
18893 insn |= encoded_addend;
18894
18895 /* Update the instruction. */
18896 md_number_to_chars (buf, insn, INSN_SIZE);
18897 }
18898 break;
18899
18900 case BFD_RELOC_ARM_LDR_PC_G0:
18901 case BFD_RELOC_ARM_LDR_PC_G1:
18902 case BFD_RELOC_ARM_LDR_PC_G2:
18903 case BFD_RELOC_ARM_LDR_SB_G0:
18904 case BFD_RELOC_ARM_LDR_SB_G1:
18905 case BFD_RELOC_ARM_LDR_SB_G2:
18906 assert (!fixP->fx_done);
18907 if (!seg->use_rela_p)
18908 {
18909 bfd_vma insn;
18910 bfd_vma addend_abs = abs (value);
18911
18912 /* Check that the absolute value of the addend can be
18913 encoded in 12 bits. */
18914 if (addend_abs >= 0x1000)
18915 as_bad_where (fixP->fx_file, fixP->fx_line,
18916 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
18917 (unsigned long) addend_abs);
18918
18919 /* Extract the instruction. */
18920 insn = md_chars_to_number (buf, INSN_SIZE);
18921
18922 /* If the addend is negative, clear bit 23 of the instruction.
18923 Otherwise set it. */
18924 if (value < 0)
18925 insn &= ~(1 << 23);
18926 else
18927 insn |= 1 << 23;
18928
18929 /* Place the absolute value of the addend into the first 12 bits
18930 of the instruction. */
18931 insn &= 0xfffff000;
18932 insn |= addend_abs;
18933
18934 /* Update the instruction. */
18935 md_number_to_chars (buf, insn, INSN_SIZE);
18936 }
18937 break;
18938
18939 case BFD_RELOC_ARM_LDRS_PC_G0:
18940 case BFD_RELOC_ARM_LDRS_PC_G1:
18941 case BFD_RELOC_ARM_LDRS_PC_G2:
18942 case BFD_RELOC_ARM_LDRS_SB_G0:
18943 case BFD_RELOC_ARM_LDRS_SB_G1:
18944 case BFD_RELOC_ARM_LDRS_SB_G2:
18945 assert (!fixP->fx_done);
18946 if (!seg->use_rela_p)
18947 {
18948 bfd_vma insn;
18949 bfd_vma addend_abs = abs (value);
18950
18951 /* Check that the absolute value of the addend can be
18952 encoded in 8 bits. */
18953 if (addend_abs >= 0x100)
18954 as_bad_where (fixP->fx_file, fixP->fx_line,
18955 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
18956 (unsigned long) addend_abs);
18957
18958 /* Extract the instruction. */
18959 insn = md_chars_to_number (buf, INSN_SIZE);
18960
18961 /* If the addend is negative, clear bit 23 of the instruction.
18962 Otherwise set it. */
18963 if (value < 0)
18964 insn &= ~(1 << 23);
18965 else
18966 insn |= 1 << 23;
18967
18968 /* Place the first four bits of the absolute value of the addend
18969 into the first 4 bits of the instruction, and the remaining
18970 four into bits 8 .. 11. */
18971 insn &= 0xfffff0f0;
18972 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
18973
18974 /* Update the instruction. */
18975 md_number_to_chars (buf, insn, INSN_SIZE);
18976 }
18977 break;
18978
18979 case BFD_RELOC_ARM_LDC_PC_G0:
18980 case BFD_RELOC_ARM_LDC_PC_G1:
18981 case BFD_RELOC_ARM_LDC_PC_G2:
18982 case BFD_RELOC_ARM_LDC_SB_G0:
18983 case BFD_RELOC_ARM_LDC_SB_G1:
18984 case BFD_RELOC_ARM_LDC_SB_G2:
18985 assert (!fixP->fx_done);
18986 if (!seg->use_rela_p)
18987 {
18988 bfd_vma insn;
18989 bfd_vma addend_abs = abs (value);
18990
18991 /* Check that the absolute value of the addend is a multiple of
18992 four and, when divided by four, fits in 8 bits. */
18993 if (addend_abs & 0x3)
18994 as_bad_where (fixP->fx_file, fixP->fx_line,
18995 _("bad offset 0x%08lX (must be word-aligned)"),
18996 (unsigned long) addend_abs);
18997
18998 if ((addend_abs >> 2) > 0xff)
18999 as_bad_where (fixP->fx_file, fixP->fx_line,
19000 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
19001 (unsigned long) addend_abs);
19002
19003 /* Extract the instruction. */
19004 insn = md_chars_to_number (buf, INSN_SIZE);
19005
19006 /* If the addend is negative, clear bit 23 of the instruction.
19007 Otherwise set it. */
19008 if (value < 0)
19009 insn &= ~(1 << 23);
19010 else
19011 insn |= 1 << 23;
19012
19013 /* Place the addend (divided by four) into the first eight
19014 bits of the instruction. */
19015 insn &= 0xfffffff0;
19016 insn |= addend_abs >> 2;
19017
19018 /* Update the instruction. */
19019 md_number_to_chars (buf, insn, INSN_SIZE);
19020 }
19021 break;
19022
19023 case BFD_RELOC_ARM_V4BX:
19024 /* This will need to go in the object file. */
19025 fixP->fx_done = 0;
19026 break;
19027
19028 case BFD_RELOC_UNUSED:
19029 default:
19030 as_bad_where (fixP->fx_file, fixP->fx_line,
19031 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
19032 }
19033 }
19034
19035 /* Translate internal representation of relocation info to BFD target
19036 format. */
19037
19038 arelent *
19039 tc_gen_reloc (asection *section, fixS *fixp)
19040 {
19041 arelent * reloc;
19042 bfd_reloc_code_real_type code;
19043
19044 reloc = xmalloc (sizeof (arelent));
19045
19046 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
19047 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
19048 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
19049
19050 if (fixp->fx_pcrel)
19051 {
19052 if (section->use_rela_p)
19053 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
19054 else
19055 fixp->fx_offset = reloc->address;
19056 }
19057 reloc->addend = fixp->fx_offset;
19058
19059 switch (fixp->fx_r_type)
19060 {
19061 case BFD_RELOC_8:
19062 if (fixp->fx_pcrel)
19063 {
19064 code = BFD_RELOC_8_PCREL;
19065 break;
19066 }
19067
19068 case BFD_RELOC_16:
19069 if (fixp->fx_pcrel)
19070 {
19071 code = BFD_RELOC_16_PCREL;
19072 break;
19073 }
19074
19075 case BFD_RELOC_32:
19076 if (fixp->fx_pcrel)
19077 {
19078 code = BFD_RELOC_32_PCREL;
19079 break;
19080 }
19081
19082 case BFD_RELOC_ARM_MOVW:
19083 if (fixp->fx_pcrel)
19084 {
19085 code = BFD_RELOC_ARM_MOVW_PCREL;
19086 break;
19087 }
19088
19089 case BFD_RELOC_ARM_MOVT:
19090 if (fixp->fx_pcrel)
19091 {
19092 code = BFD_RELOC_ARM_MOVT_PCREL;
19093 break;
19094 }
19095
19096 case BFD_RELOC_ARM_THUMB_MOVW:
19097 if (fixp->fx_pcrel)
19098 {
19099 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
19100 break;
19101 }
19102
19103 case BFD_RELOC_ARM_THUMB_MOVT:
19104 if (fixp->fx_pcrel)
19105 {
19106 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
19107 break;
19108 }
19109
19110 case BFD_RELOC_NONE:
19111 case BFD_RELOC_ARM_PCREL_BRANCH:
19112 case BFD_RELOC_ARM_PCREL_BLX:
19113 case BFD_RELOC_RVA:
19114 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19115 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19116 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19117 case BFD_RELOC_THUMB_PCREL_BRANCH20:
19118 case BFD_RELOC_THUMB_PCREL_BRANCH23:
19119 case BFD_RELOC_THUMB_PCREL_BRANCH25:
19120 case BFD_RELOC_THUMB_PCREL_BLX:
19121 case BFD_RELOC_VTABLE_ENTRY:
19122 case BFD_RELOC_VTABLE_INHERIT:
19123 #ifdef TE_PE
19124 case BFD_RELOC_32_SECREL:
19125 #endif
19126 code = fixp->fx_r_type;
19127 break;
19128
19129 case BFD_RELOC_ARM_LITERAL:
19130 case BFD_RELOC_ARM_HWLITERAL:
19131 /* If this is called then the a literal has
19132 been referenced across a section boundary. */
19133 as_bad_where (fixp->fx_file, fixp->fx_line,
19134 _("literal referenced across section boundary"));
19135 return NULL;
19136
19137 #ifdef OBJ_ELF
19138 case BFD_RELOC_ARM_GOT32:
19139 case BFD_RELOC_ARM_GOTOFF:
19140 case BFD_RELOC_ARM_PLT32:
19141 case BFD_RELOC_ARM_TARGET1:
19142 case BFD_RELOC_ARM_ROSEGREL32:
19143 case BFD_RELOC_ARM_SBREL32:
19144 case BFD_RELOC_ARM_PREL31:
19145 case BFD_RELOC_ARM_TARGET2:
19146 case BFD_RELOC_ARM_TLS_LE32:
19147 case BFD_RELOC_ARM_TLS_LDO32:
19148 case BFD_RELOC_ARM_PCREL_CALL:
19149 case BFD_RELOC_ARM_PCREL_JUMP:
19150 case BFD_RELOC_ARM_ALU_PC_G0_NC:
19151 case BFD_RELOC_ARM_ALU_PC_G0:
19152 case BFD_RELOC_ARM_ALU_PC_G1_NC:
19153 case BFD_RELOC_ARM_ALU_PC_G1:
19154 case BFD_RELOC_ARM_ALU_PC_G2:
19155 case BFD_RELOC_ARM_LDR_PC_G0:
19156 case BFD_RELOC_ARM_LDR_PC_G1:
19157 case BFD_RELOC_ARM_LDR_PC_G2:
19158 case BFD_RELOC_ARM_LDRS_PC_G0:
19159 case BFD_RELOC_ARM_LDRS_PC_G1:
19160 case BFD_RELOC_ARM_LDRS_PC_G2:
19161 case BFD_RELOC_ARM_LDC_PC_G0:
19162 case BFD_RELOC_ARM_LDC_PC_G1:
19163 case BFD_RELOC_ARM_LDC_PC_G2:
19164 case BFD_RELOC_ARM_ALU_SB_G0_NC:
19165 case BFD_RELOC_ARM_ALU_SB_G0:
19166 case BFD_RELOC_ARM_ALU_SB_G1_NC:
19167 case BFD_RELOC_ARM_ALU_SB_G1:
19168 case BFD_RELOC_ARM_ALU_SB_G2:
19169 case BFD_RELOC_ARM_LDR_SB_G0:
19170 case BFD_RELOC_ARM_LDR_SB_G1:
19171 case BFD_RELOC_ARM_LDR_SB_G2:
19172 case BFD_RELOC_ARM_LDRS_SB_G0:
19173 case BFD_RELOC_ARM_LDRS_SB_G1:
19174 case BFD_RELOC_ARM_LDRS_SB_G2:
19175 case BFD_RELOC_ARM_LDC_SB_G0:
19176 case BFD_RELOC_ARM_LDC_SB_G1:
19177 case BFD_RELOC_ARM_LDC_SB_G2:
19178 case BFD_RELOC_ARM_V4BX:
19179 code = fixp->fx_r_type;
19180 break;
19181
19182 case BFD_RELOC_ARM_TLS_GD32:
19183 case BFD_RELOC_ARM_TLS_IE32:
19184 case BFD_RELOC_ARM_TLS_LDM32:
19185 /* BFD will include the symbol's address in the addend.
19186 But we don't want that, so subtract it out again here. */
19187 if (!S_IS_COMMON (fixp->fx_addsy))
19188 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
19189 code = fixp->fx_r_type;
19190 break;
19191 #endif
19192
19193 case BFD_RELOC_ARM_IMMEDIATE:
19194 as_bad_where (fixp->fx_file, fixp->fx_line,
19195 _("internal relocation (type: IMMEDIATE) not fixed up"));
19196 return NULL;
19197
19198 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19199 as_bad_where (fixp->fx_file, fixp->fx_line,
19200 _("ADRL used for a symbol not defined in the same file"));
19201 return NULL;
19202
19203 case BFD_RELOC_ARM_OFFSET_IMM:
19204 if (section->use_rela_p)
19205 {
19206 code = fixp->fx_r_type;
19207 break;
19208 }
19209
19210 if (fixp->fx_addsy != NULL
19211 && !S_IS_DEFINED (fixp->fx_addsy)
19212 && S_IS_LOCAL (fixp->fx_addsy))
19213 {
19214 as_bad_where (fixp->fx_file, fixp->fx_line,
19215 _("undefined local label `%s'"),
19216 S_GET_NAME (fixp->fx_addsy));
19217 return NULL;
19218 }
19219
19220 as_bad_where (fixp->fx_file, fixp->fx_line,
19221 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
19222 return NULL;
19223
19224 default:
19225 {
19226 char * type;
19227
19228 switch (fixp->fx_r_type)
19229 {
19230 case BFD_RELOC_NONE: type = "NONE"; break;
19231 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
19232 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
19233 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
19234 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
19235 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
19236 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
19237 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
19238 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
19239 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
19240 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
19241 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
19242 default: type = _("<unknown>"); break;
19243 }
19244 as_bad_where (fixp->fx_file, fixp->fx_line,
19245 _("cannot represent %s relocation in this object file format"),
19246 type);
19247 return NULL;
19248 }
19249 }
19250
19251 #ifdef OBJ_ELF
19252 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
19253 && GOT_symbol
19254 && fixp->fx_addsy == GOT_symbol)
19255 {
19256 code = BFD_RELOC_ARM_GOTPC;
19257 reloc->addend = fixp->fx_offset = reloc->address;
19258 }
19259 #endif
19260
19261 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
19262
19263 if (reloc->howto == NULL)
19264 {
19265 as_bad_where (fixp->fx_file, fixp->fx_line,
19266 _("cannot represent %s relocation in this object file format"),
19267 bfd_get_reloc_code_name (code));
19268 return NULL;
19269 }
19270
19271 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
19272 vtable entry to be used in the relocation's section offset. */
19273 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19274 reloc->address = fixp->fx_offset;
19275
19276 return reloc;
19277 }
19278
19279 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
19280
19281 void
19282 cons_fix_new_arm (fragS * frag,
19283 int where,
19284 int size,
19285 expressionS * exp)
19286 {
19287 bfd_reloc_code_real_type type;
19288 int pcrel = 0;
19289
19290 /* Pick a reloc.
19291 FIXME: @@ Should look at CPU word size. */
19292 switch (size)
19293 {
19294 case 1:
19295 type = BFD_RELOC_8;
19296 break;
19297 case 2:
19298 type = BFD_RELOC_16;
19299 break;
19300 case 4:
19301 default:
19302 type = BFD_RELOC_32;
19303 break;
19304 case 8:
19305 type = BFD_RELOC_64;
19306 break;
19307 }
19308
19309 #ifdef TE_PE
19310 if (exp->X_op == O_secrel)
19311 {
19312 exp->X_op = O_symbol;
19313 type = BFD_RELOC_32_SECREL;
19314 }
19315 #endif
19316
19317 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
19318 }
19319
19320 #if defined OBJ_COFF || defined OBJ_ELF
19321 void
19322 arm_validate_fix (fixS * fixP)
19323 {
19324 /* If the destination of the branch is a defined symbol which does not have
19325 the THUMB_FUNC attribute, then we must be calling a function which has
19326 the (interfacearm) attribute. We look for the Thumb entry point to that
19327 function and change the branch to refer to that function instead. */
19328 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
19329 && fixP->fx_addsy != NULL
19330 && S_IS_DEFINED (fixP->fx_addsy)
19331 && ! THUMB_IS_FUNC (fixP->fx_addsy))
19332 {
19333 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
19334 }
19335 }
19336 #endif
19337
19338 int
19339 arm_force_relocation (struct fix * fixp)
19340 {
19341 #if defined (OBJ_COFF) && defined (TE_PE)
19342 if (fixp->fx_r_type == BFD_RELOC_RVA)
19343 return 1;
19344 #endif
19345
19346 /* Resolve these relocations even if the symbol is extern or weak. */
19347 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
19348 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
19349 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
19350 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
19351 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
19352 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
19353 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
19354 return 0;
19355
19356 /* Always leave these relocations for the linker. */
19357 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19358 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19359 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19360 return 1;
19361
19362 /* Always generate relocations against function symbols. */
19363 if (fixp->fx_r_type == BFD_RELOC_32
19364 && fixp->fx_addsy
19365 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
19366 return 1;
19367
19368 return generic_force_reloc (fixp);
19369 }
19370
19371 #if defined (OBJ_ELF) || defined (OBJ_COFF)
19372 /* Relocations against function names must be left unadjusted,
19373 so that the linker can use this information to generate interworking
19374 stubs. The MIPS version of this function
19375 also prevents relocations that are mips-16 specific, but I do not
19376 know why it does this.
19377
19378 FIXME:
19379 There is one other problem that ought to be addressed here, but
19380 which currently is not: Taking the address of a label (rather
19381 than a function) and then later jumping to that address. Such
19382 addresses also ought to have their bottom bit set (assuming that
19383 they reside in Thumb code), but at the moment they will not. */
19384
19385 bfd_boolean
19386 arm_fix_adjustable (fixS * fixP)
19387 {
19388 if (fixP->fx_addsy == NULL)
19389 return 1;
19390
19391 /* Preserve relocations against symbols with function type. */
19392 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
19393 return 0;
19394
19395 if (THUMB_IS_FUNC (fixP->fx_addsy)
19396 && fixP->fx_subsy == NULL)
19397 return 0;
19398
19399 /* We need the symbol name for the VTABLE entries. */
19400 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
19401 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19402 return 0;
19403
19404 /* Don't allow symbols to be discarded on GOT related relocs. */
19405 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
19406 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
19407 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
19408 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
19409 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
19410 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
19411 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
19412 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
19413 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
19414 return 0;
19415
19416 /* Similarly for group relocations. */
19417 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19418 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19419 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19420 return 0;
19421
19422 return 1;
19423 }
19424 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
19425
19426 #ifdef OBJ_ELF
19427
19428 const char *
19429 elf32_arm_target_format (void)
19430 {
19431 #ifdef TE_SYMBIAN
19432 return (target_big_endian
19433 ? "elf32-bigarm-symbian"
19434 : "elf32-littlearm-symbian");
19435 #elif defined (TE_VXWORKS)
19436 return (target_big_endian
19437 ? "elf32-bigarm-vxworks"
19438 : "elf32-littlearm-vxworks");
19439 #else
19440 if (target_big_endian)
19441 return "elf32-bigarm";
19442 else
19443 return "elf32-littlearm";
19444 #endif
19445 }
19446
19447 void
19448 armelf_frob_symbol (symbolS * symp,
19449 int * puntp)
19450 {
19451 elf_frob_symbol (symp, puntp);
19452 }
19453 #endif
19454
19455 /* MD interface: Finalization. */
19456
19457 /* A good place to do this, although this was probably not intended
19458 for this kind of use. We need to dump the literal pool before
19459 references are made to a null symbol pointer. */
19460
19461 void
19462 arm_cleanup (void)
19463 {
19464 literal_pool * pool;
19465
19466 for (pool = list_of_pools; pool; pool = pool->next)
19467 {
19468 /* Put it at the end of the relevant section. */
19469 subseg_set (pool->section, pool->sub_section);
19470 #ifdef OBJ_ELF
19471 arm_elf_change_section ();
19472 #endif
19473 s_ltorg (0);
19474 }
19475 }
19476
19477 /* Adjust the symbol table. This marks Thumb symbols as distinct from
19478 ARM ones. */
19479
19480 void
19481 arm_adjust_symtab (void)
19482 {
19483 #ifdef OBJ_COFF
19484 symbolS * sym;
19485
19486 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
19487 {
19488 if (ARM_IS_THUMB (sym))
19489 {
19490 if (THUMB_IS_FUNC (sym))
19491 {
19492 /* Mark the symbol as a Thumb function. */
19493 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
19494 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
19495 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
19496
19497 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
19498 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
19499 else
19500 as_bad (_("%s: unexpected function type: %d"),
19501 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
19502 }
19503 else switch (S_GET_STORAGE_CLASS (sym))
19504 {
19505 case C_EXT:
19506 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
19507 break;
19508 case C_STAT:
19509 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
19510 break;
19511 case C_LABEL:
19512 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
19513 break;
19514 default:
19515 /* Do nothing. */
19516 break;
19517 }
19518 }
19519
19520 if (ARM_IS_INTERWORK (sym))
19521 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
19522 }
19523 #endif
19524 #ifdef OBJ_ELF
19525 symbolS * sym;
19526 char bind;
19527
19528 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
19529 {
19530 if (ARM_IS_THUMB (sym))
19531 {
19532 elf_symbol_type * elf_sym;
19533
19534 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
19535 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
19536
19537 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
19538 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
19539 {
19540 /* If it's a .thumb_func, declare it as so,
19541 otherwise tag label as .code 16. */
19542 if (THUMB_IS_FUNC (sym))
19543 elf_sym->internal_elf_sym.st_info =
19544 ELF_ST_INFO (bind, STT_ARM_TFUNC);
19545 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
19546 elf_sym->internal_elf_sym.st_info =
19547 ELF_ST_INFO (bind, STT_ARM_16BIT);
19548 }
19549 }
19550 }
19551 #endif
19552 }
19553
19554 /* MD interface: Initialization. */
19555
19556 static void
19557 set_constant_flonums (void)
19558 {
19559 int i;
19560
19561 for (i = 0; i < NUM_FLOAT_VALS; i++)
19562 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
19563 abort ();
19564 }
19565
19566 /* Auto-select Thumb mode if it's the only available instruction set for the
19567 given architecture. */
19568
19569 static void
19570 autoselect_thumb_from_cpu_variant (void)
19571 {
19572 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
19573 opcode_select (16);
19574 }
19575
19576 void
19577 md_begin (void)
19578 {
19579 unsigned mach;
19580 unsigned int i;
19581
19582 if ( (arm_ops_hsh = hash_new ()) == NULL
19583 || (arm_cond_hsh = hash_new ()) == NULL
19584 || (arm_shift_hsh = hash_new ()) == NULL
19585 || (arm_psr_hsh = hash_new ()) == NULL
19586 || (arm_v7m_psr_hsh = hash_new ()) == NULL
19587 || (arm_reg_hsh = hash_new ()) == NULL
19588 || (arm_reloc_hsh = hash_new ()) == NULL
19589 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
19590 as_fatal (_("virtual memory exhausted"));
19591
19592 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
19593 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
19594 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
19595 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
19596 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
19597 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
19598 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
19599 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
19600 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
19601 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (PTR) (v7m_psrs + i));
19602 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
19603 hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i));
19604 for (i = 0;
19605 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
19606 i++)
19607 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
19608 (PTR) (barrier_opt_names + i));
19609 #ifdef OBJ_ELF
19610 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
19611 hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i));
19612 #endif
19613
19614 set_constant_flonums ();
19615
19616 /* Set the cpu variant based on the command-line options. We prefer
19617 -mcpu= over -march= if both are set (as for GCC); and we prefer
19618 -mfpu= over any other way of setting the floating point unit.
19619 Use of legacy options with new options are faulted. */
19620 if (legacy_cpu)
19621 {
19622 if (mcpu_cpu_opt || march_cpu_opt)
19623 as_bad (_("use of old and new-style options to set CPU type"));
19624
19625 mcpu_cpu_opt = legacy_cpu;
19626 }
19627 else if (!mcpu_cpu_opt)
19628 mcpu_cpu_opt = march_cpu_opt;
19629
19630 if (legacy_fpu)
19631 {
19632 if (mfpu_opt)
19633 as_bad (_("use of old and new-style options to set FPU type"));
19634
19635 mfpu_opt = legacy_fpu;
19636 }
19637 else if (!mfpu_opt)
19638 {
19639 #if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
19640 /* Some environments specify a default FPU. If they don't, infer it
19641 from the processor. */
19642 if (mcpu_fpu_opt)
19643 mfpu_opt = mcpu_fpu_opt;
19644 else
19645 mfpu_opt = march_fpu_opt;
19646 #else
19647 mfpu_opt = &fpu_default;
19648 #endif
19649 }
19650
19651 if (!mfpu_opt)
19652 {
19653 if (mcpu_cpu_opt != NULL)
19654 mfpu_opt = &fpu_default;
19655 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
19656 mfpu_opt = &fpu_arch_vfp_v2;
19657 else
19658 mfpu_opt = &fpu_arch_fpa;
19659 }
19660
19661 #ifdef CPU_DEFAULT
19662 if (!mcpu_cpu_opt)
19663 {
19664 mcpu_cpu_opt = &cpu_default;
19665 selected_cpu = cpu_default;
19666 }
19667 #else
19668 if (mcpu_cpu_opt)
19669 selected_cpu = *mcpu_cpu_opt;
19670 else
19671 mcpu_cpu_opt = &arm_arch_any;
19672 #endif
19673
19674 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
19675
19676 autoselect_thumb_from_cpu_variant ();
19677
19678 arm_arch_used = thumb_arch_used = arm_arch_none;
19679
19680 #if defined OBJ_COFF || defined OBJ_ELF
19681 {
19682 unsigned int flags = 0;
19683
19684 #if defined OBJ_ELF
19685 flags = meabi_flags;
19686
19687 switch (meabi_flags)
19688 {
19689 case EF_ARM_EABI_UNKNOWN:
19690 #endif
19691 /* Set the flags in the private structure. */
19692 if (uses_apcs_26) flags |= F_APCS26;
19693 if (support_interwork) flags |= F_INTERWORK;
19694 if (uses_apcs_float) flags |= F_APCS_FLOAT;
19695 if (pic_code) flags |= F_PIC;
19696 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
19697 flags |= F_SOFT_FLOAT;
19698
19699 switch (mfloat_abi_opt)
19700 {
19701 case ARM_FLOAT_ABI_SOFT:
19702 case ARM_FLOAT_ABI_SOFTFP:
19703 flags |= F_SOFT_FLOAT;
19704 break;
19705
19706 case ARM_FLOAT_ABI_HARD:
19707 if (flags & F_SOFT_FLOAT)
19708 as_bad (_("hard-float conflicts with specified fpu"));
19709 break;
19710 }
19711
19712 /* Using pure-endian doubles (even if soft-float). */
19713 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
19714 flags |= F_VFP_FLOAT;
19715
19716 #if defined OBJ_ELF
19717 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
19718 flags |= EF_ARM_MAVERICK_FLOAT;
19719 break;
19720
19721 case EF_ARM_EABI_VER4:
19722 case EF_ARM_EABI_VER5:
19723 /* No additional flags to set. */
19724 break;
19725
19726 default:
19727 abort ();
19728 }
19729 #endif
19730 bfd_set_private_flags (stdoutput, flags);
19731
19732 /* We have run out flags in the COFF header to encode the
19733 status of ATPCS support, so instead we create a dummy,
19734 empty, debug section called .arm.atpcs. */
19735 if (atpcs)
19736 {
19737 asection * sec;
19738
19739 sec = bfd_make_section (stdoutput, ".arm.atpcs");
19740
19741 if (sec != NULL)
19742 {
19743 bfd_set_section_flags
19744 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
19745 bfd_set_section_size (stdoutput, sec, 0);
19746 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
19747 }
19748 }
19749 }
19750 #endif
19751
19752 /* Record the CPU type as well. */
19753 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
19754 mach = bfd_mach_arm_iWMMXt2;
19755 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
19756 mach = bfd_mach_arm_iWMMXt;
19757 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
19758 mach = bfd_mach_arm_XScale;
19759 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
19760 mach = bfd_mach_arm_ep9312;
19761 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
19762 mach = bfd_mach_arm_5TE;
19763 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
19764 {
19765 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
19766 mach = bfd_mach_arm_5T;
19767 else
19768 mach = bfd_mach_arm_5;
19769 }
19770 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
19771 {
19772 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
19773 mach = bfd_mach_arm_4T;
19774 else
19775 mach = bfd_mach_arm_4;
19776 }
19777 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
19778 mach = bfd_mach_arm_3M;
19779 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
19780 mach = bfd_mach_arm_3;
19781 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
19782 mach = bfd_mach_arm_2a;
19783 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
19784 mach = bfd_mach_arm_2;
19785 else
19786 mach = bfd_mach_arm_unknown;
19787
19788 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
19789 }
19790
19791 /* Command line processing. */
19792
19793 /* md_parse_option
19794 Invocation line includes a switch not recognized by the base assembler.
19795 See if it's a processor-specific option.
19796
19797 This routine is somewhat complicated by the need for backwards
19798 compatibility (since older releases of gcc can't be changed).
19799 The new options try to make the interface as compatible as
19800 possible with GCC.
19801
19802 New options (supported) are:
19803
19804 -mcpu=<cpu name> Assemble for selected processor
19805 -march=<architecture name> Assemble for selected architecture
19806 -mfpu=<fpu architecture> Assemble for selected FPU.
19807 -EB/-mbig-endian Big-endian
19808 -EL/-mlittle-endian Little-endian
19809 -k Generate PIC code
19810 -mthumb Start in Thumb mode
19811 -mthumb-interwork Code supports ARM/Thumb interworking
19812
19813 For now we will also provide support for:
19814
19815 -mapcs-32 32-bit Program counter
19816 -mapcs-26 26-bit Program counter
19817 -macps-float Floats passed in FP registers
19818 -mapcs-reentrant Reentrant code
19819 -matpcs
19820 (sometime these will probably be replaced with -mapcs=<list of options>
19821 and -matpcs=<list of options>)
19822
19823 The remaining options are only supported for back-wards compatibility.
19824 Cpu variants, the arm part is optional:
19825 -m[arm]1 Currently not supported.
19826 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
19827 -m[arm]3 Arm 3 processor
19828 -m[arm]6[xx], Arm 6 processors
19829 -m[arm]7[xx][t][[d]m] Arm 7 processors
19830 -m[arm]8[10] Arm 8 processors
19831 -m[arm]9[20][tdmi] Arm 9 processors
19832 -mstrongarm[110[0]] StrongARM processors
19833 -mxscale XScale processors
19834 -m[arm]v[2345[t[e]]] Arm architectures
19835 -mall All (except the ARM1)
19836 FP variants:
19837 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
19838 -mfpe-old (No float load/store multiples)
19839 -mvfpxd VFP Single precision
19840 -mvfp All VFP
19841 -mno-fpu Disable all floating point instructions
19842
19843 The following CPU names are recognized:
19844 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
19845 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
19846 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
19847 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
19848 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
19849 arm10t arm10e, arm1020t, arm1020e, arm10200e,
19850 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
19851
19852 */
19853
19854 const char * md_shortopts = "m:k";
19855
19856 #ifdef ARM_BI_ENDIAN
19857 #define OPTION_EB (OPTION_MD_BASE + 0)
19858 #define OPTION_EL (OPTION_MD_BASE + 1)
19859 #else
19860 #if TARGET_BYTES_BIG_ENDIAN
19861 #define OPTION_EB (OPTION_MD_BASE + 0)
19862 #else
19863 #define OPTION_EL (OPTION_MD_BASE + 1)
19864 #endif
19865 #endif
19866 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
19867
19868 struct option md_longopts[] =
19869 {
19870 #ifdef OPTION_EB
19871 {"EB", no_argument, NULL, OPTION_EB},
19872 #endif
19873 #ifdef OPTION_EL
19874 {"EL", no_argument, NULL, OPTION_EL},
19875 #endif
19876 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
19877 {NULL, no_argument, NULL, 0}
19878 };
19879
19880 size_t md_longopts_size = sizeof (md_longopts);
19881
19882 struct arm_option_table
19883 {
19884 char *option; /* Option name to match. */
19885 char *help; /* Help information. */
19886 int *var; /* Variable to change. */
19887 int value; /* What to change it to. */
19888 char *deprecated; /* If non-null, print this message. */
19889 };
19890
19891 struct arm_option_table arm_opts[] =
19892 {
19893 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
19894 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
19895 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
19896 &support_interwork, 1, NULL},
19897 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
19898 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
19899 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
19900 1, NULL},
19901 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
19902 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
19903 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
19904 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
19905 NULL},
19906
19907 /* These are recognized by the assembler, but have no affect on code. */
19908 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
19909 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
19910 {NULL, NULL, NULL, 0, NULL}
19911 };
19912
19913 struct arm_legacy_option_table
19914 {
19915 char *option; /* Option name to match. */
19916 const arm_feature_set **var; /* Variable to change. */
19917 const arm_feature_set value; /* What to change it to. */
19918 char *deprecated; /* If non-null, print this message. */
19919 };
19920
19921 const struct arm_legacy_option_table arm_legacy_opts[] =
19922 {
19923 /* DON'T add any new processors to this list -- we want the whole list
19924 to go away... Add them to the processors table instead. */
19925 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19926 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19927 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19928 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19929 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19930 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19931 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19932 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19933 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19934 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19935 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19936 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19937 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19938 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19939 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19940 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19941 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19942 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19943 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19944 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19945 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19946 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19947 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19948 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19949 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19950 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19951 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19952 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19953 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19954 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19955 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19956 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19957 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19958 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19959 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19960 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19961 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19962 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19963 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19964 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19965 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19966 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19967 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19968 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19969 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19970 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19971 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19972 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19973 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19974 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19975 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19976 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19977 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19978 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19979 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19980 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19981 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19982 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19983 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19984 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19985 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19986 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19987 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19988 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19989 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19990 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19991 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19992 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19993 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
19994 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
19995 N_("use -mcpu=strongarm110")},
19996 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
19997 N_("use -mcpu=strongarm1100")},
19998 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
19999 N_("use -mcpu=strongarm1110")},
20000 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
20001 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
20002 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
20003
20004 /* Architecture variants -- don't add any more to this list either. */
20005 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
20006 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
20007 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
20008 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
20009 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
20010 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
20011 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
20012 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
20013 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
20014 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
20015 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
20016 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
20017 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
20018 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
20019 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
20020 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
20021 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
20022 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
20023
20024 /* Floating point variants -- don't add any more to this list either. */
20025 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
20026 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
20027 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
20028 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
20029 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
20030
20031 {NULL, NULL, ARM_ARCH_NONE, NULL}
20032 };
20033
20034 struct arm_cpu_option_table
20035 {
20036 char *name;
20037 const arm_feature_set value;
20038 /* For some CPUs we assume an FPU unless the user explicitly sets
20039 -mfpu=... */
20040 const arm_feature_set default_fpu;
20041 /* The canonical name of the CPU, or NULL to use NAME converted to upper
20042 case. */
20043 const char *canonical_name;
20044 };
20045
20046 /* This list should, at a minimum, contain all the cpu names
20047 recognized by GCC. */
20048 static const struct arm_cpu_option_table arm_cpus[] =
20049 {
20050 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
20051 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
20052 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
20053 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20054 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20055 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20056 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20057 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20058 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20059 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20060 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20061 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20062 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20063 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20064 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20065 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20066 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20067 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20068 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20069 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20070 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20071 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20072 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20073 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20074 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20075 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20076 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20077 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20078 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20079 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20080 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20081 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20082 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20083 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20084 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20085 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20086 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20087 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20088 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20089 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
20090 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20091 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20092 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20093 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20094 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20095 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20096 /* For V5 or later processors we default to using VFP; but the user
20097 should really set the FPU type explicitly. */
20098 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20099 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20100 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20101 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20102 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20103 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20104 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
20105 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20106 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20107 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
20108 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20109 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20110 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20111 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20112 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20113 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
20114 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20115 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20116 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20117 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
20118 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20119 {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL},
20120 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20121 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
20122 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
20123 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
20124 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
20125 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
20126 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
20127 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
20128 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
20129 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
20130 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
20131 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
20132 | FPU_NEON_EXT_V1),
20133 NULL},
20134 {"cortex-a9", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
20135 | FPU_NEON_EXT_V1),
20136 NULL},
20137 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
20138 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
20139 {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL},
20140 /* ??? XSCALE is really an architecture. */
20141 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
20142 /* ??? iwmmxt is not a processor. */
20143 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
20144 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
20145 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
20146 /* Maverick */
20147 {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
20148 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
20149 };
20150
20151 struct arm_arch_option_table
20152 {
20153 char *name;
20154 const arm_feature_set value;
20155 const arm_feature_set default_fpu;
20156 };
20157
20158 /* This list should, at a minimum, contain all the architecture names
20159 recognized by GCC. */
20160 static const struct arm_arch_option_table arm_archs[] =
20161 {
20162 {"all", ARM_ANY, FPU_ARCH_FPA},
20163 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
20164 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
20165 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
20166 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
20167 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
20168 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
20169 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
20170 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
20171 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
20172 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
20173 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
20174 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
20175 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
20176 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
20177 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
20178 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
20179 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
20180 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
20181 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
20182 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
20183 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
20184 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
20185 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
20186 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
20187 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
20188 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
20189 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
20190 /* The official spelling of the ARMv7 profile variants is the dashed form.
20191 Accept the non-dashed form for compatibility with old toolchains. */
20192 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20193 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20194 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
20195 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20196 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20197 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
20198 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
20199 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
20200 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
20201 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
20202 };
20203
20204 /* ISA extensions in the co-processor space. */
20205 struct arm_option_cpu_value_table
20206 {
20207 char *name;
20208 const arm_feature_set value;
20209 };
20210
20211 static const struct arm_option_cpu_value_table arm_extensions[] =
20212 {
20213 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
20214 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
20215 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
20216 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
20217 {NULL, ARM_ARCH_NONE}
20218 };
20219
20220 /* This list should, at a minimum, contain all the fpu names
20221 recognized by GCC. */
20222 static const struct arm_option_cpu_value_table arm_fpus[] =
20223 {
20224 {"softfpa", FPU_NONE},
20225 {"fpe", FPU_ARCH_FPE},
20226 {"fpe2", FPU_ARCH_FPE},
20227 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
20228 {"fpa", FPU_ARCH_FPA},
20229 {"fpa10", FPU_ARCH_FPA},
20230 {"fpa11", FPU_ARCH_FPA},
20231 {"arm7500fe", FPU_ARCH_FPA},
20232 {"softvfp", FPU_ARCH_VFP},
20233 {"softvfp+vfp", FPU_ARCH_VFP_V2},
20234 {"vfp", FPU_ARCH_VFP_V2},
20235 {"vfp9", FPU_ARCH_VFP_V2},
20236 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
20237 {"vfp10", FPU_ARCH_VFP_V2},
20238 {"vfp10-r0", FPU_ARCH_VFP_V1},
20239 {"vfpxd", FPU_ARCH_VFP_V1xD},
20240 {"vfpv2", FPU_ARCH_VFP_V2},
20241 {"vfpv3", FPU_ARCH_VFP_V3},
20242 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
20243 {"arm1020t", FPU_ARCH_VFP_V1},
20244 {"arm1020e", FPU_ARCH_VFP_V2},
20245 {"arm1136jfs", FPU_ARCH_VFP_V2},
20246 {"arm1136jf-s", FPU_ARCH_VFP_V2},
20247 {"maverick", FPU_ARCH_MAVERICK},
20248 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
20249 {NULL, ARM_ARCH_NONE}
20250 };
20251
20252 struct arm_option_value_table
20253 {
20254 char *name;
20255 long value;
20256 };
20257
20258 static const struct arm_option_value_table arm_float_abis[] =
20259 {
20260 {"hard", ARM_FLOAT_ABI_HARD},
20261 {"softfp", ARM_FLOAT_ABI_SOFTFP},
20262 {"soft", ARM_FLOAT_ABI_SOFT},
20263 {NULL, 0}
20264 };
20265
20266 #ifdef OBJ_ELF
20267 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
20268 static const struct arm_option_value_table arm_eabis[] =
20269 {
20270 {"gnu", EF_ARM_EABI_UNKNOWN},
20271 {"4", EF_ARM_EABI_VER4},
20272 {"5", EF_ARM_EABI_VER5},
20273 {NULL, 0}
20274 };
20275 #endif
20276
20277 struct arm_long_option_table
20278 {
20279 char * option; /* Substring to match. */
20280 char * help; /* Help information. */
20281 int (* func) (char * subopt); /* Function to decode sub-option. */
20282 char * deprecated; /* If non-null, print this message. */
20283 };
20284
20285 static int
20286 arm_parse_extension (char * str, const arm_feature_set **opt_p)
20287 {
20288 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
20289
20290 /* Copy the feature set, so that we can modify it. */
20291 *ext_set = **opt_p;
20292 *opt_p = ext_set;
20293
20294 while (str != NULL && *str != 0)
20295 {
20296 const struct arm_option_cpu_value_table * opt;
20297 char * ext;
20298 int optlen;
20299
20300 if (*str != '+')
20301 {
20302 as_bad (_("invalid architectural extension"));
20303 return 0;
20304 }
20305
20306 str++;
20307 ext = strchr (str, '+');
20308
20309 if (ext != NULL)
20310 optlen = ext - str;
20311 else
20312 optlen = strlen (str);
20313
20314 if (optlen == 0)
20315 {
20316 as_bad (_("missing architectural extension"));
20317 return 0;
20318 }
20319
20320 for (opt = arm_extensions; opt->name != NULL; opt++)
20321 if (strncmp (opt->name, str, optlen) == 0)
20322 {
20323 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
20324 break;
20325 }
20326
20327 if (opt->name == NULL)
20328 {
20329 as_bad (_("unknown architectural extension `%s'"), str);
20330 return 0;
20331 }
20332
20333 str = ext;
20334 };
20335
20336 return 1;
20337 }
20338
20339 static int
20340 arm_parse_cpu (char * str)
20341 {
20342 const struct arm_cpu_option_table * opt;
20343 char * ext = strchr (str, '+');
20344 int optlen;
20345
20346 if (ext != NULL)
20347 optlen = ext - str;
20348 else
20349 optlen = strlen (str);
20350
20351 if (optlen == 0)
20352 {
20353 as_bad (_("missing cpu name `%s'"), str);
20354 return 0;
20355 }
20356
20357 for (opt = arm_cpus; opt->name != NULL; opt++)
20358 if (strncmp (opt->name, str, optlen) == 0)
20359 {
20360 mcpu_cpu_opt = &opt->value;
20361 mcpu_fpu_opt = &opt->default_fpu;
20362 if (opt->canonical_name)
20363 strcpy (selected_cpu_name, opt->canonical_name);
20364 else
20365 {
20366 int i;
20367 for (i = 0; i < optlen; i++)
20368 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20369 selected_cpu_name[i] = 0;
20370 }
20371
20372 if (ext != NULL)
20373 return arm_parse_extension (ext, &mcpu_cpu_opt);
20374
20375 return 1;
20376 }
20377
20378 as_bad (_("unknown cpu `%s'"), str);
20379 return 0;
20380 }
20381
20382 static int
20383 arm_parse_arch (char * str)
20384 {
20385 const struct arm_arch_option_table *opt;
20386 char *ext = strchr (str, '+');
20387 int optlen;
20388
20389 if (ext != NULL)
20390 optlen = ext - str;
20391 else
20392 optlen = strlen (str);
20393
20394 if (optlen == 0)
20395 {
20396 as_bad (_("missing architecture name `%s'"), str);
20397 return 0;
20398 }
20399
20400 for (opt = arm_archs; opt->name != NULL; opt++)
20401 if (streq (opt->name, str))
20402 {
20403 march_cpu_opt = &opt->value;
20404 march_fpu_opt = &opt->default_fpu;
20405 strcpy (selected_cpu_name, opt->name);
20406
20407 if (ext != NULL)
20408 return arm_parse_extension (ext, &march_cpu_opt);
20409
20410 return 1;
20411 }
20412
20413 as_bad (_("unknown architecture `%s'\n"), str);
20414 return 0;
20415 }
20416
20417 static int
20418 arm_parse_fpu (char * str)
20419 {
20420 const struct arm_option_cpu_value_table * opt;
20421
20422 for (opt = arm_fpus; opt->name != NULL; opt++)
20423 if (streq (opt->name, str))
20424 {
20425 mfpu_opt = &opt->value;
20426 return 1;
20427 }
20428
20429 as_bad (_("unknown floating point format `%s'\n"), str);
20430 return 0;
20431 }
20432
20433 static int
20434 arm_parse_float_abi (char * str)
20435 {
20436 const struct arm_option_value_table * opt;
20437
20438 for (opt = arm_float_abis; opt->name != NULL; opt++)
20439 if (streq (opt->name, str))
20440 {
20441 mfloat_abi_opt = opt->value;
20442 return 1;
20443 }
20444
20445 as_bad (_("unknown floating point abi `%s'\n"), str);
20446 return 0;
20447 }
20448
20449 #ifdef OBJ_ELF
20450 static int
20451 arm_parse_eabi (char * str)
20452 {
20453 const struct arm_option_value_table *opt;
20454
20455 for (opt = arm_eabis; opt->name != NULL; opt++)
20456 if (streq (opt->name, str))
20457 {
20458 meabi_flags = opt->value;
20459 return 1;
20460 }
20461 as_bad (_("unknown EABI `%s'\n"), str);
20462 return 0;
20463 }
20464 #endif
20465
20466 struct arm_long_option_table arm_long_opts[] =
20467 {
20468 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
20469 arm_parse_cpu, NULL},
20470 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
20471 arm_parse_arch, NULL},
20472 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
20473 arm_parse_fpu, NULL},
20474 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
20475 arm_parse_float_abi, NULL},
20476 #ifdef OBJ_ELF
20477 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
20478 arm_parse_eabi, NULL},
20479 #endif
20480 {NULL, NULL, 0, NULL}
20481 };
20482
20483 int
20484 md_parse_option (int c, char * arg)
20485 {
20486 struct arm_option_table *opt;
20487 const struct arm_legacy_option_table *fopt;
20488 struct arm_long_option_table *lopt;
20489
20490 switch (c)
20491 {
20492 #ifdef OPTION_EB
20493 case OPTION_EB:
20494 target_big_endian = 1;
20495 break;
20496 #endif
20497
20498 #ifdef OPTION_EL
20499 case OPTION_EL:
20500 target_big_endian = 0;
20501 break;
20502 #endif
20503
20504 case OPTION_FIX_V4BX:
20505 fix_v4bx = TRUE;
20506 break;
20507
20508 case 'a':
20509 /* Listing option. Just ignore these, we don't support additional
20510 ones. */
20511 return 0;
20512
20513 default:
20514 for (opt = arm_opts; opt->option != NULL; opt++)
20515 {
20516 if (c == opt->option[0]
20517 && ((arg == NULL && opt->option[1] == 0)
20518 || streq (arg, opt->option + 1)))
20519 {
20520 #if WARN_DEPRECATED
20521 /* If the option is deprecated, tell the user. */
20522 if (opt->deprecated != NULL)
20523 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20524 arg ? arg : "", _(opt->deprecated));
20525 #endif
20526
20527 if (opt->var != NULL)
20528 *opt->var = opt->value;
20529
20530 return 1;
20531 }
20532 }
20533
20534 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
20535 {
20536 if (c == fopt->option[0]
20537 && ((arg == NULL && fopt->option[1] == 0)
20538 || streq (arg, fopt->option + 1)))
20539 {
20540 #if WARN_DEPRECATED
20541 /* If the option is deprecated, tell the user. */
20542 if (fopt->deprecated != NULL)
20543 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20544 arg ? arg : "", _(fopt->deprecated));
20545 #endif
20546
20547 if (fopt->var != NULL)
20548 *fopt->var = &fopt->value;
20549
20550 return 1;
20551 }
20552 }
20553
20554 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20555 {
20556 /* These options are expected to have an argument. */
20557 if (c == lopt->option[0]
20558 && arg != NULL
20559 && strncmp (arg, lopt->option + 1,
20560 strlen (lopt->option + 1)) == 0)
20561 {
20562 #if WARN_DEPRECATED
20563 /* If the option is deprecated, tell the user. */
20564 if (lopt->deprecated != NULL)
20565 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
20566 _(lopt->deprecated));
20567 #endif
20568
20569 /* Call the sup-option parser. */
20570 return lopt->func (arg + strlen (lopt->option) - 1);
20571 }
20572 }
20573
20574 return 0;
20575 }
20576
20577 return 1;
20578 }
20579
20580 void
20581 md_show_usage (FILE * fp)
20582 {
20583 struct arm_option_table *opt;
20584 struct arm_long_option_table *lopt;
20585
20586 fprintf (fp, _(" ARM-specific assembler options:\n"));
20587
20588 for (opt = arm_opts; opt->option != NULL; opt++)
20589 if (opt->help != NULL)
20590 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
20591
20592 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20593 if (lopt->help != NULL)
20594 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
20595
20596 #ifdef OPTION_EB
20597 fprintf (fp, _("\
20598 -EB assemble code for a big-endian cpu\n"));
20599 #endif
20600
20601 #ifdef OPTION_EL
20602 fprintf (fp, _("\
20603 -EL assemble code for a little-endian cpu\n"));
20604 #endif
20605
20606 fprintf (fp, _("\
20607 --fix-v4bx Allow BX in ARMv4 code\n"));
20608 }
20609
20610
20611 #ifdef OBJ_ELF
20612 typedef struct
20613 {
20614 int val;
20615 arm_feature_set flags;
20616 } cpu_arch_ver_table;
20617
20618 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
20619 least features first. */
20620 static const cpu_arch_ver_table cpu_arch_ver[] =
20621 {
20622 {1, ARM_ARCH_V4},
20623 {2, ARM_ARCH_V4T},
20624 {3, ARM_ARCH_V5},
20625 {4, ARM_ARCH_V5TE},
20626 {5, ARM_ARCH_V5TEJ},
20627 {6, ARM_ARCH_V6},
20628 {7, ARM_ARCH_V6Z},
20629 {9, ARM_ARCH_V6K},
20630 {9, ARM_ARCH_V6M},
20631 {8, ARM_ARCH_V6T2},
20632 {10, ARM_ARCH_V7A},
20633 {10, ARM_ARCH_V7R},
20634 {10, ARM_ARCH_V7M},
20635 {0, ARM_ARCH_NONE}
20636 };
20637
20638 /* Set the public EABI object attributes. */
20639 static void
20640 aeabi_set_public_attributes (void)
20641 {
20642 int arch;
20643 arm_feature_set flags;
20644 arm_feature_set tmp;
20645 const cpu_arch_ver_table *p;
20646
20647 /* Choose the architecture based on the capabilities of the requested cpu
20648 (if any) and/or the instructions actually used. */
20649 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
20650 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
20651 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
20652 /*Allow the user to override the reported architecture. */
20653 if (object_arch)
20654 {
20655 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
20656 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
20657 }
20658
20659 tmp = flags;
20660 arch = 0;
20661 for (p = cpu_arch_ver; p->val; p++)
20662 {
20663 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
20664 {
20665 arch = p->val;
20666 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
20667 }
20668 }
20669
20670 /* Tag_CPU_name. */
20671 if (selected_cpu_name[0])
20672 {
20673 char *p;
20674
20675 p = selected_cpu_name;
20676 if (strncmp (p, "armv", 4) == 0)
20677 {
20678 int i;
20679
20680 p += 4;
20681 for (i = 0; p[i]; i++)
20682 p[i] = TOUPPER (p[i]);
20683 }
20684 bfd_elf_add_proc_attr_string (stdoutput, 5, p);
20685 }
20686 /* Tag_CPU_arch. */
20687 bfd_elf_add_proc_attr_int (stdoutput, 6, arch);
20688 /* Tag_CPU_arch_profile. */
20689 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
20690 bfd_elf_add_proc_attr_int (stdoutput, 7, 'A');
20691 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
20692 bfd_elf_add_proc_attr_int (stdoutput, 7, 'R');
20693 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
20694 bfd_elf_add_proc_attr_int (stdoutput, 7, 'M');
20695 /* Tag_ARM_ISA_use. */
20696 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_full))
20697 bfd_elf_add_proc_attr_int (stdoutput, 8, 1);
20698 /* Tag_THUMB_ISA_use. */
20699 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_full))
20700 bfd_elf_add_proc_attr_int (stdoutput, 9,
20701 ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2) ? 2 : 1);
20702 /* Tag_VFP_arch. */
20703 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_d32)
20704 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_d32))
20705 bfd_elf_add_proc_attr_int (stdoutput, 10, 4);
20706 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v3)
20707 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v3))
20708 bfd_elf_add_proc_attr_int (stdoutput, 10, 3);
20709 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v2)
20710 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v2))
20711 bfd_elf_add_proc_attr_int (stdoutput, 10, 2);
20712 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1)
20713 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1)
20714 || ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1xd)
20715 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1xd))
20716 bfd_elf_add_proc_attr_int (stdoutput, 10, 1);
20717 /* Tag_WMMX_arch. */
20718 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_cext_iwmmxt)
20719 || ARM_CPU_HAS_FEATURE (arm_arch_used, arm_cext_iwmmxt))
20720 bfd_elf_add_proc_attr_int (stdoutput, 11, 1);
20721 /* Tag_NEON_arch. */
20722 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_neon_ext_v1)
20723 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_neon_ext_v1))
20724 bfd_elf_add_proc_attr_int (stdoutput, 12, 1);
20725 }
20726
20727 /* Add the default contents for the .ARM.attributes section. */
20728 void
20729 arm_md_end (void)
20730 {
20731 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
20732 return;
20733
20734 aeabi_set_public_attributes ();
20735 }
20736 #endif /* OBJ_ELF */
20737
20738
20739 /* Parse a .cpu directive. */
20740
20741 static void
20742 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
20743 {
20744 const struct arm_cpu_option_table *opt;
20745 char *name;
20746 char saved_char;
20747
20748 name = input_line_pointer;
20749 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
20750 input_line_pointer++;
20751 saved_char = *input_line_pointer;
20752 *input_line_pointer = 0;
20753
20754 /* Skip the first "all" entry. */
20755 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
20756 if (streq (opt->name, name))
20757 {
20758 mcpu_cpu_opt = &opt->value;
20759 selected_cpu = opt->value;
20760 if (opt->canonical_name)
20761 strcpy (selected_cpu_name, opt->canonical_name);
20762 else
20763 {
20764 int i;
20765 for (i = 0; opt->name[i]; i++)
20766 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20767 selected_cpu_name[i] = 0;
20768 }
20769 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20770 *input_line_pointer = saved_char;
20771 demand_empty_rest_of_line ();
20772 return;
20773 }
20774 as_bad (_("unknown cpu `%s'"), name);
20775 *input_line_pointer = saved_char;
20776 ignore_rest_of_line ();
20777 }
20778
20779
20780 /* Parse a .arch directive. */
20781
20782 static void
20783 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
20784 {
20785 const struct arm_arch_option_table *opt;
20786 char saved_char;
20787 char *name;
20788
20789 name = input_line_pointer;
20790 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
20791 input_line_pointer++;
20792 saved_char = *input_line_pointer;
20793 *input_line_pointer = 0;
20794
20795 /* Skip the first "all" entry. */
20796 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20797 if (streq (opt->name, name))
20798 {
20799 mcpu_cpu_opt = &opt->value;
20800 selected_cpu = opt->value;
20801 strcpy (selected_cpu_name, opt->name);
20802 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20803 *input_line_pointer = saved_char;
20804 demand_empty_rest_of_line ();
20805 return;
20806 }
20807
20808 as_bad (_("unknown architecture `%s'\n"), name);
20809 *input_line_pointer = saved_char;
20810 ignore_rest_of_line ();
20811 }
20812
20813
20814 /* Parse a .object_arch directive. */
20815
20816 static void
20817 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
20818 {
20819 const struct arm_arch_option_table *opt;
20820 char saved_char;
20821 char *name;
20822
20823 name = input_line_pointer;
20824 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
20825 input_line_pointer++;
20826 saved_char = *input_line_pointer;
20827 *input_line_pointer = 0;
20828
20829 /* Skip the first "all" entry. */
20830 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20831 if (streq (opt->name, name))
20832 {
20833 object_arch = &opt->value;
20834 *input_line_pointer = saved_char;
20835 demand_empty_rest_of_line ();
20836 return;
20837 }
20838
20839 as_bad (_("unknown architecture `%s'\n"), name);
20840 *input_line_pointer = saved_char;
20841 ignore_rest_of_line ();
20842 }
20843
20844
20845 /* Parse a .fpu directive. */
20846
20847 static void
20848 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
20849 {
20850 const struct arm_option_cpu_value_table *opt;
20851 char saved_char;
20852 char *name;
20853
20854 name = input_line_pointer;
20855 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
20856 input_line_pointer++;
20857 saved_char = *input_line_pointer;
20858 *input_line_pointer = 0;
20859
20860 for (opt = arm_fpus; opt->name != NULL; opt++)
20861 if (streq (opt->name, name))
20862 {
20863 mfpu_opt = &opt->value;
20864 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20865 *input_line_pointer = saved_char;
20866 demand_empty_rest_of_line ();
20867 return;
20868 }
20869
20870 as_bad (_("unknown floating point format `%s'\n"), name);
20871 *input_line_pointer = saved_char;
20872 ignore_rest_of_line ();
20873 }
20874
20875 /* Copy symbol information. */
20876 void
20877 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
20878 {
20879 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
20880 }
This page took 0.537681 seconds and 5 git commands to generate.