PR binutils/10924
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
1 /* tc-arm.c -- Assemble for the ARM
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008, 2009
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 "as.h"
29 #include <limits.h>
30 #include <stdarg.h>
31 #define NO_RELOC 0
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 #ifdef OBJ_ELF
46 /* Must be at least the size of the largest unwind opcode (currently two). */
47 #define ARM_OPCODE_CHUNK_SIZE 8
48
49 /* This structure holds the unwinding state. */
50
51 static struct
52 {
53 symbolS * proc_start;
54 symbolS * table_entry;
55 symbolS * personality_routine;
56 int personality_index;
57 /* The segment containing the function. */
58 segT saved_seg;
59 subsegT saved_subseg;
60 /* Opcodes generated from this function. */
61 unsigned char * opcodes;
62 int opcode_count;
63 int opcode_alloc;
64 /* The number of bytes pushed to the stack. */
65 offsetT frame_size;
66 /* We don't add stack adjustment opcodes immediately so that we can merge
67 multiple adjustments. We can also omit the final adjustment
68 when using a frame pointer. */
69 offsetT pending_offset;
70 /* These two fields are set by both unwind_movsp and unwind_setfp. They
71 hold the reg+offset to use when restoring sp from a frame pointer. */
72 offsetT fp_offset;
73 int fp_reg;
74 /* Nonzero if an unwind_setfp directive has been seen. */
75 unsigned fp_used:1;
76 /* Nonzero if the last opcode restores sp from fp_reg. */
77 unsigned sp_restored:1;
78 } unwind;
79
80 #endif /* OBJ_ELF */
81
82 /* Results from operand parsing worker functions. */
83
84 typedef enum
85 {
86 PARSE_OPERAND_SUCCESS,
87 PARSE_OPERAND_FAIL,
88 PARSE_OPERAND_FAIL_NO_BACKTRACK
89 } parse_operand_result;
90
91 enum arm_float_abi
92 {
93 ARM_FLOAT_ABI_HARD,
94 ARM_FLOAT_ABI_SOFTFP,
95 ARM_FLOAT_ABI_SOFT
96 };
97
98 /* Types of processor to assemble for. */
99 #ifndef CPU_DEFAULT
100 #if defined __XSCALE__
101 #define CPU_DEFAULT ARM_ARCH_XSCALE
102 #else
103 #if defined __thumb__
104 #define CPU_DEFAULT ARM_ARCH_V5T
105 #endif
106 #endif
107 #endif
108
109 #ifndef FPU_DEFAULT
110 # ifdef TE_LINUX
111 # define FPU_DEFAULT FPU_ARCH_FPA
112 # elif defined (TE_NetBSD)
113 # ifdef OBJ_ELF
114 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
115 # else
116 /* Legacy a.out format. */
117 # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
118 # endif
119 # elif defined (TE_VXWORKS)
120 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
121 # else
122 /* For backwards compatibility, default to FPA. */
123 # define FPU_DEFAULT FPU_ARCH_FPA
124 # endif
125 #endif /* ifndef FPU_DEFAULT */
126
127 #define streq(a, b) (strcmp (a, b) == 0)
128
129 static arm_feature_set cpu_variant;
130 static arm_feature_set arm_arch_used;
131 static arm_feature_set thumb_arch_used;
132
133 /* Flags stored in private area of BFD structure. */
134 static int uses_apcs_26 = FALSE;
135 static int atpcs = FALSE;
136 static int support_interwork = FALSE;
137 static int uses_apcs_float = FALSE;
138 static int pic_code = FALSE;
139 static int fix_v4bx = FALSE;
140 /* Warn on using deprecated features. */
141 static int warn_on_deprecated = TRUE;
142
143
144 /* Variables that we set while parsing command-line options. Once all
145 options have been read we re-process these values to set the real
146 assembly flags. */
147 static const arm_feature_set *legacy_cpu = NULL;
148 static const arm_feature_set *legacy_fpu = NULL;
149
150 static const arm_feature_set *mcpu_cpu_opt = NULL;
151 static const arm_feature_set *mcpu_fpu_opt = NULL;
152 static const arm_feature_set *march_cpu_opt = NULL;
153 static const arm_feature_set *march_fpu_opt = NULL;
154 static const arm_feature_set *mfpu_opt = NULL;
155 static const arm_feature_set *object_arch = NULL;
156
157 /* Constants for known architecture features. */
158 static const arm_feature_set fpu_default = FPU_DEFAULT;
159 static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
160 static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
161 static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
162 static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
163 static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
164 static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
165 static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
166 static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
167
168 #ifdef CPU_DEFAULT
169 static const arm_feature_set cpu_default = CPU_DEFAULT;
170 #endif
171
172 static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
173 static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
174 static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
175 static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
176 static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
177 static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
178 static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
179 static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
180 static const arm_feature_set arm_ext_v4t_5 =
181 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
182 static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
183 static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
184 static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
185 static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
186 static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
187 static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
188 static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
189 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
190 static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
191 static const arm_feature_set arm_ext_v6_dsp = ARM_FEATURE (ARM_EXT_V6_DSP, 0);
192 static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
193 static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 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 static const arm_feature_set arm_ext_m =
200 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_V7M, 0);
201
202 static const arm_feature_set arm_arch_any = ARM_ANY;
203 static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
204 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
205 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
206
207 static const arm_feature_set arm_cext_iwmmxt2 =
208 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
209 static const arm_feature_set arm_cext_iwmmxt =
210 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
211 static const arm_feature_set arm_cext_xscale =
212 ARM_FEATURE (0, ARM_CEXT_XSCALE);
213 static const arm_feature_set arm_cext_maverick =
214 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
215 static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
216 static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
217 static const arm_feature_set fpu_vfp_ext_v1xd =
218 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
219 static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
220 static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
221 static const arm_feature_set fpu_vfp_ext_v3xd = ARM_FEATURE (0, FPU_VFP_EXT_V3xD);
222 static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
223 static const arm_feature_set fpu_vfp_ext_d32 =
224 ARM_FEATURE (0, FPU_VFP_EXT_D32);
225 static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
226 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
227 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
228 static const arm_feature_set fpu_vfp_fp16 = ARM_FEATURE (0, FPU_VFP_EXT_FP16);
229 static const arm_feature_set fpu_neon_ext_fma = ARM_FEATURE (0, FPU_NEON_EXT_FMA);
230 static const arm_feature_set fpu_vfp_ext_fma = ARM_FEATURE (0, FPU_VFP_EXT_FMA);
231
232 static int mfloat_abi_opt = -1;
233 /* Record user cpu selection for object attributes. */
234 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
235 /* Must be long enough to hold any of the names in arm_cpus. */
236 static char selected_cpu_name[16];
237 #ifdef OBJ_ELF
238 # ifdef EABI_DEFAULT
239 static int meabi_flags = EABI_DEFAULT;
240 # else
241 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
242 # endif
243
244 static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
245
246 bfd_boolean
247 arm_is_eabi (void)
248 {
249 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
250 }
251 #endif
252
253 #ifdef OBJ_ELF
254 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
255 symbolS * GOT_symbol;
256 #endif
257
258 /* 0: assemble for ARM,
259 1: assemble for Thumb,
260 2: assemble for Thumb even though target CPU does not support thumb
261 instructions. */
262 static int thumb_mode = 0;
263 /* A value distinct from the possible values for thumb_mode that we
264 can use to record whether thumb_mode has been copied into the
265 tc_frag_data field of a frag. */
266 #define MODE_RECORDED (1 << 4)
267
268 /* Specifies the intrinsic IT insn behavior mode. */
269 enum implicit_it_mode
270 {
271 IMPLICIT_IT_MODE_NEVER = 0x00,
272 IMPLICIT_IT_MODE_ARM = 0x01,
273 IMPLICIT_IT_MODE_THUMB = 0x02,
274 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
275 };
276 static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
277
278 /* If unified_syntax is true, we are processing the new unified
279 ARM/Thumb syntax. Important differences from the old ARM mode:
280
281 - Immediate operands do not require a # prefix.
282 - Conditional affixes always appear at the end of the
283 instruction. (For backward compatibility, those instructions
284 that formerly had them in the middle, continue to accept them
285 there.)
286 - The IT instruction may appear, and if it does is validated
287 against subsequent conditional affixes. It does not generate
288 machine code.
289
290 Important differences from the old Thumb mode:
291
292 - Immediate operands do not require a # prefix.
293 - Most of the V6T2 instructions are only available in unified mode.
294 - The .N and .W suffixes are recognized and honored (it is an error
295 if they cannot be honored).
296 - All instructions set the flags if and only if they have an 's' affix.
297 - Conditional affixes may be used. They are validated against
298 preceding IT instructions. Unlike ARM mode, you cannot use a
299 conditional affix except in the scope of an IT instruction. */
300
301 static bfd_boolean unified_syntax = FALSE;
302
303 enum neon_el_type
304 {
305 NT_invtype,
306 NT_untyped,
307 NT_integer,
308 NT_float,
309 NT_poly,
310 NT_signed,
311 NT_unsigned
312 };
313
314 struct neon_type_el
315 {
316 enum neon_el_type type;
317 unsigned size;
318 };
319
320 #define NEON_MAX_TYPE_ELS 4
321
322 struct neon_type
323 {
324 struct neon_type_el el[NEON_MAX_TYPE_ELS];
325 unsigned elems;
326 };
327
328 enum it_instruction_type
329 {
330 OUTSIDE_IT_INSN,
331 INSIDE_IT_INSN,
332 INSIDE_IT_LAST_INSN,
333 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
334 if inside, should be the last one. */
335 NEUTRAL_IT_INSN, /* This could be either inside or outside,
336 i.e. BKPT and NOP. */
337 IT_INSN /* The IT insn has been parsed. */
338 };
339
340 struct arm_it
341 {
342 const char * error;
343 unsigned long instruction;
344 int size;
345 int size_req;
346 int cond;
347 /* "uncond_value" is set to the value in place of the conditional field in
348 unconditional versions of the instruction, or -1 if nothing is
349 appropriate. */
350 int uncond_value;
351 struct neon_type vectype;
352 /* Set to the opcode if the instruction needs relaxation.
353 Zero if the instruction is not relaxed. */
354 unsigned long relax;
355 struct
356 {
357 bfd_reloc_code_real_type type;
358 expressionS exp;
359 int pc_rel;
360 } reloc;
361
362 enum it_instruction_type it_insn_type;
363
364 struct
365 {
366 unsigned reg;
367 signed int imm;
368 struct neon_type_el vectype;
369 unsigned present : 1; /* Operand present. */
370 unsigned isreg : 1; /* Operand was a register. */
371 unsigned immisreg : 1; /* .imm field is a second register. */
372 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
373 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
374 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
375 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
376 instructions. This allows us to disambiguate ARM <-> vector insns. */
377 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
378 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
379 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
380 unsigned issingle : 1; /* Operand is VFP single-precision register. */
381 unsigned hasreloc : 1; /* Operand has relocation suffix. */
382 unsigned writeback : 1; /* Operand has trailing ! */
383 unsigned preind : 1; /* Preindexed address. */
384 unsigned postind : 1; /* Postindexed address. */
385 unsigned negative : 1; /* Index register was negated. */
386 unsigned shifted : 1; /* Shift applied to operation. */
387 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
388 } operands[6];
389 };
390
391 static struct arm_it inst;
392
393 #define NUM_FLOAT_VALS 8
394
395 const char * fp_const[] =
396 {
397 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
398 };
399
400 /* Number of littlenums required to hold an extended precision number. */
401 #define MAX_LITTLENUMS 6
402
403 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
404
405 #define FAIL (-1)
406 #define SUCCESS (0)
407
408 #define SUFF_S 1
409 #define SUFF_D 2
410 #define SUFF_E 3
411 #define SUFF_P 4
412
413 #define CP_T_X 0x00008000
414 #define CP_T_Y 0x00400000
415
416 #define CONDS_BIT 0x00100000
417 #define LOAD_BIT 0x00100000
418
419 #define DOUBLE_LOAD_FLAG 0x00000001
420
421 struct asm_cond
422 {
423 const char * template_name;
424 unsigned long value;
425 };
426
427 #define COND_ALWAYS 0xE
428
429 struct asm_psr
430 {
431 const char * template_name;
432 unsigned long field;
433 };
434
435 struct asm_barrier_opt
436 {
437 const char * template_name;
438 unsigned long value;
439 };
440
441 /* The bit that distinguishes CPSR and SPSR. */
442 #define SPSR_BIT (1 << 22)
443
444 /* The individual PSR flag bits. */
445 #define PSR_c (1 << 16)
446 #define PSR_x (1 << 17)
447 #define PSR_s (1 << 18)
448 #define PSR_f (1 << 19)
449
450 struct reloc_entry
451 {
452 char * name;
453 bfd_reloc_code_real_type reloc;
454 };
455
456 enum vfp_reg_pos
457 {
458 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
459 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
460 };
461
462 enum vfp_ldstm_type
463 {
464 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
465 };
466
467 /* Bits for DEFINED field in neon_typed_alias. */
468 #define NTA_HASTYPE 1
469 #define NTA_HASINDEX 2
470
471 struct neon_typed_alias
472 {
473 unsigned char defined;
474 unsigned char index;
475 struct neon_type_el eltype;
476 };
477
478 /* ARM register categories. This includes coprocessor numbers and various
479 architecture extensions' registers. */
480 enum arm_reg_type
481 {
482 REG_TYPE_RN,
483 REG_TYPE_CP,
484 REG_TYPE_CN,
485 REG_TYPE_FN,
486 REG_TYPE_VFS,
487 REG_TYPE_VFD,
488 REG_TYPE_NQ,
489 REG_TYPE_VFSD,
490 REG_TYPE_NDQ,
491 REG_TYPE_NSDQ,
492 REG_TYPE_VFC,
493 REG_TYPE_MVF,
494 REG_TYPE_MVD,
495 REG_TYPE_MVFX,
496 REG_TYPE_MVDX,
497 REG_TYPE_MVAX,
498 REG_TYPE_DSPSC,
499 REG_TYPE_MMXWR,
500 REG_TYPE_MMXWC,
501 REG_TYPE_MMXWCG,
502 REG_TYPE_XSCALE,
503 };
504
505 /* Structure for a hash table entry for a register.
506 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
507 information which states whether a vector type or index is specified (for a
508 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
509 struct reg_entry
510 {
511 const char * name;
512 unsigned char number;
513 unsigned char type;
514 unsigned char builtin;
515 struct neon_typed_alias * neon;
516 };
517
518 /* Diagnostics used when we don't get a register of the expected type. */
519 const char * const reg_expected_msgs[] =
520 {
521 N_("ARM register expected"),
522 N_("bad or missing co-processor number"),
523 N_("co-processor register expected"),
524 N_("FPA register expected"),
525 N_("VFP single precision register expected"),
526 N_("VFP/Neon double precision register expected"),
527 N_("Neon quad precision register expected"),
528 N_("VFP single or double precision register expected"),
529 N_("Neon double or quad precision register expected"),
530 N_("VFP single, double or Neon quad precision register expected"),
531 N_("VFP system register expected"),
532 N_("Maverick MVF register expected"),
533 N_("Maverick MVD register expected"),
534 N_("Maverick MVFX register expected"),
535 N_("Maverick MVDX register expected"),
536 N_("Maverick MVAX register expected"),
537 N_("Maverick DSPSC register expected"),
538 N_("iWMMXt data register expected"),
539 N_("iWMMXt control register expected"),
540 N_("iWMMXt scalar register expected"),
541 N_("XScale accumulator register expected"),
542 };
543
544 /* Some well known registers that we refer to directly elsewhere. */
545 #define REG_SP 13
546 #define REG_LR 14
547 #define REG_PC 15
548
549 /* ARM instructions take 4bytes in the object file, Thumb instructions
550 take 2: */
551 #define INSN_SIZE 4
552
553 struct asm_opcode
554 {
555 /* Basic string to match. */
556 const char * template_name;
557
558 /* Parameters to instruction. */
559 unsigned char operands[8];
560
561 /* Conditional tag - see opcode_lookup. */
562 unsigned int tag : 4;
563
564 /* Basic instruction code. */
565 unsigned int avalue : 28;
566
567 /* Thumb-format instruction code. */
568 unsigned int tvalue;
569
570 /* Which architecture variant provides this instruction. */
571 const arm_feature_set * avariant;
572 const arm_feature_set * tvariant;
573
574 /* Function to call to encode instruction in ARM format. */
575 void (* aencode) (void);
576
577 /* Function to call to encode instruction in Thumb format. */
578 void (* tencode) (void);
579 };
580
581 /* Defines for various bits that we will want to toggle. */
582 #define INST_IMMEDIATE 0x02000000
583 #define OFFSET_REG 0x02000000
584 #define HWOFFSET_IMM 0x00400000
585 #define SHIFT_BY_REG 0x00000010
586 #define PRE_INDEX 0x01000000
587 #define INDEX_UP 0x00800000
588 #define WRITE_BACK 0x00200000
589 #define LDM_TYPE_2_OR_3 0x00400000
590 #define CPSI_MMOD 0x00020000
591
592 #define LITERAL_MASK 0xf000f000
593 #define OPCODE_MASK 0xfe1fffff
594 #define V4_STR_BIT 0x00000020
595
596 #define T2_SUBS_PC_LR 0xf3de8f00
597
598 #define DATA_OP_SHIFT 21
599
600 #define T2_OPCODE_MASK 0xfe1fffff
601 #define T2_DATA_OP_SHIFT 21
602
603 /* Codes to distinguish the arithmetic instructions. */
604 #define OPCODE_AND 0
605 #define OPCODE_EOR 1
606 #define OPCODE_SUB 2
607 #define OPCODE_RSB 3
608 #define OPCODE_ADD 4
609 #define OPCODE_ADC 5
610 #define OPCODE_SBC 6
611 #define OPCODE_RSC 7
612 #define OPCODE_TST 8
613 #define OPCODE_TEQ 9
614 #define OPCODE_CMP 10
615 #define OPCODE_CMN 11
616 #define OPCODE_ORR 12
617 #define OPCODE_MOV 13
618 #define OPCODE_BIC 14
619 #define OPCODE_MVN 15
620
621 #define T2_OPCODE_AND 0
622 #define T2_OPCODE_BIC 1
623 #define T2_OPCODE_ORR 2
624 #define T2_OPCODE_ORN 3
625 #define T2_OPCODE_EOR 4
626 #define T2_OPCODE_ADD 8
627 #define T2_OPCODE_ADC 10
628 #define T2_OPCODE_SBC 11
629 #define T2_OPCODE_SUB 13
630 #define T2_OPCODE_RSB 14
631
632 #define T_OPCODE_MUL 0x4340
633 #define T_OPCODE_TST 0x4200
634 #define T_OPCODE_CMN 0x42c0
635 #define T_OPCODE_NEG 0x4240
636 #define T_OPCODE_MVN 0x43c0
637
638 #define T_OPCODE_ADD_R3 0x1800
639 #define T_OPCODE_SUB_R3 0x1a00
640 #define T_OPCODE_ADD_HI 0x4400
641 #define T_OPCODE_ADD_ST 0xb000
642 #define T_OPCODE_SUB_ST 0xb080
643 #define T_OPCODE_ADD_SP 0xa800
644 #define T_OPCODE_ADD_PC 0xa000
645 #define T_OPCODE_ADD_I8 0x3000
646 #define T_OPCODE_SUB_I8 0x3800
647 #define T_OPCODE_ADD_I3 0x1c00
648 #define T_OPCODE_SUB_I3 0x1e00
649
650 #define T_OPCODE_ASR_R 0x4100
651 #define T_OPCODE_LSL_R 0x4080
652 #define T_OPCODE_LSR_R 0x40c0
653 #define T_OPCODE_ROR_R 0x41c0
654 #define T_OPCODE_ASR_I 0x1000
655 #define T_OPCODE_LSL_I 0x0000
656 #define T_OPCODE_LSR_I 0x0800
657
658 #define T_OPCODE_MOV_I8 0x2000
659 #define T_OPCODE_CMP_I8 0x2800
660 #define T_OPCODE_CMP_LR 0x4280
661 #define T_OPCODE_MOV_HR 0x4600
662 #define T_OPCODE_CMP_HR 0x4500
663
664 #define T_OPCODE_LDR_PC 0x4800
665 #define T_OPCODE_LDR_SP 0x9800
666 #define T_OPCODE_STR_SP 0x9000
667 #define T_OPCODE_LDR_IW 0x6800
668 #define T_OPCODE_STR_IW 0x6000
669 #define T_OPCODE_LDR_IH 0x8800
670 #define T_OPCODE_STR_IH 0x8000
671 #define T_OPCODE_LDR_IB 0x7800
672 #define T_OPCODE_STR_IB 0x7000
673 #define T_OPCODE_LDR_RW 0x5800
674 #define T_OPCODE_STR_RW 0x5000
675 #define T_OPCODE_LDR_RH 0x5a00
676 #define T_OPCODE_STR_RH 0x5200
677 #define T_OPCODE_LDR_RB 0x5c00
678 #define T_OPCODE_STR_RB 0x5400
679
680 #define T_OPCODE_PUSH 0xb400
681 #define T_OPCODE_POP 0xbc00
682
683 #define T_OPCODE_BRANCH 0xe000
684
685 #define THUMB_SIZE 2 /* Size of thumb instruction. */
686 #define THUMB_PP_PC_LR 0x0100
687 #define THUMB_LOAD_BIT 0x0800
688 #define THUMB2_LOAD_BIT 0x00100000
689
690 #define BAD_ARGS _("bad arguments to instruction")
691 #define BAD_SP _("r13 not allowed here")
692 #define BAD_PC _("r15 not allowed here")
693 #define BAD_COND _("instruction cannot be conditional")
694 #define BAD_OVERLAP _("registers may not be the same")
695 #define BAD_HIREG _("lo register required")
696 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
697 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
698 #define BAD_BRANCH _("branch must be last instruction in IT block")
699 #define BAD_NOT_IT _("instruction not allowed in IT block")
700 #define BAD_FPU _("selected FPU does not support instruction")
701 #define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
702 #define BAD_IT_COND _("incorrect condition in IT block")
703 #define BAD_IT_IT _("IT falling in the range of a previous IT block")
704 #define MISSING_FNSTART _("missing .fnstart before unwinding directive")
705
706 static struct hash_control * arm_ops_hsh;
707 static struct hash_control * arm_cond_hsh;
708 static struct hash_control * arm_shift_hsh;
709 static struct hash_control * arm_psr_hsh;
710 static struct hash_control * arm_v7m_psr_hsh;
711 static struct hash_control * arm_reg_hsh;
712 static struct hash_control * arm_reloc_hsh;
713 static struct hash_control * arm_barrier_opt_hsh;
714
715 /* Stuff needed to resolve the label ambiguity
716 As:
717 ...
718 label: <insn>
719 may differ from:
720 ...
721 label:
722 <insn> */
723
724 symbolS * last_label_seen;
725 static int label_is_thumb_function_name = FALSE;
726
727 /* Literal pool structure. Held on a per-section
728 and per-sub-section basis. */
729
730 #define MAX_LITERAL_POOL_SIZE 1024
731 typedef struct literal_pool
732 {
733 expressionS literals [MAX_LITERAL_POOL_SIZE];
734 unsigned int next_free_entry;
735 unsigned int id;
736 symbolS * symbol;
737 segT section;
738 subsegT sub_section;
739 struct literal_pool * next;
740 } literal_pool;
741
742 /* Pointer to a linked list of literal pools. */
743 literal_pool * list_of_pools = NULL;
744
745 #ifdef OBJ_ELF
746 # define now_it seg_info (now_seg)->tc_segment_info_data.current_it
747 #else
748 static struct current_it now_it;
749 #endif
750
751 static inline int
752 now_it_compatible (int cond)
753 {
754 return (cond & ~1) == (now_it.cc & ~1);
755 }
756
757 static inline int
758 conditional_insn (void)
759 {
760 return inst.cond != COND_ALWAYS;
761 }
762
763 static int in_it_block (void);
764
765 static int handle_it_state (void);
766
767 static void force_automatic_it_block_close (void);
768
769 static void it_fsm_post_encode (void);
770
771 #define set_it_insn_type(type) \
772 do \
773 { \
774 inst.it_insn_type = type; \
775 if (handle_it_state () == FAIL) \
776 return; \
777 } \
778 while (0)
779
780 #define set_it_insn_type_nonvoid(type, failret) \
781 do \
782 { \
783 inst.it_insn_type = type; \
784 if (handle_it_state () == FAIL) \
785 return failret; \
786 } \
787 while(0)
788
789 #define set_it_insn_type_last() \
790 do \
791 { \
792 if (inst.cond == COND_ALWAYS) \
793 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
794 else \
795 set_it_insn_type (INSIDE_IT_LAST_INSN); \
796 } \
797 while (0)
798
799 /* Pure syntax. */
800
801 /* This array holds the chars that always start a comment. If the
802 pre-processor is disabled, these aren't very useful. */
803 const char comment_chars[] = "@";
804
805 /* This array holds the chars that only start a comment at the beginning of
806 a line. If the line seems to have the form '# 123 filename'
807 .line and .file directives will appear in the pre-processed output. */
808 /* Note that input_file.c hand checks for '#' at the beginning of the
809 first line of the input file. This is because the compiler outputs
810 #NO_APP at the beginning of its output. */
811 /* Also note that comments like this one will always work. */
812 const char line_comment_chars[] = "#";
813
814 const char line_separator_chars[] = ";";
815
816 /* Chars that can be used to separate mant
817 from exp in floating point numbers. */
818 const char EXP_CHARS[] = "eE";
819
820 /* Chars that mean this number is a floating point constant. */
821 /* As in 0f12.456 */
822 /* or 0d1.2345e12 */
823
824 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
825
826 /* Prefix characters that indicate the start of an immediate
827 value. */
828 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
829
830 /* Separator character handling. */
831
832 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
833
834 static inline int
835 skip_past_char (char ** str, char c)
836 {
837 if (**str == c)
838 {
839 (*str)++;
840 return SUCCESS;
841 }
842 else
843 return FAIL;
844 }
845
846 #define skip_past_comma(str) skip_past_char (str, ',')
847
848 /* Arithmetic expressions (possibly involving symbols). */
849
850 /* Return TRUE if anything in the expression is a bignum. */
851
852 static int
853 walk_no_bignums (symbolS * sp)
854 {
855 if (symbol_get_value_expression (sp)->X_op == O_big)
856 return 1;
857
858 if (symbol_get_value_expression (sp)->X_add_symbol)
859 {
860 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
861 || (symbol_get_value_expression (sp)->X_op_symbol
862 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
863 }
864
865 return 0;
866 }
867
868 static int in_my_get_expression = 0;
869
870 /* Third argument to my_get_expression. */
871 #define GE_NO_PREFIX 0
872 #define GE_IMM_PREFIX 1
873 #define GE_OPT_PREFIX 2
874 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
875 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
876 #define GE_OPT_PREFIX_BIG 3
877
878 static int
879 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
880 {
881 char * save_in;
882 segT seg;
883
884 /* In unified syntax, all prefixes are optional. */
885 if (unified_syntax)
886 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
887 : GE_OPT_PREFIX;
888
889 switch (prefix_mode)
890 {
891 case GE_NO_PREFIX: break;
892 case GE_IMM_PREFIX:
893 if (!is_immediate_prefix (**str))
894 {
895 inst.error = _("immediate expression requires a # prefix");
896 return FAIL;
897 }
898 (*str)++;
899 break;
900 case GE_OPT_PREFIX:
901 case GE_OPT_PREFIX_BIG:
902 if (is_immediate_prefix (**str))
903 (*str)++;
904 break;
905 default: abort ();
906 }
907
908 memset (ep, 0, sizeof (expressionS));
909
910 save_in = input_line_pointer;
911 input_line_pointer = *str;
912 in_my_get_expression = 1;
913 seg = expression (ep);
914 in_my_get_expression = 0;
915
916 if (ep->X_op == O_illegal || ep->X_op == O_absent)
917 {
918 /* We found a bad or missing expression in md_operand(). */
919 *str = input_line_pointer;
920 input_line_pointer = save_in;
921 if (inst.error == NULL)
922 inst.error = (ep->X_op == O_absent
923 ? _("missing expression") :_("bad expression"));
924 return 1;
925 }
926
927 #ifdef OBJ_AOUT
928 if (seg != absolute_section
929 && seg != text_section
930 && seg != data_section
931 && seg != bss_section
932 && seg != undefined_section)
933 {
934 inst.error = _("bad segment");
935 *str = input_line_pointer;
936 input_line_pointer = save_in;
937 return 1;
938 }
939 #endif
940
941 /* Get rid of any bignums now, so that we don't generate an error for which
942 we can't establish a line number later on. Big numbers are never valid
943 in instructions, which is where this routine is always called. */
944 if (prefix_mode != GE_OPT_PREFIX_BIG
945 && (ep->X_op == O_big
946 || (ep->X_add_symbol
947 && (walk_no_bignums (ep->X_add_symbol)
948 || (ep->X_op_symbol
949 && walk_no_bignums (ep->X_op_symbol))))))
950 {
951 inst.error = _("invalid constant");
952 *str = input_line_pointer;
953 input_line_pointer = save_in;
954 return 1;
955 }
956
957 *str = input_line_pointer;
958 input_line_pointer = save_in;
959 return 0;
960 }
961
962 /* Turn a string in input_line_pointer into a floating point constant
963 of type TYPE, and store the appropriate bytes in *LITP. The number
964 of LITTLENUMS emitted is stored in *SIZEP. An error message is
965 returned, or NULL on OK.
966
967 Note that fp constants aren't represent in the normal way on the ARM.
968 In big endian mode, things are as expected. However, in little endian
969 mode fp constants are big-endian word-wise, and little-endian byte-wise
970 within the words. For example, (double) 1.1 in big endian mode is
971 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
972 the byte sequence 99 99 f1 3f 9a 99 99 99.
973
974 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
975
976 char *
977 md_atof (int type, char * litP, int * sizeP)
978 {
979 int prec;
980 LITTLENUM_TYPE words[MAX_LITTLENUMS];
981 char *t;
982 int i;
983
984 switch (type)
985 {
986 case 'f':
987 case 'F':
988 case 's':
989 case 'S':
990 prec = 2;
991 break;
992
993 case 'd':
994 case 'D':
995 case 'r':
996 case 'R':
997 prec = 4;
998 break;
999
1000 case 'x':
1001 case 'X':
1002 prec = 5;
1003 break;
1004
1005 case 'p':
1006 case 'P':
1007 prec = 5;
1008 break;
1009
1010 default:
1011 *sizeP = 0;
1012 return _("Unrecognized or unsupported floating point constant");
1013 }
1014
1015 t = atof_ieee (input_line_pointer, type, words);
1016 if (t)
1017 input_line_pointer = t;
1018 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1019
1020 if (target_big_endian)
1021 {
1022 for (i = 0; i < prec; i++)
1023 {
1024 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1025 litP += sizeof (LITTLENUM_TYPE);
1026 }
1027 }
1028 else
1029 {
1030 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
1031 for (i = prec - 1; i >= 0; i--)
1032 {
1033 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1034 litP += sizeof (LITTLENUM_TYPE);
1035 }
1036 else
1037 /* For a 4 byte float the order of elements in `words' is 1 0.
1038 For an 8 byte float the order is 1 0 3 2. */
1039 for (i = 0; i < prec; i += 2)
1040 {
1041 md_number_to_chars (litP, (valueT) words[i + 1],
1042 sizeof (LITTLENUM_TYPE));
1043 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1044 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1045 litP += 2 * sizeof (LITTLENUM_TYPE);
1046 }
1047 }
1048
1049 return NULL;
1050 }
1051
1052 /* We handle all bad expressions here, so that we can report the faulty
1053 instruction in the error message. */
1054 void
1055 md_operand (expressionS * exp)
1056 {
1057 if (in_my_get_expression)
1058 exp->X_op = O_illegal;
1059 }
1060
1061 /* Immediate values. */
1062
1063 /* Generic immediate-value read function for use in directives.
1064 Accepts anything that 'expression' can fold to a constant.
1065 *val receives the number. */
1066 #ifdef OBJ_ELF
1067 static int
1068 immediate_for_directive (int *val)
1069 {
1070 expressionS exp;
1071 exp.X_op = O_illegal;
1072
1073 if (is_immediate_prefix (*input_line_pointer))
1074 {
1075 input_line_pointer++;
1076 expression (&exp);
1077 }
1078
1079 if (exp.X_op != O_constant)
1080 {
1081 as_bad (_("expected #constant"));
1082 ignore_rest_of_line ();
1083 return FAIL;
1084 }
1085 *val = exp.X_add_number;
1086 return SUCCESS;
1087 }
1088 #endif
1089
1090 /* Register parsing. */
1091
1092 /* Generic register parser. CCP points to what should be the
1093 beginning of a register name. If it is indeed a valid register
1094 name, advance CCP over it and return the reg_entry structure;
1095 otherwise return NULL. Does not issue diagnostics. */
1096
1097 static struct reg_entry *
1098 arm_reg_parse_multi (char **ccp)
1099 {
1100 char *start = *ccp;
1101 char *p;
1102 struct reg_entry *reg;
1103
1104 #ifdef REGISTER_PREFIX
1105 if (*start != REGISTER_PREFIX)
1106 return NULL;
1107 start++;
1108 #endif
1109 #ifdef OPTIONAL_REGISTER_PREFIX
1110 if (*start == OPTIONAL_REGISTER_PREFIX)
1111 start++;
1112 #endif
1113
1114 p = start;
1115 if (!ISALPHA (*p) || !is_name_beginner (*p))
1116 return NULL;
1117
1118 do
1119 p++;
1120 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1121
1122 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1123
1124 if (!reg)
1125 return NULL;
1126
1127 *ccp = p;
1128 return reg;
1129 }
1130
1131 static int
1132 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1133 enum arm_reg_type type)
1134 {
1135 /* Alternative syntaxes are accepted for a few register classes. */
1136 switch (type)
1137 {
1138 case REG_TYPE_MVF:
1139 case REG_TYPE_MVD:
1140 case REG_TYPE_MVFX:
1141 case REG_TYPE_MVDX:
1142 /* Generic coprocessor register names are allowed for these. */
1143 if (reg && reg->type == REG_TYPE_CN)
1144 return reg->number;
1145 break;
1146
1147 case REG_TYPE_CP:
1148 /* For backward compatibility, a bare number is valid here. */
1149 {
1150 unsigned long processor = strtoul (start, ccp, 10);
1151 if (*ccp != start && processor <= 15)
1152 return processor;
1153 }
1154
1155 case REG_TYPE_MMXWC:
1156 /* WC includes WCG. ??? I'm not sure this is true for all
1157 instructions that take WC registers. */
1158 if (reg && reg->type == REG_TYPE_MMXWCG)
1159 return reg->number;
1160 break;
1161
1162 default:
1163 break;
1164 }
1165
1166 return FAIL;
1167 }
1168
1169 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1170 return value is the register number or FAIL. */
1171
1172 static int
1173 arm_reg_parse (char **ccp, enum arm_reg_type type)
1174 {
1175 char *start = *ccp;
1176 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1177 int ret;
1178
1179 /* Do not allow a scalar (reg+index) to parse as a register. */
1180 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1181 return FAIL;
1182
1183 if (reg && reg->type == type)
1184 return reg->number;
1185
1186 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1187 return ret;
1188
1189 *ccp = start;
1190 return FAIL;
1191 }
1192
1193 /* Parse a Neon type specifier. *STR should point at the leading '.'
1194 character. Does no verification at this stage that the type fits the opcode
1195 properly. E.g.,
1196
1197 .i32.i32.s16
1198 .s32.f32
1199 .u16
1200
1201 Can all be legally parsed by this function.
1202
1203 Fills in neon_type struct pointer with parsed information, and updates STR
1204 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1205 type, FAIL if not. */
1206
1207 static int
1208 parse_neon_type (struct neon_type *type, char **str)
1209 {
1210 char *ptr = *str;
1211
1212 if (type)
1213 type->elems = 0;
1214
1215 while (type->elems < NEON_MAX_TYPE_ELS)
1216 {
1217 enum neon_el_type thistype = NT_untyped;
1218 unsigned thissize = -1u;
1219
1220 if (*ptr != '.')
1221 break;
1222
1223 ptr++;
1224
1225 /* Just a size without an explicit type. */
1226 if (ISDIGIT (*ptr))
1227 goto parsesize;
1228
1229 switch (TOLOWER (*ptr))
1230 {
1231 case 'i': thistype = NT_integer; break;
1232 case 'f': thistype = NT_float; break;
1233 case 'p': thistype = NT_poly; break;
1234 case 's': thistype = NT_signed; break;
1235 case 'u': thistype = NT_unsigned; break;
1236 case 'd':
1237 thistype = NT_float;
1238 thissize = 64;
1239 ptr++;
1240 goto done;
1241 default:
1242 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1243 return FAIL;
1244 }
1245
1246 ptr++;
1247
1248 /* .f is an abbreviation for .f32. */
1249 if (thistype == NT_float && !ISDIGIT (*ptr))
1250 thissize = 32;
1251 else
1252 {
1253 parsesize:
1254 thissize = strtoul (ptr, &ptr, 10);
1255
1256 if (thissize != 8 && thissize != 16 && thissize != 32
1257 && thissize != 64)
1258 {
1259 as_bad (_("bad size %d in type specifier"), thissize);
1260 return FAIL;
1261 }
1262 }
1263
1264 done:
1265 if (type)
1266 {
1267 type->el[type->elems].type = thistype;
1268 type->el[type->elems].size = thissize;
1269 type->elems++;
1270 }
1271 }
1272
1273 /* Empty/missing type is not a successful parse. */
1274 if (type->elems == 0)
1275 return FAIL;
1276
1277 *str = ptr;
1278
1279 return SUCCESS;
1280 }
1281
1282 /* Errors may be set multiple times during parsing or bit encoding
1283 (particularly in the Neon bits), but usually the earliest error which is set
1284 will be the most meaningful. Avoid overwriting it with later (cascading)
1285 errors by calling this function. */
1286
1287 static void
1288 first_error (const char *err)
1289 {
1290 if (!inst.error)
1291 inst.error = err;
1292 }
1293
1294 /* Parse a single type, e.g. ".s32", leading period included. */
1295 static int
1296 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1297 {
1298 char *str = *ccp;
1299 struct neon_type optype;
1300
1301 if (*str == '.')
1302 {
1303 if (parse_neon_type (&optype, &str) == SUCCESS)
1304 {
1305 if (optype.elems == 1)
1306 *vectype = optype.el[0];
1307 else
1308 {
1309 first_error (_("only one type should be specified for operand"));
1310 return FAIL;
1311 }
1312 }
1313 else
1314 {
1315 first_error (_("vector type expected"));
1316 return FAIL;
1317 }
1318 }
1319 else
1320 return FAIL;
1321
1322 *ccp = str;
1323
1324 return SUCCESS;
1325 }
1326
1327 /* Special meanings for indices (which have a range of 0-7), which will fit into
1328 a 4-bit integer. */
1329
1330 #define NEON_ALL_LANES 15
1331 #define NEON_INTERLEAVE_LANES 14
1332
1333 /* Parse either a register or a scalar, with an optional type. Return the
1334 register number, and optionally fill in the actual type of the register
1335 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1336 type/index information in *TYPEINFO. */
1337
1338 static int
1339 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1340 enum arm_reg_type *rtype,
1341 struct neon_typed_alias *typeinfo)
1342 {
1343 char *str = *ccp;
1344 struct reg_entry *reg = arm_reg_parse_multi (&str);
1345 struct neon_typed_alias atype;
1346 struct neon_type_el parsetype;
1347
1348 atype.defined = 0;
1349 atype.index = -1;
1350 atype.eltype.type = NT_invtype;
1351 atype.eltype.size = -1;
1352
1353 /* Try alternate syntax for some types of register. Note these are mutually
1354 exclusive with the Neon syntax extensions. */
1355 if (reg == NULL)
1356 {
1357 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1358 if (altreg != FAIL)
1359 *ccp = str;
1360 if (typeinfo)
1361 *typeinfo = atype;
1362 return altreg;
1363 }
1364
1365 /* Undo polymorphism when a set of register types may be accepted. */
1366 if ((type == REG_TYPE_NDQ
1367 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1368 || (type == REG_TYPE_VFSD
1369 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1370 || (type == REG_TYPE_NSDQ
1371 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1372 || reg->type == REG_TYPE_NQ))
1373 || (type == REG_TYPE_MMXWC
1374 && (reg->type == REG_TYPE_MMXWCG)))
1375 type = (enum arm_reg_type) reg->type;
1376
1377 if (type != reg->type)
1378 return FAIL;
1379
1380 if (reg->neon)
1381 atype = *reg->neon;
1382
1383 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1384 {
1385 if ((atype.defined & NTA_HASTYPE) != 0)
1386 {
1387 first_error (_("can't redefine type for operand"));
1388 return FAIL;
1389 }
1390 atype.defined |= NTA_HASTYPE;
1391 atype.eltype = parsetype;
1392 }
1393
1394 if (skip_past_char (&str, '[') == SUCCESS)
1395 {
1396 if (type != REG_TYPE_VFD)
1397 {
1398 first_error (_("only D registers may be indexed"));
1399 return FAIL;
1400 }
1401
1402 if ((atype.defined & NTA_HASINDEX) != 0)
1403 {
1404 first_error (_("can't change index for operand"));
1405 return FAIL;
1406 }
1407
1408 atype.defined |= NTA_HASINDEX;
1409
1410 if (skip_past_char (&str, ']') == SUCCESS)
1411 atype.index = NEON_ALL_LANES;
1412 else
1413 {
1414 expressionS exp;
1415
1416 my_get_expression (&exp, &str, GE_NO_PREFIX);
1417
1418 if (exp.X_op != O_constant)
1419 {
1420 first_error (_("constant expression required"));
1421 return FAIL;
1422 }
1423
1424 if (skip_past_char (&str, ']') == FAIL)
1425 return FAIL;
1426
1427 atype.index = exp.X_add_number;
1428 }
1429 }
1430
1431 if (typeinfo)
1432 *typeinfo = atype;
1433
1434 if (rtype)
1435 *rtype = type;
1436
1437 *ccp = str;
1438
1439 return reg->number;
1440 }
1441
1442 /* Like arm_reg_parse, but allow allow the following extra features:
1443 - If RTYPE is non-zero, return the (possibly restricted) type of the
1444 register (e.g. Neon double or quad reg when either has been requested).
1445 - If this is a Neon vector type with additional type information, fill
1446 in the struct pointed to by VECTYPE (if non-NULL).
1447 This function will fault on encountering a scalar. */
1448
1449 static int
1450 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1451 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1452 {
1453 struct neon_typed_alias atype;
1454 char *str = *ccp;
1455 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1456
1457 if (reg == FAIL)
1458 return FAIL;
1459
1460 /* Do not allow a scalar (reg+index) to parse as a register. */
1461 if ((atype.defined & NTA_HASINDEX) != 0)
1462 {
1463 first_error (_("register operand expected, but got scalar"));
1464 return FAIL;
1465 }
1466
1467 if (vectype)
1468 *vectype = atype.eltype;
1469
1470 *ccp = str;
1471
1472 return reg;
1473 }
1474
1475 #define NEON_SCALAR_REG(X) ((X) >> 4)
1476 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1477
1478 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1479 have enough information to be able to do a good job bounds-checking. So, we
1480 just do easy checks here, and do further checks later. */
1481
1482 static int
1483 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1484 {
1485 int reg;
1486 char *str = *ccp;
1487 struct neon_typed_alias atype;
1488
1489 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
1490
1491 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1492 return FAIL;
1493
1494 if (atype.index == NEON_ALL_LANES)
1495 {
1496 first_error (_("scalar must have an index"));
1497 return FAIL;
1498 }
1499 else if (atype.index >= 64 / elsize)
1500 {
1501 first_error (_("scalar index out of range"));
1502 return FAIL;
1503 }
1504
1505 if (type)
1506 *type = atype.eltype;
1507
1508 *ccp = str;
1509
1510 return reg * 16 + atype.index;
1511 }
1512
1513 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1514
1515 static long
1516 parse_reg_list (char ** strp)
1517 {
1518 char * str = * strp;
1519 long range = 0;
1520 int another_range;
1521
1522 /* We come back here if we get ranges concatenated by '+' or '|'. */
1523 do
1524 {
1525 another_range = 0;
1526
1527 if (*str == '{')
1528 {
1529 int in_range = 0;
1530 int cur_reg = -1;
1531
1532 str++;
1533 do
1534 {
1535 int reg;
1536
1537 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1538 {
1539 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
1540 return FAIL;
1541 }
1542
1543 if (in_range)
1544 {
1545 int i;
1546
1547 if (reg <= cur_reg)
1548 {
1549 first_error (_("bad range in register list"));
1550 return FAIL;
1551 }
1552
1553 for (i = cur_reg + 1; i < reg; i++)
1554 {
1555 if (range & (1 << i))
1556 as_tsktsk
1557 (_("Warning: duplicated register (r%d) in register list"),
1558 i);
1559 else
1560 range |= 1 << i;
1561 }
1562 in_range = 0;
1563 }
1564
1565 if (range & (1 << reg))
1566 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1567 reg);
1568 else if (reg <= cur_reg)
1569 as_tsktsk (_("Warning: register range not in ascending order"));
1570
1571 range |= 1 << reg;
1572 cur_reg = reg;
1573 }
1574 while (skip_past_comma (&str) != FAIL
1575 || (in_range = 1, *str++ == '-'));
1576 str--;
1577
1578 if (*str++ != '}')
1579 {
1580 first_error (_("missing `}'"));
1581 return FAIL;
1582 }
1583 }
1584 else
1585 {
1586 expressionS exp;
1587
1588 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
1589 return FAIL;
1590
1591 if (exp.X_op == O_constant)
1592 {
1593 if (exp.X_add_number
1594 != (exp.X_add_number & 0x0000ffff))
1595 {
1596 inst.error = _("invalid register mask");
1597 return FAIL;
1598 }
1599
1600 if ((range & exp.X_add_number) != 0)
1601 {
1602 int regno = range & exp.X_add_number;
1603
1604 regno &= -regno;
1605 regno = (1 << regno) - 1;
1606 as_tsktsk
1607 (_("Warning: duplicated register (r%d) in register list"),
1608 regno);
1609 }
1610
1611 range |= exp.X_add_number;
1612 }
1613 else
1614 {
1615 if (inst.reloc.type != 0)
1616 {
1617 inst.error = _("expression too complex");
1618 return FAIL;
1619 }
1620
1621 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
1622 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1623 inst.reloc.pc_rel = 0;
1624 }
1625 }
1626
1627 if (*str == '|' || *str == '+')
1628 {
1629 str++;
1630 another_range = 1;
1631 }
1632 }
1633 while (another_range);
1634
1635 *strp = str;
1636 return range;
1637 }
1638
1639 /* Types of registers in a list. */
1640
1641 enum reg_list_els
1642 {
1643 REGLIST_VFP_S,
1644 REGLIST_VFP_D,
1645 REGLIST_NEON_D
1646 };
1647
1648 /* Parse a VFP register list. If the string is invalid return FAIL.
1649 Otherwise return the number of registers, and set PBASE to the first
1650 register. Parses registers of type ETYPE.
1651 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1652 - Q registers can be used to specify pairs of D registers
1653 - { } can be omitted from around a singleton register list
1654 FIXME: This is not implemented, as it would require backtracking in
1655 some cases, e.g.:
1656 vtbl.8 d3,d4,d5
1657 This could be done (the meaning isn't really ambiguous), but doesn't
1658 fit in well with the current parsing framework.
1659 - 32 D registers may be used (also true for VFPv3).
1660 FIXME: Types are ignored in these register lists, which is probably a
1661 bug. */
1662
1663 static int
1664 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
1665 {
1666 char *str = *ccp;
1667 int base_reg;
1668 int new_base;
1669 enum arm_reg_type regtype = (enum arm_reg_type) 0;
1670 int max_regs = 0;
1671 int count = 0;
1672 int warned = 0;
1673 unsigned long mask = 0;
1674 int i;
1675
1676 if (*str != '{')
1677 {
1678 inst.error = _("expecting {");
1679 return FAIL;
1680 }
1681
1682 str++;
1683
1684 switch (etype)
1685 {
1686 case REGLIST_VFP_S:
1687 regtype = REG_TYPE_VFS;
1688 max_regs = 32;
1689 break;
1690
1691 case REGLIST_VFP_D:
1692 regtype = REG_TYPE_VFD;
1693 break;
1694
1695 case REGLIST_NEON_D:
1696 regtype = REG_TYPE_NDQ;
1697 break;
1698 }
1699
1700 if (etype != REGLIST_VFP_S)
1701 {
1702 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1703 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
1704 {
1705 max_regs = 32;
1706 if (thumb_mode)
1707 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1708 fpu_vfp_ext_d32);
1709 else
1710 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1711 fpu_vfp_ext_d32);
1712 }
1713 else
1714 max_regs = 16;
1715 }
1716
1717 base_reg = max_regs;
1718
1719 do
1720 {
1721 int setmask = 1, addregs = 1;
1722
1723 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
1724
1725 if (new_base == FAIL)
1726 {
1727 first_error (_(reg_expected_msgs[regtype]));
1728 return FAIL;
1729 }
1730
1731 if (new_base >= max_regs)
1732 {
1733 first_error (_("register out of range in list"));
1734 return FAIL;
1735 }
1736
1737 /* Note: a value of 2 * n is returned for the register Q<n>. */
1738 if (regtype == REG_TYPE_NQ)
1739 {
1740 setmask = 3;
1741 addregs = 2;
1742 }
1743
1744 if (new_base < base_reg)
1745 base_reg = new_base;
1746
1747 if (mask & (setmask << new_base))
1748 {
1749 first_error (_("invalid register list"));
1750 return FAIL;
1751 }
1752
1753 if ((mask >> new_base) != 0 && ! warned)
1754 {
1755 as_tsktsk (_("register list not in ascending order"));
1756 warned = 1;
1757 }
1758
1759 mask |= setmask << new_base;
1760 count += addregs;
1761
1762 if (*str == '-') /* We have the start of a range expression */
1763 {
1764 int high_range;
1765
1766 str++;
1767
1768 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
1769 == FAIL)
1770 {
1771 inst.error = gettext (reg_expected_msgs[regtype]);
1772 return FAIL;
1773 }
1774
1775 if (high_range >= max_regs)
1776 {
1777 first_error (_("register out of range in list"));
1778 return FAIL;
1779 }
1780
1781 if (regtype == REG_TYPE_NQ)
1782 high_range = high_range + 1;
1783
1784 if (high_range <= new_base)
1785 {
1786 inst.error = _("register range not in ascending order");
1787 return FAIL;
1788 }
1789
1790 for (new_base += addregs; new_base <= high_range; new_base += addregs)
1791 {
1792 if (mask & (setmask << new_base))
1793 {
1794 inst.error = _("invalid register list");
1795 return FAIL;
1796 }
1797
1798 mask |= setmask << new_base;
1799 count += addregs;
1800 }
1801 }
1802 }
1803 while (skip_past_comma (&str) != FAIL);
1804
1805 str++;
1806
1807 /* Sanity check -- should have raised a parse error above. */
1808 if (count == 0 || count > max_regs)
1809 abort ();
1810
1811 *pbase = base_reg;
1812
1813 /* Final test -- the registers must be consecutive. */
1814 mask >>= base_reg;
1815 for (i = 0; i < count; i++)
1816 {
1817 if ((mask & (1u << i)) == 0)
1818 {
1819 inst.error = _("non-contiguous register range");
1820 return FAIL;
1821 }
1822 }
1823
1824 *ccp = str;
1825
1826 return count;
1827 }
1828
1829 /* True if two alias types are the same. */
1830
1831 static bfd_boolean
1832 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1833 {
1834 if (!a && !b)
1835 return TRUE;
1836
1837 if (!a || !b)
1838 return FALSE;
1839
1840 if (a->defined != b->defined)
1841 return FALSE;
1842
1843 if ((a->defined & NTA_HASTYPE) != 0
1844 && (a->eltype.type != b->eltype.type
1845 || a->eltype.size != b->eltype.size))
1846 return FALSE;
1847
1848 if ((a->defined & NTA_HASINDEX) != 0
1849 && (a->index != b->index))
1850 return FALSE;
1851
1852 return TRUE;
1853 }
1854
1855 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1856 The base register is put in *PBASE.
1857 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
1858 the return value.
1859 The register stride (minus one) is put in bit 4 of the return value.
1860 Bits [6:5] encode the list length (minus one).
1861 The type of the list elements is put in *ELTYPE, if non-NULL. */
1862
1863 #define NEON_LANE(X) ((X) & 0xf)
1864 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
1865 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1866
1867 static int
1868 parse_neon_el_struct_list (char **str, unsigned *pbase,
1869 struct neon_type_el *eltype)
1870 {
1871 char *ptr = *str;
1872 int base_reg = -1;
1873 int reg_incr = -1;
1874 int count = 0;
1875 int lane = -1;
1876 int leading_brace = 0;
1877 enum arm_reg_type rtype = REG_TYPE_NDQ;
1878 int addregs = 1;
1879 const char *const incr_error = _("register stride must be 1 or 2");
1880 const char *const type_error = _("mismatched element/structure types in list");
1881 struct neon_typed_alias firsttype;
1882
1883 if (skip_past_char (&ptr, '{') == SUCCESS)
1884 leading_brace = 1;
1885
1886 do
1887 {
1888 struct neon_typed_alias atype;
1889 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1890
1891 if (getreg == FAIL)
1892 {
1893 first_error (_(reg_expected_msgs[rtype]));
1894 return FAIL;
1895 }
1896
1897 if (base_reg == -1)
1898 {
1899 base_reg = getreg;
1900 if (rtype == REG_TYPE_NQ)
1901 {
1902 reg_incr = 1;
1903 addregs = 2;
1904 }
1905 firsttype = atype;
1906 }
1907 else if (reg_incr == -1)
1908 {
1909 reg_incr = getreg - base_reg;
1910 if (reg_incr < 1 || reg_incr > 2)
1911 {
1912 first_error (_(incr_error));
1913 return FAIL;
1914 }
1915 }
1916 else if (getreg != base_reg + reg_incr * count)
1917 {
1918 first_error (_(incr_error));
1919 return FAIL;
1920 }
1921
1922 if (! neon_alias_types_same (&atype, &firsttype))
1923 {
1924 first_error (_(type_error));
1925 return FAIL;
1926 }
1927
1928 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1929 modes. */
1930 if (ptr[0] == '-')
1931 {
1932 struct neon_typed_alias htype;
1933 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1934 if (lane == -1)
1935 lane = NEON_INTERLEAVE_LANES;
1936 else if (lane != NEON_INTERLEAVE_LANES)
1937 {
1938 first_error (_(type_error));
1939 return FAIL;
1940 }
1941 if (reg_incr == -1)
1942 reg_incr = 1;
1943 else if (reg_incr != 1)
1944 {
1945 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
1946 return FAIL;
1947 }
1948 ptr++;
1949 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
1950 if (hireg == FAIL)
1951 {
1952 first_error (_(reg_expected_msgs[rtype]));
1953 return FAIL;
1954 }
1955 if (! neon_alias_types_same (&htype, &firsttype))
1956 {
1957 first_error (_(type_error));
1958 return FAIL;
1959 }
1960 count += hireg + dregs - getreg;
1961 continue;
1962 }
1963
1964 /* If we're using Q registers, we can't use [] or [n] syntax. */
1965 if (rtype == REG_TYPE_NQ)
1966 {
1967 count += 2;
1968 continue;
1969 }
1970
1971 if ((atype.defined & NTA_HASINDEX) != 0)
1972 {
1973 if (lane == -1)
1974 lane = atype.index;
1975 else if (lane != atype.index)
1976 {
1977 first_error (_(type_error));
1978 return FAIL;
1979 }
1980 }
1981 else if (lane == -1)
1982 lane = NEON_INTERLEAVE_LANES;
1983 else if (lane != NEON_INTERLEAVE_LANES)
1984 {
1985 first_error (_(type_error));
1986 return FAIL;
1987 }
1988 count++;
1989 }
1990 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
1991
1992 /* No lane set by [x]. We must be interleaving structures. */
1993 if (lane == -1)
1994 lane = NEON_INTERLEAVE_LANES;
1995
1996 /* Sanity check. */
1997 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
1998 || (count > 1 && reg_incr == -1))
1999 {
2000 first_error (_("error parsing element/structure list"));
2001 return FAIL;
2002 }
2003
2004 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2005 {
2006 first_error (_("expected }"));
2007 return FAIL;
2008 }
2009
2010 if (reg_incr == -1)
2011 reg_incr = 1;
2012
2013 if (eltype)
2014 *eltype = firsttype.eltype;
2015
2016 *pbase = base_reg;
2017 *str = ptr;
2018
2019 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2020 }
2021
2022 /* Parse an explicit relocation suffix on an expression. This is
2023 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2024 arm_reloc_hsh contains no entries, so this function can only
2025 succeed if there is no () after the word. Returns -1 on error,
2026 BFD_RELOC_UNUSED if there wasn't any suffix. */
2027 static int
2028 parse_reloc (char **str)
2029 {
2030 struct reloc_entry *r;
2031 char *p, *q;
2032
2033 if (**str != '(')
2034 return BFD_RELOC_UNUSED;
2035
2036 p = *str + 1;
2037 q = p;
2038
2039 while (*q && *q != ')' && *q != ',')
2040 q++;
2041 if (*q != ')')
2042 return -1;
2043
2044 if ((r = (struct reloc_entry *)
2045 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
2046 return -1;
2047
2048 *str = q + 1;
2049 return r->reloc;
2050 }
2051
2052 /* Directives: register aliases. */
2053
2054 static struct reg_entry *
2055 insert_reg_alias (char *str, int number, int type)
2056 {
2057 struct reg_entry *new_reg;
2058 const char *name;
2059
2060 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
2061 {
2062 if (new_reg->builtin)
2063 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
2064
2065 /* Only warn about a redefinition if it's not defined as the
2066 same register. */
2067 else if (new_reg->number != number || new_reg->type != type)
2068 as_warn (_("ignoring redefinition of register alias '%s'"), str);
2069
2070 return NULL;
2071 }
2072
2073 name = xstrdup (str);
2074 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
2075
2076 new_reg->name = name;
2077 new_reg->number = number;
2078 new_reg->type = type;
2079 new_reg->builtin = FALSE;
2080 new_reg->neon = NULL;
2081
2082 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
2083 abort ();
2084
2085 return new_reg;
2086 }
2087
2088 static void
2089 insert_neon_reg_alias (char *str, int number, int type,
2090 struct neon_typed_alias *atype)
2091 {
2092 struct reg_entry *reg = insert_reg_alias (str, number, type);
2093
2094 if (!reg)
2095 {
2096 first_error (_("attempt to redefine typed alias"));
2097 return;
2098 }
2099
2100 if (atype)
2101 {
2102 reg->neon = (struct neon_typed_alias *)
2103 xmalloc (sizeof (struct neon_typed_alias));
2104 *reg->neon = *atype;
2105 }
2106 }
2107
2108 /* Look for the .req directive. This is of the form:
2109
2110 new_register_name .req existing_register_name
2111
2112 If we find one, or if it looks sufficiently like one that we want to
2113 handle any error here, return TRUE. Otherwise return FALSE. */
2114
2115 static bfd_boolean
2116 create_register_alias (char * newname, char *p)
2117 {
2118 struct reg_entry *old;
2119 char *oldname, *nbuf;
2120 size_t nlen;
2121
2122 /* The input scrubber ensures that whitespace after the mnemonic is
2123 collapsed to single spaces. */
2124 oldname = p;
2125 if (strncmp (oldname, " .req ", 6) != 0)
2126 return FALSE;
2127
2128 oldname += 6;
2129 if (*oldname == '\0')
2130 return FALSE;
2131
2132 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
2133 if (!old)
2134 {
2135 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2136 return TRUE;
2137 }
2138
2139 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2140 the desired alias name, and p points to its end. If not, then
2141 the desired alias name is in the global original_case_string. */
2142 #ifdef TC_CASE_SENSITIVE
2143 nlen = p - newname;
2144 #else
2145 newname = original_case_string;
2146 nlen = strlen (newname);
2147 #endif
2148
2149 nbuf = (char *) alloca (nlen + 1);
2150 memcpy (nbuf, newname, nlen);
2151 nbuf[nlen] = '\0';
2152
2153 /* Create aliases under the new name as stated; an all-lowercase
2154 version of the new name; and an all-uppercase version of the new
2155 name. */
2156 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2157 {
2158 for (p = nbuf; *p; p++)
2159 *p = TOUPPER (*p);
2160
2161 if (strncmp (nbuf, newname, nlen))
2162 {
2163 /* If this attempt to create an additional alias fails, do not bother
2164 trying to create the all-lower case alias. We will fail and issue
2165 a second, duplicate error message. This situation arises when the
2166 programmer does something like:
2167 foo .req r0
2168 Foo .req r1
2169 The second .req creates the "Foo" alias but then fails to create
2170 the artificial FOO alias because it has already been created by the
2171 first .req. */
2172 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2173 return TRUE;
2174 }
2175
2176 for (p = nbuf; *p; p++)
2177 *p = TOLOWER (*p);
2178
2179 if (strncmp (nbuf, newname, nlen))
2180 insert_reg_alias (nbuf, old->number, old->type);
2181 }
2182
2183 return TRUE;
2184 }
2185
2186 /* Create a Neon typed/indexed register alias using directives, e.g.:
2187 X .dn d5.s32[1]
2188 Y .qn 6.s16
2189 Z .dn d7
2190 T .dn Z[0]
2191 These typed registers can be used instead of the types specified after the
2192 Neon mnemonic, so long as all operands given have types. Types can also be
2193 specified directly, e.g.:
2194 vadd d0.s32, d1.s32, d2.s32 */
2195
2196 static bfd_boolean
2197 create_neon_reg_alias (char *newname, char *p)
2198 {
2199 enum arm_reg_type basetype;
2200 struct reg_entry *basereg;
2201 struct reg_entry mybasereg;
2202 struct neon_type ntype;
2203 struct neon_typed_alias typeinfo;
2204 char *namebuf, *nameend;
2205 int namelen;
2206
2207 typeinfo.defined = 0;
2208 typeinfo.eltype.type = NT_invtype;
2209 typeinfo.eltype.size = -1;
2210 typeinfo.index = -1;
2211
2212 nameend = p;
2213
2214 if (strncmp (p, " .dn ", 5) == 0)
2215 basetype = REG_TYPE_VFD;
2216 else if (strncmp (p, " .qn ", 5) == 0)
2217 basetype = REG_TYPE_NQ;
2218 else
2219 return FALSE;
2220
2221 p += 5;
2222
2223 if (*p == '\0')
2224 return FALSE;
2225
2226 basereg = arm_reg_parse_multi (&p);
2227
2228 if (basereg && basereg->type != basetype)
2229 {
2230 as_bad (_("bad type for register"));
2231 return FALSE;
2232 }
2233
2234 if (basereg == NULL)
2235 {
2236 expressionS exp;
2237 /* Try parsing as an integer. */
2238 my_get_expression (&exp, &p, GE_NO_PREFIX);
2239 if (exp.X_op != O_constant)
2240 {
2241 as_bad (_("expression must be constant"));
2242 return FALSE;
2243 }
2244 basereg = &mybasereg;
2245 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2246 : exp.X_add_number;
2247 basereg->neon = 0;
2248 }
2249
2250 if (basereg->neon)
2251 typeinfo = *basereg->neon;
2252
2253 if (parse_neon_type (&ntype, &p) == SUCCESS)
2254 {
2255 /* We got a type. */
2256 if (typeinfo.defined & NTA_HASTYPE)
2257 {
2258 as_bad (_("can't redefine the type of a register alias"));
2259 return FALSE;
2260 }
2261
2262 typeinfo.defined |= NTA_HASTYPE;
2263 if (ntype.elems != 1)
2264 {
2265 as_bad (_("you must specify a single type only"));
2266 return FALSE;
2267 }
2268 typeinfo.eltype = ntype.el[0];
2269 }
2270
2271 if (skip_past_char (&p, '[') == SUCCESS)
2272 {
2273 expressionS exp;
2274 /* We got a scalar index. */
2275
2276 if (typeinfo.defined & NTA_HASINDEX)
2277 {
2278 as_bad (_("can't redefine the index of a scalar alias"));
2279 return FALSE;
2280 }
2281
2282 my_get_expression (&exp, &p, GE_NO_PREFIX);
2283
2284 if (exp.X_op != O_constant)
2285 {
2286 as_bad (_("scalar index must be constant"));
2287 return FALSE;
2288 }
2289
2290 typeinfo.defined |= NTA_HASINDEX;
2291 typeinfo.index = exp.X_add_number;
2292
2293 if (skip_past_char (&p, ']') == FAIL)
2294 {
2295 as_bad (_("expecting ]"));
2296 return FALSE;
2297 }
2298 }
2299
2300 namelen = nameend - newname;
2301 namebuf = (char *) alloca (namelen + 1);
2302 strncpy (namebuf, newname, namelen);
2303 namebuf[namelen] = '\0';
2304
2305 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2306 typeinfo.defined != 0 ? &typeinfo : NULL);
2307
2308 /* Insert name in all uppercase. */
2309 for (p = namebuf; *p; p++)
2310 *p = TOUPPER (*p);
2311
2312 if (strncmp (namebuf, newname, namelen))
2313 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2314 typeinfo.defined != 0 ? &typeinfo : NULL);
2315
2316 /* Insert name in all lowercase. */
2317 for (p = namebuf; *p; p++)
2318 *p = TOLOWER (*p);
2319
2320 if (strncmp (namebuf, newname, namelen))
2321 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2322 typeinfo.defined != 0 ? &typeinfo : NULL);
2323
2324 return TRUE;
2325 }
2326
2327 /* Should never be called, as .req goes between the alias and the
2328 register name, not at the beginning of the line. */
2329
2330 static void
2331 s_req (int a ATTRIBUTE_UNUSED)
2332 {
2333 as_bad (_("invalid syntax for .req directive"));
2334 }
2335
2336 static void
2337 s_dn (int a ATTRIBUTE_UNUSED)
2338 {
2339 as_bad (_("invalid syntax for .dn directive"));
2340 }
2341
2342 static void
2343 s_qn (int a ATTRIBUTE_UNUSED)
2344 {
2345 as_bad (_("invalid syntax for .qn directive"));
2346 }
2347
2348 /* The .unreq directive deletes an alias which was previously defined
2349 by .req. For example:
2350
2351 my_alias .req r11
2352 .unreq my_alias */
2353
2354 static void
2355 s_unreq (int a ATTRIBUTE_UNUSED)
2356 {
2357 char * name;
2358 char saved_char;
2359
2360 name = input_line_pointer;
2361
2362 while (*input_line_pointer != 0
2363 && *input_line_pointer != ' '
2364 && *input_line_pointer != '\n')
2365 ++input_line_pointer;
2366
2367 saved_char = *input_line_pointer;
2368 *input_line_pointer = 0;
2369
2370 if (!*name)
2371 as_bad (_("invalid syntax for .unreq directive"));
2372 else
2373 {
2374 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2375 name);
2376
2377 if (!reg)
2378 as_bad (_("unknown register alias '%s'"), name);
2379 else if (reg->builtin)
2380 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2381 name);
2382 else
2383 {
2384 char * p;
2385 char * nbuf;
2386
2387 hash_delete (arm_reg_hsh, name, FALSE);
2388 free ((char *) reg->name);
2389 if (reg->neon)
2390 free (reg->neon);
2391 free (reg);
2392
2393 /* Also locate the all upper case and all lower case versions.
2394 Do not complain if we cannot find one or the other as it
2395 was probably deleted above. */
2396
2397 nbuf = strdup (name);
2398 for (p = nbuf; *p; p++)
2399 *p = TOUPPER (*p);
2400 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2401 if (reg)
2402 {
2403 hash_delete (arm_reg_hsh, nbuf, FALSE);
2404 free ((char *) reg->name);
2405 if (reg->neon)
2406 free (reg->neon);
2407 free (reg);
2408 }
2409
2410 for (p = nbuf; *p; p++)
2411 *p = TOLOWER (*p);
2412 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2413 if (reg)
2414 {
2415 hash_delete (arm_reg_hsh, nbuf, FALSE);
2416 free ((char *) reg->name);
2417 if (reg->neon)
2418 free (reg->neon);
2419 free (reg);
2420 }
2421
2422 free (nbuf);
2423 }
2424 }
2425
2426 *input_line_pointer = saved_char;
2427 demand_empty_rest_of_line ();
2428 }
2429
2430 /* Directives: Instruction set selection. */
2431
2432 #ifdef OBJ_ELF
2433 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2434 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2435 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2436 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2437
2438 /* Create a new mapping symbol for the transition to STATE. */
2439
2440 static void
2441 make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
2442 {
2443 symbolS * symbolP;
2444 const char * symname;
2445 int type;
2446
2447 switch (state)
2448 {
2449 case MAP_DATA:
2450 symname = "$d";
2451 type = BSF_NO_FLAGS;
2452 break;
2453 case MAP_ARM:
2454 symname = "$a";
2455 type = BSF_NO_FLAGS;
2456 break;
2457 case MAP_THUMB:
2458 symname = "$t";
2459 type = BSF_NO_FLAGS;
2460 break;
2461 default:
2462 abort ();
2463 }
2464
2465 symbolP = symbol_new (symname, now_seg, value, frag);
2466 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2467
2468 switch (state)
2469 {
2470 case MAP_ARM:
2471 THUMB_SET_FUNC (symbolP, 0);
2472 ARM_SET_THUMB (symbolP, 0);
2473 ARM_SET_INTERWORK (symbolP, support_interwork);
2474 break;
2475
2476 case MAP_THUMB:
2477 THUMB_SET_FUNC (symbolP, 1);
2478 ARM_SET_THUMB (symbolP, 1);
2479 ARM_SET_INTERWORK (symbolP, support_interwork);
2480 break;
2481
2482 case MAP_DATA:
2483 default:
2484 break;
2485 }
2486
2487 /* Save the mapping symbols for future reference. Also check that
2488 we do not place two mapping symbols at the same offset within a
2489 frag. We'll handle overlap between frags in
2490 check_mapping_symbols. */
2491 if (value == 0)
2492 {
2493 know (frag->tc_frag_data.first_map == NULL);
2494 frag->tc_frag_data.first_map = symbolP;
2495 }
2496 if (frag->tc_frag_data.last_map != NULL)
2497 know (S_GET_VALUE (frag->tc_frag_data.last_map) < S_GET_VALUE (symbolP));
2498 frag->tc_frag_data.last_map = symbolP;
2499 }
2500
2501 /* We must sometimes convert a region marked as code to data during
2502 code alignment, if an odd number of bytes have to be padded. The
2503 code mapping symbol is pushed to an aligned address. */
2504
2505 static void
2506 insert_data_mapping_symbol (enum mstate state,
2507 valueT value, fragS *frag, offsetT bytes)
2508 {
2509 /* If there was already a mapping symbol, remove it. */
2510 if (frag->tc_frag_data.last_map != NULL
2511 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2512 {
2513 symbolS *symp = frag->tc_frag_data.last_map;
2514
2515 if (value == 0)
2516 {
2517 know (frag->tc_frag_data.first_map == symp);
2518 frag->tc_frag_data.first_map = NULL;
2519 }
2520 frag->tc_frag_data.last_map = NULL;
2521 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
2522 }
2523
2524 make_mapping_symbol (MAP_DATA, value, frag);
2525 make_mapping_symbol (state, value + bytes, frag);
2526 }
2527
2528 static void mapping_state_2 (enum mstate state, int max_chars);
2529
2530 /* Set the mapping state to STATE. Only call this when about to
2531 emit some STATE bytes to the file. */
2532
2533 void
2534 mapping_state (enum mstate state)
2535 {
2536 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2537
2538 #define TRANSITION(from, to) (mapstate == (from) && state == (to))
2539
2540 if (mapstate == state)
2541 /* The mapping symbol has already been emitted.
2542 There is nothing else to do. */
2543 return;
2544 else if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
2545 /* This case will be evaluated later in the next else. */
2546 return;
2547 else if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2548 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2549 {
2550 /* Only add the symbol if the offset is > 0:
2551 if we're at the first frag, check it's size > 0;
2552 if we're not at the first frag, then for sure
2553 the offset is > 0. */
2554 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2555 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2556
2557 if (add_symbol)
2558 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2559 }
2560
2561 mapping_state_2 (state, 0);
2562 #undef TRANSITION
2563 }
2564
2565 /* Same as mapping_state, but MAX_CHARS bytes have already been
2566 allocated. Put the mapping symbol that far back. */
2567
2568 static void
2569 mapping_state_2 (enum mstate state, int max_chars)
2570 {
2571 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2572
2573 if (!SEG_NORMAL (now_seg))
2574 return;
2575
2576 if (mapstate == state)
2577 /* The mapping symbol has already been emitted.
2578 There is nothing else to do. */
2579 return;
2580
2581 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2582 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
2583 }
2584 #else
2585 #define mapping_state(x) ((void)0)
2586 #define mapping_state_2(x, y) ((void)0)
2587 #endif
2588
2589 /* Find the real, Thumb encoded start of a Thumb function. */
2590
2591 #ifdef OBJ_COFF
2592 static symbolS *
2593 find_real_start (symbolS * symbolP)
2594 {
2595 char * real_start;
2596 const char * name = S_GET_NAME (symbolP);
2597 symbolS * new_target;
2598
2599 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2600 #define STUB_NAME ".real_start_of"
2601
2602 if (name == NULL)
2603 abort ();
2604
2605 /* The compiler may generate BL instructions to local labels because
2606 it needs to perform a branch to a far away location. These labels
2607 do not have a corresponding ".real_start_of" label. We check
2608 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2609 the ".real_start_of" convention for nonlocal branches. */
2610 if (S_IS_LOCAL (symbolP) || name[0] == '.')
2611 return symbolP;
2612
2613 real_start = ACONCAT ((STUB_NAME, name, NULL));
2614 new_target = symbol_find (real_start);
2615
2616 if (new_target == NULL)
2617 {
2618 as_warn (_("Failed to find real start of function: %s\n"), name);
2619 new_target = symbolP;
2620 }
2621
2622 return new_target;
2623 }
2624 #endif
2625
2626 static void
2627 opcode_select (int width)
2628 {
2629 switch (width)
2630 {
2631 case 16:
2632 if (! thumb_mode)
2633 {
2634 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
2635 as_bad (_("selected processor does not support THUMB opcodes"));
2636
2637 thumb_mode = 1;
2638 /* No need to force the alignment, since we will have been
2639 coming from ARM mode, which is word-aligned. */
2640 record_alignment (now_seg, 1);
2641 }
2642 break;
2643
2644 case 32:
2645 if (thumb_mode)
2646 {
2647 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
2648 as_bad (_("selected processor does not support ARM opcodes"));
2649
2650 thumb_mode = 0;
2651
2652 if (!need_pass_2)
2653 frag_align (2, 0, 0);
2654
2655 record_alignment (now_seg, 1);
2656 }
2657 break;
2658
2659 default:
2660 as_bad (_("invalid instruction size selected (%d)"), width);
2661 }
2662 }
2663
2664 static void
2665 s_arm (int ignore ATTRIBUTE_UNUSED)
2666 {
2667 opcode_select (32);
2668 demand_empty_rest_of_line ();
2669 }
2670
2671 static void
2672 s_thumb (int ignore ATTRIBUTE_UNUSED)
2673 {
2674 opcode_select (16);
2675 demand_empty_rest_of_line ();
2676 }
2677
2678 static void
2679 s_code (int unused ATTRIBUTE_UNUSED)
2680 {
2681 int temp;
2682
2683 temp = get_absolute_expression ();
2684 switch (temp)
2685 {
2686 case 16:
2687 case 32:
2688 opcode_select (temp);
2689 break;
2690
2691 default:
2692 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2693 }
2694 }
2695
2696 static void
2697 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2698 {
2699 /* If we are not already in thumb mode go into it, EVEN if
2700 the target processor does not support thumb instructions.
2701 This is used by gcc/config/arm/lib1funcs.asm for example
2702 to compile interworking support functions even if the
2703 target processor should not support interworking. */
2704 if (! thumb_mode)
2705 {
2706 thumb_mode = 2;
2707 record_alignment (now_seg, 1);
2708 }
2709
2710 demand_empty_rest_of_line ();
2711 }
2712
2713 static void
2714 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2715 {
2716 s_thumb (0);
2717
2718 /* The following label is the name/address of the start of a Thumb function.
2719 We need to know this for the interworking support. */
2720 label_is_thumb_function_name = TRUE;
2721 }
2722
2723 /* Perform a .set directive, but also mark the alias as
2724 being a thumb function. */
2725
2726 static void
2727 s_thumb_set (int equiv)
2728 {
2729 /* XXX the following is a duplicate of the code for s_set() in read.c
2730 We cannot just call that code as we need to get at the symbol that
2731 is created. */
2732 char * name;
2733 char delim;
2734 char * end_name;
2735 symbolS * symbolP;
2736
2737 /* Especial apologies for the random logic:
2738 This just grew, and could be parsed much more simply!
2739 Dean - in haste. */
2740 name = input_line_pointer;
2741 delim = get_symbol_end ();
2742 end_name = input_line_pointer;
2743 *end_name = delim;
2744
2745 if (*input_line_pointer != ',')
2746 {
2747 *end_name = 0;
2748 as_bad (_("expected comma after name \"%s\""), name);
2749 *end_name = delim;
2750 ignore_rest_of_line ();
2751 return;
2752 }
2753
2754 input_line_pointer++;
2755 *end_name = 0;
2756
2757 if (name[0] == '.' && name[1] == '\0')
2758 {
2759 /* XXX - this should not happen to .thumb_set. */
2760 abort ();
2761 }
2762
2763 if ((symbolP = symbol_find (name)) == NULL
2764 && (symbolP = md_undefined_symbol (name)) == NULL)
2765 {
2766 #ifndef NO_LISTING
2767 /* When doing symbol listings, play games with dummy fragments living
2768 outside the normal fragment chain to record the file and line info
2769 for this symbol. */
2770 if (listing & LISTING_SYMBOLS)
2771 {
2772 extern struct list_info_struct * listing_tail;
2773 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
2774
2775 memset (dummy_frag, 0, sizeof (fragS));
2776 dummy_frag->fr_type = rs_fill;
2777 dummy_frag->line = listing_tail;
2778 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2779 dummy_frag->fr_symbol = symbolP;
2780 }
2781 else
2782 #endif
2783 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2784
2785 #ifdef OBJ_COFF
2786 /* "set" symbols are local unless otherwise specified. */
2787 SF_SET_LOCAL (symbolP);
2788 #endif /* OBJ_COFF */
2789 } /* Make a new symbol. */
2790
2791 symbol_table_insert (symbolP);
2792
2793 * end_name = delim;
2794
2795 if (equiv
2796 && S_IS_DEFINED (symbolP)
2797 && S_GET_SEGMENT (symbolP) != reg_section)
2798 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2799
2800 pseudo_set (symbolP);
2801
2802 demand_empty_rest_of_line ();
2803
2804 /* XXX Now we come to the Thumb specific bit of code. */
2805
2806 THUMB_SET_FUNC (symbolP, 1);
2807 ARM_SET_THUMB (symbolP, 1);
2808 #if defined OBJ_ELF || defined OBJ_COFF
2809 ARM_SET_INTERWORK (symbolP, support_interwork);
2810 #endif
2811 }
2812
2813 /* Directives: Mode selection. */
2814
2815 /* .syntax [unified|divided] - choose the new unified syntax
2816 (same for Arm and Thumb encoding, modulo slight differences in what
2817 can be represented) or the old divergent syntax for each mode. */
2818 static void
2819 s_syntax (int unused ATTRIBUTE_UNUSED)
2820 {
2821 char *name, delim;
2822
2823 name = input_line_pointer;
2824 delim = get_symbol_end ();
2825
2826 if (!strcasecmp (name, "unified"))
2827 unified_syntax = TRUE;
2828 else if (!strcasecmp (name, "divided"))
2829 unified_syntax = FALSE;
2830 else
2831 {
2832 as_bad (_("unrecognized syntax mode \"%s\""), name);
2833 return;
2834 }
2835 *input_line_pointer = delim;
2836 demand_empty_rest_of_line ();
2837 }
2838
2839 /* Directives: sectioning and alignment. */
2840
2841 /* Same as s_align_ptwo but align 0 => align 2. */
2842
2843 static void
2844 s_align (int unused ATTRIBUTE_UNUSED)
2845 {
2846 int temp;
2847 bfd_boolean fill_p;
2848 long temp_fill;
2849 long max_alignment = 15;
2850
2851 temp = get_absolute_expression ();
2852 if (temp > max_alignment)
2853 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2854 else if (temp < 0)
2855 {
2856 as_bad (_("alignment negative. 0 assumed."));
2857 temp = 0;
2858 }
2859
2860 if (*input_line_pointer == ',')
2861 {
2862 input_line_pointer++;
2863 temp_fill = get_absolute_expression ();
2864 fill_p = TRUE;
2865 }
2866 else
2867 {
2868 fill_p = FALSE;
2869 temp_fill = 0;
2870 }
2871
2872 if (!temp)
2873 temp = 2;
2874
2875 /* Only make a frag if we HAVE to. */
2876 if (temp && !need_pass_2)
2877 {
2878 if (!fill_p && subseg_text_p (now_seg))
2879 frag_align_code (temp, 0);
2880 else
2881 frag_align (temp, (int) temp_fill, 0);
2882 }
2883 demand_empty_rest_of_line ();
2884
2885 record_alignment (now_seg, temp);
2886 }
2887
2888 static void
2889 s_bss (int ignore ATTRIBUTE_UNUSED)
2890 {
2891 /* We don't support putting frags in the BSS segment, we fake it by
2892 marking in_bss, then looking at s_skip for clues. */
2893 subseg_set (bss_section, 0);
2894 demand_empty_rest_of_line ();
2895
2896 #ifdef md_elf_section_change_hook
2897 md_elf_section_change_hook ();
2898 #endif
2899 }
2900
2901 static void
2902 s_even (int ignore ATTRIBUTE_UNUSED)
2903 {
2904 /* Never make frag if expect extra pass. */
2905 if (!need_pass_2)
2906 frag_align (1, 0, 0);
2907
2908 record_alignment (now_seg, 1);
2909
2910 demand_empty_rest_of_line ();
2911 }
2912
2913 /* Directives: Literal pools. */
2914
2915 static literal_pool *
2916 find_literal_pool (void)
2917 {
2918 literal_pool * pool;
2919
2920 for (pool = list_of_pools; pool != NULL; pool = pool->next)
2921 {
2922 if (pool->section == now_seg
2923 && pool->sub_section == now_subseg)
2924 break;
2925 }
2926
2927 return pool;
2928 }
2929
2930 static literal_pool *
2931 find_or_make_literal_pool (void)
2932 {
2933 /* Next literal pool ID number. */
2934 static unsigned int latest_pool_num = 1;
2935 literal_pool * pool;
2936
2937 pool = find_literal_pool ();
2938
2939 if (pool == NULL)
2940 {
2941 /* Create a new pool. */
2942 pool = (literal_pool *) xmalloc (sizeof (* pool));
2943 if (! pool)
2944 return NULL;
2945
2946 pool->next_free_entry = 0;
2947 pool->section = now_seg;
2948 pool->sub_section = now_subseg;
2949 pool->next = list_of_pools;
2950 pool->symbol = NULL;
2951
2952 /* Add it to the list. */
2953 list_of_pools = pool;
2954 }
2955
2956 /* New pools, and emptied pools, will have a NULL symbol. */
2957 if (pool->symbol == NULL)
2958 {
2959 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2960 (valueT) 0, &zero_address_frag);
2961 pool->id = latest_pool_num ++;
2962 }
2963
2964 /* Done. */
2965 return pool;
2966 }
2967
2968 /* Add the literal in the global 'inst'
2969 structure to the relevant literal pool. */
2970
2971 static int
2972 add_to_lit_pool (void)
2973 {
2974 literal_pool * pool;
2975 unsigned int entry;
2976
2977 pool = find_or_make_literal_pool ();
2978
2979 /* Check if this literal value is already in the pool. */
2980 for (entry = 0; entry < pool->next_free_entry; entry ++)
2981 {
2982 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2983 && (inst.reloc.exp.X_op == O_constant)
2984 && (pool->literals[entry].X_add_number
2985 == inst.reloc.exp.X_add_number)
2986 && (pool->literals[entry].X_unsigned
2987 == inst.reloc.exp.X_unsigned))
2988 break;
2989
2990 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2991 && (inst.reloc.exp.X_op == O_symbol)
2992 && (pool->literals[entry].X_add_number
2993 == inst.reloc.exp.X_add_number)
2994 && (pool->literals[entry].X_add_symbol
2995 == inst.reloc.exp.X_add_symbol)
2996 && (pool->literals[entry].X_op_symbol
2997 == inst.reloc.exp.X_op_symbol))
2998 break;
2999 }
3000
3001 /* Do we need to create a new entry? */
3002 if (entry == pool->next_free_entry)
3003 {
3004 if (entry >= MAX_LITERAL_POOL_SIZE)
3005 {
3006 inst.error = _("literal pool overflow");
3007 return FAIL;
3008 }
3009
3010 pool->literals[entry] = inst.reloc.exp;
3011 pool->next_free_entry += 1;
3012 }
3013
3014 inst.reloc.exp.X_op = O_symbol;
3015 inst.reloc.exp.X_add_number = ((int) entry) * 4;
3016 inst.reloc.exp.X_add_symbol = pool->symbol;
3017
3018 return SUCCESS;
3019 }
3020
3021 /* Can't use symbol_new here, so have to create a symbol and then at
3022 a later date assign it a value. Thats what these functions do. */
3023
3024 static void
3025 symbol_locate (symbolS * symbolP,
3026 const char * name, /* It is copied, the caller can modify. */
3027 segT segment, /* Segment identifier (SEG_<something>). */
3028 valueT valu, /* Symbol value. */
3029 fragS * frag) /* Associated fragment. */
3030 {
3031 unsigned int name_length;
3032 char * preserved_copy_of_name;
3033
3034 name_length = strlen (name) + 1; /* +1 for \0. */
3035 obstack_grow (&notes, name, name_length);
3036 preserved_copy_of_name = (char *) obstack_finish (&notes);
3037
3038 #ifdef tc_canonicalize_symbol_name
3039 preserved_copy_of_name =
3040 tc_canonicalize_symbol_name (preserved_copy_of_name);
3041 #endif
3042
3043 S_SET_NAME (symbolP, preserved_copy_of_name);
3044
3045 S_SET_SEGMENT (symbolP, segment);
3046 S_SET_VALUE (symbolP, valu);
3047 symbol_clear_list_pointers (symbolP);
3048
3049 symbol_set_frag (symbolP, frag);
3050
3051 /* Link to end of symbol chain. */
3052 {
3053 extern int symbol_table_frozen;
3054
3055 if (symbol_table_frozen)
3056 abort ();
3057 }
3058
3059 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
3060
3061 obj_symbol_new_hook (symbolP);
3062
3063 #ifdef tc_symbol_new_hook
3064 tc_symbol_new_hook (symbolP);
3065 #endif
3066
3067 #ifdef DEBUG_SYMS
3068 verify_symbol_chain (symbol_rootP, symbol_lastP);
3069 #endif /* DEBUG_SYMS */
3070 }
3071
3072
3073 static void
3074 s_ltorg (int ignored ATTRIBUTE_UNUSED)
3075 {
3076 unsigned int entry;
3077 literal_pool * pool;
3078 char sym_name[20];
3079
3080 pool = find_literal_pool ();
3081 if (pool == NULL
3082 || pool->symbol == NULL
3083 || pool->next_free_entry == 0)
3084 return;
3085
3086 mapping_state (MAP_DATA);
3087
3088 /* Align pool as you have word accesses.
3089 Only make a frag if we have to. */
3090 if (!need_pass_2)
3091 frag_align (2, 0, 0);
3092
3093 record_alignment (now_seg, 2);
3094
3095 sprintf (sym_name, "$$lit_\002%x", pool->id);
3096
3097 symbol_locate (pool->symbol, sym_name, now_seg,
3098 (valueT) frag_now_fix (), frag_now);
3099 symbol_table_insert (pool->symbol);
3100
3101 ARM_SET_THUMB (pool->symbol, thumb_mode);
3102
3103 #if defined OBJ_COFF || defined OBJ_ELF
3104 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3105 #endif
3106
3107 for (entry = 0; entry < pool->next_free_entry; entry ++)
3108 /* First output the expression in the instruction to the pool. */
3109 emit_expr (&(pool->literals[entry]), 4); /* .word */
3110
3111 /* Mark the pool as empty. */
3112 pool->next_free_entry = 0;
3113 pool->symbol = NULL;
3114 }
3115
3116 #ifdef OBJ_ELF
3117 /* Forward declarations for functions below, in the MD interface
3118 section. */
3119 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3120 static valueT create_unwind_entry (int);
3121 static void start_unwind_section (const segT, int);
3122 static void add_unwind_opcode (valueT, int);
3123 static void flush_pending_unwind (void);
3124
3125 /* Directives: Data. */
3126
3127 static void
3128 s_arm_elf_cons (int nbytes)
3129 {
3130 expressionS exp;
3131
3132 #ifdef md_flush_pending_output
3133 md_flush_pending_output ();
3134 #endif
3135
3136 if (is_it_end_of_statement ())
3137 {
3138 demand_empty_rest_of_line ();
3139 return;
3140 }
3141
3142 #ifdef md_cons_align
3143 md_cons_align (nbytes);
3144 #endif
3145
3146 mapping_state (MAP_DATA);
3147 do
3148 {
3149 int reloc;
3150 char *base = input_line_pointer;
3151
3152 expression (& exp);
3153
3154 if (exp.X_op != O_symbol)
3155 emit_expr (&exp, (unsigned int) nbytes);
3156 else
3157 {
3158 char *before_reloc = input_line_pointer;
3159 reloc = parse_reloc (&input_line_pointer);
3160 if (reloc == -1)
3161 {
3162 as_bad (_("unrecognized relocation suffix"));
3163 ignore_rest_of_line ();
3164 return;
3165 }
3166 else if (reloc == BFD_RELOC_UNUSED)
3167 emit_expr (&exp, (unsigned int) nbytes);
3168 else
3169 {
3170 reloc_howto_type *howto = (reloc_howto_type *)
3171 bfd_reloc_type_lookup (stdoutput,
3172 (bfd_reloc_code_real_type) reloc);
3173 int size = bfd_get_reloc_size (howto);
3174
3175 if (reloc == BFD_RELOC_ARM_PLT32)
3176 {
3177 as_bad (_("(plt) is only valid on branch targets"));
3178 reloc = BFD_RELOC_UNUSED;
3179 size = 0;
3180 }
3181
3182 if (size > nbytes)
3183 as_bad (_("%s relocations do not fit in %d bytes"),
3184 howto->name, nbytes);
3185 else
3186 {
3187 /* We've parsed an expression stopping at O_symbol.
3188 But there may be more expression left now that we
3189 have parsed the relocation marker. Parse it again.
3190 XXX Surely there is a cleaner way to do this. */
3191 char *p = input_line_pointer;
3192 int offset;
3193 char *save_buf = (char *) alloca (input_line_pointer - base);
3194 memcpy (save_buf, base, input_line_pointer - base);
3195 memmove (base + (input_line_pointer - before_reloc),
3196 base, before_reloc - base);
3197
3198 input_line_pointer = base + (input_line_pointer-before_reloc);
3199 expression (&exp);
3200 memcpy (base, save_buf, p - base);
3201
3202 offset = nbytes - size;
3203 p = frag_more ((int) nbytes);
3204 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3205 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
3206 }
3207 }
3208 }
3209 }
3210 while (*input_line_pointer++ == ',');
3211
3212 /* Put terminator back into stream. */
3213 input_line_pointer --;
3214 demand_empty_rest_of_line ();
3215 }
3216
3217 /* Emit an expression containing a 32-bit thumb instruction.
3218 Implementation based on put_thumb32_insn. */
3219
3220 static void
3221 emit_thumb32_expr (expressionS * exp)
3222 {
3223 expressionS exp_high = *exp;
3224
3225 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3226 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3227 exp->X_add_number &= 0xffff;
3228 emit_expr (exp, (unsigned int) THUMB_SIZE);
3229 }
3230
3231 /* Guess the instruction size based on the opcode. */
3232
3233 static int
3234 thumb_insn_size (int opcode)
3235 {
3236 if ((unsigned int) opcode < 0xe800u)
3237 return 2;
3238 else if ((unsigned int) opcode >= 0xe8000000u)
3239 return 4;
3240 else
3241 return 0;
3242 }
3243
3244 static bfd_boolean
3245 emit_insn (expressionS *exp, int nbytes)
3246 {
3247 int size = 0;
3248
3249 if (exp->X_op == O_constant)
3250 {
3251 size = nbytes;
3252
3253 if (size == 0)
3254 size = thumb_insn_size (exp->X_add_number);
3255
3256 if (size != 0)
3257 {
3258 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3259 {
3260 as_bad (_(".inst.n operand too big. "\
3261 "Use .inst.w instead"));
3262 size = 0;
3263 }
3264 else
3265 {
3266 if (now_it.state == AUTOMATIC_IT_BLOCK)
3267 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3268 else
3269 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3270
3271 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3272 emit_thumb32_expr (exp);
3273 else
3274 emit_expr (exp, (unsigned int) size);
3275
3276 it_fsm_post_encode ();
3277 }
3278 }
3279 else
3280 as_bad (_("cannot determine Thumb instruction size. " \
3281 "Use .inst.n/.inst.w instead"));
3282 }
3283 else
3284 as_bad (_("constant expression required"));
3285
3286 return (size != 0);
3287 }
3288
3289 /* Like s_arm_elf_cons but do not use md_cons_align and
3290 set the mapping state to MAP_ARM/MAP_THUMB. */
3291
3292 static void
3293 s_arm_elf_inst (int nbytes)
3294 {
3295 if (is_it_end_of_statement ())
3296 {
3297 demand_empty_rest_of_line ();
3298 return;
3299 }
3300
3301 /* Calling mapping_state () here will not change ARM/THUMB,
3302 but will ensure not to be in DATA state. */
3303
3304 if (thumb_mode)
3305 mapping_state (MAP_THUMB);
3306 else
3307 {
3308 if (nbytes != 0)
3309 {
3310 as_bad (_("width suffixes are invalid in ARM mode"));
3311 ignore_rest_of_line ();
3312 return;
3313 }
3314
3315 nbytes = 4;
3316
3317 mapping_state (MAP_ARM);
3318 }
3319
3320 do
3321 {
3322 expressionS exp;
3323
3324 expression (& exp);
3325
3326 if (! emit_insn (& exp, nbytes))
3327 {
3328 ignore_rest_of_line ();
3329 return;
3330 }
3331 }
3332 while (*input_line_pointer++ == ',');
3333
3334 /* Put terminator back into stream. */
3335 input_line_pointer --;
3336 demand_empty_rest_of_line ();
3337 }
3338
3339 /* Parse a .rel31 directive. */
3340
3341 static void
3342 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3343 {
3344 expressionS exp;
3345 char *p;
3346 valueT highbit;
3347
3348 highbit = 0;
3349 if (*input_line_pointer == '1')
3350 highbit = 0x80000000;
3351 else if (*input_line_pointer != '0')
3352 as_bad (_("expected 0 or 1"));
3353
3354 input_line_pointer++;
3355 if (*input_line_pointer != ',')
3356 as_bad (_("missing comma"));
3357 input_line_pointer++;
3358
3359 #ifdef md_flush_pending_output
3360 md_flush_pending_output ();
3361 #endif
3362
3363 #ifdef md_cons_align
3364 md_cons_align (4);
3365 #endif
3366
3367 mapping_state (MAP_DATA);
3368
3369 expression (&exp);
3370
3371 p = frag_more (4);
3372 md_number_to_chars (p, highbit, 4);
3373 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3374 BFD_RELOC_ARM_PREL31);
3375
3376 demand_empty_rest_of_line ();
3377 }
3378
3379 /* Directives: AEABI stack-unwind tables. */
3380
3381 /* Parse an unwind_fnstart directive. Simply records the current location. */
3382
3383 static void
3384 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3385 {
3386 demand_empty_rest_of_line ();
3387 if (unwind.proc_start)
3388 {
3389 as_bad (_("duplicate .fnstart directive"));
3390 return;
3391 }
3392
3393 /* Mark the start of the function. */
3394 unwind.proc_start = expr_build_dot ();
3395
3396 /* Reset the rest of the unwind info. */
3397 unwind.opcode_count = 0;
3398 unwind.table_entry = NULL;
3399 unwind.personality_routine = NULL;
3400 unwind.personality_index = -1;
3401 unwind.frame_size = 0;
3402 unwind.fp_offset = 0;
3403 unwind.fp_reg = REG_SP;
3404 unwind.fp_used = 0;
3405 unwind.sp_restored = 0;
3406 }
3407
3408
3409 /* Parse a handlerdata directive. Creates the exception handling table entry
3410 for the function. */
3411
3412 static void
3413 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3414 {
3415 demand_empty_rest_of_line ();
3416 if (!unwind.proc_start)
3417 as_bad (MISSING_FNSTART);
3418
3419 if (unwind.table_entry)
3420 as_bad (_("duplicate .handlerdata directive"));
3421
3422 create_unwind_entry (1);
3423 }
3424
3425 /* Parse an unwind_fnend directive. Generates the index table entry. */
3426
3427 static void
3428 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3429 {
3430 long where;
3431 char *ptr;
3432 valueT val;
3433 unsigned int marked_pr_dependency;
3434
3435 demand_empty_rest_of_line ();
3436
3437 if (!unwind.proc_start)
3438 {
3439 as_bad (_(".fnend directive without .fnstart"));
3440 return;
3441 }
3442
3443 /* Add eh table entry. */
3444 if (unwind.table_entry == NULL)
3445 val = create_unwind_entry (0);
3446 else
3447 val = 0;
3448
3449 /* Add index table entry. This is two words. */
3450 start_unwind_section (unwind.saved_seg, 1);
3451 frag_align (2, 0, 0);
3452 record_alignment (now_seg, 2);
3453
3454 ptr = frag_more (8);
3455 where = frag_now_fix () - 8;
3456
3457 /* Self relative offset of the function start. */
3458 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3459 BFD_RELOC_ARM_PREL31);
3460
3461 /* Indicate dependency on EHABI-defined personality routines to the
3462 linker, if it hasn't been done already. */
3463 marked_pr_dependency
3464 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
3465 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3466 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3467 {
3468 static const char *const name[] =
3469 {
3470 "__aeabi_unwind_cpp_pr0",
3471 "__aeabi_unwind_cpp_pr1",
3472 "__aeabi_unwind_cpp_pr2"
3473 };
3474 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3475 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3476 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3477 |= 1 << unwind.personality_index;
3478 }
3479
3480 if (val)
3481 /* Inline exception table entry. */
3482 md_number_to_chars (ptr + 4, val, 4);
3483 else
3484 /* Self relative offset of the table entry. */
3485 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3486 BFD_RELOC_ARM_PREL31);
3487
3488 /* Restore the original section. */
3489 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3490
3491 unwind.proc_start = NULL;
3492 }
3493
3494
3495 /* Parse an unwind_cantunwind directive. */
3496
3497 static void
3498 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3499 {
3500 demand_empty_rest_of_line ();
3501 if (!unwind.proc_start)
3502 as_bad (MISSING_FNSTART);
3503
3504 if (unwind.personality_routine || unwind.personality_index != -1)
3505 as_bad (_("personality routine specified for cantunwind frame"));
3506
3507 unwind.personality_index = -2;
3508 }
3509
3510
3511 /* Parse a personalityindex directive. */
3512
3513 static void
3514 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3515 {
3516 expressionS exp;
3517
3518 if (!unwind.proc_start)
3519 as_bad (MISSING_FNSTART);
3520
3521 if (unwind.personality_routine || unwind.personality_index != -1)
3522 as_bad (_("duplicate .personalityindex directive"));
3523
3524 expression (&exp);
3525
3526 if (exp.X_op != O_constant
3527 || exp.X_add_number < 0 || exp.X_add_number > 15)
3528 {
3529 as_bad (_("bad personality routine number"));
3530 ignore_rest_of_line ();
3531 return;
3532 }
3533
3534 unwind.personality_index = exp.X_add_number;
3535
3536 demand_empty_rest_of_line ();
3537 }
3538
3539
3540 /* Parse a personality directive. */
3541
3542 static void
3543 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3544 {
3545 char *name, *p, c;
3546
3547 if (!unwind.proc_start)
3548 as_bad (MISSING_FNSTART);
3549
3550 if (unwind.personality_routine || unwind.personality_index != -1)
3551 as_bad (_("duplicate .personality directive"));
3552
3553 name = input_line_pointer;
3554 c = get_symbol_end ();
3555 p = input_line_pointer;
3556 unwind.personality_routine = symbol_find_or_make (name);
3557 *p = c;
3558 demand_empty_rest_of_line ();
3559 }
3560
3561
3562 /* Parse a directive saving core registers. */
3563
3564 static void
3565 s_arm_unwind_save_core (void)
3566 {
3567 valueT op;
3568 long range;
3569 int n;
3570
3571 range = parse_reg_list (&input_line_pointer);
3572 if (range == FAIL)
3573 {
3574 as_bad (_("expected register list"));
3575 ignore_rest_of_line ();
3576 return;
3577 }
3578
3579 demand_empty_rest_of_line ();
3580
3581 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3582 into .unwind_save {..., sp...}. We aren't bothered about the value of
3583 ip because it is clobbered by calls. */
3584 if (unwind.sp_restored && unwind.fp_reg == 12
3585 && (range & 0x3000) == 0x1000)
3586 {
3587 unwind.opcode_count--;
3588 unwind.sp_restored = 0;
3589 range = (range | 0x2000) & ~0x1000;
3590 unwind.pending_offset = 0;
3591 }
3592
3593 /* Pop r4-r15. */
3594 if (range & 0xfff0)
3595 {
3596 /* See if we can use the short opcodes. These pop a block of up to 8
3597 registers starting with r4, plus maybe r14. */
3598 for (n = 0; n < 8; n++)
3599 {
3600 /* Break at the first non-saved register. */
3601 if ((range & (1 << (n + 4))) == 0)
3602 break;
3603 }
3604 /* See if there are any other bits set. */
3605 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3606 {
3607 /* Use the long form. */
3608 op = 0x8000 | ((range >> 4) & 0xfff);
3609 add_unwind_opcode (op, 2);
3610 }
3611 else
3612 {
3613 /* Use the short form. */
3614 if (range & 0x4000)
3615 op = 0xa8; /* Pop r14. */
3616 else
3617 op = 0xa0; /* Do not pop r14. */
3618 op |= (n - 1);
3619 add_unwind_opcode (op, 1);
3620 }
3621 }
3622
3623 /* Pop r0-r3. */
3624 if (range & 0xf)
3625 {
3626 op = 0xb100 | (range & 0xf);
3627 add_unwind_opcode (op, 2);
3628 }
3629
3630 /* Record the number of bytes pushed. */
3631 for (n = 0; n < 16; n++)
3632 {
3633 if (range & (1 << n))
3634 unwind.frame_size += 4;
3635 }
3636 }
3637
3638
3639 /* Parse a directive saving FPA registers. */
3640
3641 static void
3642 s_arm_unwind_save_fpa (int reg)
3643 {
3644 expressionS exp;
3645 int num_regs;
3646 valueT op;
3647
3648 /* Get Number of registers to transfer. */
3649 if (skip_past_comma (&input_line_pointer) != FAIL)
3650 expression (&exp);
3651 else
3652 exp.X_op = O_illegal;
3653
3654 if (exp.X_op != O_constant)
3655 {
3656 as_bad (_("expected , <constant>"));
3657 ignore_rest_of_line ();
3658 return;
3659 }
3660
3661 num_regs = exp.X_add_number;
3662
3663 if (num_regs < 1 || num_regs > 4)
3664 {
3665 as_bad (_("number of registers must be in the range [1:4]"));
3666 ignore_rest_of_line ();
3667 return;
3668 }
3669
3670 demand_empty_rest_of_line ();
3671
3672 if (reg == 4)
3673 {
3674 /* Short form. */
3675 op = 0xb4 | (num_regs - 1);
3676 add_unwind_opcode (op, 1);
3677 }
3678 else
3679 {
3680 /* Long form. */
3681 op = 0xc800 | (reg << 4) | (num_regs - 1);
3682 add_unwind_opcode (op, 2);
3683 }
3684 unwind.frame_size += num_regs * 12;
3685 }
3686
3687
3688 /* Parse a directive saving VFP registers for ARMv6 and above. */
3689
3690 static void
3691 s_arm_unwind_save_vfp_armv6 (void)
3692 {
3693 int count;
3694 unsigned int start;
3695 valueT op;
3696 int num_vfpv3_regs = 0;
3697 int num_regs_below_16;
3698
3699 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3700 if (count == FAIL)
3701 {
3702 as_bad (_("expected register list"));
3703 ignore_rest_of_line ();
3704 return;
3705 }
3706
3707 demand_empty_rest_of_line ();
3708
3709 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3710 than FSTMX/FLDMX-style ones). */
3711
3712 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3713 if (start >= 16)
3714 num_vfpv3_regs = count;
3715 else if (start + count > 16)
3716 num_vfpv3_regs = start + count - 16;
3717
3718 if (num_vfpv3_regs > 0)
3719 {
3720 int start_offset = start > 16 ? start - 16 : 0;
3721 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3722 add_unwind_opcode (op, 2);
3723 }
3724
3725 /* Generate opcode for registers numbered in the range 0 .. 15. */
3726 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3727 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
3728 if (num_regs_below_16 > 0)
3729 {
3730 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3731 add_unwind_opcode (op, 2);
3732 }
3733
3734 unwind.frame_size += count * 8;
3735 }
3736
3737
3738 /* Parse a directive saving VFP registers for pre-ARMv6. */
3739
3740 static void
3741 s_arm_unwind_save_vfp (void)
3742 {
3743 int count;
3744 unsigned int reg;
3745 valueT op;
3746
3747 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
3748 if (count == FAIL)
3749 {
3750 as_bad (_("expected register list"));
3751 ignore_rest_of_line ();
3752 return;
3753 }
3754
3755 demand_empty_rest_of_line ();
3756
3757 if (reg == 8)
3758 {
3759 /* Short form. */
3760 op = 0xb8 | (count - 1);
3761 add_unwind_opcode (op, 1);
3762 }
3763 else
3764 {
3765 /* Long form. */
3766 op = 0xb300 | (reg << 4) | (count - 1);
3767 add_unwind_opcode (op, 2);
3768 }
3769 unwind.frame_size += count * 8 + 4;
3770 }
3771
3772
3773 /* Parse a directive saving iWMMXt data registers. */
3774
3775 static void
3776 s_arm_unwind_save_mmxwr (void)
3777 {
3778 int reg;
3779 int hi_reg;
3780 int i;
3781 unsigned mask = 0;
3782 valueT op;
3783
3784 if (*input_line_pointer == '{')
3785 input_line_pointer++;
3786
3787 do
3788 {
3789 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3790
3791 if (reg == FAIL)
3792 {
3793 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3794 goto error;
3795 }
3796
3797 if (mask >> reg)
3798 as_tsktsk (_("register list not in ascending order"));
3799 mask |= 1 << reg;
3800
3801 if (*input_line_pointer == '-')
3802 {
3803 input_line_pointer++;
3804 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3805 if (hi_reg == FAIL)
3806 {
3807 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3808 goto error;
3809 }
3810 else if (reg >= hi_reg)
3811 {
3812 as_bad (_("bad register range"));
3813 goto error;
3814 }
3815 for (; reg < hi_reg; reg++)
3816 mask |= 1 << reg;
3817 }
3818 }
3819 while (skip_past_comma (&input_line_pointer) != FAIL);
3820
3821 if (*input_line_pointer == '}')
3822 input_line_pointer++;
3823
3824 demand_empty_rest_of_line ();
3825
3826 /* Generate any deferred opcodes because we're going to be looking at
3827 the list. */
3828 flush_pending_unwind ();
3829
3830 for (i = 0; i < 16; i++)
3831 {
3832 if (mask & (1 << i))
3833 unwind.frame_size += 8;
3834 }
3835
3836 /* Attempt to combine with a previous opcode. We do this because gcc
3837 likes to output separate unwind directives for a single block of
3838 registers. */
3839 if (unwind.opcode_count > 0)
3840 {
3841 i = unwind.opcodes[unwind.opcode_count - 1];
3842 if ((i & 0xf8) == 0xc0)
3843 {
3844 i &= 7;
3845 /* Only merge if the blocks are contiguous. */
3846 if (i < 6)
3847 {
3848 if ((mask & 0xfe00) == (1 << 9))
3849 {
3850 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3851 unwind.opcode_count--;
3852 }
3853 }
3854 else if (i == 6 && unwind.opcode_count >= 2)
3855 {
3856 i = unwind.opcodes[unwind.opcode_count - 2];
3857 reg = i >> 4;
3858 i &= 0xf;
3859
3860 op = 0xffff << (reg - 1);
3861 if (reg > 0
3862 && ((mask & op) == (1u << (reg - 1))))
3863 {
3864 op = (1 << (reg + i + 1)) - 1;
3865 op &= ~((1 << reg) - 1);
3866 mask |= op;
3867 unwind.opcode_count -= 2;
3868 }
3869 }
3870 }
3871 }
3872
3873 hi_reg = 15;
3874 /* We want to generate opcodes in the order the registers have been
3875 saved, ie. descending order. */
3876 for (reg = 15; reg >= -1; reg--)
3877 {
3878 /* Save registers in blocks. */
3879 if (reg < 0
3880 || !(mask & (1 << reg)))
3881 {
3882 /* We found an unsaved reg. Generate opcodes to save the
3883 preceding block. */
3884 if (reg != hi_reg)
3885 {
3886 if (reg == 9)
3887 {
3888 /* Short form. */
3889 op = 0xc0 | (hi_reg - 10);
3890 add_unwind_opcode (op, 1);
3891 }
3892 else
3893 {
3894 /* Long form. */
3895 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3896 add_unwind_opcode (op, 2);
3897 }
3898 }
3899 hi_reg = reg - 1;
3900 }
3901 }
3902
3903 return;
3904 error:
3905 ignore_rest_of_line ();
3906 }
3907
3908 static void
3909 s_arm_unwind_save_mmxwcg (void)
3910 {
3911 int reg;
3912 int hi_reg;
3913 unsigned mask = 0;
3914 valueT op;
3915
3916 if (*input_line_pointer == '{')
3917 input_line_pointer++;
3918
3919 do
3920 {
3921 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3922
3923 if (reg == FAIL)
3924 {
3925 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
3926 goto error;
3927 }
3928
3929 reg -= 8;
3930 if (mask >> reg)
3931 as_tsktsk (_("register list not in ascending order"));
3932 mask |= 1 << reg;
3933
3934 if (*input_line_pointer == '-')
3935 {
3936 input_line_pointer++;
3937 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3938 if (hi_reg == FAIL)
3939 {
3940 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
3941 goto error;
3942 }
3943 else if (reg >= hi_reg)
3944 {
3945 as_bad (_("bad register range"));
3946 goto error;
3947 }
3948 for (; reg < hi_reg; reg++)
3949 mask |= 1 << reg;
3950 }
3951 }
3952 while (skip_past_comma (&input_line_pointer) != FAIL);
3953
3954 if (*input_line_pointer == '}')
3955 input_line_pointer++;
3956
3957 demand_empty_rest_of_line ();
3958
3959 /* Generate any deferred opcodes because we're going to be looking at
3960 the list. */
3961 flush_pending_unwind ();
3962
3963 for (reg = 0; reg < 16; reg++)
3964 {
3965 if (mask & (1 << reg))
3966 unwind.frame_size += 4;
3967 }
3968 op = 0xc700 | mask;
3969 add_unwind_opcode (op, 2);
3970 return;
3971 error:
3972 ignore_rest_of_line ();
3973 }
3974
3975
3976 /* Parse an unwind_save directive.
3977 If the argument is non-zero, this is a .vsave directive. */
3978
3979 static void
3980 s_arm_unwind_save (int arch_v6)
3981 {
3982 char *peek;
3983 struct reg_entry *reg;
3984 bfd_boolean had_brace = FALSE;
3985
3986 if (!unwind.proc_start)
3987 as_bad (MISSING_FNSTART);
3988
3989 /* Figure out what sort of save we have. */
3990 peek = input_line_pointer;
3991
3992 if (*peek == '{')
3993 {
3994 had_brace = TRUE;
3995 peek++;
3996 }
3997
3998 reg = arm_reg_parse_multi (&peek);
3999
4000 if (!reg)
4001 {
4002 as_bad (_("register expected"));
4003 ignore_rest_of_line ();
4004 return;
4005 }
4006
4007 switch (reg->type)
4008 {
4009 case REG_TYPE_FN:
4010 if (had_brace)
4011 {
4012 as_bad (_("FPA .unwind_save does not take a register list"));
4013 ignore_rest_of_line ();
4014 return;
4015 }
4016 input_line_pointer = peek;
4017 s_arm_unwind_save_fpa (reg->number);
4018 return;
4019
4020 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
4021 case REG_TYPE_VFD:
4022 if (arch_v6)
4023 s_arm_unwind_save_vfp_armv6 ();
4024 else
4025 s_arm_unwind_save_vfp ();
4026 return;
4027 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
4028 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
4029
4030 default:
4031 as_bad (_(".unwind_save does not support this kind of register"));
4032 ignore_rest_of_line ();
4033 }
4034 }
4035
4036
4037 /* Parse an unwind_movsp directive. */
4038
4039 static void
4040 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4041 {
4042 int reg;
4043 valueT op;
4044 int offset;
4045
4046 if (!unwind.proc_start)
4047 as_bad (MISSING_FNSTART);
4048
4049 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4050 if (reg == FAIL)
4051 {
4052 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
4053 ignore_rest_of_line ();
4054 return;
4055 }
4056
4057 /* Optional constant. */
4058 if (skip_past_comma (&input_line_pointer) != FAIL)
4059 {
4060 if (immediate_for_directive (&offset) == FAIL)
4061 return;
4062 }
4063 else
4064 offset = 0;
4065
4066 demand_empty_rest_of_line ();
4067
4068 if (reg == REG_SP || reg == REG_PC)
4069 {
4070 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
4071 return;
4072 }
4073
4074 if (unwind.fp_reg != REG_SP)
4075 as_bad (_("unexpected .unwind_movsp directive"));
4076
4077 /* Generate opcode to restore the value. */
4078 op = 0x90 | reg;
4079 add_unwind_opcode (op, 1);
4080
4081 /* Record the information for later. */
4082 unwind.fp_reg = reg;
4083 unwind.fp_offset = unwind.frame_size - offset;
4084 unwind.sp_restored = 1;
4085 }
4086
4087 /* Parse an unwind_pad directive. */
4088
4089 static void
4090 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
4091 {
4092 int offset;
4093
4094 if (!unwind.proc_start)
4095 as_bad (MISSING_FNSTART);
4096
4097 if (immediate_for_directive (&offset) == FAIL)
4098 return;
4099
4100 if (offset & 3)
4101 {
4102 as_bad (_("stack increment must be multiple of 4"));
4103 ignore_rest_of_line ();
4104 return;
4105 }
4106
4107 /* Don't generate any opcodes, just record the details for later. */
4108 unwind.frame_size += offset;
4109 unwind.pending_offset += offset;
4110
4111 demand_empty_rest_of_line ();
4112 }
4113
4114 /* Parse an unwind_setfp directive. */
4115
4116 static void
4117 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
4118 {
4119 int sp_reg;
4120 int fp_reg;
4121 int offset;
4122
4123 if (!unwind.proc_start)
4124 as_bad (MISSING_FNSTART);
4125
4126 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4127 if (skip_past_comma (&input_line_pointer) == FAIL)
4128 sp_reg = FAIL;
4129 else
4130 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4131
4132 if (fp_reg == FAIL || sp_reg == FAIL)
4133 {
4134 as_bad (_("expected <reg>, <reg>"));
4135 ignore_rest_of_line ();
4136 return;
4137 }
4138
4139 /* Optional constant. */
4140 if (skip_past_comma (&input_line_pointer) != FAIL)
4141 {
4142 if (immediate_for_directive (&offset) == FAIL)
4143 return;
4144 }
4145 else
4146 offset = 0;
4147
4148 demand_empty_rest_of_line ();
4149
4150 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
4151 {
4152 as_bad (_("register must be either sp or set by a previous"
4153 "unwind_movsp directive"));
4154 return;
4155 }
4156
4157 /* Don't generate any opcodes, just record the information for later. */
4158 unwind.fp_reg = fp_reg;
4159 unwind.fp_used = 1;
4160 if (sp_reg == REG_SP)
4161 unwind.fp_offset = unwind.frame_size - offset;
4162 else
4163 unwind.fp_offset -= offset;
4164 }
4165
4166 /* Parse an unwind_raw directive. */
4167
4168 static void
4169 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
4170 {
4171 expressionS exp;
4172 /* This is an arbitrary limit. */
4173 unsigned char op[16];
4174 int count;
4175
4176 if (!unwind.proc_start)
4177 as_bad (MISSING_FNSTART);
4178
4179 expression (&exp);
4180 if (exp.X_op == O_constant
4181 && skip_past_comma (&input_line_pointer) != FAIL)
4182 {
4183 unwind.frame_size += exp.X_add_number;
4184 expression (&exp);
4185 }
4186 else
4187 exp.X_op = O_illegal;
4188
4189 if (exp.X_op != O_constant)
4190 {
4191 as_bad (_("expected <offset>, <opcode>"));
4192 ignore_rest_of_line ();
4193 return;
4194 }
4195
4196 count = 0;
4197
4198 /* Parse the opcode. */
4199 for (;;)
4200 {
4201 if (count >= 16)
4202 {
4203 as_bad (_("unwind opcode too long"));
4204 ignore_rest_of_line ();
4205 }
4206 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
4207 {
4208 as_bad (_("invalid unwind opcode"));
4209 ignore_rest_of_line ();
4210 return;
4211 }
4212 op[count++] = exp.X_add_number;
4213
4214 /* Parse the next byte. */
4215 if (skip_past_comma (&input_line_pointer) == FAIL)
4216 break;
4217
4218 expression (&exp);
4219 }
4220
4221 /* Add the opcode bytes in reverse order. */
4222 while (count--)
4223 add_unwind_opcode (op[count], 1);
4224
4225 demand_empty_rest_of_line ();
4226 }
4227
4228
4229 /* Parse a .eabi_attribute directive. */
4230
4231 static void
4232 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4233 {
4234 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
4235
4236 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4237 attributes_set_explicitly[tag] = 1;
4238 }
4239 #endif /* OBJ_ELF */
4240
4241 static void s_arm_arch (int);
4242 static void s_arm_object_arch (int);
4243 static void s_arm_cpu (int);
4244 static void s_arm_fpu (int);
4245
4246 #ifdef TE_PE
4247
4248 static void
4249 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
4250 {
4251 expressionS exp;
4252
4253 do
4254 {
4255 expression (&exp);
4256 if (exp.X_op == O_symbol)
4257 exp.X_op = O_secrel;
4258
4259 emit_expr (&exp, 4);
4260 }
4261 while (*input_line_pointer++ == ',');
4262
4263 input_line_pointer--;
4264 demand_empty_rest_of_line ();
4265 }
4266 #endif /* TE_PE */
4267
4268 /* This table describes all the machine specific pseudo-ops the assembler
4269 has to support. The fields are:
4270 pseudo-op name without dot
4271 function to call to execute this pseudo-op
4272 Integer arg to pass to the function. */
4273
4274 const pseudo_typeS md_pseudo_table[] =
4275 {
4276 /* Never called because '.req' does not start a line. */
4277 { "req", s_req, 0 },
4278 /* Following two are likewise never called. */
4279 { "dn", s_dn, 0 },
4280 { "qn", s_qn, 0 },
4281 { "unreq", s_unreq, 0 },
4282 { "bss", s_bss, 0 },
4283 { "align", s_align, 0 },
4284 { "arm", s_arm, 0 },
4285 { "thumb", s_thumb, 0 },
4286 { "code", s_code, 0 },
4287 { "force_thumb", s_force_thumb, 0 },
4288 { "thumb_func", s_thumb_func, 0 },
4289 { "thumb_set", s_thumb_set, 0 },
4290 { "even", s_even, 0 },
4291 { "ltorg", s_ltorg, 0 },
4292 { "pool", s_ltorg, 0 },
4293 { "syntax", s_syntax, 0 },
4294 { "cpu", s_arm_cpu, 0 },
4295 { "arch", s_arm_arch, 0 },
4296 { "object_arch", s_arm_object_arch, 0 },
4297 { "fpu", s_arm_fpu, 0 },
4298 #ifdef OBJ_ELF
4299 { "word", s_arm_elf_cons, 4 },
4300 { "long", s_arm_elf_cons, 4 },
4301 { "inst.n", s_arm_elf_inst, 2 },
4302 { "inst.w", s_arm_elf_inst, 4 },
4303 { "inst", s_arm_elf_inst, 0 },
4304 { "rel31", s_arm_rel31, 0 },
4305 { "fnstart", s_arm_unwind_fnstart, 0 },
4306 { "fnend", s_arm_unwind_fnend, 0 },
4307 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4308 { "personality", s_arm_unwind_personality, 0 },
4309 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4310 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4311 { "save", s_arm_unwind_save, 0 },
4312 { "vsave", s_arm_unwind_save, 1 },
4313 { "movsp", s_arm_unwind_movsp, 0 },
4314 { "pad", s_arm_unwind_pad, 0 },
4315 { "setfp", s_arm_unwind_setfp, 0 },
4316 { "unwind_raw", s_arm_unwind_raw, 0 },
4317 { "eabi_attribute", s_arm_eabi_attribute, 0 },
4318 #else
4319 { "word", cons, 4},
4320
4321 /* These are used for dwarf. */
4322 {"2byte", cons, 2},
4323 {"4byte", cons, 4},
4324 {"8byte", cons, 8},
4325 /* These are used for dwarf2. */
4326 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4327 { "loc", dwarf2_directive_loc, 0 },
4328 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
4329 #endif
4330 { "extend", float_cons, 'x' },
4331 { "ldouble", float_cons, 'x' },
4332 { "packed", float_cons, 'p' },
4333 #ifdef TE_PE
4334 {"secrel32", pe_directive_secrel, 0},
4335 #endif
4336 { 0, 0, 0 }
4337 };
4338 \f
4339 /* Parser functions used exclusively in instruction operands. */
4340
4341 /* Generic immediate-value read function for use in insn parsing.
4342 STR points to the beginning of the immediate (the leading #);
4343 VAL receives the value; if the value is outside [MIN, MAX]
4344 issue an error. PREFIX_OPT is true if the immediate prefix is
4345 optional. */
4346
4347 static int
4348 parse_immediate (char **str, int *val, int min, int max,
4349 bfd_boolean prefix_opt)
4350 {
4351 expressionS exp;
4352 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4353 if (exp.X_op != O_constant)
4354 {
4355 inst.error = _("constant expression required");
4356 return FAIL;
4357 }
4358
4359 if (exp.X_add_number < min || exp.X_add_number > max)
4360 {
4361 inst.error = _("immediate value out of range");
4362 return FAIL;
4363 }
4364
4365 *val = exp.X_add_number;
4366 return SUCCESS;
4367 }
4368
4369 /* Less-generic immediate-value read function with the possibility of loading a
4370 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
4371 instructions. Puts the result directly in inst.operands[i]. */
4372
4373 static int
4374 parse_big_immediate (char **str, int i)
4375 {
4376 expressionS exp;
4377 char *ptr = *str;
4378
4379 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4380
4381 if (exp.X_op == O_constant)
4382 {
4383 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4384 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4385 O_constant. We have to be careful not to break compilation for
4386 32-bit X_add_number, though. */
4387 if ((exp.X_add_number & ~0xffffffffl) != 0)
4388 {
4389 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4390 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4391 inst.operands[i].regisimm = 1;
4392 }
4393 }
4394 else if (exp.X_op == O_big
4395 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4396 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4397 {
4398 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4399 /* Bignums have their least significant bits in
4400 generic_bignum[0]. Make sure we put 32 bits in imm and
4401 32 bits in reg, in a (hopefully) portable way. */
4402 gas_assert (parts != 0);
4403 inst.operands[i].imm = 0;
4404 for (j = 0; j < parts; j++, idx++)
4405 inst.operands[i].imm |= generic_bignum[idx]
4406 << (LITTLENUM_NUMBER_OF_BITS * j);
4407 inst.operands[i].reg = 0;
4408 for (j = 0; j < parts; j++, idx++)
4409 inst.operands[i].reg |= generic_bignum[idx]
4410 << (LITTLENUM_NUMBER_OF_BITS * j);
4411 inst.operands[i].regisimm = 1;
4412 }
4413 else
4414 return FAIL;
4415
4416 *str = ptr;
4417
4418 return SUCCESS;
4419 }
4420
4421 /* Returns the pseudo-register number of an FPA immediate constant,
4422 or FAIL if there isn't a valid constant here. */
4423
4424 static int
4425 parse_fpa_immediate (char ** str)
4426 {
4427 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4428 char * save_in;
4429 expressionS exp;
4430 int i;
4431 int j;
4432
4433 /* First try and match exact strings, this is to guarantee
4434 that some formats will work even for cross assembly. */
4435
4436 for (i = 0; fp_const[i]; i++)
4437 {
4438 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4439 {
4440 char *start = *str;
4441
4442 *str += strlen (fp_const[i]);
4443 if (is_end_of_line[(unsigned char) **str])
4444 return i + 8;
4445 *str = start;
4446 }
4447 }
4448
4449 /* Just because we didn't get a match doesn't mean that the constant
4450 isn't valid, just that it is in a format that we don't
4451 automatically recognize. Try parsing it with the standard
4452 expression routines. */
4453
4454 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
4455
4456 /* Look for a raw floating point number. */
4457 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4458 && is_end_of_line[(unsigned char) *save_in])
4459 {
4460 for (i = 0; i < NUM_FLOAT_VALS; i++)
4461 {
4462 for (j = 0; j < MAX_LITTLENUMS; j++)
4463 {
4464 if (words[j] != fp_values[i][j])
4465 break;
4466 }
4467
4468 if (j == MAX_LITTLENUMS)
4469 {
4470 *str = save_in;
4471 return i + 8;
4472 }
4473 }
4474 }
4475
4476 /* Try and parse a more complex expression, this will probably fail
4477 unless the code uses a floating point prefix (eg "0f"). */
4478 save_in = input_line_pointer;
4479 input_line_pointer = *str;
4480 if (expression (&exp) == absolute_section
4481 && exp.X_op == O_big
4482 && exp.X_add_number < 0)
4483 {
4484 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4485 Ditto for 15. */
4486 if (gen_to_words (words, 5, (long) 15) == 0)
4487 {
4488 for (i = 0; i < NUM_FLOAT_VALS; i++)
4489 {
4490 for (j = 0; j < MAX_LITTLENUMS; j++)
4491 {
4492 if (words[j] != fp_values[i][j])
4493 break;
4494 }
4495
4496 if (j == MAX_LITTLENUMS)
4497 {
4498 *str = input_line_pointer;
4499 input_line_pointer = save_in;
4500 return i + 8;
4501 }
4502 }
4503 }
4504 }
4505
4506 *str = input_line_pointer;
4507 input_line_pointer = save_in;
4508 inst.error = _("invalid FPA immediate expression");
4509 return FAIL;
4510 }
4511
4512 /* Returns 1 if a number has "quarter-precision" float format
4513 0baBbbbbbc defgh000 00000000 00000000. */
4514
4515 static int
4516 is_quarter_float (unsigned imm)
4517 {
4518 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4519 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4520 }
4521
4522 /* Parse an 8-bit "quarter-precision" floating point number of the form:
4523 0baBbbbbbc defgh000 00000000 00000000.
4524 The zero and minus-zero cases need special handling, since they can't be
4525 encoded in the "quarter-precision" float format, but can nonetheless be
4526 loaded as integer constants. */
4527
4528 static unsigned
4529 parse_qfloat_immediate (char **ccp, int *immed)
4530 {
4531 char *str = *ccp;
4532 char *fpnum;
4533 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4534 int found_fpchar = 0;
4535
4536 skip_past_char (&str, '#');
4537
4538 /* We must not accidentally parse an integer as a floating-point number. Make
4539 sure that the value we parse is not an integer by checking for special
4540 characters '.' or 'e'.
4541 FIXME: This is a horrible hack, but doing better is tricky because type
4542 information isn't in a very usable state at parse time. */
4543 fpnum = str;
4544 skip_whitespace (fpnum);
4545
4546 if (strncmp (fpnum, "0x", 2) == 0)
4547 return FAIL;
4548 else
4549 {
4550 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4551 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4552 {
4553 found_fpchar = 1;
4554 break;
4555 }
4556
4557 if (!found_fpchar)
4558 return FAIL;
4559 }
4560
4561 if ((str = atof_ieee (str, 's', words)) != NULL)
4562 {
4563 unsigned fpword = 0;
4564 int i;
4565
4566 /* Our FP word must be 32 bits (single-precision FP). */
4567 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4568 {
4569 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4570 fpword |= words[i];
4571 }
4572
4573 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
4574 *immed = fpword;
4575 else
4576 return FAIL;
4577
4578 *ccp = str;
4579
4580 return SUCCESS;
4581 }
4582
4583 return FAIL;
4584 }
4585
4586 /* Shift operands. */
4587 enum shift_kind
4588 {
4589 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4590 };
4591
4592 struct asm_shift_name
4593 {
4594 const char *name;
4595 enum shift_kind kind;
4596 };
4597
4598 /* Third argument to parse_shift. */
4599 enum parse_shift_mode
4600 {
4601 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4602 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4603 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4604 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4605 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4606 };
4607
4608 /* Parse a <shift> specifier on an ARM data processing instruction.
4609 This has three forms:
4610
4611 (LSL|LSR|ASL|ASR|ROR) Rs
4612 (LSL|LSR|ASL|ASR|ROR) #imm
4613 RRX
4614
4615 Note that ASL is assimilated to LSL in the instruction encoding, and
4616 RRX to ROR #0 (which cannot be written as such). */
4617
4618 static int
4619 parse_shift (char **str, int i, enum parse_shift_mode mode)
4620 {
4621 const struct asm_shift_name *shift_name;
4622 enum shift_kind shift;
4623 char *s = *str;
4624 char *p = s;
4625 int reg;
4626
4627 for (p = *str; ISALPHA (*p); p++)
4628 ;
4629
4630 if (p == *str)
4631 {
4632 inst.error = _("shift expression expected");
4633 return FAIL;
4634 }
4635
4636 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
4637 p - *str);
4638
4639 if (shift_name == NULL)
4640 {
4641 inst.error = _("shift expression expected");
4642 return FAIL;
4643 }
4644
4645 shift = shift_name->kind;
4646
4647 switch (mode)
4648 {
4649 case NO_SHIFT_RESTRICT:
4650 case SHIFT_IMMEDIATE: break;
4651
4652 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4653 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4654 {
4655 inst.error = _("'LSL' or 'ASR' required");
4656 return FAIL;
4657 }
4658 break;
4659
4660 case SHIFT_LSL_IMMEDIATE:
4661 if (shift != SHIFT_LSL)
4662 {
4663 inst.error = _("'LSL' required");
4664 return FAIL;
4665 }
4666 break;
4667
4668 case SHIFT_ASR_IMMEDIATE:
4669 if (shift != SHIFT_ASR)
4670 {
4671 inst.error = _("'ASR' required");
4672 return FAIL;
4673 }
4674 break;
4675
4676 default: abort ();
4677 }
4678
4679 if (shift != SHIFT_RRX)
4680 {
4681 /* Whitespace can appear here if the next thing is a bare digit. */
4682 skip_whitespace (p);
4683
4684 if (mode == NO_SHIFT_RESTRICT
4685 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4686 {
4687 inst.operands[i].imm = reg;
4688 inst.operands[i].immisreg = 1;
4689 }
4690 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4691 return FAIL;
4692 }
4693 inst.operands[i].shift_kind = shift;
4694 inst.operands[i].shifted = 1;
4695 *str = p;
4696 return SUCCESS;
4697 }
4698
4699 /* Parse a <shifter_operand> for an ARM data processing instruction:
4700
4701 #<immediate>
4702 #<immediate>, <rotate>
4703 <Rm>
4704 <Rm>, <shift>
4705
4706 where <shift> is defined by parse_shift above, and <rotate> is a
4707 multiple of 2 between 0 and 30. Validation of immediate operands
4708 is deferred to md_apply_fix. */
4709
4710 static int
4711 parse_shifter_operand (char **str, int i)
4712 {
4713 int value;
4714 expressionS exp;
4715
4716 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
4717 {
4718 inst.operands[i].reg = value;
4719 inst.operands[i].isreg = 1;
4720
4721 /* parse_shift will override this if appropriate */
4722 inst.reloc.exp.X_op = O_constant;
4723 inst.reloc.exp.X_add_number = 0;
4724
4725 if (skip_past_comma (str) == FAIL)
4726 return SUCCESS;
4727
4728 /* Shift operation on register. */
4729 return parse_shift (str, i, NO_SHIFT_RESTRICT);
4730 }
4731
4732 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4733 return FAIL;
4734
4735 if (skip_past_comma (str) == SUCCESS)
4736 {
4737 /* #x, y -- ie explicit rotation by Y. */
4738 if (my_get_expression (&exp, str, GE_NO_PREFIX))
4739 return FAIL;
4740
4741 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4742 {
4743 inst.error = _("constant expression expected");
4744 return FAIL;
4745 }
4746
4747 value = exp.X_add_number;
4748 if (value < 0 || value > 30 || value % 2 != 0)
4749 {
4750 inst.error = _("invalid rotation");
4751 return FAIL;
4752 }
4753 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4754 {
4755 inst.error = _("invalid constant");
4756 return FAIL;
4757 }
4758
4759 /* Convert to decoded value. md_apply_fix will put it back. */
4760 inst.reloc.exp.X_add_number
4761 = (((inst.reloc.exp.X_add_number << (32 - value))
4762 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
4763 }
4764
4765 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4766 inst.reloc.pc_rel = 0;
4767 return SUCCESS;
4768 }
4769
4770 /* Group relocation information. Each entry in the table contains the
4771 textual name of the relocation as may appear in assembler source
4772 and must end with a colon.
4773 Along with this textual name are the relocation codes to be used if
4774 the corresponding instruction is an ALU instruction (ADD or SUB only),
4775 an LDR, an LDRS, or an LDC. */
4776
4777 struct group_reloc_table_entry
4778 {
4779 const char *name;
4780 int alu_code;
4781 int ldr_code;
4782 int ldrs_code;
4783 int ldc_code;
4784 };
4785
4786 typedef enum
4787 {
4788 /* Varieties of non-ALU group relocation. */
4789
4790 GROUP_LDR,
4791 GROUP_LDRS,
4792 GROUP_LDC
4793 } group_reloc_type;
4794
4795 static struct group_reloc_table_entry group_reloc_table[] =
4796 { /* Program counter relative: */
4797 { "pc_g0_nc",
4798 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4799 0, /* LDR */
4800 0, /* LDRS */
4801 0 }, /* LDC */
4802 { "pc_g0",
4803 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4804 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4805 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4806 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4807 { "pc_g1_nc",
4808 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4809 0, /* LDR */
4810 0, /* LDRS */
4811 0 }, /* LDC */
4812 { "pc_g1",
4813 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4814 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4815 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4816 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4817 { "pc_g2",
4818 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4819 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4820 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4821 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4822 /* Section base relative */
4823 { "sb_g0_nc",
4824 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4825 0, /* LDR */
4826 0, /* LDRS */
4827 0 }, /* LDC */
4828 { "sb_g0",
4829 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4830 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4831 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4832 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4833 { "sb_g1_nc",
4834 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4835 0, /* LDR */
4836 0, /* LDRS */
4837 0 }, /* LDC */
4838 { "sb_g1",
4839 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4840 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4841 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4842 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4843 { "sb_g2",
4844 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4845 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4846 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4847 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4848
4849 /* Given the address of a pointer pointing to the textual name of a group
4850 relocation as may appear in assembler source, attempt to find its details
4851 in group_reloc_table. The pointer will be updated to the character after
4852 the trailing colon. On failure, FAIL will be returned; SUCCESS
4853 otherwise. On success, *entry will be updated to point at the relevant
4854 group_reloc_table entry. */
4855
4856 static int
4857 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4858 {
4859 unsigned int i;
4860 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4861 {
4862 int length = strlen (group_reloc_table[i].name);
4863
4864 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4865 && (*str)[length] == ':')
4866 {
4867 *out = &group_reloc_table[i];
4868 *str += (length + 1);
4869 return SUCCESS;
4870 }
4871 }
4872
4873 return FAIL;
4874 }
4875
4876 /* Parse a <shifter_operand> for an ARM data processing instruction
4877 (as for parse_shifter_operand) where group relocations are allowed:
4878
4879 #<immediate>
4880 #<immediate>, <rotate>
4881 #:<group_reloc>:<expression>
4882 <Rm>
4883 <Rm>, <shift>
4884
4885 where <group_reloc> is one of the strings defined in group_reloc_table.
4886 The hashes are optional.
4887
4888 Everything else is as for parse_shifter_operand. */
4889
4890 static parse_operand_result
4891 parse_shifter_operand_group_reloc (char **str, int i)
4892 {
4893 /* Determine if we have the sequence of characters #: or just :
4894 coming next. If we do, then we check for a group relocation.
4895 If we don't, punt the whole lot to parse_shifter_operand. */
4896
4897 if (((*str)[0] == '#' && (*str)[1] == ':')
4898 || (*str)[0] == ':')
4899 {
4900 struct group_reloc_table_entry *entry;
4901
4902 if ((*str)[0] == '#')
4903 (*str) += 2;
4904 else
4905 (*str)++;
4906
4907 /* Try to parse a group relocation. Anything else is an error. */
4908 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4909 {
4910 inst.error = _("unknown group relocation");
4911 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4912 }
4913
4914 /* We now have the group relocation table entry corresponding to
4915 the name in the assembler source. Next, we parse the expression. */
4916 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4917 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4918
4919 /* Record the relocation type (always the ALU variant here). */
4920 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
4921 gas_assert (inst.reloc.type != 0);
4922
4923 return PARSE_OPERAND_SUCCESS;
4924 }
4925 else
4926 return parse_shifter_operand (str, i) == SUCCESS
4927 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4928
4929 /* Never reached. */
4930 }
4931
4932 /* Parse all forms of an ARM address expression. Information is written
4933 to inst.operands[i] and/or inst.reloc.
4934
4935 Preindexed addressing (.preind=1):
4936
4937 [Rn, #offset] .reg=Rn .reloc.exp=offset
4938 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4939 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4940 .shift_kind=shift .reloc.exp=shift_imm
4941
4942 These three may have a trailing ! which causes .writeback to be set also.
4943
4944 Postindexed addressing (.postind=1, .writeback=1):
4945
4946 [Rn], #offset .reg=Rn .reloc.exp=offset
4947 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4948 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4949 .shift_kind=shift .reloc.exp=shift_imm
4950
4951 Unindexed addressing (.preind=0, .postind=0):
4952
4953 [Rn], {option} .reg=Rn .imm=option .immisreg=0
4954
4955 Other:
4956
4957 [Rn]{!} shorthand for [Rn,#0]{!}
4958 =immediate .isreg=0 .reloc.exp=immediate
4959 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
4960
4961 It is the caller's responsibility to check for addressing modes not
4962 supported by the instruction, and to set inst.reloc.type. */
4963
4964 static parse_operand_result
4965 parse_address_main (char **str, int i, int group_relocations,
4966 group_reloc_type group_type)
4967 {
4968 char *p = *str;
4969 int reg;
4970
4971 if (skip_past_char (&p, '[') == FAIL)
4972 {
4973 if (skip_past_char (&p, '=') == FAIL)
4974 {
4975 /* Bare address - translate to PC-relative offset. */
4976 inst.reloc.pc_rel = 1;
4977 inst.operands[i].reg = REG_PC;
4978 inst.operands[i].isreg = 1;
4979 inst.operands[i].preind = 1;
4980 }
4981 /* Otherwise a load-constant pseudo op, no special treatment needed here. */
4982
4983 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4984 return PARSE_OPERAND_FAIL;
4985
4986 *str = p;
4987 return PARSE_OPERAND_SUCCESS;
4988 }
4989
4990 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
4991 {
4992 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4993 return PARSE_OPERAND_FAIL;
4994 }
4995 inst.operands[i].reg = reg;
4996 inst.operands[i].isreg = 1;
4997
4998 if (skip_past_comma (&p) == SUCCESS)
4999 {
5000 inst.operands[i].preind = 1;
5001
5002 if (*p == '+') p++;
5003 else if (*p == '-') p++, inst.operands[i].negative = 1;
5004
5005 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5006 {
5007 inst.operands[i].imm = reg;
5008 inst.operands[i].immisreg = 1;
5009
5010 if (skip_past_comma (&p) == SUCCESS)
5011 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5012 return PARSE_OPERAND_FAIL;
5013 }
5014 else if (skip_past_char (&p, ':') == SUCCESS)
5015 {
5016 /* FIXME: '@' should be used here, but it's filtered out by generic
5017 code before we get to see it here. This may be subject to
5018 change. */
5019 expressionS exp;
5020 my_get_expression (&exp, &p, GE_NO_PREFIX);
5021 if (exp.X_op != O_constant)
5022 {
5023 inst.error = _("alignment must be constant");
5024 return PARSE_OPERAND_FAIL;
5025 }
5026 inst.operands[i].imm = exp.X_add_number << 8;
5027 inst.operands[i].immisalign = 1;
5028 /* Alignments are not pre-indexes. */
5029 inst.operands[i].preind = 0;
5030 }
5031 else
5032 {
5033 if (inst.operands[i].negative)
5034 {
5035 inst.operands[i].negative = 0;
5036 p--;
5037 }
5038
5039 if (group_relocations
5040 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
5041 {
5042 struct group_reloc_table_entry *entry;
5043
5044 /* Skip over the #: or : sequence. */
5045 if (*p == '#')
5046 p += 2;
5047 else
5048 p++;
5049
5050 /* Try to parse a group relocation. Anything else is an
5051 error. */
5052 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5053 {
5054 inst.error = _("unknown group relocation");
5055 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5056 }
5057
5058 /* We now have the group relocation table entry corresponding to
5059 the name in the assembler source. Next, we parse the
5060 expression. */
5061 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5062 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5063
5064 /* Record the relocation type. */
5065 switch (group_type)
5066 {
5067 case GROUP_LDR:
5068 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5069 break;
5070
5071 case GROUP_LDRS:
5072 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5073 break;
5074
5075 case GROUP_LDC:
5076 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5077 break;
5078
5079 default:
5080 gas_assert (0);
5081 }
5082
5083 if (inst.reloc.type == 0)
5084 {
5085 inst.error = _("this group relocation is not allowed on this instruction");
5086 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5087 }
5088 }
5089 else
5090 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5091 return PARSE_OPERAND_FAIL;
5092 }
5093 }
5094
5095 if (skip_past_char (&p, ']') == FAIL)
5096 {
5097 inst.error = _("']' expected");
5098 return PARSE_OPERAND_FAIL;
5099 }
5100
5101 if (skip_past_char (&p, '!') == SUCCESS)
5102 inst.operands[i].writeback = 1;
5103
5104 else if (skip_past_comma (&p) == SUCCESS)
5105 {
5106 if (skip_past_char (&p, '{') == SUCCESS)
5107 {
5108 /* [Rn], {expr} - unindexed, with option */
5109 if (parse_immediate (&p, &inst.operands[i].imm,
5110 0, 255, TRUE) == FAIL)
5111 return PARSE_OPERAND_FAIL;
5112
5113 if (skip_past_char (&p, '}') == FAIL)
5114 {
5115 inst.error = _("'}' expected at end of 'option' field");
5116 return PARSE_OPERAND_FAIL;
5117 }
5118 if (inst.operands[i].preind)
5119 {
5120 inst.error = _("cannot combine index with option");
5121 return PARSE_OPERAND_FAIL;
5122 }
5123 *str = p;
5124 return PARSE_OPERAND_SUCCESS;
5125 }
5126 else
5127 {
5128 inst.operands[i].postind = 1;
5129 inst.operands[i].writeback = 1;
5130
5131 if (inst.operands[i].preind)
5132 {
5133 inst.error = _("cannot combine pre- and post-indexing");
5134 return PARSE_OPERAND_FAIL;
5135 }
5136
5137 if (*p == '+') p++;
5138 else if (*p == '-') p++, inst.operands[i].negative = 1;
5139
5140 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5141 {
5142 /* We might be using the immediate for alignment already. If we
5143 are, OR the register number into the low-order bits. */
5144 if (inst.operands[i].immisalign)
5145 inst.operands[i].imm |= reg;
5146 else
5147 inst.operands[i].imm = reg;
5148 inst.operands[i].immisreg = 1;
5149
5150 if (skip_past_comma (&p) == SUCCESS)
5151 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5152 return PARSE_OPERAND_FAIL;
5153 }
5154 else
5155 {
5156 if (inst.operands[i].negative)
5157 {
5158 inst.operands[i].negative = 0;
5159 p--;
5160 }
5161 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5162 return PARSE_OPERAND_FAIL;
5163 }
5164 }
5165 }
5166
5167 /* If at this point neither .preind nor .postind is set, we have a
5168 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5169 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5170 {
5171 inst.operands[i].preind = 1;
5172 inst.reloc.exp.X_op = O_constant;
5173 inst.reloc.exp.X_add_number = 0;
5174 }
5175 *str = p;
5176 return PARSE_OPERAND_SUCCESS;
5177 }
5178
5179 static int
5180 parse_address (char **str, int i)
5181 {
5182 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
5183 ? SUCCESS : FAIL;
5184 }
5185
5186 static parse_operand_result
5187 parse_address_group_reloc (char **str, int i, group_reloc_type type)
5188 {
5189 return parse_address_main (str, i, 1, type);
5190 }
5191
5192 /* Parse an operand for a MOVW or MOVT instruction. */
5193 static int
5194 parse_half (char **str)
5195 {
5196 char * p;
5197
5198 p = *str;
5199 skip_past_char (&p, '#');
5200 if (strncasecmp (p, ":lower16:", 9) == 0)
5201 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5202 else if (strncasecmp (p, ":upper16:", 9) == 0)
5203 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5204
5205 if (inst.reloc.type != BFD_RELOC_UNUSED)
5206 {
5207 p += 9;
5208 skip_whitespace (p);
5209 }
5210
5211 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5212 return FAIL;
5213
5214 if (inst.reloc.type == BFD_RELOC_UNUSED)
5215 {
5216 if (inst.reloc.exp.X_op != O_constant)
5217 {
5218 inst.error = _("constant expression expected");
5219 return FAIL;
5220 }
5221 if (inst.reloc.exp.X_add_number < 0
5222 || inst.reloc.exp.X_add_number > 0xffff)
5223 {
5224 inst.error = _("immediate value out of range");
5225 return FAIL;
5226 }
5227 }
5228 *str = p;
5229 return SUCCESS;
5230 }
5231
5232 /* Miscellaneous. */
5233
5234 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5235 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5236 static int
5237 parse_psr (char **str)
5238 {
5239 char *p;
5240 unsigned long psr_field;
5241 const struct asm_psr *psr;
5242 char *start;
5243
5244 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5245 feature for ease of use and backwards compatibility. */
5246 p = *str;
5247 if (strncasecmp (p, "SPSR", 4) == 0)
5248 psr_field = SPSR_BIT;
5249 else if (strncasecmp (p, "CPSR", 4) == 0)
5250 psr_field = 0;
5251 else
5252 {
5253 start = p;
5254 do
5255 p++;
5256 while (ISALNUM (*p) || *p == '_');
5257
5258 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5259 p - start);
5260 if (!psr)
5261 return FAIL;
5262
5263 *str = p;
5264 return psr->field;
5265 }
5266
5267 p += 4;
5268 if (*p == '_')
5269 {
5270 /* A suffix follows. */
5271 p++;
5272 start = p;
5273
5274 do
5275 p++;
5276 while (ISALNUM (*p) || *p == '_');
5277
5278 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
5279 p - start);
5280 if (!psr)
5281 goto error;
5282
5283 psr_field |= psr->field;
5284 }
5285 else
5286 {
5287 if (ISALNUM (*p))
5288 goto error; /* Garbage after "[CS]PSR". */
5289
5290 psr_field |= (PSR_c | PSR_f);
5291 }
5292 *str = p;
5293 return psr_field;
5294
5295 error:
5296 inst.error = _("flag for {c}psr instruction expected");
5297 return FAIL;
5298 }
5299
5300 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5301 value suitable for splatting into the AIF field of the instruction. */
5302
5303 static int
5304 parse_cps_flags (char **str)
5305 {
5306 int val = 0;
5307 int saw_a_flag = 0;
5308 char *s = *str;
5309
5310 for (;;)
5311 switch (*s++)
5312 {
5313 case '\0': case ',':
5314 goto done;
5315
5316 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5317 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5318 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
5319
5320 default:
5321 inst.error = _("unrecognized CPS flag");
5322 return FAIL;
5323 }
5324
5325 done:
5326 if (saw_a_flag == 0)
5327 {
5328 inst.error = _("missing CPS flags");
5329 return FAIL;
5330 }
5331
5332 *str = s - 1;
5333 return val;
5334 }
5335
5336 /* Parse an endian specifier ("BE" or "LE", case insensitive);
5337 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
5338
5339 static int
5340 parse_endian_specifier (char **str)
5341 {
5342 int little_endian;
5343 char *s = *str;
5344
5345 if (strncasecmp (s, "BE", 2))
5346 little_endian = 0;
5347 else if (strncasecmp (s, "LE", 2))
5348 little_endian = 1;
5349 else
5350 {
5351 inst.error = _("valid endian specifiers are be or le");
5352 return FAIL;
5353 }
5354
5355 if (ISALNUM (s[2]) || s[2] == '_')
5356 {
5357 inst.error = _("valid endian specifiers are be or le");
5358 return FAIL;
5359 }
5360
5361 *str = s + 2;
5362 return little_endian;
5363 }
5364
5365 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5366 value suitable for poking into the rotate field of an sxt or sxta
5367 instruction, or FAIL on error. */
5368
5369 static int
5370 parse_ror (char **str)
5371 {
5372 int rot;
5373 char *s = *str;
5374
5375 if (strncasecmp (s, "ROR", 3) == 0)
5376 s += 3;
5377 else
5378 {
5379 inst.error = _("missing rotation field after comma");
5380 return FAIL;
5381 }
5382
5383 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5384 return FAIL;
5385
5386 switch (rot)
5387 {
5388 case 0: *str = s; return 0x0;
5389 case 8: *str = s; return 0x1;
5390 case 16: *str = s; return 0x2;
5391 case 24: *str = s; return 0x3;
5392
5393 default:
5394 inst.error = _("rotation can only be 0, 8, 16, or 24");
5395 return FAIL;
5396 }
5397 }
5398
5399 /* Parse a conditional code (from conds[] below). The value returned is in the
5400 range 0 .. 14, or FAIL. */
5401 static int
5402 parse_cond (char **str)
5403 {
5404 char *q;
5405 const struct asm_cond *c;
5406 int n;
5407 /* Condition codes are always 2 characters, so matching up to
5408 3 characters is sufficient. */
5409 char cond[3];
5410
5411 q = *str;
5412 n = 0;
5413 while (ISALPHA (*q) && n < 3)
5414 {
5415 cond[n] = TOLOWER (*q);
5416 q++;
5417 n++;
5418 }
5419
5420 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
5421 if (!c)
5422 {
5423 inst.error = _("condition required");
5424 return FAIL;
5425 }
5426
5427 *str = q;
5428 return c->value;
5429 }
5430
5431 /* Parse an option for a barrier instruction. Returns the encoding for the
5432 option, or FAIL. */
5433 static int
5434 parse_barrier (char **str)
5435 {
5436 char *p, *q;
5437 const struct asm_barrier_opt *o;
5438
5439 p = q = *str;
5440 while (ISALPHA (*q))
5441 q++;
5442
5443 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
5444 q - p);
5445 if (!o)
5446 return FAIL;
5447
5448 *str = q;
5449 return o->value;
5450 }
5451
5452 /* Parse the operands of a table branch instruction. Similar to a memory
5453 operand. */
5454 static int
5455 parse_tb (char **str)
5456 {
5457 char * p = *str;
5458 int reg;
5459
5460 if (skip_past_char (&p, '[') == FAIL)
5461 {
5462 inst.error = _("'[' expected");
5463 return FAIL;
5464 }
5465
5466 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5467 {
5468 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5469 return FAIL;
5470 }
5471 inst.operands[0].reg = reg;
5472
5473 if (skip_past_comma (&p) == FAIL)
5474 {
5475 inst.error = _("',' expected");
5476 return FAIL;
5477 }
5478
5479 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5480 {
5481 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5482 return FAIL;
5483 }
5484 inst.operands[0].imm = reg;
5485
5486 if (skip_past_comma (&p) == SUCCESS)
5487 {
5488 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5489 return FAIL;
5490 if (inst.reloc.exp.X_add_number != 1)
5491 {
5492 inst.error = _("invalid shift");
5493 return FAIL;
5494 }
5495 inst.operands[0].shifted = 1;
5496 }
5497
5498 if (skip_past_char (&p, ']') == FAIL)
5499 {
5500 inst.error = _("']' expected");
5501 return FAIL;
5502 }
5503 *str = p;
5504 return SUCCESS;
5505 }
5506
5507 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5508 information on the types the operands can take and how they are encoded.
5509 Up to four operands may be read; this function handles setting the
5510 ".present" field for each read operand itself.
5511 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5512 else returns FAIL. */
5513
5514 static int
5515 parse_neon_mov (char **str, int *which_operand)
5516 {
5517 int i = *which_operand, val;
5518 enum arm_reg_type rtype;
5519 char *ptr = *str;
5520 struct neon_type_el optype;
5521
5522 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5523 {
5524 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5525 inst.operands[i].reg = val;
5526 inst.operands[i].isscalar = 1;
5527 inst.operands[i].vectype = optype;
5528 inst.operands[i++].present = 1;
5529
5530 if (skip_past_comma (&ptr) == FAIL)
5531 goto wanted_comma;
5532
5533 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5534 goto wanted_arm;
5535
5536 inst.operands[i].reg = val;
5537 inst.operands[i].isreg = 1;
5538 inst.operands[i].present = 1;
5539 }
5540 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
5541 != FAIL)
5542 {
5543 /* Cases 0, 1, 2, 3, 5 (D only). */
5544 if (skip_past_comma (&ptr) == FAIL)
5545 goto wanted_comma;
5546
5547 inst.operands[i].reg = val;
5548 inst.operands[i].isreg = 1;
5549 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5550 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5551 inst.operands[i].isvec = 1;
5552 inst.operands[i].vectype = optype;
5553 inst.operands[i++].present = 1;
5554
5555 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5556 {
5557 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5558 Case 13: VMOV <Sd>, <Rm> */
5559 inst.operands[i].reg = val;
5560 inst.operands[i].isreg = 1;
5561 inst.operands[i].present = 1;
5562
5563 if (rtype == REG_TYPE_NQ)
5564 {
5565 first_error (_("can't use Neon quad register here"));
5566 return FAIL;
5567 }
5568 else if (rtype != REG_TYPE_VFS)
5569 {
5570 i++;
5571 if (skip_past_comma (&ptr) == FAIL)
5572 goto wanted_comma;
5573 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5574 goto wanted_arm;
5575 inst.operands[i].reg = val;
5576 inst.operands[i].isreg = 1;
5577 inst.operands[i].present = 1;
5578 }
5579 }
5580 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5581 &optype)) != FAIL)
5582 {
5583 /* Case 0: VMOV<c><q> <Qd>, <Qm>
5584 Case 1: VMOV<c><q> <Dd>, <Dm>
5585 Case 8: VMOV.F32 <Sd>, <Sm>
5586 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5587
5588 inst.operands[i].reg = val;
5589 inst.operands[i].isreg = 1;
5590 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5591 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5592 inst.operands[i].isvec = 1;
5593 inst.operands[i].vectype = optype;
5594 inst.operands[i].present = 1;
5595
5596 if (skip_past_comma (&ptr) == SUCCESS)
5597 {
5598 /* Case 15. */
5599 i++;
5600
5601 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5602 goto wanted_arm;
5603
5604 inst.operands[i].reg = val;
5605 inst.operands[i].isreg = 1;
5606 inst.operands[i++].present = 1;
5607
5608 if (skip_past_comma (&ptr) == FAIL)
5609 goto wanted_comma;
5610
5611 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5612 goto wanted_arm;
5613
5614 inst.operands[i].reg = val;
5615 inst.operands[i].isreg = 1;
5616 inst.operands[i++].present = 1;
5617 }
5618 }
5619 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5620 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5621 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5622 Case 10: VMOV.F32 <Sd>, #<imm>
5623 Case 11: VMOV.F64 <Dd>, #<imm> */
5624 inst.operands[i].immisfloat = 1;
5625 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5626 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5627 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5628 ;
5629 else
5630 {
5631 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5632 return FAIL;
5633 }
5634 }
5635 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5636 {
5637 /* Cases 6, 7. */
5638 inst.operands[i].reg = val;
5639 inst.operands[i].isreg = 1;
5640 inst.operands[i++].present = 1;
5641
5642 if (skip_past_comma (&ptr) == FAIL)
5643 goto wanted_comma;
5644
5645 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5646 {
5647 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5648 inst.operands[i].reg = val;
5649 inst.operands[i].isscalar = 1;
5650 inst.operands[i].present = 1;
5651 inst.operands[i].vectype = optype;
5652 }
5653 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5654 {
5655 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5656 inst.operands[i].reg = val;
5657 inst.operands[i].isreg = 1;
5658 inst.operands[i++].present = 1;
5659
5660 if (skip_past_comma (&ptr) == FAIL)
5661 goto wanted_comma;
5662
5663 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
5664 == FAIL)
5665 {
5666 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5667 return FAIL;
5668 }
5669
5670 inst.operands[i].reg = val;
5671 inst.operands[i].isreg = 1;
5672 inst.operands[i].isvec = 1;
5673 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5674 inst.operands[i].vectype = optype;
5675 inst.operands[i].present = 1;
5676
5677 if (rtype == REG_TYPE_VFS)
5678 {
5679 /* Case 14. */
5680 i++;
5681 if (skip_past_comma (&ptr) == FAIL)
5682 goto wanted_comma;
5683 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5684 &optype)) == FAIL)
5685 {
5686 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5687 return FAIL;
5688 }
5689 inst.operands[i].reg = val;
5690 inst.operands[i].isreg = 1;
5691 inst.operands[i].isvec = 1;
5692 inst.operands[i].issingle = 1;
5693 inst.operands[i].vectype = optype;
5694 inst.operands[i].present = 1;
5695 }
5696 }
5697 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5698 != FAIL)
5699 {
5700 /* Case 13. */
5701 inst.operands[i].reg = val;
5702 inst.operands[i].isreg = 1;
5703 inst.operands[i].isvec = 1;
5704 inst.operands[i].issingle = 1;
5705 inst.operands[i].vectype = optype;
5706 inst.operands[i++].present = 1;
5707 }
5708 }
5709 else
5710 {
5711 first_error (_("parse error"));
5712 return FAIL;
5713 }
5714
5715 /* Successfully parsed the operands. Update args. */
5716 *which_operand = i;
5717 *str = ptr;
5718 return SUCCESS;
5719
5720 wanted_comma:
5721 first_error (_("expected comma"));
5722 return FAIL;
5723
5724 wanted_arm:
5725 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5726 return FAIL;
5727 }
5728
5729 /* Matcher codes for parse_operands. */
5730 enum operand_parse_code
5731 {
5732 OP_stop, /* end of line */
5733
5734 OP_RR, /* ARM register */
5735 OP_RRnpc, /* ARM register, not r15 */
5736 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5737 OP_RRw, /* ARM register, not r15, optional trailing ! */
5738 OP_RCP, /* Coprocessor number */
5739 OP_RCN, /* Coprocessor register */
5740 OP_RF, /* FPA register */
5741 OP_RVS, /* VFP single precision register */
5742 OP_RVD, /* VFP double precision register (0..15) */
5743 OP_RND, /* Neon double precision register (0..31) */
5744 OP_RNQ, /* Neon quad precision register */
5745 OP_RVSD, /* VFP single or double precision register */
5746 OP_RNDQ, /* Neon double or quad precision register */
5747 OP_RNSDQ, /* Neon single, double or quad precision register */
5748 OP_RNSC, /* Neon scalar D[X] */
5749 OP_RVC, /* VFP control register */
5750 OP_RMF, /* Maverick F register */
5751 OP_RMD, /* Maverick D register */
5752 OP_RMFX, /* Maverick FX register */
5753 OP_RMDX, /* Maverick DX register */
5754 OP_RMAX, /* Maverick AX register */
5755 OP_RMDS, /* Maverick DSPSC register */
5756 OP_RIWR, /* iWMMXt wR register */
5757 OP_RIWC, /* iWMMXt wC register */
5758 OP_RIWG, /* iWMMXt wCG register */
5759 OP_RXA, /* XScale accumulator register */
5760
5761 OP_REGLST, /* ARM register list */
5762 OP_VRSLST, /* VFP single-precision register list */
5763 OP_VRDLST, /* VFP double-precision register list */
5764 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5765 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5766 OP_NSTRLST, /* Neon element/structure list */
5767
5768 OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */
5769 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
5770 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5771 OP_RR_RNSC, /* ARM reg or Neon scalar. */
5772 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5773 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5774 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5775 OP_VMOV, /* Neon VMOV operands. */
5776 OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */
5777 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
5778 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5779
5780 OP_I0, /* immediate zero */
5781 OP_I7, /* immediate value 0 .. 7 */
5782 OP_I15, /* 0 .. 15 */
5783 OP_I16, /* 1 .. 16 */
5784 OP_I16z, /* 0 .. 16 */
5785 OP_I31, /* 0 .. 31 */
5786 OP_I31w, /* 0 .. 31, optional trailing ! */
5787 OP_I32, /* 1 .. 32 */
5788 OP_I32z, /* 0 .. 32 */
5789 OP_I63, /* 0 .. 63 */
5790 OP_I63s, /* -64 .. 63 */
5791 OP_I64, /* 1 .. 64 */
5792 OP_I64z, /* 0 .. 64 */
5793 OP_I255, /* 0 .. 255 */
5794
5795 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5796 OP_I7b, /* 0 .. 7 */
5797 OP_I15b, /* 0 .. 15 */
5798 OP_I31b, /* 0 .. 31 */
5799
5800 OP_SH, /* shifter operand */
5801 OP_SHG, /* shifter operand with possible group relocation */
5802 OP_ADDR, /* Memory address expression (any mode) */
5803 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5804 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5805 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
5806 OP_EXP, /* arbitrary expression */
5807 OP_EXPi, /* same, with optional immediate prefix */
5808 OP_EXPr, /* same, with optional relocation suffix */
5809 OP_HALF, /* 0 .. 65535 or low/high reloc. */
5810
5811 OP_CPSF, /* CPS flags */
5812 OP_ENDI, /* Endianness specifier */
5813 OP_PSR, /* CPSR/SPSR mask for msr */
5814 OP_COND, /* conditional code */
5815 OP_TB, /* Table branch. */
5816
5817 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5818 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5819
5820 OP_RRnpc_I0, /* ARM register or literal 0 */
5821 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5822 OP_RR_EXi, /* ARM register or expression with imm prefix */
5823 OP_RF_IF, /* FPA register or immediate */
5824 OP_RIWR_RIWC, /* iWMMXt R or C reg */
5825 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
5826
5827 /* Optional operands. */
5828 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5829 OP_oI31b, /* 0 .. 31 */
5830 OP_oI32b, /* 1 .. 32 */
5831 OP_oIffffb, /* 0 .. 65535 */
5832 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5833
5834 OP_oRR, /* ARM register */
5835 OP_oRRnpc, /* ARM register, not the PC */
5836 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5837 OP_oRND, /* Optional Neon double precision register */
5838 OP_oRNQ, /* Optional Neon quad precision register */
5839 OP_oRNDQ, /* Optional Neon double or quad precision register */
5840 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
5841 OP_oSHll, /* LSL immediate */
5842 OP_oSHar, /* ASR immediate */
5843 OP_oSHllar, /* LSL or ASR immediate */
5844 OP_oROR, /* ROR 0/8/16/24 */
5845 OP_oBARRIER, /* Option argument for a barrier instruction. */
5846
5847 OP_FIRST_OPTIONAL = OP_oI7b
5848 };
5849
5850 /* Generic instruction operand parser. This does no encoding and no
5851 semantic validation; it merely squirrels values away in the inst
5852 structure. Returns SUCCESS or FAIL depending on whether the
5853 specified grammar matched. */
5854 static int
5855 parse_operands (char *str, const unsigned char *pattern)
5856 {
5857 unsigned const char *upat = pattern;
5858 char *backtrack_pos = 0;
5859 const char *backtrack_error = 0;
5860 int i, val, backtrack_index = 0;
5861 enum arm_reg_type rtype;
5862 parse_operand_result result;
5863
5864 #define po_char_or_fail(chr) \
5865 do \
5866 { \
5867 if (skip_past_char (&str, chr) == FAIL) \
5868 goto bad_args; \
5869 } \
5870 while (0)
5871
5872 #define po_reg_or_fail(regtype) \
5873 do \
5874 { \
5875 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5876 & inst.operands[i].vectype); \
5877 if (val == FAIL) \
5878 { \
5879 first_error (_(reg_expected_msgs[regtype])); \
5880 goto failure; \
5881 } \
5882 inst.operands[i].reg = val; \
5883 inst.operands[i].isreg = 1; \
5884 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5885 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5886 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5887 || rtype == REG_TYPE_VFD \
5888 || rtype == REG_TYPE_NQ); \
5889 } \
5890 while (0)
5891
5892 #define po_reg_or_goto(regtype, label) \
5893 do \
5894 { \
5895 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5896 & inst.operands[i].vectype); \
5897 if (val == FAIL) \
5898 goto label; \
5899 \
5900 inst.operands[i].reg = val; \
5901 inst.operands[i].isreg = 1; \
5902 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5903 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5904 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5905 || rtype == REG_TYPE_VFD \
5906 || rtype == REG_TYPE_NQ); \
5907 } \
5908 while (0)
5909
5910 #define po_imm_or_fail(min, max, popt) \
5911 do \
5912 { \
5913 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5914 goto failure; \
5915 inst.operands[i].imm = val; \
5916 } \
5917 while (0)
5918
5919 #define po_scalar_or_goto(elsz, label) \
5920 do \
5921 { \
5922 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
5923 if (val == FAIL) \
5924 goto label; \
5925 inst.operands[i].reg = val; \
5926 inst.operands[i].isscalar = 1; \
5927 } \
5928 while (0)
5929
5930 #define po_misc_or_fail(expr) \
5931 do \
5932 { \
5933 if (expr) \
5934 goto failure; \
5935 } \
5936 while (0)
5937
5938 #define po_misc_or_fail_no_backtrack(expr) \
5939 do \
5940 { \
5941 result = expr; \
5942 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
5943 backtrack_pos = 0; \
5944 if (result != PARSE_OPERAND_SUCCESS) \
5945 goto failure; \
5946 } \
5947 while (0)
5948
5949 skip_whitespace (str);
5950
5951 for (i = 0; upat[i] != OP_stop; i++)
5952 {
5953 if (upat[i] >= OP_FIRST_OPTIONAL)
5954 {
5955 /* Remember where we are in case we need to backtrack. */
5956 gas_assert (!backtrack_pos);
5957 backtrack_pos = str;
5958 backtrack_error = inst.error;
5959 backtrack_index = i;
5960 }
5961
5962 if (i > 0 && (i > 1 || inst.operands[0].present))
5963 po_char_or_fail (',');
5964
5965 switch (upat[i])
5966 {
5967 /* Registers */
5968 case OP_oRRnpc:
5969 case OP_RRnpc:
5970 case OP_oRR:
5971 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5972 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5973 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
5974 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
5975 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
5976 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5977 case OP_oRND:
5978 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
5979 case OP_RVC:
5980 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
5981 break;
5982 /* Also accept generic coprocessor regs for unknown registers. */
5983 coproc_reg:
5984 po_reg_or_fail (REG_TYPE_CN);
5985 break;
5986 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
5987 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
5988 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
5989 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
5990 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
5991 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
5992 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
5993 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
5994 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
5995 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5996 case OP_oRNQ:
5997 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
5998 case OP_oRNDQ:
5999 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
6000 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6001 case OP_oRNSDQ:
6002 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6003
6004 /* Neon scalar. Using an element size of 8 means that some invalid
6005 scalars are accepted here, so deal with those in later code. */
6006 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6007
6008 /* WARNING: We can expand to two operands here. This has the potential
6009 to totally confuse the backtracking mechanism! It will be OK at
6010 least as long as we don't try to use optional args as well,
6011 though. */
6012 case OP_NILO:
6013 {
6014 po_reg_or_goto (REG_TYPE_NDQ, try_imm);
6015 inst.operands[i].present = 1;
6016 i++;
6017 skip_past_comma (&str);
6018 po_reg_or_goto (REG_TYPE_NDQ, one_reg_only);
6019 break;
6020 one_reg_only:
6021 /* Optional register operand was omitted. Unfortunately, it's in
6022 operands[i-1] and we need it to be in inst.operands[i]. Fix that
6023 here (this is a bit grotty). */
6024 inst.operands[i] = inst.operands[i-1];
6025 inst.operands[i-1].present = 0;
6026 break;
6027 try_imm:
6028 /* There's a possibility of getting a 64-bit immediate here, so
6029 we need special handling. */
6030 if (parse_big_immediate (&str, i) == FAIL)
6031 {
6032 inst.error = _("immediate value is out of range");
6033 goto failure;
6034 }
6035 }
6036 break;
6037
6038 case OP_RNDQ_I0:
6039 {
6040 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6041 break;
6042 try_imm0:
6043 po_imm_or_fail (0, 0, TRUE);
6044 }
6045 break;
6046
6047 case OP_RVSD_I0:
6048 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6049 break;
6050
6051 case OP_RR_RNSC:
6052 {
6053 po_scalar_or_goto (8, try_rr);
6054 break;
6055 try_rr:
6056 po_reg_or_fail (REG_TYPE_RN);
6057 }
6058 break;
6059
6060 case OP_RNSDQ_RNSC:
6061 {
6062 po_scalar_or_goto (8, try_nsdq);
6063 break;
6064 try_nsdq:
6065 po_reg_or_fail (REG_TYPE_NSDQ);
6066 }
6067 break;
6068
6069 case OP_RNDQ_RNSC:
6070 {
6071 po_scalar_or_goto (8, try_ndq);
6072 break;
6073 try_ndq:
6074 po_reg_or_fail (REG_TYPE_NDQ);
6075 }
6076 break;
6077
6078 case OP_RND_RNSC:
6079 {
6080 po_scalar_or_goto (8, try_vfd);
6081 break;
6082 try_vfd:
6083 po_reg_or_fail (REG_TYPE_VFD);
6084 }
6085 break;
6086
6087 case OP_VMOV:
6088 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6089 not careful then bad things might happen. */
6090 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6091 break;
6092
6093 case OP_RNDQ_IMVNb:
6094 {
6095 po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm);
6096 break;
6097 try_mvnimm:
6098 /* There's a possibility of getting a 64-bit immediate here, so
6099 we need special handling. */
6100 if (parse_big_immediate (&str, i) == FAIL)
6101 {
6102 inst.error = _("immediate value is out of range");
6103 goto failure;
6104 }
6105 }
6106 break;
6107
6108 case OP_RNDQ_I63b:
6109 {
6110 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6111 break;
6112 try_shimm:
6113 po_imm_or_fail (0, 63, TRUE);
6114 }
6115 break;
6116
6117 case OP_RRnpcb:
6118 po_char_or_fail ('[');
6119 po_reg_or_fail (REG_TYPE_RN);
6120 po_char_or_fail (']');
6121 break;
6122
6123 case OP_RRw:
6124 case OP_oRRw:
6125 po_reg_or_fail (REG_TYPE_RN);
6126 if (skip_past_char (&str, '!') == SUCCESS)
6127 inst.operands[i].writeback = 1;
6128 break;
6129
6130 /* Immediates */
6131 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6132 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6133 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
6134 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
6135 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6136 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
6137 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
6138 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
6139 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6140 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6141 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
6142 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
6143
6144 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6145 case OP_oI7b:
6146 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6147 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6148 case OP_oI31b:
6149 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
6150 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6151 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6152
6153 /* Immediate variants */
6154 case OP_oI255c:
6155 po_char_or_fail ('{');
6156 po_imm_or_fail (0, 255, TRUE);
6157 po_char_or_fail ('}');
6158 break;
6159
6160 case OP_I31w:
6161 /* The expression parser chokes on a trailing !, so we have
6162 to find it first and zap it. */
6163 {
6164 char *s = str;
6165 while (*s && *s != ',')
6166 s++;
6167 if (s[-1] == '!')
6168 {
6169 s[-1] = '\0';
6170 inst.operands[i].writeback = 1;
6171 }
6172 po_imm_or_fail (0, 31, TRUE);
6173 if (str == s - 1)
6174 str = s;
6175 }
6176 break;
6177
6178 /* Expressions */
6179 case OP_EXPi: EXPi:
6180 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6181 GE_OPT_PREFIX));
6182 break;
6183
6184 case OP_EXP:
6185 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6186 GE_NO_PREFIX));
6187 break;
6188
6189 case OP_EXPr: EXPr:
6190 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6191 GE_NO_PREFIX));
6192 if (inst.reloc.exp.X_op == O_symbol)
6193 {
6194 val = parse_reloc (&str);
6195 if (val == -1)
6196 {
6197 inst.error = _("unrecognized relocation suffix");
6198 goto failure;
6199 }
6200 else if (val != BFD_RELOC_UNUSED)
6201 {
6202 inst.operands[i].imm = val;
6203 inst.operands[i].hasreloc = 1;
6204 }
6205 }
6206 break;
6207
6208 /* Operand for MOVW or MOVT. */
6209 case OP_HALF:
6210 po_misc_or_fail (parse_half (&str));
6211 break;
6212
6213 /* Register or expression. */
6214 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6215 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
6216
6217 /* Register or immediate. */
6218 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6219 I0: po_imm_or_fail (0, 0, FALSE); break;
6220
6221 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6222 IF:
6223 if (!is_immediate_prefix (*str))
6224 goto bad_args;
6225 str++;
6226 val = parse_fpa_immediate (&str);
6227 if (val == FAIL)
6228 goto failure;
6229 /* FPA immediates are encoded as registers 8-15.
6230 parse_fpa_immediate has already applied the offset. */
6231 inst.operands[i].reg = val;
6232 inst.operands[i].isreg = 1;
6233 break;
6234
6235 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6236 I32z: po_imm_or_fail (0, 32, FALSE); break;
6237
6238 /* Two kinds of register. */
6239 case OP_RIWR_RIWC:
6240 {
6241 struct reg_entry *rege = arm_reg_parse_multi (&str);
6242 if (!rege
6243 || (rege->type != REG_TYPE_MMXWR
6244 && rege->type != REG_TYPE_MMXWC
6245 && rege->type != REG_TYPE_MMXWCG))
6246 {
6247 inst.error = _("iWMMXt data or control register expected");
6248 goto failure;
6249 }
6250 inst.operands[i].reg = rege->number;
6251 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6252 }
6253 break;
6254
6255 case OP_RIWC_RIWG:
6256 {
6257 struct reg_entry *rege = arm_reg_parse_multi (&str);
6258 if (!rege
6259 || (rege->type != REG_TYPE_MMXWC
6260 && rege->type != REG_TYPE_MMXWCG))
6261 {
6262 inst.error = _("iWMMXt control register expected");
6263 goto failure;
6264 }
6265 inst.operands[i].reg = rege->number;
6266 inst.operands[i].isreg = 1;
6267 }
6268 break;
6269
6270 /* Misc */
6271 case OP_CPSF: val = parse_cps_flags (&str); break;
6272 case OP_ENDI: val = parse_endian_specifier (&str); break;
6273 case OP_oROR: val = parse_ror (&str); break;
6274 case OP_PSR: val = parse_psr (&str); break;
6275 case OP_COND: val = parse_cond (&str); break;
6276 case OP_oBARRIER:val = parse_barrier (&str); break;
6277
6278 case OP_RVC_PSR:
6279 po_reg_or_goto (REG_TYPE_VFC, try_psr);
6280 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
6281 break;
6282 try_psr:
6283 val = parse_psr (&str);
6284 break;
6285
6286 case OP_APSR_RR:
6287 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6288 break;
6289 try_apsr:
6290 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6291 instruction). */
6292 if (strncasecmp (str, "APSR_", 5) == 0)
6293 {
6294 unsigned found = 0;
6295 str += 5;
6296 while (found < 15)
6297 switch (*str++)
6298 {
6299 case 'c': found = (found & 1) ? 16 : found | 1; break;
6300 case 'n': found = (found & 2) ? 16 : found | 2; break;
6301 case 'z': found = (found & 4) ? 16 : found | 4; break;
6302 case 'v': found = (found & 8) ? 16 : found | 8; break;
6303 default: found = 16;
6304 }
6305 if (found != 15)
6306 goto failure;
6307 inst.operands[i].isvec = 1;
6308 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6309 inst.operands[i].reg = REG_PC;
6310 }
6311 else
6312 goto failure;
6313 break;
6314
6315 case OP_TB:
6316 po_misc_or_fail (parse_tb (&str));
6317 break;
6318
6319 /* Register lists. */
6320 case OP_REGLST:
6321 val = parse_reg_list (&str);
6322 if (*str == '^')
6323 {
6324 inst.operands[1].writeback = 1;
6325 str++;
6326 }
6327 break;
6328
6329 case OP_VRSLST:
6330 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
6331 break;
6332
6333 case OP_VRDLST:
6334 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
6335 break;
6336
6337 case OP_VRSDLST:
6338 /* Allow Q registers too. */
6339 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6340 REGLIST_NEON_D);
6341 if (val == FAIL)
6342 {
6343 inst.error = NULL;
6344 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6345 REGLIST_VFP_S);
6346 inst.operands[i].issingle = 1;
6347 }
6348 break;
6349
6350 case OP_NRDLST:
6351 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6352 REGLIST_NEON_D);
6353 break;
6354
6355 case OP_NSTRLST:
6356 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6357 &inst.operands[i].vectype);
6358 break;
6359
6360 /* Addressing modes */
6361 case OP_ADDR:
6362 po_misc_or_fail (parse_address (&str, i));
6363 break;
6364
6365 case OP_ADDRGLDR:
6366 po_misc_or_fail_no_backtrack (
6367 parse_address_group_reloc (&str, i, GROUP_LDR));
6368 break;
6369
6370 case OP_ADDRGLDRS:
6371 po_misc_or_fail_no_backtrack (
6372 parse_address_group_reloc (&str, i, GROUP_LDRS));
6373 break;
6374
6375 case OP_ADDRGLDC:
6376 po_misc_or_fail_no_backtrack (
6377 parse_address_group_reloc (&str, i, GROUP_LDC));
6378 break;
6379
6380 case OP_SH:
6381 po_misc_or_fail (parse_shifter_operand (&str, i));
6382 break;
6383
6384 case OP_SHG:
6385 po_misc_or_fail_no_backtrack (
6386 parse_shifter_operand_group_reloc (&str, i));
6387 break;
6388
6389 case OP_oSHll:
6390 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6391 break;
6392
6393 case OP_oSHar:
6394 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6395 break;
6396
6397 case OP_oSHllar:
6398 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6399 break;
6400
6401 default:
6402 as_fatal (_("unhandled operand code %d"), upat[i]);
6403 }
6404
6405 /* Various value-based sanity checks and shared operations. We
6406 do not signal immediate failures for the register constraints;
6407 this allows a syntax error to take precedence. */
6408 switch (upat[i])
6409 {
6410 case OP_oRRnpc:
6411 case OP_RRnpc:
6412 case OP_RRnpcb:
6413 case OP_RRw:
6414 case OP_oRRw:
6415 case OP_RRnpc_I0:
6416 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6417 inst.error = BAD_PC;
6418 break;
6419
6420 case OP_CPSF:
6421 case OP_ENDI:
6422 case OP_oROR:
6423 case OP_PSR:
6424 case OP_RVC_PSR:
6425 case OP_COND:
6426 case OP_oBARRIER:
6427 case OP_REGLST:
6428 case OP_VRSLST:
6429 case OP_VRDLST:
6430 case OP_VRSDLST:
6431 case OP_NRDLST:
6432 case OP_NSTRLST:
6433 if (val == FAIL)
6434 goto failure;
6435 inst.operands[i].imm = val;
6436 break;
6437
6438 default:
6439 break;
6440 }
6441
6442 /* If we get here, this operand was successfully parsed. */
6443 inst.operands[i].present = 1;
6444 continue;
6445
6446 bad_args:
6447 inst.error = BAD_ARGS;
6448
6449 failure:
6450 if (!backtrack_pos)
6451 {
6452 /* The parse routine should already have set inst.error, but set a
6453 default here just in case. */
6454 if (!inst.error)
6455 inst.error = _("syntax error");
6456 return FAIL;
6457 }
6458
6459 /* Do not backtrack over a trailing optional argument that
6460 absorbed some text. We will only fail again, with the
6461 'garbage following instruction' error message, which is
6462 probably less helpful than the current one. */
6463 if (backtrack_index == i && backtrack_pos != str
6464 && upat[i+1] == OP_stop)
6465 {
6466 if (!inst.error)
6467 inst.error = _("syntax error");
6468 return FAIL;
6469 }
6470
6471 /* Try again, skipping the optional argument at backtrack_pos. */
6472 str = backtrack_pos;
6473 inst.error = backtrack_error;
6474 inst.operands[backtrack_index].present = 0;
6475 i = backtrack_index;
6476 backtrack_pos = 0;
6477 }
6478
6479 /* Check that we have parsed all the arguments. */
6480 if (*str != '\0' && !inst.error)
6481 inst.error = _("garbage following instruction");
6482
6483 return inst.error ? FAIL : SUCCESS;
6484 }
6485
6486 #undef po_char_or_fail
6487 #undef po_reg_or_fail
6488 #undef po_reg_or_goto
6489 #undef po_imm_or_fail
6490 #undef po_scalar_or_fail
6491
6492 /* Shorthand macro for instruction encoding functions issuing errors. */
6493 #define constraint(expr, err) \
6494 do \
6495 { \
6496 if (expr) \
6497 { \
6498 inst.error = err; \
6499 return; \
6500 } \
6501 } \
6502 while (0)
6503
6504 /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6505 instructions are unpredictable if these registers are used. This
6506 is the BadReg predicate in ARM's Thumb-2 documentation. */
6507 #define reject_bad_reg(reg) \
6508 do \
6509 if (reg == REG_SP || reg == REG_PC) \
6510 { \
6511 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6512 return; \
6513 } \
6514 while (0)
6515
6516 /* If REG is R13 (the stack pointer), warn that its use is
6517 deprecated. */
6518 #define warn_deprecated_sp(reg) \
6519 do \
6520 if (warn_on_deprecated && reg == REG_SP) \
6521 as_warn (_("use of r13 is deprecated")); \
6522 while (0)
6523
6524 /* Functions for operand encoding. ARM, then Thumb. */
6525
6526 #define rotate_left(v, n) (v << n | v >> (32 - n))
6527
6528 /* If VAL can be encoded in the immediate field of an ARM instruction,
6529 return the encoded form. Otherwise, return FAIL. */
6530
6531 static unsigned int
6532 encode_arm_immediate (unsigned int val)
6533 {
6534 unsigned int a, i;
6535
6536 for (i = 0; i < 32; i += 2)
6537 if ((a = rotate_left (val, i)) <= 0xff)
6538 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6539
6540 return FAIL;
6541 }
6542
6543 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6544 return the encoded form. Otherwise, return FAIL. */
6545 static unsigned int
6546 encode_thumb32_immediate (unsigned int val)
6547 {
6548 unsigned int a, i;
6549
6550 if (val <= 0xff)
6551 return val;
6552
6553 for (i = 1; i <= 24; i++)
6554 {
6555 a = val >> i;
6556 if ((val & ~(0xff << i)) == 0)
6557 return ((val >> i) & 0x7f) | ((32 - i) << 7);
6558 }
6559
6560 a = val & 0xff;
6561 if (val == ((a << 16) | a))
6562 return 0x100 | a;
6563 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6564 return 0x300 | a;
6565
6566 a = val & 0xff00;
6567 if (val == ((a << 16) | a))
6568 return 0x200 | (a >> 8);
6569
6570 return FAIL;
6571 }
6572 /* Encode a VFP SP or DP register number into inst.instruction. */
6573
6574 static void
6575 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6576 {
6577 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6578 && reg > 15)
6579 {
6580 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
6581 {
6582 if (thumb_mode)
6583 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
6584 fpu_vfp_ext_d32);
6585 else
6586 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
6587 fpu_vfp_ext_d32);
6588 }
6589 else
6590 {
6591 first_error (_("D register out of range for selected VFP version"));
6592 return;
6593 }
6594 }
6595
6596 switch (pos)
6597 {
6598 case VFP_REG_Sd:
6599 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6600 break;
6601
6602 case VFP_REG_Sn:
6603 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6604 break;
6605
6606 case VFP_REG_Sm:
6607 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6608 break;
6609
6610 case VFP_REG_Dd:
6611 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6612 break;
6613
6614 case VFP_REG_Dn:
6615 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6616 break;
6617
6618 case VFP_REG_Dm:
6619 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6620 break;
6621
6622 default:
6623 abort ();
6624 }
6625 }
6626
6627 /* Encode a <shift> in an ARM-format instruction. The immediate,
6628 if any, is handled by md_apply_fix. */
6629 static void
6630 encode_arm_shift (int i)
6631 {
6632 if (inst.operands[i].shift_kind == SHIFT_RRX)
6633 inst.instruction |= SHIFT_ROR << 5;
6634 else
6635 {
6636 inst.instruction |= inst.operands[i].shift_kind << 5;
6637 if (inst.operands[i].immisreg)
6638 {
6639 inst.instruction |= SHIFT_BY_REG;
6640 inst.instruction |= inst.operands[i].imm << 8;
6641 }
6642 else
6643 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6644 }
6645 }
6646
6647 static void
6648 encode_arm_shifter_operand (int i)
6649 {
6650 if (inst.operands[i].isreg)
6651 {
6652 inst.instruction |= inst.operands[i].reg;
6653 encode_arm_shift (i);
6654 }
6655 else
6656 inst.instruction |= INST_IMMEDIATE;
6657 }
6658
6659 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
6660 static void
6661 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
6662 {
6663 gas_assert (inst.operands[i].isreg);
6664 inst.instruction |= inst.operands[i].reg << 16;
6665
6666 if (inst.operands[i].preind)
6667 {
6668 if (is_t)
6669 {
6670 inst.error = _("instruction does not accept preindexed addressing");
6671 return;
6672 }
6673 inst.instruction |= PRE_INDEX;
6674 if (inst.operands[i].writeback)
6675 inst.instruction |= WRITE_BACK;
6676
6677 }
6678 else if (inst.operands[i].postind)
6679 {
6680 gas_assert (inst.operands[i].writeback);
6681 if (is_t)
6682 inst.instruction |= WRITE_BACK;
6683 }
6684 else /* unindexed - only for coprocessor */
6685 {
6686 inst.error = _("instruction does not accept unindexed addressing");
6687 return;
6688 }
6689
6690 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6691 && (((inst.instruction & 0x000f0000) >> 16)
6692 == ((inst.instruction & 0x0000f000) >> 12)))
6693 as_warn ((inst.instruction & LOAD_BIT)
6694 ? _("destination register same as write-back base")
6695 : _("source register same as write-back base"));
6696 }
6697
6698 /* inst.operands[i] was set up by parse_address. Encode it into an
6699 ARM-format mode 2 load or store instruction. If is_t is true,
6700 reject forms that cannot be used with a T instruction (i.e. not
6701 post-indexed). */
6702 static void
6703 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
6704 {
6705 encode_arm_addr_mode_common (i, is_t);
6706
6707 if (inst.operands[i].immisreg)
6708 {
6709 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6710 inst.instruction |= inst.operands[i].imm;
6711 if (!inst.operands[i].negative)
6712 inst.instruction |= INDEX_UP;
6713 if (inst.operands[i].shifted)
6714 {
6715 if (inst.operands[i].shift_kind == SHIFT_RRX)
6716 inst.instruction |= SHIFT_ROR << 5;
6717 else
6718 {
6719 inst.instruction |= inst.operands[i].shift_kind << 5;
6720 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6721 }
6722 }
6723 }
6724 else /* immediate offset in inst.reloc */
6725 {
6726 if (inst.reloc.type == BFD_RELOC_UNUSED)
6727 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
6728 }
6729 }
6730
6731 /* inst.operands[i] was set up by parse_address. Encode it into an
6732 ARM-format mode 3 load or store instruction. Reject forms that
6733 cannot be used with such instructions. If is_t is true, reject
6734 forms that cannot be used with a T instruction (i.e. not
6735 post-indexed). */
6736 static void
6737 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
6738 {
6739 if (inst.operands[i].immisreg && inst.operands[i].shifted)
6740 {
6741 inst.error = _("instruction does not accept scaled register index");
6742 return;
6743 }
6744
6745 encode_arm_addr_mode_common (i, is_t);
6746
6747 if (inst.operands[i].immisreg)
6748 {
6749 inst.instruction |= inst.operands[i].imm;
6750 if (!inst.operands[i].negative)
6751 inst.instruction |= INDEX_UP;
6752 }
6753 else /* immediate offset in inst.reloc */
6754 {
6755 inst.instruction |= HWOFFSET_IMM;
6756 if (inst.reloc.type == BFD_RELOC_UNUSED)
6757 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
6758 }
6759 }
6760
6761 /* inst.operands[i] was set up by parse_address. Encode it into an
6762 ARM-format instruction. Reject all forms which cannot be encoded
6763 into a coprocessor load/store instruction. If wb_ok is false,
6764 reject use of writeback; if unind_ok is false, reject use of
6765 unindexed addressing. If reloc_override is not 0, use it instead
6766 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6767 (in which case it is preserved). */
6768
6769 static int
6770 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
6771 {
6772 inst.instruction |= inst.operands[i].reg << 16;
6773
6774 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
6775
6776 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
6777 {
6778 gas_assert (!inst.operands[i].writeback);
6779 if (!unind_ok)
6780 {
6781 inst.error = _("instruction does not support unindexed addressing");
6782 return FAIL;
6783 }
6784 inst.instruction |= inst.operands[i].imm;
6785 inst.instruction |= INDEX_UP;
6786 return SUCCESS;
6787 }
6788
6789 if (inst.operands[i].preind)
6790 inst.instruction |= PRE_INDEX;
6791
6792 if (inst.operands[i].writeback)
6793 {
6794 if (inst.operands[i].reg == REG_PC)
6795 {
6796 inst.error = _("pc may not be used with write-back");
6797 return FAIL;
6798 }
6799 if (!wb_ok)
6800 {
6801 inst.error = _("instruction does not support writeback");
6802 return FAIL;
6803 }
6804 inst.instruction |= WRITE_BACK;
6805 }
6806
6807 if (reloc_override)
6808 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
6809 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6810 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6811 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6812 {
6813 if (thumb_mode)
6814 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6815 else
6816 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6817 }
6818
6819 return SUCCESS;
6820 }
6821
6822 /* inst.reloc.exp describes an "=expr" load pseudo-operation.
6823 Determine whether it can be performed with a move instruction; if
6824 it can, convert inst.instruction to that move instruction and
6825 return TRUE; if it can't, convert inst.instruction to a literal-pool
6826 load and return FALSE. If this is not a valid thing to do in the
6827 current context, set inst.error and return TRUE.
6828
6829 inst.operands[i] describes the destination register. */
6830
6831 static bfd_boolean
6832 move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6833 {
6834 unsigned long tbit;
6835
6836 if (thumb_p)
6837 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6838 else
6839 tbit = LOAD_BIT;
6840
6841 if ((inst.instruction & tbit) == 0)
6842 {
6843 inst.error = _("invalid pseudo operation");
6844 return TRUE;
6845 }
6846 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
6847 {
6848 inst.error = _("constant expression expected");
6849 return TRUE;
6850 }
6851 if (inst.reloc.exp.X_op == O_constant)
6852 {
6853 if (thumb_p)
6854 {
6855 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
6856 {
6857 /* This can be done with a mov(1) instruction. */
6858 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6859 inst.instruction |= inst.reloc.exp.X_add_number;
6860 return TRUE;
6861 }
6862 }
6863 else
6864 {
6865 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6866 if (value != FAIL)
6867 {
6868 /* This can be done with a mov instruction. */
6869 inst.instruction &= LITERAL_MASK;
6870 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6871 inst.instruction |= value & 0xfff;
6872 return TRUE;
6873 }
6874
6875 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6876 if (value != FAIL)
6877 {
6878 /* This can be done with a mvn instruction. */
6879 inst.instruction &= LITERAL_MASK;
6880 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6881 inst.instruction |= value & 0xfff;
6882 return TRUE;
6883 }
6884 }
6885 }
6886
6887 if (add_to_lit_pool () == FAIL)
6888 {
6889 inst.error = _("literal pool insertion failed");
6890 return TRUE;
6891 }
6892 inst.operands[1].reg = REG_PC;
6893 inst.operands[1].isreg = 1;
6894 inst.operands[1].preind = 1;
6895 inst.reloc.pc_rel = 1;
6896 inst.reloc.type = (thumb_p
6897 ? BFD_RELOC_ARM_THUMB_OFFSET
6898 : (mode_3
6899 ? BFD_RELOC_ARM_HWLITERAL
6900 : BFD_RELOC_ARM_LITERAL));
6901 return FALSE;
6902 }
6903
6904 /* Functions for instruction encoding, sorted by sub-architecture.
6905 First some generics; their names are taken from the conventional
6906 bit positions for register arguments in ARM format instructions. */
6907
6908 static void
6909 do_noargs (void)
6910 {
6911 }
6912
6913 static void
6914 do_rd (void)
6915 {
6916 inst.instruction |= inst.operands[0].reg << 12;
6917 }
6918
6919 static void
6920 do_rd_rm (void)
6921 {
6922 inst.instruction |= inst.operands[0].reg << 12;
6923 inst.instruction |= inst.operands[1].reg;
6924 }
6925
6926 static void
6927 do_rd_rn (void)
6928 {
6929 inst.instruction |= inst.operands[0].reg << 12;
6930 inst.instruction |= inst.operands[1].reg << 16;
6931 }
6932
6933 static void
6934 do_rn_rd (void)
6935 {
6936 inst.instruction |= inst.operands[0].reg << 16;
6937 inst.instruction |= inst.operands[1].reg << 12;
6938 }
6939
6940 static void
6941 do_rd_rm_rn (void)
6942 {
6943 unsigned Rn = inst.operands[2].reg;
6944 /* Enforce restrictions on SWP instruction. */
6945 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6946 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6947 _("Rn must not overlap other operands"));
6948 inst.instruction |= inst.operands[0].reg << 12;
6949 inst.instruction |= inst.operands[1].reg;
6950 inst.instruction |= Rn << 16;
6951 }
6952
6953 static void
6954 do_rd_rn_rm (void)
6955 {
6956 inst.instruction |= inst.operands[0].reg << 12;
6957 inst.instruction |= inst.operands[1].reg << 16;
6958 inst.instruction |= inst.operands[2].reg;
6959 }
6960
6961 static void
6962 do_rm_rd_rn (void)
6963 {
6964 inst.instruction |= inst.operands[0].reg;
6965 inst.instruction |= inst.operands[1].reg << 12;
6966 inst.instruction |= inst.operands[2].reg << 16;
6967 }
6968
6969 static void
6970 do_imm0 (void)
6971 {
6972 inst.instruction |= inst.operands[0].imm;
6973 }
6974
6975 static void
6976 do_rd_cpaddr (void)
6977 {
6978 inst.instruction |= inst.operands[0].reg << 12;
6979 encode_arm_cp_address (1, TRUE, TRUE, 0);
6980 }
6981
6982 /* ARM instructions, in alphabetical order by function name (except
6983 that wrapper functions appear immediately after the function they
6984 wrap). */
6985
6986 /* This is a pseudo-op of the form "adr rd, label" to be converted
6987 into a relative address of the form "add rd, pc, #label-.-8". */
6988
6989 static void
6990 do_adr (void)
6991 {
6992 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
6993
6994 /* Frag hacking will turn this into a sub instruction if the offset turns
6995 out to be negative. */
6996 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
6997 inst.reloc.pc_rel = 1;
6998 inst.reloc.exp.X_add_number -= 8;
6999 }
7000
7001 /* This is a pseudo-op of the form "adrl rd, label" to be converted
7002 into a relative address of the form:
7003 add rd, pc, #low(label-.-8)"
7004 add rd, rd, #high(label-.-8)" */
7005
7006 static void
7007 do_adrl (void)
7008 {
7009 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
7010
7011 /* Frag hacking will turn this into a sub instruction if the offset turns
7012 out to be negative. */
7013 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
7014 inst.reloc.pc_rel = 1;
7015 inst.size = INSN_SIZE * 2;
7016 inst.reloc.exp.X_add_number -= 8;
7017 }
7018
7019 static void
7020 do_arit (void)
7021 {
7022 if (!inst.operands[1].present)
7023 inst.operands[1].reg = inst.operands[0].reg;
7024 inst.instruction |= inst.operands[0].reg << 12;
7025 inst.instruction |= inst.operands[1].reg << 16;
7026 encode_arm_shifter_operand (2);
7027 }
7028
7029 static void
7030 do_barrier (void)
7031 {
7032 if (inst.operands[0].present)
7033 {
7034 constraint ((inst.instruction & 0xf0) != 0x40
7035 && inst.operands[0].imm != 0xf,
7036 _("bad barrier type"));
7037 inst.instruction |= inst.operands[0].imm;
7038 }
7039 else
7040 inst.instruction |= 0xf;
7041 }
7042
7043 static void
7044 do_bfc (void)
7045 {
7046 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
7047 constraint (msb > 32, _("bit-field extends past end of register"));
7048 /* The instruction encoding stores the LSB and MSB,
7049 not the LSB and width. */
7050 inst.instruction |= inst.operands[0].reg << 12;
7051 inst.instruction |= inst.operands[1].imm << 7;
7052 inst.instruction |= (msb - 1) << 16;
7053 }
7054
7055 static void
7056 do_bfi (void)
7057 {
7058 unsigned int msb;
7059
7060 /* #0 in second position is alternative syntax for bfc, which is
7061 the same instruction but with REG_PC in the Rm field. */
7062 if (!inst.operands[1].isreg)
7063 inst.operands[1].reg = REG_PC;
7064
7065 msb = inst.operands[2].imm + inst.operands[3].imm;
7066 constraint (msb > 32, _("bit-field extends past end of register"));
7067 /* The instruction encoding stores the LSB and MSB,
7068 not the LSB and width. */
7069 inst.instruction |= inst.operands[0].reg << 12;
7070 inst.instruction |= inst.operands[1].reg;
7071 inst.instruction |= inst.operands[2].imm << 7;
7072 inst.instruction |= (msb - 1) << 16;
7073 }
7074
7075 static void
7076 do_bfx (void)
7077 {
7078 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
7079 _("bit-field extends past end of register"));
7080 inst.instruction |= inst.operands[0].reg << 12;
7081 inst.instruction |= inst.operands[1].reg;
7082 inst.instruction |= inst.operands[2].imm << 7;
7083 inst.instruction |= (inst.operands[3].imm - 1) << 16;
7084 }
7085
7086 /* ARM V5 breakpoint instruction (argument parse)
7087 BKPT <16 bit unsigned immediate>
7088 Instruction is not conditional.
7089 The bit pattern given in insns[] has the COND_ALWAYS condition,
7090 and it is an error if the caller tried to override that. */
7091
7092 static void
7093 do_bkpt (void)
7094 {
7095 /* Top 12 of 16 bits to bits 19:8. */
7096 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
7097
7098 /* Bottom 4 of 16 bits to bits 3:0. */
7099 inst.instruction |= inst.operands[0].imm & 0xf;
7100 }
7101
7102 static void
7103 encode_branch (int default_reloc)
7104 {
7105 if (inst.operands[0].hasreloc)
7106 {
7107 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
7108 _("the only suffix valid here is '(plt)'"));
7109 inst.reloc.type = BFD_RELOC_ARM_PLT32;
7110 }
7111 else
7112 {
7113 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
7114 }
7115 inst.reloc.pc_rel = 1;
7116 }
7117
7118 static void
7119 do_branch (void)
7120 {
7121 #ifdef OBJ_ELF
7122 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7123 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7124 else
7125 #endif
7126 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7127 }
7128
7129 static void
7130 do_bl (void)
7131 {
7132 #ifdef OBJ_ELF
7133 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7134 {
7135 if (inst.cond == COND_ALWAYS)
7136 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
7137 else
7138 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7139 }
7140 else
7141 #endif
7142 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7143 }
7144
7145 /* ARM V5 branch-link-exchange instruction (argument parse)
7146 BLX <target_addr> ie BLX(1)
7147 BLX{<condition>} <Rm> ie BLX(2)
7148 Unfortunately, there are two different opcodes for this mnemonic.
7149 So, the insns[].value is not used, and the code here zaps values
7150 into inst.instruction.
7151 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
7152
7153 static void
7154 do_blx (void)
7155 {
7156 if (inst.operands[0].isreg)
7157 {
7158 /* Arg is a register; the opcode provided by insns[] is correct.
7159 It is not illegal to do "blx pc", just useless. */
7160 if (inst.operands[0].reg == REG_PC)
7161 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
7162
7163 inst.instruction |= inst.operands[0].reg;
7164 }
7165 else
7166 {
7167 /* Arg is an address; this instruction cannot be executed
7168 conditionally, and the opcode must be adjusted.
7169 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
7170 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
7171 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7172 inst.instruction = 0xfa000000;
7173 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
7174 }
7175 }
7176
7177 static void
7178 do_bx (void)
7179 {
7180 bfd_boolean want_reloc;
7181
7182 if (inst.operands[0].reg == REG_PC)
7183 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
7184
7185 inst.instruction |= inst.operands[0].reg;
7186 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
7187 it is for ARMv4t or earlier. */
7188 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
7189 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
7190 want_reloc = TRUE;
7191
7192 #ifdef OBJ_ELF
7193 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
7194 #endif
7195 want_reloc = FALSE;
7196
7197 if (want_reloc)
7198 inst.reloc.type = BFD_RELOC_ARM_V4BX;
7199 }
7200
7201
7202 /* ARM v5TEJ. Jump to Jazelle code. */
7203
7204 static void
7205 do_bxj (void)
7206 {
7207 if (inst.operands[0].reg == REG_PC)
7208 as_tsktsk (_("use of r15 in bxj is not really useful"));
7209
7210 inst.instruction |= inst.operands[0].reg;
7211 }
7212
7213 /* Co-processor data operation:
7214 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
7215 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
7216 static void
7217 do_cdp (void)
7218 {
7219 inst.instruction |= inst.operands[0].reg << 8;
7220 inst.instruction |= inst.operands[1].imm << 20;
7221 inst.instruction |= inst.operands[2].reg << 12;
7222 inst.instruction |= inst.operands[3].reg << 16;
7223 inst.instruction |= inst.operands[4].reg;
7224 inst.instruction |= inst.operands[5].imm << 5;
7225 }
7226
7227 static void
7228 do_cmp (void)
7229 {
7230 inst.instruction |= inst.operands[0].reg << 16;
7231 encode_arm_shifter_operand (1);
7232 }
7233
7234 /* Transfer between coprocessor and ARM registers.
7235 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
7236 MRC2
7237 MCR{cond}
7238 MCR2
7239
7240 No special properties. */
7241
7242 static void
7243 do_co_reg (void)
7244 {
7245 unsigned Rd;
7246
7247 Rd = inst.operands[2].reg;
7248 if (thumb_mode)
7249 {
7250 if (inst.instruction == 0xee000010
7251 || inst.instruction == 0xfe000010)
7252 /* MCR, MCR2 */
7253 reject_bad_reg (Rd);
7254 else
7255 /* MRC, MRC2 */
7256 constraint (Rd == REG_SP, BAD_SP);
7257 }
7258 else
7259 {
7260 /* MCR */
7261 if (inst.instruction == 0xe000010)
7262 constraint (Rd == REG_PC, BAD_PC);
7263 }
7264
7265
7266 inst.instruction |= inst.operands[0].reg << 8;
7267 inst.instruction |= inst.operands[1].imm << 21;
7268 inst.instruction |= Rd << 12;
7269 inst.instruction |= inst.operands[3].reg << 16;
7270 inst.instruction |= inst.operands[4].reg;
7271 inst.instruction |= inst.operands[5].imm << 5;
7272 }
7273
7274 /* Transfer between coprocessor register and pair of ARM registers.
7275 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7276 MCRR2
7277 MRRC{cond}
7278 MRRC2
7279
7280 Two XScale instructions are special cases of these:
7281
7282 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7283 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
7284
7285 Result unpredictable if Rd or Rn is R15. */
7286
7287 static void
7288 do_co_reg2c (void)
7289 {
7290 unsigned Rd, Rn;
7291
7292 Rd = inst.operands[2].reg;
7293 Rn = inst.operands[3].reg;
7294
7295 if (thumb_mode)
7296 {
7297 reject_bad_reg (Rd);
7298 reject_bad_reg (Rn);
7299 }
7300 else
7301 {
7302 constraint (Rd == REG_PC, BAD_PC);
7303 constraint (Rn == REG_PC, BAD_PC);
7304 }
7305
7306 inst.instruction |= inst.operands[0].reg << 8;
7307 inst.instruction |= inst.operands[1].imm << 4;
7308 inst.instruction |= Rd << 12;
7309 inst.instruction |= Rn << 16;
7310 inst.instruction |= inst.operands[4].reg;
7311 }
7312
7313 static void
7314 do_cpsi (void)
7315 {
7316 inst.instruction |= inst.operands[0].imm << 6;
7317 if (inst.operands[1].present)
7318 {
7319 inst.instruction |= CPSI_MMOD;
7320 inst.instruction |= inst.operands[1].imm;
7321 }
7322 }
7323
7324 static void
7325 do_dbg (void)
7326 {
7327 inst.instruction |= inst.operands[0].imm;
7328 }
7329
7330 static void
7331 do_it (void)
7332 {
7333 /* There is no IT instruction in ARM mode. We
7334 process it to do the validation as if in
7335 thumb mode, just in case the code gets
7336 assembled for thumb using the unified syntax. */
7337
7338 inst.size = 0;
7339 if (unified_syntax)
7340 {
7341 set_it_insn_type (IT_INSN);
7342 now_it.mask = (inst.instruction & 0xf) | 0x10;
7343 now_it.cc = inst.operands[0].imm;
7344 }
7345 }
7346
7347 static void
7348 do_ldmstm (void)
7349 {
7350 int base_reg = inst.operands[0].reg;
7351 int range = inst.operands[1].imm;
7352
7353 inst.instruction |= base_reg << 16;
7354 inst.instruction |= range;
7355
7356 if (inst.operands[1].writeback)
7357 inst.instruction |= LDM_TYPE_2_OR_3;
7358
7359 if (inst.operands[0].writeback)
7360 {
7361 inst.instruction |= WRITE_BACK;
7362 /* Check for unpredictable uses of writeback. */
7363 if (inst.instruction & LOAD_BIT)
7364 {
7365 /* Not allowed in LDM type 2. */
7366 if ((inst.instruction & LDM_TYPE_2_OR_3)
7367 && ((range & (1 << REG_PC)) == 0))
7368 as_warn (_("writeback of base register is UNPREDICTABLE"));
7369 /* Only allowed if base reg not in list for other types. */
7370 else if (range & (1 << base_reg))
7371 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7372 }
7373 else /* STM. */
7374 {
7375 /* Not allowed for type 2. */
7376 if (inst.instruction & LDM_TYPE_2_OR_3)
7377 as_warn (_("writeback of base register is UNPREDICTABLE"));
7378 /* Only allowed if base reg not in list, or first in list. */
7379 else if ((range & (1 << base_reg))
7380 && (range & ((1 << base_reg) - 1)))
7381 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
7382 }
7383 }
7384 }
7385
7386 /* ARMv5TE load-consecutive (argument parse)
7387 Mode is like LDRH.
7388
7389 LDRccD R, mode
7390 STRccD R, mode. */
7391
7392 static void
7393 do_ldrd (void)
7394 {
7395 constraint (inst.operands[0].reg % 2 != 0,
7396 _("first destination register must be even"));
7397 constraint (inst.operands[1].present
7398 && inst.operands[1].reg != inst.operands[0].reg + 1,
7399 _("can only load two consecutive registers"));
7400 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7401 constraint (!inst.operands[2].isreg, _("'[' expected"));
7402
7403 if (!inst.operands[1].present)
7404 inst.operands[1].reg = inst.operands[0].reg + 1;
7405
7406 if (inst.instruction & LOAD_BIT)
7407 {
7408 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7409 register and the first register written; we have to diagnose
7410 overlap between the base and the second register written here. */
7411
7412 if (inst.operands[2].reg == inst.operands[1].reg
7413 && (inst.operands[2].writeback || inst.operands[2].postind))
7414 as_warn (_("base register written back, and overlaps "
7415 "second destination register"));
7416
7417 /* For an index-register load, the index register must not overlap the
7418 destination (even if not write-back). */
7419 else if (inst.operands[2].immisreg
7420 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7421 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
7422 as_warn (_("index register overlaps destination register"));
7423 }
7424
7425 inst.instruction |= inst.operands[0].reg << 12;
7426 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
7427 }
7428
7429 static void
7430 do_ldrex (void)
7431 {
7432 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7433 || inst.operands[1].postind || inst.operands[1].writeback
7434 || inst.operands[1].immisreg || inst.operands[1].shifted
7435 || inst.operands[1].negative
7436 /* This can arise if the programmer has written
7437 strex rN, rM, foo
7438 or if they have mistakenly used a register name as the last
7439 operand, eg:
7440 strex rN, rM, rX
7441 It is very difficult to distinguish between these two cases
7442 because "rX" might actually be a label. ie the register
7443 name has been occluded by a symbol of the same name. So we
7444 just generate a general 'bad addressing mode' type error
7445 message and leave it up to the programmer to discover the
7446 true cause and fix their mistake. */
7447 || (inst.operands[1].reg == REG_PC),
7448 BAD_ADDR_MODE);
7449
7450 constraint (inst.reloc.exp.X_op != O_constant
7451 || inst.reloc.exp.X_add_number != 0,
7452 _("offset must be zero in ARM encoding"));
7453
7454 inst.instruction |= inst.operands[0].reg << 12;
7455 inst.instruction |= inst.operands[1].reg << 16;
7456 inst.reloc.type = BFD_RELOC_UNUSED;
7457 }
7458
7459 static void
7460 do_ldrexd (void)
7461 {
7462 constraint (inst.operands[0].reg % 2 != 0,
7463 _("even register required"));
7464 constraint (inst.operands[1].present
7465 && inst.operands[1].reg != inst.operands[0].reg + 1,
7466 _("can only load two consecutive registers"));
7467 /* If op 1 were present and equal to PC, this function wouldn't
7468 have been called in the first place. */
7469 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7470
7471 inst.instruction |= inst.operands[0].reg << 12;
7472 inst.instruction |= inst.operands[2].reg << 16;
7473 }
7474
7475 static void
7476 do_ldst (void)
7477 {
7478 inst.instruction |= inst.operands[0].reg << 12;
7479 if (!inst.operands[1].isreg)
7480 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
7481 return;
7482 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
7483 }
7484
7485 static void
7486 do_ldstt (void)
7487 {
7488 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7489 reject [Rn,...]. */
7490 if (inst.operands[1].preind)
7491 {
7492 constraint (inst.reloc.exp.X_op != O_constant
7493 || inst.reloc.exp.X_add_number != 0,
7494 _("this instruction requires a post-indexed address"));
7495
7496 inst.operands[1].preind = 0;
7497 inst.operands[1].postind = 1;
7498 inst.operands[1].writeback = 1;
7499 }
7500 inst.instruction |= inst.operands[0].reg << 12;
7501 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7502 }
7503
7504 /* Halfword and signed-byte load/store operations. */
7505
7506 static void
7507 do_ldstv4 (void)
7508 {
7509 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
7510 inst.instruction |= inst.operands[0].reg << 12;
7511 if (!inst.operands[1].isreg)
7512 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
7513 return;
7514 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
7515 }
7516
7517 static void
7518 do_ldsttv4 (void)
7519 {
7520 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7521 reject [Rn,...]. */
7522 if (inst.operands[1].preind)
7523 {
7524 constraint (inst.reloc.exp.X_op != O_constant
7525 || inst.reloc.exp.X_add_number != 0,
7526 _("this instruction requires a post-indexed address"));
7527
7528 inst.operands[1].preind = 0;
7529 inst.operands[1].postind = 1;
7530 inst.operands[1].writeback = 1;
7531 }
7532 inst.instruction |= inst.operands[0].reg << 12;
7533 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7534 }
7535
7536 /* Co-processor register load/store.
7537 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7538 static void
7539 do_lstc (void)
7540 {
7541 inst.instruction |= inst.operands[0].reg << 8;
7542 inst.instruction |= inst.operands[1].reg << 12;
7543 encode_arm_cp_address (2, TRUE, TRUE, 0);
7544 }
7545
7546 static void
7547 do_mlas (void)
7548 {
7549 /* This restriction does not apply to mls (nor to mla in v6 or later). */
7550 if (inst.operands[0].reg == inst.operands[1].reg
7551 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
7552 && !(inst.instruction & 0x00400000))
7553 as_tsktsk (_("Rd and Rm should be different in mla"));
7554
7555 inst.instruction |= inst.operands[0].reg << 16;
7556 inst.instruction |= inst.operands[1].reg;
7557 inst.instruction |= inst.operands[2].reg << 8;
7558 inst.instruction |= inst.operands[3].reg << 12;
7559 }
7560
7561 static void
7562 do_mov (void)
7563 {
7564 inst.instruction |= inst.operands[0].reg << 12;
7565 encode_arm_shifter_operand (1);
7566 }
7567
7568 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7569 static void
7570 do_mov16 (void)
7571 {
7572 bfd_vma imm;
7573 bfd_boolean top;
7574
7575 top = (inst.instruction & 0x00400000) != 0;
7576 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7577 _(":lower16: not allowed this instruction"));
7578 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7579 _(":upper16: not allowed instruction"));
7580 inst.instruction |= inst.operands[0].reg << 12;
7581 if (inst.reloc.type == BFD_RELOC_UNUSED)
7582 {
7583 imm = inst.reloc.exp.X_add_number;
7584 /* The value is in two pieces: 0:11, 16:19. */
7585 inst.instruction |= (imm & 0x00000fff);
7586 inst.instruction |= (imm & 0x0000f000) << 4;
7587 }
7588 }
7589
7590 static void do_vfp_nsyn_opcode (const char *);
7591
7592 static int
7593 do_vfp_nsyn_mrs (void)
7594 {
7595 if (inst.operands[0].isvec)
7596 {
7597 if (inst.operands[1].reg != 1)
7598 first_error (_("operand 1 must be FPSCR"));
7599 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7600 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7601 do_vfp_nsyn_opcode ("fmstat");
7602 }
7603 else if (inst.operands[1].isvec)
7604 do_vfp_nsyn_opcode ("fmrx");
7605 else
7606 return FAIL;
7607
7608 return SUCCESS;
7609 }
7610
7611 static int
7612 do_vfp_nsyn_msr (void)
7613 {
7614 if (inst.operands[0].isvec)
7615 do_vfp_nsyn_opcode ("fmxr");
7616 else
7617 return FAIL;
7618
7619 return SUCCESS;
7620 }
7621
7622 static void
7623 do_vmrs (void)
7624 {
7625 unsigned Rt = inst.operands[0].reg;
7626
7627 if (thumb_mode && inst.operands[0].reg == REG_SP)
7628 {
7629 inst.error = BAD_SP;
7630 return;
7631 }
7632
7633 /* APSR_ sets isvec. All other refs to PC are illegal. */
7634 if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC)
7635 {
7636 inst.error = BAD_PC;
7637 return;
7638 }
7639
7640 if (inst.operands[1].reg != 1)
7641 first_error (_("operand 1 must be FPSCR"));
7642
7643 inst.instruction |= (Rt << 12);
7644 }
7645
7646 static void
7647 do_vmsr (void)
7648 {
7649 unsigned Rt = inst.operands[1].reg;
7650
7651 if (thumb_mode)
7652 reject_bad_reg (Rt);
7653 else if (Rt == REG_PC)
7654 {
7655 inst.error = BAD_PC;
7656 return;
7657 }
7658
7659 if (inst.operands[0].reg != 1)
7660 first_error (_("operand 0 must be FPSCR"));
7661
7662 inst.instruction |= (Rt << 12);
7663 }
7664
7665 static void
7666 do_mrs (void)
7667 {
7668 if (do_vfp_nsyn_mrs () == SUCCESS)
7669 return;
7670
7671 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7672 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7673 != (PSR_c|PSR_f),
7674 _("'CPSR' or 'SPSR' expected"));
7675 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
7676 inst.instruction |= inst.operands[0].reg << 12;
7677 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7678 }
7679
7680 /* Two possible forms:
7681 "{C|S}PSR_<field>, Rm",
7682 "{C|S}PSR_f, #expression". */
7683
7684 static void
7685 do_msr (void)
7686 {
7687 if (do_vfp_nsyn_msr () == SUCCESS)
7688 return;
7689
7690 inst.instruction |= inst.operands[0].imm;
7691 if (inst.operands[1].isreg)
7692 inst.instruction |= inst.operands[1].reg;
7693 else
7694 {
7695 inst.instruction |= INST_IMMEDIATE;
7696 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7697 inst.reloc.pc_rel = 0;
7698 }
7699 }
7700
7701 static void
7702 do_mul (void)
7703 {
7704 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
7705
7706 if (!inst.operands[2].present)
7707 inst.operands[2].reg = inst.operands[0].reg;
7708 inst.instruction |= inst.operands[0].reg << 16;
7709 inst.instruction |= inst.operands[1].reg;
7710 inst.instruction |= inst.operands[2].reg << 8;
7711
7712 if (inst.operands[0].reg == inst.operands[1].reg
7713 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7714 as_tsktsk (_("Rd and Rm should be different in mul"));
7715 }
7716
7717 /* Long Multiply Parser
7718 UMULL RdLo, RdHi, Rm, Rs
7719 SMULL RdLo, RdHi, Rm, Rs
7720 UMLAL RdLo, RdHi, Rm, Rs
7721 SMLAL RdLo, RdHi, Rm, Rs. */
7722
7723 static void
7724 do_mull (void)
7725 {
7726 inst.instruction |= inst.operands[0].reg << 12;
7727 inst.instruction |= inst.operands[1].reg << 16;
7728 inst.instruction |= inst.operands[2].reg;
7729 inst.instruction |= inst.operands[3].reg << 8;
7730
7731 /* rdhi and rdlo must be different. */
7732 if (inst.operands[0].reg == inst.operands[1].reg)
7733 as_tsktsk (_("rdhi and rdlo must be different"));
7734
7735 /* rdhi, rdlo and rm must all be different before armv6. */
7736 if ((inst.operands[0].reg == inst.operands[2].reg
7737 || inst.operands[1].reg == inst.operands[2].reg)
7738 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7739 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7740 }
7741
7742 static void
7743 do_nop (void)
7744 {
7745 if (inst.operands[0].present
7746 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
7747 {
7748 /* Architectural NOP hints are CPSR sets with no bits selected. */
7749 inst.instruction &= 0xf0000000;
7750 inst.instruction |= 0x0320f000;
7751 if (inst.operands[0].present)
7752 inst.instruction |= inst.operands[0].imm;
7753 }
7754 }
7755
7756 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7757 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7758 Condition defaults to COND_ALWAYS.
7759 Error if Rd, Rn or Rm are R15. */
7760
7761 static void
7762 do_pkhbt (void)
7763 {
7764 inst.instruction |= inst.operands[0].reg << 12;
7765 inst.instruction |= inst.operands[1].reg << 16;
7766 inst.instruction |= inst.operands[2].reg;
7767 if (inst.operands[3].present)
7768 encode_arm_shift (3);
7769 }
7770
7771 /* ARM V6 PKHTB (Argument Parse). */
7772
7773 static void
7774 do_pkhtb (void)
7775 {
7776 if (!inst.operands[3].present)
7777 {
7778 /* If the shift specifier is omitted, turn the instruction
7779 into pkhbt rd, rm, rn. */
7780 inst.instruction &= 0xfff00010;
7781 inst.instruction |= inst.operands[0].reg << 12;
7782 inst.instruction |= inst.operands[1].reg;
7783 inst.instruction |= inst.operands[2].reg << 16;
7784 }
7785 else
7786 {
7787 inst.instruction |= inst.operands[0].reg << 12;
7788 inst.instruction |= inst.operands[1].reg << 16;
7789 inst.instruction |= inst.operands[2].reg;
7790 encode_arm_shift (3);
7791 }
7792 }
7793
7794 /* ARMv5TE: Preload-Cache
7795
7796 PLD <addr_mode>
7797
7798 Syntactically, like LDR with B=1, W=0, L=1. */
7799
7800 static void
7801 do_pld (void)
7802 {
7803 constraint (!inst.operands[0].isreg,
7804 _("'[' expected after PLD mnemonic"));
7805 constraint (inst.operands[0].postind,
7806 _("post-indexed expression used in preload instruction"));
7807 constraint (inst.operands[0].writeback,
7808 _("writeback used in preload instruction"));
7809 constraint (!inst.operands[0].preind,
7810 _("unindexed addressing used in preload instruction"));
7811 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7812 }
7813
7814 /* ARMv7: PLI <addr_mode> */
7815 static void
7816 do_pli (void)
7817 {
7818 constraint (!inst.operands[0].isreg,
7819 _("'[' expected after PLI mnemonic"));
7820 constraint (inst.operands[0].postind,
7821 _("post-indexed expression used in preload instruction"));
7822 constraint (inst.operands[0].writeback,
7823 _("writeback used in preload instruction"));
7824 constraint (!inst.operands[0].preind,
7825 _("unindexed addressing used in preload instruction"));
7826 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7827 inst.instruction &= ~PRE_INDEX;
7828 }
7829
7830 static void
7831 do_push_pop (void)
7832 {
7833 inst.operands[1] = inst.operands[0];
7834 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7835 inst.operands[0].isreg = 1;
7836 inst.operands[0].writeback = 1;
7837 inst.operands[0].reg = REG_SP;
7838 do_ldmstm ();
7839 }
7840
7841 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7842 word at the specified address and the following word
7843 respectively.
7844 Unconditionally executed.
7845 Error if Rn is R15. */
7846
7847 static void
7848 do_rfe (void)
7849 {
7850 inst.instruction |= inst.operands[0].reg << 16;
7851 if (inst.operands[0].writeback)
7852 inst.instruction |= WRITE_BACK;
7853 }
7854
7855 /* ARM V6 ssat (argument parse). */
7856
7857 static void
7858 do_ssat (void)
7859 {
7860 inst.instruction |= inst.operands[0].reg << 12;
7861 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7862 inst.instruction |= inst.operands[2].reg;
7863
7864 if (inst.operands[3].present)
7865 encode_arm_shift (3);
7866 }
7867
7868 /* ARM V6 usat (argument parse). */
7869
7870 static void
7871 do_usat (void)
7872 {
7873 inst.instruction |= inst.operands[0].reg << 12;
7874 inst.instruction |= inst.operands[1].imm << 16;
7875 inst.instruction |= inst.operands[2].reg;
7876
7877 if (inst.operands[3].present)
7878 encode_arm_shift (3);
7879 }
7880
7881 /* ARM V6 ssat16 (argument parse). */
7882
7883 static void
7884 do_ssat16 (void)
7885 {
7886 inst.instruction |= inst.operands[0].reg << 12;
7887 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7888 inst.instruction |= inst.operands[2].reg;
7889 }
7890
7891 static void
7892 do_usat16 (void)
7893 {
7894 inst.instruction |= inst.operands[0].reg << 12;
7895 inst.instruction |= inst.operands[1].imm << 16;
7896 inst.instruction |= inst.operands[2].reg;
7897 }
7898
7899 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7900 preserving the other bits.
7901
7902 setend <endian_specifier>, where <endian_specifier> is either
7903 BE or LE. */
7904
7905 static void
7906 do_setend (void)
7907 {
7908 if (inst.operands[0].imm)
7909 inst.instruction |= 0x200;
7910 }
7911
7912 static void
7913 do_shift (void)
7914 {
7915 unsigned int Rm = (inst.operands[1].present
7916 ? inst.operands[1].reg
7917 : inst.operands[0].reg);
7918
7919 inst.instruction |= inst.operands[0].reg << 12;
7920 inst.instruction |= Rm;
7921 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
7922 {
7923 inst.instruction |= inst.operands[2].reg << 8;
7924 inst.instruction |= SHIFT_BY_REG;
7925 }
7926 else
7927 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7928 }
7929
7930 static void
7931 do_smc (void)
7932 {
7933 inst.reloc.type = BFD_RELOC_ARM_SMC;
7934 inst.reloc.pc_rel = 0;
7935 }
7936
7937 static void
7938 do_swi (void)
7939 {
7940 inst.reloc.type = BFD_RELOC_ARM_SWI;
7941 inst.reloc.pc_rel = 0;
7942 }
7943
7944 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7945 SMLAxy{cond} Rd,Rm,Rs,Rn
7946 SMLAWy{cond} Rd,Rm,Rs,Rn
7947 Error if any register is R15. */
7948
7949 static void
7950 do_smla (void)
7951 {
7952 inst.instruction |= inst.operands[0].reg << 16;
7953 inst.instruction |= inst.operands[1].reg;
7954 inst.instruction |= inst.operands[2].reg << 8;
7955 inst.instruction |= inst.operands[3].reg << 12;
7956 }
7957
7958 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7959 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7960 Error if any register is R15.
7961 Warning if Rdlo == Rdhi. */
7962
7963 static void
7964 do_smlal (void)
7965 {
7966 inst.instruction |= inst.operands[0].reg << 12;
7967 inst.instruction |= inst.operands[1].reg << 16;
7968 inst.instruction |= inst.operands[2].reg;
7969 inst.instruction |= inst.operands[3].reg << 8;
7970
7971 if (inst.operands[0].reg == inst.operands[1].reg)
7972 as_tsktsk (_("rdhi and rdlo must be different"));
7973 }
7974
7975 /* ARM V5E (El Segundo) signed-multiply (argument parse)
7976 SMULxy{cond} Rd,Rm,Rs
7977 Error if any register is R15. */
7978
7979 static void
7980 do_smul (void)
7981 {
7982 inst.instruction |= inst.operands[0].reg << 16;
7983 inst.instruction |= inst.operands[1].reg;
7984 inst.instruction |= inst.operands[2].reg << 8;
7985 }
7986
7987 /* ARM V6 srs (argument parse). The variable fields in the encoding are
7988 the same for both ARM and Thumb-2. */
7989
7990 static void
7991 do_srs (void)
7992 {
7993 int reg;
7994
7995 if (inst.operands[0].present)
7996 {
7997 reg = inst.operands[0].reg;
7998 constraint (reg != REG_SP, _("SRS base register must be r13"));
7999 }
8000 else
8001 reg = REG_SP;
8002
8003 inst.instruction |= reg << 16;
8004 inst.instruction |= inst.operands[1].imm;
8005 if (inst.operands[0].writeback || inst.operands[1].writeback)
8006 inst.instruction |= WRITE_BACK;
8007 }
8008
8009 /* ARM V6 strex (argument parse). */
8010
8011 static void
8012 do_strex (void)
8013 {
8014 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8015 || inst.operands[2].postind || inst.operands[2].writeback
8016 || inst.operands[2].immisreg || inst.operands[2].shifted
8017 || inst.operands[2].negative
8018 /* See comment in do_ldrex(). */
8019 || (inst.operands[2].reg == REG_PC),
8020 BAD_ADDR_MODE);
8021
8022 constraint (inst.operands[0].reg == inst.operands[1].reg
8023 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8024
8025 constraint (inst.reloc.exp.X_op != O_constant
8026 || inst.reloc.exp.X_add_number != 0,
8027 _("offset must be zero in ARM encoding"));
8028
8029 inst.instruction |= inst.operands[0].reg << 12;
8030 inst.instruction |= inst.operands[1].reg;
8031 inst.instruction |= inst.operands[2].reg << 16;
8032 inst.reloc.type = BFD_RELOC_UNUSED;
8033 }
8034
8035 static void
8036 do_strexd (void)
8037 {
8038 constraint (inst.operands[1].reg % 2 != 0,
8039 _("even register required"));
8040 constraint (inst.operands[2].present
8041 && inst.operands[2].reg != inst.operands[1].reg + 1,
8042 _("can only store two consecutive registers"));
8043 /* If op 2 were present and equal to PC, this function wouldn't
8044 have been called in the first place. */
8045 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
8046
8047 constraint (inst.operands[0].reg == inst.operands[1].reg
8048 || inst.operands[0].reg == inst.operands[1].reg + 1
8049 || inst.operands[0].reg == inst.operands[3].reg,
8050 BAD_OVERLAP);
8051
8052 inst.instruction |= inst.operands[0].reg << 12;
8053 inst.instruction |= inst.operands[1].reg;
8054 inst.instruction |= inst.operands[3].reg << 16;
8055 }
8056
8057 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
8058 extends it to 32-bits, and adds the result to a value in another
8059 register. You can specify a rotation by 0, 8, 16, or 24 bits
8060 before extracting the 16-bit value.
8061 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
8062 Condition defaults to COND_ALWAYS.
8063 Error if any register uses R15. */
8064
8065 static void
8066 do_sxtah (void)
8067 {
8068 inst.instruction |= inst.operands[0].reg << 12;
8069 inst.instruction |= inst.operands[1].reg << 16;
8070 inst.instruction |= inst.operands[2].reg;
8071 inst.instruction |= inst.operands[3].imm << 10;
8072 }
8073
8074 /* ARM V6 SXTH.
8075
8076 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
8077 Condition defaults to COND_ALWAYS.
8078 Error if any register uses R15. */
8079
8080 static void
8081 do_sxth (void)
8082 {
8083 inst.instruction |= inst.operands[0].reg << 12;
8084 inst.instruction |= inst.operands[1].reg;
8085 inst.instruction |= inst.operands[2].imm << 10;
8086 }
8087 \f
8088 /* VFP instructions. In a logical order: SP variant first, monad
8089 before dyad, arithmetic then move then load/store. */
8090
8091 static void
8092 do_vfp_sp_monadic (void)
8093 {
8094 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8095 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
8096 }
8097
8098 static void
8099 do_vfp_sp_dyadic (void)
8100 {
8101 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8102 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8103 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
8104 }
8105
8106 static void
8107 do_vfp_sp_compare_z (void)
8108 {
8109 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8110 }
8111
8112 static void
8113 do_vfp_dp_sp_cvt (void)
8114 {
8115 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8116 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
8117 }
8118
8119 static void
8120 do_vfp_sp_dp_cvt (void)
8121 {
8122 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8123 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8124 }
8125
8126 static void
8127 do_vfp_reg_from_sp (void)
8128 {
8129 inst.instruction |= inst.operands[0].reg << 12;
8130 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8131 }
8132
8133 static void
8134 do_vfp_reg2_from_sp2 (void)
8135 {
8136 constraint (inst.operands[2].imm != 2,
8137 _("only two consecutive VFP SP registers allowed here"));
8138 inst.instruction |= inst.operands[0].reg << 12;
8139 inst.instruction |= inst.operands[1].reg << 16;
8140 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
8141 }
8142
8143 static void
8144 do_vfp_sp_from_reg (void)
8145 {
8146 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
8147 inst.instruction |= inst.operands[1].reg << 12;
8148 }
8149
8150 static void
8151 do_vfp_sp2_from_reg2 (void)
8152 {
8153 constraint (inst.operands[0].imm != 2,
8154 _("only two consecutive VFP SP registers allowed here"));
8155 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
8156 inst.instruction |= inst.operands[1].reg << 12;
8157 inst.instruction |= inst.operands[2].reg << 16;
8158 }
8159
8160 static void
8161 do_vfp_sp_ldst (void)
8162 {
8163 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8164 encode_arm_cp_address (1, FALSE, TRUE, 0);
8165 }
8166
8167 static void
8168 do_vfp_dp_ldst (void)
8169 {
8170 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8171 encode_arm_cp_address (1, FALSE, TRUE, 0);
8172 }
8173
8174
8175 static void
8176 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
8177 {
8178 if (inst.operands[0].writeback)
8179 inst.instruction |= WRITE_BACK;
8180 else
8181 constraint (ldstm_type != VFP_LDSTMIA,
8182 _("this addressing mode requires base-register writeback"));
8183 inst.instruction |= inst.operands[0].reg << 16;
8184 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
8185 inst.instruction |= inst.operands[1].imm;
8186 }
8187
8188 static void
8189 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
8190 {
8191 int count;
8192
8193 if (inst.operands[0].writeback)
8194 inst.instruction |= WRITE_BACK;
8195 else
8196 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
8197 _("this addressing mode requires base-register writeback"));
8198
8199 inst.instruction |= inst.operands[0].reg << 16;
8200 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8201
8202 count = inst.operands[1].imm << 1;
8203 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
8204 count += 1;
8205
8206 inst.instruction |= count;
8207 }
8208
8209 static void
8210 do_vfp_sp_ldstmia (void)
8211 {
8212 vfp_sp_ldstm (VFP_LDSTMIA);
8213 }
8214
8215 static void
8216 do_vfp_sp_ldstmdb (void)
8217 {
8218 vfp_sp_ldstm (VFP_LDSTMDB);
8219 }
8220
8221 static void
8222 do_vfp_dp_ldstmia (void)
8223 {
8224 vfp_dp_ldstm (VFP_LDSTMIA);
8225 }
8226
8227 static void
8228 do_vfp_dp_ldstmdb (void)
8229 {
8230 vfp_dp_ldstm (VFP_LDSTMDB);
8231 }
8232
8233 static void
8234 do_vfp_xp_ldstmia (void)
8235 {
8236 vfp_dp_ldstm (VFP_LDSTMIAX);
8237 }
8238
8239 static void
8240 do_vfp_xp_ldstmdb (void)
8241 {
8242 vfp_dp_ldstm (VFP_LDSTMDBX);
8243 }
8244
8245 static void
8246 do_vfp_dp_rd_rm (void)
8247 {
8248 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8249 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8250 }
8251
8252 static void
8253 do_vfp_dp_rn_rd (void)
8254 {
8255 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
8256 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8257 }
8258
8259 static void
8260 do_vfp_dp_rd_rn (void)
8261 {
8262 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8263 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8264 }
8265
8266 static void
8267 do_vfp_dp_rd_rn_rm (void)
8268 {
8269 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8270 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8271 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
8272 }
8273
8274 static void
8275 do_vfp_dp_rd (void)
8276 {
8277 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8278 }
8279
8280 static void
8281 do_vfp_dp_rm_rd_rn (void)
8282 {
8283 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
8284 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8285 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8286 }
8287
8288 /* VFPv3 instructions. */
8289 static void
8290 do_vfp_sp_const (void)
8291 {
8292 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8293 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8294 inst.instruction |= (inst.operands[1].imm & 0x0f);
8295 }
8296
8297 static void
8298 do_vfp_dp_const (void)
8299 {
8300 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8301 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8302 inst.instruction |= (inst.operands[1].imm & 0x0f);
8303 }
8304
8305 static void
8306 vfp_conv (int srcsize)
8307 {
8308 unsigned immbits = srcsize - inst.operands[1].imm;
8309 inst.instruction |= (immbits & 1) << 5;
8310 inst.instruction |= (immbits >> 1);
8311 }
8312
8313 static void
8314 do_vfp_sp_conv_16 (void)
8315 {
8316 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8317 vfp_conv (16);
8318 }
8319
8320 static void
8321 do_vfp_dp_conv_16 (void)
8322 {
8323 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8324 vfp_conv (16);
8325 }
8326
8327 static void
8328 do_vfp_sp_conv_32 (void)
8329 {
8330 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8331 vfp_conv (32);
8332 }
8333
8334 static void
8335 do_vfp_dp_conv_32 (void)
8336 {
8337 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8338 vfp_conv (32);
8339 }
8340 \f
8341 /* FPA instructions. Also in a logical order. */
8342
8343 static void
8344 do_fpa_cmp (void)
8345 {
8346 inst.instruction |= inst.operands[0].reg << 16;
8347 inst.instruction |= inst.operands[1].reg;
8348 }
8349
8350 static void
8351 do_fpa_ldmstm (void)
8352 {
8353 inst.instruction |= inst.operands[0].reg << 12;
8354 switch (inst.operands[1].imm)
8355 {
8356 case 1: inst.instruction |= CP_T_X; break;
8357 case 2: inst.instruction |= CP_T_Y; break;
8358 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
8359 case 4: break;
8360 default: abort ();
8361 }
8362
8363 if (inst.instruction & (PRE_INDEX | INDEX_UP))
8364 {
8365 /* The instruction specified "ea" or "fd", so we can only accept
8366 [Rn]{!}. The instruction does not really support stacking or
8367 unstacking, so we have to emulate these by setting appropriate
8368 bits and offsets. */
8369 constraint (inst.reloc.exp.X_op != O_constant
8370 || inst.reloc.exp.X_add_number != 0,
8371 _("this instruction does not support indexing"));
8372
8373 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
8374 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
8375
8376 if (!(inst.instruction & INDEX_UP))
8377 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
8378
8379 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
8380 {
8381 inst.operands[2].preind = 0;
8382 inst.operands[2].postind = 1;
8383 }
8384 }
8385
8386 encode_arm_cp_address (2, TRUE, TRUE, 0);
8387 }
8388 \f
8389 /* iWMMXt instructions: strictly in alphabetical order. */
8390
8391 static void
8392 do_iwmmxt_tandorc (void)
8393 {
8394 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
8395 }
8396
8397 static void
8398 do_iwmmxt_textrc (void)
8399 {
8400 inst.instruction |= inst.operands[0].reg << 12;
8401 inst.instruction |= inst.operands[1].imm;
8402 }
8403
8404 static void
8405 do_iwmmxt_textrm (void)
8406 {
8407 inst.instruction |= inst.operands[0].reg << 12;
8408 inst.instruction |= inst.operands[1].reg << 16;
8409 inst.instruction |= inst.operands[2].imm;
8410 }
8411
8412 static void
8413 do_iwmmxt_tinsr (void)
8414 {
8415 inst.instruction |= inst.operands[0].reg << 16;
8416 inst.instruction |= inst.operands[1].reg << 12;
8417 inst.instruction |= inst.operands[2].imm;
8418 }
8419
8420 static void
8421 do_iwmmxt_tmia (void)
8422 {
8423 inst.instruction |= inst.operands[0].reg << 5;
8424 inst.instruction |= inst.operands[1].reg;
8425 inst.instruction |= inst.operands[2].reg << 12;
8426 }
8427
8428 static void
8429 do_iwmmxt_waligni (void)
8430 {
8431 inst.instruction |= inst.operands[0].reg << 12;
8432 inst.instruction |= inst.operands[1].reg << 16;
8433 inst.instruction |= inst.operands[2].reg;
8434 inst.instruction |= inst.operands[3].imm << 20;
8435 }
8436
8437 static void
8438 do_iwmmxt_wmerge (void)
8439 {
8440 inst.instruction |= inst.operands[0].reg << 12;
8441 inst.instruction |= inst.operands[1].reg << 16;
8442 inst.instruction |= inst.operands[2].reg;
8443 inst.instruction |= inst.operands[3].imm << 21;
8444 }
8445
8446 static void
8447 do_iwmmxt_wmov (void)
8448 {
8449 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
8450 inst.instruction |= inst.operands[0].reg << 12;
8451 inst.instruction |= inst.operands[1].reg << 16;
8452 inst.instruction |= inst.operands[1].reg;
8453 }
8454
8455 static void
8456 do_iwmmxt_wldstbh (void)
8457 {
8458 int reloc;
8459 inst.instruction |= inst.operands[0].reg << 12;
8460 if (thumb_mode)
8461 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
8462 else
8463 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
8464 encode_arm_cp_address (1, TRUE, FALSE, reloc);
8465 }
8466
8467 static void
8468 do_iwmmxt_wldstw (void)
8469 {
8470 /* RIWR_RIWC clears .isreg for a control register. */
8471 if (!inst.operands[0].isreg)
8472 {
8473 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8474 inst.instruction |= 0xf0000000;
8475 }
8476
8477 inst.instruction |= inst.operands[0].reg << 12;
8478 encode_arm_cp_address (1, TRUE, TRUE, 0);
8479 }
8480
8481 static void
8482 do_iwmmxt_wldstd (void)
8483 {
8484 inst.instruction |= inst.operands[0].reg << 12;
8485 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
8486 && inst.operands[1].immisreg)
8487 {
8488 inst.instruction &= ~0x1a000ff;
8489 inst.instruction |= (0xf << 28);
8490 if (inst.operands[1].preind)
8491 inst.instruction |= PRE_INDEX;
8492 if (!inst.operands[1].negative)
8493 inst.instruction |= INDEX_UP;
8494 if (inst.operands[1].writeback)
8495 inst.instruction |= WRITE_BACK;
8496 inst.instruction |= inst.operands[1].reg << 16;
8497 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8498 inst.instruction |= inst.operands[1].imm;
8499 }
8500 else
8501 encode_arm_cp_address (1, TRUE, FALSE, 0);
8502 }
8503
8504 static void
8505 do_iwmmxt_wshufh (void)
8506 {
8507 inst.instruction |= inst.operands[0].reg << 12;
8508 inst.instruction |= inst.operands[1].reg << 16;
8509 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8510 inst.instruction |= (inst.operands[2].imm & 0x0f);
8511 }
8512
8513 static void
8514 do_iwmmxt_wzero (void)
8515 {
8516 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8517 inst.instruction |= inst.operands[0].reg;
8518 inst.instruction |= inst.operands[0].reg << 12;
8519 inst.instruction |= inst.operands[0].reg << 16;
8520 }
8521
8522 static void
8523 do_iwmmxt_wrwrwr_or_imm5 (void)
8524 {
8525 if (inst.operands[2].isreg)
8526 do_rd_rn_rm ();
8527 else {
8528 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8529 _("immediate operand requires iWMMXt2"));
8530 do_rd_rn ();
8531 if (inst.operands[2].imm == 0)
8532 {
8533 switch ((inst.instruction >> 20) & 0xf)
8534 {
8535 case 4:
8536 case 5:
8537 case 6:
8538 case 7:
8539 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8540 inst.operands[2].imm = 16;
8541 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8542 break;
8543 case 8:
8544 case 9:
8545 case 10:
8546 case 11:
8547 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8548 inst.operands[2].imm = 32;
8549 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8550 break;
8551 case 12:
8552 case 13:
8553 case 14:
8554 case 15:
8555 {
8556 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8557 unsigned long wrn;
8558 wrn = (inst.instruction >> 16) & 0xf;
8559 inst.instruction &= 0xff0fff0f;
8560 inst.instruction |= wrn;
8561 /* Bail out here; the instruction is now assembled. */
8562 return;
8563 }
8564 }
8565 }
8566 /* Map 32 -> 0, etc. */
8567 inst.operands[2].imm &= 0x1f;
8568 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8569 }
8570 }
8571 \f
8572 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8573 operations first, then control, shift, and load/store. */
8574
8575 /* Insns like "foo X,Y,Z". */
8576
8577 static void
8578 do_mav_triple (void)
8579 {
8580 inst.instruction |= inst.operands[0].reg << 16;
8581 inst.instruction |= inst.operands[1].reg;
8582 inst.instruction |= inst.operands[2].reg << 12;
8583 }
8584
8585 /* Insns like "foo W,X,Y,Z".
8586 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
8587
8588 static void
8589 do_mav_quad (void)
8590 {
8591 inst.instruction |= inst.operands[0].reg << 5;
8592 inst.instruction |= inst.operands[1].reg << 12;
8593 inst.instruction |= inst.operands[2].reg << 16;
8594 inst.instruction |= inst.operands[3].reg;
8595 }
8596
8597 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8598 static void
8599 do_mav_dspsc (void)
8600 {
8601 inst.instruction |= inst.operands[1].reg << 12;
8602 }
8603
8604 /* Maverick shift immediate instructions.
8605 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8606 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
8607
8608 static void
8609 do_mav_shift (void)
8610 {
8611 int imm = inst.operands[2].imm;
8612
8613 inst.instruction |= inst.operands[0].reg << 12;
8614 inst.instruction |= inst.operands[1].reg << 16;
8615
8616 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8617 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8618 Bit 4 should be 0. */
8619 imm = (imm & 0xf) | ((imm & 0x70) << 1);
8620
8621 inst.instruction |= imm;
8622 }
8623 \f
8624 /* XScale instructions. Also sorted arithmetic before move. */
8625
8626 /* Xscale multiply-accumulate (argument parse)
8627 MIAcc acc0,Rm,Rs
8628 MIAPHcc acc0,Rm,Rs
8629 MIAxycc acc0,Rm,Rs. */
8630
8631 static void
8632 do_xsc_mia (void)
8633 {
8634 inst.instruction |= inst.operands[1].reg;
8635 inst.instruction |= inst.operands[2].reg << 12;
8636 }
8637
8638 /* Xscale move-accumulator-register (argument parse)
8639
8640 MARcc acc0,RdLo,RdHi. */
8641
8642 static void
8643 do_xsc_mar (void)
8644 {
8645 inst.instruction |= inst.operands[1].reg << 12;
8646 inst.instruction |= inst.operands[2].reg << 16;
8647 }
8648
8649 /* Xscale move-register-accumulator (argument parse)
8650
8651 MRAcc RdLo,RdHi,acc0. */
8652
8653 static void
8654 do_xsc_mra (void)
8655 {
8656 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8657 inst.instruction |= inst.operands[0].reg << 12;
8658 inst.instruction |= inst.operands[1].reg << 16;
8659 }
8660 \f
8661 /* Encoding functions relevant only to Thumb. */
8662
8663 /* inst.operands[i] is a shifted-register operand; encode
8664 it into inst.instruction in the format used by Thumb32. */
8665
8666 static void
8667 encode_thumb32_shifted_operand (int i)
8668 {
8669 unsigned int value = inst.reloc.exp.X_add_number;
8670 unsigned int shift = inst.operands[i].shift_kind;
8671
8672 constraint (inst.operands[i].immisreg,
8673 _("shift by register not allowed in thumb mode"));
8674 inst.instruction |= inst.operands[i].reg;
8675 if (shift == SHIFT_RRX)
8676 inst.instruction |= SHIFT_ROR << 4;
8677 else
8678 {
8679 constraint (inst.reloc.exp.X_op != O_constant,
8680 _("expression too complex"));
8681
8682 constraint (value > 32
8683 || (value == 32 && (shift == SHIFT_LSL
8684 || shift == SHIFT_ROR)),
8685 _("shift expression is too large"));
8686
8687 if (value == 0)
8688 shift = SHIFT_LSL;
8689 else if (value == 32)
8690 value = 0;
8691
8692 inst.instruction |= shift << 4;
8693 inst.instruction |= (value & 0x1c) << 10;
8694 inst.instruction |= (value & 0x03) << 6;
8695 }
8696 }
8697
8698
8699 /* inst.operands[i] was set up by parse_address. Encode it into a
8700 Thumb32 format load or store instruction. Reject forms that cannot
8701 be used with such instructions. If is_t is true, reject forms that
8702 cannot be used with a T instruction; if is_d is true, reject forms
8703 that cannot be used with a D instruction. */
8704
8705 static void
8706 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8707 {
8708 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8709
8710 constraint (!inst.operands[i].isreg,
8711 _("Instruction does not support =N addresses"));
8712
8713 inst.instruction |= inst.operands[i].reg << 16;
8714 if (inst.operands[i].immisreg)
8715 {
8716 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
8717 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8718 constraint (inst.operands[i].negative,
8719 _("Thumb does not support negative register indexing"));
8720 constraint (inst.operands[i].postind,
8721 _("Thumb does not support register post-indexing"));
8722 constraint (inst.operands[i].writeback,
8723 _("Thumb does not support register indexing with writeback"));
8724 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8725 _("Thumb supports only LSL in shifted register indexing"));
8726
8727 inst.instruction |= inst.operands[i].imm;
8728 if (inst.operands[i].shifted)
8729 {
8730 constraint (inst.reloc.exp.X_op != O_constant,
8731 _("expression too complex"));
8732 constraint (inst.reloc.exp.X_add_number < 0
8733 || inst.reloc.exp.X_add_number > 3,
8734 _("shift out of range"));
8735 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8736 }
8737 inst.reloc.type = BFD_RELOC_UNUSED;
8738 }
8739 else if (inst.operands[i].preind)
8740 {
8741 constraint (is_pc && inst.operands[i].writeback,
8742 _("cannot use writeback with PC-relative addressing"));
8743 constraint (is_t && inst.operands[i].writeback,
8744 _("cannot use writeback with this instruction"));
8745
8746 if (is_d)
8747 {
8748 inst.instruction |= 0x01000000;
8749 if (inst.operands[i].writeback)
8750 inst.instruction |= 0x00200000;
8751 }
8752 else
8753 {
8754 inst.instruction |= 0x00000c00;
8755 if (inst.operands[i].writeback)
8756 inst.instruction |= 0x00000100;
8757 }
8758 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8759 }
8760 else if (inst.operands[i].postind)
8761 {
8762 gas_assert (inst.operands[i].writeback);
8763 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8764 constraint (is_t, _("cannot use post-indexing with this instruction"));
8765
8766 if (is_d)
8767 inst.instruction |= 0x00200000;
8768 else
8769 inst.instruction |= 0x00000900;
8770 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8771 }
8772 else /* unindexed - only for coprocessor */
8773 inst.error = _("instruction does not accept unindexed addressing");
8774 }
8775
8776 /* Table of Thumb instructions which exist in both 16- and 32-bit
8777 encodings (the latter only in post-V6T2 cores). The index is the
8778 value used in the insns table below. When there is more than one
8779 possible 16-bit encoding for the instruction, this table always
8780 holds variant (1).
8781 Also contains several pseudo-instructions used during relaxation. */
8782 #define T16_32_TAB \
8783 X(_adc, 4140, eb400000), \
8784 X(_adcs, 4140, eb500000), \
8785 X(_add, 1c00, eb000000), \
8786 X(_adds, 1c00, eb100000), \
8787 X(_addi, 0000, f1000000), \
8788 X(_addis, 0000, f1100000), \
8789 X(_add_pc,000f, f20f0000), \
8790 X(_add_sp,000d, f10d0000), \
8791 X(_adr, 000f, f20f0000), \
8792 X(_and, 4000, ea000000), \
8793 X(_ands, 4000, ea100000), \
8794 X(_asr, 1000, fa40f000), \
8795 X(_asrs, 1000, fa50f000), \
8796 X(_b, e000, f000b000), \
8797 X(_bcond, d000, f0008000), \
8798 X(_bic, 4380, ea200000), \
8799 X(_bics, 4380, ea300000), \
8800 X(_cmn, 42c0, eb100f00), \
8801 X(_cmp, 2800, ebb00f00), \
8802 X(_cpsie, b660, f3af8400), \
8803 X(_cpsid, b670, f3af8600), \
8804 X(_cpy, 4600, ea4f0000), \
8805 X(_dec_sp,80dd, f1ad0d00), \
8806 X(_eor, 4040, ea800000), \
8807 X(_eors, 4040, ea900000), \
8808 X(_inc_sp,00dd, f10d0d00), \
8809 X(_ldmia, c800, e8900000), \
8810 X(_ldr, 6800, f8500000), \
8811 X(_ldrb, 7800, f8100000), \
8812 X(_ldrh, 8800, f8300000), \
8813 X(_ldrsb, 5600, f9100000), \
8814 X(_ldrsh, 5e00, f9300000), \
8815 X(_ldr_pc,4800, f85f0000), \
8816 X(_ldr_pc2,4800, f85f0000), \
8817 X(_ldr_sp,9800, f85d0000), \
8818 X(_lsl, 0000, fa00f000), \
8819 X(_lsls, 0000, fa10f000), \
8820 X(_lsr, 0800, fa20f000), \
8821 X(_lsrs, 0800, fa30f000), \
8822 X(_mov, 2000, ea4f0000), \
8823 X(_movs, 2000, ea5f0000), \
8824 X(_mul, 4340, fb00f000), \
8825 X(_muls, 4340, ffffffff), /* no 32b muls */ \
8826 X(_mvn, 43c0, ea6f0000), \
8827 X(_mvns, 43c0, ea7f0000), \
8828 X(_neg, 4240, f1c00000), /* rsb #0 */ \
8829 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
8830 X(_orr, 4300, ea400000), \
8831 X(_orrs, 4300, ea500000), \
8832 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8833 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
8834 X(_rev, ba00, fa90f080), \
8835 X(_rev16, ba40, fa90f090), \
8836 X(_revsh, bac0, fa90f0b0), \
8837 X(_ror, 41c0, fa60f000), \
8838 X(_rors, 41c0, fa70f000), \
8839 X(_sbc, 4180, eb600000), \
8840 X(_sbcs, 4180, eb700000), \
8841 X(_stmia, c000, e8800000), \
8842 X(_str, 6000, f8400000), \
8843 X(_strb, 7000, f8000000), \
8844 X(_strh, 8000, f8200000), \
8845 X(_str_sp,9000, f84d0000), \
8846 X(_sub, 1e00, eba00000), \
8847 X(_subs, 1e00, ebb00000), \
8848 X(_subi, 8000, f1a00000), \
8849 X(_subis, 8000, f1b00000), \
8850 X(_sxtb, b240, fa4ff080), \
8851 X(_sxth, b200, fa0ff080), \
8852 X(_tst, 4200, ea100f00), \
8853 X(_uxtb, b2c0, fa5ff080), \
8854 X(_uxth, b280, fa1ff080), \
8855 X(_nop, bf00, f3af8000), \
8856 X(_yield, bf10, f3af8001), \
8857 X(_wfe, bf20, f3af8002), \
8858 X(_wfi, bf30, f3af8003), \
8859 X(_sev, bf40, f3af8004),
8860
8861 /* To catch errors in encoding functions, the codes are all offset by
8862 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8863 as 16-bit instructions. */
8864 #define X(a,b,c) T_MNEM##a
8865 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8866 #undef X
8867
8868 #define X(a,b,c) 0x##b
8869 static const unsigned short thumb_op16[] = { T16_32_TAB };
8870 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8871 #undef X
8872
8873 #define X(a,b,c) 0x##c
8874 static const unsigned int thumb_op32[] = { T16_32_TAB };
8875 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8876 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
8877 #undef X
8878 #undef T16_32_TAB
8879
8880 /* Thumb instruction encoders, in alphabetical order. */
8881
8882 /* ADDW or SUBW. */
8883
8884 static void
8885 do_t_add_sub_w (void)
8886 {
8887 int Rd, Rn;
8888
8889 Rd = inst.operands[0].reg;
8890 Rn = inst.operands[1].reg;
8891
8892 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
8893 is the SP-{plus,minus}-immediate form of the instruction. */
8894 if (Rn == REG_SP)
8895 constraint (Rd == REG_PC, BAD_PC);
8896 else
8897 reject_bad_reg (Rd);
8898
8899 inst.instruction |= (Rn << 16) | (Rd << 8);
8900 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8901 }
8902
8903 /* Parse an add or subtract instruction. We get here with inst.instruction
8904 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8905
8906 static void
8907 do_t_add_sub (void)
8908 {
8909 int Rd, Rs, Rn;
8910
8911 Rd = inst.operands[0].reg;
8912 Rs = (inst.operands[1].present
8913 ? inst.operands[1].reg /* Rd, Rs, foo */
8914 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8915
8916 if (Rd == REG_PC)
8917 set_it_insn_type_last ();
8918
8919 if (unified_syntax)
8920 {
8921 bfd_boolean flags;
8922 bfd_boolean narrow;
8923 int opcode;
8924
8925 flags = (inst.instruction == T_MNEM_adds
8926 || inst.instruction == T_MNEM_subs);
8927 if (flags)
8928 narrow = !in_it_block ();
8929 else
8930 narrow = in_it_block ();
8931 if (!inst.operands[2].isreg)
8932 {
8933 int add;
8934
8935 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
8936
8937 add = (inst.instruction == T_MNEM_add
8938 || inst.instruction == T_MNEM_adds);
8939 opcode = 0;
8940 if (inst.size_req != 4)
8941 {
8942 /* Attempt to use a narrow opcode, with relaxation if
8943 appropriate. */
8944 if (Rd == REG_SP && Rs == REG_SP && !flags)
8945 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8946 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8947 opcode = T_MNEM_add_sp;
8948 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8949 opcode = T_MNEM_add_pc;
8950 else if (Rd <= 7 && Rs <= 7 && narrow)
8951 {
8952 if (flags)
8953 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8954 else
8955 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8956 }
8957 if (opcode)
8958 {
8959 inst.instruction = THUMB_OP16(opcode);
8960 inst.instruction |= (Rd << 4) | Rs;
8961 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8962 if (inst.size_req != 2)
8963 inst.relax = opcode;
8964 }
8965 else
8966 constraint (inst.size_req == 2, BAD_HIREG);
8967 }
8968 if (inst.size_req == 4
8969 || (inst.size_req != 2 && !opcode))
8970 {
8971 if (Rd == REG_PC)
8972 {
8973 constraint (add, BAD_PC);
8974 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
8975 _("only SUBS PC, LR, #const allowed"));
8976 constraint (inst.reloc.exp.X_op != O_constant,
8977 _("expression too complex"));
8978 constraint (inst.reloc.exp.X_add_number < 0
8979 || inst.reloc.exp.X_add_number > 0xff,
8980 _("immediate value out of range"));
8981 inst.instruction = T2_SUBS_PC_LR
8982 | inst.reloc.exp.X_add_number;
8983 inst.reloc.type = BFD_RELOC_UNUSED;
8984 return;
8985 }
8986 else if (Rs == REG_PC)
8987 {
8988 /* Always use addw/subw. */
8989 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8990 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8991 }
8992 else
8993 {
8994 inst.instruction = THUMB_OP32 (inst.instruction);
8995 inst.instruction = (inst.instruction & 0xe1ffffff)
8996 | 0x10000000;
8997 if (flags)
8998 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8999 else
9000 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
9001 }
9002 inst.instruction |= Rd << 8;
9003 inst.instruction |= Rs << 16;
9004 }
9005 }
9006 else
9007 {
9008 Rn = inst.operands[2].reg;
9009 /* See if we can do this with a 16-bit instruction. */
9010 if (!inst.operands[2].shifted && inst.size_req != 4)
9011 {
9012 if (Rd > 7 || Rs > 7 || Rn > 7)
9013 narrow = FALSE;
9014
9015 if (narrow)
9016 {
9017 inst.instruction = ((inst.instruction == T_MNEM_adds
9018 || inst.instruction == T_MNEM_add)
9019 ? T_OPCODE_ADD_R3
9020 : T_OPCODE_SUB_R3);
9021 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9022 return;
9023 }
9024
9025 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
9026 {
9027 /* Thumb-1 cores (except v6-M) require at least one high
9028 register in a narrow non flag setting add. */
9029 if (Rd > 7 || Rn > 7
9030 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
9031 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
9032 {
9033 if (Rd == Rn)
9034 {
9035 Rn = Rs;
9036 Rs = Rd;
9037 }
9038 inst.instruction = T_OPCODE_ADD_HI;
9039 inst.instruction |= (Rd & 8) << 4;
9040 inst.instruction |= (Rd & 7);
9041 inst.instruction |= Rn << 3;
9042 return;
9043 }
9044 }
9045 }
9046
9047 constraint (Rd == REG_PC, BAD_PC);
9048 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9049 constraint (Rs == REG_PC, BAD_PC);
9050 reject_bad_reg (Rn);
9051
9052 /* If we get here, it can't be done in 16 bits. */
9053 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
9054 _("shift must be constant"));
9055 inst.instruction = THUMB_OP32 (inst.instruction);
9056 inst.instruction |= Rd << 8;
9057 inst.instruction |= Rs << 16;
9058 encode_thumb32_shifted_operand (2);
9059 }
9060 }
9061 else
9062 {
9063 constraint (inst.instruction == T_MNEM_adds
9064 || inst.instruction == T_MNEM_subs,
9065 BAD_THUMB32);
9066
9067 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
9068 {
9069 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
9070 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
9071 BAD_HIREG);
9072
9073 inst.instruction = (inst.instruction == T_MNEM_add
9074 ? 0x0000 : 0x8000);
9075 inst.instruction |= (Rd << 4) | Rs;
9076 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9077 return;
9078 }
9079
9080 Rn = inst.operands[2].reg;
9081 constraint (inst.operands[2].shifted, _("unshifted register required"));
9082
9083 /* We now have Rd, Rs, and Rn set to registers. */
9084 if (Rd > 7 || Rs > 7 || Rn > 7)
9085 {
9086 /* Can't do this for SUB. */
9087 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
9088 inst.instruction = T_OPCODE_ADD_HI;
9089 inst.instruction |= (Rd & 8) << 4;
9090 inst.instruction |= (Rd & 7);
9091 if (Rs == Rd)
9092 inst.instruction |= Rn << 3;
9093 else if (Rn == Rd)
9094 inst.instruction |= Rs << 3;
9095 else
9096 constraint (1, _("dest must overlap one source register"));
9097 }
9098 else
9099 {
9100 inst.instruction = (inst.instruction == T_MNEM_add
9101 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
9102 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9103 }
9104 }
9105 }
9106
9107 static void
9108 do_t_adr (void)
9109 {
9110 unsigned Rd;
9111
9112 Rd = inst.operands[0].reg;
9113 reject_bad_reg (Rd);
9114
9115 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
9116 {
9117 /* Defer to section relaxation. */
9118 inst.relax = inst.instruction;
9119 inst.instruction = THUMB_OP16 (inst.instruction);
9120 inst.instruction |= Rd << 4;
9121 }
9122 else if (unified_syntax && inst.size_req != 2)
9123 {
9124 /* Generate a 32-bit opcode. */
9125 inst.instruction = THUMB_OP32 (inst.instruction);
9126 inst.instruction |= Rd << 8;
9127 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
9128 inst.reloc.pc_rel = 1;
9129 }
9130 else
9131 {
9132 /* Generate a 16-bit opcode. */
9133 inst.instruction = THUMB_OP16 (inst.instruction);
9134 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9135 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
9136 inst.reloc.pc_rel = 1;
9137
9138 inst.instruction |= Rd << 4;
9139 }
9140 }
9141
9142 /* Arithmetic instructions for which there is just one 16-bit
9143 instruction encoding, and it allows only two low registers.
9144 For maximal compatibility with ARM syntax, we allow three register
9145 operands even when Thumb-32 instructions are not available, as long
9146 as the first two are identical. For instance, both "sbc r0,r1" and
9147 "sbc r0,r0,r1" are allowed. */
9148 static void
9149 do_t_arit3 (void)
9150 {
9151 int Rd, Rs, Rn;
9152
9153 Rd = inst.operands[0].reg;
9154 Rs = (inst.operands[1].present
9155 ? inst.operands[1].reg /* Rd, Rs, foo */
9156 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9157 Rn = inst.operands[2].reg;
9158
9159 reject_bad_reg (Rd);
9160 reject_bad_reg (Rs);
9161 if (inst.operands[2].isreg)
9162 reject_bad_reg (Rn);
9163
9164 if (unified_syntax)
9165 {
9166 if (!inst.operands[2].isreg)
9167 {
9168 /* For an immediate, we always generate a 32-bit opcode;
9169 section relaxation will shrink it later if possible. */
9170 inst.instruction = THUMB_OP32 (inst.instruction);
9171 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9172 inst.instruction |= Rd << 8;
9173 inst.instruction |= Rs << 16;
9174 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9175 }
9176 else
9177 {
9178 bfd_boolean narrow;
9179
9180 /* See if we can do this with a 16-bit instruction. */
9181 if (THUMB_SETS_FLAGS (inst.instruction))
9182 narrow = !in_it_block ();
9183 else
9184 narrow = in_it_block ();
9185
9186 if (Rd > 7 || Rn > 7 || Rs > 7)
9187 narrow = FALSE;
9188 if (inst.operands[2].shifted)
9189 narrow = FALSE;
9190 if (inst.size_req == 4)
9191 narrow = FALSE;
9192
9193 if (narrow
9194 && Rd == Rs)
9195 {
9196 inst.instruction = THUMB_OP16 (inst.instruction);
9197 inst.instruction |= Rd;
9198 inst.instruction |= Rn << 3;
9199 return;
9200 }
9201
9202 /* If we get here, it can't be done in 16 bits. */
9203 constraint (inst.operands[2].shifted
9204 && inst.operands[2].immisreg,
9205 _("shift must be constant"));
9206 inst.instruction = THUMB_OP32 (inst.instruction);
9207 inst.instruction |= Rd << 8;
9208 inst.instruction |= Rs << 16;
9209 encode_thumb32_shifted_operand (2);
9210 }
9211 }
9212 else
9213 {
9214 /* On its face this is a lie - the instruction does set the
9215 flags. However, the only supported mnemonic in this mode
9216 says it doesn't. */
9217 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9218
9219 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9220 _("unshifted register required"));
9221 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9222 constraint (Rd != Rs,
9223 _("dest and source1 must be the same register"));
9224
9225 inst.instruction = THUMB_OP16 (inst.instruction);
9226 inst.instruction |= Rd;
9227 inst.instruction |= Rn << 3;
9228 }
9229 }
9230
9231 /* Similarly, but for instructions where the arithmetic operation is
9232 commutative, so we can allow either of them to be different from
9233 the destination operand in a 16-bit instruction. For instance, all
9234 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
9235 accepted. */
9236 static void
9237 do_t_arit3c (void)
9238 {
9239 int Rd, Rs, Rn;
9240
9241 Rd = inst.operands[0].reg;
9242 Rs = (inst.operands[1].present
9243 ? inst.operands[1].reg /* Rd, Rs, foo */
9244 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9245 Rn = inst.operands[2].reg;
9246
9247 reject_bad_reg (Rd);
9248 reject_bad_reg (Rs);
9249 if (inst.operands[2].isreg)
9250 reject_bad_reg (Rn);
9251
9252 if (unified_syntax)
9253 {
9254 if (!inst.operands[2].isreg)
9255 {
9256 /* For an immediate, we always generate a 32-bit opcode;
9257 section relaxation will shrink it later if possible. */
9258 inst.instruction = THUMB_OP32 (inst.instruction);
9259 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9260 inst.instruction |= Rd << 8;
9261 inst.instruction |= Rs << 16;
9262 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9263 }
9264 else
9265 {
9266 bfd_boolean narrow;
9267
9268 /* See if we can do this with a 16-bit instruction. */
9269 if (THUMB_SETS_FLAGS (inst.instruction))
9270 narrow = !in_it_block ();
9271 else
9272 narrow = in_it_block ();
9273
9274 if (Rd > 7 || Rn > 7 || Rs > 7)
9275 narrow = FALSE;
9276 if (inst.operands[2].shifted)
9277 narrow = FALSE;
9278 if (inst.size_req == 4)
9279 narrow = FALSE;
9280
9281 if (narrow)
9282 {
9283 if (Rd == Rs)
9284 {
9285 inst.instruction = THUMB_OP16 (inst.instruction);
9286 inst.instruction |= Rd;
9287 inst.instruction |= Rn << 3;
9288 return;
9289 }
9290 if (Rd == Rn)
9291 {
9292 inst.instruction = THUMB_OP16 (inst.instruction);
9293 inst.instruction |= Rd;
9294 inst.instruction |= Rs << 3;
9295 return;
9296 }
9297 }
9298
9299 /* If we get here, it can't be done in 16 bits. */
9300 constraint (inst.operands[2].shifted
9301 && inst.operands[2].immisreg,
9302 _("shift must be constant"));
9303 inst.instruction = THUMB_OP32 (inst.instruction);
9304 inst.instruction |= Rd << 8;
9305 inst.instruction |= Rs << 16;
9306 encode_thumb32_shifted_operand (2);
9307 }
9308 }
9309 else
9310 {
9311 /* On its face this is a lie - the instruction does set the
9312 flags. However, the only supported mnemonic in this mode
9313 says it doesn't. */
9314 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9315
9316 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9317 _("unshifted register required"));
9318 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9319
9320 inst.instruction = THUMB_OP16 (inst.instruction);
9321 inst.instruction |= Rd;
9322
9323 if (Rd == Rs)
9324 inst.instruction |= Rn << 3;
9325 else if (Rd == Rn)
9326 inst.instruction |= Rs << 3;
9327 else
9328 constraint (1, _("dest must overlap one source register"));
9329 }
9330 }
9331
9332 static void
9333 do_t_barrier (void)
9334 {
9335 if (inst.operands[0].present)
9336 {
9337 constraint ((inst.instruction & 0xf0) != 0x40
9338 && inst.operands[0].imm != 0xf,
9339 _("bad barrier type"));
9340 inst.instruction |= inst.operands[0].imm;
9341 }
9342 else
9343 inst.instruction |= 0xf;
9344 }
9345
9346 static void
9347 do_t_bfc (void)
9348 {
9349 unsigned Rd;
9350 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9351 constraint (msb > 32, _("bit-field extends past end of register"));
9352 /* The instruction encoding stores the LSB and MSB,
9353 not the LSB and width. */
9354 Rd = inst.operands[0].reg;
9355 reject_bad_reg (Rd);
9356 inst.instruction |= Rd << 8;
9357 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
9358 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
9359 inst.instruction |= msb - 1;
9360 }
9361
9362 static void
9363 do_t_bfi (void)
9364 {
9365 int Rd, Rn;
9366 unsigned int msb;
9367
9368 Rd = inst.operands[0].reg;
9369 reject_bad_reg (Rd);
9370
9371 /* #0 in second position is alternative syntax for bfc, which is
9372 the same instruction but with REG_PC in the Rm field. */
9373 if (!inst.operands[1].isreg)
9374 Rn = REG_PC;
9375 else
9376 {
9377 Rn = inst.operands[1].reg;
9378 reject_bad_reg (Rn);
9379 }
9380
9381 msb = inst.operands[2].imm + inst.operands[3].imm;
9382 constraint (msb > 32, _("bit-field extends past end of register"));
9383 /* The instruction encoding stores the LSB and MSB,
9384 not the LSB and width. */
9385 inst.instruction |= Rd << 8;
9386 inst.instruction |= Rn << 16;
9387 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9388 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9389 inst.instruction |= msb - 1;
9390 }
9391
9392 static void
9393 do_t_bfx (void)
9394 {
9395 unsigned Rd, Rn;
9396
9397 Rd = inst.operands[0].reg;
9398 Rn = inst.operands[1].reg;
9399
9400 reject_bad_reg (Rd);
9401 reject_bad_reg (Rn);
9402
9403 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9404 _("bit-field extends past end of register"));
9405 inst.instruction |= Rd << 8;
9406 inst.instruction |= Rn << 16;
9407 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9408 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9409 inst.instruction |= inst.operands[3].imm - 1;
9410 }
9411
9412 /* ARM V5 Thumb BLX (argument parse)
9413 BLX <target_addr> which is BLX(1)
9414 BLX <Rm> which is BLX(2)
9415 Unfortunately, there are two different opcodes for this mnemonic.
9416 So, the insns[].value is not used, and the code here zaps values
9417 into inst.instruction.
9418
9419 ??? How to take advantage of the additional two bits of displacement
9420 available in Thumb32 mode? Need new relocation? */
9421
9422 static void
9423 do_t_blx (void)
9424 {
9425 set_it_insn_type_last ();
9426
9427 if (inst.operands[0].isreg)
9428 {
9429 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9430 /* We have a register, so this is BLX(2). */
9431 inst.instruction |= inst.operands[0].reg << 3;
9432 }
9433 else
9434 {
9435 /* No register. This must be BLX(1). */
9436 inst.instruction = 0xf000e800;
9437 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
9438 inst.reloc.pc_rel = 1;
9439 }
9440 }
9441
9442 static void
9443 do_t_branch (void)
9444 {
9445 int opcode;
9446 int cond;
9447
9448 cond = inst.cond;
9449 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
9450
9451 if (in_it_block ())
9452 {
9453 /* Conditional branches inside IT blocks are encoded as unconditional
9454 branches. */
9455 cond = COND_ALWAYS;
9456 }
9457 else
9458 cond = inst.cond;
9459
9460 if (cond != COND_ALWAYS)
9461 opcode = T_MNEM_bcond;
9462 else
9463 opcode = inst.instruction;
9464
9465 if (unified_syntax && inst.size_req == 4)
9466 {
9467 inst.instruction = THUMB_OP32(opcode);
9468 if (cond == COND_ALWAYS)
9469 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
9470 else
9471 {
9472 gas_assert (cond != 0xF);
9473 inst.instruction |= cond << 22;
9474 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
9475 }
9476 }
9477 else
9478 {
9479 inst.instruction = THUMB_OP16(opcode);
9480 if (cond == COND_ALWAYS)
9481 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
9482 else
9483 {
9484 inst.instruction |= cond << 8;
9485 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
9486 }
9487 /* Allow section relaxation. */
9488 if (unified_syntax && inst.size_req != 2)
9489 inst.relax = opcode;
9490 }
9491
9492 inst.reloc.pc_rel = 1;
9493 }
9494
9495 static void
9496 do_t_bkpt (void)
9497 {
9498 constraint (inst.cond != COND_ALWAYS,
9499 _("instruction is always unconditional"));
9500 if (inst.operands[0].present)
9501 {
9502 constraint (inst.operands[0].imm > 255,
9503 _("immediate value out of range"));
9504 inst.instruction |= inst.operands[0].imm;
9505 set_it_insn_type (NEUTRAL_IT_INSN);
9506 }
9507 }
9508
9509 static void
9510 do_t_branch23 (void)
9511 {
9512 set_it_insn_type_last ();
9513 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
9514 inst.reloc.pc_rel = 1;
9515
9516 #if defined(OBJ_COFF)
9517 /* If the destination of the branch is a defined symbol which does not have
9518 the THUMB_FUNC attribute, then we must be calling a function which has
9519 the (interfacearm) attribute. We look for the Thumb entry point to that
9520 function and change the branch to refer to that function instead. */
9521 if ( inst.reloc.exp.X_op == O_symbol
9522 && inst.reloc.exp.X_add_symbol != NULL
9523 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
9524 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
9525 inst.reloc.exp.X_add_symbol =
9526 find_real_start (inst.reloc.exp.X_add_symbol);
9527 #endif
9528 }
9529
9530 static void
9531 do_t_bx (void)
9532 {
9533 set_it_insn_type_last ();
9534 inst.instruction |= inst.operands[0].reg << 3;
9535 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
9536 should cause the alignment to be checked once it is known. This is
9537 because BX PC only works if the instruction is word aligned. */
9538 }
9539
9540 static void
9541 do_t_bxj (void)
9542 {
9543 int Rm;
9544
9545 set_it_insn_type_last ();
9546 Rm = inst.operands[0].reg;
9547 reject_bad_reg (Rm);
9548 inst.instruction |= Rm << 16;
9549 }
9550
9551 static void
9552 do_t_clz (void)
9553 {
9554 unsigned Rd;
9555 unsigned Rm;
9556
9557 Rd = inst.operands[0].reg;
9558 Rm = inst.operands[1].reg;
9559
9560 reject_bad_reg (Rd);
9561 reject_bad_reg (Rm);
9562
9563 inst.instruction |= Rd << 8;
9564 inst.instruction |= Rm << 16;
9565 inst.instruction |= Rm;
9566 }
9567
9568 static void
9569 do_t_cps (void)
9570 {
9571 set_it_insn_type (OUTSIDE_IT_INSN);
9572 inst.instruction |= inst.operands[0].imm;
9573 }
9574
9575 static void
9576 do_t_cpsi (void)
9577 {
9578 set_it_insn_type (OUTSIDE_IT_INSN);
9579 if (unified_syntax
9580 && (inst.operands[1].present || inst.size_req == 4)
9581 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
9582 {
9583 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9584 inst.instruction = 0xf3af8000;
9585 inst.instruction |= imod << 9;
9586 inst.instruction |= inst.operands[0].imm << 5;
9587 if (inst.operands[1].present)
9588 inst.instruction |= 0x100 | inst.operands[1].imm;
9589 }
9590 else
9591 {
9592 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9593 && (inst.operands[0].imm & 4),
9594 _("selected processor does not support 'A' form "
9595 "of this instruction"));
9596 constraint (inst.operands[1].present || inst.size_req == 4,
9597 _("Thumb does not support the 2-argument "
9598 "form of this instruction"));
9599 inst.instruction |= inst.operands[0].imm;
9600 }
9601 }
9602
9603 /* THUMB CPY instruction (argument parse). */
9604
9605 static void
9606 do_t_cpy (void)
9607 {
9608 if (inst.size_req == 4)
9609 {
9610 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9611 inst.instruction |= inst.operands[0].reg << 8;
9612 inst.instruction |= inst.operands[1].reg;
9613 }
9614 else
9615 {
9616 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9617 inst.instruction |= (inst.operands[0].reg & 0x7);
9618 inst.instruction |= inst.operands[1].reg << 3;
9619 }
9620 }
9621
9622 static void
9623 do_t_cbz (void)
9624 {
9625 set_it_insn_type (OUTSIDE_IT_INSN);
9626 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9627 inst.instruction |= inst.operands[0].reg;
9628 inst.reloc.pc_rel = 1;
9629 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9630 }
9631
9632 static void
9633 do_t_dbg (void)
9634 {
9635 inst.instruction |= inst.operands[0].imm;
9636 }
9637
9638 static void
9639 do_t_div (void)
9640 {
9641 unsigned Rd, Rn, Rm;
9642
9643 Rd = inst.operands[0].reg;
9644 Rn = (inst.operands[1].present
9645 ? inst.operands[1].reg : Rd);
9646 Rm = inst.operands[2].reg;
9647
9648 reject_bad_reg (Rd);
9649 reject_bad_reg (Rn);
9650 reject_bad_reg (Rm);
9651
9652 inst.instruction |= Rd << 8;
9653 inst.instruction |= Rn << 16;
9654 inst.instruction |= Rm;
9655 }
9656
9657 static void
9658 do_t_hint (void)
9659 {
9660 if (unified_syntax && inst.size_req == 4)
9661 inst.instruction = THUMB_OP32 (inst.instruction);
9662 else
9663 inst.instruction = THUMB_OP16 (inst.instruction);
9664 }
9665
9666 static void
9667 do_t_it (void)
9668 {
9669 unsigned int cond = inst.operands[0].imm;
9670
9671 set_it_insn_type (IT_INSN);
9672 now_it.mask = (inst.instruction & 0xf) | 0x10;
9673 now_it.cc = cond;
9674
9675 /* If the condition is a negative condition, invert the mask. */
9676 if ((cond & 0x1) == 0x0)
9677 {
9678 unsigned int mask = inst.instruction & 0x000f;
9679
9680 if ((mask & 0x7) == 0)
9681 /* no conversion needed */;
9682 else if ((mask & 0x3) == 0)
9683 mask ^= 0x8;
9684 else if ((mask & 0x1) == 0)
9685 mask ^= 0xC;
9686 else
9687 mask ^= 0xE;
9688
9689 inst.instruction &= 0xfff0;
9690 inst.instruction |= mask;
9691 }
9692
9693 inst.instruction |= cond << 4;
9694 }
9695
9696 /* Helper function used for both push/pop and ldm/stm. */
9697 static void
9698 encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9699 {
9700 bfd_boolean load;
9701
9702 load = (inst.instruction & (1 << 20)) != 0;
9703
9704 if (mask & (1 << 13))
9705 inst.error = _("SP not allowed in register list");
9706 if (load)
9707 {
9708 if (mask & (1 << 15))
9709 {
9710 if (mask & (1 << 14))
9711 inst.error = _("LR and PC should not both be in register list");
9712 else
9713 set_it_insn_type_last ();
9714 }
9715
9716 if ((mask & (1 << base)) != 0
9717 && writeback)
9718 as_warn (_("base register should not be in register list "
9719 "when written back"));
9720 }
9721 else
9722 {
9723 if (mask & (1 << 15))
9724 inst.error = _("PC not allowed in register list");
9725
9726 if (mask & (1 << base))
9727 as_warn (_("value stored for r%d is UNPREDICTABLE"), base);
9728 }
9729
9730 if ((mask & (mask - 1)) == 0)
9731 {
9732 /* Single register transfers implemented as str/ldr. */
9733 if (writeback)
9734 {
9735 if (inst.instruction & (1 << 23))
9736 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9737 else
9738 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9739 }
9740 else
9741 {
9742 if (inst.instruction & (1 << 23))
9743 inst.instruction = 0x00800000; /* ia -> [base] */
9744 else
9745 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9746 }
9747
9748 inst.instruction |= 0xf8400000;
9749 if (load)
9750 inst.instruction |= 0x00100000;
9751
9752 mask = ffs (mask) - 1;
9753 mask <<= 12;
9754 }
9755 else if (writeback)
9756 inst.instruction |= WRITE_BACK;
9757
9758 inst.instruction |= mask;
9759 inst.instruction |= base << 16;
9760 }
9761
9762 static void
9763 do_t_ldmstm (void)
9764 {
9765 /* This really doesn't seem worth it. */
9766 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9767 _("expression too complex"));
9768 constraint (inst.operands[1].writeback,
9769 _("Thumb load/store multiple does not support {reglist}^"));
9770
9771 if (unified_syntax)
9772 {
9773 bfd_boolean narrow;
9774 unsigned mask;
9775
9776 narrow = FALSE;
9777 /* See if we can use a 16-bit instruction. */
9778 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9779 && inst.size_req != 4
9780 && !(inst.operands[1].imm & ~0xff))
9781 {
9782 mask = 1 << inst.operands[0].reg;
9783
9784 if (inst.operands[0].reg <= 7
9785 && (inst.instruction == T_MNEM_stmia
9786 ? inst.operands[0].writeback
9787 : (inst.operands[0].writeback
9788 == !(inst.operands[1].imm & mask))))
9789 {
9790 if (inst.instruction == T_MNEM_stmia
9791 && (inst.operands[1].imm & mask)
9792 && (inst.operands[1].imm & (mask - 1)))
9793 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9794 inst.operands[0].reg);
9795
9796 inst.instruction = THUMB_OP16 (inst.instruction);
9797 inst.instruction |= inst.operands[0].reg << 8;
9798 inst.instruction |= inst.operands[1].imm;
9799 narrow = TRUE;
9800 }
9801 else if (inst.operands[0] .reg == REG_SP
9802 && inst.operands[0].writeback)
9803 {
9804 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9805 ? T_MNEM_push : T_MNEM_pop);
9806 inst.instruction |= inst.operands[1].imm;
9807 narrow = TRUE;
9808 }
9809 }
9810
9811 if (!narrow)
9812 {
9813 if (inst.instruction < 0xffff)
9814 inst.instruction = THUMB_OP32 (inst.instruction);
9815
9816 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
9817 inst.operands[0].writeback);
9818 }
9819 }
9820 else
9821 {
9822 constraint (inst.operands[0].reg > 7
9823 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
9824 constraint (inst.instruction != T_MNEM_ldmia
9825 && inst.instruction != T_MNEM_stmia,
9826 _("Thumb-2 instruction only valid in unified syntax"));
9827 if (inst.instruction == T_MNEM_stmia)
9828 {
9829 if (!inst.operands[0].writeback)
9830 as_warn (_("this instruction will write back the base register"));
9831 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9832 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9833 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9834 inst.operands[0].reg);
9835 }
9836 else
9837 {
9838 if (!inst.operands[0].writeback
9839 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9840 as_warn (_("this instruction will write back the base register"));
9841 else if (inst.operands[0].writeback
9842 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9843 as_warn (_("this instruction will not write back the base register"));
9844 }
9845
9846 inst.instruction = THUMB_OP16 (inst.instruction);
9847 inst.instruction |= inst.operands[0].reg << 8;
9848 inst.instruction |= inst.operands[1].imm;
9849 }
9850 }
9851
9852 static void
9853 do_t_ldrex (void)
9854 {
9855 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9856 || inst.operands[1].postind || inst.operands[1].writeback
9857 || inst.operands[1].immisreg || inst.operands[1].shifted
9858 || inst.operands[1].negative,
9859 BAD_ADDR_MODE);
9860
9861 inst.instruction |= inst.operands[0].reg << 12;
9862 inst.instruction |= inst.operands[1].reg << 16;
9863 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9864 }
9865
9866 static void
9867 do_t_ldrexd (void)
9868 {
9869 if (!inst.operands[1].present)
9870 {
9871 constraint (inst.operands[0].reg == REG_LR,
9872 _("r14 not allowed as first register "
9873 "when second register is omitted"));
9874 inst.operands[1].reg = inst.operands[0].reg + 1;
9875 }
9876 constraint (inst.operands[0].reg == inst.operands[1].reg,
9877 BAD_OVERLAP);
9878
9879 inst.instruction |= inst.operands[0].reg << 12;
9880 inst.instruction |= inst.operands[1].reg << 8;
9881 inst.instruction |= inst.operands[2].reg << 16;
9882 }
9883
9884 static void
9885 do_t_ldst (void)
9886 {
9887 unsigned long opcode;
9888 int Rn;
9889
9890 if (inst.operands[0].isreg
9891 && !inst.operands[0].preind
9892 && inst.operands[0].reg == REG_PC)
9893 set_it_insn_type_last ();
9894
9895 opcode = inst.instruction;
9896 if (unified_syntax)
9897 {
9898 if (!inst.operands[1].isreg)
9899 {
9900 if (opcode <= 0xffff)
9901 inst.instruction = THUMB_OP32 (opcode);
9902 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9903 return;
9904 }
9905 if (inst.operands[1].isreg
9906 && !inst.operands[1].writeback
9907 && !inst.operands[1].shifted && !inst.operands[1].postind
9908 && !inst.operands[1].negative && inst.operands[0].reg <= 7
9909 && opcode <= 0xffff
9910 && inst.size_req != 4)
9911 {
9912 /* Insn may have a 16-bit form. */
9913 Rn = inst.operands[1].reg;
9914 if (inst.operands[1].immisreg)
9915 {
9916 inst.instruction = THUMB_OP16 (opcode);
9917 /* [Rn, Rik] */
9918 if (Rn <= 7 && inst.operands[1].imm <= 7)
9919 goto op16;
9920 }
9921 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9922 && opcode != T_MNEM_ldrsb)
9923 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9924 || (Rn == REG_SP && opcode == T_MNEM_str))
9925 {
9926 /* [Rn, #const] */
9927 if (Rn > 7)
9928 {
9929 if (Rn == REG_PC)
9930 {
9931 if (inst.reloc.pc_rel)
9932 opcode = T_MNEM_ldr_pc2;
9933 else
9934 opcode = T_MNEM_ldr_pc;
9935 }
9936 else
9937 {
9938 if (opcode == T_MNEM_ldr)
9939 opcode = T_MNEM_ldr_sp;
9940 else
9941 opcode = T_MNEM_str_sp;
9942 }
9943 inst.instruction = inst.operands[0].reg << 8;
9944 }
9945 else
9946 {
9947 inst.instruction = inst.operands[0].reg;
9948 inst.instruction |= inst.operands[1].reg << 3;
9949 }
9950 inst.instruction |= THUMB_OP16 (opcode);
9951 if (inst.size_req == 2)
9952 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9953 else
9954 inst.relax = opcode;
9955 return;
9956 }
9957 }
9958 /* Definitely a 32-bit variant. */
9959 inst.instruction = THUMB_OP32 (opcode);
9960 inst.instruction |= inst.operands[0].reg << 12;
9961 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
9962 return;
9963 }
9964
9965 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9966
9967 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
9968 {
9969 /* Only [Rn,Rm] is acceptable. */
9970 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
9971 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
9972 || inst.operands[1].postind || inst.operands[1].shifted
9973 || inst.operands[1].negative,
9974 _("Thumb does not support this addressing mode"));
9975 inst.instruction = THUMB_OP16 (inst.instruction);
9976 goto op16;
9977 }
9978
9979 inst.instruction = THUMB_OP16 (inst.instruction);
9980 if (!inst.operands[1].isreg)
9981 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9982 return;
9983
9984 constraint (!inst.operands[1].preind
9985 || inst.operands[1].shifted
9986 || inst.operands[1].writeback,
9987 _("Thumb does not support this addressing mode"));
9988 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
9989 {
9990 constraint (inst.instruction & 0x0600,
9991 _("byte or halfword not valid for base register"));
9992 constraint (inst.operands[1].reg == REG_PC
9993 && !(inst.instruction & THUMB_LOAD_BIT),
9994 _("r15 based store not allowed"));
9995 constraint (inst.operands[1].immisreg,
9996 _("invalid base register for register offset"));
9997
9998 if (inst.operands[1].reg == REG_PC)
9999 inst.instruction = T_OPCODE_LDR_PC;
10000 else if (inst.instruction & THUMB_LOAD_BIT)
10001 inst.instruction = T_OPCODE_LDR_SP;
10002 else
10003 inst.instruction = T_OPCODE_STR_SP;
10004
10005 inst.instruction |= inst.operands[0].reg << 8;
10006 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10007 return;
10008 }
10009
10010 constraint (inst.operands[1].reg > 7, BAD_HIREG);
10011 if (!inst.operands[1].immisreg)
10012 {
10013 /* Immediate offset. */
10014 inst.instruction |= inst.operands[0].reg;
10015 inst.instruction |= inst.operands[1].reg << 3;
10016 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10017 return;
10018 }
10019
10020 /* Register offset. */
10021 constraint (inst.operands[1].imm > 7, BAD_HIREG);
10022 constraint (inst.operands[1].negative,
10023 _("Thumb does not support this addressing mode"));
10024
10025 op16:
10026 switch (inst.instruction)
10027 {
10028 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
10029 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
10030 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
10031 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
10032 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
10033 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
10034 case 0x5600 /* ldrsb */:
10035 case 0x5e00 /* ldrsh */: break;
10036 default: abort ();
10037 }
10038
10039 inst.instruction |= inst.operands[0].reg;
10040 inst.instruction |= inst.operands[1].reg << 3;
10041 inst.instruction |= inst.operands[1].imm << 6;
10042 }
10043
10044 static void
10045 do_t_ldstd (void)
10046 {
10047 if (!inst.operands[1].present)
10048 {
10049 inst.operands[1].reg = inst.operands[0].reg + 1;
10050 constraint (inst.operands[0].reg == REG_LR,
10051 _("r14 not allowed here"));
10052 }
10053 inst.instruction |= inst.operands[0].reg << 12;
10054 inst.instruction |= inst.operands[1].reg << 8;
10055 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
10056 }
10057
10058 static void
10059 do_t_ldstt (void)
10060 {
10061 inst.instruction |= inst.operands[0].reg << 12;
10062 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
10063 }
10064
10065 static void
10066 do_t_mla (void)
10067 {
10068 unsigned Rd, Rn, Rm, Ra;
10069
10070 Rd = inst.operands[0].reg;
10071 Rn = inst.operands[1].reg;
10072 Rm = inst.operands[2].reg;
10073 Ra = inst.operands[3].reg;
10074
10075 reject_bad_reg (Rd);
10076 reject_bad_reg (Rn);
10077 reject_bad_reg (Rm);
10078 reject_bad_reg (Ra);
10079
10080 inst.instruction |= Rd << 8;
10081 inst.instruction |= Rn << 16;
10082 inst.instruction |= Rm;
10083 inst.instruction |= Ra << 12;
10084 }
10085
10086 static void
10087 do_t_mlal (void)
10088 {
10089 unsigned RdLo, RdHi, Rn, Rm;
10090
10091 RdLo = inst.operands[0].reg;
10092 RdHi = inst.operands[1].reg;
10093 Rn = inst.operands[2].reg;
10094 Rm = inst.operands[3].reg;
10095
10096 reject_bad_reg (RdLo);
10097 reject_bad_reg (RdHi);
10098 reject_bad_reg (Rn);
10099 reject_bad_reg (Rm);
10100
10101 inst.instruction |= RdLo << 12;
10102 inst.instruction |= RdHi << 8;
10103 inst.instruction |= Rn << 16;
10104 inst.instruction |= Rm;
10105 }
10106
10107 static void
10108 do_t_mov_cmp (void)
10109 {
10110 unsigned Rn, Rm;
10111
10112 Rn = inst.operands[0].reg;
10113 Rm = inst.operands[1].reg;
10114
10115 if (Rn == REG_PC)
10116 set_it_insn_type_last ();
10117
10118 if (unified_syntax)
10119 {
10120 int r0off = (inst.instruction == T_MNEM_mov
10121 || inst.instruction == T_MNEM_movs) ? 8 : 16;
10122 unsigned long opcode;
10123 bfd_boolean narrow;
10124 bfd_boolean low_regs;
10125
10126 low_regs = (Rn <= 7 && Rm <= 7);
10127 opcode = inst.instruction;
10128 if (in_it_block ())
10129 narrow = opcode != T_MNEM_movs;
10130 else
10131 narrow = opcode != T_MNEM_movs || low_regs;
10132 if (inst.size_req == 4
10133 || inst.operands[1].shifted)
10134 narrow = FALSE;
10135
10136 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
10137 if (opcode == T_MNEM_movs && inst.operands[1].isreg
10138 && !inst.operands[1].shifted
10139 && Rn == REG_PC
10140 && Rm == REG_LR)
10141 {
10142 inst.instruction = T2_SUBS_PC_LR;
10143 return;
10144 }
10145
10146 if (opcode == T_MNEM_cmp)
10147 {
10148 constraint (Rn == REG_PC, BAD_PC);
10149 if (narrow)
10150 {
10151 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
10152 but valid. */
10153 warn_deprecated_sp (Rm);
10154 /* R15 was documented as a valid choice for Rm in ARMv6,
10155 but as UNPREDICTABLE in ARMv7. ARM's proprietary
10156 tools reject R15, so we do too. */
10157 constraint (Rm == REG_PC, BAD_PC);
10158 }
10159 else
10160 reject_bad_reg (Rm);
10161 }
10162 else if (opcode == T_MNEM_mov
10163 || opcode == T_MNEM_movs)
10164 {
10165 if (inst.operands[1].isreg)
10166 {
10167 if (opcode == T_MNEM_movs)
10168 {
10169 reject_bad_reg (Rn);
10170 reject_bad_reg (Rm);
10171 }
10172 else if ((Rn == REG_SP || Rn == REG_PC)
10173 && (Rm == REG_SP || Rm == REG_PC))
10174 reject_bad_reg (Rm);
10175 }
10176 else
10177 reject_bad_reg (Rn);
10178 }
10179
10180 if (!inst.operands[1].isreg)
10181 {
10182 /* Immediate operand. */
10183 if (!in_it_block () && opcode == T_MNEM_mov)
10184 narrow = 0;
10185 if (low_regs && narrow)
10186 {
10187 inst.instruction = THUMB_OP16 (opcode);
10188 inst.instruction |= Rn << 8;
10189 if (inst.size_req == 2)
10190 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10191 else
10192 inst.relax = opcode;
10193 }
10194 else
10195 {
10196 inst.instruction = THUMB_OP32 (inst.instruction);
10197 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10198 inst.instruction |= Rn << r0off;
10199 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10200 }
10201 }
10202 else if (inst.operands[1].shifted && inst.operands[1].immisreg
10203 && (inst.instruction == T_MNEM_mov
10204 || inst.instruction == T_MNEM_movs))
10205 {
10206 /* Register shifts are encoded as separate shift instructions. */
10207 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
10208
10209 if (in_it_block ())
10210 narrow = !flags;
10211 else
10212 narrow = flags;
10213
10214 if (inst.size_req == 4)
10215 narrow = FALSE;
10216
10217 if (!low_regs || inst.operands[1].imm > 7)
10218 narrow = FALSE;
10219
10220 if (Rn != Rm)
10221 narrow = FALSE;
10222
10223 switch (inst.operands[1].shift_kind)
10224 {
10225 case SHIFT_LSL:
10226 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
10227 break;
10228 case SHIFT_ASR:
10229 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
10230 break;
10231 case SHIFT_LSR:
10232 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
10233 break;
10234 case SHIFT_ROR:
10235 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
10236 break;
10237 default:
10238 abort ();
10239 }
10240
10241 inst.instruction = opcode;
10242 if (narrow)
10243 {
10244 inst.instruction |= Rn;
10245 inst.instruction |= inst.operands[1].imm << 3;
10246 }
10247 else
10248 {
10249 if (flags)
10250 inst.instruction |= CONDS_BIT;
10251
10252 inst.instruction |= Rn << 8;
10253 inst.instruction |= Rm << 16;
10254 inst.instruction |= inst.operands[1].imm;
10255 }
10256 }
10257 else if (!narrow)
10258 {
10259 /* Some mov with immediate shift have narrow variants.
10260 Register shifts are handled above. */
10261 if (low_regs && inst.operands[1].shifted
10262 && (inst.instruction == T_MNEM_mov
10263 || inst.instruction == T_MNEM_movs))
10264 {
10265 if (in_it_block ())
10266 narrow = (inst.instruction == T_MNEM_mov);
10267 else
10268 narrow = (inst.instruction == T_MNEM_movs);
10269 }
10270
10271 if (narrow)
10272 {
10273 switch (inst.operands[1].shift_kind)
10274 {
10275 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10276 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10277 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10278 default: narrow = FALSE; break;
10279 }
10280 }
10281
10282 if (narrow)
10283 {
10284 inst.instruction |= Rn;
10285 inst.instruction |= Rm << 3;
10286 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10287 }
10288 else
10289 {
10290 inst.instruction = THUMB_OP32 (inst.instruction);
10291 inst.instruction |= Rn << r0off;
10292 encode_thumb32_shifted_operand (1);
10293 }
10294 }
10295 else
10296 switch (inst.instruction)
10297 {
10298 case T_MNEM_mov:
10299 inst.instruction = T_OPCODE_MOV_HR;
10300 inst.instruction |= (Rn & 0x8) << 4;
10301 inst.instruction |= (Rn & 0x7);
10302 inst.instruction |= Rm << 3;
10303 break;
10304
10305 case T_MNEM_movs:
10306 /* We know we have low registers at this point.
10307 Generate ADD Rd, Rs, #0. */
10308 inst.instruction = T_OPCODE_ADD_I3;
10309 inst.instruction |= Rn;
10310 inst.instruction |= Rm << 3;
10311 break;
10312
10313 case T_MNEM_cmp:
10314 if (low_regs)
10315 {
10316 inst.instruction = T_OPCODE_CMP_LR;
10317 inst.instruction |= Rn;
10318 inst.instruction |= Rm << 3;
10319 }
10320 else
10321 {
10322 inst.instruction = T_OPCODE_CMP_HR;
10323 inst.instruction |= (Rn & 0x8) << 4;
10324 inst.instruction |= (Rn & 0x7);
10325 inst.instruction |= Rm << 3;
10326 }
10327 break;
10328 }
10329 return;
10330 }
10331
10332 inst.instruction = THUMB_OP16 (inst.instruction);
10333
10334 /* PR 10443: Do not silently ignore shifted operands. */
10335 constraint (inst.operands[1].shifted,
10336 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
10337
10338 if (inst.operands[1].isreg)
10339 {
10340 if (Rn < 8 && Rm < 8)
10341 {
10342 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
10343 since a MOV instruction produces unpredictable results. */
10344 if (inst.instruction == T_OPCODE_MOV_I8)
10345 inst.instruction = T_OPCODE_ADD_I3;
10346 else
10347 inst.instruction = T_OPCODE_CMP_LR;
10348
10349 inst.instruction |= Rn;
10350 inst.instruction |= Rm << 3;
10351 }
10352 else
10353 {
10354 if (inst.instruction == T_OPCODE_MOV_I8)
10355 inst.instruction = T_OPCODE_MOV_HR;
10356 else
10357 inst.instruction = T_OPCODE_CMP_HR;
10358 do_t_cpy ();
10359 }
10360 }
10361 else
10362 {
10363 constraint (Rn > 7,
10364 _("only lo regs allowed with immediate"));
10365 inst.instruction |= Rn << 8;
10366 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10367 }
10368 }
10369
10370 static void
10371 do_t_mov16 (void)
10372 {
10373 unsigned Rd;
10374 bfd_vma imm;
10375 bfd_boolean top;
10376
10377 top = (inst.instruction & 0x00800000) != 0;
10378 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
10379 {
10380 constraint (top, _(":lower16: not allowed this instruction"));
10381 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
10382 }
10383 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
10384 {
10385 constraint (!top, _(":upper16: not allowed this instruction"));
10386 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
10387 }
10388
10389 Rd = inst.operands[0].reg;
10390 reject_bad_reg (Rd);
10391
10392 inst.instruction |= Rd << 8;
10393 if (inst.reloc.type == BFD_RELOC_UNUSED)
10394 {
10395 imm = inst.reloc.exp.X_add_number;
10396 inst.instruction |= (imm & 0xf000) << 4;
10397 inst.instruction |= (imm & 0x0800) << 15;
10398 inst.instruction |= (imm & 0x0700) << 4;
10399 inst.instruction |= (imm & 0x00ff);
10400 }
10401 }
10402
10403 static void
10404 do_t_mvn_tst (void)
10405 {
10406 unsigned Rn, Rm;
10407
10408 Rn = inst.operands[0].reg;
10409 Rm = inst.operands[1].reg;
10410
10411 if (inst.instruction == T_MNEM_cmp
10412 || inst.instruction == T_MNEM_cmn)
10413 constraint (Rn == REG_PC, BAD_PC);
10414 else
10415 reject_bad_reg (Rn);
10416 reject_bad_reg (Rm);
10417
10418 if (unified_syntax)
10419 {
10420 int r0off = (inst.instruction == T_MNEM_mvn
10421 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
10422 bfd_boolean narrow;
10423
10424 if (inst.size_req == 4
10425 || inst.instruction > 0xffff
10426 || inst.operands[1].shifted
10427 || Rn > 7 || Rm > 7)
10428 narrow = FALSE;
10429 else if (inst.instruction == T_MNEM_cmn)
10430 narrow = TRUE;
10431 else if (THUMB_SETS_FLAGS (inst.instruction))
10432 narrow = !in_it_block ();
10433 else
10434 narrow = in_it_block ();
10435
10436 if (!inst.operands[1].isreg)
10437 {
10438 /* For an immediate, we always generate a 32-bit opcode;
10439 section relaxation will shrink it later if possible. */
10440 if (inst.instruction < 0xffff)
10441 inst.instruction = THUMB_OP32 (inst.instruction);
10442 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10443 inst.instruction |= Rn << r0off;
10444 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10445 }
10446 else
10447 {
10448 /* See if we can do this with a 16-bit instruction. */
10449 if (narrow)
10450 {
10451 inst.instruction = THUMB_OP16 (inst.instruction);
10452 inst.instruction |= Rn;
10453 inst.instruction |= Rm << 3;
10454 }
10455 else
10456 {
10457 constraint (inst.operands[1].shifted
10458 && inst.operands[1].immisreg,
10459 _("shift must be constant"));
10460 if (inst.instruction < 0xffff)
10461 inst.instruction = THUMB_OP32 (inst.instruction);
10462 inst.instruction |= Rn << r0off;
10463 encode_thumb32_shifted_operand (1);
10464 }
10465 }
10466 }
10467 else
10468 {
10469 constraint (inst.instruction > 0xffff
10470 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
10471 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
10472 _("unshifted register required"));
10473 constraint (Rn > 7 || Rm > 7,
10474 BAD_HIREG);
10475
10476 inst.instruction = THUMB_OP16 (inst.instruction);
10477 inst.instruction |= Rn;
10478 inst.instruction |= Rm << 3;
10479 }
10480 }
10481
10482 static void
10483 do_t_mrs (void)
10484 {
10485 unsigned Rd;
10486 int flags;
10487
10488 if (do_vfp_nsyn_mrs () == SUCCESS)
10489 return;
10490
10491 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
10492 if (flags == 0)
10493 {
10494 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
10495 _("selected processor does not support "
10496 "requested special purpose register"));
10497 }
10498 else
10499 {
10500 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10501 _("selected processor does not support "
10502 "requested special purpose register"));
10503 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10504 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
10505 _("'CPSR' or 'SPSR' expected"));
10506 }
10507
10508 Rd = inst.operands[0].reg;
10509 reject_bad_reg (Rd);
10510
10511 inst.instruction |= Rd << 8;
10512 inst.instruction |= (flags & SPSR_BIT) >> 2;
10513 inst.instruction |= inst.operands[1].imm & 0xff;
10514 }
10515
10516 static void
10517 do_t_msr (void)
10518 {
10519 int flags;
10520 unsigned Rn;
10521
10522 if (do_vfp_nsyn_msr () == SUCCESS)
10523 return;
10524
10525 constraint (!inst.operands[1].isreg,
10526 _("Thumb encoding does not support an immediate here"));
10527 flags = inst.operands[0].imm;
10528 if (flags & ~0xff)
10529 {
10530 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10531 _("selected processor does not support "
10532 "requested special purpose register"));
10533 }
10534 else
10535 {
10536 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
10537 _("selected processor does not support "
10538 "requested special purpose register"));
10539 flags |= PSR_f;
10540 }
10541
10542 Rn = inst.operands[1].reg;
10543 reject_bad_reg (Rn);
10544
10545 inst.instruction |= (flags & SPSR_BIT) >> 2;
10546 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
10547 inst.instruction |= (flags & 0xff);
10548 inst.instruction |= Rn << 16;
10549 }
10550
10551 static void
10552 do_t_mul (void)
10553 {
10554 bfd_boolean narrow;
10555 unsigned Rd, Rn, Rm;
10556
10557 if (!inst.operands[2].present)
10558 inst.operands[2].reg = inst.operands[0].reg;
10559
10560 Rd = inst.operands[0].reg;
10561 Rn = inst.operands[1].reg;
10562 Rm = inst.operands[2].reg;
10563
10564 if (unified_syntax)
10565 {
10566 if (inst.size_req == 4
10567 || (Rd != Rn
10568 && Rd != Rm)
10569 || Rn > 7
10570 || Rm > 7)
10571 narrow = FALSE;
10572 else if (inst.instruction == T_MNEM_muls)
10573 narrow = !in_it_block ();
10574 else
10575 narrow = in_it_block ();
10576 }
10577 else
10578 {
10579 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
10580 constraint (Rn > 7 || Rm > 7,
10581 BAD_HIREG);
10582 narrow = TRUE;
10583 }
10584
10585 if (narrow)
10586 {
10587 /* 16-bit MULS/Conditional MUL. */
10588 inst.instruction = THUMB_OP16 (inst.instruction);
10589 inst.instruction |= Rd;
10590
10591 if (Rd == Rn)
10592 inst.instruction |= Rm << 3;
10593 else if (Rd == Rm)
10594 inst.instruction |= Rn << 3;
10595 else
10596 constraint (1, _("dest must overlap one source register"));
10597 }
10598 else
10599 {
10600 constraint (inst.instruction != T_MNEM_mul,
10601 _("Thumb-2 MUL must not set flags"));
10602 /* 32-bit MUL. */
10603 inst.instruction = THUMB_OP32 (inst.instruction);
10604 inst.instruction |= Rd << 8;
10605 inst.instruction |= Rn << 16;
10606 inst.instruction |= Rm << 0;
10607
10608 reject_bad_reg (Rd);
10609 reject_bad_reg (Rn);
10610 reject_bad_reg (Rm);
10611 }
10612 }
10613
10614 static void
10615 do_t_mull (void)
10616 {
10617 unsigned RdLo, RdHi, Rn, Rm;
10618
10619 RdLo = inst.operands[0].reg;
10620 RdHi = inst.operands[1].reg;
10621 Rn = inst.operands[2].reg;
10622 Rm = inst.operands[3].reg;
10623
10624 reject_bad_reg (RdLo);
10625 reject_bad_reg (RdHi);
10626 reject_bad_reg (Rn);
10627 reject_bad_reg (Rm);
10628
10629 inst.instruction |= RdLo << 12;
10630 inst.instruction |= RdHi << 8;
10631 inst.instruction |= Rn << 16;
10632 inst.instruction |= Rm;
10633
10634 if (RdLo == RdHi)
10635 as_tsktsk (_("rdhi and rdlo must be different"));
10636 }
10637
10638 static void
10639 do_t_nop (void)
10640 {
10641 set_it_insn_type (NEUTRAL_IT_INSN);
10642
10643 if (unified_syntax)
10644 {
10645 if (inst.size_req == 4 || inst.operands[0].imm > 15)
10646 {
10647 inst.instruction = THUMB_OP32 (inst.instruction);
10648 inst.instruction |= inst.operands[0].imm;
10649 }
10650 else
10651 {
10652 /* PR9722: Check for Thumb2 availability before
10653 generating a thumb2 nop instruction. */
10654 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
10655 {
10656 inst.instruction = THUMB_OP16 (inst.instruction);
10657 inst.instruction |= inst.operands[0].imm << 4;
10658 }
10659 else
10660 inst.instruction = 0x46c0;
10661 }
10662 }
10663 else
10664 {
10665 constraint (inst.operands[0].present,
10666 _("Thumb does not support NOP with hints"));
10667 inst.instruction = 0x46c0;
10668 }
10669 }
10670
10671 static void
10672 do_t_neg (void)
10673 {
10674 if (unified_syntax)
10675 {
10676 bfd_boolean narrow;
10677
10678 if (THUMB_SETS_FLAGS (inst.instruction))
10679 narrow = !in_it_block ();
10680 else
10681 narrow = in_it_block ();
10682 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10683 narrow = FALSE;
10684 if (inst.size_req == 4)
10685 narrow = FALSE;
10686
10687 if (!narrow)
10688 {
10689 inst.instruction = THUMB_OP32 (inst.instruction);
10690 inst.instruction |= inst.operands[0].reg << 8;
10691 inst.instruction |= inst.operands[1].reg << 16;
10692 }
10693 else
10694 {
10695 inst.instruction = THUMB_OP16 (inst.instruction);
10696 inst.instruction |= inst.operands[0].reg;
10697 inst.instruction |= inst.operands[1].reg << 3;
10698 }
10699 }
10700 else
10701 {
10702 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
10703 BAD_HIREG);
10704 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10705
10706 inst.instruction = THUMB_OP16 (inst.instruction);
10707 inst.instruction |= inst.operands[0].reg;
10708 inst.instruction |= inst.operands[1].reg << 3;
10709 }
10710 }
10711
10712 static void
10713 do_t_orn (void)
10714 {
10715 unsigned Rd, Rn;
10716
10717 Rd = inst.operands[0].reg;
10718 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
10719
10720 reject_bad_reg (Rd);
10721 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
10722 reject_bad_reg (Rn);
10723
10724 inst.instruction |= Rd << 8;
10725 inst.instruction |= Rn << 16;
10726
10727 if (!inst.operands[2].isreg)
10728 {
10729 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10730 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10731 }
10732 else
10733 {
10734 unsigned Rm;
10735
10736 Rm = inst.operands[2].reg;
10737 reject_bad_reg (Rm);
10738
10739 constraint (inst.operands[2].shifted
10740 && inst.operands[2].immisreg,
10741 _("shift must be constant"));
10742 encode_thumb32_shifted_operand (2);
10743 }
10744 }
10745
10746 static void
10747 do_t_pkhbt (void)
10748 {
10749 unsigned Rd, Rn, Rm;
10750
10751 Rd = inst.operands[0].reg;
10752 Rn = inst.operands[1].reg;
10753 Rm = inst.operands[2].reg;
10754
10755 reject_bad_reg (Rd);
10756 reject_bad_reg (Rn);
10757 reject_bad_reg (Rm);
10758
10759 inst.instruction |= Rd << 8;
10760 inst.instruction |= Rn << 16;
10761 inst.instruction |= Rm;
10762 if (inst.operands[3].present)
10763 {
10764 unsigned int val = inst.reloc.exp.X_add_number;
10765 constraint (inst.reloc.exp.X_op != O_constant,
10766 _("expression too complex"));
10767 inst.instruction |= (val & 0x1c) << 10;
10768 inst.instruction |= (val & 0x03) << 6;
10769 }
10770 }
10771
10772 static void
10773 do_t_pkhtb (void)
10774 {
10775 if (!inst.operands[3].present)
10776 {
10777 unsigned Rtmp;
10778
10779 inst.instruction &= ~0x00000020;
10780
10781 /* PR 10168. Swap the Rm and Rn registers. */
10782 Rtmp = inst.operands[1].reg;
10783 inst.operands[1].reg = inst.operands[2].reg;
10784 inst.operands[2].reg = Rtmp;
10785 }
10786 do_t_pkhbt ();
10787 }
10788
10789 static void
10790 do_t_pld (void)
10791 {
10792 if (inst.operands[0].immisreg)
10793 reject_bad_reg (inst.operands[0].imm);
10794
10795 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
10796 }
10797
10798 static void
10799 do_t_push_pop (void)
10800 {
10801 unsigned mask;
10802
10803 constraint (inst.operands[0].writeback,
10804 _("push/pop do not support {reglist}^"));
10805 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10806 _("expression too complex"));
10807
10808 mask = inst.operands[0].imm;
10809 if ((mask & ~0xff) == 0)
10810 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
10811 else if ((inst.instruction == T_MNEM_push
10812 && (mask & ~0xff) == 1 << REG_LR)
10813 || (inst.instruction == T_MNEM_pop
10814 && (mask & ~0xff) == 1 << REG_PC))
10815 {
10816 inst.instruction = THUMB_OP16 (inst.instruction);
10817 inst.instruction |= THUMB_PP_PC_LR;
10818 inst.instruction |= mask & 0xff;
10819 }
10820 else if (unified_syntax)
10821 {
10822 inst.instruction = THUMB_OP32 (inst.instruction);
10823 encode_thumb2_ldmstm (13, mask, TRUE);
10824 }
10825 else
10826 {
10827 inst.error = _("invalid register list to push/pop instruction");
10828 return;
10829 }
10830 }
10831
10832 static void
10833 do_t_rbit (void)
10834 {
10835 unsigned Rd, Rm;
10836
10837 Rd = inst.operands[0].reg;
10838 Rm = inst.operands[1].reg;
10839
10840 reject_bad_reg (Rd);
10841 reject_bad_reg (Rm);
10842
10843 inst.instruction |= Rd << 8;
10844 inst.instruction |= Rm << 16;
10845 inst.instruction |= Rm;
10846 }
10847
10848 static void
10849 do_t_rev (void)
10850 {
10851 unsigned Rd, Rm;
10852
10853 Rd = inst.operands[0].reg;
10854 Rm = inst.operands[1].reg;
10855
10856 reject_bad_reg (Rd);
10857 reject_bad_reg (Rm);
10858
10859 if (Rd <= 7 && Rm <= 7
10860 && inst.size_req != 4)
10861 {
10862 inst.instruction = THUMB_OP16 (inst.instruction);
10863 inst.instruction |= Rd;
10864 inst.instruction |= Rm << 3;
10865 }
10866 else if (unified_syntax)
10867 {
10868 inst.instruction = THUMB_OP32 (inst.instruction);
10869 inst.instruction |= Rd << 8;
10870 inst.instruction |= Rm << 16;
10871 inst.instruction |= Rm;
10872 }
10873 else
10874 inst.error = BAD_HIREG;
10875 }
10876
10877 static void
10878 do_t_rrx (void)
10879 {
10880 unsigned Rd, Rm;
10881
10882 Rd = inst.operands[0].reg;
10883 Rm = inst.operands[1].reg;
10884
10885 reject_bad_reg (Rd);
10886 reject_bad_reg (Rm);
10887
10888 inst.instruction |= Rd << 8;
10889 inst.instruction |= Rm;
10890 }
10891
10892 static void
10893 do_t_rsb (void)
10894 {
10895 unsigned Rd, Rs;
10896
10897 Rd = inst.operands[0].reg;
10898 Rs = (inst.operands[1].present
10899 ? inst.operands[1].reg /* Rd, Rs, foo */
10900 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10901
10902 reject_bad_reg (Rd);
10903 reject_bad_reg (Rs);
10904 if (inst.operands[2].isreg)
10905 reject_bad_reg (inst.operands[2].reg);
10906
10907 inst.instruction |= Rd << 8;
10908 inst.instruction |= Rs << 16;
10909 if (!inst.operands[2].isreg)
10910 {
10911 bfd_boolean narrow;
10912
10913 if ((inst.instruction & 0x00100000) != 0)
10914 narrow = !in_it_block ();
10915 else
10916 narrow = in_it_block ();
10917
10918 if (Rd > 7 || Rs > 7)
10919 narrow = FALSE;
10920
10921 if (inst.size_req == 4 || !unified_syntax)
10922 narrow = FALSE;
10923
10924 if (inst.reloc.exp.X_op != O_constant
10925 || inst.reloc.exp.X_add_number != 0)
10926 narrow = FALSE;
10927
10928 /* Turn rsb #0 into 16-bit neg. We should probably do this via
10929 relaxation, but it doesn't seem worth the hassle. */
10930 if (narrow)
10931 {
10932 inst.reloc.type = BFD_RELOC_UNUSED;
10933 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10934 inst.instruction |= Rs << 3;
10935 inst.instruction |= Rd;
10936 }
10937 else
10938 {
10939 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10940 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10941 }
10942 }
10943 else
10944 encode_thumb32_shifted_operand (2);
10945 }
10946
10947 static void
10948 do_t_setend (void)
10949 {
10950 set_it_insn_type (OUTSIDE_IT_INSN);
10951 if (inst.operands[0].imm)
10952 inst.instruction |= 0x8;
10953 }
10954
10955 static void
10956 do_t_shift (void)
10957 {
10958 if (!inst.operands[1].present)
10959 inst.operands[1].reg = inst.operands[0].reg;
10960
10961 if (unified_syntax)
10962 {
10963 bfd_boolean narrow;
10964 int shift_kind;
10965
10966 switch (inst.instruction)
10967 {
10968 case T_MNEM_asr:
10969 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
10970 case T_MNEM_lsl:
10971 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
10972 case T_MNEM_lsr:
10973 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
10974 case T_MNEM_ror:
10975 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
10976 default: abort ();
10977 }
10978
10979 if (THUMB_SETS_FLAGS (inst.instruction))
10980 narrow = !in_it_block ();
10981 else
10982 narrow = in_it_block ();
10983 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10984 narrow = FALSE;
10985 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
10986 narrow = FALSE;
10987 if (inst.operands[2].isreg
10988 && (inst.operands[1].reg != inst.operands[0].reg
10989 || inst.operands[2].reg > 7))
10990 narrow = FALSE;
10991 if (inst.size_req == 4)
10992 narrow = FALSE;
10993
10994 reject_bad_reg (inst.operands[0].reg);
10995 reject_bad_reg (inst.operands[1].reg);
10996
10997 if (!narrow)
10998 {
10999 if (inst.operands[2].isreg)
11000 {
11001 reject_bad_reg (inst.operands[2].reg);
11002 inst.instruction = THUMB_OP32 (inst.instruction);
11003 inst.instruction |= inst.operands[0].reg << 8;
11004 inst.instruction |= inst.operands[1].reg << 16;
11005 inst.instruction |= inst.operands[2].reg;
11006 }
11007 else
11008 {
11009 inst.operands[1].shifted = 1;
11010 inst.operands[1].shift_kind = shift_kind;
11011 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
11012 ? T_MNEM_movs : T_MNEM_mov);
11013 inst.instruction |= inst.operands[0].reg << 8;
11014 encode_thumb32_shifted_operand (1);
11015 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
11016 inst.reloc.type = BFD_RELOC_UNUSED;
11017 }
11018 }
11019 else
11020 {
11021 if (inst.operands[2].isreg)
11022 {
11023 switch (shift_kind)
11024 {
11025 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
11026 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
11027 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
11028 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
11029 default: abort ();
11030 }
11031
11032 inst.instruction |= inst.operands[0].reg;
11033 inst.instruction |= inst.operands[2].reg << 3;
11034 }
11035 else
11036 {
11037 switch (shift_kind)
11038 {
11039 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11040 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11041 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11042 default: abort ();
11043 }
11044 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11045 inst.instruction |= inst.operands[0].reg;
11046 inst.instruction |= inst.operands[1].reg << 3;
11047 }
11048 }
11049 }
11050 else
11051 {
11052 constraint (inst.operands[0].reg > 7
11053 || inst.operands[1].reg > 7, BAD_HIREG);
11054 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11055
11056 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
11057 {
11058 constraint (inst.operands[2].reg > 7, BAD_HIREG);
11059 constraint (inst.operands[0].reg != inst.operands[1].reg,
11060 _("source1 and dest must be same register"));
11061
11062 switch (inst.instruction)
11063 {
11064 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
11065 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
11066 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
11067 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
11068 default: abort ();
11069 }
11070
11071 inst.instruction |= inst.operands[0].reg;
11072 inst.instruction |= inst.operands[2].reg << 3;
11073 }
11074 else
11075 {
11076 switch (inst.instruction)
11077 {
11078 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
11079 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
11080 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
11081 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
11082 default: abort ();
11083 }
11084 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11085 inst.instruction |= inst.operands[0].reg;
11086 inst.instruction |= inst.operands[1].reg << 3;
11087 }
11088 }
11089 }
11090
11091 static void
11092 do_t_simd (void)
11093 {
11094 unsigned Rd, Rn, Rm;
11095
11096 Rd = inst.operands[0].reg;
11097 Rn = inst.operands[1].reg;
11098 Rm = inst.operands[2].reg;
11099
11100 reject_bad_reg (Rd);
11101 reject_bad_reg (Rn);
11102 reject_bad_reg (Rm);
11103
11104 inst.instruction |= Rd << 8;
11105 inst.instruction |= Rn << 16;
11106 inst.instruction |= Rm;
11107 }
11108
11109 static void
11110 do_t_simd2 (void)
11111 {
11112 unsigned Rd, Rn, Rm;
11113
11114 Rd = inst.operands[0].reg;
11115 Rm = inst.operands[1].reg;
11116 Rn = inst.operands[2].reg;
11117
11118 reject_bad_reg (Rd);
11119 reject_bad_reg (Rn);
11120 reject_bad_reg (Rm);
11121
11122 inst.instruction |= Rd << 8;
11123 inst.instruction |= Rn << 16;
11124 inst.instruction |= Rm;
11125 }
11126
11127 static void
11128 do_t_smc (void)
11129 {
11130 unsigned int value = inst.reloc.exp.X_add_number;
11131 constraint (inst.reloc.exp.X_op != O_constant,
11132 _("expression too complex"));
11133 inst.reloc.type = BFD_RELOC_UNUSED;
11134 inst.instruction |= (value & 0xf000) >> 12;
11135 inst.instruction |= (value & 0x0ff0);
11136 inst.instruction |= (value & 0x000f) << 16;
11137 }
11138
11139 static void
11140 do_t_ssat_usat (int bias)
11141 {
11142 unsigned Rd, Rn;
11143
11144 Rd = inst.operands[0].reg;
11145 Rn = inst.operands[2].reg;
11146
11147 reject_bad_reg (Rd);
11148 reject_bad_reg (Rn);
11149
11150 inst.instruction |= Rd << 8;
11151 inst.instruction |= inst.operands[1].imm - bias;
11152 inst.instruction |= Rn << 16;
11153
11154 if (inst.operands[3].present)
11155 {
11156 offsetT shift_amount = inst.reloc.exp.X_add_number;
11157
11158 inst.reloc.type = BFD_RELOC_UNUSED;
11159
11160 constraint (inst.reloc.exp.X_op != O_constant,
11161 _("expression too complex"));
11162
11163 if (shift_amount != 0)
11164 {
11165 constraint (shift_amount > 31,
11166 _("shift expression is too large"));
11167
11168 if (inst.operands[3].shift_kind == SHIFT_ASR)
11169 inst.instruction |= 0x00200000; /* sh bit. */
11170
11171 inst.instruction |= (shift_amount & 0x1c) << 10;
11172 inst.instruction |= (shift_amount & 0x03) << 6;
11173 }
11174 }
11175 }
11176
11177 static void
11178 do_t_ssat (void)
11179 {
11180 do_t_ssat_usat (1);
11181 }
11182
11183 static void
11184 do_t_ssat16 (void)
11185 {
11186 unsigned Rd, Rn;
11187
11188 Rd = inst.operands[0].reg;
11189 Rn = inst.operands[2].reg;
11190
11191 reject_bad_reg (Rd);
11192 reject_bad_reg (Rn);
11193
11194 inst.instruction |= Rd << 8;
11195 inst.instruction |= inst.operands[1].imm - 1;
11196 inst.instruction |= Rn << 16;
11197 }
11198
11199 static void
11200 do_t_strex (void)
11201 {
11202 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
11203 || inst.operands[2].postind || inst.operands[2].writeback
11204 || inst.operands[2].immisreg || inst.operands[2].shifted
11205 || inst.operands[2].negative,
11206 BAD_ADDR_MODE);
11207
11208 inst.instruction |= inst.operands[0].reg << 8;
11209 inst.instruction |= inst.operands[1].reg << 12;
11210 inst.instruction |= inst.operands[2].reg << 16;
11211 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11212 }
11213
11214 static void
11215 do_t_strexd (void)
11216 {
11217 if (!inst.operands[2].present)
11218 inst.operands[2].reg = inst.operands[1].reg + 1;
11219
11220 constraint (inst.operands[0].reg == inst.operands[1].reg
11221 || inst.operands[0].reg == inst.operands[2].reg
11222 || inst.operands[0].reg == inst.operands[3].reg
11223 || inst.operands[1].reg == inst.operands[2].reg,
11224 BAD_OVERLAP);
11225
11226 inst.instruction |= inst.operands[0].reg;
11227 inst.instruction |= inst.operands[1].reg << 12;
11228 inst.instruction |= inst.operands[2].reg << 8;
11229 inst.instruction |= inst.operands[3].reg << 16;
11230 }
11231
11232 static void
11233 do_t_sxtah (void)
11234 {
11235 unsigned Rd, Rn, Rm;
11236
11237 Rd = inst.operands[0].reg;
11238 Rn = inst.operands[1].reg;
11239 Rm = inst.operands[2].reg;
11240
11241 reject_bad_reg (Rd);
11242 reject_bad_reg (Rn);
11243 reject_bad_reg (Rm);
11244
11245 inst.instruction |= Rd << 8;
11246 inst.instruction |= Rn << 16;
11247 inst.instruction |= Rm;
11248 inst.instruction |= inst.operands[3].imm << 4;
11249 }
11250
11251 static void
11252 do_t_sxth (void)
11253 {
11254 unsigned Rd, Rm;
11255
11256 Rd = inst.operands[0].reg;
11257 Rm = inst.operands[1].reg;
11258
11259 reject_bad_reg (Rd);
11260 reject_bad_reg (Rm);
11261
11262 if (inst.instruction <= 0xffff
11263 && inst.size_req != 4
11264 && Rd <= 7 && Rm <= 7
11265 && (!inst.operands[2].present || inst.operands[2].imm == 0))
11266 {
11267 inst.instruction = THUMB_OP16 (inst.instruction);
11268 inst.instruction |= Rd;
11269 inst.instruction |= Rm << 3;
11270 }
11271 else if (unified_syntax)
11272 {
11273 if (inst.instruction <= 0xffff)
11274 inst.instruction = THUMB_OP32 (inst.instruction);
11275 inst.instruction |= Rd << 8;
11276 inst.instruction |= Rm;
11277 inst.instruction |= inst.operands[2].imm << 4;
11278 }
11279 else
11280 {
11281 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
11282 _("Thumb encoding does not support rotation"));
11283 constraint (1, BAD_HIREG);
11284 }
11285 }
11286
11287 static void
11288 do_t_swi (void)
11289 {
11290 inst.reloc.type = BFD_RELOC_ARM_SWI;
11291 }
11292
11293 static void
11294 do_t_tb (void)
11295 {
11296 unsigned Rn, Rm;
11297 int half;
11298
11299 half = (inst.instruction & 0x10) != 0;
11300 set_it_insn_type_last ();
11301 constraint (inst.operands[0].immisreg,
11302 _("instruction requires register index"));
11303
11304 Rn = inst.operands[0].reg;
11305 Rm = inst.operands[0].imm;
11306
11307 constraint (Rn == REG_SP, BAD_SP);
11308 reject_bad_reg (Rm);
11309
11310 constraint (!half && inst.operands[0].shifted,
11311 _("instruction does not allow shifted index"));
11312 inst.instruction |= (Rn << 16) | Rm;
11313 }
11314
11315 static void
11316 do_t_usat (void)
11317 {
11318 do_t_ssat_usat (0);
11319 }
11320
11321 static void
11322 do_t_usat16 (void)
11323 {
11324 unsigned Rd, Rn;
11325
11326 Rd = inst.operands[0].reg;
11327 Rn = inst.operands[2].reg;
11328
11329 reject_bad_reg (Rd);
11330 reject_bad_reg (Rn);
11331
11332 inst.instruction |= Rd << 8;
11333 inst.instruction |= inst.operands[1].imm;
11334 inst.instruction |= Rn << 16;
11335 }
11336
11337 /* Neon instruction encoder helpers. */
11338
11339 /* Encodings for the different types for various Neon opcodes. */
11340
11341 /* An "invalid" code for the following tables. */
11342 #define N_INV -1u
11343
11344 struct neon_tab_entry
11345 {
11346 unsigned integer;
11347 unsigned float_or_poly;
11348 unsigned scalar_or_imm;
11349 };
11350
11351 /* Map overloaded Neon opcodes to their respective encodings. */
11352 #define NEON_ENC_TAB \
11353 X(vabd, 0x0000700, 0x1200d00, N_INV), \
11354 X(vmax, 0x0000600, 0x0000f00, N_INV), \
11355 X(vmin, 0x0000610, 0x0200f00, N_INV), \
11356 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
11357 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
11358 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
11359 X(vadd, 0x0000800, 0x0000d00, N_INV), \
11360 X(vsub, 0x1000800, 0x0200d00, N_INV), \
11361 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
11362 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
11363 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
11364 /* Register variants of the following two instructions are encoded as
11365 vcge / vcgt with the operands reversed. */ \
11366 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
11367 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
11368 X(vfma, N_INV, 0x0000c10, N_INV), \
11369 X(vfms, N_INV, 0x0200c10, N_INV), \
11370 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
11371 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
11372 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
11373 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
11374 X(vmlal, 0x0800800, N_INV, 0x0800240), \
11375 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
11376 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
11377 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
11378 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
11379 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
11380 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
11381 X(vshl, 0x0000400, N_INV, 0x0800510), \
11382 X(vqshl, 0x0000410, N_INV, 0x0800710), \
11383 X(vand, 0x0000110, N_INV, 0x0800030), \
11384 X(vbic, 0x0100110, N_INV, 0x0800030), \
11385 X(veor, 0x1000110, N_INV, N_INV), \
11386 X(vorn, 0x0300110, N_INV, 0x0800010), \
11387 X(vorr, 0x0200110, N_INV, 0x0800010), \
11388 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
11389 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
11390 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
11391 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
11392 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
11393 X(vst1, 0x0000000, 0x0800000, N_INV), \
11394 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
11395 X(vst2, 0x0000100, 0x0800100, N_INV), \
11396 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
11397 X(vst3, 0x0000200, 0x0800200, N_INV), \
11398 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
11399 X(vst4, 0x0000300, 0x0800300, N_INV), \
11400 X(vmovn, 0x1b20200, N_INV, N_INV), \
11401 X(vtrn, 0x1b20080, N_INV, N_INV), \
11402 X(vqmovn, 0x1b20200, N_INV, N_INV), \
11403 X(vqmovun, 0x1b20240, N_INV, N_INV), \
11404 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
11405 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
11406 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
11407 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
11408 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
11409 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
11410 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
11411 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
11412 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
11413
11414 enum neon_opc
11415 {
11416 #define X(OPC,I,F,S) N_MNEM_##OPC
11417 NEON_ENC_TAB
11418 #undef X
11419 };
11420
11421 static const struct neon_tab_entry neon_enc_tab[] =
11422 {
11423 #define X(OPC,I,F,S) { (I), (F), (S) }
11424 NEON_ENC_TAB
11425 #undef X
11426 };
11427
11428 #define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11429 #define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11430 #define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11431 #define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11432 #define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11433 #define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11434 #define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11435 #define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11436 #define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11437 #define NEON_ENC_SINGLE(X) \
11438 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
11439 #define NEON_ENC_DOUBLE(X) \
11440 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
11441
11442 /* Define shapes for instruction operands. The following mnemonic characters
11443 are used in this table:
11444
11445 F - VFP S<n> register
11446 D - Neon D<n> register
11447 Q - Neon Q<n> register
11448 I - Immediate
11449 S - Scalar
11450 R - ARM register
11451 L - D<n> register list
11452
11453 This table is used to generate various data:
11454 - enumerations of the form NS_DDR to be used as arguments to
11455 neon_select_shape.
11456 - a table classifying shapes into single, double, quad, mixed.
11457 - a table used to drive neon_select_shape. */
11458
11459 #define NEON_SHAPE_DEF \
11460 X(3, (D, D, D), DOUBLE), \
11461 X(3, (Q, Q, Q), QUAD), \
11462 X(3, (D, D, I), DOUBLE), \
11463 X(3, (Q, Q, I), QUAD), \
11464 X(3, (D, D, S), DOUBLE), \
11465 X(3, (Q, Q, S), QUAD), \
11466 X(2, (D, D), DOUBLE), \
11467 X(2, (Q, Q), QUAD), \
11468 X(2, (D, S), DOUBLE), \
11469 X(2, (Q, S), QUAD), \
11470 X(2, (D, R), DOUBLE), \
11471 X(2, (Q, R), QUAD), \
11472 X(2, (D, I), DOUBLE), \
11473 X(2, (Q, I), QUAD), \
11474 X(3, (D, L, D), DOUBLE), \
11475 X(2, (D, Q), MIXED), \
11476 X(2, (Q, D), MIXED), \
11477 X(3, (D, Q, I), MIXED), \
11478 X(3, (Q, D, I), MIXED), \
11479 X(3, (Q, D, D), MIXED), \
11480 X(3, (D, Q, Q), MIXED), \
11481 X(3, (Q, Q, D), MIXED), \
11482 X(3, (Q, D, S), MIXED), \
11483 X(3, (D, Q, S), MIXED), \
11484 X(4, (D, D, D, I), DOUBLE), \
11485 X(4, (Q, Q, Q, I), QUAD), \
11486 X(2, (F, F), SINGLE), \
11487 X(3, (F, F, F), SINGLE), \
11488 X(2, (F, I), SINGLE), \
11489 X(2, (F, D), MIXED), \
11490 X(2, (D, F), MIXED), \
11491 X(3, (F, F, I), MIXED), \
11492 X(4, (R, R, F, F), SINGLE), \
11493 X(4, (F, F, R, R), SINGLE), \
11494 X(3, (D, R, R), DOUBLE), \
11495 X(3, (R, R, D), DOUBLE), \
11496 X(2, (S, R), SINGLE), \
11497 X(2, (R, S), SINGLE), \
11498 X(2, (F, R), SINGLE), \
11499 X(2, (R, F), SINGLE)
11500
11501 #define S2(A,B) NS_##A##B
11502 #define S3(A,B,C) NS_##A##B##C
11503 #define S4(A,B,C,D) NS_##A##B##C##D
11504
11505 #define X(N, L, C) S##N L
11506
11507 enum neon_shape
11508 {
11509 NEON_SHAPE_DEF,
11510 NS_NULL
11511 };
11512
11513 #undef X
11514 #undef S2
11515 #undef S3
11516 #undef S4
11517
11518 enum neon_shape_class
11519 {
11520 SC_SINGLE,
11521 SC_DOUBLE,
11522 SC_QUAD,
11523 SC_MIXED
11524 };
11525
11526 #define X(N, L, C) SC_##C
11527
11528 static enum neon_shape_class neon_shape_class[] =
11529 {
11530 NEON_SHAPE_DEF
11531 };
11532
11533 #undef X
11534
11535 enum neon_shape_el
11536 {
11537 SE_F,
11538 SE_D,
11539 SE_Q,
11540 SE_I,
11541 SE_S,
11542 SE_R,
11543 SE_L
11544 };
11545
11546 /* Register widths of above. */
11547 static unsigned neon_shape_el_size[] =
11548 {
11549 32,
11550 64,
11551 128,
11552 0,
11553 32,
11554 32,
11555 0
11556 };
11557
11558 struct neon_shape_info
11559 {
11560 unsigned els;
11561 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
11562 };
11563
11564 #define S2(A,B) { SE_##A, SE_##B }
11565 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
11566 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
11567
11568 #define X(N, L, C) { N, S##N L }
11569
11570 static struct neon_shape_info neon_shape_tab[] =
11571 {
11572 NEON_SHAPE_DEF
11573 };
11574
11575 #undef X
11576 #undef S2
11577 #undef S3
11578 #undef S4
11579
11580 /* Bit masks used in type checking given instructions.
11581 'N_EQK' means the type must be the same as (or based on in some way) the key
11582 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
11583 set, various other bits can be set as well in order to modify the meaning of
11584 the type constraint. */
11585
11586 enum neon_type_mask
11587 {
11588 N_S8 = 0x0000001,
11589 N_S16 = 0x0000002,
11590 N_S32 = 0x0000004,
11591 N_S64 = 0x0000008,
11592 N_U8 = 0x0000010,
11593 N_U16 = 0x0000020,
11594 N_U32 = 0x0000040,
11595 N_U64 = 0x0000080,
11596 N_I8 = 0x0000100,
11597 N_I16 = 0x0000200,
11598 N_I32 = 0x0000400,
11599 N_I64 = 0x0000800,
11600 N_8 = 0x0001000,
11601 N_16 = 0x0002000,
11602 N_32 = 0x0004000,
11603 N_64 = 0x0008000,
11604 N_P8 = 0x0010000,
11605 N_P16 = 0x0020000,
11606 N_F16 = 0x0040000,
11607 N_F32 = 0x0080000,
11608 N_F64 = 0x0100000,
11609 N_KEY = 0x1000000, /* Key element (main type specifier). */
11610 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
11611 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
11612 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
11613 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
11614 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
11615 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
11616 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
11617 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
11618 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
11619 N_UTYP = 0,
11620 N_MAX_NONSPECIAL = N_F64
11621 };
11622
11623 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
11624
11625 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
11626 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
11627 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
11628 #define N_SUF_32 (N_SU_32 | N_F32)
11629 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
11630 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
11631
11632 /* Pass this as the first type argument to neon_check_type to ignore types
11633 altogether. */
11634 #define N_IGNORE_TYPE (N_KEY | N_EQK)
11635
11636 /* Select a "shape" for the current instruction (describing register types or
11637 sizes) from a list of alternatives. Return NS_NULL if the current instruction
11638 doesn't fit. For non-polymorphic shapes, checking is usually done as a
11639 function of operand parsing, so this function doesn't need to be called.
11640 Shapes should be listed in order of decreasing length. */
11641
11642 static enum neon_shape
11643 neon_select_shape (enum neon_shape shape, ...)
11644 {
11645 va_list ap;
11646 enum neon_shape first_shape = shape;
11647
11648 /* Fix missing optional operands. FIXME: we don't know at this point how
11649 many arguments we should have, so this makes the assumption that we have
11650 > 1. This is true of all current Neon opcodes, I think, but may not be
11651 true in the future. */
11652 if (!inst.operands[1].present)
11653 inst.operands[1] = inst.operands[0];
11654
11655 va_start (ap, shape);
11656
11657 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
11658 {
11659 unsigned j;
11660 int matches = 1;
11661
11662 for (j = 0; j < neon_shape_tab[shape].els; j++)
11663 {
11664 if (!inst.operands[j].present)
11665 {
11666 matches = 0;
11667 break;
11668 }
11669
11670 switch (neon_shape_tab[shape].el[j])
11671 {
11672 case SE_F:
11673 if (!(inst.operands[j].isreg
11674 && inst.operands[j].isvec
11675 && inst.operands[j].issingle
11676 && !inst.operands[j].isquad))
11677 matches = 0;
11678 break;
11679
11680 case SE_D:
11681 if (!(inst.operands[j].isreg
11682 && inst.operands[j].isvec
11683 && !inst.operands[j].isquad
11684 && !inst.operands[j].issingle))
11685 matches = 0;
11686 break;
11687
11688 case SE_R:
11689 if (!(inst.operands[j].isreg
11690 && !inst.operands[j].isvec))
11691 matches = 0;
11692 break;
11693
11694 case SE_Q:
11695 if (!(inst.operands[j].isreg
11696 && inst.operands[j].isvec
11697 && inst.operands[j].isquad
11698 && !inst.operands[j].issingle))
11699 matches = 0;
11700 break;
11701
11702 case SE_I:
11703 if (!(!inst.operands[j].isreg
11704 && !inst.operands[j].isscalar))
11705 matches = 0;
11706 break;
11707
11708 case SE_S:
11709 if (!(!inst.operands[j].isreg
11710 && inst.operands[j].isscalar))
11711 matches = 0;
11712 break;
11713
11714 case SE_L:
11715 break;
11716 }
11717 }
11718 if (matches)
11719 break;
11720 }
11721
11722 va_end (ap);
11723
11724 if (shape == NS_NULL && first_shape != NS_NULL)
11725 first_error (_("invalid instruction shape"));
11726
11727 return shape;
11728 }
11729
11730 /* True if SHAPE is predominantly a quadword operation (most of the time, this
11731 means the Q bit should be set). */
11732
11733 static int
11734 neon_quad (enum neon_shape shape)
11735 {
11736 return neon_shape_class[shape] == SC_QUAD;
11737 }
11738
11739 static void
11740 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
11741 unsigned *g_size)
11742 {
11743 /* Allow modification to be made to types which are constrained to be
11744 based on the key element, based on bits set alongside N_EQK. */
11745 if ((typebits & N_EQK) != 0)
11746 {
11747 if ((typebits & N_HLF) != 0)
11748 *g_size /= 2;
11749 else if ((typebits & N_DBL) != 0)
11750 *g_size *= 2;
11751 if ((typebits & N_SGN) != 0)
11752 *g_type = NT_signed;
11753 else if ((typebits & N_UNS) != 0)
11754 *g_type = NT_unsigned;
11755 else if ((typebits & N_INT) != 0)
11756 *g_type = NT_integer;
11757 else if ((typebits & N_FLT) != 0)
11758 *g_type = NT_float;
11759 else if ((typebits & N_SIZ) != 0)
11760 *g_type = NT_untyped;
11761 }
11762 }
11763
11764 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
11765 operand type, i.e. the single type specified in a Neon instruction when it
11766 is the only one given. */
11767
11768 static struct neon_type_el
11769 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
11770 {
11771 struct neon_type_el dest = *key;
11772
11773 gas_assert ((thisarg & N_EQK) != 0);
11774
11775 neon_modify_type_size (thisarg, &dest.type, &dest.size);
11776
11777 return dest;
11778 }
11779
11780 /* Convert Neon type and size into compact bitmask representation. */
11781
11782 static enum neon_type_mask
11783 type_chk_of_el_type (enum neon_el_type type, unsigned size)
11784 {
11785 switch (type)
11786 {
11787 case NT_untyped:
11788 switch (size)
11789 {
11790 case 8: return N_8;
11791 case 16: return N_16;
11792 case 32: return N_32;
11793 case 64: return N_64;
11794 default: ;
11795 }
11796 break;
11797
11798 case NT_integer:
11799 switch (size)
11800 {
11801 case 8: return N_I8;
11802 case 16: return N_I16;
11803 case 32: return N_I32;
11804 case 64: return N_I64;
11805 default: ;
11806 }
11807 break;
11808
11809 case NT_float:
11810 switch (size)
11811 {
11812 case 16: return N_F16;
11813 case 32: return N_F32;
11814 case 64: return N_F64;
11815 default: ;
11816 }
11817 break;
11818
11819 case NT_poly:
11820 switch (size)
11821 {
11822 case 8: return N_P8;
11823 case 16: return N_P16;
11824 default: ;
11825 }
11826 break;
11827
11828 case NT_signed:
11829 switch (size)
11830 {
11831 case 8: return N_S8;
11832 case 16: return N_S16;
11833 case 32: return N_S32;
11834 case 64: return N_S64;
11835 default: ;
11836 }
11837 break;
11838
11839 case NT_unsigned:
11840 switch (size)
11841 {
11842 case 8: return N_U8;
11843 case 16: return N_U16;
11844 case 32: return N_U32;
11845 case 64: return N_U64;
11846 default: ;
11847 }
11848 break;
11849
11850 default: ;
11851 }
11852
11853 return N_UTYP;
11854 }
11855
11856 /* Convert compact Neon bitmask type representation to a type and size. Only
11857 handles the case where a single bit is set in the mask. */
11858
11859 static int
11860 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
11861 enum neon_type_mask mask)
11862 {
11863 if ((mask & N_EQK) != 0)
11864 return FAIL;
11865
11866 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
11867 *size = 8;
11868 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
11869 *size = 16;
11870 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
11871 *size = 32;
11872 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
11873 *size = 64;
11874 else
11875 return FAIL;
11876
11877 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
11878 *type = NT_signed;
11879 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
11880 *type = NT_unsigned;
11881 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
11882 *type = NT_integer;
11883 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
11884 *type = NT_untyped;
11885 else if ((mask & (N_P8 | N_P16)) != 0)
11886 *type = NT_poly;
11887 else if ((mask & (N_F32 | N_F64)) != 0)
11888 *type = NT_float;
11889 else
11890 return FAIL;
11891
11892 return SUCCESS;
11893 }
11894
11895 /* Modify a bitmask of allowed types. This is only needed for type
11896 relaxation. */
11897
11898 static unsigned
11899 modify_types_allowed (unsigned allowed, unsigned mods)
11900 {
11901 unsigned size;
11902 enum neon_el_type type;
11903 unsigned destmask;
11904 int i;
11905
11906 destmask = 0;
11907
11908 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
11909 {
11910 if (el_type_of_type_chk (&type, &size,
11911 (enum neon_type_mask) (allowed & i)) == SUCCESS)
11912 {
11913 neon_modify_type_size (mods, &type, &size);
11914 destmask |= type_chk_of_el_type (type, size);
11915 }
11916 }
11917
11918 return destmask;
11919 }
11920
11921 /* Check type and return type classification.
11922 The manual states (paraphrase): If one datatype is given, it indicates the
11923 type given in:
11924 - the second operand, if there is one
11925 - the operand, if there is no second operand
11926 - the result, if there are no operands.
11927 This isn't quite good enough though, so we use a concept of a "key" datatype
11928 which is set on a per-instruction basis, which is the one which matters when
11929 only one data type is written.
11930 Note: this function has side-effects (e.g. filling in missing operands). All
11931 Neon instructions should call it before performing bit encoding. */
11932
11933 static struct neon_type_el
11934 neon_check_type (unsigned els, enum neon_shape ns, ...)
11935 {
11936 va_list ap;
11937 unsigned i, pass, key_el = 0;
11938 unsigned types[NEON_MAX_TYPE_ELS];
11939 enum neon_el_type k_type = NT_invtype;
11940 unsigned k_size = -1u;
11941 struct neon_type_el badtype = {NT_invtype, -1};
11942 unsigned key_allowed = 0;
11943
11944 /* Optional registers in Neon instructions are always (not) in operand 1.
11945 Fill in the missing operand here, if it was omitted. */
11946 if (els > 1 && !inst.operands[1].present)
11947 inst.operands[1] = inst.operands[0];
11948
11949 /* Suck up all the varargs. */
11950 va_start (ap, ns);
11951 for (i = 0; i < els; i++)
11952 {
11953 unsigned thisarg = va_arg (ap, unsigned);
11954 if (thisarg == N_IGNORE_TYPE)
11955 {
11956 va_end (ap);
11957 return badtype;
11958 }
11959 types[i] = thisarg;
11960 if ((thisarg & N_KEY) != 0)
11961 key_el = i;
11962 }
11963 va_end (ap);
11964
11965 if (inst.vectype.elems > 0)
11966 for (i = 0; i < els; i++)
11967 if (inst.operands[i].vectype.type != NT_invtype)
11968 {
11969 first_error (_("types specified in both the mnemonic and operands"));
11970 return badtype;
11971 }
11972
11973 /* Duplicate inst.vectype elements here as necessary.
11974 FIXME: No idea if this is exactly the same as the ARM assembler,
11975 particularly when an insn takes one register and one non-register
11976 operand. */
11977 if (inst.vectype.elems == 1 && els > 1)
11978 {
11979 unsigned j;
11980 inst.vectype.elems = els;
11981 inst.vectype.el[key_el] = inst.vectype.el[0];
11982 for (j = 0; j < els; j++)
11983 if (j != key_el)
11984 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11985 types[j]);
11986 }
11987 else if (inst.vectype.elems == 0 && els > 0)
11988 {
11989 unsigned j;
11990 /* No types were given after the mnemonic, so look for types specified
11991 after each operand. We allow some flexibility here; as long as the
11992 "key" operand has a type, we can infer the others. */
11993 for (j = 0; j < els; j++)
11994 if (inst.operands[j].vectype.type != NT_invtype)
11995 inst.vectype.el[j] = inst.operands[j].vectype;
11996
11997 if (inst.operands[key_el].vectype.type != NT_invtype)
11998 {
11999 for (j = 0; j < els; j++)
12000 if (inst.operands[j].vectype.type == NT_invtype)
12001 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12002 types[j]);
12003 }
12004 else
12005 {
12006 first_error (_("operand types can't be inferred"));
12007 return badtype;
12008 }
12009 }
12010 else if (inst.vectype.elems != els)
12011 {
12012 first_error (_("type specifier has the wrong number of parts"));
12013 return badtype;
12014 }
12015
12016 for (pass = 0; pass < 2; pass++)
12017 {
12018 for (i = 0; i < els; i++)
12019 {
12020 unsigned thisarg = types[i];
12021 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
12022 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
12023 enum neon_el_type g_type = inst.vectype.el[i].type;
12024 unsigned g_size = inst.vectype.el[i].size;
12025
12026 /* Decay more-specific signed & unsigned types to sign-insensitive
12027 integer types if sign-specific variants are unavailable. */
12028 if ((g_type == NT_signed || g_type == NT_unsigned)
12029 && (types_allowed & N_SU_ALL) == 0)
12030 g_type = NT_integer;
12031
12032 /* If only untyped args are allowed, decay any more specific types to
12033 them. Some instructions only care about signs for some element
12034 sizes, so handle that properly. */
12035 if ((g_size == 8 && (types_allowed & N_8) != 0)
12036 || (g_size == 16 && (types_allowed & N_16) != 0)
12037 || (g_size == 32 && (types_allowed & N_32) != 0)
12038 || (g_size == 64 && (types_allowed & N_64) != 0))
12039 g_type = NT_untyped;
12040
12041 if (pass == 0)
12042 {
12043 if ((thisarg & N_KEY) != 0)
12044 {
12045 k_type = g_type;
12046 k_size = g_size;
12047 key_allowed = thisarg & ~N_KEY;
12048 }
12049 }
12050 else
12051 {
12052 if ((thisarg & N_VFP) != 0)
12053 {
12054 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
12055 unsigned regwidth = neon_shape_el_size[regshape], match;
12056
12057 /* In VFP mode, operands must match register widths. If we
12058 have a key operand, use its width, else use the width of
12059 the current operand. */
12060 if (k_size != -1u)
12061 match = k_size;
12062 else
12063 match = g_size;
12064
12065 if (regwidth != match)
12066 {
12067 first_error (_("operand size must match register width"));
12068 return badtype;
12069 }
12070 }
12071
12072 if ((thisarg & N_EQK) == 0)
12073 {
12074 unsigned given_type = type_chk_of_el_type (g_type, g_size);
12075
12076 if ((given_type & types_allowed) == 0)
12077 {
12078 first_error (_("bad type in Neon instruction"));
12079 return badtype;
12080 }
12081 }
12082 else
12083 {
12084 enum neon_el_type mod_k_type = k_type;
12085 unsigned mod_k_size = k_size;
12086 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
12087 if (g_type != mod_k_type || g_size != mod_k_size)
12088 {
12089 first_error (_("inconsistent types in Neon instruction"));
12090 return badtype;
12091 }
12092 }
12093 }
12094 }
12095 }
12096
12097 return inst.vectype.el[key_el];
12098 }
12099
12100 /* Neon-style VFP instruction forwarding. */
12101
12102 /* Thumb VFP instructions have 0xE in the condition field. */
12103
12104 static void
12105 do_vfp_cond_or_thumb (void)
12106 {
12107 if (thumb_mode)
12108 inst.instruction |= 0xe0000000;
12109 else
12110 inst.instruction |= inst.cond << 28;
12111 }
12112
12113 /* Look up and encode a simple mnemonic, for use as a helper function for the
12114 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
12115 etc. It is assumed that operand parsing has already been done, and that the
12116 operands are in the form expected by the given opcode (this isn't necessarily
12117 the same as the form in which they were parsed, hence some massaging must
12118 take place before this function is called).
12119 Checks current arch version against that in the looked-up opcode. */
12120
12121 static void
12122 do_vfp_nsyn_opcode (const char *opname)
12123 {
12124 const struct asm_opcode *opcode;
12125
12126 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
12127
12128 if (!opcode)
12129 abort ();
12130
12131 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
12132 thumb_mode ? *opcode->tvariant : *opcode->avariant),
12133 _(BAD_FPU));
12134
12135 if (thumb_mode)
12136 {
12137 inst.instruction = opcode->tvalue;
12138 opcode->tencode ();
12139 }
12140 else
12141 {
12142 inst.instruction = (inst.cond << 28) | opcode->avalue;
12143 opcode->aencode ();
12144 }
12145 }
12146
12147 static void
12148 do_vfp_nsyn_add_sub (enum neon_shape rs)
12149 {
12150 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
12151
12152 if (rs == NS_FFF)
12153 {
12154 if (is_add)
12155 do_vfp_nsyn_opcode ("fadds");
12156 else
12157 do_vfp_nsyn_opcode ("fsubs");
12158 }
12159 else
12160 {
12161 if (is_add)
12162 do_vfp_nsyn_opcode ("faddd");
12163 else
12164 do_vfp_nsyn_opcode ("fsubd");
12165 }
12166 }
12167
12168 /* Check operand types to see if this is a VFP instruction, and if so call
12169 PFN (). */
12170
12171 static int
12172 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
12173 {
12174 enum neon_shape rs;
12175 struct neon_type_el et;
12176
12177 switch (args)
12178 {
12179 case 2:
12180 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12181 et = neon_check_type (2, rs,
12182 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12183 break;
12184
12185 case 3:
12186 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12187 et = neon_check_type (3, rs,
12188 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12189 break;
12190
12191 default:
12192 abort ();
12193 }
12194
12195 if (et.type != NT_invtype)
12196 {
12197 pfn (rs);
12198 return SUCCESS;
12199 }
12200 else
12201 inst.error = NULL;
12202
12203 return FAIL;
12204 }
12205
12206 static void
12207 do_vfp_nsyn_mla_mls (enum neon_shape rs)
12208 {
12209 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
12210
12211 if (rs == NS_FFF)
12212 {
12213 if (is_mla)
12214 do_vfp_nsyn_opcode ("fmacs");
12215 else
12216 do_vfp_nsyn_opcode ("fnmacs");
12217 }
12218 else
12219 {
12220 if (is_mla)
12221 do_vfp_nsyn_opcode ("fmacd");
12222 else
12223 do_vfp_nsyn_opcode ("fnmacd");
12224 }
12225 }
12226
12227 static void
12228 do_vfp_nsyn_fma_fms (enum neon_shape rs)
12229 {
12230 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
12231
12232 if (rs == NS_FFF)
12233 {
12234 if (is_fma)
12235 do_vfp_nsyn_opcode ("ffmas");
12236 else
12237 do_vfp_nsyn_opcode ("ffnmas");
12238 }
12239 else
12240 {
12241 if (is_fma)
12242 do_vfp_nsyn_opcode ("ffmad");
12243 else
12244 do_vfp_nsyn_opcode ("ffnmad");
12245 }
12246 }
12247
12248 static void
12249 do_vfp_nsyn_mul (enum neon_shape rs)
12250 {
12251 if (rs == NS_FFF)
12252 do_vfp_nsyn_opcode ("fmuls");
12253 else
12254 do_vfp_nsyn_opcode ("fmuld");
12255 }
12256
12257 static void
12258 do_vfp_nsyn_abs_neg (enum neon_shape rs)
12259 {
12260 int is_neg = (inst.instruction & 0x80) != 0;
12261 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
12262
12263 if (rs == NS_FF)
12264 {
12265 if (is_neg)
12266 do_vfp_nsyn_opcode ("fnegs");
12267 else
12268 do_vfp_nsyn_opcode ("fabss");
12269 }
12270 else
12271 {
12272 if (is_neg)
12273 do_vfp_nsyn_opcode ("fnegd");
12274 else
12275 do_vfp_nsyn_opcode ("fabsd");
12276 }
12277 }
12278
12279 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
12280 insns belong to Neon, and are handled elsewhere. */
12281
12282 static void
12283 do_vfp_nsyn_ldm_stm (int is_dbmode)
12284 {
12285 int is_ldm = (inst.instruction & (1 << 20)) != 0;
12286 if (is_ldm)
12287 {
12288 if (is_dbmode)
12289 do_vfp_nsyn_opcode ("fldmdbs");
12290 else
12291 do_vfp_nsyn_opcode ("fldmias");
12292 }
12293 else
12294 {
12295 if (is_dbmode)
12296 do_vfp_nsyn_opcode ("fstmdbs");
12297 else
12298 do_vfp_nsyn_opcode ("fstmias");
12299 }
12300 }
12301
12302 static void
12303 do_vfp_nsyn_sqrt (void)
12304 {
12305 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12306 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12307
12308 if (rs == NS_FF)
12309 do_vfp_nsyn_opcode ("fsqrts");
12310 else
12311 do_vfp_nsyn_opcode ("fsqrtd");
12312 }
12313
12314 static void
12315 do_vfp_nsyn_div (void)
12316 {
12317 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12318 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12319 N_F32 | N_F64 | N_KEY | N_VFP);
12320
12321 if (rs == NS_FFF)
12322 do_vfp_nsyn_opcode ("fdivs");
12323 else
12324 do_vfp_nsyn_opcode ("fdivd");
12325 }
12326
12327 static void
12328 do_vfp_nsyn_nmul (void)
12329 {
12330 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12331 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12332 N_F32 | N_F64 | N_KEY | N_VFP);
12333
12334 if (rs == NS_FFF)
12335 {
12336 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
12337 do_vfp_sp_dyadic ();
12338 }
12339 else
12340 {
12341 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
12342 do_vfp_dp_rd_rn_rm ();
12343 }
12344 do_vfp_cond_or_thumb ();
12345 }
12346
12347 static void
12348 do_vfp_nsyn_cmp (void)
12349 {
12350 if (inst.operands[1].isreg)
12351 {
12352 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12353 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12354
12355 if (rs == NS_FF)
12356 {
12357 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
12358 do_vfp_sp_monadic ();
12359 }
12360 else
12361 {
12362 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
12363 do_vfp_dp_rd_rm ();
12364 }
12365 }
12366 else
12367 {
12368 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
12369 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
12370
12371 switch (inst.instruction & 0x0fffffff)
12372 {
12373 case N_MNEM_vcmp:
12374 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
12375 break;
12376 case N_MNEM_vcmpe:
12377 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
12378 break;
12379 default:
12380 abort ();
12381 }
12382
12383 if (rs == NS_FI)
12384 {
12385 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
12386 do_vfp_sp_compare_z ();
12387 }
12388 else
12389 {
12390 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
12391 do_vfp_dp_rd ();
12392 }
12393 }
12394 do_vfp_cond_or_thumb ();
12395 }
12396
12397 static void
12398 nsyn_insert_sp (void)
12399 {
12400 inst.operands[1] = inst.operands[0];
12401 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
12402 inst.operands[0].reg = REG_SP;
12403 inst.operands[0].isreg = 1;
12404 inst.operands[0].writeback = 1;
12405 inst.operands[0].present = 1;
12406 }
12407
12408 static void
12409 do_vfp_nsyn_push (void)
12410 {
12411 nsyn_insert_sp ();
12412 if (inst.operands[1].issingle)
12413 do_vfp_nsyn_opcode ("fstmdbs");
12414 else
12415 do_vfp_nsyn_opcode ("fstmdbd");
12416 }
12417
12418 static void
12419 do_vfp_nsyn_pop (void)
12420 {
12421 nsyn_insert_sp ();
12422 if (inst.operands[1].issingle)
12423 do_vfp_nsyn_opcode ("fldmias");
12424 else
12425 do_vfp_nsyn_opcode ("fldmiad");
12426 }
12427
12428 /* Fix up Neon data-processing instructions, ORing in the correct bits for
12429 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
12430
12431 static unsigned
12432 neon_dp_fixup (unsigned i)
12433 {
12434 if (thumb_mode)
12435 {
12436 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
12437 if (i & (1 << 24))
12438 i |= 1 << 28;
12439
12440 i &= ~(1 << 24);
12441
12442 i |= 0xef000000;
12443 }
12444 else
12445 i |= 0xf2000000;
12446
12447 return i;
12448 }
12449
12450 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
12451 (0, 1, 2, 3). */
12452
12453 static unsigned
12454 neon_logbits (unsigned x)
12455 {
12456 return ffs (x) - 4;
12457 }
12458
12459 #define LOW4(R) ((R) & 0xf)
12460 #define HI1(R) (((R) >> 4) & 1)
12461
12462 /* Encode insns with bit pattern:
12463
12464 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12465 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
12466
12467 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
12468 different meaning for some instruction. */
12469
12470 static void
12471 neon_three_same (int isquad, int ubit, int size)
12472 {
12473 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12474 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12475 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12476 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12477 inst.instruction |= LOW4 (inst.operands[2].reg);
12478 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12479 inst.instruction |= (isquad != 0) << 6;
12480 inst.instruction |= (ubit != 0) << 24;
12481 if (size != -1)
12482 inst.instruction |= neon_logbits (size) << 20;
12483
12484 inst.instruction = neon_dp_fixup (inst.instruction);
12485 }
12486
12487 /* Encode instructions of the form:
12488
12489 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
12490 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
12491
12492 Don't write size if SIZE == -1. */
12493
12494 static void
12495 neon_two_same (int qbit, int ubit, int size)
12496 {
12497 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12498 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12499 inst.instruction |= LOW4 (inst.operands[1].reg);
12500 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12501 inst.instruction |= (qbit != 0) << 6;
12502 inst.instruction |= (ubit != 0) << 24;
12503
12504 if (size != -1)
12505 inst.instruction |= neon_logbits (size) << 18;
12506
12507 inst.instruction = neon_dp_fixup (inst.instruction);
12508 }
12509
12510 /* Neon instruction encoders, in approximate order of appearance. */
12511
12512 static void
12513 do_neon_dyadic_i_su (void)
12514 {
12515 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12516 struct neon_type_el et = neon_check_type (3, rs,
12517 N_EQK, N_EQK, N_SU_32 | N_KEY);
12518 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12519 }
12520
12521 static void
12522 do_neon_dyadic_i64_su (void)
12523 {
12524 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12525 struct neon_type_el et = neon_check_type (3, rs,
12526 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12527 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12528 }
12529
12530 static void
12531 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
12532 unsigned immbits)
12533 {
12534 unsigned size = et.size >> 3;
12535 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12536 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12537 inst.instruction |= LOW4 (inst.operands[1].reg);
12538 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12539 inst.instruction |= (isquad != 0) << 6;
12540 inst.instruction |= immbits << 16;
12541 inst.instruction |= (size >> 3) << 7;
12542 inst.instruction |= (size & 0x7) << 19;
12543 if (write_ubit)
12544 inst.instruction |= (uval != 0) << 24;
12545
12546 inst.instruction = neon_dp_fixup (inst.instruction);
12547 }
12548
12549 static void
12550 do_neon_shl_imm (void)
12551 {
12552 if (!inst.operands[2].isreg)
12553 {
12554 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12555 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
12556 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12557 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
12558 }
12559 else
12560 {
12561 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12562 struct neon_type_el et = neon_check_type (3, rs,
12563 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
12564 unsigned int tmp;
12565
12566 /* VSHL/VQSHL 3-register variants have syntax such as:
12567 vshl.xx Dd, Dm, Dn
12568 whereas other 3-register operations encoded by neon_three_same have
12569 syntax like:
12570 vadd.xx Dd, Dn, Dm
12571 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
12572 here. */
12573 tmp = inst.operands[2].reg;
12574 inst.operands[2].reg = inst.operands[1].reg;
12575 inst.operands[1].reg = tmp;
12576 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12577 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12578 }
12579 }
12580
12581 static void
12582 do_neon_qshl_imm (void)
12583 {
12584 if (!inst.operands[2].isreg)
12585 {
12586 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12587 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
12588
12589 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12590 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
12591 inst.operands[2].imm);
12592 }
12593 else
12594 {
12595 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12596 struct neon_type_el et = neon_check_type (3, rs,
12597 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
12598 unsigned int tmp;
12599
12600 /* See note in do_neon_shl_imm. */
12601 tmp = inst.operands[2].reg;
12602 inst.operands[2].reg = inst.operands[1].reg;
12603 inst.operands[1].reg = tmp;
12604 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12605 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12606 }
12607 }
12608
12609 static void
12610 do_neon_rshl (void)
12611 {
12612 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12613 struct neon_type_el et = neon_check_type (3, rs,
12614 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12615 unsigned int tmp;
12616
12617 tmp = inst.operands[2].reg;
12618 inst.operands[2].reg = inst.operands[1].reg;
12619 inst.operands[1].reg = tmp;
12620 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12621 }
12622
12623 static int
12624 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
12625 {
12626 /* Handle .I8 pseudo-instructions. */
12627 if (size == 8)
12628 {
12629 /* Unfortunately, this will make everything apart from zero out-of-range.
12630 FIXME is this the intended semantics? There doesn't seem much point in
12631 accepting .I8 if so. */
12632 immediate |= immediate << 8;
12633 size = 16;
12634 }
12635
12636 if (size >= 32)
12637 {
12638 if (immediate == (immediate & 0x000000ff))
12639 {
12640 *immbits = immediate;
12641 return 0x1;
12642 }
12643 else if (immediate == (immediate & 0x0000ff00))
12644 {
12645 *immbits = immediate >> 8;
12646 return 0x3;
12647 }
12648 else if (immediate == (immediate & 0x00ff0000))
12649 {
12650 *immbits = immediate >> 16;
12651 return 0x5;
12652 }
12653 else if (immediate == (immediate & 0xff000000))
12654 {
12655 *immbits = immediate >> 24;
12656 return 0x7;
12657 }
12658 if ((immediate & 0xffff) != (immediate >> 16))
12659 goto bad_immediate;
12660 immediate &= 0xffff;
12661 }
12662
12663 if (immediate == (immediate & 0x000000ff))
12664 {
12665 *immbits = immediate;
12666 return 0x9;
12667 }
12668 else if (immediate == (immediate & 0x0000ff00))
12669 {
12670 *immbits = immediate >> 8;
12671 return 0xb;
12672 }
12673
12674 bad_immediate:
12675 first_error (_("immediate value out of range"));
12676 return FAIL;
12677 }
12678
12679 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
12680 A, B, C, D. */
12681
12682 static int
12683 neon_bits_same_in_bytes (unsigned imm)
12684 {
12685 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
12686 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
12687 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
12688 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
12689 }
12690
12691 /* For immediate of above form, return 0bABCD. */
12692
12693 static unsigned
12694 neon_squash_bits (unsigned imm)
12695 {
12696 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
12697 | ((imm & 0x01000000) >> 21);
12698 }
12699
12700 /* Compress quarter-float representation to 0b...000 abcdefgh. */
12701
12702 static unsigned
12703 neon_qfloat_bits (unsigned imm)
12704 {
12705 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
12706 }
12707
12708 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
12709 the instruction. *OP is passed as the initial value of the op field, and
12710 may be set to a different value depending on the constant (i.e.
12711 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
12712 MVN). If the immediate looks like a repeated pattern then also
12713 try smaller element sizes. */
12714
12715 static int
12716 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
12717 unsigned *immbits, int *op, int size,
12718 enum neon_el_type type)
12719 {
12720 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
12721 float. */
12722 if (type == NT_float && !float_p)
12723 return FAIL;
12724
12725 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
12726 {
12727 if (size != 32 || *op == 1)
12728 return FAIL;
12729 *immbits = neon_qfloat_bits (immlo);
12730 return 0xf;
12731 }
12732
12733 if (size == 64)
12734 {
12735 if (neon_bits_same_in_bytes (immhi)
12736 && neon_bits_same_in_bytes (immlo))
12737 {
12738 if (*op == 1)
12739 return FAIL;
12740 *immbits = (neon_squash_bits (immhi) << 4)
12741 | neon_squash_bits (immlo);
12742 *op = 1;
12743 return 0xe;
12744 }
12745
12746 if (immhi != immlo)
12747 return FAIL;
12748 }
12749
12750 if (size >= 32)
12751 {
12752 if (immlo == (immlo & 0x000000ff))
12753 {
12754 *immbits = immlo;
12755 return 0x0;
12756 }
12757 else if (immlo == (immlo & 0x0000ff00))
12758 {
12759 *immbits = immlo >> 8;
12760 return 0x2;
12761 }
12762 else if (immlo == (immlo & 0x00ff0000))
12763 {
12764 *immbits = immlo >> 16;
12765 return 0x4;
12766 }
12767 else if (immlo == (immlo & 0xff000000))
12768 {
12769 *immbits = immlo >> 24;
12770 return 0x6;
12771 }
12772 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
12773 {
12774 *immbits = (immlo >> 8) & 0xff;
12775 return 0xc;
12776 }
12777 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
12778 {
12779 *immbits = (immlo >> 16) & 0xff;
12780 return 0xd;
12781 }
12782
12783 if ((immlo & 0xffff) != (immlo >> 16))
12784 return FAIL;
12785 immlo &= 0xffff;
12786 }
12787
12788 if (size >= 16)
12789 {
12790 if (immlo == (immlo & 0x000000ff))
12791 {
12792 *immbits = immlo;
12793 return 0x8;
12794 }
12795 else if (immlo == (immlo & 0x0000ff00))
12796 {
12797 *immbits = immlo >> 8;
12798 return 0xa;
12799 }
12800
12801 if ((immlo & 0xff) != (immlo >> 8))
12802 return FAIL;
12803 immlo &= 0xff;
12804 }
12805
12806 if (immlo == (immlo & 0x000000ff))
12807 {
12808 /* Don't allow MVN with 8-bit immediate. */
12809 if (*op == 1)
12810 return FAIL;
12811 *immbits = immlo;
12812 return 0xe;
12813 }
12814
12815 return FAIL;
12816 }
12817
12818 /* Write immediate bits [7:0] to the following locations:
12819
12820 |28/24|23 19|18 16|15 4|3 0|
12821 | 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|
12822
12823 This function is used by VMOV/VMVN/VORR/VBIC. */
12824
12825 static void
12826 neon_write_immbits (unsigned immbits)
12827 {
12828 inst.instruction |= immbits & 0xf;
12829 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
12830 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
12831 }
12832
12833 /* Invert low-order SIZE bits of XHI:XLO. */
12834
12835 static void
12836 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
12837 {
12838 unsigned immlo = xlo ? *xlo : 0;
12839 unsigned immhi = xhi ? *xhi : 0;
12840
12841 switch (size)
12842 {
12843 case 8:
12844 immlo = (~immlo) & 0xff;
12845 break;
12846
12847 case 16:
12848 immlo = (~immlo) & 0xffff;
12849 break;
12850
12851 case 64:
12852 immhi = (~immhi) & 0xffffffff;
12853 /* fall through. */
12854
12855 case 32:
12856 immlo = (~immlo) & 0xffffffff;
12857 break;
12858
12859 default:
12860 abort ();
12861 }
12862
12863 if (xlo)
12864 *xlo = immlo;
12865
12866 if (xhi)
12867 *xhi = immhi;
12868 }
12869
12870 static void
12871 do_neon_logic (void)
12872 {
12873 if (inst.operands[2].present && inst.operands[2].isreg)
12874 {
12875 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12876 neon_check_type (3, rs, N_IGNORE_TYPE);
12877 /* U bit and size field were set as part of the bitmask. */
12878 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12879 neon_three_same (neon_quad (rs), 0, -1);
12880 }
12881 else
12882 {
12883 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
12884 struct neon_type_el et = neon_check_type (2, rs,
12885 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
12886 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
12887 unsigned immbits;
12888 int cmode;
12889
12890 if (et.type == NT_invtype)
12891 return;
12892
12893 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12894
12895 immbits = inst.operands[1].imm;
12896 if (et.size == 64)
12897 {
12898 /* .i64 is a pseudo-op, so the immediate must be a repeating
12899 pattern. */
12900 if (immbits != (inst.operands[1].regisimm ?
12901 inst.operands[1].reg : 0))
12902 {
12903 /* Set immbits to an invalid constant. */
12904 immbits = 0xdeadbeef;
12905 }
12906 }
12907
12908 switch (opcode)
12909 {
12910 case N_MNEM_vbic:
12911 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12912 break;
12913
12914 case N_MNEM_vorr:
12915 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12916 break;
12917
12918 case N_MNEM_vand:
12919 /* Pseudo-instruction for VBIC. */
12920 neon_invert_size (&immbits, 0, et.size);
12921 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12922 break;
12923
12924 case N_MNEM_vorn:
12925 /* Pseudo-instruction for VORR. */
12926 neon_invert_size (&immbits, 0, et.size);
12927 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12928 break;
12929
12930 default:
12931 abort ();
12932 }
12933
12934 if (cmode == FAIL)
12935 return;
12936
12937 inst.instruction |= neon_quad (rs) << 6;
12938 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12939 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12940 inst.instruction |= cmode << 8;
12941 neon_write_immbits (immbits);
12942
12943 inst.instruction = neon_dp_fixup (inst.instruction);
12944 }
12945 }
12946
12947 static void
12948 do_neon_bitfield (void)
12949 {
12950 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12951 neon_check_type (3, rs, N_IGNORE_TYPE);
12952 neon_three_same (neon_quad (rs), 0, -1);
12953 }
12954
12955 static void
12956 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
12957 unsigned destbits)
12958 {
12959 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12960 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
12961 types | N_KEY);
12962 if (et.type == NT_float)
12963 {
12964 inst.instruction = NEON_ENC_FLOAT (inst.instruction);
12965 neon_three_same (neon_quad (rs), 0, -1);
12966 }
12967 else
12968 {
12969 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12970 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
12971 }
12972 }
12973
12974 static void
12975 do_neon_dyadic_if_su (void)
12976 {
12977 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
12978 }
12979
12980 static void
12981 do_neon_dyadic_if_su_d (void)
12982 {
12983 /* This version only allow D registers, but that constraint is enforced during
12984 operand parsing so we don't need to do anything extra here. */
12985 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
12986 }
12987
12988 static void
12989 do_neon_dyadic_if_i_d (void)
12990 {
12991 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12992 affected if we specify unsigned args. */
12993 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12994 }
12995
12996 enum vfp_or_neon_is_neon_bits
12997 {
12998 NEON_CHECK_CC = 1,
12999 NEON_CHECK_ARCH = 2
13000 };
13001
13002 /* Call this function if an instruction which may have belonged to the VFP or
13003 Neon instruction sets, but turned out to be a Neon instruction (due to the
13004 operand types involved, etc.). We have to check and/or fix-up a couple of
13005 things:
13006
13007 - Make sure the user hasn't attempted to make a Neon instruction
13008 conditional.
13009 - Alter the value in the condition code field if necessary.
13010 - Make sure that the arch supports Neon instructions.
13011
13012 Which of these operations take place depends on bits from enum
13013 vfp_or_neon_is_neon_bits.
13014
13015 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
13016 current instruction's condition is COND_ALWAYS, the condition field is
13017 changed to inst.uncond_value. This is necessary because instructions shared
13018 between VFP and Neon may be conditional for the VFP variants only, and the
13019 unconditional Neon version must have, e.g., 0xF in the condition field. */
13020
13021 static int
13022 vfp_or_neon_is_neon (unsigned check)
13023 {
13024 /* Conditions are always legal in Thumb mode (IT blocks). */
13025 if (!thumb_mode && (check & NEON_CHECK_CC))
13026 {
13027 if (inst.cond != COND_ALWAYS)
13028 {
13029 first_error (_(BAD_COND));
13030 return FAIL;
13031 }
13032 if (inst.uncond_value != -1)
13033 inst.instruction |= inst.uncond_value << 28;
13034 }
13035
13036 if ((check & NEON_CHECK_ARCH)
13037 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
13038 {
13039 first_error (_(BAD_FPU));
13040 return FAIL;
13041 }
13042
13043 return SUCCESS;
13044 }
13045
13046 static void
13047 do_neon_addsub_if_i (void)
13048 {
13049 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
13050 return;
13051
13052 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13053 return;
13054
13055 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13056 affected if we specify unsigned args. */
13057 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
13058 }
13059
13060 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
13061 result to be:
13062 V<op> A,B (A is operand 0, B is operand 2)
13063 to mean:
13064 V<op> A,B,A
13065 not:
13066 V<op> A,B,B
13067 so handle that case specially. */
13068
13069 static void
13070 neon_exchange_operands (void)
13071 {
13072 void *scratch = alloca (sizeof (inst.operands[0]));
13073 if (inst.operands[1].present)
13074 {
13075 /* Swap operands[1] and operands[2]. */
13076 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
13077 inst.operands[1] = inst.operands[2];
13078 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
13079 }
13080 else
13081 {
13082 inst.operands[1] = inst.operands[2];
13083 inst.operands[2] = inst.operands[0];
13084 }
13085 }
13086
13087 static void
13088 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
13089 {
13090 if (inst.operands[2].isreg)
13091 {
13092 if (invert)
13093 neon_exchange_operands ();
13094 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
13095 }
13096 else
13097 {
13098 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13099 struct neon_type_el et = neon_check_type (2, rs,
13100 N_EQK | N_SIZ, immtypes | N_KEY);
13101
13102 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13103 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13104 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13105 inst.instruction |= LOW4 (inst.operands[1].reg);
13106 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13107 inst.instruction |= neon_quad (rs) << 6;
13108 inst.instruction |= (et.type == NT_float) << 10;
13109 inst.instruction |= neon_logbits (et.size) << 18;
13110
13111 inst.instruction = neon_dp_fixup (inst.instruction);
13112 }
13113 }
13114
13115 static void
13116 do_neon_cmp (void)
13117 {
13118 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
13119 }
13120
13121 static void
13122 do_neon_cmp_inv (void)
13123 {
13124 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
13125 }
13126
13127 static void
13128 do_neon_ceq (void)
13129 {
13130 neon_compare (N_IF_32, N_IF_32, FALSE);
13131 }
13132
13133 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
13134 scalars, which are encoded in 5 bits, M : Rm.
13135 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
13136 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
13137 index in M. */
13138
13139 static unsigned
13140 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
13141 {
13142 unsigned regno = NEON_SCALAR_REG (scalar);
13143 unsigned elno = NEON_SCALAR_INDEX (scalar);
13144
13145 switch (elsize)
13146 {
13147 case 16:
13148 if (regno > 7 || elno > 3)
13149 goto bad_scalar;
13150 return regno | (elno << 3);
13151
13152 case 32:
13153 if (regno > 15 || elno > 1)
13154 goto bad_scalar;
13155 return regno | (elno << 4);
13156
13157 default:
13158 bad_scalar:
13159 first_error (_("scalar out of range for multiply instruction"));
13160 }
13161
13162 return 0;
13163 }
13164
13165 /* Encode multiply / multiply-accumulate scalar instructions. */
13166
13167 static void
13168 neon_mul_mac (struct neon_type_el et, int ubit)
13169 {
13170 unsigned scalar;
13171
13172 /* Give a more helpful error message if we have an invalid type. */
13173 if (et.type == NT_invtype)
13174 return;
13175
13176 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
13177 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13178 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13179 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13180 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13181 inst.instruction |= LOW4 (scalar);
13182 inst.instruction |= HI1 (scalar) << 5;
13183 inst.instruction |= (et.type == NT_float) << 8;
13184 inst.instruction |= neon_logbits (et.size) << 20;
13185 inst.instruction |= (ubit != 0) << 24;
13186
13187 inst.instruction = neon_dp_fixup (inst.instruction);
13188 }
13189
13190 static void
13191 do_neon_mac_maybe_scalar (void)
13192 {
13193 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
13194 return;
13195
13196 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13197 return;
13198
13199 if (inst.operands[2].isscalar)
13200 {
13201 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
13202 struct neon_type_el et = neon_check_type (3, rs,
13203 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
13204 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13205 neon_mul_mac (et, neon_quad (rs));
13206 }
13207 else
13208 {
13209 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13210 affected if we specify unsigned args. */
13211 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13212 }
13213 }
13214
13215 static void
13216 do_neon_fmac (void)
13217 {
13218 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
13219 return;
13220
13221 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13222 return;
13223
13224 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13225 }
13226
13227 static void
13228 do_neon_tst (void)
13229 {
13230 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13231 struct neon_type_el et = neon_check_type (3, rs,
13232 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
13233 neon_three_same (neon_quad (rs), 0, et.size);
13234 }
13235
13236 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
13237 same types as the MAC equivalents. The polynomial type for this instruction
13238 is encoded the same as the integer type. */
13239
13240 static void
13241 do_neon_mul (void)
13242 {
13243 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
13244 return;
13245
13246 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13247 return;
13248
13249 if (inst.operands[2].isscalar)
13250 do_neon_mac_maybe_scalar ();
13251 else
13252 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
13253 }
13254
13255 static void
13256 do_neon_qdmulh (void)
13257 {
13258 if (inst.operands[2].isscalar)
13259 {
13260 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
13261 struct neon_type_el et = neon_check_type (3, rs,
13262 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
13263 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13264 neon_mul_mac (et, neon_quad (rs));
13265 }
13266 else
13267 {
13268 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13269 struct neon_type_el et = neon_check_type (3, rs,
13270 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
13271 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13272 /* The U bit (rounding) comes from bit mask. */
13273 neon_three_same (neon_quad (rs), 0, et.size);
13274 }
13275 }
13276
13277 static void
13278 do_neon_fcmp_absolute (void)
13279 {
13280 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13281 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
13282 /* Size field comes from bit mask. */
13283 neon_three_same (neon_quad (rs), 1, -1);
13284 }
13285
13286 static void
13287 do_neon_fcmp_absolute_inv (void)
13288 {
13289 neon_exchange_operands ();
13290 do_neon_fcmp_absolute ();
13291 }
13292
13293 static void
13294 do_neon_step (void)
13295 {
13296 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13297 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
13298 neon_three_same (neon_quad (rs), 0, -1);
13299 }
13300
13301 static void
13302 do_neon_abs_neg (void)
13303 {
13304 enum neon_shape rs;
13305 struct neon_type_el et;
13306
13307 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
13308 return;
13309
13310 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13311 return;
13312
13313 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13314 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
13315
13316 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13317 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13318 inst.instruction |= LOW4 (inst.operands[1].reg);
13319 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13320 inst.instruction |= neon_quad (rs) << 6;
13321 inst.instruction |= (et.type == NT_float) << 10;
13322 inst.instruction |= neon_logbits (et.size) << 18;
13323
13324 inst.instruction = neon_dp_fixup (inst.instruction);
13325 }
13326
13327 static void
13328 do_neon_sli (void)
13329 {
13330 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13331 struct neon_type_el et = neon_check_type (2, rs,
13332 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13333 int imm = inst.operands[2].imm;
13334 constraint (imm < 0 || (unsigned)imm >= et.size,
13335 _("immediate out of range for insert"));
13336 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
13337 }
13338
13339 static void
13340 do_neon_sri (void)
13341 {
13342 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13343 struct neon_type_el et = neon_check_type (2, rs,
13344 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13345 int imm = inst.operands[2].imm;
13346 constraint (imm < 1 || (unsigned)imm > et.size,
13347 _("immediate out of range for insert"));
13348 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
13349 }
13350
13351 static void
13352 do_neon_qshlu_imm (void)
13353 {
13354 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13355 struct neon_type_el et = neon_check_type (2, rs,
13356 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
13357 int imm = inst.operands[2].imm;
13358 constraint (imm < 0 || (unsigned)imm >= et.size,
13359 _("immediate out of range for shift"));
13360 /* Only encodes the 'U present' variant of the instruction.
13361 In this case, signed types have OP (bit 8) set to 0.
13362 Unsigned types have OP set to 1. */
13363 inst.instruction |= (et.type == NT_unsigned) << 8;
13364 /* The rest of the bits are the same as other immediate shifts. */
13365 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
13366 }
13367
13368 static void
13369 do_neon_qmovn (void)
13370 {
13371 struct neon_type_el et = neon_check_type (2, NS_DQ,
13372 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13373 /* Saturating move where operands can be signed or unsigned, and the
13374 destination has the same signedness. */
13375 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13376 if (et.type == NT_unsigned)
13377 inst.instruction |= 0xc0;
13378 else
13379 inst.instruction |= 0x80;
13380 neon_two_same (0, 1, et.size / 2);
13381 }
13382
13383 static void
13384 do_neon_qmovun (void)
13385 {
13386 struct neon_type_el et = neon_check_type (2, NS_DQ,
13387 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13388 /* Saturating move with unsigned results. Operands must be signed. */
13389 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13390 neon_two_same (0, 1, et.size / 2);
13391 }
13392
13393 static void
13394 do_neon_rshift_sat_narrow (void)
13395 {
13396 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13397 or unsigned. If operands are unsigned, results must also be unsigned. */
13398 struct neon_type_el et = neon_check_type (2, NS_DQI,
13399 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13400 int imm = inst.operands[2].imm;
13401 /* This gets the bounds check, size encoding and immediate bits calculation
13402 right. */
13403 et.size /= 2;
13404
13405 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
13406 VQMOVN.I<size> <Dd>, <Qm>. */
13407 if (imm == 0)
13408 {
13409 inst.operands[2].present = 0;
13410 inst.instruction = N_MNEM_vqmovn;
13411 do_neon_qmovn ();
13412 return;
13413 }
13414
13415 constraint (imm < 1 || (unsigned)imm > et.size,
13416 _("immediate out of range"));
13417 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
13418 }
13419
13420 static void
13421 do_neon_rshift_sat_narrow_u (void)
13422 {
13423 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13424 or unsigned. If operands are unsigned, results must also be unsigned. */
13425 struct neon_type_el et = neon_check_type (2, NS_DQI,
13426 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13427 int imm = inst.operands[2].imm;
13428 /* This gets the bounds check, size encoding and immediate bits calculation
13429 right. */
13430 et.size /= 2;
13431
13432 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
13433 VQMOVUN.I<size> <Dd>, <Qm>. */
13434 if (imm == 0)
13435 {
13436 inst.operands[2].present = 0;
13437 inst.instruction = N_MNEM_vqmovun;
13438 do_neon_qmovun ();
13439 return;
13440 }
13441
13442 constraint (imm < 1 || (unsigned)imm > et.size,
13443 _("immediate out of range"));
13444 /* FIXME: The manual is kind of unclear about what value U should have in
13445 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
13446 must be 1. */
13447 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
13448 }
13449
13450 static void
13451 do_neon_movn (void)
13452 {
13453 struct neon_type_el et = neon_check_type (2, NS_DQ,
13454 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
13455 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13456 neon_two_same (0, 1, et.size / 2);
13457 }
13458
13459 static void
13460 do_neon_rshift_narrow (void)
13461 {
13462 struct neon_type_el et = neon_check_type (2, NS_DQI,
13463 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
13464 int imm = inst.operands[2].imm;
13465 /* This gets the bounds check, size encoding and immediate bits calculation
13466 right. */
13467 et.size /= 2;
13468
13469 /* If immediate is zero then we are a pseudo-instruction for
13470 VMOVN.I<size> <Dd>, <Qm> */
13471 if (imm == 0)
13472 {
13473 inst.operands[2].present = 0;
13474 inst.instruction = N_MNEM_vmovn;
13475 do_neon_movn ();
13476 return;
13477 }
13478
13479 constraint (imm < 1 || (unsigned)imm > et.size,
13480 _("immediate out of range for narrowing operation"));
13481 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
13482 }
13483
13484 static void
13485 do_neon_shll (void)
13486 {
13487 /* FIXME: Type checking when lengthening. */
13488 struct neon_type_el et = neon_check_type (2, NS_QDI,
13489 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
13490 unsigned imm = inst.operands[2].imm;
13491
13492 if (imm == et.size)
13493 {
13494 /* Maximum shift variant. */
13495 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13496 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13497 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13498 inst.instruction |= LOW4 (inst.operands[1].reg);
13499 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13500 inst.instruction |= neon_logbits (et.size) << 18;
13501
13502 inst.instruction = neon_dp_fixup (inst.instruction);
13503 }
13504 else
13505 {
13506 /* A more-specific type check for non-max versions. */
13507 et = neon_check_type (2, NS_QDI,
13508 N_EQK | N_DBL, N_SU_32 | N_KEY);
13509 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13510 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
13511 }
13512 }
13513
13514 /* Check the various types for the VCVT instruction, and return which version
13515 the current instruction is. */
13516
13517 static int
13518 neon_cvt_flavour (enum neon_shape rs)
13519 {
13520 #define CVT_VAR(C,X,Y) \
13521 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
13522 if (et.type != NT_invtype) \
13523 { \
13524 inst.error = NULL; \
13525 return (C); \
13526 }
13527 struct neon_type_el et;
13528 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
13529 || rs == NS_FF) ? N_VFP : 0;
13530 /* The instruction versions which take an immediate take one register
13531 argument, which is extended to the width of the full register. Thus the
13532 "source" and "destination" registers must have the same width. Hack that
13533 here by making the size equal to the key (wider, in this case) operand. */
13534 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
13535
13536 CVT_VAR (0, N_S32, N_F32);
13537 CVT_VAR (1, N_U32, N_F32);
13538 CVT_VAR (2, N_F32, N_S32);
13539 CVT_VAR (3, N_F32, N_U32);
13540 /* Half-precision conversions. */
13541 CVT_VAR (4, N_F32, N_F16);
13542 CVT_VAR (5, N_F16, N_F32);
13543
13544 whole_reg = N_VFP;
13545
13546 /* VFP instructions. */
13547 CVT_VAR (6, N_F32, N_F64);
13548 CVT_VAR (7, N_F64, N_F32);
13549 CVT_VAR (8, N_S32, N_F64 | key);
13550 CVT_VAR (9, N_U32, N_F64 | key);
13551 CVT_VAR (10, N_F64 | key, N_S32);
13552 CVT_VAR (11, N_F64 | key, N_U32);
13553 /* VFP instructions with bitshift. */
13554 CVT_VAR (12, N_F32 | key, N_S16);
13555 CVT_VAR (13, N_F32 | key, N_U16);
13556 CVT_VAR (14, N_F64 | key, N_S16);
13557 CVT_VAR (15, N_F64 | key, N_U16);
13558 CVT_VAR (16, N_S16, N_F32 | key);
13559 CVT_VAR (17, N_U16, N_F32 | key);
13560 CVT_VAR (18, N_S16, N_F64 | key);
13561 CVT_VAR (19, N_U16, N_F64 | key);
13562
13563 return -1;
13564 #undef CVT_VAR
13565 }
13566
13567 /* Neon-syntax VFP conversions. */
13568
13569 static void
13570 do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
13571 {
13572 const char *opname = 0;
13573
13574 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
13575 {
13576 /* Conversions with immediate bitshift. */
13577 const char *enc[] =
13578 {
13579 "ftosls",
13580 "ftouls",
13581 "fsltos",
13582 "fultos",
13583 NULL,
13584 NULL,
13585 NULL,
13586 NULL,
13587 "ftosld",
13588 "ftould",
13589 "fsltod",
13590 "fultod",
13591 "fshtos",
13592 "fuhtos",
13593 "fshtod",
13594 "fuhtod",
13595 "ftoshs",
13596 "ftouhs",
13597 "ftoshd",
13598 "ftouhd"
13599 };
13600
13601 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13602 {
13603 opname = enc[flavour];
13604 constraint (inst.operands[0].reg != inst.operands[1].reg,
13605 _("operands 0 and 1 must be the same register"));
13606 inst.operands[1] = inst.operands[2];
13607 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
13608 }
13609 }
13610 else
13611 {
13612 /* Conversions without bitshift. */
13613 const char *enc[] =
13614 {
13615 "ftosis",
13616 "ftouis",
13617 "fsitos",
13618 "fuitos",
13619 "NULL",
13620 "NULL",
13621 "fcvtsd",
13622 "fcvtds",
13623 "ftosid",
13624 "ftouid",
13625 "fsitod",
13626 "fuitod"
13627 };
13628
13629 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13630 opname = enc[flavour];
13631 }
13632
13633 if (opname)
13634 do_vfp_nsyn_opcode (opname);
13635 }
13636
13637 static void
13638 do_vfp_nsyn_cvtz (void)
13639 {
13640 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
13641 int flavour = neon_cvt_flavour (rs);
13642 const char *enc[] =
13643 {
13644 "ftosizs",
13645 "ftouizs",
13646 NULL,
13647 NULL,
13648 NULL,
13649 NULL,
13650 NULL,
13651 NULL,
13652 "ftosizd",
13653 "ftouizd"
13654 };
13655
13656 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
13657 do_vfp_nsyn_opcode (enc[flavour]);
13658 }
13659
13660 static void
13661 do_neon_cvt (void)
13662 {
13663 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
13664 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
13665 int flavour = neon_cvt_flavour (rs);
13666
13667 /* VFP rather than Neon conversions. */
13668 if (flavour >= 6)
13669 {
13670 do_vfp_nsyn_cvt (rs, flavour);
13671 return;
13672 }
13673
13674 switch (rs)
13675 {
13676 case NS_DDI:
13677 case NS_QQI:
13678 {
13679 unsigned immbits;
13680 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
13681
13682 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13683 return;
13684
13685 /* Fixed-point conversion with #0 immediate is encoded as an
13686 integer conversion. */
13687 if (inst.operands[2].present && inst.operands[2].imm == 0)
13688 goto int_encode;
13689 immbits = 32 - inst.operands[2].imm;
13690 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13691 if (flavour != -1)
13692 inst.instruction |= enctab[flavour];
13693 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13694 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13695 inst.instruction |= LOW4 (inst.operands[1].reg);
13696 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13697 inst.instruction |= neon_quad (rs) << 6;
13698 inst.instruction |= 1 << 21;
13699 inst.instruction |= immbits << 16;
13700
13701 inst.instruction = neon_dp_fixup (inst.instruction);
13702 }
13703 break;
13704
13705 case NS_DD:
13706 case NS_QQ:
13707 int_encode:
13708 {
13709 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
13710
13711 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13712
13713 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13714 return;
13715
13716 if (flavour != -1)
13717 inst.instruction |= enctab[flavour];
13718
13719 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13720 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13721 inst.instruction |= LOW4 (inst.operands[1].reg);
13722 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13723 inst.instruction |= neon_quad (rs) << 6;
13724 inst.instruction |= 2 << 18;
13725
13726 inst.instruction = neon_dp_fixup (inst.instruction);
13727 }
13728 break;
13729
13730 /* Half-precision conversions for Advanced SIMD -- neon. */
13731 case NS_QD:
13732 case NS_DQ:
13733
13734 if ((rs == NS_DQ)
13735 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
13736 {
13737 as_bad (_("operand size must match register width"));
13738 break;
13739 }
13740
13741 if ((rs == NS_QD)
13742 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
13743 {
13744 as_bad (_("operand size must match register width"));
13745 break;
13746 }
13747
13748 if (rs == NS_DQ)
13749 inst.instruction = 0x3b60600;
13750 else
13751 inst.instruction = 0x3b60700;
13752
13753 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13754 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13755 inst.instruction |= LOW4 (inst.operands[1].reg);
13756 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13757 inst.instruction = neon_dp_fixup (inst.instruction);
13758 break;
13759
13760 default:
13761 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
13762 do_vfp_nsyn_cvt (rs, flavour);
13763 }
13764 }
13765
13766 static void
13767 do_neon_cvtb (void)
13768 {
13769 inst.instruction = 0xeb20a40;
13770
13771 /* The sizes are attached to the mnemonic. */
13772 if (inst.vectype.el[0].type != NT_invtype
13773 && inst.vectype.el[0].size == 16)
13774 inst.instruction |= 0x00010000;
13775
13776 /* Programmer's syntax: the sizes are attached to the operands. */
13777 else if (inst.operands[0].vectype.type != NT_invtype
13778 && inst.operands[0].vectype.size == 16)
13779 inst.instruction |= 0x00010000;
13780
13781 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
13782 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
13783 do_vfp_cond_or_thumb ();
13784 }
13785
13786
13787 static void
13788 do_neon_cvtt (void)
13789 {
13790 do_neon_cvtb ();
13791 inst.instruction |= 0x80;
13792 }
13793
13794 static void
13795 neon_move_immediate (void)
13796 {
13797 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
13798 struct neon_type_el et = neon_check_type (2, rs,
13799 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
13800 unsigned immlo, immhi = 0, immbits;
13801 int op, cmode, float_p;
13802
13803 constraint (et.type == NT_invtype,
13804 _("operand size must be specified for immediate VMOV"));
13805
13806 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
13807 op = (inst.instruction & (1 << 5)) != 0;
13808
13809 immlo = inst.operands[1].imm;
13810 if (inst.operands[1].regisimm)
13811 immhi = inst.operands[1].reg;
13812
13813 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
13814 _("immediate has bits set outside the operand size"));
13815
13816 float_p = inst.operands[1].immisfloat;
13817
13818 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
13819 et.size, et.type)) == FAIL)
13820 {
13821 /* Invert relevant bits only. */
13822 neon_invert_size (&immlo, &immhi, et.size);
13823 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
13824 with one or the other; those cases are caught by
13825 neon_cmode_for_move_imm. */
13826 op = !op;
13827 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
13828 &op, et.size, et.type)) == FAIL)
13829 {
13830 first_error (_("immediate out of range"));
13831 return;
13832 }
13833 }
13834
13835 inst.instruction &= ~(1 << 5);
13836 inst.instruction |= op << 5;
13837
13838 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13839 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13840 inst.instruction |= neon_quad (rs) << 6;
13841 inst.instruction |= cmode << 8;
13842
13843 neon_write_immbits (immbits);
13844 }
13845
13846 static void
13847 do_neon_mvn (void)
13848 {
13849 if (inst.operands[1].isreg)
13850 {
13851 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13852
13853 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13854 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13855 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13856 inst.instruction |= LOW4 (inst.operands[1].reg);
13857 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13858 inst.instruction |= neon_quad (rs) << 6;
13859 }
13860 else
13861 {
13862 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13863 neon_move_immediate ();
13864 }
13865
13866 inst.instruction = neon_dp_fixup (inst.instruction);
13867 }
13868
13869 /* Encode instructions of form:
13870
13871 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
13872 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
13873
13874 static void
13875 neon_mixed_length (struct neon_type_el et, unsigned size)
13876 {
13877 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13878 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13879 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13880 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13881 inst.instruction |= LOW4 (inst.operands[2].reg);
13882 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13883 inst.instruction |= (et.type == NT_unsigned) << 24;
13884 inst.instruction |= neon_logbits (size) << 20;
13885
13886 inst.instruction = neon_dp_fixup (inst.instruction);
13887 }
13888
13889 static void
13890 do_neon_dyadic_long (void)
13891 {
13892 /* FIXME: Type checking for lengthening op. */
13893 struct neon_type_el et = neon_check_type (3, NS_QDD,
13894 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
13895 neon_mixed_length (et, et.size);
13896 }
13897
13898 static void
13899 do_neon_abal (void)
13900 {
13901 struct neon_type_el et = neon_check_type (3, NS_QDD,
13902 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
13903 neon_mixed_length (et, et.size);
13904 }
13905
13906 static void
13907 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
13908 {
13909 if (inst.operands[2].isscalar)
13910 {
13911 struct neon_type_el et = neon_check_type (3, NS_QDS,
13912 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
13913 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13914 neon_mul_mac (et, et.type == NT_unsigned);
13915 }
13916 else
13917 {
13918 struct neon_type_el et = neon_check_type (3, NS_QDD,
13919 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
13920 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13921 neon_mixed_length (et, et.size);
13922 }
13923 }
13924
13925 static void
13926 do_neon_mac_maybe_scalar_long (void)
13927 {
13928 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
13929 }
13930
13931 static void
13932 do_neon_dyadic_wide (void)
13933 {
13934 struct neon_type_el et = neon_check_type (3, NS_QQD,
13935 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
13936 neon_mixed_length (et, et.size);
13937 }
13938
13939 static void
13940 do_neon_dyadic_narrow (void)
13941 {
13942 struct neon_type_el et = neon_check_type (3, NS_QDD,
13943 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
13944 /* Operand sign is unimportant, and the U bit is part of the opcode,
13945 so force the operand type to integer. */
13946 et.type = NT_integer;
13947 neon_mixed_length (et, et.size / 2);
13948 }
13949
13950 static void
13951 do_neon_mul_sat_scalar_long (void)
13952 {
13953 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
13954 }
13955
13956 static void
13957 do_neon_vmull (void)
13958 {
13959 if (inst.operands[2].isscalar)
13960 do_neon_mac_maybe_scalar_long ();
13961 else
13962 {
13963 struct neon_type_el et = neon_check_type (3, NS_QDD,
13964 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
13965 if (et.type == NT_poly)
13966 inst.instruction = NEON_ENC_POLY (inst.instruction);
13967 else
13968 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13969 /* For polynomial encoding, size field must be 0b00 and the U bit must be
13970 zero. Should be OK as-is. */
13971 neon_mixed_length (et, et.size);
13972 }
13973 }
13974
13975 static void
13976 do_neon_ext (void)
13977 {
13978 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
13979 struct neon_type_el et = neon_check_type (3, rs,
13980 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13981 unsigned imm = (inst.operands[3].imm * et.size) / 8;
13982
13983 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
13984 _("shift out of range"));
13985 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13986 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13987 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13988 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13989 inst.instruction |= LOW4 (inst.operands[2].reg);
13990 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13991 inst.instruction |= neon_quad (rs) << 6;
13992 inst.instruction |= imm << 8;
13993
13994 inst.instruction = neon_dp_fixup (inst.instruction);
13995 }
13996
13997 static void
13998 do_neon_rev (void)
13999 {
14000 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14001 struct neon_type_el et = neon_check_type (2, rs,
14002 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14003 unsigned op = (inst.instruction >> 7) & 3;
14004 /* N (width of reversed regions) is encoded as part of the bitmask. We
14005 extract it here to check the elements to be reversed are smaller.
14006 Otherwise we'd get a reserved instruction. */
14007 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
14008 gas_assert (elsize != 0);
14009 constraint (et.size >= elsize,
14010 _("elements must be smaller than reversal region"));
14011 neon_two_same (neon_quad (rs), 1, et.size);
14012 }
14013
14014 static void
14015 do_neon_dup (void)
14016 {
14017 if (inst.operands[1].isscalar)
14018 {
14019 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
14020 struct neon_type_el et = neon_check_type (2, rs,
14021 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14022 unsigned sizebits = et.size >> 3;
14023 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
14024 int logsize = neon_logbits (et.size);
14025 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
14026
14027 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
14028 return;
14029
14030 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
14031 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14032 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14033 inst.instruction |= LOW4 (dm);
14034 inst.instruction |= HI1 (dm) << 5;
14035 inst.instruction |= neon_quad (rs) << 6;
14036 inst.instruction |= x << 17;
14037 inst.instruction |= sizebits << 16;
14038
14039 inst.instruction = neon_dp_fixup (inst.instruction);
14040 }
14041 else
14042 {
14043 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
14044 struct neon_type_el et = neon_check_type (2, rs,
14045 N_8 | N_16 | N_32 | N_KEY, N_EQK);
14046 /* Duplicate ARM register to lanes of vector. */
14047 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
14048 switch (et.size)
14049 {
14050 case 8: inst.instruction |= 0x400000; break;
14051 case 16: inst.instruction |= 0x000020; break;
14052 case 32: inst.instruction |= 0x000000; break;
14053 default: break;
14054 }
14055 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14056 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
14057 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
14058 inst.instruction |= neon_quad (rs) << 21;
14059 /* The encoding for this instruction is identical for the ARM and Thumb
14060 variants, except for the condition field. */
14061 do_vfp_cond_or_thumb ();
14062 }
14063 }
14064
14065 /* VMOV has particularly many variations. It can be one of:
14066 0. VMOV<c><q> <Qd>, <Qm>
14067 1. VMOV<c><q> <Dd>, <Dm>
14068 (Register operations, which are VORR with Rm = Rn.)
14069 2. VMOV<c><q>.<dt> <Qd>, #<imm>
14070 3. VMOV<c><q>.<dt> <Dd>, #<imm>
14071 (Immediate loads.)
14072 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
14073 (ARM register to scalar.)
14074 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
14075 (Two ARM registers to vector.)
14076 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
14077 (Scalar to ARM register.)
14078 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
14079 (Vector to two ARM registers.)
14080 8. VMOV.F32 <Sd>, <Sm>
14081 9. VMOV.F64 <Dd>, <Dm>
14082 (VFP register moves.)
14083 10. VMOV.F32 <Sd>, #imm
14084 11. VMOV.F64 <Dd>, #imm
14085 (VFP float immediate load.)
14086 12. VMOV <Rd>, <Sm>
14087 (VFP single to ARM reg.)
14088 13. VMOV <Sd>, <Rm>
14089 (ARM reg to VFP single.)
14090 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
14091 (Two ARM regs to two VFP singles.)
14092 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
14093 (Two VFP singles to two ARM regs.)
14094
14095 These cases can be disambiguated using neon_select_shape, except cases 1/9
14096 and 3/11 which depend on the operand type too.
14097
14098 All the encoded bits are hardcoded by this function.
14099
14100 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
14101 Cases 5, 7 may be used with VFPv2 and above.
14102
14103 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
14104 can specify a type where it doesn't make sense to, and is ignored). */
14105
14106 static void
14107 do_neon_mov (void)
14108 {
14109 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
14110 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
14111 NS_NULL);
14112 struct neon_type_el et;
14113 const char *ldconst = 0;
14114
14115 switch (rs)
14116 {
14117 case NS_DD: /* case 1/9. */
14118 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14119 /* It is not an error here if no type is given. */
14120 inst.error = NULL;
14121 if (et.type == NT_float && et.size == 64)
14122 {
14123 do_vfp_nsyn_opcode ("fcpyd");
14124 break;
14125 }
14126 /* fall through. */
14127
14128 case NS_QQ: /* case 0/1. */
14129 {
14130 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14131 return;
14132 /* The architecture manual I have doesn't explicitly state which
14133 value the U bit should have for register->register moves, but
14134 the equivalent VORR instruction has U = 0, so do that. */
14135 inst.instruction = 0x0200110;
14136 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14137 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14138 inst.instruction |= LOW4 (inst.operands[1].reg);
14139 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14140 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14141 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14142 inst.instruction |= neon_quad (rs) << 6;
14143
14144 inst.instruction = neon_dp_fixup (inst.instruction);
14145 }
14146 break;
14147
14148 case NS_DI: /* case 3/11. */
14149 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14150 inst.error = NULL;
14151 if (et.type == NT_float && et.size == 64)
14152 {
14153 /* case 11 (fconstd). */
14154 ldconst = "fconstd";
14155 goto encode_fconstd;
14156 }
14157 /* fall through. */
14158
14159 case NS_QI: /* case 2/3. */
14160 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14161 return;
14162 inst.instruction = 0x0800010;
14163 neon_move_immediate ();
14164 inst.instruction = neon_dp_fixup (inst.instruction);
14165 break;
14166
14167 case NS_SR: /* case 4. */
14168 {
14169 unsigned bcdebits = 0;
14170 int logsize;
14171 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
14172 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
14173
14174 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
14175 logsize = neon_logbits (et.size);
14176
14177 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14178 _(BAD_FPU));
14179 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14180 && et.size != 32, _(BAD_FPU));
14181 constraint (et.type == NT_invtype, _("bad type for scalar"));
14182 constraint (x >= 64 / et.size, _("scalar index out of range"));
14183
14184 switch (et.size)
14185 {
14186 case 8: bcdebits = 0x8; break;
14187 case 16: bcdebits = 0x1; break;
14188 case 32: bcdebits = 0x0; break;
14189 default: ;
14190 }
14191
14192 bcdebits |= x << logsize;
14193
14194 inst.instruction = 0xe000b10;
14195 do_vfp_cond_or_thumb ();
14196 inst.instruction |= LOW4 (dn) << 16;
14197 inst.instruction |= HI1 (dn) << 7;
14198 inst.instruction |= inst.operands[1].reg << 12;
14199 inst.instruction |= (bcdebits & 3) << 5;
14200 inst.instruction |= (bcdebits >> 2) << 21;
14201 }
14202 break;
14203
14204 case NS_DRR: /* case 5 (fmdrr). */
14205 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
14206 _(BAD_FPU));
14207
14208 inst.instruction = 0xc400b10;
14209 do_vfp_cond_or_thumb ();
14210 inst.instruction |= LOW4 (inst.operands[0].reg);
14211 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
14212 inst.instruction |= inst.operands[1].reg << 12;
14213 inst.instruction |= inst.operands[2].reg << 16;
14214 break;
14215
14216 case NS_RS: /* case 6. */
14217 {
14218 unsigned logsize;
14219 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
14220 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
14221 unsigned abcdebits = 0;
14222
14223 et = neon_check_type (2, NS_NULL,
14224 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
14225 logsize = neon_logbits (et.size);
14226
14227 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14228 _(BAD_FPU));
14229 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14230 && et.size != 32, _(BAD_FPU));
14231 constraint (et.type == NT_invtype, _("bad type for scalar"));
14232 constraint (x >= 64 / et.size, _("scalar index out of range"));
14233
14234 switch (et.size)
14235 {
14236 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
14237 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
14238 case 32: abcdebits = 0x00; break;
14239 default: ;
14240 }
14241
14242 abcdebits |= x << logsize;
14243 inst.instruction = 0xe100b10;
14244 do_vfp_cond_or_thumb ();
14245 inst.instruction |= LOW4 (dn) << 16;
14246 inst.instruction |= HI1 (dn) << 7;
14247 inst.instruction |= inst.operands[0].reg << 12;
14248 inst.instruction |= (abcdebits & 3) << 5;
14249 inst.instruction |= (abcdebits >> 2) << 21;
14250 }
14251 break;
14252
14253 case NS_RRD: /* case 7 (fmrrd). */
14254 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
14255 _(BAD_FPU));
14256
14257 inst.instruction = 0xc500b10;
14258 do_vfp_cond_or_thumb ();
14259 inst.instruction |= inst.operands[0].reg << 12;
14260 inst.instruction |= inst.operands[1].reg << 16;
14261 inst.instruction |= LOW4 (inst.operands[2].reg);
14262 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14263 break;
14264
14265 case NS_FF: /* case 8 (fcpys). */
14266 do_vfp_nsyn_opcode ("fcpys");
14267 break;
14268
14269 case NS_FI: /* case 10 (fconsts). */
14270 ldconst = "fconsts";
14271 encode_fconstd:
14272 if (is_quarter_float (inst.operands[1].imm))
14273 {
14274 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
14275 do_vfp_nsyn_opcode (ldconst);
14276 }
14277 else
14278 first_error (_("immediate out of range"));
14279 break;
14280
14281 case NS_RF: /* case 12 (fmrs). */
14282 do_vfp_nsyn_opcode ("fmrs");
14283 break;
14284
14285 case NS_FR: /* case 13 (fmsr). */
14286 do_vfp_nsyn_opcode ("fmsr");
14287 break;
14288
14289 /* The encoders for the fmrrs and fmsrr instructions expect three operands
14290 (one of which is a list), but we have parsed four. Do some fiddling to
14291 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
14292 expect. */
14293 case NS_RRFF: /* case 14 (fmrrs). */
14294 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
14295 _("VFP registers must be adjacent"));
14296 inst.operands[2].imm = 2;
14297 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14298 do_vfp_nsyn_opcode ("fmrrs");
14299 break;
14300
14301 case NS_FFRR: /* case 15 (fmsrr). */
14302 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
14303 _("VFP registers must be adjacent"));
14304 inst.operands[1] = inst.operands[2];
14305 inst.operands[2] = inst.operands[3];
14306 inst.operands[0].imm = 2;
14307 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14308 do_vfp_nsyn_opcode ("fmsrr");
14309 break;
14310
14311 default:
14312 abort ();
14313 }
14314 }
14315
14316 static void
14317 do_neon_rshift_round_imm (void)
14318 {
14319 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14320 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
14321 int imm = inst.operands[2].imm;
14322
14323 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
14324 if (imm == 0)
14325 {
14326 inst.operands[2].present = 0;
14327 do_neon_mov ();
14328 return;
14329 }
14330
14331 constraint (imm < 1 || (unsigned)imm > et.size,
14332 _("immediate out of range for shift"));
14333 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
14334 et.size - imm);
14335 }
14336
14337 static void
14338 do_neon_movl (void)
14339 {
14340 struct neon_type_el et = neon_check_type (2, NS_QD,
14341 N_EQK | N_DBL, N_SU_32 | N_KEY);
14342 unsigned sizebits = et.size >> 3;
14343 inst.instruction |= sizebits << 19;
14344 neon_two_same (0, et.type == NT_unsigned, -1);
14345 }
14346
14347 static void
14348 do_neon_trn (void)
14349 {
14350 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14351 struct neon_type_el et = neon_check_type (2, rs,
14352 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14353 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
14354 neon_two_same (neon_quad (rs), 1, et.size);
14355 }
14356
14357 static void
14358 do_neon_zip_uzp (void)
14359 {
14360 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14361 struct neon_type_el et = neon_check_type (2, rs,
14362 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14363 if (rs == NS_DD && et.size == 32)
14364 {
14365 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
14366 inst.instruction = N_MNEM_vtrn;
14367 do_neon_trn ();
14368 return;
14369 }
14370 neon_two_same (neon_quad (rs), 1, et.size);
14371 }
14372
14373 static void
14374 do_neon_sat_abs_neg (void)
14375 {
14376 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14377 struct neon_type_el et = neon_check_type (2, rs,
14378 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
14379 neon_two_same (neon_quad (rs), 1, et.size);
14380 }
14381
14382 static void
14383 do_neon_pair_long (void)
14384 {
14385 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14386 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
14387 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
14388 inst.instruction |= (et.type == NT_unsigned) << 7;
14389 neon_two_same (neon_quad (rs), 1, et.size);
14390 }
14391
14392 static void
14393 do_neon_recip_est (void)
14394 {
14395 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14396 struct neon_type_el et = neon_check_type (2, rs,
14397 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
14398 inst.instruction |= (et.type == NT_float) << 8;
14399 neon_two_same (neon_quad (rs), 1, et.size);
14400 }
14401
14402 static void
14403 do_neon_cls (void)
14404 {
14405 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14406 struct neon_type_el et = neon_check_type (2, rs,
14407 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
14408 neon_two_same (neon_quad (rs), 1, et.size);
14409 }
14410
14411 static void
14412 do_neon_clz (void)
14413 {
14414 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14415 struct neon_type_el et = neon_check_type (2, rs,
14416 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
14417 neon_two_same (neon_quad (rs), 1, et.size);
14418 }
14419
14420 static void
14421 do_neon_cnt (void)
14422 {
14423 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14424 struct neon_type_el et = neon_check_type (2, rs,
14425 N_EQK | N_INT, N_8 | N_KEY);
14426 neon_two_same (neon_quad (rs), 1, et.size);
14427 }
14428
14429 static void
14430 do_neon_swp (void)
14431 {
14432 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14433 neon_two_same (neon_quad (rs), 1, -1);
14434 }
14435
14436 static void
14437 do_neon_tbl_tbx (void)
14438 {
14439 unsigned listlenbits;
14440 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
14441
14442 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
14443 {
14444 first_error (_("bad list length for table lookup"));
14445 return;
14446 }
14447
14448 listlenbits = inst.operands[1].imm - 1;
14449 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14450 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14451 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14452 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14453 inst.instruction |= LOW4 (inst.operands[2].reg);
14454 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14455 inst.instruction |= listlenbits << 8;
14456
14457 inst.instruction = neon_dp_fixup (inst.instruction);
14458 }
14459
14460 static void
14461 do_neon_ldm_stm (void)
14462 {
14463 /* P, U and L bits are part of bitmask. */
14464 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
14465 unsigned offsetbits = inst.operands[1].imm * 2;
14466
14467 if (inst.operands[1].issingle)
14468 {
14469 do_vfp_nsyn_ldm_stm (is_dbmode);
14470 return;
14471 }
14472
14473 constraint (is_dbmode && !inst.operands[0].writeback,
14474 _("writeback (!) must be used for VLDMDB and VSTMDB"));
14475
14476 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14477 _("register list must contain at least 1 and at most 16 "
14478 "registers"));
14479
14480 inst.instruction |= inst.operands[0].reg << 16;
14481 inst.instruction |= inst.operands[0].writeback << 21;
14482 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14483 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
14484
14485 inst.instruction |= offsetbits;
14486
14487 do_vfp_cond_or_thumb ();
14488 }
14489
14490 static void
14491 do_neon_ldr_str (void)
14492 {
14493 int is_ldr = (inst.instruction & (1 << 20)) != 0;
14494
14495 if (inst.operands[0].issingle)
14496 {
14497 if (is_ldr)
14498 do_vfp_nsyn_opcode ("flds");
14499 else
14500 do_vfp_nsyn_opcode ("fsts");
14501 }
14502 else
14503 {
14504 if (is_ldr)
14505 do_vfp_nsyn_opcode ("fldd");
14506 else
14507 do_vfp_nsyn_opcode ("fstd");
14508 }
14509 }
14510
14511 /* "interleave" version also handles non-interleaving register VLD1/VST1
14512 instructions. */
14513
14514 static void
14515 do_neon_ld_st_interleave (void)
14516 {
14517 struct neon_type_el et = neon_check_type (1, NS_NULL,
14518 N_8 | N_16 | N_32 | N_64);
14519 unsigned alignbits = 0;
14520 unsigned idx;
14521 /* The bits in this table go:
14522 0: register stride of one (0) or two (1)
14523 1,2: register list length, minus one (1, 2, 3, 4).
14524 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
14525 We use -1 for invalid entries. */
14526 const int typetable[] =
14527 {
14528 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
14529 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
14530 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
14531 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
14532 };
14533 int typebits;
14534
14535 if (et.type == NT_invtype)
14536 return;
14537
14538 if (inst.operands[1].immisalign)
14539 switch (inst.operands[1].imm >> 8)
14540 {
14541 case 64: alignbits = 1; break;
14542 case 128:
14543 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
14544 goto bad_alignment;
14545 alignbits = 2;
14546 break;
14547 case 256:
14548 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
14549 goto bad_alignment;
14550 alignbits = 3;
14551 break;
14552 default:
14553 bad_alignment:
14554 first_error (_("bad alignment"));
14555 return;
14556 }
14557
14558 inst.instruction |= alignbits << 4;
14559 inst.instruction |= neon_logbits (et.size) << 6;
14560
14561 /* Bits [4:6] of the immediate in a list specifier encode register stride
14562 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
14563 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
14564 up the right value for "type" in a table based on this value and the given
14565 list style, then stick it back. */
14566 idx = ((inst.operands[0].imm >> 4) & 7)
14567 | (((inst.instruction >> 8) & 3) << 3);
14568
14569 typebits = typetable[idx];
14570
14571 constraint (typebits == -1, _("bad list type for instruction"));
14572
14573 inst.instruction &= ~0xf00;
14574 inst.instruction |= typebits << 8;
14575 }
14576
14577 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
14578 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
14579 otherwise. The variable arguments are a list of pairs of legal (size, align)
14580 values, terminated with -1. */
14581
14582 static int
14583 neon_alignment_bit (int size, int align, int *do_align, ...)
14584 {
14585 va_list ap;
14586 int result = FAIL, thissize, thisalign;
14587
14588 if (!inst.operands[1].immisalign)
14589 {
14590 *do_align = 0;
14591 return SUCCESS;
14592 }
14593
14594 va_start (ap, do_align);
14595
14596 do
14597 {
14598 thissize = va_arg (ap, int);
14599 if (thissize == -1)
14600 break;
14601 thisalign = va_arg (ap, int);
14602
14603 if (size == thissize && align == thisalign)
14604 result = SUCCESS;
14605 }
14606 while (result != SUCCESS);
14607
14608 va_end (ap);
14609
14610 if (result == SUCCESS)
14611 *do_align = 1;
14612 else
14613 first_error (_("unsupported alignment for instruction"));
14614
14615 return result;
14616 }
14617
14618 static void
14619 do_neon_ld_st_lane (void)
14620 {
14621 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
14622 int align_good, do_align = 0;
14623 int logsize = neon_logbits (et.size);
14624 int align = inst.operands[1].imm >> 8;
14625 int n = (inst.instruction >> 8) & 3;
14626 int max_el = 64 / et.size;
14627
14628 if (et.type == NT_invtype)
14629 return;
14630
14631 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
14632 _("bad list length"));
14633 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
14634 _("scalar index out of range"));
14635 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
14636 && et.size == 8,
14637 _("stride of 2 unavailable when element size is 8"));
14638
14639 switch (n)
14640 {
14641 case 0: /* VLD1 / VST1. */
14642 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
14643 32, 32, -1);
14644 if (align_good == FAIL)
14645 return;
14646 if (do_align)
14647 {
14648 unsigned alignbits = 0;
14649 switch (et.size)
14650 {
14651 case 16: alignbits = 0x1; break;
14652 case 32: alignbits = 0x3; break;
14653 default: ;
14654 }
14655 inst.instruction |= alignbits << 4;
14656 }
14657 break;
14658
14659 case 1: /* VLD2 / VST2. */
14660 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
14661 32, 64, -1);
14662 if (align_good == FAIL)
14663 return;
14664 if (do_align)
14665 inst.instruction |= 1 << 4;
14666 break;
14667
14668 case 2: /* VLD3 / VST3. */
14669 constraint (inst.operands[1].immisalign,
14670 _("can't use alignment with this instruction"));
14671 break;
14672
14673 case 3: /* VLD4 / VST4. */
14674 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14675 16, 64, 32, 64, 32, 128, -1);
14676 if (align_good == FAIL)
14677 return;
14678 if (do_align)
14679 {
14680 unsigned alignbits = 0;
14681 switch (et.size)
14682 {
14683 case 8: alignbits = 0x1; break;
14684 case 16: alignbits = 0x1; break;
14685 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
14686 default: ;
14687 }
14688 inst.instruction |= alignbits << 4;
14689 }
14690 break;
14691
14692 default: ;
14693 }
14694
14695 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
14696 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14697 inst.instruction |= 1 << (4 + logsize);
14698
14699 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
14700 inst.instruction |= logsize << 10;
14701 }
14702
14703 /* Encode single n-element structure to all lanes VLD<n> instructions. */
14704
14705 static void
14706 do_neon_ld_dup (void)
14707 {
14708 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
14709 int align_good, do_align = 0;
14710
14711 if (et.type == NT_invtype)
14712 return;
14713
14714 switch ((inst.instruction >> 8) & 3)
14715 {
14716 case 0: /* VLD1. */
14717 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
14718 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14719 &do_align, 16, 16, 32, 32, -1);
14720 if (align_good == FAIL)
14721 return;
14722 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
14723 {
14724 case 1: break;
14725 case 2: inst.instruction |= 1 << 5; break;
14726 default: first_error (_("bad list length")); return;
14727 }
14728 inst.instruction |= neon_logbits (et.size) << 6;
14729 break;
14730
14731 case 1: /* VLD2. */
14732 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14733 &do_align, 8, 16, 16, 32, 32, 64, -1);
14734 if (align_good == FAIL)
14735 return;
14736 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
14737 _("bad list length"));
14738 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14739 inst.instruction |= 1 << 5;
14740 inst.instruction |= neon_logbits (et.size) << 6;
14741 break;
14742
14743 case 2: /* VLD3. */
14744 constraint (inst.operands[1].immisalign,
14745 _("can't use alignment with this instruction"));
14746 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
14747 _("bad list length"));
14748 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14749 inst.instruction |= 1 << 5;
14750 inst.instruction |= neon_logbits (et.size) << 6;
14751 break;
14752
14753 case 3: /* VLD4. */
14754 {
14755 int align = inst.operands[1].imm >> 8;
14756 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14757 16, 64, 32, 64, 32, 128, -1);
14758 if (align_good == FAIL)
14759 return;
14760 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
14761 _("bad list length"));
14762 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14763 inst.instruction |= 1 << 5;
14764 if (et.size == 32 && align == 128)
14765 inst.instruction |= 0x3 << 6;
14766 else
14767 inst.instruction |= neon_logbits (et.size) << 6;
14768 }
14769 break;
14770
14771 default: ;
14772 }
14773
14774 inst.instruction |= do_align << 4;
14775 }
14776
14777 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
14778 apart from bits [11:4]. */
14779
14780 static void
14781 do_neon_ldx_stx (void)
14782 {
14783 switch (NEON_LANE (inst.operands[0].imm))
14784 {
14785 case NEON_INTERLEAVE_LANES:
14786 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
14787 do_neon_ld_st_interleave ();
14788 break;
14789
14790 case NEON_ALL_LANES:
14791 inst.instruction = NEON_ENC_DUP (inst.instruction);
14792 do_neon_ld_dup ();
14793 break;
14794
14795 default:
14796 inst.instruction = NEON_ENC_LANE (inst.instruction);
14797 do_neon_ld_st_lane ();
14798 }
14799
14800 /* L bit comes from bit mask. */
14801 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14802 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14803 inst.instruction |= inst.operands[1].reg << 16;
14804
14805 if (inst.operands[1].postind)
14806 {
14807 int postreg = inst.operands[1].imm & 0xf;
14808 constraint (!inst.operands[1].immisreg,
14809 _("post-index must be a register"));
14810 constraint (postreg == 0xd || postreg == 0xf,
14811 _("bad register for post-index"));
14812 inst.instruction |= postreg;
14813 }
14814 else if (inst.operands[1].writeback)
14815 {
14816 inst.instruction |= 0xd;
14817 }
14818 else
14819 inst.instruction |= 0xf;
14820
14821 if (thumb_mode)
14822 inst.instruction |= 0xf9000000;
14823 else
14824 inst.instruction |= 0xf4000000;
14825 }
14826 \f
14827 /* Overall per-instruction processing. */
14828
14829 /* We need to be able to fix up arbitrary expressions in some statements.
14830 This is so that we can handle symbols that are an arbitrary distance from
14831 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
14832 which returns part of an address in a form which will be valid for
14833 a data instruction. We do this by pushing the expression into a symbol
14834 in the expr_section, and creating a fix for that. */
14835
14836 static void
14837 fix_new_arm (fragS * frag,
14838 int where,
14839 short int size,
14840 expressionS * exp,
14841 int pc_rel,
14842 int reloc)
14843 {
14844 fixS * new_fix;
14845
14846 switch (exp->X_op)
14847 {
14848 case O_constant:
14849 case O_symbol:
14850 case O_add:
14851 case O_subtract:
14852 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
14853 (enum bfd_reloc_code_real) reloc);
14854 break;
14855
14856 default:
14857 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
14858 pc_rel, (enum bfd_reloc_code_real) reloc);
14859 break;
14860 }
14861
14862 /* Mark whether the fix is to a THUMB instruction, or an ARM
14863 instruction. */
14864 new_fix->tc_fix_data = thumb_mode;
14865 }
14866
14867 /* Create a frg for an instruction requiring relaxation. */
14868 static void
14869 output_relax_insn (void)
14870 {
14871 char * to;
14872 symbolS *sym;
14873 int offset;
14874
14875 /* The size of the instruction is unknown, so tie the debug info to the
14876 start of the instruction. */
14877 dwarf2_emit_insn (0);
14878
14879 switch (inst.reloc.exp.X_op)
14880 {
14881 case O_symbol:
14882 sym = inst.reloc.exp.X_add_symbol;
14883 offset = inst.reloc.exp.X_add_number;
14884 break;
14885 case O_constant:
14886 sym = NULL;
14887 offset = inst.reloc.exp.X_add_number;
14888 break;
14889 default:
14890 sym = make_expr_symbol (&inst.reloc.exp);
14891 offset = 0;
14892 break;
14893 }
14894 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
14895 inst.relax, sym, offset, NULL/*offset, opcode*/);
14896 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
14897 }
14898
14899 /* Write a 32-bit thumb instruction to buf. */
14900 static void
14901 put_thumb32_insn (char * buf, unsigned long insn)
14902 {
14903 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
14904 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
14905 }
14906
14907 static void
14908 output_inst (const char * str)
14909 {
14910 char * to = NULL;
14911
14912 if (inst.error)
14913 {
14914 as_bad ("%s -- `%s'", inst.error, str);
14915 return;
14916 }
14917 if (inst.relax)
14918 {
14919 output_relax_insn ();
14920 return;
14921 }
14922 if (inst.size == 0)
14923 return;
14924
14925 to = frag_more (inst.size);
14926 /* PR 9814: Record the thumb mode into the current frag so that we know
14927 what type of NOP padding to use, if necessary. We override any previous
14928 setting so that if the mode has changed then the NOPS that we use will
14929 match the encoding of the last instruction in the frag. */
14930 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
14931
14932 if (thumb_mode && (inst.size > THUMB_SIZE))
14933 {
14934 gas_assert (inst.size == (2 * THUMB_SIZE));
14935 put_thumb32_insn (to, inst.instruction);
14936 }
14937 else if (inst.size > INSN_SIZE)
14938 {
14939 gas_assert (inst.size == (2 * INSN_SIZE));
14940 md_number_to_chars (to, inst.instruction, INSN_SIZE);
14941 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
14942 }
14943 else
14944 md_number_to_chars (to, inst.instruction, inst.size);
14945
14946 if (inst.reloc.type != BFD_RELOC_UNUSED)
14947 fix_new_arm (frag_now, to - frag_now->fr_literal,
14948 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
14949 inst.reloc.type);
14950
14951 dwarf2_emit_insn (inst.size);
14952 }
14953
14954 static char *
14955 output_it_inst (int cond, int mask, char * to)
14956 {
14957 unsigned long instruction = 0xbf00;
14958
14959 mask &= 0xf;
14960 instruction |= mask;
14961 instruction |= cond << 4;
14962
14963 if (to == NULL)
14964 {
14965 to = frag_more (2);
14966 #ifdef OBJ_ELF
14967 dwarf2_emit_insn (2);
14968 #endif
14969 }
14970
14971 md_number_to_chars (to, instruction, 2);
14972
14973 return to;
14974 }
14975
14976 /* Tag values used in struct asm_opcode's tag field. */
14977 enum opcode_tag
14978 {
14979 OT_unconditional, /* Instruction cannot be conditionalized.
14980 The ARM condition field is still 0xE. */
14981 OT_unconditionalF, /* Instruction cannot be conditionalized
14982 and carries 0xF in its ARM condition field. */
14983 OT_csuffix, /* Instruction takes a conditional suffix. */
14984 OT_csuffixF, /* Some forms of the instruction take a conditional
14985 suffix, others place 0xF where the condition field
14986 would be. */
14987 OT_cinfix3, /* Instruction takes a conditional infix,
14988 beginning at character index 3. (In
14989 unified mode, it becomes a suffix.) */
14990 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
14991 tsts, cmps, cmns, and teqs. */
14992 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
14993 character index 3, even in unified mode. Used for
14994 legacy instructions where suffix and infix forms
14995 may be ambiguous. */
14996 OT_csuf_or_in3, /* Instruction takes either a conditional
14997 suffix or an infix at character index 3. */
14998 OT_odd_infix_unc, /* This is the unconditional variant of an
14999 instruction that takes a conditional infix
15000 at an unusual position. In unified mode,
15001 this variant will accept a suffix. */
15002 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
15003 are the conditional variants of instructions that
15004 take conditional infixes in unusual positions.
15005 The infix appears at character index
15006 (tag - OT_odd_infix_0). These are not accepted
15007 in unified mode. */
15008 };
15009
15010 /* Subroutine of md_assemble, responsible for looking up the primary
15011 opcode from the mnemonic the user wrote. STR points to the
15012 beginning of the mnemonic.
15013
15014 This is not simply a hash table lookup, because of conditional
15015 variants. Most instructions have conditional variants, which are
15016 expressed with a _conditional affix_ to the mnemonic. If we were
15017 to encode each conditional variant as a literal string in the opcode
15018 table, it would have approximately 20,000 entries.
15019
15020 Most mnemonics take this affix as a suffix, and in unified syntax,
15021 'most' is upgraded to 'all'. However, in the divided syntax, some
15022 instructions take the affix as an infix, notably the s-variants of
15023 the arithmetic instructions. Of those instructions, all but six
15024 have the infix appear after the third character of the mnemonic.
15025
15026 Accordingly, the algorithm for looking up primary opcodes given
15027 an identifier is:
15028
15029 1. Look up the identifier in the opcode table.
15030 If we find a match, go to step U.
15031
15032 2. Look up the last two characters of the identifier in the
15033 conditions table. If we find a match, look up the first N-2
15034 characters of the identifier in the opcode table. If we
15035 find a match, go to step CE.
15036
15037 3. Look up the fourth and fifth characters of the identifier in
15038 the conditions table. If we find a match, extract those
15039 characters from the identifier, and look up the remaining
15040 characters in the opcode table. If we find a match, go
15041 to step CM.
15042
15043 4. Fail.
15044
15045 U. Examine the tag field of the opcode structure, in case this is
15046 one of the six instructions with its conditional infix in an
15047 unusual place. If it is, the tag tells us where to find the
15048 infix; look it up in the conditions table and set inst.cond
15049 accordingly. Otherwise, this is an unconditional instruction.
15050 Again set inst.cond accordingly. Return the opcode structure.
15051
15052 CE. Examine the tag field to make sure this is an instruction that
15053 should receive a conditional suffix. If it is not, fail.
15054 Otherwise, set inst.cond from the suffix we already looked up,
15055 and return the opcode structure.
15056
15057 CM. Examine the tag field to make sure this is an instruction that
15058 should receive a conditional infix after the third character.
15059 If it is not, fail. Otherwise, undo the edits to the current
15060 line of input and proceed as for case CE. */
15061
15062 static const struct asm_opcode *
15063 opcode_lookup (char **str)
15064 {
15065 char *end, *base;
15066 char *affix;
15067 const struct asm_opcode *opcode;
15068 const struct asm_cond *cond;
15069 char save[2];
15070
15071 /* Scan up to the end of the mnemonic, which must end in white space,
15072 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
15073 for (base = end = *str; *end != '\0'; end++)
15074 if (*end == ' ' || *end == '.')
15075 break;
15076
15077 if (end == base)
15078 return NULL;
15079
15080 /* Handle a possible width suffix and/or Neon type suffix. */
15081 if (end[0] == '.')
15082 {
15083 int offset = 2;
15084
15085 /* The .w and .n suffixes are only valid if the unified syntax is in
15086 use. */
15087 if (unified_syntax && end[1] == 'w')
15088 inst.size_req = 4;
15089 else if (unified_syntax && end[1] == 'n')
15090 inst.size_req = 2;
15091 else
15092 offset = 0;
15093
15094 inst.vectype.elems = 0;
15095
15096 *str = end + offset;
15097
15098 if (end[offset] == '.')
15099 {
15100 /* See if we have a Neon type suffix (possible in either unified or
15101 non-unified ARM syntax mode). */
15102 if (parse_neon_type (&inst.vectype, str) == FAIL)
15103 return NULL;
15104 }
15105 else if (end[offset] != '\0' && end[offset] != ' ')
15106 return NULL;
15107 }
15108 else
15109 *str = end;
15110
15111 /* Look for unaffixed or special-case affixed mnemonic. */
15112 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15113 end - base);
15114 if (opcode)
15115 {
15116 /* step U */
15117 if (opcode->tag < OT_odd_infix_0)
15118 {
15119 inst.cond = COND_ALWAYS;
15120 return opcode;
15121 }
15122
15123 if (warn_on_deprecated && unified_syntax)
15124 as_warn (_("conditional infixes are deprecated in unified syntax"));
15125 affix = base + (opcode->tag - OT_odd_infix_0);
15126 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15127 gas_assert (cond);
15128
15129 inst.cond = cond->value;
15130 return opcode;
15131 }
15132
15133 /* Cannot have a conditional suffix on a mnemonic of less than two
15134 characters. */
15135 if (end - base < 3)
15136 return NULL;
15137
15138 /* Look for suffixed mnemonic. */
15139 affix = end - 2;
15140 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15141 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15142 affix - base);
15143 if (opcode && cond)
15144 {
15145 /* step CE */
15146 switch (opcode->tag)
15147 {
15148 case OT_cinfix3_legacy:
15149 /* Ignore conditional suffixes matched on infix only mnemonics. */
15150 break;
15151
15152 case OT_cinfix3:
15153 case OT_cinfix3_deprecated:
15154 case OT_odd_infix_unc:
15155 if (!unified_syntax)
15156 return 0;
15157 /* else fall through */
15158
15159 case OT_csuffix:
15160 case OT_csuffixF:
15161 case OT_csuf_or_in3:
15162 inst.cond = cond->value;
15163 return opcode;
15164
15165 case OT_unconditional:
15166 case OT_unconditionalF:
15167 if (thumb_mode)
15168 inst.cond = cond->value;
15169 else
15170 {
15171 /* Delayed diagnostic. */
15172 inst.error = BAD_COND;
15173 inst.cond = COND_ALWAYS;
15174 }
15175 return opcode;
15176
15177 default:
15178 return NULL;
15179 }
15180 }
15181
15182 /* Cannot have a usual-position infix on a mnemonic of less than
15183 six characters (five would be a suffix). */
15184 if (end - base < 6)
15185 return NULL;
15186
15187 /* Look for infixed mnemonic in the usual position. */
15188 affix = base + 3;
15189 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15190 if (!cond)
15191 return NULL;
15192
15193 memcpy (save, affix, 2);
15194 memmove (affix, affix + 2, (end - affix) - 2);
15195 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15196 (end - base) - 2);
15197 memmove (affix + 2, affix, (end - affix) - 2);
15198 memcpy (affix, save, 2);
15199
15200 if (opcode
15201 && (opcode->tag == OT_cinfix3
15202 || opcode->tag == OT_cinfix3_deprecated
15203 || opcode->tag == OT_csuf_or_in3
15204 || opcode->tag == OT_cinfix3_legacy))
15205 {
15206 /* Step CM. */
15207 if (warn_on_deprecated && unified_syntax
15208 && (opcode->tag == OT_cinfix3
15209 || opcode->tag == OT_cinfix3_deprecated))
15210 as_warn (_("conditional infixes are deprecated in unified syntax"));
15211
15212 inst.cond = cond->value;
15213 return opcode;
15214 }
15215
15216 return NULL;
15217 }
15218
15219 /* This function generates an initial IT instruction, leaving its block
15220 virtually open for the new instructions. Eventually,
15221 the mask will be updated by now_it_add_mask () each time
15222 a new instruction needs to be included in the IT block.
15223 Finally, the block is closed with close_automatic_it_block ().
15224 The block closure can be requested either from md_assemble (),
15225 a tencode (), or due to a label hook. */
15226
15227 static void
15228 new_automatic_it_block (int cond)
15229 {
15230 now_it.state = AUTOMATIC_IT_BLOCK;
15231 now_it.mask = 0x18;
15232 now_it.cc = cond;
15233 now_it.block_length = 1;
15234 mapping_state (MAP_THUMB);
15235 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
15236 }
15237
15238 /* Close an automatic IT block.
15239 See comments in new_automatic_it_block (). */
15240
15241 static void
15242 close_automatic_it_block (void)
15243 {
15244 now_it.mask = 0x10;
15245 now_it.block_length = 0;
15246 }
15247
15248 /* Update the mask of the current automatically-generated IT
15249 instruction. See comments in new_automatic_it_block (). */
15250
15251 static void
15252 now_it_add_mask (int cond)
15253 {
15254 #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
15255 #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
15256 | ((bitvalue) << (nbit)))
15257 const int resulting_bit = (cond & 1);
15258
15259 now_it.mask &= 0xf;
15260 now_it.mask = SET_BIT_VALUE (now_it.mask,
15261 resulting_bit,
15262 (5 - now_it.block_length));
15263 now_it.mask = SET_BIT_VALUE (now_it.mask,
15264 1,
15265 ((5 - now_it.block_length) - 1) );
15266 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
15267
15268 #undef CLEAR_BIT
15269 #undef SET_BIT_VALUE
15270 }
15271
15272 /* The IT blocks handling machinery is accessed through the these functions:
15273 it_fsm_pre_encode () from md_assemble ()
15274 set_it_insn_type () optional, from the tencode functions
15275 set_it_insn_type_last () ditto
15276 in_it_block () ditto
15277 it_fsm_post_encode () from md_assemble ()
15278 force_automatic_it_block_close () from label habdling functions
15279
15280 Rationale:
15281 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
15282 initializing the IT insn type with a generic initial value depending
15283 on the inst.condition.
15284 2) During the tencode function, two things may happen:
15285 a) The tencode function overrides the IT insn type by
15286 calling either set_it_insn_type (type) or set_it_insn_type_last ().
15287 b) The tencode function queries the IT block state by
15288 calling in_it_block () (i.e. to determine narrow/not narrow mode).
15289
15290 Both set_it_insn_type and in_it_block run the internal FSM state
15291 handling function (handle_it_state), because: a) setting the IT insn
15292 type may incur in an invalid state (exiting the function),
15293 and b) querying the state requires the FSM to be updated.
15294 Specifically we want to avoid creating an IT block for conditional
15295 branches, so it_fsm_pre_encode is actually a guess and we can't
15296 determine whether an IT block is required until the tencode () routine
15297 has decided what type of instruction this actually it.
15298 Because of this, if set_it_insn_type and in_it_block have to be used,
15299 set_it_insn_type has to be called first.
15300
15301 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
15302 determines the insn IT type depending on the inst.cond code.
15303 When a tencode () routine encodes an instruction that can be
15304 either outside an IT block, or, in the case of being inside, has to be
15305 the last one, set_it_insn_type_last () will determine the proper
15306 IT instruction type based on the inst.cond code. Otherwise,
15307 set_it_insn_type can be called for overriding that logic or
15308 for covering other cases.
15309
15310 Calling handle_it_state () may not transition the IT block state to
15311 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
15312 still queried. Instead, if the FSM determines that the state should
15313 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
15314 after the tencode () function: that's what it_fsm_post_encode () does.
15315
15316 Since in_it_block () calls the state handling function to get an
15317 updated state, an error may occur (due to invalid insns combination).
15318 In that case, inst.error is set.
15319 Therefore, inst.error has to be checked after the execution of
15320 the tencode () routine.
15321
15322 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
15323 any pending state change (if any) that didn't take place in
15324 handle_it_state () as explained above. */
15325
15326 static void
15327 it_fsm_pre_encode (void)
15328 {
15329 if (inst.cond != COND_ALWAYS)
15330 inst.it_insn_type = INSIDE_IT_INSN;
15331 else
15332 inst.it_insn_type = OUTSIDE_IT_INSN;
15333
15334 now_it.state_handled = 0;
15335 }
15336
15337 /* IT state FSM handling function. */
15338
15339 static int
15340 handle_it_state (void)
15341 {
15342 now_it.state_handled = 1;
15343
15344 switch (now_it.state)
15345 {
15346 case OUTSIDE_IT_BLOCK:
15347 switch (inst.it_insn_type)
15348 {
15349 case OUTSIDE_IT_INSN:
15350 break;
15351
15352 case INSIDE_IT_INSN:
15353 case INSIDE_IT_LAST_INSN:
15354 if (thumb_mode == 0)
15355 {
15356 if (unified_syntax
15357 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
15358 as_tsktsk (_("Warning: conditional outside an IT block"\
15359 " for Thumb."));
15360 }
15361 else
15362 {
15363 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
15364 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
15365 {
15366 /* Automatically generate the IT instruction. */
15367 new_automatic_it_block (inst.cond);
15368 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
15369 close_automatic_it_block ();
15370 }
15371 else
15372 {
15373 inst.error = BAD_OUT_IT;
15374 return FAIL;
15375 }
15376 }
15377 break;
15378
15379 case IF_INSIDE_IT_LAST_INSN:
15380 case NEUTRAL_IT_INSN:
15381 break;
15382
15383 case IT_INSN:
15384 now_it.state = MANUAL_IT_BLOCK;
15385 now_it.block_length = 0;
15386 break;
15387 }
15388 break;
15389
15390 case AUTOMATIC_IT_BLOCK:
15391 /* Three things may happen now:
15392 a) We should increment current it block size;
15393 b) We should close current it block (closing insn or 4 insns);
15394 c) We should close current it block and start a new one (due
15395 to incompatible conditions or
15396 4 insns-length block reached). */
15397
15398 switch (inst.it_insn_type)
15399 {
15400 case OUTSIDE_IT_INSN:
15401 /* The closure of the block shall happen immediatelly,
15402 so any in_it_block () call reports the block as closed. */
15403 force_automatic_it_block_close ();
15404 break;
15405
15406 case INSIDE_IT_INSN:
15407 case INSIDE_IT_LAST_INSN:
15408 case IF_INSIDE_IT_LAST_INSN:
15409 now_it.block_length++;
15410
15411 if (now_it.block_length > 4
15412 || !now_it_compatible (inst.cond))
15413 {
15414 force_automatic_it_block_close ();
15415 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
15416 new_automatic_it_block (inst.cond);
15417 }
15418 else
15419 {
15420 now_it_add_mask (inst.cond);
15421 }
15422
15423 if (now_it.state == AUTOMATIC_IT_BLOCK
15424 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
15425 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
15426 close_automatic_it_block ();
15427 break;
15428
15429 case NEUTRAL_IT_INSN:
15430 now_it.block_length++;
15431
15432 if (now_it.block_length > 4)
15433 force_automatic_it_block_close ();
15434 else
15435 now_it_add_mask (now_it.cc & 1);
15436 break;
15437
15438 case IT_INSN:
15439 close_automatic_it_block ();
15440 now_it.state = MANUAL_IT_BLOCK;
15441 break;
15442 }
15443 break;
15444
15445 case MANUAL_IT_BLOCK:
15446 {
15447 /* Check conditional suffixes. */
15448 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
15449 int is_last;
15450 now_it.mask <<= 1;
15451 now_it.mask &= 0x1f;
15452 is_last = (now_it.mask == 0x10);
15453
15454 switch (inst.it_insn_type)
15455 {
15456 case OUTSIDE_IT_INSN:
15457 inst.error = BAD_NOT_IT;
15458 return FAIL;
15459
15460 case INSIDE_IT_INSN:
15461 if (cond != inst.cond)
15462 {
15463 inst.error = BAD_IT_COND;
15464 return FAIL;
15465 }
15466 break;
15467
15468 case INSIDE_IT_LAST_INSN:
15469 case IF_INSIDE_IT_LAST_INSN:
15470 if (cond != inst.cond)
15471 {
15472 inst.error = BAD_IT_COND;
15473 return FAIL;
15474 }
15475 if (!is_last)
15476 {
15477 inst.error = BAD_BRANCH;
15478 return FAIL;
15479 }
15480 break;
15481
15482 case NEUTRAL_IT_INSN:
15483 /* The BKPT instruction is unconditional even in an IT block. */
15484 break;
15485
15486 case IT_INSN:
15487 inst.error = BAD_IT_IT;
15488 return FAIL;
15489 }
15490 }
15491 break;
15492 }
15493
15494 return SUCCESS;
15495 }
15496
15497 static void
15498 it_fsm_post_encode (void)
15499 {
15500 int is_last;
15501
15502 if (!now_it.state_handled)
15503 handle_it_state ();
15504
15505 is_last = (now_it.mask == 0x10);
15506 if (is_last)
15507 {
15508 now_it.state = OUTSIDE_IT_BLOCK;
15509 now_it.mask = 0;
15510 }
15511 }
15512
15513 static void
15514 force_automatic_it_block_close (void)
15515 {
15516 if (now_it.state == AUTOMATIC_IT_BLOCK)
15517 {
15518 close_automatic_it_block ();
15519 now_it.state = OUTSIDE_IT_BLOCK;
15520 now_it.mask = 0;
15521 }
15522 }
15523
15524 static int
15525 in_it_block (void)
15526 {
15527 if (!now_it.state_handled)
15528 handle_it_state ();
15529
15530 return now_it.state != OUTSIDE_IT_BLOCK;
15531 }
15532
15533 void
15534 md_assemble (char *str)
15535 {
15536 char *p = str;
15537 const struct asm_opcode * opcode;
15538
15539 /* Align the previous label if needed. */
15540 if (last_label_seen != NULL)
15541 {
15542 symbol_set_frag (last_label_seen, frag_now);
15543 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
15544 S_SET_SEGMENT (last_label_seen, now_seg);
15545 }
15546
15547 memset (&inst, '\0', sizeof (inst));
15548 inst.reloc.type = BFD_RELOC_UNUSED;
15549
15550 opcode = opcode_lookup (&p);
15551 if (!opcode)
15552 {
15553 /* It wasn't an instruction, but it might be a register alias of
15554 the form alias .req reg, or a Neon .dn/.qn directive. */
15555 if (! create_register_alias (str, p)
15556 && ! create_neon_reg_alias (str, p))
15557 as_bad (_("bad instruction `%s'"), str);
15558
15559 return;
15560 }
15561
15562 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
15563 as_warn (_("s suffix on comparison instruction is deprecated"));
15564
15565 /* The value which unconditional instructions should have in place of the
15566 condition field. */
15567 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
15568
15569 if (thumb_mode)
15570 {
15571 arm_feature_set variant;
15572
15573 variant = cpu_variant;
15574 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
15575 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
15576 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
15577 /* Check that this instruction is supported for this CPU. */
15578 if (!opcode->tvariant
15579 || (thumb_mode == 1
15580 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
15581 {
15582 as_bad (_("selected processor does not support `%s'"), str);
15583 return;
15584 }
15585 if (inst.cond != COND_ALWAYS && !unified_syntax
15586 && opcode->tencode != do_t_branch)
15587 {
15588 as_bad (_("Thumb does not support conditional execution"));
15589 return;
15590 }
15591
15592 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
15593 {
15594 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
15595 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
15596 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
15597 {
15598 /* Two things are addressed here.
15599 1) Implicit require narrow instructions on Thumb-1.
15600 This avoids relaxation accidentally introducing Thumb-2
15601 instructions.
15602 2) Reject wide instructions in non Thumb-2 cores. */
15603 if (inst.size_req == 0)
15604 inst.size_req = 2;
15605 else if (inst.size_req == 4)
15606 {
15607 as_bad (_("selected processor does not support `%s'"), str);
15608 return;
15609 }
15610 }
15611 }
15612
15613 inst.instruction = opcode->tvalue;
15614
15615 if (!parse_operands (p, opcode->operands))
15616 {
15617 /* Prepare the it_insn_type for those encodings that don't set
15618 it. */
15619 it_fsm_pre_encode ();
15620
15621 opcode->tencode ();
15622
15623 it_fsm_post_encode ();
15624 }
15625
15626 if (!(inst.error || inst.relax))
15627 {
15628 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
15629 inst.size = (inst.instruction > 0xffff ? 4 : 2);
15630 if (inst.size_req && inst.size_req != inst.size)
15631 {
15632 as_bad (_("cannot honor width suffix -- `%s'"), str);
15633 return;
15634 }
15635 }
15636
15637 /* Something has gone badly wrong if we try to relax a fixed size
15638 instruction. */
15639 gas_assert (inst.size_req == 0 || !inst.relax);
15640
15641 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15642 *opcode->tvariant);
15643 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
15644 set those bits when Thumb-2 32-bit instructions are seen. ie.
15645 anything other than bl/blx and v6-M instructions.
15646 This is overly pessimistic for relaxable instructions. */
15647 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
15648 || inst.relax)
15649 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
15650 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
15651 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15652 arm_ext_v6t2);
15653
15654 if (!inst.error)
15655 {
15656 mapping_state (MAP_THUMB);
15657 }
15658 }
15659 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
15660 {
15661 bfd_boolean is_bx;
15662
15663 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
15664 is_bx = (opcode->aencode == do_bx);
15665
15666 /* Check that this instruction is supported for this CPU. */
15667 if (!(is_bx && fix_v4bx)
15668 && !(opcode->avariant &&
15669 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
15670 {
15671 as_bad (_("selected processor does not support `%s'"), str);
15672 return;
15673 }
15674 if (inst.size_req)
15675 {
15676 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
15677 return;
15678 }
15679
15680 inst.instruction = opcode->avalue;
15681 if (opcode->tag == OT_unconditionalF)
15682 inst.instruction |= 0xF << 28;
15683 else
15684 inst.instruction |= inst.cond << 28;
15685 inst.size = INSN_SIZE;
15686 if (!parse_operands (p, opcode->operands))
15687 {
15688 it_fsm_pre_encode ();
15689 opcode->aencode ();
15690 it_fsm_post_encode ();
15691 }
15692 /* Arm mode bx is marked as both v4T and v5 because it's still required
15693 on a hypothetical non-thumb v5 core. */
15694 if (is_bx)
15695 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
15696 else
15697 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
15698 *opcode->avariant);
15699 if (!inst.error)
15700 {
15701 mapping_state (MAP_ARM);
15702 }
15703 }
15704 else
15705 {
15706 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
15707 "-- `%s'"), str);
15708 return;
15709 }
15710 output_inst (str);
15711 }
15712
15713 static void
15714 check_it_blocks_finished (void)
15715 {
15716 #ifdef OBJ_ELF
15717 asection *sect;
15718
15719 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
15720 if (seg_info (sect)->tc_segment_info_data.current_it.state
15721 == MANUAL_IT_BLOCK)
15722 {
15723 as_warn (_("section '%s' finished with an open IT block."),
15724 sect->name);
15725 }
15726 #else
15727 if (now_it.state == MANUAL_IT_BLOCK)
15728 as_warn (_("file finished with an open IT block."));
15729 #endif
15730 }
15731
15732 /* Various frobbings of labels and their addresses. */
15733
15734 void
15735 arm_start_line_hook (void)
15736 {
15737 last_label_seen = NULL;
15738 }
15739
15740 void
15741 arm_frob_label (symbolS * sym)
15742 {
15743 last_label_seen = sym;
15744
15745 ARM_SET_THUMB (sym, thumb_mode);
15746
15747 #if defined OBJ_COFF || defined OBJ_ELF
15748 ARM_SET_INTERWORK (sym, support_interwork);
15749 #endif
15750
15751 force_automatic_it_block_close ();
15752
15753 /* Note - do not allow local symbols (.Lxxx) to be labelled
15754 as Thumb functions. This is because these labels, whilst
15755 they exist inside Thumb code, are not the entry points for
15756 possible ARM->Thumb calls. Also, these labels can be used
15757 as part of a computed goto or switch statement. eg gcc
15758 can generate code that looks like this:
15759
15760 ldr r2, [pc, .Laaa]
15761 lsl r3, r3, #2
15762 ldr r2, [r3, r2]
15763 mov pc, r2
15764
15765 .Lbbb: .word .Lxxx
15766 .Lccc: .word .Lyyy
15767 ..etc...
15768 .Laaa: .word Lbbb
15769
15770 The first instruction loads the address of the jump table.
15771 The second instruction converts a table index into a byte offset.
15772 The third instruction gets the jump address out of the table.
15773 The fourth instruction performs the jump.
15774
15775 If the address stored at .Laaa is that of a symbol which has the
15776 Thumb_Func bit set, then the linker will arrange for this address
15777 to have the bottom bit set, which in turn would mean that the
15778 address computation performed by the third instruction would end
15779 up with the bottom bit set. Since the ARM is capable of unaligned
15780 word loads, the instruction would then load the incorrect address
15781 out of the jump table, and chaos would ensue. */
15782 if (label_is_thumb_function_name
15783 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
15784 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
15785 {
15786 /* When the address of a Thumb function is taken the bottom
15787 bit of that address should be set. This will allow
15788 interworking between Arm and Thumb functions to work
15789 correctly. */
15790
15791 THUMB_SET_FUNC (sym, 1);
15792
15793 label_is_thumb_function_name = FALSE;
15794 }
15795
15796 dwarf2_emit_label (sym);
15797 }
15798
15799 bfd_boolean
15800 arm_data_in_code (void)
15801 {
15802 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
15803 {
15804 *input_line_pointer = '/';
15805 input_line_pointer += 5;
15806 *input_line_pointer = 0;
15807 return TRUE;
15808 }
15809
15810 return FALSE;
15811 }
15812
15813 char *
15814 arm_canonicalize_symbol_name (char * name)
15815 {
15816 int len;
15817
15818 if (thumb_mode && (len = strlen (name)) > 5
15819 && streq (name + len - 5, "/data"))
15820 *(name + len - 5) = 0;
15821
15822 return name;
15823 }
15824 \f
15825 /* Table of all register names defined by default. The user can
15826 define additional names with .req. Note that all register names
15827 should appear in both upper and lowercase variants. Some registers
15828 also have mixed-case names. */
15829
15830 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
15831 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
15832 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
15833 #define REGSET(p,t) \
15834 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
15835 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
15836 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
15837 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
15838 #define REGSETH(p,t) \
15839 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
15840 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
15841 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
15842 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
15843 #define REGSET2(p,t) \
15844 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
15845 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
15846 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
15847 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
15848
15849 static const struct reg_entry reg_names[] =
15850 {
15851 /* ARM integer registers. */
15852 REGSET(r, RN), REGSET(R, RN),
15853
15854 /* ATPCS synonyms. */
15855 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
15856 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
15857 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
15858
15859 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
15860 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
15861 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
15862
15863 /* Well-known aliases. */
15864 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
15865 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
15866
15867 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
15868 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
15869
15870 /* Coprocessor numbers. */
15871 REGSET(p, CP), REGSET(P, CP),
15872
15873 /* Coprocessor register numbers. The "cr" variants are for backward
15874 compatibility. */
15875 REGSET(c, CN), REGSET(C, CN),
15876 REGSET(cr, CN), REGSET(CR, CN),
15877
15878 /* FPA registers. */
15879 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
15880 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
15881
15882 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
15883 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
15884
15885 /* VFP SP registers. */
15886 REGSET(s,VFS), REGSET(S,VFS),
15887 REGSETH(s,VFS), REGSETH(S,VFS),
15888
15889 /* VFP DP Registers. */
15890 REGSET(d,VFD), REGSET(D,VFD),
15891 /* Extra Neon DP registers. */
15892 REGSETH(d,VFD), REGSETH(D,VFD),
15893
15894 /* Neon QP registers. */
15895 REGSET2(q,NQ), REGSET2(Q,NQ),
15896
15897 /* VFP control registers. */
15898 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
15899 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
15900 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
15901 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
15902 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
15903 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
15904
15905 /* Maverick DSP coprocessor registers. */
15906 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
15907 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
15908
15909 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
15910 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
15911 REGDEF(dspsc,0,DSPSC),
15912
15913 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
15914 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
15915 REGDEF(DSPSC,0,DSPSC),
15916
15917 /* iWMMXt data registers - p0, c0-15. */
15918 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
15919
15920 /* iWMMXt control registers - p1, c0-3. */
15921 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
15922 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
15923 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
15924 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
15925
15926 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
15927 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
15928 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
15929 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
15930 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
15931
15932 /* XScale accumulator registers. */
15933 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
15934 };
15935 #undef REGDEF
15936 #undef REGNUM
15937 #undef REGSET
15938
15939 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
15940 within psr_required_here. */
15941 static const struct asm_psr psrs[] =
15942 {
15943 /* Backward compatibility notation. Note that "all" is no longer
15944 truly all possible PSR bits. */
15945 {"all", PSR_c | PSR_f},
15946 {"flg", PSR_f},
15947 {"ctl", PSR_c},
15948
15949 /* Individual flags. */
15950 {"f", PSR_f},
15951 {"c", PSR_c},
15952 {"x", PSR_x},
15953 {"s", PSR_s},
15954 /* Combinations of flags. */
15955 {"fs", PSR_f | PSR_s},
15956 {"fx", PSR_f | PSR_x},
15957 {"fc", PSR_f | PSR_c},
15958 {"sf", PSR_s | PSR_f},
15959 {"sx", PSR_s | PSR_x},
15960 {"sc", PSR_s | PSR_c},
15961 {"xf", PSR_x | PSR_f},
15962 {"xs", PSR_x | PSR_s},
15963 {"xc", PSR_x | PSR_c},
15964 {"cf", PSR_c | PSR_f},
15965 {"cs", PSR_c | PSR_s},
15966 {"cx", PSR_c | PSR_x},
15967 {"fsx", PSR_f | PSR_s | PSR_x},
15968 {"fsc", PSR_f | PSR_s | PSR_c},
15969 {"fxs", PSR_f | PSR_x | PSR_s},
15970 {"fxc", PSR_f | PSR_x | PSR_c},
15971 {"fcs", PSR_f | PSR_c | PSR_s},
15972 {"fcx", PSR_f | PSR_c | PSR_x},
15973 {"sfx", PSR_s | PSR_f | PSR_x},
15974 {"sfc", PSR_s | PSR_f | PSR_c},
15975 {"sxf", PSR_s | PSR_x | PSR_f},
15976 {"sxc", PSR_s | PSR_x | PSR_c},
15977 {"scf", PSR_s | PSR_c | PSR_f},
15978 {"scx", PSR_s | PSR_c | PSR_x},
15979 {"xfs", PSR_x | PSR_f | PSR_s},
15980 {"xfc", PSR_x | PSR_f | PSR_c},
15981 {"xsf", PSR_x | PSR_s | PSR_f},
15982 {"xsc", PSR_x | PSR_s | PSR_c},
15983 {"xcf", PSR_x | PSR_c | PSR_f},
15984 {"xcs", PSR_x | PSR_c | PSR_s},
15985 {"cfs", PSR_c | PSR_f | PSR_s},
15986 {"cfx", PSR_c | PSR_f | PSR_x},
15987 {"csf", PSR_c | PSR_s | PSR_f},
15988 {"csx", PSR_c | PSR_s | PSR_x},
15989 {"cxf", PSR_c | PSR_x | PSR_f},
15990 {"cxs", PSR_c | PSR_x | PSR_s},
15991 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
15992 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
15993 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
15994 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
15995 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
15996 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
15997 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
15998 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
15999 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
16000 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
16001 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
16002 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
16003 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
16004 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
16005 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
16006 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
16007 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
16008 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
16009 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
16010 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
16011 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
16012 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
16013 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
16014 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
16015 };
16016
16017 /* Table of V7M psr names. */
16018 static const struct asm_psr v7m_psrs[] =
16019 {
16020 {"apsr", 0 }, {"APSR", 0 },
16021 {"iapsr", 1 }, {"IAPSR", 1 },
16022 {"eapsr", 2 }, {"EAPSR", 2 },
16023 {"psr", 3 }, {"PSR", 3 },
16024 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
16025 {"ipsr", 5 }, {"IPSR", 5 },
16026 {"epsr", 6 }, {"EPSR", 6 },
16027 {"iepsr", 7 }, {"IEPSR", 7 },
16028 {"msp", 8 }, {"MSP", 8 },
16029 {"psp", 9 }, {"PSP", 9 },
16030 {"primask", 16}, {"PRIMASK", 16},
16031 {"basepri", 17}, {"BASEPRI", 17},
16032 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
16033 {"faultmask", 19}, {"FAULTMASK", 19},
16034 {"control", 20}, {"CONTROL", 20}
16035 };
16036
16037 /* Table of all shift-in-operand names. */
16038 static const struct asm_shift_name shift_names [] =
16039 {
16040 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
16041 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
16042 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
16043 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
16044 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
16045 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
16046 };
16047
16048 /* Table of all explicit relocation names. */
16049 #ifdef OBJ_ELF
16050 static struct reloc_entry reloc_names[] =
16051 {
16052 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
16053 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
16054 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
16055 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
16056 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
16057 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
16058 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
16059 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
16060 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
16061 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
16062 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
16063 };
16064 #endif
16065
16066 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
16067 static const struct asm_cond conds[] =
16068 {
16069 {"eq", 0x0},
16070 {"ne", 0x1},
16071 {"cs", 0x2}, {"hs", 0x2},
16072 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
16073 {"mi", 0x4},
16074 {"pl", 0x5},
16075 {"vs", 0x6},
16076 {"vc", 0x7},
16077 {"hi", 0x8},
16078 {"ls", 0x9},
16079 {"ge", 0xa},
16080 {"lt", 0xb},
16081 {"gt", 0xc},
16082 {"le", 0xd},
16083 {"al", 0xe}
16084 };
16085
16086 static struct asm_barrier_opt barrier_opt_names[] =
16087 {
16088 { "sy", 0xf },
16089 { "un", 0x7 },
16090 { "st", 0xe },
16091 { "unst", 0x6 }
16092 };
16093
16094 /* Table of ARM-format instructions. */
16095
16096 /* Macros for gluing together operand strings. N.B. In all cases
16097 other than OPS0, the trailing OP_stop comes from default
16098 zero-initialization of the unspecified elements of the array. */
16099 #define OPS0() { OP_stop, }
16100 #define OPS1(a) { OP_##a, }
16101 #define OPS2(a,b) { OP_##a,OP_##b, }
16102 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
16103 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
16104 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
16105 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
16106
16107 /* These macros abstract out the exact format of the mnemonic table and
16108 save some repeated characters. */
16109
16110 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
16111 #define TxCE(mnem, op, top, nops, ops, ae, te) \
16112 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
16113 THUMB_VARIANT, do_##ae, do_##te }
16114
16115 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
16116 a T_MNEM_xyz enumerator. */
16117 #define TCE(mnem, aop, top, nops, ops, ae, te) \
16118 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
16119 #define tCE(mnem, aop, top, nops, ops, ae, te) \
16120 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
16121
16122 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
16123 infix after the third character. */
16124 #define TxC3(mnem, op, top, nops, ops, ae, te) \
16125 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
16126 THUMB_VARIANT, do_##ae, do_##te }
16127 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
16128 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
16129 THUMB_VARIANT, do_##ae, do_##te }
16130 #define TC3(mnem, aop, top, nops, ops, ae, te) \
16131 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
16132 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
16133 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
16134 #define tC3(mnem, aop, top, nops, ops, ae, te) \
16135 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
16136 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
16137 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
16138
16139 /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
16140 appear in the condition table. */
16141 #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
16142 { m1 #m2 m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
16143 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
16144
16145 #define TxCM(m1, m2, op, top, nops, ops, ae, te) \
16146 TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \
16147 TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \
16148 TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \
16149 TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \
16150 TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \
16151 TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \
16152 TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \
16153 TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \
16154 TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \
16155 TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \
16156 TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \
16157 TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \
16158 TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \
16159 TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \
16160 TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \
16161 TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \
16162 TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \
16163 TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \
16164 TxCM_ (m1, al, m2, op, top, nops, ops, ae, te)
16165
16166 #define TCM(m1,m2, aop, top, nops, ops, ae, te) \
16167 TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te)
16168 #define tCM(m1,m2, aop, top, nops, ops, ae, te) \
16169 TxCM (m1,m2, aop, T_MNEM##top, nops, ops, ae, te)
16170
16171 /* Mnemonic that cannot be conditionalized. The ARM condition-code
16172 field is still 0xE. Many of the Thumb variants can be executed
16173 conditionally, so this is checked separately. */
16174 #define TUE(mnem, op, top, nops, ops, ae, te) \
16175 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
16176 THUMB_VARIANT, do_##ae, do_##te }
16177
16178 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
16179 condition code field. */
16180 #define TUF(mnem, op, top, nops, ops, ae, te) \
16181 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
16182 THUMB_VARIANT, do_##ae, do_##te }
16183
16184 /* ARM-only variants of all the above. */
16185 #define CE(mnem, op, nops, ops, ae) \
16186 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16187
16188 #define C3(mnem, op, nops, ops, ae) \
16189 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16190
16191 /* Legacy mnemonics that always have conditional infix after the third
16192 character. */
16193 #define CL(mnem, op, nops, ops, ae) \
16194 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
16195 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16196
16197 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
16198 #define cCE(mnem, op, nops, ops, ae) \
16199 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16200
16201 /* Legacy coprocessor instructions where conditional infix and conditional
16202 suffix are ambiguous. For consistency this includes all FPA instructions,
16203 not just the potentially ambiguous ones. */
16204 #define cCL(mnem, op, nops, ops, ae) \
16205 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
16206 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16207
16208 /* Coprocessor, takes either a suffix or a position-3 infix
16209 (for an FPA corner case). */
16210 #define C3E(mnem, op, nops, ops, ae) \
16211 { mnem, OPS##nops ops, OT_csuf_or_in3, \
16212 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16213
16214 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
16215 { m1 #m2 m3, OPS##nops ops, \
16216 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
16217 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16218
16219 #define CM(m1, m2, op, nops, ops, ae) \
16220 xCM_ (m1, , m2, op, nops, ops, ae), \
16221 xCM_ (m1, eq, m2, op, nops, ops, ae), \
16222 xCM_ (m1, ne, m2, op, nops, ops, ae), \
16223 xCM_ (m1, cs, m2, op, nops, ops, ae), \
16224 xCM_ (m1, hs, m2, op, nops, ops, ae), \
16225 xCM_ (m1, cc, m2, op, nops, ops, ae), \
16226 xCM_ (m1, ul, m2, op, nops, ops, ae), \
16227 xCM_ (m1, lo, m2, op, nops, ops, ae), \
16228 xCM_ (m1, mi, m2, op, nops, ops, ae), \
16229 xCM_ (m1, pl, m2, op, nops, ops, ae), \
16230 xCM_ (m1, vs, m2, op, nops, ops, ae), \
16231 xCM_ (m1, vc, m2, op, nops, ops, ae), \
16232 xCM_ (m1, hi, m2, op, nops, ops, ae), \
16233 xCM_ (m1, ls, m2, op, nops, ops, ae), \
16234 xCM_ (m1, ge, m2, op, nops, ops, ae), \
16235 xCM_ (m1, lt, m2, op, nops, ops, ae), \
16236 xCM_ (m1, gt, m2, op, nops, ops, ae), \
16237 xCM_ (m1, le, m2, op, nops, ops, ae), \
16238 xCM_ (m1, al, m2, op, nops, ops, ae)
16239
16240 #define UE(mnem, op, nops, ops, ae) \
16241 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16242
16243 #define UF(mnem, op, nops, ops, ae) \
16244 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16245
16246 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
16247 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
16248 use the same encoding function for each. */
16249 #define NUF(mnem, op, nops, ops, enc) \
16250 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
16251 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16252
16253 /* Neon data processing, version which indirects through neon_enc_tab for
16254 the various overloaded versions of opcodes. */
16255 #define nUF(mnem, op, nops, ops, enc) \
16256 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
16257 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16258
16259 /* Neon insn with conditional suffix for the ARM version, non-overloaded
16260 version. */
16261 #define NCE_tag(mnem, op, nops, ops, enc, tag) \
16262 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
16263 THUMB_VARIANT, do_##enc, do_##enc }
16264
16265 #define NCE(mnem, op, nops, ops, enc) \
16266 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
16267
16268 #define NCEF(mnem, op, nops, ops, enc) \
16269 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
16270
16271 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
16272 #define nCE_tag(mnem, op, nops, ops, enc, tag) \
16273 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
16274 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16275
16276 #define nCE(mnem, op, nops, ops, enc) \
16277 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
16278
16279 #define nCEF(mnem, op, nops, ops, enc) \
16280 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
16281
16282 #define do_0 0
16283
16284 /* Thumb-only, unconditional. */
16285 #define UT(mnem, op, nops, ops, te) TUE (mnem, 0, op, nops, ops, 0, te)
16286
16287 static const struct asm_opcode insns[] =
16288 {
16289 #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
16290 #define THUMB_VARIANT &arm_ext_v4t
16291 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
16292 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
16293 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
16294 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
16295 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
16296 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
16297 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
16298 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
16299 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
16300 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
16301 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
16302 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
16303 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
16304 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
16305 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
16306 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
16307
16308 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
16309 for setting PSR flag bits. They are obsolete in V6 and do not
16310 have Thumb equivalents. */
16311 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16312 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16313 CL("tstp", 110f000, 2, (RR, SH), cmp),
16314 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16315 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16316 CL("cmpp", 150f000, 2, (RR, SH), cmp),
16317 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16318 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16319 CL("cmnp", 170f000, 2, (RR, SH), cmp),
16320
16321 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
16322 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
16323 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
16324 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
16325
16326 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
16327 tC3("ldrb", 4500000, _ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
16328 tCE("str", 4000000, _str, 2, (RR, ADDRGLDR),ldst, t_ldst),
16329 tC3("strb", 4400000, _strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
16330
16331 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16332 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16333 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16334 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16335 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16336 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16337
16338 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
16339 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
16340 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
16341 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
16342
16343 /* Pseudo ops. */
16344 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
16345 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
16346 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
16347
16348 /* Thumb-compatibility pseudo ops. */
16349 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
16350 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
16351 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
16352 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
16353 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
16354 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
16355 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
16356 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
16357 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
16358 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
16359 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
16360 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
16361
16362 /* These may simplify to neg. */
16363 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
16364 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16365
16366 #undef THUMB_VARIANT
16367 #define THUMB_VARIANT & arm_ext_v6
16368
16369 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
16370
16371 /* V1 instructions with no Thumb analogue prior to V6T2. */
16372 #undef THUMB_VARIANT
16373 #define THUMB_VARIANT & arm_ext_v6t2
16374
16375 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16376 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16377 CL("teqp", 130f000, 2, (RR, SH), cmp),
16378
16379 TC3("ldrt", 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
16380 TC3("ldrbt", 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
16381 TC3("strt", 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
16382 TC3("strbt", 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
16383
16384 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16385 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16386
16387 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16388 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16389
16390 /* V1 instructions with no Thumb analogue at all. */
16391 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
16392 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
16393
16394 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
16395 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
16396 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
16397 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
16398 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
16399 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
16400 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
16401 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
16402
16403 #undef ARM_VARIANT
16404 #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
16405 #undef THUMB_VARIANT
16406 #define THUMB_VARIANT & arm_ext_v4t
16407
16408 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
16409 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
16410
16411 #undef THUMB_VARIANT
16412 #define THUMB_VARIANT & arm_ext_v6t2
16413
16414 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
16415 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
16416
16417 /* Generic coprocessor instructions. */
16418 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16419 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16420 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16421 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16422 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16423 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16424 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16425
16426 #undef ARM_VARIANT
16427 #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
16428
16429 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
16430 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
16431
16432 #undef ARM_VARIANT
16433 #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
16434 #undef THUMB_VARIANT
16435 #define THUMB_VARIANT & arm_ext_msr
16436
16437 TCE("mrs", 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
16438 TCE("msr", 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
16439
16440 #undef ARM_VARIANT
16441 #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
16442 #undef THUMB_VARIANT
16443 #define THUMB_VARIANT & arm_ext_v6t2
16444
16445 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16446 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16447 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16448 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16449 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16450 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16451 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16452 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16453
16454 #undef ARM_VARIANT
16455 #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
16456 #undef THUMB_VARIANT
16457 #define THUMB_VARIANT & arm_ext_v4t
16458
16459 tC3("ldrh", 01000b0, _ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16460 tC3("strh", 00000b0, _strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16461 tC3("ldrsh", 01000f0, _ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16462 tC3("ldrsb", 01000d0, _ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16463 tCM("ld","sh", 01000f0, _ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16464 tCM("ld","sb", 01000d0, _ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16465
16466 #undef ARM_VARIANT
16467 #define ARM_VARIANT & arm_ext_v4t_5
16468
16469 /* ARM Architecture 4T. */
16470 /* Note: bx (and blx) are required on V5, even if the processor does
16471 not support Thumb. */
16472 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
16473
16474 #undef ARM_VARIANT
16475 #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
16476 #undef THUMB_VARIANT
16477 #define THUMB_VARIANT & arm_ext_v5t
16478
16479 /* Note: blx has 2 variants; the .value coded here is for
16480 BLX(2). Only this variant has conditional execution. */
16481 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
16482 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
16483
16484 #undef THUMB_VARIANT
16485 #define THUMB_VARIANT & arm_ext_v6t2
16486
16487 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
16488 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16489 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16490 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16491 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16492 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16493 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16494 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16495
16496 #undef ARM_VARIANT
16497 #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
16498 #undef THUMB_VARIANT
16499 #define THUMB_VARIANT &arm_ext_v5exp
16500
16501 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16502 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16503 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16504 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16505
16506 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16507 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16508
16509 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16510 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16511 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16512 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16513
16514 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16515 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16516 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16517 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16518
16519 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16520 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16521
16522 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16523 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16524 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16525 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16526
16527 #undef ARM_VARIANT
16528 #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
16529 #undef THUMB_VARIANT
16530 #define THUMB_VARIANT &arm_ext_v6t2
16531
16532 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
16533 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
16534 TC3("strd", 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
16535
16536 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16537 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16538
16539 #undef ARM_VARIANT
16540 #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
16541
16542 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
16543
16544 #undef ARM_VARIANT
16545 #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
16546 #undef THUMB_VARIANT
16547 #define THUMB_VARIANT & arm_ext_v6
16548
16549 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
16550 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
16551 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16552 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16553 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16554 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16555 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16556 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16557 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16558 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
16559
16560 #undef THUMB_VARIANT
16561 #define THUMB_VARIANT & arm_ext_v6t2
16562
16563 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
16564 TCE("strex", 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
16565 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16566 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16567
16568 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
16569 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
16570
16571 /* ARM V6 not included in V7M. */
16572 #undef THUMB_VARIANT
16573 #define THUMB_VARIANT & arm_ext_v6_notm
16574 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
16575 UF(rfeib, 9900a00, 1, (RRw), rfe),
16576 UF(rfeda, 8100a00, 1, (RRw), rfe),
16577 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
16578 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
16579 UF(rfefa, 9900a00, 1, (RRw), rfe),
16580 UF(rfeea, 8100a00, 1, (RRw), rfe),
16581 TUF("rfeed", 9100a00, e810c000, 1, (RRw), rfe, rfe),
16582 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
16583 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
16584 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
16585 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
16586
16587 /* ARM V6 not included in V7M (eg. integer SIMD). */
16588 #undef THUMB_VARIANT
16589 #define THUMB_VARIANT & arm_ext_v6_dsp
16590 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
16591 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
16592 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
16593 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16594 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16595 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16596 /* Old name for QASX. */
16597 TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16598 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16599 /* Old name for QSAX. */
16600 TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16601 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16602 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16603 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16604 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16605 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16606 /* Old name for SASX. */
16607 TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16608 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16609 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16610 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16611 /* Old name for SHASX. */
16612 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16613 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16614 /* Old name for SHSAX. */
16615 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16616 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16617 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16618 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16619 /* Old name for SSAX. */
16620 TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16621 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16622 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16623 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16624 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16625 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16626 /* Old name for UASX. */
16627 TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16628 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16629 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16630 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16631 /* Old name for UHASX. */
16632 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16633 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16634 /* Old name for UHSAX. */
16635 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16636 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16637 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16638 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16639 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16640 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16641 /* Old name for UQASX. */
16642 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16643 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16644 /* Old name for UQSAX. */
16645 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16646 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16647 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16648 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16649 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16650 /* Old name for USAX. */
16651 TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16652 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16653 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16654 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16655 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16656 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16657 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16658 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16659 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16660 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16661 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16662 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16663 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16664 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16665 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16666 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16667 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16668 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16669 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16670 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16671 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16672 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16673 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16674 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16675 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16676 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16677 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16678 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16679 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16680 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
16681 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
16682 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16683 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16684 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
16685
16686 #undef ARM_VARIANT
16687 #define ARM_VARIANT & arm_ext_v6k
16688 #undef THUMB_VARIANT
16689 #define THUMB_VARIANT & arm_ext_v6k
16690
16691 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
16692 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
16693 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
16694 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
16695
16696 #undef THUMB_VARIANT
16697 #define THUMB_VARIANT & arm_ext_v6_notm
16698
16699 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
16700 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
16701
16702 #undef THUMB_VARIANT
16703 #define THUMB_VARIANT & arm_ext_v6t2
16704
16705 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
16706 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
16707 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
16708 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
16709 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
16710
16711 #undef ARM_VARIANT
16712 #define ARM_VARIANT & arm_ext_v6z
16713
16714 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
16715
16716 #undef ARM_VARIANT
16717 #define ARM_VARIANT & arm_ext_v6t2
16718
16719 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
16720 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
16721 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
16722 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
16723
16724 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
16725 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
16726 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
16727 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
16728
16729 TC3("ldrht", 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
16730 TC3("ldrsht", 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
16731 TC3("ldrsbt", 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
16732 TC3("strht", 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
16733
16734 UT("cbnz", b900, 2, (RR, EXP), t_cbz),
16735 UT("cbz", b100, 2, (RR, EXP), t_cbz),
16736
16737 /* ARM does not really have an IT instruction, so always allow it.
16738 The opcode is copied from Thumb in order to allow warnings in
16739 -mimplicit-it=[never | arm] modes. */
16740 #undef ARM_VARIANT
16741 #define ARM_VARIANT & arm_ext_v1
16742
16743 TUE("it", bf08, bf08, 1, (COND), it, t_it),
16744 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
16745 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
16746 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
16747 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
16748 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
16749 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
16750 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
16751 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
16752 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
16753 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
16754 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
16755 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
16756 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
16757 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
16758 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
16759 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
16760 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
16761
16762 /* Thumb2 only instructions. */
16763 #undef ARM_VARIANT
16764 #define ARM_VARIANT NULL
16765
16766 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
16767 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
16768 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
16769 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
16770 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
16771 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
16772
16773 /* Thumb-2 hardware division instructions (R and M profiles only). */
16774 #undef THUMB_VARIANT
16775 #define THUMB_VARIANT & arm_ext_div
16776
16777 TCE("sdiv", 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
16778 TCE("udiv", 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
16779
16780 /* ARM V6M/V7 instructions. */
16781 #undef ARM_VARIANT
16782 #define ARM_VARIANT & arm_ext_barrier
16783 #undef THUMB_VARIANT
16784 #define THUMB_VARIANT & arm_ext_barrier
16785
16786 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
16787 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
16788 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
16789
16790 /* ARM V7 instructions. */
16791 #undef ARM_VARIANT
16792 #define ARM_VARIANT & arm_ext_v7
16793 #undef THUMB_VARIANT
16794 #define THUMB_VARIANT & arm_ext_v7
16795
16796 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
16797 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
16798
16799 #undef ARM_VARIANT
16800 #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
16801
16802 cCE("wfs", e200110, 1, (RR), rd),
16803 cCE("rfs", e300110, 1, (RR), rd),
16804 cCE("wfc", e400110, 1, (RR), rd),
16805 cCE("rfc", e500110, 1, (RR), rd),
16806
16807 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
16808 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
16809 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
16810 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
16811
16812 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
16813 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
16814 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
16815 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
16816
16817 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
16818 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
16819 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
16820 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
16821 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
16822 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
16823 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
16824 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
16825 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
16826 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
16827 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
16828 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
16829
16830 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
16831 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
16832 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
16833 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
16834 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
16835 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
16836 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
16837 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
16838 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
16839 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
16840 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
16841 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
16842
16843 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
16844 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
16845 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
16846 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
16847 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
16848 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
16849 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
16850 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
16851 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
16852 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
16853 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
16854 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
16855
16856 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
16857 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
16858 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
16859 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
16860 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
16861 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
16862 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
16863 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
16864 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
16865 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
16866 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
16867 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
16868
16869 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
16870 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
16871 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
16872 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
16873 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
16874 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
16875 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
16876 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
16877 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
16878 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
16879 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
16880 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
16881
16882 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
16883 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
16884 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
16885 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
16886 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
16887 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
16888 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
16889 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
16890 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
16891 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
16892 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
16893 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
16894
16895 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
16896 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
16897 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
16898 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
16899 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
16900 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
16901 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
16902 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
16903 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
16904 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
16905 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
16906 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
16907
16908 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
16909 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
16910 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
16911 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
16912 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
16913 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
16914 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
16915 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
16916 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
16917 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
16918 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
16919 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
16920
16921 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
16922 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
16923 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
16924 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
16925 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
16926 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
16927 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
16928 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
16929 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
16930 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
16931 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
16932 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
16933
16934 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
16935 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
16936 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
16937 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
16938 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
16939 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
16940 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
16941 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
16942 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
16943 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
16944 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
16945 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
16946
16947 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
16948 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
16949 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
16950 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
16951 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
16952 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
16953 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
16954 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
16955 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
16956 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
16957 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
16958 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
16959
16960 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
16961 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
16962 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
16963 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
16964 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
16965 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
16966 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
16967 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
16968 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
16969 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
16970 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
16971 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
16972
16973 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
16974 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
16975 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
16976 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
16977 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
16978 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
16979 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
16980 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
16981 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
16982 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
16983 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
16984 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
16985
16986 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
16987 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
16988 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
16989 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
16990 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
16991 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
16992 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
16993 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
16994 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
16995 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
16996 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
16997 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
16998
16999 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
17000 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
17001 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
17002 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
17003 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
17004 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
17005 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
17006 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
17007 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
17008 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
17009 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
17010 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
17011
17012 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
17013 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
17014 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
17015 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
17016 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
17017 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
17018 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
17019 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
17020 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
17021 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
17022 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
17023 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
17024
17025 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
17026 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
17027 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
17028 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
17029 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
17030 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17031 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17032 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17033 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
17034 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
17035 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
17036 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
17037
17038 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
17039 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
17040 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
17041 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
17042 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
17043 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17044 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17045 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17046 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
17047 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
17048 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
17049 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
17050
17051 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
17052 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
17053 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
17054 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
17055 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
17056 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17057 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17058 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17059 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
17060 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
17061 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
17062 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
17063
17064 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
17065 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
17066 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
17067 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
17068 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
17069 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17070 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17071 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17072 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
17073 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
17074 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
17075 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
17076
17077 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
17078 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
17079 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
17080 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
17081 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
17082 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17083 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17084 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17085 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
17086 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
17087 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
17088 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
17089
17090 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
17091 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
17092 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
17093 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
17094 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
17095 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17096 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17097 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17098 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
17099 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
17100 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
17101 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
17102
17103 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
17104 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
17105 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
17106 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
17107 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
17108 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17109 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17110 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17111 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
17112 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
17113 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
17114 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
17115
17116 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
17117 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
17118 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
17119 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
17120 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
17121 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17122 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17123 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17124 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
17125 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
17126 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
17127 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
17128
17129 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
17130 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
17131 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
17132 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
17133 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
17134 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17135 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17136 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17137 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
17138 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
17139 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
17140 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
17141
17142 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
17143 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
17144 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
17145 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
17146 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
17147 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17148 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17149 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17150 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
17151 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
17152 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
17153 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
17154
17155 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17156 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17157 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17158 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17159 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17160 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17161 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17162 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17163 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17164 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17165 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17166 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17167
17168 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17169 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17170 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17171 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17172 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17173 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17174 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17175 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17176 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17177 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17178 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17179 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17180
17181 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17182 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17183 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17184 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17185 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17186 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17187 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17188 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17189 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17190 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17191 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17192 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17193
17194 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
17195 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
17196 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
17197 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
17198
17199 cCL("flts", e000110, 2, (RF, RR), rn_rd),
17200 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
17201 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
17202 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
17203 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
17204 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
17205 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
17206 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
17207 cCL("flte", e080110, 2, (RF, RR), rn_rd),
17208 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
17209 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
17210 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
17211
17212 /* The implementation of the FIX instruction is broken on some
17213 assemblers, in that it accepts a precision specifier as well as a
17214 rounding specifier, despite the fact that this is meaningless.
17215 To be more compatible, we accept it as well, though of course it
17216 does not set any bits. */
17217 cCE("fix", e100110, 2, (RR, RF), rd_rm),
17218 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
17219 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
17220 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
17221 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
17222 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
17223 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
17224 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
17225 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
17226 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
17227 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
17228 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
17229 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
17230
17231 /* Instructions that were new with the real FPA, call them V2. */
17232 #undef ARM_VARIANT
17233 #define ARM_VARIANT & fpu_fpa_ext_v2
17234
17235 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17236 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17237 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17238 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17239 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17240 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17241
17242 #undef ARM_VARIANT
17243 #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
17244
17245 /* Moves and type conversions. */
17246 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
17247 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
17248 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
17249 cCE("fmstat", ef1fa10, 0, (), noargs),
17250 cCE("vmrs", ef10a10, 2, (APSR_RR, RVC), vmrs),
17251 cCE("vmsr", ee10a10, 2, (RVC, RR), vmsr),
17252 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
17253 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
17254 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
17255 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17256 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
17257 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17258 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
17259 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
17260
17261 /* Memory operations. */
17262 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
17263 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
17264 cCE("fldmias", c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17265 cCE("fldmfds", c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17266 cCE("fldmdbs", d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17267 cCE("fldmeas", d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17268 cCE("fldmiax", c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17269 cCE("fldmfdx", c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17270 cCE("fldmdbx", d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
17271 cCE("fldmeax", d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
17272 cCE("fstmias", c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17273 cCE("fstmeas", c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17274 cCE("fstmdbs", d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17275 cCE("fstmfds", d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17276 cCE("fstmiax", c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17277 cCE("fstmeax", c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17278 cCE("fstmdbx", d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
17279 cCE("fstmfdx", d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
17280
17281 /* Monadic operations. */
17282 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
17283 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
17284 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
17285
17286 /* Dyadic operations. */
17287 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17288 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17289 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17290 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17291 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17292 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17293 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17294 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17295 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17296
17297 /* Comparisons. */
17298 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
17299 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
17300 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
17301 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
17302
17303 /* Double precision load/store are still present on single precision
17304 implementations. */
17305 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
17306 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
17307 cCE("fldmiad", c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17308 cCE("fldmfdd", c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17309 cCE("fldmdbd", d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17310 cCE("fldmead", d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17311 cCE("fstmiad", c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17312 cCE("fstmead", c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17313 cCE("fstmdbd", d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17314 cCE("fstmfdd", d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17315
17316 #undef ARM_VARIANT
17317 #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
17318
17319 /* Moves and type conversions. */
17320 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17321 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17322 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17323 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
17324 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
17325 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
17326 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
17327 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17328 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
17329 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17330 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17331 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17332 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17333
17334 /* Monadic operations. */
17335 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17336 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17337 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17338
17339 /* Dyadic operations. */
17340 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17341 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17342 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17343 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17344 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17345 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17346 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17347 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17348 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17349
17350 /* Comparisons. */
17351 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17352 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
17353 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17354 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
17355
17356 #undef ARM_VARIANT
17357 #define ARM_VARIANT & fpu_vfp_ext_v2
17358
17359 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
17360 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
17361 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
17362 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
17363
17364 /* Instructions which may belong to either the Neon or VFP instruction sets.
17365 Individual encoder functions perform additional architecture checks. */
17366 #undef ARM_VARIANT
17367 #define ARM_VARIANT & fpu_vfp_ext_v1xd
17368 #undef THUMB_VARIANT
17369 #define THUMB_VARIANT & fpu_vfp_ext_v1xd
17370
17371 /* These mnemonics are unique to VFP. */
17372 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
17373 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
17374 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17375 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17376 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17377 nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
17378 nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
17379 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
17380 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
17381 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
17382
17383 /* Mnemonics shared by Neon and VFP. */
17384 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
17385 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
17386 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
17387
17388 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
17389 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
17390
17391 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17392 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17393
17394 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17395 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17396 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17397 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17398 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17399 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17400 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
17401 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
17402
17403 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
17404 nCEF(vcvtb, _vcvt, 2, (RVS, RVS), neon_cvtb),
17405 nCEF(vcvtt, _vcvt, 2, (RVS, RVS), neon_cvtt),
17406
17407
17408 /* NOTE: All VMOV encoding is special-cased! */
17409 NCE(vmov, 0, 1, (VMOV), neon_mov),
17410 NCE(vmovq, 0, 1, (VMOV), neon_mov),
17411
17412 #undef THUMB_VARIANT
17413 #define THUMB_VARIANT & fpu_neon_ext_v1
17414 #undef ARM_VARIANT
17415 #define ARM_VARIANT & fpu_neon_ext_v1
17416
17417 /* Data processing with three registers of the same length. */
17418 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
17419 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
17420 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
17421 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17422 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17423 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17424 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17425 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17426 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17427 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
17428 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17429 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
17430 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17431 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
17432 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17433 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
17434 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17435 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
17436 /* If not immediate, fall back to neon_dyadic_i64_su.
17437 shl_imm should accept I8 I16 I32 I64,
17438 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
17439 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
17440 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
17441 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
17442 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
17443 /* Logic ops, types optional & ignored. */
17444 nUF(vand, _vand, 2, (RNDQ, NILO), neon_logic),
17445 nUF(vandq, _vand, 2, (RNQ, NILO), neon_logic),
17446 nUF(vbic, _vbic, 2, (RNDQ, NILO), neon_logic),
17447 nUF(vbicq, _vbic, 2, (RNQ, NILO), neon_logic),
17448 nUF(vorr, _vorr, 2, (RNDQ, NILO), neon_logic),
17449 nUF(vorrq, _vorr, 2, (RNQ, NILO), neon_logic),
17450 nUF(vorn, _vorn, 2, (RNDQ, NILO), neon_logic),
17451 nUF(vornq, _vorn, 2, (RNQ, NILO), neon_logic),
17452 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
17453 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
17454 /* Bitfield ops, untyped. */
17455 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17456 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17457 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17458 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17459 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17460 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17461 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
17462 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17463 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17464 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17465 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17466 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17467 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17468 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
17469 back to neon_dyadic_if_su. */
17470 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17471 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17472 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17473 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17474 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17475 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
17476 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17477 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
17478 /* Comparison. Type I8 I16 I32 F32. */
17479 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
17480 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
17481 /* As above, D registers only. */
17482 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
17483 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
17484 /* Int and float variants, signedness unimportant. */
17485 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17486 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17487 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
17488 /* Add/sub take types I8 I16 I32 I64 F32. */
17489 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
17490 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
17491 /* vtst takes sizes 8, 16, 32. */
17492 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
17493 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
17494 /* VMUL takes I8 I16 I32 F32 P8. */
17495 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
17496 /* VQD{R}MULH takes S16 S32. */
17497 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17498 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
17499 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17500 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
17501 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17502 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
17503 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17504 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
17505 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17506 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
17507 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17508 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
17509 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17510 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17511 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17512 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17513
17514 /* Two address, int/float. Types S8 S16 S32 F32. */
17515 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
17516 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
17517
17518 /* Data processing with two registers and a shift amount. */
17519 /* Right shifts, and variants with rounding.
17520 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
17521 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17522 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17523 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17524 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17525 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17526 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17527 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17528 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17529 /* Shift and insert. Sizes accepted 8 16 32 64. */
17530 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
17531 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
17532 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
17533 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
17534 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
17535 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
17536 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
17537 /* Right shift immediate, saturating & narrowing, with rounding variants.
17538 Types accepted S16 S32 S64 U16 U32 U64. */
17539 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17540 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17541 /* As above, unsigned. Types accepted S16 S32 S64. */
17542 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17543 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17544 /* Right shift narrowing. Types accepted I16 I32 I64. */
17545 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17546 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17547 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
17548 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
17549 /* CVT with optional immediate for fixed-point variant. */
17550 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
17551
17552 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
17553 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
17554
17555 /* Data processing, three registers of different lengths. */
17556 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
17557 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
17558 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
17559 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
17560 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
17561 /* If not scalar, fall back to neon_dyadic_long.
17562 Vector types as above, scalar types S16 S32 U16 U32. */
17563 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
17564 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
17565 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
17566 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17567 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17568 /* Dyadic, narrowing insns. Types I16 I32 I64. */
17569 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17570 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17571 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17572 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17573 /* Saturating doubling multiplies. Types S16 S32. */
17574 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17575 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17576 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17577 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
17578 S16 S32 U16 U32. */
17579 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
17580
17581 /* Extract. Size 8. */
17582 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
17583 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
17584
17585 /* Two registers, miscellaneous. */
17586 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
17587 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
17588 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
17589 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
17590 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
17591 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
17592 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
17593 /* Vector replicate. Sizes 8 16 32. */
17594 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
17595 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
17596 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
17597 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
17598 /* VMOVN. Types I16 I32 I64. */
17599 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
17600 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
17601 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
17602 /* VQMOVUN. Types S16 S32 S64. */
17603 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
17604 /* VZIP / VUZP. Sizes 8 16 32. */
17605 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
17606 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
17607 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
17608 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
17609 /* VQABS / VQNEG. Types S8 S16 S32. */
17610 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17611 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
17612 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17613 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
17614 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
17615 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
17616 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
17617 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
17618 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
17619 /* Reciprocal estimates. Types U32 F32. */
17620 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
17621 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
17622 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
17623 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
17624 /* VCLS. Types S8 S16 S32. */
17625 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
17626 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
17627 /* VCLZ. Types I8 I16 I32. */
17628 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
17629 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
17630 /* VCNT. Size 8. */
17631 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
17632 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
17633 /* Two address, untyped. */
17634 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
17635 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
17636 /* VTRN. Sizes 8 16 32. */
17637 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
17638 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
17639
17640 /* Table lookup. Size 8. */
17641 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
17642 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
17643
17644 #undef THUMB_VARIANT
17645 #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
17646 #undef ARM_VARIANT
17647 #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
17648
17649 /* Neon element/structure load/store. */
17650 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
17651 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
17652 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
17653 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
17654 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
17655 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
17656 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
17657 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
17658
17659 #undef THUMB_VARIANT
17660 #define THUMB_VARIANT &fpu_vfp_ext_v3xd
17661 #undef ARM_VARIANT
17662 #define ARM_VARIANT &fpu_vfp_ext_v3xd
17663 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
17664 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17665 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17666 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17667 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17668 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17669 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17670 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17671 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17672
17673 #undef THUMB_VARIANT
17674 #define THUMB_VARIANT & fpu_vfp_ext_v3
17675 #undef ARM_VARIANT
17676 #define ARM_VARIANT & fpu_vfp_ext_v3
17677
17678 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
17679 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
17680 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
17681 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
17682 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
17683 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
17684 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
17685 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
17686 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
17687
17688 #undef ARM_VARIANT
17689 #define ARM_VARIANT &fpu_vfp_ext_fma
17690 #undef THUMB_VARIANT
17691 #define THUMB_VARIANT &fpu_vfp_ext_fma
17692 /* Mnemonics shared by Neon and VFP. These are included in the
17693 VFP FMA variant; NEON and VFP FMA always includes the NEON
17694 FMA instructions. */
17695 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
17696 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
17697 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
17698 the v form should always be used. */
17699 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17700 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17701 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17702 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17703 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17704 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17705
17706 #undef THUMB_VARIANT
17707 #undef ARM_VARIANT
17708 #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
17709
17710 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17711 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17712 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17713 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17714 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17715 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17716 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
17717 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
17718
17719 #undef ARM_VARIANT
17720 #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
17721
17722 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
17723 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
17724 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
17725 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
17726 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
17727 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
17728 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
17729 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
17730 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
17731 cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17732 cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17733 cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17734 cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17735 cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17736 cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17737 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17738 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17739 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17740 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
17741 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
17742 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17743 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17744 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17745 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17746 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17747 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17748 cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn),
17749 cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn),
17750 cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn),
17751 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
17752 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
17753 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
17754 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
17755 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
17756 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
17757 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
17758 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
17759 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17760 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17761 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17762 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17763 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17764 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17765 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17766 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17767 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17768 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
17769 cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17770 cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17771 cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17772 cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17773 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17774 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17775 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17776 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17777 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17778 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17779 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17780 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17781 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17782 cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17783 cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17784 cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17785 cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17786 cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17787 cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17788 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17789 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17790 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
17791 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
17792 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17793 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17794 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17795 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17796 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17797 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17798 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17799 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17800 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17801 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17802 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17803 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17804 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17805 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17806 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17807 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17808 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17809 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17810 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
17811 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17812 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17813 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17814 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17815 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17816 cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17817 cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17818 cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17819 cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17820 cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17821 cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17822 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17823 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17824 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17825 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17826 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17827 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17828 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17829 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17830 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17831 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17832 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
17833 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17834 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17835 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17836 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17837 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17838 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17839 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17840 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17841 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17842 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17843 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17844 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17845 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17846 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17847 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17848 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17849 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17850 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17851 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17852 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17853 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
17854 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
17855 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17856 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17857 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17858 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17859 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17860 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17861 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17862 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17863 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17864 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
17865 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
17866 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
17867 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
17868 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
17869 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
17870 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17871 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17872 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17873 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
17874 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
17875 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
17876 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
17877 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
17878 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
17879 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17880 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17881 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17882 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17883 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
17884
17885 #undef ARM_VARIANT
17886 #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
17887
17888 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
17889 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
17890 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
17891 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
17892 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
17893 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
17894 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17895 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17896 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17897 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17898 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17899 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17900 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17901 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17902 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17903 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17904 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17905 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17906 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17907 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17908 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
17909 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17910 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17911 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17912 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17913 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17914 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17915 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17916 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17917 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17918 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17919 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17920 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17921 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17922 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17923 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17924 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17925 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17926 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17927 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17928 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17929 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17930 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17931 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17932 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17933 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17934 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17935 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17936 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17937 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17938 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17939 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17940 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17941 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17942 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17943 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17944 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17945
17946 #undef ARM_VARIANT
17947 #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
17948
17949 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
17950 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
17951 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
17952 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
17953 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
17954 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
17955 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
17956 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
17957 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
17958 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
17959 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
17960 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
17961 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
17962 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
17963 cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd),
17964 cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn),
17965 cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd),
17966 cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn),
17967 cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn),
17968 cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn),
17969 cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn),
17970 cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn),
17971 cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn),
17972 cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn),
17973 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
17974 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
17975 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
17976 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
17977 cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc),
17978 cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd),
17979 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
17980 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
17981 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
17982 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
17983 cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn),
17984 cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn),
17985 cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn),
17986 cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn),
17987 cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn),
17988 cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn),
17989 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
17990 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
17991 cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple),
17992 cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple),
17993 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
17994 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
17995 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
17996 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
17997 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
17998 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
17999 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
18000 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
18001 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
18002 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
18003 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
18004 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
18005 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
18006 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
18007 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
18008 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
18009 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
18010 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
18011 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
18012 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
18013 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18014 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18015 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18016 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18017 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18018 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18019 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18020 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18021 cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18022 cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18023 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
18024 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
18025 };
18026 #undef ARM_VARIANT
18027 #undef THUMB_VARIANT
18028 #undef TCE
18029 #undef TCM
18030 #undef TUE
18031 #undef TUF
18032 #undef TCC
18033 #undef cCE
18034 #undef cCL
18035 #undef C3E
18036 #undef CE
18037 #undef CM
18038 #undef UE
18039 #undef UF
18040 #undef UT
18041 #undef NUF
18042 #undef nUF
18043 #undef NCE
18044 #undef nCE
18045 #undef OPS0
18046 #undef OPS1
18047 #undef OPS2
18048 #undef OPS3
18049 #undef OPS4
18050 #undef OPS5
18051 #undef OPS6
18052 #undef do_0
18053 \f
18054 /* MD interface: bits in the object file. */
18055
18056 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
18057 for use in the a.out file, and stores them in the array pointed to by buf.
18058 This knows about the endian-ness of the target machine and does
18059 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
18060 2 (short) and 4 (long) Floating numbers are put out as a series of
18061 LITTLENUMS (shorts, here at least). */
18062
18063 void
18064 md_number_to_chars (char * buf, valueT val, int n)
18065 {
18066 if (target_big_endian)
18067 number_to_chars_bigendian (buf, val, n);
18068 else
18069 number_to_chars_littleendian (buf, val, n);
18070 }
18071
18072 static valueT
18073 md_chars_to_number (char * buf, int n)
18074 {
18075 valueT result = 0;
18076 unsigned char * where = (unsigned char *) buf;
18077
18078 if (target_big_endian)
18079 {
18080 while (n--)
18081 {
18082 result <<= 8;
18083 result |= (*where++ & 255);
18084 }
18085 }
18086 else
18087 {
18088 while (n--)
18089 {
18090 result <<= 8;
18091 result |= (where[n] & 255);
18092 }
18093 }
18094
18095 return result;
18096 }
18097
18098 /* MD interface: Sections. */
18099
18100 /* Estimate the size of a frag before relaxing. Assume everything fits in
18101 2 bytes. */
18102
18103 int
18104 md_estimate_size_before_relax (fragS * fragp,
18105 segT segtype ATTRIBUTE_UNUSED)
18106 {
18107 fragp->fr_var = 2;
18108 return 2;
18109 }
18110
18111 /* Convert a machine dependent frag. */
18112
18113 void
18114 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
18115 {
18116 unsigned long insn;
18117 unsigned long old_op;
18118 char *buf;
18119 expressionS exp;
18120 fixS *fixp;
18121 int reloc_type;
18122 int pc_rel;
18123 int opcode;
18124
18125 buf = fragp->fr_literal + fragp->fr_fix;
18126
18127 old_op = bfd_get_16(abfd, buf);
18128 if (fragp->fr_symbol)
18129 {
18130 exp.X_op = O_symbol;
18131 exp.X_add_symbol = fragp->fr_symbol;
18132 }
18133 else
18134 {
18135 exp.X_op = O_constant;
18136 }
18137 exp.X_add_number = fragp->fr_offset;
18138 opcode = fragp->fr_subtype;
18139 switch (opcode)
18140 {
18141 case T_MNEM_ldr_pc:
18142 case T_MNEM_ldr_pc2:
18143 case T_MNEM_ldr_sp:
18144 case T_MNEM_str_sp:
18145 case T_MNEM_ldr:
18146 case T_MNEM_ldrb:
18147 case T_MNEM_ldrh:
18148 case T_MNEM_str:
18149 case T_MNEM_strb:
18150 case T_MNEM_strh:
18151 if (fragp->fr_var == 4)
18152 {
18153 insn = THUMB_OP32 (opcode);
18154 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
18155 {
18156 insn |= (old_op & 0x700) << 4;
18157 }
18158 else
18159 {
18160 insn |= (old_op & 7) << 12;
18161 insn |= (old_op & 0x38) << 13;
18162 }
18163 insn |= 0x00000c00;
18164 put_thumb32_insn (buf, insn);
18165 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
18166 }
18167 else
18168 {
18169 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
18170 }
18171 pc_rel = (opcode == T_MNEM_ldr_pc2);
18172 break;
18173 case T_MNEM_adr:
18174 if (fragp->fr_var == 4)
18175 {
18176 insn = THUMB_OP32 (opcode);
18177 insn |= (old_op & 0xf0) << 4;
18178 put_thumb32_insn (buf, insn);
18179 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
18180 }
18181 else
18182 {
18183 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18184 exp.X_add_number -= 4;
18185 }
18186 pc_rel = 1;
18187 break;
18188 case T_MNEM_mov:
18189 case T_MNEM_movs:
18190 case T_MNEM_cmp:
18191 case T_MNEM_cmn:
18192 if (fragp->fr_var == 4)
18193 {
18194 int r0off = (opcode == T_MNEM_mov
18195 || opcode == T_MNEM_movs) ? 0 : 8;
18196 insn = THUMB_OP32 (opcode);
18197 insn = (insn & 0xe1ffffff) | 0x10000000;
18198 insn |= (old_op & 0x700) << r0off;
18199 put_thumb32_insn (buf, insn);
18200 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
18201 }
18202 else
18203 {
18204 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
18205 }
18206 pc_rel = 0;
18207 break;
18208 case T_MNEM_b:
18209 if (fragp->fr_var == 4)
18210 {
18211 insn = THUMB_OP32(opcode);
18212 put_thumb32_insn (buf, insn);
18213 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
18214 }
18215 else
18216 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
18217 pc_rel = 1;
18218 break;
18219 case T_MNEM_bcond:
18220 if (fragp->fr_var == 4)
18221 {
18222 insn = THUMB_OP32(opcode);
18223 insn |= (old_op & 0xf00) << 14;
18224 put_thumb32_insn (buf, insn);
18225 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
18226 }
18227 else
18228 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
18229 pc_rel = 1;
18230 break;
18231 case T_MNEM_add_sp:
18232 case T_MNEM_add_pc:
18233 case T_MNEM_inc_sp:
18234 case T_MNEM_dec_sp:
18235 if (fragp->fr_var == 4)
18236 {
18237 /* ??? Choose between add and addw. */
18238 insn = THUMB_OP32 (opcode);
18239 insn |= (old_op & 0xf0) << 4;
18240 put_thumb32_insn (buf, insn);
18241 if (opcode == T_MNEM_add_pc)
18242 reloc_type = BFD_RELOC_ARM_T32_IMM12;
18243 else
18244 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
18245 }
18246 else
18247 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18248 pc_rel = 0;
18249 break;
18250
18251 case T_MNEM_addi:
18252 case T_MNEM_addis:
18253 case T_MNEM_subi:
18254 case T_MNEM_subis:
18255 if (fragp->fr_var == 4)
18256 {
18257 insn = THUMB_OP32 (opcode);
18258 insn |= (old_op & 0xf0) << 4;
18259 insn |= (old_op & 0xf) << 16;
18260 put_thumb32_insn (buf, insn);
18261 if (insn & (1 << 20))
18262 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
18263 else
18264 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
18265 }
18266 else
18267 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18268 pc_rel = 0;
18269 break;
18270 default:
18271 abort ();
18272 }
18273 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
18274 (enum bfd_reloc_code_real) reloc_type);
18275 fixp->fx_file = fragp->fr_file;
18276 fixp->fx_line = fragp->fr_line;
18277 fragp->fr_fix += fragp->fr_var;
18278 }
18279
18280 /* Return the size of a relaxable immediate operand instruction.
18281 SHIFT and SIZE specify the form of the allowable immediate. */
18282 static int
18283 relax_immediate (fragS *fragp, int size, int shift)
18284 {
18285 offsetT offset;
18286 offsetT mask;
18287 offsetT low;
18288
18289 /* ??? Should be able to do better than this. */
18290 if (fragp->fr_symbol)
18291 return 4;
18292
18293 low = (1 << shift) - 1;
18294 mask = (1 << (shift + size)) - (1 << shift);
18295 offset = fragp->fr_offset;
18296 /* Force misaligned offsets to 32-bit variant. */
18297 if (offset & low)
18298 return 4;
18299 if (offset & ~mask)
18300 return 4;
18301 return 2;
18302 }
18303
18304 /* Get the address of a symbol during relaxation. */
18305 static addressT
18306 relaxed_symbol_addr (fragS *fragp, long stretch)
18307 {
18308 fragS *sym_frag;
18309 addressT addr;
18310 symbolS *sym;
18311
18312 sym = fragp->fr_symbol;
18313 sym_frag = symbol_get_frag (sym);
18314 know (S_GET_SEGMENT (sym) != absolute_section
18315 || sym_frag == &zero_address_frag);
18316 addr = S_GET_VALUE (sym) + fragp->fr_offset;
18317
18318 /* If frag has yet to be reached on this pass, assume it will
18319 move by STRETCH just as we did. If this is not so, it will
18320 be because some frag between grows, and that will force
18321 another pass. */
18322
18323 if (stretch != 0
18324 && sym_frag->relax_marker != fragp->relax_marker)
18325 {
18326 fragS *f;
18327
18328 /* Adjust stretch for any alignment frag. Note that if have
18329 been expanding the earlier code, the symbol may be
18330 defined in what appears to be an earlier frag. FIXME:
18331 This doesn't handle the fr_subtype field, which specifies
18332 a maximum number of bytes to skip when doing an
18333 alignment. */
18334 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
18335 {
18336 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
18337 {
18338 if (stretch < 0)
18339 stretch = - ((- stretch)
18340 & ~ ((1 << (int) f->fr_offset) - 1));
18341 else
18342 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
18343 if (stretch == 0)
18344 break;
18345 }
18346 }
18347 if (f != NULL)
18348 addr += stretch;
18349 }
18350
18351 return addr;
18352 }
18353
18354 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
18355 load. */
18356 static int
18357 relax_adr (fragS *fragp, asection *sec, long stretch)
18358 {
18359 addressT addr;
18360 offsetT val;
18361
18362 /* Assume worst case for symbols not known to be in the same section. */
18363 if (fragp->fr_symbol == NULL
18364 || !S_IS_DEFINED (fragp->fr_symbol)
18365 || sec != S_GET_SEGMENT (fragp->fr_symbol))
18366 return 4;
18367
18368 val = relaxed_symbol_addr (fragp, stretch);
18369 addr = fragp->fr_address + fragp->fr_fix;
18370 addr = (addr + 4) & ~3;
18371 /* Force misaligned targets to 32-bit variant. */
18372 if (val & 3)
18373 return 4;
18374 val -= addr;
18375 if (val < 0 || val > 1020)
18376 return 4;
18377 return 2;
18378 }
18379
18380 /* Return the size of a relaxable add/sub immediate instruction. */
18381 static int
18382 relax_addsub (fragS *fragp, asection *sec)
18383 {
18384 char *buf;
18385 int op;
18386
18387 buf = fragp->fr_literal + fragp->fr_fix;
18388 op = bfd_get_16(sec->owner, buf);
18389 if ((op & 0xf) == ((op >> 4) & 0xf))
18390 return relax_immediate (fragp, 8, 0);
18391 else
18392 return relax_immediate (fragp, 3, 0);
18393 }
18394
18395
18396 /* Return the size of a relaxable branch instruction. BITS is the
18397 size of the offset field in the narrow instruction. */
18398
18399 static int
18400 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
18401 {
18402 addressT addr;
18403 offsetT val;
18404 offsetT limit;
18405
18406 /* Assume worst case for symbols not known to be in the same section. */
18407 if (!S_IS_DEFINED (fragp->fr_symbol)
18408 || sec != S_GET_SEGMENT (fragp->fr_symbol))
18409 return 4;
18410
18411 #ifdef OBJ_ELF
18412 if (S_IS_DEFINED (fragp->fr_symbol)
18413 && ARM_IS_FUNC (fragp->fr_symbol))
18414 return 4;
18415 #endif
18416
18417 val = relaxed_symbol_addr (fragp, stretch);
18418 addr = fragp->fr_address + fragp->fr_fix + 4;
18419 val -= addr;
18420
18421 /* Offset is a signed value *2 */
18422 limit = 1 << bits;
18423 if (val >= limit || val < -limit)
18424 return 4;
18425 return 2;
18426 }
18427
18428
18429 /* Relax a machine dependent frag. This returns the amount by which
18430 the current size of the frag should change. */
18431
18432 int
18433 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
18434 {
18435 int oldsize;
18436 int newsize;
18437
18438 oldsize = fragp->fr_var;
18439 switch (fragp->fr_subtype)
18440 {
18441 case T_MNEM_ldr_pc2:
18442 newsize = relax_adr (fragp, sec, stretch);
18443 break;
18444 case T_MNEM_ldr_pc:
18445 case T_MNEM_ldr_sp:
18446 case T_MNEM_str_sp:
18447 newsize = relax_immediate (fragp, 8, 2);
18448 break;
18449 case T_MNEM_ldr:
18450 case T_MNEM_str:
18451 newsize = relax_immediate (fragp, 5, 2);
18452 break;
18453 case T_MNEM_ldrh:
18454 case T_MNEM_strh:
18455 newsize = relax_immediate (fragp, 5, 1);
18456 break;
18457 case T_MNEM_ldrb:
18458 case T_MNEM_strb:
18459 newsize = relax_immediate (fragp, 5, 0);
18460 break;
18461 case T_MNEM_adr:
18462 newsize = relax_adr (fragp, sec, stretch);
18463 break;
18464 case T_MNEM_mov:
18465 case T_MNEM_movs:
18466 case T_MNEM_cmp:
18467 case T_MNEM_cmn:
18468 newsize = relax_immediate (fragp, 8, 0);
18469 break;
18470 case T_MNEM_b:
18471 newsize = relax_branch (fragp, sec, 11, stretch);
18472 break;
18473 case T_MNEM_bcond:
18474 newsize = relax_branch (fragp, sec, 8, stretch);
18475 break;
18476 case T_MNEM_add_sp:
18477 case T_MNEM_add_pc:
18478 newsize = relax_immediate (fragp, 8, 2);
18479 break;
18480 case T_MNEM_inc_sp:
18481 case T_MNEM_dec_sp:
18482 newsize = relax_immediate (fragp, 7, 2);
18483 break;
18484 case T_MNEM_addi:
18485 case T_MNEM_addis:
18486 case T_MNEM_subi:
18487 case T_MNEM_subis:
18488 newsize = relax_addsub (fragp, sec);
18489 break;
18490 default:
18491 abort ();
18492 }
18493
18494 fragp->fr_var = newsize;
18495 /* Freeze wide instructions that are at or before the same location as
18496 in the previous pass. This avoids infinite loops.
18497 Don't freeze them unconditionally because targets may be artificially
18498 misaligned by the expansion of preceding frags. */
18499 if (stretch <= 0 && newsize > 2)
18500 {
18501 md_convert_frag (sec->owner, sec, fragp);
18502 frag_wane (fragp);
18503 }
18504
18505 return newsize - oldsize;
18506 }
18507
18508 /* Round up a section size to the appropriate boundary. */
18509
18510 valueT
18511 md_section_align (segT segment ATTRIBUTE_UNUSED,
18512 valueT size)
18513 {
18514 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
18515 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
18516 {
18517 /* For a.out, force the section size to be aligned. If we don't do
18518 this, BFD will align it for us, but it will not write out the
18519 final bytes of the section. This may be a bug in BFD, but it is
18520 easier to fix it here since that is how the other a.out targets
18521 work. */
18522 int align;
18523
18524 align = bfd_get_section_alignment (stdoutput, segment);
18525 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
18526 }
18527 #endif
18528
18529 return size;
18530 }
18531
18532 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
18533 of an rs_align_code fragment. */
18534
18535 void
18536 arm_handle_align (fragS * fragP)
18537 {
18538 static char const arm_noop[2][2][4] =
18539 {
18540 { /* ARMv1 */
18541 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
18542 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
18543 },
18544 { /* ARMv6k */
18545 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
18546 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
18547 },
18548 };
18549 static char const thumb_noop[2][2][2] =
18550 {
18551 { /* Thumb-1 */
18552 {0xc0, 0x46}, /* LE */
18553 {0x46, 0xc0}, /* BE */
18554 },
18555 { /* Thumb-2 */
18556 {0x00, 0xbf}, /* LE */
18557 {0xbf, 0x00} /* BE */
18558 }
18559 };
18560 static char const wide_thumb_noop[2][4] =
18561 { /* Wide Thumb-2 */
18562 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
18563 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
18564 };
18565
18566 unsigned bytes, fix, noop_size;
18567 char * p;
18568 const char * noop;
18569 const char *narrow_noop = NULL;
18570 #ifdef OBJ_ELF
18571 enum mstate state;
18572 #endif
18573
18574 if (fragP->fr_type != rs_align_code)
18575 return;
18576
18577 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
18578 p = fragP->fr_literal + fragP->fr_fix;
18579 fix = 0;
18580
18581 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
18582 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
18583
18584 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
18585
18586 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
18587 {
18588 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
18589 {
18590 narrow_noop = thumb_noop[1][target_big_endian];
18591 noop = wide_thumb_noop[target_big_endian];
18592 }
18593 else
18594 noop = thumb_noop[0][target_big_endian];
18595 noop_size = 2;
18596 #ifdef OBJ_ELF
18597 state = MAP_THUMB;
18598 #endif
18599 }
18600 else
18601 {
18602 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
18603 [target_big_endian];
18604 noop_size = 4;
18605 #ifdef OBJ_ELF
18606 state = MAP_ARM;
18607 #endif
18608 }
18609
18610 fragP->fr_var = noop_size;
18611
18612 if (bytes & (noop_size - 1))
18613 {
18614 fix = bytes & (noop_size - 1);
18615 #ifdef OBJ_ELF
18616 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
18617 #endif
18618 memset (p, 0, fix);
18619 p += fix;
18620 bytes -= fix;
18621 }
18622
18623 if (narrow_noop)
18624 {
18625 if (bytes & noop_size)
18626 {
18627 /* Insert a narrow noop. */
18628 memcpy (p, narrow_noop, noop_size);
18629 p += noop_size;
18630 bytes -= noop_size;
18631 fix += noop_size;
18632 }
18633
18634 /* Use wide noops for the remainder */
18635 noop_size = 4;
18636 }
18637
18638 while (bytes >= noop_size)
18639 {
18640 memcpy (p, noop, noop_size);
18641 p += noop_size;
18642 bytes -= noop_size;
18643 fix += noop_size;
18644 }
18645
18646 fragP->fr_fix += fix;
18647 }
18648
18649 /* Called from md_do_align. Used to create an alignment
18650 frag in a code section. */
18651
18652 void
18653 arm_frag_align_code (int n, int max)
18654 {
18655 char * p;
18656
18657 /* We assume that there will never be a requirement
18658 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
18659 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
18660 {
18661 char err_msg[128];
18662
18663 sprintf (err_msg,
18664 _("alignments greater than %d bytes not supported in .text sections."),
18665 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
18666 as_fatal ("%s", err_msg);
18667 }
18668
18669 p = frag_var (rs_align_code,
18670 MAX_MEM_FOR_RS_ALIGN_CODE,
18671 1,
18672 (relax_substateT) max,
18673 (symbolS *) NULL,
18674 (offsetT) n,
18675 (char *) NULL);
18676 *p = 0;
18677 }
18678
18679 /* Perform target specific initialisation of a frag.
18680 Note - despite the name this initialisation is not done when the frag
18681 is created, but only when its type is assigned. A frag can be created
18682 and used a long time before its type is set, so beware of assuming that
18683 this initialisationis performed first. */
18684
18685 #ifndef OBJ_ELF
18686 void
18687 arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
18688 {
18689 /* Record whether this frag is in an ARM or a THUMB area. */
18690 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
18691 }
18692
18693 #else /* OBJ_ELF is defined. */
18694 void
18695 arm_init_frag (fragS * fragP, int max_chars)
18696 {
18697 /* If the current ARM vs THUMB mode has not already
18698 been recorded into this frag then do so now. */
18699 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
18700 {
18701 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
18702
18703 /* Record a mapping symbol for alignment frags. We will delete this
18704 later if the alignment ends up empty. */
18705 switch (fragP->fr_type)
18706 {
18707 case rs_align:
18708 case rs_align_test:
18709 case rs_fill:
18710 mapping_state_2 (MAP_DATA, max_chars);
18711 break;
18712 case rs_align_code:
18713 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
18714 break;
18715 default:
18716 break;
18717 }
18718 }
18719 }
18720
18721 /* When we change sections we need to issue a new mapping symbol. */
18722
18723 void
18724 arm_elf_change_section (void)
18725 {
18726 /* Link an unlinked unwind index table section to the .text section. */
18727 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
18728 && elf_linked_to_section (now_seg) == NULL)
18729 elf_linked_to_section (now_seg) = text_section;
18730 }
18731
18732 int
18733 arm_elf_section_type (const char * str, size_t len)
18734 {
18735 if (len == 5 && strncmp (str, "exidx", 5) == 0)
18736 return SHT_ARM_EXIDX;
18737
18738 return -1;
18739 }
18740 \f
18741 /* Code to deal with unwinding tables. */
18742
18743 static void add_unwind_adjustsp (offsetT);
18744
18745 /* Generate any deferred unwind frame offset. */
18746
18747 static void
18748 flush_pending_unwind (void)
18749 {
18750 offsetT offset;
18751
18752 offset = unwind.pending_offset;
18753 unwind.pending_offset = 0;
18754 if (offset != 0)
18755 add_unwind_adjustsp (offset);
18756 }
18757
18758 /* Add an opcode to this list for this function. Two-byte opcodes should
18759 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
18760 order. */
18761
18762 static void
18763 add_unwind_opcode (valueT op, int length)
18764 {
18765 /* Add any deferred stack adjustment. */
18766 if (unwind.pending_offset)
18767 flush_pending_unwind ();
18768
18769 unwind.sp_restored = 0;
18770
18771 if (unwind.opcode_count + length > unwind.opcode_alloc)
18772 {
18773 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
18774 if (unwind.opcodes)
18775 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
18776 unwind.opcode_alloc);
18777 else
18778 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
18779 }
18780 while (length > 0)
18781 {
18782 length--;
18783 unwind.opcodes[unwind.opcode_count] = op & 0xff;
18784 op >>= 8;
18785 unwind.opcode_count++;
18786 }
18787 }
18788
18789 /* Add unwind opcodes to adjust the stack pointer. */
18790
18791 static void
18792 add_unwind_adjustsp (offsetT offset)
18793 {
18794 valueT op;
18795
18796 if (offset > 0x200)
18797 {
18798 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
18799 char bytes[5];
18800 int n;
18801 valueT o;
18802
18803 /* Long form: 0xb2, uleb128. */
18804 /* This might not fit in a word so add the individual bytes,
18805 remembering the list is built in reverse order. */
18806 o = (valueT) ((offset - 0x204) >> 2);
18807 if (o == 0)
18808 add_unwind_opcode (0, 1);
18809
18810 /* Calculate the uleb128 encoding of the offset. */
18811 n = 0;
18812 while (o)
18813 {
18814 bytes[n] = o & 0x7f;
18815 o >>= 7;
18816 if (o)
18817 bytes[n] |= 0x80;
18818 n++;
18819 }
18820 /* Add the insn. */
18821 for (; n; n--)
18822 add_unwind_opcode (bytes[n - 1], 1);
18823 add_unwind_opcode (0xb2, 1);
18824 }
18825 else if (offset > 0x100)
18826 {
18827 /* Two short opcodes. */
18828 add_unwind_opcode (0x3f, 1);
18829 op = (offset - 0x104) >> 2;
18830 add_unwind_opcode (op, 1);
18831 }
18832 else if (offset > 0)
18833 {
18834 /* Short opcode. */
18835 op = (offset - 4) >> 2;
18836 add_unwind_opcode (op, 1);
18837 }
18838 else if (offset < 0)
18839 {
18840 offset = -offset;
18841 while (offset > 0x100)
18842 {
18843 add_unwind_opcode (0x7f, 1);
18844 offset -= 0x100;
18845 }
18846 op = ((offset - 4) >> 2) | 0x40;
18847 add_unwind_opcode (op, 1);
18848 }
18849 }
18850
18851 /* Finish the list of unwind opcodes for this function. */
18852 static void
18853 finish_unwind_opcodes (void)
18854 {
18855 valueT op;
18856
18857 if (unwind.fp_used)
18858 {
18859 /* Adjust sp as necessary. */
18860 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
18861 flush_pending_unwind ();
18862
18863 /* After restoring sp from the frame pointer. */
18864 op = 0x90 | unwind.fp_reg;
18865 add_unwind_opcode (op, 1);
18866 }
18867 else
18868 flush_pending_unwind ();
18869 }
18870
18871
18872 /* Start an exception table entry. If idx is nonzero this is an index table
18873 entry. */
18874
18875 static void
18876 start_unwind_section (const segT text_seg, int idx)
18877 {
18878 const char * text_name;
18879 const char * prefix;
18880 const char * prefix_once;
18881 const char * group_name;
18882 size_t prefix_len;
18883 size_t text_len;
18884 char * sec_name;
18885 size_t sec_name_len;
18886 int type;
18887 int flags;
18888 int linkonce;
18889
18890 if (idx)
18891 {
18892 prefix = ELF_STRING_ARM_unwind;
18893 prefix_once = ELF_STRING_ARM_unwind_once;
18894 type = SHT_ARM_EXIDX;
18895 }
18896 else
18897 {
18898 prefix = ELF_STRING_ARM_unwind_info;
18899 prefix_once = ELF_STRING_ARM_unwind_info_once;
18900 type = SHT_PROGBITS;
18901 }
18902
18903 text_name = segment_name (text_seg);
18904 if (streq (text_name, ".text"))
18905 text_name = "";
18906
18907 if (strncmp (text_name, ".gnu.linkonce.t.",
18908 strlen (".gnu.linkonce.t.")) == 0)
18909 {
18910 prefix = prefix_once;
18911 text_name += strlen (".gnu.linkonce.t.");
18912 }
18913
18914 prefix_len = strlen (prefix);
18915 text_len = strlen (text_name);
18916 sec_name_len = prefix_len + text_len;
18917 sec_name = (char *) xmalloc (sec_name_len + 1);
18918 memcpy (sec_name, prefix, prefix_len);
18919 memcpy (sec_name + prefix_len, text_name, text_len);
18920 sec_name[prefix_len + text_len] = '\0';
18921
18922 flags = SHF_ALLOC;
18923 linkonce = 0;
18924 group_name = 0;
18925
18926 /* Handle COMDAT group. */
18927 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
18928 {
18929 group_name = elf_group_name (text_seg);
18930 if (group_name == NULL)
18931 {
18932 as_bad (_("Group section `%s' has no group signature"),
18933 segment_name (text_seg));
18934 ignore_rest_of_line ();
18935 return;
18936 }
18937 flags |= SHF_GROUP;
18938 linkonce = 1;
18939 }
18940
18941 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
18942
18943 /* Set the section link for index tables. */
18944 if (idx)
18945 elf_linked_to_section (now_seg) = text_seg;
18946 }
18947
18948
18949 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
18950 personality routine data. Returns zero, or the index table value for
18951 and inline entry. */
18952
18953 static valueT
18954 create_unwind_entry (int have_data)
18955 {
18956 int size;
18957 addressT where;
18958 char *ptr;
18959 /* The current word of data. */
18960 valueT data;
18961 /* The number of bytes left in this word. */
18962 int n;
18963
18964 finish_unwind_opcodes ();
18965
18966 /* Remember the current text section. */
18967 unwind.saved_seg = now_seg;
18968 unwind.saved_subseg = now_subseg;
18969
18970 start_unwind_section (now_seg, 0);
18971
18972 if (unwind.personality_routine == NULL)
18973 {
18974 if (unwind.personality_index == -2)
18975 {
18976 if (have_data)
18977 as_bad (_("handlerdata in cantunwind frame"));
18978 return 1; /* EXIDX_CANTUNWIND. */
18979 }
18980
18981 /* Use a default personality routine if none is specified. */
18982 if (unwind.personality_index == -1)
18983 {
18984 if (unwind.opcode_count > 3)
18985 unwind.personality_index = 1;
18986 else
18987 unwind.personality_index = 0;
18988 }
18989
18990 /* Space for the personality routine entry. */
18991 if (unwind.personality_index == 0)
18992 {
18993 if (unwind.opcode_count > 3)
18994 as_bad (_("too many unwind opcodes for personality routine 0"));
18995
18996 if (!have_data)
18997 {
18998 /* All the data is inline in the index table. */
18999 data = 0x80;
19000 n = 3;
19001 while (unwind.opcode_count > 0)
19002 {
19003 unwind.opcode_count--;
19004 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19005 n--;
19006 }
19007
19008 /* Pad with "finish" opcodes. */
19009 while (n--)
19010 data = (data << 8) | 0xb0;
19011
19012 return data;
19013 }
19014 size = 0;
19015 }
19016 else
19017 /* We get two opcodes "free" in the first word. */
19018 size = unwind.opcode_count - 2;
19019 }
19020 else
19021 /* An extra byte is required for the opcode count. */
19022 size = unwind.opcode_count + 1;
19023
19024 size = (size + 3) >> 2;
19025 if (size > 0xff)
19026 as_bad (_("too many unwind opcodes"));
19027
19028 frag_align (2, 0, 0);
19029 record_alignment (now_seg, 2);
19030 unwind.table_entry = expr_build_dot ();
19031
19032 /* Allocate the table entry. */
19033 ptr = frag_more ((size << 2) + 4);
19034 where = frag_now_fix () - ((size << 2) + 4);
19035
19036 switch (unwind.personality_index)
19037 {
19038 case -1:
19039 /* ??? Should this be a PLT generating relocation? */
19040 /* Custom personality routine. */
19041 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
19042 BFD_RELOC_ARM_PREL31);
19043
19044 where += 4;
19045 ptr += 4;
19046
19047 /* Set the first byte to the number of additional words. */
19048 data = size - 1;
19049 n = 3;
19050 break;
19051
19052 /* ABI defined personality routines. */
19053 case 0:
19054 /* Three opcodes bytes are packed into the first word. */
19055 data = 0x80;
19056 n = 3;
19057 break;
19058
19059 case 1:
19060 case 2:
19061 /* The size and first two opcode bytes go in the first word. */
19062 data = ((0x80 + unwind.personality_index) << 8) | size;
19063 n = 2;
19064 break;
19065
19066 default:
19067 /* Should never happen. */
19068 abort ();
19069 }
19070
19071 /* Pack the opcodes into words (MSB first), reversing the list at the same
19072 time. */
19073 while (unwind.opcode_count > 0)
19074 {
19075 if (n == 0)
19076 {
19077 md_number_to_chars (ptr, data, 4);
19078 ptr += 4;
19079 n = 4;
19080 data = 0;
19081 }
19082 unwind.opcode_count--;
19083 n--;
19084 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19085 }
19086
19087 /* Finish off the last word. */
19088 if (n < 4)
19089 {
19090 /* Pad with "finish" opcodes. */
19091 while (n--)
19092 data = (data << 8) | 0xb0;
19093
19094 md_number_to_chars (ptr, data, 4);
19095 }
19096
19097 if (!have_data)
19098 {
19099 /* Add an empty descriptor if there is no user-specified data. */
19100 ptr = frag_more (4);
19101 md_number_to_chars (ptr, 0, 4);
19102 }
19103
19104 return 0;
19105 }
19106
19107
19108 /* Initialize the DWARF-2 unwind information for this procedure. */
19109
19110 void
19111 tc_arm_frame_initial_instructions (void)
19112 {
19113 cfi_add_CFA_def_cfa (REG_SP, 0);
19114 }
19115 #endif /* OBJ_ELF */
19116
19117 /* Convert REGNAME to a DWARF-2 register number. */
19118
19119 int
19120 tc_arm_regname_to_dw2regnum (char *regname)
19121 {
19122 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
19123
19124 if (reg == FAIL)
19125 return -1;
19126
19127 return reg;
19128 }
19129
19130 #ifdef TE_PE
19131 void
19132 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
19133 {
19134 expressionS exp;
19135
19136 exp.X_op = O_secrel;
19137 exp.X_add_symbol = symbol;
19138 exp.X_add_number = 0;
19139 emit_expr (&exp, size);
19140 }
19141 #endif
19142
19143 /* MD interface: Symbol and relocation handling. */
19144
19145 /* Return the address within the segment that a PC-relative fixup is
19146 relative to. For ARM, PC-relative fixups applied to instructions
19147 are generally relative to the location of the fixup plus 8 bytes.
19148 Thumb branches are offset by 4, and Thumb loads relative to PC
19149 require special handling. */
19150
19151 long
19152 md_pcrel_from_section (fixS * fixP, segT seg)
19153 {
19154 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
19155
19156 /* If this is pc-relative and we are going to emit a relocation
19157 then we just want to put out any pipeline compensation that the linker
19158 will need. Otherwise we want to use the calculated base.
19159 For WinCE we skip the bias for externals as well, since this
19160 is how the MS ARM-CE assembler behaves and we want to be compatible. */
19161 if (fixP->fx_pcrel
19162 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
19163 || (arm_force_relocation (fixP)
19164 #ifdef TE_WINCE
19165 && !S_IS_EXTERNAL (fixP->fx_addsy)
19166 #endif
19167 )))
19168 base = 0;
19169
19170
19171 switch (fixP->fx_r_type)
19172 {
19173 /* PC relative addressing on the Thumb is slightly odd as the
19174 bottom two bits of the PC are forced to zero for the
19175 calculation. This happens *after* application of the
19176 pipeline offset. However, Thumb adrl already adjusts for
19177 this, so we need not do it again. */
19178 case BFD_RELOC_ARM_THUMB_ADD:
19179 return base & ~3;
19180
19181 case BFD_RELOC_ARM_THUMB_OFFSET:
19182 case BFD_RELOC_ARM_T32_OFFSET_IMM:
19183 case BFD_RELOC_ARM_T32_ADD_PC12:
19184 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
19185 return (base + 4) & ~3;
19186
19187 /* Thumb branches are simply offset by +4. */
19188 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19189 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19190 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19191 case BFD_RELOC_THUMB_PCREL_BRANCH20:
19192 case BFD_RELOC_THUMB_PCREL_BRANCH25:
19193 return base + 4;
19194
19195 case BFD_RELOC_THUMB_PCREL_BRANCH23:
19196 if (fixP->fx_addsy
19197 && ARM_IS_FUNC (fixP->fx_addsy)
19198 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19199 base = fixP->fx_where + fixP->fx_frag->fr_address;
19200 return base + 4;
19201
19202 /* BLX is like branches above, but forces the low two bits of PC to
19203 zero. */
19204 case BFD_RELOC_THUMB_PCREL_BLX:
19205 if (fixP->fx_addsy
19206 && THUMB_IS_FUNC (fixP->fx_addsy)
19207 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19208 base = fixP->fx_where + fixP->fx_frag->fr_address;
19209 return (base + 4) & ~3;
19210
19211 /* ARM mode branches are offset by +8. However, the Windows CE
19212 loader expects the relocation not to take this into account. */
19213 case BFD_RELOC_ARM_PCREL_BLX:
19214 if (fixP->fx_addsy
19215 && ARM_IS_FUNC (fixP->fx_addsy)
19216 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19217 base = fixP->fx_where + fixP->fx_frag->fr_address;
19218 return base + 8;
19219
19220 case BFD_RELOC_ARM_PCREL_CALL:
19221 if (fixP->fx_addsy
19222 && THUMB_IS_FUNC (fixP->fx_addsy)
19223 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19224 base = fixP->fx_where + fixP->fx_frag->fr_address;
19225 return base + 8;
19226
19227 case BFD_RELOC_ARM_PCREL_BRANCH:
19228 case BFD_RELOC_ARM_PCREL_JUMP:
19229 case BFD_RELOC_ARM_PLT32:
19230 #ifdef TE_WINCE
19231 /* When handling fixups immediately, because we have already
19232 discovered the value of a symbol, or the address of the frag involved
19233 we must account for the offset by +8, as the OS loader will never see the reloc.
19234 see fixup_segment() in write.c
19235 The S_IS_EXTERNAL test handles the case of global symbols.
19236 Those need the calculated base, not just the pipe compensation the linker will need. */
19237 if (fixP->fx_pcrel
19238 && fixP->fx_addsy != NULL
19239 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19240 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
19241 return base + 8;
19242 return base;
19243 #else
19244 return base + 8;
19245 #endif
19246
19247
19248 /* ARM mode loads relative to PC are also offset by +8. Unlike
19249 branches, the Windows CE loader *does* expect the relocation
19250 to take this into account. */
19251 case BFD_RELOC_ARM_OFFSET_IMM:
19252 case BFD_RELOC_ARM_OFFSET_IMM8:
19253 case BFD_RELOC_ARM_HWLITERAL:
19254 case BFD_RELOC_ARM_LITERAL:
19255 case BFD_RELOC_ARM_CP_OFF_IMM:
19256 return base + 8;
19257
19258
19259 /* Other PC-relative relocations are un-offset. */
19260 default:
19261 return base;
19262 }
19263 }
19264
19265 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
19266 Otherwise we have no need to default values of symbols. */
19267
19268 symbolS *
19269 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
19270 {
19271 #ifdef OBJ_ELF
19272 if (name[0] == '_' && name[1] == 'G'
19273 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
19274 {
19275 if (!GOT_symbol)
19276 {
19277 if (symbol_find (name))
19278 as_bad (_("GOT already in the symbol table"));
19279
19280 GOT_symbol = symbol_new (name, undefined_section,
19281 (valueT) 0, & zero_address_frag);
19282 }
19283
19284 return GOT_symbol;
19285 }
19286 #endif
19287
19288 return NULL;
19289 }
19290
19291 /* Subroutine of md_apply_fix. Check to see if an immediate can be
19292 computed as two separate immediate values, added together. We
19293 already know that this value cannot be computed by just one ARM
19294 instruction. */
19295
19296 static unsigned int
19297 validate_immediate_twopart (unsigned int val,
19298 unsigned int * highpart)
19299 {
19300 unsigned int a;
19301 unsigned int i;
19302
19303 for (i = 0; i < 32; i += 2)
19304 if (((a = rotate_left (val, i)) & 0xff) != 0)
19305 {
19306 if (a & 0xff00)
19307 {
19308 if (a & ~ 0xffff)
19309 continue;
19310 * highpart = (a >> 8) | ((i + 24) << 7);
19311 }
19312 else if (a & 0xff0000)
19313 {
19314 if (a & 0xff000000)
19315 continue;
19316 * highpart = (a >> 16) | ((i + 16) << 7);
19317 }
19318 else
19319 {
19320 gas_assert (a & 0xff000000);
19321 * highpart = (a >> 24) | ((i + 8) << 7);
19322 }
19323
19324 return (a & 0xff) | (i << 7);
19325 }
19326
19327 return FAIL;
19328 }
19329
19330 static int
19331 validate_offset_imm (unsigned int val, int hwse)
19332 {
19333 if ((hwse && val > 255) || val > 4095)
19334 return FAIL;
19335 return val;
19336 }
19337
19338 /* Subroutine of md_apply_fix. Do those data_ops which can take a
19339 negative immediate constant by altering the instruction. A bit of
19340 a hack really.
19341 MOV <-> MVN
19342 AND <-> BIC
19343 ADC <-> SBC
19344 by inverting the second operand, and
19345 ADD <-> SUB
19346 CMP <-> CMN
19347 by negating the second operand. */
19348
19349 static int
19350 negate_data_op (unsigned long * instruction,
19351 unsigned long value)
19352 {
19353 int op, new_inst;
19354 unsigned long negated, inverted;
19355
19356 negated = encode_arm_immediate (-value);
19357 inverted = encode_arm_immediate (~value);
19358
19359 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
19360 switch (op)
19361 {
19362 /* First negates. */
19363 case OPCODE_SUB: /* ADD <-> SUB */
19364 new_inst = OPCODE_ADD;
19365 value = negated;
19366 break;
19367
19368 case OPCODE_ADD:
19369 new_inst = OPCODE_SUB;
19370 value = negated;
19371 break;
19372
19373 case OPCODE_CMP: /* CMP <-> CMN */
19374 new_inst = OPCODE_CMN;
19375 value = negated;
19376 break;
19377
19378 case OPCODE_CMN:
19379 new_inst = OPCODE_CMP;
19380 value = negated;
19381 break;
19382
19383 /* Now Inverted ops. */
19384 case OPCODE_MOV: /* MOV <-> MVN */
19385 new_inst = OPCODE_MVN;
19386 value = inverted;
19387 break;
19388
19389 case OPCODE_MVN:
19390 new_inst = OPCODE_MOV;
19391 value = inverted;
19392 break;
19393
19394 case OPCODE_AND: /* AND <-> BIC */
19395 new_inst = OPCODE_BIC;
19396 value = inverted;
19397 break;
19398
19399 case OPCODE_BIC:
19400 new_inst = OPCODE_AND;
19401 value = inverted;
19402 break;
19403
19404 case OPCODE_ADC: /* ADC <-> SBC */
19405 new_inst = OPCODE_SBC;
19406 value = inverted;
19407 break;
19408
19409 case OPCODE_SBC:
19410 new_inst = OPCODE_ADC;
19411 value = inverted;
19412 break;
19413
19414 /* We cannot do anything. */
19415 default:
19416 return FAIL;
19417 }
19418
19419 if (value == (unsigned) FAIL)
19420 return FAIL;
19421
19422 *instruction &= OPCODE_MASK;
19423 *instruction |= new_inst << DATA_OP_SHIFT;
19424 return value;
19425 }
19426
19427 /* Like negate_data_op, but for Thumb-2. */
19428
19429 static unsigned int
19430 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
19431 {
19432 int op, new_inst;
19433 int rd;
19434 unsigned int negated, inverted;
19435
19436 negated = encode_thumb32_immediate (-value);
19437 inverted = encode_thumb32_immediate (~value);
19438
19439 rd = (*instruction >> 8) & 0xf;
19440 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
19441 switch (op)
19442 {
19443 /* ADD <-> SUB. Includes CMP <-> CMN. */
19444 case T2_OPCODE_SUB:
19445 new_inst = T2_OPCODE_ADD;
19446 value = negated;
19447 break;
19448
19449 case T2_OPCODE_ADD:
19450 new_inst = T2_OPCODE_SUB;
19451 value = negated;
19452 break;
19453
19454 /* ORR <-> ORN. Includes MOV <-> MVN. */
19455 case T2_OPCODE_ORR:
19456 new_inst = T2_OPCODE_ORN;
19457 value = inverted;
19458 break;
19459
19460 case T2_OPCODE_ORN:
19461 new_inst = T2_OPCODE_ORR;
19462 value = inverted;
19463 break;
19464
19465 /* AND <-> BIC. TST has no inverted equivalent. */
19466 case T2_OPCODE_AND:
19467 new_inst = T2_OPCODE_BIC;
19468 if (rd == 15)
19469 value = FAIL;
19470 else
19471 value = inverted;
19472 break;
19473
19474 case T2_OPCODE_BIC:
19475 new_inst = T2_OPCODE_AND;
19476 value = inverted;
19477 break;
19478
19479 /* ADC <-> SBC */
19480 case T2_OPCODE_ADC:
19481 new_inst = T2_OPCODE_SBC;
19482 value = inverted;
19483 break;
19484
19485 case T2_OPCODE_SBC:
19486 new_inst = T2_OPCODE_ADC;
19487 value = inverted;
19488 break;
19489
19490 /* We cannot do anything. */
19491 default:
19492 return FAIL;
19493 }
19494
19495 if (value == (unsigned int)FAIL)
19496 return FAIL;
19497
19498 *instruction &= T2_OPCODE_MASK;
19499 *instruction |= new_inst << T2_DATA_OP_SHIFT;
19500 return value;
19501 }
19502
19503 /* Read a 32-bit thumb instruction from buf. */
19504 static unsigned long
19505 get_thumb32_insn (char * buf)
19506 {
19507 unsigned long insn;
19508 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
19509 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19510
19511 return insn;
19512 }
19513
19514
19515 /* We usually want to set the low bit on the address of thumb function
19516 symbols. In particular .word foo - . should have the low bit set.
19517 Generic code tries to fold the difference of two symbols to
19518 a constant. Prevent this and force a relocation when the first symbols
19519 is a thumb function. */
19520
19521 bfd_boolean
19522 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
19523 {
19524 if (op == O_subtract
19525 && l->X_op == O_symbol
19526 && r->X_op == O_symbol
19527 && THUMB_IS_FUNC (l->X_add_symbol))
19528 {
19529 l->X_op = O_subtract;
19530 l->X_op_symbol = r->X_add_symbol;
19531 l->X_add_number -= r->X_add_number;
19532 return TRUE;
19533 }
19534
19535 /* Process as normal. */
19536 return FALSE;
19537 }
19538
19539 void
19540 md_apply_fix (fixS * fixP,
19541 valueT * valP,
19542 segT seg)
19543 {
19544 offsetT value = * valP;
19545 offsetT newval;
19546 unsigned int newimm;
19547 unsigned long temp;
19548 int sign;
19549 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
19550
19551 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
19552
19553 /* Note whether this will delete the relocation. */
19554
19555 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
19556 fixP->fx_done = 1;
19557
19558 /* On a 64-bit host, silently truncate 'value' to 32 bits for
19559 consistency with the behaviour on 32-bit hosts. Remember value
19560 for emit_reloc. */
19561 value &= 0xffffffff;
19562 value ^= 0x80000000;
19563 value -= 0x80000000;
19564
19565 *valP = value;
19566 fixP->fx_addnumber = value;
19567
19568 /* Same treatment for fixP->fx_offset. */
19569 fixP->fx_offset &= 0xffffffff;
19570 fixP->fx_offset ^= 0x80000000;
19571 fixP->fx_offset -= 0x80000000;
19572
19573 switch (fixP->fx_r_type)
19574 {
19575 case BFD_RELOC_NONE:
19576 /* This will need to go in the object file. */
19577 fixP->fx_done = 0;
19578 break;
19579
19580 case BFD_RELOC_ARM_IMMEDIATE:
19581 /* We claim that this fixup has been processed here,
19582 even if in fact we generate an error because we do
19583 not have a reloc for it, so tc_gen_reloc will reject it. */
19584 fixP->fx_done = 1;
19585
19586 if (fixP->fx_addsy
19587 && ! S_IS_DEFINED (fixP->fx_addsy))
19588 {
19589 as_bad_where (fixP->fx_file, fixP->fx_line,
19590 _("undefined symbol %s used as an immediate value"),
19591 S_GET_NAME (fixP->fx_addsy));
19592 break;
19593 }
19594
19595 if (fixP->fx_addsy
19596 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
19597 {
19598 as_bad_where (fixP->fx_file, fixP->fx_line,
19599 _("symbol %s is in a different section"),
19600 S_GET_NAME (fixP->fx_addsy));
19601 break;
19602 }
19603
19604 newimm = encode_arm_immediate (value);
19605 temp = md_chars_to_number (buf, INSN_SIZE);
19606
19607 /* If the instruction will fail, see if we can fix things up by
19608 changing the opcode. */
19609 if (newimm == (unsigned int) FAIL
19610 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
19611 {
19612 as_bad_where (fixP->fx_file, fixP->fx_line,
19613 _("invalid constant (%lx) after fixup"),
19614 (unsigned long) value);
19615 break;
19616 }
19617
19618 newimm |= (temp & 0xfffff000);
19619 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
19620 break;
19621
19622 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19623 {
19624 unsigned int highpart = 0;
19625 unsigned int newinsn = 0xe1a00000; /* nop. */
19626
19627 if (fixP->fx_addsy
19628 && ! S_IS_DEFINED (fixP->fx_addsy))
19629 {
19630 as_bad_where (fixP->fx_file, fixP->fx_line,
19631 _("undefined symbol %s used as an immediate value"),
19632 S_GET_NAME (fixP->fx_addsy));
19633 break;
19634 }
19635
19636 if (fixP->fx_addsy
19637 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
19638 {
19639 as_bad_where (fixP->fx_file, fixP->fx_line,
19640 _("symbol %s is in a different section"),
19641 S_GET_NAME (fixP->fx_addsy));
19642 break;
19643 }
19644
19645 newimm = encode_arm_immediate (value);
19646 temp = md_chars_to_number (buf, INSN_SIZE);
19647
19648 /* If the instruction will fail, see if we can fix things up by
19649 changing the opcode. */
19650 if (newimm == (unsigned int) FAIL
19651 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
19652 {
19653 /* No ? OK - try using two ADD instructions to generate
19654 the value. */
19655 newimm = validate_immediate_twopart (value, & highpart);
19656
19657 /* Yes - then make sure that the second instruction is
19658 also an add. */
19659 if (newimm != (unsigned int) FAIL)
19660 newinsn = temp;
19661 /* Still No ? Try using a negated value. */
19662 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
19663 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
19664 /* Otherwise - give up. */
19665 else
19666 {
19667 as_bad_where (fixP->fx_file, fixP->fx_line,
19668 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
19669 (long) value);
19670 break;
19671 }
19672
19673 /* Replace the first operand in the 2nd instruction (which
19674 is the PC) with the destination register. We have
19675 already added in the PC in the first instruction and we
19676 do not want to do it again. */
19677 newinsn &= ~ 0xf0000;
19678 newinsn |= ((newinsn & 0x0f000) << 4);
19679 }
19680
19681 newimm |= (temp & 0xfffff000);
19682 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
19683
19684 highpart |= (newinsn & 0xfffff000);
19685 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
19686 }
19687 break;
19688
19689 case BFD_RELOC_ARM_OFFSET_IMM:
19690 if (!fixP->fx_done && seg->use_rela_p)
19691 value = 0;
19692
19693 case BFD_RELOC_ARM_LITERAL:
19694 sign = value >= 0;
19695
19696 if (value < 0)
19697 value = - value;
19698
19699 if (validate_offset_imm (value, 0) == FAIL)
19700 {
19701 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
19702 as_bad_where (fixP->fx_file, fixP->fx_line,
19703 _("invalid literal constant: pool needs to be closer"));
19704 else
19705 as_bad_where (fixP->fx_file, fixP->fx_line,
19706 _("bad immediate value for offset (%ld)"),
19707 (long) value);
19708 break;
19709 }
19710
19711 newval = md_chars_to_number (buf, INSN_SIZE);
19712 newval &= 0xff7ff000;
19713 newval |= value | (sign ? INDEX_UP : 0);
19714 md_number_to_chars (buf, newval, INSN_SIZE);
19715 break;
19716
19717 case BFD_RELOC_ARM_OFFSET_IMM8:
19718 case BFD_RELOC_ARM_HWLITERAL:
19719 sign = value >= 0;
19720
19721 if (value < 0)
19722 value = - value;
19723
19724 if (validate_offset_imm (value, 1) == FAIL)
19725 {
19726 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
19727 as_bad_where (fixP->fx_file, fixP->fx_line,
19728 _("invalid literal constant: pool needs to be closer"));
19729 else
19730 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
19731 (long) value);
19732 break;
19733 }
19734
19735 newval = md_chars_to_number (buf, INSN_SIZE);
19736 newval &= 0xff7ff0f0;
19737 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
19738 md_number_to_chars (buf, newval, INSN_SIZE);
19739 break;
19740
19741 case BFD_RELOC_ARM_T32_OFFSET_U8:
19742 if (value < 0 || value > 1020 || value % 4 != 0)
19743 as_bad_where (fixP->fx_file, fixP->fx_line,
19744 _("bad immediate value for offset (%ld)"), (long) value);
19745 value /= 4;
19746
19747 newval = md_chars_to_number (buf+2, THUMB_SIZE);
19748 newval |= value;
19749 md_number_to_chars (buf+2, newval, THUMB_SIZE);
19750 break;
19751
19752 case BFD_RELOC_ARM_T32_OFFSET_IMM:
19753 /* This is a complicated relocation used for all varieties of Thumb32
19754 load/store instruction with immediate offset:
19755
19756 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
19757 *4, optional writeback(W)
19758 (doubleword load/store)
19759
19760 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
19761 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
19762 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
19763 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
19764 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
19765
19766 Uppercase letters indicate bits that are already encoded at
19767 this point. Lowercase letters are our problem. For the
19768 second block of instructions, the secondary opcode nybble
19769 (bits 8..11) is present, and bit 23 is zero, even if this is
19770 a PC-relative operation. */
19771 newval = md_chars_to_number (buf, THUMB_SIZE);
19772 newval <<= 16;
19773 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
19774
19775 if ((newval & 0xf0000000) == 0xe0000000)
19776 {
19777 /* Doubleword load/store: 8-bit offset, scaled by 4. */
19778 if (value >= 0)
19779 newval |= (1 << 23);
19780 else
19781 value = -value;
19782 if (value % 4 != 0)
19783 {
19784 as_bad_where (fixP->fx_file, fixP->fx_line,
19785 _("offset not a multiple of 4"));
19786 break;
19787 }
19788 value /= 4;
19789 if (value > 0xff)
19790 {
19791 as_bad_where (fixP->fx_file, fixP->fx_line,
19792 _("offset out of range"));
19793 break;
19794 }
19795 newval &= ~0xff;
19796 }
19797 else if ((newval & 0x000f0000) == 0x000f0000)
19798 {
19799 /* PC-relative, 12-bit offset. */
19800 if (value >= 0)
19801 newval |= (1 << 23);
19802 else
19803 value = -value;
19804 if (value > 0xfff)
19805 {
19806 as_bad_where (fixP->fx_file, fixP->fx_line,
19807 _("offset out of range"));
19808 break;
19809 }
19810 newval &= ~0xfff;
19811 }
19812 else if ((newval & 0x00000100) == 0x00000100)
19813 {
19814 /* Writeback: 8-bit, +/- offset. */
19815 if (value >= 0)
19816 newval |= (1 << 9);
19817 else
19818 value = -value;
19819 if (value > 0xff)
19820 {
19821 as_bad_where (fixP->fx_file, fixP->fx_line,
19822 _("offset out of range"));
19823 break;
19824 }
19825 newval &= ~0xff;
19826 }
19827 else if ((newval & 0x00000f00) == 0x00000e00)
19828 {
19829 /* T-instruction: positive 8-bit offset. */
19830 if (value < 0 || value > 0xff)
19831 {
19832 as_bad_where (fixP->fx_file, fixP->fx_line,
19833 _("offset out of range"));
19834 break;
19835 }
19836 newval &= ~0xff;
19837 newval |= value;
19838 }
19839 else
19840 {
19841 /* Positive 12-bit or negative 8-bit offset. */
19842 int limit;
19843 if (value >= 0)
19844 {
19845 newval |= (1 << 23);
19846 limit = 0xfff;
19847 }
19848 else
19849 {
19850 value = -value;
19851 limit = 0xff;
19852 }
19853 if (value > limit)
19854 {
19855 as_bad_where (fixP->fx_file, fixP->fx_line,
19856 _("offset out of range"));
19857 break;
19858 }
19859 newval &= ~limit;
19860 }
19861
19862 newval |= value;
19863 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
19864 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
19865 break;
19866
19867 case BFD_RELOC_ARM_SHIFT_IMM:
19868 newval = md_chars_to_number (buf, INSN_SIZE);
19869 if (((unsigned long) value) > 32
19870 || (value == 32
19871 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
19872 {
19873 as_bad_where (fixP->fx_file, fixP->fx_line,
19874 _("shift expression is too large"));
19875 break;
19876 }
19877
19878 if (value == 0)
19879 /* Shifts of zero must be done as lsl. */
19880 newval &= ~0x60;
19881 else if (value == 32)
19882 value = 0;
19883 newval &= 0xfffff07f;
19884 newval |= (value & 0x1f) << 7;
19885 md_number_to_chars (buf, newval, INSN_SIZE);
19886 break;
19887
19888 case BFD_RELOC_ARM_T32_IMMEDIATE:
19889 case BFD_RELOC_ARM_T32_ADD_IMM:
19890 case BFD_RELOC_ARM_T32_IMM12:
19891 case BFD_RELOC_ARM_T32_ADD_PC12:
19892 /* We claim that this fixup has been processed here,
19893 even if in fact we generate an error because we do
19894 not have a reloc for it, so tc_gen_reloc will reject it. */
19895 fixP->fx_done = 1;
19896
19897 if (fixP->fx_addsy
19898 && ! S_IS_DEFINED (fixP->fx_addsy))
19899 {
19900 as_bad_where (fixP->fx_file, fixP->fx_line,
19901 _("undefined symbol %s used as an immediate value"),
19902 S_GET_NAME (fixP->fx_addsy));
19903 break;
19904 }
19905
19906 newval = md_chars_to_number (buf, THUMB_SIZE);
19907 newval <<= 16;
19908 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
19909
19910 newimm = FAIL;
19911 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
19912 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
19913 {
19914 newimm = encode_thumb32_immediate (value);
19915 if (newimm == (unsigned int) FAIL)
19916 newimm = thumb32_negate_data_op (&newval, value);
19917 }
19918 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
19919 && newimm == (unsigned int) FAIL)
19920 {
19921 /* Turn add/sum into addw/subw. */
19922 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
19923 newval = (newval & 0xfeffffff) | 0x02000000;
19924
19925 /* 12 bit immediate for addw/subw. */
19926 if (value < 0)
19927 {
19928 value = -value;
19929 newval ^= 0x00a00000;
19930 }
19931 if (value > 0xfff)
19932 newimm = (unsigned int) FAIL;
19933 else
19934 newimm = value;
19935 }
19936
19937 if (newimm == (unsigned int)FAIL)
19938 {
19939 as_bad_where (fixP->fx_file, fixP->fx_line,
19940 _("invalid constant (%lx) after fixup"),
19941 (unsigned long) value);
19942 break;
19943 }
19944
19945 newval |= (newimm & 0x800) << 15;
19946 newval |= (newimm & 0x700) << 4;
19947 newval |= (newimm & 0x0ff);
19948
19949 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
19950 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
19951 break;
19952
19953 case BFD_RELOC_ARM_SMC:
19954 if (((unsigned long) value) > 0xffff)
19955 as_bad_where (fixP->fx_file, fixP->fx_line,
19956 _("invalid smc expression"));
19957 newval = md_chars_to_number (buf, INSN_SIZE);
19958 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
19959 md_number_to_chars (buf, newval, INSN_SIZE);
19960 break;
19961
19962 case BFD_RELOC_ARM_SWI:
19963 if (fixP->tc_fix_data != 0)
19964 {
19965 if (((unsigned long) value) > 0xff)
19966 as_bad_where (fixP->fx_file, fixP->fx_line,
19967 _("invalid swi expression"));
19968 newval = md_chars_to_number (buf, THUMB_SIZE);
19969 newval |= value;
19970 md_number_to_chars (buf, newval, THUMB_SIZE);
19971 }
19972 else
19973 {
19974 if (((unsigned long) value) > 0x00ffffff)
19975 as_bad_where (fixP->fx_file, fixP->fx_line,
19976 _("invalid swi expression"));
19977 newval = md_chars_to_number (buf, INSN_SIZE);
19978 newval |= value;
19979 md_number_to_chars (buf, newval, INSN_SIZE);
19980 }
19981 break;
19982
19983 case BFD_RELOC_ARM_MULTI:
19984 if (((unsigned long) value) > 0xffff)
19985 as_bad_where (fixP->fx_file, fixP->fx_line,
19986 _("invalid expression in load/store multiple"));
19987 newval = value | md_chars_to_number (buf, INSN_SIZE);
19988 md_number_to_chars (buf, newval, INSN_SIZE);
19989 break;
19990
19991 #ifdef OBJ_ELF
19992 case BFD_RELOC_ARM_PCREL_CALL:
19993
19994 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
19995 && fixP->fx_addsy
19996 && !S_IS_EXTERNAL (fixP->fx_addsy)
19997 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19998 && THUMB_IS_FUNC (fixP->fx_addsy))
19999 /* Flip the bl to blx. This is a simple flip
20000 bit here because we generate PCREL_CALL for
20001 unconditional bls. */
20002 {
20003 newval = md_chars_to_number (buf, INSN_SIZE);
20004 newval = newval | 0x10000000;
20005 md_number_to_chars (buf, newval, INSN_SIZE);
20006 temp = 1;
20007 fixP->fx_done = 1;
20008 }
20009 else
20010 temp = 3;
20011 goto arm_branch_common;
20012
20013 case BFD_RELOC_ARM_PCREL_JUMP:
20014 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20015 && fixP->fx_addsy
20016 && !S_IS_EXTERNAL (fixP->fx_addsy)
20017 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20018 && THUMB_IS_FUNC (fixP->fx_addsy))
20019 {
20020 /* This would map to a bl<cond>, b<cond>,
20021 b<always> to a Thumb function. We
20022 need to force a relocation for this particular
20023 case. */
20024 newval = md_chars_to_number (buf, INSN_SIZE);
20025 fixP->fx_done = 0;
20026 }
20027
20028 case BFD_RELOC_ARM_PLT32:
20029 #endif
20030 case BFD_RELOC_ARM_PCREL_BRANCH:
20031 temp = 3;
20032 goto arm_branch_common;
20033
20034 case BFD_RELOC_ARM_PCREL_BLX:
20035
20036 temp = 1;
20037 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20038 && fixP->fx_addsy
20039 && !S_IS_EXTERNAL (fixP->fx_addsy)
20040 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20041 && ARM_IS_FUNC (fixP->fx_addsy))
20042 {
20043 /* Flip the blx to a bl and warn. */
20044 const char *name = S_GET_NAME (fixP->fx_addsy);
20045 newval = 0xeb000000;
20046 as_warn_where (fixP->fx_file, fixP->fx_line,
20047 _("blx to '%s' an ARM ISA state function changed to bl"),
20048 name);
20049 md_number_to_chars (buf, newval, INSN_SIZE);
20050 temp = 3;
20051 fixP->fx_done = 1;
20052 }
20053
20054 #ifdef OBJ_ELF
20055 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
20056 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
20057 #endif
20058
20059 arm_branch_common:
20060 /* We are going to store value (shifted right by two) in the
20061 instruction, in a 24 bit, signed field. Bits 26 through 32 either
20062 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
20063 also be be clear. */
20064 if (value & temp)
20065 as_bad_where (fixP->fx_file, fixP->fx_line,
20066 _("misaligned branch destination"));
20067 if ((value & (offsetT)0xfe000000) != (offsetT)0
20068 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
20069 as_bad_where (fixP->fx_file, fixP->fx_line,
20070 _("branch out of range"));
20071
20072 if (fixP->fx_done || !seg->use_rela_p)
20073 {
20074 newval = md_chars_to_number (buf, INSN_SIZE);
20075 newval |= (value >> 2) & 0x00ffffff;
20076 /* Set the H bit on BLX instructions. */
20077 if (temp == 1)
20078 {
20079 if (value & 2)
20080 newval |= 0x01000000;
20081 else
20082 newval &= ~0x01000000;
20083 }
20084 md_number_to_chars (buf, newval, INSN_SIZE);
20085 }
20086 break;
20087
20088 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
20089 /* CBZ can only branch forward. */
20090
20091 /* Attempts to use CBZ to branch to the next instruction
20092 (which, strictly speaking, are prohibited) will be turned into
20093 no-ops.
20094
20095 FIXME: It may be better to remove the instruction completely and
20096 perform relaxation. */
20097 if (value == -2)
20098 {
20099 newval = md_chars_to_number (buf, THUMB_SIZE);
20100 newval = 0xbf00; /* NOP encoding T1 */
20101 md_number_to_chars (buf, newval, THUMB_SIZE);
20102 }
20103 else
20104 {
20105 if (value & ~0x7e)
20106 as_bad_where (fixP->fx_file, fixP->fx_line,
20107 _("branch out of range"));
20108
20109 if (fixP->fx_done || !seg->use_rela_p)
20110 {
20111 newval = md_chars_to_number (buf, THUMB_SIZE);
20112 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
20113 md_number_to_chars (buf, newval, THUMB_SIZE);
20114 }
20115 }
20116 break;
20117
20118 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
20119 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
20120 as_bad_where (fixP->fx_file, fixP->fx_line,
20121 _("branch out of range"));
20122
20123 if (fixP->fx_done || !seg->use_rela_p)
20124 {
20125 newval = md_chars_to_number (buf, THUMB_SIZE);
20126 newval |= (value & 0x1ff) >> 1;
20127 md_number_to_chars (buf, newval, THUMB_SIZE);
20128 }
20129 break;
20130
20131 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
20132 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
20133 as_bad_where (fixP->fx_file, fixP->fx_line,
20134 _("branch out of range"));
20135
20136 if (fixP->fx_done || !seg->use_rela_p)
20137 {
20138 newval = md_chars_to_number (buf, THUMB_SIZE);
20139 newval |= (value & 0xfff) >> 1;
20140 md_number_to_chars (buf, newval, THUMB_SIZE);
20141 }
20142 break;
20143
20144 case BFD_RELOC_THUMB_PCREL_BRANCH20:
20145 if (fixP->fx_addsy
20146 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20147 && !S_IS_EXTERNAL (fixP->fx_addsy)
20148 && S_IS_DEFINED (fixP->fx_addsy)
20149 && ARM_IS_FUNC (fixP->fx_addsy)
20150 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20151 {
20152 /* Force a relocation for a branch 20 bits wide. */
20153 fixP->fx_done = 0;
20154 }
20155 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
20156 as_bad_where (fixP->fx_file, fixP->fx_line,
20157 _("conditional branch out of range"));
20158
20159 if (fixP->fx_done || !seg->use_rela_p)
20160 {
20161 offsetT newval2;
20162 addressT S, J1, J2, lo, hi;
20163
20164 S = (value & 0x00100000) >> 20;
20165 J2 = (value & 0x00080000) >> 19;
20166 J1 = (value & 0x00040000) >> 18;
20167 hi = (value & 0x0003f000) >> 12;
20168 lo = (value & 0x00000ffe) >> 1;
20169
20170 newval = md_chars_to_number (buf, THUMB_SIZE);
20171 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20172 newval |= (S << 10) | hi;
20173 newval2 |= (J1 << 13) | (J2 << 11) | lo;
20174 md_number_to_chars (buf, newval, THUMB_SIZE);
20175 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20176 }
20177 break;
20178
20179 case BFD_RELOC_THUMB_PCREL_BLX:
20180
20181 /* If there is a blx from a thumb state function to
20182 another thumb function flip this to a bl and warn
20183 about it. */
20184
20185 if (fixP->fx_addsy
20186 && S_IS_DEFINED (fixP->fx_addsy)
20187 && !S_IS_EXTERNAL (fixP->fx_addsy)
20188 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20189 && THUMB_IS_FUNC (fixP->fx_addsy))
20190 {
20191 const char *name = S_GET_NAME (fixP->fx_addsy);
20192 as_warn_where (fixP->fx_file, fixP->fx_line,
20193 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
20194 name);
20195 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20196 newval = newval | 0x1000;
20197 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20198 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20199 fixP->fx_done = 1;
20200 }
20201
20202
20203 goto thumb_bl_common;
20204
20205 case BFD_RELOC_THUMB_PCREL_BRANCH23:
20206
20207 /* A bl from Thumb state ISA to an internal ARM state function
20208 is converted to a blx. */
20209 if (fixP->fx_addsy
20210 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20211 && !S_IS_EXTERNAL (fixP->fx_addsy)
20212 && S_IS_DEFINED (fixP->fx_addsy)
20213 && ARM_IS_FUNC (fixP->fx_addsy)
20214 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20215 {
20216 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20217 newval = newval & ~0x1000;
20218 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20219 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
20220 fixP->fx_done = 1;
20221 }
20222
20223 thumb_bl_common:
20224
20225 #ifdef OBJ_ELF
20226 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 &&
20227 fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20228 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20229 #endif
20230
20231 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
20232 as_bad_where (fixP->fx_file, fixP->fx_line,
20233 _("branch out of range"));
20234
20235 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20236 /* For a BLX instruction, make sure that the relocation is rounded up
20237 to a word boundary. This follows the semantics of the instruction
20238 which specifies that bit 1 of the target address will come from bit
20239 1 of the base address. */
20240 value = (value + 1) & ~ 1;
20241
20242 if (fixP->fx_done || !seg->use_rela_p)
20243 {
20244 offsetT newval2;
20245
20246 newval = md_chars_to_number (buf, THUMB_SIZE);
20247 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20248 newval |= (value & 0x7fffff) >> 12;
20249 newval2 |= (value & 0xfff) >> 1;
20250 md_number_to_chars (buf, newval, THUMB_SIZE);
20251 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20252 }
20253 break;
20254
20255 case BFD_RELOC_THUMB_PCREL_BRANCH25:
20256 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
20257 as_bad_where (fixP->fx_file, fixP->fx_line,
20258 _("branch out of range"));
20259
20260 if (fixP->fx_done || !seg->use_rela_p)
20261 {
20262 offsetT newval2;
20263 addressT S, I1, I2, lo, hi;
20264
20265 S = (value & 0x01000000) >> 24;
20266 I1 = (value & 0x00800000) >> 23;
20267 I2 = (value & 0x00400000) >> 22;
20268 hi = (value & 0x003ff000) >> 12;
20269 lo = (value & 0x00000ffe) >> 1;
20270
20271 I1 = !(I1 ^ S);
20272 I2 = !(I2 ^ S);
20273
20274 newval = md_chars_to_number (buf, THUMB_SIZE);
20275 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20276 newval |= (S << 10) | hi;
20277 newval2 |= (I1 << 13) | (I2 << 11) | lo;
20278 md_number_to_chars (buf, newval, THUMB_SIZE);
20279 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20280 }
20281 break;
20282
20283 case BFD_RELOC_8:
20284 if (fixP->fx_done || !seg->use_rela_p)
20285 md_number_to_chars (buf, value, 1);
20286 break;
20287
20288 case BFD_RELOC_16:
20289 if (fixP->fx_done || !seg->use_rela_p)
20290 md_number_to_chars (buf, value, 2);
20291 break;
20292
20293 #ifdef OBJ_ELF
20294 case BFD_RELOC_ARM_TLS_GD32:
20295 case BFD_RELOC_ARM_TLS_LE32:
20296 case BFD_RELOC_ARM_TLS_IE32:
20297 case BFD_RELOC_ARM_TLS_LDM32:
20298 case BFD_RELOC_ARM_TLS_LDO32:
20299 S_SET_THREAD_LOCAL (fixP->fx_addsy);
20300 /* fall through */
20301
20302 case BFD_RELOC_ARM_GOT32:
20303 case BFD_RELOC_ARM_GOTOFF:
20304 if (fixP->fx_done || !seg->use_rela_p)
20305 md_number_to_chars (buf, 0, 4);
20306 break;
20307
20308 case BFD_RELOC_ARM_TARGET2:
20309 /* TARGET2 is not partial-inplace, so we need to write the
20310 addend here for REL targets, because it won't be written out
20311 during reloc processing later. */
20312 if (fixP->fx_done || !seg->use_rela_p)
20313 md_number_to_chars (buf, fixP->fx_offset, 4);
20314 break;
20315 #endif
20316
20317 case BFD_RELOC_RVA:
20318 case BFD_RELOC_32:
20319 case BFD_RELOC_ARM_TARGET1:
20320 case BFD_RELOC_ARM_ROSEGREL32:
20321 case BFD_RELOC_ARM_SBREL32:
20322 case BFD_RELOC_32_PCREL:
20323 #ifdef TE_PE
20324 case BFD_RELOC_32_SECREL:
20325 #endif
20326 if (fixP->fx_done || !seg->use_rela_p)
20327 #ifdef TE_WINCE
20328 /* For WinCE we only do this for pcrel fixups. */
20329 if (fixP->fx_done || fixP->fx_pcrel)
20330 #endif
20331 md_number_to_chars (buf, value, 4);
20332 break;
20333
20334 #ifdef OBJ_ELF
20335 case BFD_RELOC_ARM_PREL31:
20336 if (fixP->fx_done || !seg->use_rela_p)
20337 {
20338 newval = md_chars_to_number (buf, 4) & 0x80000000;
20339 if ((value ^ (value >> 1)) & 0x40000000)
20340 {
20341 as_bad_where (fixP->fx_file, fixP->fx_line,
20342 _("rel31 relocation overflow"));
20343 }
20344 newval |= value & 0x7fffffff;
20345 md_number_to_chars (buf, newval, 4);
20346 }
20347 break;
20348 #endif
20349
20350 case BFD_RELOC_ARM_CP_OFF_IMM:
20351 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
20352 if (value < -1023 || value > 1023 || (value & 3))
20353 as_bad_where (fixP->fx_file, fixP->fx_line,
20354 _("co-processor offset out of range"));
20355 cp_off_common:
20356 sign = value >= 0;
20357 if (value < 0)
20358 value = -value;
20359 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20360 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20361 newval = md_chars_to_number (buf, INSN_SIZE);
20362 else
20363 newval = get_thumb32_insn (buf);
20364 newval &= 0xff7fff00;
20365 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
20366 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20367 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20368 md_number_to_chars (buf, newval, INSN_SIZE);
20369 else
20370 put_thumb32_insn (buf, newval);
20371 break;
20372
20373 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
20374 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
20375 if (value < -255 || value > 255)
20376 as_bad_where (fixP->fx_file, fixP->fx_line,
20377 _("co-processor offset out of range"));
20378 value *= 4;
20379 goto cp_off_common;
20380
20381 case BFD_RELOC_ARM_THUMB_OFFSET:
20382 newval = md_chars_to_number (buf, THUMB_SIZE);
20383 /* Exactly what ranges, and where the offset is inserted depends
20384 on the type of instruction, we can establish this from the
20385 top 4 bits. */
20386 switch (newval >> 12)
20387 {
20388 case 4: /* PC load. */
20389 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
20390 forced to zero for these loads; md_pcrel_from has already
20391 compensated for this. */
20392 if (value & 3)
20393 as_bad_where (fixP->fx_file, fixP->fx_line,
20394 _("invalid offset, target not word aligned (0x%08lX)"),
20395 (((unsigned long) fixP->fx_frag->fr_address
20396 + (unsigned long) fixP->fx_where) & ~3)
20397 + (unsigned long) value);
20398
20399 if (value & ~0x3fc)
20400 as_bad_where (fixP->fx_file, fixP->fx_line,
20401 _("invalid offset, value too big (0x%08lX)"),
20402 (long) value);
20403
20404 newval |= value >> 2;
20405 break;
20406
20407 case 9: /* SP load/store. */
20408 if (value & ~0x3fc)
20409 as_bad_where (fixP->fx_file, fixP->fx_line,
20410 _("invalid offset, value too big (0x%08lX)"),
20411 (long) value);
20412 newval |= value >> 2;
20413 break;
20414
20415 case 6: /* Word load/store. */
20416 if (value & ~0x7c)
20417 as_bad_where (fixP->fx_file, fixP->fx_line,
20418 _("invalid offset, value too big (0x%08lX)"),
20419 (long) value);
20420 newval |= value << 4; /* 6 - 2. */
20421 break;
20422
20423 case 7: /* Byte load/store. */
20424 if (value & ~0x1f)
20425 as_bad_where (fixP->fx_file, fixP->fx_line,
20426 _("invalid offset, value too big (0x%08lX)"),
20427 (long) value);
20428 newval |= value << 6;
20429 break;
20430
20431 case 8: /* Halfword load/store. */
20432 if (value & ~0x3e)
20433 as_bad_where (fixP->fx_file, fixP->fx_line,
20434 _("invalid offset, value too big (0x%08lX)"),
20435 (long) value);
20436 newval |= value << 5; /* 6 - 1. */
20437 break;
20438
20439 default:
20440 as_bad_where (fixP->fx_file, fixP->fx_line,
20441 "Unable to process relocation for thumb opcode: %lx",
20442 (unsigned long) newval);
20443 break;
20444 }
20445 md_number_to_chars (buf, newval, THUMB_SIZE);
20446 break;
20447
20448 case BFD_RELOC_ARM_THUMB_ADD:
20449 /* This is a complicated relocation, since we use it for all of
20450 the following immediate relocations:
20451
20452 3bit ADD/SUB
20453 8bit ADD/SUB
20454 9bit ADD/SUB SP word-aligned
20455 10bit ADD PC/SP word-aligned
20456
20457 The type of instruction being processed is encoded in the
20458 instruction field:
20459
20460 0x8000 SUB
20461 0x00F0 Rd
20462 0x000F Rs
20463 */
20464 newval = md_chars_to_number (buf, THUMB_SIZE);
20465 {
20466 int rd = (newval >> 4) & 0xf;
20467 int rs = newval & 0xf;
20468 int subtract = !!(newval & 0x8000);
20469
20470 /* Check for HI regs, only very restricted cases allowed:
20471 Adjusting SP, and using PC or SP to get an address. */
20472 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
20473 || (rs > 7 && rs != REG_SP && rs != REG_PC))
20474 as_bad_where (fixP->fx_file, fixP->fx_line,
20475 _("invalid Hi register with immediate"));
20476
20477 /* If value is negative, choose the opposite instruction. */
20478 if (value < 0)
20479 {
20480 value = -value;
20481 subtract = !subtract;
20482 if (value < 0)
20483 as_bad_where (fixP->fx_file, fixP->fx_line,
20484 _("immediate value out of range"));
20485 }
20486
20487 if (rd == REG_SP)
20488 {
20489 if (value & ~0x1fc)
20490 as_bad_where (fixP->fx_file, fixP->fx_line,
20491 _("invalid immediate for stack address calculation"));
20492 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
20493 newval |= value >> 2;
20494 }
20495 else if (rs == REG_PC || rs == REG_SP)
20496 {
20497 if (subtract || value & ~0x3fc)
20498 as_bad_where (fixP->fx_file, fixP->fx_line,
20499 _("invalid immediate for address calculation (value = 0x%08lX)"),
20500 (unsigned long) value);
20501 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
20502 newval |= rd << 8;
20503 newval |= value >> 2;
20504 }
20505 else if (rs == rd)
20506 {
20507 if (value & ~0xff)
20508 as_bad_where (fixP->fx_file, fixP->fx_line,
20509 _("immediate value out of range"));
20510 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
20511 newval |= (rd << 8) | value;
20512 }
20513 else
20514 {
20515 if (value & ~0x7)
20516 as_bad_where (fixP->fx_file, fixP->fx_line,
20517 _("immediate value out of range"));
20518 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
20519 newval |= rd | (rs << 3) | (value << 6);
20520 }
20521 }
20522 md_number_to_chars (buf, newval, THUMB_SIZE);
20523 break;
20524
20525 case BFD_RELOC_ARM_THUMB_IMM:
20526 newval = md_chars_to_number (buf, THUMB_SIZE);
20527 if (value < 0 || value > 255)
20528 as_bad_where (fixP->fx_file, fixP->fx_line,
20529 _("invalid immediate: %ld is out of range"),
20530 (long) value);
20531 newval |= value;
20532 md_number_to_chars (buf, newval, THUMB_SIZE);
20533 break;
20534
20535 case BFD_RELOC_ARM_THUMB_SHIFT:
20536 /* 5bit shift value (0..32). LSL cannot take 32. */
20537 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
20538 temp = newval & 0xf800;
20539 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
20540 as_bad_where (fixP->fx_file, fixP->fx_line,
20541 _("invalid shift value: %ld"), (long) value);
20542 /* Shifts of zero must be encoded as LSL. */
20543 if (value == 0)
20544 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
20545 /* Shifts of 32 are encoded as zero. */
20546 else if (value == 32)
20547 value = 0;
20548 newval |= value << 6;
20549 md_number_to_chars (buf, newval, THUMB_SIZE);
20550 break;
20551
20552 case BFD_RELOC_VTABLE_INHERIT:
20553 case BFD_RELOC_VTABLE_ENTRY:
20554 fixP->fx_done = 0;
20555 return;
20556
20557 case BFD_RELOC_ARM_MOVW:
20558 case BFD_RELOC_ARM_MOVT:
20559 case BFD_RELOC_ARM_THUMB_MOVW:
20560 case BFD_RELOC_ARM_THUMB_MOVT:
20561 if (fixP->fx_done || !seg->use_rela_p)
20562 {
20563 /* REL format relocations are limited to a 16-bit addend. */
20564 if (!fixP->fx_done)
20565 {
20566 if (value < -0x8000 || value > 0x7fff)
20567 as_bad_where (fixP->fx_file, fixP->fx_line,
20568 _("offset out of range"));
20569 }
20570 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
20571 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20572 {
20573 value >>= 16;
20574 }
20575
20576 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
20577 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20578 {
20579 newval = get_thumb32_insn (buf);
20580 newval &= 0xfbf08f00;
20581 newval |= (value & 0xf000) << 4;
20582 newval |= (value & 0x0800) << 15;
20583 newval |= (value & 0x0700) << 4;
20584 newval |= (value & 0x00ff);
20585 put_thumb32_insn (buf, newval);
20586 }
20587 else
20588 {
20589 newval = md_chars_to_number (buf, 4);
20590 newval &= 0xfff0f000;
20591 newval |= value & 0x0fff;
20592 newval |= (value & 0xf000) << 4;
20593 md_number_to_chars (buf, newval, 4);
20594 }
20595 }
20596 return;
20597
20598 case BFD_RELOC_ARM_ALU_PC_G0_NC:
20599 case BFD_RELOC_ARM_ALU_PC_G0:
20600 case BFD_RELOC_ARM_ALU_PC_G1_NC:
20601 case BFD_RELOC_ARM_ALU_PC_G1:
20602 case BFD_RELOC_ARM_ALU_PC_G2:
20603 case BFD_RELOC_ARM_ALU_SB_G0_NC:
20604 case BFD_RELOC_ARM_ALU_SB_G0:
20605 case BFD_RELOC_ARM_ALU_SB_G1_NC:
20606 case BFD_RELOC_ARM_ALU_SB_G1:
20607 case BFD_RELOC_ARM_ALU_SB_G2:
20608 gas_assert (!fixP->fx_done);
20609 if (!seg->use_rela_p)
20610 {
20611 bfd_vma insn;
20612 bfd_vma encoded_addend;
20613 bfd_vma addend_abs = abs (value);
20614
20615 /* Check that the absolute value of the addend can be
20616 expressed as an 8-bit constant plus a rotation. */
20617 encoded_addend = encode_arm_immediate (addend_abs);
20618 if (encoded_addend == (unsigned int) FAIL)
20619 as_bad_where (fixP->fx_file, fixP->fx_line,
20620 _("the offset 0x%08lX is not representable"),
20621 (unsigned long) addend_abs);
20622
20623 /* Extract the instruction. */
20624 insn = md_chars_to_number (buf, INSN_SIZE);
20625
20626 /* If the addend is positive, use an ADD instruction.
20627 Otherwise use a SUB. Take care not to destroy the S bit. */
20628 insn &= 0xff1fffff;
20629 if (value < 0)
20630 insn |= 1 << 22;
20631 else
20632 insn |= 1 << 23;
20633
20634 /* Place the encoded addend into the first 12 bits of the
20635 instruction. */
20636 insn &= 0xfffff000;
20637 insn |= encoded_addend;
20638
20639 /* Update the instruction. */
20640 md_number_to_chars (buf, insn, INSN_SIZE);
20641 }
20642 break;
20643
20644 case BFD_RELOC_ARM_LDR_PC_G0:
20645 case BFD_RELOC_ARM_LDR_PC_G1:
20646 case BFD_RELOC_ARM_LDR_PC_G2:
20647 case BFD_RELOC_ARM_LDR_SB_G0:
20648 case BFD_RELOC_ARM_LDR_SB_G1:
20649 case BFD_RELOC_ARM_LDR_SB_G2:
20650 gas_assert (!fixP->fx_done);
20651 if (!seg->use_rela_p)
20652 {
20653 bfd_vma insn;
20654 bfd_vma addend_abs = abs (value);
20655
20656 /* Check that the absolute value of the addend can be
20657 encoded in 12 bits. */
20658 if (addend_abs >= 0x1000)
20659 as_bad_where (fixP->fx_file, fixP->fx_line,
20660 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
20661 (unsigned long) addend_abs);
20662
20663 /* Extract the instruction. */
20664 insn = md_chars_to_number (buf, INSN_SIZE);
20665
20666 /* If the addend is negative, clear bit 23 of the instruction.
20667 Otherwise set it. */
20668 if (value < 0)
20669 insn &= ~(1 << 23);
20670 else
20671 insn |= 1 << 23;
20672
20673 /* Place the absolute value of the addend into the first 12 bits
20674 of the instruction. */
20675 insn &= 0xfffff000;
20676 insn |= addend_abs;
20677
20678 /* Update the instruction. */
20679 md_number_to_chars (buf, insn, INSN_SIZE);
20680 }
20681 break;
20682
20683 case BFD_RELOC_ARM_LDRS_PC_G0:
20684 case BFD_RELOC_ARM_LDRS_PC_G1:
20685 case BFD_RELOC_ARM_LDRS_PC_G2:
20686 case BFD_RELOC_ARM_LDRS_SB_G0:
20687 case BFD_RELOC_ARM_LDRS_SB_G1:
20688 case BFD_RELOC_ARM_LDRS_SB_G2:
20689 gas_assert (!fixP->fx_done);
20690 if (!seg->use_rela_p)
20691 {
20692 bfd_vma insn;
20693 bfd_vma addend_abs = abs (value);
20694
20695 /* Check that the absolute value of the addend can be
20696 encoded in 8 bits. */
20697 if (addend_abs >= 0x100)
20698 as_bad_where (fixP->fx_file, fixP->fx_line,
20699 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
20700 (unsigned long) addend_abs);
20701
20702 /* Extract the instruction. */
20703 insn = md_chars_to_number (buf, INSN_SIZE);
20704
20705 /* If the addend is negative, clear bit 23 of the instruction.
20706 Otherwise set it. */
20707 if (value < 0)
20708 insn &= ~(1 << 23);
20709 else
20710 insn |= 1 << 23;
20711
20712 /* Place the first four bits of the absolute value of the addend
20713 into the first 4 bits of the instruction, and the remaining
20714 four into bits 8 .. 11. */
20715 insn &= 0xfffff0f0;
20716 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
20717
20718 /* Update the instruction. */
20719 md_number_to_chars (buf, insn, INSN_SIZE);
20720 }
20721 break;
20722
20723 case BFD_RELOC_ARM_LDC_PC_G0:
20724 case BFD_RELOC_ARM_LDC_PC_G1:
20725 case BFD_RELOC_ARM_LDC_PC_G2:
20726 case BFD_RELOC_ARM_LDC_SB_G0:
20727 case BFD_RELOC_ARM_LDC_SB_G1:
20728 case BFD_RELOC_ARM_LDC_SB_G2:
20729 gas_assert (!fixP->fx_done);
20730 if (!seg->use_rela_p)
20731 {
20732 bfd_vma insn;
20733 bfd_vma addend_abs = abs (value);
20734
20735 /* Check that the absolute value of the addend is a multiple of
20736 four and, when divided by four, fits in 8 bits. */
20737 if (addend_abs & 0x3)
20738 as_bad_where (fixP->fx_file, fixP->fx_line,
20739 _("bad offset 0x%08lX (must be word-aligned)"),
20740 (unsigned long) addend_abs);
20741
20742 if ((addend_abs >> 2) > 0xff)
20743 as_bad_where (fixP->fx_file, fixP->fx_line,
20744 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
20745 (unsigned long) addend_abs);
20746
20747 /* Extract the instruction. */
20748 insn = md_chars_to_number (buf, INSN_SIZE);
20749
20750 /* If the addend is negative, clear bit 23 of the instruction.
20751 Otherwise set it. */
20752 if (value < 0)
20753 insn &= ~(1 << 23);
20754 else
20755 insn |= 1 << 23;
20756
20757 /* Place the addend (divided by four) into the first eight
20758 bits of the instruction. */
20759 insn &= 0xfffffff0;
20760 insn |= addend_abs >> 2;
20761
20762 /* Update the instruction. */
20763 md_number_to_chars (buf, insn, INSN_SIZE);
20764 }
20765 break;
20766
20767 case BFD_RELOC_ARM_V4BX:
20768 /* This will need to go in the object file. */
20769 fixP->fx_done = 0;
20770 break;
20771
20772 case BFD_RELOC_UNUSED:
20773 default:
20774 as_bad_where (fixP->fx_file, fixP->fx_line,
20775 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
20776 }
20777 }
20778
20779 /* Translate internal representation of relocation info to BFD target
20780 format. */
20781
20782 arelent *
20783 tc_gen_reloc (asection *section, fixS *fixp)
20784 {
20785 arelent * reloc;
20786 bfd_reloc_code_real_type code;
20787
20788 reloc = (arelent *) xmalloc (sizeof (arelent));
20789
20790 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
20791 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
20792 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
20793
20794 if (fixp->fx_pcrel)
20795 {
20796 if (section->use_rela_p)
20797 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
20798 else
20799 fixp->fx_offset = reloc->address;
20800 }
20801 reloc->addend = fixp->fx_offset;
20802
20803 switch (fixp->fx_r_type)
20804 {
20805 case BFD_RELOC_8:
20806 if (fixp->fx_pcrel)
20807 {
20808 code = BFD_RELOC_8_PCREL;
20809 break;
20810 }
20811
20812 case BFD_RELOC_16:
20813 if (fixp->fx_pcrel)
20814 {
20815 code = BFD_RELOC_16_PCREL;
20816 break;
20817 }
20818
20819 case BFD_RELOC_32:
20820 if (fixp->fx_pcrel)
20821 {
20822 code = BFD_RELOC_32_PCREL;
20823 break;
20824 }
20825
20826 case BFD_RELOC_ARM_MOVW:
20827 if (fixp->fx_pcrel)
20828 {
20829 code = BFD_RELOC_ARM_MOVW_PCREL;
20830 break;
20831 }
20832
20833 case BFD_RELOC_ARM_MOVT:
20834 if (fixp->fx_pcrel)
20835 {
20836 code = BFD_RELOC_ARM_MOVT_PCREL;
20837 break;
20838 }
20839
20840 case BFD_RELOC_ARM_THUMB_MOVW:
20841 if (fixp->fx_pcrel)
20842 {
20843 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
20844 break;
20845 }
20846
20847 case BFD_RELOC_ARM_THUMB_MOVT:
20848 if (fixp->fx_pcrel)
20849 {
20850 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
20851 break;
20852 }
20853
20854 case BFD_RELOC_NONE:
20855 case BFD_RELOC_ARM_PCREL_BRANCH:
20856 case BFD_RELOC_ARM_PCREL_BLX:
20857 case BFD_RELOC_RVA:
20858 case BFD_RELOC_THUMB_PCREL_BRANCH7:
20859 case BFD_RELOC_THUMB_PCREL_BRANCH9:
20860 case BFD_RELOC_THUMB_PCREL_BRANCH12:
20861 case BFD_RELOC_THUMB_PCREL_BRANCH20:
20862 case BFD_RELOC_THUMB_PCREL_BRANCH23:
20863 case BFD_RELOC_THUMB_PCREL_BRANCH25:
20864 case BFD_RELOC_VTABLE_ENTRY:
20865 case BFD_RELOC_VTABLE_INHERIT:
20866 #ifdef TE_PE
20867 case BFD_RELOC_32_SECREL:
20868 #endif
20869 code = fixp->fx_r_type;
20870 break;
20871
20872 case BFD_RELOC_THUMB_PCREL_BLX:
20873 #ifdef OBJ_ELF
20874 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
20875 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
20876 else
20877 #endif
20878 code = BFD_RELOC_THUMB_PCREL_BLX;
20879 break;
20880
20881 case BFD_RELOC_ARM_LITERAL:
20882 case BFD_RELOC_ARM_HWLITERAL:
20883 /* If this is called then the a literal has
20884 been referenced across a section boundary. */
20885 as_bad_where (fixp->fx_file, fixp->fx_line,
20886 _("literal referenced across section boundary"));
20887 return NULL;
20888
20889 #ifdef OBJ_ELF
20890 case BFD_RELOC_ARM_GOT32:
20891 case BFD_RELOC_ARM_GOTOFF:
20892 case BFD_RELOC_ARM_PLT32:
20893 case BFD_RELOC_ARM_TARGET1:
20894 case BFD_RELOC_ARM_ROSEGREL32:
20895 case BFD_RELOC_ARM_SBREL32:
20896 case BFD_RELOC_ARM_PREL31:
20897 case BFD_RELOC_ARM_TARGET2:
20898 case BFD_RELOC_ARM_TLS_LE32:
20899 case BFD_RELOC_ARM_TLS_LDO32:
20900 case BFD_RELOC_ARM_PCREL_CALL:
20901 case BFD_RELOC_ARM_PCREL_JUMP:
20902 case BFD_RELOC_ARM_ALU_PC_G0_NC:
20903 case BFD_RELOC_ARM_ALU_PC_G0:
20904 case BFD_RELOC_ARM_ALU_PC_G1_NC:
20905 case BFD_RELOC_ARM_ALU_PC_G1:
20906 case BFD_RELOC_ARM_ALU_PC_G2:
20907 case BFD_RELOC_ARM_LDR_PC_G0:
20908 case BFD_RELOC_ARM_LDR_PC_G1:
20909 case BFD_RELOC_ARM_LDR_PC_G2:
20910 case BFD_RELOC_ARM_LDRS_PC_G0:
20911 case BFD_RELOC_ARM_LDRS_PC_G1:
20912 case BFD_RELOC_ARM_LDRS_PC_G2:
20913 case BFD_RELOC_ARM_LDC_PC_G0:
20914 case BFD_RELOC_ARM_LDC_PC_G1:
20915 case BFD_RELOC_ARM_LDC_PC_G2:
20916 case BFD_RELOC_ARM_ALU_SB_G0_NC:
20917 case BFD_RELOC_ARM_ALU_SB_G0:
20918 case BFD_RELOC_ARM_ALU_SB_G1_NC:
20919 case BFD_RELOC_ARM_ALU_SB_G1:
20920 case BFD_RELOC_ARM_ALU_SB_G2:
20921 case BFD_RELOC_ARM_LDR_SB_G0:
20922 case BFD_RELOC_ARM_LDR_SB_G1:
20923 case BFD_RELOC_ARM_LDR_SB_G2:
20924 case BFD_RELOC_ARM_LDRS_SB_G0:
20925 case BFD_RELOC_ARM_LDRS_SB_G1:
20926 case BFD_RELOC_ARM_LDRS_SB_G2:
20927 case BFD_RELOC_ARM_LDC_SB_G0:
20928 case BFD_RELOC_ARM_LDC_SB_G1:
20929 case BFD_RELOC_ARM_LDC_SB_G2:
20930 case BFD_RELOC_ARM_V4BX:
20931 code = fixp->fx_r_type;
20932 break;
20933
20934 case BFD_RELOC_ARM_TLS_GD32:
20935 case BFD_RELOC_ARM_TLS_IE32:
20936 case BFD_RELOC_ARM_TLS_LDM32:
20937 /* BFD will include the symbol's address in the addend.
20938 But we don't want that, so subtract it out again here. */
20939 if (!S_IS_COMMON (fixp->fx_addsy))
20940 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
20941 code = fixp->fx_r_type;
20942 break;
20943 #endif
20944
20945 case BFD_RELOC_ARM_IMMEDIATE:
20946 as_bad_where (fixp->fx_file, fixp->fx_line,
20947 _("internal relocation (type: IMMEDIATE) not fixed up"));
20948 return NULL;
20949
20950 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
20951 as_bad_where (fixp->fx_file, fixp->fx_line,
20952 _("ADRL used for a symbol not defined in the same file"));
20953 return NULL;
20954
20955 case BFD_RELOC_ARM_OFFSET_IMM:
20956 if (section->use_rela_p)
20957 {
20958 code = fixp->fx_r_type;
20959 break;
20960 }
20961
20962 if (fixp->fx_addsy != NULL
20963 && !S_IS_DEFINED (fixp->fx_addsy)
20964 && S_IS_LOCAL (fixp->fx_addsy))
20965 {
20966 as_bad_where (fixp->fx_file, fixp->fx_line,
20967 _("undefined local label `%s'"),
20968 S_GET_NAME (fixp->fx_addsy));
20969 return NULL;
20970 }
20971
20972 as_bad_where (fixp->fx_file, fixp->fx_line,
20973 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
20974 return NULL;
20975
20976 default:
20977 {
20978 char * type;
20979
20980 switch (fixp->fx_r_type)
20981 {
20982 case BFD_RELOC_NONE: type = "NONE"; break;
20983 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
20984 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
20985 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
20986 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
20987 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
20988 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
20989 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
20990 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
20991 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
20992 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
20993 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
20994 default: type = _("<unknown>"); break;
20995 }
20996 as_bad_where (fixp->fx_file, fixp->fx_line,
20997 _("cannot represent %s relocation in this object file format"),
20998 type);
20999 return NULL;
21000 }
21001 }
21002
21003 #ifdef OBJ_ELF
21004 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
21005 && GOT_symbol
21006 && fixp->fx_addsy == GOT_symbol)
21007 {
21008 code = BFD_RELOC_ARM_GOTPC;
21009 reloc->addend = fixp->fx_offset = reloc->address;
21010 }
21011 #endif
21012
21013 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
21014
21015 if (reloc->howto == NULL)
21016 {
21017 as_bad_where (fixp->fx_file, fixp->fx_line,
21018 _("cannot represent %s relocation in this object file format"),
21019 bfd_get_reloc_code_name (code));
21020 return NULL;
21021 }
21022
21023 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
21024 vtable entry to be used in the relocation's section offset. */
21025 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
21026 reloc->address = fixp->fx_offset;
21027
21028 return reloc;
21029 }
21030
21031 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
21032
21033 void
21034 cons_fix_new_arm (fragS * frag,
21035 int where,
21036 int size,
21037 expressionS * exp)
21038 {
21039 bfd_reloc_code_real_type type;
21040 int pcrel = 0;
21041
21042 /* Pick a reloc.
21043 FIXME: @@ Should look at CPU word size. */
21044 switch (size)
21045 {
21046 case 1:
21047 type = BFD_RELOC_8;
21048 break;
21049 case 2:
21050 type = BFD_RELOC_16;
21051 break;
21052 case 4:
21053 default:
21054 type = BFD_RELOC_32;
21055 break;
21056 case 8:
21057 type = BFD_RELOC_64;
21058 break;
21059 }
21060
21061 #ifdef TE_PE
21062 if (exp->X_op == O_secrel)
21063 {
21064 exp->X_op = O_symbol;
21065 type = BFD_RELOC_32_SECREL;
21066 }
21067 #endif
21068
21069 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
21070 }
21071
21072 #if defined (OBJ_COFF)
21073 void
21074 arm_validate_fix (fixS * fixP)
21075 {
21076 /* If the destination of the branch is a defined symbol which does not have
21077 the THUMB_FUNC attribute, then we must be calling a function which has
21078 the (interfacearm) attribute. We look for the Thumb entry point to that
21079 function and change the branch to refer to that function instead. */
21080 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
21081 && fixP->fx_addsy != NULL
21082 && S_IS_DEFINED (fixP->fx_addsy)
21083 && ! THUMB_IS_FUNC (fixP->fx_addsy))
21084 {
21085 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
21086 }
21087 }
21088 #endif
21089
21090
21091 int
21092 arm_force_relocation (struct fix * fixp)
21093 {
21094 #if defined (OBJ_COFF) && defined (TE_PE)
21095 if (fixp->fx_r_type == BFD_RELOC_RVA)
21096 return 1;
21097 #endif
21098
21099 /* In case we have a call or a branch to a function in ARM ISA mode from
21100 a thumb function or vice-versa force the relocation. These relocations
21101 are cleared off for some cores that might have blx and simple transformations
21102 are possible. */
21103
21104 #ifdef OBJ_ELF
21105 switch (fixp->fx_r_type)
21106 {
21107 case BFD_RELOC_ARM_PCREL_JUMP:
21108 case BFD_RELOC_ARM_PCREL_CALL:
21109 case BFD_RELOC_THUMB_PCREL_BLX:
21110 if (THUMB_IS_FUNC (fixp->fx_addsy))
21111 return 1;
21112 break;
21113
21114 case BFD_RELOC_ARM_PCREL_BLX:
21115 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21116 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21117 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21118 if (ARM_IS_FUNC (fixp->fx_addsy))
21119 return 1;
21120 break;
21121
21122 default:
21123 break;
21124 }
21125 #endif
21126
21127 /* Resolve these relocations even if the symbol is extern or weak. */
21128 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
21129 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
21130 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
21131 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
21132 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
21133 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
21134 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
21135 return 0;
21136
21137 /* Always leave these relocations for the linker. */
21138 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21139 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21140 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
21141 return 1;
21142
21143 /* Always generate relocations against function symbols. */
21144 if (fixp->fx_r_type == BFD_RELOC_32
21145 && fixp->fx_addsy
21146 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
21147 return 1;
21148
21149 return generic_force_reloc (fixp);
21150 }
21151
21152 #if defined (OBJ_ELF) || defined (OBJ_COFF)
21153 /* Relocations against function names must be left unadjusted,
21154 so that the linker can use this information to generate interworking
21155 stubs. The MIPS version of this function
21156 also prevents relocations that are mips-16 specific, but I do not
21157 know why it does this.
21158
21159 FIXME:
21160 There is one other problem that ought to be addressed here, but
21161 which currently is not: Taking the address of a label (rather
21162 than a function) and then later jumping to that address. Such
21163 addresses also ought to have their bottom bit set (assuming that
21164 they reside in Thumb code), but at the moment they will not. */
21165
21166 bfd_boolean
21167 arm_fix_adjustable (fixS * fixP)
21168 {
21169 if (fixP->fx_addsy == NULL)
21170 return 1;
21171
21172 /* Preserve relocations against symbols with function type. */
21173 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
21174 return FALSE;
21175
21176 if (THUMB_IS_FUNC (fixP->fx_addsy)
21177 && fixP->fx_subsy == NULL)
21178 return FALSE;
21179
21180 /* We need the symbol name for the VTABLE entries. */
21181 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
21182 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
21183 return FALSE;
21184
21185 /* Don't allow symbols to be discarded on GOT related relocs. */
21186 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
21187 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
21188 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
21189 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
21190 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
21191 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
21192 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
21193 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
21194 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
21195 return FALSE;
21196
21197 /* Similarly for group relocations. */
21198 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21199 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21200 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
21201 return FALSE;
21202
21203 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
21204 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
21205 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
21206 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
21207 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
21208 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
21209 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
21210 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
21211 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
21212 return FALSE;
21213
21214 return TRUE;
21215 }
21216 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
21217
21218 #ifdef OBJ_ELF
21219
21220 const char *
21221 elf32_arm_target_format (void)
21222 {
21223 #ifdef TE_SYMBIAN
21224 return (target_big_endian
21225 ? "elf32-bigarm-symbian"
21226 : "elf32-littlearm-symbian");
21227 #elif defined (TE_VXWORKS)
21228 return (target_big_endian
21229 ? "elf32-bigarm-vxworks"
21230 : "elf32-littlearm-vxworks");
21231 #else
21232 if (target_big_endian)
21233 return "elf32-bigarm";
21234 else
21235 return "elf32-littlearm";
21236 #endif
21237 }
21238
21239 void
21240 armelf_frob_symbol (symbolS * symp,
21241 int * puntp)
21242 {
21243 elf_frob_symbol (symp, puntp);
21244 }
21245 #endif
21246
21247 /* MD interface: Finalization. */
21248
21249 void
21250 arm_cleanup (void)
21251 {
21252 literal_pool * pool;
21253
21254 /* Ensure that all the IT blocks are properly closed. */
21255 check_it_blocks_finished ();
21256
21257 for (pool = list_of_pools; pool; pool = pool->next)
21258 {
21259 /* Put it at the end of the relevant section. */
21260 subseg_set (pool->section, pool->sub_section);
21261 #ifdef OBJ_ELF
21262 arm_elf_change_section ();
21263 #endif
21264 s_ltorg (0);
21265 }
21266 }
21267
21268 #ifdef OBJ_ELF
21269 /* Remove any excess mapping symbols generated for alignment frags in
21270 SEC. We may have created a mapping symbol before a zero byte
21271 alignment; remove it if there's a mapping symbol after the
21272 alignment. */
21273 static void
21274 check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
21275 void *dummy ATTRIBUTE_UNUSED)
21276 {
21277 segment_info_type *seginfo = seg_info (sec);
21278 fragS *fragp;
21279
21280 if (seginfo == NULL || seginfo->frchainP == NULL)
21281 return;
21282
21283 for (fragp = seginfo->frchainP->frch_root;
21284 fragp != NULL;
21285 fragp = fragp->fr_next)
21286 {
21287 symbolS *sym = fragp->tc_frag_data.last_map;
21288 fragS *next = fragp->fr_next;
21289
21290 /* Variable-sized frags have been converted to fixed size by
21291 this point. But if this was variable-sized to start with,
21292 there will be a fixed-size frag after it. So don't handle
21293 next == NULL. */
21294 if (sym == NULL || next == NULL)
21295 continue;
21296
21297 if (S_GET_VALUE (sym) < next->fr_address)
21298 /* Not at the end of this frag. */
21299 continue;
21300 know (S_GET_VALUE (sym) == next->fr_address);
21301
21302 do
21303 {
21304 if (next->tc_frag_data.first_map != NULL)
21305 {
21306 /* Next frag starts with a mapping symbol. Discard this
21307 one. */
21308 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21309 break;
21310 }
21311
21312 if (next->fr_next == NULL)
21313 {
21314 /* This mapping symbol is at the end of the section. Discard
21315 it. */
21316 know (next->fr_fix == 0 && next->fr_var == 0);
21317 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21318 break;
21319 }
21320
21321 /* As long as we have empty frags without any mapping symbols,
21322 keep looking. */
21323 /* If the next frag is non-empty and does not start with a
21324 mapping symbol, then this mapping symbol is required. */
21325 if (next->fr_address != next->fr_next->fr_address)
21326 break;
21327
21328 next = next->fr_next;
21329 }
21330 while (next != NULL);
21331 }
21332 }
21333 #endif
21334
21335 /* Adjust the symbol table. This marks Thumb symbols as distinct from
21336 ARM ones. */
21337
21338 void
21339 arm_adjust_symtab (void)
21340 {
21341 #ifdef OBJ_COFF
21342 symbolS * sym;
21343
21344 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
21345 {
21346 if (ARM_IS_THUMB (sym))
21347 {
21348 if (THUMB_IS_FUNC (sym))
21349 {
21350 /* Mark the symbol as a Thumb function. */
21351 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
21352 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
21353 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
21354
21355 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
21356 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
21357 else
21358 as_bad (_("%s: unexpected function type: %d"),
21359 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
21360 }
21361 else switch (S_GET_STORAGE_CLASS (sym))
21362 {
21363 case C_EXT:
21364 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
21365 break;
21366 case C_STAT:
21367 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
21368 break;
21369 case C_LABEL:
21370 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
21371 break;
21372 default:
21373 /* Do nothing. */
21374 break;
21375 }
21376 }
21377
21378 if (ARM_IS_INTERWORK (sym))
21379 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
21380 }
21381 #endif
21382 #ifdef OBJ_ELF
21383 symbolS * sym;
21384 char bind;
21385
21386 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
21387 {
21388 if (ARM_IS_THUMB (sym))
21389 {
21390 elf_symbol_type * elf_sym;
21391
21392 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
21393 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
21394
21395 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
21396 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
21397 {
21398 /* If it's a .thumb_func, declare it as so,
21399 otherwise tag label as .code 16. */
21400 if (THUMB_IS_FUNC (sym))
21401 elf_sym->internal_elf_sym.st_info =
21402 ELF_ST_INFO (bind, STT_ARM_TFUNC);
21403 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
21404 elf_sym->internal_elf_sym.st_info =
21405 ELF_ST_INFO (bind, STT_ARM_16BIT);
21406 }
21407 }
21408 }
21409
21410 /* Remove any overlapping mapping symbols generated by alignment frags. */
21411 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
21412 #endif
21413 }
21414
21415 /* MD interface: Initialization. */
21416
21417 static void
21418 set_constant_flonums (void)
21419 {
21420 int i;
21421
21422 for (i = 0; i < NUM_FLOAT_VALS; i++)
21423 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
21424 abort ();
21425 }
21426
21427 /* Auto-select Thumb mode if it's the only available instruction set for the
21428 given architecture. */
21429
21430 static void
21431 autoselect_thumb_from_cpu_variant (void)
21432 {
21433 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
21434 opcode_select (16);
21435 }
21436
21437 void
21438 md_begin (void)
21439 {
21440 unsigned mach;
21441 unsigned int i;
21442
21443 if ( (arm_ops_hsh = hash_new ()) == NULL
21444 || (arm_cond_hsh = hash_new ()) == NULL
21445 || (arm_shift_hsh = hash_new ()) == NULL
21446 || (arm_psr_hsh = hash_new ()) == NULL
21447 || (arm_v7m_psr_hsh = hash_new ()) == NULL
21448 || (arm_reg_hsh = hash_new ()) == NULL
21449 || (arm_reloc_hsh = hash_new ()) == NULL
21450 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
21451 as_fatal (_("virtual memory exhausted"));
21452
21453 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
21454 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
21455 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
21456 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
21457 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
21458 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
21459 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
21460 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
21461 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
21462 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
21463 (void *) (v7m_psrs + i));
21464 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
21465 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
21466 for (i = 0;
21467 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
21468 i++)
21469 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
21470 (void *) (barrier_opt_names + i));
21471 #ifdef OBJ_ELF
21472 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
21473 hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i));
21474 #endif
21475
21476 set_constant_flonums ();
21477
21478 /* Set the cpu variant based on the command-line options. We prefer
21479 -mcpu= over -march= if both are set (as for GCC); and we prefer
21480 -mfpu= over any other way of setting the floating point unit.
21481 Use of legacy options with new options are faulted. */
21482 if (legacy_cpu)
21483 {
21484 if (mcpu_cpu_opt || march_cpu_opt)
21485 as_bad (_("use of old and new-style options to set CPU type"));
21486
21487 mcpu_cpu_opt = legacy_cpu;
21488 }
21489 else if (!mcpu_cpu_opt)
21490 mcpu_cpu_opt = march_cpu_opt;
21491
21492 if (legacy_fpu)
21493 {
21494 if (mfpu_opt)
21495 as_bad (_("use of old and new-style options to set FPU type"));
21496
21497 mfpu_opt = legacy_fpu;
21498 }
21499 else if (!mfpu_opt)
21500 {
21501 #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
21502 || defined (TE_NetBSD) || defined (TE_VXWORKS))
21503 /* Some environments specify a default FPU. If they don't, infer it
21504 from the processor. */
21505 if (mcpu_fpu_opt)
21506 mfpu_opt = mcpu_fpu_opt;
21507 else
21508 mfpu_opt = march_fpu_opt;
21509 #else
21510 mfpu_opt = &fpu_default;
21511 #endif
21512 }
21513
21514 if (!mfpu_opt)
21515 {
21516 if (mcpu_cpu_opt != NULL)
21517 mfpu_opt = &fpu_default;
21518 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
21519 mfpu_opt = &fpu_arch_vfp_v2;
21520 else
21521 mfpu_opt = &fpu_arch_fpa;
21522 }
21523
21524 #ifdef CPU_DEFAULT
21525 if (!mcpu_cpu_opt)
21526 {
21527 mcpu_cpu_opt = &cpu_default;
21528 selected_cpu = cpu_default;
21529 }
21530 #else
21531 if (mcpu_cpu_opt)
21532 selected_cpu = *mcpu_cpu_opt;
21533 else
21534 mcpu_cpu_opt = &arm_arch_any;
21535 #endif
21536
21537 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
21538
21539 autoselect_thumb_from_cpu_variant ();
21540
21541 arm_arch_used = thumb_arch_used = arm_arch_none;
21542
21543 #if defined OBJ_COFF || defined OBJ_ELF
21544 {
21545 unsigned int flags = 0;
21546
21547 #if defined OBJ_ELF
21548 flags = meabi_flags;
21549
21550 switch (meabi_flags)
21551 {
21552 case EF_ARM_EABI_UNKNOWN:
21553 #endif
21554 /* Set the flags in the private structure. */
21555 if (uses_apcs_26) flags |= F_APCS26;
21556 if (support_interwork) flags |= F_INTERWORK;
21557 if (uses_apcs_float) flags |= F_APCS_FLOAT;
21558 if (pic_code) flags |= F_PIC;
21559 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
21560 flags |= F_SOFT_FLOAT;
21561
21562 switch (mfloat_abi_opt)
21563 {
21564 case ARM_FLOAT_ABI_SOFT:
21565 case ARM_FLOAT_ABI_SOFTFP:
21566 flags |= F_SOFT_FLOAT;
21567 break;
21568
21569 case ARM_FLOAT_ABI_HARD:
21570 if (flags & F_SOFT_FLOAT)
21571 as_bad (_("hard-float conflicts with specified fpu"));
21572 break;
21573 }
21574
21575 /* Using pure-endian doubles (even if soft-float). */
21576 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
21577 flags |= F_VFP_FLOAT;
21578
21579 #if defined OBJ_ELF
21580 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
21581 flags |= EF_ARM_MAVERICK_FLOAT;
21582 break;
21583
21584 case EF_ARM_EABI_VER4:
21585 case EF_ARM_EABI_VER5:
21586 /* No additional flags to set. */
21587 break;
21588
21589 default:
21590 abort ();
21591 }
21592 #endif
21593 bfd_set_private_flags (stdoutput, flags);
21594
21595 /* We have run out flags in the COFF header to encode the
21596 status of ATPCS support, so instead we create a dummy,
21597 empty, debug section called .arm.atpcs. */
21598 if (atpcs)
21599 {
21600 asection * sec;
21601
21602 sec = bfd_make_section (stdoutput, ".arm.atpcs");
21603
21604 if (sec != NULL)
21605 {
21606 bfd_set_section_flags
21607 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
21608 bfd_set_section_size (stdoutput, sec, 0);
21609 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
21610 }
21611 }
21612 }
21613 #endif
21614
21615 /* Record the CPU type as well. */
21616 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
21617 mach = bfd_mach_arm_iWMMXt2;
21618 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
21619 mach = bfd_mach_arm_iWMMXt;
21620 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
21621 mach = bfd_mach_arm_XScale;
21622 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
21623 mach = bfd_mach_arm_ep9312;
21624 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
21625 mach = bfd_mach_arm_5TE;
21626 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
21627 {
21628 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
21629 mach = bfd_mach_arm_5T;
21630 else
21631 mach = bfd_mach_arm_5;
21632 }
21633 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
21634 {
21635 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
21636 mach = bfd_mach_arm_4T;
21637 else
21638 mach = bfd_mach_arm_4;
21639 }
21640 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
21641 mach = bfd_mach_arm_3M;
21642 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
21643 mach = bfd_mach_arm_3;
21644 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
21645 mach = bfd_mach_arm_2a;
21646 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
21647 mach = bfd_mach_arm_2;
21648 else
21649 mach = bfd_mach_arm_unknown;
21650
21651 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
21652 }
21653
21654 /* Command line processing. */
21655
21656 /* md_parse_option
21657 Invocation line includes a switch not recognized by the base assembler.
21658 See if it's a processor-specific option.
21659
21660 This routine is somewhat complicated by the need for backwards
21661 compatibility (since older releases of gcc can't be changed).
21662 The new options try to make the interface as compatible as
21663 possible with GCC.
21664
21665 New options (supported) are:
21666
21667 -mcpu=<cpu name> Assemble for selected processor
21668 -march=<architecture name> Assemble for selected architecture
21669 -mfpu=<fpu architecture> Assemble for selected FPU.
21670 -EB/-mbig-endian Big-endian
21671 -EL/-mlittle-endian Little-endian
21672 -k Generate PIC code
21673 -mthumb Start in Thumb mode
21674 -mthumb-interwork Code supports ARM/Thumb interworking
21675
21676 -m[no-]warn-deprecated Warn about deprecated features
21677
21678 For now we will also provide support for:
21679
21680 -mapcs-32 32-bit Program counter
21681 -mapcs-26 26-bit Program counter
21682 -macps-float Floats passed in FP registers
21683 -mapcs-reentrant Reentrant code
21684 -matpcs
21685 (sometime these will probably be replaced with -mapcs=<list of options>
21686 and -matpcs=<list of options>)
21687
21688 The remaining options are only supported for back-wards compatibility.
21689 Cpu variants, the arm part is optional:
21690 -m[arm]1 Currently not supported.
21691 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
21692 -m[arm]3 Arm 3 processor
21693 -m[arm]6[xx], Arm 6 processors
21694 -m[arm]7[xx][t][[d]m] Arm 7 processors
21695 -m[arm]8[10] Arm 8 processors
21696 -m[arm]9[20][tdmi] Arm 9 processors
21697 -mstrongarm[110[0]] StrongARM processors
21698 -mxscale XScale processors
21699 -m[arm]v[2345[t[e]]] Arm architectures
21700 -mall All (except the ARM1)
21701 FP variants:
21702 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
21703 -mfpe-old (No float load/store multiples)
21704 -mvfpxd VFP Single precision
21705 -mvfp All VFP
21706 -mno-fpu Disable all floating point instructions
21707
21708 The following CPU names are recognized:
21709 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
21710 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
21711 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
21712 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
21713 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
21714 arm10t arm10e, arm1020t, arm1020e, arm10200e,
21715 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
21716
21717 */
21718
21719 const char * md_shortopts = "m:k";
21720
21721 #ifdef ARM_BI_ENDIAN
21722 #define OPTION_EB (OPTION_MD_BASE + 0)
21723 #define OPTION_EL (OPTION_MD_BASE + 1)
21724 #else
21725 #if TARGET_BYTES_BIG_ENDIAN
21726 #define OPTION_EB (OPTION_MD_BASE + 0)
21727 #else
21728 #define OPTION_EL (OPTION_MD_BASE + 1)
21729 #endif
21730 #endif
21731 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
21732
21733 struct option md_longopts[] =
21734 {
21735 #ifdef OPTION_EB
21736 {"EB", no_argument, NULL, OPTION_EB},
21737 #endif
21738 #ifdef OPTION_EL
21739 {"EL", no_argument, NULL, OPTION_EL},
21740 #endif
21741 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
21742 {NULL, no_argument, NULL, 0}
21743 };
21744
21745 size_t md_longopts_size = sizeof (md_longopts);
21746
21747 struct arm_option_table
21748 {
21749 char *option; /* Option name to match. */
21750 char *help; /* Help information. */
21751 int *var; /* Variable to change. */
21752 int value; /* What to change it to. */
21753 char *deprecated; /* If non-null, print this message. */
21754 };
21755
21756 struct arm_option_table arm_opts[] =
21757 {
21758 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
21759 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
21760 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
21761 &support_interwork, 1, NULL},
21762 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
21763 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
21764 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
21765 1, NULL},
21766 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
21767 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
21768 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
21769 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
21770 NULL},
21771
21772 /* These are recognized by the assembler, but have no affect on code. */
21773 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
21774 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
21775
21776 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
21777 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
21778 &warn_on_deprecated, 0, NULL},
21779 {NULL, NULL, NULL, 0, NULL}
21780 };
21781
21782 struct arm_legacy_option_table
21783 {
21784 char *option; /* Option name to match. */
21785 const arm_feature_set **var; /* Variable to change. */
21786 const arm_feature_set value; /* What to change it to. */
21787 char *deprecated; /* If non-null, print this message. */
21788 };
21789
21790 const struct arm_legacy_option_table arm_legacy_opts[] =
21791 {
21792 /* DON'T add any new processors to this list -- we want the whole list
21793 to go away... Add them to the processors table instead. */
21794 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
21795 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
21796 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
21797 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
21798 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
21799 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
21800 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
21801 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
21802 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
21803 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
21804 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
21805 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
21806 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
21807 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
21808 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
21809 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
21810 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
21811 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
21812 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
21813 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
21814 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
21815 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
21816 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
21817 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
21818 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
21819 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
21820 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
21821 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
21822 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
21823 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
21824 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
21825 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
21826 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
21827 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
21828 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
21829 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
21830 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
21831 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
21832 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
21833 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
21834 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
21835 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
21836 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
21837 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
21838 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
21839 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
21840 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
21841 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
21842 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
21843 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
21844 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
21845 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
21846 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
21847 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
21848 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
21849 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
21850 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
21851 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
21852 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
21853 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
21854 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
21855 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
21856 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
21857 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
21858 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
21859 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
21860 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
21861 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
21862 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
21863 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
21864 N_("use -mcpu=strongarm110")},
21865 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
21866 N_("use -mcpu=strongarm1100")},
21867 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
21868 N_("use -mcpu=strongarm1110")},
21869 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
21870 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
21871 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
21872
21873 /* Architecture variants -- don't add any more to this list either. */
21874 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
21875 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
21876 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
21877 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
21878 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
21879 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
21880 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
21881 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
21882 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
21883 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
21884 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
21885 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
21886 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
21887 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
21888 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
21889 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
21890 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
21891 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
21892
21893 /* Floating point variants -- don't add any more to this list either. */
21894 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
21895 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
21896 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
21897 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
21898 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
21899
21900 {NULL, NULL, ARM_ARCH_NONE, NULL}
21901 };
21902
21903 struct arm_cpu_option_table
21904 {
21905 char *name;
21906 const arm_feature_set value;
21907 /* For some CPUs we assume an FPU unless the user explicitly sets
21908 -mfpu=... */
21909 const arm_feature_set default_fpu;
21910 /* The canonical name of the CPU, or NULL to use NAME converted to upper
21911 case. */
21912 const char *canonical_name;
21913 };
21914
21915 /* This list should, at a minimum, contain all the cpu names
21916 recognized by GCC. */
21917 static const struct arm_cpu_option_table arm_cpus[] =
21918 {
21919 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
21920 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
21921 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
21922 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
21923 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
21924 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21925 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21926 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21927 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21928 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21929 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21930 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
21931 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21932 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
21933 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21934 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
21935 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21936 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21937 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21938 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21939 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21940 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21941 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21942 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21943 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21944 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21945 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21946 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21947 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21948 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21949 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21950 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21951 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21952 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21953 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21954 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21955 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21956 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21957 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21958 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
21959 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21960 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21961 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21962 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21963 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21964 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21965 /* For V5 or later processors we default to using VFP; but the user
21966 should really set the FPU type explicitly. */
21967 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
21968 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21969 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
21970 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
21971 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
21972 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
21973 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
21974 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21975 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
21976 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
21977 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21978 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21979 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
21980 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
21981 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21982 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
21983 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
21984 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21985 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21986 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
21987 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
21988 {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL},
21989 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21990 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
21991 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
21992 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
21993 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
21994 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
21995 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
21996 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
21997 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
21998 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
21999 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
22000 {"cortex-a5", ARM_ARCH_V7A, FPU_NONE, NULL},
22001 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
22002 | FPU_NEON_EXT_V1),
22003 NULL},
22004 {"cortex-a9", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
22005 | FPU_NEON_EXT_V1),
22006 NULL},
22007 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
22008 {"cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16, NULL},
22009 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
22010 {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL},
22011 {"cortex-m0", ARM_ARCH_V6M, FPU_NONE, NULL},
22012 /* ??? XSCALE is really an architecture. */
22013 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
22014 /* ??? iwmmxt is not a processor. */
22015 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
22016 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
22017 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
22018 /* Maverick */
22019 {"ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
22020 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
22021 };
22022
22023 struct arm_arch_option_table
22024 {
22025 char *name;
22026 const arm_feature_set value;
22027 const arm_feature_set default_fpu;
22028 };
22029
22030 /* This list should, at a minimum, contain all the architecture names
22031 recognized by GCC. */
22032 static const struct arm_arch_option_table arm_archs[] =
22033 {
22034 {"all", ARM_ANY, FPU_ARCH_FPA},
22035 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
22036 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
22037 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
22038 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
22039 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
22040 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
22041 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
22042 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
22043 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
22044 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
22045 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
22046 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
22047 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
22048 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
22049 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
22050 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
22051 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
22052 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
22053 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
22054 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
22055 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
22056 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
22057 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
22058 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
22059 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
22060 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
22061 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
22062 /* The official spelling of the ARMv7 profile variants is the dashed form.
22063 Accept the non-dashed form for compatibility with old toolchains. */
22064 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22065 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22066 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
22067 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22068 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22069 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
22070 {"armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP},
22071 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
22072 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
22073 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
22074 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
22075 };
22076
22077 /* ISA extensions in the co-processor space. */
22078 struct arm_option_cpu_value_table
22079 {
22080 char *name;
22081 const arm_feature_set value;
22082 };
22083
22084 static const struct arm_option_cpu_value_table arm_extensions[] =
22085 {
22086 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
22087 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
22088 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
22089 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
22090 {NULL, ARM_ARCH_NONE}
22091 };
22092
22093 /* This list should, at a minimum, contain all the fpu names
22094 recognized by GCC. */
22095 static const struct arm_option_cpu_value_table arm_fpus[] =
22096 {
22097 {"softfpa", FPU_NONE},
22098 {"fpe", FPU_ARCH_FPE},
22099 {"fpe2", FPU_ARCH_FPE},
22100 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
22101 {"fpa", FPU_ARCH_FPA},
22102 {"fpa10", FPU_ARCH_FPA},
22103 {"fpa11", FPU_ARCH_FPA},
22104 {"arm7500fe", FPU_ARCH_FPA},
22105 {"softvfp", FPU_ARCH_VFP},
22106 {"softvfp+vfp", FPU_ARCH_VFP_V2},
22107 {"vfp", FPU_ARCH_VFP_V2},
22108 {"vfp9", FPU_ARCH_VFP_V2},
22109 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
22110 {"vfp10", FPU_ARCH_VFP_V2},
22111 {"vfp10-r0", FPU_ARCH_VFP_V1},
22112 {"vfpxd", FPU_ARCH_VFP_V1xD},
22113 {"vfpv2", FPU_ARCH_VFP_V2},
22114 {"vfpv3", FPU_ARCH_VFP_V3},
22115 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
22116 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
22117 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
22118 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
22119 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
22120 {"arm1020t", FPU_ARCH_VFP_V1},
22121 {"arm1020e", FPU_ARCH_VFP_V2},
22122 {"arm1136jfs", FPU_ARCH_VFP_V2},
22123 {"arm1136jf-s", FPU_ARCH_VFP_V2},
22124 {"maverick", FPU_ARCH_MAVERICK},
22125 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
22126 {"neon-fp16", FPU_ARCH_NEON_FP16},
22127 {"vfpv4", FPU_ARCH_VFP_V4},
22128 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
22129 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
22130 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
22131 {NULL, ARM_ARCH_NONE}
22132 };
22133
22134 struct arm_option_value_table
22135 {
22136 char *name;
22137 long value;
22138 };
22139
22140 static const struct arm_option_value_table arm_float_abis[] =
22141 {
22142 {"hard", ARM_FLOAT_ABI_HARD},
22143 {"softfp", ARM_FLOAT_ABI_SOFTFP},
22144 {"soft", ARM_FLOAT_ABI_SOFT},
22145 {NULL, 0}
22146 };
22147
22148 #ifdef OBJ_ELF
22149 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
22150 static const struct arm_option_value_table arm_eabis[] =
22151 {
22152 {"gnu", EF_ARM_EABI_UNKNOWN},
22153 {"4", EF_ARM_EABI_VER4},
22154 {"5", EF_ARM_EABI_VER5},
22155 {NULL, 0}
22156 };
22157 #endif
22158
22159 struct arm_long_option_table
22160 {
22161 char * option; /* Substring to match. */
22162 char * help; /* Help information. */
22163 int (* func) (char * subopt); /* Function to decode sub-option. */
22164 char * deprecated; /* If non-null, print this message. */
22165 };
22166
22167 static bfd_boolean
22168 arm_parse_extension (char * str, const arm_feature_set **opt_p)
22169 {
22170 arm_feature_set *ext_set = (arm_feature_set *)
22171 xmalloc (sizeof (arm_feature_set));
22172
22173 /* Copy the feature set, so that we can modify it. */
22174 *ext_set = **opt_p;
22175 *opt_p = ext_set;
22176
22177 while (str != NULL && *str != 0)
22178 {
22179 const struct arm_option_cpu_value_table * opt;
22180 char * ext;
22181 int optlen;
22182
22183 if (*str != '+')
22184 {
22185 as_bad (_("invalid architectural extension"));
22186 return FALSE;
22187 }
22188
22189 str++;
22190 ext = strchr (str, '+');
22191
22192 if (ext != NULL)
22193 optlen = ext - str;
22194 else
22195 optlen = strlen (str);
22196
22197 if (optlen == 0)
22198 {
22199 as_bad (_("missing architectural extension"));
22200 return FALSE;
22201 }
22202
22203 for (opt = arm_extensions; opt->name != NULL; opt++)
22204 if (strncmp (opt->name, str, optlen) == 0)
22205 {
22206 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
22207 break;
22208 }
22209
22210 if (opt->name == NULL)
22211 {
22212 as_bad (_("unknown architectural extension `%s'"), str);
22213 return FALSE;
22214 }
22215
22216 str = ext;
22217 };
22218
22219 return TRUE;
22220 }
22221
22222 static bfd_boolean
22223 arm_parse_cpu (char * str)
22224 {
22225 const struct arm_cpu_option_table * opt;
22226 char * ext = strchr (str, '+');
22227 int optlen;
22228
22229 if (ext != NULL)
22230 optlen = ext - str;
22231 else
22232 optlen = strlen (str);
22233
22234 if (optlen == 0)
22235 {
22236 as_bad (_("missing cpu name `%s'"), str);
22237 return FALSE;
22238 }
22239
22240 for (opt = arm_cpus; opt->name != NULL; opt++)
22241 if (strncmp (opt->name, str, optlen) == 0)
22242 {
22243 mcpu_cpu_opt = &opt->value;
22244 mcpu_fpu_opt = &opt->default_fpu;
22245 if (opt->canonical_name)
22246 strcpy (selected_cpu_name, opt->canonical_name);
22247 else
22248 {
22249 int i;
22250
22251 for (i = 0; i < optlen; i++)
22252 selected_cpu_name[i] = TOUPPER (opt->name[i]);
22253 selected_cpu_name[i] = 0;
22254 }
22255
22256 if (ext != NULL)
22257 return arm_parse_extension (ext, &mcpu_cpu_opt);
22258
22259 return TRUE;
22260 }
22261
22262 as_bad (_("unknown cpu `%s'"), str);
22263 return FALSE;
22264 }
22265
22266 static bfd_boolean
22267 arm_parse_arch (char * str)
22268 {
22269 const struct arm_arch_option_table *opt;
22270 char *ext = strchr (str, '+');
22271 int optlen;
22272
22273 if (ext != NULL)
22274 optlen = ext - str;
22275 else
22276 optlen = strlen (str);
22277
22278 if (optlen == 0)
22279 {
22280 as_bad (_("missing architecture name `%s'"), str);
22281 return FALSE;
22282 }
22283
22284 for (opt = arm_archs; opt->name != NULL; opt++)
22285 if (streq (opt->name, str))
22286 {
22287 march_cpu_opt = &opt->value;
22288 march_fpu_opt = &opt->default_fpu;
22289 strcpy (selected_cpu_name, opt->name);
22290
22291 if (ext != NULL)
22292 return arm_parse_extension (ext, &march_cpu_opt);
22293
22294 return TRUE;
22295 }
22296
22297 as_bad (_("unknown architecture `%s'\n"), str);
22298 return FALSE;
22299 }
22300
22301 static bfd_boolean
22302 arm_parse_fpu (char * str)
22303 {
22304 const struct arm_option_cpu_value_table * opt;
22305
22306 for (opt = arm_fpus; opt->name != NULL; opt++)
22307 if (streq (opt->name, str))
22308 {
22309 mfpu_opt = &opt->value;
22310 return TRUE;
22311 }
22312
22313 as_bad (_("unknown floating point format `%s'\n"), str);
22314 return FALSE;
22315 }
22316
22317 static bfd_boolean
22318 arm_parse_float_abi (char * str)
22319 {
22320 const struct arm_option_value_table * opt;
22321
22322 for (opt = arm_float_abis; opt->name != NULL; opt++)
22323 if (streq (opt->name, str))
22324 {
22325 mfloat_abi_opt = opt->value;
22326 return TRUE;
22327 }
22328
22329 as_bad (_("unknown floating point abi `%s'\n"), str);
22330 return FALSE;
22331 }
22332
22333 #ifdef OBJ_ELF
22334 static bfd_boolean
22335 arm_parse_eabi (char * str)
22336 {
22337 const struct arm_option_value_table *opt;
22338
22339 for (opt = arm_eabis; opt->name != NULL; opt++)
22340 if (streq (opt->name, str))
22341 {
22342 meabi_flags = opt->value;
22343 return TRUE;
22344 }
22345 as_bad (_("unknown EABI `%s'\n"), str);
22346 return FALSE;
22347 }
22348 #endif
22349
22350 static bfd_boolean
22351 arm_parse_it_mode (char * str)
22352 {
22353 bfd_boolean ret = TRUE;
22354
22355 if (streq ("arm", str))
22356 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
22357 else if (streq ("thumb", str))
22358 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
22359 else if (streq ("always", str))
22360 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
22361 else if (streq ("never", str))
22362 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
22363 else
22364 {
22365 as_bad (_("unknown implicit IT mode `%s', should be "\
22366 "arm, thumb, always, or never."), str);
22367 ret = FALSE;
22368 }
22369
22370 return ret;
22371 }
22372
22373 struct arm_long_option_table arm_long_opts[] =
22374 {
22375 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
22376 arm_parse_cpu, NULL},
22377 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
22378 arm_parse_arch, NULL},
22379 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
22380 arm_parse_fpu, NULL},
22381 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
22382 arm_parse_float_abi, NULL},
22383 #ifdef OBJ_ELF
22384 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
22385 arm_parse_eabi, NULL},
22386 #endif
22387 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
22388 arm_parse_it_mode, NULL},
22389 {NULL, NULL, 0, NULL}
22390 };
22391
22392 int
22393 md_parse_option (int c, char * arg)
22394 {
22395 struct arm_option_table *opt;
22396 const struct arm_legacy_option_table *fopt;
22397 struct arm_long_option_table *lopt;
22398
22399 switch (c)
22400 {
22401 #ifdef OPTION_EB
22402 case OPTION_EB:
22403 target_big_endian = 1;
22404 break;
22405 #endif
22406
22407 #ifdef OPTION_EL
22408 case OPTION_EL:
22409 target_big_endian = 0;
22410 break;
22411 #endif
22412
22413 case OPTION_FIX_V4BX:
22414 fix_v4bx = TRUE;
22415 break;
22416
22417 case 'a':
22418 /* Listing option. Just ignore these, we don't support additional
22419 ones. */
22420 return 0;
22421
22422 default:
22423 for (opt = arm_opts; opt->option != NULL; opt++)
22424 {
22425 if (c == opt->option[0]
22426 && ((arg == NULL && opt->option[1] == 0)
22427 || streq (arg, opt->option + 1)))
22428 {
22429 /* If the option is deprecated, tell the user. */
22430 if (warn_on_deprecated && opt->deprecated != NULL)
22431 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
22432 arg ? arg : "", _(opt->deprecated));
22433
22434 if (opt->var != NULL)
22435 *opt->var = opt->value;
22436
22437 return 1;
22438 }
22439 }
22440
22441 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
22442 {
22443 if (c == fopt->option[0]
22444 && ((arg == NULL && fopt->option[1] == 0)
22445 || streq (arg, fopt->option + 1)))
22446 {
22447 /* If the option is deprecated, tell the user. */
22448 if (warn_on_deprecated && fopt->deprecated != NULL)
22449 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
22450 arg ? arg : "", _(fopt->deprecated));
22451
22452 if (fopt->var != NULL)
22453 *fopt->var = &fopt->value;
22454
22455 return 1;
22456 }
22457 }
22458
22459 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
22460 {
22461 /* These options are expected to have an argument. */
22462 if (c == lopt->option[0]
22463 && arg != NULL
22464 && strncmp (arg, lopt->option + 1,
22465 strlen (lopt->option + 1)) == 0)
22466 {
22467 /* If the option is deprecated, tell the user. */
22468 if (warn_on_deprecated && lopt->deprecated != NULL)
22469 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
22470 _(lopt->deprecated));
22471
22472 /* Call the sup-option parser. */
22473 return lopt->func (arg + strlen (lopt->option) - 1);
22474 }
22475 }
22476
22477 return 0;
22478 }
22479
22480 return 1;
22481 }
22482
22483 void
22484 md_show_usage (FILE * fp)
22485 {
22486 struct arm_option_table *opt;
22487 struct arm_long_option_table *lopt;
22488
22489 fprintf (fp, _(" ARM-specific assembler options:\n"));
22490
22491 for (opt = arm_opts; opt->option != NULL; opt++)
22492 if (opt->help != NULL)
22493 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
22494
22495 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
22496 if (lopt->help != NULL)
22497 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
22498
22499 #ifdef OPTION_EB
22500 fprintf (fp, _("\
22501 -EB assemble code for a big-endian cpu\n"));
22502 #endif
22503
22504 #ifdef OPTION_EL
22505 fprintf (fp, _("\
22506 -EL assemble code for a little-endian cpu\n"));
22507 #endif
22508
22509 fprintf (fp, _("\
22510 --fix-v4bx Allow BX in ARMv4 code\n"));
22511 }
22512
22513
22514 #ifdef OBJ_ELF
22515 typedef struct
22516 {
22517 int val;
22518 arm_feature_set flags;
22519 } cpu_arch_ver_table;
22520
22521 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
22522 least features first. */
22523 static const cpu_arch_ver_table cpu_arch_ver[] =
22524 {
22525 {1, ARM_ARCH_V4},
22526 {2, ARM_ARCH_V4T},
22527 {3, ARM_ARCH_V5},
22528 {3, ARM_ARCH_V5T},
22529 {4, ARM_ARCH_V5TE},
22530 {5, ARM_ARCH_V5TEJ},
22531 {6, ARM_ARCH_V6},
22532 {7, ARM_ARCH_V6Z},
22533 {9, ARM_ARCH_V6K},
22534 {11, ARM_ARCH_V6M},
22535 {8, ARM_ARCH_V6T2},
22536 {10, ARM_ARCH_V7A},
22537 {10, ARM_ARCH_V7R},
22538 {10, ARM_ARCH_V7M},
22539 {0, ARM_ARCH_NONE}
22540 };
22541
22542 /* Set an attribute if it has not already been set by the user. */
22543 static void
22544 aeabi_set_attribute_int (int tag, int value)
22545 {
22546 if (tag < 1
22547 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
22548 || !attributes_set_explicitly[tag])
22549 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
22550 }
22551
22552 static void
22553 aeabi_set_attribute_string (int tag, const char *value)
22554 {
22555 if (tag < 1
22556 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
22557 || !attributes_set_explicitly[tag])
22558 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
22559 }
22560
22561 /* Set the public EABI object attributes. */
22562 static void
22563 aeabi_set_public_attributes (void)
22564 {
22565 int arch;
22566 arm_feature_set flags;
22567 arm_feature_set tmp;
22568 const cpu_arch_ver_table *p;
22569
22570 /* Choose the architecture based on the capabilities of the requested cpu
22571 (if any) and/or the instructions actually used. */
22572 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
22573 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
22574 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
22575 /*Allow the user to override the reported architecture. */
22576 if (object_arch)
22577 {
22578 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
22579 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
22580 }
22581
22582 tmp = flags;
22583 arch = 0;
22584 for (p = cpu_arch_ver; p->val; p++)
22585 {
22586 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
22587 {
22588 arch = p->val;
22589 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
22590 }
22591 }
22592
22593 /* The table lookup above finds the last architecture to contribute
22594 a new feature. Unfortunately, Tag13 is a subset of the union of
22595 v6T2 and v7-M, so it is never seen as contributing a new feature.
22596 We can not search for the last entry which is entirely used,
22597 because if no CPU is specified we build up only those flags
22598 actually used. Perhaps we should separate out the specified
22599 and implicit cases. Avoid taking this path for -march=all by
22600 checking for contradictory v7-A / v7-M features. */
22601 if (arch == 10
22602 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
22603 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
22604 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
22605 arch = 13;
22606
22607 /* Tag_CPU_name. */
22608 if (selected_cpu_name[0])
22609 {
22610 char *q;
22611
22612 q = selected_cpu_name;
22613 if (strncmp (q, "armv", 4) == 0)
22614 {
22615 int i;
22616
22617 q += 4;
22618 for (i = 0; q[i]; i++)
22619 q[i] = TOUPPER (q[i]);
22620 }
22621 aeabi_set_attribute_string (Tag_CPU_name, q);
22622 }
22623
22624 /* Tag_CPU_arch. */
22625 aeabi_set_attribute_int (Tag_CPU_arch, arch);
22626
22627 /* Tag_CPU_arch_profile. */
22628 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
22629 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A');
22630 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
22631 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R');
22632 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
22633 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M');
22634
22635 /* Tag_ARM_ISA_use. */
22636 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
22637 || arch == 0)
22638 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
22639
22640 /* Tag_THUMB_ISA_use. */
22641 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
22642 || arch == 0)
22643 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
22644 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
22645
22646 /* Tag_VFP_arch. */
22647 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
22648 aeabi_set_attribute_int (Tag_VFP_arch,
22649 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
22650 ? 5 : 6);
22651 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
22652 aeabi_set_attribute_int (Tag_VFP_arch, 3);
22653 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
22654 aeabi_set_attribute_int (Tag_VFP_arch, 4);
22655 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
22656 aeabi_set_attribute_int (Tag_VFP_arch, 2);
22657 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
22658 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
22659 aeabi_set_attribute_int (Tag_VFP_arch, 1);
22660
22661 /* Tag_WMMX_arch. */
22662 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
22663 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
22664 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
22665 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
22666
22667 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
22668 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
22669 aeabi_set_attribute_int
22670 (Tag_Advanced_SIMD_arch, (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma)
22671 ? 2 : 1));
22672
22673 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
22674 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16))
22675 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
22676 }
22677
22678 /* Add the default contents for the .ARM.attributes section. */
22679 void
22680 arm_md_end (void)
22681 {
22682 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
22683 return;
22684
22685 aeabi_set_public_attributes ();
22686 }
22687 #endif /* OBJ_ELF */
22688
22689
22690 /* Parse a .cpu directive. */
22691
22692 static void
22693 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
22694 {
22695 const struct arm_cpu_option_table *opt;
22696 char *name;
22697 char saved_char;
22698
22699 name = input_line_pointer;
22700 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
22701 input_line_pointer++;
22702 saved_char = *input_line_pointer;
22703 *input_line_pointer = 0;
22704
22705 /* Skip the first "all" entry. */
22706 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
22707 if (streq (opt->name, name))
22708 {
22709 mcpu_cpu_opt = &opt->value;
22710 selected_cpu = opt->value;
22711 if (opt->canonical_name)
22712 strcpy (selected_cpu_name, opt->canonical_name);
22713 else
22714 {
22715 int i;
22716 for (i = 0; opt->name[i]; i++)
22717 selected_cpu_name[i] = TOUPPER (opt->name[i]);
22718 selected_cpu_name[i] = 0;
22719 }
22720 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
22721 *input_line_pointer = saved_char;
22722 demand_empty_rest_of_line ();
22723 return;
22724 }
22725 as_bad (_("unknown cpu `%s'"), name);
22726 *input_line_pointer = saved_char;
22727 ignore_rest_of_line ();
22728 }
22729
22730
22731 /* Parse a .arch directive. */
22732
22733 static void
22734 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
22735 {
22736 const struct arm_arch_option_table *opt;
22737 char saved_char;
22738 char *name;
22739
22740 name = input_line_pointer;
22741 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
22742 input_line_pointer++;
22743 saved_char = *input_line_pointer;
22744 *input_line_pointer = 0;
22745
22746 /* Skip the first "all" entry. */
22747 for (opt = arm_archs + 1; opt->name != NULL; opt++)
22748 if (streq (opt->name, name))
22749 {
22750 mcpu_cpu_opt = &opt->value;
22751 selected_cpu = opt->value;
22752 strcpy (selected_cpu_name, opt->name);
22753 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
22754 *input_line_pointer = saved_char;
22755 demand_empty_rest_of_line ();
22756 return;
22757 }
22758
22759 as_bad (_("unknown architecture `%s'\n"), name);
22760 *input_line_pointer = saved_char;
22761 ignore_rest_of_line ();
22762 }
22763
22764
22765 /* Parse a .object_arch directive. */
22766
22767 static void
22768 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
22769 {
22770 const struct arm_arch_option_table *opt;
22771 char saved_char;
22772 char *name;
22773
22774 name = input_line_pointer;
22775 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
22776 input_line_pointer++;
22777 saved_char = *input_line_pointer;
22778 *input_line_pointer = 0;
22779
22780 /* Skip the first "all" entry. */
22781 for (opt = arm_archs + 1; opt->name != NULL; opt++)
22782 if (streq (opt->name, name))
22783 {
22784 object_arch = &opt->value;
22785 *input_line_pointer = saved_char;
22786 demand_empty_rest_of_line ();
22787 return;
22788 }
22789
22790 as_bad (_("unknown architecture `%s'\n"), name);
22791 *input_line_pointer = saved_char;
22792 ignore_rest_of_line ();
22793 }
22794
22795 /* Parse a .fpu directive. */
22796
22797 static void
22798 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
22799 {
22800 const struct arm_option_cpu_value_table *opt;
22801 char saved_char;
22802 char *name;
22803
22804 name = input_line_pointer;
22805 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
22806 input_line_pointer++;
22807 saved_char = *input_line_pointer;
22808 *input_line_pointer = 0;
22809
22810 for (opt = arm_fpus; opt->name != NULL; opt++)
22811 if (streq (opt->name, name))
22812 {
22813 mfpu_opt = &opt->value;
22814 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
22815 *input_line_pointer = saved_char;
22816 demand_empty_rest_of_line ();
22817 return;
22818 }
22819
22820 as_bad (_("unknown floating point format `%s'\n"), name);
22821 *input_line_pointer = saved_char;
22822 ignore_rest_of_line ();
22823 }
22824
22825 /* Copy symbol information. */
22826
22827 void
22828 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
22829 {
22830 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
22831 }
22832
22833 #ifdef OBJ_ELF
22834 /* Given a symbolic attribute NAME, return the proper integer value.
22835 Returns -1 if the attribute is not known. */
22836
22837 int
22838 arm_convert_symbolic_attribute (const char *name)
22839 {
22840 static const struct
22841 {
22842 const char * name;
22843 const int tag;
22844 }
22845 attribute_table[] =
22846 {
22847 /* When you modify this table you should
22848 also modify the list in doc/c-arm.texi. */
22849 #define T(tag) {#tag, tag}
22850 T (Tag_CPU_raw_name),
22851 T (Tag_CPU_name),
22852 T (Tag_CPU_arch),
22853 T (Tag_CPU_arch_profile),
22854 T (Tag_ARM_ISA_use),
22855 T (Tag_THUMB_ISA_use),
22856 T (Tag_VFP_arch),
22857 T (Tag_WMMX_arch),
22858 T (Tag_Advanced_SIMD_arch),
22859 T (Tag_PCS_config),
22860 T (Tag_ABI_PCS_R9_use),
22861 T (Tag_ABI_PCS_RW_data),
22862 T (Tag_ABI_PCS_RO_data),
22863 T (Tag_ABI_PCS_GOT_use),
22864 T (Tag_ABI_PCS_wchar_t),
22865 T (Tag_ABI_FP_rounding),
22866 T (Tag_ABI_FP_denormal),
22867 T (Tag_ABI_FP_exceptions),
22868 T (Tag_ABI_FP_user_exceptions),
22869 T (Tag_ABI_FP_number_model),
22870 T (Tag_ABI_align8_needed),
22871 T (Tag_ABI_align8_preserved),
22872 T (Tag_ABI_enum_size),
22873 T (Tag_ABI_HardFP_use),
22874 T (Tag_ABI_VFP_args),
22875 T (Tag_ABI_WMMX_args),
22876 T (Tag_ABI_optimization_goals),
22877 T (Tag_ABI_FP_optimization_goals),
22878 T (Tag_compatibility),
22879 T (Tag_CPU_unaligned_access),
22880 T (Tag_VFP_HP_extension),
22881 T (Tag_ABI_FP_16bit_format),
22882 T (Tag_nodefaults),
22883 T (Tag_also_compatible_with),
22884 T (Tag_conformance),
22885 T (Tag_T2EE_use),
22886 T (Tag_Virtualization_use),
22887 T (Tag_MPextension_use)
22888 #undef T
22889 };
22890 unsigned int i;
22891
22892 if (name == NULL)
22893 return -1;
22894
22895 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
22896 if (streq (name, attribute_table[i].name))
22897 return attribute_table[i].tag;
22898
22899 return -1;
22900 }
22901
22902
22903 /* Apply sym value for relocations only in the case that
22904 they are for local symbols and you have the respective
22905 architectural feature for blx and simple switches. */
22906 int
22907 arm_apply_sym_value (struct fix * fixP)
22908 {
22909 if (fixP->fx_addsy
22910 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
22911 && !S_IS_EXTERNAL (fixP->fx_addsy))
22912 {
22913 switch (fixP->fx_r_type)
22914 {
22915 case BFD_RELOC_ARM_PCREL_BLX:
22916 case BFD_RELOC_THUMB_PCREL_BRANCH23:
22917 if (ARM_IS_FUNC (fixP->fx_addsy))
22918 return 1;
22919 break;
22920
22921 case BFD_RELOC_ARM_PCREL_CALL:
22922 case BFD_RELOC_THUMB_PCREL_BLX:
22923 if (THUMB_IS_FUNC (fixP->fx_addsy))
22924 return 1;
22925 break;
22926
22927 default:
22928 break;
22929 }
22930
22931 }
22932 return 0;
22933 }
22934 #endif /* OBJ_ELF */
This page took 0.768436 seconds and 5 git commands to generate.