82562d7e96fe0efe83b8431487aa2666f63ddb78
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
1 /* tc-arm.c -- Assemble for the ARM
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007
4 Free Software Foundation, Inc.
5 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
6 Modified by David Taylor (dtaylor@armltd.co.uk)
7 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
8 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
9 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
10
11 This file is part of GAS, the GNU Assembler.
12
13 GAS is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 3, or (at your option)
16 any later version.
17
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with GAS; see the file COPYING. If not, write to the Free
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 02110-1301, USA. */
27
28 #include <limits.h>
29 #include <stdarg.h>
30 #define NO_RELOC 0
31 #include "as.h"
32 #include "safe-ctype.h"
33 #include "subsegs.h"
34 #include "obstack.h"
35
36 #include "opcode/arm.h"
37
38 #ifdef OBJ_ELF
39 #include "elf/arm.h"
40 #include "dw2gencfi.h"
41 #endif
42
43 #include "dwarf2dbg.h"
44
45 #define WARN_DEPRECATED 1
46
47 #ifdef OBJ_ELF
48 /* Must be at least the size of the largest unwind opcode (currently two). */
49 #define ARM_OPCODE_CHUNK_SIZE 8
50
51 /* This structure holds the unwinding state. */
52
53 static struct
54 {
55 symbolS * proc_start;
56 symbolS * table_entry;
57 symbolS * personality_routine;
58 int personality_index;
59 /* The segment containing the function. */
60 segT saved_seg;
61 subsegT saved_subseg;
62 /* Opcodes generated from this function. */
63 unsigned char * opcodes;
64 int opcode_count;
65 int opcode_alloc;
66 /* The number of bytes pushed to the stack. */
67 offsetT frame_size;
68 /* We don't add stack adjustment opcodes immediately so that we can merge
69 multiple adjustments. We can also omit the final adjustment
70 when using a frame pointer. */
71 offsetT pending_offset;
72 /* These two fields are set by both unwind_movsp and unwind_setfp. They
73 hold the reg+offset to use when restoring sp from a frame pointer. */
74 offsetT fp_offset;
75 int fp_reg;
76 /* Nonzero if an unwind_setfp directive has been seen. */
77 unsigned fp_used:1;
78 /* Nonzero if the last opcode restores sp from fp_reg. */
79 unsigned sp_restored:1;
80 } unwind;
81
82 /* Bit N indicates that an R_ARM_NONE relocation has been output for
83 __aeabi_unwind_cpp_prN already if set. This enables dependencies to be
84 emitted only once per section, to save unnecessary bloat. */
85 static unsigned int marked_pr_dependency = 0;
86
87 #endif /* OBJ_ELF */
88
89 /* Results from operand parsing worker functions. */
90
91 typedef enum
92 {
93 PARSE_OPERAND_SUCCESS,
94 PARSE_OPERAND_FAIL,
95 PARSE_OPERAND_FAIL_NO_BACKTRACK
96 } parse_operand_result;
97
98 enum arm_float_abi
99 {
100 ARM_FLOAT_ABI_HARD,
101 ARM_FLOAT_ABI_SOFTFP,
102 ARM_FLOAT_ABI_SOFT
103 };
104
105 /* Types of processor to assemble for. */
106 #ifndef CPU_DEFAULT
107 #if defined __XSCALE__
108 #define CPU_DEFAULT ARM_ARCH_XSCALE
109 #else
110 #if defined __thumb__
111 #define CPU_DEFAULT ARM_ARCH_V5T
112 #endif
113 #endif
114 #endif
115
116 #ifndef FPU_DEFAULT
117 # ifdef TE_LINUX
118 # define FPU_DEFAULT FPU_ARCH_FPA
119 # elif defined (TE_NetBSD)
120 # ifdef OBJ_ELF
121 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
122 # else
123 /* Legacy a.out format. */
124 # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
125 # endif
126 # elif defined (TE_VXWORKS)
127 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
128 # else
129 /* For backwards compatibility, default to FPA. */
130 # define FPU_DEFAULT FPU_ARCH_FPA
131 # endif
132 #endif /* ifndef FPU_DEFAULT */
133
134 #define streq(a, b) (strcmp (a, b) == 0)
135
136 static arm_feature_set cpu_variant;
137 static arm_feature_set arm_arch_used;
138 static arm_feature_set thumb_arch_used;
139
140 /* Flags stored in private area of BFD structure. */
141 static int uses_apcs_26 = FALSE;
142 static int atpcs = FALSE;
143 static int support_interwork = FALSE;
144 static int uses_apcs_float = FALSE;
145 static int pic_code = FALSE;
146
147 /* Variables that we set while parsing command-line options. Once all
148 options have been read we re-process these values to set the real
149 assembly flags. */
150 static const arm_feature_set *legacy_cpu = NULL;
151 static const arm_feature_set *legacy_fpu = NULL;
152
153 static const arm_feature_set *mcpu_cpu_opt = NULL;
154 static const arm_feature_set *mcpu_fpu_opt = NULL;
155 static const arm_feature_set *march_cpu_opt = NULL;
156 static const arm_feature_set *march_fpu_opt = NULL;
157 static const arm_feature_set *mfpu_opt = NULL;
158 static const arm_feature_set *object_arch = NULL;
159
160 /* Constants for known architecture features. */
161 static const arm_feature_set fpu_default = FPU_DEFAULT;
162 static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
163 static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
164 static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
165 static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
166 static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
167 static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
168 static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
169 static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
170
171 #ifdef CPU_DEFAULT
172 static const arm_feature_set cpu_default = CPU_DEFAULT;
173 #endif
174
175 static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
176 static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
177 static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
178 static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
179 static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
180 static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
181 static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
182 static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
183 static const arm_feature_set arm_ext_v4t_5 =
184 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
185 static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
186 static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
187 static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
188 static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
189 static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
190 static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
191 static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
192 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
193 static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
194 static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
195 static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
196 static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
197 static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
198 static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
199
200 static const arm_feature_set arm_arch_any = ARM_ANY;
201 static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
202 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
203 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
204
205 static const arm_feature_set arm_cext_iwmmxt2 =
206 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
207 static const arm_feature_set arm_cext_iwmmxt =
208 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
209 static const arm_feature_set arm_cext_xscale =
210 ARM_FEATURE (0, ARM_CEXT_XSCALE);
211 static const arm_feature_set arm_cext_maverick =
212 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
213 static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
214 static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
215 static const arm_feature_set fpu_vfp_ext_v1xd =
216 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
217 static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
218 static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
219 static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
220 static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
221 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
222 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
223
224 static int mfloat_abi_opt = -1;
225 /* Record user cpu selection for object attributes. */
226 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
227 /* Must be long enough to hold any of the names in arm_cpus. */
228 static char selected_cpu_name[16];
229 #ifdef OBJ_ELF
230 # ifdef EABI_DEFAULT
231 static int meabi_flags = EABI_DEFAULT;
232 # else
233 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
234 # endif
235
236 bfd_boolean
237 arm_is_eabi(void)
238 {
239 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
240 }
241 #endif
242
243 #ifdef OBJ_ELF
244 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
245 symbolS * GOT_symbol;
246 #endif
247
248 /* 0: assemble for ARM,
249 1: assemble for Thumb,
250 2: assemble for Thumb even though target CPU does not support thumb
251 instructions. */
252 static int thumb_mode = 0;
253
254 /* If unified_syntax is true, we are processing the new unified
255 ARM/Thumb syntax. Important differences from the old ARM mode:
256
257 - Immediate operands do not require a # prefix.
258 - Conditional affixes always appear at the end of the
259 instruction. (For backward compatibility, those instructions
260 that formerly had them in the middle, continue to accept them
261 there.)
262 - The IT instruction may appear, and if it does is validated
263 against subsequent conditional affixes. It does not generate
264 machine code.
265
266 Important differences from the old Thumb mode:
267
268 - Immediate operands do not require a # prefix.
269 - Most of the V6T2 instructions are only available in unified mode.
270 - The .N and .W suffixes are recognized and honored (it is an error
271 if they cannot be honored).
272 - All instructions set the flags if and only if they have an 's' affix.
273 - Conditional affixes may be used. They are validated against
274 preceding IT instructions. Unlike ARM mode, you cannot use a
275 conditional affix except in the scope of an IT instruction. */
276
277 static bfd_boolean unified_syntax = FALSE;
278
279 enum neon_el_type
280 {
281 NT_invtype,
282 NT_untyped,
283 NT_integer,
284 NT_float,
285 NT_poly,
286 NT_signed,
287 NT_unsigned
288 };
289
290 struct neon_type_el
291 {
292 enum neon_el_type type;
293 unsigned size;
294 };
295
296 #define NEON_MAX_TYPE_ELS 4
297
298 struct neon_type
299 {
300 struct neon_type_el el[NEON_MAX_TYPE_ELS];
301 unsigned elems;
302 };
303
304 struct arm_it
305 {
306 const char * error;
307 unsigned long instruction;
308 int size;
309 int size_req;
310 int cond;
311 /* "uncond_value" is set to the value in place of the conditional field in
312 unconditional versions of the instruction, or -1 if nothing is
313 appropriate. */
314 int uncond_value;
315 struct neon_type vectype;
316 /* Set to the opcode if the instruction needs relaxation.
317 Zero if the instruction is not relaxed. */
318 unsigned long relax;
319 struct
320 {
321 bfd_reloc_code_real_type type;
322 expressionS exp;
323 int pc_rel;
324 } reloc;
325
326 struct
327 {
328 unsigned reg;
329 signed int imm;
330 struct neon_type_el vectype;
331 unsigned present : 1; /* Operand present. */
332 unsigned isreg : 1; /* Operand was a register. */
333 unsigned immisreg : 1; /* .imm field is a second register. */
334 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
335 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
336 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
337 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
338 instructions. This allows us to disambiguate ARM <-> vector insns. */
339 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
340 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
341 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
342 unsigned issingle : 1; /* Operand is VFP single-precision register. */
343 unsigned hasreloc : 1; /* Operand has relocation suffix. */
344 unsigned writeback : 1; /* Operand has trailing ! */
345 unsigned preind : 1; /* Preindexed address. */
346 unsigned postind : 1; /* Postindexed address. */
347 unsigned negative : 1; /* Index register was negated. */
348 unsigned shifted : 1; /* Shift applied to operation. */
349 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
350 } operands[6];
351 };
352
353 static struct arm_it inst;
354
355 #define NUM_FLOAT_VALS 8
356
357 const char * fp_const[] =
358 {
359 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
360 };
361
362 /* Number of littlenums required to hold an extended precision number. */
363 #define MAX_LITTLENUMS 6
364
365 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
366
367 #define FAIL (-1)
368 #define SUCCESS (0)
369
370 #define SUFF_S 1
371 #define SUFF_D 2
372 #define SUFF_E 3
373 #define SUFF_P 4
374
375 #define CP_T_X 0x00008000
376 #define CP_T_Y 0x00400000
377
378 #define CONDS_BIT 0x00100000
379 #define LOAD_BIT 0x00100000
380
381 #define DOUBLE_LOAD_FLAG 0x00000001
382
383 struct asm_cond
384 {
385 const char * template;
386 unsigned long value;
387 };
388
389 #define COND_ALWAYS 0xE
390
391 struct asm_psr
392 {
393 const char *template;
394 unsigned long field;
395 };
396
397 struct asm_barrier_opt
398 {
399 const char *template;
400 unsigned long value;
401 };
402
403 /* The bit that distinguishes CPSR and SPSR. */
404 #define SPSR_BIT (1 << 22)
405
406 /* The individual PSR flag bits. */
407 #define PSR_c (1 << 16)
408 #define PSR_x (1 << 17)
409 #define PSR_s (1 << 18)
410 #define PSR_f (1 << 19)
411
412 struct reloc_entry
413 {
414 char *name;
415 bfd_reloc_code_real_type reloc;
416 };
417
418 enum vfp_reg_pos
419 {
420 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
421 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
422 };
423
424 enum vfp_ldstm_type
425 {
426 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
427 };
428
429 /* Bits for DEFINED field in neon_typed_alias. */
430 #define NTA_HASTYPE 1
431 #define NTA_HASINDEX 2
432
433 struct neon_typed_alias
434 {
435 unsigned char defined;
436 unsigned char index;
437 struct neon_type_el eltype;
438 };
439
440 /* ARM register categories. This includes coprocessor numbers and various
441 architecture extensions' registers. */
442 enum arm_reg_type
443 {
444 REG_TYPE_RN,
445 REG_TYPE_CP,
446 REG_TYPE_CN,
447 REG_TYPE_FN,
448 REG_TYPE_VFS,
449 REG_TYPE_VFD,
450 REG_TYPE_NQ,
451 REG_TYPE_VFSD,
452 REG_TYPE_NDQ,
453 REG_TYPE_NSDQ,
454 REG_TYPE_VFC,
455 REG_TYPE_MVF,
456 REG_TYPE_MVD,
457 REG_TYPE_MVFX,
458 REG_TYPE_MVDX,
459 REG_TYPE_MVAX,
460 REG_TYPE_DSPSC,
461 REG_TYPE_MMXWR,
462 REG_TYPE_MMXWC,
463 REG_TYPE_MMXWCG,
464 REG_TYPE_XSCALE,
465 };
466
467 /* Structure for a hash table entry for a register.
468 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
469 information which states whether a vector type or index is specified (for a
470 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
471 struct reg_entry
472 {
473 const char *name;
474 unsigned char number;
475 unsigned char type;
476 unsigned char builtin;
477 struct neon_typed_alias *neon;
478 };
479
480 /* Diagnostics used when we don't get a register of the expected type. */
481 const char *const reg_expected_msgs[] =
482 {
483 N_("ARM register expected"),
484 N_("bad or missing co-processor number"),
485 N_("co-processor register expected"),
486 N_("FPA register expected"),
487 N_("VFP single precision register expected"),
488 N_("VFP/Neon double precision register expected"),
489 N_("Neon quad precision register expected"),
490 N_("VFP single or double precision register expected"),
491 N_("Neon double or quad precision register expected"),
492 N_("VFP single, double or Neon quad precision register expected"),
493 N_("VFP system register expected"),
494 N_("Maverick MVF register expected"),
495 N_("Maverick MVD register expected"),
496 N_("Maverick MVFX register expected"),
497 N_("Maverick MVDX register expected"),
498 N_("Maverick MVAX register expected"),
499 N_("Maverick DSPSC register expected"),
500 N_("iWMMXt data register expected"),
501 N_("iWMMXt control register expected"),
502 N_("iWMMXt scalar register expected"),
503 N_("XScale accumulator register expected"),
504 };
505
506 /* Some well known registers that we refer to directly elsewhere. */
507 #define REG_SP 13
508 #define REG_LR 14
509 #define REG_PC 15
510
511 /* ARM instructions take 4bytes in the object file, Thumb instructions
512 take 2: */
513 #define INSN_SIZE 4
514
515 struct asm_opcode
516 {
517 /* Basic string to match. */
518 const char *template;
519
520 /* Parameters to instruction. */
521 unsigned char operands[8];
522
523 /* Conditional tag - see opcode_lookup. */
524 unsigned int tag : 4;
525
526 /* Basic instruction code. */
527 unsigned int avalue : 28;
528
529 /* Thumb-format instruction code. */
530 unsigned int tvalue;
531
532 /* Which architecture variant provides this instruction. */
533 const arm_feature_set *avariant;
534 const arm_feature_set *tvariant;
535
536 /* Function to call to encode instruction in ARM format. */
537 void (* aencode) (void);
538
539 /* Function to call to encode instruction in Thumb format. */
540 void (* tencode) (void);
541 };
542
543 /* Defines for various bits that we will want to toggle. */
544 #define INST_IMMEDIATE 0x02000000
545 #define OFFSET_REG 0x02000000
546 #define HWOFFSET_IMM 0x00400000
547 #define SHIFT_BY_REG 0x00000010
548 #define PRE_INDEX 0x01000000
549 #define INDEX_UP 0x00800000
550 #define WRITE_BACK 0x00200000
551 #define LDM_TYPE_2_OR_3 0x00400000
552 #define CPSI_MMOD 0x00020000
553
554 #define LITERAL_MASK 0xf000f000
555 #define OPCODE_MASK 0xfe1fffff
556 #define V4_STR_BIT 0x00000020
557
558 #define T2_SUBS_PC_LR 0xf3de8f00
559
560 #define DATA_OP_SHIFT 21
561
562 #define T2_OPCODE_MASK 0xfe1fffff
563 #define T2_DATA_OP_SHIFT 21
564
565 /* Codes to distinguish the arithmetic instructions. */
566 #define OPCODE_AND 0
567 #define OPCODE_EOR 1
568 #define OPCODE_SUB 2
569 #define OPCODE_RSB 3
570 #define OPCODE_ADD 4
571 #define OPCODE_ADC 5
572 #define OPCODE_SBC 6
573 #define OPCODE_RSC 7
574 #define OPCODE_TST 8
575 #define OPCODE_TEQ 9
576 #define OPCODE_CMP 10
577 #define OPCODE_CMN 11
578 #define OPCODE_ORR 12
579 #define OPCODE_MOV 13
580 #define OPCODE_BIC 14
581 #define OPCODE_MVN 15
582
583 #define T2_OPCODE_AND 0
584 #define T2_OPCODE_BIC 1
585 #define T2_OPCODE_ORR 2
586 #define T2_OPCODE_ORN 3
587 #define T2_OPCODE_EOR 4
588 #define T2_OPCODE_ADD 8
589 #define T2_OPCODE_ADC 10
590 #define T2_OPCODE_SBC 11
591 #define T2_OPCODE_SUB 13
592 #define T2_OPCODE_RSB 14
593
594 #define T_OPCODE_MUL 0x4340
595 #define T_OPCODE_TST 0x4200
596 #define T_OPCODE_CMN 0x42c0
597 #define T_OPCODE_NEG 0x4240
598 #define T_OPCODE_MVN 0x43c0
599
600 #define T_OPCODE_ADD_R3 0x1800
601 #define T_OPCODE_SUB_R3 0x1a00
602 #define T_OPCODE_ADD_HI 0x4400
603 #define T_OPCODE_ADD_ST 0xb000
604 #define T_OPCODE_SUB_ST 0xb080
605 #define T_OPCODE_ADD_SP 0xa800
606 #define T_OPCODE_ADD_PC 0xa000
607 #define T_OPCODE_ADD_I8 0x3000
608 #define T_OPCODE_SUB_I8 0x3800
609 #define T_OPCODE_ADD_I3 0x1c00
610 #define T_OPCODE_SUB_I3 0x1e00
611
612 #define T_OPCODE_ASR_R 0x4100
613 #define T_OPCODE_LSL_R 0x4080
614 #define T_OPCODE_LSR_R 0x40c0
615 #define T_OPCODE_ROR_R 0x41c0
616 #define T_OPCODE_ASR_I 0x1000
617 #define T_OPCODE_LSL_I 0x0000
618 #define T_OPCODE_LSR_I 0x0800
619
620 #define T_OPCODE_MOV_I8 0x2000
621 #define T_OPCODE_CMP_I8 0x2800
622 #define T_OPCODE_CMP_LR 0x4280
623 #define T_OPCODE_MOV_HR 0x4600
624 #define T_OPCODE_CMP_HR 0x4500
625
626 #define T_OPCODE_LDR_PC 0x4800
627 #define T_OPCODE_LDR_SP 0x9800
628 #define T_OPCODE_STR_SP 0x9000
629 #define T_OPCODE_LDR_IW 0x6800
630 #define T_OPCODE_STR_IW 0x6000
631 #define T_OPCODE_LDR_IH 0x8800
632 #define T_OPCODE_STR_IH 0x8000
633 #define T_OPCODE_LDR_IB 0x7800
634 #define T_OPCODE_STR_IB 0x7000
635 #define T_OPCODE_LDR_RW 0x5800
636 #define T_OPCODE_STR_RW 0x5000
637 #define T_OPCODE_LDR_RH 0x5a00
638 #define T_OPCODE_STR_RH 0x5200
639 #define T_OPCODE_LDR_RB 0x5c00
640 #define T_OPCODE_STR_RB 0x5400
641
642 #define T_OPCODE_PUSH 0xb400
643 #define T_OPCODE_POP 0xbc00
644
645 #define T_OPCODE_BRANCH 0xe000
646
647 #define THUMB_SIZE 2 /* Size of thumb instruction. */
648 #define THUMB_PP_PC_LR 0x0100
649 #define THUMB_LOAD_BIT 0x0800
650 #define THUMB2_LOAD_BIT 0x00100000
651
652 #define BAD_ARGS _("bad arguments to instruction")
653 #define BAD_PC _("r15 not allowed here")
654 #define BAD_COND _("instruction cannot be conditional")
655 #define BAD_OVERLAP _("registers may not be the same")
656 #define BAD_HIREG _("lo register required")
657 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
658 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
659 #define BAD_BRANCH _("branch must be last instruction in IT block")
660 #define BAD_NOT_IT _("instruction not allowed in IT block")
661 #define BAD_FPU _("selected FPU does not support instruction")
662
663 static struct hash_control *arm_ops_hsh;
664 static struct hash_control *arm_cond_hsh;
665 static struct hash_control *arm_shift_hsh;
666 static struct hash_control *arm_psr_hsh;
667 static struct hash_control *arm_v7m_psr_hsh;
668 static struct hash_control *arm_reg_hsh;
669 static struct hash_control *arm_reloc_hsh;
670 static struct hash_control *arm_barrier_opt_hsh;
671
672 /* Stuff needed to resolve the label ambiguity
673 As:
674 ...
675 label: <insn>
676 may differ from:
677 ...
678 label:
679 <insn>
680 */
681
682 symbolS * last_label_seen;
683 static int label_is_thumb_function_name = FALSE;
684 \f
685 /* Literal pool structure. Held on a per-section
686 and per-sub-section basis. */
687
688 #define MAX_LITERAL_POOL_SIZE 1024
689 typedef struct literal_pool
690 {
691 expressionS literals [MAX_LITERAL_POOL_SIZE];
692 unsigned int next_free_entry;
693 unsigned int id;
694 symbolS * symbol;
695 segT section;
696 subsegT sub_section;
697 struct literal_pool * next;
698 } literal_pool;
699
700 /* Pointer to a linked list of literal pools. */
701 literal_pool * list_of_pools = NULL;
702
703 /* State variables for IT block handling. */
704 static bfd_boolean current_it_mask = 0;
705 static int current_cc;
706
707 \f
708 /* Pure syntax. */
709
710 /* This array holds the chars that always start a comment. If the
711 pre-processor is disabled, these aren't very useful. */
712 const char comment_chars[] = "@";
713
714 /* This array holds the chars that only start a comment at the beginning of
715 a line. If the line seems to have the form '# 123 filename'
716 .line and .file directives will appear in the pre-processed output. */
717 /* Note that input_file.c hand checks for '#' at the beginning of the
718 first line of the input file. This is because the compiler outputs
719 #NO_APP at the beginning of its output. */
720 /* Also note that comments like this one will always work. */
721 const char line_comment_chars[] = "#";
722
723 const char line_separator_chars[] = ";";
724
725 /* Chars that can be used to separate mant
726 from exp in floating point numbers. */
727 const char EXP_CHARS[] = "eE";
728
729 /* Chars that mean this number is a floating point constant. */
730 /* As in 0f12.456 */
731 /* or 0d1.2345e12 */
732
733 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
734
735 /* Prefix characters that indicate the start of an immediate
736 value. */
737 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
738
739 /* Separator character handling. */
740
741 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
742
743 static inline int
744 skip_past_char (char ** str, char c)
745 {
746 if (**str == c)
747 {
748 (*str)++;
749 return SUCCESS;
750 }
751 else
752 return FAIL;
753 }
754 #define skip_past_comma(str) skip_past_char (str, ',')
755
756 /* Arithmetic expressions (possibly involving symbols). */
757
758 /* Return TRUE if anything in the expression is a bignum. */
759
760 static int
761 walk_no_bignums (symbolS * sp)
762 {
763 if (symbol_get_value_expression (sp)->X_op == O_big)
764 return 1;
765
766 if (symbol_get_value_expression (sp)->X_add_symbol)
767 {
768 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
769 || (symbol_get_value_expression (sp)->X_op_symbol
770 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
771 }
772
773 return 0;
774 }
775
776 static int in_my_get_expression = 0;
777
778 /* Third argument to my_get_expression. */
779 #define GE_NO_PREFIX 0
780 #define GE_IMM_PREFIX 1
781 #define GE_OPT_PREFIX 2
782 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
783 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
784 #define GE_OPT_PREFIX_BIG 3
785
786 static int
787 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
788 {
789 char * save_in;
790 segT seg;
791
792 /* In unified syntax, all prefixes are optional. */
793 if (unified_syntax)
794 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
795 : GE_OPT_PREFIX;
796
797 switch (prefix_mode)
798 {
799 case GE_NO_PREFIX: break;
800 case GE_IMM_PREFIX:
801 if (!is_immediate_prefix (**str))
802 {
803 inst.error = _("immediate expression requires a # prefix");
804 return FAIL;
805 }
806 (*str)++;
807 break;
808 case GE_OPT_PREFIX:
809 case GE_OPT_PREFIX_BIG:
810 if (is_immediate_prefix (**str))
811 (*str)++;
812 break;
813 default: abort ();
814 }
815
816 memset (ep, 0, sizeof (expressionS));
817
818 save_in = input_line_pointer;
819 input_line_pointer = *str;
820 in_my_get_expression = 1;
821 seg = expression (ep);
822 in_my_get_expression = 0;
823
824 if (ep->X_op == O_illegal)
825 {
826 /* We found a bad expression in md_operand(). */
827 *str = input_line_pointer;
828 input_line_pointer = save_in;
829 if (inst.error == NULL)
830 inst.error = _("bad expression");
831 return 1;
832 }
833
834 #ifdef OBJ_AOUT
835 if (seg != absolute_section
836 && seg != text_section
837 && seg != data_section
838 && seg != bss_section
839 && seg != undefined_section)
840 {
841 inst.error = _("bad segment");
842 *str = input_line_pointer;
843 input_line_pointer = save_in;
844 return 1;
845 }
846 #endif
847
848 /* Get rid of any bignums now, so that we don't generate an error for which
849 we can't establish a line number later on. Big numbers are never valid
850 in instructions, which is where this routine is always called. */
851 if (prefix_mode != GE_OPT_PREFIX_BIG
852 && (ep->X_op == O_big
853 || (ep->X_add_symbol
854 && (walk_no_bignums (ep->X_add_symbol)
855 || (ep->X_op_symbol
856 && walk_no_bignums (ep->X_op_symbol))))))
857 {
858 inst.error = _("invalid constant");
859 *str = input_line_pointer;
860 input_line_pointer = save_in;
861 return 1;
862 }
863
864 *str = input_line_pointer;
865 input_line_pointer = save_in;
866 return 0;
867 }
868
869 /* Turn a string in input_line_pointer into a floating point constant
870 of type TYPE, and store the appropriate bytes in *LITP. The number
871 of LITTLENUMS emitted is stored in *SIZEP. An error message is
872 returned, or NULL on OK.
873
874 Note that fp constants aren't represent in the normal way on the ARM.
875 In big endian mode, things are as expected. However, in little endian
876 mode fp constants are big-endian word-wise, and little-endian byte-wise
877 within the words. For example, (double) 1.1 in big endian mode is
878 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
879 the byte sequence 99 99 f1 3f 9a 99 99 99.
880
881 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
882
883 char *
884 md_atof (int type, char * litP, int * sizeP)
885 {
886 int prec;
887 LITTLENUM_TYPE words[MAX_LITTLENUMS];
888 char *t;
889 int i;
890
891 switch (type)
892 {
893 case 'f':
894 case 'F':
895 case 's':
896 case 'S':
897 prec = 2;
898 break;
899
900 case 'd':
901 case 'D':
902 case 'r':
903 case 'R':
904 prec = 4;
905 break;
906
907 case 'x':
908 case 'X':
909 prec = 6;
910 break;
911
912 case 'p':
913 case 'P':
914 prec = 6;
915 break;
916
917 default:
918 *sizeP = 0;
919 return _("bad call to MD_ATOF()");
920 }
921
922 t = atof_ieee (input_line_pointer, type, words);
923 if (t)
924 input_line_pointer = t;
925 *sizeP = prec * 2;
926
927 if (target_big_endian)
928 {
929 for (i = 0; i < prec; i++)
930 {
931 md_number_to_chars (litP, (valueT) words[i], 2);
932 litP += 2;
933 }
934 }
935 else
936 {
937 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
938 for (i = prec - 1; i >= 0; i--)
939 {
940 md_number_to_chars (litP, (valueT) words[i], 2);
941 litP += 2;
942 }
943 else
944 /* For a 4 byte float the order of elements in `words' is 1 0.
945 For an 8 byte float the order is 1 0 3 2. */
946 for (i = 0; i < prec; i += 2)
947 {
948 md_number_to_chars (litP, (valueT) words[i + 1], 2);
949 md_number_to_chars (litP + 2, (valueT) words[i], 2);
950 litP += 4;
951 }
952 }
953
954 return 0;
955 }
956
957 /* We handle all bad expressions here, so that we can report the faulty
958 instruction in the error message. */
959 void
960 md_operand (expressionS * expr)
961 {
962 if (in_my_get_expression)
963 expr->X_op = O_illegal;
964 }
965
966 /* Immediate values. */
967
968 /* Generic immediate-value read function for use in directives.
969 Accepts anything that 'expression' can fold to a constant.
970 *val receives the number. */
971 #ifdef OBJ_ELF
972 static int
973 immediate_for_directive (int *val)
974 {
975 expressionS exp;
976 exp.X_op = O_illegal;
977
978 if (is_immediate_prefix (*input_line_pointer))
979 {
980 input_line_pointer++;
981 expression (&exp);
982 }
983
984 if (exp.X_op != O_constant)
985 {
986 as_bad (_("expected #constant"));
987 ignore_rest_of_line ();
988 return FAIL;
989 }
990 *val = exp.X_add_number;
991 return SUCCESS;
992 }
993 #endif
994
995 /* Register parsing. */
996
997 /* Generic register parser. CCP points to what should be the
998 beginning of a register name. If it is indeed a valid register
999 name, advance CCP over it and return the reg_entry structure;
1000 otherwise return NULL. Does not issue diagnostics. */
1001
1002 static struct reg_entry *
1003 arm_reg_parse_multi (char **ccp)
1004 {
1005 char *start = *ccp;
1006 char *p;
1007 struct reg_entry *reg;
1008
1009 #ifdef REGISTER_PREFIX
1010 if (*start != REGISTER_PREFIX)
1011 return NULL;
1012 start++;
1013 #endif
1014 #ifdef OPTIONAL_REGISTER_PREFIX
1015 if (*start == OPTIONAL_REGISTER_PREFIX)
1016 start++;
1017 #endif
1018
1019 p = start;
1020 if (!ISALPHA (*p) || !is_name_beginner (*p))
1021 return NULL;
1022
1023 do
1024 p++;
1025 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1026
1027 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1028
1029 if (!reg)
1030 return NULL;
1031
1032 *ccp = p;
1033 return reg;
1034 }
1035
1036 static int
1037 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1038 enum arm_reg_type type)
1039 {
1040 /* Alternative syntaxes are accepted for a few register classes. */
1041 switch (type)
1042 {
1043 case REG_TYPE_MVF:
1044 case REG_TYPE_MVD:
1045 case REG_TYPE_MVFX:
1046 case REG_TYPE_MVDX:
1047 /* Generic coprocessor register names are allowed for these. */
1048 if (reg && reg->type == REG_TYPE_CN)
1049 return reg->number;
1050 break;
1051
1052 case REG_TYPE_CP:
1053 /* For backward compatibility, a bare number is valid here. */
1054 {
1055 unsigned long processor = strtoul (start, ccp, 10);
1056 if (*ccp != start && processor <= 15)
1057 return processor;
1058 }
1059
1060 case REG_TYPE_MMXWC:
1061 /* WC includes WCG. ??? I'm not sure this is true for all
1062 instructions that take WC registers. */
1063 if (reg && reg->type == REG_TYPE_MMXWCG)
1064 return reg->number;
1065 break;
1066
1067 default:
1068 break;
1069 }
1070
1071 return FAIL;
1072 }
1073
1074 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1075 return value is the register number or FAIL. */
1076
1077 static int
1078 arm_reg_parse (char **ccp, enum arm_reg_type type)
1079 {
1080 char *start = *ccp;
1081 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1082 int ret;
1083
1084 /* Do not allow a scalar (reg+index) to parse as a register. */
1085 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1086 return FAIL;
1087
1088 if (reg && reg->type == type)
1089 return reg->number;
1090
1091 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1092 return ret;
1093
1094 *ccp = start;
1095 return FAIL;
1096 }
1097
1098 /* Parse a Neon type specifier. *STR should point at the leading '.'
1099 character. Does no verification at this stage that the type fits the opcode
1100 properly. E.g.,
1101
1102 .i32.i32.s16
1103 .s32.f32
1104 .u16
1105
1106 Can all be legally parsed by this function.
1107
1108 Fills in neon_type struct pointer with parsed information, and updates STR
1109 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1110 type, FAIL if not. */
1111
1112 static int
1113 parse_neon_type (struct neon_type *type, char **str)
1114 {
1115 char *ptr = *str;
1116
1117 if (type)
1118 type->elems = 0;
1119
1120 while (type->elems < NEON_MAX_TYPE_ELS)
1121 {
1122 enum neon_el_type thistype = NT_untyped;
1123 unsigned thissize = -1u;
1124
1125 if (*ptr != '.')
1126 break;
1127
1128 ptr++;
1129
1130 /* Just a size without an explicit type. */
1131 if (ISDIGIT (*ptr))
1132 goto parsesize;
1133
1134 switch (TOLOWER (*ptr))
1135 {
1136 case 'i': thistype = NT_integer; break;
1137 case 'f': thistype = NT_float; break;
1138 case 'p': thistype = NT_poly; break;
1139 case 's': thistype = NT_signed; break;
1140 case 'u': thistype = NT_unsigned; break;
1141 case 'd':
1142 thistype = NT_float;
1143 thissize = 64;
1144 ptr++;
1145 goto done;
1146 default:
1147 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1148 return FAIL;
1149 }
1150
1151 ptr++;
1152
1153 /* .f is an abbreviation for .f32. */
1154 if (thistype == NT_float && !ISDIGIT (*ptr))
1155 thissize = 32;
1156 else
1157 {
1158 parsesize:
1159 thissize = strtoul (ptr, &ptr, 10);
1160
1161 if (thissize != 8 && thissize != 16 && thissize != 32
1162 && thissize != 64)
1163 {
1164 as_bad (_("bad size %d in type specifier"), thissize);
1165 return FAIL;
1166 }
1167 }
1168
1169 done:
1170 if (type)
1171 {
1172 type->el[type->elems].type = thistype;
1173 type->el[type->elems].size = thissize;
1174 type->elems++;
1175 }
1176 }
1177
1178 /* Empty/missing type is not a successful parse. */
1179 if (type->elems == 0)
1180 return FAIL;
1181
1182 *str = ptr;
1183
1184 return SUCCESS;
1185 }
1186
1187 /* Errors may be set multiple times during parsing or bit encoding
1188 (particularly in the Neon bits), but usually the earliest error which is set
1189 will be the most meaningful. Avoid overwriting it with later (cascading)
1190 errors by calling this function. */
1191
1192 static void
1193 first_error (const char *err)
1194 {
1195 if (!inst.error)
1196 inst.error = err;
1197 }
1198
1199 /* Parse a single type, e.g. ".s32", leading period included. */
1200 static int
1201 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1202 {
1203 char *str = *ccp;
1204 struct neon_type optype;
1205
1206 if (*str == '.')
1207 {
1208 if (parse_neon_type (&optype, &str) == SUCCESS)
1209 {
1210 if (optype.elems == 1)
1211 *vectype = optype.el[0];
1212 else
1213 {
1214 first_error (_("only one type should be specified for operand"));
1215 return FAIL;
1216 }
1217 }
1218 else
1219 {
1220 first_error (_("vector type expected"));
1221 return FAIL;
1222 }
1223 }
1224 else
1225 return FAIL;
1226
1227 *ccp = str;
1228
1229 return SUCCESS;
1230 }
1231
1232 /* Special meanings for indices (which have a range of 0-7), which will fit into
1233 a 4-bit integer. */
1234
1235 #define NEON_ALL_LANES 15
1236 #define NEON_INTERLEAVE_LANES 14
1237
1238 /* Parse either a register or a scalar, with an optional type. Return the
1239 register number, and optionally fill in the actual type of the register
1240 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1241 type/index information in *TYPEINFO. */
1242
1243 static int
1244 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1245 enum arm_reg_type *rtype,
1246 struct neon_typed_alias *typeinfo)
1247 {
1248 char *str = *ccp;
1249 struct reg_entry *reg = arm_reg_parse_multi (&str);
1250 struct neon_typed_alias atype;
1251 struct neon_type_el parsetype;
1252
1253 atype.defined = 0;
1254 atype.index = -1;
1255 atype.eltype.type = NT_invtype;
1256 atype.eltype.size = -1;
1257
1258 /* Try alternate syntax for some types of register. Note these are mutually
1259 exclusive with the Neon syntax extensions. */
1260 if (reg == NULL)
1261 {
1262 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1263 if (altreg != FAIL)
1264 *ccp = str;
1265 if (typeinfo)
1266 *typeinfo = atype;
1267 return altreg;
1268 }
1269
1270 /* Undo polymorphism when a set of register types may be accepted. */
1271 if ((type == REG_TYPE_NDQ
1272 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1273 || (type == REG_TYPE_VFSD
1274 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1275 || (type == REG_TYPE_NSDQ
1276 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1277 || reg->type == REG_TYPE_NQ))
1278 || (type == REG_TYPE_MMXWC
1279 && (reg->type == REG_TYPE_MMXWCG)))
1280 type = reg->type;
1281
1282 if (type != reg->type)
1283 return FAIL;
1284
1285 if (reg->neon)
1286 atype = *reg->neon;
1287
1288 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1289 {
1290 if ((atype.defined & NTA_HASTYPE) != 0)
1291 {
1292 first_error (_("can't redefine type for operand"));
1293 return FAIL;
1294 }
1295 atype.defined |= NTA_HASTYPE;
1296 atype.eltype = parsetype;
1297 }
1298
1299 if (skip_past_char (&str, '[') == SUCCESS)
1300 {
1301 if (type != REG_TYPE_VFD)
1302 {
1303 first_error (_("only D registers may be indexed"));
1304 return FAIL;
1305 }
1306
1307 if ((atype.defined & NTA_HASINDEX) != 0)
1308 {
1309 first_error (_("can't change index for operand"));
1310 return FAIL;
1311 }
1312
1313 atype.defined |= NTA_HASINDEX;
1314
1315 if (skip_past_char (&str, ']') == SUCCESS)
1316 atype.index = NEON_ALL_LANES;
1317 else
1318 {
1319 expressionS exp;
1320
1321 my_get_expression (&exp, &str, GE_NO_PREFIX);
1322
1323 if (exp.X_op != O_constant)
1324 {
1325 first_error (_("constant expression required"));
1326 return FAIL;
1327 }
1328
1329 if (skip_past_char (&str, ']') == FAIL)
1330 return FAIL;
1331
1332 atype.index = exp.X_add_number;
1333 }
1334 }
1335
1336 if (typeinfo)
1337 *typeinfo = atype;
1338
1339 if (rtype)
1340 *rtype = type;
1341
1342 *ccp = str;
1343
1344 return reg->number;
1345 }
1346
1347 /* Like arm_reg_parse, but allow allow the following extra features:
1348 - If RTYPE is non-zero, return the (possibly restricted) type of the
1349 register (e.g. Neon double or quad reg when either has been requested).
1350 - If this is a Neon vector type with additional type information, fill
1351 in the struct pointed to by VECTYPE (if non-NULL).
1352 This function will fault on encountering a scalar.
1353 */
1354
1355 static int
1356 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1357 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1358 {
1359 struct neon_typed_alias atype;
1360 char *str = *ccp;
1361 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1362
1363 if (reg == FAIL)
1364 return FAIL;
1365
1366 /* Do not allow a scalar (reg+index) to parse as a register. */
1367 if ((atype.defined & NTA_HASINDEX) != 0)
1368 {
1369 first_error (_("register operand expected, but got scalar"));
1370 return FAIL;
1371 }
1372
1373 if (vectype)
1374 *vectype = atype.eltype;
1375
1376 *ccp = str;
1377
1378 return reg;
1379 }
1380
1381 #define NEON_SCALAR_REG(X) ((X) >> 4)
1382 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1383
1384 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1385 have enough information to be able to do a good job bounds-checking. So, we
1386 just do easy checks here, and do further checks later. */
1387
1388 static int
1389 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1390 {
1391 int reg;
1392 char *str = *ccp;
1393 struct neon_typed_alias atype;
1394
1395 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
1396
1397 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1398 return FAIL;
1399
1400 if (atype.index == NEON_ALL_LANES)
1401 {
1402 first_error (_("scalar must have an index"));
1403 return FAIL;
1404 }
1405 else if (atype.index >= 64 / elsize)
1406 {
1407 first_error (_("scalar index out of range"));
1408 return FAIL;
1409 }
1410
1411 if (type)
1412 *type = atype.eltype;
1413
1414 *ccp = str;
1415
1416 return reg * 16 + atype.index;
1417 }
1418
1419 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1420 static long
1421 parse_reg_list (char ** strp)
1422 {
1423 char * str = * strp;
1424 long range = 0;
1425 int another_range;
1426
1427 /* We come back here if we get ranges concatenated by '+' or '|'. */
1428 do
1429 {
1430 another_range = 0;
1431
1432 if (*str == '{')
1433 {
1434 int in_range = 0;
1435 int cur_reg = -1;
1436
1437 str++;
1438 do
1439 {
1440 int reg;
1441
1442 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1443 {
1444 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
1445 return FAIL;
1446 }
1447
1448 if (in_range)
1449 {
1450 int i;
1451
1452 if (reg <= cur_reg)
1453 {
1454 first_error (_("bad range in register list"));
1455 return FAIL;
1456 }
1457
1458 for (i = cur_reg + 1; i < reg; i++)
1459 {
1460 if (range & (1 << i))
1461 as_tsktsk
1462 (_("Warning: duplicated register (r%d) in register list"),
1463 i);
1464 else
1465 range |= 1 << i;
1466 }
1467 in_range = 0;
1468 }
1469
1470 if (range & (1 << reg))
1471 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1472 reg);
1473 else if (reg <= cur_reg)
1474 as_tsktsk (_("Warning: register range not in ascending order"));
1475
1476 range |= 1 << reg;
1477 cur_reg = reg;
1478 }
1479 while (skip_past_comma (&str) != FAIL
1480 || (in_range = 1, *str++ == '-'));
1481 str--;
1482
1483 if (*str++ != '}')
1484 {
1485 first_error (_("missing `}'"));
1486 return FAIL;
1487 }
1488 }
1489 else
1490 {
1491 expressionS expr;
1492
1493 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1494 return FAIL;
1495
1496 if (expr.X_op == O_constant)
1497 {
1498 if (expr.X_add_number
1499 != (expr.X_add_number & 0x0000ffff))
1500 {
1501 inst.error = _("invalid register mask");
1502 return FAIL;
1503 }
1504
1505 if ((range & expr.X_add_number) != 0)
1506 {
1507 int regno = range & expr.X_add_number;
1508
1509 regno &= -regno;
1510 regno = (1 << regno) - 1;
1511 as_tsktsk
1512 (_("Warning: duplicated register (r%d) in register list"),
1513 regno);
1514 }
1515
1516 range |= expr.X_add_number;
1517 }
1518 else
1519 {
1520 if (inst.reloc.type != 0)
1521 {
1522 inst.error = _("expression too complex");
1523 return FAIL;
1524 }
1525
1526 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1527 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1528 inst.reloc.pc_rel = 0;
1529 }
1530 }
1531
1532 if (*str == '|' || *str == '+')
1533 {
1534 str++;
1535 another_range = 1;
1536 }
1537 }
1538 while (another_range);
1539
1540 *strp = str;
1541 return range;
1542 }
1543
1544 /* Types of registers in a list. */
1545
1546 enum reg_list_els
1547 {
1548 REGLIST_VFP_S,
1549 REGLIST_VFP_D,
1550 REGLIST_NEON_D
1551 };
1552
1553 /* Parse a VFP register list. If the string is invalid return FAIL.
1554 Otherwise return the number of registers, and set PBASE to the first
1555 register. Parses registers of type ETYPE.
1556 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1557 - Q registers can be used to specify pairs of D registers
1558 - { } can be omitted from around a singleton register list
1559 FIXME: This is not implemented, as it would require backtracking in
1560 some cases, e.g.:
1561 vtbl.8 d3,d4,d5
1562 This could be done (the meaning isn't really ambiguous), but doesn't
1563 fit in well with the current parsing framework.
1564 - 32 D registers may be used (also true for VFPv3).
1565 FIXME: Types are ignored in these register lists, which is probably a
1566 bug. */
1567
1568 static int
1569 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
1570 {
1571 char *str = *ccp;
1572 int base_reg;
1573 int new_base;
1574 enum arm_reg_type regtype = 0;
1575 int max_regs = 0;
1576 int count = 0;
1577 int warned = 0;
1578 unsigned long mask = 0;
1579 int i;
1580
1581 if (*str != '{')
1582 {
1583 inst.error = _("expecting {");
1584 return FAIL;
1585 }
1586
1587 str++;
1588
1589 switch (etype)
1590 {
1591 case REGLIST_VFP_S:
1592 regtype = REG_TYPE_VFS;
1593 max_regs = 32;
1594 break;
1595
1596 case REGLIST_VFP_D:
1597 regtype = REG_TYPE_VFD;
1598 break;
1599
1600 case REGLIST_NEON_D:
1601 regtype = REG_TYPE_NDQ;
1602 break;
1603 }
1604
1605 if (etype != REGLIST_VFP_S)
1606 {
1607 /* VFPv3 allows 32 D registers. */
1608 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
1609 {
1610 max_regs = 32;
1611 if (thumb_mode)
1612 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1613 fpu_vfp_ext_v3);
1614 else
1615 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1616 fpu_vfp_ext_v3);
1617 }
1618 else
1619 max_regs = 16;
1620 }
1621
1622 base_reg = max_regs;
1623
1624 do
1625 {
1626 int setmask = 1, addregs = 1;
1627
1628 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
1629
1630 if (new_base == FAIL)
1631 {
1632 first_error (_(reg_expected_msgs[regtype]));
1633 return FAIL;
1634 }
1635
1636 if (new_base >= max_regs)
1637 {
1638 first_error (_("register out of range in list"));
1639 return FAIL;
1640 }
1641
1642 /* Note: a value of 2 * n is returned for the register Q<n>. */
1643 if (regtype == REG_TYPE_NQ)
1644 {
1645 setmask = 3;
1646 addregs = 2;
1647 }
1648
1649 if (new_base < base_reg)
1650 base_reg = new_base;
1651
1652 if (mask & (setmask << new_base))
1653 {
1654 first_error (_("invalid register list"));
1655 return FAIL;
1656 }
1657
1658 if ((mask >> new_base) != 0 && ! warned)
1659 {
1660 as_tsktsk (_("register list not in ascending order"));
1661 warned = 1;
1662 }
1663
1664 mask |= setmask << new_base;
1665 count += addregs;
1666
1667 if (*str == '-') /* We have the start of a range expression */
1668 {
1669 int high_range;
1670
1671 str++;
1672
1673 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
1674 == FAIL)
1675 {
1676 inst.error = gettext (reg_expected_msgs[regtype]);
1677 return FAIL;
1678 }
1679
1680 if (high_range >= max_regs)
1681 {
1682 first_error (_("register out of range in list"));
1683 return FAIL;
1684 }
1685
1686 if (regtype == REG_TYPE_NQ)
1687 high_range = high_range + 1;
1688
1689 if (high_range <= new_base)
1690 {
1691 inst.error = _("register range not in ascending order");
1692 return FAIL;
1693 }
1694
1695 for (new_base += addregs; new_base <= high_range; new_base += addregs)
1696 {
1697 if (mask & (setmask << new_base))
1698 {
1699 inst.error = _("invalid register list");
1700 return FAIL;
1701 }
1702
1703 mask |= setmask << new_base;
1704 count += addregs;
1705 }
1706 }
1707 }
1708 while (skip_past_comma (&str) != FAIL);
1709
1710 str++;
1711
1712 /* Sanity check -- should have raised a parse error above. */
1713 if (count == 0 || count > max_regs)
1714 abort ();
1715
1716 *pbase = base_reg;
1717
1718 /* Final test -- the registers must be consecutive. */
1719 mask >>= base_reg;
1720 for (i = 0; i < count; i++)
1721 {
1722 if ((mask & (1u << i)) == 0)
1723 {
1724 inst.error = _("non-contiguous register range");
1725 return FAIL;
1726 }
1727 }
1728
1729 *ccp = str;
1730
1731 return count;
1732 }
1733
1734 /* True if two alias types are the same. */
1735
1736 static int
1737 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1738 {
1739 if (!a && !b)
1740 return 1;
1741
1742 if (!a || !b)
1743 return 0;
1744
1745 if (a->defined != b->defined)
1746 return 0;
1747
1748 if ((a->defined & NTA_HASTYPE) != 0
1749 && (a->eltype.type != b->eltype.type
1750 || a->eltype.size != b->eltype.size))
1751 return 0;
1752
1753 if ((a->defined & NTA_HASINDEX) != 0
1754 && (a->index != b->index))
1755 return 0;
1756
1757 return 1;
1758 }
1759
1760 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1761 The base register is put in *PBASE.
1762 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
1763 the return value.
1764 The register stride (minus one) is put in bit 4 of the return value.
1765 Bits [6:5] encode the list length (minus one).
1766 The type of the list elements is put in *ELTYPE, if non-NULL. */
1767
1768 #define NEON_LANE(X) ((X) & 0xf)
1769 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
1770 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1771
1772 static int
1773 parse_neon_el_struct_list (char **str, unsigned *pbase,
1774 struct neon_type_el *eltype)
1775 {
1776 char *ptr = *str;
1777 int base_reg = -1;
1778 int reg_incr = -1;
1779 int count = 0;
1780 int lane = -1;
1781 int leading_brace = 0;
1782 enum arm_reg_type rtype = REG_TYPE_NDQ;
1783 int addregs = 1;
1784 const char *const incr_error = "register stride must be 1 or 2";
1785 const char *const type_error = "mismatched element/structure types in list";
1786 struct neon_typed_alias firsttype;
1787
1788 if (skip_past_char (&ptr, '{') == SUCCESS)
1789 leading_brace = 1;
1790
1791 do
1792 {
1793 struct neon_typed_alias atype;
1794 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1795
1796 if (getreg == FAIL)
1797 {
1798 first_error (_(reg_expected_msgs[rtype]));
1799 return FAIL;
1800 }
1801
1802 if (base_reg == -1)
1803 {
1804 base_reg = getreg;
1805 if (rtype == REG_TYPE_NQ)
1806 {
1807 reg_incr = 1;
1808 addregs = 2;
1809 }
1810 firsttype = atype;
1811 }
1812 else if (reg_incr == -1)
1813 {
1814 reg_incr = getreg - base_reg;
1815 if (reg_incr < 1 || reg_incr > 2)
1816 {
1817 first_error (_(incr_error));
1818 return FAIL;
1819 }
1820 }
1821 else if (getreg != base_reg + reg_incr * count)
1822 {
1823 first_error (_(incr_error));
1824 return FAIL;
1825 }
1826
1827 if (!neon_alias_types_same (&atype, &firsttype))
1828 {
1829 first_error (_(type_error));
1830 return FAIL;
1831 }
1832
1833 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1834 modes. */
1835 if (ptr[0] == '-')
1836 {
1837 struct neon_typed_alias htype;
1838 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1839 if (lane == -1)
1840 lane = NEON_INTERLEAVE_LANES;
1841 else if (lane != NEON_INTERLEAVE_LANES)
1842 {
1843 first_error (_(type_error));
1844 return FAIL;
1845 }
1846 if (reg_incr == -1)
1847 reg_incr = 1;
1848 else if (reg_incr != 1)
1849 {
1850 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
1851 return FAIL;
1852 }
1853 ptr++;
1854 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
1855 if (hireg == FAIL)
1856 {
1857 first_error (_(reg_expected_msgs[rtype]));
1858 return FAIL;
1859 }
1860 if (!neon_alias_types_same (&htype, &firsttype))
1861 {
1862 first_error (_(type_error));
1863 return FAIL;
1864 }
1865 count += hireg + dregs - getreg;
1866 continue;
1867 }
1868
1869 /* If we're using Q registers, we can't use [] or [n] syntax. */
1870 if (rtype == REG_TYPE_NQ)
1871 {
1872 count += 2;
1873 continue;
1874 }
1875
1876 if ((atype.defined & NTA_HASINDEX) != 0)
1877 {
1878 if (lane == -1)
1879 lane = atype.index;
1880 else if (lane != atype.index)
1881 {
1882 first_error (_(type_error));
1883 return FAIL;
1884 }
1885 }
1886 else if (lane == -1)
1887 lane = NEON_INTERLEAVE_LANES;
1888 else if (lane != NEON_INTERLEAVE_LANES)
1889 {
1890 first_error (_(type_error));
1891 return FAIL;
1892 }
1893 count++;
1894 }
1895 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
1896
1897 /* No lane set by [x]. We must be interleaving structures. */
1898 if (lane == -1)
1899 lane = NEON_INTERLEAVE_LANES;
1900
1901 /* Sanity check. */
1902 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
1903 || (count > 1 && reg_incr == -1))
1904 {
1905 first_error (_("error parsing element/structure list"));
1906 return FAIL;
1907 }
1908
1909 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
1910 {
1911 first_error (_("expected }"));
1912 return FAIL;
1913 }
1914
1915 if (reg_incr == -1)
1916 reg_incr = 1;
1917
1918 if (eltype)
1919 *eltype = firsttype.eltype;
1920
1921 *pbase = base_reg;
1922 *str = ptr;
1923
1924 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
1925 }
1926
1927 /* Parse an explicit relocation suffix on an expression. This is
1928 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1929 arm_reloc_hsh contains no entries, so this function can only
1930 succeed if there is no () after the word. Returns -1 on error,
1931 BFD_RELOC_UNUSED if there wasn't any suffix. */
1932 static int
1933 parse_reloc (char **str)
1934 {
1935 struct reloc_entry *r;
1936 char *p, *q;
1937
1938 if (**str != '(')
1939 return BFD_RELOC_UNUSED;
1940
1941 p = *str + 1;
1942 q = p;
1943
1944 while (*q && *q != ')' && *q != ',')
1945 q++;
1946 if (*q != ')')
1947 return -1;
1948
1949 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1950 return -1;
1951
1952 *str = q + 1;
1953 return r->reloc;
1954 }
1955
1956 /* Directives: register aliases. */
1957
1958 static struct reg_entry *
1959 insert_reg_alias (char *str, int number, int type)
1960 {
1961 struct reg_entry *new;
1962 const char *name;
1963
1964 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1965 {
1966 if (new->builtin)
1967 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
1968
1969 /* Only warn about a redefinition if it's not defined as the
1970 same register. */
1971 else if (new->number != number || new->type != type)
1972 as_warn (_("ignoring redefinition of register alias '%s'"), str);
1973
1974 return NULL;
1975 }
1976
1977 name = xstrdup (str);
1978 new = xmalloc (sizeof (struct reg_entry));
1979
1980 new->name = name;
1981 new->number = number;
1982 new->type = type;
1983 new->builtin = FALSE;
1984 new->neon = NULL;
1985
1986 if (hash_insert (arm_reg_hsh, name, (PTR) new))
1987 abort ();
1988
1989 return new;
1990 }
1991
1992 static void
1993 insert_neon_reg_alias (char *str, int number, int type,
1994 struct neon_typed_alias *atype)
1995 {
1996 struct reg_entry *reg = insert_reg_alias (str, number, type);
1997
1998 if (!reg)
1999 {
2000 first_error (_("attempt to redefine typed alias"));
2001 return;
2002 }
2003
2004 if (atype)
2005 {
2006 reg->neon = xmalloc (sizeof (struct neon_typed_alias));
2007 *reg->neon = *atype;
2008 }
2009 }
2010
2011 /* Look for the .req directive. This is of the form:
2012
2013 new_register_name .req existing_register_name
2014
2015 If we find one, or if it looks sufficiently like one that we want to
2016 handle any error here, return TRUE. Otherwise return FALSE. */
2017
2018 static bfd_boolean
2019 create_register_alias (char * newname, char *p)
2020 {
2021 struct reg_entry *old;
2022 char *oldname, *nbuf;
2023 size_t nlen;
2024
2025 /* The input scrubber ensures that whitespace after the mnemonic is
2026 collapsed to single spaces. */
2027 oldname = p;
2028 if (strncmp (oldname, " .req ", 6) != 0)
2029 return FALSE;
2030
2031 oldname += 6;
2032 if (*oldname == '\0')
2033 return FALSE;
2034
2035 old = hash_find (arm_reg_hsh, oldname);
2036 if (!old)
2037 {
2038 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2039 return TRUE;
2040 }
2041
2042 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2043 the desired alias name, and p points to its end. If not, then
2044 the desired alias name is in the global original_case_string. */
2045 #ifdef TC_CASE_SENSITIVE
2046 nlen = p - newname;
2047 #else
2048 newname = original_case_string;
2049 nlen = strlen (newname);
2050 #endif
2051
2052 nbuf = alloca (nlen + 1);
2053 memcpy (nbuf, newname, nlen);
2054 nbuf[nlen] = '\0';
2055
2056 /* Create aliases under the new name as stated; an all-lowercase
2057 version of the new name; and an all-uppercase version of the new
2058 name. */
2059 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2060 {
2061 for (p = nbuf; *p; p++)
2062 *p = TOUPPER (*p);
2063
2064 if (strncmp (nbuf, newname, nlen))
2065 {
2066 /* If this attempt to create an additional alias fails, do not bother
2067 trying to create the all-lower case alias. We will fail and issue
2068 a second, duplicate error message. This situation arises when the
2069 programmer does something like:
2070 foo .req r0
2071 Foo .req r1
2072 The second .req creates the "Foo" alias but then fails to create
2073 the artifical FOO alias because it has already been created by the
2074 first .req. */
2075 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2076 return TRUE;
2077 }
2078
2079 for (p = nbuf; *p; p++)
2080 *p = TOLOWER (*p);
2081
2082 if (strncmp (nbuf, newname, nlen))
2083 insert_reg_alias (nbuf, old->number, old->type);
2084 }
2085
2086 return TRUE;
2087 }
2088
2089 /* Create a Neon typed/indexed register alias using directives, e.g.:
2090 X .dn d5.s32[1]
2091 Y .qn 6.s16
2092 Z .dn d7
2093 T .dn Z[0]
2094 These typed registers can be used instead of the types specified after the
2095 Neon mnemonic, so long as all operands given have types. Types can also be
2096 specified directly, e.g.:
2097 vadd d0.s32, d1.s32, d2.s32
2098 */
2099
2100 static int
2101 create_neon_reg_alias (char *newname, char *p)
2102 {
2103 enum arm_reg_type basetype;
2104 struct reg_entry *basereg;
2105 struct reg_entry mybasereg;
2106 struct neon_type ntype;
2107 struct neon_typed_alias typeinfo;
2108 char *namebuf, *nameend;
2109 int namelen;
2110
2111 typeinfo.defined = 0;
2112 typeinfo.eltype.type = NT_invtype;
2113 typeinfo.eltype.size = -1;
2114 typeinfo.index = -1;
2115
2116 nameend = p;
2117
2118 if (strncmp (p, " .dn ", 5) == 0)
2119 basetype = REG_TYPE_VFD;
2120 else if (strncmp (p, " .qn ", 5) == 0)
2121 basetype = REG_TYPE_NQ;
2122 else
2123 return 0;
2124
2125 p += 5;
2126
2127 if (*p == '\0')
2128 return 0;
2129
2130 basereg = arm_reg_parse_multi (&p);
2131
2132 if (basereg && basereg->type != basetype)
2133 {
2134 as_bad (_("bad type for register"));
2135 return 0;
2136 }
2137
2138 if (basereg == NULL)
2139 {
2140 expressionS exp;
2141 /* Try parsing as an integer. */
2142 my_get_expression (&exp, &p, GE_NO_PREFIX);
2143 if (exp.X_op != O_constant)
2144 {
2145 as_bad (_("expression must be constant"));
2146 return 0;
2147 }
2148 basereg = &mybasereg;
2149 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2150 : exp.X_add_number;
2151 basereg->neon = 0;
2152 }
2153
2154 if (basereg->neon)
2155 typeinfo = *basereg->neon;
2156
2157 if (parse_neon_type (&ntype, &p) == SUCCESS)
2158 {
2159 /* We got a type. */
2160 if (typeinfo.defined & NTA_HASTYPE)
2161 {
2162 as_bad (_("can't redefine the type of a register alias"));
2163 return 0;
2164 }
2165
2166 typeinfo.defined |= NTA_HASTYPE;
2167 if (ntype.elems != 1)
2168 {
2169 as_bad (_("you must specify a single type only"));
2170 return 0;
2171 }
2172 typeinfo.eltype = ntype.el[0];
2173 }
2174
2175 if (skip_past_char (&p, '[') == SUCCESS)
2176 {
2177 expressionS exp;
2178 /* We got a scalar index. */
2179
2180 if (typeinfo.defined & NTA_HASINDEX)
2181 {
2182 as_bad (_("can't redefine the index of a scalar alias"));
2183 return 0;
2184 }
2185
2186 my_get_expression (&exp, &p, GE_NO_PREFIX);
2187
2188 if (exp.X_op != O_constant)
2189 {
2190 as_bad (_("scalar index must be constant"));
2191 return 0;
2192 }
2193
2194 typeinfo.defined |= NTA_HASINDEX;
2195 typeinfo.index = exp.X_add_number;
2196
2197 if (skip_past_char (&p, ']') == FAIL)
2198 {
2199 as_bad (_("expecting ]"));
2200 return 0;
2201 }
2202 }
2203
2204 namelen = nameend - newname;
2205 namebuf = alloca (namelen + 1);
2206 strncpy (namebuf, newname, namelen);
2207 namebuf[namelen] = '\0';
2208
2209 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2210 typeinfo.defined != 0 ? &typeinfo : NULL);
2211
2212 /* Insert name in all uppercase. */
2213 for (p = namebuf; *p; p++)
2214 *p = TOUPPER (*p);
2215
2216 if (strncmp (namebuf, newname, namelen))
2217 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2218 typeinfo.defined != 0 ? &typeinfo : NULL);
2219
2220 /* Insert name in all lowercase. */
2221 for (p = namebuf; *p; p++)
2222 *p = TOLOWER (*p);
2223
2224 if (strncmp (namebuf, newname, namelen))
2225 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2226 typeinfo.defined != 0 ? &typeinfo : NULL);
2227
2228 return 1;
2229 }
2230
2231 /* Should never be called, as .req goes between the alias and the
2232 register name, not at the beginning of the line. */
2233 static void
2234 s_req (int a ATTRIBUTE_UNUSED)
2235 {
2236 as_bad (_("invalid syntax for .req directive"));
2237 }
2238
2239 static void
2240 s_dn (int a ATTRIBUTE_UNUSED)
2241 {
2242 as_bad (_("invalid syntax for .dn directive"));
2243 }
2244
2245 static void
2246 s_qn (int a ATTRIBUTE_UNUSED)
2247 {
2248 as_bad (_("invalid syntax for .qn directive"));
2249 }
2250
2251 /* The .unreq directive deletes an alias which was previously defined
2252 by .req. For example:
2253
2254 my_alias .req r11
2255 .unreq my_alias */
2256
2257 static void
2258 s_unreq (int a ATTRIBUTE_UNUSED)
2259 {
2260 char * name;
2261 char saved_char;
2262
2263 name = input_line_pointer;
2264
2265 while (*input_line_pointer != 0
2266 && *input_line_pointer != ' '
2267 && *input_line_pointer != '\n')
2268 ++input_line_pointer;
2269
2270 saved_char = *input_line_pointer;
2271 *input_line_pointer = 0;
2272
2273 if (!*name)
2274 as_bad (_("invalid syntax for .unreq directive"));
2275 else
2276 {
2277 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
2278
2279 if (!reg)
2280 as_bad (_("unknown register alias '%s'"), name);
2281 else if (reg->builtin)
2282 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2283 name);
2284 else
2285 {
2286 char * p;
2287 char * nbuf;
2288
2289 hash_delete (arm_reg_hsh, name);
2290 free ((char *) reg->name);
2291 if (reg->neon)
2292 free (reg->neon);
2293 free (reg);
2294
2295 /* Also locate the all upper case and all lower case versions.
2296 Do not complain if we cannot find one or the other as it
2297 was probably deleted above. */
2298
2299 nbuf = strdup (name);
2300 for (p = nbuf; *p; p++)
2301 *p = TOUPPER (*p);
2302 reg = hash_find (arm_reg_hsh, nbuf);
2303 if (reg)
2304 {
2305 hash_delete (arm_reg_hsh, nbuf);
2306 free ((char *) reg->name);
2307 if (reg->neon)
2308 free (reg->neon);
2309 free (reg);
2310 }
2311
2312 for (p = nbuf; *p; p++)
2313 *p = TOLOWER (*p);
2314 reg = hash_find (arm_reg_hsh, nbuf);
2315 if (reg)
2316 {
2317 hash_delete (arm_reg_hsh, nbuf);
2318 free ((char *) reg->name);
2319 if (reg->neon)
2320 free (reg->neon);
2321 free (reg);
2322 }
2323
2324 free (nbuf);
2325 }
2326 }
2327
2328 *input_line_pointer = saved_char;
2329 demand_empty_rest_of_line ();
2330 }
2331
2332 /* Directives: Instruction set selection. */
2333
2334 #ifdef OBJ_ELF
2335 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2336 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2337 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2338 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2339
2340 static enum mstate mapstate = MAP_UNDEFINED;
2341
2342 void
2343 mapping_state (enum mstate state)
2344 {
2345 symbolS * symbolP;
2346 const char * symname;
2347 int type;
2348
2349 if (mapstate == state)
2350 /* The mapping symbol has already been emitted.
2351 There is nothing else to do. */
2352 return;
2353
2354 mapstate = state;
2355
2356 switch (state)
2357 {
2358 case MAP_DATA:
2359 symname = "$d";
2360 type = BSF_NO_FLAGS;
2361 break;
2362 case MAP_ARM:
2363 symname = "$a";
2364 type = BSF_NO_FLAGS;
2365 break;
2366 case MAP_THUMB:
2367 symname = "$t";
2368 type = BSF_NO_FLAGS;
2369 break;
2370 case MAP_UNDEFINED:
2371 return;
2372 default:
2373 abort ();
2374 }
2375
2376 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2377
2378 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
2379 symbol_table_insert (symbolP);
2380 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2381
2382 switch (state)
2383 {
2384 case MAP_ARM:
2385 THUMB_SET_FUNC (symbolP, 0);
2386 ARM_SET_THUMB (symbolP, 0);
2387 ARM_SET_INTERWORK (symbolP, support_interwork);
2388 break;
2389
2390 case MAP_THUMB:
2391 THUMB_SET_FUNC (symbolP, 1);
2392 ARM_SET_THUMB (symbolP, 1);
2393 ARM_SET_INTERWORK (symbolP, support_interwork);
2394 break;
2395
2396 case MAP_DATA:
2397 default:
2398 return;
2399 }
2400 }
2401 #else
2402 #define mapping_state(x) /* nothing */
2403 #endif
2404
2405 /* Find the real, Thumb encoded start of a Thumb function. */
2406
2407 static symbolS *
2408 find_real_start (symbolS * symbolP)
2409 {
2410 char * real_start;
2411 const char * name = S_GET_NAME (symbolP);
2412 symbolS * new_target;
2413
2414 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2415 #define STUB_NAME ".real_start_of"
2416
2417 if (name == NULL)
2418 abort ();
2419
2420 /* The compiler may generate BL instructions to local labels because
2421 it needs to perform a branch to a far away location. These labels
2422 do not have a corresponding ".real_start_of" label. We check
2423 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2424 the ".real_start_of" convention for nonlocal branches. */
2425 if (S_IS_LOCAL (symbolP) || name[0] == '.')
2426 return symbolP;
2427
2428 real_start = ACONCAT ((STUB_NAME, name, NULL));
2429 new_target = symbol_find (real_start);
2430
2431 if (new_target == NULL)
2432 {
2433 as_warn ("Failed to find real start of function: %s\n", name);
2434 new_target = symbolP;
2435 }
2436
2437 return new_target;
2438 }
2439
2440 static void
2441 opcode_select (int width)
2442 {
2443 switch (width)
2444 {
2445 case 16:
2446 if (! thumb_mode)
2447 {
2448 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
2449 as_bad (_("selected processor does not support THUMB opcodes"));
2450
2451 thumb_mode = 1;
2452 /* No need to force the alignment, since we will have been
2453 coming from ARM mode, which is word-aligned. */
2454 record_alignment (now_seg, 1);
2455 }
2456 mapping_state (MAP_THUMB);
2457 break;
2458
2459 case 32:
2460 if (thumb_mode)
2461 {
2462 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
2463 as_bad (_("selected processor does not support ARM opcodes"));
2464
2465 thumb_mode = 0;
2466
2467 if (!need_pass_2)
2468 frag_align (2, 0, 0);
2469
2470 record_alignment (now_seg, 1);
2471 }
2472 mapping_state (MAP_ARM);
2473 break;
2474
2475 default:
2476 as_bad (_("invalid instruction size selected (%d)"), width);
2477 }
2478 }
2479
2480 static void
2481 s_arm (int ignore ATTRIBUTE_UNUSED)
2482 {
2483 opcode_select (32);
2484 demand_empty_rest_of_line ();
2485 }
2486
2487 static void
2488 s_thumb (int ignore ATTRIBUTE_UNUSED)
2489 {
2490 opcode_select (16);
2491 demand_empty_rest_of_line ();
2492 }
2493
2494 static void
2495 s_code (int unused ATTRIBUTE_UNUSED)
2496 {
2497 int temp;
2498
2499 temp = get_absolute_expression ();
2500 switch (temp)
2501 {
2502 case 16:
2503 case 32:
2504 opcode_select (temp);
2505 break;
2506
2507 default:
2508 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2509 }
2510 }
2511
2512 static void
2513 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2514 {
2515 /* If we are not already in thumb mode go into it, EVEN if
2516 the target processor does not support thumb instructions.
2517 This is used by gcc/config/arm/lib1funcs.asm for example
2518 to compile interworking support functions even if the
2519 target processor should not support interworking. */
2520 if (! thumb_mode)
2521 {
2522 thumb_mode = 2;
2523 record_alignment (now_seg, 1);
2524 }
2525
2526 demand_empty_rest_of_line ();
2527 }
2528
2529 static void
2530 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2531 {
2532 s_thumb (0);
2533
2534 /* The following label is the name/address of the start of a Thumb function.
2535 We need to know this for the interworking support. */
2536 label_is_thumb_function_name = TRUE;
2537 }
2538
2539 /* Perform a .set directive, but also mark the alias as
2540 being a thumb function. */
2541
2542 static void
2543 s_thumb_set (int equiv)
2544 {
2545 /* XXX the following is a duplicate of the code for s_set() in read.c
2546 We cannot just call that code as we need to get at the symbol that
2547 is created. */
2548 char * name;
2549 char delim;
2550 char * end_name;
2551 symbolS * symbolP;
2552
2553 /* Especial apologies for the random logic:
2554 This just grew, and could be parsed much more simply!
2555 Dean - in haste. */
2556 name = input_line_pointer;
2557 delim = get_symbol_end ();
2558 end_name = input_line_pointer;
2559 *end_name = delim;
2560
2561 if (*input_line_pointer != ',')
2562 {
2563 *end_name = 0;
2564 as_bad (_("expected comma after name \"%s\""), name);
2565 *end_name = delim;
2566 ignore_rest_of_line ();
2567 return;
2568 }
2569
2570 input_line_pointer++;
2571 *end_name = 0;
2572
2573 if (name[0] == '.' && name[1] == '\0')
2574 {
2575 /* XXX - this should not happen to .thumb_set. */
2576 abort ();
2577 }
2578
2579 if ((symbolP = symbol_find (name)) == NULL
2580 && (symbolP = md_undefined_symbol (name)) == NULL)
2581 {
2582 #ifndef NO_LISTING
2583 /* When doing symbol listings, play games with dummy fragments living
2584 outside the normal fragment chain to record the file and line info
2585 for this symbol. */
2586 if (listing & LISTING_SYMBOLS)
2587 {
2588 extern struct list_info_struct * listing_tail;
2589 fragS * dummy_frag = xmalloc (sizeof (fragS));
2590
2591 memset (dummy_frag, 0, sizeof (fragS));
2592 dummy_frag->fr_type = rs_fill;
2593 dummy_frag->line = listing_tail;
2594 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2595 dummy_frag->fr_symbol = symbolP;
2596 }
2597 else
2598 #endif
2599 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2600
2601 #ifdef OBJ_COFF
2602 /* "set" symbols are local unless otherwise specified. */
2603 SF_SET_LOCAL (symbolP);
2604 #endif /* OBJ_COFF */
2605 } /* Make a new symbol. */
2606
2607 symbol_table_insert (symbolP);
2608
2609 * end_name = delim;
2610
2611 if (equiv
2612 && S_IS_DEFINED (symbolP)
2613 && S_GET_SEGMENT (symbolP) != reg_section)
2614 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2615
2616 pseudo_set (symbolP);
2617
2618 demand_empty_rest_of_line ();
2619
2620 /* XXX Now we come to the Thumb specific bit of code. */
2621
2622 THUMB_SET_FUNC (symbolP, 1);
2623 ARM_SET_THUMB (symbolP, 1);
2624 #if defined OBJ_ELF || defined OBJ_COFF
2625 ARM_SET_INTERWORK (symbolP, support_interwork);
2626 #endif
2627 }
2628
2629 /* Directives: Mode selection. */
2630
2631 /* .syntax [unified|divided] - choose the new unified syntax
2632 (same for Arm and Thumb encoding, modulo slight differences in what
2633 can be represented) or the old divergent syntax for each mode. */
2634 static void
2635 s_syntax (int unused ATTRIBUTE_UNUSED)
2636 {
2637 char *name, delim;
2638
2639 name = input_line_pointer;
2640 delim = get_symbol_end ();
2641
2642 if (!strcasecmp (name, "unified"))
2643 unified_syntax = TRUE;
2644 else if (!strcasecmp (name, "divided"))
2645 unified_syntax = FALSE;
2646 else
2647 {
2648 as_bad (_("unrecognized syntax mode \"%s\""), name);
2649 return;
2650 }
2651 *input_line_pointer = delim;
2652 demand_empty_rest_of_line ();
2653 }
2654
2655 /* Directives: sectioning and alignment. */
2656
2657 /* Same as s_align_ptwo but align 0 => align 2. */
2658
2659 static void
2660 s_align (int unused ATTRIBUTE_UNUSED)
2661 {
2662 int temp;
2663 bfd_boolean fill_p;
2664 long temp_fill;
2665 long max_alignment = 15;
2666
2667 temp = get_absolute_expression ();
2668 if (temp > max_alignment)
2669 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2670 else if (temp < 0)
2671 {
2672 as_bad (_("alignment negative. 0 assumed."));
2673 temp = 0;
2674 }
2675
2676 if (*input_line_pointer == ',')
2677 {
2678 input_line_pointer++;
2679 temp_fill = get_absolute_expression ();
2680 fill_p = TRUE;
2681 }
2682 else
2683 {
2684 fill_p = FALSE;
2685 temp_fill = 0;
2686 }
2687
2688 if (!temp)
2689 temp = 2;
2690
2691 /* Only make a frag if we HAVE to. */
2692 if (temp && !need_pass_2)
2693 {
2694 if (!fill_p && subseg_text_p (now_seg))
2695 frag_align_code (temp, 0);
2696 else
2697 frag_align (temp, (int) temp_fill, 0);
2698 }
2699 demand_empty_rest_of_line ();
2700
2701 record_alignment (now_seg, temp);
2702 }
2703
2704 static void
2705 s_bss (int ignore ATTRIBUTE_UNUSED)
2706 {
2707 /* We don't support putting frags in the BSS segment, we fake it by
2708 marking in_bss, then looking at s_skip for clues. */
2709 subseg_set (bss_section, 0);
2710 demand_empty_rest_of_line ();
2711 mapping_state (MAP_DATA);
2712 }
2713
2714 static void
2715 s_even (int ignore ATTRIBUTE_UNUSED)
2716 {
2717 /* Never make frag if expect extra pass. */
2718 if (!need_pass_2)
2719 frag_align (1, 0, 0);
2720
2721 record_alignment (now_seg, 1);
2722
2723 demand_empty_rest_of_line ();
2724 }
2725
2726 /* Directives: Literal pools. */
2727
2728 static literal_pool *
2729 find_literal_pool (void)
2730 {
2731 literal_pool * pool;
2732
2733 for (pool = list_of_pools; pool != NULL; pool = pool->next)
2734 {
2735 if (pool->section == now_seg
2736 && pool->sub_section == now_subseg)
2737 break;
2738 }
2739
2740 return pool;
2741 }
2742
2743 static literal_pool *
2744 find_or_make_literal_pool (void)
2745 {
2746 /* Next literal pool ID number. */
2747 static unsigned int latest_pool_num = 1;
2748 literal_pool * pool;
2749
2750 pool = find_literal_pool ();
2751
2752 if (pool == NULL)
2753 {
2754 /* Create a new pool. */
2755 pool = xmalloc (sizeof (* pool));
2756 if (! pool)
2757 return NULL;
2758
2759 pool->next_free_entry = 0;
2760 pool->section = now_seg;
2761 pool->sub_section = now_subseg;
2762 pool->next = list_of_pools;
2763 pool->symbol = NULL;
2764
2765 /* Add it to the list. */
2766 list_of_pools = pool;
2767 }
2768
2769 /* New pools, and emptied pools, will have a NULL symbol. */
2770 if (pool->symbol == NULL)
2771 {
2772 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2773 (valueT) 0, &zero_address_frag);
2774 pool->id = latest_pool_num ++;
2775 }
2776
2777 /* Done. */
2778 return pool;
2779 }
2780
2781 /* Add the literal in the global 'inst'
2782 structure to the relevent literal pool. */
2783
2784 static int
2785 add_to_lit_pool (void)
2786 {
2787 literal_pool * pool;
2788 unsigned int entry;
2789
2790 pool = find_or_make_literal_pool ();
2791
2792 /* Check if this literal value is already in the pool. */
2793 for (entry = 0; entry < pool->next_free_entry; entry ++)
2794 {
2795 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2796 && (inst.reloc.exp.X_op == O_constant)
2797 && (pool->literals[entry].X_add_number
2798 == inst.reloc.exp.X_add_number)
2799 && (pool->literals[entry].X_unsigned
2800 == inst.reloc.exp.X_unsigned))
2801 break;
2802
2803 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2804 && (inst.reloc.exp.X_op == O_symbol)
2805 && (pool->literals[entry].X_add_number
2806 == inst.reloc.exp.X_add_number)
2807 && (pool->literals[entry].X_add_symbol
2808 == inst.reloc.exp.X_add_symbol)
2809 && (pool->literals[entry].X_op_symbol
2810 == inst.reloc.exp.X_op_symbol))
2811 break;
2812 }
2813
2814 /* Do we need to create a new entry? */
2815 if (entry == pool->next_free_entry)
2816 {
2817 if (entry >= MAX_LITERAL_POOL_SIZE)
2818 {
2819 inst.error = _("literal pool overflow");
2820 return FAIL;
2821 }
2822
2823 pool->literals[entry] = inst.reloc.exp;
2824 pool->next_free_entry += 1;
2825 }
2826
2827 inst.reloc.exp.X_op = O_symbol;
2828 inst.reloc.exp.X_add_number = ((int) entry) * 4;
2829 inst.reloc.exp.X_add_symbol = pool->symbol;
2830
2831 return SUCCESS;
2832 }
2833
2834 /* Can't use symbol_new here, so have to create a symbol and then at
2835 a later date assign it a value. Thats what these functions do. */
2836
2837 static void
2838 symbol_locate (symbolS * symbolP,
2839 const char * name, /* It is copied, the caller can modify. */
2840 segT segment, /* Segment identifier (SEG_<something>). */
2841 valueT valu, /* Symbol value. */
2842 fragS * frag) /* Associated fragment. */
2843 {
2844 unsigned int name_length;
2845 char * preserved_copy_of_name;
2846
2847 name_length = strlen (name) + 1; /* +1 for \0. */
2848 obstack_grow (&notes, name, name_length);
2849 preserved_copy_of_name = obstack_finish (&notes);
2850
2851 #ifdef tc_canonicalize_symbol_name
2852 preserved_copy_of_name =
2853 tc_canonicalize_symbol_name (preserved_copy_of_name);
2854 #endif
2855
2856 S_SET_NAME (symbolP, preserved_copy_of_name);
2857
2858 S_SET_SEGMENT (symbolP, segment);
2859 S_SET_VALUE (symbolP, valu);
2860 symbol_clear_list_pointers (symbolP);
2861
2862 symbol_set_frag (symbolP, frag);
2863
2864 /* Link to end of symbol chain. */
2865 {
2866 extern int symbol_table_frozen;
2867
2868 if (symbol_table_frozen)
2869 abort ();
2870 }
2871
2872 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
2873
2874 obj_symbol_new_hook (symbolP);
2875
2876 #ifdef tc_symbol_new_hook
2877 tc_symbol_new_hook (symbolP);
2878 #endif
2879
2880 #ifdef DEBUG_SYMS
2881 verify_symbol_chain (symbol_rootP, symbol_lastP);
2882 #endif /* DEBUG_SYMS */
2883 }
2884
2885
2886 static void
2887 s_ltorg (int ignored ATTRIBUTE_UNUSED)
2888 {
2889 unsigned int entry;
2890 literal_pool * pool;
2891 char sym_name[20];
2892
2893 pool = find_literal_pool ();
2894 if (pool == NULL
2895 || pool->symbol == NULL
2896 || pool->next_free_entry == 0)
2897 return;
2898
2899 mapping_state (MAP_DATA);
2900
2901 /* Align pool as you have word accesses.
2902 Only make a frag if we have to. */
2903 if (!need_pass_2)
2904 frag_align (2, 0, 0);
2905
2906 record_alignment (now_seg, 2);
2907
2908 sprintf (sym_name, "$$lit_\002%x", pool->id);
2909
2910 symbol_locate (pool->symbol, sym_name, now_seg,
2911 (valueT) frag_now_fix (), frag_now);
2912 symbol_table_insert (pool->symbol);
2913
2914 ARM_SET_THUMB (pool->symbol, thumb_mode);
2915
2916 #if defined OBJ_COFF || defined OBJ_ELF
2917 ARM_SET_INTERWORK (pool->symbol, support_interwork);
2918 #endif
2919
2920 for (entry = 0; entry < pool->next_free_entry; entry ++)
2921 /* First output the expression in the instruction to the pool. */
2922 emit_expr (&(pool->literals[entry]), 4); /* .word */
2923
2924 /* Mark the pool as empty. */
2925 pool->next_free_entry = 0;
2926 pool->symbol = NULL;
2927 }
2928
2929 #ifdef OBJ_ELF
2930 /* Forward declarations for functions below, in the MD interface
2931 section. */
2932 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
2933 static valueT create_unwind_entry (int);
2934 static void start_unwind_section (const segT, int);
2935 static void add_unwind_opcode (valueT, int);
2936 static void flush_pending_unwind (void);
2937
2938 /* Directives: Data. */
2939
2940 static void
2941 s_arm_elf_cons (int nbytes)
2942 {
2943 expressionS exp;
2944
2945 #ifdef md_flush_pending_output
2946 md_flush_pending_output ();
2947 #endif
2948
2949 if (is_it_end_of_statement ())
2950 {
2951 demand_empty_rest_of_line ();
2952 return;
2953 }
2954
2955 #ifdef md_cons_align
2956 md_cons_align (nbytes);
2957 #endif
2958
2959 mapping_state (MAP_DATA);
2960 do
2961 {
2962 int reloc;
2963 char *base = input_line_pointer;
2964
2965 expression (& exp);
2966
2967 if (exp.X_op != O_symbol)
2968 emit_expr (&exp, (unsigned int) nbytes);
2969 else
2970 {
2971 char *before_reloc = input_line_pointer;
2972 reloc = parse_reloc (&input_line_pointer);
2973 if (reloc == -1)
2974 {
2975 as_bad (_("unrecognized relocation suffix"));
2976 ignore_rest_of_line ();
2977 return;
2978 }
2979 else if (reloc == BFD_RELOC_UNUSED)
2980 emit_expr (&exp, (unsigned int) nbytes);
2981 else
2982 {
2983 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
2984 int size = bfd_get_reloc_size (howto);
2985
2986 if (reloc == BFD_RELOC_ARM_PLT32)
2987 {
2988 as_bad (_("(plt) is only valid on branch targets"));
2989 reloc = BFD_RELOC_UNUSED;
2990 size = 0;
2991 }
2992
2993 if (size > nbytes)
2994 as_bad (_("%s relocations do not fit in %d bytes"),
2995 howto->name, nbytes);
2996 else
2997 {
2998 /* We've parsed an expression stopping at O_symbol.
2999 But there may be more expression left now that we
3000 have parsed the relocation marker. Parse it again.
3001 XXX Surely there is a cleaner way to do this. */
3002 char *p = input_line_pointer;
3003 int offset;
3004 char *save_buf = alloca (input_line_pointer - base);
3005 memcpy (save_buf, base, input_line_pointer - base);
3006 memmove (base + (input_line_pointer - before_reloc),
3007 base, before_reloc - base);
3008
3009 input_line_pointer = base + (input_line_pointer-before_reloc);
3010 expression (&exp);
3011 memcpy (base, save_buf, p - base);
3012
3013 offset = nbytes - size;
3014 p = frag_more ((int) nbytes);
3015 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3016 size, &exp, 0, reloc);
3017 }
3018 }
3019 }
3020 }
3021 while (*input_line_pointer++ == ',');
3022
3023 /* Put terminator back into stream. */
3024 input_line_pointer --;
3025 demand_empty_rest_of_line ();
3026 }
3027
3028
3029 /* Parse a .rel31 directive. */
3030
3031 static void
3032 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3033 {
3034 expressionS exp;
3035 char *p;
3036 valueT highbit;
3037
3038 highbit = 0;
3039 if (*input_line_pointer == '1')
3040 highbit = 0x80000000;
3041 else if (*input_line_pointer != '0')
3042 as_bad (_("expected 0 or 1"));
3043
3044 input_line_pointer++;
3045 if (*input_line_pointer != ',')
3046 as_bad (_("missing comma"));
3047 input_line_pointer++;
3048
3049 #ifdef md_flush_pending_output
3050 md_flush_pending_output ();
3051 #endif
3052
3053 #ifdef md_cons_align
3054 md_cons_align (4);
3055 #endif
3056
3057 mapping_state (MAP_DATA);
3058
3059 expression (&exp);
3060
3061 p = frag_more (4);
3062 md_number_to_chars (p, highbit, 4);
3063 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3064 BFD_RELOC_ARM_PREL31);
3065
3066 demand_empty_rest_of_line ();
3067 }
3068
3069 /* Directives: AEABI stack-unwind tables. */
3070
3071 /* Parse an unwind_fnstart directive. Simply records the current location. */
3072
3073 static void
3074 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3075 {
3076 demand_empty_rest_of_line ();
3077 /* Mark the start of the function. */
3078 unwind.proc_start = expr_build_dot ();
3079
3080 /* Reset the rest of the unwind info. */
3081 unwind.opcode_count = 0;
3082 unwind.table_entry = NULL;
3083 unwind.personality_routine = NULL;
3084 unwind.personality_index = -1;
3085 unwind.frame_size = 0;
3086 unwind.fp_offset = 0;
3087 unwind.fp_reg = 13;
3088 unwind.fp_used = 0;
3089 unwind.sp_restored = 0;
3090 }
3091
3092
3093 /* Parse a handlerdata directive. Creates the exception handling table entry
3094 for the function. */
3095
3096 static void
3097 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3098 {
3099 demand_empty_rest_of_line ();
3100 if (unwind.table_entry)
3101 as_bad (_("dupicate .handlerdata directive"));
3102
3103 create_unwind_entry (1);
3104 }
3105
3106 /* Parse an unwind_fnend directive. Generates the index table entry. */
3107
3108 static void
3109 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3110 {
3111 long where;
3112 char *ptr;
3113 valueT val;
3114
3115 demand_empty_rest_of_line ();
3116
3117 /* Add eh table entry. */
3118 if (unwind.table_entry == NULL)
3119 val = create_unwind_entry (0);
3120 else
3121 val = 0;
3122
3123 /* Add index table entry. This is two words. */
3124 start_unwind_section (unwind.saved_seg, 1);
3125 frag_align (2, 0, 0);
3126 record_alignment (now_seg, 2);
3127
3128 ptr = frag_more (8);
3129 where = frag_now_fix () - 8;
3130
3131 /* Self relative offset of the function start. */
3132 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3133 BFD_RELOC_ARM_PREL31);
3134
3135 /* Indicate dependency on EHABI-defined personality routines to the
3136 linker, if it hasn't been done already. */
3137 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3138 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3139 {
3140 static const char *const name[] = {
3141 "__aeabi_unwind_cpp_pr0",
3142 "__aeabi_unwind_cpp_pr1",
3143 "__aeabi_unwind_cpp_pr2"
3144 };
3145 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3146 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3147 marked_pr_dependency |= 1 << unwind.personality_index;
3148 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3149 = marked_pr_dependency;
3150 }
3151
3152 if (val)
3153 /* Inline exception table entry. */
3154 md_number_to_chars (ptr + 4, val, 4);
3155 else
3156 /* Self relative offset of the table entry. */
3157 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3158 BFD_RELOC_ARM_PREL31);
3159
3160 /* Restore the original section. */
3161 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3162 }
3163
3164
3165 /* Parse an unwind_cantunwind directive. */
3166
3167 static void
3168 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3169 {
3170 demand_empty_rest_of_line ();
3171 if (unwind.personality_routine || unwind.personality_index != -1)
3172 as_bad (_("personality routine specified for cantunwind frame"));
3173
3174 unwind.personality_index = -2;
3175 }
3176
3177
3178 /* Parse a personalityindex directive. */
3179
3180 static void
3181 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3182 {
3183 expressionS exp;
3184
3185 if (unwind.personality_routine || unwind.personality_index != -1)
3186 as_bad (_("duplicate .personalityindex directive"));
3187
3188 expression (&exp);
3189
3190 if (exp.X_op != O_constant
3191 || exp.X_add_number < 0 || exp.X_add_number > 15)
3192 {
3193 as_bad (_("bad personality routine number"));
3194 ignore_rest_of_line ();
3195 return;
3196 }
3197
3198 unwind.personality_index = exp.X_add_number;
3199
3200 demand_empty_rest_of_line ();
3201 }
3202
3203
3204 /* Parse a personality directive. */
3205
3206 static void
3207 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3208 {
3209 char *name, *p, c;
3210
3211 if (unwind.personality_routine || unwind.personality_index != -1)
3212 as_bad (_("duplicate .personality directive"));
3213
3214 name = input_line_pointer;
3215 c = get_symbol_end ();
3216 p = input_line_pointer;
3217 unwind.personality_routine = symbol_find_or_make (name);
3218 *p = c;
3219 demand_empty_rest_of_line ();
3220 }
3221
3222
3223 /* Parse a directive saving core registers. */
3224
3225 static void
3226 s_arm_unwind_save_core (void)
3227 {
3228 valueT op;
3229 long range;
3230 int n;
3231
3232 range = parse_reg_list (&input_line_pointer);
3233 if (range == FAIL)
3234 {
3235 as_bad (_("expected register list"));
3236 ignore_rest_of_line ();
3237 return;
3238 }
3239
3240 demand_empty_rest_of_line ();
3241
3242 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3243 into .unwind_save {..., sp...}. We aren't bothered about the value of
3244 ip because it is clobbered by calls. */
3245 if (unwind.sp_restored && unwind.fp_reg == 12
3246 && (range & 0x3000) == 0x1000)
3247 {
3248 unwind.opcode_count--;
3249 unwind.sp_restored = 0;
3250 range = (range | 0x2000) & ~0x1000;
3251 unwind.pending_offset = 0;
3252 }
3253
3254 /* Pop r4-r15. */
3255 if (range & 0xfff0)
3256 {
3257 /* See if we can use the short opcodes. These pop a block of up to 8
3258 registers starting with r4, plus maybe r14. */
3259 for (n = 0; n < 8; n++)
3260 {
3261 /* Break at the first non-saved register. */
3262 if ((range & (1 << (n + 4))) == 0)
3263 break;
3264 }
3265 /* See if there are any other bits set. */
3266 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3267 {
3268 /* Use the long form. */
3269 op = 0x8000 | ((range >> 4) & 0xfff);
3270 add_unwind_opcode (op, 2);
3271 }
3272 else
3273 {
3274 /* Use the short form. */
3275 if (range & 0x4000)
3276 op = 0xa8; /* Pop r14. */
3277 else
3278 op = 0xa0; /* Do not pop r14. */
3279 op |= (n - 1);
3280 add_unwind_opcode (op, 1);
3281 }
3282 }
3283
3284 /* Pop r0-r3. */
3285 if (range & 0xf)
3286 {
3287 op = 0xb100 | (range & 0xf);
3288 add_unwind_opcode (op, 2);
3289 }
3290
3291 /* Record the number of bytes pushed. */
3292 for (n = 0; n < 16; n++)
3293 {
3294 if (range & (1 << n))
3295 unwind.frame_size += 4;
3296 }
3297 }
3298
3299
3300 /* Parse a directive saving FPA registers. */
3301
3302 static void
3303 s_arm_unwind_save_fpa (int reg)
3304 {
3305 expressionS exp;
3306 int num_regs;
3307 valueT op;
3308
3309 /* Get Number of registers to transfer. */
3310 if (skip_past_comma (&input_line_pointer) != FAIL)
3311 expression (&exp);
3312 else
3313 exp.X_op = O_illegal;
3314
3315 if (exp.X_op != O_constant)
3316 {
3317 as_bad (_("expected , <constant>"));
3318 ignore_rest_of_line ();
3319 return;
3320 }
3321
3322 num_regs = exp.X_add_number;
3323
3324 if (num_regs < 1 || num_regs > 4)
3325 {
3326 as_bad (_("number of registers must be in the range [1:4]"));
3327 ignore_rest_of_line ();
3328 return;
3329 }
3330
3331 demand_empty_rest_of_line ();
3332
3333 if (reg == 4)
3334 {
3335 /* Short form. */
3336 op = 0xb4 | (num_regs - 1);
3337 add_unwind_opcode (op, 1);
3338 }
3339 else
3340 {
3341 /* Long form. */
3342 op = 0xc800 | (reg << 4) | (num_regs - 1);
3343 add_unwind_opcode (op, 2);
3344 }
3345 unwind.frame_size += num_regs * 12;
3346 }
3347
3348
3349 /* Parse a directive saving VFP registers for ARMv6 and above. */
3350
3351 static void
3352 s_arm_unwind_save_vfp_armv6 (void)
3353 {
3354 int count;
3355 unsigned int start;
3356 valueT op;
3357 int num_vfpv3_regs = 0;
3358 int num_regs_below_16;
3359
3360 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3361 if (count == FAIL)
3362 {
3363 as_bad (_("expected register list"));
3364 ignore_rest_of_line ();
3365 return;
3366 }
3367
3368 demand_empty_rest_of_line ();
3369
3370 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3371 than FSTMX/FLDMX-style ones). */
3372
3373 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3374 if (start >= 16)
3375 num_vfpv3_regs = count;
3376 else if (start + count > 16)
3377 num_vfpv3_regs = start + count - 16;
3378
3379 if (num_vfpv3_regs > 0)
3380 {
3381 int start_offset = start > 16 ? start - 16 : 0;
3382 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3383 add_unwind_opcode (op, 2);
3384 }
3385
3386 /* Generate opcode for registers numbered in the range 0 .. 15. */
3387 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3388 assert (num_regs_below_16 + num_vfpv3_regs == count);
3389 if (num_regs_below_16 > 0)
3390 {
3391 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3392 add_unwind_opcode (op, 2);
3393 }
3394
3395 unwind.frame_size += count * 8;
3396 }
3397
3398
3399 /* Parse a directive saving VFP registers for pre-ARMv6. */
3400
3401 static void
3402 s_arm_unwind_save_vfp (void)
3403 {
3404 int count;
3405 unsigned int reg;
3406 valueT op;
3407
3408 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
3409 if (count == FAIL)
3410 {
3411 as_bad (_("expected register list"));
3412 ignore_rest_of_line ();
3413 return;
3414 }
3415
3416 demand_empty_rest_of_line ();
3417
3418 if (reg == 8)
3419 {
3420 /* Short form. */
3421 op = 0xb8 | (count - 1);
3422 add_unwind_opcode (op, 1);
3423 }
3424 else
3425 {
3426 /* Long form. */
3427 op = 0xb300 | (reg << 4) | (count - 1);
3428 add_unwind_opcode (op, 2);
3429 }
3430 unwind.frame_size += count * 8 + 4;
3431 }
3432
3433
3434 /* Parse a directive saving iWMMXt data registers. */
3435
3436 static void
3437 s_arm_unwind_save_mmxwr (void)
3438 {
3439 int reg;
3440 int hi_reg;
3441 int i;
3442 unsigned mask = 0;
3443 valueT op;
3444
3445 if (*input_line_pointer == '{')
3446 input_line_pointer++;
3447
3448 do
3449 {
3450 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3451
3452 if (reg == FAIL)
3453 {
3454 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3455 goto error;
3456 }
3457
3458 if (mask >> reg)
3459 as_tsktsk (_("register list not in ascending order"));
3460 mask |= 1 << reg;
3461
3462 if (*input_line_pointer == '-')
3463 {
3464 input_line_pointer++;
3465 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3466 if (hi_reg == FAIL)
3467 {
3468 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3469 goto error;
3470 }
3471 else if (reg >= hi_reg)
3472 {
3473 as_bad (_("bad register range"));
3474 goto error;
3475 }
3476 for (; reg < hi_reg; reg++)
3477 mask |= 1 << reg;
3478 }
3479 }
3480 while (skip_past_comma (&input_line_pointer) != FAIL);
3481
3482 if (*input_line_pointer == '}')
3483 input_line_pointer++;
3484
3485 demand_empty_rest_of_line ();
3486
3487 /* Generate any deferred opcodes because we're going to be looking at
3488 the list. */
3489 flush_pending_unwind ();
3490
3491 for (i = 0; i < 16; i++)
3492 {
3493 if (mask & (1 << i))
3494 unwind.frame_size += 8;
3495 }
3496
3497 /* Attempt to combine with a previous opcode. We do this because gcc
3498 likes to output separate unwind directives for a single block of
3499 registers. */
3500 if (unwind.opcode_count > 0)
3501 {
3502 i = unwind.opcodes[unwind.opcode_count - 1];
3503 if ((i & 0xf8) == 0xc0)
3504 {
3505 i &= 7;
3506 /* Only merge if the blocks are contiguous. */
3507 if (i < 6)
3508 {
3509 if ((mask & 0xfe00) == (1 << 9))
3510 {
3511 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3512 unwind.opcode_count--;
3513 }
3514 }
3515 else if (i == 6 && unwind.opcode_count >= 2)
3516 {
3517 i = unwind.opcodes[unwind.opcode_count - 2];
3518 reg = i >> 4;
3519 i &= 0xf;
3520
3521 op = 0xffff << (reg - 1);
3522 if (reg > 0
3523 && ((mask & op) == (1u << (reg - 1))))
3524 {
3525 op = (1 << (reg + i + 1)) - 1;
3526 op &= ~((1 << reg) - 1);
3527 mask |= op;
3528 unwind.opcode_count -= 2;
3529 }
3530 }
3531 }
3532 }
3533
3534 hi_reg = 15;
3535 /* We want to generate opcodes in the order the registers have been
3536 saved, ie. descending order. */
3537 for (reg = 15; reg >= -1; reg--)
3538 {
3539 /* Save registers in blocks. */
3540 if (reg < 0
3541 || !(mask & (1 << reg)))
3542 {
3543 /* We found an unsaved reg. Generate opcodes to save the
3544 preceeding block. */
3545 if (reg != hi_reg)
3546 {
3547 if (reg == 9)
3548 {
3549 /* Short form. */
3550 op = 0xc0 | (hi_reg - 10);
3551 add_unwind_opcode (op, 1);
3552 }
3553 else
3554 {
3555 /* Long form. */
3556 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3557 add_unwind_opcode (op, 2);
3558 }
3559 }
3560 hi_reg = reg - 1;
3561 }
3562 }
3563
3564 return;
3565 error:
3566 ignore_rest_of_line ();
3567 }
3568
3569 static void
3570 s_arm_unwind_save_mmxwcg (void)
3571 {
3572 int reg;
3573 int hi_reg;
3574 unsigned mask = 0;
3575 valueT op;
3576
3577 if (*input_line_pointer == '{')
3578 input_line_pointer++;
3579
3580 do
3581 {
3582 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3583
3584 if (reg == FAIL)
3585 {
3586 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3587 goto error;
3588 }
3589
3590 reg -= 8;
3591 if (mask >> reg)
3592 as_tsktsk (_("register list not in ascending order"));
3593 mask |= 1 << reg;
3594
3595 if (*input_line_pointer == '-')
3596 {
3597 input_line_pointer++;
3598 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3599 if (hi_reg == FAIL)
3600 {
3601 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3602 goto error;
3603 }
3604 else if (reg >= hi_reg)
3605 {
3606 as_bad (_("bad register range"));
3607 goto error;
3608 }
3609 for (; reg < hi_reg; reg++)
3610 mask |= 1 << reg;
3611 }
3612 }
3613 while (skip_past_comma (&input_line_pointer) != FAIL);
3614
3615 if (*input_line_pointer == '}')
3616 input_line_pointer++;
3617
3618 demand_empty_rest_of_line ();
3619
3620 /* Generate any deferred opcodes because we're going to be looking at
3621 the list. */
3622 flush_pending_unwind ();
3623
3624 for (reg = 0; reg < 16; reg++)
3625 {
3626 if (mask & (1 << reg))
3627 unwind.frame_size += 4;
3628 }
3629 op = 0xc700 | mask;
3630 add_unwind_opcode (op, 2);
3631 return;
3632 error:
3633 ignore_rest_of_line ();
3634 }
3635
3636
3637 /* Parse an unwind_save directive.
3638 If the argument is non-zero, this is a .vsave directive. */
3639
3640 static void
3641 s_arm_unwind_save (int arch_v6)
3642 {
3643 char *peek;
3644 struct reg_entry *reg;
3645 bfd_boolean had_brace = FALSE;
3646
3647 /* Figure out what sort of save we have. */
3648 peek = input_line_pointer;
3649
3650 if (*peek == '{')
3651 {
3652 had_brace = TRUE;
3653 peek++;
3654 }
3655
3656 reg = arm_reg_parse_multi (&peek);
3657
3658 if (!reg)
3659 {
3660 as_bad (_("register expected"));
3661 ignore_rest_of_line ();
3662 return;
3663 }
3664
3665 switch (reg->type)
3666 {
3667 case REG_TYPE_FN:
3668 if (had_brace)
3669 {
3670 as_bad (_("FPA .unwind_save does not take a register list"));
3671 ignore_rest_of_line ();
3672 return;
3673 }
3674 s_arm_unwind_save_fpa (reg->number);
3675 return;
3676
3677 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
3678 case REG_TYPE_VFD:
3679 if (arch_v6)
3680 s_arm_unwind_save_vfp_armv6 ();
3681 else
3682 s_arm_unwind_save_vfp ();
3683 return;
3684 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
3685 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
3686
3687 default:
3688 as_bad (_(".unwind_save does not support this kind of register"));
3689 ignore_rest_of_line ();
3690 }
3691 }
3692
3693
3694 /* Parse an unwind_movsp directive. */
3695
3696 static void
3697 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
3698 {
3699 int reg;
3700 valueT op;
3701 int offset;
3702
3703 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3704 if (reg == FAIL)
3705 {
3706 as_bad (_(reg_expected_msgs[REG_TYPE_RN]));
3707 ignore_rest_of_line ();
3708 return;
3709 }
3710
3711 /* Optional constant. */
3712 if (skip_past_comma (&input_line_pointer) != FAIL)
3713 {
3714 if (immediate_for_directive (&offset) == FAIL)
3715 return;
3716 }
3717 else
3718 offset = 0;
3719
3720 demand_empty_rest_of_line ();
3721
3722 if (reg == REG_SP || reg == REG_PC)
3723 {
3724 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
3725 return;
3726 }
3727
3728 if (unwind.fp_reg != REG_SP)
3729 as_bad (_("unexpected .unwind_movsp directive"));
3730
3731 /* Generate opcode to restore the value. */
3732 op = 0x90 | reg;
3733 add_unwind_opcode (op, 1);
3734
3735 /* Record the information for later. */
3736 unwind.fp_reg = reg;
3737 unwind.fp_offset = unwind.frame_size - offset;
3738 unwind.sp_restored = 1;
3739 }
3740
3741 /* Parse an unwind_pad directive. */
3742
3743 static void
3744 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
3745 {
3746 int offset;
3747
3748 if (immediate_for_directive (&offset) == FAIL)
3749 return;
3750
3751 if (offset & 3)
3752 {
3753 as_bad (_("stack increment must be multiple of 4"));
3754 ignore_rest_of_line ();
3755 return;
3756 }
3757
3758 /* Don't generate any opcodes, just record the details for later. */
3759 unwind.frame_size += offset;
3760 unwind.pending_offset += offset;
3761
3762 demand_empty_rest_of_line ();
3763 }
3764
3765 /* Parse an unwind_setfp directive. */
3766
3767 static void
3768 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
3769 {
3770 int sp_reg;
3771 int fp_reg;
3772 int offset;
3773
3774 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3775 if (skip_past_comma (&input_line_pointer) == FAIL)
3776 sp_reg = FAIL;
3777 else
3778 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3779
3780 if (fp_reg == FAIL || sp_reg == FAIL)
3781 {
3782 as_bad (_("expected <reg>, <reg>"));
3783 ignore_rest_of_line ();
3784 return;
3785 }
3786
3787 /* Optional constant. */
3788 if (skip_past_comma (&input_line_pointer) != FAIL)
3789 {
3790 if (immediate_for_directive (&offset) == FAIL)
3791 return;
3792 }
3793 else
3794 offset = 0;
3795
3796 demand_empty_rest_of_line ();
3797
3798 if (sp_reg != 13 && sp_reg != unwind.fp_reg)
3799 {
3800 as_bad (_("register must be either sp or set by a previous"
3801 "unwind_movsp directive"));
3802 return;
3803 }
3804
3805 /* Don't generate any opcodes, just record the information for later. */
3806 unwind.fp_reg = fp_reg;
3807 unwind.fp_used = 1;
3808 if (sp_reg == 13)
3809 unwind.fp_offset = unwind.frame_size - offset;
3810 else
3811 unwind.fp_offset -= offset;
3812 }
3813
3814 /* Parse an unwind_raw directive. */
3815
3816 static void
3817 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
3818 {
3819 expressionS exp;
3820 /* This is an arbitrary limit. */
3821 unsigned char op[16];
3822 int count;
3823
3824 expression (&exp);
3825 if (exp.X_op == O_constant
3826 && skip_past_comma (&input_line_pointer) != FAIL)
3827 {
3828 unwind.frame_size += exp.X_add_number;
3829 expression (&exp);
3830 }
3831 else
3832 exp.X_op = O_illegal;
3833
3834 if (exp.X_op != O_constant)
3835 {
3836 as_bad (_("expected <offset>, <opcode>"));
3837 ignore_rest_of_line ();
3838 return;
3839 }
3840
3841 count = 0;
3842
3843 /* Parse the opcode. */
3844 for (;;)
3845 {
3846 if (count >= 16)
3847 {
3848 as_bad (_("unwind opcode too long"));
3849 ignore_rest_of_line ();
3850 }
3851 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
3852 {
3853 as_bad (_("invalid unwind opcode"));
3854 ignore_rest_of_line ();
3855 return;
3856 }
3857 op[count++] = exp.X_add_number;
3858
3859 /* Parse the next byte. */
3860 if (skip_past_comma (&input_line_pointer) == FAIL)
3861 break;
3862
3863 expression (&exp);
3864 }
3865
3866 /* Add the opcode bytes in reverse order. */
3867 while (count--)
3868 add_unwind_opcode (op[count], 1);
3869
3870 demand_empty_rest_of_line ();
3871 }
3872
3873
3874 /* Parse a .eabi_attribute directive. */
3875
3876 static void
3877 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
3878 {
3879 s_vendor_attribute (OBJ_ATTR_PROC);
3880 }
3881 #endif /* OBJ_ELF */
3882
3883 static void s_arm_arch (int);
3884 static void s_arm_object_arch (int);
3885 static void s_arm_cpu (int);
3886 static void s_arm_fpu (int);
3887
3888 #ifdef TE_PE
3889
3890 static void
3891 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
3892 {
3893 expressionS exp;
3894
3895 do
3896 {
3897 expression (&exp);
3898 if (exp.X_op == O_symbol)
3899 exp.X_op = O_secrel;
3900
3901 emit_expr (&exp, 4);
3902 }
3903 while (*input_line_pointer++ == ',');
3904
3905 input_line_pointer--;
3906 demand_empty_rest_of_line ();
3907 }
3908 #endif /* TE_PE */
3909
3910 /* This table describes all the machine specific pseudo-ops the assembler
3911 has to support. The fields are:
3912 pseudo-op name without dot
3913 function to call to execute this pseudo-op
3914 Integer arg to pass to the function. */
3915
3916 const pseudo_typeS md_pseudo_table[] =
3917 {
3918 /* Never called because '.req' does not start a line. */
3919 { "req", s_req, 0 },
3920 /* Following two are likewise never called. */
3921 { "dn", s_dn, 0 },
3922 { "qn", s_qn, 0 },
3923 { "unreq", s_unreq, 0 },
3924 { "bss", s_bss, 0 },
3925 { "align", s_align, 0 },
3926 { "arm", s_arm, 0 },
3927 { "thumb", s_thumb, 0 },
3928 { "code", s_code, 0 },
3929 { "force_thumb", s_force_thumb, 0 },
3930 { "thumb_func", s_thumb_func, 0 },
3931 { "thumb_set", s_thumb_set, 0 },
3932 { "even", s_even, 0 },
3933 { "ltorg", s_ltorg, 0 },
3934 { "pool", s_ltorg, 0 },
3935 { "syntax", s_syntax, 0 },
3936 { "cpu", s_arm_cpu, 0 },
3937 { "arch", s_arm_arch, 0 },
3938 { "object_arch", s_arm_object_arch, 0 },
3939 { "fpu", s_arm_fpu, 0 },
3940 #ifdef OBJ_ELF
3941 { "word", s_arm_elf_cons, 4 },
3942 { "long", s_arm_elf_cons, 4 },
3943 { "rel31", s_arm_rel31, 0 },
3944 { "fnstart", s_arm_unwind_fnstart, 0 },
3945 { "fnend", s_arm_unwind_fnend, 0 },
3946 { "cantunwind", s_arm_unwind_cantunwind, 0 },
3947 { "personality", s_arm_unwind_personality, 0 },
3948 { "personalityindex", s_arm_unwind_personalityindex, 0 },
3949 { "handlerdata", s_arm_unwind_handlerdata, 0 },
3950 { "save", s_arm_unwind_save, 0 },
3951 { "vsave", s_arm_unwind_save, 1 },
3952 { "movsp", s_arm_unwind_movsp, 0 },
3953 { "pad", s_arm_unwind_pad, 0 },
3954 { "setfp", s_arm_unwind_setfp, 0 },
3955 { "unwind_raw", s_arm_unwind_raw, 0 },
3956 { "eabi_attribute", s_arm_eabi_attribute, 0 },
3957 #else
3958 { "word", cons, 4},
3959
3960 /* These are used for dwarf. */
3961 {"2byte", cons, 2},
3962 {"4byte", cons, 4},
3963 {"8byte", cons, 8},
3964 /* These are used for dwarf2. */
3965 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
3966 { "loc", dwarf2_directive_loc, 0 },
3967 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
3968 #endif
3969 { "extend", float_cons, 'x' },
3970 { "ldouble", float_cons, 'x' },
3971 { "packed", float_cons, 'p' },
3972 #ifdef TE_PE
3973 {"secrel32", pe_directive_secrel, 0},
3974 #endif
3975 { 0, 0, 0 }
3976 };
3977 \f
3978 /* Parser functions used exclusively in instruction operands. */
3979
3980 /* Generic immediate-value read function for use in insn parsing.
3981 STR points to the beginning of the immediate (the leading #);
3982 VAL receives the value; if the value is outside [MIN, MAX]
3983 issue an error. PREFIX_OPT is true if the immediate prefix is
3984 optional. */
3985
3986 static int
3987 parse_immediate (char **str, int *val, int min, int max,
3988 bfd_boolean prefix_opt)
3989 {
3990 expressionS exp;
3991 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
3992 if (exp.X_op != O_constant)
3993 {
3994 inst.error = _("constant expression required");
3995 return FAIL;
3996 }
3997
3998 if (exp.X_add_number < min || exp.X_add_number > max)
3999 {
4000 inst.error = _("immediate value out of range");
4001 return FAIL;
4002 }
4003
4004 *val = exp.X_add_number;
4005 return SUCCESS;
4006 }
4007
4008 /* Less-generic immediate-value read function with the possibility of loading a
4009 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
4010 instructions. Puts the result directly in inst.operands[i]. */
4011
4012 static int
4013 parse_big_immediate (char **str, int i)
4014 {
4015 expressionS exp;
4016 char *ptr = *str;
4017
4018 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4019
4020 if (exp.X_op == O_constant)
4021 {
4022 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4023 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4024 O_constant. We have to be careful not to break compilation for
4025 32-bit X_add_number, though. */
4026 if ((exp.X_add_number & ~0xffffffffl) != 0)
4027 {
4028 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4029 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4030 inst.operands[i].regisimm = 1;
4031 }
4032 }
4033 else if (exp.X_op == O_big
4034 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4035 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4036 {
4037 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4038 /* Bignums have their least significant bits in
4039 generic_bignum[0]. Make sure we put 32 bits in imm and
4040 32 bits in reg, in a (hopefully) portable way. */
4041 assert (parts != 0);
4042 inst.operands[i].imm = 0;
4043 for (j = 0; j < parts; j++, idx++)
4044 inst.operands[i].imm |= generic_bignum[idx]
4045 << (LITTLENUM_NUMBER_OF_BITS * j);
4046 inst.operands[i].reg = 0;
4047 for (j = 0; j < parts; j++, idx++)
4048 inst.operands[i].reg |= generic_bignum[idx]
4049 << (LITTLENUM_NUMBER_OF_BITS * j);
4050 inst.operands[i].regisimm = 1;
4051 }
4052 else
4053 return FAIL;
4054
4055 *str = ptr;
4056
4057 return SUCCESS;
4058 }
4059
4060 /* Returns the pseudo-register number of an FPA immediate constant,
4061 or FAIL if there isn't a valid constant here. */
4062
4063 static int
4064 parse_fpa_immediate (char ** str)
4065 {
4066 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4067 char * save_in;
4068 expressionS exp;
4069 int i;
4070 int j;
4071
4072 /* First try and match exact strings, this is to guarantee
4073 that some formats will work even for cross assembly. */
4074
4075 for (i = 0; fp_const[i]; i++)
4076 {
4077 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4078 {
4079 char *start = *str;
4080
4081 *str += strlen (fp_const[i]);
4082 if (is_end_of_line[(unsigned char) **str])
4083 return i + 8;
4084 *str = start;
4085 }
4086 }
4087
4088 /* Just because we didn't get a match doesn't mean that the constant
4089 isn't valid, just that it is in a format that we don't
4090 automatically recognize. Try parsing it with the standard
4091 expression routines. */
4092
4093 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
4094
4095 /* Look for a raw floating point number. */
4096 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4097 && is_end_of_line[(unsigned char) *save_in])
4098 {
4099 for (i = 0; i < NUM_FLOAT_VALS; i++)
4100 {
4101 for (j = 0; j < MAX_LITTLENUMS; j++)
4102 {
4103 if (words[j] != fp_values[i][j])
4104 break;
4105 }
4106
4107 if (j == MAX_LITTLENUMS)
4108 {
4109 *str = save_in;
4110 return i + 8;
4111 }
4112 }
4113 }
4114
4115 /* Try and parse a more complex expression, this will probably fail
4116 unless the code uses a floating point prefix (eg "0f"). */
4117 save_in = input_line_pointer;
4118 input_line_pointer = *str;
4119 if (expression (&exp) == absolute_section
4120 && exp.X_op == O_big
4121 && exp.X_add_number < 0)
4122 {
4123 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4124 Ditto for 15. */
4125 if (gen_to_words (words, 5, (long) 15) == 0)
4126 {
4127 for (i = 0; i < NUM_FLOAT_VALS; i++)
4128 {
4129 for (j = 0; j < MAX_LITTLENUMS; j++)
4130 {
4131 if (words[j] != fp_values[i][j])
4132 break;
4133 }
4134
4135 if (j == MAX_LITTLENUMS)
4136 {
4137 *str = input_line_pointer;
4138 input_line_pointer = save_in;
4139 return i + 8;
4140 }
4141 }
4142 }
4143 }
4144
4145 *str = input_line_pointer;
4146 input_line_pointer = save_in;
4147 inst.error = _("invalid FPA immediate expression");
4148 return FAIL;
4149 }
4150
4151 /* Returns 1 if a number has "quarter-precision" float format
4152 0baBbbbbbc defgh000 00000000 00000000. */
4153
4154 static int
4155 is_quarter_float (unsigned imm)
4156 {
4157 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4158 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4159 }
4160
4161 /* Parse an 8-bit "quarter-precision" floating point number of the form:
4162 0baBbbbbbc defgh000 00000000 00000000.
4163 The zero and minus-zero cases need special handling, since they can't be
4164 encoded in the "quarter-precision" float format, but can nonetheless be
4165 loaded as integer constants. */
4166
4167 static unsigned
4168 parse_qfloat_immediate (char **ccp, int *immed)
4169 {
4170 char *str = *ccp;
4171 char *fpnum;
4172 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4173 int found_fpchar = 0;
4174
4175 skip_past_char (&str, '#');
4176
4177 /* We must not accidentally parse an integer as a floating-point number. Make
4178 sure that the value we parse is not an integer by checking for special
4179 characters '.' or 'e'.
4180 FIXME: This is a horrible hack, but doing better is tricky because type
4181 information isn't in a very usable state at parse time. */
4182 fpnum = str;
4183 skip_whitespace (fpnum);
4184
4185 if (strncmp (fpnum, "0x", 2) == 0)
4186 return FAIL;
4187 else
4188 {
4189 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4190 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4191 {
4192 found_fpchar = 1;
4193 break;
4194 }
4195
4196 if (!found_fpchar)
4197 return FAIL;
4198 }
4199
4200 if ((str = atof_ieee (str, 's', words)) != NULL)
4201 {
4202 unsigned fpword = 0;
4203 int i;
4204
4205 /* Our FP word must be 32 bits (single-precision FP). */
4206 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4207 {
4208 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4209 fpword |= words[i];
4210 }
4211
4212 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
4213 *immed = fpword;
4214 else
4215 return FAIL;
4216
4217 *ccp = str;
4218
4219 return SUCCESS;
4220 }
4221
4222 return FAIL;
4223 }
4224
4225 /* Shift operands. */
4226 enum shift_kind
4227 {
4228 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4229 };
4230
4231 struct asm_shift_name
4232 {
4233 const char *name;
4234 enum shift_kind kind;
4235 };
4236
4237 /* Third argument to parse_shift. */
4238 enum parse_shift_mode
4239 {
4240 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4241 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4242 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4243 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4244 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4245 };
4246
4247 /* Parse a <shift> specifier on an ARM data processing instruction.
4248 This has three forms:
4249
4250 (LSL|LSR|ASL|ASR|ROR) Rs
4251 (LSL|LSR|ASL|ASR|ROR) #imm
4252 RRX
4253
4254 Note that ASL is assimilated to LSL in the instruction encoding, and
4255 RRX to ROR #0 (which cannot be written as such). */
4256
4257 static int
4258 parse_shift (char **str, int i, enum parse_shift_mode mode)
4259 {
4260 const struct asm_shift_name *shift_name;
4261 enum shift_kind shift;
4262 char *s = *str;
4263 char *p = s;
4264 int reg;
4265
4266 for (p = *str; ISALPHA (*p); p++)
4267 ;
4268
4269 if (p == *str)
4270 {
4271 inst.error = _("shift expression expected");
4272 return FAIL;
4273 }
4274
4275 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
4276
4277 if (shift_name == NULL)
4278 {
4279 inst.error = _("shift expression expected");
4280 return FAIL;
4281 }
4282
4283 shift = shift_name->kind;
4284
4285 switch (mode)
4286 {
4287 case NO_SHIFT_RESTRICT:
4288 case SHIFT_IMMEDIATE: break;
4289
4290 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4291 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4292 {
4293 inst.error = _("'LSL' or 'ASR' required");
4294 return FAIL;
4295 }
4296 break;
4297
4298 case SHIFT_LSL_IMMEDIATE:
4299 if (shift != SHIFT_LSL)
4300 {
4301 inst.error = _("'LSL' required");
4302 return FAIL;
4303 }
4304 break;
4305
4306 case SHIFT_ASR_IMMEDIATE:
4307 if (shift != SHIFT_ASR)
4308 {
4309 inst.error = _("'ASR' required");
4310 return FAIL;
4311 }
4312 break;
4313
4314 default: abort ();
4315 }
4316
4317 if (shift != SHIFT_RRX)
4318 {
4319 /* Whitespace can appear here if the next thing is a bare digit. */
4320 skip_whitespace (p);
4321
4322 if (mode == NO_SHIFT_RESTRICT
4323 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4324 {
4325 inst.operands[i].imm = reg;
4326 inst.operands[i].immisreg = 1;
4327 }
4328 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4329 return FAIL;
4330 }
4331 inst.operands[i].shift_kind = shift;
4332 inst.operands[i].shifted = 1;
4333 *str = p;
4334 return SUCCESS;
4335 }
4336
4337 /* Parse a <shifter_operand> for an ARM data processing instruction:
4338
4339 #<immediate>
4340 #<immediate>, <rotate>
4341 <Rm>
4342 <Rm>, <shift>
4343
4344 where <shift> is defined by parse_shift above, and <rotate> is a
4345 multiple of 2 between 0 and 30. Validation of immediate operands
4346 is deferred to md_apply_fix. */
4347
4348 static int
4349 parse_shifter_operand (char **str, int i)
4350 {
4351 int value;
4352 expressionS expr;
4353
4354 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
4355 {
4356 inst.operands[i].reg = value;
4357 inst.operands[i].isreg = 1;
4358
4359 /* parse_shift will override this if appropriate */
4360 inst.reloc.exp.X_op = O_constant;
4361 inst.reloc.exp.X_add_number = 0;
4362
4363 if (skip_past_comma (str) == FAIL)
4364 return SUCCESS;
4365
4366 /* Shift operation on register. */
4367 return parse_shift (str, i, NO_SHIFT_RESTRICT);
4368 }
4369
4370 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4371 return FAIL;
4372
4373 if (skip_past_comma (str) == SUCCESS)
4374 {
4375 /* #x, y -- ie explicit rotation by Y. */
4376 if (my_get_expression (&expr, str, GE_NO_PREFIX))
4377 return FAIL;
4378
4379 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4380 {
4381 inst.error = _("constant expression expected");
4382 return FAIL;
4383 }
4384
4385 value = expr.X_add_number;
4386 if (value < 0 || value > 30 || value % 2 != 0)
4387 {
4388 inst.error = _("invalid rotation");
4389 return FAIL;
4390 }
4391 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4392 {
4393 inst.error = _("invalid constant");
4394 return FAIL;
4395 }
4396
4397 /* Convert to decoded value. md_apply_fix will put it back. */
4398 inst.reloc.exp.X_add_number
4399 = (((inst.reloc.exp.X_add_number << (32 - value))
4400 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
4401 }
4402
4403 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4404 inst.reloc.pc_rel = 0;
4405 return SUCCESS;
4406 }
4407
4408 /* Group relocation information. Each entry in the table contains the
4409 textual name of the relocation as may appear in assembler source
4410 and must end with a colon.
4411 Along with this textual name are the relocation codes to be used if
4412 the corresponding instruction is an ALU instruction (ADD or SUB only),
4413 an LDR, an LDRS, or an LDC. */
4414
4415 struct group_reloc_table_entry
4416 {
4417 const char *name;
4418 int alu_code;
4419 int ldr_code;
4420 int ldrs_code;
4421 int ldc_code;
4422 };
4423
4424 typedef enum
4425 {
4426 /* Varieties of non-ALU group relocation. */
4427
4428 GROUP_LDR,
4429 GROUP_LDRS,
4430 GROUP_LDC
4431 } group_reloc_type;
4432
4433 static struct group_reloc_table_entry group_reloc_table[] =
4434 { /* Program counter relative: */
4435 { "pc_g0_nc",
4436 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4437 0, /* LDR */
4438 0, /* LDRS */
4439 0 }, /* LDC */
4440 { "pc_g0",
4441 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4442 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4443 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4444 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4445 { "pc_g1_nc",
4446 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4447 0, /* LDR */
4448 0, /* LDRS */
4449 0 }, /* LDC */
4450 { "pc_g1",
4451 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4452 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4453 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4454 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4455 { "pc_g2",
4456 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4457 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4458 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4459 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4460 /* Section base relative */
4461 { "sb_g0_nc",
4462 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4463 0, /* LDR */
4464 0, /* LDRS */
4465 0 }, /* LDC */
4466 { "sb_g0",
4467 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4468 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4469 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4470 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4471 { "sb_g1_nc",
4472 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4473 0, /* LDR */
4474 0, /* LDRS */
4475 0 }, /* LDC */
4476 { "sb_g1",
4477 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4478 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4479 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4480 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4481 { "sb_g2",
4482 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4483 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4484 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4485 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4486
4487 /* Given the address of a pointer pointing to the textual name of a group
4488 relocation as may appear in assembler source, attempt to find its details
4489 in group_reloc_table. The pointer will be updated to the character after
4490 the trailing colon. On failure, FAIL will be returned; SUCCESS
4491 otherwise. On success, *entry will be updated to point at the relevant
4492 group_reloc_table entry. */
4493
4494 static int
4495 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4496 {
4497 unsigned int i;
4498 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4499 {
4500 int length = strlen (group_reloc_table[i].name);
4501
4502 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0 &&
4503 (*str)[length] == ':')
4504 {
4505 *out = &group_reloc_table[i];
4506 *str += (length + 1);
4507 return SUCCESS;
4508 }
4509 }
4510
4511 return FAIL;
4512 }
4513
4514 /* Parse a <shifter_operand> for an ARM data processing instruction
4515 (as for parse_shifter_operand) where group relocations are allowed:
4516
4517 #<immediate>
4518 #<immediate>, <rotate>
4519 #:<group_reloc>:<expression>
4520 <Rm>
4521 <Rm>, <shift>
4522
4523 where <group_reloc> is one of the strings defined in group_reloc_table.
4524 The hashes are optional.
4525
4526 Everything else is as for parse_shifter_operand. */
4527
4528 static parse_operand_result
4529 parse_shifter_operand_group_reloc (char **str, int i)
4530 {
4531 /* Determine if we have the sequence of characters #: or just :
4532 coming next. If we do, then we check for a group relocation.
4533 If we don't, punt the whole lot to parse_shifter_operand. */
4534
4535 if (((*str)[0] == '#' && (*str)[1] == ':')
4536 || (*str)[0] == ':')
4537 {
4538 struct group_reloc_table_entry *entry;
4539
4540 if ((*str)[0] == '#')
4541 (*str) += 2;
4542 else
4543 (*str)++;
4544
4545 /* Try to parse a group relocation. Anything else is an error. */
4546 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4547 {
4548 inst.error = _("unknown group relocation");
4549 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4550 }
4551
4552 /* We now have the group relocation table entry corresponding to
4553 the name in the assembler source. Next, we parse the expression. */
4554 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4555 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4556
4557 /* Record the relocation type (always the ALU variant here). */
4558 inst.reloc.type = entry->alu_code;
4559 assert (inst.reloc.type != 0);
4560
4561 return PARSE_OPERAND_SUCCESS;
4562 }
4563 else
4564 return parse_shifter_operand (str, i) == SUCCESS
4565 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4566
4567 /* Never reached. */
4568 }
4569
4570 /* Parse all forms of an ARM address expression. Information is written
4571 to inst.operands[i] and/or inst.reloc.
4572
4573 Preindexed addressing (.preind=1):
4574
4575 [Rn, #offset] .reg=Rn .reloc.exp=offset
4576 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4577 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4578 .shift_kind=shift .reloc.exp=shift_imm
4579
4580 These three may have a trailing ! which causes .writeback to be set also.
4581
4582 Postindexed addressing (.postind=1, .writeback=1):
4583
4584 [Rn], #offset .reg=Rn .reloc.exp=offset
4585 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4586 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4587 .shift_kind=shift .reloc.exp=shift_imm
4588
4589 Unindexed addressing (.preind=0, .postind=0):
4590
4591 [Rn], {option} .reg=Rn .imm=option .immisreg=0
4592
4593 Other:
4594
4595 [Rn]{!} shorthand for [Rn,#0]{!}
4596 =immediate .isreg=0 .reloc.exp=immediate
4597 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
4598
4599 It is the caller's responsibility to check for addressing modes not
4600 supported by the instruction, and to set inst.reloc.type. */
4601
4602 static parse_operand_result
4603 parse_address_main (char **str, int i, int group_relocations,
4604 group_reloc_type group_type)
4605 {
4606 char *p = *str;
4607 int reg;
4608
4609 if (skip_past_char (&p, '[') == FAIL)
4610 {
4611 if (skip_past_char (&p, '=') == FAIL)
4612 {
4613 /* bare address - translate to PC-relative offset */
4614 inst.reloc.pc_rel = 1;
4615 inst.operands[i].reg = REG_PC;
4616 inst.operands[i].isreg = 1;
4617 inst.operands[i].preind = 1;
4618 }
4619 /* else a load-constant pseudo op, no special treatment needed here */
4620
4621 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4622 return PARSE_OPERAND_FAIL;
4623
4624 *str = p;
4625 return PARSE_OPERAND_SUCCESS;
4626 }
4627
4628 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
4629 {
4630 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4631 return PARSE_OPERAND_FAIL;
4632 }
4633 inst.operands[i].reg = reg;
4634 inst.operands[i].isreg = 1;
4635
4636 if (skip_past_comma (&p) == SUCCESS)
4637 {
4638 inst.operands[i].preind = 1;
4639
4640 if (*p == '+') p++;
4641 else if (*p == '-') p++, inst.operands[i].negative = 1;
4642
4643 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4644 {
4645 inst.operands[i].imm = reg;
4646 inst.operands[i].immisreg = 1;
4647
4648 if (skip_past_comma (&p) == SUCCESS)
4649 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4650 return PARSE_OPERAND_FAIL;
4651 }
4652 else if (skip_past_char (&p, ':') == SUCCESS)
4653 {
4654 /* FIXME: '@' should be used here, but it's filtered out by generic
4655 code before we get to see it here. This may be subject to
4656 change. */
4657 expressionS exp;
4658 my_get_expression (&exp, &p, GE_NO_PREFIX);
4659 if (exp.X_op != O_constant)
4660 {
4661 inst.error = _("alignment must be constant");
4662 return PARSE_OPERAND_FAIL;
4663 }
4664 inst.operands[i].imm = exp.X_add_number << 8;
4665 inst.operands[i].immisalign = 1;
4666 /* Alignments are not pre-indexes. */
4667 inst.operands[i].preind = 0;
4668 }
4669 else
4670 {
4671 if (inst.operands[i].negative)
4672 {
4673 inst.operands[i].negative = 0;
4674 p--;
4675 }
4676
4677 if (group_relocations &&
4678 ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4679
4680 {
4681 struct group_reloc_table_entry *entry;
4682
4683 /* Skip over the #: or : sequence. */
4684 if (*p == '#')
4685 p += 2;
4686 else
4687 p++;
4688
4689 /* Try to parse a group relocation. Anything else is an
4690 error. */
4691 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
4692 {
4693 inst.error = _("unknown group relocation");
4694 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4695 }
4696
4697 /* We now have the group relocation table entry corresponding to
4698 the name in the assembler source. Next, we parse the
4699 expression. */
4700 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4701 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4702
4703 /* Record the relocation type. */
4704 switch (group_type)
4705 {
4706 case GROUP_LDR:
4707 inst.reloc.type = entry->ldr_code;
4708 break;
4709
4710 case GROUP_LDRS:
4711 inst.reloc.type = entry->ldrs_code;
4712 break;
4713
4714 case GROUP_LDC:
4715 inst.reloc.type = entry->ldc_code;
4716 break;
4717
4718 default:
4719 assert (0);
4720 }
4721
4722 if (inst.reloc.type == 0)
4723 {
4724 inst.error = _("this group relocation is not allowed on this instruction");
4725 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4726 }
4727 }
4728 else
4729 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4730 return PARSE_OPERAND_FAIL;
4731 }
4732 }
4733
4734 if (skip_past_char (&p, ']') == FAIL)
4735 {
4736 inst.error = _("']' expected");
4737 return PARSE_OPERAND_FAIL;
4738 }
4739
4740 if (skip_past_char (&p, '!') == SUCCESS)
4741 inst.operands[i].writeback = 1;
4742
4743 else if (skip_past_comma (&p) == SUCCESS)
4744 {
4745 if (skip_past_char (&p, '{') == SUCCESS)
4746 {
4747 /* [Rn], {expr} - unindexed, with option */
4748 if (parse_immediate (&p, &inst.operands[i].imm,
4749 0, 255, TRUE) == FAIL)
4750 return PARSE_OPERAND_FAIL;
4751
4752 if (skip_past_char (&p, '}') == FAIL)
4753 {
4754 inst.error = _("'}' expected at end of 'option' field");
4755 return PARSE_OPERAND_FAIL;
4756 }
4757 if (inst.operands[i].preind)
4758 {
4759 inst.error = _("cannot combine index with option");
4760 return PARSE_OPERAND_FAIL;
4761 }
4762 *str = p;
4763 return PARSE_OPERAND_SUCCESS;
4764 }
4765 else
4766 {
4767 inst.operands[i].postind = 1;
4768 inst.operands[i].writeback = 1;
4769
4770 if (inst.operands[i].preind)
4771 {
4772 inst.error = _("cannot combine pre- and post-indexing");
4773 return PARSE_OPERAND_FAIL;
4774 }
4775
4776 if (*p == '+') p++;
4777 else if (*p == '-') p++, inst.operands[i].negative = 1;
4778
4779 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4780 {
4781 /* We might be using the immediate for alignment already. If we
4782 are, OR the register number into the low-order bits. */
4783 if (inst.operands[i].immisalign)
4784 inst.operands[i].imm |= reg;
4785 else
4786 inst.operands[i].imm = reg;
4787 inst.operands[i].immisreg = 1;
4788
4789 if (skip_past_comma (&p) == SUCCESS)
4790 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4791 return PARSE_OPERAND_FAIL;
4792 }
4793 else
4794 {
4795 if (inst.operands[i].negative)
4796 {
4797 inst.operands[i].negative = 0;
4798 p--;
4799 }
4800 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4801 return PARSE_OPERAND_FAIL;
4802 }
4803 }
4804 }
4805
4806 /* If at this point neither .preind nor .postind is set, we have a
4807 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
4808 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
4809 {
4810 inst.operands[i].preind = 1;
4811 inst.reloc.exp.X_op = O_constant;
4812 inst.reloc.exp.X_add_number = 0;
4813 }
4814 *str = p;
4815 return PARSE_OPERAND_SUCCESS;
4816 }
4817
4818 static int
4819 parse_address (char **str, int i)
4820 {
4821 return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS
4822 ? SUCCESS : FAIL;
4823 }
4824
4825 static parse_operand_result
4826 parse_address_group_reloc (char **str, int i, group_reloc_type type)
4827 {
4828 return parse_address_main (str, i, 1, type);
4829 }
4830
4831 /* Parse an operand for a MOVW or MOVT instruction. */
4832 static int
4833 parse_half (char **str)
4834 {
4835 char * p;
4836
4837 p = *str;
4838 skip_past_char (&p, '#');
4839 if (strncasecmp (p, ":lower16:", 9) == 0)
4840 inst.reloc.type = BFD_RELOC_ARM_MOVW;
4841 else if (strncasecmp (p, ":upper16:", 9) == 0)
4842 inst.reloc.type = BFD_RELOC_ARM_MOVT;
4843
4844 if (inst.reloc.type != BFD_RELOC_UNUSED)
4845 {
4846 p += 9;
4847 skip_whitespace(p);
4848 }
4849
4850 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4851 return FAIL;
4852
4853 if (inst.reloc.type == BFD_RELOC_UNUSED)
4854 {
4855 if (inst.reloc.exp.X_op != O_constant)
4856 {
4857 inst.error = _("constant expression expected");
4858 return FAIL;
4859 }
4860 if (inst.reloc.exp.X_add_number < 0
4861 || inst.reloc.exp.X_add_number > 0xffff)
4862 {
4863 inst.error = _("immediate value out of range");
4864 return FAIL;
4865 }
4866 }
4867 *str = p;
4868 return SUCCESS;
4869 }
4870
4871 /* Miscellaneous. */
4872
4873 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
4874 or a bitmask suitable to be or-ed into the ARM msr instruction. */
4875 static int
4876 parse_psr (char **str)
4877 {
4878 char *p;
4879 unsigned long psr_field;
4880 const struct asm_psr *psr;
4881 char *start;
4882
4883 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
4884 feature for ease of use and backwards compatibility. */
4885 p = *str;
4886 if (strncasecmp (p, "SPSR", 4) == 0)
4887 psr_field = SPSR_BIT;
4888 else if (strncasecmp (p, "CPSR", 4) == 0)
4889 psr_field = 0;
4890 else
4891 {
4892 start = p;
4893 do
4894 p++;
4895 while (ISALNUM (*p) || *p == '_');
4896
4897 psr = hash_find_n (arm_v7m_psr_hsh, start, p - start);
4898 if (!psr)
4899 return FAIL;
4900
4901 *str = p;
4902 return psr->field;
4903 }
4904
4905 p += 4;
4906 if (*p == '_')
4907 {
4908 /* A suffix follows. */
4909 p++;
4910 start = p;
4911
4912 do
4913 p++;
4914 while (ISALNUM (*p) || *p == '_');
4915
4916 psr = hash_find_n (arm_psr_hsh, start, p - start);
4917 if (!psr)
4918 goto error;
4919
4920 psr_field |= psr->field;
4921 }
4922 else
4923 {
4924 if (ISALNUM (*p))
4925 goto error; /* Garbage after "[CS]PSR". */
4926
4927 psr_field |= (PSR_c | PSR_f);
4928 }
4929 *str = p;
4930 return psr_field;
4931
4932 error:
4933 inst.error = _("flag for {c}psr instruction expected");
4934 return FAIL;
4935 }
4936
4937 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
4938 value suitable for splatting into the AIF field of the instruction. */
4939
4940 static int
4941 parse_cps_flags (char **str)
4942 {
4943 int val = 0;
4944 int saw_a_flag = 0;
4945 char *s = *str;
4946
4947 for (;;)
4948 switch (*s++)
4949 {
4950 case '\0': case ',':
4951 goto done;
4952
4953 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
4954 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
4955 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
4956
4957 default:
4958 inst.error = _("unrecognized CPS flag");
4959 return FAIL;
4960 }
4961
4962 done:
4963 if (saw_a_flag == 0)
4964 {
4965 inst.error = _("missing CPS flags");
4966 return FAIL;
4967 }
4968
4969 *str = s - 1;
4970 return val;
4971 }
4972
4973 /* Parse an endian specifier ("BE" or "LE", case insensitive);
4974 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
4975
4976 static int
4977 parse_endian_specifier (char **str)
4978 {
4979 int little_endian;
4980 char *s = *str;
4981
4982 if (strncasecmp (s, "BE", 2))
4983 little_endian = 0;
4984 else if (strncasecmp (s, "LE", 2))
4985 little_endian = 1;
4986 else
4987 {
4988 inst.error = _("valid endian specifiers are be or le");
4989 return FAIL;
4990 }
4991
4992 if (ISALNUM (s[2]) || s[2] == '_')
4993 {
4994 inst.error = _("valid endian specifiers are be or le");
4995 return FAIL;
4996 }
4997
4998 *str = s + 2;
4999 return little_endian;
5000 }
5001
5002 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5003 value suitable for poking into the rotate field of an sxt or sxta
5004 instruction, or FAIL on error. */
5005
5006 static int
5007 parse_ror (char **str)
5008 {
5009 int rot;
5010 char *s = *str;
5011
5012 if (strncasecmp (s, "ROR", 3) == 0)
5013 s += 3;
5014 else
5015 {
5016 inst.error = _("missing rotation field after comma");
5017 return FAIL;
5018 }
5019
5020 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5021 return FAIL;
5022
5023 switch (rot)
5024 {
5025 case 0: *str = s; return 0x0;
5026 case 8: *str = s; return 0x1;
5027 case 16: *str = s; return 0x2;
5028 case 24: *str = s; return 0x3;
5029
5030 default:
5031 inst.error = _("rotation can only be 0, 8, 16, or 24");
5032 return FAIL;
5033 }
5034 }
5035
5036 /* Parse a conditional code (from conds[] below). The value returned is in the
5037 range 0 .. 14, or FAIL. */
5038 static int
5039 parse_cond (char **str)
5040 {
5041 char *p, *q;
5042 const struct asm_cond *c;
5043
5044 p = q = *str;
5045 while (ISALPHA (*q))
5046 q++;
5047
5048 c = hash_find_n (arm_cond_hsh, p, q - p);
5049 if (!c)
5050 {
5051 inst.error = _("condition required");
5052 return FAIL;
5053 }
5054
5055 *str = q;
5056 return c->value;
5057 }
5058
5059 /* Parse an option for a barrier instruction. Returns the encoding for the
5060 option, or FAIL. */
5061 static int
5062 parse_barrier (char **str)
5063 {
5064 char *p, *q;
5065 const struct asm_barrier_opt *o;
5066
5067 p = q = *str;
5068 while (ISALPHA (*q))
5069 q++;
5070
5071 o = hash_find_n (arm_barrier_opt_hsh, p, q - p);
5072 if (!o)
5073 return FAIL;
5074
5075 *str = q;
5076 return o->value;
5077 }
5078
5079 /* Parse the operands of a table branch instruction. Similar to a memory
5080 operand. */
5081 static int
5082 parse_tb (char **str)
5083 {
5084 char * p = *str;
5085 int reg;
5086
5087 if (skip_past_char (&p, '[') == FAIL)
5088 {
5089 inst.error = _("'[' expected");
5090 return FAIL;
5091 }
5092
5093 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5094 {
5095 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5096 return FAIL;
5097 }
5098 inst.operands[0].reg = reg;
5099
5100 if (skip_past_comma (&p) == FAIL)
5101 {
5102 inst.error = _("',' expected");
5103 return FAIL;
5104 }
5105
5106 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5107 {
5108 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5109 return FAIL;
5110 }
5111 inst.operands[0].imm = reg;
5112
5113 if (skip_past_comma (&p) == SUCCESS)
5114 {
5115 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5116 return FAIL;
5117 if (inst.reloc.exp.X_add_number != 1)
5118 {
5119 inst.error = _("invalid shift");
5120 return FAIL;
5121 }
5122 inst.operands[0].shifted = 1;
5123 }
5124
5125 if (skip_past_char (&p, ']') == FAIL)
5126 {
5127 inst.error = _("']' expected");
5128 return FAIL;
5129 }
5130 *str = p;
5131 return SUCCESS;
5132 }
5133
5134 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5135 information on the types the operands can take and how they are encoded.
5136 Up to four operands may be read; this function handles setting the
5137 ".present" field for each read operand itself.
5138 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5139 else returns FAIL. */
5140
5141 static int
5142 parse_neon_mov (char **str, int *which_operand)
5143 {
5144 int i = *which_operand, val;
5145 enum arm_reg_type rtype;
5146 char *ptr = *str;
5147 struct neon_type_el optype;
5148
5149 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5150 {
5151 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5152 inst.operands[i].reg = val;
5153 inst.operands[i].isscalar = 1;
5154 inst.operands[i].vectype = optype;
5155 inst.operands[i++].present = 1;
5156
5157 if (skip_past_comma (&ptr) == FAIL)
5158 goto wanted_comma;
5159
5160 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5161 goto wanted_arm;
5162
5163 inst.operands[i].reg = val;
5164 inst.operands[i].isreg = 1;
5165 inst.operands[i].present = 1;
5166 }
5167 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
5168 != FAIL)
5169 {
5170 /* Cases 0, 1, 2, 3, 5 (D only). */
5171 if (skip_past_comma (&ptr) == FAIL)
5172 goto wanted_comma;
5173
5174 inst.operands[i].reg = val;
5175 inst.operands[i].isreg = 1;
5176 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5177 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5178 inst.operands[i].isvec = 1;
5179 inst.operands[i].vectype = optype;
5180 inst.operands[i++].present = 1;
5181
5182 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5183 {
5184 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5185 Case 13: VMOV <Sd>, <Rm> */
5186 inst.operands[i].reg = val;
5187 inst.operands[i].isreg = 1;
5188 inst.operands[i].present = 1;
5189
5190 if (rtype == REG_TYPE_NQ)
5191 {
5192 first_error (_("can't use Neon quad register here"));
5193 return FAIL;
5194 }
5195 else if (rtype != REG_TYPE_VFS)
5196 {
5197 i++;
5198 if (skip_past_comma (&ptr) == FAIL)
5199 goto wanted_comma;
5200 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5201 goto wanted_arm;
5202 inst.operands[i].reg = val;
5203 inst.operands[i].isreg = 1;
5204 inst.operands[i].present = 1;
5205 }
5206 }
5207 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5208 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5209 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5210 Case 10: VMOV.F32 <Sd>, #<imm>
5211 Case 11: VMOV.F64 <Dd>, #<imm> */
5212 inst.operands[i].immisfloat = 1;
5213 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5214 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5215 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5216 ;
5217 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5218 &optype)) != FAIL)
5219 {
5220 /* Case 0: VMOV<c><q> <Qd>, <Qm>
5221 Case 1: VMOV<c><q> <Dd>, <Dm>
5222 Case 8: VMOV.F32 <Sd>, <Sm>
5223 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5224
5225 inst.operands[i].reg = val;
5226 inst.operands[i].isreg = 1;
5227 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5228 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5229 inst.operands[i].isvec = 1;
5230 inst.operands[i].vectype = optype;
5231 inst.operands[i].present = 1;
5232
5233 if (skip_past_comma (&ptr) == SUCCESS)
5234 {
5235 /* Case 15. */
5236 i++;
5237
5238 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5239 goto wanted_arm;
5240
5241 inst.operands[i].reg = val;
5242 inst.operands[i].isreg = 1;
5243 inst.operands[i++].present = 1;
5244
5245 if (skip_past_comma (&ptr) == FAIL)
5246 goto wanted_comma;
5247
5248 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5249 goto wanted_arm;
5250
5251 inst.operands[i].reg = val;
5252 inst.operands[i].isreg = 1;
5253 inst.operands[i++].present = 1;
5254 }
5255 }
5256 else
5257 {
5258 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5259 return FAIL;
5260 }
5261 }
5262 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5263 {
5264 /* Cases 6, 7. */
5265 inst.operands[i].reg = val;
5266 inst.operands[i].isreg = 1;
5267 inst.operands[i++].present = 1;
5268
5269 if (skip_past_comma (&ptr) == FAIL)
5270 goto wanted_comma;
5271
5272 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5273 {
5274 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5275 inst.operands[i].reg = val;
5276 inst.operands[i].isscalar = 1;
5277 inst.operands[i].present = 1;
5278 inst.operands[i].vectype = optype;
5279 }
5280 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5281 {
5282 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5283 inst.operands[i].reg = val;
5284 inst.operands[i].isreg = 1;
5285 inst.operands[i++].present = 1;
5286
5287 if (skip_past_comma (&ptr) == FAIL)
5288 goto wanted_comma;
5289
5290 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
5291 == FAIL)
5292 {
5293 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5294 return FAIL;
5295 }
5296
5297 inst.operands[i].reg = val;
5298 inst.operands[i].isreg = 1;
5299 inst.operands[i].isvec = 1;
5300 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5301 inst.operands[i].vectype = optype;
5302 inst.operands[i].present = 1;
5303
5304 if (rtype == REG_TYPE_VFS)
5305 {
5306 /* Case 14. */
5307 i++;
5308 if (skip_past_comma (&ptr) == FAIL)
5309 goto wanted_comma;
5310 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5311 &optype)) == FAIL)
5312 {
5313 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5314 return FAIL;
5315 }
5316 inst.operands[i].reg = val;
5317 inst.operands[i].isreg = 1;
5318 inst.operands[i].isvec = 1;
5319 inst.operands[i].issingle = 1;
5320 inst.operands[i].vectype = optype;
5321 inst.operands[i].present = 1;
5322 }
5323 }
5324 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5325 != FAIL)
5326 {
5327 /* Case 13. */
5328 inst.operands[i].reg = val;
5329 inst.operands[i].isreg = 1;
5330 inst.operands[i].isvec = 1;
5331 inst.operands[i].issingle = 1;
5332 inst.operands[i].vectype = optype;
5333 inst.operands[i++].present = 1;
5334 }
5335 }
5336 else
5337 {
5338 first_error (_("parse error"));
5339 return FAIL;
5340 }
5341
5342 /* Successfully parsed the operands. Update args. */
5343 *which_operand = i;
5344 *str = ptr;
5345 return SUCCESS;
5346
5347 wanted_comma:
5348 first_error (_("expected comma"));
5349 return FAIL;
5350
5351 wanted_arm:
5352 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5353 return FAIL;
5354 }
5355
5356 /* Matcher codes for parse_operands. */
5357 enum operand_parse_code
5358 {
5359 OP_stop, /* end of line */
5360
5361 OP_RR, /* ARM register */
5362 OP_RRnpc, /* ARM register, not r15 */
5363 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5364 OP_RRw, /* ARM register, not r15, optional trailing ! */
5365 OP_RCP, /* Coprocessor number */
5366 OP_RCN, /* Coprocessor register */
5367 OP_RF, /* FPA register */
5368 OP_RVS, /* VFP single precision register */
5369 OP_RVD, /* VFP double precision register (0..15) */
5370 OP_RND, /* Neon double precision register (0..31) */
5371 OP_RNQ, /* Neon quad precision register */
5372 OP_RVSD, /* VFP single or double precision register */
5373 OP_RNDQ, /* Neon double or quad precision register */
5374 OP_RNSDQ, /* Neon single, double or quad precision register */
5375 OP_RNSC, /* Neon scalar D[X] */
5376 OP_RVC, /* VFP control register */
5377 OP_RMF, /* Maverick F register */
5378 OP_RMD, /* Maverick D register */
5379 OP_RMFX, /* Maverick FX register */
5380 OP_RMDX, /* Maverick DX register */
5381 OP_RMAX, /* Maverick AX register */
5382 OP_RMDS, /* Maverick DSPSC register */
5383 OP_RIWR, /* iWMMXt wR register */
5384 OP_RIWC, /* iWMMXt wC register */
5385 OP_RIWG, /* iWMMXt wCG register */
5386 OP_RXA, /* XScale accumulator register */
5387
5388 OP_REGLST, /* ARM register list */
5389 OP_VRSLST, /* VFP single-precision register list */
5390 OP_VRDLST, /* VFP double-precision register list */
5391 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5392 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5393 OP_NSTRLST, /* Neon element/structure list */
5394
5395 OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */
5396 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
5397 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5398 OP_RR_RNSC, /* ARM reg or Neon scalar. */
5399 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5400 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5401 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5402 OP_VMOV, /* Neon VMOV operands. */
5403 OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */
5404 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
5405 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5406
5407 OP_I0, /* immediate zero */
5408 OP_I7, /* immediate value 0 .. 7 */
5409 OP_I15, /* 0 .. 15 */
5410 OP_I16, /* 1 .. 16 */
5411 OP_I16z, /* 0 .. 16 */
5412 OP_I31, /* 0 .. 31 */
5413 OP_I31w, /* 0 .. 31, optional trailing ! */
5414 OP_I32, /* 1 .. 32 */
5415 OP_I32z, /* 0 .. 32 */
5416 OP_I63, /* 0 .. 63 */
5417 OP_I63s, /* -64 .. 63 */
5418 OP_I64, /* 1 .. 64 */
5419 OP_I64z, /* 0 .. 64 */
5420 OP_I255, /* 0 .. 255 */
5421
5422 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5423 OP_I7b, /* 0 .. 7 */
5424 OP_I15b, /* 0 .. 15 */
5425 OP_I31b, /* 0 .. 31 */
5426
5427 OP_SH, /* shifter operand */
5428 OP_SHG, /* shifter operand with possible group relocation */
5429 OP_ADDR, /* Memory address expression (any mode) */
5430 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5431 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5432 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
5433 OP_EXP, /* arbitrary expression */
5434 OP_EXPi, /* same, with optional immediate prefix */
5435 OP_EXPr, /* same, with optional relocation suffix */
5436 OP_HALF, /* 0 .. 65535 or low/high reloc. */
5437
5438 OP_CPSF, /* CPS flags */
5439 OP_ENDI, /* Endianness specifier */
5440 OP_PSR, /* CPSR/SPSR mask for msr */
5441 OP_COND, /* conditional code */
5442 OP_TB, /* Table branch. */
5443
5444 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5445 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5446
5447 OP_RRnpc_I0, /* ARM register or literal 0 */
5448 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5449 OP_RR_EXi, /* ARM register or expression with imm prefix */
5450 OP_RF_IF, /* FPA register or immediate */
5451 OP_RIWR_RIWC, /* iWMMXt R or C reg */
5452 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
5453
5454 /* Optional operands. */
5455 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5456 OP_oI31b, /* 0 .. 31 */
5457 OP_oI32b, /* 1 .. 32 */
5458 OP_oIffffb, /* 0 .. 65535 */
5459 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5460
5461 OP_oRR, /* ARM register */
5462 OP_oRRnpc, /* ARM register, not the PC */
5463 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5464 OP_oRND, /* Optional Neon double precision register */
5465 OP_oRNQ, /* Optional Neon quad precision register */
5466 OP_oRNDQ, /* Optional Neon double or quad precision register */
5467 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
5468 OP_oSHll, /* LSL immediate */
5469 OP_oSHar, /* ASR immediate */
5470 OP_oSHllar, /* LSL or ASR immediate */
5471 OP_oROR, /* ROR 0/8/16/24 */
5472 OP_oBARRIER, /* Option argument for a barrier instruction. */
5473
5474 OP_FIRST_OPTIONAL = OP_oI7b
5475 };
5476
5477 /* Generic instruction operand parser. This does no encoding and no
5478 semantic validation; it merely squirrels values away in the inst
5479 structure. Returns SUCCESS or FAIL depending on whether the
5480 specified grammar matched. */
5481 static int
5482 parse_operands (char *str, const unsigned char *pattern)
5483 {
5484 unsigned const char *upat = pattern;
5485 char *backtrack_pos = 0;
5486 const char *backtrack_error = 0;
5487 int i, val, backtrack_index = 0;
5488 enum arm_reg_type rtype;
5489 parse_operand_result result;
5490
5491 #define po_char_or_fail(chr) do { \
5492 if (skip_past_char (&str, chr) == FAIL) \
5493 goto bad_args; \
5494 } while (0)
5495
5496 #define po_reg_or_fail(regtype) do { \
5497 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5498 &inst.operands[i].vectype); \
5499 if (val == FAIL) \
5500 { \
5501 first_error (_(reg_expected_msgs[regtype])); \
5502 goto failure; \
5503 } \
5504 inst.operands[i].reg = val; \
5505 inst.operands[i].isreg = 1; \
5506 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5507 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5508 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5509 || rtype == REG_TYPE_VFD \
5510 || rtype == REG_TYPE_NQ); \
5511 } while (0)
5512
5513 #define po_reg_or_goto(regtype, label) do { \
5514 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5515 &inst.operands[i].vectype); \
5516 if (val == FAIL) \
5517 goto label; \
5518 \
5519 inst.operands[i].reg = val; \
5520 inst.operands[i].isreg = 1; \
5521 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5522 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5523 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5524 || rtype == REG_TYPE_VFD \
5525 || rtype == REG_TYPE_NQ); \
5526 } while (0)
5527
5528 #define po_imm_or_fail(min, max, popt) do { \
5529 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5530 goto failure; \
5531 inst.operands[i].imm = val; \
5532 } while (0)
5533
5534 #define po_scalar_or_goto(elsz, label) do { \
5535 val = parse_scalar (&str, elsz, &inst.operands[i].vectype); \
5536 if (val == FAIL) \
5537 goto label; \
5538 inst.operands[i].reg = val; \
5539 inst.operands[i].isscalar = 1; \
5540 } while (0)
5541
5542 #define po_misc_or_fail(expr) do { \
5543 if (expr) \
5544 goto failure; \
5545 } while (0)
5546
5547 #define po_misc_or_fail_no_backtrack(expr) do { \
5548 result = expr; \
5549 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK)\
5550 backtrack_pos = 0; \
5551 if (result != PARSE_OPERAND_SUCCESS) \
5552 goto failure; \
5553 } while (0)
5554
5555 skip_whitespace (str);
5556
5557 for (i = 0; upat[i] != OP_stop; i++)
5558 {
5559 if (upat[i] >= OP_FIRST_OPTIONAL)
5560 {
5561 /* Remember where we are in case we need to backtrack. */
5562 assert (!backtrack_pos);
5563 backtrack_pos = str;
5564 backtrack_error = inst.error;
5565 backtrack_index = i;
5566 }
5567
5568 if (i > 0 && (i > 1 || inst.operands[0].present))
5569 po_char_or_fail (',');
5570
5571 switch (upat[i])
5572 {
5573 /* Registers */
5574 case OP_oRRnpc:
5575 case OP_RRnpc:
5576 case OP_oRR:
5577 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5578 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5579 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
5580 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
5581 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
5582 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5583 case OP_oRND:
5584 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
5585 case OP_RVC:
5586 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
5587 break;
5588 /* Also accept generic coprocessor regs for unknown registers. */
5589 coproc_reg:
5590 po_reg_or_fail (REG_TYPE_CN);
5591 break;
5592 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
5593 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
5594 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
5595 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
5596 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
5597 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
5598 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
5599 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
5600 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
5601 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5602 case OP_oRNQ:
5603 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
5604 case OP_oRNDQ:
5605 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
5606 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
5607 case OP_oRNSDQ:
5608 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5609
5610 /* Neon scalar. Using an element size of 8 means that some invalid
5611 scalars are accepted here, so deal with those in later code. */
5612 case OP_RNSC: po_scalar_or_goto (8, failure); break;
5613
5614 /* WARNING: We can expand to two operands here. This has the potential
5615 to totally confuse the backtracking mechanism! It will be OK at
5616 least as long as we don't try to use optional args as well,
5617 though. */
5618 case OP_NILO:
5619 {
5620 po_reg_or_goto (REG_TYPE_NDQ, try_imm);
5621 inst.operands[i].present = 1;
5622 i++;
5623 skip_past_comma (&str);
5624 po_reg_or_goto (REG_TYPE_NDQ, one_reg_only);
5625 break;
5626 one_reg_only:
5627 /* Optional register operand was omitted. Unfortunately, it's in
5628 operands[i-1] and we need it to be in inst.operands[i]. Fix that
5629 here (this is a bit grotty). */
5630 inst.operands[i] = inst.operands[i-1];
5631 inst.operands[i-1].present = 0;
5632 break;
5633 try_imm:
5634 /* There's a possibility of getting a 64-bit immediate here, so
5635 we need special handling. */
5636 if (parse_big_immediate (&str, i) == FAIL)
5637 {
5638 inst.error = _("immediate value is out of range");
5639 goto failure;
5640 }
5641 }
5642 break;
5643
5644 case OP_RNDQ_I0:
5645 {
5646 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
5647 break;
5648 try_imm0:
5649 po_imm_or_fail (0, 0, TRUE);
5650 }
5651 break;
5652
5653 case OP_RVSD_I0:
5654 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
5655 break;
5656
5657 case OP_RR_RNSC:
5658 {
5659 po_scalar_or_goto (8, try_rr);
5660 break;
5661 try_rr:
5662 po_reg_or_fail (REG_TYPE_RN);
5663 }
5664 break;
5665
5666 case OP_RNSDQ_RNSC:
5667 {
5668 po_scalar_or_goto (8, try_nsdq);
5669 break;
5670 try_nsdq:
5671 po_reg_or_fail (REG_TYPE_NSDQ);
5672 }
5673 break;
5674
5675 case OP_RNDQ_RNSC:
5676 {
5677 po_scalar_or_goto (8, try_ndq);
5678 break;
5679 try_ndq:
5680 po_reg_or_fail (REG_TYPE_NDQ);
5681 }
5682 break;
5683
5684 case OP_RND_RNSC:
5685 {
5686 po_scalar_or_goto (8, try_vfd);
5687 break;
5688 try_vfd:
5689 po_reg_or_fail (REG_TYPE_VFD);
5690 }
5691 break;
5692
5693 case OP_VMOV:
5694 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
5695 not careful then bad things might happen. */
5696 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
5697 break;
5698
5699 case OP_RNDQ_IMVNb:
5700 {
5701 po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm);
5702 break;
5703 try_mvnimm:
5704 /* There's a possibility of getting a 64-bit immediate here, so
5705 we need special handling. */
5706 if (parse_big_immediate (&str, i) == FAIL)
5707 {
5708 inst.error = _("immediate value is out of range");
5709 goto failure;
5710 }
5711 }
5712 break;
5713
5714 case OP_RNDQ_I63b:
5715 {
5716 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
5717 break;
5718 try_shimm:
5719 po_imm_or_fail (0, 63, TRUE);
5720 }
5721 break;
5722
5723 case OP_RRnpcb:
5724 po_char_or_fail ('[');
5725 po_reg_or_fail (REG_TYPE_RN);
5726 po_char_or_fail (']');
5727 break;
5728
5729 case OP_RRw:
5730 case OP_oRRw:
5731 po_reg_or_fail (REG_TYPE_RN);
5732 if (skip_past_char (&str, '!') == SUCCESS)
5733 inst.operands[i].writeback = 1;
5734 break;
5735
5736 /* Immediates */
5737 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
5738 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
5739 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5740 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
5741 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
5742 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5743 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
5744 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5745 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
5746 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
5747 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
5748 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
5749
5750 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
5751 case OP_oI7b:
5752 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
5753 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
5754 case OP_oI31b:
5755 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5756 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
5757 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
5758
5759 /* Immediate variants */
5760 case OP_oI255c:
5761 po_char_or_fail ('{');
5762 po_imm_or_fail (0, 255, TRUE);
5763 po_char_or_fail ('}');
5764 break;
5765
5766 case OP_I31w:
5767 /* The expression parser chokes on a trailing !, so we have
5768 to find it first and zap it. */
5769 {
5770 char *s = str;
5771 while (*s && *s != ',')
5772 s++;
5773 if (s[-1] == '!')
5774 {
5775 s[-1] = '\0';
5776 inst.operands[i].writeback = 1;
5777 }
5778 po_imm_or_fail (0, 31, TRUE);
5779 if (str == s - 1)
5780 str = s;
5781 }
5782 break;
5783
5784 /* Expressions */
5785 case OP_EXPi: EXPi:
5786 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5787 GE_OPT_PREFIX));
5788 break;
5789
5790 case OP_EXP:
5791 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5792 GE_NO_PREFIX));
5793 break;
5794
5795 case OP_EXPr: EXPr:
5796 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5797 GE_NO_PREFIX));
5798 if (inst.reloc.exp.X_op == O_symbol)
5799 {
5800 val = parse_reloc (&str);
5801 if (val == -1)
5802 {
5803 inst.error = _("unrecognized relocation suffix");
5804 goto failure;
5805 }
5806 else if (val != BFD_RELOC_UNUSED)
5807 {
5808 inst.operands[i].imm = val;
5809 inst.operands[i].hasreloc = 1;
5810 }
5811 }
5812 break;
5813
5814 /* Operand for MOVW or MOVT. */
5815 case OP_HALF:
5816 po_misc_or_fail (parse_half (&str));
5817 break;
5818
5819 /* Register or expression */
5820 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
5821 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
5822
5823 /* Register or immediate */
5824 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
5825 I0: po_imm_or_fail (0, 0, FALSE); break;
5826
5827 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
5828 IF:
5829 if (!is_immediate_prefix (*str))
5830 goto bad_args;
5831 str++;
5832 val = parse_fpa_immediate (&str);
5833 if (val == FAIL)
5834 goto failure;
5835 /* FPA immediates are encoded as registers 8-15.
5836 parse_fpa_immediate has already applied the offset. */
5837 inst.operands[i].reg = val;
5838 inst.operands[i].isreg = 1;
5839 break;
5840
5841 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
5842 I32z: po_imm_or_fail (0, 32, FALSE); break;
5843
5844 /* Two kinds of register */
5845 case OP_RIWR_RIWC:
5846 {
5847 struct reg_entry *rege = arm_reg_parse_multi (&str);
5848 if (!rege
5849 || (rege->type != REG_TYPE_MMXWR
5850 && rege->type != REG_TYPE_MMXWC
5851 && rege->type != REG_TYPE_MMXWCG))
5852 {
5853 inst.error = _("iWMMXt data or control register expected");
5854 goto failure;
5855 }
5856 inst.operands[i].reg = rege->number;
5857 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
5858 }
5859 break;
5860
5861 case OP_RIWC_RIWG:
5862 {
5863 struct reg_entry *rege = arm_reg_parse_multi (&str);
5864 if (!rege
5865 || (rege->type != REG_TYPE_MMXWC
5866 && rege->type != REG_TYPE_MMXWCG))
5867 {
5868 inst.error = _("iWMMXt control register expected");
5869 goto failure;
5870 }
5871 inst.operands[i].reg = rege->number;
5872 inst.operands[i].isreg = 1;
5873 }
5874 break;
5875
5876 /* Misc */
5877 case OP_CPSF: val = parse_cps_flags (&str); break;
5878 case OP_ENDI: val = parse_endian_specifier (&str); break;
5879 case OP_oROR: val = parse_ror (&str); break;
5880 case OP_PSR: val = parse_psr (&str); break;
5881 case OP_COND: val = parse_cond (&str); break;
5882 case OP_oBARRIER:val = parse_barrier (&str); break;
5883
5884 case OP_RVC_PSR:
5885 po_reg_or_goto (REG_TYPE_VFC, try_psr);
5886 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
5887 break;
5888 try_psr:
5889 val = parse_psr (&str);
5890 break;
5891
5892 case OP_APSR_RR:
5893 po_reg_or_goto (REG_TYPE_RN, try_apsr);
5894 break;
5895 try_apsr:
5896 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
5897 instruction). */
5898 if (strncasecmp (str, "APSR_", 5) == 0)
5899 {
5900 unsigned found = 0;
5901 str += 5;
5902 while (found < 15)
5903 switch (*str++)
5904 {
5905 case 'c': found = (found & 1) ? 16 : found | 1; break;
5906 case 'n': found = (found & 2) ? 16 : found | 2; break;
5907 case 'z': found = (found & 4) ? 16 : found | 4; break;
5908 case 'v': found = (found & 8) ? 16 : found | 8; break;
5909 default: found = 16;
5910 }
5911 if (found != 15)
5912 goto failure;
5913 inst.operands[i].isvec = 1;
5914 }
5915 else
5916 goto failure;
5917 break;
5918
5919 case OP_TB:
5920 po_misc_or_fail (parse_tb (&str));
5921 break;
5922
5923 /* Register lists */
5924 case OP_REGLST:
5925 val = parse_reg_list (&str);
5926 if (*str == '^')
5927 {
5928 inst.operands[1].writeback = 1;
5929 str++;
5930 }
5931 break;
5932
5933 case OP_VRSLST:
5934 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
5935 break;
5936
5937 case OP_VRDLST:
5938 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
5939 break;
5940
5941 case OP_VRSDLST:
5942 /* Allow Q registers too. */
5943 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5944 REGLIST_NEON_D);
5945 if (val == FAIL)
5946 {
5947 inst.error = NULL;
5948 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5949 REGLIST_VFP_S);
5950 inst.operands[i].issingle = 1;
5951 }
5952 break;
5953
5954 case OP_NRDLST:
5955 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5956 REGLIST_NEON_D);
5957 break;
5958
5959 case OP_NSTRLST:
5960 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
5961 &inst.operands[i].vectype);
5962 break;
5963
5964 /* Addressing modes */
5965 case OP_ADDR:
5966 po_misc_or_fail (parse_address (&str, i));
5967 break;
5968
5969 case OP_ADDRGLDR:
5970 po_misc_or_fail_no_backtrack (
5971 parse_address_group_reloc (&str, i, GROUP_LDR));
5972 break;
5973
5974 case OP_ADDRGLDRS:
5975 po_misc_or_fail_no_backtrack (
5976 parse_address_group_reloc (&str, i, GROUP_LDRS));
5977 break;
5978
5979 case OP_ADDRGLDC:
5980 po_misc_or_fail_no_backtrack (
5981 parse_address_group_reloc (&str, i, GROUP_LDC));
5982 break;
5983
5984 case OP_SH:
5985 po_misc_or_fail (parse_shifter_operand (&str, i));
5986 break;
5987
5988 case OP_SHG:
5989 po_misc_or_fail_no_backtrack (
5990 parse_shifter_operand_group_reloc (&str, i));
5991 break;
5992
5993 case OP_oSHll:
5994 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
5995 break;
5996
5997 case OP_oSHar:
5998 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
5999 break;
6000
6001 case OP_oSHllar:
6002 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6003 break;
6004
6005 default:
6006 as_fatal ("unhandled operand code %d", upat[i]);
6007 }
6008
6009 /* Various value-based sanity checks and shared operations. We
6010 do not signal immediate failures for the register constraints;
6011 this allows a syntax error to take precedence. */
6012 switch (upat[i])
6013 {
6014 case OP_oRRnpc:
6015 case OP_RRnpc:
6016 case OP_RRnpcb:
6017 case OP_RRw:
6018 case OP_oRRw:
6019 case OP_RRnpc_I0:
6020 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6021 inst.error = BAD_PC;
6022 break;
6023
6024 case OP_CPSF:
6025 case OP_ENDI:
6026 case OP_oROR:
6027 case OP_PSR:
6028 case OP_RVC_PSR:
6029 case OP_COND:
6030 case OP_oBARRIER:
6031 case OP_REGLST:
6032 case OP_VRSLST:
6033 case OP_VRDLST:
6034 case OP_VRSDLST:
6035 case OP_NRDLST:
6036 case OP_NSTRLST:
6037 if (val == FAIL)
6038 goto failure;
6039 inst.operands[i].imm = val;
6040 break;
6041
6042 default:
6043 break;
6044 }
6045
6046 /* If we get here, this operand was successfully parsed. */
6047 inst.operands[i].present = 1;
6048 continue;
6049
6050 bad_args:
6051 inst.error = BAD_ARGS;
6052
6053 failure:
6054 if (!backtrack_pos)
6055 {
6056 /* The parse routine should already have set inst.error, but set a
6057 defaut here just in case. */
6058 if (!inst.error)
6059 inst.error = _("syntax error");
6060 return FAIL;
6061 }
6062
6063 /* Do not backtrack over a trailing optional argument that
6064 absorbed some text. We will only fail again, with the
6065 'garbage following instruction' error message, which is
6066 probably less helpful than the current one. */
6067 if (backtrack_index == i && backtrack_pos != str
6068 && upat[i+1] == OP_stop)
6069 {
6070 if (!inst.error)
6071 inst.error = _("syntax error");
6072 return FAIL;
6073 }
6074
6075 /* Try again, skipping the optional argument at backtrack_pos. */
6076 str = backtrack_pos;
6077 inst.error = backtrack_error;
6078 inst.operands[backtrack_index].present = 0;
6079 i = backtrack_index;
6080 backtrack_pos = 0;
6081 }
6082
6083 /* Check that we have parsed all the arguments. */
6084 if (*str != '\0' && !inst.error)
6085 inst.error = _("garbage following instruction");
6086
6087 return inst.error ? FAIL : SUCCESS;
6088 }
6089
6090 #undef po_char_or_fail
6091 #undef po_reg_or_fail
6092 #undef po_reg_or_goto
6093 #undef po_imm_or_fail
6094 #undef po_scalar_or_fail
6095 \f
6096 /* Shorthand macro for instruction encoding functions issuing errors. */
6097 #define constraint(expr, err) do { \
6098 if (expr) \
6099 { \
6100 inst.error = err; \
6101 return; \
6102 } \
6103 } while (0)
6104
6105 /* Functions for operand encoding. ARM, then Thumb. */
6106
6107 #define rotate_left(v, n) (v << n | v >> (32 - n))
6108
6109 /* If VAL can be encoded in the immediate field of an ARM instruction,
6110 return the encoded form. Otherwise, return FAIL. */
6111
6112 static unsigned int
6113 encode_arm_immediate (unsigned int val)
6114 {
6115 unsigned int a, i;
6116
6117 for (i = 0; i < 32; i += 2)
6118 if ((a = rotate_left (val, i)) <= 0xff)
6119 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6120
6121 return FAIL;
6122 }
6123
6124 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6125 return the encoded form. Otherwise, return FAIL. */
6126 static unsigned int
6127 encode_thumb32_immediate (unsigned int val)
6128 {
6129 unsigned int a, i;
6130
6131 if (val <= 0xff)
6132 return val;
6133
6134 for (i = 1; i <= 24; i++)
6135 {
6136 a = val >> i;
6137 if ((val & ~(0xff << i)) == 0)
6138 return ((val >> i) & 0x7f) | ((32 - i) << 7);
6139 }
6140
6141 a = val & 0xff;
6142 if (val == ((a << 16) | a))
6143 return 0x100 | a;
6144 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6145 return 0x300 | a;
6146
6147 a = val & 0xff00;
6148 if (val == ((a << 16) | a))
6149 return 0x200 | (a >> 8);
6150
6151 return FAIL;
6152 }
6153 /* Encode a VFP SP or DP register number into inst.instruction. */
6154
6155 static void
6156 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6157 {
6158 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6159 && reg > 15)
6160 {
6161 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
6162 {
6163 if (thumb_mode)
6164 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
6165 fpu_vfp_ext_v3);
6166 else
6167 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
6168 fpu_vfp_ext_v3);
6169 }
6170 else
6171 {
6172 first_error (_("D register out of range for selected VFP version"));
6173 return;
6174 }
6175 }
6176
6177 switch (pos)
6178 {
6179 case VFP_REG_Sd:
6180 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6181 break;
6182
6183 case VFP_REG_Sn:
6184 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6185 break;
6186
6187 case VFP_REG_Sm:
6188 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6189 break;
6190
6191 case VFP_REG_Dd:
6192 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6193 break;
6194
6195 case VFP_REG_Dn:
6196 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6197 break;
6198
6199 case VFP_REG_Dm:
6200 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6201 break;
6202
6203 default:
6204 abort ();
6205 }
6206 }
6207
6208 /* Encode a <shift> in an ARM-format instruction. The immediate,
6209 if any, is handled by md_apply_fix. */
6210 static void
6211 encode_arm_shift (int i)
6212 {
6213 if (inst.operands[i].shift_kind == SHIFT_RRX)
6214 inst.instruction |= SHIFT_ROR << 5;
6215 else
6216 {
6217 inst.instruction |= inst.operands[i].shift_kind << 5;
6218 if (inst.operands[i].immisreg)
6219 {
6220 inst.instruction |= SHIFT_BY_REG;
6221 inst.instruction |= inst.operands[i].imm << 8;
6222 }
6223 else
6224 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6225 }
6226 }
6227
6228 static void
6229 encode_arm_shifter_operand (int i)
6230 {
6231 if (inst.operands[i].isreg)
6232 {
6233 inst.instruction |= inst.operands[i].reg;
6234 encode_arm_shift (i);
6235 }
6236 else
6237 inst.instruction |= INST_IMMEDIATE;
6238 }
6239
6240 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
6241 static void
6242 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
6243 {
6244 assert (inst.operands[i].isreg);
6245 inst.instruction |= inst.operands[i].reg << 16;
6246
6247 if (inst.operands[i].preind)
6248 {
6249 if (is_t)
6250 {
6251 inst.error = _("instruction does not accept preindexed addressing");
6252 return;
6253 }
6254 inst.instruction |= PRE_INDEX;
6255 if (inst.operands[i].writeback)
6256 inst.instruction |= WRITE_BACK;
6257
6258 }
6259 else if (inst.operands[i].postind)
6260 {
6261 assert (inst.operands[i].writeback);
6262 if (is_t)
6263 inst.instruction |= WRITE_BACK;
6264 }
6265 else /* unindexed - only for coprocessor */
6266 {
6267 inst.error = _("instruction does not accept unindexed addressing");
6268 return;
6269 }
6270
6271 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6272 && (((inst.instruction & 0x000f0000) >> 16)
6273 == ((inst.instruction & 0x0000f000) >> 12)))
6274 as_warn ((inst.instruction & LOAD_BIT)
6275 ? _("destination register same as write-back base")
6276 : _("source register same as write-back base"));
6277 }
6278
6279 /* inst.operands[i] was set up by parse_address. Encode it into an
6280 ARM-format mode 2 load or store instruction. If is_t is true,
6281 reject forms that cannot be used with a T instruction (i.e. not
6282 post-indexed). */
6283 static void
6284 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
6285 {
6286 encode_arm_addr_mode_common (i, is_t);
6287
6288 if (inst.operands[i].immisreg)
6289 {
6290 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6291 inst.instruction |= inst.operands[i].imm;
6292 if (!inst.operands[i].negative)
6293 inst.instruction |= INDEX_UP;
6294 if (inst.operands[i].shifted)
6295 {
6296 if (inst.operands[i].shift_kind == SHIFT_RRX)
6297 inst.instruction |= SHIFT_ROR << 5;
6298 else
6299 {
6300 inst.instruction |= inst.operands[i].shift_kind << 5;
6301 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6302 }
6303 }
6304 }
6305 else /* immediate offset in inst.reloc */
6306 {
6307 if (inst.reloc.type == BFD_RELOC_UNUSED)
6308 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
6309 }
6310 }
6311
6312 /* inst.operands[i] was set up by parse_address. Encode it into an
6313 ARM-format mode 3 load or store instruction. Reject forms that
6314 cannot be used with such instructions. If is_t is true, reject
6315 forms that cannot be used with a T instruction (i.e. not
6316 post-indexed). */
6317 static void
6318 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
6319 {
6320 if (inst.operands[i].immisreg && inst.operands[i].shifted)
6321 {
6322 inst.error = _("instruction does not accept scaled register index");
6323 return;
6324 }
6325
6326 encode_arm_addr_mode_common (i, is_t);
6327
6328 if (inst.operands[i].immisreg)
6329 {
6330 inst.instruction |= inst.operands[i].imm;
6331 if (!inst.operands[i].negative)
6332 inst.instruction |= INDEX_UP;
6333 }
6334 else /* immediate offset in inst.reloc */
6335 {
6336 inst.instruction |= HWOFFSET_IMM;
6337 if (inst.reloc.type == BFD_RELOC_UNUSED)
6338 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
6339 }
6340 }
6341
6342 /* inst.operands[i] was set up by parse_address. Encode it into an
6343 ARM-format instruction. Reject all forms which cannot be encoded
6344 into a coprocessor load/store instruction. If wb_ok is false,
6345 reject use of writeback; if unind_ok is false, reject use of
6346 unindexed addressing. If reloc_override is not 0, use it instead
6347 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6348 (in which case it is preserved). */
6349
6350 static int
6351 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
6352 {
6353 inst.instruction |= inst.operands[i].reg << 16;
6354
6355 assert (!(inst.operands[i].preind && inst.operands[i].postind));
6356
6357 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
6358 {
6359 assert (!inst.operands[i].writeback);
6360 if (!unind_ok)
6361 {
6362 inst.error = _("instruction does not support unindexed addressing");
6363 return FAIL;
6364 }
6365 inst.instruction |= inst.operands[i].imm;
6366 inst.instruction |= INDEX_UP;
6367 return SUCCESS;
6368 }
6369
6370 if (inst.operands[i].preind)
6371 inst.instruction |= PRE_INDEX;
6372
6373 if (inst.operands[i].writeback)
6374 {
6375 if (inst.operands[i].reg == REG_PC)
6376 {
6377 inst.error = _("pc may not be used with write-back");
6378 return FAIL;
6379 }
6380 if (!wb_ok)
6381 {
6382 inst.error = _("instruction does not support writeback");
6383 return FAIL;
6384 }
6385 inst.instruction |= WRITE_BACK;
6386 }
6387
6388 if (reloc_override)
6389 inst.reloc.type = reloc_override;
6390 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6391 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6392 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6393 {
6394 if (thumb_mode)
6395 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6396 else
6397 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6398 }
6399
6400 return SUCCESS;
6401 }
6402
6403 /* inst.reloc.exp describes an "=expr" load pseudo-operation.
6404 Determine whether it can be performed with a move instruction; if
6405 it can, convert inst.instruction to that move instruction and
6406 return 1; if it can't, convert inst.instruction to a literal-pool
6407 load and return 0. If this is not a valid thing to do in the
6408 current context, set inst.error and return 1.
6409
6410 inst.operands[i] describes the destination register. */
6411
6412 static int
6413 move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6414 {
6415 unsigned long tbit;
6416
6417 if (thumb_p)
6418 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6419 else
6420 tbit = LOAD_BIT;
6421
6422 if ((inst.instruction & tbit) == 0)
6423 {
6424 inst.error = _("invalid pseudo operation");
6425 return 1;
6426 }
6427 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
6428 {
6429 inst.error = _("constant expression expected");
6430 return 1;
6431 }
6432 if (inst.reloc.exp.X_op == O_constant)
6433 {
6434 if (thumb_p)
6435 {
6436 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
6437 {
6438 /* This can be done with a mov(1) instruction. */
6439 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6440 inst.instruction |= inst.reloc.exp.X_add_number;
6441 return 1;
6442 }
6443 }
6444 else
6445 {
6446 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6447 if (value != FAIL)
6448 {
6449 /* This can be done with a mov instruction. */
6450 inst.instruction &= LITERAL_MASK;
6451 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6452 inst.instruction |= value & 0xfff;
6453 return 1;
6454 }
6455
6456 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6457 if (value != FAIL)
6458 {
6459 /* This can be done with a mvn instruction. */
6460 inst.instruction &= LITERAL_MASK;
6461 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6462 inst.instruction |= value & 0xfff;
6463 return 1;
6464 }
6465 }
6466 }
6467
6468 if (add_to_lit_pool () == FAIL)
6469 {
6470 inst.error = _("literal pool insertion failed");
6471 return 1;
6472 }
6473 inst.operands[1].reg = REG_PC;
6474 inst.operands[1].isreg = 1;
6475 inst.operands[1].preind = 1;
6476 inst.reloc.pc_rel = 1;
6477 inst.reloc.type = (thumb_p
6478 ? BFD_RELOC_ARM_THUMB_OFFSET
6479 : (mode_3
6480 ? BFD_RELOC_ARM_HWLITERAL
6481 : BFD_RELOC_ARM_LITERAL));
6482 return 0;
6483 }
6484
6485 /* Functions for instruction encoding, sorted by subarchitecture.
6486 First some generics; their names are taken from the conventional
6487 bit positions for register arguments in ARM format instructions. */
6488
6489 static void
6490 do_noargs (void)
6491 {
6492 }
6493
6494 static void
6495 do_rd (void)
6496 {
6497 inst.instruction |= inst.operands[0].reg << 12;
6498 }
6499
6500 static void
6501 do_rd_rm (void)
6502 {
6503 inst.instruction |= inst.operands[0].reg << 12;
6504 inst.instruction |= inst.operands[1].reg;
6505 }
6506
6507 static void
6508 do_rd_rn (void)
6509 {
6510 inst.instruction |= inst.operands[0].reg << 12;
6511 inst.instruction |= inst.operands[1].reg << 16;
6512 }
6513
6514 static void
6515 do_rn_rd (void)
6516 {
6517 inst.instruction |= inst.operands[0].reg << 16;
6518 inst.instruction |= inst.operands[1].reg << 12;
6519 }
6520
6521 static void
6522 do_rd_rm_rn (void)
6523 {
6524 unsigned Rn = inst.operands[2].reg;
6525 /* Enforce restrictions on SWP instruction. */
6526 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6527 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6528 _("Rn must not overlap other operands"));
6529 inst.instruction |= inst.operands[0].reg << 12;
6530 inst.instruction |= inst.operands[1].reg;
6531 inst.instruction |= Rn << 16;
6532 }
6533
6534 static void
6535 do_rd_rn_rm (void)
6536 {
6537 inst.instruction |= inst.operands[0].reg << 12;
6538 inst.instruction |= inst.operands[1].reg << 16;
6539 inst.instruction |= inst.operands[2].reg;
6540 }
6541
6542 static void
6543 do_rm_rd_rn (void)
6544 {
6545 inst.instruction |= inst.operands[0].reg;
6546 inst.instruction |= inst.operands[1].reg << 12;
6547 inst.instruction |= inst.operands[2].reg << 16;
6548 }
6549
6550 static void
6551 do_imm0 (void)
6552 {
6553 inst.instruction |= inst.operands[0].imm;
6554 }
6555
6556 static void
6557 do_rd_cpaddr (void)
6558 {
6559 inst.instruction |= inst.operands[0].reg << 12;
6560 encode_arm_cp_address (1, TRUE, TRUE, 0);
6561 }
6562
6563 /* ARM instructions, in alphabetical order by function name (except
6564 that wrapper functions appear immediately after the function they
6565 wrap). */
6566
6567 /* This is a pseudo-op of the form "adr rd, label" to be converted
6568 into a relative address of the form "add rd, pc, #label-.-8". */
6569
6570 static void
6571 do_adr (void)
6572 {
6573 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
6574
6575 /* Frag hacking will turn this into a sub instruction if the offset turns
6576 out to be negative. */
6577 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
6578 inst.reloc.pc_rel = 1;
6579 inst.reloc.exp.X_add_number -= 8;
6580 }
6581
6582 /* This is a pseudo-op of the form "adrl rd, label" to be converted
6583 into a relative address of the form:
6584 add rd, pc, #low(label-.-8)"
6585 add rd, rd, #high(label-.-8)" */
6586
6587 static void
6588 do_adrl (void)
6589 {
6590 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
6591
6592 /* Frag hacking will turn this into a sub instruction if the offset turns
6593 out to be negative. */
6594 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
6595 inst.reloc.pc_rel = 1;
6596 inst.size = INSN_SIZE * 2;
6597 inst.reloc.exp.X_add_number -= 8;
6598 }
6599
6600 static void
6601 do_arit (void)
6602 {
6603 if (!inst.operands[1].present)
6604 inst.operands[1].reg = inst.operands[0].reg;
6605 inst.instruction |= inst.operands[0].reg << 12;
6606 inst.instruction |= inst.operands[1].reg << 16;
6607 encode_arm_shifter_operand (2);
6608 }
6609
6610 static void
6611 do_barrier (void)
6612 {
6613 if (inst.operands[0].present)
6614 {
6615 constraint ((inst.instruction & 0xf0) != 0x40
6616 && inst.operands[0].imm != 0xf,
6617 "bad barrier type");
6618 inst.instruction |= inst.operands[0].imm;
6619 }
6620 else
6621 inst.instruction |= 0xf;
6622 }
6623
6624 static void
6625 do_bfc (void)
6626 {
6627 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6628 constraint (msb > 32, _("bit-field extends past end of register"));
6629 /* The instruction encoding stores the LSB and MSB,
6630 not the LSB and width. */
6631 inst.instruction |= inst.operands[0].reg << 12;
6632 inst.instruction |= inst.operands[1].imm << 7;
6633 inst.instruction |= (msb - 1) << 16;
6634 }
6635
6636 static void
6637 do_bfi (void)
6638 {
6639 unsigned int msb;
6640
6641 /* #0 in second position is alternative syntax for bfc, which is
6642 the same instruction but with REG_PC in the Rm field. */
6643 if (!inst.operands[1].isreg)
6644 inst.operands[1].reg = REG_PC;
6645
6646 msb = inst.operands[2].imm + inst.operands[3].imm;
6647 constraint (msb > 32, _("bit-field extends past end of register"));
6648 /* The instruction encoding stores the LSB and MSB,
6649 not the LSB and width. */
6650 inst.instruction |= inst.operands[0].reg << 12;
6651 inst.instruction |= inst.operands[1].reg;
6652 inst.instruction |= inst.operands[2].imm << 7;
6653 inst.instruction |= (msb - 1) << 16;
6654 }
6655
6656 static void
6657 do_bfx (void)
6658 {
6659 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6660 _("bit-field extends past end of register"));
6661 inst.instruction |= inst.operands[0].reg << 12;
6662 inst.instruction |= inst.operands[1].reg;
6663 inst.instruction |= inst.operands[2].imm << 7;
6664 inst.instruction |= (inst.operands[3].imm - 1) << 16;
6665 }
6666
6667 /* ARM V5 breakpoint instruction (argument parse)
6668 BKPT <16 bit unsigned immediate>
6669 Instruction is not conditional.
6670 The bit pattern given in insns[] has the COND_ALWAYS condition,
6671 and it is an error if the caller tried to override that. */
6672
6673 static void
6674 do_bkpt (void)
6675 {
6676 /* Top 12 of 16 bits to bits 19:8. */
6677 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
6678
6679 /* Bottom 4 of 16 bits to bits 3:0. */
6680 inst.instruction |= inst.operands[0].imm & 0xf;
6681 }
6682
6683 static void
6684 encode_branch (int default_reloc)
6685 {
6686 if (inst.operands[0].hasreloc)
6687 {
6688 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
6689 _("the only suffix valid here is '(plt)'"));
6690 inst.reloc.type = BFD_RELOC_ARM_PLT32;
6691 }
6692 else
6693 {
6694 inst.reloc.type = default_reloc;
6695 }
6696 inst.reloc.pc_rel = 1;
6697 }
6698
6699 static void
6700 do_branch (void)
6701 {
6702 #ifdef OBJ_ELF
6703 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6704 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6705 else
6706 #endif
6707 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6708 }
6709
6710 static void
6711 do_bl (void)
6712 {
6713 #ifdef OBJ_ELF
6714 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6715 {
6716 if (inst.cond == COND_ALWAYS)
6717 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6718 else
6719 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6720 }
6721 else
6722 #endif
6723 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6724 }
6725
6726 /* ARM V5 branch-link-exchange instruction (argument parse)
6727 BLX <target_addr> ie BLX(1)
6728 BLX{<condition>} <Rm> ie BLX(2)
6729 Unfortunately, there are two different opcodes for this mnemonic.
6730 So, the insns[].value is not used, and the code here zaps values
6731 into inst.instruction.
6732 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
6733
6734 static void
6735 do_blx (void)
6736 {
6737 if (inst.operands[0].isreg)
6738 {
6739 /* Arg is a register; the opcode provided by insns[] is correct.
6740 It is not illegal to do "blx pc", just useless. */
6741 if (inst.operands[0].reg == REG_PC)
6742 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
6743
6744 inst.instruction |= inst.operands[0].reg;
6745 }
6746 else
6747 {
6748 /* Arg is an address; this instruction cannot be executed
6749 conditionally, and the opcode must be adjusted. */
6750 constraint (inst.cond != COND_ALWAYS, BAD_COND);
6751 inst.instruction = 0xfa000000;
6752 #ifdef OBJ_ELF
6753 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6754 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6755 else
6756 #endif
6757 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
6758 }
6759 }
6760
6761 static void
6762 do_bx (void)
6763 {
6764 if (inst.operands[0].reg == REG_PC)
6765 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
6766
6767 inst.instruction |= inst.operands[0].reg;
6768 }
6769
6770
6771 /* ARM v5TEJ. Jump to Jazelle code. */
6772
6773 static void
6774 do_bxj (void)
6775 {
6776 if (inst.operands[0].reg == REG_PC)
6777 as_tsktsk (_("use of r15 in bxj is not really useful"));
6778
6779 inst.instruction |= inst.operands[0].reg;
6780 }
6781
6782 /* Co-processor data operation:
6783 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
6784 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
6785 static void
6786 do_cdp (void)
6787 {
6788 inst.instruction |= inst.operands[0].reg << 8;
6789 inst.instruction |= inst.operands[1].imm << 20;
6790 inst.instruction |= inst.operands[2].reg << 12;
6791 inst.instruction |= inst.operands[3].reg << 16;
6792 inst.instruction |= inst.operands[4].reg;
6793 inst.instruction |= inst.operands[5].imm << 5;
6794 }
6795
6796 static void
6797 do_cmp (void)
6798 {
6799 inst.instruction |= inst.operands[0].reg << 16;
6800 encode_arm_shifter_operand (1);
6801 }
6802
6803 /* Transfer between coprocessor and ARM registers.
6804 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
6805 MRC2
6806 MCR{cond}
6807 MCR2
6808
6809 No special properties. */
6810
6811 static void
6812 do_co_reg (void)
6813 {
6814 inst.instruction |= inst.operands[0].reg << 8;
6815 inst.instruction |= inst.operands[1].imm << 21;
6816 inst.instruction |= inst.operands[2].reg << 12;
6817 inst.instruction |= inst.operands[3].reg << 16;
6818 inst.instruction |= inst.operands[4].reg;
6819 inst.instruction |= inst.operands[5].imm << 5;
6820 }
6821
6822 /* Transfer between coprocessor register and pair of ARM registers.
6823 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
6824 MCRR2
6825 MRRC{cond}
6826 MRRC2
6827
6828 Two XScale instructions are special cases of these:
6829
6830 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
6831 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
6832
6833 Result unpredicatable if Rd or Rn is R15. */
6834
6835 static void
6836 do_co_reg2c (void)
6837 {
6838 inst.instruction |= inst.operands[0].reg << 8;
6839 inst.instruction |= inst.operands[1].imm << 4;
6840 inst.instruction |= inst.operands[2].reg << 12;
6841 inst.instruction |= inst.operands[3].reg << 16;
6842 inst.instruction |= inst.operands[4].reg;
6843 }
6844
6845 static void
6846 do_cpsi (void)
6847 {
6848 inst.instruction |= inst.operands[0].imm << 6;
6849 if (inst.operands[1].present)
6850 {
6851 inst.instruction |= CPSI_MMOD;
6852 inst.instruction |= inst.operands[1].imm;
6853 }
6854 }
6855
6856 static void
6857 do_dbg (void)
6858 {
6859 inst.instruction |= inst.operands[0].imm;
6860 }
6861
6862 static void
6863 do_it (void)
6864 {
6865 /* There is no IT instruction in ARM mode. We
6866 process it but do not generate code for it. */
6867 inst.size = 0;
6868 }
6869
6870 static void
6871 do_ldmstm (void)
6872 {
6873 int base_reg = inst.operands[0].reg;
6874 int range = inst.operands[1].imm;
6875
6876 inst.instruction |= base_reg << 16;
6877 inst.instruction |= range;
6878
6879 if (inst.operands[1].writeback)
6880 inst.instruction |= LDM_TYPE_2_OR_3;
6881
6882 if (inst.operands[0].writeback)
6883 {
6884 inst.instruction |= WRITE_BACK;
6885 /* Check for unpredictable uses of writeback. */
6886 if (inst.instruction & LOAD_BIT)
6887 {
6888 /* Not allowed in LDM type 2. */
6889 if ((inst.instruction & LDM_TYPE_2_OR_3)
6890 && ((range & (1 << REG_PC)) == 0))
6891 as_warn (_("writeback of base register is UNPREDICTABLE"));
6892 /* Only allowed if base reg not in list for other types. */
6893 else if (range & (1 << base_reg))
6894 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
6895 }
6896 else /* STM. */
6897 {
6898 /* Not allowed for type 2. */
6899 if (inst.instruction & LDM_TYPE_2_OR_3)
6900 as_warn (_("writeback of base register is UNPREDICTABLE"));
6901 /* Only allowed if base reg not in list, or first in list. */
6902 else if ((range & (1 << base_reg))
6903 && (range & ((1 << base_reg) - 1)))
6904 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
6905 }
6906 }
6907 }
6908
6909 /* ARMv5TE load-consecutive (argument parse)
6910 Mode is like LDRH.
6911
6912 LDRccD R, mode
6913 STRccD R, mode. */
6914
6915 static void
6916 do_ldrd (void)
6917 {
6918 constraint (inst.operands[0].reg % 2 != 0,
6919 _("first destination register must be even"));
6920 constraint (inst.operands[1].present
6921 && inst.operands[1].reg != inst.operands[0].reg + 1,
6922 _("can only load two consecutive registers"));
6923 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
6924 constraint (!inst.operands[2].isreg, _("'[' expected"));
6925
6926 if (!inst.operands[1].present)
6927 inst.operands[1].reg = inst.operands[0].reg + 1;
6928
6929 if (inst.instruction & LOAD_BIT)
6930 {
6931 /* encode_arm_addr_mode_3 will diagnose overlap between the base
6932 register and the first register written; we have to diagnose
6933 overlap between the base and the second register written here. */
6934
6935 if (inst.operands[2].reg == inst.operands[1].reg
6936 && (inst.operands[2].writeback || inst.operands[2].postind))
6937 as_warn (_("base register written back, and overlaps "
6938 "second destination register"));
6939
6940 /* For an index-register load, the index register must not overlap the
6941 destination (even if not write-back). */
6942 else if (inst.operands[2].immisreg
6943 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
6944 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
6945 as_warn (_("index register overlaps destination register"));
6946 }
6947
6948 inst.instruction |= inst.operands[0].reg << 12;
6949 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
6950 }
6951
6952 static void
6953 do_ldrex (void)
6954 {
6955 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
6956 || inst.operands[1].postind || inst.operands[1].writeback
6957 || inst.operands[1].immisreg || inst.operands[1].shifted
6958 || inst.operands[1].negative
6959 /* This can arise if the programmer has written
6960 strex rN, rM, foo
6961 or if they have mistakenly used a register name as the last
6962 operand, eg:
6963 strex rN, rM, rX
6964 It is very difficult to distinguish between these two cases
6965 because "rX" might actually be a label. ie the register
6966 name has been occluded by a symbol of the same name. So we
6967 just generate a general 'bad addressing mode' type error
6968 message and leave it up to the programmer to discover the
6969 true cause and fix their mistake. */
6970 || (inst.operands[1].reg == REG_PC),
6971 BAD_ADDR_MODE);
6972
6973 constraint (inst.reloc.exp.X_op != O_constant
6974 || inst.reloc.exp.X_add_number != 0,
6975 _("offset must be zero in ARM encoding"));
6976
6977 inst.instruction |= inst.operands[0].reg << 12;
6978 inst.instruction |= inst.operands[1].reg << 16;
6979 inst.reloc.type = BFD_RELOC_UNUSED;
6980 }
6981
6982 static void
6983 do_ldrexd (void)
6984 {
6985 constraint (inst.operands[0].reg % 2 != 0,
6986 _("even register required"));
6987 constraint (inst.operands[1].present
6988 && inst.operands[1].reg != inst.operands[0].reg + 1,
6989 _("can only load two consecutive registers"));
6990 /* If op 1 were present and equal to PC, this function wouldn't
6991 have been called in the first place. */
6992 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
6993
6994 inst.instruction |= inst.operands[0].reg << 12;
6995 inst.instruction |= inst.operands[2].reg << 16;
6996 }
6997
6998 static void
6999 do_ldst (void)
7000 {
7001 inst.instruction |= inst.operands[0].reg << 12;
7002 if (!inst.operands[1].isreg)
7003 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
7004 return;
7005 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
7006 }
7007
7008 static void
7009 do_ldstt (void)
7010 {
7011 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7012 reject [Rn,...]. */
7013 if (inst.operands[1].preind)
7014 {
7015 constraint (inst.reloc.exp.X_op != O_constant ||
7016 inst.reloc.exp.X_add_number != 0,
7017 _("this instruction requires a post-indexed address"));
7018
7019 inst.operands[1].preind = 0;
7020 inst.operands[1].postind = 1;
7021 inst.operands[1].writeback = 1;
7022 }
7023 inst.instruction |= inst.operands[0].reg << 12;
7024 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7025 }
7026
7027 /* Halfword and signed-byte load/store operations. */
7028
7029 static void
7030 do_ldstv4 (void)
7031 {
7032 inst.instruction |= inst.operands[0].reg << 12;
7033 if (!inst.operands[1].isreg)
7034 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
7035 return;
7036 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
7037 }
7038
7039 static void
7040 do_ldsttv4 (void)
7041 {
7042 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7043 reject [Rn,...]. */
7044 if (inst.operands[1].preind)
7045 {
7046 constraint (inst.reloc.exp.X_op != O_constant ||
7047 inst.reloc.exp.X_add_number != 0,
7048 _("this instruction requires a post-indexed address"));
7049
7050 inst.operands[1].preind = 0;
7051 inst.operands[1].postind = 1;
7052 inst.operands[1].writeback = 1;
7053 }
7054 inst.instruction |= inst.operands[0].reg << 12;
7055 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7056 }
7057
7058 /* Co-processor register load/store.
7059 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7060 static void
7061 do_lstc (void)
7062 {
7063 inst.instruction |= inst.operands[0].reg << 8;
7064 inst.instruction |= inst.operands[1].reg << 12;
7065 encode_arm_cp_address (2, TRUE, TRUE, 0);
7066 }
7067
7068 static void
7069 do_mlas (void)
7070 {
7071 /* This restriction does not apply to mls (nor to mla in v6 or later). */
7072 if (inst.operands[0].reg == inst.operands[1].reg
7073 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
7074 && !(inst.instruction & 0x00400000))
7075 as_tsktsk (_("Rd and Rm should be different in mla"));
7076
7077 inst.instruction |= inst.operands[0].reg << 16;
7078 inst.instruction |= inst.operands[1].reg;
7079 inst.instruction |= inst.operands[2].reg << 8;
7080 inst.instruction |= inst.operands[3].reg << 12;
7081 }
7082
7083 static void
7084 do_mov (void)
7085 {
7086 inst.instruction |= inst.operands[0].reg << 12;
7087 encode_arm_shifter_operand (1);
7088 }
7089
7090 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7091 static void
7092 do_mov16 (void)
7093 {
7094 bfd_vma imm;
7095 bfd_boolean top;
7096
7097 top = (inst.instruction & 0x00400000) != 0;
7098 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7099 _(":lower16: not allowed this instruction"));
7100 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7101 _(":upper16: not allowed instruction"));
7102 inst.instruction |= inst.operands[0].reg << 12;
7103 if (inst.reloc.type == BFD_RELOC_UNUSED)
7104 {
7105 imm = inst.reloc.exp.X_add_number;
7106 /* The value is in two pieces: 0:11, 16:19. */
7107 inst.instruction |= (imm & 0x00000fff);
7108 inst.instruction |= (imm & 0x0000f000) << 4;
7109 }
7110 }
7111
7112 static void do_vfp_nsyn_opcode (const char *);
7113
7114 static int
7115 do_vfp_nsyn_mrs (void)
7116 {
7117 if (inst.operands[0].isvec)
7118 {
7119 if (inst.operands[1].reg != 1)
7120 first_error (_("operand 1 must be FPSCR"));
7121 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7122 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7123 do_vfp_nsyn_opcode ("fmstat");
7124 }
7125 else if (inst.operands[1].isvec)
7126 do_vfp_nsyn_opcode ("fmrx");
7127 else
7128 return FAIL;
7129
7130 return SUCCESS;
7131 }
7132
7133 static int
7134 do_vfp_nsyn_msr (void)
7135 {
7136 if (inst.operands[0].isvec)
7137 do_vfp_nsyn_opcode ("fmxr");
7138 else
7139 return FAIL;
7140
7141 return SUCCESS;
7142 }
7143
7144 static void
7145 do_mrs (void)
7146 {
7147 if (do_vfp_nsyn_mrs () == SUCCESS)
7148 return;
7149
7150 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7151 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7152 != (PSR_c|PSR_f),
7153 _("'CPSR' or 'SPSR' expected"));
7154 inst.instruction |= inst.operands[0].reg << 12;
7155 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7156 }
7157
7158 /* Two possible forms:
7159 "{C|S}PSR_<field>, Rm",
7160 "{C|S}PSR_f, #expression". */
7161
7162 static void
7163 do_msr (void)
7164 {
7165 if (do_vfp_nsyn_msr () == SUCCESS)
7166 return;
7167
7168 inst.instruction |= inst.operands[0].imm;
7169 if (inst.operands[1].isreg)
7170 inst.instruction |= inst.operands[1].reg;
7171 else
7172 {
7173 inst.instruction |= INST_IMMEDIATE;
7174 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7175 inst.reloc.pc_rel = 0;
7176 }
7177 }
7178
7179 static void
7180 do_mul (void)
7181 {
7182 if (!inst.operands[2].present)
7183 inst.operands[2].reg = inst.operands[0].reg;
7184 inst.instruction |= inst.operands[0].reg << 16;
7185 inst.instruction |= inst.operands[1].reg;
7186 inst.instruction |= inst.operands[2].reg << 8;
7187
7188 if (inst.operands[0].reg == inst.operands[1].reg
7189 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7190 as_tsktsk (_("Rd and Rm should be different in mul"));
7191 }
7192
7193 /* Long Multiply Parser
7194 UMULL RdLo, RdHi, Rm, Rs
7195 SMULL RdLo, RdHi, Rm, Rs
7196 UMLAL RdLo, RdHi, Rm, Rs
7197 SMLAL RdLo, RdHi, Rm, Rs. */
7198
7199 static void
7200 do_mull (void)
7201 {
7202 inst.instruction |= inst.operands[0].reg << 12;
7203 inst.instruction |= inst.operands[1].reg << 16;
7204 inst.instruction |= inst.operands[2].reg;
7205 inst.instruction |= inst.operands[3].reg << 8;
7206
7207 /* rdhi, rdlo and rm must all be different. */
7208 if (inst.operands[0].reg == inst.operands[1].reg
7209 || inst.operands[0].reg == inst.operands[2].reg
7210 || inst.operands[1].reg == inst.operands[2].reg)
7211 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7212 }
7213
7214 static void
7215 do_nop (void)
7216 {
7217 if (inst.operands[0].present)
7218 {
7219 /* Architectural NOP hints are CPSR sets with no bits selected. */
7220 inst.instruction &= 0xf0000000;
7221 inst.instruction |= 0x0320f000 + inst.operands[0].imm;
7222 }
7223 }
7224
7225 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7226 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7227 Condition defaults to COND_ALWAYS.
7228 Error if Rd, Rn or Rm are R15. */
7229
7230 static void
7231 do_pkhbt (void)
7232 {
7233 inst.instruction |= inst.operands[0].reg << 12;
7234 inst.instruction |= inst.operands[1].reg << 16;
7235 inst.instruction |= inst.operands[2].reg;
7236 if (inst.operands[3].present)
7237 encode_arm_shift (3);
7238 }
7239
7240 /* ARM V6 PKHTB (Argument Parse). */
7241
7242 static void
7243 do_pkhtb (void)
7244 {
7245 if (!inst.operands[3].present)
7246 {
7247 /* If the shift specifier is omitted, turn the instruction
7248 into pkhbt rd, rm, rn. */
7249 inst.instruction &= 0xfff00010;
7250 inst.instruction |= inst.operands[0].reg << 12;
7251 inst.instruction |= inst.operands[1].reg;
7252 inst.instruction |= inst.operands[2].reg << 16;
7253 }
7254 else
7255 {
7256 inst.instruction |= inst.operands[0].reg << 12;
7257 inst.instruction |= inst.operands[1].reg << 16;
7258 inst.instruction |= inst.operands[2].reg;
7259 encode_arm_shift (3);
7260 }
7261 }
7262
7263 /* ARMv5TE: Preload-Cache
7264
7265 PLD <addr_mode>
7266
7267 Syntactically, like LDR with B=1, W=0, L=1. */
7268
7269 static void
7270 do_pld (void)
7271 {
7272 constraint (!inst.operands[0].isreg,
7273 _("'[' expected after PLD mnemonic"));
7274 constraint (inst.operands[0].postind,
7275 _("post-indexed expression used in preload instruction"));
7276 constraint (inst.operands[0].writeback,
7277 _("writeback used in preload instruction"));
7278 constraint (!inst.operands[0].preind,
7279 _("unindexed addressing used in preload instruction"));
7280 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7281 }
7282
7283 /* ARMv7: PLI <addr_mode> */
7284 static void
7285 do_pli (void)
7286 {
7287 constraint (!inst.operands[0].isreg,
7288 _("'[' expected after PLI mnemonic"));
7289 constraint (inst.operands[0].postind,
7290 _("post-indexed expression used in preload instruction"));
7291 constraint (inst.operands[0].writeback,
7292 _("writeback used in preload instruction"));
7293 constraint (!inst.operands[0].preind,
7294 _("unindexed addressing used in preload instruction"));
7295 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7296 inst.instruction &= ~PRE_INDEX;
7297 }
7298
7299 static void
7300 do_push_pop (void)
7301 {
7302 inst.operands[1] = inst.operands[0];
7303 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7304 inst.operands[0].isreg = 1;
7305 inst.operands[0].writeback = 1;
7306 inst.operands[0].reg = REG_SP;
7307 do_ldmstm ();
7308 }
7309
7310 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7311 word at the specified address and the following word
7312 respectively.
7313 Unconditionally executed.
7314 Error if Rn is R15. */
7315
7316 static void
7317 do_rfe (void)
7318 {
7319 inst.instruction |= inst.operands[0].reg << 16;
7320 if (inst.operands[0].writeback)
7321 inst.instruction |= WRITE_BACK;
7322 }
7323
7324 /* ARM V6 ssat (argument parse). */
7325
7326 static void
7327 do_ssat (void)
7328 {
7329 inst.instruction |= inst.operands[0].reg << 12;
7330 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7331 inst.instruction |= inst.operands[2].reg;
7332
7333 if (inst.operands[3].present)
7334 encode_arm_shift (3);
7335 }
7336
7337 /* ARM V6 usat (argument parse). */
7338
7339 static void
7340 do_usat (void)
7341 {
7342 inst.instruction |= inst.operands[0].reg << 12;
7343 inst.instruction |= inst.operands[1].imm << 16;
7344 inst.instruction |= inst.operands[2].reg;
7345
7346 if (inst.operands[3].present)
7347 encode_arm_shift (3);
7348 }
7349
7350 /* ARM V6 ssat16 (argument parse). */
7351
7352 static void
7353 do_ssat16 (void)
7354 {
7355 inst.instruction |= inst.operands[0].reg << 12;
7356 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7357 inst.instruction |= inst.operands[2].reg;
7358 }
7359
7360 static void
7361 do_usat16 (void)
7362 {
7363 inst.instruction |= inst.operands[0].reg << 12;
7364 inst.instruction |= inst.operands[1].imm << 16;
7365 inst.instruction |= inst.operands[2].reg;
7366 }
7367
7368 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7369 preserving the other bits.
7370
7371 setend <endian_specifier>, where <endian_specifier> is either
7372 BE or LE. */
7373
7374 static void
7375 do_setend (void)
7376 {
7377 if (inst.operands[0].imm)
7378 inst.instruction |= 0x200;
7379 }
7380
7381 static void
7382 do_shift (void)
7383 {
7384 unsigned int Rm = (inst.operands[1].present
7385 ? inst.operands[1].reg
7386 : inst.operands[0].reg);
7387
7388 inst.instruction |= inst.operands[0].reg << 12;
7389 inst.instruction |= Rm;
7390 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
7391 {
7392 inst.instruction |= inst.operands[2].reg << 8;
7393 inst.instruction |= SHIFT_BY_REG;
7394 }
7395 else
7396 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7397 }
7398
7399 static void
7400 do_smc (void)
7401 {
7402 inst.reloc.type = BFD_RELOC_ARM_SMC;
7403 inst.reloc.pc_rel = 0;
7404 }
7405
7406 static void
7407 do_swi (void)
7408 {
7409 inst.reloc.type = BFD_RELOC_ARM_SWI;
7410 inst.reloc.pc_rel = 0;
7411 }
7412
7413 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7414 SMLAxy{cond} Rd,Rm,Rs,Rn
7415 SMLAWy{cond} Rd,Rm,Rs,Rn
7416 Error if any register is R15. */
7417
7418 static void
7419 do_smla (void)
7420 {
7421 inst.instruction |= inst.operands[0].reg << 16;
7422 inst.instruction |= inst.operands[1].reg;
7423 inst.instruction |= inst.operands[2].reg << 8;
7424 inst.instruction |= inst.operands[3].reg << 12;
7425 }
7426
7427 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7428 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7429 Error if any register is R15.
7430 Warning if Rdlo == Rdhi. */
7431
7432 static void
7433 do_smlal (void)
7434 {
7435 inst.instruction |= inst.operands[0].reg << 12;
7436 inst.instruction |= inst.operands[1].reg << 16;
7437 inst.instruction |= inst.operands[2].reg;
7438 inst.instruction |= inst.operands[3].reg << 8;
7439
7440 if (inst.operands[0].reg == inst.operands[1].reg)
7441 as_tsktsk (_("rdhi and rdlo must be different"));
7442 }
7443
7444 /* ARM V5E (El Segundo) signed-multiply (argument parse)
7445 SMULxy{cond} Rd,Rm,Rs
7446 Error if any register is R15. */
7447
7448 static void
7449 do_smul (void)
7450 {
7451 inst.instruction |= inst.operands[0].reg << 16;
7452 inst.instruction |= inst.operands[1].reg;
7453 inst.instruction |= inst.operands[2].reg << 8;
7454 }
7455
7456 /* ARM V6 srs (argument parse). The variable fields in the encoding are
7457 the same for both ARM and Thumb-2. */
7458
7459 static void
7460 do_srs (void)
7461 {
7462 int reg;
7463
7464 if (inst.operands[0].present)
7465 {
7466 reg = inst.operands[0].reg;
7467 constraint (reg != 13, _("SRS base register must be r13"));
7468 }
7469 else
7470 reg = 13;
7471
7472 inst.instruction |= reg << 16;
7473 inst.instruction |= inst.operands[1].imm;
7474 if (inst.operands[0].writeback || inst.operands[1].writeback)
7475 inst.instruction |= WRITE_BACK;
7476 }
7477
7478 /* ARM V6 strex (argument parse). */
7479
7480 static void
7481 do_strex (void)
7482 {
7483 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7484 || inst.operands[2].postind || inst.operands[2].writeback
7485 || inst.operands[2].immisreg || inst.operands[2].shifted
7486 || inst.operands[2].negative
7487 /* See comment in do_ldrex(). */
7488 || (inst.operands[2].reg == REG_PC),
7489 BAD_ADDR_MODE);
7490
7491 constraint (inst.operands[0].reg == inst.operands[1].reg
7492 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
7493
7494 constraint (inst.reloc.exp.X_op != O_constant
7495 || inst.reloc.exp.X_add_number != 0,
7496 _("offset must be zero in ARM encoding"));
7497
7498 inst.instruction |= inst.operands[0].reg << 12;
7499 inst.instruction |= inst.operands[1].reg;
7500 inst.instruction |= inst.operands[2].reg << 16;
7501 inst.reloc.type = BFD_RELOC_UNUSED;
7502 }
7503
7504 static void
7505 do_strexd (void)
7506 {
7507 constraint (inst.operands[1].reg % 2 != 0,
7508 _("even register required"));
7509 constraint (inst.operands[2].present
7510 && inst.operands[2].reg != inst.operands[1].reg + 1,
7511 _("can only store two consecutive registers"));
7512 /* If op 2 were present and equal to PC, this function wouldn't
7513 have been called in the first place. */
7514 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
7515
7516 constraint (inst.operands[0].reg == inst.operands[1].reg
7517 || inst.operands[0].reg == inst.operands[1].reg + 1
7518 || inst.operands[0].reg == inst.operands[3].reg,
7519 BAD_OVERLAP);
7520
7521 inst.instruction |= inst.operands[0].reg << 12;
7522 inst.instruction |= inst.operands[1].reg;
7523 inst.instruction |= inst.operands[3].reg << 16;
7524 }
7525
7526 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
7527 extends it to 32-bits, and adds the result to a value in another
7528 register. You can specify a rotation by 0, 8, 16, or 24 bits
7529 before extracting the 16-bit value.
7530 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
7531 Condition defaults to COND_ALWAYS.
7532 Error if any register uses R15. */
7533
7534 static void
7535 do_sxtah (void)
7536 {
7537 inst.instruction |= inst.operands[0].reg << 12;
7538 inst.instruction |= inst.operands[1].reg << 16;
7539 inst.instruction |= inst.operands[2].reg;
7540 inst.instruction |= inst.operands[3].imm << 10;
7541 }
7542
7543 /* ARM V6 SXTH.
7544
7545 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
7546 Condition defaults to COND_ALWAYS.
7547 Error if any register uses R15. */
7548
7549 static void
7550 do_sxth (void)
7551 {
7552 inst.instruction |= inst.operands[0].reg << 12;
7553 inst.instruction |= inst.operands[1].reg;
7554 inst.instruction |= inst.operands[2].imm << 10;
7555 }
7556 \f
7557 /* VFP instructions. In a logical order: SP variant first, monad
7558 before dyad, arithmetic then move then load/store. */
7559
7560 static void
7561 do_vfp_sp_monadic (void)
7562 {
7563 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7564 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
7565 }
7566
7567 static void
7568 do_vfp_sp_dyadic (void)
7569 {
7570 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7571 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7572 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
7573 }
7574
7575 static void
7576 do_vfp_sp_compare_z (void)
7577 {
7578 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7579 }
7580
7581 static void
7582 do_vfp_dp_sp_cvt (void)
7583 {
7584 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7585 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
7586 }
7587
7588 static void
7589 do_vfp_sp_dp_cvt (void)
7590 {
7591 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7592 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7593 }
7594
7595 static void
7596 do_vfp_reg_from_sp (void)
7597 {
7598 inst.instruction |= inst.operands[0].reg << 12;
7599 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7600 }
7601
7602 static void
7603 do_vfp_reg2_from_sp2 (void)
7604 {
7605 constraint (inst.operands[2].imm != 2,
7606 _("only two consecutive VFP SP registers allowed here"));
7607 inst.instruction |= inst.operands[0].reg << 12;
7608 inst.instruction |= inst.operands[1].reg << 16;
7609 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
7610 }
7611
7612 static void
7613 do_vfp_sp_from_reg (void)
7614 {
7615 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
7616 inst.instruction |= inst.operands[1].reg << 12;
7617 }
7618
7619 static void
7620 do_vfp_sp2_from_reg2 (void)
7621 {
7622 constraint (inst.operands[0].imm != 2,
7623 _("only two consecutive VFP SP registers allowed here"));
7624 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
7625 inst.instruction |= inst.operands[1].reg << 12;
7626 inst.instruction |= inst.operands[2].reg << 16;
7627 }
7628
7629 static void
7630 do_vfp_sp_ldst (void)
7631 {
7632 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7633 encode_arm_cp_address (1, FALSE, TRUE, 0);
7634 }
7635
7636 static void
7637 do_vfp_dp_ldst (void)
7638 {
7639 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7640 encode_arm_cp_address (1, FALSE, TRUE, 0);
7641 }
7642
7643
7644 static void
7645 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
7646 {
7647 if (inst.operands[0].writeback)
7648 inst.instruction |= WRITE_BACK;
7649 else
7650 constraint (ldstm_type != VFP_LDSTMIA,
7651 _("this addressing mode requires base-register writeback"));
7652 inst.instruction |= inst.operands[0].reg << 16;
7653 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
7654 inst.instruction |= inst.operands[1].imm;
7655 }
7656
7657 static void
7658 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
7659 {
7660 int count;
7661
7662 if (inst.operands[0].writeback)
7663 inst.instruction |= WRITE_BACK;
7664 else
7665 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
7666 _("this addressing mode requires base-register writeback"));
7667
7668 inst.instruction |= inst.operands[0].reg << 16;
7669 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7670
7671 count = inst.operands[1].imm << 1;
7672 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
7673 count += 1;
7674
7675 inst.instruction |= count;
7676 }
7677
7678 static void
7679 do_vfp_sp_ldstmia (void)
7680 {
7681 vfp_sp_ldstm (VFP_LDSTMIA);
7682 }
7683
7684 static void
7685 do_vfp_sp_ldstmdb (void)
7686 {
7687 vfp_sp_ldstm (VFP_LDSTMDB);
7688 }
7689
7690 static void
7691 do_vfp_dp_ldstmia (void)
7692 {
7693 vfp_dp_ldstm (VFP_LDSTMIA);
7694 }
7695
7696 static void
7697 do_vfp_dp_ldstmdb (void)
7698 {
7699 vfp_dp_ldstm (VFP_LDSTMDB);
7700 }
7701
7702 static void
7703 do_vfp_xp_ldstmia (void)
7704 {
7705 vfp_dp_ldstm (VFP_LDSTMIAX);
7706 }
7707
7708 static void
7709 do_vfp_xp_ldstmdb (void)
7710 {
7711 vfp_dp_ldstm (VFP_LDSTMDBX);
7712 }
7713
7714 static void
7715 do_vfp_dp_rd_rm (void)
7716 {
7717 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7718 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7719 }
7720
7721 static void
7722 do_vfp_dp_rn_rd (void)
7723 {
7724 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
7725 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7726 }
7727
7728 static void
7729 do_vfp_dp_rd_rn (void)
7730 {
7731 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7732 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7733 }
7734
7735 static void
7736 do_vfp_dp_rd_rn_rm (void)
7737 {
7738 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7739 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7740 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
7741 }
7742
7743 static void
7744 do_vfp_dp_rd (void)
7745 {
7746 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7747 }
7748
7749 static void
7750 do_vfp_dp_rm_rd_rn (void)
7751 {
7752 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
7753 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7754 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
7755 }
7756
7757 /* VFPv3 instructions. */
7758 static void
7759 do_vfp_sp_const (void)
7760 {
7761 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7762 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7763 inst.instruction |= (inst.operands[1].imm & 0x0f);
7764 }
7765
7766 static void
7767 do_vfp_dp_const (void)
7768 {
7769 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7770 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7771 inst.instruction |= (inst.operands[1].imm & 0x0f);
7772 }
7773
7774 static void
7775 vfp_conv (int srcsize)
7776 {
7777 unsigned immbits = srcsize - inst.operands[1].imm;
7778 inst.instruction |= (immbits & 1) << 5;
7779 inst.instruction |= (immbits >> 1);
7780 }
7781
7782 static void
7783 do_vfp_sp_conv_16 (void)
7784 {
7785 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7786 vfp_conv (16);
7787 }
7788
7789 static void
7790 do_vfp_dp_conv_16 (void)
7791 {
7792 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7793 vfp_conv (16);
7794 }
7795
7796 static void
7797 do_vfp_sp_conv_32 (void)
7798 {
7799 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7800 vfp_conv (32);
7801 }
7802
7803 static void
7804 do_vfp_dp_conv_32 (void)
7805 {
7806 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7807 vfp_conv (32);
7808 }
7809
7810 \f
7811 /* FPA instructions. Also in a logical order. */
7812
7813 static void
7814 do_fpa_cmp (void)
7815 {
7816 inst.instruction |= inst.operands[0].reg << 16;
7817 inst.instruction |= inst.operands[1].reg;
7818 }
7819
7820 static void
7821 do_fpa_ldmstm (void)
7822 {
7823 inst.instruction |= inst.operands[0].reg << 12;
7824 switch (inst.operands[1].imm)
7825 {
7826 case 1: inst.instruction |= CP_T_X; break;
7827 case 2: inst.instruction |= CP_T_Y; break;
7828 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
7829 case 4: break;
7830 default: abort ();
7831 }
7832
7833 if (inst.instruction & (PRE_INDEX | INDEX_UP))
7834 {
7835 /* The instruction specified "ea" or "fd", so we can only accept
7836 [Rn]{!}. The instruction does not really support stacking or
7837 unstacking, so we have to emulate these by setting appropriate
7838 bits and offsets. */
7839 constraint (inst.reloc.exp.X_op != O_constant
7840 || inst.reloc.exp.X_add_number != 0,
7841 _("this instruction does not support indexing"));
7842
7843 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
7844 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
7845
7846 if (!(inst.instruction & INDEX_UP))
7847 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
7848
7849 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
7850 {
7851 inst.operands[2].preind = 0;
7852 inst.operands[2].postind = 1;
7853 }
7854 }
7855
7856 encode_arm_cp_address (2, TRUE, TRUE, 0);
7857 }
7858
7859 \f
7860 /* iWMMXt instructions: strictly in alphabetical order. */
7861
7862 static void
7863 do_iwmmxt_tandorc (void)
7864 {
7865 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
7866 }
7867
7868 static void
7869 do_iwmmxt_textrc (void)
7870 {
7871 inst.instruction |= inst.operands[0].reg << 12;
7872 inst.instruction |= inst.operands[1].imm;
7873 }
7874
7875 static void
7876 do_iwmmxt_textrm (void)
7877 {
7878 inst.instruction |= inst.operands[0].reg << 12;
7879 inst.instruction |= inst.operands[1].reg << 16;
7880 inst.instruction |= inst.operands[2].imm;
7881 }
7882
7883 static void
7884 do_iwmmxt_tinsr (void)
7885 {
7886 inst.instruction |= inst.operands[0].reg << 16;
7887 inst.instruction |= inst.operands[1].reg << 12;
7888 inst.instruction |= inst.operands[2].imm;
7889 }
7890
7891 static void
7892 do_iwmmxt_tmia (void)
7893 {
7894 inst.instruction |= inst.operands[0].reg << 5;
7895 inst.instruction |= inst.operands[1].reg;
7896 inst.instruction |= inst.operands[2].reg << 12;
7897 }
7898
7899 static void
7900 do_iwmmxt_waligni (void)
7901 {
7902 inst.instruction |= inst.operands[0].reg << 12;
7903 inst.instruction |= inst.operands[1].reg << 16;
7904 inst.instruction |= inst.operands[2].reg;
7905 inst.instruction |= inst.operands[3].imm << 20;
7906 }
7907
7908 static void
7909 do_iwmmxt_wmerge (void)
7910 {
7911 inst.instruction |= inst.operands[0].reg << 12;
7912 inst.instruction |= inst.operands[1].reg << 16;
7913 inst.instruction |= inst.operands[2].reg;
7914 inst.instruction |= inst.operands[3].imm << 21;
7915 }
7916
7917 static void
7918 do_iwmmxt_wmov (void)
7919 {
7920 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
7921 inst.instruction |= inst.operands[0].reg << 12;
7922 inst.instruction |= inst.operands[1].reg << 16;
7923 inst.instruction |= inst.operands[1].reg;
7924 }
7925
7926 static void
7927 do_iwmmxt_wldstbh (void)
7928 {
7929 int reloc;
7930 inst.instruction |= inst.operands[0].reg << 12;
7931 if (thumb_mode)
7932 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
7933 else
7934 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
7935 encode_arm_cp_address (1, TRUE, FALSE, reloc);
7936 }
7937
7938 static void
7939 do_iwmmxt_wldstw (void)
7940 {
7941 /* RIWR_RIWC clears .isreg for a control register. */
7942 if (!inst.operands[0].isreg)
7943 {
7944 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7945 inst.instruction |= 0xf0000000;
7946 }
7947
7948 inst.instruction |= inst.operands[0].reg << 12;
7949 encode_arm_cp_address (1, TRUE, TRUE, 0);
7950 }
7951
7952 static void
7953 do_iwmmxt_wldstd (void)
7954 {
7955 inst.instruction |= inst.operands[0].reg << 12;
7956 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
7957 && inst.operands[1].immisreg)
7958 {
7959 inst.instruction &= ~0x1a000ff;
7960 inst.instruction |= (0xf << 28);
7961 if (inst.operands[1].preind)
7962 inst.instruction |= PRE_INDEX;
7963 if (!inst.operands[1].negative)
7964 inst.instruction |= INDEX_UP;
7965 if (inst.operands[1].writeback)
7966 inst.instruction |= WRITE_BACK;
7967 inst.instruction |= inst.operands[1].reg << 16;
7968 inst.instruction |= inst.reloc.exp.X_add_number << 4;
7969 inst.instruction |= inst.operands[1].imm;
7970 }
7971 else
7972 encode_arm_cp_address (1, TRUE, FALSE, 0);
7973 }
7974
7975 static void
7976 do_iwmmxt_wshufh (void)
7977 {
7978 inst.instruction |= inst.operands[0].reg << 12;
7979 inst.instruction |= inst.operands[1].reg << 16;
7980 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
7981 inst.instruction |= (inst.operands[2].imm & 0x0f);
7982 }
7983
7984 static void
7985 do_iwmmxt_wzero (void)
7986 {
7987 /* WZERO reg is an alias for WANDN reg, reg, reg. */
7988 inst.instruction |= inst.operands[0].reg;
7989 inst.instruction |= inst.operands[0].reg << 12;
7990 inst.instruction |= inst.operands[0].reg << 16;
7991 }
7992
7993 static void
7994 do_iwmmxt_wrwrwr_or_imm5 (void)
7995 {
7996 if (inst.operands[2].isreg)
7997 do_rd_rn_rm ();
7998 else {
7999 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8000 _("immediate operand requires iWMMXt2"));
8001 do_rd_rn ();
8002 if (inst.operands[2].imm == 0)
8003 {
8004 switch ((inst.instruction >> 20) & 0xf)
8005 {
8006 case 4:
8007 case 5:
8008 case 6:
8009 case 7:
8010 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8011 inst.operands[2].imm = 16;
8012 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8013 break;
8014 case 8:
8015 case 9:
8016 case 10:
8017 case 11:
8018 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8019 inst.operands[2].imm = 32;
8020 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8021 break;
8022 case 12:
8023 case 13:
8024 case 14:
8025 case 15:
8026 {
8027 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8028 unsigned long wrn;
8029 wrn = (inst.instruction >> 16) & 0xf;
8030 inst.instruction &= 0xff0fff0f;
8031 inst.instruction |= wrn;
8032 /* Bail out here; the instruction is now assembled. */
8033 return;
8034 }
8035 }
8036 }
8037 /* Map 32 -> 0, etc. */
8038 inst.operands[2].imm &= 0x1f;
8039 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8040 }
8041 }
8042 \f
8043 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8044 operations first, then control, shift, and load/store. */
8045
8046 /* Insns like "foo X,Y,Z". */
8047
8048 static void
8049 do_mav_triple (void)
8050 {
8051 inst.instruction |= inst.operands[0].reg << 16;
8052 inst.instruction |= inst.operands[1].reg;
8053 inst.instruction |= inst.operands[2].reg << 12;
8054 }
8055
8056 /* Insns like "foo W,X,Y,Z".
8057 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
8058
8059 static void
8060 do_mav_quad (void)
8061 {
8062 inst.instruction |= inst.operands[0].reg << 5;
8063 inst.instruction |= inst.operands[1].reg << 12;
8064 inst.instruction |= inst.operands[2].reg << 16;
8065 inst.instruction |= inst.operands[3].reg;
8066 }
8067
8068 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8069 static void
8070 do_mav_dspsc (void)
8071 {
8072 inst.instruction |= inst.operands[1].reg << 12;
8073 }
8074
8075 /* Maverick shift immediate instructions.
8076 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8077 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
8078
8079 static void
8080 do_mav_shift (void)
8081 {
8082 int imm = inst.operands[2].imm;
8083
8084 inst.instruction |= inst.operands[0].reg << 12;
8085 inst.instruction |= inst.operands[1].reg << 16;
8086
8087 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8088 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8089 Bit 4 should be 0. */
8090 imm = (imm & 0xf) | ((imm & 0x70) << 1);
8091
8092 inst.instruction |= imm;
8093 }
8094 \f
8095 /* XScale instructions. Also sorted arithmetic before move. */
8096
8097 /* Xscale multiply-accumulate (argument parse)
8098 MIAcc acc0,Rm,Rs
8099 MIAPHcc acc0,Rm,Rs
8100 MIAxycc acc0,Rm,Rs. */
8101
8102 static void
8103 do_xsc_mia (void)
8104 {
8105 inst.instruction |= inst.operands[1].reg;
8106 inst.instruction |= inst.operands[2].reg << 12;
8107 }
8108
8109 /* Xscale move-accumulator-register (argument parse)
8110
8111 MARcc acc0,RdLo,RdHi. */
8112
8113 static void
8114 do_xsc_mar (void)
8115 {
8116 inst.instruction |= inst.operands[1].reg << 12;
8117 inst.instruction |= inst.operands[2].reg << 16;
8118 }
8119
8120 /* Xscale move-register-accumulator (argument parse)
8121
8122 MRAcc RdLo,RdHi,acc0. */
8123
8124 static void
8125 do_xsc_mra (void)
8126 {
8127 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8128 inst.instruction |= inst.operands[0].reg << 12;
8129 inst.instruction |= inst.operands[1].reg << 16;
8130 }
8131 \f
8132 /* Encoding functions relevant only to Thumb. */
8133
8134 /* inst.operands[i] is a shifted-register operand; encode
8135 it into inst.instruction in the format used by Thumb32. */
8136
8137 static void
8138 encode_thumb32_shifted_operand (int i)
8139 {
8140 unsigned int value = inst.reloc.exp.X_add_number;
8141 unsigned int shift = inst.operands[i].shift_kind;
8142
8143 constraint (inst.operands[i].immisreg,
8144 _("shift by register not allowed in thumb mode"));
8145 inst.instruction |= inst.operands[i].reg;
8146 if (shift == SHIFT_RRX)
8147 inst.instruction |= SHIFT_ROR << 4;
8148 else
8149 {
8150 constraint (inst.reloc.exp.X_op != O_constant,
8151 _("expression too complex"));
8152
8153 constraint (value > 32
8154 || (value == 32 && (shift == SHIFT_LSL
8155 || shift == SHIFT_ROR)),
8156 _("shift expression is too large"));
8157
8158 if (value == 0)
8159 shift = SHIFT_LSL;
8160 else if (value == 32)
8161 value = 0;
8162
8163 inst.instruction |= shift << 4;
8164 inst.instruction |= (value & 0x1c) << 10;
8165 inst.instruction |= (value & 0x03) << 6;
8166 }
8167 }
8168
8169
8170 /* inst.operands[i] was set up by parse_address. Encode it into a
8171 Thumb32 format load or store instruction. Reject forms that cannot
8172 be used with such instructions. If is_t is true, reject forms that
8173 cannot be used with a T instruction; if is_d is true, reject forms
8174 that cannot be used with a D instruction. */
8175
8176 static void
8177 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8178 {
8179 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8180
8181 constraint (!inst.operands[i].isreg,
8182 _("Instruction does not support =N addresses"));
8183
8184 inst.instruction |= inst.operands[i].reg << 16;
8185 if (inst.operands[i].immisreg)
8186 {
8187 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
8188 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8189 constraint (inst.operands[i].negative,
8190 _("Thumb does not support negative register indexing"));
8191 constraint (inst.operands[i].postind,
8192 _("Thumb does not support register post-indexing"));
8193 constraint (inst.operands[i].writeback,
8194 _("Thumb does not support register indexing with writeback"));
8195 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8196 _("Thumb supports only LSL in shifted register indexing"));
8197
8198 inst.instruction |= inst.operands[i].imm;
8199 if (inst.operands[i].shifted)
8200 {
8201 constraint (inst.reloc.exp.X_op != O_constant,
8202 _("expression too complex"));
8203 constraint (inst.reloc.exp.X_add_number < 0
8204 || inst.reloc.exp.X_add_number > 3,
8205 _("shift out of range"));
8206 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8207 }
8208 inst.reloc.type = BFD_RELOC_UNUSED;
8209 }
8210 else if (inst.operands[i].preind)
8211 {
8212 constraint (is_pc && inst.operands[i].writeback,
8213 _("cannot use writeback with PC-relative addressing"));
8214 constraint (is_t && inst.operands[i].writeback,
8215 _("cannot use writeback with this instruction"));
8216
8217 if (is_d)
8218 {
8219 inst.instruction |= 0x01000000;
8220 if (inst.operands[i].writeback)
8221 inst.instruction |= 0x00200000;
8222 }
8223 else
8224 {
8225 inst.instruction |= 0x00000c00;
8226 if (inst.operands[i].writeback)
8227 inst.instruction |= 0x00000100;
8228 }
8229 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8230 }
8231 else if (inst.operands[i].postind)
8232 {
8233 assert (inst.operands[i].writeback);
8234 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8235 constraint (is_t, _("cannot use post-indexing with this instruction"));
8236
8237 if (is_d)
8238 inst.instruction |= 0x00200000;
8239 else
8240 inst.instruction |= 0x00000900;
8241 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8242 }
8243 else /* unindexed - only for coprocessor */
8244 inst.error = _("instruction does not accept unindexed addressing");
8245 }
8246
8247 /* Table of Thumb instructions which exist in both 16- and 32-bit
8248 encodings (the latter only in post-V6T2 cores). The index is the
8249 value used in the insns table below. When there is more than one
8250 possible 16-bit encoding for the instruction, this table always
8251 holds variant (1).
8252 Also contains several pseudo-instructions used during relaxation. */
8253 #define T16_32_TAB \
8254 X(adc, 4140, eb400000), \
8255 X(adcs, 4140, eb500000), \
8256 X(add, 1c00, eb000000), \
8257 X(adds, 1c00, eb100000), \
8258 X(addi, 0000, f1000000), \
8259 X(addis, 0000, f1100000), \
8260 X(add_pc,000f, f20f0000), \
8261 X(add_sp,000d, f10d0000), \
8262 X(adr, 000f, f20f0000), \
8263 X(and, 4000, ea000000), \
8264 X(ands, 4000, ea100000), \
8265 X(asr, 1000, fa40f000), \
8266 X(asrs, 1000, fa50f000), \
8267 X(b, e000, f000b000), \
8268 X(bcond, d000, f0008000), \
8269 X(bic, 4380, ea200000), \
8270 X(bics, 4380, ea300000), \
8271 X(cmn, 42c0, eb100f00), \
8272 X(cmp, 2800, ebb00f00), \
8273 X(cpsie, b660, f3af8400), \
8274 X(cpsid, b670, f3af8600), \
8275 X(cpy, 4600, ea4f0000), \
8276 X(dec_sp,80dd, f1ad0d00), \
8277 X(eor, 4040, ea800000), \
8278 X(eors, 4040, ea900000), \
8279 X(inc_sp,00dd, f10d0d00), \
8280 X(ldmia, c800, e8900000), \
8281 X(ldr, 6800, f8500000), \
8282 X(ldrb, 7800, f8100000), \
8283 X(ldrh, 8800, f8300000), \
8284 X(ldrsb, 5600, f9100000), \
8285 X(ldrsh, 5e00, f9300000), \
8286 X(ldr_pc,4800, f85f0000), \
8287 X(ldr_pc2,4800, f85f0000), \
8288 X(ldr_sp,9800, f85d0000), \
8289 X(lsl, 0000, fa00f000), \
8290 X(lsls, 0000, fa10f000), \
8291 X(lsr, 0800, fa20f000), \
8292 X(lsrs, 0800, fa30f000), \
8293 X(mov, 2000, ea4f0000), \
8294 X(movs, 2000, ea5f0000), \
8295 X(mul, 4340, fb00f000), \
8296 X(muls, 4340, ffffffff), /* no 32b muls */ \
8297 X(mvn, 43c0, ea6f0000), \
8298 X(mvns, 43c0, ea7f0000), \
8299 X(neg, 4240, f1c00000), /* rsb #0 */ \
8300 X(negs, 4240, f1d00000), /* rsbs #0 */ \
8301 X(orr, 4300, ea400000), \
8302 X(orrs, 4300, ea500000), \
8303 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8304 X(push, b400, e92d0000), /* stmdb sp!,... */ \
8305 X(rev, ba00, fa90f080), \
8306 X(rev16, ba40, fa90f090), \
8307 X(revsh, bac0, fa90f0b0), \
8308 X(ror, 41c0, fa60f000), \
8309 X(rors, 41c0, fa70f000), \
8310 X(sbc, 4180, eb600000), \
8311 X(sbcs, 4180, eb700000), \
8312 X(stmia, c000, e8800000), \
8313 X(str, 6000, f8400000), \
8314 X(strb, 7000, f8000000), \
8315 X(strh, 8000, f8200000), \
8316 X(str_sp,9000, f84d0000), \
8317 X(sub, 1e00, eba00000), \
8318 X(subs, 1e00, ebb00000), \
8319 X(subi, 8000, f1a00000), \
8320 X(subis, 8000, f1b00000), \
8321 X(sxtb, b240, fa4ff080), \
8322 X(sxth, b200, fa0ff080), \
8323 X(tst, 4200, ea100f00), \
8324 X(uxtb, b2c0, fa5ff080), \
8325 X(uxth, b280, fa1ff080), \
8326 X(nop, bf00, f3af8000), \
8327 X(yield, bf10, f3af8001), \
8328 X(wfe, bf20, f3af8002), \
8329 X(wfi, bf30, f3af8003), \
8330 X(sev, bf40, f3af9004), /* typo, 8004? */
8331
8332 /* To catch errors in encoding functions, the codes are all offset by
8333 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8334 as 16-bit instructions. */
8335 #define X(a,b,c) T_MNEM_##a
8336 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8337 #undef X
8338
8339 #define X(a,b,c) 0x##b
8340 static const unsigned short thumb_op16[] = { T16_32_TAB };
8341 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8342 #undef X
8343
8344 #define X(a,b,c) 0x##c
8345 static const unsigned int thumb_op32[] = { T16_32_TAB };
8346 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8347 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
8348 #undef X
8349 #undef T16_32_TAB
8350
8351 /* Thumb instruction encoders, in alphabetical order. */
8352
8353 /* ADDW or SUBW. */
8354 static void
8355 do_t_add_sub_w (void)
8356 {
8357 int Rd, Rn;
8358
8359 Rd = inst.operands[0].reg;
8360 Rn = inst.operands[1].reg;
8361
8362 constraint (Rd == 15, _("PC not allowed as destination"));
8363 inst.instruction |= (Rn << 16) | (Rd << 8);
8364 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8365 }
8366
8367 /* Parse an add or subtract instruction. We get here with inst.instruction
8368 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8369
8370 static void
8371 do_t_add_sub (void)
8372 {
8373 int Rd, Rs, Rn;
8374
8375 Rd = inst.operands[0].reg;
8376 Rs = (inst.operands[1].present
8377 ? inst.operands[1].reg /* Rd, Rs, foo */
8378 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8379
8380 if (unified_syntax)
8381 {
8382 bfd_boolean flags;
8383 bfd_boolean narrow;
8384 int opcode;
8385
8386 flags = (inst.instruction == T_MNEM_adds
8387 || inst.instruction == T_MNEM_subs);
8388 if (flags)
8389 narrow = (current_it_mask == 0);
8390 else
8391 narrow = (current_it_mask != 0);
8392 if (!inst.operands[2].isreg)
8393 {
8394 int add;
8395
8396 add = (inst.instruction == T_MNEM_add
8397 || inst.instruction == T_MNEM_adds);
8398 opcode = 0;
8399 if (inst.size_req != 4)
8400 {
8401 /* Attempt to use a narrow opcode, with relaxation if
8402 appropriate. */
8403 if (Rd == REG_SP && Rs == REG_SP && !flags)
8404 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8405 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8406 opcode = T_MNEM_add_sp;
8407 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8408 opcode = T_MNEM_add_pc;
8409 else if (Rd <= 7 && Rs <= 7 && narrow)
8410 {
8411 if (flags)
8412 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8413 else
8414 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8415 }
8416 if (opcode)
8417 {
8418 inst.instruction = THUMB_OP16(opcode);
8419 inst.instruction |= (Rd << 4) | Rs;
8420 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8421 if (inst.size_req != 2)
8422 inst.relax = opcode;
8423 }
8424 else
8425 constraint (inst.size_req == 2, BAD_HIREG);
8426 }
8427 if (inst.size_req == 4
8428 || (inst.size_req != 2 && !opcode))
8429 {
8430 if (Rd == REG_PC)
8431 {
8432 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
8433 _("only SUBS PC, LR, #const allowed"));
8434 constraint (inst.reloc.exp.X_op != O_constant,
8435 _("expression too complex"));
8436 constraint (inst.reloc.exp.X_add_number < 0
8437 || inst.reloc.exp.X_add_number > 0xff,
8438 _("immediate value out of range"));
8439 inst.instruction = T2_SUBS_PC_LR
8440 | inst.reloc.exp.X_add_number;
8441 inst.reloc.type = BFD_RELOC_UNUSED;
8442 return;
8443 }
8444 else if (Rs == REG_PC)
8445 {
8446 /* Always use addw/subw. */
8447 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8448 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8449 }
8450 else
8451 {
8452 inst.instruction = THUMB_OP32 (inst.instruction);
8453 inst.instruction = (inst.instruction & 0xe1ffffff)
8454 | 0x10000000;
8455 if (flags)
8456 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8457 else
8458 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
8459 }
8460 inst.instruction |= Rd << 8;
8461 inst.instruction |= Rs << 16;
8462 }
8463 }
8464 else
8465 {
8466 Rn = inst.operands[2].reg;
8467 /* See if we can do this with a 16-bit instruction. */
8468 if (!inst.operands[2].shifted && inst.size_req != 4)
8469 {
8470 if (Rd > 7 || Rs > 7 || Rn > 7)
8471 narrow = FALSE;
8472
8473 if (narrow)
8474 {
8475 inst.instruction = ((inst.instruction == T_MNEM_adds
8476 || inst.instruction == T_MNEM_add)
8477 ? T_OPCODE_ADD_R3
8478 : T_OPCODE_SUB_R3);
8479 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8480 return;
8481 }
8482
8483 if (inst.instruction == T_MNEM_add)
8484 {
8485 if (Rd == Rs)
8486 {
8487 inst.instruction = T_OPCODE_ADD_HI;
8488 inst.instruction |= (Rd & 8) << 4;
8489 inst.instruction |= (Rd & 7);
8490 inst.instruction |= Rn << 3;
8491 return;
8492 }
8493 /* ... because addition is commutative! */
8494 else if (Rd == Rn)
8495 {
8496 inst.instruction = T_OPCODE_ADD_HI;
8497 inst.instruction |= (Rd & 8) << 4;
8498 inst.instruction |= (Rd & 7);
8499 inst.instruction |= Rs << 3;
8500 return;
8501 }
8502 }
8503 }
8504 /* If we get here, it can't be done in 16 bits. */
8505 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
8506 _("shift must be constant"));
8507 inst.instruction = THUMB_OP32 (inst.instruction);
8508 inst.instruction |= Rd << 8;
8509 inst.instruction |= Rs << 16;
8510 encode_thumb32_shifted_operand (2);
8511 }
8512 }
8513 else
8514 {
8515 constraint (inst.instruction == T_MNEM_adds
8516 || inst.instruction == T_MNEM_subs,
8517 BAD_THUMB32);
8518
8519 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
8520 {
8521 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
8522 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
8523 BAD_HIREG);
8524
8525 inst.instruction = (inst.instruction == T_MNEM_add
8526 ? 0x0000 : 0x8000);
8527 inst.instruction |= (Rd << 4) | Rs;
8528 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8529 return;
8530 }
8531
8532 Rn = inst.operands[2].reg;
8533 constraint (inst.operands[2].shifted, _("unshifted register required"));
8534
8535 /* We now have Rd, Rs, and Rn set to registers. */
8536 if (Rd > 7 || Rs > 7 || Rn > 7)
8537 {
8538 /* Can't do this for SUB. */
8539 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
8540 inst.instruction = T_OPCODE_ADD_HI;
8541 inst.instruction |= (Rd & 8) << 4;
8542 inst.instruction |= (Rd & 7);
8543 if (Rs == Rd)
8544 inst.instruction |= Rn << 3;
8545 else if (Rn == Rd)
8546 inst.instruction |= Rs << 3;
8547 else
8548 constraint (1, _("dest must overlap one source register"));
8549 }
8550 else
8551 {
8552 inst.instruction = (inst.instruction == T_MNEM_add
8553 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
8554 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8555 }
8556 }
8557 }
8558
8559 static void
8560 do_t_adr (void)
8561 {
8562 if (unified_syntax && inst.size_req == 0 && inst.operands[0].reg <= 7)
8563 {
8564 /* Defer to section relaxation. */
8565 inst.relax = inst.instruction;
8566 inst.instruction = THUMB_OP16 (inst.instruction);
8567 inst.instruction |= inst.operands[0].reg << 4;
8568 }
8569 else if (unified_syntax && inst.size_req != 2)
8570 {
8571 /* Generate a 32-bit opcode. */
8572 inst.instruction = THUMB_OP32 (inst.instruction);
8573 inst.instruction |= inst.operands[0].reg << 8;
8574 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
8575 inst.reloc.pc_rel = 1;
8576 }
8577 else
8578 {
8579 /* Generate a 16-bit opcode. */
8580 inst.instruction = THUMB_OP16 (inst.instruction);
8581 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8582 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
8583 inst.reloc.pc_rel = 1;
8584
8585 inst.instruction |= inst.operands[0].reg << 4;
8586 }
8587 }
8588
8589 /* Arithmetic instructions for which there is just one 16-bit
8590 instruction encoding, and it allows only two low registers.
8591 For maximal compatibility with ARM syntax, we allow three register
8592 operands even when Thumb-32 instructions are not available, as long
8593 as the first two are identical. For instance, both "sbc r0,r1" and
8594 "sbc r0,r0,r1" are allowed. */
8595 static void
8596 do_t_arit3 (void)
8597 {
8598 int Rd, Rs, Rn;
8599
8600 Rd = inst.operands[0].reg;
8601 Rs = (inst.operands[1].present
8602 ? inst.operands[1].reg /* Rd, Rs, foo */
8603 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8604 Rn = inst.operands[2].reg;
8605
8606 if (unified_syntax)
8607 {
8608 if (!inst.operands[2].isreg)
8609 {
8610 /* For an immediate, we always generate a 32-bit opcode;
8611 section relaxation will shrink it later if possible. */
8612 inst.instruction = THUMB_OP32 (inst.instruction);
8613 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8614 inst.instruction |= Rd << 8;
8615 inst.instruction |= Rs << 16;
8616 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8617 }
8618 else
8619 {
8620 bfd_boolean narrow;
8621
8622 /* See if we can do this with a 16-bit instruction. */
8623 if (THUMB_SETS_FLAGS (inst.instruction))
8624 narrow = current_it_mask == 0;
8625 else
8626 narrow = current_it_mask != 0;
8627
8628 if (Rd > 7 || Rn > 7 || Rs > 7)
8629 narrow = FALSE;
8630 if (inst.operands[2].shifted)
8631 narrow = FALSE;
8632 if (inst.size_req == 4)
8633 narrow = FALSE;
8634
8635 if (narrow
8636 && Rd == Rs)
8637 {
8638 inst.instruction = THUMB_OP16 (inst.instruction);
8639 inst.instruction |= Rd;
8640 inst.instruction |= Rn << 3;
8641 return;
8642 }
8643
8644 /* If we get here, it can't be done in 16 bits. */
8645 constraint (inst.operands[2].shifted
8646 && inst.operands[2].immisreg,
8647 _("shift must be constant"));
8648 inst.instruction = THUMB_OP32 (inst.instruction);
8649 inst.instruction |= Rd << 8;
8650 inst.instruction |= Rs << 16;
8651 encode_thumb32_shifted_operand (2);
8652 }
8653 }
8654 else
8655 {
8656 /* On its face this is a lie - the instruction does set the
8657 flags. However, the only supported mnemonic in this mode
8658 says it doesn't. */
8659 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
8660
8661 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8662 _("unshifted register required"));
8663 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8664 constraint (Rd != Rs,
8665 _("dest and source1 must be the same register"));
8666
8667 inst.instruction = THUMB_OP16 (inst.instruction);
8668 inst.instruction |= Rd;
8669 inst.instruction |= Rn << 3;
8670 }
8671 }
8672
8673 /* Similarly, but for instructions where the arithmetic operation is
8674 commutative, so we can allow either of them to be different from
8675 the destination operand in a 16-bit instruction. For instance, all
8676 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
8677 accepted. */
8678 static void
8679 do_t_arit3c (void)
8680 {
8681 int Rd, Rs, Rn;
8682
8683 Rd = inst.operands[0].reg;
8684 Rs = (inst.operands[1].present
8685 ? inst.operands[1].reg /* Rd, Rs, foo */
8686 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8687 Rn = inst.operands[2].reg;
8688
8689 if (unified_syntax)
8690 {
8691 if (!inst.operands[2].isreg)
8692 {
8693 /* For an immediate, we always generate a 32-bit opcode;
8694 section relaxation will shrink it later if possible. */
8695 inst.instruction = THUMB_OP32 (inst.instruction);
8696 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8697 inst.instruction |= Rd << 8;
8698 inst.instruction |= Rs << 16;
8699 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8700 }
8701 else
8702 {
8703 bfd_boolean narrow;
8704
8705 /* See if we can do this with a 16-bit instruction. */
8706 if (THUMB_SETS_FLAGS (inst.instruction))
8707 narrow = current_it_mask == 0;
8708 else
8709 narrow = current_it_mask != 0;
8710
8711 if (Rd > 7 || Rn > 7 || Rs > 7)
8712 narrow = FALSE;
8713 if (inst.operands[2].shifted)
8714 narrow = FALSE;
8715 if (inst.size_req == 4)
8716 narrow = FALSE;
8717
8718 if (narrow)
8719 {
8720 if (Rd == Rs)
8721 {
8722 inst.instruction = THUMB_OP16 (inst.instruction);
8723 inst.instruction |= Rd;
8724 inst.instruction |= Rn << 3;
8725 return;
8726 }
8727 if (Rd == Rn)
8728 {
8729 inst.instruction = THUMB_OP16 (inst.instruction);
8730 inst.instruction |= Rd;
8731 inst.instruction |= Rs << 3;
8732 return;
8733 }
8734 }
8735
8736 /* If we get here, it can't be done in 16 bits. */
8737 constraint (inst.operands[2].shifted
8738 && inst.operands[2].immisreg,
8739 _("shift must be constant"));
8740 inst.instruction = THUMB_OP32 (inst.instruction);
8741 inst.instruction |= Rd << 8;
8742 inst.instruction |= Rs << 16;
8743 encode_thumb32_shifted_operand (2);
8744 }
8745 }
8746 else
8747 {
8748 /* On its face this is a lie - the instruction does set the
8749 flags. However, the only supported mnemonic in this mode
8750 says it doesn't. */
8751 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
8752
8753 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8754 _("unshifted register required"));
8755 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8756
8757 inst.instruction = THUMB_OP16 (inst.instruction);
8758 inst.instruction |= Rd;
8759
8760 if (Rd == Rs)
8761 inst.instruction |= Rn << 3;
8762 else if (Rd == Rn)
8763 inst.instruction |= Rs << 3;
8764 else
8765 constraint (1, _("dest must overlap one source register"));
8766 }
8767 }
8768
8769 static void
8770 do_t_barrier (void)
8771 {
8772 if (inst.operands[0].present)
8773 {
8774 constraint ((inst.instruction & 0xf0) != 0x40
8775 && inst.operands[0].imm != 0xf,
8776 "bad barrier type");
8777 inst.instruction |= inst.operands[0].imm;
8778 }
8779 else
8780 inst.instruction |= 0xf;
8781 }
8782
8783 static void
8784 do_t_bfc (void)
8785 {
8786 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8787 constraint (msb > 32, _("bit-field extends past end of register"));
8788 /* The instruction encoding stores the LSB and MSB,
8789 not the LSB and width. */
8790 inst.instruction |= inst.operands[0].reg << 8;
8791 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
8792 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
8793 inst.instruction |= msb - 1;
8794 }
8795
8796 static void
8797 do_t_bfi (void)
8798 {
8799 unsigned int msb;
8800
8801 /* #0 in second position is alternative syntax for bfc, which is
8802 the same instruction but with REG_PC in the Rm field. */
8803 if (!inst.operands[1].isreg)
8804 inst.operands[1].reg = REG_PC;
8805
8806 msb = inst.operands[2].imm + inst.operands[3].imm;
8807 constraint (msb > 32, _("bit-field extends past end of register"));
8808 /* The instruction encoding stores the LSB and MSB,
8809 not the LSB and width. */
8810 inst.instruction |= inst.operands[0].reg << 8;
8811 inst.instruction |= inst.operands[1].reg << 16;
8812 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8813 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8814 inst.instruction |= msb - 1;
8815 }
8816
8817 static void
8818 do_t_bfx (void)
8819 {
8820 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8821 _("bit-field extends past end of register"));
8822 inst.instruction |= inst.operands[0].reg << 8;
8823 inst.instruction |= inst.operands[1].reg << 16;
8824 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8825 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8826 inst.instruction |= inst.operands[3].imm - 1;
8827 }
8828
8829 /* ARM V5 Thumb BLX (argument parse)
8830 BLX <target_addr> which is BLX(1)
8831 BLX <Rm> which is BLX(2)
8832 Unfortunately, there are two different opcodes for this mnemonic.
8833 So, the insns[].value is not used, and the code here zaps values
8834 into inst.instruction.
8835
8836 ??? How to take advantage of the additional two bits of displacement
8837 available in Thumb32 mode? Need new relocation? */
8838
8839 static void
8840 do_t_blx (void)
8841 {
8842 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8843 if (inst.operands[0].isreg)
8844 /* We have a register, so this is BLX(2). */
8845 inst.instruction |= inst.operands[0].reg << 3;
8846 else
8847 {
8848 /* No register. This must be BLX(1). */
8849 inst.instruction = 0xf000e800;
8850 #ifdef OBJ_ELF
8851 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8852 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
8853 else
8854 #endif
8855 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
8856 inst.reloc.pc_rel = 1;
8857 }
8858 }
8859
8860 static void
8861 do_t_branch (void)
8862 {
8863 int opcode;
8864 int cond;
8865
8866 if (current_it_mask)
8867 {
8868 /* Conditional branches inside IT blocks are encoded as unconditional
8869 branches. */
8870 cond = COND_ALWAYS;
8871 /* A branch must be the last instruction in an IT block. */
8872 constraint (current_it_mask != 0x10, BAD_BRANCH);
8873 }
8874 else
8875 cond = inst.cond;
8876
8877 if (cond != COND_ALWAYS)
8878 opcode = T_MNEM_bcond;
8879 else
8880 opcode = inst.instruction;
8881
8882 if (unified_syntax && inst.size_req == 4)
8883 {
8884 inst.instruction = THUMB_OP32(opcode);
8885 if (cond == COND_ALWAYS)
8886 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
8887 else
8888 {
8889 assert (cond != 0xF);
8890 inst.instruction |= cond << 22;
8891 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
8892 }
8893 }
8894 else
8895 {
8896 inst.instruction = THUMB_OP16(opcode);
8897 if (cond == COND_ALWAYS)
8898 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
8899 else
8900 {
8901 inst.instruction |= cond << 8;
8902 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
8903 }
8904 /* Allow section relaxation. */
8905 if (unified_syntax && inst.size_req != 2)
8906 inst.relax = opcode;
8907 }
8908
8909 inst.reloc.pc_rel = 1;
8910 }
8911
8912 static void
8913 do_t_bkpt (void)
8914 {
8915 constraint (inst.cond != COND_ALWAYS,
8916 _("instruction is always unconditional"));
8917 if (inst.operands[0].present)
8918 {
8919 constraint (inst.operands[0].imm > 255,
8920 _("immediate value out of range"));
8921 inst.instruction |= inst.operands[0].imm;
8922 }
8923 }
8924
8925 static void
8926 do_t_branch23 (void)
8927 {
8928 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8929 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
8930 inst.reloc.pc_rel = 1;
8931
8932 /* If the destination of the branch is a defined symbol which does not have
8933 the THUMB_FUNC attribute, then we must be calling a function which has
8934 the (interfacearm) attribute. We look for the Thumb entry point to that
8935 function and change the branch to refer to that function instead. */
8936 if ( inst.reloc.exp.X_op == O_symbol
8937 && inst.reloc.exp.X_add_symbol != NULL
8938 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8939 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8940 inst.reloc.exp.X_add_symbol =
8941 find_real_start (inst.reloc.exp.X_add_symbol);
8942 }
8943
8944 static void
8945 do_t_bx (void)
8946 {
8947 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8948 inst.instruction |= inst.operands[0].reg << 3;
8949 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
8950 should cause the alignment to be checked once it is known. This is
8951 because BX PC only works if the instruction is word aligned. */
8952 }
8953
8954 static void
8955 do_t_bxj (void)
8956 {
8957 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8958 if (inst.operands[0].reg == REG_PC)
8959 as_tsktsk (_("use of r15 in bxj is not really useful"));
8960
8961 inst.instruction |= inst.operands[0].reg << 16;
8962 }
8963
8964 static void
8965 do_t_clz (void)
8966 {
8967 inst.instruction |= inst.operands[0].reg << 8;
8968 inst.instruction |= inst.operands[1].reg << 16;
8969 inst.instruction |= inst.operands[1].reg;
8970 }
8971
8972 static void
8973 do_t_cps (void)
8974 {
8975 constraint (current_it_mask, BAD_NOT_IT);
8976 inst.instruction |= inst.operands[0].imm;
8977 }
8978
8979 static void
8980 do_t_cpsi (void)
8981 {
8982 constraint (current_it_mask, BAD_NOT_IT);
8983 if (unified_syntax
8984 && (inst.operands[1].present || inst.size_req == 4)
8985 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
8986 {
8987 unsigned int imod = (inst.instruction & 0x0030) >> 4;
8988 inst.instruction = 0xf3af8000;
8989 inst.instruction |= imod << 9;
8990 inst.instruction |= inst.operands[0].imm << 5;
8991 if (inst.operands[1].present)
8992 inst.instruction |= 0x100 | inst.operands[1].imm;
8993 }
8994 else
8995 {
8996 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
8997 && (inst.operands[0].imm & 4),
8998 _("selected processor does not support 'A' form "
8999 "of this instruction"));
9000 constraint (inst.operands[1].present || inst.size_req == 4,
9001 _("Thumb does not support the 2-argument "
9002 "form of this instruction"));
9003 inst.instruction |= inst.operands[0].imm;
9004 }
9005 }
9006
9007 /* THUMB CPY instruction (argument parse). */
9008
9009 static void
9010 do_t_cpy (void)
9011 {
9012 if (inst.size_req == 4)
9013 {
9014 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9015 inst.instruction |= inst.operands[0].reg << 8;
9016 inst.instruction |= inst.operands[1].reg;
9017 }
9018 else
9019 {
9020 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9021 inst.instruction |= (inst.operands[0].reg & 0x7);
9022 inst.instruction |= inst.operands[1].reg << 3;
9023 }
9024 }
9025
9026 static void
9027 do_t_cbz (void)
9028 {
9029 constraint (current_it_mask, BAD_NOT_IT);
9030 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9031 inst.instruction |= inst.operands[0].reg;
9032 inst.reloc.pc_rel = 1;
9033 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9034 }
9035
9036 static void
9037 do_t_dbg (void)
9038 {
9039 inst.instruction |= inst.operands[0].imm;
9040 }
9041
9042 static void
9043 do_t_div (void)
9044 {
9045 if (!inst.operands[1].present)
9046 inst.operands[1].reg = inst.operands[0].reg;
9047 inst.instruction |= inst.operands[0].reg << 8;
9048 inst.instruction |= inst.operands[1].reg << 16;
9049 inst.instruction |= inst.operands[2].reg;
9050 }
9051
9052 static void
9053 do_t_hint (void)
9054 {
9055 if (unified_syntax && inst.size_req == 4)
9056 inst.instruction = THUMB_OP32 (inst.instruction);
9057 else
9058 inst.instruction = THUMB_OP16 (inst.instruction);
9059 }
9060
9061 static void
9062 do_t_it (void)
9063 {
9064 unsigned int cond = inst.operands[0].imm;
9065
9066 constraint (current_it_mask, BAD_NOT_IT);
9067 current_it_mask = (inst.instruction & 0xf) | 0x10;
9068 current_cc = cond;
9069
9070 /* If the condition is a negative condition, invert the mask. */
9071 if ((cond & 0x1) == 0x0)
9072 {
9073 unsigned int mask = inst.instruction & 0x000f;
9074
9075 if ((mask & 0x7) == 0)
9076 /* no conversion needed */;
9077 else if ((mask & 0x3) == 0)
9078 mask ^= 0x8;
9079 else if ((mask & 0x1) == 0)
9080 mask ^= 0xC;
9081 else
9082 mask ^= 0xE;
9083
9084 inst.instruction &= 0xfff0;
9085 inst.instruction |= mask;
9086 }
9087
9088 inst.instruction |= cond << 4;
9089 }
9090
9091 /* Helper function used for both push/pop and ldm/stm. */
9092 static void
9093 encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9094 {
9095 bfd_boolean load;
9096
9097 load = (inst.instruction & (1 << 20)) != 0;
9098
9099 if (mask & (1 << 13))
9100 inst.error = _("SP not allowed in register list");
9101 if (load)
9102 {
9103 if (mask & (1 << 14)
9104 && mask & (1 << 15))
9105 inst.error = _("LR and PC should not both be in register list");
9106
9107 if ((mask & (1 << base)) != 0
9108 && writeback)
9109 as_warn (_("base register should not be in register list "
9110 "when written back"));
9111 }
9112 else
9113 {
9114 if (mask & (1 << 15))
9115 inst.error = _("PC not allowed in register list");
9116
9117 if (mask & (1 << base))
9118 as_warn (_("value stored for r%d is UNPREDICTABLE"), base);
9119 }
9120
9121 if ((mask & (mask - 1)) == 0)
9122 {
9123 /* Single register transfers implemented as str/ldr. */
9124 if (writeback)
9125 {
9126 if (inst.instruction & (1 << 23))
9127 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9128 else
9129 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9130 }
9131 else
9132 {
9133 if (inst.instruction & (1 << 23))
9134 inst.instruction = 0x00800000; /* ia -> [base] */
9135 else
9136 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9137 }
9138
9139 inst.instruction |= 0xf8400000;
9140 if (load)
9141 inst.instruction |= 0x00100000;
9142
9143 mask = ffs(mask) - 1;
9144 mask <<= 12;
9145 }
9146 else if (writeback)
9147 inst.instruction |= WRITE_BACK;
9148
9149 inst.instruction |= mask;
9150 inst.instruction |= base << 16;
9151 }
9152
9153 static void
9154 do_t_ldmstm (void)
9155 {
9156 /* This really doesn't seem worth it. */
9157 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9158 _("expression too complex"));
9159 constraint (inst.operands[1].writeback,
9160 _("Thumb load/store multiple does not support {reglist}^"));
9161
9162 if (unified_syntax)
9163 {
9164 bfd_boolean narrow;
9165 unsigned mask;
9166
9167 narrow = FALSE;
9168 /* See if we can use a 16-bit instruction. */
9169 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9170 && inst.size_req != 4
9171 && !(inst.operands[1].imm & ~0xff))
9172 {
9173 mask = 1 << inst.operands[0].reg;
9174
9175 if (inst.operands[0].reg <= 7
9176 && (inst.instruction == T_MNEM_stmia
9177 ? inst.operands[0].writeback
9178 : (inst.operands[0].writeback
9179 == !(inst.operands[1].imm & mask))))
9180 {
9181 if (inst.instruction == T_MNEM_stmia
9182 && (inst.operands[1].imm & mask)
9183 && (inst.operands[1].imm & (mask - 1)))
9184 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9185 inst.operands[0].reg);
9186
9187 inst.instruction = THUMB_OP16 (inst.instruction);
9188 inst.instruction |= inst.operands[0].reg << 8;
9189 inst.instruction |= inst.operands[1].imm;
9190 narrow = TRUE;
9191 }
9192 else if (inst.operands[0] .reg == REG_SP
9193 && inst.operands[0].writeback)
9194 {
9195 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9196 ? T_MNEM_push : T_MNEM_pop);
9197 inst.instruction |= inst.operands[1].imm;
9198 narrow = TRUE;
9199 }
9200 }
9201
9202 if (!narrow)
9203 {
9204 if (inst.instruction < 0xffff)
9205 inst.instruction = THUMB_OP32 (inst.instruction);
9206
9207 encode_thumb2_ldmstm(inst.operands[0].reg, inst.operands[1].imm,
9208 inst.operands[0].writeback);
9209 }
9210 }
9211 else
9212 {
9213 constraint (inst.operands[0].reg > 7
9214 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
9215 constraint (inst.instruction != T_MNEM_ldmia
9216 && inst.instruction != T_MNEM_stmia,
9217 _("Thumb-2 instruction only valid in unified syntax"));
9218 if (inst.instruction == T_MNEM_stmia)
9219 {
9220 if (!inst.operands[0].writeback)
9221 as_warn (_("this instruction will write back the base register"));
9222 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9223 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9224 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9225 inst.operands[0].reg);
9226 }
9227 else
9228 {
9229 if (!inst.operands[0].writeback
9230 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9231 as_warn (_("this instruction will write back the base register"));
9232 else if (inst.operands[0].writeback
9233 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9234 as_warn (_("this instruction will not write back the base register"));
9235 }
9236
9237 inst.instruction = THUMB_OP16 (inst.instruction);
9238 inst.instruction |= inst.operands[0].reg << 8;
9239 inst.instruction |= inst.operands[1].imm;
9240 }
9241 }
9242
9243 static void
9244 do_t_ldrex (void)
9245 {
9246 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9247 || inst.operands[1].postind || inst.operands[1].writeback
9248 || inst.operands[1].immisreg || inst.operands[1].shifted
9249 || inst.operands[1].negative,
9250 BAD_ADDR_MODE);
9251
9252 inst.instruction |= inst.operands[0].reg << 12;
9253 inst.instruction |= inst.operands[1].reg << 16;
9254 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9255 }
9256
9257 static void
9258 do_t_ldrexd (void)
9259 {
9260 if (!inst.operands[1].present)
9261 {
9262 constraint (inst.operands[0].reg == REG_LR,
9263 _("r14 not allowed as first register "
9264 "when second register is omitted"));
9265 inst.operands[1].reg = inst.operands[0].reg + 1;
9266 }
9267 constraint (inst.operands[0].reg == inst.operands[1].reg,
9268 BAD_OVERLAP);
9269
9270 inst.instruction |= inst.operands[0].reg << 12;
9271 inst.instruction |= inst.operands[1].reg << 8;
9272 inst.instruction |= inst.operands[2].reg << 16;
9273 }
9274
9275 static void
9276 do_t_ldst (void)
9277 {
9278 unsigned long opcode;
9279 int Rn;
9280
9281 opcode = inst.instruction;
9282 if (unified_syntax)
9283 {
9284 if (!inst.operands[1].isreg)
9285 {
9286 if (opcode <= 0xffff)
9287 inst.instruction = THUMB_OP32 (opcode);
9288 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9289 return;
9290 }
9291 if (inst.operands[1].isreg
9292 && !inst.operands[1].writeback
9293 && !inst.operands[1].shifted && !inst.operands[1].postind
9294 && !inst.operands[1].negative && inst.operands[0].reg <= 7
9295 && opcode <= 0xffff
9296 && inst.size_req != 4)
9297 {
9298 /* Insn may have a 16-bit form. */
9299 Rn = inst.operands[1].reg;
9300 if (inst.operands[1].immisreg)
9301 {
9302 inst.instruction = THUMB_OP16 (opcode);
9303 /* [Rn, Ri] */
9304 if (Rn <= 7 && inst.operands[1].imm <= 7)
9305 goto op16;
9306 }
9307 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9308 && opcode != T_MNEM_ldrsb)
9309 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9310 || (Rn == REG_SP && opcode == T_MNEM_str))
9311 {
9312 /* [Rn, #const] */
9313 if (Rn > 7)
9314 {
9315 if (Rn == REG_PC)
9316 {
9317 if (inst.reloc.pc_rel)
9318 opcode = T_MNEM_ldr_pc2;
9319 else
9320 opcode = T_MNEM_ldr_pc;
9321 }
9322 else
9323 {
9324 if (opcode == T_MNEM_ldr)
9325 opcode = T_MNEM_ldr_sp;
9326 else
9327 opcode = T_MNEM_str_sp;
9328 }
9329 inst.instruction = inst.operands[0].reg << 8;
9330 }
9331 else
9332 {
9333 inst.instruction = inst.operands[0].reg;
9334 inst.instruction |= inst.operands[1].reg << 3;
9335 }
9336 inst.instruction |= THUMB_OP16 (opcode);
9337 if (inst.size_req == 2)
9338 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9339 else
9340 inst.relax = opcode;
9341 return;
9342 }
9343 }
9344 /* Definitely a 32-bit variant. */
9345 inst.instruction = THUMB_OP32 (opcode);
9346 inst.instruction |= inst.operands[0].reg << 12;
9347 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
9348 return;
9349 }
9350
9351 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9352
9353 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
9354 {
9355 /* Only [Rn,Rm] is acceptable. */
9356 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
9357 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
9358 || inst.operands[1].postind || inst.operands[1].shifted
9359 || inst.operands[1].negative,
9360 _("Thumb does not support this addressing mode"));
9361 inst.instruction = THUMB_OP16 (inst.instruction);
9362 goto op16;
9363 }
9364
9365 inst.instruction = THUMB_OP16 (inst.instruction);
9366 if (!inst.operands[1].isreg)
9367 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9368 return;
9369
9370 constraint (!inst.operands[1].preind
9371 || inst.operands[1].shifted
9372 || inst.operands[1].writeback,
9373 _("Thumb does not support this addressing mode"));
9374 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
9375 {
9376 constraint (inst.instruction & 0x0600,
9377 _("byte or halfword not valid for base register"));
9378 constraint (inst.operands[1].reg == REG_PC
9379 && !(inst.instruction & THUMB_LOAD_BIT),
9380 _("r15 based store not allowed"));
9381 constraint (inst.operands[1].immisreg,
9382 _("invalid base register for register offset"));
9383
9384 if (inst.operands[1].reg == REG_PC)
9385 inst.instruction = T_OPCODE_LDR_PC;
9386 else if (inst.instruction & THUMB_LOAD_BIT)
9387 inst.instruction = T_OPCODE_LDR_SP;
9388 else
9389 inst.instruction = T_OPCODE_STR_SP;
9390
9391 inst.instruction |= inst.operands[0].reg << 8;
9392 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9393 return;
9394 }
9395
9396 constraint (inst.operands[1].reg > 7, BAD_HIREG);
9397 if (!inst.operands[1].immisreg)
9398 {
9399 /* Immediate offset. */
9400 inst.instruction |= inst.operands[0].reg;
9401 inst.instruction |= inst.operands[1].reg << 3;
9402 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9403 return;
9404 }
9405
9406 /* Register offset. */
9407 constraint (inst.operands[1].imm > 7, BAD_HIREG);
9408 constraint (inst.operands[1].negative,
9409 _("Thumb does not support this addressing mode"));
9410
9411 op16:
9412 switch (inst.instruction)
9413 {
9414 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
9415 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
9416 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
9417 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
9418 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
9419 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
9420 case 0x5600 /* ldrsb */:
9421 case 0x5e00 /* ldrsh */: break;
9422 default: abort ();
9423 }
9424
9425 inst.instruction |= inst.operands[0].reg;
9426 inst.instruction |= inst.operands[1].reg << 3;
9427 inst.instruction |= inst.operands[1].imm << 6;
9428 }
9429
9430 static void
9431 do_t_ldstd (void)
9432 {
9433 if (!inst.operands[1].present)
9434 {
9435 inst.operands[1].reg = inst.operands[0].reg + 1;
9436 constraint (inst.operands[0].reg == REG_LR,
9437 _("r14 not allowed here"));
9438 }
9439 inst.instruction |= inst.operands[0].reg << 12;
9440 inst.instruction |= inst.operands[1].reg << 8;
9441 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
9442
9443 }
9444
9445 static void
9446 do_t_ldstt (void)
9447 {
9448 inst.instruction |= inst.operands[0].reg << 12;
9449 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
9450 }
9451
9452 static void
9453 do_t_mla (void)
9454 {
9455 inst.instruction |= inst.operands[0].reg << 8;
9456 inst.instruction |= inst.operands[1].reg << 16;
9457 inst.instruction |= inst.operands[2].reg;
9458 inst.instruction |= inst.operands[3].reg << 12;
9459 }
9460
9461 static void
9462 do_t_mlal (void)
9463 {
9464 inst.instruction |= inst.operands[0].reg << 12;
9465 inst.instruction |= inst.operands[1].reg << 8;
9466 inst.instruction |= inst.operands[2].reg << 16;
9467 inst.instruction |= inst.operands[3].reg;
9468 }
9469
9470 static void
9471 do_t_mov_cmp (void)
9472 {
9473 if (unified_syntax)
9474 {
9475 int r0off = (inst.instruction == T_MNEM_mov
9476 || inst.instruction == T_MNEM_movs) ? 8 : 16;
9477 unsigned long opcode;
9478 bfd_boolean narrow;
9479 bfd_boolean low_regs;
9480
9481 low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7);
9482 opcode = inst.instruction;
9483 if (current_it_mask)
9484 narrow = opcode != T_MNEM_movs;
9485 else
9486 narrow = opcode != T_MNEM_movs || low_regs;
9487 if (inst.size_req == 4
9488 || inst.operands[1].shifted)
9489 narrow = FALSE;
9490
9491 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
9492 if (opcode == T_MNEM_movs && inst.operands[1].isreg
9493 && !inst.operands[1].shifted
9494 && inst.operands[0].reg == REG_PC
9495 && inst.operands[1].reg == REG_LR)
9496 {
9497 inst.instruction = T2_SUBS_PC_LR;
9498 return;
9499 }
9500
9501 if (!inst.operands[1].isreg)
9502 {
9503 /* Immediate operand. */
9504 if (current_it_mask == 0 && opcode == T_MNEM_mov)
9505 narrow = 0;
9506 if (low_regs && narrow)
9507 {
9508 inst.instruction = THUMB_OP16 (opcode);
9509 inst.instruction |= inst.operands[0].reg << 8;
9510 if (inst.size_req == 2)
9511 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9512 else
9513 inst.relax = opcode;
9514 }
9515 else
9516 {
9517 inst.instruction = THUMB_OP32 (inst.instruction);
9518 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9519 inst.instruction |= inst.operands[0].reg << r0off;
9520 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9521 }
9522 }
9523 else if (inst.operands[1].shifted && inst.operands[1].immisreg
9524 && (inst.instruction == T_MNEM_mov
9525 || inst.instruction == T_MNEM_movs))
9526 {
9527 /* Register shifts are encoded as separate shift instructions. */
9528 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
9529
9530 if (current_it_mask)
9531 narrow = !flags;
9532 else
9533 narrow = flags;
9534
9535 if (inst.size_req == 4)
9536 narrow = FALSE;
9537
9538 if (!low_regs || inst.operands[1].imm > 7)
9539 narrow = FALSE;
9540
9541 if (inst.operands[0].reg != inst.operands[1].reg)
9542 narrow = FALSE;
9543
9544 switch (inst.operands[1].shift_kind)
9545 {
9546 case SHIFT_LSL:
9547 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
9548 break;
9549 case SHIFT_ASR:
9550 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
9551 break;
9552 case SHIFT_LSR:
9553 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
9554 break;
9555 case SHIFT_ROR:
9556 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
9557 break;
9558 default:
9559 abort();
9560 }
9561
9562 inst.instruction = opcode;
9563 if (narrow)
9564 {
9565 inst.instruction |= inst.operands[0].reg;
9566 inst.instruction |= inst.operands[1].imm << 3;
9567 }
9568 else
9569 {
9570 if (flags)
9571 inst.instruction |= CONDS_BIT;
9572
9573 inst.instruction |= inst.operands[0].reg << 8;
9574 inst.instruction |= inst.operands[1].reg << 16;
9575 inst.instruction |= inst.operands[1].imm;
9576 }
9577 }
9578 else if (!narrow)
9579 {
9580 /* Some mov with immediate shift have narrow variants.
9581 Register shifts are handled above. */
9582 if (low_regs && inst.operands[1].shifted
9583 && (inst.instruction == T_MNEM_mov
9584 || inst.instruction == T_MNEM_movs))
9585 {
9586 if (current_it_mask)
9587 narrow = (inst.instruction == T_MNEM_mov);
9588 else
9589 narrow = (inst.instruction == T_MNEM_movs);
9590 }
9591
9592 if (narrow)
9593 {
9594 switch (inst.operands[1].shift_kind)
9595 {
9596 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
9597 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
9598 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
9599 default: narrow = FALSE; break;
9600 }
9601 }
9602
9603 if (narrow)
9604 {
9605 inst.instruction |= inst.operands[0].reg;
9606 inst.instruction |= inst.operands[1].reg << 3;
9607 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
9608 }
9609 else
9610 {
9611 inst.instruction = THUMB_OP32 (inst.instruction);
9612 inst.instruction |= inst.operands[0].reg << r0off;
9613 encode_thumb32_shifted_operand (1);
9614 }
9615 }
9616 else
9617 switch (inst.instruction)
9618 {
9619 case T_MNEM_mov:
9620 inst.instruction = T_OPCODE_MOV_HR;
9621 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9622 inst.instruction |= (inst.operands[0].reg & 0x7);
9623 inst.instruction |= inst.operands[1].reg << 3;
9624 break;
9625
9626 case T_MNEM_movs:
9627 /* We know we have low registers at this point.
9628 Generate ADD Rd, Rs, #0. */
9629 inst.instruction = T_OPCODE_ADD_I3;
9630 inst.instruction |= inst.operands[0].reg;
9631 inst.instruction |= inst.operands[1].reg << 3;
9632 break;
9633
9634 case T_MNEM_cmp:
9635 if (low_regs)
9636 {
9637 inst.instruction = T_OPCODE_CMP_LR;
9638 inst.instruction |= inst.operands[0].reg;
9639 inst.instruction |= inst.operands[1].reg << 3;
9640 }
9641 else
9642 {
9643 inst.instruction = T_OPCODE_CMP_HR;
9644 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9645 inst.instruction |= (inst.operands[0].reg & 0x7);
9646 inst.instruction |= inst.operands[1].reg << 3;
9647 }
9648 break;
9649 }
9650 return;
9651 }
9652
9653 inst.instruction = THUMB_OP16 (inst.instruction);
9654 if (inst.operands[1].isreg)
9655 {
9656 if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8)
9657 {
9658 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
9659 since a MOV instruction produces unpredictable results. */
9660 if (inst.instruction == T_OPCODE_MOV_I8)
9661 inst.instruction = T_OPCODE_ADD_I3;
9662 else
9663 inst.instruction = T_OPCODE_CMP_LR;
9664
9665 inst.instruction |= inst.operands[0].reg;
9666 inst.instruction |= inst.operands[1].reg << 3;
9667 }
9668 else
9669 {
9670 if (inst.instruction == T_OPCODE_MOV_I8)
9671 inst.instruction = T_OPCODE_MOV_HR;
9672 else
9673 inst.instruction = T_OPCODE_CMP_HR;
9674 do_t_cpy ();
9675 }
9676 }
9677 else
9678 {
9679 constraint (inst.operands[0].reg > 7,
9680 _("only lo regs allowed with immediate"));
9681 inst.instruction |= inst.operands[0].reg << 8;
9682 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9683 }
9684 }
9685
9686 static void
9687 do_t_mov16 (void)
9688 {
9689 bfd_vma imm;
9690 bfd_boolean top;
9691
9692 top = (inst.instruction & 0x00800000) != 0;
9693 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
9694 {
9695 constraint (top, _(":lower16: not allowed this instruction"));
9696 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
9697 }
9698 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
9699 {
9700 constraint (!top, _(":upper16: not allowed this instruction"));
9701 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
9702 }
9703
9704 inst.instruction |= inst.operands[0].reg << 8;
9705 if (inst.reloc.type == BFD_RELOC_UNUSED)
9706 {
9707 imm = inst.reloc.exp.X_add_number;
9708 inst.instruction |= (imm & 0xf000) << 4;
9709 inst.instruction |= (imm & 0x0800) << 15;
9710 inst.instruction |= (imm & 0x0700) << 4;
9711 inst.instruction |= (imm & 0x00ff);
9712 }
9713 }
9714
9715 static void
9716 do_t_mvn_tst (void)
9717 {
9718 if (unified_syntax)
9719 {
9720 int r0off = (inst.instruction == T_MNEM_mvn
9721 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
9722 bfd_boolean narrow;
9723
9724 if (inst.size_req == 4
9725 || inst.instruction > 0xffff
9726 || inst.operands[1].shifted
9727 || inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9728 narrow = FALSE;
9729 else if (inst.instruction == T_MNEM_cmn)
9730 narrow = TRUE;
9731 else if (THUMB_SETS_FLAGS (inst.instruction))
9732 narrow = (current_it_mask == 0);
9733 else
9734 narrow = (current_it_mask != 0);
9735
9736 if (!inst.operands[1].isreg)
9737 {
9738 /* For an immediate, we always generate a 32-bit opcode;
9739 section relaxation will shrink it later if possible. */
9740 if (inst.instruction < 0xffff)
9741 inst.instruction = THUMB_OP32 (inst.instruction);
9742 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9743 inst.instruction |= inst.operands[0].reg << r0off;
9744 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9745 }
9746 else
9747 {
9748 /* See if we can do this with a 16-bit instruction. */
9749 if (narrow)
9750 {
9751 inst.instruction = THUMB_OP16 (inst.instruction);
9752 inst.instruction |= inst.operands[0].reg;
9753 inst.instruction |= inst.operands[1].reg << 3;
9754 }
9755 else
9756 {
9757 constraint (inst.operands[1].shifted
9758 && inst.operands[1].immisreg,
9759 _("shift must be constant"));
9760 if (inst.instruction < 0xffff)
9761 inst.instruction = THUMB_OP32 (inst.instruction);
9762 inst.instruction |= inst.operands[0].reg << r0off;
9763 encode_thumb32_shifted_operand (1);
9764 }
9765 }
9766 }
9767 else
9768 {
9769 constraint (inst.instruction > 0xffff
9770 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
9771 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
9772 _("unshifted register required"));
9773 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9774 BAD_HIREG);
9775
9776 inst.instruction = THUMB_OP16 (inst.instruction);
9777 inst.instruction |= inst.operands[0].reg;
9778 inst.instruction |= inst.operands[1].reg << 3;
9779 }
9780 }
9781
9782 static void
9783 do_t_mrs (void)
9784 {
9785 int flags;
9786
9787 if (do_vfp_nsyn_mrs () == SUCCESS)
9788 return;
9789
9790 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
9791 if (flags == 0)
9792 {
9793 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m),
9794 _("selected processor does not support "
9795 "requested special purpose register"));
9796 }
9797 else
9798 {
9799 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9800 _("selected processor does not support "
9801 "requested special purpose register %x"));
9802 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9803 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
9804 _("'CPSR' or 'SPSR' expected"));
9805 }
9806
9807 inst.instruction |= inst.operands[0].reg << 8;
9808 inst.instruction |= (flags & SPSR_BIT) >> 2;
9809 inst.instruction |= inst.operands[1].imm & 0xff;
9810 }
9811
9812 static void
9813 do_t_msr (void)
9814 {
9815 int flags;
9816
9817 if (do_vfp_nsyn_msr () == SUCCESS)
9818 return;
9819
9820 constraint (!inst.operands[1].isreg,
9821 _("Thumb encoding does not support an immediate here"));
9822 flags = inst.operands[0].imm;
9823 if (flags & ~0xff)
9824 {
9825 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9826 _("selected processor does not support "
9827 "requested special purpose register"));
9828 }
9829 else
9830 {
9831 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m),
9832 _("selected processor does not support "
9833 "requested special purpose register"));
9834 flags |= PSR_f;
9835 }
9836 inst.instruction |= (flags & SPSR_BIT) >> 2;
9837 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
9838 inst.instruction |= (flags & 0xff);
9839 inst.instruction |= inst.operands[1].reg << 16;
9840 }
9841
9842 static void
9843 do_t_mul (void)
9844 {
9845 if (!inst.operands[2].present)
9846 inst.operands[2].reg = inst.operands[0].reg;
9847
9848 /* There is no 32-bit MULS and no 16-bit MUL. */
9849 if (unified_syntax && inst.instruction == T_MNEM_mul)
9850 {
9851 inst.instruction = THUMB_OP32 (inst.instruction);
9852 inst.instruction |= inst.operands[0].reg << 8;
9853 inst.instruction |= inst.operands[1].reg << 16;
9854 inst.instruction |= inst.operands[2].reg << 0;
9855 }
9856 else
9857 {
9858 constraint (!unified_syntax
9859 && inst.instruction == T_MNEM_muls, BAD_THUMB32);
9860 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9861 BAD_HIREG);
9862
9863 inst.instruction = THUMB_OP16 (inst.instruction);
9864 inst.instruction |= inst.operands[0].reg;
9865
9866 if (inst.operands[0].reg == inst.operands[1].reg)
9867 inst.instruction |= inst.operands[2].reg << 3;
9868 else if (inst.operands[0].reg == inst.operands[2].reg)
9869 inst.instruction |= inst.operands[1].reg << 3;
9870 else
9871 constraint (1, _("dest must overlap one source register"));
9872 }
9873 }
9874
9875 static void
9876 do_t_mull (void)
9877 {
9878 inst.instruction |= inst.operands[0].reg << 12;
9879 inst.instruction |= inst.operands[1].reg << 8;
9880 inst.instruction |= inst.operands[2].reg << 16;
9881 inst.instruction |= inst.operands[3].reg;
9882
9883 if (inst.operands[0].reg == inst.operands[1].reg)
9884 as_tsktsk (_("rdhi and rdlo must be different"));
9885 }
9886
9887 static void
9888 do_t_nop (void)
9889 {
9890 if (unified_syntax)
9891 {
9892 if (inst.size_req == 4 || inst.operands[0].imm > 15)
9893 {
9894 inst.instruction = THUMB_OP32 (inst.instruction);
9895 inst.instruction |= inst.operands[0].imm;
9896 }
9897 else
9898 {
9899 inst.instruction = THUMB_OP16 (inst.instruction);
9900 inst.instruction |= inst.operands[0].imm << 4;
9901 }
9902 }
9903 else
9904 {
9905 constraint (inst.operands[0].present,
9906 _("Thumb does not support NOP with hints"));
9907 inst.instruction = 0x46c0;
9908 }
9909 }
9910
9911 static void
9912 do_t_neg (void)
9913 {
9914 if (unified_syntax)
9915 {
9916 bfd_boolean narrow;
9917
9918 if (THUMB_SETS_FLAGS (inst.instruction))
9919 narrow = (current_it_mask == 0);
9920 else
9921 narrow = (current_it_mask != 0);
9922 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9923 narrow = FALSE;
9924 if (inst.size_req == 4)
9925 narrow = FALSE;
9926
9927 if (!narrow)
9928 {
9929 inst.instruction = THUMB_OP32 (inst.instruction);
9930 inst.instruction |= inst.operands[0].reg << 8;
9931 inst.instruction |= inst.operands[1].reg << 16;
9932 }
9933 else
9934 {
9935 inst.instruction = THUMB_OP16 (inst.instruction);
9936 inst.instruction |= inst.operands[0].reg;
9937 inst.instruction |= inst.operands[1].reg << 3;
9938 }
9939 }
9940 else
9941 {
9942 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9943 BAD_HIREG);
9944 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9945
9946 inst.instruction = THUMB_OP16 (inst.instruction);
9947 inst.instruction |= inst.operands[0].reg;
9948 inst.instruction |= inst.operands[1].reg << 3;
9949 }
9950 }
9951
9952 static void
9953 do_t_pkhbt (void)
9954 {
9955 inst.instruction |= inst.operands[0].reg << 8;
9956 inst.instruction |= inst.operands[1].reg << 16;
9957 inst.instruction |= inst.operands[2].reg;
9958 if (inst.operands[3].present)
9959 {
9960 unsigned int val = inst.reloc.exp.X_add_number;
9961 constraint (inst.reloc.exp.X_op != O_constant,
9962 _("expression too complex"));
9963 inst.instruction |= (val & 0x1c) << 10;
9964 inst.instruction |= (val & 0x03) << 6;
9965 }
9966 }
9967
9968 static void
9969 do_t_pkhtb (void)
9970 {
9971 if (!inst.operands[3].present)
9972 inst.instruction &= ~0x00000020;
9973 do_t_pkhbt ();
9974 }
9975
9976 static void
9977 do_t_pld (void)
9978 {
9979 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
9980 }
9981
9982 static void
9983 do_t_push_pop (void)
9984 {
9985 unsigned mask;
9986
9987 constraint (inst.operands[0].writeback,
9988 _("push/pop do not support {reglist}^"));
9989 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9990 _("expression too complex"));
9991
9992 mask = inst.operands[0].imm;
9993 if ((mask & ~0xff) == 0)
9994 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
9995 else if ((inst.instruction == T_MNEM_push
9996 && (mask & ~0xff) == 1 << REG_LR)
9997 || (inst.instruction == T_MNEM_pop
9998 && (mask & ~0xff) == 1 << REG_PC))
9999 {
10000 inst.instruction = THUMB_OP16 (inst.instruction);
10001 inst.instruction |= THUMB_PP_PC_LR;
10002 inst.instruction |= mask & 0xff;
10003 }
10004 else if (unified_syntax)
10005 {
10006 inst.instruction = THUMB_OP32 (inst.instruction);
10007 encode_thumb2_ldmstm(13, mask, TRUE);
10008 }
10009 else
10010 {
10011 inst.error = _("invalid register list to push/pop instruction");
10012 return;
10013 }
10014 }
10015
10016 static void
10017 do_t_rbit (void)
10018 {
10019 inst.instruction |= inst.operands[0].reg << 8;
10020 inst.instruction |= inst.operands[1].reg << 16;
10021 }
10022
10023 static void
10024 do_t_rev (void)
10025 {
10026 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10027 && inst.size_req != 4)
10028 {
10029 inst.instruction = THUMB_OP16 (inst.instruction);
10030 inst.instruction |= inst.operands[0].reg;
10031 inst.instruction |= inst.operands[1].reg << 3;
10032 }
10033 else if (unified_syntax)
10034 {
10035 inst.instruction = THUMB_OP32 (inst.instruction);
10036 inst.instruction |= inst.operands[0].reg << 8;
10037 inst.instruction |= inst.operands[1].reg << 16;
10038 inst.instruction |= inst.operands[1].reg;
10039 }
10040 else
10041 inst.error = BAD_HIREG;
10042 }
10043
10044 static void
10045 do_t_rsb (void)
10046 {
10047 int Rd, Rs;
10048
10049 Rd = inst.operands[0].reg;
10050 Rs = (inst.operands[1].present
10051 ? inst.operands[1].reg /* Rd, Rs, foo */
10052 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10053
10054 inst.instruction |= Rd << 8;
10055 inst.instruction |= Rs << 16;
10056 if (!inst.operands[2].isreg)
10057 {
10058 bfd_boolean narrow;
10059
10060 if ((inst.instruction & 0x00100000) != 0)
10061 narrow = (current_it_mask == 0);
10062 else
10063 narrow = (current_it_mask != 0);
10064
10065 if (Rd > 7 || Rs > 7)
10066 narrow = FALSE;
10067
10068 if (inst.size_req == 4 || !unified_syntax)
10069 narrow = FALSE;
10070
10071 if (inst.reloc.exp.X_op != O_constant
10072 || inst.reloc.exp.X_add_number != 0)
10073 narrow = FALSE;
10074
10075 /* Turn rsb #0 into 16-bit neg. We should probably do this via
10076 relaxation, but it doesn't seem worth the hassle. */
10077 if (narrow)
10078 {
10079 inst.reloc.type = BFD_RELOC_UNUSED;
10080 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10081 inst.instruction |= Rs << 3;
10082 inst.instruction |= Rd;
10083 }
10084 else
10085 {
10086 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10087 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10088 }
10089 }
10090 else
10091 encode_thumb32_shifted_operand (2);
10092 }
10093
10094 static void
10095 do_t_setend (void)
10096 {
10097 constraint (current_it_mask, BAD_NOT_IT);
10098 if (inst.operands[0].imm)
10099 inst.instruction |= 0x8;
10100 }
10101
10102 static void
10103 do_t_shift (void)
10104 {
10105 if (!inst.operands[1].present)
10106 inst.operands[1].reg = inst.operands[0].reg;
10107
10108 if (unified_syntax)
10109 {
10110 bfd_boolean narrow;
10111 int shift_kind;
10112
10113 switch (inst.instruction)
10114 {
10115 case T_MNEM_asr:
10116 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
10117 case T_MNEM_lsl:
10118 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
10119 case T_MNEM_lsr:
10120 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
10121 case T_MNEM_ror:
10122 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
10123 default: abort ();
10124 }
10125
10126 if (THUMB_SETS_FLAGS (inst.instruction))
10127 narrow = (current_it_mask == 0);
10128 else
10129 narrow = (current_it_mask != 0);
10130 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10131 narrow = FALSE;
10132 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
10133 narrow = FALSE;
10134 if (inst.operands[2].isreg
10135 && (inst.operands[1].reg != inst.operands[0].reg
10136 || inst.operands[2].reg > 7))
10137 narrow = FALSE;
10138 if (inst.size_req == 4)
10139 narrow = FALSE;
10140
10141 if (!narrow)
10142 {
10143 if (inst.operands[2].isreg)
10144 {
10145 inst.instruction = THUMB_OP32 (inst.instruction);
10146 inst.instruction |= inst.operands[0].reg << 8;
10147 inst.instruction |= inst.operands[1].reg << 16;
10148 inst.instruction |= inst.operands[2].reg;
10149 }
10150 else
10151 {
10152 inst.operands[1].shifted = 1;
10153 inst.operands[1].shift_kind = shift_kind;
10154 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
10155 ? T_MNEM_movs : T_MNEM_mov);
10156 inst.instruction |= inst.operands[0].reg << 8;
10157 encode_thumb32_shifted_operand (1);
10158 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
10159 inst.reloc.type = BFD_RELOC_UNUSED;
10160 }
10161 }
10162 else
10163 {
10164 if (inst.operands[2].isreg)
10165 {
10166 switch (shift_kind)
10167 {
10168 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
10169 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
10170 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
10171 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
10172 default: abort ();
10173 }
10174
10175 inst.instruction |= inst.operands[0].reg;
10176 inst.instruction |= inst.operands[2].reg << 3;
10177 }
10178 else
10179 {
10180 switch (shift_kind)
10181 {
10182 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10183 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10184 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10185 default: abort ();
10186 }
10187 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10188 inst.instruction |= inst.operands[0].reg;
10189 inst.instruction |= inst.operands[1].reg << 3;
10190 }
10191 }
10192 }
10193 else
10194 {
10195 constraint (inst.operands[0].reg > 7
10196 || inst.operands[1].reg > 7, BAD_HIREG);
10197 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10198
10199 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
10200 {
10201 constraint (inst.operands[2].reg > 7, BAD_HIREG);
10202 constraint (inst.operands[0].reg != inst.operands[1].reg,
10203 _("source1 and dest must be same register"));
10204
10205 switch (inst.instruction)
10206 {
10207 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
10208 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
10209 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
10210 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
10211 default: abort ();
10212 }
10213
10214 inst.instruction |= inst.operands[0].reg;
10215 inst.instruction |= inst.operands[2].reg << 3;
10216 }
10217 else
10218 {
10219 switch (inst.instruction)
10220 {
10221 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
10222 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
10223 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
10224 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
10225 default: abort ();
10226 }
10227 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10228 inst.instruction |= inst.operands[0].reg;
10229 inst.instruction |= inst.operands[1].reg << 3;
10230 }
10231 }
10232 }
10233
10234 static void
10235 do_t_simd (void)
10236 {
10237 inst.instruction |= inst.operands[0].reg << 8;
10238 inst.instruction |= inst.operands[1].reg << 16;
10239 inst.instruction |= inst.operands[2].reg;
10240 }
10241
10242 static void
10243 do_t_smc (void)
10244 {
10245 unsigned int value = inst.reloc.exp.X_add_number;
10246 constraint (inst.reloc.exp.X_op != O_constant,
10247 _("expression too complex"));
10248 inst.reloc.type = BFD_RELOC_UNUSED;
10249 inst.instruction |= (value & 0xf000) >> 12;
10250 inst.instruction |= (value & 0x0ff0);
10251 inst.instruction |= (value & 0x000f) << 16;
10252 }
10253
10254 static void
10255 do_t_ssat (void)
10256 {
10257 inst.instruction |= inst.operands[0].reg << 8;
10258 inst.instruction |= inst.operands[1].imm - 1;
10259 inst.instruction |= inst.operands[2].reg << 16;
10260
10261 if (inst.operands[3].present)
10262 {
10263 constraint (inst.reloc.exp.X_op != O_constant,
10264 _("expression too complex"));
10265
10266 if (inst.reloc.exp.X_add_number != 0)
10267 {
10268 if (inst.operands[3].shift_kind == SHIFT_ASR)
10269 inst.instruction |= 0x00200000; /* sh bit */
10270 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10271 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10272 }
10273 inst.reloc.type = BFD_RELOC_UNUSED;
10274 }
10275 }
10276
10277 static void
10278 do_t_ssat16 (void)
10279 {
10280 inst.instruction |= inst.operands[0].reg << 8;
10281 inst.instruction |= inst.operands[1].imm - 1;
10282 inst.instruction |= inst.operands[2].reg << 16;
10283 }
10284
10285 static void
10286 do_t_strex (void)
10287 {
10288 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10289 || inst.operands[2].postind || inst.operands[2].writeback
10290 || inst.operands[2].immisreg || inst.operands[2].shifted
10291 || inst.operands[2].negative,
10292 BAD_ADDR_MODE);
10293
10294 inst.instruction |= inst.operands[0].reg << 8;
10295 inst.instruction |= inst.operands[1].reg << 12;
10296 inst.instruction |= inst.operands[2].reg << 16;
10297 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
10298 }
10299
10300 static void
10301 do_t_strexd (void)
10302 {
10303 if (!inst.operands[2].present)
10304 inst.operands[2].reg = inst.operands[1].reg + 1;
10305
10306 constraint (inst.operands[0].reg == inst.operands[1].reg
10307 || inst.operands[0].reg == inst.operands[2].reg
10308 || inst.operands[0].reg == inst.operands[3].reg
10309 || inst.operands[1].reg == inst.operands[2].reg,
10310 BAD_OVERLAP);
10311
10312 inst.instruction |= inst.operands[0].reg;
10313 inst.instruction |= inst.operands[1].reg << 12;
10314 inst.instruction |= inst.operands[2].reg << 8;
10315 inst.instruction |= inst.operands[3].reg << 16;
10316 }
10317
10318 static void
10319 do_t_sxtah (void)
10320 {
10321 inst.instruction |= inst.operands[0].reg << 8;
10322 inst.instruction |= inst.operands[1].reg << 16;
10323 inst.instruction |= inst.operands[2].reg;
10324 inst.instruction |= inst.operands[3].imm << 4;
10325 }
10326
10327 static void
10328 do_t_sxth (void)
10329 {
10330 if (inst.instruction <= 0xffff && inst.size_req != 4
10331 && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10332 && (!inst.operands[2].present || inst.operands[2].imm == 0))
10333 {
10334 inst.instruction = THUMB_OP16 (inst.instruction);
10335 inst.instruction |= inst.operands[0].reg;
10336 inst.instruction |= inst.operands[1].reg << 3;
10337 }
10338 else if (unified_syntax)
10339 {
10340 if (inst.instruction <= 0xffff)
10341 inst.instruction = THUMB_OP32 (inst.instruction);
10342 inst.instruction |= inst.operands[0].reg << 8;
10343 inst.instruction |= inst.operands[1].reg;
10344 inst.instruction |= inst.operands[2].imm << 4;
10345 }
10346 else
10347 {
10348 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
10349 _("Thumb encoding does not support rotation"));
10350 constraint (1, BAD_HIREG);
10351 }
10352 }
10353
10354 static void
10355 do_t_swi (void)
10356 {
10357 inst.reloc.type = BFD_RELOC_ARM_SWI;
10358 }
10359
10360 static void
10361 do_t_tb (void)
10362 {
10363 int half;
10364
10365 half = (inst.instruction & 0x10) != 0;
10366 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
10367 constraint (inst.operands[0].immisreg,
10368 _("instruction requires register index"));
10369 constraint (inst.operands[0].imm == 15,
10370 _("PC is not a valid index register"));
10371 constraint (!half && inst.operands[0].shifted,
10372 _("instruction does not allow shifted index"));
10373 inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm;
10374 }
10375
10376 static void
10377 do_t_usat (void)
10378 {
10379 inst.instruction |= inst.operands[0].reg << 8;
10380 inst.instruction |= inst.operands[1].imm;
10381 inst.instruction |= inst.operands[2].reg << 16;
10382
10383 if (inst.operands[3].present)
10384 {
10385 constraint (inst.reloc.exp.X_op != O_constant,
10386 _("expression too complex"));
10387 if (inst.reloc.exp.X_add_number != 0)
10388 {
10389 if (inst.operands[3].shift_kind == SHIFT_ASR)
10390 inst.instruction |= 0x00200000; /* sh bit */
10391
10392 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10393 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10394 }
10395 inst.reloc.type = BFD_RELOC_UNUSED;
10396 }
10397 }
10398
10399 static void
10400 do_t_usat16 (void)
10401 {
10402 inst.instruction |= inst.operands[0].reg << 8;
10403 inst.instruction |= inst.operands[1].imm;
10404 inst.instruction |= inst.operands[2].reg << 16;
10405 }
10406
10407 /* Neon instruction encoder helpers. */
10408
10409 /* Encodings for the different types for various Neon opcodes. */
10410
10411 /* An "invalid" code for the following tables. */
10412 #define N_INV -1u
10413
10414 struct neon_tab_entry
10415 {
10416 unsigned integer;
10417 unsigned float_or_poly;
10418 unsigned scalar_or_imm;
10419 };
10420
10421 /* Map overloaded Neon opcodes to their respective encodings. */
10422 #define NEON_ENC_TAB \
10423 X(vabd, 0x0000700, 0x1200d00, N_INV), \
10424 X(vmax, 0x0000600, 0x0000f00, N_INV), \
10425 X(vmin, 0x0000610, 0x0200f00, N_INV), \
10426 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
10427 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
10428 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
10429 X(vadd, 0x0000800, 0x0000d00, N_INV), \
10430 X(vsub, 0x1000800, 0x0200d00, N_INV), \
10431 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
10432 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
10433 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
10434 /* Register variants of the following two instructions are encoded as
10435 vcge / vcgt with the operands reversed. */ \
10436 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
10437 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
10438 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
10439 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
10440 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
10441 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
10442 X(vmlal, 0x0800800, N_INV, 0x0800240), \
10443 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
10444 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
10445 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
10446 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
10447 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
10448 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
10449 X(vshl, 0x0000400, N_INV, 0x0800510), \
10450 X(vqshl, 0x0000410, N_INV, 0x0800710), \
10451 X(vand, 0x0000110, N_INV, 0x0800030), \
10452 X(vbic, 0x0100110, N_INV, 0x0800030), \
10453 X(veor, 0x1000110, N_INV, N_INV), \
10454 X(vorn, 0x0300110, N_INV, 0x0800010), \
10455 X(vorr, 0x0200110, N_INV, 0x0800010), \
10456 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
10457 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
10458 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
10459 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
10460 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
10461 X(vst1, 0x0000000, 0x0800000, N_INV), \
10462 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
10463 X(vst2, 0x0000100, 0x0800100, N_INV), \
10464 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
10465 X(vst3, 0x0000200, 0x0800200, N_INV), \
10466 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
10467 X(vst4, 0x0000300, 0x0800300, N_INV), \
10468 X(vmovn, 0x1b20200, N_INV, N_INV), \
10469 X(vtrn, 0x1b20080, N_INV, N_INV), \
10470 X(vqmovn, 0x1b20200, N_INV, N_INV), \
10471 X(vqmovun, 0x1b20240, N_INV, N_INV), \
10472 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
10473 X(vnmla, 0xe000a40, 0xe000b40, N_INV), \
10474 X(vnmls, 0xe100a40, 0xe100b40, N_INV), \
10475 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
10476 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
10477 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
10478 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
10479
10480 enum neon_opc
10481 {
10482 #define X(OPC,I,F,S) N_MNEM_##OPC
10483 NEON_ENC_TAB
10484 #undef X
10485 };
10486
10487 static const struct neon_tab_entry neon_enc_tab[] =
10488 {
10489 #define X(OPC,I,F,S) { (I), (F), (S) }
10490 NEON_ENC_TAB
10491 #undef X
10492 };
10493
10494 #define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10495 #define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10496 #define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10497 #define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10498 #define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10499 #define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10500 #define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10501 #define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10502 #define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10503 #define NEON_ENC_SINGLE(X) \
10504 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
10505 #define NEON_ENC_DOUBLE(X) \
10506 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
10507
10508 /* Define shapes for instruction operands. The following mnemonic characters
10509 are used in this table:
10510
10511 F - VFP S<n> register
10512 D - Neon D<n> register
10513 Q - Neon Q<n> register
10514 I - Immediate
10515 S - Scalar
10516 R - ARM register
10517 L - D<n> register list
10518
10519 This table is used to generate various data:
10520 - enumerations of the form NS_DDR to be used as arguments to
10521 neon_select_shape.
10522 - a table classifying shapes into single, double, quad, mixed.
10523 - a table used to drive neon_select_shape.
10524 */
10525
10526 #define NEON_SHAPE_DEF \
10527 X(3, (D, D, D), DOUBLE), \
10528 X(3, (Q, Q, Q), QUAD), \
10529 X(3, (D, D, I), DOUBLE), \
10530 X(3, (Q, Q, I), QUAD), \
10531 X(3, (D, D, S), DOUBLE), \
10532 X(3, (Q, Q, S), QUAD), \
10533 X(2, (D, D), DOUBLE), \
10534 X(2, (Q, Q), QUAD), \
10535 X(2, (D, S), DOUBLE), \
10536 X(2, (Q, S), QUAD), \
10537 X(2, (D, R), DOUBLE), \
10538 X(2, (Q, R), QUAD), \
10539 X(2, (D, I), DOUBLE), \
10540 X(2, (Q, I), QUAD), \
10541 X(3, (D, L, D), DOUBLE), \
10542 X(2, (D, Q), MIXED), \
10543 X(2, (Q, D), MIXED), \
10544 X(3, (D, Q, I), MIXED), \
10545 X(3, (Q, D, I), MIXED), \
10546 X(3, (Q, D, D), MIXED), \
10547 X(3, (D, Q, Q), MIXED), \
10548 X(3, (Q, Q, D), MIXED), \
10549 X(3, (Q, D, S), MIXED), \
10550 X(3, (D, Q, S), MIXED), \
10551 X(4, (D, D, D, I), DOUBLE), \
10552 X(4, (Q, Q, Q, I), QUAD), \
10553 X(2, (F, F), SINGLE), \
10554 X(3, (F, F, F), SINGLE), \
10555 X(2, (F, I), SINGLE), \
10556 X(2, (F, D), MIXED), \
10557 X(2, (D, F), MIXED), \
10558 X(3, (F, F, I), MIXED), \
10559 X(4, (R, R, F, F), SINGLE), \
10560 X(4, (F, F, R, R), SINGLE), \
10561 X(3, (D, R, R), DOUBLE), \
10562 X(3, (R, R, D), DOUBLE), \
10563 X(2, (S, R), SINGLE), \
10564 X(2, (R, S), SINGLE), \
10565 X(2, (F, R), SINGLE), \
10566 X(2, (R, F), SINGLE)
10567
10568 #define S2(A,B) NS_##A##B
10569 #define S3(A,B,C) NS_##A##B##C
10570 #define S4(A,B,C,D) NS_##A##B##C##D
10571
10572 #define X(N, L, C) S##N L
10573
10574 enum neon_shape
10575 {
10576 NEON_SHAPE_DEF,
10577 NS_NULL
10578 };
10579
10580 #undef X
10581 #undef S2
10582 #undef S3
10583 #undef S4
10584
10585 enum neon_shape_class
10586 {
10587 SC_SINGLE,
10588 SC_DOUBLE,
10589 SC_QUAD,
10590 SC_MIXED
10591 };
10592
10593 #define X(N, L, C) SC_##C
10594
10595 static enum neon_shape_class neon_shape_class[] =
10596 {
10597 NEON_SHAPE_DEF
10598 };
10599
10600 #undef X
10601
10602 enum neon_shape_el
10603 {
10604 SE_F,
10605 SE_D,
10606 SE_Q,
10607 SE_I,
10608 SE_S,
10609 SE_R,
10610 SE_L
10611 };
10612
10613 /* Register widths of above. */
10614 static unsigned neon_shape_el_size[] =
10615 {
10616 32,
10617 64,
10618 128,
10619 0,
10620 32,
10621 32,
10622 0
10623 };
10624
10625 struct neon_shape_info
10626 {
10627 unsigned els;
10628 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
10629 };
10630
10631 #define S2(A,B) { SE_##A, SE_##B }
10632 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
10633 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
10634
10635 #define X(N, L, C) { N, S##N L }
10636
10637 static struct neon_shape_info neon_shape_tab[] =
10638 {
10639 NEON_SHAPE_DEF
10640 };
10641
10642 #undef X
10643 #undef S2
10644 #undef S3
10645 #undef S4
10646
10647 /* Bit masks used in type checking given instructions.
10648 'N_EQK' means the type must be the same as (or based on in some way) the key
10649 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
10650 set, various other bits can be set as well in order to modify the meaning of
10651 the type constraint. */
10652
10653 enum neon_type_mask
10654 {
10655 N_S8 = 0x000001,
10656 N_S16 = 0x000002,
10657 N_S32 = 0x000004,
10658 N_S64 = 0x000008,
10659 N_U8 = 0x000010,
10660 N_U16 = 0x000020,
10661 N_U32 = 0x000040,
10662 N_U64 = 0x000080,
10663 N_I8 = 0x000100,
10664 N_I16 = 0x000200,
10665 N_I32 = 0x000400,
10666 N_I64 = 0x000800,
10667 N_8 = 0x001000,
10668 N_16 = 0x002000,
10669 N_32 = 0x004000,
10670 N_64 = 0x008000,
10671 N_P8 = 0x010000,
10672 N_P16 = 0x020000,
10673 N_F32 = 0x040000,
10674 N_F64 = 0x080000,
10675 N_KEY = 0x100000, /* key element (main type specifier). */
10676 N_EQK = 0x200000, /* given operand has the same type & size as the key. */
10677 N_VFP = 0x400000, /* VFP mode: operand size must match register width. */
10678 N_DBL = 0x000001, /* if N_EQK, this operand is twice the size. */
10679 N_HLF = 0x000002, /* if N_EQK, this operand is half the size. */
10680 N_SGN = 0x000004, /* if N_EQK, this operand is forced to be signed. */
10681 N_UNS = 0x000008, /* if N_EQK, this operand is forced to be unsigned. */
10682 N_INT = 0x000010, /* if N_EQK, this operand is forced to be integer. */
10683 N_FLT = 0x000020, /* if N_EQK, this operand is forced to be float. */
10684 N_SIZ = 0x000040, /* if N_EQK, this operand is forced to be size-only. */
10685 N_UTYP = 0,
10686 N_MAX_NONSPECIAL = N_F64
10687 };
10688
10689 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
10690
10691 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
10692 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
10693 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
10694 #define N_SUF_32 (N_SU_32 | N_F32)
10695 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
10696 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
10697
10698 /* Pass this as the first type argument to neon_check_type to ignore types
10699 altogether. */
10700 #define N_IGNORE_TYPE (N_KEY | N_EQK)
10701
10702 /* Select a "shape" for the current instruction (describing register types or
10703 sizes) from a list of alternatives. Return NS_NULL if the current instruction
10704 doesn't fit. For non-polymorphic shapes, checking is usually done as a
10705 function of operand parsing, so this function doesn't need to be called.
10706 Shapes should be listed in order of decreasing length. */
10707
10708 static enum neon_shape
10709 neon_select_shape (enum neon_shape shape, ...)
10710 {
10711 va_list ap;
10712 enum neon_shape first_shape = shape;
10713
10714 /* Fix missing optional operands. FIXME: we don't know at this point how
10715 many arguments we should have, so this makes the assumption that we have
10716 > 1. This is true of all current Neon opcodes, I think, but may not be
10717 true in the future. */
10718 if (!inst.operands[1].present)
10719 inst.operands[1] = inst.operands[0];
10720
10721 va_start (ap, shape);
10722
10723 for (; shape != NS_NULL; shape = va_arg (ap, int))
10724 {
10725 unsigned j;
10726 int matches = 1;
10727
10728 for (j = 0; j < neon_shape_tab[shape].els; j++)
10729 {
10730 if (!inst.operands[j].present)
10731 {
10732 matches = 0;
10733 break;
10734 }
10735
10736 switch (neon_shape_tab[shape].el[j])
10737 {
10738 case SE_F:
10739 if (!(inst.operands[j].isreg
10740 && inst.operands[j].isvec
10741 && inst.operands[j].issingle
10742 && !inst.operands[j].isquad))
10743 matches = 0;
10744 break;
10745
10746 case SE_D:
10747 if (!(inst.operands[j].isreg
10748 && inst.operands[j].isvec
10749 && !inst.operands[j].isquad
10750 && !inst.operands[j].issingle))
10751 matches = 0;
10752 break;
10753
10754 case SE_R:
10755 if (!(inst.operands[j].isreg
10756 && !inst.operands[j].isvec))
10757 matches = 0;
10758 break;
10759
10760 case SE_Q:
10761 if (!(inst.operands[j].isreg
10762 && inst.operands[j].isvec
10763 && inst.operands[j].isquad
10764 && !inst.operands[j].issingle))
10765 matches = 0;
10766 break;
10767
10768 case SE_I:
10769 if (!(!inst.operands[j].isreg
10770 && !inst.operands[j].isscalar))
10771 matches = 0;
10772 break;
10773
10774 case SE_S:
10775 if (!(!inst.operands[j].isreg
10776 && inst.operands[j].isscalar))
10777 matches = 0;
10778 break;
10779
10780 case SE_L:
10781 break;
10782 }
10783 }
10784 if (matches)
10785 break;
10786 }
10787
10788 va_end (ap);
10789
10790 if (shape == NS_NULL && first_shape != NS_NULL)
10791 first_error (_("invalid instruction shape"));
10792
10793 return shape;
10794 }
10795
10796 /* True if SHAPE is predominantly a quadword operation (most of the time, this
10797 means the Q bit should be set). */
10798
10799 static int
10800 neon_quad (enum neon_shape shape)
10801 {
10802 return neon_shape_class[shape] == SC_QUAD;
10803 }
10804
10805 static void
10806 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
10807 unsigned *g_size)
10808 {
10809 /* Allow modification to be made to types which are constrained to be
10810 based on the key element, based on bits set alongside N_EQK. */
10811 if ((typebits & N_EQK) != 0)
10812 {
10813 if ((typebits & N_HLF) != 0)
10814 *g_size /= 2;
10815 else if ((typebits & N_DBL) != 0)
10816 *g_size *= 2;
10817 if ((typebits & N_SGN) != 0)
10818 *g_type = NT_signed;
10819 else if ((typebits & N_UNS) != 0)
10820 *g_type = NT_unsigned;
10821 else if ((typebits & N_INT) != 0)
10822 *g_type = NT_integer;
10823 else if ((typebits & N_FLT) != 0)
10824 *g_type = NT_float;
10825 else if ((typebits & N_SIZ) != 0)
10826 *g_type = NT_untyped;
10827 }
10828 }
10829
10830 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
10831 operand type, i.e. the single type specified in a Neon instruction when it
10832 is the only one given. */
10833
10834 static struct neon_type_el
10835 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
10836 {
10837 struct neon_type_el dest = *key;
10838
10839 assert ((thisarg & N_EQK) != 0);
10840
10841 neon_modify_type_size (thisarg, &dest.type, &dest.size);
10842
10843 return dest;
10844 }
10845
10846 /* Convert Neon type and size into compact bitmask representation. */
10847
10848 static enum neon_type_mask
10849 type_chk_of_el_type (enum neon_el_type type, unsigned size)
10850 {
10851 switch (type)
10852 {
10853 case NT_untyped:
10854 switch (size)
10855 {
10856 case 8: return N_8;
10857 case 16: return N_16;
10858 case 32: return N_32;
10859 case 64: return N_64;
10860 default: ;
10861 }
10862 break;
10863
10864 case NT_integer:
10865 switch (size)
10866 {
10867 case 8: return N_I8;
10868 case 16: return N_I16;
10869 case 32: return N_I32;
10870 case 64: return N_I64;
10871 default: ;
10872 }
10873 break;
10874
10875 case NT_float:
10876 switch (size)
10877 {
10878 case 32: return N_F32;
10879 case 64: return N_F64;
10880 default: ;
10881 }
10882 break;
10883
10884 case NT_poly:
10885 switch (size)
10886 {
10887 case 8: return N_P8;
10888 case 16: return N_P16;
10889 default: ;
10890 }
10891 break;
10892
10893 case NT_signed:
10894 switch (size)
10895 {
10896 case 8: return N_S8;
10897 case 16: return N_S16;
10898 case 32: return N_S32;
10899 case 64: return N_S64;
10900 default: ;
10901 }
10902 break;
10903
10904 case NT_unsigned:
10905 switch (size)
10906 {
10907 case 8: return N_U8;
10908 case 16: return N_U16;
10909 case 32: return N_U32;
10910 case 64: return N_U64;
10911 default: ;
10912 }
10913 break;
10914
10915 default: ;
10916 }
10917
10918 return N_UTYP;
10919 }
10920
10921 /* Convert compact Neon bitmask type representation to a type and size. Only
10922 handles the case where a single bit is set in the mask. */
10923
10924 static int
10925 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
10926 enum neon_type_mask mask)
10927 {
10928 if ((mask & N_EQK) != 0)
10929 return FAIL;
10930
10931 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
10932 *size = 8;
10933 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
10934 *size = 16;
10935 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
10936 *size = 32;
10937 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
10938 *size = 64;
10939 else
10940 return FAIL;
10941
10942 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
10943 *type = NT_signed;
10944 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
10945 *type = NT_unsigned;
10946 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
10947 *type = NT_integer;
10948 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
10949 *type = NT_untyped;
10950 else if ((mask & (N_P8 | N_P16)) != 0)
10951 *type = NT_poly;
10952 else if ((mask & (N_F32 | N_F64)) != 0)
10953 *type = NT_float;
10954 else
10955 return FAIL;
10956
10957 return SUCCESS;
10958 }
10959
10960 /* Modify a bitmask of allowed types. This is only needed for type
10961 relaxation. */
10962
10963 static unsigned
10964 modify_types_allowed (unsigned allowed, unsigned mods)
10965 {
10966 unsigned size;
10967 enum neon_el_type type;
10968 unsigned destmask;
10969 int i;
10970
10971 destmask = 0;
10972
10973 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
10974 {
10975 if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS)
10976 {
10977 neon_modify_type_size (mods, &type, &size);
10978 destmask |= type_chk_of_el_type (type, size);
10979 }
10980 }
10981
10982 return destmask;
10983 }
10984
10985 /* Check type and return type classification.
10986 The manual states (paraphrase): If one datatype is given, it indicates the
10987 type given in:
10988 - the second operand, if there is one
10989 - the operand, if there is no second operand
10990 - the result, if there are no operands.
10991 This isn't quite good enough though, so we use a concept of a "key" datatype
10992 which is set on a per-instruction basis, which is the one which matters when
10993 only one data type is written.
10994 Note: this function has side-effects (e.g. filling in missing operands). All
10995 Neon instructions should call it before performing bit encoding. */
10996
10997 static struct neon_type_el
10998 neon_check_type (unsigned els, enum neon_shape ns, ...)
10999 {
11000 va_list ap;
11001 unsigned i, pass, key_el = 0;
11002 unsigned types[NEON_MAX_TYPE_ELS];
11003 enum neon_el_type k_type = NT_invtype;
11004 unsigned k_size = -1u;
11005 struct neon_type_el badtype = {NT_invtype, -1};
11006 unsigned key_allowed = 0;
11007
11008 /* Optional registers in Neon instructions are always (not) in operand 1.
11009 Fill in the missing operand here, if it was omitted. */
11010 if (els > 1 && !inst.operands[1].present)
11011 inst.operands[1] = inst.operands[0];
11012
11013 /* Suck up all the varargs. */
11014 va_start (ap, ns);
11015 for (i = 0; i < els; i++)
11016 {
11017 unsigned thisarg = va_arg (ap, unsigned);
11018 if (thisarg == N_IGNORE_TYPE)
11019 {
11020 va_end (ap);
11021 return badtype;
11022 }
11023 types[i] = thisarg;
11024 if ((thisarg & N_KEY) != 0)
11025 key_el = i;
11026 }
11027 va_end (ap);
11028
11029 if (inst.vectype.elems > 0)
11030 for (i = 0; i < els; i++)
11031 if (inst.operands[i].vectype.type != NT_invtype)
11032 {
11033 first_error (_("types specified in both the mnemonic and operands"));
11034 return badtype;
11035 }
11036
11037 /* Duplicate inst.vectype elements here as necessary.
11038 FIXME: No idea if this is exactly the same as the ARM assembler,
11039 particularly when an insn takes one register and one non-register
11040 operand. */
11041 if (inst.vectype.elems == 1 && els > 1)
11042 {
11043 unsigned j;
11044 inst.vectype.elems = els;
11045 inst.vectype.el[key_el] = inst.vectype.el[0];
11046 for (j = 0; j < els; j++)
11047 if (j != key_el)
11048 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11049 types[j]);
11050 }
11051 else if (inst.vectype.elems == 0 && els > 0)
11052 {
11053 unsigned j;
11054 /* No types were given after the mnemonic, so look for types specified
11055 after each operand. We allow some flexibility here; as long as the
11056 "key" operand has a type, we can infer the others. */
11057 for (j = 0; j < els; j++)
11058 if (inst.operands[j].vectype.type != NT_invtype)
11059 inst.vectype.el[j] = inst.operands[j].vectype;
11060
11061 if (inst.operands[key_el].vectype.type != NT_invtype)
11062 {
11063 for (j = 0; j < els; j++)
11064 if (inst.operands[j].vectype.type == NT_invtype)
11065 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11066 types[j]);
11067 }
11068 else
11069 {
11070 first_error (_("operand types can't be inferred"));
11071 return badtype;
11072 }
11073 }
11074 else if (inst.vectype.elems != els)
11075 {
11076 first_error (_("type specifier has the wrong number of parts"));
11077 return badtype;
11078 }
11079
11080 for (pass = 0; pass < 2; pass++)
11081 {
11082 for (i = 0; i < els; i++)
11083 {
11084 unsigned thisarg = types[i];
11085 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
11086 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
11087 enum neon_el_type g_type = inst.vectype.el[i].type;
11088 unsigned g_size = inst.vectype.el[i].size;
11089
11090 /* Decay more-specific signed & unsigned types to sign-insensitive
11091 integer types if sign-specific variants are unavailable. */
11092 if ((g_type == NT_signed || g_type == NT_unsigned)
11093 && (types_allowed & N_SU_ALL) == 0)
11094 g_type = NT_integer;
11095
11096 /* If only untyped args are allowed, decay any more specific types to
11097 them. Some instructions only care about signs for some element
11098 sizes, so handle that properly. */
11099 if ((g_size == 8 && (types_allowed & N_8) != 0)
11100 || (g_size == 16 && (types_allowed & N_16) != 0)
11101 || (g_size == 32 && (types_allowed & N_32) != 0)
11102 || (g_size == 64 && (types_allowed & N_64) != 0))
11103 g_type = NT_untyped;
11104
11105 if (pass == 0)
11106 {
11107 if ((thisarg & N_KEY) != 0)
11108 {
11109 k_type = g_type;
11110 k_size = g_size;
11111 key_allowed = thisarg & ~N_KEY;
11112 }
11113 }
11114 else
11115 {
11116 if ((thisarg & N_VFP) != 0)
11117 {
11118 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
11119 unsigned regwidth = neon_shape_el_size[regshape], match;
11120
11121 /* In VFP mode, operands must match register widths. If we
11122 have a key operand, use its width, else use the width of
11123 the current operand. */
11124 if (k_size != -1u)
11125 match = k_size;
11126 else
11127 match = g_size;
11128
11129 if (regwidth != match)
11130 {
11131 first_error (_("operand size must match register width"));
11132 return badtype;
11133 }
11134 }
11135
11136 if ((thisarg & N_EQK) == 0)
11137 {
11138 unsigned given_type = type_chk_of_el_type (g_type, g_size);
11139
11140 if ((given_type & types_allowed) == 0)
11141 {
11142 first_error (_("bad type in Neon instruction"));
11143 return badtype;
11144 }
11145 }
11146 else
11147 {
11148 enum neon_el_type mod_k_type = k_type;
11149 unsigned mod_k_size = k_size;
11150 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
11151 if (g_type != mod_k_type || g_size != mod_k_size)
11152 {
11153 first_error (_("inconsistent types in Neon instruction"));
11154 return badtype;
11155 }
11156 }
11157 }
11158 }
11159 }
11160
11161 return inst.vectype.el[key_el];
11162 }
11163
11164 /* Neon-style VFP instruction forwarding. */
11165
11166 /* Thumb VFP instructions have 0xE in the condition field. */
11167
11168 static void
11169 do_vfp_cond_or_thumb (void)
11170 {
11171 if (thumb_mode)
11172 inst.instruction |= 0xe0000000;
11173 else
11174 inst.instruction |= inst.cond << 28;
11175 }
11176
11177 /* Look up and encode a simple mnemonic, for use as a helper function for the
11178 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
11179 etc. It is assumed that operand parsing has already been done, and that the
11180 operands are in the form expected by the given opcode (this isn't necessarily
11181 the same as the form in which they were parsed, hence some massaging must
11182 take place before this function is called).
11183 Checks current arch version against that in the looked-up opcode. */
11184
11185 static void
11186 do_vfp_nsyn_opcode (const char *opname)
11187 {
11188 const struct asm_opcode *opcode;
11189
11190 opcode = hash_find (arm_ops_hsh, opname);
11191
11192 if (!opcode)
11193 abort ();
11194
11195 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
11196 thumb_mode ? *opcode->tvariant : *opcode->avariant),
11197 _(BAD_FPU));
11198
11199 if (thumb_mode)
11200 {
11201 inst.instruction = opcode->tvalue;
11202 opcode->tencode ();
11203 }
11204 else
11205 {
11206 inst.instruction = (inst.cond << 28) | opcode->avalue;
11207 opcode->aencode ();
11208 }
11209 }
11210
11211 static void
11212 do_vfp_nsyn_add_sub (enum neon_shape rs)
11213 {
11214 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
11215
11216 if (rs == NS_FFF)
11217 {
11218 if (is_add)
11219 do_vfp_nsyn_opcode ("fadds");
11220 else
11221 do_vfp_nsyn_opcode ("fsubs");
11222 }
11223 else
11224 {
11225 if (is_add)
11226 do_vfp_nsyn_opcode ("faddd");
11227 else
11228 do_vfp_nsyn_opcode ("fsubd");
11229 }
11230 }
11231
11232 /* Check operand types to see if this is a VFP instruction, and if so call
11233 PFN (). */
11234
11235 static int
11236 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
11237 {
11238 enum neon_shape rs;
11239 struct neon_type_el et;
11240
11241 switch (args)
11242 {
11243 case 2:
11244 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11245 et = neon_check_type (2, rs,
11246 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11247 break;
11248
11249 case 3:
11250 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11251 et = neon_check_type (3, rs,
11252 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11253 break;
11254
11255 default:
11256 abort ();
11257 }
11258
11259 if (et.type != NT_invtype)
11260 {
11261 pfn (rs);
11262 return SUCCESS;
11263 }
11264 else
11265 inst.error = NULL;
11266
11267 return FAIL;
11268 }
11269
11270 static void
11271 do_vfp_nsyn_mla_mls (enum neon_shape rs)
11272 {
11273 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
11274
11275 if (rs == NS_FFF)
11276 {
11277 if (is_mla)
11278 do_vfp_nsyn_opcode ("fmacs");
11279 else
11280 do_vfp_nsyn_opcode ("fmscs");
11281 }
11282 else
11283 {
11284 if (is_mla)
11285 do_vfp_nsyn_opcode ("fmacd");
11286 else
11287 do_vfp_nsyn_opcode ("fmscd");
11288 }
11289 }
11290
11291 static void
11292 do_vfp_nsyn_mul (enum neon_shape rs)
11293 {
11294 if (rs == NS_FFF)
11295 do_vfp_nsyn_opcode ("fmuls");
11296 else
11297 do_vfp_nsyn_opcode ("fmuld");
11298 }
11299
11300 static void
11301 do_vfp_nsyn_abs_neg (enum neon_shape rs)
11302 {
11303 int is_neg = (inst.instruction & 0x80) != 0;
11304 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
11305
11306 if (rs == NS_FF)
11307 {
11308 if (is_neg)
11309 do_vfp_nsyn_opcode ("fnegs");
11310 else
11311 do_vfp_nsyn_opcode ("fabss");
11312 }
11313 else
11314 {
11315 if (is_neg)
11316 do_vfp_nsyn_opcode ("fnegd");
11317 else
11318 do_vfp_nsyn_opcode ("fabsd");
11319 }
11320 }
11321
11322 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
11323 insns belong to Neon, and are handled elsewhere. */
11324
11325 static void
11326 do_vfp_nsyn_ldm_stm (int is_dbmode)
11327 {
11328 int is_ldm = (inst.instruction & (1 << 20)) != 0;
11329 if (is_ldm)
11330 {
11331 if (is_dbmode)
11332 do_vfp_nsyn_opcode ("fldmdbs");
11333 else
11334 do_vfp_nsyn_opcode ("fldmias");
11335 }
11336 else
11337 {
11338 if (is_dbmode)
11339 do_vfp_nsyn_opcode ("fstmdbs");
11340 else
11341 do_vfp_nsyn_opcode ("fstmias");
11342 }
11343 }
11344
11345 static void
11346 do_vfp_nsyn_sqrt (void)
11347 {
11348 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11349 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11350
11351 if (rs == NS_FF)
11352 do_vfp_nsyn_opcode ("fsqrts");
11353 else
11354 do_vfp_nsyn_opcode ("fsqrtd");
11355 }
11356
11357 static void
11358 do_vfp_nsyn_div (void)
11359 {
11360 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11361 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11362 N_F32 | N_F64 | N_KEY | N_VFP);
11363
11364 if (rs == NS_FFF)
11365 do_vfp_nsyn_opcode ("fdivs");
11366 else
11367 do_vfp_nsyn_opcode ("fdivd");
11368 }
11369
11370 static void
11371 do_vfp_nsyn_nmul (void)
11372 {
11373 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11374 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11375 N_F32 | N_F64 | N_KEY | N_VFP);
11376
11377 if (rs == NS_FFF)
11378 {
11379 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11380 do_vfp_sp_dyadic ();
11381 }
11382 else
11383 {
11384 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11385 do_vfp_dp_rd_rn_rm ();
11386 }
11387 do_vfp_cond_or_thumb ();
11388 }
11389
11390 static void
11391 do_vfp_nsyn_cmp (void)
11392 {
11393 if (inst.operands[1].isreg)
11394 {
11395 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11396 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11397
11398 if (rs == NS_FF)
11399 {
11400 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11401 do_vfp_sp_monadic ();
11402 }
11403 else
11404 {
11405 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11406 do_vfp_dp_rd_rm ();
11407 }
11408 }
11409 else
11410 {
11411 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
11412 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
11413
11414 switch (inst.instruction & 0x0fffffff)
11415 {
11416 case N_MNEM_vcmp:
11417 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
11418 break;
11419 case N_MNEM_vcmpe:
11420 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
11421 break;
11422 default:
11423 abort ();
11424 }
11425
11426 if (rs == NS_FI)
11427 {
11428 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11429 do_vfp_sp_compare_z ();
11430 }
11431 else
11432 {
11433 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11434 do_vfp_dp_rd ();
11435 }
11436 }
11437 do_vfp_cond_or_thumb ();
11438 }
11439
11440 static void
11441 nsyn_insert_sp (void)
11442 {
11443 inst.operands[1] = inst.operands[0];
11444 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
11445 inst.operands[0].reg = 13;
11446 inst.operands[0].isreg = 1;
11447 inst.operands[0].writeback = 1;
11448 inst.operands[0].present = 1;
11449 }
11450
11451 static void
11452 do_vfp_nsyn_push (void)
11453 {
11454 nsyn_insert_sp ();
11455 if (inst.operands[1].issingle)
11456 do_vfp_nsyn_opcode ("fstmdbs");
11457 else
11458 do_vfp_nsyn_opcode ("fstmdbd");
11459 }
11460
11461 static void
11462 do_vfp_nsyn_pop (void)
11463 {
11464 nsyn_insert_sp ();
11465 if (inst.operands[1].issingle)
11466 do_vfp_nsyn_opcode ("fldmias");
11467 else
11468 do_vfp_nsyn_opcode ("fldmiad");
11469 }
11470
11471 /* Fix up Neon data-processing instructions, ORing in the correct bits for
11472 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
11473
11474 static unsigned
11475 neon_dp_fixup (unsigned i)
11476 {
11477 if (thumb_mode)
11478 {
11479 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
11480 if (i & (1 << 24))
11481 i |= 1 << 28;
11482
11483 i &= ~(1 << 24);
11484
11485 i |= 0xef000000;
11486 }
11487 else
11488 i |= 0xf2000000;
11489
11490 return i;
11491 }
11492
11493 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
11494 (0, 1, 2, 3). */
11495
11496 static unsigned
11497 neon_logbits (unsigned x)
11498 {
11499 return ffs (x) - 4;
11500 }
11501
11502 #define LOW4(R) ((R) & 0xf)
11503 #define HI1(R) (((R) >> 4) & 1)
11504
11505 /* Encode insns with bit pattern:
11506
11507 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
11508 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
11509
11510 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
11511 different meaning for some instruction. */
11512
11513 static void
11514 neon_three_same (int isquad, int ubit, int size)
11515 {
11516 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11517 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11518 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
11519 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
11520 inst.instruction |= LOW4 (inst.operands[2].reg);
11521 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
11522 inst.instruction |= (isquad != 0) << 6;
11523 inst.instruction |= (ubit != 0) << 24;
11524 if (size != -1)
11525 inst.instruction |= neon_logbits (size) << 20;
11526
11527 inst.instruction = neon_dp_fixup (inst.instruction);
11528 }
11529
11530 /* Encode instructions of the form:
11531
11532 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
11533 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
11534
11535 Don't write size if SIZE == -1. */
11536
11537 static void
11538 neon_two_same (int qbit, int ubit, int size)
11539 {
11540 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11541 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11542 inst.instruction |= LOW4 (inst.operands[1].reg);
11543 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11544 inst.instruction |= (qbit != 0) << 6;
11545 inst.instruction |= (ubit != 0) << 24;
11546
11547 if (size != -1)
11548 inst.instruction |= neon_logbits (size) << 18;
11549
11550 inst.instruction = neon_dp_fixup (inst.instruction);
11551 }
11552
11553 /* Neon instruction encoders, in approximate order of appearance. */
11554
11555 static void
11556 do_neon_dyadic_i_su (void)
11557 {
11558 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11559 struct neon_type_el et = neon_check_type (3, rs,
11560 N_EQK, N_EQK, N_SU_32 | N_KEY);
11561 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11562 }
11563
11564 static void
11565 do_neon_dyadic_i64_su (void)
11566 {
11567 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11568 struct neon_type_el et = neon_check_type (3, rs,
11569 N_EQK, N_EQK, N_SU_ALL | N_KEY);
11570 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11571 }
11572
11573 static void
11574 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
11575 unsigned immbits)
11576 {
11577 unsigned size = et.size >> 3;
11578 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11579 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11580 inst.instruction |= LOW4 (inst.operands[1].reg);
11581 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11582 inst.instruction |= (isquad != 0) << 6;
11583 inst.instruction |= immbits << 16;
11584 inst.instruction |= (size >> 3) << 7;
11585 inst.instruction |= (size & 0x7) << 19;
11586 if (write_ubit)
11587 inst.instruction |= (uval != 0) << 24;
11588
11589 inst.instruction = neon_dp_fixup (inst.instruction);
11590 }
11591
11592 static void
11593 do_neon_shl_imm (void)
11594 {
11595 if (!inst.operands[2].isreg)
11596 {
11597 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11598 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
11599 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11600 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
11601 }
11602 else
11603 {
11604 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11605 struct neon_type_el et = neon_check_type (3, rs,
11606 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
11607 unsigned int tmp;
11608
11609 /* VSHL/VQSHL 3-register variants have syntax such as:
11610 vshl.xx Dd, Dm, Dn
11611 whereas other 3-register operations encoded by neon_three_same have
11612 syntax like:
11613 vadd.xx Dd, Dn, Dm
11614 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
11615 here. */
11616 tmp = inst.operands[2].reg;
11617 inst.operands[2].reg = inst.operands[1].reg;
11618 inst.operands[1].reg = tmp;
11619 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11620 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11621 }
11622 }
11623
11624 static void
11625 do_neon_qshl_imm (void)
11626 {
11627 if (!inst.operands[2].isreg)
11628 {
11629 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11630 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
11631
11632 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11633 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
11634 inst.operands[2].imm);
11635 }
11636 else
11637 {
11638 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11639 struct neon_type_el et = neon_check_type (3, rs,
11640 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
11641 unsigned int tmp;
11642
11643 /* See note in do_neon_shl_imm. */
11644 tmp = inst.operands[2].reg;
11645 inst.operands[2].reg = inst.operands[1].reg;
11646 inst.operands[1].reg = tmp;
11647 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11648 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11649 }
11650 }
11651
11652 static void
11653 do_neon_rshl (void)
11654 {
11655 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11656 struct neon_type_el et = neon_check_type (3, rs,
11657 N_EQK, N_EQK, N_SU_ALL | N_KEY);
11658 unsigned int tmp;
11659
11660 tmp = inst.operands[2].reg;
11661 inst.operands[2].reg = inst.operands[1].reg;
11662 inst.operands[1].reg = tmp;
11663 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11664 }
11665
11666 static int
11667 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
11668 {
11669 /* Handle .I8 pseudo-instructions. */
11670 if (size == 8)
11671 {
11672 /* Unfortunately, this will make everything apart from zero out-of-range.
11673 FIXME is this the intended semantics? There doesn't seem much point in
11674 accepting .I8 if so. */
11675 immediate |= immediate << 8;
11676 size = 16;
11677 }
11678
11679 if (size >= 32)
11680 {
11681 if (immediate == (immediate & 0x000000ff))
11682 {
11683 *immbits = immediate;
11684 return 0x1;
11685 }
11686 else if (immediate == (immediate & 0x0000ff00))
11687 {
11688 *immbits = immediate >> 8;
11689 return 0x3;
11690 }
11691 else if (immediate == (immediate & 0x00ff0000))
11692 {
11693 *immbits = immediate >> 16;
11694 return 0x5;
11695 }
11696 else if (immediate == (immediate & 0xff000000))
11697 {
11698 *immbits = immediate >> 24;
11699 return 0x7;
11700 }
11701 if ((immediate & 0xffff) != (immediate >> 16))
11702 goto bad_immediate;
11703 immediate &= 0xffff;
11704 }
11705
11706 if (immediate == (immediate & 0x000000ff))
11707 {
11708 *immbits = immediate;
11709 return 0x9;
11710 }
11711 else if (immediate == (immediate & 0x0000ff00))
11712 {
11713 *immbits = immediate >> 8;
11714 return 0xb;
11715 }
11716
11717 bad_immediate:
11718 first_error (_("immediate value out of range"));
11719 return FAIL;
11720 }
11721
11722 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
11723 A, B, C, D. */
11724
11725 static int
11726 neon_bits_same_in_bytes (unsigned imm)
11727 {
11728 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
11729 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
11730 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
11731 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
11732 }
11733
11734 /* For immediate of above form, return 0bABCD. */
11735
11736 static unsigned
11737 neon_squash_bits (unsigned imm)
11738 {
11739 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
11740 | ((imm & 0x01000000) >> 21);
11741 }
11742
11743 /* Compress quarter-float representation to 0b...000 abcdefgh. */
11744
11745 static unsigned
11746 neon_qfloat_bits (unsigned imm)
11747 {
11748 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
11749 }
11750
11751 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
11752 the instruction. *OP is passed as the initial value of the op field, and
11753 may be set to a different value depending on the constant (i.e.
11754 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
11755 MVN). If the immediate looks like a repeated parttern then also
11756 try smaller element sizes. */
11757
11758 static int
11759 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
11760 unsigned *immbits, int *op, int size,
11761 enum neon_el_type type)
11762 {
11763 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
11764 float. */
11765 if (type == NT_float && !float_p)
11766 return FAIL;
11767
11768 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
11769 {
11770 if (size != 32 || *op == 1)
11771 return FAIL;
11772 *immbits = neon_qfloat_bits (immlo);
11773 return 0xf;
11774 }
11775
11776 if (size == 64)
11777 {
11778 if (neon_bits_same_in_bytes (immhi)
11779 && neon_bits_same_in_bytes (immlo))
11780 {
11781 if (*op == 1)
11782 return FAIL;
11783 *immbits = (neon_squash_bits (immhi) << 4)
11784 | neon_squash_bits (immlo);
11785 *op = 1;
11786 return 0xe;
11787 }
11788
11789 if (immhi != immlo)
11790 return FAIL;
11791 }
11792
11793 if (size >= 32)
11794 {
11795 if (immlo == (immlo & 0x000000ff))
11796 {
11797 *immbits = immlo;
11798 return 0x0;
11799 }
11800 else if (immlo == (immlo & 0x0000ff00))
11801 {
11802 *immbits = immlo >> 8;
11803 return 0x2;
11804 }
11805 else if (immlo == (immlo & 0x00ff0000))
11806 {
11807 *immbits = immlo >> 16;
11808 return 0x4;
11809 }
11810 else if (immlo == (immlo & 0xff000000))
11811 {
11812 *immbits = immlo >> 24;
11813 return 0x6;
11814 }
11815 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
11816 {
11817 *immbits = (immlo >> 8) & 0xff;
11818 return 0xc;
11819 }
11820 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
11821 {
11822 *immbits = (immlo >> 16) & 0xff;
11823 return 0xd;
11824 }
11825
11826 if ((immlo & 0xffff) != (immlo >> 16))
11827 return FAIL;
11828 immlo &= 0xffff;
11829 }
11830
11831 if (size >= 16)
11832 {
11833 if (immlo == (immlo & 0x000000ff))
11834 {
11835 *immbits = immlo;
11836 return 0x8;
11837 }
11838 else if (immlo == (immlo & 0x0000ff00))
11839 {
11840 *immbits = immlo >> 8;
11841 return 0xa;
11842 }
11843
11844 if ((immlo & 0xff) != (immlo >> 8))
11845 return FAIL;
11846 immlo &= 0xff;
11847 }
11848
11849 if (immlo == (immlo & 0x000000ff))
11850 {
11851 /* Don't allow MVN with 8-bit immediate. */
11852 if (*op == 1)
11853 return FAIL;
11854 *immbits = immlo;
11855 return 0xe;
11856 }
11857
11858 return FAIL;
11859 }
11860
11861 /* Write immediate bits [7:0] to the following locations:
11862
11863 |28/24|23 19|18 16|15 4|3 0|
11864 | 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|
11865
11866 This function is used by VMOV/VMVN/VORR/VBIC. */
11867
11868 static void
11869 neon_write_immbits (unsigned immbits)
11870 {
11871 inst.instruction |= immbits & 0xf;
11872 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
11873 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
11874 }
11875
11876 /* Invert low-order SIZE bits of XHI:XLO. */
11877
11878 static void
11879 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
11880 {
11881 unsigned immlo = xlo ? *xlo : 0;
11882 unsigned immhi = xhi ? *xhi : 0;
11883
11884 switch (size)
11885 {
11886 case 8:
11887 immlo = (~immlo) & 0xff;
11888 break;
11889
11890 case 16:
11891 immlo = (~immlo) & 0xffff;
11892 break;
11893
11894 case 64:
11895 immhi = (~immhi) & 0xffffffff;
11896 /* fall through. */
11897
11898 case 32:
11899 immlo = (~immlo) & 0xffffffff;
11900 break;
11901
11902 default:
11903 abort ();
11904 }
11905
11906 if (xlo)
11907 *xlo = immlo;
11908
11909 if (xhi)
11910 *xhi = immhi;
11911 }
11912
11913 static void
11914 do_neon_logic (void)
11915 {
11916 if (inst.operands[2].present && inst.operands[2].isreg)
11917 {
11918 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11919 neon_check_type (3, rs, N_IGNORE_TYPE);
11920 /* U bit and size field were set as part of the bitmask. */
11921 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11922 neon_three_same (neon_quad (rs), 0, -1);
11923 }
11924 else
11925 {
11926 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
11927 struct neon_type_el et = neon_check_type (2, rs,
11928 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
11929 enum neon_opc opcode = inst.instruction & 0x0fffffff;
11930 unsigned immbits;
11931 int cmode;
11932
11933 if (et.type == NT_invtype)
11934 return;
11935
11936 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11937
11938 immbits = inst.operands[1].imm;
11939 if (et.size == 64)
11940 {
11941 /* .i64 is a pseudo-op, so the immediate must be a repeating
11942 pattern. */
11943 if (immbits != (inst.operands[1].regisimm ?
11944 inst.operands[1].reg : 0))
11945 {
11946 /* Set immbits to an invalid constant. */
11947 immbits = 0xdeadbeef;
11948 }
11949 }
11950
11951 switch (opcode)
11952 {
11953 case N_MNEM_vbic:
11954 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11955 break;
11956
11957 case N_MNEM_vorr:
11958 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11959 break;
11960
11961 case N_MNEM_vand:
11962 /* Pseudo-instruction for VBIC. */
11963 neon_invert_size (&immbits, 0, et.size);
11964 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11965 break;
11966
11967 case N_MNEM_vorn:
11968 /* Pseudo-instruction for VORR. */
11969 neon_invert_size (&immbits, 0, et.size);
11970 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11971 break;
11972
11973 default:
11974 abort ();
11975 }
11976
11977 if (cmode == FAIL)
11978 return;
11979
11980 inst.instruction |= neon_quad (rs) << 6;
11981 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11982 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11983 inst.instruction |= cmode << 8;
11984 neon_write_immbits (immbits);
11985
11986 inst.instruction = neon_dp_fixup (inst.instruction);
11987 }
11988 }
11989
11990 static void
11991 do_neon_bitfield (void)
11992 {
11993 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11994 neon_check_type (3, rs, N_IGNORE_TYPE);
11995 neon_three_same (neon_quad (rs), 0, -1);
11996 }
11997
11998 static void
11999 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
12000 unsigned destbits)
12001 {
12002 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12003 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
12004 types | N_KEY);
12005 if (et.type == NT_float)
12006 {
12007 inst.instruction = NEON_ENC_FLOAT (inst.instruction);
12008 neon_three_same (neon_quad (rs), 0, -1);
12009 }
12010 else
12011 {
12012 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12013 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
12014 }
12015 }
12016
12017 static void
12018 do_neon_dyadic_if_su (void)
12019 {
12020 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
12021 }
12022
12023 static void
12024 do_neon_dyadic_if_su_d (void)
12025 {
12026 /* This version only allow D registers, but that constraint is enforced during
12027 operand parsing so we don't need to do anything extra here. */
12028 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
12029 }
12030
12031 static void
12032 do_neon_dyadic_if_i_d (void)
12033 {
12034 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12035 affected if we specify unsigned args. */
12036 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12037 }
12038
12039 enum vfp_or_neon_is_neon_bits
12040 {
12041 NEON_CHECK_CC = 1,
12042 NEON_CHECK_ARCH = 2
12043 };
12044
12045 /* Call this function if an instruction which may have belonged to the VFP or
12046 Neon instruction sets, but turned out to be a Neon instruction (due to the
12047 operand types involved, etc.). We have to check and/or fix-up a couple of
12048 things:
12049
12050 - Make sure the user hasn't attempted to make a Neon instruction
12051 conditional.
12052 - Alter the value in the condition code field if necessary.
12053 - Make sure that the arch supports Neon instructions.
12054
12055 Which of these operations take place depends on bits from enum
12056 vfp_or_neon_is_neon_bits.
12057
12058 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
12059 current instruction's condition is COND_ALWAYS, the condition field is
12060 changed to inst.uncond_value. This is necessary because instructions shared
12061 between VFP and Neon may be conditional for the VFP variants only, and the
12062 unconditional Neon version must have, e.g., 0xF in the condition field. */
12063
12064 static int
12065 vfp_or_neon_is_neon (unsigned check)
12066 {
12067 /* Conditions are always legal in Thumb mode (IT blocks). */
12068 if (!thumb_mode && (check & NEON_CHECK_CC))
12069 {
12070 if (inst.cond != COND_ALWAYS)
12071 {
12072 first_error (_(BAD_COND));
12073 return FAIL;
12074 }
12075 if (inst.uncond_value != -1)
12076 inst.instruction |= inst.uncond_value << 28;
12077 }
12078
12079 if ((check & NEON_CHECK_ARCH)
12080 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
12081 {
12082 first_error (_(BAD_FPU));
12083 return FAIL;
12084 }
12085
12086 return SUCCESS;
12087 }
12088
12089 static void
12090 do_neon_addsub_if_i (void)
12091 {
12092 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
12093 return;
12094
12095 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12096 return;
12097
12098 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12099 affected if we specify unsigned args. */
12100 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
12101 }
12102
12103 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
12104 result to be:
12105 V<op> A,B (A is operand 0, B is operand 2)
12106 to mean:
12107 V<op> A,B,A
12108 not:
12109 V<op> A,B,B
12110 so handle that case specially. */
12111
12112 static void
12113 neon_exchange_operands (void)
12114 {
12115 void *scratch = alloca (sizeof (inst.operands[0]));
12116 if (inst.operands[1].present)
12117 {
12118 /* Swap operands[1] and operands[2]. */
12119 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
12120 inst.operands[1] = inst.operands[2];
12121 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
12122 }
12123 else
12124 {
12125 inst.operands[1] = inst.operands[2];
12126 inst.operands[2] = inst.operands[0];
12127 }
12128 }
12129
12130 static void
12131 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
12132 {
12133 if (inst.operands[2].isreg)
12134 {
12135 if (invert)
12136 neon_exchange_operands ();
12137 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
12138 }
12139 else
12140 {
12141 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12142 struct neon_type_el et = neon_check_type (2, rs,
12143 N_EQK | N_SIZ, immtypes | N_KEY);
12144
12145 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12146 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12147 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12148 inst.instruction |= LOW4 (inst.operands[1].reg);
12149 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12150 inst.instruction |= neon_quad (rs) << 6;
12151 inst.instruction |= (et.type == NT_float) << 10;
12152 inst.instruction |= neon_logbits (et.size) << 18;
12153
12154 inst.instruction = neon_dp_fixup (inst.instruction);
12155 }
12156 }
12157
12158 static void
12159 do_neon_cmp (void)
12160 {
12161 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
12162 }
12163
12164 static void
12165 do_neon_cmp_inv (void)
12166 {
12167 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
12168 }
12169
12170 static void
12171 do_neon_ceq (void)
12172 {
12173 neon_compare (N_IF_32, N_IF_32, FALSE);
12174 }
12175
12176 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
12177 scalars, which are encoded in 5 bits, M : Rm.
12178 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
12179 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
12180 index in M. */
12181
12182 static unsigned
12183 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
12184 {
12185 unsigned regno = NEON_SCALAR_REG (scalar);
12186 unsigned elno = NEON_SCALAR_INDEX (scalar);
12187
12188 switch (elsize)
12189 {
12190 case 16:
12191 if (regno > 7 || elno > 3)
12192 goto bad_scalar;
12193 return regno | (elno << 3);
12194
12195 case 32:
12196 if (regno > 15 || elno > 1)
12197 goto bad_scalar;
12198 return regno | (elno << 4);
12199
12200 default:
12201 bad_scalar:
12202 first_error (_("scalar out of range for multiply instruction"));
12203 }
12204
12205 return 0;
12206 }
12207
12208 /* Encode multiply / multiply-accumulate scalar instructions. */
12209
12210 static void
12211 neon_mul_mac (struct neon_type_el et, int ubit)
12212 {
12213 unsigned scalar;
12214
12215 /* Give a more helpful error message if we have an invalid type. */
12216 if (et.type == NT_invtype)
12217 return;
12218
12219 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
12220 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12221 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12222 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12223 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12224 inst.instruction |= LOW4 (scalar);
12225 inst.instruction |= HI1 (scalar) << 5;
12226 inst.instruction |= (et.type == NT_float) << 8;
12227 inst.instruction |= neon_logbits (et.size) << 20;
12228 inst.instruction |= (ubit != 0) << 24;
12229
12230 inst.instruction = neon_dp_fixup (inst.instruction);
12231 }
12232
12233 static void
12234 do_neon_mac_maybe_scalar (void)
12235 {
12236 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
12237 return;
12238
12239 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12240 return;
12241
12242 if (inst.operands[2].isscalar)
12243 {
12244 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
12245 struct neon_type_el et = neon_check_type (3, rs,
12246 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
12247 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12248 neon_mul_mac (et, neon_quad (rs));
12249 }
12250 else
12251 {
12252 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12253 affected if we specify unsigned args. */
12254 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12255 }
12256 }
12257
12258 static void
12259 do_neon_tst (void)
12260 {
12261 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12262 struct neon_type_el et = neon_check_type (3, rs,
12263 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
12264 neon_three_same (neon_quad (rs), 0, et.size);
12265 }
12266
12267 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
12268 same types as the MAC equivalents. The polynomial type for this instruction
12269 is encoded the same as the integer type. */
12270
12271 static void
12272 do_neon_mul (void)
12273 {
12274 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
12275 return;
12276
12277 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12278 return;
12279
12280 if (inst.operands[2].isscalar)
12281 do_neon_mac_maybe_scalar ();
12282 else
12283 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
12284 }
12285
12286 static void
12287 do_neon_qdmulh (void)
12288 {
12289 if (inst.operands[2].isscalar)
12290 {
12291 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
12292 struct neon_type_el et = neon_check_type (3, rs,
12293 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12294 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12295 neon_mul_mac (et, neon_quad (rs));
12296 }
12297 else
12298 {
12299 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12300 struct neon_type_el et = neon_check_type (3, rs,
12301 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12302 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12303 /* The U bit (rounding) comes from bit mask. */
12304 neon_three_same (neon_quad (rs), 0, et.size);
12305 }
12306 }
12307
12308 static void
12309 do_neon_fcmp_absolute (void)
12310 {
12311 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12312 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12313 /* Size field comes from bit mask. */
12314 neon_three_same (neon_quad (rs), 1, -1);
12315 }
12316
12317 static void
12318 do_neon_fcmp_absolute_inv (void)
12319 {
12320 neon_exchange_operands ();
12321 do_neon_fcmp_absolute ();
12322 }
12323
12324 static void
12325 do_neon_step (void)
12326 {
12327 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12328 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12329 neon_three_same (neon_quad (rs), 0, -1);
12330 }
12331
12332 static void
12333 do_neon_abs_neg (void)
12334 {
12335 enum neon_shape rs;
12336 struct neon_type_el et;
12337
12338 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
12339 return;
12340
12341 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12342 return;
12343
12344 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12345 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
12346
12347 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12348 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12349 inst.instruction |= LOW4 (inst.operands[1].reg);
12350 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12351 inst.instruction |= neon_quad (rs) << 6;
12352 inst.instruction |= (et.type == NT_float) << 10;
12353 inst.instruction |= neon_logbits (et.size) << 18;
12354
12355 inst.instruction = neon_dp_fixup (inst.instruction);
12356 }
12357
12358 static void
12359 do_neon_sli (void)
12360 {
12361 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12362 struct neon_type_el et = neon_check_type (2, rs,
12363 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12364 int imm = inst.operands[2].imm;
12365 constraint (imm < 0 || (unsigned)imm >= et.size,
12366 _("immediate out of range for insert"));
12367 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
12368 }
12369
12370 static void
12371 do_neon_sri (void)
12372 {
12373 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12374 struct neon_type_el et = neon_check_type (2, rs,
12375 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12376 int imm = inst.operands[2].imm;
12377 constraint (imm < 1 || (unsigned)imm > et.size,
12378 _("immediate out of range for insert"));
12379 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
12380 }
12381
12382 static void
12383 do_neon_qshlu_imm (void)
12384 {
12385 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12386 struct neon_type_el et = neon_check_type (2, rs,
12387 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
12388 int imm = inst.operands[2].imm;
12389 constraint (imm < 0 || (unsigned)imm >= et.size,
12390 _("immediate out of range for shift"));
12391 /* Only encodes the 'U present' variant of the instruction.
12392 In this case, signed types have OP (bit 8) set to 0.
12393 Unsigned types have OP set to 1. */
12394 inst.instruction |= (et.type == NT_unsigned) << 8;
12395 /* The rest of the bits are the same as other immediate shifts. */
12396 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
12397 }
12398
12399 static void
12400 do_neon_qmovn (void)
12401 {
12402 struct neon_type_el et = neon_check_type (2, NS_DQ,
12403 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12404 /* Saturating move where operands can be signed or unsigned, and the
12405 destination has the same signedness. */
12406 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12407 if (et.type == NT_unsigned)
12408 inst.instruction |= 0xc0;
12409 else
12410 inst.instruction |= 0x80;
12411 neon_two_same (0, 1, et.size / 2);
12412 }
12413
12414 static void
12415 do_neon_qmovun (void)
12416 {
12417 struct neon_type_el et = neon_check_type (2, NS_DQ,
12418 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12419 /* Saturating move with unsigned results. Operands must be signed. */
12420 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12421 neon_two_same (0, 1, et.size / 2);
12422 }
12423
12424 static void
12425 do_neon_rshift_sat_narrow (void)
12426 {
12427 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12428 or unsigned. If operands are unsigned, results must also be unsigned. */
12429 struct neon_type_el et = neon_check_type (2, NS_DQI,
12430 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12431 int imm = inst.operands[2].imm;
12432 /* This gets the bounds check, size encoding and immediate bits calculation
12433 right. */
12434 et.size /= 2;
12435
12436 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
12437 VQMOVN.I<size> <Dd>, <Qm>. */
12438 if (imm == 0)
12439 {
12440 inst.operands[2].present = 0;
12441 inst.instruction = N_MNEM_vqmovn;
12442 do_neon_qmovn ();
12443 return;
12444 }
12445
12446 constraint (imm < 1 || (unsigned)imm > et.size,
12447 _("immediate out of range"));
12448 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
12449 }
12450
12451 static void
12452 do_neon_rshift_sat_narrow_u (void)
12453 {
12454 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12455 or unsigned. If operands are unsigned, results must also be unsigned. */
12456 struct neon_type_el et = neon_check_type (2, NS_DQI,
12457 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12458 int imm = inst.operands[2].imm;
12459 /* This gets the bounds check, size encoding and immediate bits calculation
12460 right. */
12461 et.size /= 2;
12462
12463 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
12464 VQMOVUN.I<size> <Dd>, <Qm>. */
12465 if (imm == 0)
12466 {
12467 inst.operands[2].present = 0;
12468 inst.instruction = N_MNEM_vqmovun;
12469 do_neon_qmovun ();
12470 return;
12471 }
12472
12473 constraint (imm < 1 || (unsigned)imm > et.size,
12474 _("immediate out of range"));
12475 /* FIXME: The manual is kind of unclear about what value U should have in
12476 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
12477 must be 1. */
12478 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
12479 }
12480
12481 static void
12482 do_neon_movn (void)
12483 {
12484 struct neon_type_el et = neon_check_type (2, NS_DQ,
12485 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12486 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12487 neon_two_same (0, 1, et.size / 2);
12488 }
12489
12490 static void
12491 do_neon_rshift_narrow (void)
12492 {
12493 struct neon_type_el et = neon_check_type (2, NS_DQI,
12494 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12495 int imm = inst.operands[2].imm;
12496 /* This gets the bounds check, size encoding and immediate bits calculation
12497 right. */
12498 et.size /= 2;
12499
12500 /* If immediate is zero then we are a pseudo-instruction for
12501 VMOVN.I<size> <Dd>, <Qm> */
12502 if (imm == 0)
12503 {
12504 inst.operands[2].present = 0;
12505 inst.instruction = N_MNEM_vmovn;
12506 do_neon_movn ();
12507 return;
12508 }
12509
12510 constraint (imm < 1 || (unsigned)imm > et.size,
12511 _("immediate out of range for narrowing operation"));
12512 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
12513 }
12514
12515 static void
12516 do_neon_shll (void)
12517 {
12518 /* FIXME: Type checking when lengthening. */
12519 struct neon_type_el et = neon_check_type (2, NS_QDI,
12520 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
12521 unsigned imm = inst.operands[2].imm;
12522
12523 if (imm == et.size)
12524 {
12525 /* Maximum shift variant. */
12526 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12527 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12528 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12529 inst.instruction |= LOW4 (inst.operands[1].reg);
12530 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12531 inst.instruction |= neon_logbits (et.size) << 18;
12532
12533 inst.instruction = neon_dp_fixup (inst.instruction);
12534 }
12535 else
12536 {
12537 /* A more-specific type check for non-max versions. */
12538 et = neon_check_type (2, NS_QDI,
12539 N_EQK | N_DBL, N_SU_32 | N_KEY);
12540 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12541 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
12542 }
12543 }
12544
12545 /* Check the various types for the VCVT instruction, and return which version
12546 the current instruction is. */
12547
12548 static int
12549 neon_cvt_flavour (enum neon_shape rs)
12550 {
12551 #define CVT_VAR(C,X,Y) \
12552 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
12553 if (et.type != NT_invtype) \
12554 { \
12555 inst.error = NULL; \
12556 return (C); \
12557 }
12558 struct neon_type_el et;
12559 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
12560 || rs == NS_FF) ? N_VFP : 0;
12561 /* The instruction versions which take an immediate take one register
12562 argument, which is extended to the width of the full register. Thus the
12563 "source" and "destination" registers must have the same width. Hack that
12564 here by making the size equal to the key (wider, in this case) operand. */
12565 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
12566
12567 CVT_VAR (0, N_S32, N_F32);
12568 CVT_VAR (1, N_U32, N_F32);
12569 CVT_VAR (2, N_F32, N_S32);
12570 CVT_VAR (3, N_F32, N_U32);
12571
12572 whole_reg = N_VFP;
12573
12574 /* VFP instructions. */
12575 CVT_VAR (4, N_F32, N_F64);
12576 CVT_VAR (5, N_F64, N_F32);
12577 CVT_VAR (6, N_S32, N_F64 | key);
12578 CVT_VAR (7, N_U32, N_F64 | key);
12579 CVT_VAR (8, N_F64 | key, N_S32);
12580 CVT_VAR (9, N_F64 | key, N_U32);
12581 /* VFP instructions with bitshift. */
12582 CVT_VAR (10, N_F32 | key, N_S16);
12583 CVT_VAR (11, N_F32 | key, N_U16);
12584 CVT_VAR (12, N_F64 | key, N_S16);
12585 CVT_VAR (13, N_F64 | key, N_U16);
12586 CVT_VAR (14, N_S16, N_F32 | key);
12587 CVT_VAR (15, N_U16, N_F32 | key);
12588 CVT_VAR (16, N_S16, N_F64 | key);
12589 CVT_VAR (17, N_U16, N_F64 | key);
12590
12591 return -1;
12592 #undef CVT_VAR
12593 }
12594
12595 /* Neon-syntax VFP conversions. */
12596
12597 static void
12598 do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
12599 {
12600 const char *opname = 0;
12601
12602 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
12603 {
12604 /* Conversions with immediate bitshift. */
12605 const char *enc[] =
12606 {
12607 "ftosls",
12608 "ftouls",
12609 "fsltos",
12610 "fultos",
12611 NULL,
12612 NULL,
12613 "ftosld",
12614 "ftould",
12615 "fsltod",
12616 "fultod",
12617 "fshtos",
12618 "fuhtos",
12619 "fshtod",
12620 "fuhtod",
12621 "ftoshs",
12622 "ftouhs",
12623 "ftoshd",
12624 "ftouhd"
12625 };
12626
12627 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12628 {
12629 opname = enc[flavour];
12630 constraint (inst.operands[0].reg != inst.operands[1].reg,
12631 _("operands 0 and 1 must be the same register"));
12632 inst.operands[1] = inst.operands[2];
12633 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
12634 }
12635 }
12636 else
12637 {
12638 /* Conversions without bitshift. */
12639 const char *enc[] =
12640 {
12641 "ftosis",
12642 "ftouis",
12643 "fsitos",
12644 "fuitos",
12645 "fcvtsd",
12646 "fcvtds",
12647 "ftosid",
12648 "ftouid",
12649 "fsitod",
12650 "fuitod"
12651 };
12652
12653 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12654 opname = enc[flavour];
12655 }
12656
12657 if (opname)
12658 do_vfp_nsyn_opcode (opname);
12659 }
12660
12661 static void
12662 do_vfp_nsyn_cvtz (void)
12663 {
12664 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
12665 int flavour = neon_cvt_flavour (rs);
12666 const char *enc[] =
12667 {
12668 "ftosizs",
12669 "ftouizs",
12670 NULL,
12671 NULL,
12672 NULL,
12673 NULL,
12674 "ftosizd",
12675 "ftouizd"
12676 };
12677
12678 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
12679 do_vfp_nsyn_opcode (enc[flavour]);
12680 }
12681
12682 static void
12683 do_neon_cvt (void)
12684 {
12685 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
12686 NS_FD, NS_DF, NS_FF, NS_NULL);
12687 int flavour = neon_cvt_flavour (rs);
12688
12689 /* VFP rather than Neon conversions. */
12690 if (flavour >= 4)
12691 {
12692 do_vfp_nsyn_cvt (rs, flavour);
12693 return;
12694 }
12695
12696 switch (rs)
12697 {
12698 case NS_DDI:
12699 case NS_QQI:
12700 {
12701 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12702 return;
12703
12704 /* Fixed-point conversion with #0 immediate is encoded as an
12705 integer conversion. */
12706 if (inst.operands[2].present && inst.operands[2].imm == 0)
12707 goto int_encode;
12708 unsigned immbits = 32 - inst.operands[2].imm;
12709 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
12710 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12711 if (flavour != -1)
12712 inst.instruction |= enctab[flavour];
12713 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12714 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12715 inst.instruction |= LOW4 (inst.operands[1].reg);
12716 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12717 inst.instruction |= neon_quad (rs) << 6;
12718 inst.instruction |= 1 << 21;
12719 inst.instruction |= immbits << 16;
12720
12721 inst.instruction = neon_dp_fixup (inst.instruction);
12722 }
12723 break;
12724
12725 case NS_DD:
12726 case NS_QQ:
12727 int_encode:
12728 {
12729 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
12730
12731 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12732
12733 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12734 return;
12735
12736 if (flavour != -1)
12737 inst.instruction |= enctab[flavour];
12738
12739 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12740 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12741 inst.instruction |= LOW4 (inst.operands[1].reg);
12742 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12743 inst.instruction |= neon_quad (rs) << 6;
12744 inst.instruction |= 2 << 18;
12745
12746 inst.instruction = neon_dp_fixup (inst.instruction);
12747 }
12748 break;
12749
12750 default:
12751 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
12752 do_vfp_nsyn_cvt (rs, flavour);
12753 }
12754 }
12755
12756 static void
12757 neon_move_immediate (void)
12758 {
12759 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
12760 struct neon_type_el et = neon_check_type (2, rs,
12761 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
12762 unsigned immlo, immhi = 0, immbits;
12763 int op, cmode, float_p;
12764
12765 constraint (et.type == NT_invtype,
12766 _("operand size must be specified for immediate VMOV"));
12767
12768 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
12769 op = (inst.instruction & (1 << 5)) != 0;
12770
12771 immlo = inst.operands[1].imm;
12772 if (inst.operands[1].regisimm)
12773 immhi = inst.operands[1].reg;
12774
12775 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
12776 _("immediate has bits set outside the operand size"));
12777
12778 float_p = inst.operands[1].immisfloat;
12779
12780 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
12781 et.size, et.type)) == FAIL)
12782 {
12783 /* Invert relevant bits only. */
12784 neon_invert_size (&immlo, &immhi, et.size);
12785 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
12786 with one or the other; those cases are caught by
12787 neon_cmode_for_move_imm. */
12788 op = !op;
12789 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
12790 &op, et.size, et.type)) == FAIL)
12791 {
12792 first_error (_("immediate out of range"));
12793 return;
12794 }
12795 }
12796
12797 inst.instruction &= ~(1 << 5);
12798 inst.instruction |= op << 5;
12799
12800 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12801 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12802 inst.instruction |= neon_quad (rs) << 6;
12803 inst.instruction |= cmode << 8;
12804
12805 neon_write_immbits (immbits);
12806 }
12807
12808 static void
12809 do_neon_mvn (void)
12810 {
12811 if (inst.operands[1].isreg)
12812 {
12813 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12814
12815 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12816 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12817 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12818 inst.instruction |= LOW4 (inst.operands[1].reg);
12819 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12820 inst.instruction |= neon_quad (rs) << 6;
12821 }
12822 else
12823 {
12824 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12825 neon_move_immediate ();
12826 }
12827
12828 inst.instruction = neon_dp_fixup (inst.instruction);
12829 }
12830
12831 /* Encode instructions of form:
12832
12833 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12834 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm |
12835
12836 */
12837
12838 static void
12839 neon_mixed_length (struct neon_type_el et, unsigned size)
12840 {
12841 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12842 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12843 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12844 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12845 inst.instruction |= LOW4 (inst.operands[2].reg);
12846 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12847 inst.instruction |= (et.type == NT_unsigned) << 24;
12848 inst.instruction |= neon_logbits (size) << 20;
12849
12850 inst.instruction = neon_dp_fixup (inst.instruction);
12851 }
12852
12853 static void
12854 do_neon_dyadic_long (void)
12855 {
12856 /* FIXME: Type checking for lengthening op. */
12857 struct neon_type_el et = neon_check_type (3, NS_QDD,
12858 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
12859 neon_mixed_length (et, et.size);
12860 }
12861
12862 static void
12863 do_neon_abal (void)
12864 {
12865 struct neon_type_el et = neon_check_type (3, NS_QDD,
12866 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
12867 neon_mixed_length (et, et.size);
12868 }
12869
12870 static void
12871 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
12872 {
12873 if (inst.operands[2].isscalar)
12874 {
12875 struct neon_type_el et = neon_check_type (3, NS_QDS,
12876 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
12877 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12878 neon_mul_mac (et, et.type == NT_unsigned);
12879 }
12880 else
12881 {
12882 struct neon_type_el et = neon_check_type (3, NS_QDD,
12883 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
12884 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12885 neon_mixed_length (et, et.size);
12886 }
12887 }
12888
12889 static void
12890 do_neon_mac_maybe_scalar_long (void)
12891 {
12892 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
12893 }
12894
12895 static void
12896 do_neon_dyadic_wide (void)
12897 {
12898 struct neon_type_el et = neon_check_type (3, NS_QQD,
12899 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
12900 neon_mixed_length (et, et.size);
12901 }
12902
12903 static void
12904 do_neon_dyadic_narrow (void)
12905 {
12906 struct neon_type_el et = neon_check_type (3, NS_QDD,
12907 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
12908 /* Operand sign is unimportant, and the U bit is part of the opcode,
12909 so force the operand type to integer. */
12910 et.type = NT_integer;
12911 neon_mixed_length (et, et.size / 2);
12912 }
12913
12914 static void
12915 do_neon_mul_sat_scalar_long (void)
12916 {
12917 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
12918 }
12919
12920 static void
12921 do_neon_vmull (void)
12922 {
12923 if (inst.operands[2].isscalar)
12924 do_neon_mac_maybe_scalar_long ();
12925 else
12926 {
12927 struct neon_type_el et = neon_check_type (3, NS_QDD,
12928 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
12929 if (et.type == NT_poly)
12930 inst.instruction = NEON_ENC_POLY (inst.instruction);
12931 else
12932 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12933 /* For polynomial encoding, size field must be 0b00 and the U bit must be
12934 zero. Should be OK as-is. */
12935 neon_mixed_length (et, et.size);
12936 }
12937 }
12938
12939 static void
12940 do_neon_ext (void)
12941 {
12942 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
12943 struct neon_type_el et = neon_check_type (3, rs,
12944 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12945 unsigned imm = (inst.operands[3].imm * et.size) / 8;
12946 constraint (imm >= (neon_quad (rs) ? 16 : 8), _("shift out of range"));
12947 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12948 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12949 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12950 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12951 inst.instruction |= LOW4 (inst.operands[2].reg);
12952 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12953 inst.instruction |= neon_quad (rs) << 6;
12954 inst.instruction |= imm << 8;
12955
12956 inst.instruction = neon_dp_fixup (inst.instruction);
12957 }
12958
12959 static void
12960 do_neon_rev (void)
12961 {
12962 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12963 struct neon_type_el et = neon_check_type (2, rs,
12964 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12965 unsigned op = (inst.instruction >> 7) & 3;
12966 /* N (width of reversed regions) is encoded as part of the bitmask. We
12967 extract it here to check the elements to be reversed are smaller.
12968 Otherwise we'd get a reserved instruction. */
12969 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
12970 assert (elsize != 0);
12971 constraint (et.size >= elsize,
12972 _("elements must be smaller than reversal region"));
12973 neon_two_same (neon_quad (rs), 1, et.size);
12974 }
12975
12976 static void
12977 do_neon_dup (void)
12978 {
12979 if (inst.operands[1].isscalar)
12980 {
12981 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
12982 struct neon_type_el et = neon_check_type (2, rs,
12983 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12984 unsigned sizebits = et.size >> 3;
12985 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
12986 int logsize = neon_logbits (et.size);
12987 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
12988
12989 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
12990 return;
12991
12992 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12993 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12994 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12995 inst.instruction |= LOW4 (dm);
12996 inst.instruction |= HI1 (dm) << 5;
12997 inst.instruction |= neon_quad (rs) << 6;
12998 inst.instruction |= x << 17;
12999 inst.instruction |= sizebits << 16;
13000
13001 inst.instruction = neon_dp_fixup (inst.instruction);
13002 }
13003 else
13004 {
13005 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
13006 struct neon_type_el et = neon_check_type (2, rs,
13007 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13008 /* Duplicate ARM register to lanes of vector. */
13009 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
13010 switch (et.size)
13011 {
13012 case 8: inst.instruction |= 0x400000; break;
13013 case 16: inst.instruction |= 0x000020; break;
13014 case 32: inst.instruction |= 0x000000; break;
13015 default: break;
13016 }
13017 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13018 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
13019 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
13020 inst.instruction |= neon_quad (rs) << 21;
13021 /* The encoding for this instruction is identical for the ARM and Thumb
13022 variants, except for the condition field. */
13023 do_vfp_cond_or_thumb ();
13024 }
13025 }
13026
13027 /* VMOV has particularly many variations. It can be one of:
13028 0. VMOV<c><q> <Qd>, <Qm>
13029 1. VMOV<c><q> <Dd>, <Dm>
13030 (Register operations, which are VORR with Rm = Rn.)
13031 2. VMOV<c><q>.<dt> <Qd>, #<imm>
13032 3. VMOV<c><q>.<dt> <Dd>, #<imm>
13033 (Immediate loads.)
13034 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
13035 (ARM register to scalar.)
13036 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
13037 (Two ARM registers to vector.)
13038 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
13039 (Scalar to ARM register.)
13040 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
13041 (Vector to two ARM registers.)
13042 8. VMOV.F32 <Sd>, <Sm>
13043 9. VMOV.F64 <Dd>, <Dm>
13044 (VFP register moves.)
13045 10. VMOV.F32 <Sd>, #imm
13046 11. VMOV.F64 <Dd>, #imm
13047 (VFP float immediate load.)
13048 12. VMOV <Rd>, <Sm>
13049 (VFP single to ARM reg.)
13050 13. VMOV <Sd>, <Rm>
13051 (ARM reg to VFP single.)
13052 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
13053 (Two ARM regs to two VFP singles.)
13054 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
13055 (Two VFP singles to two ARM regs.)
13056
13057 These cases can be disambiguated using neon_select_shape, except cases 1/9
13058 and 3/11 which depend on the operand type too.
13059
13060 All the encoded bits are hardcoded by this function.
13061
13062 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
13063 Cases 5, 7 may be used with VFPv2 and above.
13064
13065 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
13066 can specify a type where it doesn't make sense to, and is ignored).
13067 */
13068
13069 static void
13070 do_neon_mov (void)
13071 {
13072 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
13073 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
13074 NS_NULL);
13075 struct neon_type_el et;
13076 const char *ldconst = 0;
13077
13078 switch (rs)
13079 {
13080 case NS_DD: /* case 1/9. */
13081 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13082 /* It is not an error here if no type is given. */
13083 inst.error = NULL;
13084 if (et.type == NT_float && et.size == 64)
13085 {
13086 do_vfp_nsyn_opcode ("fcpyd");
13087 break;
13088 }
13089 /* fall through. */
13090
13091 case NS_QQ: /* case 0/1. */
13092 {
13093 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13094 return;
13095 /* The architecture manual I have doesn't explicitly state which
13096 value the U bit should have for register->register moves, but
13097 the equivalent VORR instruction has U = 0, so do that. */
13098 inst.instruction = 0x0200110;
13099 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13100 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13101 inst.instruction |= LOW4 (inst.operands[1].reg);
13102 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13103 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13104 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13105 inst.instruction |= neon_quad (rs) << 6;
13106
13107 inst.instruction = neon_dp_fixup (inst.instruction);
13108 }
13109 break;
13110
13111 case NS_DI: /* case 3/11. */
13112 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13113 inst.error = NULL;
13114 if (et.type == NT_float && et.size == 64)
13115 {
13116 /* case 11 (fconstd). */
13117 ldconst = "fconstd";
13118 goto encode_fconstd;
13119 }
13120 /* fall through. */
13121
13122 case NS_QI: /* case 2/3. */
13123 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13124 return;
13125 inst.instruction = 0x0800010;
13126 neon_move_immediate ();
13127 inst.instruction = neon_dp_fixup (inst.instruction);
13128 break;
13129
13130 case NS_SR: /* case 4. */
13131 {
13132 unsigned bcdebits = 0;
13133 struct neon_type_el et = neon_check_type (2, NS_NULL,
13134 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13135 int logsize = neon_logbits (et.size);
13136 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
13137 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
13138
13139 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13140 _(BAD_FPU));
13141 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13142 && et.size != 32, _(BAD_FPU));
13143 constraint (et.type == NT_invtype, _("bad type for scalar"));
13144 constraint (x >= 64 / et.size, _("scalar index out of range"));
13145
13146 switch (et.size)
13147 {
13148 case 8: bcdebits = 0x8; break;
13149 case 16: bcdebits = 0x1; break;
13150 case 32: bcdebits = 0x0; break;
13151 default: ;
13152 }
13153
13154 bcdebits |= x << logsize;
13155
13156 inst.instruction = 0xe000b10;
13157 do_vfp_cond_or_thumb ();
13158 inst.instruction |= LOW4 (dn) << 16;
13159 inst.instruction |= HI1 (dn) << 7;
13160 inst.instruction |= inst.operands[1].reg << 12;
13161 inst.instruction |= (bcdebits & 3) << 5;
13162 inst.instruction |= (bcdebits >> 2) << 21;
13163 }
13164 break;
13165
13166 case NS_DRR: /* case 5 (fmdrr). */
13167 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13168 _(BAD_FPU));
13169
13170 inst.instruction = 0xc400b10;
13171 do_vfp_cond_or_thumb ();
13172 inst.instruction |= LOW4 (inst.operands[0].reg);
13173 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
13174 inst.instruction |= inst.operands[1].reg << 12;
13175 inst.instruction |= inst.operands[2].reg << 16;
13176 break;
13177
13178 case NS_RS: /* case 6. */
13179 {
13180 struct neon_type_el et = neon_check_type (2, NS_NULL,
13181 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
13182 unsigned logsize = neon_logbits (et.size);
13183 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
13184 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
13185 unsigned abcdebits = 0;
13186
13187 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13188 _(BAD_FPU));
13189 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13190 && et.size != 32, _(BAD_FPU));
13191 constraint (et.type == NT_invtype, _("bad type for scalar"));
13192 constraint (x >= 64 / et.size, _("scalar index out of range"));
13193
13194 switch (et.size)
13195 {
13196 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
13197 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
13198 case 32: abcdebits = 0x00; break;
13199 default: ;
13200 }
13201
13202 abcdebits |= x << logsize;
13203 inst.instruction = 0xe100b10;
13204 do_vfp_cond_or_thumb ();
13205 inst.instruction |= LOW4 (dn) << 16;
13206 inst.instruction |= HI1 (dn) << 7;
13207 inst.instruction |= inst.operands[0].reg << 12;
13208 inst.instruction |= (abcdebits & 3) << 5;
13209 inst.instruction |= (abcdebits >> 2) << 21;
13210 }
13211 break;
13212
13213 case NS_RRD: /* case 7 (fmrrd). */
13214 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13215 _(BAD_FPU));
13216
13217 inst.instruction = 0xc500b10;
13218 do_vfp_cond_or_thumb ();
13219 inst.instruction |= inst.operands[0].reg << 12;
13220 inst.instruction |= inst.operands[1].reg << 16;
13221 inst.instruction |= LOW4 (inst.operands[2].reg);
13222 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13223 break;
13224
13225 case NS_FF: /* case 8 (fcpys). */
13226 do_vfp_nsyn_opcode ("fcpys");
13227 break;
13228
13229 case NS_FI: /* case 10 (fconsts). */
13230 ldconst = "fconsts";
13231 encode_fconstd:
13232 if (is_quarter_float (inst.operands[1].imm))
13233 {
13234 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
13235 do_vfp_nsyn_opcode (ldconst);
13236 }
13237 else
13238 first_error (_("immediate out of range"));
13239 break;
13240
13241 case NS_RF: /* case 12 (fmrs). */
13242 do_vfp_nsyn_opcode ("fmrs");
13243 break;
13244
13245 case NS_FR: /* case 13 (fmsr). */
13246 do_vfp_nsyn_opcode ("fmsr");
13247 break;
13248
13249 /* The encoders for the fmrrs and fmsrr instructions expect three operands
13250 (one of which is a list), but we have parsed four. Do some fiddling to
13251 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
13252 expect. */
13253 case NS_RRFF: /* case 14 (fmrrs). */
13254 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
13255 _("VFP registers must be adjacent"));
13256 inst.operands[2].imm = 2;
13257 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13258 do_vfp_nsyn_opcode ("fmrrs");
13259 break;
13260
13261 case NS_FFRR: /* case 15 (fmsrr). */
13262 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
13263 _("VFP registers must be adjacent"));
13264 inst.operands[1] = inst.operands[2];
13265 inst.operands[2] = inst.operands[3];
13266 inst.operands[0].imm = 2;
13267 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13268 do_vfp_nsyn_opcode ("fmsrr");
13269 break;
13270
13271 default:
13272 abort ();
13273 }
13274 }
13275
13276 static void
13277 do_neon_rshift_round_imm (void)
13278 {
13279 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13280 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
13281 int imm = inst.operands[2].imm;
13282
13283 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
13284 if (imm == 0)
13285 {
13286 inst.operands[2].present = 0;
13287 do_neon_mov ();
13288 return;
13289 }
13290
13291 constraint (imm < 1 || (unsigned)imm > et.size,
13292 _("immediate out of range for shift"));
13293 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
13294 et.size - imm);
13295 }
13296
13297 static void
13298 do_neon_movl (void)
13299 {
13300 struct neon_type_el et = neon_check_type (2, NS_QD,
13301 N_EQK | N_DBL, N_SU_32 | N_KEY);
13302 unsigned sizebits = et.size >> 3;
13303 inst.instruction |= sizebits << 19;
13304 neon_two_same (0, et.type == NT_unsigned, -1);
13305 }
13306
13307 static void
13308 do_neon_trn (void)
13309 {
13310 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13311 struct neon_type_el et = neon_check_type (2, rs,
13312 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13313 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13314 neon_two_same (neon_quad (rs), 1, et.size);
13315 }
13316
13317 static void
13318 do_neon_zip_uzp (void)
13319 {
13320 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13321 struct neon_type_el et = neon_check_type (2, rs,
13322 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13323 if (rs == NS_DD && et.size == 32)
13324 {
13325 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
13326 inst.instruction = N_MNEM_vtrn;
13327 do_neon_trn ();
13328 return;
13329 }
13330 neon_two_same (neon_quad (rs), 1, et.size);
13331 }
13332
13333 static void
13334 do_neon_sat_abs_neg (void)
13335 {
13336 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13337 struct neon_type_el et = neon_check_type (2, rs,
13338 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
13339 neon_two_same (neon_quad (rs), 1, et.size);
13340 }
13341
13342 static void
13343 do_neon_pair_long (void)
13344 {
13345 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13346 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
13347 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
13348 inst.instruction |= (et.type == NT_unsigned) << 7;
13349 neon_two_same (neon_quad (rs), 1, et.size);
13350 }
13351
13352 static void
13353 do_neon_recip_est (void)
13354 {
13355 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13356 struct neon_type_el et = neon_check_type (2, rs,
13357 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
13358 inst.instruction |= (et.type == NT_float) << 8;
13359 neon_two_same (neon_quad (rs), 1, et.size);
13360 }
13361
13362 static void
13363 do_neon_cls (void)
13364 {
13365 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13366 struct neon_type_el et = neon_check_type (2, rs,
13367 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
13368 neon_two_same (neon_quad (rs), 1, et.size);
13369 }
13370
13371 static void
13372 do_neon_clz (void)
13373 {
13374 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13375 struct neon_type_el et = neon_check_type (2, rs,
13376 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
13377 neon_two_same (neon_quad (rs), 1, et.size);
13378 }
13379
13380 static void
13381 do_neon_cnt (void)
13382 {
13383 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13384 struct neon_type_el et = neon_check_type (2, rs,
13385 N_EQK | N_INT, N_8 | N_KEY);
13386 neon_two_same (neon_quad (rs), 1, et.size);
13387 }
13388
13389 static void
13390 do_neon_swp (void)
13391 {
13392 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13393 neon_two_same (neon_quad (rs), 1, -1);
13394 }
13395
13396 static void
13397 do_neon_tbl_tbx (void)
13398 {
13399 unsigned listlenbits;
13400 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
13401
13402 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
13403 {
13404 first_error (_("bad list length for table lookup"));
13405 return;
13406 }
13407
13408 listlenbits = inst.operands[1].imm - 1;
13409 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13410 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13411 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13412 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13413 inst.instruction |= LOW4 (inst.operands[2].reg);
13414 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13415 inst.instruction |= listlenbits << 8;
13416
13417 inst.instruction = neon_dp_fixup (inst.instruction);
13418 }
13419
13420 static void
13421 do_neon_ldm_stm (void)
13422 {
13423 /* P, U and L bits are part of bitmask. */
13424 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
13425 unsigned offsetbits = inst.operands[1].imm * 2;
13426
13427 if (inst.operands[1].issingle)
13428 {
13429 do_vfp_nsyn_ldm_stm (is_dbmode);
13430 return;
13431 }
13432
13433 constraint (is_dbmode && !inst.operands[0].writeback,
13434 _("writeback (!) must be used for VLDMDB and VSTMDB"));
13435
13436 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
13437 _("register list must contain at least 1 and at most 16 "
13438 "registers"));
13439
13440 inst.instruction |= inst.operands[0].reg << 16;
13441 inst.instruction |= inst.operands[0].writeback << 21;
13442 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13443 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
13444
13445 inst.instruction |= offsetbits;
13446
13447 do_vfp_cond_or_thumb ();
13448 }
13449
13450 static void
13451 do_neon_ldr_str (void)
13452 {
13453 int is_ldr = (inst.instruction & (1 << 20)) != 0;
13454
13455 if (inst.operands[0].issingle)
13456 {
13457 if (is_ldr)
13458 do_vfp_nsyn_opcode ("flds");
13459 else
13460 do_vfp_nsyn_opcode ("fsts");
13461 }
13462 else
13463 {
13464 if (is_ldr)
13465 do_vfp_nsyn_opcode ("fldd");
13466 else
13467 do_vfp_nsyn_opcode ("fstd");
13468 }
13469 }
13470
13471 /* "interleave" version also handles non-interleaving register VLD1/VST1
13472 instructions. */
13473
13474 static void
13475 do_neon_ld_st_interleave (void)
13476 {
13477 struct neon_type_el et = neon_check_type (1, NS_NULL,
13478 N_8 | N_16 | N_32 | N_64);
13479 unsigned alignbits = 0;
13480 unsigned idx;
13481 /* The bits in this table go:
13482 0: register stride of one (0) or two (1)
13483 1,2: register list length, minus one (1, 2, 3, 4).
13484 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
13485 We use -1 for invalid entries. */
13486 const int typetable[] =
13487 {
13488 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
13489 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
13490 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
13491 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
13492 };
13493 int typebits;
13494
13495 if (et.type == NT_invtype)
13496 return;
13497
13498 if (inst.operands[1].immisalign)
13499 switch (inst.operands[1].imm >> 8)
13500 {
13501 case 64: alignbits = 1; break;
13502 case 128:
13503 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13504 goto bad_alignment;
13505 alignbits = 2;
13506 break;
13507 case 256:
13508 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13509 goto bad_alignment;
13510 alignbits = 3;
13511 break;
13512 default:
13513 bad_alignment:
13514 first_error (_("bad alignment"));
13515 return;
13516 }
13517
13518 inst.instruction |= alignbits << 4;
13519 inst.instruction |= neon_logbits (et.size) << 6;
13520
13521 /* Bits [4:6] of the immediate in a list specifier encode register stride
13522 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
13523 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
13524 up the right value for "type" in a table based on this value and the given
13525 list style, then stick it back. */
13526 idx = ((inst.operands[0].imm >> 4) & 7)
13527 | (((inst.instruction >> 8) & 3) << 3);
13528
13529 typebits = typetable[idx];
13530
13531 constraint (typebits == -1, _("bad list type for instruction"));
13532
13533 inst.instruction &= ~0xf00;
13534 inst.instruction |= typebits << 8;
13535 }
13536
13537 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
13538 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
13539 otherwise. The variable arguments are a list of pairs of legal (size, align)
13540 values, terminated with -1. */
13541
13542 static int
13543 neon_alignment_bit (int size, int align, int *do_align, ...)
13544 {
13545 va_list ap;
13546 int result = FAIL, thissize, thisalign;
13547
13548 if (!inst.operands[1].immisalign)
13549 {
13550 *do_align = 0;
13551 return SUCCESS;
13552 }
13553
13554 va_start (ap, do_align);
13555
13556 do
13557 {
13558 thissize = va_arg (ap, int);
13559 if (thissize == -1)
13560 break;
13561 thisalign = va_arg (ap, int);
13562
13563 if (size == thissize && align == thisalign)
13564 result = SUCCESS;
13565 }
13566 while (result != SUCCESS);
13567
13568 va_end (ap);
13569
13570 if (result == SUCCESS)
13571 *do_align = 1;
13572 else
13573 first_error (_("unsupported alignment for instruction"));
13574
13575 return result;
13576 }
13577
13578 static void
13579 do_neon_ld_st_lane (void)
13580 {
13581 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
13582 int align_good, do_align = 0;
13583 int logsize = neon_logbits (et.size);
13584 int align = inst.operands[1].imm >> 8;
13585 int n = (inst.instruction >> 8) & 3;
13586 int max_el = 64 / et.size;
13587
13588 if (et.type == NT_invtype)
13589 return;
13590
13591 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
13592 _("bad list length"));
13593 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
13594 _("scalar index out of range"));
13595 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
13596 && et.size == 8,
13597 _("stride of 2 unavailable when element size is 8"));
13598
13599 switch (n)
13600 {
13601 case 0: /* VLD1 / VST1. */
13602 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
13603 32, 32, -1);
13604 if (align_good == FAIL)
13605 return;
13606 if (do_align)
13607 {
13608 unsigned alignbits = 0;
13609 switch (et.size)
13610 {
13611 case 16: alignbits = 0x1; break;
13612 case 32: alignbits = 0x3; break;
13613 default: ;
13614 }
13615 inst.instruction |= alignbits << 4;
13616 }
13617 break;
13618
13619 case 1: /* VLD2 / VST2. */
13620 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
13621 32, 64, -1);
13622 if (align_good == FAIL)
13623 return;
13624 if (do_align)
13625 inst.instruction |= 1 << 4;
13626 break;
13627
13628 case 2: /* VLD3 / VST3. */
13629 constraint (inst.operands[1].immisalign,
13630 _("can't use alignment with this instruction"));
13631 break;
13632
13633 case 3: /* VLD4 / VST4. */
13634 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13635 16, 64, 32, 64, 32, 128, -1);
13636 if (align_good == FAIL)
13637 return;
13638 if (do_align)
13639 {
13640 unsigned alignbits = 0;
13641 switch (et.size)
13642 {
13643 case 8: alignbits = 0x1; break;
13644 case 16: alignbits = 0x1; break;
13645 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
13646 default: ;
13647 }
13648 inst.instruction |= alignbits << 4;
13649 }
13650 break;
13651
13652 default: ;
13653 }
13654
13655 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
13656 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13657 inst.instruction |= 1 << (4 + logsize);
13658
13659 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
13660 inst.instruction |= logsize << 10;
13661 }
13662
13663 /* Encode single n-element structure to all lanes VLD<n> instructions. */
13664
13665 static void
13666 do_neon_ld_dup (void)
13667 {
13668 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
13669 int align_good, do_align = 0;
13670
13671 if (et.type == NT_invtype)
13672 return;
13673
13674 switch ((inst.instruction >> 8) & 3)
13675 {
13676 case 0: /* VLD1. */
13677 assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
13678 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13679 &do_align, 16, 16, 32, 32, -1);
13680 if (align_good == FAIL)
13681 return;
13682 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
13683 {
13684 case 1: break;
13685 case 2: inst.instruction |= 1 << 5; break;
13686 default: first_error (_("bad list length")); return;
13687 }
13688 inst.instruction |= neon_logbits (et.size) << 6;
13689 break;
13690
13691 case 1: /* VLD2. */
13692 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13693 &do_align, 8, 16, 16, 32, 32, 64, -1);
13694 if (align_good == FAIL)
13695 return;
13696 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
13697 _("bad list length"));
13698 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13699 inst.instruction |= 1 << 5;
13700 inst.instruction |= neon_logbits (et.size) << 6;
13701 break;
13702
13703 case 2: /* VLD3. */
13704 constraint (inst.operands[1].immisalign,
13705 _("can't use alignment with this instruction"));
13706 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
13707 _("bad list length"));
13708 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13709 inst.instruction |= 1 << 5;
13710 inst.instruction |= neon_logbits (et.size) << 6;
13711 break;
13712
13713 case 3: /* VLD4. */
13714 {
13715 int align = inst.operands[1].imm >> 8;
13716 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13717 16, 64, 32, 64, 32, 128, -1);
13718 if (align_good == FAIL)
13719 return;
13720 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
13721 _("bad list length"));
13722 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13723 inst.instruction |= 1 << 5;
13724 if (et.size == 32 && align == 128)
13725 inst.instruction |= 0x3 << 6;
13726 else
13727 inst.instruction |= neon_logbits (et.size) << 6;
13728 }
13729 break;
13730
13731 default: ;
13732 }
13733
13734 inst.instruction |= do_align << 4;
13735 }
13736
13737 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
13738 apart from bits [11:4]. */
13739
13740 static void
13741 do_neon_ldx_stx (void)
13742 {
13743 switch (NEON_LANE (inst.operands[0].imm))
13744 {
13745 case NEON_INTERLEAVE_LANES:
13746 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
13747 do_neon_ld_st_interleave ();
13748 break;
13749
13750 case NEON_ALL_LANES:
13751 inst.instruction = NEON_ENC_DUP (inst.instruction);
13752 do_neon_ld_dup ();
13753 break;
13754
13755 default:
13756 inst.instruction = NEON_ENC_LANE (inst.instruction);
13757 do_neon_ld_st_lane ();
13758 }
13759
13760 /* L bit comes from bit mask. */
13761 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13762 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13763 inst.instruction |= inst.operands[1].reg << 16;
13764
13765 if (inst.operands[1].postind)
13766 {
13767 int postreg = inst.operands[1].imm & 0xf;
13768 constraint (!inst.operands[1].immisreg,
13769 _("post-index must be a register"));
13770 constraint (postreg == 0xd || postreg == 0xf,
13771 _("bad register for post-index"));
13772 inst.instruction |= postreg;
13773 }
13774 else if (inst.operands[1].writeback)
13775 {
13776 inst.instruction |= 0xd;
13777 }
13778 else
13779 inst.instruction |= 0xf;
13780
13781 if (thumb_mode)
13782 inst.instruction |= 0xf9000000;
13783 else
13784 inst.instruction |= 0xf4000000;
13785 }
13786
13787 \f
13788 /* Overall per-instruction processing. */
13789
13790 /* We need to be able to fix up arbitrary expressions in some statements.
13791 This is so that we can handle symbols that are an arbitrary distance from
13792 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
13793 which returns part of an address in a form which will be valid for
13794 a data instruction. We do this by pushing the expression into a symbol
13795 in the expr_section, and creating a fix for that. */
13796
13797 static void
13798 fix_new_arm (fragS * frag,
13799 int where,
13800 short int size,
13801 expressionS * exp,
13802 int pc_rel,
13803 int reloc)
13804 {
13805 fixS * new_fix;
13806
13807 switch (exp->X_op)
13808 {
13809 case O_constant:
13810 case O_symbol:
13811 case O_add:
13812 case O_subtract:
13813 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
13814 break;
13815
13816 default:
13817 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
13818 pc_rel, reloc);
13819 break;
13820 }
13821
13822 /* Mark whether the fix is to a THUMB instruction, or an ARM
13823 instruction. */
13824 new_fix->tc_fix_data = thumb_mode;
13825 }
13826
13827 /* Create a frg for an instruction requiring relaxation. */
13828 static void
13829 output_relax_insn (void)
13830 {
13831 char * to;
13832 symbolS *sym;
13833 int offset;
13834
13835 /* The size of the instruction is unknown, so tie the debug info to the
13836 start of the instruction. */
13837 dwarf2_emit_insn (0);
13838
13839 switch (inst.reloc.exp.X_op)
13840 {
13841 case O_symbol:
13842 sym = inst.reloc.exp.X_add_symbol;
13843 offset = inst.reloc.exp.X_add_number;
13844 break;
13845 case O_constant:
13846 sym = NULL;
13847 offset = inst.reloc.exp.X_add_number;
13848 break;
13849 default:
13850 sym = make_expr_symbol (&inst.reloc.exp);
13851 offset = 0;
13852 break;
13853 }
13854 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
13855 inst.relax, sym, offset, NULL/*offset, opcode*/);
13856 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
13857 }
13858
13859 /* Write a 32-bit thumb instruction to buf. */
13860 static void
13861 put_thumb32_insn (char * buf, unsigned long insn)
13862 {
13863 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
13864 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
13865 }
13866
13867 static void
13868 output_inst (const char * str)
13869 {
13870 char * to = NULL;
13871
13872 if (inst.error)
13873 {
13874 as_bad ("%s -- `%s'", inst.error, str);
13875 return;
13876 }
13877 if (inst.relax) {
13878 output_relax_insn();
13879 return;
13880 }
13881 if (inst.size == 0)
13882 return;
13883
13884 to = frag_more (inst.size);
13885
13886 if (thumb_mode && (inst.size > THUMB_SIZE))
13887 {
13888 assert (inst.size == (2 * THUMB_SIZE));
13889 put_thumb32_insn (to, inst.instruction);
13890 }
13891 else if (inst.size > INSN_SIZE)
13892 {
13893 assert (inst.size == (2 * INSN_SIZE));
13894 md_number_to_chars (to, inst.instruction, INSN_SIZE);
13895 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
13896 }
13897 else
13898 md_number_to_chars (to, inst.instruction, inst.size);
13899
13900 if (inst.reloc.type != BFD_RELOC_UNUSED)
13901 fix_new_arm (frag_now, to - frag_now->fr_literal,
13902 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
13903 inst.reloc.type);
13904
13905 dwarf2_emit_insn (inst.size);
13906 }
13907
13908 /* Tag values used in struct asm_opcode's tag field. */
13909 enum opcode_tag
13910 {
13911 OT_unconditional, /* Instruction cannot be conditionalized.
13912 The ARM condition field is still 0xE. */
13913 OT_unconditionalF, /* Instruction cannot be conditionalized
13914 and carries 0xF in its ARM condition field. */
13915 OT_csuffix, /* Instruction takes a conditional suffix. */
13916 OT_csuffixF, /* Some forms of the instruction take a conditional
13917 suffix, others place 0xF where the condition field
13918 would be. */
13919 OT_cinfix3, /* Instruction takes a conditional infix,
13920 beginning at character index 3. (In
13921 unified mode, it becomes a suffix.) */
13922 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
13923 tsts, cmps, cmns, and teqs. */
13924 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
13925 character index 3, even in unified mode. Used for
13926 legacy instructions where suffix and infix forms
13927 may be ambiguous. */
13928 OT_csuf_or_in3, /* Instruction takes either a conditional
13929 suffix or an infix at character index 3. */
13930 OT_odd_infix_unc, /* This is the unconditional variant of an
13931 instruction that takes a conditional infix
13932 at an unusual position. In unified mode,
13933 this variant will accept a suffix. */
13934 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
13935 are the conditional variants of instructions that
13936 take conditional infixes in unusual positions.
13937 The infix appears at character index
13938 (tag - OT_odd_infix_0). These are not accepted
13939 in unified mode. */
13940 };
13941
13942 /* Subroutine of md_assemble, responsible for looking up the primary
13943 opcode from the mnemonic the user wrote. STR points to the
13944 beginning of the mnemonic.
13945
13946 This is not simply a hash table lookup, because of conditional
13947 variants. Most instructions have conditional variants, which are
13948 expressed with a _conditional affix_ to the mnemonic. If we were
13949 to encode each conditional variant as a literal string in the opcode
13950 table, it would have approximately 20,000 entries.
13951
13952 Most mnemonics take this affix as a suffix, and in unified syntax,
13953 'most' is upgraded to 'all'. However, in the divided syntax, some
13954 instructions take the affix as an infix, notably the s-variants of
13955 the arithmetic instructions. Of those instructions, all but six
13956 have the infix appear after the third character of the mnemonic.
13957
13958 Accordingly, the algorithm for looking up primary opcodes given
13959 an identifier is:
13960
13961 1. Look up the identifier in the opcode table.
13962 If we find a match, go to step U.
13963
13964 2. Look up the last two characters of the identifier in the
13965 conditions table. If we find a match, look up the first N-2
13966 characters of the identifier in the opcode table. If we
13967 find a match, go to step CE.
13968
13969 3. Look up the fourth and fifth characters of the identifier in
13970 the conditions table. If we find a match, extract those
13971 characters from the identifier, and look up the remaining
13972 characters in the opcode table. If we find a match, go
13973 to step CM.
13974
13975 4. Fail.
13976
13977 U. Examine the tag field of the opcode structure, in case this is
13978 one of the six instructions with its conditional infix in an
13979 unusual place. If it is, the tag tells us where to find the
13980 infix; look it up in the conditions table and set inst.cond
13981 accordingly. Otherwise, this is an unconditional instruction.
13982 Again set inst.cond accordingly. Return the opcode structure.
13983
13984 CE. Examine the tag field to make sure this is an instruction that
13985 should receive a conditional suffix. If it is not, fail.
13986 Otherwise, set inst.cond from the suffix we already looked up,
13987 and return the opcode structure.
13988
13989 CM. Examine the tag field to make sure this is an instruction that
13990 should receive a conditional infix after the third character.
13991 If it is not, fail. Otherwise, undo the edits to the current
13992 line of input and proceed as for case CE. */
13993
13994 static const struct asm_opcode *
13995 opcode_lookup (char **str)
13996 {
13997 char *end, *base;
13998 char *affix;
13999 const struct asm_opcode *opcode;
14000 const struct asm_cond *cond;
14001 char save[2];
14002 bfd_boolean neon_supported;
14003
14004 neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1);
14005
14006 /* Scan up to the end of the mnemonic, which must end in white space,
14007 '.' (in unified mode, or for Neon instructions), or end of string. */
14008 for (base = end = *str; *end != '\0'; end++)
14009 if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.'))
14010 break;
14011
14012 if (end == base)
14013 return 0;
14014
14015 /* Handle a possible width suffix and/or Neon type suffix. */
14016 if (end[0] == '.')
14017 {
14018 int offset = 2;
14019
14020 /* The .w and .n suffixes are only valid if the unified syntax is in
14021 use. */
14022 if (unified_syntax && end[1] == 'w')
14023 inst.size_req = 4;
14024 else if (unified_syntax && end[1] == 'n')
14025 inst.size_req = 2;
14026 else
14027 offset = 0;
14028
14029 inst.vectype.elems = 0;
14030
14031 *str = end + offset;
14032
14033 if (end[offset] == '.')
14034 {
14035 /* See if we have a Neon type suffix (possible in either unified or
14036 non-unified ARM syntax mode). */
14037 if (parse_neon_type (&inst.vectype, str) == FAIL)
14038 return 0;
14039 }
14040 else if (end[offset] != '\0' && end[offset] != ' ')
14041 return 0;
14042 }
14043 else
14044 *str = end;
14045
14046 /* Look for unaffixed or special-case affixed mnemonic. */
14047 opcode = hash_find_n (arm_ops_hsh, base, end - base);
14048 if (opcode)
14049 {
14050 /* step U */
14051 if (opcode->tag < OT_odd_infix_0)
14052 {
14053 inst.cond = COND_ALWAYS;
14054 return opcode;
14055 }
14056
14057 if (unified_syntax)
14058 as_warn (_("conditional infixes are deprecated in unified syntax"));
14059 affix = base + (opcode->tag - OT_odd_infix_0);
14060 cond = hash_find_n (arm_cond_hsh, affix, 2);
14061 assert (cond);
14062
14063 inst.cond = cond->value;
14064 return opcode;
14065 }
14066
14067 /* Cannot have a conditional suffix on a mnemonic of less than two
14068 characters. */
14069 if (end - base < 3)
14070 return 0;
14071
14072 /* Look for suffixed mnemonic. */
14073 affix = end - 2;
14074 cond = hash_find_n (arm_cond_hsh, affix, 2);
14075 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
14076 if (opcode && cond)
14077 {
14078 /* step CE */
14079 switch (opcode->tag)
14080 {
14081 case OT_cinfix3_legacy:
14082 /* Ignore conditional suffixes matched on infix only mnemonics. */
14083 break;
14084
14085 case OT_cinfix3:
14086 case OT_cinfix3_deprecated:
14087 case OT_odd_infix_unc:
14088 if (!unified_syntax)
14089 return 0;
14090 /* else fall through */
14091
14092 case OT_csuffix:
14093 case OT_csuffixF:
14094 case OT_csuf_or_in3:
14095 inst.cond = cond->value;
14096 return opcode;
14097
14098 case OT_unconditional:
14099 case OT_unconditionalF:
14100 if (thumb_mode)
14101 {
14102 inst.cond = cond->value;
14103 }
14104 else
14105 {
14106 /* delayed diagnostic */
14107 inst.error = BAD_COND;
14108 inst.cond = COND_ALWAYS;
14109 }
14110 return opcode;
14111
14112 default:
14113 return 0;
14114 }
14115 }
14116
14117 /* Cannot have a usual-position infix on a mnemonic of less than
14118 six characters (five would be a suffix). */
14119 if (end - base < 6)
14120 return 0;
14121
14122 /* Look for infixed mnemonic in the usual position. */
14123 affix = base + 3;
14124 cond = hash_find_n (arm_cond_hsh, affix, 2);
14125 if (!cond)
14126 return 0;
14127
14128 memcpy (save, affix, 2);
14129 memmove (affix, affix + 2, (end - affix) - 2);
14130 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
14131 memmove (affix + 2, affix, (end - affix) - 2);
14132 memcpy (affix, save, 2);
14133
14134 if (opcode
14135 && (opcode->tag == OT_cinfix3
14136 || opcode->tag == OT_cinfix3_deprecated
14137 || opcode->tag == OT_csuf_or_in3
14138 || opcode->tag == OT_cinfix3_legacy))
14139 {
14140 /* step CM */
14141 if (unified_syntax
14142 && (opcode->tag == OT_cinfix3
14143 || opcode->tag == OT_cinfix3_deprecated))
14144 as_warn (_("conditional infixes are deprecated in unified syntax"));
14145
14146 inst.cond = cond->value;
14147 return opcode;
14148 }
14149
14150 return 0;
14151 }
14152
14153 void
14154 md_assemble (char *str)
14155 {
14156 char *p = str;
14157 const struct asm_opcode * opcode;
14158
14159 /* Align the previous label if needed. */
14160 if (last_label_seen != NULL)
14161 {
14162 symbol_set_frag (last_label_seen, frag_now);
14163 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
14164 S_SET_SEGMENT (last_label_seen, now_seg);
14165 }
14166
14167 memset (&inst, '\0', sizeof (inst));
14168 inst.reloc.type = BFD_RELOC_UNUSED;
14169
14170 opcode = opcode_lookup (&p);
14171 if (!opcode)
14172 {
14173 /* It wasn't an instruction, but it might be a register alias of
14174 the form alias .req reg, or a Neon .dn/.qn directive. */
14175 if (!create_register_alias (str, p)
14176 && !create_neon_reg_alias (str, p))
14177 as_bad (_("bad instruction `%s'"), str);
14178
14179 return;
14180 }
14181
14182 if (opcode->tag == OT_cinfix3_deprecated)
14183 as_warn (_("s suffix on comparison instruction is deprecated"));
14184
14185 /* The value which unconditional instructions should have in place of the
14186 condition field. */
14187 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
14188
14189 if (thumb_mode)
14190 {
14191 arm_feature_set variant;
14192
14193 variant = cpu_variant;
14194 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
14195 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
14196 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
14197 /* Check that this instruction is supported for this CPU. */
14198 if (!opcode->tvariant
14199 || (thumb_mode == 1
14200 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
14201 {
14202 as_bad (_("selected processor does not support `%s'"), str);
14203 return;
14204 }
14205 if (inst.cond != COND_ALWAYS && !unified_syntax
14206 && opcode->tencode != do_t_branch)
14207 {
14208 as_bad (_("Thumb does not support conditional execution"));
14209 return;
14210 }
14211
14212 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) && !inst.size_req)
14213 {
14214 /* Implicit require narrow instructions on Thumb-1. This avoids
14215 relaxation accidentally introducing Thumb-2 instructions. */
14216 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23)
14217 inst.size_req = 2;
14218 }
14219
14220 /* Check conditional suffixes. */
14221 if (current_it_mask)
14222 {
14223 int cond;
14224 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
14225 current_it_mask <<= 1;
14226 current_it_mask &= 0x1f;
14227 /* The BKPT instruction is unconditional even in an IT block. */
14228 if (!inst.error
14229 && cond != inst.cond && opcode->tencode != do_t_bkpt)
14230 {
14231 as_bad (_("incorrect condition in IT block"));
14232 return;
14233 }
14234 }
14235 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
14236 {
14237 as_bad (_("thumb conditional instrunction not in IT block"));
14238 return;
14239 }
14240
14241 mapping_state (MAP_THUMB);
14242 inst.instruction = opcode->tvalue;
14243
14244 if (!parse_operands (p, opcode->operands))
14245 opcode->tencode ();
14246
14247 /* Clear current_it_mask at the end of an IT block. */
14248 if (current_it_mask == 0x10)
14249 current_it_mask = 0;
14250
14251 if (!(inst.error || inst.relax))
14252 {
14253 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
14254 inst.size = (inst.instruction > 0xffff ? 4 : 2);
14255 if (inst.size_req && inst.size_req != inst.size)
14256 {
14257 as_bad (_("cannot honor width suffix -- `%s'"), str);
14258 return;
14259 }
14260 }
14261
14262 /* Something has gone badly wrong if we try to relax a fixed size
14263 instruction. */
14264 assert (inst.size_req == 0 || !inst.relax);
14265
14266 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14267 *opcode->tvariant);
14268 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
14269 set those bits when Thumb-2 32-bit instructions are seen. ie.
14270 anything other than bl/blx.
14271 This is overly pessimistic for relaxable instructions. */
14272 if ((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
14273 || inst.relax)
14274 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14275 arm_ext_v6t2);
14276 }
14277 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
14278 {
14279 /* Check that this instruction is supported for this CPU. */
14280 if (!opcode->avariant ||
14281 !ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant))
14282 {
14283 as_bad (_("selected processor does not support `%s'"), str);
14284 return;
14285 }
14286 if (inst.size_req)
14287 {
14288 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
14289 return;
14290 }
14291
14292 mapping_state (MAP_ARM);
14293 inst.instruction = opcode->avalue;
14294 if (opcode->tag == OT_unconditionalF)
14295 inst.instruction |= 0xF << 28;
14296 else
14297 inst.instruction |= inst.cond << 28;
14298 inst.size = INSN_SIZE;
14299 if (!parse_operands (p, opcode->operands))
14300 opcode->aencode ();
14301 /* Arm mode bx is marked as both v4T and v5 because it's still required
14302 on a hypothetical non-thumb v5 core. */
14303 if (ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v4t)
14304 || ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v5))
14305 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
14306 else
14307 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
14308 *opcode->avariant);
14309 }
14310 else
14311 {
14312 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
14313 "-- `%s'"), str);
14314 return;
14315 }
14316 output_inst (str);
14317 }
14318
14319 /* Various frobbings of labels and their addresses. */
14320
14321 void
14322 arm_start_line_hook (void)
14323 {
14324 last_label_seen = NULL;
14325 }
14326
14327 void
14328 arm_frob_label (symbolS * sym)
14329 {
14330 last_label_seen = sym;
14331
14332 ARM_SET_THUMB (sym, thumb_mode);
14333
14334 #if defined OBJ_COFF || defined OBJ_ELF
14335 ARM_SET_INTERWORK (sym, support_interwork);
14336 #endif
14337
14338 /* Note - do not allow local symbols (.Lxxx) to be labeled
14339 as Thumb functions. This is because these labels, whilst
14340 they exist inside Thumb code, are not the entry points for
14341 possible ARM->Thumb calls. Also, these labels can be used
14342 as part of a computed goto or switch statement. eg gcc
14343 can generate code that looks like this:
14344
14345 ldr r2, [pc, .Laaa]
14346 lsl r3, r3, #2
14347 ldr r2, [r3, r2]
14348 mov pc, r2
14349
14350 .Lbbb: .word .Lxxx
14351 .Lccc: .word .Lyyy
14352 ..etc...
14353 .Laaa: .word Lbbb
14354
14355 The first instruction loads the address of the jump table.
14356 The second instruction converts a table index into a byte offset.
14357 The third instruction gets the jump address out of the table.
14358 The fourth instruction performs the jump.
14359
14360 If the address stored at .Laaa is that of a symbol which has the
14361 Thumb_Func bit set, then the linker will arrange for this address
14362 to have the bottom bit set, which in turn would mean that the
14363 address computation performed by the third instruction would end
14364 up with the bottom bit set. Since the ARM is capable of unaligned
14365 word loads, the instruction would then load the incorrect address
14366 out of the jump table, and chaos would ensue. */
14367 if (label_is_thumb_function_name
14368 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
14369 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
14370 {
14371 /* When the address of a Thumb function is taken the bottom
14372 bit of that address should be set. This will allow
14373 interworking between Arm and Thumb functions to work
14374 correctly. */
14375
14376 THUMB_SET_FUNC (sym, 1);
14377
14378 label_is_thumb_function_name = FALSE;
14379 }
14380
14381 dwarf2_emit_label (sym);
14382 }
14383
14384 int
14385 arm_data_in_code (void)
14386 {
14387 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
14388 {
14389 *input_line_pointer = '/';
14390 input_line_pointer += 5;
14391 *input_line_pointer = 0;
14392 return 1;
14393 }
14394
14395 return 0;
14396 }
14397
14398 char *
14399 arm_canonicalize_symbol_name (char * name)
14400 {
14401 int len;
14402
14403 if (thumb_mode && (len = strlen (name)) > 5
14404 && streq (name + len - 5, "/data"))
14405 *(name + len - 5) = 0;
14406
14407 return name;
14408 }
14409 \f
14410 /* Table of all register names defined by default. The user can
14411 define additional names with .req. Note that all register names
14412 should appear in both upper and lowercase variants. Some registers
14413 also have mixed-case names. */
14414
14415 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
14416 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
14417 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
14418 #define REGSET(p,t) \
14419 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
14420 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
14421 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
14422 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
14423 #define REGSETH(p,t) \
14424 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
14425 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
14426 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
14427 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
14428 #define REGSET2(p,t) \
14429 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
14430 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
14431 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
14432 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
14433
14434 static const struct reg_entry reg_names[] =
14435 {
14436 /* ARM integer registers. */
14437 REGSET(r, RN), REGSET(R, RN),
14438
14439 /* ATPCS synonyms. */
14440 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
14441 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
14442 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
14443
14444 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
14445 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
14446 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
14447
14448 /* Well-known aliases. */
14449 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
14450 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
14451
14452 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
14453 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
14454
14455 /* Coprocessor numbers. */
14456 REGSET(p, CP), REGSET(P, CP),
14457
14458 /* Coprocessor register numbers. The "cr" variants are for backward
14459 compatibility. */
14460 REGSET(c, CN), REGSET(C, CN),
14461 REGSET(cr, CN), REGSET(CR, CN),
14462
14463 /* FPA registers. */
14464 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
14465 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
14466
14467 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
14468 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
14469
14470 /* VFP SP registers. */
14471 REGSET(s,VFS), REGSET(S,VFS),
14472 REGSETH(s,VFS), REGSETH(S,VFS),
14473
14474 /* VFP DP Registers. */
14475 REGSET(d,VFD), REGSET(D,VFD),
14476 /* Extra Neon DP registers. */
14477 REGSETH(d,VFD), REGSETH(D,VFD),
14478
14479 /* Neon QP registers. */
14480 REGSET2(q,NQ), REGSET2(Q,NQ),
14481
14482 /* VFP control registers. */
14483 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
14484 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
14485 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
14486 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
14487 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
14488 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
14489
14490 /* Maverick DSP coprocessor registers. */
14491 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
14492 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
14493
14494 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
14495 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
14496 REGDEF(dspsc,0,DSPSC),
14497
14498 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
14499 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
14500 REGDEF(DSPSC,0,DSPSC),
14501
14502 /* iWMMXt data registers - p0, c0-15. */
14503 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
14504
14505 /* iWMMXt control registers - p1, c0-3. */
14506 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
14507 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
14508 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
14509 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
14510
14511 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
14512 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
14513 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
14514 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
14515 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
14516
14517 /* XScale accumulator registers. */
14518 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
14519 };
14520 #undef REGDEF
14521 #undef REGNUM
14522 #undef REGSET
14523
14524 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
14525 within psr_required_here. */
14526 static const struct asm_psr psrs[] =
14527 {
14528 /* Backward compatibility notation. Note that "all" is no longer
14529 truly all possible PSR bits. */
14530 {"all", PSR_c | PSR_f},
14531 {"flg", PSR_f},
14532 {"ctl", PSR_c},
14533
14534 /* Individual flags. */
14535 {"f", PSR_f},
14536 {"c", PSR_c},
14537 {"x", PSR_x},
14538 {"s", PSR_s},
14539 /* Combinations of flags. */
14540 {"fs", PSR_f | PSR_s},
14541 {"fx", PSR_f | PSR_x},
14542 {"fc", PSR_f | PSR_c},
14543 {"sf", PSR_s | PSR_f},
14544 {"sx", PSR_s | PSR_x},
14545 {"sc", PSR_s | PSR_c},
14546 {"xf", PSR_x | PSR_f},
14547 {"xs", PSR_x | PSR_s},
14548 {"xc", PSR_x | PSR_c},
14549 {"cf", PSR_c | PSR_f},
14550 {"cs", PSR_c | PSR_s},
14551 {"cx", PSR_c | PSR_x},
14552 {"fsx", PSR_f | PSR_s | PSR_x},
14553 {"fsc", PSR_f | PSR_s | PSR_c},
14554 {"fxs", PSR_f | PSR_x | PSR_s},
14555 {"fxc", PSR_f | PSR_x | PSR_c},
14556 {"fcs", PSR_f | PSR_c | PSR_s},
14557 {"fcx", PSR_f | PSR_c | PSR_x},
14558 {"sfx", PSR_s | PSR_f | PSR_x},
14559 {"sfc", PSR_s | PSR_f | PSR_c},
14560 {"sxf", PSR_s | PSR_x | PSR_f},
14561 {"sxc", PSR_s | PSR_x | PSR_c},
14562 {"scf", PSR_s | PSR_c | PSR_f},
14563 {"scx", PSR_s | PSR_c | PSR_x},
14564 {"xfs", PSR_x | PSR_f | PSR_s},
14565 {"xfc", PSR_x | PSR_f | PSR_c},
14566 {"xsf", PSR_x | PSR_s | PSR_f},
14567 {"xsc", PSR_x | PSR_s | PSR_c},
14568 {"xcf", PSR_x | PSR_c | PSR_f},
14569 {"xcs", PSR_x | PSR_c | PSR_s},
14570 {"cfs", PSR_c | PSR_f | PSR_s},
14571 {"cfx", PSR_c | PSR_f | PSR_x},
14572 {"csf", PSR_c | PSR_s | PSR_f},
14573 {"csx", PSR_c | PSR_s | PSR_x},
14574 {"cxf", PSR_c | PSR_x | PSR_f},
14575 {"cxs", PSR_c | PSR_x | PSR_s},
14576 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
14577 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
14578 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
14579 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
14580 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
14581 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
14582 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
14583 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
14584 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
14585 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
14586 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
14587 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
14588 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
14589 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
14590 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
14591 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
14592 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
14593 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
14594 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
14595 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
14596 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
14597 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
14598 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
14599 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
14600 };
14601
14602 /* Table of V7M psr names. */
14603 static const struct asm_psr v7m_psrs[] =
14604 {
14605 {"apsr", 0 }, {"APSR", 0 },
14606 {"iapsr", 1 }, {"IAPSR", 1 },
14607 {"eapsr", 2 }, {"EAPSR", 2 },
14608 {"psr", 3 }, {"PSR", 3 },
14609 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
14610 {"ipsr", 5 }, {"IPSR", 5 },
14611 {"epsr", 6 }, {"EPSR", 6 },
14612 {"iepsr", 7 }, {"IEPSR", 7 },
14613 {"msp", 8 }, {"MSP", 8 },
14614 {"psp", 9 }, {"PSP", 9 },
14615 {"primask", 16}, {"PRIMASK", 16},
14616 {"basepri", 17}, {"BASEPRI", 17},
14617 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
14618 {"faultmask", 19}, {"FAULTMASK", 19},
14619 {"control", 20}, {"CONTROL", 20}
14620 };
14621
14622 /* Table of all shift-in-operand names. */
14623 static const struct asm_shift_name shift_names [] =
14624 {
14625 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
14626 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
14627 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
14628 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
14629 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
14630 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
14631 };
14632
14633 /* Table of all explicit relocation names. */
14634 #ifdef OBJ_ELF
14635 static struct reloc_entry reloc_names[] =
14636 {
14637 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
14638 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
14639 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
14640 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
14641 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
14642 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
14643 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
14644 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
14645 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
14646 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
14647 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
14648 };
14649 #endif
14650
14651 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
14652 static const struct asm_cond conds[] =
14653 {
14654 {"eq", 0x0},
14655 {"ne", 0x1},
14656 {"cs", 0x2}, {"hs", 0x2},
14657 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
14658 {"mi", 0x4},
14659 {"pl", 0x5},
14660 {"vs", 0x6},
14661 {"vc", 0x7},
14662 {"hi", 0x8},
14663 {"ls", 0x9},
14664 {"ge", 0xa},
14665 {"lt", 0xb},
14666 {"gt", 0xc},
14667 {"le", 0xd},
14668 {"al", 0xe}
14669 };
14670
14671 static struct asm_barrier_opt barrier_opt_names[] =
14672 {
14673 { "sy", 0xf },
14674 { "un", 0x7 },
14675 { "st", 0xe },
14676 { "unst", 0x6 }
14677 };
14678
14679 /* Table of ARM-format instructions. */
14680
14681 /* Macros for gluing together operand strings. N.B. In all cases
14682 other than OPS0, the trailing OP_stop comes from default
14683 zero-initialization of the unspecified elements of the array. */
14684 #define OPS0() { OP_stop, }
14685 #define OPS1(a) { OP_##a, }
14686 #define OPS2(a,b) { OP_##a,OP_##b, }
14687 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
14688 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
14689 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
14690 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
14691
14692 /* These macros abstract out the exact format of the mnemonic table and
14693 save some repeated characters. */
14694
14695 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
14696 #define TxCE(mnem, op, top, nops, ops, ae, te) \
14697 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
14698 THUMB_VARIANT, do_##ae, do_##te }
14699
14700 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
14701 a T_MNEM_xyz enumerator. */
14702 #define TCE(mnem, aop, top, nops, ops, ae, te) \
14703 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
14704 #define tCE(mnem, aop, top, nops, ops, ae, te) \
14705 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14706
14707 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
14708 infix after the third character. */
14709 #define TxC3(mnem, op, top, nops, ops, ae, te) \
14710 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
14711 THUMB_VARIANT, do_##ae, do_##te }
14712 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
14713 { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
14714 THUMB_VARIANT, do_##ae, do_##te }
14715 #define TC3(mnem, aop, top, nops, ops, ae, te) \
14716 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
14717 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
14718 TxC3w(mnem, aop, 0x##top, nops, ops, ae, te)
14719 #define tC3(mnem, aop, top, nops, ops, ae, te) \
14720 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14721 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
14722 TxC3w(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14723
14724 /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
14725 appear in the condition table. */
14726 #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
14727 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14728 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
14729
14730 #define TxCM(m1, m2, op, top, nops, ops, ae, te) \
14731 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
14732 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
14733 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
14734 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
14735 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
14736 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
14737 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
14738 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
14739 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
14740 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
14741 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
14742 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
14743 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
14744 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
14745 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
14746 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
14747 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
14748 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
14749 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
14750
14751 #define TCM(m1,m2, aop, top, nops, ops, ae, te) \
14752 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
14753 #define tCM(m1,m2, aop, top, nops, ops, ae, te) \
14754 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
14755
14756 /* Mnemonic that cannot be conditionalized. The ARM condition-code
14757 field is still 0xE. Many of the Thumb variants can be executed
14758 conditionally, so this is checked separately. */
14759 #define TUE(mnem, op, top, nops, ops, ae, te) \
14760 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
14761 THUMB_VARIANT, do_##ae, do_##te }
14762
14763 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
14764 condition code field. */
14765 #define TUF(mnem, op, top, nops, ops, ae, te) \
14766 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
14767 THUMB_VARIANT, do_##ae, do_##te }
14768
14769 /* ARM-only variants of all the above. */
14770 #define CE(mnem, op, nops, ops, ae) \
14771 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14772
14773 #define C3(mnem, op, nops, ops, ae) \
14774 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14775
14776 /* Legacy mnemonics that always have conditional infix after the third
14777 character. */
14778 #define CL(mnem, op, nops, ops, ae) \
14779 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14780 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14781
14782 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
14783 #define cCE(mnem, op, nops, ops, ae) \
14784 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14785
14786 /* Legacy coprocessor instructions where conditional infix and conditional
14787 suffix are ambiguous. For consistency this includes all FPA instructions,
14788 not just the potentially ambiguous ones. */
14789 #define cCL(mnem, op, nops, ops, ae) \
14790 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14791 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14792
14793 /* Coprocessor, takes either a suffix or a position-3 infix
14794 (for an FPA corner case). */
14795 #define C3E(mnem, op, nops, ops, ae) \
14796 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
14797 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14798
14799 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
14800 { #m1 #m2 #m3, OPS##nops ops, \
14801 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14802 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14803
14804 #define CM(m1, m2, op, nops, ops, ae) \
14805 xCM_(m1, , m2, op, nops, ops, ae), \
14806 xCM_(m1, eq, m2, op, nops, ops, ae), \
14807 xCM_(m1, ne, m2, op, nops, ops, ae), \
14808 xCM_(m1, cs, m2, op, nops, ops, ae), \
14809 xCM_(m1, hs, m2, op, nops, ops, ae), \
14810 xCM_(m1, cc, m2, op, nops, ops, ae), \
14811 xCM_(m1, ul, m2, op, nops, ops, ae), \
14812 xCM_(m1, lo, m2, op, nops, ops, ae), \
14813 xCM_(m1, mi, m2, op, nops, ops, ae), \
14814 xCM_(m1, pl, m2, op, nops, ops, ae), \
14815 xCM_(m1, vs, m2, op, nops, ops, ae), \
14816 xCM_(m1, vc, m2, op, nops, ops, ae), \
14817 xCM_(m1, hi, m2, op, nops, ops, ae), \
14818 xCM_(m1, ls, m2, op, nops, ops, ae), \
14819 xCM_(m1, ge, m2, op, nops, ops, ae), \
14820 xCM_(m1, lt, m2, op, nops, ops, ae), \
14821 xCM_(m1, gt, m2, op, nops, ops, ae), \
14822 xCM_(m1, le, m2, op, nops, ops, ae), \
14823 xCM_(m1, al, m2, op, nops, ops, ae)
14824
14825 #define UE(mnem, op, nops, ops, ae) \
14826 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14827
14828 #define UF(mnem, op, nops, ops, ae) \
14829 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14830
14831 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
14832 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
14833 use the same encoding function for each. */
14834 #define NUF(mnem, op, nops, ops, enc) \
14835 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
14836 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14837
14838 /* Neon data processing, version which indirects through neon_enc_tab for
14839 the various overloaded versions of opcodes. */
14840 #define nUF(mnem, op, nops, ops, enc) \
14841 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \
14842 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14843
14844 /* Neon insn with conditional suffix for the ARM version, non-overloaded
14845 version. */
14846 #define NCE_tag(mnem, op, nops, ops, enc, tag) \
14847 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
14848 THUMB_VARIANT, do_##enc, do_##enc }
14849
14850 #define NCE(mnem, op, nops, ops, enc) \
14851 NCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14852
14853 #define NCEF(mnem, op, nops, ops, enc) \
14854 NCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14855
14856 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
14857 #define nCE_tag(mnem, op, nops, ops, enc, tag) \
14858 { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \
14859 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14860
14861 #define nCE(mnem, op, nops, ops, enc) \
14862 nCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14863
14864 #define nCEF(mnem, op, nops, ops, enc) \
14865 nCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14866
14867 #define do_0 0
14868
14869 /* Thumb-only, unconditional. */
14870 #define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
14871
14872 static const struct asm_opcode insns[] =
14873 {
14874 #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
14875 #define THUMB_VARIANT &arm_ext_v4t
14876 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
14877 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
14878 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
14879 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
14880 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
14881 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
14882 tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub),
14883 tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub),
14884 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
14885 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
14886 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
14887 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
14888 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
14889 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
14890 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
14891 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
14892
14893 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
14894 for setting PSR flag bits. They are obsolete in V6 and do not
14895 have Thumb equivalents. */
14896 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
14897 tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
14898 CL(tstp, 110f000, 2, (RR, SH), cmp),
14899 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
14900 tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
14901 CL(cmpp, 150f000, 2, (RR, SH), cmp),
14902 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
14903 tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
14904 CL(cmnp, 170f000, 2, (RR, SH), cmp),
14905
14906 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
14907 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
14908 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
14909 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
14910
14911 tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
14912 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
14913 tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst),
14914 tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
14915
14916 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14917 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14918 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14919 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14920 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14921 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14922
14923 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
14924 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
14925 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
14926 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
14927
14928 /* Pseudo ops. */
14929 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
14930 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
14931 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
14932
14933 /* Thumb-compatibility pseudo ops. */
14934 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
14935 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
14936 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
14937 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
14938 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
14939 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
14940 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
14941 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
14942 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
14943 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
14944 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
14945 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
14946
14947 /* These may simplify to neg. */
14948 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
14949 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
14950
14951 #undef THUMB_VARIANT
14952 #define THUMB_VARIANT &arm_ext_v6
14953 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
14954
14955 /* V1 instructions with no Thumb analogue prior to V6T2. */
14956 #undef THUMB_VARIANT
14957 #define THUMB_VARIANT &arm_ext_v6t2
14958 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
14959 TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
14960 CL(teqp, 130f000, 2, (RR, SH), cmp),
14961
14962 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
14963 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
14964 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
14965 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
14966
14967 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14968 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14969
14970 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14971 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14972
14973 /* V1 instructions with no Thumb analogue at all. */
14974 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
14975 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
14976
14977 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
14978 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
14979 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
14980 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
14981 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
14982 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
14983 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
14984 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
14985
14986 #undef ARM_VARIANT
14987 #define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
14988 #undef THUMB_VARIANT
14989 #define THUMB_VARIANT &arm_ext_v4t
14990 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
14991 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
14992
14993 #undef THUMB_VARIANT
14994 #define THUMB_VARIANT &arm_ext_v6t2
14995 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
14996 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
14997
14998 /* Generic coprocessor instructions. */
14999 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
15000 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15001 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15002 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15003 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15004 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15005 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15006
15007 #undef ARM_VARIANT
15008 #define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
15009 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15010 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15011
15012 #undef ARM_VARIANT
15013 #define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
15014 TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
15015 TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
15016
15017 #undef ARM_VARIANT
15018 #define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
15019 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15020 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15021 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15022 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15023 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15024 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15025 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15026 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15027
15028 #undef ARM_VARIANT
15029 #define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
15030 #undef THUMB_VARIANT
15031 #define THUMB_VARIANT &arm_ext_v4t
15032 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15033 tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15034 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15035 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15036 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15037 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15038
15039 #undef ARM_VARIANT
15040 #define ARM_VARIANT &arm_ext_v4t_5
15041 /* ARM Architecture 4T. */
15042 /* Note: bx (and blx) are required on V5, even if the processor does
15043 not support Thumb. */
15044 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
15045
15046 #undef ARM_VARIANT
15047 #define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
15048 #undef THUMB_VARIANT
15049 #define THUMB_VARIANT &arm_ext_v5t
15050 /* Note: blx has 2 variants; the .value coded here is for
15051 BLX(2). Only this variant has conditional execution. */
15052 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
15053 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
15054
15055 #undef THUMB_VARIANT
15056 #define THUMB_VARIANT &arm_ext_v6t2
15057 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
15058 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15059 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15060 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15061 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15062 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
15063 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15064 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15065
15066 #undef ARM_VARIANT
15067 #define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
15068 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15069 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15070 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15071 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15072
15073 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15074 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15075
15076 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15077 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15078 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15079 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15080
15081 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15082 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15083 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15084 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15085
15086 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15087 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15088
15089 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15090 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15091 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15092 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15093
15094 #undef ARM_VARIANT
15095 #define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
15096 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
15097 TC3(ldrd, 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
15098 TC3(strd, 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
15099
15100 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15101 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15102
15103 #undef ARM_VARIANT
15104 #define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
15105 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
15106
15107 #undef ARM_VARIANT
15108 #define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
15109 #undef THUMB_VARIANT
15110 #define THUMB_VARIANT &arm_ext_v6
15111 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
15112 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
15113 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15114 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15115 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15116 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15117 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15118 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15119 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15120 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
15121
15122 #undef THUMB_VARIANT
15123 #define THUMB_VARIANT &arm_ext_v6t2
15124 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
15125 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
15126 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15127 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15128
15129 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
15130 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
15131
15132 /* ARM V6 not included in V7M (eg. integer SIMD). */
15133 #undef THUMB_VARIANT
15134 #define THUMB_VARIANT &arm_ext_v6_notm
15135 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
15136 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
15137 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
15138 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15139 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15140 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15141 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15142 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15143 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15144 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15145 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15146 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15147 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15148 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15149 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15150 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15151 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15152 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15153 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15154 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15155 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15156 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15157 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15158 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15159 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15160 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15161 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15162 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15163 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15164 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15165 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15166 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15167 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15168 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15169 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15170 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15171 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15172 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15173 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15174 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15175 UF(rfeib, 9900a00, 1, (RRw), rfe),
15176 UF(rfeda, 8100a00, 1, (RRw), rfe),
15177 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15178 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15179 UF(rfefa, 9900a00, 1, (RRw), rfe),
15180 UF(rfeea, 8100a00, 1, (RRw), rfe),
15181 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15182 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15183 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15184 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15185 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15186 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15187 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15188 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15189 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15190 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15191 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15192 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15193 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15194 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15195 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15196 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15197 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15198 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15199 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15200 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15201 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15202 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15203 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15204 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15205 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15206 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15207 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15208 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15209 TUF(srsia, 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
15210 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
15211 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
15212 TUF(srsdb, 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
15213 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
15214 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
15215 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15216 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15217 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
15218
15219 #undef ARM_VARIANT
15220 #define ARM_VARIANT &arm_ext_v6k
15221 #undef THUMB_VARIANT
15222 #define THUMB_VARIANT &arm_ext_v6k
15223 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
15224 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
15225 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
15226 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
15227
15228 #undef THUMB_VARIANT
15229 #define THUMB_VARIANT &arm_ext_v6_notm
15230 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
15231 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
15232
15233 #undef THUMB_VARIANT
15234 #define THUMB_VARIANT &arm_ext_v6t2
15235 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15236 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15237 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15238 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15239 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
15240
15241 #undef ARM_VARIANT
15242 #define ARM_VARIANT &arm_ext_v6z
15243 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
15244
15245 #undef ARM_VARIANT
15246 #define ARM_VARIANT &arm_ext_v6t2
15247 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
15248 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
15249 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15250 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15251
15252 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
15253 TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
15254 TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
15255 TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
15256
15257 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15258 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15259 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15260 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15261
15262 UT(cbnz, b900, 2, (RR, EXP), t_cbz),
15263 UT(cbz, b100, 2, (RR, EXP), t_cbz),
15264 /* ARM does not really have an IT instruction, so always allow it. */
15265 #undef ARM_VARIANT
15266 #define ARM_VARIANT &arm_ext_v1
15267 TUE(it, 0, bf08, 1, (COND), it, t_it),
15268 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
15269 TUE(ite, 0, bf04, 1, (COND), it, t_it),
15270 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
15271 TUE(itet, 0, bf06, 1, (COND), it, t_it),
15272 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
15273 TUE(itee, 0, bf02, 1, (COND), it, t_it),
15274 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
15275 TUE(itett, 0, bf07, 1, (COND), it, t_it),
15276 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
15277 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
15278 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
15279 TUE(itete, 0, bf05, 1, (COND), it, t_it),
15280 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
15281 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
15282
15283 /* Thumb2 only instructions. */
15284 #undef ARM_VARIANT
15285 #define ARM_VARIANT NULL
15286
15287 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15288 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15289 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
15290 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
15291
15292 /* Thumb-2 hardware division instructions (R and M profiles only). */
15293 #undef THUMB_VARIANT
15294 #define THUMB_VARIANT &arm_ext_div
15295 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
15296 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
15297
15298 /* ARM V7 instructions. */
15299 #undef ARM_VARIANT
15300 #define ARM_VARIANT &arm_ext_v7
15301 #undef THUMB_VARIANT
15302 #define THUMB_VARIANT &arm_ext_v7
15303 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
15304 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
15305 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
15306 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
15307 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
15308
15309 #undef ARM_VARIANT
15310 #define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
15311 cCE(wfs, e200110, 1, (RR), rd),
15312 cCE(rfs, e300110, 1, (RR), rd),
15313 cCE(wfc, e400110, 1, (RR), rd),
15314 cCE(rfc, e500110, 1, (RR), rd),
15315
15316 cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
15317 cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
15318 cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
15319 cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
15320
15321 cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
15322 cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
15323 cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
15324 cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
15325
15326 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
15327 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
15328 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
15329 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
15330 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
15331 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
15332 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
15333 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
15334 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
15335 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
15336 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
15337 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
15338
15339 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
15340 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
15341 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
15342 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
15343 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
15344 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
15345 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
15346 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
15347 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
15348 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
15349 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
15350 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
15351
15352 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
15353 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
15354 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
15355 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
15356 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
15357 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
15358 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
15359 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
15360 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
15361 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
15362 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
15363 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
15364
15365 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
15366 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
15367 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
15368 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
15369 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
15370 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
15371 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
15372 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
15373 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
15374 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
15375 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
15376 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
15377
15378 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
15379 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
15380 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
15381 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
15382 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
15383 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
15384 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
15385 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
15386 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
15387 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
15388 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
15389 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
15390
15391 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
15392 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
15393 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
15394 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
15395 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
15396 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
15397 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
15398 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
15399 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
15400 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
15401 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
15402 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
15403
15404 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
15405 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
15406 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
15407 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
15408 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
15409 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
15410 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
15411 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
15412 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
15413 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
15414 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
15415 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
15416
15417 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
15418 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
15419 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
15420 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
15421 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
15422 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
15423 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
15424 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
15425 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
15426 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
15427 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
15428 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
15429
15430 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
15431 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
15432 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
15433 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
15434 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
15435 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
15436 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
15437 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
15438 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
15439 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
15440 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
15441 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
15442
15443 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
15444 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
15445 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
15446 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
15447 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
15448 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
15449 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
15450 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
15451 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
15452 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
15453 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
15454 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
15455
15456 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
15457 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
15458 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
15459 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
15460 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
15461 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
15462 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
15463 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
15464 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
15465 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
15466 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
15467 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
15468
15469 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
15470 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
15471 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
15472 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
15473 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
15474 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
15475 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
15476 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
15477 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
15478 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
15479 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
15480 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
15481
15482 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
15483 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
15484 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
15485 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
15486 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
15487 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
15488 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
15489 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
15490 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
15491 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
15492 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
15493 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
15494
15495 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
15496 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
15497 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
15498 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
15499 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
15500 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
15501 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
15502 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
15503 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
15504 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
15505 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
15506 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
15507
15508 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
15509 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
15510 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
15511 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
15512 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
15513 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
15514 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
15515 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
15516 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
15517 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
15518 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
15519 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
15520
15521 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
15522 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
15523 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
15524 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
15525 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
15526 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
15527 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
15528 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
15529 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
15530 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
15531 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
15532 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
15533
15534 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
15535 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
15536 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
15537 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
15538 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
15539 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15540 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15541 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15542 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
15543 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
15544 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
15545 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
15546
15547 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
15548 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
15549 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
15550 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
15551 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
15552 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15553 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15554 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15555 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
15556 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
15557 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
15558 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
15559
15560 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
15561 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
15562 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
15563 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
15564 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
15565 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15566 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15567 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15568 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
15569 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
15570 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
15571 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
15572
15573 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
15574 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
15575 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
15576 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
15577 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
15578 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15579 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15580 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15581 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
15582 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
15583 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
15584 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
15585
15586 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
15587 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
15588 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
15589 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
15590 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
15591 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15592 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15593 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15594 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
15595 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
15596 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
15597 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
15598
15599 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
15600 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
15601 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
15602 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
15603 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
15604 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15605 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15606 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15607 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
15608 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
15609 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
15610 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
15611
15612 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
15613 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
15614 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
15615 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
15616 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
15617 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15618 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15619 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15620 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
15621 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
15622 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
15623 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
15624
15625 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
15626 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
15627 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
15628 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
15629 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
15630 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15631 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15632 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15633 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
15634 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
15635 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
15636 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
15637
15638 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
15639 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
15640 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
15641 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
15642 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
15643 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15644 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15645 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15646 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
15647 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
15648 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
15649 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
15650
15651 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
15652 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
15653 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
15654 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
15655 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
15656 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15657 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15658 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15659 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
15660 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
15661 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
15662 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
15663
15664 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15665 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15666 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15667 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15668 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15669 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15670 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15671 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15672 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15673 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15674 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15675 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15676
15677 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15678 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15679 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15680 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15681 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15682 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15683 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15684 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15685 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15686 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15687 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15688 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15689
15690 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15691 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15692 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15693 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15694 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15695 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15696 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15697 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15698 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15699 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15700 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15701 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15702
15703 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
15704 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
15705 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
15706 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
15707
15708 cCL(flts, e000110, 2, (RF, RR), rn_rd),
15709 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
15710 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
15711 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
15712 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
15713 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
15714 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
15715 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
15716 cCL(flte, e080110, 2, (RF, RR), rn_rd),
15717 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
15718 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
15719 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
15720
15721 /* The implementation of the FIX instruction is broken on some
15722 assemblers, in that it accepts a precision specifier as well as a
15723 rounding specifier, despite the fact that this is meaningless.
15724 To be more compatible, we accept it as well, though of course it
15725 does not set any bits. */
15726 cCE(fix, e100110, 2, (RR, RF), rd_rm),
15727 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
15728 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
15729 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
15730 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
15731 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
15732 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
15733 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
15734 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
15735 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
15736 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
15737 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
15738 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
15739
15740 /* Instructions that were new with the real FPA, call them V2. */
15741 #undef ARM_VARIANT
15742 #define ARM_VARIANT &fpu_fpa_ext_v2
15743 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15744 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15745 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15746 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15747 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15748 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15749
15750 #undef ARM_VARIANT
15751 #define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
15752 /* Moves and type conversions. */
15753 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
15754 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
15755 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
15756 cCE(fmstat, ef1fa10, 0, (), noargs),
15757 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
15758 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
15759 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
15760 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15761 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
15762 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15763 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
15764 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
15765
15766 /* Memory operations. */
15767 cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15768 cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15769 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15770 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15771 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15772 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15773 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15774 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15775 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15776 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15777 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15778 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15779 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15780 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15781 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15782 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15783 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15784 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15785
15786 /* Monadic operations. */
15787 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
15788 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
15789 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
15790
15791 /* Dyadic operations. */
15792 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15793 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15794 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15795 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15796 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15797 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15798 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15799 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15800 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15801
15802 /* Comparisons. */
15803 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
15804 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
15805 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
15806 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
15807
15808 #undef ARM_VARIANT
15809 #define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
15810 /* Moves and type conversions. */
15811 cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15812 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15813 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15814 cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
15815 cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
15816 cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
15817 cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
15818 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15819 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
15820 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15821 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15822 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15823 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15824
15825 /* Memory operations. */
15826 cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
15827 cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
15828 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15829 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15830 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15831 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15832 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15833 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15834 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15835 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15836
15837 /* Monadic operations. */
15838 cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15839 cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15840 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15841
15842 /* Dyadic operations. */
15843 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15844 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15845 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15846 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15847 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15848 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15849 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15850 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15851 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15852
15853 /* Comparisons. */
15854 cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15855 cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd),
15856 cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15857 cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd),
15858
15859 #undef ARM_VARIANT
15860 #define ARM_VARIANT &fpu_vfp_ext_v2
15861 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
15862 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
15863 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
15864 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
15865
15866 /* Instructions which may belong to either the Neon or VFP instruction sets.
15867 Individual encoder functions perform additional architecture checks. */
15868 #undef ARM_VARIANT
15869 #define ARM_VARIANT &fpu_vfp_ext_v1xd
15870 #undef THUMB_VARIANT
15871 #define THUMB_VARIANT &fpu_vfp_ext_v1xd
15872 /* These mnemonics are unique to VFP. */
15873 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
15874 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
15875 nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15876 nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15877 nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15878 nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15879 nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15880 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
15881 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
15882 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
15883
15884 /* Mnemonics shared by Neon and VFP. */
15885 nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
15886 nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15887 nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15888
15889 nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15890 nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15891
15892 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15893 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15894
15895 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15896 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15897 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15898 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15899 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15900 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15901 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
15902 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
15903
15904 nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
15905
15906 /* NOTE: All VMOV encoding is special-cased! */
15907 NCE(vmov, 0, 1, (VMOV), neon_mov),
15908 NCE(vmovq, 0, 1, (VMOV), neon_mov),
15909
15910 #undef THUMB_VARIANT
15911 #define THUMB_VARIANT &fpu_neon_ext_v1
15912 #undef ARM_VARIANT
15913 #define ARM_VARIANT &fpu_neon_ext_v1
15914 /* Data processing with three registers of the same length. */
15915 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
15916 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
15917 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
15918 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15919 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15920 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15921 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15922 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15923 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15924 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
15925 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15926 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15927 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15928 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15929 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15930 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
15931 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15932 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
15933 /* If not immediate, fall back to neon_dyadic_i64_su.
15934 shl_imm should accept I8 I16 I32 I64,
15935 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
15936 nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
15937 nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
15938 nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
15939 nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
15940 /* Logic ops, types optional & ignored. */
15941 nUF(vand, vand, 2, (RNDQ, NILO), neon_logic),
15942 nUF(vandq, vand, 2, (RNQ, NILO), neon_logic),
15943 nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic),
15944 nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic),
15945 nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic),
15946 nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic),
15947 nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic),
15948 nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic),
15949 nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
15950 nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
15951 /* Bitfield ops, untyped. */
15952 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15953 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15954 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15955 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15956 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15957 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15958 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
15959 nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15960 nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15961 nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15962 nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15963 nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15964 nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15965 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
15966 back to neon_dyadic_if_su. */
15967 nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
15968 nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
15969 nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
15970 nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
15971 nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
15972 nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
15973 nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
15974 nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
15975 /* Comparison. Type I8 I16 I32 F32. */
15976 nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
15977 nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
15978 /* As above, D registers only. */
15979 nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
15980 nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
15981 /* Int and float variants, signedness unimportant. */
15982 nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
15983 nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
15984 nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
15985 /* Add/sub take types I8 I16 I32 I64 F32. */
15986 nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
15987 nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
15988 /* vtst takes sizes 8, 16, 32. */
15989 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
15990 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
15991 /* VMUL takes I8 I16 I32 F32 P8. */
15992 nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
15993 /* VQD{R}MULH takes S16 S32. */
15994 nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
15995 nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
15996 nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
15997 nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
15998 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
15999 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
16000 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16001 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
16002 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16003 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
16004 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16005 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
16006 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16007 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16008 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16009 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16010
16011 /* Two address, int/float. Types S8 S16 S32 F32. */
16012 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
16013 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
16014
16015 /* Data processing with two registers and a shift amount. */
16016 /* Right shifts, and variants with rounding.
16017 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
16018 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16019 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16020 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16021 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16022 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16023 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16024 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16025 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16026 /* Shift and insert. Sizes accepted 8 16 32 64. */
16027 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
16028 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
16029 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
16030 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
16031 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
16032 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
16033 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
16034 /* Right shift immediate, saturating & narrowing, with rounding variants.
16035 Types accepted S16 S32 S64 U16 U32 U64. */
16036 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16037 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16038 /* As above, unsigned. Types accepted S16 S32 S64. */
16039 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16040 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16041 /* Right shift narrowing. Types accepted I16 I32 I64. */
16042 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16043 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16044 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
16045 nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll),
16046 /* CVT with optional immediate for fixed-point variant. */
16047 nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
16048
16049 nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
16050 nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
16051
16052 /* Data processing, three registers of different lengths. */
16053 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
16054 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
16055 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
16056 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
16057 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
16058 /* If not scalar, fall back to neon_dyadic_long.
16059 Vector types as above, scalar types S16 S32 U16 U32. */
16060 nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16061 nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16062 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
16063 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16064 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16065 /* Dyadic, narrowing insns. Types I16 I32 I64. */
16066 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16067 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16068 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16069 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16070 /* Saturating doubling multiplies. Types S16 S32. */
16071 nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16072 nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16073 nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16074 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
16075 S16 S32 U16 U32. */
16076 nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
16077
16078 /* Extract. Size 8. */
16079 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
16080 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
16081
16082 /* Two registers, miscellaneous. */
16083 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
16084 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
16085 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
16086 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
16087 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
16088 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
16089 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
16090 /* Vector replicate. Sizes 8 16 32. */
16091 nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup),
16092 nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup),
16093 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
16094 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
16095 /* VMOVN. Types I16 I32 I64. */
16096 nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn),
16097 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
16098 nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn),
16099 /* VQMOVUN. Types S16 S32 S64. */
16100 nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun),
16101 /* VZIP / VUZP. Sizes 8 16 32. */
16102 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
16103 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
16104 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
16105 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
16106 /* VQABS / VQNEG. Types S8 S16 S32. */
16107 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16108 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
16109 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16110 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
16111 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
16112 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
16113 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
16114 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
16115 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
16116 /* Reciprocal estimates. Types U32 F32. */
16117 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
16118 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
16119 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
16120 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
16121 /* VCLS. Types S8 S16 S32. */
16122 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
16123 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
16124 /* VCLZ. Types I8 I16 I32. */
16125 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
16126 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
16127 /* VCNT. Size 8. */
16128 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
16129 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
16130 /* Two address, untyped. */
16131 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
16132 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
16133 /* VTRN. Sizes 8 16 32. */
16134 nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn),
16135 nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn),
16136
16137 /* Table lookup. Size 8. */
16138 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16139 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16140
16141 #undef THUMB_VARIANT
16142 #define THUMB_VARIANT &fpu_vfp_v3_or_neon_ext
16143 #undef ARM_VARIANT
16144 #define ARM_VARIANT &fpu_vfp_v3_or_neon_ext
16145 /* Neon element/structure load/store. */
16146 nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16147 nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16148 nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16149 nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16150 nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16151 nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16152 nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16153 nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16154
16155 #undef THUMB_VARIANT
16156 #define THUMB_VARIANT &fpu_vfp_ext_v3
16157 #undef ARM_VARIANT
16158 #define ARM_VARIANT &fpu_vfp_ext_v3
16159 cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const),
16160 cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const),
16161 cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16162 cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16163 cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16164 cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16165 cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16166 cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16167 cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16168 cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16169 cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16170 cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16171 cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16172 cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16173 cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16174 cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16175 cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16176 cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16177
16178 #undef THUMB_VARIANT
16179 #undef ARM_VARIANT
16180 #define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
16181 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16182 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16183 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16184 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16185 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16186 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16187 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
16188 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
16189
16190 #undef ARM_VARIANT
16191 #define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
16192 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
16193 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
16194 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
16195 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
16196 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
16197 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
16198 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
16199 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
16200 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
16201 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16202 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16203 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16204 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16205 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16206 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16207 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16208 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16209 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16210 cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd),
16211 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
16212 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16213 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16214 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16215 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16216 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16217 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16218 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
16219 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
16220 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
16221 cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn),
16222 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
16223 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
16224 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
16225 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
16226 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
16227 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
16228 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
16229 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16230 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16231 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16232 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16233 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16234 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16235 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16236 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16237 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16238 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
16239 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16240 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16241 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16242 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16243 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16244 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16245 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16246 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16247 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16248 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16249 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16250 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16251 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16252 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16253 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16254 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16255 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16256 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16257 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16258 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16259 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16260 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16261 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16262 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16263 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16264 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16265 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16266 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16267 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16268 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16269 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16270 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16271 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16272 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16273 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16274 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16275 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16276 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16277 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16278 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16279 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16280 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
16281 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16282 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16283 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16284 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16285 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16286 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16287 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16288 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16289 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16290 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16291 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16292 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16293 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16294 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16295 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16296 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16297 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16298 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16299 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16300 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16301 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16302 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
16303 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16304 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16305 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16306 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16307 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16308 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16309 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16310 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16311 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16312 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16313 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16314 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16315 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16316 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16317 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16318 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16319 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16320 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16321 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16322 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16323 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16324 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16325 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16326 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16327 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16328 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16329 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16330 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16331 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16332 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16333 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16334 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
16335 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
16336 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
16337 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
16338 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
16339 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
16340 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16341 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16342 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16343 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
16344 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
16345 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
16346 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
16347 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
16348 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
16349 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16350 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16351 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16352 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16353 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
16354
16355 #undef ARM_VARIANT
16356 #define ARM_VARIANT &arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
16357 cCE(torvscb, e13f190, 1, (RR), iwmmxt_tandorc),
16358 cCE(torvsch, e53f190, 1, (RR), iwmmxt_tandorc),
16359 cCE(torvscw, e93f190, 1, (RR), iwmmxt_tandorc),
16360 cCE(wabsb, e2001c0, 2, (RIWR, RIWR), rd_rn),
16361 cCE(wabsh, e6001c0, 2, (RIWR, RIWR), rd_rn),
16362 cCE(wabsw, ea001c0, 2, (RIWR, RIWR), rd_rn),
16363 cCE(wabsdiffb, e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16364 cCE(wabsdiffh, e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16365 cCE(wabsdiffw, e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16366 cCE(waddbhusl, e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16367 cCE(waddbhusm, e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16368 cCE(waddhc, e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16369 cCE(waddwc, ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16370 cCE(waddsubhx, ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16371 cCE(wavg4, e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16372 cCE(wavg4r, e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16373 cCE(wmaddsn, ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16374 cCE(wmaddsx, eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16375 cCE(wmaddun, ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16376 cCE(wmaddux, e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16377 cCE(wmerge, e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
16378 cCE(wmiabb, e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16379 cCE(wmiabt, e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16380 cCE(wmiatb, e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16381 cCE(wmiatt, e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16382 cCE(wmiabbn, e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16383 cCE(wmiabtn, e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16384 cCE(wmiatbn, e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16385 cCE(wmiattn, e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16386 cCE(wmiawbb, e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16387 cCE(wmiawbt, e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16388 cCE(wmiawtb, ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16389 cCE(wmiawtt, eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16390 cCE(wmiawbbn, ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16391 cCE(wmiawbtn, ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16392 cCE(wmiawtbn, ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16393 cCE(wmiawttn, ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16394 cCE(wmulsmr, ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16395 cCE(wmulumr, ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16396 cCE(wmulwumr, ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16397 cCE(wmulwsmr, ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16398 cCE(wmulwum, ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16399 cCE(wmulwsm, ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16400 cCE(wmulwl, eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16401 cCE(wqmiabb, e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16402 cCE(wqmiabt, e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16403 cCE(wqmiatb, ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16404 cCE(wqmiatt, eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16405 cCE(wqmiabbn, ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16406 cCE(wqmiabtn, ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16407 cCE(wqmiatbn, ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16408 cCE(wqmiattn, ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16409 cCE(wqmulm, e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16410 cCE(wqmulmr, e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16411 cCE(wqmulwm, ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16412 cCE(wqmulwmr, ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16413 cCE(wsubaddhx, ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16414
16415 #undef ARM_VARIANT
16416 #define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
16417 cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16418 cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16419 cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16420 cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
16421 cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16422 cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16423 cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16424 cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
16425 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
16426 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
16427 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
16428 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
16429 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
16430 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
16431 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
16432 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
16433 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
16434 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
16435 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
16436 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
16437 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
16438 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
16439 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
16440 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
16441 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
16442 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
16443 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
16444 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
16445 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
16446 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
16447 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
16448 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
16449 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
16450 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
16451 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
16452 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
16453 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
16454 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
16455 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
16456 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
16457 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
16458 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
16459 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
16460 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
16461 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
16462 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
16463 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
16464 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
16465 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
16466 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
16467 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
16468 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
16469 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
16470 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
16471 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
16472 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
16473 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
16474 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
16475 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
16476 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
16477 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
16478 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
16479 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
16480 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
16481 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16482 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16483 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16484 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16485 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16486 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16487 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16488 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16489 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16490 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16491 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
16492 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
16493 };
16494 #undef ARM_VARIANT
16495 #undef THUMB_VARIANT
16496 #undef TCE
16497 #undef TCM
16498 #undef TUE
16499 #undef TUF
16500 #undef TCC
16501 #undef cCE
16502 #undef cCL
16503 #undef C3E
16504 #undef CE
16505 #undef CM
16506 #undef UE
16507 #undef UF
16508 #undef UT
16509 #undef NUF
16510 #undef nUF
16511 #undef NCE
16512 #undef nCE
16513 #undef OPS0
16514 #undef OPS1
16515 #undef OPS2
16516 #undef OPS3
16517 #undef OPS4
16518 #undef OPS5
16519 #undef OPS6
16520 #undef do_0
16521 \f
16522 /* MD interface: bits in the object file. */
16523
16524 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
16525 for use in the a.out file, and stores them in the array pointed to by buf.
16526 This knows about the endian-ness of the target machine and does
16527 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
16528 2 (short) and 4 (long) Floating numbers are put out as a series of
16529 LITTLENUMS (shorts, here at least). */
16530
16531 void
16532 md_number_to_chars (char * buf, valueT val, int n)
16533 {
16534 if (target_big_endian)
16535 number_to_chars_bigendian (buf, val, n);
16536 else
16537 number_to_chars_littleendian (buf, val, n);
16538 }
16539
16540 static valueT
16541 md_chars_to_number (char * buf, int n)
16542 {
16543 valueT result = 0;
16544 unsigned char * where = (unsigned char *) buf;
16545
16546 if (target_big_endian)
16547 {
16548 while (n--)
16549 {
16550 result <<= 8;
16551 result |= (*where++ & 255);
16552 }
16553 }
16554 else
16555 {
16556 while (n--)
16557 {
16558 result <<= 8;
16559 result |= (where[n] & 255);
16560 }
16561 }
16562
16563 return result;
16564 }
16565
16566 /* MD interface: Sections. */
16567
16568 /* Estimate the size of a frag before relaxing. Assume everything fits in
16569 2 bytes. */
16570
16571 int
16572 md_estimate_size_before_relax (fragS * fragp,
16573 segT segtype ATTRIBUTE_UNUSED)
16574 {
16575 fragp->fr_var = 2;
16576 return 2;
16577 }
16578
16579 /* Convert a machine dependent frag. */
16580
16581 void
16582 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
16583 {
16584 unsigned long insn;
16585 unsigned long old_op;
16586 char *buf;
16587 expressionS exp;
16588 fixS *fixp;
16589 int reloc_type;
16590 int pc_rel;
16591 int opcode;
16592
16593 buf = fragp->fr_literal + fragp->fr_fix;
16594
16595 old_op = bfd_get_16(abfd, buf);
16596 if (fragp->fr_symbol) {
16597 exp.X_op = O_symbol;
16598 exp.X_add_symbol = fragp->fr_symbol;
16599 } else {
16600 exp.X_op = O_constant;
16601 }
16602 exp.X_add_number = fragp->fr_offset;
16603 opcode = fragp->fr_subtype;
16604 switch (opcode)
16605 {
16606 case T_MNEM_ldr_pc:
16607 case T_MNEM_ldr_pc2:
16608 case T_MNEM_ldr_sp:
16609 case T_MNEM_str_sp:
16610 case T_MNEM_ldr:
16611 case T_MNEM_ldrb:
16612 case T_MNEM_ldrh:
16613 case T_MNEM_str:
16614 case T_MNEM_strb:
16615 case T_MNEM_strh:
16616 if (fragp->fr_var == 4)
16617 {
16618 insn = THUMB_OP32(opcode);
16619 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
16620 {
16621 insn |= (old_op & 0x700) << 4;
16622 }
16623 else
16624 {
16625 insn |= (old_op & 7) << 12;
16626 insn |= (old_op & 0x38) << 13;
16627 }
16628 insn |= 0x00000c00;
16629 put_thumb32_insn (buf, insn);
16630 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
16631 }
16632 else
16633 {
16634 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
16635 }
16636 pc_rel = (opcode == T_MNEM_ldr_pc2);
16637 break;
16638 case T_MNEM_adr:
16639 if (fragp->fr_var == 4)
16640 {
16641 insn = THUMB_OP32 (opcode);
16642 insn |= (old_op & 0xf0) << 4;
16643 put_thumb32_insn (buf, insn);
16644 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
16645 }
16646 else
16647 {
16648 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16649 exp.X_add_number -= 4;
16650 }
16651 pc_rel = 1;
16652 break;
16653 case T_MNEM_mov:
16654 case T_MNEM_movs:
16655 case T_MNEM_cmp:
16656 case T_MNEM_cmn:
16657 if (fragp->fr_var == 4)
16658 {
16659 int r0off = (opcode == T_MNEM_mov
16660 || opcode == T_MNEM_movs) ? 0 : 8;
16661 insn = THUMB_OP32 (opcode);
16662 insn = (insn & 0xe1ffffff) | 0x10000000;
16663 insn |= (old_op & 0x700) << r0off;
16664 put_thumb32_insn (buf, insn);
16665 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16666 }
16667 else
16668 {
16669 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
16670 }
16671 pc_rel = 0;
16672 break;
16673 case T_MNEM_b:
16674 if (fragp->fr_var == 4)
16675 {
16676 insn = THUMB_OP32(opcode);
16677 put_thumb32_insn (buf, insn);
16678 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
16679 }
16680 else
16681 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
16682 pc_rel = 1;
16683 break;
16684 case T_MNEM_bcond:
16685 if (fragp->fr_var == 4)
16686 {
16687 insn = THUMB_OP32(opcode);
16688 insn |= (old_op & 0xf00) << 14;
16689 put_thumb32_insn (buf, insn);
16690 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
16691 }
16692 else
16693 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
16694 pc_rel = 1;
16695 break;
16696 case T_MNEM_add_sp:
16697 case T_MNEM_add_pc:
16698 case T_MNEM_inc_sp:
16699 case T_MNEM_dec_sp:
16700 if (fragp->fr_var == 4)
16701 {
16702 /* ??? Choose between add and addw. */
16703 insn = THUMB_OP32 (opcode);
16704 insn |= (old_op & 0xf0) << 4;
16705 put_thumb32_insn (buf, insn);
16706 if (opcode == T_MNEM_add_pc)
16707 reloc_type = BFD_RELOC_ARM_T32_IMM12;
16708 else
16709 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16710 }
16711 else
16712 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16713 pc_rel = 0;
16714 break;
16715
16716 case T_MNEM_addi:
16717 case T_MNEM_addis:
16718 case T_MNEM_subi:
16719 case T_MNEM_subis:
16720 if (fragp->fr_var == 4)
16721 {
16722 insn = THUMB_OP32 (opcode);
16723 insn |= (old_op & 0xf0) << 4;
16724 insn |= (old_op & 0xf) << 16;
16725 put_thumb32_insn (buf, insn);
16726 if (insn & (1 << 20))
16727 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16728 else
16729 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16730 }
16731 else
16732 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16733 pc_rel = 0;
16734 break;
16735 default:
16736 abort();
16737 }
16738 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
16739 reloc_type);
16740 fixp->fx_file = fragp->fr_file;
16741 fixp->fx_line = fragp->fr_line;
16742 fragp->fr_fix += fragp->fr_var;
16743 }
16744
16745 /* Return the size of a relaxable immediate operand instruction.
16746 SHIFT and SIZE specify the form of the allowable immediate. */
16747 static int
16748 relax_immediate (fragS *fragp, int size, int shift)
16749 {
16750 offsetT offset;
16751 offsetT mask;
16752 offsetT low;
16753
16754 /* ??? Should be able to do better than this. */
16755 if (fragp->fr_symbol)
16756 return 4;
16757
16758 low = (1 << shift) - 1;
16759 mask = (1 << (shift + size)) - (1 << shift);
16760 offset = fragp->fr_offset;
16761 /* Force misaligned offsets to 32-bit variant. */
16762 if (offset & low)
16763 return 4;
16764 if (offset & ~mask)
16765 return 4;
16766 return 2;
16767 }
16768
16769 /* Get the address of a symbol during relaxation. */
16770 static addressT
16771 relaxed_symbol_addr(fragS *fragp, long stretch)
16772 {
16773 fragS *sym_frag;
16774 addressT addr;
16775 symbolS *sym;
16776
16777 sym = fragp->fr_symbol;
16778 sym_frag = symbol_get_frag (sym);
16779 know (S_GET_SEGMENT (sym) != absolute_section
16780 || sym_frag == &zero_address_frag);
16781 addr = S_GET_VALUE (sym) + fragp->fr_offset;
16782
16783 /* If frag has yet to be reached on this pass, assume it will
16784 move by STRETCH just as we did. If this is not so, it will
16785 be because some frag between grows, and that will force
16786 another pass. */
16787
16788 if (stretch != 0
16789 && sym_frag->relax_marker != fragp->relax_marker)
16790 addr += stretch;
16791
16792 return addr;
16793 }
16794
16795 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
16796 load. */
16797 static int
16798 relax_adr (fragS *fragp, asection *sec, long stretch)
16799 {
16800 addressT addr;
16801 offsetT val;
16802
16803 /* Assume worst case for symbols not known to be in the same section. */
16804 if (!S_IS_DEFINED(fragp->fr_symbol)
16805 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16806 return 4;
16807
16808 val = relaxed_symbol_addr(fragp, stretch);
16809 addr = fragp->fr_address + fragp->fr_fix;
16810 addr = (addr + 4) & ~3;
16811 /* Force misaligned targets to 32-bit variant. */
16812 if (val & 3)
16813 return 4;
16814 val -= addr;
16815 if (val < 0 || val > 1020)
16816 return 4;
16817 return 2;
16818 }
16819
16820 /* Return the size of a relaxable add/sub immediate instruction. */
16821 static int
16822 relax_addsub (fragS *fragp, asection *sec)
16823 {
16824 char *buf;
16825 int op;
16826
16827 buf = fragp->fr_literal + fragp->fr_fix;
16828 op = bfd_get_16(sec->owner, buf);
16829 if ((op & 0xf) == ((op >> 4) & 0xf))
16830 return relax_immediate (fragp, 8, 0);
16831 else
16832 return relax_immediate (fragp, 3, 0);
16833 }
16834
16835
16836 /* Return the size of a relaxable branch instruction. BITS is the
16837 size of the offset field in the narrow instruction. */
16838
16839 static int
16840 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
16841 {
16842 addressT addr;
16843 offsetT val;
16844 offsetT limit;
16845
16846 /* Assume worst case for symbols not known to be in the same section. */
16847 if (!S_IS_DEFINED(fragp->fr_symbol)
16848 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16849 return 4;
16850
16851 val = relaxed_symbol_addr(fragp, stretch);
16852 addr = fragp->fr_address + fragp->fr_fix + 4;
16853 val -= addr;
16854
16855 /* Offset is a signed value *2 */
16856 limit = 1 << bits;
16857 if (val >= limit || val < -limit)
16858 return 4;
16859 return 2;
16860 }
16861
16862
16863 /* Relax a machine dependent frag. This returns the amount by which
16864 the current size of the frag should change. */
16865
16866 int
16867 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
16868 {
16869 int oldsize;
16870 int newsize;
16871
16872 oldsize = fragp->fr_var;
16873 switch (fragp->fr_subtype)
16874 {
16875 case T_MNEM_ldr_pc2:
16876 newsize = relax_adr(fragp, sec, stretch);
16877 break;
16878 case T_MNEM_ldr_pc:
16879 case T_MNEM_ldr_sp:
16880 case T_MNEM_str_sp:
16881 newsize = relax_immediate(fragp, 8, 2);
16882 break;
16883 case T_MNEM_ldr:
16884 case T_MNEM_str:
16885 newsize = relax_immediate(fragp, 5, 2);
16886 break;
16887 case T_MNEM_ldrh:
16888 case T_MNEM_strh:
16889 newsize = relax_immediate(fragp, 5, 1);
16890 break;
16891 case T_MNEM_ldrb:
16892 case T_MNEM_strb:
16893 newsize = relax_immediate(fragp, 5, 0);
16894 break;
16895 case T_MNEM_adr:
16896 newsize = relax_adr(fragp, sec, stretch);
16897 break;
16898 case T_MNEM_mov:
16899 case T_MNEM_movs:
16900 case T_MNEM_cmp:
16901 case T_MNEM_cmn:
16902 newsize = relax_immediate(fragp, 8, 0);
16903 break;
16904 case T_MNEM_b:
16905 newsize = relax_branch(fragp, sec, 11, stretch);
16906 break;
16907 case T_MNEM_bcond:
16908 newsize = relax_branch(fragp, sec, 8, stretch);
16909 break;
16910 case T_MNEM_add_sp:
16911 case T_MNEM_add_pc:
16912 newsize = relax_immediate (fragp, 8, 2);
16913 break;
16914 case T_MNEM_inc_sp:
16915 case T_MNEM_dec_sp:
16916 newsize = relax_immediate (fragp, 7, 2);
16917 break;
16918 case T_MNEM_addi:
16919 case T_MNEM_addis:
16920 case T_MNEM_subi:
16921 case T_MNEM_subis:
16922 newsize = relax_addsub (fragp, sec);
16923 break;
16924 default:
16925 abort();
16926 }
16927
16928 fragp->fr_var = newsize;
16929 /* Freeze wide instructions that are at or before the same location as
16930 in the previous pass. This avoids infinite loops.
16931 Don't freeze them unconditionally because targets may be artificialy
16932 misaligned by the expansion of preceeding frags. */
16933 if (stretch <= 0 && newsize > 2)
16934 {
16935 md_convert_frag (sec->owner, sec, fragp);
16936 frag_wane(fragp);
16937 }
16938
16939 return newsize - oldsize;
16940 }
16941
16942 /* Round up a section size to the appropriate boundary. */
16943
16944 valueT
16945 md_section_align (segT segment ATTRIBUTE_UNUSED,
16946 valueT size)
16947 {
16948 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
16949 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
16950 {
16951 /* For a.out, force the section size to be aligned. If we don't do
16952 this, BFD will align it for us, but it will not write out the
16953 final bytes of the section. This may be a bug in BFD, but it is
16954 easier to fix it here since that is how the other a.out targets
16955 work. */
16956 int align;
16957
16958 align = bfd_get_section_alignment (stdoutput, segment);
16959 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
16960 }
16961 #endif
16962
16963 return size;
16964 }
16965
16966 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
16967 of an rs_align_code fragment. */
16968
16969 void
16970 arm_handle_align (fragS * fragP)
16971 {
16972 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
16973 static char const thumb_noop[2] = { 0xc0, 0x46 };
16974 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
16975 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
16976
16977 int bytes, fix, noop_size;
16978 char * p;
16979 const char * noop;
16980
16981 if (fragP->fr_type != rs_align_code)
16982 return;
16983
16984 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
16985 p = fragP->fr_literal + fragP->fr_fix;
16986 fix = 0;
16987
16988 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
16989 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
16990
16991 if (fragP->tc_frag_data)
16992 {
16993 if (target_big_endian)
16994 noop = thumb_bigend_noop;
16995 else
16996 noop = thumb_noop;
16997 noop_size = sizeof (thumb_noop);
16998 }
16999 else
17000 {
17001 if (target_big_endian)
17002 noop = arm_bigend_noop;
17003 else
17004 noop = arm_noop;
17005 noop_size = sizeof (arm_noop);
17006 }
17007
17008 if (bytes & (noop_size - 1))
17009 {
17010 fix = bytes & (noop_size - 1);
17011 memset (p, 0, fix);
17012 p += fix;
17013 bytes -= fix;
17014 }
17015
17016 while (bytes >= noop_size)
17017 {
17018 memcpy (p, noop, noop_size);
17019 p += noop_size;
17020 bytes -= noop_size;
17021 fix += noop_size;
17022 }
17023
17024 fragP->fr_fix += fix;
17025 fragP->fr_var = noop_size;
17026 }
17027
17028 /* Called from md_do_align. Used to create an alignment
17029 frag in a code section. */
17030
17031 void
17032 arm_frag_align_code (int n, int max)
17033 {
17034 char * p;
17035
17036 /* We assume that there will never be a requirement
17037 to support alignments greater than 32 bytes. */
17038 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
17039 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
17040
17041 p = frag_var (rs_align_code,
17042 MAX_MEM_FOR_RS_ALIGN_CODE,
17043 1,
17044 (relax_substateT) max,
17045 (symbolS *) NULL,
17046 (offsetT) n,
17047 (char *) NULL);
17048 *p = 0;
17049 }
17050
17051 /* Perform target specific initialisation of a frag. */
17052
17053 void
17054 arm_init_frag (fragS * fragP)
17055 {
17056 /* Record whether this frag is in an ARM or a THUMB area. */
17057 fragP->tc_frag_data = thumb_mode;
17058 }
17059
17060 #ifdef OBJ_ELF
17061 /* When we change sections we need to issue a new mapping symbol. */
17062
17063 void
17064 arm_elf_change_section (void)
17065 {
17066 flagword flags;
17067 segment_info_type *seginfo;
17068
17069 /* Link an unlinked unwind index table section to the .text section. */
17070 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
17071 && elf_linked_to_section (now_seg) == NULL)
17072 elf_linked_to_section (now_seg) = text_section;
17073
17074 if (!SEG_NORMAL (now_seg))
17075 return;
17076
17077 flags = bfd_get_section_flags (stdoutput, now_seg);
17078
17079 /* We can ignore sections that only contain debug info. */
17080 if ((flags & SEC_ALLOC) == 0)
17081 return;
17082
17083 seginfo = seg_info (now_seg);
17084 mapstate = seginfo->tc_segment_info_data.mapstate;
17085 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
17086 }
17087
17088 int
17089 arm_elf_section_type (const char * str, size_t len)
17090 {
17091 if (len == 5 && strncmp (str, "exidx", 5) == 0)
17092 return SHT_ARM_EXIDX;
17093
17094 return -1;
17095 }
17096 \f
17097 /* Code to deal with unwinding tables. */
17098
17099 static void add_unwind_adjustsp (offsetT);
17100
17101 /* Cenerate and deferred unwind frame offset. */
17102
17103 static void
17104 flush_pending_unwind (void)
17105 {
17106 offsetT offset;
17107
17108 offset = unwind.pending_offset;
17109 unwind.pending_offset = 0;
17110 if (offset != 0)
17111 add_unwind_adjustsp (offset);
17112 }
17113
17114 /* Add an opcode to this list for this function. Two-byte opcodes should
17115 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
17116 order. */
17117
17118 static void
17119 add_unwind_opcode (valueT op, int length)
17120 {
17121 /* Add any deferred stack adjustment. */
17122 if (unwind.pending_offset)
17123 flush_pending_unwind ();
17124
17125 unwind.sp_restored = 0;
17126
17127 if (unwind.opcode_count + length > unwind.opcode_alloc)
17128 {
17129 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
17130 if (unwind.opcodes)
17131 unwind.opcodes = xrealloc (unwind.opcodes,
17132 unwind.opcode_alloc);
17133 else
17134 unwind.opcodes = xmalloc (unwind.opcode_alloc);
17135 }
17136 while (length > 0)
17137 {
17138 length--;
17139 unwind.opcodes[unwind.opcode_count] = op & 0xff;
17140 op >>= 8;
17141 unwind.opcode_count++;
17142 }
17143 }
17144
17145 /* Add unwind opcodes to adjust the stack pointer. */
17146
17147 static void
17148 add_unwind_adjustsp (offsetT offset)
17149 {
17150 valueT op;
17151
17152 if (offset > 0x200)
17153 {
17154 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
17155 char bytes[5];
17156 int n;
17157 valueT o;
17158
17159 /* Long form: 0xb2, uleb128. */
17160 /* This might not fit in a word so add the individual bytes,
17161 remembering the list is built in reverse order. */
17162 o = (valueT) ((offset - 0x204) >> 2);
17163 if (o == 0)
17164 add_unwind_opcode (0, 1);
17165
17166 /* Calculate the uleb128 encoding of the offset. */
17167 n = 0;
17168 while (o)
17169 {
17170 bytes[n] = o & 0x7f;
17171 o >>= 7;
17172 if (o)
17173 bytes[n] |= 0x80;
17174 n++;
17175 }
17176 /* Add the insn. */
17177 for (; n; n--)
17178 add_unwind_opcode (bytes[n - 1], 1);
17179 add_unwind_opcode (0xb2, 1);
17180 }
17181 else if (offset > 0x100)
17182 {
17183 /* Two short opcodes. */
17184 add_unwind_opcode (0x3f, 1);
17185 op = (offset - 0x104) >> 2;
17186 add_unwind_opcode (op, 1);
17187 }
17188 else if (offset > 0)
17189 {
17190 /* Short opcode. */
17191 op = (offset - 4) >> 2;
17192 add_unwind_opcode (op, 1);
17193 }
17194 else if (offset < 0)
17195 {
17196 offset = -offset;
17197 while (offset > 0x100)
17198 {
17199 add_unwind_opcode (0x7f, 1);
17200 offset -= 0x100;
17201 }
17202 op = ((offset - 4) >> 2) | 0x40;
17203 add_unwind_opcode (op, 1);
17204 }
17205 }
17206
17207 /* Finish the list of unwind opcodes for this function. */
17208 static void
17209 finish_unwind_opcodes (void)
17210 {
17211 valueT op;
17212
17213 if (unwind.fp_used)
17214 {
17215 /* Adjust sp as necessary. */
17216 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
17217 flush_pending_unwind ();
17218
17219 /* After restoring sp from the frame pointer. */
17220 op = 0x90 | unwind.fp_reg;
17221 add_unwind_opcode (op, 1);
17222 }
17223 else
17224 flush_pending_unwind ();
17225 }
17226
17227
17228 /* Start an exception table entry. If idx is nonzero this is an index table
17229 entry. */
17230
17231 static void
17232 start_unwind_section (const segT text_seg, int idx)
17233 {
17234 const char * text_name;
17235 const char * prefix;
17236 const char * prefix_once;
17237 const char * group_name;
17238 size_t prefix_len;
17239 size_t text_len;
17240 char * sec_name;
17241 size_t sec_name_len;
17242 int type;
17243 int flags;
17244 int linkonce;
17245
17246 if (idx)
17247 {
17248 prefix = ELF_STRING_ARM_unwind;
17249 prefix_once = ELF_STRING_ARM_unwind_once;
17250 type = SHT_ARM_EXIDX;
17251 }
17252 else
17253 {
17254 prefix = ELF_STRING_ARM_unwind_info;
17255 prefix_once = ELF_STRING_ARM_unwind_info_once;
17256 type = SHT_PROGBITS;
17257 }
17258
17259 text_name = segment_name (text_seg);
17260 if (streq (text_name, ".text"))
17261 text_name = "";
17262
17263 if (strncmp (text_name, ".gnu.linkonce.t.",
17264 strlen (".gnu.linkonce.t.")) == 0)
17265 {
17266 prefix = prefix_once;
17267 text_name += strlen (".gnu.linkonce.t.");
17268 }
17269
17270 prefix_len = strlen (prefix);
17271 text_len = strlen (text_name);
17272 sec_name_len = prefix_len + text_len;
17273 sec_name = xmalloc (sec_name_len + 1);
17274 memcpy (sec_name, prefix, prefix_len);
17275 memcpy (sec_name + prefix_len, text_name, text_len);
17276 sec_name[prefix_len + text_len] = '\0';
17277
17278 flags = SHF_ALLOC;
17279 linkonce = 0;
17280 group_name = 0;
17281
17282 /* Handle COMDAT group. */
17283 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
17284 {
17285 group_name = elf_group_name (text_seg);
17286 if (group_name == NULL)
17287 {
17288 as_bad ("Group section `%s' has no group signature",
17289 segment_name (text_seg));
17290 ignore_rest_of_line ();
17291 return;
17292 }
17293 flags |= SHF_GROUP;
17294 linkonce = 1;
17295 }
17296
17297 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
17298
17299 /* Set the setion link for index tables. */
17300 if (idx)
17301 elf_linked_to_section (now_seg) = text_seg;
17302 }
17303
17304
17305 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
17306 personality routine data. Returns zero, or the index table value for
17307 and inline entry. */
17308
17309 static valueT
17310 create_unwind_entry (int have_data)
17311 {
17312 int size;
17313 addressT where;
17314 char *ptr;
17315 /* The current word of data. */
17316 valueT data;
17317 /* The number of bytes left in this word. */
17318 int n;
17319
17320 finish_unwind_opcodes ();
17321
17322 /* Remember the current text section. */
17323 unwind.saved_seg = now_seg;
17324 unwind.saved_subseg = now_subseg;
17325
17326 start_unwind_section (now_seg, 0);
17327
17328 if (unwind.personality_routine == NULL)
17329 {
17330 if (unwind.personality_index == -2)
17331 {
17332 if (have_data)
17333 as_bad (_("handerdata in cantunwind frame"));
17334 return 1; /* EXIDX_CANTUNWIND. */
17335 }
17336
17337 /* Use a default personality routine if none is specified. */
17338 if (unwind.personality_index == -1)
17339 {
17340 if (unwind.opcode_count > 3)
17341 unwind.personality_index = 1;
17342 else
17343 unwind.personality_index = 0;
17344 }
17345
17346 /* Space for the personality routine entry. */
17347 if (unwind.personality_index == 0)
17348 {
17349 if (unwind.opcode_count > 3)
17350 as_bad (_("too many unwind opcodes for personality routine 0"));
17351
17352 if (!have_data)
17353 {
17354 /* All the data is inline in the index table. */
17355 data = 0x80;
17356 n = 3;
17357 while (unwind.opcode_count > 0)
17358 {
17359 unwind.opcode_count--;
17360 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17361 n--;
17362 }
17363
17364 /* Pad with "finish" opcodes. */
17365 while (n--)
17366 data = (data << 8) | 0xb0;
17367
17368 return data;
17369 }
17370 size = 0;
17371 }
17372 else
17373 /* We get two opcodes "free" in the first word. */
17374 size = unwind.opcode_count - 2;
17375 }
17376 else
17377 /* An extra byte is required for the opcode count. */
17378 size = unwind.opcode_count + 1;
17379
17380 size = (size + 3) >> 2;
17381 if (size > 0xff)
17382 as_bad (_("too many unwind opcodes"));
17383
17384 frag_align (2, 0, 0);
17385 record_alignment (now_seg, 2);
17386 unwind.table_entry = expr_build_dot ();
17387
17388 /* Allocate the table entry. */
17389 ptr = frag_more ((size << 2) + 4);
17390 where = frag_now_fix () - ((size << 2) + 4);
17391
17392 switch (unwind.personality_index)
17393 {
17394 case -1:
17395 /* ??? Should this be a PLT generating relocation? */
17396 /* Custom personality routine. */
17397 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
17398 BFD_RELOC_ARM_PREL31);
17399
17400 where += 4;
17401 ptr += 4;
17402
17403 /* Set the first byte to the number of additional words. */
17404 data = size - 1;
17405 n = 3;
17406 break;
17407
17408 /* ABI defined personality routines. */
17409 case 0:
17410 /* Three opcodes bytes are packed into the first word. */
17411 data = 0x80;
17412 n = 3;
17413 break;
17414
17415 case 1:
17416 case 2:
17417 /* The size and first two opcode bytes go in the first word. */
17418 data = ((0x80 + unwind.personality_index) << 8) | size;
17419 n = 2;
17420 break;
17421
17422 default:
17423 /* Should never happen. */
17424 abort ();
17425 }
17426
17427 /* Pack the opcodes into words (MSB first), reversing the list at the same
17428 time. */
17429 while (unwind.opcode_count > 0)
17430 {
17431 if (n == 0)
17432 {
17433 md_number_to_chars (ptr, data, 4);
17434 ptr += 4;
17435 n = 4;
17436 data = 0;
17437 }
17438 unwind.opcode_count--;
17439 n--;
17440 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17441 }
17442
17443 /* Finish off the last word. */
17444 if (n < 4)
17445 {
17446 /* Pad with "finish" opcodes. */
17447 while (n--)
17448 data = (data << 8) | 0xb0;
17449
17450 md_number_to_chars (ptr, data, 4);
17451 }
17452
17453 if (!have_data)
17454 {
17455 /* Add an empty descriptor if there is no user-specified data. */
17456 ptr = frag_more (4);
17457 md_number_to_chars (ptr, 0, 4);
17458 }
17459
17460 return 0;
17461 }
17462
17463
17464 /* Initialize the DWARF-2 unwind information for this procedure. */
17465
17466 void
17467 tc_arm_frame_initial_instructions (void)
17468 {
17469 cfi_add_CFA_def_cfa (REG_SP, 0);
17470 }
17471 #endif /* OBJ_ELF */
17472
17473 /* Convert REGNAME to a DWARF-2 register number. */
17474
17475 int
17476 tc_arm_regname_to_dw2regnum (char *regname)
17477 {
17478 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
17479
17480 if (reg == FAIL)
17481 return -1;
17482
17483 return reg;
17484 }
17485
17486 #ifdef TE_PE
17487 void
17488 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
17489 {
17490 expressionS expr;
17491
17492 expr.X_op = O_secrel;
17493 expr.X_add_symbol = symbol;
17494 expr.X_add_number = 0;
17495 emit_expr (&expr, size);
17496 }
17497 #endif
17498
17499 /* MD interface: Symbol and relocation handling. */
17500
17501 /* Return the address within the segment that a PC-relative fixup is
17502 relative to. For ARM, PC-relative fixups applied to instructions
17503 are generally relative to the location of the fixup plus 8 bytes.
17504 Thumb branches are offset by 4, and Thumb loads relative to PC
17505 require special handling. */
17506
17507 long
17508 md_pcrel_from_section (fixS * fixP, segT seg)
17509 {
17510 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
17511
17512 /* If this is pc-relative and we are going to emit a relocation
17513 then we just want to put out any pipeline compensation that the linker
17514 will need. Otherwise we want to use the calculated base.
17515 For WinCE we skip the bias for externals as well, since this
17516 is how the MS ARM-CE assembler behaves and we want to be compatible. */
17517 if (fixP->fx_pcrel
17518 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
17519 || (arm_force_relocation (fixP)
17520 #ifdef TE_WINCE
17521 && !S_IS_EXTERNAL (fixP->fx_addsy)
17522 #endif
17523 )))
17524 base = 0;
17525
17526 switch (fixP->fx_r_type)
17527 {
17528 /* PC relative addressing on the Thumb is slightly odd as the
17529 bottom two bits of the PC are forced to zero for the
17530 calculation. This happens *after* application of the
17531 pipeline offset. However, Thumb adrl already adjusts for
17532 this, so we need not do it again. */
17533 case BFD_RELOC_ARM_THUMB_ADD:
17534 return base & ~3;
17535
17536 case BFD_RELOC_ARM_THUMB_OFFSET:
17537 case BFD_RELOC_ARM_T32_OFFSET_IMM:
17538 case BFD_RELOC_ARM_T32_ADD_PC12:
17539 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
17540 return (base + 4) & ~3;
17541
17542 /* Thumb branches are simply offset by +4. */
17543 case BFD_RELOC_THUMB_PCREL_BRANCH7:
17544 case BFD_RELOC_THUMB_PCREL_BRANCH9:
17545 case BFD_RELOC_THUMB_PCREL_BRANCH12:
17546 case BFD_RELOC_THUMB_PCREL_BRANCH20:
17547 case BFD_RELOC_THUMB_PCREL_BRANCH23:
17548 case BFD_RELOC_THUMB_PCREL_BRANCH25:
17549 case BFD_RELOC_THUMB_PCREL_BLX:
17550 return base + 4;
17551
17552 /* ARM mode branches are offset by +8. However, the Windows CE
17553 loader expects the relocation not to take this into account. */
17554 case BFD_RELOC_ARM_PCREL_BRANCH:
17555 case BFD_RELOC_ARM_PCREL_CALL:
17556 case BFD_RELOC_ARM_PCREL_JUMP:
17557 case BFD_RELOC_ARM_PCREL_BLX:
17558 case BFD_RELOC_ARM_PLT32:
17559 #ifdef TE_WINCE
17560 /* When handling fixups immediately, because we have already
17561 discovered the value of a symbol, or the address of the frag involved
17562 we must account for the offset by +8, as the OS loader will never see the reloc.
17563 see fixup_segment() in write.c
17564 The S_IS_EXTERNAL test handles the case of global symbols.
17565 Those need the calculated base, not just the pipe compensation the linker will need. */
17566 if (fixP->fx_pcrel
17567 && fixP->fx_addsy != NULL
17568 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
17569 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
17570 return base + 8;
17571 return base;
17572 #else
17573 return base + 8;
17574 #endif
17575
17576 /* ARM mode loads relative to PC are also offset by +8. Unlike
17577 branches, the Windows CE loader *does* expect the relocation
17578 to take this into account. */
17579 case BFD_RELOC_ARM_OFFSET_IMM:
17580 case BFD_RELOC_ARM_OFFSET_IMM8:
17581 case BFD_RELOC_ARM_HWLITERAL:
17582 case BFD_RELOC_ARM_LITERAL:
17583 case BFD_RELOC_ARM_CP_OFF_IMM:
17584 return base + 8;
17585
17586
17587 /* Other PC-relative relocations are un-offset. */
17588 default:
17589 return base;
17590 }
17591 }
17592
17593 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
17594 Otherwise we have no need to default values of symbols. */
17595
17596 symbolS *
17597 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
17598 {
17599 #ifdef OBJ_ELF
17600 if (name[0] == '_' && name[1] == 'G'
17601 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
17602 {
17603 if (!GOT_symbol)
17604 {
17605 if (symbol_find (name))
17606 as_bad ("GOT already in the symbol table");
17607
17608 GOT_symbol = symbol_new (name, undefined_section,
17609 (valueT) 0, & zero_address_frag);
17610 }
17611
17612 return GOT_symbol;
17613 }
17614 #endif
17615
17616 return 0;
17617 }
17618
17619 /* Subroutine of md_apply_fix. Check to see if an immediate can be
17620 computed as two separate immediate values, added together. We
17621 already know that this value cannot be computed by just one ARM
17622 instruction. */
17623
17624 static unsigned int
17625 validate_immediate_twopart (unsigned int val,
17626 unsigned int * highpart)
17627 {
17628 unsigned int a;
17629 unsigned int i;
17630
17631 for (i = 0; i < 32; i += 2)
17632 if (((a = rotate_left (val, i)) & 0xff) != 0)
17633 {
17634 if (a & 0xff00)
17635 {
17636 if (a & ~ 0xffff)
17637 continue;
17638 * highpart = (a >> 8) | ((i + 24) << 7);
17639 }
17640 else if (a & 0xff0000)
17641 {
17642 if (a & 0xff000000)
17643 continue;
17644 * highpart = (a >> 16) | ((i + 16) << 7);
17645 }
17646 else
17647 {
17648 assert (a & 0xff000000);
17649 * highpart = (a >> 24) | ((i + 8) << 7);
17650 }
17651
17652 return (a & 0xff) | (i << 7);
17653 }
17654
17655 return FAIL;
17656 }
17657
17658 static int
17659 validate_offset_imm (unsigned int val, int hwse)
17660 {
17661 if ((hwse && val > 255) || val > 4095)
17662 return FAIL;
17663 return val;
17664 }
17665
17666 /* Subroutine of md_apply_fix. Do those data_ops which can take a
17667 negative immediate constant by altering the instruction. A bit of
17668 a hack really.
17669 MOV <-> MVN
17670 AND <-> BIC
17671 ADC <-> SBC
17672 by inverting the second operand, and
17673 ADD <-> SUB
17674 CMP <-> CMN
17675 by negating the second operand. */
17676
17677 static int
17678 negate_data_op (unsigned long * instruction,
17679 unsigned long value)
17680 {
17681 int op, new_inst;
17682 unsigned long negated, inverted;
17683
17684 negated = encode_arm_immediate (-value);
17685 inverted = encode_arm_immediate (~value);
17686
17687 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
17688 switch (op)
17689 {
17690 /* First negates. */
17691 case OPCODE_SUB: /* ADD <-> SUB */
17692 new_inst = OPCODE_ADD;
17693 value = negated;
17694 break;
17695
17696 case OPCODE_ADD:
17697 new_inst = OPCODE_SUB;
17698 value = negated;
17699 break;
17700
17701 case OPCODE_CMP: /* CMP <-> CMN */
17702 new_inst = OPCODE_CMN;
17703 value = negated;
17704 break;
17705
17706 case OPCODE_CMN:
17707 new_inst = OPCODE_CMP;
17708 value = negated;
17709 break;
17710
17711 /* Now Inverted ops. */
17712 case OPCODE_MOV: /* MOV <-> MVN */
17713 new_inst = OPCODE_MVN;
17714 value = inverted;
17715 break;
17716
17717 case OPCODE_MVN:
17718 new_inst = OPCODE_MOV;
17719 value = inverted;
17720 break;
17721
17722 case OPCODE_AND: /* AND <-> BIC */
17723 new_inst = OPCODE_BIC;
17724 value = inverted;
17725 break;
17726
17727 case OPCODE_BIC:
17728 new_inst = OPCODE_AND;
17729 value = inverted;
17730 break;
17731
17732 case OPCODE_ADC: /* ADC <-> SBC */
17733 new_inst = OPCODE_SBC;
17734 value = inverted;
17735 break;
17736
17737 case OPCODE_SBC:
17738 new_inst = OPCODE_ADC;
17739 value = inverted;
17740 break;
17741
17742 /* We cannot do anything. */
17743 default:
17744 return FAIL;
17745 }
17746
17747 if (value == (unsigned) FAIL)
17748 return FAIL;
17749
17750 *instruction &= OPCODE_MASK;
17751 *instruction |= new_inst << DATA_OP_SHIFT;
17752 return value;
17753 }
17754
17755 /* Like negate_data_op, but for Thumb-2. */
17756
17757 static unsigned int
17758 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
17759 {
17760 int op, new_inst;
17761 int rd;
17762 unsigned int negated, inverted;
17763
17764 negated = encode_thumb32_immediate (-value);
17765 inverted = encode_thumb32_immediate (~value);
17766
17767 rd = (*instruction >> 8) & 0xf;
17768 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
17769 switch (op)
17770 {
17771 /* ADD <-> SUB. Includes CMP <-> CMN. */
17772 case T2_OPCODE_SUB:
17773 new_inst = T2_OPCODE_ADD;
17774 value = negated;
17775 break;
17776
17777 case T2_OPCODE_ADD:
17778 new_inst = T2_OPCODE_SUB;
17779 value = negated;
17780 break;
17781
17782 /* ORR <-> ORN. Includes MOV <-> MVN. */
17783 case T2_OPCODE_ORR:
17784 new_inst = T2_OPCODE_ORN;
17785 value = inverted;
17786 break;
17787
17788 case T2_OPCODE_ORN:
17789 new_inst = T2_OPCODE_ORR;
17790 value = inverted;
17791 break;
17792
17793 /* AND <-> BIC. TST has no inverted equivalent. */
17794 case T2_OPCODE_AND:
17795 new_inst = T2_OPCODE_BIC;
17796 if (rd == 15)
17797 value = FAIL;
17798 else
17799 value = inverted;
17800 break;
17801
17802 case T2_OPCODE_BIC:
17803 new_inst = T2_OPCODE_AND;
17804 value = inverted;
17805 break;
17806
17807 /* ADC <-> SBC */
17808 case T2_OPCODE_ADC:
17809 new_inst = T2_OPCODE_SBC;
17810 value = inverted;
17811 break;
17812
17813 case T2_OPCODE_SBC:
17814 new_inst = T2_OPCODE_ADC;
17815 value = inverted;
17816 break;
17817
17818 /* We cannot do anything. */
17819 default:
17820 return FAIL;
17821 }
17822
17823 if (value == (unsigned int)FAIL)
17824 return FAIL;
17825
17826 *instruction &= T2_OPCODE_MASK;
17827 *instruction |= new_inst << T2_DATA_OP_SHIFT;
17828 return value;
17829 }
17830
17831 /* Read a 32-bit thumb instruction from buf. */
17832 static unsigned long
17833 get_thumb32_insn (char * buf)
17834 {
17835 unsigned long insn;
17836 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
17837 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
17838
17839 return insn;
17840 }
17841
17842
17843 /* We usually want to set the low bit on the address of thumb function
17844 symbols. In particular .word foo - . should have the low bit set.
17845 Generic code tries to fold the difference of two symbols to
17846 a constant. Prevent this and force a relocation when the first symbols
17847 is a thumb function. */
17848 int
17849 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
17850 {
17851 if (op == O_subtract
17852 && l->X_op == O_symbol
17853 && r->X_op == O_symbol
17854 && THUMB_IS_FUNC (l->X_add_symbol))
17855 {
17856 l->X_op = O_subtract;
17857 l->X_op_symbol = r->X_add_symbol;
17858 l->X_add_number -= r->X_add_number;
17859 return 1;
17860 }
17861 /* Process as normal. */
17862 return 0;
17863 }
17864
17865 void
17866 md_apply_fix (fixS * fixP,
17867 valueT * valP,
17868 segT seg)
17869 {
17870 offsetT value = * valP;
17871 offsetT newval;
17872 unsigned int newimm;
17873 unsigned long temp;
17874 int sign;
17875 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
17876
17877 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
17878
17879 /* Note whether this will delete the relocation. */
17880
17881 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
17882 fixP->fx_done = 1;
17883
17884 /* On a 64-bit host, silently truncate 'value' to 32 bits for
17885 consistency with the behavior on 32-bit hosts. Remember value
17886 for emit_reloc. */
17887 value &= 0xffffffff;
17888 value ^= 0x80000000;
17889 value -= 0x80000000;
17890
17891 *valP = value;
17892 fixP->fx_addnumber = value;
17893
17894 /* Same treatment for fixP->fx_offset. */
17895 fixP->fx_offset &= 0xffffffff;
17896 fixP->fx_offset ^= 0x80000000;
17897 fixP->fx_offset -= 0x80000000;
17898
17899 switch (fixP->fx_r_type)
17900 {
17901 case BFD_RELOC_NONE:
17902 /* This will need to go in the object file. */
17903 fixP->fx_done = 0;
17904 break;
17905
17906 case BFD_RELOC_ARM_IMMEDIATE:
17907 /* We claim that this fixup has been processed here,
17908 even if in fact we generate an error because we do
17909 not have a reloc for it, so tc_gen_reloc will reject it. */
17910 fixP->fx_done = 1;
17911
17912 if (fixP->fx_addsy
17913 && ! S_IS_DEFINED (fixP->fx_addsy))
17914 {
17915 as_bad_where (fixP->fx_file, fixP->fx_line,
17916 _("undefined symbol %s used as an immediate value"),
17917 S_GET_NAME (fixP->fx_addsy));
17918 break;
17919 }
17920
17921 newimm = encode_arm_immediate (value);
17922 temp = md_chars_to_number (buf, INSN_SIZE);
17923
17924 /* If the instruction will fail, see if we can fix things up by
17925 changing the opcode. */
17926 if (newimm == (unsigned int) FAIL
17927 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
17928 {
17929 as_bad_where (fixP->fx_file, fixP->fx_line,
17930 _("invalid constant (%lx) after fixup"),
17931 (unsigned long) value);
17932 break;
17933 }
17934
17935 newimm |= (temp & 0xfffff000);
17936 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
17937 break;
17938
17939 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
17940 {
17941 unsigned int highpart = 0;
17942 unsigned int newinsn = 0xe1a00000; /* nop. */
17943
17944 newimm = encode_arm_immediate (value);
17945 temp = md_chars_to_number (buf, INSN_SIZE);
17946
17947 /* If the instruction will fail, see if we can fix things up by
17948 changing the opcode. */
17949 if (newimm == (unsigned int) FAIL
17950 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
17951 {
17952 /* No ? OK - try using two ADD instructions to generate
17953 the value. */
17954 newimm = validate_immediate_twopart (value, & highpart);
17955
17956 /* Yes - then make sure that the second instruction is
17957 also an add. */
17958 if (newimm != (unsigned int) FAIL)
17959 newinsn = temp;
17960 /* Still No ? Try using a negated value. */
17961 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
17962 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
17963 /* Otherwise - give up. */
17964 else
17965 {
17966 as_bad_where (fixP->fx_file, fixP->fx_line,
17967 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
17968 (long) value);
17969 break;
17970 }
17971
17972 /* Replace the first operand in the 2nd instruction (which
17973 is the PC) with the destination register. We have
17974 already added in the PC in the first instruction and we
17975 do not want to do it again. */
17976 newinsn &= ~ 0xf0000;
17977 newinsn |= ((newinsn & 0x0f000) << 4);
17978 }
17979
17980 newimm |= (temp & 0xfffff000);
17981 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
17982
17983 highpart |= (newinsn & 0xfffff000);
17984 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
17985 }
17986 break;
17987
17988 case BFD_RELOC_ARM_OFFSET_IMM:
17989 if (!fixP->fx_done && seg->use_rela_p)
17990 value = 0;
17991
17992 case BFD_RELOC_ARM_LITERAL:
17993 sign = value >= 0;
17994
17995 if (value < 0)
17996 value = - value;
17997
17998 if (validate_offset_imm (value, 0) == FAIL)
17999 {
18000 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
18001 as_bad_where (fixP->fx_file, fixP->fx_line,
18002 _("invalid literal constant: pool needs to be closer"));
18003 else
18004 as_bad_where (fixP->fx_file, fixP->fx_line,
18005 _("bad immediate value for offset (%ld)"),
18006 (long) value);
18007 break;
18008 }
18009
18010 newval = md_chars_to_number (buf, INSN_SIZE);
18011 newval &= 0xff7ff000;
18012 newval |= value | (sign ? INDEX_UP : 0);
18013 md_number_to_chars (buf, newval, INSN_SIZE);
18014 break;
18015
18016 case BFD_RELOC_ARM_OFFSET_IMM8:
18017 case BFD_RELOC_ARM_HWLITERAL:
18018 sign = value >= 0;
18019
18020 if (value < 0)
18021 value = - value;
18022
18023 if (validate_offset_imm (value, 1) == FAIL)
18024 {
18025 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
18026 as_bad_where (fixP->fx_file, fixP->fx_line,
18027 _("invalid literal constant: pool needs to be closer"));
18028 else
18029 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
18030 (long) value);
18031 break;
18032 }
18033
18034 newval = md_chars_to_number (buf, INSN_SIZE);
18035 newval &= 0xff7ff0f0;
18036 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
18037 md_number_to_chars (buf, newval, INSN_SIZE);
18038 break;
18039
18040 case BFD_RELOC_ARM_T32_OFFSET_U8:
18041 if (value < 0 || value > 1020 || value % 4 != 0)
18042 as_bad_where (fixP->fx_file, fixP->fx_line,
18043 _("bad immediate value for offset (%ld)"), (long) value);
18044 value /= 4;
18045
18046 newval = md_chars_to_number (buf+2, THUMB_SIZE);
18047 newval |= value;
18048 md_number_to_chars (buf+2, newval, THUMB_SIZE);
18049 break;
18050
18051 case BFD_RELOC_ARM_T32_OFFSET_IMM:
18052 /* This is a complicated relocation used for all varieties of Thumb32
18053 load/store instruction with immediate offset:
18054
18055 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
18056 *4, optional writeback(W)
18057 (doubleword load/store)
18058
18059 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
18060 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
18061 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
18062 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
18063 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
18064
18065 Uppercase letters indicate bits that are already encoded at
18066 this point. Lowercase letters are our problem. For the
18067 second block of instructions, the secondary opcode nybble
18068 (bits 8..11) is present, and bit 23 is zero, even if this is
18069 a PC-relative operation. */
18070 newval = md_chars_to_number (buf, THUMB_SIZE);
18071 newval <<= 16;
18072 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
18073
18074 if ((newval & 0xf0000000) == 0xe0000000)
18075 {
18076 /* Doubleword load/store: 8-bit offset, scaled by 4. */
18077 if (value >= 0)
18078 newval |= (1 << 23);
18079 else
18080 value = -value;
18081 if (value % 4 != 0)
18082 {
18083 as_bad_where (fixP->fx_file, fixP->fx_line,
18084 _("offset not a multiple of 4"));
18085 break;
18086 }
18087 value /= 4;
18088 if (value > 0xff)
18089 {
18090 as_bad_where (fixP->fx_file, fixP->fx_line,
18091 _("offset out of range"));
18092 break;
18093 }
18094 newval &= ~0xff;
18095 }
18096 else if ((newval & 0x000f0000) == 0x000f0000)
18097 {
18098 /* PC-relative, 12-bit offset. */
18099 if (value >= 0)
18100 newval |= (1 << 23);
18101 else
18102 value = -value;
18103 if (value > 0xfff)
18104 {
18105 as_bad_where (fixP->fx_file, fixP->fx_line,
18106 _("offset out of range"));
18107 break;
18108 }
18109 newval &= ~0xfff;
18110 }
18111 else if ((newval & 0x00000100) == 0x00000100)
18112 {
18113 /* Writeback: 8-bit, +/- offset. */
18114 if (value >= 0)
18115 newval |= (1 << 9);
18116 else
18117 value = -value;
18118 if (value > 0xff)
18119 {
18120 as_bad_where (fixP->fx_file, fixP->fx_line,
18121 _("offset out of range"));
18122 break;
18123 }
18124 newval &= ~0xff;
18125 }
18126 else if ((newval & 0x00000f00) == 0x00000e00)
18127 {
18128 /* T-instruction: positive 8-bit offset. */
18129 if (value < 0 || value > 0xff)
18130 {
18131 as_bad_where (fixP->fx_file, fixP->fx_line,
18132 _("offset out of range"));
18133 break;
18134 }
18135 newval &= ~0xff;
18136 newval |= value;
18137 }
18138 else
18139 {
18140 /* Positive 12-bit or negative 8-bit offset. */
18141 int limit;
18142 if (value >= 0)
18143 {
18144 newval |= (1 << 23);
18145 limit = 0xfff;
18146 }
18147 else
18148 {
18149 value = -value;
18150 limit = 0xff;
18151 }
18152 if (value > limit)
18153 {
18154 as_bad_where (fixP->fx_file, fixP->fx_line,
18155 _("offset out of range"));
18156 break;
18157 }
18158 newval &= ~limit;
18159 }
18160
18161 newval |= value;
18162 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
18163 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
18164 break;
18165
18166 case BFD_RELOC_ARM_SHIFT_IMM:
18167 newval = md_chars_to_number (buf, INSN_SIZE);
18168 if (((unsigned long) value) > 32
18169 || (value == 32
18170 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
18171 {
18172 as_bad_where (fixP->fx_file, fixP->fx_line,
18173 _("shift expression is too large"));
18174 break;
18175 }
18176
18177 if (value == 0)
18178 /* Shifts of zero must be done as lsl. */
18179 newval &= ~0x60;
18180 else if (value == 32)
18181 value = 0;
18182 newval &= 0xfffff07f;
18183 newval |= (value & 0x1f) << 7;
18184 md_number_to_chars (buf, newval, INSN_SIZE);
18185 break;
18186
18187 case BFD_RELOC_ARM_T32_IMMEDIATE:
18188 case BFD_RELOC_ARM_T32_ADD_IMM:
18189 case BFD_RELOC_ARM_T32_IMM12:
18190 case BFD_RELOC_ARM_T32_ADD_PC12:
18191 /* We claim that this fixup has been processed here,
18192 even if in fact we generate an error because we do
18193 not have a reloc for it, so tc_gen_reloc will reject it. */
18194 fixP->fx_done = 1;
18195
18196 if (fixP->fx_addsy
18197 && ! S_IS_DEFINED (fixP->fx_addsy))
18198 {
18199 as_bad_where (fixP->fx_file, fixP->fx_line,
18200 _("undefined symbol %s used as an immediate value"),
18201 S_GET_NAME (fixP->fx_addsy));
18202 break;
18203 }
18204
18205 newval = md_chars_to_number (buf, THUMB_SIZE);
18206 newval <<= 16;
18207 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
18208
18209 newimm = FAIL;
18210 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
18211 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18212 {
18213 newimm = encode_thumb32_immediate (value);
18214 if (newimm == (unsigned int) FAIL)
18215 newimm = thumb32_negate_data_op (&newval, value);
18216 }
18217 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
18218 && newimm == (unsigned int) FAIL)
18219 {
18220 /* Turn add/sum into addw/subw. */
18221 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18222 newval = (newval & 0xfeffffff) | 0x02000000;
18223
18224 /* 12 bit immediate for addw/subw. */
18225 if (value < 0)
18226 {
18227 value = -value;
18228 newval ^= 0x00a00000;
18229 }
18230 if (value > 0xfff)
18231 newimm = (unsigned int) FAIL;
18232 else
18233 newimm = value;
18234 }
18235
18236 if (newimm == (unsigned int)FAIL)
18237 {
18238 as_bad_where (fixP->fx_file, fixP->fx_line,
18239 _("invalid constant (%lx) after fixup"),
18240 (unsigned long) value);
18241 break;
18242 }
18243
18244 newval |= (newimm & 0x800) << 15;
18245 newval |= (newimm & 0x700) << 4;
18246 newval |= (newimm & 0x0ff);
18247
18248 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
18249 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
18250 break;
18251
18252 case BFD_RELOC_ARM_SMC:
18253 if (((unsigned long) value) > 0xffff)
18254 as_bad_where (fixP->fx_file, fixP->fx_line,
18255 _("invalid smc expression"));
18256 newval = md_chars_to_number (buf, INSN_SIZE);
18257 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
18258 md_number_to_chars (buf, newval, INSN_SIZE);
18259 break;
18260
18261 case BFD_RELOC_ARM_SWI:
18262 if (fixP->tc_fix_data != 0)
18263 {
18264 if (((unsigned long) value) > 0xff)
18265 as_bad_where (fixP->fx_file, fixP->fx_line,
18266 _("invalid swi expression"));
18267 newval = md_chars_to_number (buf, THUMB_SIZE);
18268 newval |= value;
18269 md_number_to_chars (buf, newval, THUMB_SIZE);
18270 }
18271 else
18272 {
18273 if (((unsigned long) value) > 0x00ffffff)
18274 as_bad_where (fixP->fx_file, fixP->fx_line,
18275 _("invalid swi expression"));
18276 newval = md_chars_to_number (buf, INSN_SIZE);
18277 newval |= value;
18278 md_number_to_chars (buf, newval, INSN_SIZE);
18279 }
18280 break;
18281
18282 case BFD_RELOC_ARM_MULTI:
18283 if (((unsigned long) value) > 0xffff)
18284 as_bad_where (fixP->fx_file, fixP->fx_line,
18285 _("invalid expression in load/store multiple"));
18286 newval = value | md_chars_to_number (buf, INSN_SIZE);
18287 md_number_to_chars (buf, newval, INSN_SIZE);
18288 break;
18289
18290 #ifdef OBJ_ELF
18291 case BFD_RELOC_ARM_PCREL_CALL:
18292 newval = md_chars_to_number (buf, INSN_SIZE);
18293 if ((newval & 0xf0000000) == 0xf0000000)
18294 temp = 1;
18295 else
18296 temp = 3;
18297 goto arm_branch_common;
18298
18299 case BFD_RELOC_ARM_PCREL_JUMP:
18300 case BFD_RELOC_ARM_PLT32:
18301 #endif
18302 case BFD_RELOC_ARM_PCREL_BRANCH:
18303 temp = 3;
18304 goto arm_branch_common;
18305
18306 case BFD_RELOC_ARM_PCREL_BLX:
18307 temp = 1;
18308 arm_branch_common:
18309 /* We are going to store value (shifted right by two) in the
18310 instruction, in a 24 bit, signed field. Bits 26 through 32 either
18311 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
18312 also be be clear. */
18313 if (value & temp)
18314 as_bad_where (fixP->fx_file, fixP->fx_line,
18315 _("misaligned branch destination"));
18316 if ((value & (offsetT)0xfe000000) != (offsetT)0
18317 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
18318 as_bad_where (fixP->fx_file, fixP->fx_line,
18319 _("branch out of range"));
18320
18321 if (fixP->fx_done || !seg->use_rela_p)
18322 {
18323 newval = md_chars_to_number (buf, INSN_SIZE);
18324 newval |= (value >> 2) & 0x00ffffff;
18325 /* Set the H bit on BLX instructions. */
18326 if (temp == 1)
18327 {
18328 if (value & 2)
18329 newval |= 0x01000000;
18330 else
18331 newval &= ~0x01000000;
18332 }
18333 md_number_to_chars (buf, newval, INSN_SIZE);
18334 }
18335 break;
18336
18337 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
18338 /* CBZ can only branch forward. */
18339
18340 /* Attempts to use CBZ to branch to the next instruction
18341 (which, strictly speaking, are prohibited) will be turned into
18342 no-ops.
18343
18344 FIXME: It may be better to remove the instruction completely and
18345 perform relaxation. */
18346 if (value == -2)
18347 {
18348 newval = md_chars_to_number (buf, THUMB_SIZE);
18349 newval = 0xbf00; /* NOP encoding T1 */
18350 md_number_to_chars (buf, newval, THUMB_SIZE);
18351 }
18352 else
18353 {
18354 if (value & ~0x7e)
18355 as_bad_where (fixP->fx_file, fixP->fx_line,
18356 _("branch out of range"));
18357
18358 if (fixP->fx_done || !seg->use_rela_p)
18359 {
18360 newval = md_chars_to_number (buf, THUMB_SIZE);
18361 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
18362 md_number_to_chars (buf, newval, THUMB_SIZE);
18363 }
18364 }
18365 break;
18366
18367 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
18368 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
18369 as_bad_where (fixP->fx_file, fixP->fx_line,
18370 _("branch out of range"));
18371
18372 if (fixP->fx_done || !seg->use_rela_p)
18373 {
18374 newval = md_chars_to_number (buf, THUMB_SIZE);
18375 newval |= (value & 0x1ff) >> 1;
18376 md_number_to_chars (buf, newval, THUMB_SIZE);
18377 }
18378 break;
18379
18380 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
18381 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
18382 as_bad_where (fixP->fx_file, fixP->fx_line,
18383 _("branch out of range"));
18384
18385 if (fixP->fx_done || !seg->use_rela_p)
18386 {
18387 newval = md_chars_to_number (buf, THUMB_SIZE);
18388 newval |= (value & 0xfff) >> 1;
18389 md_number_to_chars (buf, newval, THUMB_SIZE);
18390 }
18391 break;
18392
18393 case BFD_RELOC_THUMB_PCREL_BRANCH20:
18394 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
18395 as_bad_where (fixP->fx_file, fixP->fx_line,
18396 _("conditional branch out of range"));
18397
18398 if (fixP->fx_done || !seg->use_rela_p)
18399 {
18400 offsetT newval2;
18401 addressT S, J1, J2, lo, hi;
18402
18403 S = (value & 0x00100000) >> 20;
18404 J2 = (value & 0x00080000) >> 19;
18405 J1 = (value & 0x00040000) >> 18;
18406 hi = (value & 0x0003f000) >> 12;
18407 lo = (value & 0x00000ffe) >> 1;
18408
18409 newval = md_chars_to_number (buf, THUMB_SIZE);
18410 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18411 newval |= (S << 10) | hi;
18412 newval2 |= (J1 << 13) | (J2 << 11) | lo;
18413 md_number_to_chars (buf, newval, THUMB_SIZE);
18414 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18415 }
18416 break;
18417
18418 case BFD_RELOC_THUMB_PCREL_BLX:
18419 case BFD_RELOC_THUMB_PCREL_BRANCH23:
18420 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
18421 as_bad_where (fixP->fx_file, fixP->fx_line,
18422 _("branch out of range"));
18423
18424 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
18425 /* For a BLX instruction, make sure that the relocation is rounded up
18426 to a word boundary. This follows the semantics of the instruction
18427 which specifies that bit 1 of the target address will come from bit
18428 1 of the base address. */
18429 value = (value + 1) & ~ 1;
18430
18431 if (fixP->fx_done || !seg->use_rela_p)
18432 {
18433 offsetT newval2;
18434
18435 newval = md_chars_to_number (buf, THUMB_SIZE);
18436 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18437 newval |= (value & 0x7fffff) >> 12;
18438 newval2 |= (value & 0xfff) >> 1;
18439 md_number_to_chars (buf, newval, THUMB_SIZE);
18440 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18441 }
18442 break;
18443
18444 case BFD_RELOC_THUMB_PCREL_BRANCH25:
18445 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
18446 as_bad_where (fixP->fx_file, fixP->fx_line,
18447 _("branch out of range"));
18448
18449 if (fixP->fx_done || !seg->use_rela_p)
18450 {
18451 offsetT newval2;
18452 addressT S, I1, I2, lo, hi;
18453
18454 S = (value & 0x01000000) >> 24;
18455 I1 = (value & 0x00800000) >> 23;
18456 I2 = (value & 0x00400000) >> 22;
18457 hi = (value & 0x003ff000) >> 12;
18458 lo = (value & 0x00000ffe) >> 1;
18459
18460 I1 = !(I1 ^ S);
18461 I2 = !(I2 ^ S);
18462
18463 newval = md_chars_to_number (buf, THUMB_SIZE);
18464 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18465 newval |= (S << 10) | hi;
18466 newval2 |= (I1 << 13) | (I2 << 11) | lo;
18467 md_number_to_chars (buf, newval, THUMB_SIZE);
18468 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18469 }
18470 break;
18471
18472 case BFD_RELOC_8:
18473 if (fixP->fx_done || !seg->use_rela_p)
18474 md_number_to_chars (buf, value, 1);
18475 break;
18476
18477 case BFD_RELOC_16:
18478 if (fixP->fx_done || !seg->use_rela_p)
18479 md_number_to_chars (buf, value, 2);
18480 break;
18481
18482 #ifdef OBJ_ELF
18483 case BFD_RELOC_ARM_TLS_GD32:
18484 case BFD_RELOC_ARM_TLS_LE32:
18485 case BFD_RELOC_ARM_TLS_IE32:
18486 case BFD_RELOC_ARM_TLS_LDM32:
18487 case BFD_RELOC_ARM_TLS_LDO32:
18488 S_SET_THREAD_LOCAL (fixP->fx_addsy);
18489 /* fall through */
18490
18491 case BFD_RELOC_ARM_GOT32:
18492 case BFD_RELOC_ARM_GOTOFF:
18493 case BFD_RELOC_ARM_TARGET2:
18494 if (fixP->fx_done || !seg->use_rela_p)
18495 md_number_to_chars (buf, 0, 4);
18496 break;
18497 #endif
18498
18499 case BFD_RELOC_RVA:
18500 case BFD_RELOC_32:
18501 case BFD_RELOC_ARM_TARGET1:
18502 case BFD_RELOC_ARM_ROSEGREL32:
18503 case BFD_RELOC_ARM_SBREL32:
18504 case BFD_RELOC_32_PCREL:
18505 #ifdef TE_PE
18506 case BFD_RELOC_32_SECREL:
18507 #endif
18508 if (fixP->fx_done || !seg->use_rela_p)
18509 #ifdef TE_WINCE
18510 /* For WinCE we only do this for pcrel fixups. */
18511 if (fixP->fx_done || fixP->fx_pcrel)
18512 #endif
18513 md_number_to_chars (buf, value, 4);
18514 break;
18515
18516 #ifdef OBJ_ELF
18517 case BFD_RELOC_ARM_PREL31:
18518 if (fixP->fx_done || !seg->use_rela_p)
18519 {
18520 newval = md_chars_to_number (buf, 4) & 0x80000000;
18521 if ((value ^ (value >> 1)) & 0x40000000)
18522 {
18523 as_bad_where (fixP->fx_file, fixP->fx_line,
18524 _("rel31 relocation overflow"));
18525 }
18526 newval |= value & 0x7fffffff;
18527 md_number_to_chars (buf, newval, 4);
18528 }
18529 break;
18530 #endif
18531
18532 case BFD_RELOC_ARM_CP_OFF_IMM:
18533 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
18534 if (value < -1023 || value > 1023 || (value & 3))
18535 as_bad_where (fixP->fx_file, fixP->fx_line,
18536 _("co-processor offset out of range"));
18537 cp_off_common:
18538 sign = value >= 0;
18539 if (value < 0)
18540 value = -value;
18541 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18542 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18543 newval = md_chars_to_number (buf, INSN_SIZE);
18544 else
18545 newval = get_thumb32_insn (buf);
18546 newval &= 0xff7fff00;
18547 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
18548 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18549 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18550 md_number_to_chars (buf, newval, INSN_SIZE);
18551 else
18552 put_thumb32_insn (buf, newval);
18553 break;
18554
18555 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
18556 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
18557 if (value < -255 || value > 255)
18558 as_bad_where (fixP->fx_file, fixP->fx_line,
18559 _("co-processor offset out of range"));
18560 value *= 4;
18561 goto cp_off_common;
18562
18563 case BFD_RELOC_ARM_THUMB_OFFSET:
18564 newval = md_chars_to_number (buf, THUMB_SIZE);
18565 /* Exactly what ranges, and where the offset is inserted depends
18566 on the type of instruction, we can establish this from the
18567 top 4 bits. */
18568 switch (newval >> 12)
18569 {
18570 case 4: /* PC load. */
18571 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
18572 forced to zero for these loads; md_pcrel_from has already
18573 compensated for this. */
18574 if (value & 3)
18575 as_bad_where (fixP->fx_file, fixP->fx_line,
18576 _("invalid offset, target not word aligned (0x%08lX)"),
18577 (((unsigned long) fixP->fx_frag->fr_address
18578 + (unsigned long) fixP->fx_where) & ~3)
18579 + (unsigned long) value);
18580
18581 if (value & ~0x3fc)
18582 as_bad_where (fixP->fx_file, fixP->fx_line,
18583 _("invalid offset, value too big (0x%08lX)"),
18584 (long) value);
18585
18586 newval |= value >> 2;
18587 break;
18588
18589 case 9: /* SP load/store. */
18590 if (value & ~0x3fc)
18591 as_bad_where (fixP->fx_file, fixP->fx_line,
18592 _("invalid offset, value too big (0x%08lX)"),
18593 (long) value);
18594 newval |= value >> 2;
18595 break;
18596
18597 case 6: /* Word load/store. */
18598 if (value & ~0x7c)
18599 as_bad_where (fixP->fx_file, fixP->fx_line,
18600 _("invalid offset, value too big (0x%08lX)"),
18601 (long) value);
18602 newval |= value << 4; /* 6 - 2. */
18603 break;
18604
18605 case 7: /* Byte load/store. */
18606 if (value & ~0x1f)
18607 as_bad_where (fixP->fx_file, fixP->fx_line,
18608 _("invalid offset, value too big (0x%08lX)"),
18609 (long) value);
18610 newval |= value << 6;
18611 break;
18612
18613 case 8: /* Halfword load/store. */
18614 if (value & ~0x3e)
18615 as_bad_where (fixP->fx_file, fixP->fx_line,
18616 _("invalid offset, value too big (0x%08lX)"),
18617 (long) value);
18618 newval |= value << 5; /* 6 - 1. */
18619 break;
18620
18621 default:
18622 as_bad_where (fixP->fx_file, fixP->fx_line,
18623 "Unable to process relocation for thumb opcode: %lx",
18624 (unsigned long) newval);
18625 break;
18626 }
18627 md_number_to_chars (buf, newval, THUMB_SIZE);
18628 break;
18629
18630 case BFD_RELOC_ARM_THUMB_ADD:
18631 /* This is a complicated relocation, since we use it for all of
18632 the following immediate relocations:
18633
18634 3bit ADD/SUB
18635 8bit ADD/SUB
18636 9bit ADD/SUB SP word-aligned
18637 10bit ADD PC/SP word-aligned
18638
18639 The type of instruction being processed is encoded in the
18640 instruction field:
18641
18642 0x8000 SUB
18643 0x00F0 Rd
18644 0x000F Rs
18645 */
18646 newval = md_chars_to_number (buf, THUMB_SIZE);
18647 {
18648 int rd = (newval >> 4) & 0xf;
18649 int rs = newval & 0xf;
18650 int subtract = !!(newval & 0x8000);
18651
18652 /* Check for HI regs, only very restricted cases allowed:
18653 Adjusting SP, and using PC or SP to get an address. */
18654 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
18655 || (rs > 7 && rs != REG_SP && rs != REG_PC))
18656 as_bad_where (fixP->fx_file, fixP->fx_line,
18657 _("invalid Hi register with immediate"));
18658
18659 /* If value is negative, choose the opposite instruction. */
18660 if (value < 0)
18661 {
18662 value = -value;
18663 subtract = !subtract;
18664 if (value < 0)
18665 as_bad_where (fixP->fx_file, fixP->fx_line,
18666 _("immediate value out of range"));
18667 }
18668
18669 if (rd == REG_SP)
18670 {
18671 if (value & ~0x1fc)
18672 as_bad_where (fixP->fx_file, fixP->fx_line,
18673 _("invalid immediate for stack address calculation"));
18674 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
18675 newval |= value >> 2;
18676 }
18677 else if (rs == REG_PC || rs == REG_SP)
18678 {
18679 if (subtract || value & ~0x3fc)
18680 as_bad_where (fixP->fx_file, fixP->fx_line,
18681 _("invalid immediate for address calculation (value = 0x%08lX)"),
18682 (unsigned long) value);
18683 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
18684 newval |= rd << 8;
18685 newval |= value >> 2;
18686 }
18687 else if (rs == rd)
18688 {
18689 if (value & ~0xff)
18690 as_bad_where (fixP->fx_file, fixP->fx_line,
18691 _("immediate value out of range"));
18692 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
18693 newval |= (rd << 8) | value;
18694 }
18695 else
18696 {
18697 if (value & ~0x7)
18698 as_bad_where (fixP->fx_file, fixP->fx_line,
18699 _("immediate value out of range"));
18700 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
18701 newval |= rd | (rs << 3) | (value << 6);
18702 }
18703 }
18704 md_number_to_chars (buf, newval, THUMB_SIZE);
18705 break;
18706
18707 case BFD_RELOC_ARM_THUMB_IMM:
18708 newval = md_chars_to_number (buf, THUMB_SIZE);
18709 if (value < 0 || value > 255)
18710 as_bad_where (fixP->fx_file, fixP->fx_line,
18711 _("invalid immediate: %ld is too large"),
18712 (long) value);
18713 newval |= value;
18714 md_number_to_chars (buf, newval, THUMB_SIZE);
18715 break;
18716
18717 case BFD_RELOC_ARM_THUMB_SHIFT:
18718 /* 5bit shift value (0..32). LSL cannot take 32. */
18719 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
18720 temp = newval & 0xf800;
18721 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
18722 as_bad_where (fixP->fx_file, fixP->fx_line,
18723 _("invalid shift value: %ld"), (long) value);
18724 /* Shifts of zero must be encoded as LSL. */
18725 if (value == 0)
18726 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
18727 /* Shifts of 32 are encoded as zero. */
18728 else if (value == 32)
18729 value = 0;
18730 newval |= value << 6;
18731 md_number_to_chars (buf, newval, THUMB_SIZE);
18732 break;
18733
18734 case BFD_RELOC_VTABLE_INHERIT:
18735 case BFD_RELOC_VTABLE_ENTRY:
18736 fixP->fx_done = 0;
18737 return;
18738
18739 case BFD_RELOC_ARM_MOVW:
18740 case BFD_RELOC_ARM_MOVT:
18741 case BFD_RELOC_ARM_THUMB_MOVW:
18742 case BFD_RELOC_ARM_THUMB_MOVT:
18743 if (fixP->fx_done || !seg->use_rela_p)
18744 {
18745 /* REL format relocations are limited to a 16-bit addend. */
18746 if (!fixP->fx_done)
18747 {
18748 if (value < -0x1000 || value > 0xffff)
18749 as_bad_where (fixP->fx_file, fixP->fx_line,
18750 _("offset too big"));
18751 }
18752 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
18753 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18754 {
18755 value >>= 16;
18756 }
18757
18758 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
18759 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18760 {
18761 newval = get_thumb32_insn (buf);
18762 newval &= 0xfbf08f00;
18763 newval |= (value & 0xf000) << 4;
18764 newval |= (value & 0x0800) << 15;
18765 newval |= (value & 0x0700) << 4;
18766 newval |= (value & 0x00ff);
18767 put_thumb32_insn (buf, newval);
18768 }
18769 else
18770 {
18771 newval = md_chars_to_number (buf, 4);
18772 newval &= 0xfff0f000;
18773 newval |= value & 0x0fff;
18774 newval |= (value & 0xf000) << 4;
18775 md_number_to_chars (buf, newval, 4);
18776 }
18777 }
18778 return;
18779
18780 case BFD_RELOC_ARM_ALU_PC_G0_NC:
18781 case BFD_RELOC_ARM_ALU_PC_G0:
18782 case BFD_RELOC_ARM_ALU_PC_G1_NC:
18783 case BFD_RELOC_ARM_ALU_PC_G1:
18784 case BFD_RELOC_ARM_ALU_PC_G2:
18785 case BFD_RELOC_ARM_ALU_SB_G0_NC:
18786 case BFD_RELOC_ARM_ALU_SB_G0:
18787 case BFD_RELOC_ARM_ALU_SB_G1_NC:
18788 case BFD_RELOC_ARM_ALU_SB_G1:
18789 case BFD_RELOC_ARM_ALU_SB_G2:
18790 assert (!fixP->fx_done);
18791 if (!seg->use_rela_p)
18792 {
18793 bfd_vma insn;
18794 bfd_vma encoded_addend;
18795 bfd_vma addend_abs = abs (value);
18796
18797 /* Check that the absolute value of the addend can be
18798 expressed as an 8-bit constant plus a rotation. */
18799 encoded_addend = encode_arm_immediate (addend_abs);
18800 if (encoded_addend == (unsigned int) FAIL)
18801 as_bad_where (fixP->fx_file, fixP->fx_line,
18802 _("the offset 0x%08lX is not representable"),
18803 addend_abs);
18804
18805 /* Extract the instruction. */
18806 insn = md_chars_to_number (buf, INSN_SIZE);
18807
18808 /* If the addend is positive, use an ADD instruction.
18809 Otherwise use a SUB. Take care not to destroy the S bit. */
18810 insn &= 0xff1fffff;
18811 if (value < 0)
18812 insn |= 1 << 22;
18813 else
18814 insn |= 1 << 23;
18815
18816 /* Place the encoded addend into the first 12 bits of the
18817 instruction. */
18818 insn &= 0xfffff000;
18819 insn |= encoded_addend;
18820
18821 /* Update the instruction. */
18822 md_number_to_chars (buf, insn, INSN_SIZE);
18823 }
18824 break;
18825
18826 case BFD_RELOC_ARM_LDR_PC_G0:
18827 case BFD_RELOC_ARM_LDR_PC_G1:
18828 case BFD_RELOC_ARM_LDR_PC_G2:
18829 case BFD_RELOC_ARM_LDR_SB_G0:
18830 case BFD_RELOC_ARM_LDR_SB_G1:
18831 case BFD_RELOC_ARM_LDR_SB_G2:
18832 assert (!fixP->fx_done);
18833 if (!seg->use_rela_p)
18834 {
18835 bfd_vma insn;
18836 bfd_vma addend_abs = abs (value);
18837
18838 /* Check that the absolute value of the addend can be
18839 encoded in 12 bits. */
18840 if (addend_abs >= 0x1000)
18841 as_bad_where (fixP->fx_file, fixP->fx_line,
18842 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
18843 addend_abs);
18844
18845 /* Extract the instruction. */
18846 insn = md_chars_to_number (buf, INSN_SIZE);
18847
18848 /* If the addend is negative, clear bit 23 of the instruction.
18849 Otherwise set it. */
18850 if (value < 0)
18851 insn &= ~(1 << 23);
18852 else
18853 insn |= 1 << 23;
18854
18855 /* Place the absolute value of the addend into the first 12 bits
18856 of the instruction. */
18857 insn &= 0xfffff000;
18858 insn |= addend_abs;
18859
18860 /* Update the instruction. */
18861 md_number_to_chars (buf, insn, INSN_SIZE);
18862 }
18863 break;
18864
18865 case BFD_RELOC_ARM_LDRS_PC_G0:
18866 case BFD_RELOC_ARM_LDRS_PC_G1:
18867 case BFD_RELOC_ARM_LDRS_PC_G2:
18868 case BFD_RELOC_ARM_LDRS_SB_G0:
18869 case BFD_RELOC_ARM_LDRS_SB_G1:
18870 case BFD_RELOC_ARM_LDRS_SB_G2:
18871 assert (!fixP->fx_done);
18872 if (!seg->use_rela_p)
18873 {
18874 bfd_vma insn;
18875 bfd_vma addend_abs = abs (value);
18876
18877 /* Check that the absolute value of the addend can be
18878 encoded in 8 bits. */
18879 if (addend_abs >= 0x100)
18880 as_bad_where (fixP->fx_file, fixP->fx_line,
18881 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
18882 addend_abs);
18883
18884 /* Extract the instruction. */
18885 insn = md_chars_to_number (buf, INSN_SIZE);
18886
18887 /* If the addend is negative, clear bit 23 of the instruction.
18888 Otherwise set it. */
18889 if (value < 0)
18890 insn &= ~(1 << 23);
18891 else
18892 insn |= 1 << 23;
18893
18894 /* Place the first four bits of the absolute value of the addend
18895 into the first 4 bits of the instruction, and the remaining
18896 four into bits 8 .. 11. */
18897 insn &= 0xfffff0f0;
18898 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
18899
18900 /* Update the instruction. */
18901 md_number_to_chars (buf, insn, INSN_SIZE);
18902 }
18903 break;
18904
18905 case BFD_RELOC_ARM_LDC_PC_G0:
18906 case BFD_RELOC_ARM_LDC_PC_G1:
18907 case BFD_RELOC_ARM_LDC_PC_G2:
18908 case BFD_RELOC_ARM_LDC_SB_G0:
18909 case BFD_RELOC_ARM_LDC_SB_G1:
18910 case BFD_RELOC_ARM_LDC_SB_G2:
18911 assert (!fixP->fx_done);
18912 if (!seg->use_rela_p)
18913 {
18914 bfd_vma insn;
18915 bfd_vma addend_abs = abs (value);
18916
18917 /* Check that the absolute value of the addend is a multiple of
18918 four and, when divided by four, fits in 8 bits. */
18919 if (addend_abs & 0x3)
18920 as_bad_where (fixP->fx_file, fixP->fx_line,
18921 _("bad offset 0x%08lX (must be word-aligned)"),
18922 addend_abs);
18923
18924 if ((addend_abs >> 2) > 0xff)
18925 as_bad_where (fixP->fx_file, fixP->fx_line,
18926 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
18927 addend_abs);
18928
18929 /* Extract the instruction. */
18930 insn = md_chars_to_number (buf, INSN_SIZE);
18931
18932 /* If the addend is negative, clear bit 23 of the instruction.
18933 Otherwise set it. */
18934 if (value < 0)
18935 insn &= ~(1 << 23);
18936 else
18937 insn |= 1 << 23;
18938
18939 /* Place the addend (divided by four) into the first eight
18940 bits of the instruction. */
18941 insn &= 0xfffffff0;
18942 insn |= addend_abs >> 2;
18943
18944 /* Update the instruction. */
18945 md_number_to_chars (buf, insn, INSN_SIZE);
18946 }
18947 break;
18948
18949 case BFD_RELOC_UNUSED:
18950 default:
18951 as_bad_where (fixP->fx_file, fixP->fx_line,
18952 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
18953 }
18954 }
18955
18956 /* Translate internal representation of relocation info to BFD target
18957 format. */
18958
18959 arelent *
18960 tc_gen_reloc (asection *section, fixS *fixp)
18961 {
18962 arelent * reloc;
18963 bfd_reloc_code_real_type code;
18964
18965 reloc = xmalloc (sizeof (arelent));
18966
18967 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
18968 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
18969 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
18970
18971 if (fixp->fx_pcrel)
18972 {
18973 if (section->use_rela_p)
18974 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
18975 else
18976 fixp->fx_offset = reloc->address;
18977 }
18978 reloc->addend = fixp->fx_offset;
18979
18980 switch (fixp->fx_r_type)
18981 {
18982 case BFD_RELOC_8:
18983 if (fixp->fx_pcrel)
18984 {
18985 code = BFD_RELOC_8_PCREL;
18986 break;
18987 }
18988
18989 case BFD_RELOC_16:
18990 if (fixp->fx_pcrel)
18991 {
18992 code = BFD_RELOC_16_PCREL;
18993 break;
18994 }
18995
18996 case BFD_RELOC_32:
18997 if (fixp->fx_pcrel)
18998 {
18999 code = BFD_RELOC_32_PCREL;
19000 break;
19001 }
19002
19003 case BFD_RELOC_ARM_MOVW:
19004 if (fixp->fx_pcrel)
19005 {
19006 code = BFD_RELOC_ARM_MOVW_PCREL;
19007 break;
19008 }
19009
19010 case BFD_RELOC_ARM_MOVT:
19011 if (fixp->fx_pcrel)
19012 {
19013 code = BFD_RELOC_ARM_MOVT_PCREL;
19014 break;
19015 }
19016
19017 case BFD_RELOC_ARM_THUMB_MOVW:
19018 if (fixp->fx_pcrel)
19019 {
19020 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
19021 break;
19022 }
19023
19024 case BFD_RELOC_ARM_THUMB_MOVT:
19025 if (fixp->fx_pcrel)
19026 {
19027 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
19028 break;
19029 }
19030
19031 case BFD_RELOC_NONE:
19032 case BFD_RELOC_ARM_PCREL_BRANCH:
19033 case BFD_RELOC_ARM_PCREL_BLX:
19034 case BFD_RELOC_RVA:
19035 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19036 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19037 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19038 case BFD_RELOC_THUMB_PCREL_BRANCH20:
19039 case BFD_RELOC_THUMB_PCREL_BRANCH23:
19040 case BFD_RELOC_THUMB_PCREL_BRANCH25:
19041 case BFD_RELOC_THUMB_PCREL_BLX:
19042 case BFD_RELOC_VTABLE_ENTRY:
19043 case BFD_RELOC_VTABLE_INHERIT:
19044 #ifdef TE_PE
19045 case BFD_RELOC_32_SECREL:
19046 #endif
19047 code = fixp->fx_r_type;
19048 break;
19049
19050 case BFD_RELOC_ARM_LITERAL:
19051 case BFD_RELOC_ARM_HWLITERAL:
19052 /* If this is called then the a literal has
19053 been referenced across a section boundary. */
19054 as_bad_where (fixp->fx_file, fixp->fx_line,
19055 _("literal referenced across section boundary"));
19056 return NULL;
19057
19058 #ifdef OBJ_ELF
19059 case BFD_RELOC_ARM_GOT32:
19060 case BFD_RELOC_ARM_GOTOFF:
19061 case BFD_RELOC_ARM_PLT32:
19062 case BFD_RELOC_ARM_TARGET1:
19063 case BFD_RELOC_ARM_ROSEGREL32:
19064 case BFD_RELOC_ARM_SBREL32:
19065 case BFD_RELOC_ARM_PREL31:
19066 case BFD_RELOC_ARM_TARGET2:
19067 case BFD_RELOC_ARM_TLS_LE32:
19068 case BFD_RELOC_ARM_TLS_LDO32:
19069 case BFD_RELOC_ARM_PCREL_CALL:
19070 case BFD_RELOC_ARM_PCREL_JUMP:
19071 case BFD_RELOC_ARM_ALU_PC_G0_NC:
19072 case BFD_RELOC_ARM_ALU_PC_G0:
19073 case BFD_RELOC_ARM_ALU_PC_G1_NC:
19074 case BFD_RELOC_ARM_ALU_PC_G1:
19075 case BFD_RELOC_ARM_ALU_PC_G2:
19076 case BFD_RELOC_ARM_LDR_PC_G0:
19077 case BFD_RELOC_ARM_LDR_PC_G1:
19078 case BFD_RELOC_ARM_LDR_PC_G2:
19079 case BFD_RELOC_ARM_LDRS_PC_G0:
19080 case BFD_RELOC_ARM_LDRS_PC_G1:
19081 case BFD_RELOC_ARM_LDRS_PC_G2:
19082 case BFD_RELOC_ARM_LDC_PC_G0:
19083 case BFD_RELOC_ARM_LDC_PC_G1:
19084 case BFD_RELOC_ARM_LDC_PC_G2:
19085 case BFD_RELOC_ARM_ALU_SB_G0_NC:
19086 case BFD_RELOC_ARM_ALU_SB_G0:
19087 case BFD_RELOC_ARM_ALU_SB_G1_NC:
19088 case BFD_RELOC_ARM_ALU_SB_G1:
19089 case BFD_RELOC_ARM_ALU_SB_G2:
19090 case BFD_RELOC_ARM_LDR_SB_G0:
19091 case BFD_RELOC_ARM_LDR_SB_G1:
19092 case BFD_RELOC_ARM_LDR_SB_G2:
19093 case BFD_RELOC_ARM_LDRS_SB_G0:
19094 case BFD_RELOC_ARM_LDRS_SB_G1:
19095 case BFD_RELOC_ARM_LDRS_SB_G2:
19096 case BFD_RELOC_ARM_LDC_SB_G0:
19097 case BFD_RELOC_ARM_LDC_SB_G1:
19098 case BFD_RELOC_ARM_LDC_SB_G2:
19099 code = fixp->fx_r_type;
19100 break;
19101
19102 case BFD_RELOC_ARM_TLS_GD32:
19103 case BFD_RELOC_ARM_TLS_IE32:
19104 case BFD_RELOC_ARM_TLS_LDM32:
19105 /* BFD will include the symbol's address in the addend.
19106 But we don't want that, so subtract it out again here. */
19107 if (!S_IS_COMMON (fixp->fx_addsy))
19108 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
19109 code = fixp->fx_r_type;
19110 break;
19111 #endif
19112
19113 case BFD_RELOC_ARM_IMMEDIATE:
19114 as_bad_where (fixp->fx_file, fixp->fx_line,
19115 _("internal relocation (type: IMMEDIATE) not fixed up"));
19116 return NULL;
19117
19118 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19119 as_bad_where (fixp->fx_file, fixp->fx_line,
19120 _("ADRL used for a symbol not defined in the same file"));
19121 return NULL;
19122
19123 case BFD_RELOC_ARM_OFFSET_IMM:
19124 if (section->use_rela_p)
19125 {
19126 code = fixp->fx_r_type;
19127 break;
19128 }
19129
19130 if (fixp->fx_addsy != NULL
19131 && !S_IS_DEFINED (fixp->fx_addsy)
19132 && S_IS_LOCAL (fixp->fx_addsy))
19133 {
19134 as_bad_where (fixp->fx_file, fixp->fx_line,
19135 _("undefined local label `%s'"),
19136 S_GET_NAME (fixp->fx_addsy));
19137 return NULL;
19138 }
19139
19140 as_bad_where (fixp->fx_file, fixp->fx_line,
19141 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
19142 return NULL;
19143
19144 default:
19145 {
19146 char * type;
19147
19148 switch (fixp->fx_r_type)
19149 {
19150 case BFD_RELOC_NONE: type = "NONE"; break;
19151 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
19152 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
19153 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
19154 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
19155 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
19156 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
19157 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
19158 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
19159 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
19160 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
19161 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
19162 default: type = _("<unknown>"); break;
19163 }
19164 as_bad_where (fixp->fx_file, fixp->fx_line,
19165 _("cannot represent %s relocation in this object file format"),
19166 type);
19167 return NULL;
19168 }
19169 }
19170
19171 #ifdef OBJ_ELF
19172 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
19173 && GOT_symbol
19174 && fixp->fx_addsy == GOT_symbol)
19175 {
19176 code = BFD_RELOC_ARM_GOTPC;
19177 reloc->addend = fixp->fx_offset = reloc->address;
19178 }
19179 #endif
19180
19181 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
19182
19183 if (reloc->howto == NULL)
19184 {
19185 as_bad_where (fixp->fx_file, fixp->fx_line,
19186 _("cannot represent %s relocation in this object file format"),
19187 bfd_get_reloc_code_name (code));
19188 return NULL;
19189 }
19190
19191 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
19192 vtable entry to be used in the relocation's section offset. */
19193 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19194 reloc->address = fixp->fx_offset;
19195
19196 return reloc;
19197 }
19198
19199 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
19200
19201 void
19202 cons_fix_new_arm (fragS * frag,
19203 int where,
19204 int size,
19205 expressionS * exp)
19206 {
19207 bfd_reloc_code_real_type type;
19208 int pcrel = 0;
19209
19210 /* Pick a reloc.
19211 FIXME: @@ Should look at CPU word size. */
19212 switch (size)
19213 {
19214 case 1:
19215 type = BFD_RELOC_8;
19216 break;
19217 case 2:
19218 type = BFD_RELOC_16;
19219 break;
19220 case 4:
19221 default:
19222 type = BFD_RELOC_32;
19223 break;
19224 case 8:
19225 type = BFD_RELOC_64;
19226 break;
19227 }
19228
19229 #ifdef TE_PE
19230 if (exp->X_op == O_secrel)
19231 {
19232 exp->X_op = O_symbol;
19233 type = BFD_RELOC_32_SECREL;
19234 }
19235 #endif
19236
19237 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
19238 }
19239
19240 #if defined OBJ_COFF || defined OBJ_ELF
19241 void
19242 arm_validate_fix (fixS * fixP)
19243 {
19244 /* If the destination of the branch is a defined symbol which does not have
19245 the THUMB_FUNC attribute, then we must be calling a function which has
19246 the (interfacearm) attribute. We look for the Thumb entry point to that
19247 function and change the branch to refer to that function instead. */
19248 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
19249 && fixP->fx_addsy != NULL
19250 && S_IS_DEFINED (fixP->fx_addsy)
19251 && ! THUMB_IS_FUNC (fixP->fx_addsy))
19252 {
19253 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
19254 }
19255 }
19256 #endif
19257
19258 int
19259 arm_force_relocation (struct fix * fixp)
19260 {
19261 #if defined (OBJ_COFF) && defined (TE_PE)
19262 if (fixp->fx_r_type == BFD_RELOC_RVA)
19263 return 1;
19264 #endif
19265
19266 /* Resolve these relocations even if the symbol is extern or weak. */
19267 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
19268 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
19269 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
19270 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
19271 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
19272 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
19273 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
19274 return 0;
19275
19276 /* Always leave these relocations for the linker. */
19277 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19278 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19279 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19280 return 1;
19281
19282 /* Always generate relocations against function symbols. */
19283 if (fixp->fx_r_type == BFD_RELOC_32
19284 && fixp->fx_addsy
19285 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
19286 return 1;
19287
19288 return generic_force_reloc (fixp);
19289 }
19290
19291 #if defined (OBJ_ELF) || defined (OBJ_COFF)
19292 /* Relocations against function names must be left unadjusted,
19293 so that the linker can use this information to generate interworking
19294 stubs. The MIPS version of this function
19295 also prevents relocations that are mips-16 specific, but I do not
19296 know why it does this.
19297
19298 FIXME:
19299 There is one other problem that ought to be addressed here, but
19300 which currently is not: Taking the address of a label (rather
19301 than a function) and then later jumping to that address. Such
19302 addresses also ought to have their bottom bit set (assuming that
19303 they reside in Thumb code), but at the moment they will not. */
19304
19305 bfd_boolean
19306 arm_fix_adjustable (fixS * fixP)
19307 {
19308 if (fixP->fx_addsy == NULL)
19309 return 1;
19310
19311 /* Preserve relocations against symbols with function type. */
19312 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
19313 return 0;
19314
19315 if (THUMB_IS_FUNC (fixP->fx_addsy)
19316 && fixP->fx_subsy == NULL)
19317 return 0;
19318
19319 /* We need the symbol name for the VTABLE entries. */
19320 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
19321 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19322 return 0;
19323
19324 /* Don't allow symbols to be discarded on GOT related relocs. */
19325 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
19326 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
19327 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
19328 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
19329 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
19330 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
19331 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
19332 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
19333 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
19334 return 0;
19335
19336 /* Similarly for group relocations. */
19337 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19338 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19339 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19340 return 0;
19341
19342 return 1;
19343 }
19344 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
19345
19346 #ifdef OBJ_ELF
19347
19348 const char *
19349 elf32_arm_target_format (void)
19350 {
19351 #ifdef TE_SYMBIAN
19352 return (target_big_endian
19353 ? "elf32-bigarm-symbian"
19354 : "elf32-littlearm-symbian");
19355 #elif defined (TE_VXWORKS)
19356 return (target_big_endian
19357 ? "elf32-bigarm-vxworks"
19358 : "elf32-littlearm-vxworks");
19359 #else
19360 if (target_big_endian)
19361 return "elf32-bigarm";
19362 else
19363 return "elf32-littlearm";
19364 #endif
19365 }
19366
19367 void
19368 armelf_frob_symbol (symbolS * symp,
19369 int * puntp)
19370 {
19371 elf_frob_symbol (symp, puntp);
19372 }
19373 #endif
19374
19375 /* MD interface: Finalization. */
19376
19377 /* A good place to do this, although this was probably not intended
19378 for this kind of use. We need to dump the literal pool before
19379 references are made to a null symbol pointer. */
19380
19381 void
19382 arm_cleanup (void)
19383 {
19384 literal_pool * pool;
19385
19386 for (pool = list_of_pools; pool; pool = pool->next)
19387 {
19388 /* Put it at the end of the relevent section. */
19389 subseg_set (pool->section, pool->sub_section);
19390 #ifdef OBJ_ELF
19391 arm_elf_change_section ();
19392 #endif
19393 s_ltorg (0);
19394 }
19395 }
19396
19397 /* Adjust the symbol table. This marks Thumb symbols as distinct from
19398 ARM ones. */
19399
19400 void
19401 arm_adjust_symtab (void)
19402 {
19403 #ifdef OBJ_COFF
19404 symbolS * sym;
19405
19406 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
19407 {
19408 if (ARM_IS_THUMB (sym))
19409 {
19410 if (THUMB_IS_FUNC (sym))
19411 {
19412 /* Mark the symbol as a Thumb function. */
19413 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
19414 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
19415 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
19416
19417 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
19418 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
19419 else
19420 as_bad (_("%s: unexpected function type: %d"),
19421 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
19422 }
19423 else switch (S_GET_STORAGE_CLASS (sym))
19424 {
19425 case C_EXT:
19426 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
19427 break;
19428 case C_STAT:
19429 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
19430 break;
19431 case C_LABEL:
19432 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
19433 break;
19434 default:
19435 /* Do nothing. */
19436 break;
19437 }
19438 }
19439
19440 if (ARM_IS_INTERWORK (sym))
19441 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
19442 }
19443 #endif
19444 #ifdef OBJ_ELF
19445 symbolS * sym;
19446 char bind;
19447
19448 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
19449 {
19450 if (ARM_IS_THUMB (sym))
19451 {
19452 elf_symbol_type * elf_sym;
19453
19454 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
19455 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
19456
19457 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
19458 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
19459 {
19460 /* If it's a .thumb_func, declare it as so,
19461 otherwise tag label as .code 16. */
19462 if (THUMB_IS_FUNC (sym))
19463 elf_sym->internal_elf_sym.st_info =
19464 ELF_ST_INFO (bind, STT_ARM_TFUNC);
19465 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
19466 elf_sym->internal_elf_sym.st_info =
19467 ELF_ST_INFO (bind, STT_ARM_16BIT);
19468 }
19469 }
19470 }
19471 #endif
19472 }
19473
19474 /* MD interface: Initialization. */
19475
19476 static void
19477 set_constant_flonums (void)
19478 {
19479 int i;
19480
19481 for (i = 0; i < NUM_FLOAT_VALS; i++)
19482 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
19483 abort ();
19484 }
19485
19486 /* Auto-select Thumb mode if it's the only available instruction set for the
19487 given architecture. */
19488
19489 static void
19490 autoselect_thumb_from_cpu_variant (void)
19491 {
19492 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
19493 opcode_select (16);
19494 }
19495
19496 void
19497 md_begin (void)
19498 {
19499 unsigned mach;
19500 unsigned int i;
19501
19502 if ( (arm_ops_hsh = hash_new ()) == NULL
19503 || (arm_cond_hsh = hash_new ()) == NULL
19504 || (arm_shift_hsh = hash_new ()) == NULL
19505 || (arm_psr_hsh = hash_new ()) == NULL
19506 || (arm_v7m_psr_hsh = hash_new ()) == NULL
19507 || (arm_reg_hsh = hash_new ()) == NULL
19508 || (arm_reloc_hsh = hash_new ()) == NULL
19509 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
19510 as_fatal (_("virtual memory exhausted"));
19511
19512 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
19513 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
19514 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
19515 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
19516 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
19517 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
19518 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
19519 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
19520 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
19521 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (PTR) (v7m_psrs + i));
19522 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
19523 hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i));
19524 for (i = 0;
19525 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
19526 i++)
19527 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
19528 (PTR) (barrier_opt_names + i));
19529 #ifdef OBJ_ELF
19530 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
19531 hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i));
19532 #endif
19533
19534 set_constant_flonums ();
19535
19536 /* Set the cpu variant based on the command-line options. We prefer
19537 -mcpu= over -march= if both are set (as for GCC); and we prefer
19538 -mfpu= over any other way of setting the floating point unit.
19539 Use of legacy options with new options are faulted. */
19540 if (legacy_cpu)
19541 {
19542 if (mcpu_cpu_opt || march_cpu_opt)
19543 as_bad (_("use of old and new-style options to set CPU type"));
19544
19545 mcpu_cpu_opt = legacy_cpu;
19546 }
19547 else if (!mcpu_cpu_opt)
19548 mcpu_cpu_opt = march_cpu_opt;
19549
19550 if (legacy_fpu)
19551 {
19552 if (mfpu_opt)
19553 as_bad (_("use of old and new-style options to set FPU type"));
19554
19555 mfpu_opt = legacy_fpu;
19556 }
19557 else if (!mfpu_opt)
19558 {
19559 #if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
19560 /* Some environments specify a default FPU. If they don't, infer it
19561 from the processor. */
19562 if (mcpu_fpu_opt)
19563 mfpu_opt = mcpu_fpu_opt;
19564 else
19565 mfpu_opt = march_fpu_opt;
19566 #else
19567 mfpu_opt = &fpu_default;
19568 #endif
19569 }
19570
19571 if (!mfpu_opt)
19572 {
19573 if (mcpu_cpu_opt != NULL)
19574 mfpu_opt = &fpu_default;
19575 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
19576 mfpu_opt = &fpu_arch_vfp_v2;
19577 else
19578 mfpu_opt = &fpu_arch_fpa;
19579 }
19580
19581 #ifdef CPU_DEFAULT
19582 if (!mcpu_cpu_opt)
19583 {
19584 mcpu_cpu_opt = &cpu_default;
19585 selected_cpu = cpu_default;
19586 }
19587 #else
19588 if (mcpu_cpu_opt)
19589 selected_cpu = *mcpu_cpu_opt;
19590 else
19591 mcpu_cpu_opt = &arm_arch_any;
19592 #endif
19593
19594 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
19595
19596 autoselect_thumb_from_cpu_variant ();
19597
19598 arm_arch_used = thumb_arch_used = arm_arch_none;
19599
19600 #if defined OBJ_COFF || defined OBJ_ELF
19601 {
19602 unsigned int flags = 0;
19603
19604 #if defined OBJ_ELF
19605 flags = meabi_flags;
19606
19607 switch (meabi_flags)
19608 {
19609 case EF_ARM_EABI_UNKNOWN:
19610 #endif
19611 /* Set the flags in the private structure. */
19612 if (uses_apcs_26) flags |= F_APCS26;
19613 if (support_interwork) flags |= F_INTERWORK;
19614 if (uses_apcs_float) flags |= F_APCS_FLOAT;
19615 if (pic_code) flags |= F_PIC;
19616 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
19617 flags |= F_SOFT_FLOAT;
19618
19619 switch (mfloat_abi_opt)
19620 {
19621 case ARM_FLOAT_ABI_SOFT:
19622 case ARM_FLOAT_ABI_SOFTFP:
19623 flags |= F_SOFT_FLOAT;
19624 break;
19625
19626 case ARM_FLOAT_ABI_HARD:
19627 if (flags & F_SOFT_FLOAT)
19628 as_bad (_("hard-float conflicts with specified fpu"));
19629 break;
19630 }
19631
19632 /* Using pure-endian doubles (even if soft-float). */
19633 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
19634 flags |= F_VFP_FLOAT;
19635
19636 #if defined OBJ_ELF
19637 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
19638 flags |= EF_ARM_MAVERICK_FLOAT;
19639 break;
19640
19641 case EF_ARM_EABI_VER4:
19642 case EF_ARM_EABI_VER5:
19643 /* No additional flags to set. */
19644 break;
19645
19646 default:
19647 abort ();
19648 }
19649 #endif
19650 bfd_set_private_flags (stdoutput, flags);
19651
19652 /* We have run out flags in the COFF header to encode the
19653 status of ATPCS support, so instead we create a dummy,
19654 empty, debug section called .arm.atpcs. */
19655 if (atpcs)
19656 {
19657 asection * sec;
19658
19659 sec = bfd_make_section (stdoutput, ".arm.atpcs");
19660
19661 if (sec != NULL)
19662 {
19663 bfd_set_section_flags
19664 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
19665 bfd_set_section_size (stdoutput, sec, 0);
19666 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
19667 }
19668 }
19669 }
19670 #endif
19671
19672 /* Record the CPU type as well. */
19673 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
19674 mach = bfd_mach_arm_iWMMXt2;
19675 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
19676 mach = bfd_mach_arm_iWMMXt;
19677 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
19678 mach = bfd_mach_arm_XScale;
19679 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
19680 mach = bfd_mach_arm_ep9312;
19681 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
19682 mach = bfd_mach_arm_5TE;
19683 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
19684 {
19685 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
19686 mach = bfd_mach_arm_5T;
19687 else
19688 mach = bfd_mach_arm_5;
19689 }
19690 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
19691 {
19692 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
19693 mach = bfd_mach_arm_4T;
19694 else
19695 mach = bfd_mach_arm_4;
19696 }
19697 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
19698 mach = bfd_mach_arm_3M;
19699 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
19700 mach = bfd_mach_arm_3;
19701 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
19702 mach = bfd_mach_arm_2a;
19703 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
19704 mach = bfd_mach_arm_2;
19705 else
19706 mach = bfd_mach_arm_unknown;
19707
19708 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
19709 }
19710
19711 /* Command line processing. */
19712
19713 /* md_parse_option
19714 Invocation line includes a switch not recognized by the base assembler.
19715 See if it's a processor-specific option.
19716
19717 This routine is somewhat complicated by the need for backwards
19718 compatibility (since older releases of gcc can't be changed).
19719 The new options try to make the interface as compatible as
19720 possible with GCC.
19721
19722 New options (supported) are:
19723
19724 -mcpu=<cpu name> Assemble for selected processor
19725 -march=<architecture name> Assemble for selected architecture
19726 -mfpu=<fpu architecture> Assemble for selected FPU.
19727 -EB/-mbig-endian Big-endian
19728 -EL/-mlittle-endian Little-endian
19729 -k Generate PIC code
19730 -mthumb Start in Thumb mode
19731 -mthumb-interwork Code supports ARM/Thumb interworking
19732
19733 For now we will also provide support for:
19734
19735 -mapcs-32 32-bit Program counter
19736 -mapcs-26 26-bit Program counter
19737 -macps-float Floats passed in FP registers
19738 -mapcs-reentrant Reentrant code
19739 -matpcs
19740 (sometime these will probably be replaced with -mapcs=<list of options>
19741 and -matpcs=<list of options>)
19742
19743 The remaining options are only supported for back-wards compatibility.
19744 Cpu variants, the arm part is optional:
19745 -m[arm]1 Currently not supported.
19746 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
19747 -m[arm]3 Arm 3 processor
19748 -m[arm]6[xx], Arm 6 processors
19749 -m[arm]7[xx][t][[d]m] Arm 7 processors
19750 -m[arm]8[10] Arm 8 processors
19751 -m[arm]9[20][tdmi] Arm 9 processors
19752 -mstrongarm[110[0]] StrongARM processors
19753 -mxscale XScale processors
19754 -m[arm]v[2345[t[e]]] Arm architectures
19755 -mall All (except the ARM1)
19756 FP variants:
19757 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
19758 -mfpe-old (No float load/store multiples)
19759 -mvfpxd VFP Single precision
19760 -mvfp All VFP
19761 -mno-fpu Disable all floating point instructions
19762
19763 The following CPU names are recognized:
19764 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
19765 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
19766 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
19767 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
19768 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
19769 arm10t arm10e, arm1020t, arm1020e, arm10200e,
19770 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
19771
19772 */
19773
19774 const char * md_shortopts = "m:k";
19775
19776 #ifdef ARM_BI_ENDIAN
19777 #define OPTION_EB (OPTION_MD_BASE + 0)
19778 #define OPTION_EL (OPTION_MD_BASE + 1)
19779 #else
19780 #if TARGET_BYTES_BIG_ENDIAN
19781 #define OPTION_EB (OPTION_MD_BASE + 0)
19782 #else
19783 #define OPTION_EL (OPTION_MD_BASE + 1)
19784 #endif
19785 #endif
19786
19787 struct option md_longopts[] =
19788 {
19789 #ifdef OPTION_EB
19790 {"EB", no_argument, NULL, OPTION_EB},
19791 #endif
19792 #ifdef OPTION_EL
19793 {"EL", no_argument, NULL, OPTION_EL},
19794 #endif
19795 {NULL, no_argument, NULL, 0}
19796 };
19797
19798 size_t md_longopts_size = sizeof (md_longopts);
19799
19800 struct arm_option_table
19801 {
19802 char *option; /* Option name to match. */
19803 char *help; /* Help information. */
19804 int *var; /* Variable to change. */
19805 int value; /* What to change it to. */
19806 char *deprecated; /* If non-null, print this message. */
19807 };
19808
19809 struct arm_option_table arm_opts[] =
19810 {
19811 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
19812 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
19813 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
19814 &support_interwork, 1, NULL},
19815 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
19816 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
19817 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
19818 1, NULL},
19819 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
19820 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
19821 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
19822 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
19823 NULL},
19824
19825 /* These are recognized by the assembler, but have no affect on code. */
19826 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
19827 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
19828 {NULL, NULL, NULL, 0, NULL}
19829 };
19830
19831 struct arm_legacy_option_table
19832 {
19833 char *option; /* Option name to match. */
19834 const arm_feature_set **var; /* Variable to change. */
19835 const arm_feature_set value; /* What to change it to. */
19836 char *deprecated; /* If non-null, print this message. */
19837 };
19838
19839 const struct arm_legacy_option_table arm_legacy_opts[] =
19840 {
19841 /* DON'T add any new processors to this list -- we want the whole list
19842 to go away... Add them to the processors table instead. */
19843 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19844 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19845 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19846 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19847 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19848 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19849 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19850 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19851 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19852 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19853 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19854 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19855 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19856 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19857 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19858 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19859 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19860 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19861 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19862 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19863 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19864 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19865 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19866 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19867 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19868 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19869 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19870 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19871 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19872 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19873 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19874 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19875 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19876 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19877 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19878 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19879 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19880 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19881 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19882 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19883 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19884 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19885 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19886 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19887 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19888 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19889 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19890 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19891 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19892 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19893 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19894 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19895 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19896 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19897 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19898 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19899 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19900 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19901 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19902 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19903 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19904 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19905 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19906 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19907 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19908 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19909 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19910 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19911 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
19912 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
19913 N_("use -mcpu=strongarm110")},
19914 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
19915 N_("use -mcpu=strongarm1100")},
19916 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
19917 N_("use -mcpu=strongarm1110")},
19918 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
19919 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
19920 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
19921
19922 /* Architecture variants -- don't add any more to this list either. */
19923 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19924 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19925 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19926 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19927 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19928 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19929 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
19930 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
19931 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
19932 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
19933 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
19934 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
19935 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
19936 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
19937 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
19938 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
19939 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
19940 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
19941
19942 /* Floating point variants -- don't add any more to this list either. */
19943 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
19944 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
19945 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
19946 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
19947 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
19948
19949 {NULL, NULL, ARM_ARCH_NONE, NULL}
19950 };
19951
19952 struct arm_cpu_option_table
19953 {
19954 char *name;
19955 const arm_feature_set value;
19956 /* For some CPUs we assume an FPU unless the user explicitly sets
19957 -mfpu=... */
19958 const arm_feature_set default_fpu;
19959 /* The canonical name of the CPU, or NULL to use NAME converted to upper
19960 case. */
19961 const char *canonical_name;
19962 };
19963
19964 /* This list should, at a minimum, contain all the cpu names
19965 recognized by GCC. */
19966 static const struct arm_cpu_option_table arm_cpus[] =
19967 {
19968 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
19969 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
19970 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
19971 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
19972 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
19973 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19974 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19975 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19976 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19977 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19978 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19979 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
19980 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19981 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
19982 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19983 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
19984 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19985 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19986 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19987 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19988 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19989 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19990 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19991 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19992 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19993 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19994 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19995 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19996 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19997 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19998 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19999 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20000 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20001 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20002 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20003 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20004 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20005 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20006 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20007 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
20008 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20009 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20010 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20011 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20012 /* For V5 or later processors we default to using VFP; but the user
20013 should really set the FPU type explicitly. */
20014 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20015 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20016 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20017 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20018 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20019 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20020 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
20021 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20022 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20023 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
20024 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20025 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20026 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20027 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20028 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20029 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
20030 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20031 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20032 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20033 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
20034 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20035 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
20036 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
20037 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
20038 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
20039 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
20040 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
20041 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
20042 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
20043 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
20044 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
20045 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
20046 | FPU_NEON_EXT_V1),
20047 NULL},
20048 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
20049 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
20050 /* ??? XSCALE is really an architecture. */
20051 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
20052 /* ??? iwmmxt is not a processor. */
20053 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
20054 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
20055 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
20056 /* Maverick */
20057 {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
20058 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
20059 };
20060
20061 struct arm_arch_option_table
20062 {
20063 char *name;
20064 const arm_feature_set value;
20065 const arm_feature_set default_fpu;
20066 };
20067
20068 /* This list should, at a minimum, contain all the architecture names
20069 recognized by GCC. */
20070 static const struct arm_arch_option_table arm_archs[] =
20071 {
20072 {"all", ARM_ANY, FPU_ARCH_FPA},
20073 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
20074 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
20075 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
20076 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
20077 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
20078 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
20079 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
20080 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
20081 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
20082 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
20083 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
20084 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
20085 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
20086 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
20087 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
20088 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
20089 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
20090 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
20091 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
20092 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
20093 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
20094 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
20095 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
20096 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
20097 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
20098 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
20099 /* The official spelling of the ARMv7 profile variants is the dashed form.
20100 Accept the non-dashed form for compatibility with old toolchains. */
20101 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20102 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20103 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
20104 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20105 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20106 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
20107 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
20108 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
20109 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
20110 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
20111 };
20112
20113 /* ISA extensions in the co-processor space. */
20114 struct arm_option_cpu_value_table
20115 {
20116 char *name;
20117 const arm_feature_set value;
20118 };
20119
20120 static const struct arm_option_cpu_value_table arm_extensions[] =
20121 {
20122 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
20123 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
20124 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
20125 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
20126 {NULL, ARM_ARCH_NONE}
20127 };
20128
20129 /* This list should, at a minimum, contain all the fpu names
20130 recognized by GCC. */
20131 static const struct arm_option_cpu_value_table arm_fpus[] =
20132 {
20133 {"softfpa", FPU_NONE},
20134 {"fpe", FPU_ARCH_FPE},
20135 {"fpe2", FPU_ARCH_FPE},
20136 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
20137 {"fpa", FPU_ARCH_FPA},
20138 {"fpa10", FPU_ARCH_FPA},
20139 {"fpa11", FPU_ARCH_FPA},
20140 {"arm7500fe", FPU_ARCH_FPA},
20141 {"softvfp", FPU_ARCH_VFP},
20142 {"softvfp+vfp", FPU_ARCH_VFP_V2},
20143 {"vfp", FPU_ARCH_VFP_V2},
20144 {"vfp9", FPU_ARCH_VFP_V2},
20145 {"vfp3", FPU_ARCH_VFP_V3},
20146 {"vfp10", FPU_ARCH_VFP_V2},
20147 {"vfp10-r0", FPU_ARCH_VFP_V1},
20148 {"vfpxd", FPU_ARCH_VFP_V1xD},
20149 {"arm1020t", FPU_ARCH_VFP_V1},
20150 {"arm1020e", FPU_ARCH_VFP_V2},
20151 {"arm1136jfs", FPU_ARCH_VFP_V2},
20152 {"arm1136jf-s", FPU_ARCH_VFP_V2},
20153 {"maverick", FPU_ARCH_MAVERICK},
20154 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
20155 {NULL, ARM_ARCH_NONE}
20156 };
20157
20158 struct arm_option_value_table
20159 {
20160 char *name;
20161 long value;
20162 };
20163
20164 static const struct arm_option_value_table arm_float_abis[] =
20165 {
20166 {"hard", ARM_FLOAT_ABI_HARD},
20167 {"softfp", ARM_FLOAT_ABI_SOFTFP},
20168 {"soft", ARM_FLOAT_ABI_SOFT},
20169 {NULL, 0}
20170 };
20171
20172 #ifdef OBJ_ELF
20173 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
20174 static const struct arm_option_value_table arm_eabis[] =
20175 {
20176 {"gnu", EF_ARM_EABI_UNKNOWN},
20177 {"4", EF_ARM_EABI_VER4},
20178 {"5", EF_ARM_EABI_VER5},
20179 {NULL, 0}
20180 };
20181 #endif
20182
20183 struct arm_long_option_table
20184 {
20185 char * option; /* Substring to match. */
20186 char * help; /* Help information. */
20187 int (* func) (char * subopt); /* Function to decode sub-option. */
20188 char * deprecated; /* If non-null, print this message. */
20189 };
20190
20191 static int
20192 arm_parse_extension (char * str, const arm_feature_set **opt_p)
20193 {
20194 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
20195
20196 /* Copy the feature set, so that we can modify it. */
20197 *ext_set = **opt_p;
20198 *opt_p = ext_set;
20199
20200 while (str != NULL && *str != 0)
20201 {
20202 const struct arm_option_cpu_value_table * opt;
20203 char * ext;
20204 int optlen;
20205
20206 if (*str != '+')
20207 {
20208 as_bad (_("invalid architectural extension"));
20209 return 0;
20210 }
20211
20212 str++;
20213 ext = strchr (str, '+');
20214
20215 if (ext != NULL)
20216 optlen = ext - str;
20217 else
20218 optlen = strlen (str);
20219
20220 if (optlen == 0)
20221 {
20222 as_bad (_("missing architectural extension"));
20223 return 0;
20224 }
20225
20226 for (opt = arm_extensions; opt->name != NULL; opt++)
20227 if (strncmp (opt->name, str, optlen) == 0)
20228 {
20229 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
20230 break;
20231 }
20232
20233 if (opt->name == NULL)
20234 {
20235 as_bad (_("unknown architectural extnsion `%s'"), str);
20236 return 0;
20237 }
20238
20239 str = ext;
20240 };
20241
20242 return 1;
20243 }
20244
20245 static int
20246 arm_parse_cpu (char * str)
20247 {
20248 const struct arm_cpu_option_table * opt;
20249 char * ext = strchr (str, '+');
20250 int optlen;
20251
20252 if (ext != NULL)
20253 optlen = ext - str;
20254 else
20255 optlen = strlen (str);
20256
20257 if (optlen == 0)
20258 {
20259 as_bad (_("missing cpu name `%s'"), str);
20260 return 0;
20261 }
20262
20263 for (opt = arm_cpus; opt->name != NULL; opt++)
20264 if (strncmp (opt->name, str, optlen) == 0)
20265 {
20266 mcpu_cpu_opt = &opt->value;
20267 mcpu_fpu_opt = &opt->default_fpu;
20268 if (opt->canonical_name)
20269 strcpy(selected_cpu_name, opt->canonical_name);
20270 else
20271 {
20272 int i;
20273 for (i = 0; i < optlen; i++)
20274 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20275 selected_cpu_name[i] = 0;
20276 }
20277
20278 if (ext != NULL)
20279 return arm_parse_extension (ext, &mcpu_cpu_opt);
20280
20281 return 1;
20282 }
20283
20284 as_bad (_("unknown cpu `%s'"), str);
20285 return 0;
20286 }
20287
20288 static int
20289 arm_parse_arch (char * str)
20290 {
20291 const struct arm_arch_option_table *opt;
20292 char *ext = strchr (str, '+');
20293 int optlen;
20294
20295 if (ext != NULL)
20296 optlen = ext - str;
20297 else
20298 optlen = strlen (str);
20299
20300 if (optlen == 0)
20301 {
20302 as_bad (_("missing architecture name `%s'"), str);
20303 return 0;
20304 }
20305
20306 for (opt = arm_archs; opt->name != NULL; opt++)
20307 if (streq (opt->name, str))
20308 {
20309 march_cpu_opt = &opt->value;
20310 march_fpu_opt = &opt->default_fpu;
20311 strcpy(selected_cpu_name, opt->name);
20312
20313 if (ext != NULL)
20314 return arm_parse_extension (ext, &march_cpu_opt);
20315
20316 return 1;
20317 }
20318
20319 as_bad (_("unknown architecture `%s'\n"), str);
20320 return 0;
20321 }
20322
20323 static int
20324 arm_parse_fpu (char * str)
20325 {
20326 const struct arm_option_cpu_value_table * opt;
20327
20328 for (opt = arm_fpus; opt->name != NULL; opt++)
20329 if (streq (opt->name, str))
20330 {
20331 mfpu_opt = &opt->value;
20332 return 1;
20333 }
20334
20335 as_bad (_("unknown floating point format `%s'\n"), str);
20336 return 0;
20337 }
20338
20339 static int
20340 arm_parse_float_abi (char * str)
20341 {
20342 const struct arm_option_value_table * opt;
20343
20344 for (opt = arm_float_abis; opt->name != NULL; opt++)
20345 if (streq (opt->name, str))
20346 {
20347 mfloat_abi_opt = opt->value;
20348 return 1;
20349 }
20350
20351 as_bad (_("unknown floating point abi `%s'\n"), str);
20352 return 0;
20353 }
20354
20355 #ifdef OBJ_ELF
20356 static int
20357 arm_parse_eabi (char * str)
20358 {
20359 const struct arm_option_value_table *opt;
20360
20361 for (opt = arm_eabis; opt->name != NULL; opt++)
20362 if (streq (opt->name, str))
20363 {
20364 meabi_flags = opt->value;
20365 return 1;
20366 }
20367 as_bad (_("unknown EABI `%s'\n"), str);
20368 return 0;
20369 }
20370 #endif
20371
20372 struct arm_long_option_table arm_long_opts[] =
20373 {
20374 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
20375 arm_parse_cpu, NULL},
20376 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
20377 arm_parse_arch, NULL},
20378 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
20379 arm_parse_fpu, NULL},
20380 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
20381 arm_parse_float_abi, NULL},
20382 #ifdef OBJ_ELF
20383 {"meabi=", N_("<ver>\t assemble for eabi version <ver>"),
20384 arm_parse_eabi, NULL},
20385 #endif
20386 {NULL, NULL, 0, NULL}
20387 };
20388
20389 int
20390 md_parse_option (int c, char * arg)
20391 {
20392 struct arm_option_table *opt;
20393 const struct arm_legacy_option_table *fopt;
20394 struct arm_long_option_table *lopt;
20395
20396 switch (c)
20397 {
20398 #ifdef OPTION_EB
20399 case OPTION_EB:
20400 target_big_endian = 1;
20401 break;
20402 #endif
20403
20404 #ifdef OPTION_EL
20405 case OPTION_EL:
20406 target_big_endian = 0;
20407 break;
20408 #endif
20409
20410 case 'a':
20411 /* Listing option. Just ignore these, we don't support additional
20412 ones. */
20413 return 0;
20414
20415 default:
20416 for (opt = arm_opts; opt->option != NULL; opt++)
20417 {
20418 if (c == opt->option[0]
20419 && ((arg == NULL && opt->option[1] == 0)
20420 || streq (arg, opt->option + 1)))
20421 {
20422 #if WARN_DEPRECATED
20423 /* If the option is deprecated, tell the user. */
20424 if (opt->deprecated != NULL)
20425 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20426 arg ? arg : "", _(opt->deprecated));
20427 #endif
20428
20429 if (opt->var != NULL)
20430 *opt->var = opt->value;
20431
20432 return 1;
20433 }
20434 }
20435
20436 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
20437 {
20438 if (c == fopt->option[0]
20439 && ((arg == NULL && fopt->option[1] == 0)
20440 || streq (arg, fopt->option + 1)))
20441 {
20442 #if WARN_DEPRECATED
20443 /* If the option is deprecated, tell the user. */
20444 if (fopt->deprecated != NULL)
20445 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20446 arg ? arg : "", _(fopt->deprecated));
20447 #endif
20448
20449 if (fopt->var != NULL)
20450 *fopt->var = &fopt->value;
20451
20452 return 1;
20453 }
20454 }
20455
20456 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20457 {
20458 /* These options are expected to have an argument. */
20459 if (c == lopt->option[0]
20460 && arg != NULL
20461 && strncmp (arg, lopt->option + 1,
20462 strlen (lopt->option + 1)) == 0)
20463 {
20464 #if WARN_DEPRECATED
20465 /* If the option is deprecated, tell the user. */
20466 if (lopt->deprecated != NULL)
20467 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
20468 _(lopt->deprecated));
20469 #endif
20470
20471 /* Call the sup-option parser. */
20472 return lopt->func (arg + strlen (lopt->option) - 1);
20473 }
20474 }
20475
20476 return 0;
20477 }
20478
20479 return 1;
20480 }
20481
20482 void
20483 md_show_usage (FILE * fp)
20484 {
20485 struct arm_option_table *opt;
20486 struct arm_long_option_table *lopt;
20487
20488 fprintf (fp, _(" ARM-specific assembler options:\n"));
20489
20490 for (opt = arm_opts; opt->option != NULL; opt++)
20491 if (opt->help != NULL)
20492 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
20493
20494 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20495 if (lopt->help != NULL)
20496 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
20497
20498 #ifdef OPTION_EB
20499 fprintf (fp, _("\
20500 -EB assemble code for a big-endian cpu\n"));
20501 #endif
20502
20503 #ifdef OPTION_EL
20504 fprintf (fp, _("\
20505 -EL assemble code for a little-endian cpu\n"));
20506 #endif
20507 }
20508
20509
20510 #ifdef OBJ_ELF
20511 typedef struct
20512 {
20513 int val;
20514 arm_feature_set flags;
20515 } cpu_arch_ver_table;
20516
20517 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
20518 least features first. */
20519 static const cpu_arch_ver_table cpu_arch_ver[] =
20520 {
20521 {1, ARM_ARCH_V4},
20522 {2, ARM_ARCH_V4T},
20523 {3, ARM_ARCH_V5},
20524 {4, ARM_ARCH_V5TE},
20525 {5, ARM_ARCH_V5TEJ},
20526 {6, ARM_ARCH_V6},
20527 {7, ARM_ARCH_V6Z},
20528 {8, ARM_ARCH_V6K},
20529 {9, ARM_ARCH_V6T2},
20530 {10, ARM_ARCH_V7A},
20531 {10, ARM_ARCH_V7R},
20532 {10, ARM_ARCH_V7M},
20533 {0, ARM_ARCH_NONE}
20534 };
20535
20536 /* Set the public EABI object attributes. */
20537 static void
20538 aeabi_set_public_attributes (void)
20539 {
20540 int arch;
20541 arm_feature_set flags;
20542 arm_feature_set tmp;
20543 const cpu_arch_ver_table *p;
20544
20545 /* Choose the architecture based on the capabilities of the requested cpu
20546 (if any) and/or the instructions actually used. */
20547 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
20548 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
20549 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
20550 /*Allow the user to override the reported architecture. */
20551 if (object_arch)
20552 {
20553 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
20554 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
20555 }
20556
20557 tmp = flags;
20558 arch = 0;
20559 for (p = cpu_arch_ver; p->val; p++)
20560 {
20561 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
20562 {
20563 arch = p->val;
20564 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
20565 }
20566 }
20567
20568 /* Tag_CPU_name. */
20569 if (selected_cpu_name[0])
20570 {
20571 char *p;
20572
20573 p = selected_cpu_name;
20574 if (strncmp(p, "armv", 4) == 0)
20575 {
20576 int i;
20577
20578 p += 4;
20579 for (i = 0; p[i]; i++)
20580 p[i] = TOUPPER (p[i]);
20581 }
20582 bfd_elf_add_proc_attr_string (stdoutput, 5, p);
20583 }
20584 /* Tag_CPU_arch. */
20585 bfd_elf_add_proc_attr_int (stdoutput, 6, arch);
20586 /* Tag_CPU_arch_profile. */
20587 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
20588 bfd_elf_add_proc_attr_int (stdoutput, 7, 'A');
20589 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
20590 bfd_elf_add_proc_attr_int (stdoutput, 7, 'R');
20591 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m))
20592 bfd_elf_add_proc_attr_int (stdoutput, 7, 'M');
20593 /* Tag_ARM_ISA_use. */
20594 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_full))
20595 bfd_elf_add_proc_attr_int (stdoutput, 8, 1);
20596 /* Tag_THUMB_ISA_use. */
20597 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_full))
20598 bfd_elf_add_proc_attr_int (stdoutput, 9,
20599 ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2) ? 2 : 1);
20600 /* Tag_VFP_arch. */
20601 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v3)
20602 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v3))
20603 bfd_elf_add_proc_attr_int (stdoutput, 10, 3);
20604 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v2)
20605 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v2))
20606 bfd_elf_add_proc_attr_int (stdoutput, 10, 2);
20607 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1)
20608 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1)
20609 || ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1xd)
20610 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1xd))
20611 bfd_elf_add_proc_attr_int (stdoutput, 10, 1);
20612 /* Tag_WMMX_arch. */
20613 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_cext_iwmmxt)
20614 || ARM_CPU_HAS_FEATURE (arm_arch_used, arm_cext_iwmmxt))
20615 bfd_elf_add_proc_attr_int (stdoutput, 11, 1);
20616 /* Tag_NEON_arch. */
20617 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_neon_ext_v1)
20618 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_neon_ext_v1))
20619 bfd_elf_add_proc_attr_int (stdoutput, 12, 1);
20620 }
20621
20622 /* Add the default contents for the .ARM.attributes section. */
20623 void
20624 arm_md_end (void)
20625 {
20626 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
20627 return;
20628
20629 aeabi_set_public_attributes ();
20630 }
20631 #endif /* OBJ_ELF */
20632
20633
20634 /* Parse a .cpu directive. */
20635
20636 static void
20637 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
20638 {
20639 const struct arm_cpu_option_table *opt;
20640 char *name;
20641 char saved_char;
20642
20643 name = input_line_pointer;
20644 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
20645 input_line_pointer++;
20646 saved_char = *input_line_pointer;
20647 *input_line_pointer = 0;
20648
20649 /* Skip the first "all" entry. */
20650 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
20651 if (streq (opt->name, name))
20652 {
20653 mcpu_cpu_opt = &opt->value;
20654 selected_cpu = opt->value;
20655 if (opt->canonical_name)
20656 strcpy(selected_cpu_name, opt->canonical_name);
20657 else
20658 {
20659 int i;
20660 for (i = 0; opt->name[i]; i++)
20661 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20662 selected_cpu_name[i] = 0;
20663 }
20664 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20665 *input_line_pointer = saved_char;
20666 demand_empty_rest_of_line ();
20667 return;
20668 }
20669 as_bad (_("unknown cpu `%s'"), name);
20670 *input_line_pointer = saved_char;
20671 ignore_rest_of_line ();
20672 }
20673
20674
20675 /* Parse a .arch directive. */
20676
20677 static void
20678 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
20679 {
20680 const struct arm_arch_option_table *opt;
20681 char saved_char;
20682 char *name;
20683
20684 name = input_line_pointer;
20685 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
20686 input_line_pointer++;
20687 saved_char = *input_line_pointer;
20688 *input_line_pointer = 0;
20689
20690 /* Skip the first "all" entry. */
20691 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20692 if (streq (opt->name, name))
20693 {
20694 mcpu_cpu_opt = &opt->value;
20695 selected_cpu = opt->value;
20696 strcpy(selected_cpu_name, opt->name);
20697 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20698 *input_line_pointer = saved_char;
20699 demand_empty_rest_of_line ();
20700 return;
20701 }
20702
20703 as_bad (_("unknown architecture `%s'\n"), name);
20704 *input_line_pointer = saved_char;
20705 ignore_rest_of_line ();
20706 }
20707
20708
20709 /* Parse a .object_arch directive. */
20710
20711 static void
20712 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
20713 {
20714 const struct arm_arch_option_table *opt;
20715 char saved_char;
20716 char *name;
20717
20718 name = input_line_pointer;
20719 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
20720 input_line_pointer++;
20721 saved_char = *input_line_pointer;
20722 *input_line_pointer = 0;
20723
20724 /* Skip the first "all" entry. */
20725 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20726 if (streq (opt->name, name))
20727 {
20728 object_arch = &opt->value;
20729 *input_line_pointer = saved_char;
20730 demand_empty_rest_of_line ();
20731 return;
20732 }
20733
20734 as_bad (_("unknown architecture `%s'\n"), name);
20735 *input_line_pointer = saved_char;
20736 ignore_rest_of_line ();
20737 }
20738
20739
20740 /* Parse a .fpu directive. */
20741
20742 static void
20743 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
20744 {
20745 const struct arm_option_cpu_value_table *opt;
20746 char saved_char;
20747 char *name;
20748
20749 name = input_line_pointer;
20750 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
20751 input_line_pointer++;
20752 saved_char = *input_line_pointer;
20753 *input_line_pointer = 0;
20754
20755 for (opt = arm_fpus; opt->name != NULL; opt++)
20756 if (streq (opt->name, name))
20757 {
20758 mfpu_opt = &opt->value;
20759 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20760 *input_line_pointer = saved_char;
20761 demand_empty_rest_of_line ();
20762 return;
20763 }
20764
20765 as_bad (_("unknown floating point format `%s'\n"), name);
20766 *input_line_pointer = saved_char;
20767 ignore_rest_of_line ();
20768 }
20769
20770 /* Copy symbol information. */
20771 void
20772 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
20773 {
20774 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
20775 }
This page took 0.586361 seconds and 3 git commands to generate.