* bfd/bfd-in2.h (BFD_RELOC_ARM_HVC): New enum value.
[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, 2010
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 /* The code that was here used to select a default CPU depending on compiler
101 pre-defines which were only present when doing native builds, thus
102 changing gas' default behaviour depending upon the build host.
103
104 If you have a target that requires a default CPU option then the you
105 should define CPU_DEFAULT here. */
106 #endif
107
108 #ifndef FPU_DEFAULT
109 # ifdef TE_LINUX
110 # define FPU_DEFAULT FPU_ARCH_FPA
111 # elif defined (TE_NetBSD)
112 # ifdef OBJ_ELF
113 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
114 # else
115 /* Legacy a.out format. */
116 # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
117 # endif
118 # elif defined (TE_VXWORKS)
119 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
120 # else
121 /* For backwards compatibility, default to FPA. */
122 # define FPU_DEFAULT FPU_ARCH_FPA
123 # endif
124 #endif /* ifndef FPU_DEFAULT */
125
126 #define streq(a, b) (strcmp (a, b) == 0)
127
128 static arm_feature_set cpu_variant;
129 static arm_feature_set arm_arch_used;
130 static arm_feature_set thumb_arch_used;
131
132 /* Flags stored in private area of BFD structure. */
133 static int uses_apcs_26 = FALSE;
134 static int atpcs = FALSE;
135 static int support_interwork = FALSE;
136 static int uses_apcs_float = FALSE;
137 static int pic_code = FALSE;
138 static int fix_v4bx = FALSE;
139 /* Warn on using deprecated features. */
140 static int warn_on_deprecated = TRUE;
141
142
143 /* Variables that we set while parsing command-line options. Once all
144 options have been read we re-process these values to set the real
145 assembly flags. */
146 static const arm_feature_set *legacy_cpu = NULL;
147 static const arm_feature_set *legacy_fpu = NULL;
148
149 static const arm_feature_set *mcpu_cpu_opt = NULL;
150 static const arm_feature_set *mcpu_fpu_opt = NULL;
151 static const arm_feature_set *march_cpu_opt = NULL;
152 static const arm_feature_set *march_fpu_opt = NULL;
153 static const arm_feature_set *mfpu_opt = NULL;
154 static const arm_feature_set *object_arch = NULL;
155
156 /* Constants for known architecture features. */
157 static const arm_feature_set fpu_default = FPU_DEFAULT;
158 static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
159 static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
160 static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
161 static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
162 static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
163 static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
164 static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
165 static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
166
167 #ifdef CPU_DEFAULT
168 static const arm_feature_set cpu_default = CPU_DEFAULT;
169 #endif
170
171 static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
172 static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
173 static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
174 static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
175 static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
176 static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
177 static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
178 static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
179 static const arm_feature_set arm_ext_v4t_5 =
180 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
181 static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
182 static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
183 static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
184 static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
185 static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
186 static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
187 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
188 static const arm_feature_set arm_ext_v6m = ARM_FEATURE (ARM_EXT_V6M, 0);
189 static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
190 static const arm_feature_set arm_ext_v6_dsp = ARM_FEATURE (ARM_EXT_V6_DSP, 0);
191 static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
192 static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
193 static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
194 static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
195 static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
196 static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
197 static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
198 static const arm_feature_set arm_ext_m =
199 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M, 0);
200 static const arm_feature_set arm_ext_mp = ARM_FEATURE (ARM_EXT_MP, 0);
201 static const arm_feature_set arm_ext_sec = ARM_FEATURE (ARM_EXT_SEC, 0);
202 static const arm_feature_set arm_ext_os = ARM_FEATURE (ARM_EXT_OS, 0);
203 static const arm_feature_set arm_ext_adiv = ARM_FEATURE (ARM_EXT_ADIV, 0);
204 static const arm_feature_set arm_ext_virt = ARM_FEATURE (ARM_EXT_VIRT, 0);
205
206 static const arm_feature_set arm_arch_any = ARM_ANY;
207 static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
208 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
209 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
210
211 static const arm_feature_set arm_cext_iwmmxt2 =
212 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
213 static const arm_feature_set arm_cext_iwmmxt =
214 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
215 static const arm_feature_set arm_cext_xscale =
216 ARM_FEATURE (0, ARM_CEXT_XSCALE);
217 static const arm_feature_set arm_cext_maverick =
218 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
219 static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
220 static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
221 static const arm_feature_set fpu_vfp_ext_v1xd =
222 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
223 static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
224 static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
225 static const arm_feature_set fpu_vfp_ext_v3xd = ARM_FEATURE (0, FPU_VFP_EXT_V3xD);
226 static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
227 static const arm_feature_set fpu_vfp_ext_d32 =
228 ARM_FEATURE (0, FPU_VFP_EXT_D32);
229 static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
230 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
231 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
232 static const arm_feature_set fpu_vfp_fp16 = ARM_FEATURE (0, FPU_VFP_EXT_FP16);
233 static const arm_feature_set fpu_neon_ext_fma = ARM_FEATURE (0, FPU_NEON_EXT_FMA);
234 static const arm_feature_set fpu_vfp_ext_fma = ARM_FEATURE (0, FPU_VFP_EXT_FMA);
235
236 static int mfloat_abi_opt = -1;
237 /* Record user cpu selection for object attributes. */
238 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
239 /* Must be long enough to hold any of the names in arm_cpus. */
240 static char selected_cpu_name[16];
241 #ifdef OBJ_ELF
242 # ifdef EABI_DEFAULT
243 static int meabi_flags = EABI_DEFAULT;
244 # else
245 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
246 # endif
247
248 static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
249
250 bfd_boolean
251 arm_is_eabi (void)
252 {
253 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
254 }
255 #endif
256
257 #ifdef OBJ_ELF
258 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
259 symbolS * GOT_symbol;
260 #endif
261
262 /* 0: assemble for ARM,
263 1: assemble for Thumb,
264 2: assemble for Thumb even though target CPU does not support thumb
265 instructions. */
266 static int thumb_mode = 0;
267 /* A value distinct from the possible values for thumb_mode that we
268 can use to record whether thumb_mode has been copied into the
269 tc_frag_data field of a frag. */
270 #define MODE_RECORDED (1 << 4)
271
272 /* Specifies the intrinsic IT insn behavior mode. */
273 enum implicit_it_mode
274 {
275 IMPLICIT_IT_MODE_NEVER = 0x00,
276 IMPLICIT_IT_MODE_ARM = 0x01,
277 IMPLICIT_IT_MODE_THUMB = 0x02,
278 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
279 };
280 static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
281
282 /* If unified_syntax is true, we are processing the new unified
283 ARM/Thumb syntax. Important differences from the old ARM mode:
284
285 - Immediate operands do not require a # prefix.
286 - Conditional affixes always appear at the end of the
287 instruction. (For backward compatibility, those instructions
288 that formerly had them in the middle, continue to accept them
289 there.)
290 - The IT instruction may appear, and if it does is validated
291 against subsequent conditional affixes. It does not generate
292 machine code.
293
294 Important differences from the old Thumb mode:
295
296 - Immediate operands do not require a # prefix.
297 - Most of the V6T2 instructions are only available in unified mode.
298 - The .N and .W suffixes are recognized and honored (it is an error
299 if they cannot be honored).
300 - All instructions set the flags if and only if they have an 's' affix.
301 - Conditional affixes may be used. They are validated against
302 preceding IT instructions. Unlike ARM mode, you cannot use a
303 conditional affix except in the scope of an IT instruction. */
304
305 static bfd_boolean unified_syntax = FALSE;
306
307 enum neon_el_type
308 {
309 NT_invtype,
310 NT_untyped,
311 NT_integer,
312 NT_float,
313 NT_poly,
314 NT_signed,
315 NT_unsigned
316 };
317
318 struct neon_type_el
319 {
320 enum neon_el_type type;
321 unsigned size;
322 };
323
324 #define NEON_MAX_TYPE_ELS 4
325
326 struct neon_type
327 {
328 struct neon_type_el el[NEON_MAX_TYPE_ELS];
329 unsigned elems;
330 };
331
332 enum it_instruction_type
333 {
334 OUTSIDE_IT_INSN,
335 INSIDE_IT_INSN,
336 INSIDE_IT_LAST_INSN,
337 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
338 if inside, should be the last one. */
339 NEUTRAL_IT_INSN, /* This could be either inside or outside,
340 i.e. BKPT and NOP. */
341 IT_INSN /* The IT insn has been parsed. */
342 };
343
344 struct arm_it
345 {
346 const char * error;
347 unsigned long instruction;
348 int size;
349 int size_req;
350 int cond;
351 /* "uncond_value" is set to the value in place of the conditional field in
352 unconditional versions of the instruction, or -1 if nothing is
353 appropriate. */
354 int uncond_value;
355 struct neon_type vectype;
356 /* This does not indicate an actual NEON instruction, only that
357 the mnemonic accepts neon-style type suffixes. */
358 int is_neon;
359 /* Set to the opcode if the instruction needs relaxation.
360 Zero if the instruction is not relaxed. */
361 unsigned long relax;
362 struct
363 {
364 bfd_reloc_code_real_type type;
365 expressionS exp;
366 int pc_rel;
367 } reloc;
368
369 enum it_instruction_type it_insn_type;
370
371 struct
372 {
373 unsigned reg;
374 signed int imm;
375 struct neon_type_el vectype;
376 unsigned present : 1; /* Operand present. */
377 unsigned isreg : 1; /* Operand was a register. */
378 unsigned immisreg : 1; /* .imm field is a second register. */
379 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
380 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
381 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
382 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
383 instructions. This allows us to disambiguate ARM <-> vector insns. */
384 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
385 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
386 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
387 unsigned issingle : 1; /* Operand is VFP single-precision register. */
388 unsigned hasreloc : 1; /* Operand has relocation suffix. */
389 unsigned writeback : 1; /* Operand has trailing ! */
390 unsigned preind : 1; /* Preindexed address. */
391 unsigned postind : 1; /* Postindexed address. */
392 unsigned negative : 1; /* Index register was negated. */
393 unsigned shifted : 1; /* Shift applied to operation. */
394 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
395 } operands[6];
396 };
397
398 static struct arm_it inst;
399
400 #define NUM_FLOAT_VALS 8
401
402 const char * fp_const[] =
403 {
404 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
405 };
406
407 /* Number of littlenums required to hold an extended precision number. */
408 #define MAX_LITTLENUMS 6
409
410 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
411
412 #define FAIL (-1)
413 #define SUCCESS (0)
414
415 #define SUFF_S 1
416 #define SUFF_D 2
417 #define SUFF_E 3
418 #define SUFF_P 4
419
420 #define CP_T_X 0x00008000
421 #define CP_T_Y 0x00400000
422
423 #define CONDS_BIT 0x00100000
424 #define LOAD_BIT 0x00100000
425
426 #define DOUBLE_LOAD_FLAG 0x00000001
427
428 struct asm_cond
429 {
430 const char * template_name;
431 unsigned long value;
432 };
433
434 #define COND_ALWAYS 0xE
435
436 struct asm_psr
437 {
438 const char * template_name;
439 unsigned long field;
440 };
441
442 struct asm_barrier_opt
443 {
444 const char * template_name;
445 unsigned long value;
446 };
447
448 /* The bit that distinguishes CPSR and SPSR. */
449 #define SPSR_BIT (1 << 22)
450
451 /* The individual PSR flag bits. */
452 #define PSR_c (1 << 16)
453 #define PSR_x (1 << 17)
454 #define PSR_s (1 << 18)
455 #define PSR_f (1 << 19)
456
457 struct reloc_entry
458 {
459 char * name;
460 bfd_reloc_code_real_type reloc;
461 };
462
463 enum vfp_reg_pos
464 {
465 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
466 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
467 };
468
469 enum vfp_ldstm_type
470 {
471 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
472 };
473
474 /* Bits for DEFINED field in neon_typed_alias. */
475 #define NTA_HASTYPE 1
476 #define NTA_HASINDEX 2
477
478 struct neon_typed_alias
479 {
480 unsigned char defined;
481 unsigned char index;
482 struct neon_type_el eltype;
483 };
484
485 /* ARM register categories. This includes coprocessor numbers and various
486 architecture extensions' registers. */
487 enum arm_reg_type
488 {
489 REG_TYPE_RN,
490 REG_TYPE_CP,
491 REG_TYPE_CN,
492 REG_TYPE_FN,
493 REG_TYPE_VFS,
494 REG_TYPE_VFD,
495 REG_TYPE_NQ,
496 REG_TYPE_VFSD,
497 REG_TYPE_NDQ,
498 REG_TYPE_NSDQ,
499 REG_TYPE_VFC,
500 REG_TYPE_MVF,
501 REG_TYPE_MVD,
502 REG_TYPE_MVFX,
503 REG_TYPE_MVDX,
504 REG_TYPE_MVAX,
505 REG_TYPE_DSPSC,
506 REG_TYPE_MMXWR,
507 REG_TYPE_MMXWC,
508 REG_TYPE_MMXWCG,
509 REG_TYPE_XSCALE,
510 REG_TYPE_RNB
511 };
512
513 /* Structure for a hash table entry for a register.
514 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
515 information which states whether a vector type or index is specified (for a
516 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
517 struct reg_entry
518 {
519 const char * name;
520 unsigned int number;
521 unsigned char type;
522 unsigned char builtin;
523 struct neon_typed_alias * neon;
524 };
525
526 /* Diagnostics used when we don't get a register of the expected type. */
527 const char * const reg_expected_msgs[] =
528 {
529 N_("ARM register expected"),
530 N_("bad or missing co-processor number"),
531 N_("co-processor register expected"),
532 N_("FPA register expected"),
533 N_("VFP single precision register expected"),
534 N_("VFP/Neon double precision register expected"),
535 N_("Neon quad precision register expected"),
536 N_("VFP single or double precision register expected"),
537 N_("Neon double or quad precision register expected"),
538 N_("VFP single, double or Neon quad precision register expected"),
539 N_("VFP system register expected"),
540 N_("Maverick MVF register expected"),
541 N_("Maverick MVD register expected"),
542 N_("Maverick MVFX register expected"),
543 N_("Maverick MVDX register expected"),
544 N_("Maverick MVAX register expected"),
545 N_("Maverick DSPSC register expected"),
546 N_("iWMMXt data register expected"),
547 N_("iWMMXt control register expected"),
548 N_("iWMMXt scalar register expected"),
549 N_("XScale accumulator register expected"),
550 };
551
552 /* Some well known registers that we refer to directly elsewhere. */
553 #define REG_SP 13
554 #define REG_LR 14
555 #define REG_PC 15
556
557 /* ARM instructions take 4bytes in the object file, Thumb instructions
558 take 2: */
559 #define INSN_SIZE 4
560
561 struct asm_opcode
562 {
563 /* Basic string to match. */
564 const char * template_name;
565
566 /* Parameters to instruction. */
567 unsigned int operands[8];
568
569 /* Conditional tag - see opcode_lookup. */
570 unsigned int tag : 4;
571
572 /* Basic instruction code. */
573 unsigned int avalue : 28;
574
575 /* Thumb-format instruction code. */
576 unsigned int tvalue;
577
578 /* Which architecture variant provides this instruction. */
579 const arm_feature_set * avariant;
580 const arm_feature_set * tvariant;
581
582 /* Function to call to encode instruction in ARM format. */
583 void (* aencode) (void);
584
585 /* Function to call to encode instruction in Thumb format. */
586 void (* tencode) (void);
587 };
588
589 /* Defines for various bits that we will want to toggle. */
590 #define INST_IMMEDIATE 0x02000000
591 #define OFFSET_REG 0x02000000
592 #define HWOFFSET_IMM 0x00400000
593 #define SHIFT_BY_REG 0x00000010
594 #define PRE_INDEX 0x01000000
595 #define INDEX_UP 0x00800000
596 #define WRITE_BACK 0x00200000
597 #define LDM_TYPE_2_OR_3 0x00400000
598 #define CPSI_MMOD 0x00020000
599
600 #define LITERAL_MASK 0xf000f000
601 #define OPCODE_MASK 0xfe1fffff
602 #define V4_STR_BIT 0x00000020
603
604 #define T2_SUBS_PC_LR 0xf3de8f00
605
606 #define DATA_OP_SHIFT 21
607
608 #define T2_OPCODE_MASK 0xfe1fffff
609 #define T2_DATA_OP_SHIFT 21
610
611 /* Codes to distinguish the arithmetic instructions. */
612 #define OPCODE_AND 0
613 #define OPCODE_EOR 1
614 #define OPCODE_SUB 2
615 #define OPCODE_RSB 3
616 #define OPCODE_ADD 4
617 #define OPCODE_ADC 5
618 #define OPCODE_SBC 6
619 #define OPCODE_RSC 7
620 #define OPCODE_TST 8
621 #define OPCODE_TEQ 9
622 #define OPCODE_CMP 10
623 #define OPCODE_CMN 11
624 #define OPCODE_ORR 12
625 #define OPCODE_MOV 13
626 #define OPCODE_BIC 14
627 #define OPCODE_MVN 15
628
629 #define T2_OPCODE_AND 0
630 #define T2_OPCODE_BIC 1
631 #define T2_OPCODE_ORR 2
632 #define T2_OPCODE_ORN 3
633 #define T2_OPCODE_EOR 4
634 #define T2_OPCODE_ADD 8
635 #define T2_OPCODE_ADC 10
636 #define T2_OPCODE_SBC 11
637 #define T2_OPCODE_SUB 13
638 #define T2_OPCODE_RSB 14
639
640 #define T_OPCODE_MUL 0x4340
641 #define T_OPCODE_TST 0x4200
642 #define T_OPCODE_CMN 0x42c0
643 #define T_OPCODE_NEG 0x4240
644 #define T_OPCODE_MVN 0x43c0
645
646 #define T_OPCODE_ADD_R3 0x1800
647 #define T_OPCODE_SUB_R3 0x1a00
648 #define T_OPCODE_ADD_HI 0x4400
649 #define T_OPCODE_ADD_ST 0xb000
650 #define T_OPCODE_SUB_ST 0xb080
651 #define T_OPCODE_ADD_SP 0xa800
652 #define T_OPCODE_ADD_PC 0xa000
653 #define T_OPCODE_ADD_I8 0x3000
654 #define T_OPCODE_SUB_I8 0x3800
655 #define T_OPCODE_ADD_I3 0x1c00
656 #define T_OPCODE_SUB_I3 0x1e00
657
658 #define T_OPCODE_ASR_R 0x4100
659 #define T_OPCODE_LSL_R 0x4080
660 #define T_OPCODE_LSR_R 0x40c0
661 #define T_OPCODE_ROR_R 0x41c0
662 #define T_OPCODE_ASR_I 0x1000
663 #define T_OPCODE_LSL_I 0x0000
664 #define T_OPCODE_LSR_I 0x0800
665
666 #define T_OPCODE_MOV_I8 0x2000
667 #define T_OPCODE_CMP_I8 0x2800
668 #define T_OPCODE_CMP_LR 0x4280
669 #define T_OPCODE_MOV_HR 0x4600
670 #define T_OPCODE_CMP_HR 0x4500
671
672 #define T_OPCODE_LDR_PC 0x4800
673 #define T_OPCODE_LDR_SP 0x9800
674 #define T_OPCODE_STR_SP 0x9000
675 #define T_OPCODE_LDR_IW 0x6800
676 #define T_OPCODE_STR_IW 0x6000
677 #define T_OPCODE_LDR_IH 0x8800
678 #define T_OPCODE_STR_IH 0x8000
679 #define T_OPCODE_LDR_IB 0x7800
680 #define T_OPCODE_STR_IB 0x7000
681 #define T_OPCODE_LDR_RW 0x5800
682 #define T_OPCODE_STR_RW 0x5000
683 #define T_OPCODE_LDR_RH 0x5a00
684 #define T_OPCODE_STR_RH 0x5200
685 #define T_OPCODE_LDR_RB 0x5c00
686 #define T_OPCODE_STR_RB 0x5400
687
688 #define T_OPCODE_PUSH 0xb400
689 #define T_OPCODE_POP 0xbc00
690
691 #define T_OPCODE_BRANCH 0xe000
692
693 #define THUMB_SIZE 2 /* Size of thumb instruction. */
694 #define THUMB_PP_PC_LR 0x0100
695 #define THUMB_LOAD_BIT 0x0800
696 #define THUMB2_LOAD_BIT 0x00100000
697
698 #define BAD_ARGS _("bad arguments to instruction")
699 #define BAD_SP _("r13 not allowed here")
700 #define BAD_PC _("r15 not allowed here")
701 #define BAD_COND _("instruction cannot be conditional")
702 #define BAD_OVERLAP _("registers may not be the same")
703 #define BAD_HIREG _("lo register required")
704 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
705 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
706 #define BAD_BRANCH _("branch must be last instruction in IT block")
707 #define BAD_NOT_IT _("instruction not allowed in IT block")
708 #define BAD_FPU _("selected FPU does not support instruction")
709 #define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
710 #define BAD_IT_COND _("incorrect condition in IT block")
711 #define BAD_IT_IT _("IT falling in the range of a previous IT block")
712 #define MISSING_FNSTART _("missing .fnstart before unwinding directive")
713 #define BAD_PC_ADDRESSING \
714 _("cannot use register index with PC-relative addressing")
715 #define BAD_PC_WRITEBACK \
716 _("cannot use writeback with PC-relative addressing")
717
718 static struct hash_control * arm_ops_hsh;
719 static struct hash_control * arm_cond_hsh;
720 static struct hash_control * arm_shift_hsh;
721 static struct hash_control * arm_psr_hsh;
722 static struct hash_control * arm_v7m_psr_hsh;
723 static struct hash_control * arm_reg_hsh;
724 static struct hash_control * arm_reloc_hsh;
725 static struct hash_control * arm_barrier_opt_hsh;
726
727 /* Stuff needed to resolve the label ambiguity
728 As:
729 ...
730 label: <insn>
731 may differ from:
732 ...
733 label:
734 <insn> */
735
736 symbolS * last_label_seen;
737 static int label_is_thumb_function_name = FALSE;
738
739 /* Literal pool structure. Held on a per-section
740 and per-sub-section basis. */
741
742 #define MAX_LITERAL_POOL_SIZE 1024
743 typedef struct literal_pool
744 {
745 expressionS literals [MAX_LITERAL_POOL_SIZE];
746 unsigned int next_free_entry;
747 unsigned int id;
748 symbolS * symbol;
749 segT section;
750 subsegT sub_section;
751 struct literal_pool * next;
752 } literal_pool;
753
754 /* Pointer to a linked list of literal pools. */
755 literal_pool * list_of_pools = NULL;
756
757 #ifdef OBJ_ELF
758 # define now_it seg_info (now_seg)->tc_segment_info_data.current_it
759 #else
760 static struct current_it now_it;
761 #endif
762
763 static inline int
764 now_it_compatible (int cond)
765 {
766 return (cond & ~1) == (now_it.cc & ~1);
767 }
768
769 static inline int
770 conditional_insn (void)
771 {
772 return inst.cond != COND_ALWAYS;
773 }
774
775 static int in_it_block (void);
776
777 static int handle_it_state (void);
778
779 static void force_automatic_it_block_close (void);
780
781 static void it_fsm_post_encode (void);
782
783 #define set_it_insn_type(type) \
784 do \
785 { \
786 inst.it_insn_type = type; \
787 if (handle_it_state () == FAIL) \
788 return; \
789 } \
790 while (0)
791
792 #define set_it_insn_type_nonvoid(type, failret) \
793 do \
794 { \
795 inst.it_insn_type = type; \
796 if (handle_it_state () == FAIL) \
797 return failret; \
798 } \
799 while(0)
800
801 #define set_it_insn_type_last() \
802 do \
803 { \
804 if (inst.cond == COND_ALWAYS) \
805 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
806 else \
807 set_it_insn_type (INSIDE_IT_LAST_INSN); \
808 } \
809 while (0)
810
811 /* Pure syntax. */
812
813 /* This array holds the chars that always start a comment. If the
814 pre-processor is disabled, these aren't very useful. */
815 const char comment_chars[] = "@";
816
817 /* This array holds the chars that only start a comment at the beginning of
818 a line. If the line seems to have the form '# 123 filename'
819 .line and .file directives will appear in the pre-processed output. */
820 /* Note that input_file.c hand checks for '#' at the beginning of the
821 first line of the input file. This is because the compiler outputs
822 #NO_APP at the beginning of its output. */
823 /* Also note that comments like this one will always work. */
824 const char line_comment_chars[] = "#";
825
826 const char line_separator_chars[] = ";";
827
828 /* Chars that can be used to separate mant
829 from exp in floating point numbers. */
830 const char EXP_CHARS[] = "eE";
831
832 /* Chars that mean this number is a floating point constant. */
833 /* As in 0f12.456 */
834 /* or 0d1.2345e12 */
835
836 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
837
838 /* Prefix characters that indicate the start of an immediate
839 value. */
840 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
841
842 /* Separator character handling. */
843
844 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
845
846 static inline int
847 skip_past_char (char ** str, char c)
848 {
849 if (**str == c)
850 {
851 (*str)++;
852 return SUCCESS;
853 }
854 else
855 return FAIL;
856 }
857
858 #define skip_past_comma(str) skip_past_char (str, ',')
859
860 /* Arithmetic expressions (possibly involving symbols). */
861
862 /* Return TRUE if anything in the expression is a bignum. */
863
864 static int
865 walk_no_bignums (symbolS * sp)
866 {
867 if (symbol_get_value_expression (sp)->X_op == O_big)
868 return 1;
869
870 if (symbol_get_value_expression (sp)->X_add_symbol)
871 {
872 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
873 || (symbol_get_value_expression (sp)->X_op_symbol
874 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
875 }
876
877 return 0;
878 }
879
880 static int in_my_get_expression = 0;
881
882 /* Third argument to my_get_expression. */
883 #define GE_NO_PREFIX 0
884 #define GE_IMM_PREFIX 1
885 #define GE_OPT_PREFIX 2
886 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
887 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
888 #define GE_OPT_PREFIX_BIG 3
889
890 static int
891 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
892 {
893 char * save_in;
894 segT seg;
895
896 /* In unified syntax, all prefixes are optional. */
897 if (unified_syntax)
898 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
899 : GE_OPT_PREFIX;
900
901 switch (prefix_mode)
902 {
903 case GE_NO_PREFIX: break;
904 case GE_IMM_PREFIX:
905 if (!is_immediate_prefix (**str))
906 {
907 inst.error = _("immediate expression requires a # prefix");
908 return FAIL;
909 }
910 (*str)++;
911 break;
912 case GE_OPT_PREFIX:
913 case GE_OPT_PREFIX_BIG:
914 if (is_immediate_prefix (**str))
915 (*str)++;
916 break;
917 default: abort ();
918 }
919
920 memset (ep, 0, sizeof (expressionS));
921
922 save_in = input_line_pointer;
923 input_line_pointer = *str;
924 in_my_get_expression = 1;
925 seg = expression (ep);
926 in_my_get_expression = 0;
927
928 if (ep->X_op == O_illegal || ep->X_op == O_absent)
929 {
930 /* We found a bad or missing expression in md_operand(). */
931 *str = input_line_pointer;
932 input_line_pointer = save_in;
933 if (inst.error == NULL)
934 inst.error = (ep->X_op == O_absent
935 ? _("missing expression") :_("bad expression"));
936 return 1;
937 }
938
939 #ifdef OBJ_AOUT
940 if (seg != absolute_section
941 && seg != text_section
942 && seg != data_section
943 && seg != bss_section
944 && seg != undefined_section)
945 {
946 inst.error = _("bad segment");
947 *str = input_line_pointer;
948 input_line_pointer = save_in;
949 return 1;
950 }
951 #else
952 (void) seg;
953 #endif
954
955 /* Get rid of any bignums now, so that we don't generate an error for which
956 we can't establish a line number later on. Big numbers are never valid
957 in instructions, which is where this routine is always called. */
958 if (prefix_mode != GE_OPT_PREFIX_BIG
959 && (ep->X_op == O_big
960 || (ep->X_add_symbol
961 && (walk_no_bignums (ep->X_add_symbol)
962 || (ep->X_op_symbol
963 && walk_no_bignums (ep->X_op_symbol))))))
964 {
965 inst.error = _("invalid constant");
966 *str = input_line_pointer;
967 input_line_pointer = save_in;
968 return 1;
969 }
970
971 *str = input_line_pointer;
972 input_line_pointer = save_in;
973 return 0;
974 }
975
976 /* Turn a string in input_line_pointer into a floating point constant
977 of type TYPE, and store the appropriate bytes in *LITP. The number
978 of LITTLENUMS emitted is stored in *SIZEP. An error message is
979 returned, or NULL on OK.
980
981 Note that fp constants aren't represent in the normal way on the ARM.
982 In big endian mode, things are as expected. However, in little endian
983 mode fp constants are big-endian word-wise, and little-endian byte-wise
984 within the words. For example, (double) 1.1 in big endian mode is
985 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
986 the byte sequence 99 99 f1 3f 9a 99 99 99.
987
988 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
989
990 char *
991 md_atof (int type, char * litP, int * sizeP)
992 {
993 int prec;
994 LITTLENUM_TYPE words[MAX_LITTLENUMS];
995 char *t;
996 int i;
997
998 switch (type)
999 {
1000 case 'f':
1001 case 'F':
1002 case 's':
1003 case 'S':
1004 prec = 2;
1005 break;
1006
1007 case 'd':
1008 case 'D':
1009 case 'r':
1010 case 'R':
1011 prec = 4;
1012 break;
1013
1014 case 'x':
1015 case 'X':
1016 prec = 5;
1017 break;
1018
1019 case 'p':
1020 case 'P':
1021 prec = 5;
1022 break;
1023
1024 default:
1025 *sizeP = 0;
1026 return _("Unrecognized or unsupported floating point constant");
1027 }
1028
1029 t = atof_ieee (input_line_pointer, type, words);
1030 if (t)
1031 input_line_pointer = t;
1032 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1033
1034 if (target_big_endian)
1035 {
1036 for (i = 0; i < prec; i++)
1037 {
1038 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1039 litP += sizeof (LITTLENUM_TYPE);
1040 }
1041 }
1042 else
1043 {
1044 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
1045 for (i = prec - 1; i >= 0; i--)
1046 {
1047 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1048 litP += sizeof (LITTLENUM_TYPE);
1049 }
1050 else
1051 /* For a 4 byte float the order of elements in `words' is 1 0.
1052 For an 8 byte float the order is 1 0 3 2. */
1053 for (i = 0; i < prec; i += 2)
1054 {
1055 md_number_to_chars (litP, (valueT) words[i + 1],
1056 sizeof (LITTLENUM_TYPE));
1057 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1058 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1059 litP += 2 * sizeof (LITTLENUM_TYPE);
1060 }
1061 }
1062
1063 return NULL;
1064 }
1065
1066 /* We handle all bad expressions here, so that we can report the faulty
1067 instruction in the error message. */
1068 void
1069 md_operand (expressionS * exp)
1070 {
1071 if (in_my_get_expression)
1072 exp->X_op = O_illegal;
1073 }
1074
1075 /* Immediate values. */
1076
1077 /* Generic immediate-value read function for use in directives.
1078 Accepts anything that 'expression' can fold to a constant.
1079 *val receives the number. */
1080 #ifdef OBJ_ELF
1081 static int
1082 immediate_for_directive (int *val)
1083 {
1084 expressionS exp;
1085 exp.X_op = O_illegal;
1086
1087 if (is_immediate_prefix (*input_line_pointer))
1088 {
1089 input_line_pointer++;
1090 expression (&exp);
1091 }
1092
1093 if (exp.X_op != O_constant)
1094 {
1095 as_bad (_("expected #constant"));
1096 ignore_rest_of_line ();
1097 return FAIL;
1098 }
1099 *val = exp.X_add_number;
1100 return SUCCESS;
1101 }
1102 #endif
1103
1104 /* Register parsing. */
1105
1106 /* Generic register parser. CCP points to what should be the
1107 beginning of a register name. If it is indeed a valid register
1108 name, advance CCP over it and return the reg_entry structure;
1109 otherwise return NULL. Does not issue diagnostics. */
1110
1111 static struct reg_entry *
1112 arm_reg_parse_multi (char **ccp)
1113 {
1114 char *start = *ccp;
1115 char *p;
1116 struct reg_entry *reg;
1117
1118 #ifdef REGISTER_PREFIX
1119 if (*start != REGISTER_PREFIX)
1120 return NULL;
1121 start++;
1122 #endif
1123 #ifdef OPTIONAL_REGISTER_PREFIX
1124 if (*start == OPTIONAL_REGISTER_PREFIX)
1125 start++;
1126 #endif
1127
1128 p = start;
1129 if (!ISALPHA (*p) || !is_name_beginner (*p))
1130 return NULL;
1131
1132 do
1133 p++;
1134 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1135
1136 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1137
1138 if (!reg)
1139 return NULL;
1140
1141 *ccp = p;
1142 return reg;
1143 }
1144
1145 static int
1146 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1147 enum arm_reg_type type)
1148 {
1149 /* Alternative syntaxes are accepted for a few register classes. */
1150 switch (type)
1151 {
1152 case REG_TYPE_MVF:
1153 case REG_TYPE_MVD:
1154 case REG_TYPE_MVFX:
1155 case REG_TYPE_MVDX:
1156 /* Generic coprocessor register names are allowed for these. */
1157 if (reg && reg->type == REG_TYPE_CN)
1158 return reg->number;
1159 break;
1160
1161 case REG_TYPE_CP:
1162 /* For backward compatibility, a bare number is valid here. */
1163 {
1164 unsigned long processor = strtoul (start, ccp, 10);
1165 if (*ccp != start && processor <= 15)
1166 return processor;
1167 }
1168
1169 case REG_TYPE_MMXWC:
1170 /* WC includes WCG. ??? I'm not sure this is true for all
1171 instructions that take WC registers. */
1172 if (reg && reg->type == REG_TYPE_MMXWCG)
1173 return reg->number;
1174 break;
1175
1176 default:
1177 break;
1178 }
1179
1180 return FAIL;
1181 }
1182
1183 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1184 return value is the register number or FAIL. */
1185
1186 static int
1187 arm_reg_parse (char **ccp, enum arm_reg_type type)
1188 {
1189 char *start = *ccp;
1190 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1191 int ret;
1192
1193 /* Do not allow a scalar (reg+index) to parse as a register. */
1194 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1195 return FAIL;
1196
1197 if (reg && reg->type == type)
1198 return reg->number;
1199
1200 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1201 return ret;
1202
1203 *ccp = start;
1204 return FAIL;
1205 }
1206
1207 /* Parse a Neon type specifier. *STR should point at the leading '.'
1208 character. Does no verification at this stage that the type fits the opcode
1209 properly. E.g.,
1210
1211 .i32.i32.s16
1212 .s32.f32
1213 .u16
1214
1215 Can all be legally parsed by this function.
1216
1217 Fills in neon_type struct pointer with parsed information, and updates STR
1218 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1219 type, FAIL if not. */
1220
1221 static int
1222 parse_neon_type (struct neon_type *type, char **str)
1223 {
1224 char *ptr = *str;
1225
1226 if (type)
1227 type->elems = 0;
1228
1229 while (type->elems < NEON_MAX_TYPE_ELS)
1230 {
1231 enum neon_el_type thistype = NT_untyped;
1232 unsigned thissize = -1u;
1233
1234 if (*ptr != '.')
1235 break;
1236
1237 ptr++;
1238
1239 /* Just a size without an explicit type. */
1240 if (ISDIGIT (*ptr))
1241 goto parsesize;
1242
1243 switch (TOLOWER (*ptr))
1244 {
1245 case 'i': thistype = NT_integer; break;
1246 case 'f': thistype = NT_float; break;
1247 case 'p': thistype = NT_poly; break;
1248 case 's': thistype = NT_signed; break;
1249 case 'u': thistype = NT_unsigned; break;
1250 case 'd':
1251 thistype = NT_float;
1252 thissize = 64;
1253 ptr++;
1254 goto done;
1255 default:
1256 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1257 return FAIL;
1258 }
1259
1260 ptr++;
1261
1262 /* .f is an abbreviation for .f32. */
1263 if (thistype == NT_float && !ISDIGIT (*ptr))
1264 thissize = 32;
1265 else
1266 {
1267 parsesize:
1268 thissize = strtoul (ptr, &ptr, 10);
1269
1270 if (thissize != 8 && thissize != 16 && thissize != 32
1271 && thissize != 64)
1272 {
1273 as_bad (_("bad size %d in type specifier"), thissize);
1274 return FAIL;
1275 }
1276 }
1277
1278 done:
1279 if (type)
1280 {
1281 type->el[type->elems].type = thistype;
1282 type->el[type->elems].size = thissize;
1283 type->elems++;
1284 }
1285 }
1286
1287 /* Empty/missing type is not a successful parse. */
1288 if (type->elems == 0)
1289 return FAIL;
1290
1291 *str = ptr;
1292
1293 return SUCCESS;
1294 }
1295
1296 /* Errors may be set multiple times during parsing or bit encoding
1297 (particularly in the Neon bits), but usually the earliest error which is set
1298 will be the most meaningful. Avoid overwriting it with later (cascading)
1299 errors by calling this function. */
1300
1301 static void
1302 first_error (const char *err)
1303 {
1304 if (!inst.error)
1305 inst.error = err;
1306 }
1307
1308 /* Parse a single type, e.g. ".s32", leading period included. */
1309 static int
1310 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1311 {
1312 char *str = *ccp;
1313 struct neon_type optype;
1314
1315 if (*str == '.')
1316 {
1317 if (parse_neon_type (&optype, &str) == SUCCESS)
1318 {
1319 if (optype.elems == 1)
1320 *vectype = optype.el[0];
1321 else
1322 {
1323 first_error (_("only one type should be specified for operand"));
1324 return FAIL;
1325 }
1326 }
1327 else
1328 {
1329 first_error (_("vector type expected"));
1330 return FAIL;
1331 }
1332 }
1333 else
1334 return FAIL;
1335
1336 *ccp = str;
1337
1338 return SUCCESS;
1339 }
1340
1341 /* Special meanings for indices (which have a range of 0-7), which will fit into
1342 a 4-bit integer. */
1343
1344 #define NEON_ALL_LANES 15
1345 #define NEON_INTERLEAVE_LANES 14
1346
1347 /* Parse either a register or a scalar, with an optional type. Return the
1348 register number, and optionally fill in the actual type of the register
1349 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1350 type/index information in *TYPEINFO. */
1351
1352 static int
1353 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1354 enum arm_reg_type *rtype,
1355 struct neon_typed_alias *typeinfo)
1356 {
1357 char *str = *ccp;
1358 struct reg_entry *reg = arm_reg_parse_multi (&str);
1359 struct neon_typed_alias atype;
1360 struct neon_type_el parsetype;
1361
1362 atype.defined = 0;
1363 atype.index = -1;
1364 atype.eltype.type = NT_invtype;
1365 atype.eltype.size = -1;
1366
1367 /* Try alternate syntax for some types of register. Note these are mutually
1368 exclusive with the Neon syntax extensions. */
1369 if (reg == NULL)
1370 {
1371 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1372 if (altreg != FAIL)
1373 *ccp = str;
1374 if (typeinfo)
1375 *typeinfo = atype;
1376 return altreg;
1377 }
1378
1379 /* Undo polymorphism when a set of register types may be accepted. */
1380 if ((type == REG_TYPE_NDQ
1381 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1382 || (type == REG_TYPE_VFSD
1383 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1384 || (type == REG_TYPE_NSDQ
1385 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1386 || reg->type == REG_TYPE_NQ))
1387 || (type == REG_TYPE_MMXWC
1388 && (reg->type == REG_TYPE_MMXWCG)))
1389 type = (enum arm_reg_type) reg->type;
1390
1391 if (type != reg->type)
1392 return FAIL;
1393
1394 if (reg->neon)
1395 atype = *reg->neon;
1396
1397 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1398 {
1399 if ((atype.defined & NTA_HASTYPE) != 0)
1400 {
1401 first_error (_("can't redefine type for operand"));
1402 return FAIL;
1403 }
1404 atype.defined |= NTA_HASTYPE;
1405 atype.eltype = parsetype;
1406 }
1407
1408 if (skip_past_char (&str, '[') == SUCCESS)
1409 {
1410 if (type != REG_TYPE_VFD)
1411 {
1412 first_error (_("only D registers may be indexed"));
1413 return FAIL;
1414 }
1415
1416 if ((atype.defined & NTA_HASINDEX) != 0)
1417 {
1418 first_error (_("can't change index for operand"));
1419 return FAIL;
1420 }
1421
1422 atype.defined |= NTA_HASINDEX;
1423
1424 if (skip_past_char (&str, ']') == SUCCESS)
1425 atype.index = NEON_ALL_LANES;
1426 else
1427 {
1428 expressionS exp;
1429
1430 my_get_expression (&exp, &str, GE_NO_PREFIX);
1431
1432 if (exp.X_op != O_constant)
1433 {
1434 first_error (_("constant expression required"));
1435 return FAIL;
1436 }
1437
1438 if (skip_past_char (&str, ']') == FAIL)
1439 return FAIL;
1440
1441 atype.index = exp.X_add_number;
1442 }
1443 }
1444
1445 if (typeinfo)
1446 *typeinfo = atype;
1447
1448 if (rtype)
1449 *rtype = type;
1450
1451 *ccp = str;
1452
1453 return reg->number;
1454 }
1455
1456 /* Like arm_reg_parse, but allow allow the following extra features:
1457 - If RTYPE is non-zero, return the (possibly restricted) type of the
1458 register (e.g. Neon double or quad reg when either has been requested).
1459 - If this is a Neon vector type with additional type information, fill
1460 in the struct pointed to by VECTYPE (if non-NULL).
1461 This function will fault on encountering a scalar. */
1462
1463 static int
1464 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1465 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1466 {
1467 struct neon_typed_alias atype;
1468 char *str = *ccp;
1469 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1470
1471 if (reg == FAIL)
1472 return FAIL;
1473
1474 /* Do not allow a scalar (reg+index) to parse as a register. */
1475 if ((atype.defined & NTA_HASINDEX) != 0)
1476 {
1477 first_error (_("register operand expected, but got scalar"));
1478 return FAIL;
1479 }
1480
1481 if (vectype)
1482 *vectype = atype.eltype;
1483
1484 *ccp = str;
1485
1486 return reg;
1487 }
1488
1489 #define NEON_SCALAR_REG(X) ((X) >> 4)
1490 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1491
1492 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1493 have enough information to be able to do a good job bounds-checking. So, we
1494 just do easy checks here, and do further checks later. */
1495
1496 static int
1497 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1498 {
1499 int reg;
1500 char *str = *ccp;
1501 struct neon_typed_alias atype;
1502
1503 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
1504
1505 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1506 return FAIL;
1507
1508 if (atype.index == NEON_ALL_LANES)
1509 {
1510 first_error (_("scalar must have an index"));
1511 return FAIL;
1512 }
1513 else if (atype.index >= 64 / elsize)
1514 {
1515 first_error (_("scalar index out of range"));
1516 return FAIL;
1517 }
1518
1519 if (type)
1520 *type = atype.eltype;
1521
1522 *ccp = str;
1523
1524 return reg * 16 + atype.index;
1525 }
1526
1527 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1528
1529 static long
1530 parse_reg_list (char ** strp)
1531 {
1532 char * str = * strp;
1533 long range = 0;
1534 int another_range;
1535
1536 /* We come back here if we get ranges concatenated by '+' or '|'. */
1537 do
1538 {
1539 another_range = 0;
1540
1541 if (*str == '{')
1542 {
1543 int in_range = 0;
1544 int cur_reg = -1;
1545
1546 str++;
1547 do
1548 {
1549 int reg;
1550
1551 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1552 {
1553 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
1554 return FAIL;
1555 }
1556
1557 if (in_range)
1558 {
1559 int i;
1560
1561 if (reg <= cur_reg)
1562 {
1563 first_error (_("bad range in register list"));
1564 return FAIL;
1565 }
1566
1567 for (i = cur_reg + 1; i < reg; i++)
1568 {
1569 if (range & (1 << i))
1570 as_tsktsk
1571 (_("Warning: duplicated register (r%d) in register list"),
1572 i);
1573 else
1574 range |= 1 << i;
1575 }
1576 in_range = 0;
1577 }
1578
1579 if (range & (1 << reg))
1580 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1581 reg);
1582 else if (reg <= cur_reg)
1583 as_tsktsk (_("Warning: register range not in ascending order"));
1584
1585 range |= 1 << reg;
1586 cur_reg = reg;
1587 }
1588 while (skip_past_comma (&str) != FAIL
1589 || (in_range = 1, *str++ == '-'));
1590 str--;
1591
1592 if (*str++ != '}')
1593 {
1594 first_error (_("missing `}'"));
1595 return FAIL;
1596 }
1597 }
1598 else
1599 {
1600 expressionS exp;
1601
1602 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
1603 return FAIL;
1604
1605 if (exp.X_op == O_constant)
1606 {
1607 if (exp.X_add_number
1608 != (exp.X_add_number & 0x0000ffff))
1609 {
1610 inst.error = _("invalid register mask");
1611 return FAIL;
1612 }
1613
1614 if ((range & exp.X_add_number) != 0)
1615 {
1616 int regno = range & exp.X_add_number;
1617
1618 regno &= -regno;
1619 regno = (1 << regno) - 1;
1620 as_tsktsk
1621 (_("Warning: duplicated register (r%d) in register list"),
1622 regno);
1623 }
1624
1625 range |= exp.X_add_number;
1626 }
1627 else
1628 {
1629 if (inst.reloc.type != 0)
1630 {
1631 inst.error = _("expression too complex");
1632 return FAIL;
1633 }
1634
1635 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
1636 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1637 inst.reloc.pc_rel = 0;
1638 }
1639 }
1640
1641 if (*str == '|' || *str == '+')
1642 {
1643 str++;
1644 another_range = 1;
1645 }
1646 }
1647 while (another_range);
1648
1649 *strp = str;
1650 return range;
1651 }
1652
1653 /* Types of registers in a list. */
1654
1655 enum reg_list_els
1656 {
1657 REGLIST_VFP_S,
1658 REGLIST_VFP_D,
1659 REGLIST_NEON_D
1660 };
1661
1662 /* Parse a VFP register list. If the string is invalid return FAIL.
1663 Otherwise return the number of registers, and set PBASE to the first
1664 register. Parses registers of type ETYPE.
1665 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1666 - Q registers can be used to specify pairs of D registers
1667 - { } can be omitted from around a singleton register list
1668 FIXME: This is not implemented, as it would require backtracking in
1669 some cases, e.g.:
1670 vtbl.8 d3,d4,d5
1671 This could be done (the meaning isn't really ambiguous), but doesn't
1672 fit in well with the current parsing framework.
1673 - 32 D registers may be used (also true for VFPv3).
1674 FIXME: Types are ignored in these register lists, which is probably a
1675 bug. */
1676
1677 static int
1678 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
1679 {
1680 char *str = *ccp;
1681 int base_reg;
1682 int new_base;
1683 enum arm_reg_type regtype = (enum arm_reg_type) 0;
1684 int max_regs = 0;
1685 int count = 0;
1686 int warned = 0;
1687 unsigned long mask = 0;
1688 int i;
1689
1690 if (*str != '{')
1691 {
1692 inst.error = _("expecting {");
1693 return FAIL;
1694 }
1695
1696 str++;
1697
1698 switch (etype)
1699 {
1700 case REGLIST_VFP_S:
1701 regtype = REG_TYPE_VFS;
1702 max_regs = 32;
1703 break;
1704
1705 case REGLIST_VFP_D:
1706 regtype = REG_TYPE_VFD;
1707 break;
1708
1709 case REGLIST_NEON_D:
1710 regtype = REG_TYPE_NDQ;
1711 break;
1712 }
1713
1714 if (etype != REGLIST_VFP_S)
1715 {
1716 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1717 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
1718 {
1719 max_regs = 32;
1720 if (thumb_mode)
1721 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1722 fpu_vfp_ext_d32);
1723 else
1724 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1725 fpu_vfp_ext_d32);
1726 }
1727 else
1728 max_regs = 16;
1729 }
1730
1731 base_reg = max_regs;
1732
1733 do
1734 {
1735 int setmask = 1, addregs = 1;
1736
1737 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
1738
1739 if (new_base == FAIL)
1740 {
1741 first_error (_(reg_expected_msgs[regtype]));
1742 return FAIL;
1743 }
1744
1745 if (new_base >= max_regs)
1746 {
1747 first_error (_("register out of range in list"));
1748 return FAIL;
1749 }
1750
1751 /* Note: a value of 2 * n is returned for the register Q<n>. */
1752 if (regtype == REG_TYPE_NQ)
1753 {
1754 setmask = 3;
1755 addregs = 2;
1756 }
1757
1758 if (new_base < base_reg)
1759 base_reg = new_base;
1760
1761 if (mask & (setmask << new_base))
1762 {
1763 first_error (_("invalid register list"));
1764 return FAIL;
1765 }
1766
1767 if ((mask >> new_base) != 0 && ! warned)
1768 {
1769 as_tsktsk (_("register list not in ascending order"));
1770 warned = 1;
1771 }
1772
1773 mask |= setmask << new_base;
1774 count += addregs;
1775
1776 if (*str == '-') /* We have the start of a range expression */
1777 {
1778 int high_range;
1779
1780 str++;
1781
1782 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
1783 == FAIL)
1784 {
1785 inst.error = gettext (reg_expected_msgs[regtype]);
1786 return FAIL;
1787 }
1788
1789 if (high_range >= max_regs)
1790 {
1791 first_error (_("register out of range in list"));
1792 return FAIL;
1793 }
1794
1795 if (regtype == REG_TYPE_NQ)
1796 high_range = high_range + 1;
1797
1798 if (high_range <= new_base)
1799 {
1800 inst.error = _("register range not in ascending order");
1801 return FAIL;
1802 }
1803
1804 for (new_base += addregs; new_base <= high_range; new_base += addregs)
1805 {
1806 if (mask & (setmask << new_base))
1807 {
1808 inst.error = _("invalid register list");
1809 return FAIL;
1810 }
1811
1812 mask |= setmask << new_base;
1813 count += addregs;
1814 }
1815 }
1816 }
1817 while (skip_past_comma (&str) != FAIL);
1818
1819 str++;
1820
1821 /* Sanity check -- should have raised a parse error above. */
1822 if (count == 0 || count > max_regs)
1823 abort ();
1824
1825 *pbase = base_reg;
1826
1827 /* Final test -- the registers must be consecutive. */
1828 mask >>= base_reg;
1829 for (i = 0; i < count; i++)
1830 {
1831 if ((mask & (1u << i)) == 0)
1832 {
1833 inst.error = _("non-contiguous register range");
1834 return FAIL;
1835 }
1836 }
1837
1838 *ccp = str;
1839
1840 return count;
1841 }
1842
1843 /* True if two alias types are the same. */
1844
1845 static bfd_boolean
1846 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1847 {
1848 if (!a && !b)
1849 return TRUE;
1850
1851 if (!a || !b)
1852 return FALSE;
1853
1854 if (a->defined != b->defined)
1855 return FALSE;
1856
1857 if ((a->defined & NTA_HASTYPE) != 0
1858 && (a->eltype.type != b->eltype.type
1859 || a->eltype.size != b->eltype.size))
1860 return FALSE;
1861
1862 if ((a->defined & NTA_HASINDEX) != 0
1863 && (a->index != b->index))
1864 return FALSE;
1865
1866 return TRUE;
1867 }
1868
1869 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1870 The base register is put in *PBASE.
1871 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
1872 the return value.
1873 The register stride (minus one) is put in bit 4 of the return value.
1874 Bits [6:5] encode the list length (minus one).
1875 The type of the list elements is put in *ELTYPE, if non-NULL. */
1876
1877 #define NEON_LANE(X) ((X) & 0xf)
1878 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
1879 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1880
1881 static int
1882 parse_neon_el_struct_list (char **str, unsigned *pbase,
1883 struct neon_type_el *eltype)
1884 {
1885 char *ptr = *str;
1886 int base_reg = -1;
1887 int reg_incr = -1;
1888 int count = 0;
1889 int lane = -1;
1890 int leading_brace = 0;
1891 enum arm_reg_type rtype = REG_TYPE_NDQ;
1892 const char *const incr_error = _("register stride must be 1 or 2");
1893 const char *const type_error = _("mismatched element/structure types in list");
1894 struct neon_typed_alias firsttype;
1895
1896 if (skip_past_char (&ptr, '{') == SUCCESS)
1897 leading_brace = 1;
1898
1899 do
1900 {
1901 struct neon_typed_alias atype;
1902 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1903
1904 if (getreg == FAIL)
1905 {
1906 first_error (_(reg_expected_msgs[rtype]));
1907 return FAIL;
1908 }
1909
1910 if (base_reg == -1)
1911 {
1912 base_reg = getreg;
1913 if (rtype == REG_TYPE_NQ)
1914 {
1915 reg_incr = 1;
1916 }
1917 firsttype = atype;
1918 }
1919 else if (reg_incr == -1)
1920 {
1921 reg_incr = getreg - base_reg;
1922 if (reg_incr < 1 || reg_incr > 2)
1923 {
1924 first_error (_(incr_error));
1925 return FAIL;
1926 }
1927 }
1928 else if (getreg != base_reg + reg_incr * count)
1929 {
1930 first_error (_(incr_error));
1931 return FAIL;
1932 }
1933
1934 if (! neon_alias_types_same (&atype, &firsttype))
1935 {
1936 first_error (_(type_error));
1937 return FAIL;
1938 }
1939
1940 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1941 modes. */
1942 if (ptr[0] == '-')
1943 {
1944 struct neon_typed_alias htype;
1945 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1946 if (lane == -1)
1947 lane = NEON_INTERLEAVE_LANES;
1948 else if (lane != NEON_INTERLEAVE_LANES)
1949 {
1950 first_error (_(type_error));
1951 return FAIL;
1952 }
1953 if (reg_incr == -1)
1954 reg_incr = 1;
1955 else if (reg_incr != 1)
1956 {
1957 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
1958 return FAIL;
1959 }
1960 ptr++;
1961 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
1962 if (hireg == FAIL)
1963 {
1964 first_error (_(reg_expected_msgs[rtype]));
1965 return FAIL;
1966 }
1967 if (! neon_alias_types_same (&htype, &firsttype))
1968 {
1969 first_error (_(type_error));
1970 return FAIL;
1971 }
1972 count += hireg + dregs - getreg;
1973 continue;
1974 }
1975
1976 /* If we're using Q registers, we can't use [] or [n] syntax. */
1977 if (rtype == REG_TYPE_NQ)
1978 {
1979 count += 2;
1980 continue;
1981 }
1982
1983 if ((atype.defined & NTA_HASINDEX) != 0)
1984 {
1985 if (lane == -1)
1986 lane = atype.index;
1987 else if (lane != atype.index)
1988 {
1989 first_error (_(type_error));
1990 return FAIL;
1991 }
1992 }
1993 else if (lane == -1)
1994 lane = NEON_INTERLEAVE_LANES;
1995 else if (lane != NEON_INTERLEAVE_LANES)
1996 {
1997 first_error (_(type_error));
1998 return FAIL;
1999 }
2000 count++;
2001 }
2002 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
2003
2004 /* No lane set by [x]. We must be interleaving structures. */
2005 if (lane == -1)
2006 lane = NEON_INTERLEAVE_LANES;
2007
2008 /* Sanity check. */
2009 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2010 || (count > 1 && reg_incr == -1))
2011 {
2012 first_error (_("error parsing element/structure list"));
2013 return FAIL;
2014 }
2015
2016 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2017 {
2018 first_error (_("expected }"));
2019 return FAIL;
2020 }
2021
2022 if (reg_incr == -1)
2023 reg_incr = 1;
2024
2025 if (eltype)
2026 *eltype = firsttype.eltype;
2027
2028 *pbase = base_reg;
2029 *str = ptr;
2030
2031 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2032 }
2033
2034 /* Parse an explicit relocation suffix on an expression. This is
2035 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2036 arm_reloc_hsh contains no entries, so this function can only
2037 succeed if there is no () after the word. Returns -1 on error,
2038 BFD_RELOC_UNUSED if there wasn't any suffix. */
2039 static int
2040 parse_reloc (char **str)
2041 {
2042 struct reloc_entry *r;
2043 char *p, *q;
2044
2045 if (**str != '(')
2046 return BFD_RELOC_UNUSED;
2047
2048 p = *str + 1;
2049 q = p;
2050
2051 while (*q && *q != ')' && *q != ',')
2052 q++;
2053 if (*q != ')')
2054 return -1;
2055
2056 if ((r = (struct reloc_entry *)
2057 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
2058 return -1;
2059
2060 *str = q + 1;
2061 return r->reloc;
2062 }
2063
2064 /* Directives: register aliases. */
2065
2066 static struct reg_entry *
2067 insert_reg_alias (char *str, unsigned number, int type)
2068 {
2069 struct reg_entry *new_reg;
2070 const char *name;
2071
2072 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
2073 {
2074 if (new_reg->builtin)
2075 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
2076
2077 /* Only warn about a redefinition if it's not defined as the
2078 same register. */
2079 else if (new_reg->number != number || new_reg->type != type)
2080 as_warn (_("ignoring redefinition of register alias '%s'"), str);
2081
2082 return NULL;
2083 }
2084
2085 name = xstrdup (str);
2086 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
2087
2088 new_reg->name = name;
2089 new_reg->number = number;
2090 new_reg->type = type;
2091 new_reg->builtin = FALSE;
2092 new_reg->neon = NULL;
2093
2094 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
2095 abort ();
2096
2097 return new_reg;
2098 }
2099
2100 static void
2101 insert_neon_reg_alias (char *str, int number, int type,
2102 struct neon_typed_alias *atype)
2103 {
2104 struct reg_entry *reg = insert_reg_alias (str, number, type);
2105
2106 if (!reg)
2107 {
2108 first_error (_("attempt to redefine typed alias"));
2109 return;
2110 }
2111
2112 if (atype)
2113 {
2114 reg->neon = (struct neon_typed_alias *)
2115 xmalloc (sizeof (struct neon_typed_alias));
2116 *reg->neon = *atype;
2117 }
2118 }
2119
2120 /* Look for the .req directive. This is of the form:
2121
2122 new_register_name .req existing_register_name
2123
2124 If we find one, or if it looks sufficiently like one that we want to
2125 handle any error here, return TRUE. Otherwise return FALSE. */
2126
2127 static bfd_boolean
2128 create_register_alias (char * newname, char *p)
2129 {
2130 struct reg_entry *old;
2131 char *oldname, *nbuf;
2132 size_t nlen;
2133
2134 /* The input scrubber ensures that whitespace after the mnemonic is
2135 collapsed to single spaces. */
2136 oldname = p;
2137 if (strncmp (oldname, " .req ", 6) != 0)
2138 return FALSE;
2139
2140 oldname += 6;
2141 if (*oldname == '\0')
2142 return FALSE;
2143
2144 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
2145 if (!old)
2146 {
2147 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2148 return TRUE;
2149 }
2150
2151 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2152 the desired alias name, and p points to its end. If not, then
2153 the desired alias name is in the global original_case_string. */
2154 #ifdef TC_CASE_SENSITIVE
2155 nlen = p - newname;
2156 #else
2157 newname = original_case_string;
2158 nlen = strlen (newname);
2159 #endif
2160
2161 nbuf = (char *) alloca (nlen + 1);
2162 memcpy (nbuf, newname, nlen);
2163 nbuf[nlen] = '\0';
2164
2165 /* Create aliases under the new name as stated; an all-lowercase
2166 version of the new name; and an all-uppercase version of the new
2167 name. */
2168 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2169 {
2170 for (p = nbuf; *p; p++)
2171 *p = TOUPPER (*p);
2172
2173 if (strncmp (nbuf, newname, nlen))
2174 {
2175 /* If this attempt to create an additional alias fails, do not bother
2176 trying to create the all-lower case alias. We will fail and issue
2177 a second, duplicate error message. This situation arises when the
2178 programmer does something like:
2179 foo .req r0
2180 Foo .req r1
2181 The second .req creates the "Foo" alias but then fails to create
2182 the artificial FOO alias because it has already been created by the
2183 first .req. */
2184 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2185 return TRUE;
2186 }
2187
2188 for (p = nbuf; *p; p++)
2189 *p = TOLOWER (*p);
2190
2191 if (strncmp (nbuf, newname, nlen))
2192 insert_reg_alias (nbuf, old->number, old->type);
2193 }
2194
2195 return TRUE;
2196 }
2197
2198 /* Create a Neon typed/indexed register alias using directives, e.g.:
2199 X .dn d5.s32[1]
2200 Y .qn 6.s16
2201 Z .dn d7
2202 T .dn Z[0]
2203 These typed registers can be used instead of the types specified after the
2204 Neon mnemonic, so long as all operands given have types. Types can also be
2205 specified directly, e.g.:
2206 vadd d0.s32, d1.s32, d2.s32 */
2207
2208 static bfd_boolean
2209 create_neon_reg_alias (char *newname, char *p)
2210 {
2211 enum arm_reg_type basetype;
2212 struct reg_entry *basereg;
2213 struct reg_entry mybasereg;
2214 struct neon_type ntype;
2215 struct neon_typed_alias typeinfo;
2216 char *namebuf, *nameend;
2217 int namelen;
2218
2219 typeinfo.defined = 0;
2220 typeinfo.eltype.type = NT_invtype;
2221 typeinfo.eltype.size = -1;
2222 typeinfo.index = -1;
2223
2224 nameend = p;
2225
2226 if (strncmp (p, " .dn ", 5) == 0)
2227 basetype = REG_TYPE_VFD;
2228 else if (strncmp (p, " .qn ", 5) == 0)
2229 basetype = REG_TYPE_NQ;
2230 else
2231 return FALSE;
2232
2233 p += 5;
2234
2235 if (*p == '\0')
2236 return FALSE;
2237
2238 basereg = arm_reg_parse_multi (&p);
2239
2240 if (basereg && basereg->type != basetype)
2241 {
2242 as_bad (_("bad type for register"));
2243 return FALSE;
2244 }
2245
2246 if (basereg == NULL)
2247 {
2248 expressionS exp;
2249 /* Try parsing as an integer. */
2250 my_get_expression (&exp, &p, GE_NO_PREFIX);
2251 if (exp.X_op != O_constant)
2252 {
2253 as_bad (_("expression must be constant"));
2254 return FALSE;
2255 }
2256 basereg = &mybasereg;
2257 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2258 : exp.X_add_number;
2259 basereg->neon = 0;
2260 }
2261
2262 if (basereg->neon)
2263 typeinfo = *basereg->neon;
2264
2265 if (parse_neon_type (&ntype, &p) == SUCCESS)
2266 {
2267 /* We got a type. */
2268 if (typeinfo.defined & NTA_HASTYPE)
2269 {
2270 as_bad (_("can't redefine the type of a register alias"));
2271 return FALSE;
2272 }
2273
2274 typeinfo.defined |= NTA_HASTYPE;
2275 if (ntype.elems != 1)
2276 {
2277 as_bad (_("you must specify a single type only"));
2278 return FALSE;
2279 }
2280 typeinfo.eltype = ntype.el[0];
2281 }
2282
2283 if (skip_past_char (&p, '[') == SUCCESS)
2284 {
2285 expressionS exp;
2286 /* We got a scalar index. */
2287
2288 if (typeinfo.defined & NTA_HASINDEX)
2289 {
2290 as_bad (_("can't redefine the index of a scalar alias"));
2291 return FALSE;
2292 }
2293
2294 my_get_expression (&exp, &p, GE_NO_PREFIX);
2295
2296 if (exp.X_op != O_constant)
2297 {
2298 as_bad (_("scalar index must be constant"));
2299 return FALSE;
2300 }
2301
2302 typeinfo.defined |= NTA_HASINDEX;
2303 typeinfo.index = exp.X_add_number;
2304
2305 if (skip_past_char (&p, ']') == FAIL)
2306 {
2307 as_bad (_("expecting ]"));
2308 return FALSE;
2309 }
2310 }
2311
2312 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2313 the desired alias name, and p points to its end. If not, then
2314 the desired alias name is in the global original_case_string. */
2315 #ifdef TC_CASE_SENSITIVE
2316 namelen = nameend - newname;
2317 #else
2318 newname = original_case_string;
2319 namelen = strlen (newname);
2320 #endif
2321
2322 namebuf = (char *) alloca (namelen + 1);
2323 strncpy (namebuf, newname, namelen);
2324 namebuf[namelen] = '\0';
2325
2326 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2327 typeinfo.defined != 0 ? &typeinfo : NULL);
2328
2329 /* Insert name in all uppercase. */
2330 for (p = namebuf; *p; p++)
2331 *p = TOUPPER (*p);
2332
2333 if (strncmp (namebuf, newname, namelen))
2334 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2335 typeinfo.defined != 0 ? &typeinfo : NULL);
2336
2337 /* Insert name in all lowercase. */
2338 for (p = namebuf; *p; p++)
2339 *p = TOLOWER (*p);
2340
2341 if (strncmp (namebuf, newname, namelen))
2342 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2343 typeinfo.defined != 0 ? &typeinfo : NULL);
2344
2345 return TRUE;
2346 }
2347
2348 /* Should never be called, as .req goes between the alias and the
2349 register name, not at the beginning of the line. */
2350
2351 static void
2352 s_req (int a ATTRIBUTE_UNUSED)
2353 {
2354 as_bad (_("invalid syntax for .req directive"));
2355 }
2356
2357 static void
2358 s_dn (int a ATTRIBUTE_UNUSED)
2359 {
2360 as_bad (_("invalid syntax for .dn directive"));
2361 }
2362
2363 static void
2364 s_qn (int a ATTRIBUTE_UNUSED)
2365 {
2366 as_bad (_("invalid syntax for .qn directive"));
2367 }
2368
2369 /* The .unreq directive deletes an alias which was previously defined
2370 by .req. For example:
2371
2372 my_alias .req r11
2373 .unreq my_alias */
2374
2375 static void
2376 s_unreq (int a ATTRIBUTE_UNUSED)
2377 {
2378 char * name;
2379 char saved_char;
2380
2381 name = input_line_pointer;
2382
2383 while (*input_line_pointer != 0
2384 && *input_line_pointer != ' '
2385 && *input_line_pointer != '\n')
2386 ++input_line_pointer;
2387
2388 saved_char = *input_line_pointer;
2389 *input_line_pointer = 0;
2390
2391 if (!*name)
2392 as_bad (_("invalid syntax for .unreq directive"));
2393 else
2394 {
2395 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2396 name);
2397
2398 if (!reg)
2399 as_bad (_("unknown register alias '%s'"), name);
2400 else if (reg->builtin)
2401 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2402 name);
2403 else
2404 {
2405 char * p;
2406 char * nbuf;
2407
2408 hash_delete (arm_reg_hsh, name, FALSE);
2409 free ((char *) reg->name);
2410 if (reg->neon)
2411 free (reg->neon);
2412 free (reg);
2413
2414 /* Also locate the all upper case and all lower case versions.
2415 Do not complain if we cannot find one or the other as it
2416 was probably deleted above. */
2417
2418 nbuf = strdup (name);
2419 for (p = nbuf; *p; p++)
2420 *p = TOUPPER (*p);
2421 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2422 if (reg)
2423 {
2424 hash_delete (arm_reg_hsh, nbuf, FALSE);
2425 free ((char *) reg->name);
2426 if (reg->neon)
2427 free (reg->neon);
2428 free (reg);
2429 }
2430
2431 for (p = nbuf; *p; p++)
2432 *p = TOLOWER (*p);
2433 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2434 if (reg)
2435 {
2436 hash_delete (arm_reg_hsh, nbuf, FALSE);
2437 free ((char *) reg->name);
2438 if (reg->neon)
2439 free (reg->neon);
2440 free (reg);
2441 }
2442
2443 free (nbuf);
2444 }
2445 }
2446
2447 *input_line_pointer = saved_char;
2448 demand_empty_rest_of_line ();
2449 }
2450
2451 /* Directives: Instruction set selection. */
2452
2453 #ifdef OBJ_ELF
2454 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2455 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2456 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2457 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2458
2459 /* Create a new mapping symbol for the transition to STATE. */
2460
2461 static void
2462 make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
2463 {
2464 symbolS * symbolP;
2465 const char * symname;
2466 int type;
2467
2468 switch (state)
2469 {
2470 case MAP_DATA:
2471 symname = "$d";
2472 type = BSF_NO_FLAGS;
2473 break;
2474 case MAP_ARM:
2475 symname = "$a";
2476 type = BSF_NO_FLAGS;
2477 break;
2478 case MAP_THUMB:
2479 symname = "$t";
2480 type = BSF_NO_FLAGS;
2481 break;
2482 default:
2483 abort ();
2484 }
2485
2486 symbolP = symbol_new (symname, now_seg, value, frag);
2487 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2488
2489 switch (state)
2490 {
2491 case MAP_ARM:
2492 THUMB_SET_FUNC (symbolP, 0);
2493 ARM_SET_THUMB (symbolP, 0);
2494 ARM_SET_INTERWORK (symbolP, support_interwork);
2495 break;
2496
2497 case MAP_THUMB:
2498 THUMB_SET_FUNC (symbolP, 1);
2499 ARM_SET_THUMB (symbolP, 1);
2500 ARM_SET_INTERWORK (symbolP, support_interwork);
2501 break;
2502
2503 case MAP_DATA:
2504 default:
2505 break;
2506 }
2507
2508 /* Save the mapping symbols for future reference. Also check that
2509 we do not place two mapping symbols at the same offset within a
2510 frag. We'll handle overlap between frags in
2511 check_mapping_symbols.
2512
2513 If .fill or other data filling directive generates zero sized data,
2514 the mapping symbol for the following code will have the same value
2515 as the one generated for the data filling directive. In this case,
2516 we replace the old symbol with the new one at the same address. */
2517 if (value == 0)
2518 {
2519 if (frag->tc_frag_data.first_map != NULL)
2520 {
2521 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2522 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2523 }
2524 frag->tc_frag_data.first_map = symbolP;
2525 }
2526 if (frag->tc_frag_data.last_map != NULL)
2527 {
2528 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
2529 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2530 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2531 }
2532 frag->tc_frag_data.last_map = symbolP;
2533 }
2534
2535 /* We must sometimes convert a region marked as code to data during
2536 code alignment, if an odd number of bytes have to be padded. The
2537 code mapping symbol is pushed to an aligned address. */
2538
2539 static void
2540 insert_data_mapping_symbol (enum mstate state,
2541 valueT value, fragS *frag, offsetT bytes)
2542 {
2543 /* If there was already a mapping symbol, remove it. */
2544 if (frag->tc_frag_data.last_map != NULL
2545 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2546 {
2547 symbolS *symp = frag->tc_frag_data.last_map;
2548
2549 if (value == 0)
2550 {
2551 know (frag->tc_frag_data.first_map == symp);
2552 frag->tc_frag_data.first_map = NULL;
2553 }
2554 frag->tc_frag_data.last_map = NULL;
2555 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
2556 }
2557
2558 make_mapping_symbol (MAP_DATA, value, frag);
2559 make_mapping_symbol (state, value + bytes, frag);
2560 }
2561
2562 static void mapping_state_2 (enum mstate state, int max_chars);
2563
2564 /* Set the mapping state to STATE. Only call this when about to
2565 emit some STATE bytes to the file. */
2566
2567 void
2568 mapping_state (enum mstate state)
2569 {
2570 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2571
2572 #define TRANSITION(from, to) (mapstate == (from) && state == (to))
2573
2574 if (mapstate == state)
2575 /* The mapping symbol has already been emitted.
2576 There is nothing else to do. */
2577 return;
2578 else if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
2579 /* This case will be evaluated later in the next else. */
2580 return;
2581 else if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2582 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2583 {
2584 /* Only add the symbol if the offset is > 0:
2585 if we're at the first frag, check it's size > 0;
2586 if we're not at the first frag, then for sure
2587 the offset is > 0. */
2588 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2589 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2590
2591 if (add_symbol)
2592 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2593 }
2594
2595 mapping_state_2 (state, 0);
2596 #undef TRANSITION
2597 }
2598
2599 /* Same as mapping_state, but MAX_CHARS bytes have already been
2600 allocated. Put the mapping symbol that far back. */
2601
2602 static void
2603 mapping_state_2 (enum mstate state, int max_chars)
2604 {
2605 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2606
2607 if (!SEG_NORMAL (now_seg))
2608 return;
2609
2610 if (mapstate == state)
2611 /* The mapping symbol has already been emitted.
2612 There is nothing else to do. */
2613 return;
2614
2615 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2616 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
2617 }
2618 #else
2619 #define mapping_state(x) ((void)0)
2620 #define mapping_state_2(x, y) ((void)0)
2621 #endif
2622
2623 /* Find the real, Thumb encoded start of a Thumb function. */
2624
2625 #ifdef OBJ_COFF
2626 static symbolS *
2627 find_real_start (symbolS * symbolP)
2628 {
2629 char * real_start;
2630 const char * name = S_GET_NAME (symbolP);
2631 symbolS * new_target;
2632
2633 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2634 #define STUB_NAME ".real_start_of"
2635
2636 if (name == NULL)
2637 abort ();
2638
2639 /* The compiler may generate BL instructions to local labels because
2640 it needs to perform a branch to a far away location. These labels
2641 do not have a corresponding ".real_start_of" label. We check
2642 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2643 the ".real_start_of" convention for nonlocal branches. */
2644 if (S_IS_LOCAL (symbolP) || name[0] == '.')
2645 return symbolP;
2646
2647 real_start = ACONCAT ((STUB_NAME, name, NULL));
2648 new_target = symbol_find (real_start);
2649
2650 if (new_target == NULL)
2651 {
2652 as_warn (_("Failed to find real start of function: %s\n"), name);
2653 new_target = symbolP;
2654 }
2655
2656 return new_target;
2657 }
2658 #endif
2659
2660 static void
2661 opcode_select (int width)
2662 {
2663 switch (width)
2664 {
2665 case 16:
2666 if (! thumb_mode)
2667 {
2668 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
2669 as_bad (_("selected processor does not support THUMB opcodes"));
2670
2671 thumb_mode = 1;
2672 /* No need to force the alignment, since we will have been
2673 coming from ARM mode, which is word-aligned. */
2674 record_alignment (now_seg, 1);
2675 }
2676 break;
2677
2678 case 32:
2679 if (thumb_mode)
2680 {
2681 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
2682 as_bad (_("selected processor does not support ARM opcodes"));
2683
2684 thumb_mode = 0;
2685
2686 if (!need_pass_2)
2687 frag_align (2, 0, 0);
2688
2689 record_alignment (now_seg, 1);
2690 }
2691 break;
2692
2693 default:
2694 as_bad (_("invalid instruction size selected (%d)"), width);
2695 }
2696 }
2697
2698 static void
2699 s_arm (int ignore ATTRIBUTE_UNUSED)
2700 {
2701 opcode_select (32);
2702 demand_empty_rest_of_line ();
2703 }
2704
2705 static void
2706 s_thumb (int ignore ATTRIBUTE_UNUSED)
2707 {
2708 opcode_select (16);
2709 demand_empty_rest_of_line ();
2710 }
2711
2712 static void
2713 s_code (int unused ATTRIBUTE_UNUSED)
2714 {
2715 int temp;
2716
2717 temp = get_absolute_expression ();
2718 switch (temp)
2719 {
2720 case 16:
2721 case 32:
2722 opcode_select (temp);
2723 break;
2724
2725 default:
2726 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2727 }
2728 }
2729
2730 static void
2731 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2732 {
2733 /* If we are not already in thumb mode go into it, EVEN if
2734 the target processor does not support thumb instructions.
2735 This is used by gcc/config/arm/lib1funcs.asm for example
2736 to compile interworking support functions even if the
2737 target processor should not support interworking. */
2738 if (! thumb_mode)
2739 {
2740 thumb_mode = 2;
2741 record_alignment (now_seg, 1);
2742 }
2743
2744 demand_empty_rest_of_line ();
2745 }
2746
2747 static void
2748 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2749 {
2750 s_thumb (0);
2751
2752 /* The following label is the name/address of the start of a Thumb function.
2753 We need to know this for the interworking support. */
2754 label_is_thumb_function_name = TRUE;
2755 }
2756
2757 /* Perform a .set directive, but also mark the alias as
2758 being a thumb function. */
2759
2760 static void
2761 s_thumb_set (int equiv)
2762 {
2763 /* XXX the following is a duplicate of the code for s_set() in read.c
2764 We cannot just call that code as we need to get at the symbol that
2765 is created. */
2766 char * name;
2767 char delim;
2768 char * end_name;
2769 symbolS * symbolP;
2770
2771 /* Especial apologies for the random logic:
2772 This just grew, and could be parsed much more simply!
2773 Dean - in haste. */
2774 name = input_line_pointer;
2775 delim = get_symbol_end ();
2776 end_name = input_line_pointer;
2777 *end_name = delim;
2778
2779 if (*input_line_pointer != ',')
2780 {
2781 *end_name = 0;
2782 as_bad (_("expected comma after name \"%s\""), name);
2783 *end_name = delim;
2784 ignore_rest_of_line ();
2785 return;
2786 }
2787
2788 input_line_pointer++;
2789 *end_name = 0;
2790
2791 if (name[0] == '.' && name[1] == '\0')
2792 {
2793 /* XXX - this should not happen to .thumb_set. */
2794 abort ();
2795 }
2796
2797 if ((symbolP = symbol_find (name)) == NULL
2798 && (symbolP = md_undefined_symbol (name)) == NULL)
2799 {
2800 #ifndef NO_LISTING
2801 /* When doing symbol listings, play games with dummy fragments living
2802 outside the normal fragment chain to record the file and line info
2803 for this symbol. */
2804 if (listing & LISTING_SYMBOLS)
2805 {
2806 extern struct list_info_struct * listing_tail;
2807 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
2808
2809 memset (dummy_frag, 0, sizeof (fragS));
2810 dummy_frag->fr_type = rs_fill;
2811 dummy_frag->line = listing_tail;
2812 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2813 dummy_frag->fr_symbol = symbolP;
2814 }
2815 else
2816 #endif
2817 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2818
2819 #ifdef OBJ_COFF
2820 /* "set" symbols are local unless otherwise specified. */
2821 SF_SET_LOCAL (symbolP);
2822 #endif /* OBJ_COFF */
2823 } /* Make a new symbol. */
2824
2825 symbol_table_insert (symbolP);
2826
2827 * end_name = delim;
2828
2829 if (equiv
2830 && S_IS_DEFINED (symbolP)
2831 && S_GET_SEGMENT (symbolP) != reg_section)
2832 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2833
2834 pseudo_set (symbolP);
2835
2836 demand_empty_rest_of_line ();
2837
2838 /* XXX Now we come to the Thumb specific bit of code. */
2839
2840 THUMB_SET_FUNC (symbolP, 1);
2841 ARM_SET_THUMB (symbolP, 1);
2842 #if defined OBJ_ELF || defined OBJ_COFF
2843 ARM_SET_INTERWORK (symbolP, support_interwork);
2844 #endif
2845 }
2846
2847 /* Directives: Mode selection. */
2848
2849 /* .syntax [unified|divided] - choose the new unified syntax
2850 (same for Arm and Thumb encoding, modulo slight differences in what
2851 can be represented) or the old divergent syntax for each mode. */
2852 static void
2853 s_syntax (int unused ATTRIBUTE_UNUSED)
2854 {
2855 char *name, delim;
2856
2857 name = input_line_pointer;
2858 delim = get_symbol_end ();
2859
2860 if (!strcasecmp (name, "unified"))
2861 unified_syntax = TRUE;
2862 else if (!strcasecmp (name, "divided"))
2863 unified_syntax = FALSE;
2864 else
2865 {
2866 as_bad (_("unrecognized syntax mode \"%s\""), name);
2867 return;
2868 }
2869 *input_line_pointer = delim;
2870 demand_empty_rest_of_line ();
2871 }
2872
2873 /* Directives: sectioning and alignment. */
2874
2875 /* Same as s_align_ptwo but align 0 => align 2. */
2876
2877 static void
2878 s_align (int unused ATTRIBUTE_UNUSED)
2879 {
2880 int temp;
2881 bfd_boolean fill_p;
2882 long temp_fill;
2883 long max_alignment = 15;
2884
2885 temp = get_absolute_expression ();
2886 if (temp > max_alignment)
2887 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2888 else if (temp < 0)
2889 {
2890 as_bad (_("alignment negative. 0 assumed."));
2891 temp = 0;
2892 }
2893
2894 if (*input_line_pointer == ',')
2895 {
2896 input_line_pointer++;
2897 temp_fill = get_absolute_expression ();
2898 fill_p = TRUE;
2899 }
2900 else
2901 {
2902 fill_p = FALSE;
2903 temp_fill = 0;
2904 }
2905
2906 if (!temp)
2907 temp = 2;
2908
2909 /* Only make a frag if we HAVE to. */
2910 if (temp && !need_pass_2)
2911 {
2912 if (!fill_p && subseg_text_p (now_seg))
2913 frag_align_code (temp, 0);
2914 else
2915 frag_align (temp, (int) temp_fill, 0);
2916 }
2917 demand_empty_rest_of_line ();
2918
2919 record_alignment (now_seg, temp);
2920 }
2921
2922 static void
2923 s_bss (int ignore ATTRIBUTE_UNUSED)
2924 {
2925 /* We don't support putting frags in the BSS segment, we fake it by
2926 marking in_bss, then looking at s_skip for clues. */
2927 subseg_set (bss_section, 0);
2928 demand_empty_rest_of_line ();
2929
2930 #ifdef md_elf_section_change_hook
2931 md_elf_section_change_hook ();
2932 #endif
2933 }
2934
2935 static void
2936 s_even (int ignore ATTRIBUTE_UNUSED)
2937 {
2938 /* Never make frag if expect extra pass. */
2939 if (!need_pass_2)
2940 frag_align (1, 0, 0);
2941
2942 record_alignment (now_seg, 1);
2943
2944 demand_empty_rest_of_line ();
2945 }
2946
2947 /* Directives: Literal pools. */
2948
2949 static literal_pool *
2950 find_literal_pool (void)
2951 {
2952 literal_pool * pool;
2953
2954 for (pool = list_of_pools; pool != NULL; pool = pool->next)
2955 {
2956 if (pool->section == now_seg
2957 && pool->sub_section == now_subseg)
2958 break;
2959 }
2960
2961 return pool;
2962 }
2963
2964 static literal_pool *
2965 find_or_make_literal_pool (void)
2966 {
2967 /* Next literal pool ID number. */
2968 static unsigned int latest_pool_num = 1;
2969 literal_pool * pool;
2970
2971 pool = find_literal_pool ();
2972
2973 if (pool == NULL)
2974 {
2975 /* Create a new pool. */
2976 pool = (literal_pool *) xmalloc (sizeof (* pool));
2977 if (! pool)
2978 return NULL;
2979
2980 pool->next_free_entry = 0;
2981 pool->section = now_seg;
2982 pool->sub_section = now_subseg;
2983 pool->next = list_of_pools;
2984 pool->symbol = NULL;
2985
2986 /* Add it to the list. */
2987 list_of_pools = pool;
2988 }
2989
2990 /* New pools, and emptied pools, will have a NULL symbol. */
2991 if (pool->symbol == NULL)
2992 {
2993 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2994 (valueT) 0, &zero_address_frag);
2995 pool->id = latest_pool_num ++;
2996 }
2997
2998 /* Done. */
2999 return pool;
3000 }
3001
3002 /* Add the literal in the global 'inst'
3003 structure to the relevant literal pool. */
3004
3005 static int
3006 add_to_lit_pool (void)
3007 {
3008 literal_pool * pool;
3009 unsigned int entry;
3010
3011 pool = find_or_make_literal_pool ();
3012
3013 /* Check if this literal value is already in the pool. */
3014 for (entry = 0; entry < pool->next_free_entry; entry ++)
3015 {
3016 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3017 && (inst.reloc.exp.X_op == O_constant)
3018 && (pool->literals[entry].X_add_number
3019 == inst.reloc.exp.X_add_number)
3020 && (pool->literals[entry].X_unsigned
3021 == inst.reloc.exp.X_unsigned))
3022 break;
3023
3024 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3025 && (inst.reloc.exp.X_op == O_symbol)
3026 && (pool->literals[entry].X_add_number
3027 == inst.reloc.exp.X_add_number)
3028 && (pool->literals[entry].X_add_symbol
3029 == inst.reloc.exp.X_add_symbol)
3030 && (pool->literals[entry].X_op_symbol
3031 == inst.reloc.exp.X_op_symbol))
3032 break;
3033 }
3034
3035 /* Do we need to create a new entry? */
3036 if (entry == pool->next_free_entry)
3037 {
3038 if (entry >= MAX_LITERAL_POOL_SIZE)
3039 {
3040 inst.error = _("literal pool overflow");
3041 return FAIL;
3042 }
3043
3044 pool->literals[entry] = inst.reloc.exp;
3045 pool->next_free_entry += 1;
3046 }
3047
3048 inst.reloc.exp.X_op = O_symbol;
3049 inst.reloc.exp.X_add_number = ((int) entry) * 4;
3050 inst.reloc.exp.X_add_symbol = pool->symbol;
3051
3052 return SUCCESS;
3053 }
3054
3055 /* Can't use symbol_new here, so have to create a symbol and then at
3056 a later date assign it a value. Thats what these functions do. */
3057
3058 static void
3059 symbol_locate (symbolS * symbolP,
3060 const char * name, /* It is copied, the caller can modify. */
3061 segT segment, /* Segment identifier (SEG_<something>). */
3062 valueT valu, /* Symbol value. */
3063 fragS * frag) /* Associated fragment. */
3064 {
3065 unsigned int name_length;
3066 char * preserved_copy_of_name;
3067
3068 name_length = strlen (name) + 1; /* +1 for \0. */
3069 obstack_grow (&notes, name, name_length);
3070 preserved_copy_of_name = (char *) obstack_finish (&notes);
3071
3072 #ifdef tc_canonicalize_symbol_name
3073 preserved_copy_of_name =
3074 tc_canonicalize_symbol_name (preserved_copy_of_name);
3075 #endif
3076
3077 S_SET_NAME (symbolP, preserved_copy_of_name);
3078
3079 S_SET_SEGMENT (symbolP, segment);
3080 S_SET_VALUE (symbolP, valu);
3081 symbol_clear_list_pointers (symbolP);
3082
3083 symbol_set_frag (symbolP, frag);
3084
3085 /* Link to end of symbol chain. */
3086 {
3087 extern int symbol_table_frozen;
3088
3089 if (symbol_table_frozen)
3090 abort ();
3091 }
3092
3093 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
3094
3095 obj_symbol_new_hook (symbolP);
3096
3097 #ifdef tc_symbol_new_hook
3098 tc_symbol_new_hook (symbolP);
3099 #endif
3100
3101 #ifdef DEBUG_SYMS
3102 verify_symbol_chain (symbol_rootP, symbol_lastP);
3103 #endif /* DEBUG_SYMS */
3104 }
3105
3106
3107 static void
3108 s_ltorg (int ignored ATTRIBUTE_UNUSED)
3109 {
3110 unsigned int entry;
3111 literal_pool * pool;
3112 char sym_name[20];
3113
3114 pool = find_literal_pool ();
3115 if (pool == NULL
3116 || pool->symbol == NULL
3117 || pool->next_free_entry == 0)
3118 return;
3119
3120 mapping_state (MAP_DATA);
3121
3122 /* Align pool as you have word accesses.
3123 Only make a frag if we have to. */
3124 if (!need_pass_2)
3125 frag_align (2, 0, 0);
3126
3127 record_alignment (now_seg, 2);
3128
3129 sprintf (sym_name, "$$lit_\002%x", pool->id);
3130
3131 symbol_locate (pool->symbol, sym_name, now_seg,
3132 (valueT) frag_now_fix (), frag_now);
3133 symbol_table_insert (pool->symbol);
3134
3135 ARM_SET_THUMB (pool->symbol, thumb_mode);
3136
3137 #if defined OBJ_COFF || defined OBJ_ELF
3138 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3139 #endif
3140
3141 for (entry = 0; entry < pool->next_free_entry; entry ++)
3142 /* First output the expression in the instruction to the pool. */
3143 emit_expr (&(pool->literals[entry]), 4); /* .word */
3144
3145 /* Mark the pool as empty. */
3146 pool->next_free_entry = 0;
3147 pool->symbol = NULL;
3148 }
3149
3150 #ifdef OBJ_ELF
3151 /* Forward declarations for functions below, in the MD interface
3152 section. */
3153 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3154 static valueT create_unwind_entry (int);
3155 static void start_unwind_section (const segT, int);
3156 static void add_unwind_opcode (valueT, int);
3157 static void flush_pending_unwind (void);
3158
3159 /* Directives: Data. */
3160
3161 static void
3162 s_arm_elf_cons (int nbytes)
3163 {
3164 expressionS exp;
3165
3166 #ifdef md_flush_pending_output
3167 md_flush_pending_output ();
3168 #endif
3169
3170 if (is_it_end_of_statement ())
3171 {
3172 demand_empty_rest_of_line ();
3173 return;
3174 }
3175
3176 #ifdef md_cons_align
3177 md_cons_align (nbytes);
3178 #endif
3179
3180 mapping_state (MAP_DATA);
3181 do
3182 {
3183 int reloc;
3184 char *base = input_line_pointer;
3185
3186 expression (& exp);
3187
3188 if (exp.X_op != O_symbol)
3189 emit_expr (&exp, (unsigned int) nbytes);
3190 else
3191 {
3192 char *before_reloc = input_line_pointer;
3193 reloc = parse_reloc (&input_line_pointer);
3194 if (reloc == -1)
3195 {
3196 as_bad (_("unrecognized relocation suffix"));
3197 ignore_rest_of_line ();
3198 return;
3199 }
3200 else if (reloc == BFD_RELOC_UNUSED)
3201 emit_expr (&exp, (unsigned int) nbytes);
3202 else
3203 {
3204 reloc_howto_type *howto = (reloc_howto_type *)
3205 bfd_reloc_type_lookup (stdoutput,
3206 (bfd_reloc_code_real_type) reloc);
3207 int size = bfd_get_reloc_size (howto);
3208
3209 if (reloc == BFD_RELOC_ARM_PLT32)
3210 {
3211 as_bad (_("(plt) is only valid on branch targets"));
3212 reloc = BFD_RELOC_UNUSED;
3213 size = 0;
3214 }
3215
3216 if (size > nbytes)
3217 as_bad (_("%s relocations do not fit in %d bytes"),
3218 howto->name, nbytes);
3219 else
3220 {
3221 /* We've parsed an expression stopping at O_symbol.
3222 But there may be more expression left now that we
3223 have parsed the relocation marker. Parse it again.
3224 XXX Surely there is a cleaner way to do this. */
3225 char *p = input_line_pointer;
3226 int offset;
3227 char *save_buf = (char *) alloca (input_line_pointer - base);
3228 memcpy (save_buf, base, input_line_pointer - base);
3229 memmove (base + (input_line_pointer - before_reloc),
3230 base, before_reloc - base);
3231
3232 input_line_pointer = base + (input_line_pointer-before_reloc);
3233 expression (&exp);
3234 memcpy (base, save_buf, p - base);
3235
3236 offset = nbytes - size;
3237 p = frag_more ((int) nbytes);
3238 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3239 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
3240 }
3241 }
3242 }
3243 }
3244 while (*input_line_pointer++ == ',');
3245
3246 /* Put terminator back into stream. */
3247 input_line_pointer --;
3248 demand_empty_rest_of_line ();
3249 }
3250
3251 /* Emit an expression containing a 32-bit thumb instruction.
3252 Implementation based on put_thumb32_insn. */
3253
3254 static void
3255 emit_thumb32_expr (expressionS * exp)
3256 {
3257 expressionS exp_high = *exp;
3258
3259 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3260 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3261 exp->X_add_number &= 0xffff;
3262 emit_expr (exp, (unsigned int) THUMB_SIZE);
3263 }
3264
3265 /* Guess the instruction size based on the opcode. */
3266
3267 static int
3268 thumb_insn_size (int opcode)
3269 {
3270 if ((unsigned int) opcode < 0xe800u)
3271 return 2;
3272 else if ((unsigned int) opcode >= 0xe8000000u)
3273 return 4;
3274 else
3275 return 0;
3276 }
3277
3278 static bfd_boolean
3279 emit_insn (expressionS *exp, int nbytes)
3280 {
3281 int size = 0;
3282
3283 if (exp->X_op == O_constant)
3284 {
3285 size = nbytes;
3286
3287 if (size == 0)
3288 size = thumb_insn_size (exp->X_add_number);
3289
3290 if (size != 0)
3291 {
3292 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3293 {
3294 as_bad (_(".inst.n operand too big. "\
3295 "Use .inst.w instead"));
3296 size = 0;
3297 }
3298 else
3299 {
3300 if (now_it.state == AUTOMATIC_IT_BLOCK)
3301 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3302 else
3303 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3304
3305 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3306 emit_thumb32_expr (exp);
3307 else
3308 emit_expr (exp, (unsigned int) size);
3309
3310 it_fsm_post_encode ();
3311 }
3312 }
3313 else
3314 as_bad (_("cannot determine Thumb instruction size. " \
3315 "Use .inst.n/.inst.w instead"));
3316 }
3317 else
3318 as_bad (_("constant expression required"));
3319
3320 return (size != 0);
3321 }
3322
3323 /* Like s_arm_elf_cons but do not use md_cons_align and
3324 set the mapping state to MAP_ARM/MAP_THUMB. */
3325
3326 static void
3327 s_arm_elf_inst (int nbytes)
3328 {
3329 if (is_it_end_of_statement ())
3330 {
3331 demand_empty_rest_of_line ();
3332 return;
3333 }
3334
3335 /* Calling mapping_state () here will not change ARM/THUMB,
3336 but will ensure not to be in DATA state. */
3337
3338 if (thumb_mode)
3339 mapping_state (MAP_THUMB);
3340 else
3341 {
3342 if (nbytes != 0)
3343 {
3344 as_bad (_("width suffixes are invalid in ARM mode"));
3345 ignore_rest_of_line ();
3346 return;
3347 }
3348
3349 nbytes = 4;
3350
3351 mapping_state (MAP_ARM);
3352 }
3353
3354 do
3355 {
3356 expressionS exp;
3357
3358 expression (& exp);
3359
3360 if (! emit_insn (& exp, nbytes))
3361 {
3362 ignore_rest_of_line ();
3363 return;
3364 }
3365 }
3366 while (*input_line_pointer++ == ',');
3367
3368 /* Put terminator back into stream. */
3369 input_line_pointer --;
3370 demand_empty_rest_of_line ();
3371 }
3372
3373 /* Parse a .rel31 directive. */
3374
3375 static void
3376 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3377 {
3378 expressionS exp;
3379 char *p;
3380 valueT highbit;
3381
3382 highbit = 0;
3383 if (*input_line_pointer == '1')
3384 highbit = 0x80000000;
3385 else if (*input_line_pointer != '0')
3386 as_bad (_("expected 0 or 1"));
3387
3388 input_line_pointer++;
3389 if (*input_line_pointer != ',')
3390 as_bad (_("missing comma"));
3391 input_line_pointer++;
3392
3393 #ifdef md_flush_pending_output
3394 md_flush_pending_output ();
3395 #endif
3396
3397 #ifdef md_cons_align
3398 md_cons_align (4);
3399 #endif
3400
3401 mapping_state (MAP_DATA);
3402
3403 expression (&exp);
3404
3405 p = frag_more (4);
3406 md_number_to_chars (p, highbit, 4);
3407 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3408 BFD_RELOC_ARM_PREL31);
3409
3410 demand_empty_rest_of_line ();
3411 }
3412
3413 /* Directives: AEABI stack-unwind tables. */
3414
3415 /* Parse an unwind_fnstart directive. Simply records the current location. */
3416
3417 static void
3418 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3419 {
3420 demand_empty_rest_of_line ();
3421 if (unwind.proc_start)
3422 {
3423 as_bad (_("duplicate .fnstart directive"));
3424 return;
3425 }
3426
3427 /* Mark the start of the function. */
3428 unwind.proc_start = expr_build_dot ();
3429
3430 /* Reset the rest of the unwind info. */
3431 unwind.opcode_count = 0;
3432 unwind.table_entry = NULL;
3433 unwind.personality_routine = NULL;
3434 unwind.personality_index = -1;
3435 unwind.frame_size = 0;
3436 unwind.fp_offset = 0;
3437 unwind.fp_reg = REG_SP;
3438 unwind.fp_used = 0;
3439 unwind.sp_restored = 0;
3440 }
3441
3442
3443 /* Parse a handlerdata directive. Creates the exception handling table entry
3444 for the function. */
3445
3446 static void
3447 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3448 {
3449 demand_empty_rest_of_line ();
3450 if (!unwind.proc_start)
3451 as_bad (MISSING_FNSTART);
3452
3453 if (unwind.table_entry)
3454 as_bad (_("duplicate .handlerdata directive"));
3455
3456 create_unwind_entry (1);
3457 }
3458
3459 /* Parse an unwind_fnend directive. Generates the index table entry. */
3460
3461 static void
3462 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3463 {
3464 long where;
3465 char *ptr;
3466 valueT val;
3467 unsigned int marked_pr_dependency;
3468
3469 demand_empty_rest_of_line ();
3470
3471 if (!unwind.proc_start)
3472 {
3473 as_bad (_(".fnend directive without .fnstart"));
3474 return;
3475 }
3476
3477 /* Add eh table entry. */
3478 if (unwind.table_entry == NULL)
3479 val = create_unwind_entry (0);
3480 else
3481 val = 0;
3482
3483 /* Add index table entry. This is two words. */
3484 start_unwind_section (unwind.saved_seg, 1);
3485 frag_align (2, 0, 0);
3486 record_alignment (now_seg, 2);
3487
3488 ptr = frag_more (8);
3489 where = frag_now_fix () - 8;
3490
3491 /* Self relative offset of the function start. */
3492 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3493 BFD_RELOC_ARM_PREL31);
3494
3495 /* Indicate dependency on EHABI-defined personality routines to the
3496 linker, if it hasn't been done already. */
3497 marked_pr_dependency
3498 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
3499 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3500 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3501 {
3502 static const char *const name[] =
3503 {
3504 "__aeabi_unwind_cpp_pr0",
3505 "__aeabi_unwind_cpp_pr1",
3506 "__aeabi_unwind_cpp_pr2"
3507 };
3508 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3509 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3510 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3511 |= 1 << unwind.personality_index;
3512 }
3513
3514 if (val)
3515 /* Inline exception table entry. */
3516 md_number_to_chars (ptr + 4, val, 4);
3517 else
3518 /* Self relative offset of the table entry. */
3519 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3520 BFD_RELOC_ARM_PREL31);
3521
3522 /* Restore the original section. */
3523 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3524
3525 unwind.proc_start = NULL;
3526 }
3527
3528
3529 /* Parse an unwind_cantunwind directive. */
3530
3531 static void
3532 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3533 {
3534 demand_empty_rest_of_line ();
3535 if (!unwind.proc_start)
3536 as_bad (MISSING_FNSTART);
3537
3538 if (unwind.personality_routine || unwind.personality_index != -1)
3539 as_bad (_("personality routine specified for cantunwind frame"));
3540
3541 unwind.personality_index = -2;
3542 }
3543
3544
3545 /* Parse a personalityindex directive. */
3546
3547 static void
3548 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3549 {
3550 expressionS exp;
3551
3552 if (!unwind.proc_start)
3553 as_bad (MISSING_FNSTART);
3554
3555 if (unwind.personality_routine || unwind.personality_index != -1)
3556 as_bad (_("duplicate .personalityindex directive"));
3557
3558 expression (&exp);
3559
3560 if (exp.X_op != O_constant
3561 || exp.X_add_number < 0 || exp.X_add_number > 15)
3562 {
3563 as_bad (_("bad personality routine number"));
3564 ignore_rest_of_line ();
3565 return;
3566 }
3567
3568 unwind.personality_index = exp.X_add_number;
3569
3570 demand_empty_rest_of_line ();
3571 }
3572
3573
3574 /* Parse a personality directive. */
3575
3576 static void
3577 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3578 {
3579 char *name, *p, c;
3580
3581 if (!unwind.proc_start)
3582 as_bad (MISSING_FNSTART);
3583
3584 if (unwind.personality_routine || unwind.personality_index != -1)
3585 as_bad (_("duplicate .personality directive"));
3586
3587 name = input_line_pointer;
3588 c = get_symbol_end ();
3589 p = input_line_pointer;
3590 unwind.personality_routine = symbol_find_or_make (name);
3591 *p = c;
3592 demand_empty_rest_of_line ();
3593 }
3594
3595
3596 /* Parse a directive saving core registers. */
3597
3598 static void
3599 s_arm_unwind_save_core (void)
3600 {
3601 valueT op;
3602 long range;
3603 int n;
3604
3605 range = parse_reg_list (&input_line_pointer);
3606 if (range == FAIL)
3607 {
3608 as_bad (_("expected register list"));
3609 ignore_rest_of_line ();
3610 return;
3611 }
3612
3613 demand_empty_rest_of_line ();
3614
3615 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3616 into .unwind_save {..., sp...}. We aren't bothered about the value of
3617 ip because it is clobbered by calls. */
3618 if (unwind.sp_restored && unwind.fp_reg == 12
3619 && (range & 0x3000) == 0x1000)
3620 {
3621 unwind.opcode_count--;
3622 unwind.sp_restored = 0;
3623 range = (range | 0x2000) & ~0x1000;
3624 unwind.pending_offset = 0;
3625 }
3626
3627 /* Pop r4-r15. */
3628 if (range & 0xfff0)
3629 {
3630 /* See if we can use the short opcodes. These pop a block of up to 8
3631 registers starting with r4, plus maybe r14. */
3632 for (n = 0; n < 8; n++)
3633 {
3634 /* Break at the first non-saved register. */
3635 if ((range & (1 << (n + 4))) == 0)
3636 break;
3637 }
3638 /* See if there are any other bits set. */
3639 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3640 {
3641 /* Use the long form. */
3642 op = 0x8000 | ((range >> 4) & 0xfff);
3643 add_unwind_opcode (op, 2);
3644 }
3645 else
3646 {
3647 /* Use the short form. */
3648 if (range & 0x4000)
3649 op = 0xa8; /* Pop r14. */
3650 else
3651 op = 0xa0; /* Do not pop r14. */
3652 op |= (n - 1);
3653 add_unwind_opcode (op, 1);
3654 }
3655 }
3656
3657 /* Pop r0-r3. */
3658 if (range & 0xf)
3659 {
3660 op = 0xb100 | (range & 0xf);
3661 add_unwind_opcode (op, 2);
3662 }
3663
3664 /* Record the number of bytes pushed. */
3665 for (n = 0; n < 16; n++)
3666 {
3667 if (range & (1 << n))
3668 unwind.frame_size += 4;
3669 }
3670 }
3671
3672
3673 /* Parse a directive saving FPA registers. */
3674
3675 static void
3676 s_arm_unwind_save_fpa (int reg)
3677 {
3678 expressionS exp;
3679 int num_regs;
3680 valueT op;
3681
3682 /* Get Number of registers to transfer. */
3683 if (skip_past_comma (&input_line_pointer) != FAIL)
3684 expression (&exp);
3685 else
3686 exp.X_op = O_illegal;
3687
3688 if (exp.X_op != O_constant)
3689 {
3690 as_bad (_("expected , <constant>"));
3691 ignore_rest_of_line ();
3692 return;
3693 }
3694
3695 num_regs = exp.X_add_number;
3696
3697 if (num_regs < 1 || num_regs > 4)
3698 {
3699 as_bad (_("number of registers must be in the range [1:4]"));
3700 ignore_rest_of_line ();
3701 return;
3702 }
3703
3704 demand_empty_rest_of_line ();
3705
3706 if (reg == 4)
3707 {
3708 /* Short form. */
3709 op = 0xb4 | (num_regs - 1);
3710 add_unwind_opcode (op, 1);
3711 }
3712 else
3713 {
3714 /* Long form. */
3715 op = 0xc800 | (reg << 4) | (num_regs - 1);
3716 add_unwind_opcode (op, 2);
3717 }
3718 unwind.frame_size += num_regs * 12;
3719 }
3720
3721
3722 /* Parse a directive saving VFP registers for ARMv6 and above. */
3723
3724 static void
3725 s_arm_unwind_save_vfp_armv6 (void)
3726 {
3727 int count;
3728 unsigned int start;
3729 valueT op;
3730 int num_vfpv3_regs = 0;
3731 int num_regs_below_16;
3732
3733 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3734 if (count == FAIL)
3735 {
3736 as_bad (_("expected register list"));
3737 ignore_rest_of_line ();
3738 return;
3739 }
3740
3741 demand_empty_rest_of_line ();
3742
3743 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3744 than FSTMX/FLDMX-style ones). */
3745
3746 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3747 if (start >= 16)
3748 num_vfpv3_regs = count;
3749 else if (start + count > 16)
3750 num_vfpv3_regs = start + count - 16;
3751
3752 if (num_vfpv3_regs > 0)
3753 {
3754 int start_offset = start > 16 ? start - 16 : 0;
3755 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3756 add_unwind_opcode (op, 2);
3757 }
3758
3759 /* Generate opcode for registers numbered in the range 0 .. 15. */
3760 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3761 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
3762 if (num_regs_below_16 > 0)
3763 {
3764 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3765 add_unwind_opcode (op, 2);
3766 }
3767
3768 unwind.frame_size += count * 8;
3769 }
3770
3771
3772 /* Parse a directive saving VFP registers for pre-ARMv6. */
3773
3774 static void
3775 s_arm_unwind_save_vfp (void)
3776 {
3777 int count;
3778 unsigned int reg;
3779 valueT op;
3780
3781 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
3782 if (count == FAIL)
3783 {
3784 as_bad (_("expected register list"));
3785 ignore_rest_of_line ();
3786 return;
3787 }
3788
3789 demand_empty_rest_of_line ();
3790
3791 if (reg == 8)
3792 {
3793 /* Short form. */
3794 op = 0xb8 | (count - 1);
3795 add_unwind_opcode (op, 1);
3796 }
3797 else
3798 {
3799 /* Long form. */
3800 op = 0xb300 | (reg << 4) | (count - 1);
3801 add_unwind_opcode (op, 2);
3802 }
3803 unwind.frame_size += count * 8 + 4;
3804 }
3805
3806
3807 /* Parse a directive saving iWMMXt data registers. */
3808
3809 static void
3810 s_arm_unwind_save_mmxwr (void)
3811 {
3812 int reg;
3813 int hi_reg;
3814 int i;
3815 unsigned mask = 0;
3816 valueT op;
3817
3818 if (*input_line_pointer == '{')
3819 input_line_pointer++;
3820
3821 do
3822 {
3823 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3824
3825 if (reg == FAIL)
3826 {
3827 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3828 goto error;
3829 }
3830
3831 if (mask >> reg)
3832 as_tsktsk (_("register list not in ascending order"));
3833 mask |= 1 << reg;
3834
3835 if (*input_line_pointer == '-')
3836 {
3837 input_line_pointer++;
3838 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3839 if (hi_reg == FAIL)
3840 {
3841 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3842 goto error;
3843 }
3844 else if (reg >= hi_reg)
3845 {
3846 as_bad (_("bad register range"));
3847 goto error;
3848 }
3849 for (; reg < hi_reg; reg++)
3850 mask |= 1 << reg;
3851 }
3852 }
3853 while (skip_past_comma (&input_line_pointer) != FAIL);
3854
3855 if (*input_line_pointer == '}')
3856 input_line_pointer++;
3857
3858 demand_empty_rest_of_line ();
3859
3860 /* Generate any deferred opcodes because we're going to be looking at
3861 the list. */
3862 flush_pending_unwind ();
3863
3864 for (i = 0; i < 16; i++)
3865 {
3866 if (mask & (1 << i))
3867 unwind.frame_size += 8;
3868 }
3869
3870 /* Attempt to combine with a previous opcode. We do this because gcc
3871 likes to output separate unwind directives for a single block of
3872 registers. */
3873 if (unwind.opcode_count > 0)
3874 {
3875 i = unwind.opcodes[unwind.opcode_count - 1];
3876 if ((i & 0xf8) == 0xc0)
3877 {
3878 i &= 7;
3879 /* Only merge if the blocks are contiguous. */
3880 if (i < 6)
3881 {
3882 if ((mask & 0xfe00) == (1 << 9))
3883 {
3884 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3885 unwind.opcode_count--;
3886 }
3887 }
3888 else if (i == 6 && unwind.opcode_count >= 2)
3889 {
3890 i = unwind.opcodes[unwind.opcode_count - 2];
3891 reg = i >> 4;
3892 i &= 0xf;
3893
3894 op = 0xffff << (reg - 1);
3895 if (reg > 0
3896 && ((mask & op) == (1u << (reg - 1))))
3897 {
3898 op = (1 << (reg + i + 1)) - 1;
3899 op &= ~((1 << reg) - 1);
3900 mask |= op;
3901 unwind.opcode_count -= 2;
3902 }
3903 }
3904 }
3905 }
3906
3907 hi_reg = 15;
3908 /* We want to generate opcodes in the order the registers have been
3909 saved, ie. descending order. */
3910 for (reg = 15; reg >= -1; reg--)
3911 {
3912 /* Save registers in blocks. */
3913 if (reg < 0
3914 || !(mask & (1 << reg)))
3915 {
3916 /* We found an unsaved reg. Generate opcodes to save the
3917 preceding block. */
3918 if (reg != hi_reg)
3919 {
3920 if (reg == 9)
3921 {
3922 /* Short form. */
3923 op = 0xc0 | (hi_reg - 10);
3924 add_unwind_opcode (op, 1);
3925 }
3926 else
3927 {
3928 /* Long form. */
3929 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3930 add_unwind_opcode (op, 2);
3931 }
3932 }
3933 hi_reg = reg - 1;
3934 }
3935 }
3936
3937 return;
3938 error:
3939 ignore_rest_of_line ();
3940 }
3941
3942 static void
3943 s_arm_unwind_save_mmxwcg (void)
3944 {
3945 int reg;
3946 int hi_reg;
3947 unsigned mask = 0;
3948 valueT op;
3949
3950 if (*input_line_pointer == '{')
3951 input_line_pointer++;
3952
3953 do
3954 {
3955 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3956
3957 if (reg == FAIL)
3958 {
3959 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
3960 goto error;
3961 }
3962
3963 reg -= 8;
3964 if (mask >> reg)
3965 as_tsktsk (_("register list not in ascending order"));
3966 mask |= 1 << reg;
3967
3968 if (*input_line_pointer == '-')
3969 {
3970 input_line_pointer++;
3971 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3972 if (hi_reg == FAIL)
3973 {
3974 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
3975 goto error;
3976 }
3977 else if (reg >= hi_reg)
3978 {
3979 as_bad (_("bad register range"));
3980 goto error;
3981 }
3982 for (; reg < hi_reg; reg++)
3983 mask |= 1 << reg;
3984 }
3985 }
3986 while (skip_past_comma (&input_line_pointer) != FAIL);
3987
3988 if (*input_line_pointer == '}')
3989 input_line_pointer++;
3990
3991 demand_empty_rest_of_line ();
3992
3993 /* Generate any deferred opcodes because we're going to be looking at
3994 the list. */
3995 flush_pending_unwind ();
3996
3997 for (reg = 0; reg < 16; reg++)
3998 {
3999 if (mask & (1 << reg))
4000 unwind.frame_size += 4;
4001 }
4002 op = 0xc700 | mask;
4003 add_unwind_opcode (op, 2);
4004 return;
4005 error:
4006 ignore_rest_of_line ();
4007 }
4008
4009
4010 /* Parse an unwind_save directive.
4011 If the argument is non-zero, this is a .vsave directive. */
4012
4013 static void
4014 s_arm_unwind_save (int arch_v6)
4015 {
4016 char *peek;
4017 struct reg_entry *reg;
4018 bfd_boolean had_brace = FALSE;
4019
4020 if (!unwind.proc_start)
4021 as_bad (MISSING_FNSTART);
4022
4023 /* Figure out what sort of save we have. */
4024 peek = input_line_pointer;
4025
4026 if (*peek == '{')
4027 {
4028 had_brace = TRUE;
4029 peek++;
4030 }
4031
4032 reg = arm_reg_parse_multi (&peek);
4033
4034 if (!reg)
4035 {
4036 as_bad (_("register expected"));
4037 ignore_rest_of_line ();
4038 return;
4039 }
4040
4041 switch (reg->type)
4042 {
4043 case REG_TYPE_FN:
4044 if (had_brace)
4045 {
4046 as_bad (_("FPA .unwind_save does not take a register list"));
4047 ignore_rest_of_line ();
4048 return;
4049 }
4050 input_line_pointer = peek;
4051 s_arm_unwind_save_fpa (reg->number);
4052 return;
4053
4054 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
4055 case REG_TYPE_VFD:
4056 if (arch_v6)
4057 s_arm_unwind_save_vfp_armv6 ();
4058 else
4059 s_arm_unwind_save_vfp ();
4060 return;
4061 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
4062 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
4063
4064 default:
4065 as_bad (_(".unwind_save does not support this kind of register"));
4066 ignore_rest_of_line ();
4067 }
4068 }
4069
4070
4071 /* Parse an unwind_movsp directive. */
4072
4073 static void
4074 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4075 {
4076 int reg;
4077 valueT op;
4078 int offset;
4079
4080 if (!unwind.proc_start)
4081 as_bad (MISSING_FNSTART);
4082
4083 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4084 if (reg == FAIL)
4085 {
4086 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
4087 ignore_rest_of_line ();
4088 return;
4089 }
4090
4091 /* Optional constant. */
4092 if (skip_past_comma (&input_line_pointer) != FAIL)
4093 {
4094 if (immediate_for_directive (&offset) == FAIL)
4095 return;
4096 }
4097 else
4098 offset = 0;
4099
4100 demand_empty_rest_of_line ();
4101
4102 if (reg == REG_SP || reg == REG_PC)
4103 {
4104 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
4105 return;
4106 }
4107
4108 if (unwind.fp_reg != REG_SP)
4109 as_bad (_("unexpected .unwind_movsp directive"));
4110
4111 /* Generate opcode to restore the value. */
4112 op = 0x90 | reg;
4113 add_unwind_opcode (op, 1);
4114
4115 /* Record the information for later. */
4116 unwind.fp_reg = reg;
4117 unwind.fp_offset = unwind.frame_size - offset;
4118 unwind.sp_restored = 1;
4119 }
4120
4121 /* Parse an unwind_pad directive. */
4122
4123 static void
4124 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
4125 {
4126 int offset;
4127
4128 if (!unwind.proc_start)
4129 as_bad (MISSING_FNSTART);
4130
4131 if (immediate_for_directive (&offset) == FAIL)
4132 return;
4133
4134 if (offset & 3)
4135 {
4136 as_bad (_("stack increment must be multiple of 4"));
4137 ignore_rest_of_line ();
4138 return;
4139 }
4140
4141 /* Don't generate any opcodes, just record the details for later. */
4142 unwind.frame_size += offset;
4143 unwind.pending_offset += offset;
4144
4145 demand_empty_rest_of_line ();
4146 }
4147
4148 /* Parse an unwind_setfp directive. */
4149
4150 static void
4151 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
4152 {
4153 int sp_reg;
4154 int fp_reg;
4155 int offset;
4156
4157 if (!unwind.proc_start)
4158 as_bad (MISSING_FNSTART);
4159
4160 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4161 if (skip_past_comma (&input_line_pointer) == FAIL)
4162 sp_reg = FAIL;
4163 else
4164 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4165
4166 if (fp_reg == FAIL || sp_reg == FAIL)
4167 {
4168 as_bad (_("expected <reg>, <reg>"));
4169 ignore_rest_of_line ();
4170 return;
4171 }
4172
4173 /* Optional constant. */
4174 if (skip_past_comma (&input_line_pointer) != FAIL)
4175 {
4176 if (immediate_for_directive (&offset) == FAIL)
4177 return;
4178 }
4179 else
4180 offset = 0;
4181
4182 demand_empty_rest_of_line ();
4183
4184 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
4185 {
4186 as_bad (_("register must be either sp or set by a previous"
4187 "unwind_movsp directive"));
4188 return;
4189 }
4190
4191 /* Don't generate any opcodes, just record the information for later. */
4192 unwind.fp_reg = fp_reg;
4193 unwind.fp_used = 1;
4194 if (sp_reg == REG_SP)
4195 unwind.fp_offset = unwind.frame_size - offset;
4196 else
4197 unwind.fp_offset -= offset;
4198 }
4199
4200 /* Parse an unwind_raw directive. */
4201
4202 static void
4203 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
4204 {
4205 expressionS exp;
4206 /* This is an arbitrary limit. */
4207 unsigned char op[16];
4208 int count;
4209
4210 if (!unwind.proc_start)
4211 as_bad (MISSING_FNSTART);
4212
4213 expression (&exp);
4214 if (exp.X_op == O_constant
4215 && skip_past_comma (&input_line_pointer) != FAIL)
4216 {
4217 unwind.frame_size += exp.X_add_number;
4218 expression (&exp);
4219 }
4220 else
4221 exp.X_op = O_illegal;
4222
4223 if (exp.X_op != O_constant)
4224 {
4225 as_bad (_("expected <offset>, <opcode>"));
4226 ignore_rest_of_line ();
4227 return;
4228 }
4229
4230 count = 0;
4231
4232 /* Parse the opcode. */
4233 for (;;)
4234 {
4235 if (count >= 16)
4236 {
4237 as_bad (_("unwind opcode too long"));
4238 ignore_rest_of_line ();
4239 }
4240 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
4241 {
4242 as_bad (_("invalid unwind opcode"));
4243 ignore_rest_of_line ();
4244 return;
4245 }
4246 op[count++] = exp.X_add_number;
4247
4248 /* Parse the next byte. */
4249 if (skip_past_comma (&input_line_pointer) == FAIL)
4250 break;
4251
4252 expression (&exp);
4253 }
4254
4255 /* Add the opcode bytes in reverse order. */
4256 while (count--)
4257 add_unwind_opcode (op[count], 1);
4258
4259 demand_empty_rest_of_line ();
4260 }
4261
4262
4263 /* Parse a .eabi_attribute directive. */
4264
4265 static void
4266 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4267 {
4268 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
4269
4270 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4271 attributes_set_explicitly[tag] = 1;
4272 }
4273 #endif /* OBJ_ELF */
4274
4275 static void s_arm_arch (int);
4276 static void s_arm_object_arch (int);
4277 static void s_arm_cpu (int);
4278 static void s_arm_fpu (int);
4279 static void s_arm_arch_extension (int);
4280
4281 #ifdef TE_PE
4282
4283 static void
4284 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
4285 {
4286 expressionS exp;
4287
4288 do
4289 {
4290 expression (&exp);
4291 if (exp.X_op == O_symbol)
4292 exp.X_op = O_secrel;
4293
4294 emit_expr (&exp, 4);
4295 }
4296 while (*input_line_pointer++ == ',');
4297
4298 input_line_pointer--;
4299 demand_empty_rest_of_line ();
4300 }
4301 #endif /* TE_PE */
4302
4303 /* This table describes all the machine specific pseudo-ops the assembler
4304 has to support. The fields are:
4305 pseudo-op name without dot
4306 function to call to execute this pseudo-op
4307 Integer arg to pass to the function. */
4308
4309 const pseudo_typeS md_pseudo_table[] =
4310 {
4311 /* Never called because '.req' does not start a line. */
4312 { "req", s_req, 0 },
4313 /* Following two are likewise never called. */
4314 { "dn", s_dn, 0 },
4315 { "qn", s_qn, 0 },
4316 { "unreq", s_unreq, 0 },
4317 { "bss", s_bss, 0 },
4318 { "align", s_align, 0 },
4319 { "arm", s_arm, 0 },
4320 { "thumb", s_thumb, 0 },
4321 { "code", s_code, 0 },
4322 { "force_thumb", s_force_thumb, 0 },
4323 { "thumb_func", s_thumb_func, 0 },
4324 { "thumb_set", s_thumb_set, 0 },
4325 { "even", s_even, 0 },
4326 { "ltorg", s_ltorg, 0 },
4327 { "pool", s_ltorg, 0 },
4328 { "syntax", s_syntax, 0 },
4329 { "cpu", s_arm_cpu, 0 },
4330 { "arch", s_arm_arch, 0 },
4331 { "object_arch", s_arm_object_arch, 0 },
4332 { "fpu", s_arm_fpu, 0 },
4333 { "arch_extension", s_arm_arch_extension, 0 },
4334 #ifdef OBJ_ELF
4335 { "word", s_arm_elf_cons, 4 },
4336 { "long", s_arm_elf_cons, 4 },
4337 { "inst.n", s_arm_elf_inst, 2 },
4338 { "inst.w", s_arm_elf_inst, 4 },
4339 { "inst", s_arm_elf_inst, 0 },
4340 { "rel31", s_arm_rel31, 0 },
4341 { "fnstart", s_arm_unwind_fnstart, 0 },
4342 { "fnend", s_arm_unwind_fnend, 0 },
4343 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4344 { "personality", s_arm_unwind_personality, 0 },
4345 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4346 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4347 { "save", s_arm_unwind_save, 0 },
4348 { "vsave", s_arm_unwind_save, 1 },
4349 { "movsp", s_arm_unwind_movsp, 0 },
4350 { "pad", s_arm_unwind_pad, 0 },
4351 { "setfp", s_arm_unwind_setfp, 0 },
4352 { "unwind_raw", s_arm_unwind_raw, 0 },
4353 { "eabi_attribute", s_arm_eabi_attribute, 0 },
4354 #else
4355 { "word", cons, 4},
4356
4357 /* These are used for dwarf. */
4358 {"2byte", cons, 2},
4359 {"4byte", cons, 4},
4360 {"8byte", cons, 8},
4361 /* These are used for dwarf2. */
4362 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4363 { "loc", dwarf2_directive_loc, 0 },
4364 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
4365 #endif
4366 { "extend", float_cons, 'x' },
4367 { "ldouble", float_cons, 'x' },
4368 { "packed", float_cons, 'p' },
4369 #ifdef TE_PE
4370 {"secrel32", pe_directive_secrel, 0},
4371 #endif
4372 { 0, 0, 0 }
4373 };
4374 \f
4375 /* Parser functions used exclusively in instruction operands. */
4376
4377 /* Generic immediate-value read function for use in insn parsing.
4378 STR points to the beginning of the immediate (the leading #);
4379 VAL receives the value; if the value is outside [MIN, MAX]
4380 issue an error. PREFIX_OPT is true if the immediate prefix is
4381 optional. */
4382
4383 static int
4384 parse_immediate (char **str, int *val, int min, int max,
4385 bfd_boolean prefix_opt)
4386 {
4387 expressionS exp;
4388 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4389 if (exp.X_op != O_constant)
4390 {
4391 inst.error = _("constant expression required");
4392 return FAIL;
4393 }
4394
4395 if (exp.X_add_number < min || exp.X_add_number > max)
4396 {
4397 inst.error = _("immediate value out of range");
4398 return FAIL;
4399 }
4400
4401 *val = exp.X_add_number;
4402 return SUCCESS;
4403 }
4404
4405 /* Less-generic immediate-value read function with the possibility of loading a
4406 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
4407 instructions. Puts the result directly in inst.operands[i]. */
4408
4409 static int
4410 parse_big_immediate (char **str, int i)
4411 {
4412 expressionS exp;
4413 char *ptr = *str;
4414
4415 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4416
4417 if (exp.X_op == O_constant)
4418 {
4419 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4420 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4421 O_constant. We have to be careful not to break compilation for
4422 32-bit X_add_number, though. */
4423 if ((exp.X_add_number & ~0xffffffffl) != 0)
4424 {
4425 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4426 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4427 inst.operands[i].regisimm = 1;
4428 }
4429 }
4430 else if (exp.X_op == O_big
4431 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32)
4432 {
4433 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4434
4435 /* Bignums have their least significant bits in
4436 generic_bignum[0]. Make sure we put 32 bits in imm and
4437 32 bits in reg, in a (hopefully) portable way. */
4438 gas_assert (parts != 0);
4439
4440 /* Make sure that the number is not too big.
4441 PR 11972: Bignums can now be sign-extended to the
4442 size of a .octa so check that the out of range bits
4443 are all zero or all one. */
4444 if (LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 64)
4445 {
4446 LITTLENUM_TYPE m = -1;
4447
4448 if (generic_bignum[parts * 2] != 0
4449 && generic_bignum[parts * 2] != m)
4450 return FAIL;
4451
4452 for (j = parts * 2 + 1; j < (unsigned) exp.X_add_number; j++)
4453 if (generic_bignum[j] != generic_bignum[j-1])
4454 return FAIL;
4455 }
4456
4457 inst.operands[i].imm = 0;
4458 for (j = 0; j < parts; j++, idx++)
4459 inst.operands[i].imm |= generic_bignum[idx]
4460 << (LITTLENUM_NUMBER_OF_BITS * j);
4461 inst.operands[i].reg = 0;
4462 for (j = 0; j < parts; j++, idx++)
4463 inst.operands[i].reg |= generic_bignum[idx]
4464 << (LITTLENUM_NUMBER_OF_BITS * j);
4465 inst.operands[i].regisimm = 1;
4466 }
4467 else
4468 return FAIL;
4469
4470 *str = ptr;
4471
4472 return SUCCESS;
4473 }
4474
4475 /* Returns the pseudo-register number of an FPA immediate constant,
4476 or FAIL if there isn't a valid constant here. */
4477
4478 static int
4479 parse_fpa_immediate (char ** str)
4480 {
4481 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4482 char * save_in;
4483 expressionS exp;
4484 int i;
4485 int j;
4486
4487 /* First try and match exact strings, this is to guarantee
4488 that some formats will work even for cross assembly. */
4489
4490 for (i = 0; fp_const[i]; i++)
4491 {
4492 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4493 {
4494 char *start = *str;
4495
4496 *str += strlen (fp_const[i]);
4497 if (is_end_of_line[(unsigned char) **str])
4498 return i + 8;
4499 *str = start;
4500 }
4501 }
4502
4503 /* Just because we didn't get a match doesn't mean that the constant
4504 isn't valid, just that it is in a format that we don't
4505 automatically recognize. Try parsing it with the standard
4506 expression routines. */
4507
4508 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
4509
4510 /* Look for a raw floating point number. */
4511 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4512 && is_end_of_line[(unsigned char) *save_in])
4513 {
4514 for (i = 0; i < NUM_FLOAT_VALS; i++)
4515 {
4516 for (j = 0; j < MAX_LITTLENUMS; j++)
4517 {
4518 if (words[j] != fp_values[i][j])
4519 break;
4520 }
4521
4522 if (j == MAX_LITTLENUMS)
4523 {
4524 *str = save_in;
4525 return i + 8;
4526 }
4527 }
4528 }
4529
4530 /* Try and parse a more complex expression, this will probably fail
4531 unless the code uses a floating point prefix (eg "0f"). */
4532 save_in = input_line_pointer;
4533 input_line_pointer = *str;
4534 if (expression (&exp) == absolute_section
4535 && exp.X_op == O_big
4536 && exp.X_add_number < 0)
4537 {
4538 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4539 Ditto for 15. */
4540 if (gen_to_words (words, 5, (long) 15) == 0)
4541 {
4542 for (i = 0; i < NUM_FLOAT_VALS; i++)
4543 {
4544 for (j = 0; j < MAX_LITTLENUMS; j++)
4545 {
4546 if (words[j] != fp_values[i][j])
4547 break;
4548 }
4549
4550 if (j == MAX_LITTLENUMS)
4551 {
4552 *str = input_line_pointer;
4553 input_line_pointer = save_in;
4554 return i + 8;
4555 }
4556 }
4557 }
4558 }
4559
4560 *str = input_line_pointer;
4561 input_line_pointer = save_in;
4562 inst.error = _("invalid FPA immediate expression");
4563 return FAIL;
4564 }
4565
4566 /* Returns 1 if a number has "quarter-precision" float format
4567 0baBbbbbbc defgh000 00000000 00000000. */
4568
4569 static int
4570 is_quarter_float (unsigned imm)
4571 {
4572 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4573 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4574 }
4575
4576 /* Parse an 8-bit "quarter-precision" floating point number of the form:
4577 0baBbbbbbc defgh000 00000000 00000000.
4578 The zero and minus-zero cases need special handling, since they can't be
4579 encoded in the "quarter-precision" float format, but can nonetheless be
4580 loaded as integer constants. */
4581
4582 static unsigned
4583 parse_qfloat_immediate (char **ccp, int *immed)
4584 {
4585 char *str = *ccp;
4586 char *fpnum;
4587 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4588 int found_fpchar = 0;
4589
4590 skip_past_char (&str, '#');
4591
4592 /* We must not accidentally parse an integer as a floating-point number. Make
4593 sure that the value we parse is not an integer by checking for special
4594 characters '.' or 'e'.
4595 FIXME: This is a horrible hack, but doing better is tricky because type
4596 information isn't in a very usable state at parse time. */
4597 fpnum = str;
4598 skip_whitespace (fpnum);
4599
4600 if (strncmp (fpnum, "0x", 2) == 0)
4601 return FAIL;
4602 else
4603 {
4604 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4605 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4606 {
4607 found_fpchar = 1;
4608 break;
4609 }
4610
4611 if (!found_fpchar)
4612 return FAIL;
4613 }
4614
4615 if ((str = atof_ieee (str, 's', words)) != NULL)
4616 {
4617 unsigned fpword = 0;
4618 int i;
4619
4620 /* Our FP word must be 32 bits (single-precision FP). */
4621 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4622 {
4623 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4624 fpword |= words[i];
4625 }
4626
4627 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
4628 *immed = fpword;
4629 else
4630 return FAIL;
4631
4632 *ccp = str;
4633
4634 return SUCCESS;
4635 }
4636
4637 return FAIL;
4638 }
4639
4640 /* Shift operands. */
4641 enum shift_kind
4642 {
4643 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4644 };
4645
4646 struct asm_shift_name
4647 {
4648 const char *name;
4649 enum shift_kind kind;
4650 };
4651
4652 /* Third argument to parse_shift. */
4653 enum parse_shift_mode
4654 {
4655 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4656 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4657 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4658 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4659 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4660 };
4661
4662 /* Parse a <shift> specifier on an ARM data processing instruction.
4663 This has three forms:
4664
4665 (LSL|LSR|ASL|ASR|ROR) Rs
4666 (LSL|LSR|ASL|ASR|ROR) #imm
4667 RRX
4668
4669 Note that ASL is assimilated to LSL in the instruction encoding, and
4670 RRX to ROR #0 (which cannot be written as such). */
4671
4672 static int
4673 parse_shift (char **str, int i, enum parse_shift_mode mode)
4674 {
4675 const struct asm_shift_name *shift_name;
4676 enum shift_kind shift;
4677 char *s = *str;
4678 char *p = s;
4679 int reg;
4680
4681 for (p = *str; ISALPHA (*p); p++)
4682 ;
4683
4684 if (p == *str)
4685 {
4686 inst.error = _("shift expression expected");
4687 return FAIL;
4688 }
4689
4690 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
4691 p - *str);
4692
4693 if (shift_name == NULL)
4694 {
4695 inst.error = _("shift expression expected");
4696 return FAIL;
4697 }
4698
4699 shift = shift_name->kind;
4700
4701 switch (mode)
4702 {
4703 case NO_SHIFT_RESTRICT:
4704 case SHIFT_IMMEDIATE: break;
4705
4706 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4707 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4708 {
4709 inst.error = _("'LSL' or 'ASR' required");
4710 return FAIL;
4711 }
4712 break;
4713
4714 case SHIFT_LSL_IMMEDIATE:
4715 if (shift != SHIFT_LSL)
4716 {
4717 inst.error = _("'LSL' required");
4718 return FAIL;
4719 }
4720 break;
4721
4722 case SHIFT_ASR_IMMEDIATE:
4723 if (shift != SHIFT_ASR)
4724 {
4725 inst.error = _("'ASR' required");
4726 return FAIL;
4727 }
4728 break;
4729
4730 default: abort ();
4731 }
4732
4733 if (shift != SHIFT_RRX)
4734 {
4735 /* Whitespace can appear here if the next thing is a bare digit. */
4736 skip_whitespace (p);
4737
4738 if (mode == NO_SHIFT_RESTRICT
4739 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4740 {
4741 inst.operands[i].imm = reg;
4742 inst.operands[i].immisreg = 1;
4743 }
4744 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4745 return FAIL;
4746 }
4747 inst.operands[i].shift_kind = shift;
4748 inst.operands[i].shifted = 1;
4749 *str = p;
4750 return SUCCESS;
4751 }
4752
4753 /* Parse a <shifter_operand> for an ARM data processing instruction:
4754
4755 #<immediate>
4756 #<immediate>, <rotate>
4757 <Rm>
4758 <Rm>, <shift>
4759
4760 where <shift> is defined by parse_shift above, and <rotate> is a
4761 multiple of 2 between 0 and 30. Validation of immediate operands
4762 is deferred to md_apply_fix. */
4763
4764 static int
4765 parse_shifter_operand (char **str, int i)
4766 {
4767 int value;
4768 expressionS exp;
4769
4770 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
4771 {
4772 inst.operands[i].reg = value;
4773 inst.operands[i].isreg = 1;
4774
4775 /* parse_shift will override this if appropriate */
4776 inst.reloc.exp.X_op = O_constant;
4777 inst.reloc.exp.X_add_number = 0;
4778
4779 if (skip_past_comma (str) == FAIL)
4780 return SUCCESS;
4781
4782 /* Shift operation on register. */
4783 return parse_shift (str, i, NO_SHIFT_RESTRICT);
4784 }
4785
4786 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4787 return FAIL;
4788
4789 if (skip_past_comma (str) == SUCCESS)
4790 {
4791 /* #x, y -- ie explicit rotation by Y. */
4792 if (my_get_expression (&exp, str, GE_NO_PREFIX))
4793 return FAIL;
4794
4795 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4796 {
4797 inst.error = _("constant expression expected");
4798 return FAIL;
4799 }
4800
4801 value = exp.X_add_number;
4802 if (value < 0 || value > 30 || value % 2 != 0)
4803 {
4804 inst.error = _("invalid rotation");
4805 return FAIL;
4806 }
4807 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4808 {
4809 inst.error = _("invalid constant");
4810 return FAIL;
4811 }
4812
4813 /* Convert to decoded value. md_apply_fix will put it back. */
4814 inst.reloc.exp.X_add_number
4815 = (((inst.reloc.exp.X_add_number << (32 - value))
4816 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
4817 }
4818
4819 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4820 inst.reloc.pc_rel = 0;
4821 return SUCCESS;
4822 }
4823
4824 /* Group relocation information. Each entry in the table contains the
4825 textual name of the relocation as may appear in assembler source
4826 and must end with a colon.
4827 Along with this textual name are the relocation codes to be used if
4828 the corresponding instruction is an ALU instruction (ADD or SUB only),
4829 an LDR, an LDRS, or an LDC. */
4830
4831 struct group_reloc_table_entry
4832 {
4833 const char *name;
4834 int alu_code;
4835 int ldr_code;
4836 int ldrs_code;
4837 int ldc_code;
4838 };
4839
4840 typedef enum
4841 {
4842 /* Varieties of non-ALU group relocation. */
4843
4844 GROUP_LDR,
4845 GROUP_LDRS,
4846 GROUP_LDC
4847 } group_reloc_type;
4848
4849 static struct group_reloc_table_entry group_reloc_table[] =
4850 { /* Program counter relative: */
4851 { "pc_g0_nc",
4852 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4853 0, /* LDR */
4854 0, /* LDRS */
4855 0 }, /* LDC */
4856 { "pc_g0",
4857 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4858 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4859 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4860 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4861 { "pc_g1_nc",
4862 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4863 0, /* LDR */
4864 0, /* LDRS */
4865 0 }, /* LDC */
4866 { "pc_g1",
4867 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4868 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4869 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4870 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4871 { "pc_g2",
4872 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4873 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4874 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4875 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4876 /* Section base relative */
4877 { "sb_g0_nc",
4878 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4879 0, /* LDR */
4880 0, /* LDRS */
4881 0 }, /* LDC */
4882 { "sb_g0",
4883 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4884 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4885 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4886 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4887 { "sb_g1_nc",
4888 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4889 0, /* LDR */
4890 0, /* LDRS */
4891 0 }, /* LDC */
4892 { "sb_g1",
4893 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4894 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4895 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4896 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4897 { "sb_g2",
4898 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4899 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4900 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4901 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4902
4903 /* Given the address of a pointer pointing to the textual name of a group
4904 relocation as may appear in assembler source, attempt to find its details
4905 in group_reloc_table. The pointer will be updated to the character after
4906 the trailing colon. On failure, FAIL will be returned; SUCCESS
4907 otherwise. On success, *entry will be updated to point at the relevant
4908 group_reloc_table entry. */
4909
4910 static int
4911 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4912 {
4913 unsigned int i;
4914 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4915 {
4916 int length = strlen (group_reloc_table[i].name);
4917
4918 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4919 && (*str)[length] == ':')
4920 {
4921 *out = &group_reloc_table[i];
4922 *str += (length + 1);
4923 return SUCCESS;
4924 }
4925 }
4926
4927 return FAIL;
4928 }
4929
4930 /* Parse a <shifter_operand> for an ARM data processing instruction
4931 (as for parse_shifter_operand) where group relocations are allowed:
4932
4933 #<immediate>
4934 #<immediate>, <rotate>
4935 #:<group_reloc>:<expression>
4936 <Rm>
4937 <Rm>, <shift>
4938
4939 where <group_reloc> is one of the strings defined in group_reloc_table.
4940 The hashes are optional.
4941
4942 Everything else is as for parse_shifter_operand. */
4943
4944 static parse_operand_result
4945 parse_shifter_operand_group_reloc (char **str, int i)
4946 {
4947 /* Determine if we have the sequence of characters #: or just :
4948 coming next. If we do, then we check for a group relocation.
4949 If we don't, punt the whole lot to parse_shifter_operand. */
4950
4951 if (((*str)[0] == '#' && (*str)[1] == ':')
4952 || (*str)[0] == ':')
4953 {
4954 struct group_reloc_table_entry *entry;
4955
4956 if ((*str)[0] == '#')
4957 (*str) += 2;
4958 else
4959 (*str)++;
4960
4961 /* Try to parse a group relocation. Anything else is an error. */
4962 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4963 {
4964 inst.error = _("unknown group relocation");
4965 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4966 }
4967
4968 /* We now have the group relocation table entry corresponding to
4969 the name in the assembler source. Next, we parse the expression. */
4970 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4971 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4972
4973 /* Record the relocation type (always the ALU variant here). */
4974 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
4975 gas_assert (inst.reloc.type != 0);
4976
4977 return PARSE_OPERAND_SUCCESS;
4978 }
4979 else
4980 return parse_shifter_operand (str, i) == SUCCESS
4981 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4982
4983 /* Never reached. */
4984 }
4985
4986 /* Parse a Neon alignment expression. Information is written to
4987 inst.operands[i]. We assume the initial ':' has been skipped.
4988
4989 align .imm = align << 8, .immisalign=1, .preind=0 */
4990 static parse_operand_result
4991 parse_neon_alignment (char **str, int i)
4992 {
4993 char *p = *str;
4994 expressionS exp;
4995
4996 my_get_expression (&exp, &p, GE_NO_PREFIX);
4997
4998 if (exp.X_op != O_constant)
4999 {
5000 inst.error = _("alignment must be constant");
5001 return PARSE_OPERAND_FAIL;
5002 }
5003
5004 inst.operands[i].imm = exp.X_add_number << 8;
5005 inst.operands[i].immisalign = 1;
5006 /* Alignments are not pre-indexes. */
5007 inst.operands[i].preind = 0;
5008
5009 *str = p;
5010 return PARSE_OPERAND_SUCCESS;
5011 }
5012
5013 /* Parse all forms of an ARM address expression. Information is written
5014 to inst.operands[i] and/or inst.reloc.
5015
5016 Preindexed addressing (.preind=1):
5017
5018 [Rn, #offset] .reg=Rn .reloc.exp=offset
5019 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5020 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5021 .shift_kind=shift .reloc.exp=shift_imm
5022
5023 These three may have a trailing ! which causes .writeback to be set also.
5024
5025 Postindexed addressing (.postind=1, .writeback=1):
5026
5027 [Rn], #offset .reg=Rn .reloc.exp=offset
5028 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5029 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5030 .shift_kind=shift .reloc.exp=shift_imm
5031
5032 Unindexed addressing (.preind=0, .postind=0):
5033
5034 [Rn], {option} .reg=Rn .imm=option .immisreg=0
5035
5036 Other:
5037
5038 [Rn]{!} shorthand for [Rn,#0]{!}
5039 =immediate .isreg=0 .reloc.exp=immediate
5040 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
5041
5042 It is the caller's responsibility to check for addressing modes not
5043 supported by the instruction, and to set inst.reloc.type. */
5044
5045 static parse_operand_result
5046 parse_address_main (char **str, int i, int group_relocations,
5047 group_reloc_type group_type)
5048 {
5049 char *p = *str;
5050 int reg;
5051
5052 if (skip_past_char (&p, '[') == FAIL)
5053 {
5054 if (skip_past_char (&p, '=') == FAIL)
5055 {
5056 /* Bare address - translate to PC-relative offset. */
5057 inst.reloc.pc_rel = 1;
5058 inst.operands[i].reg = REG_PC;
5059 inst.operands[i].isreg = 1;
5060 inst.operands[i].preind = 1;
5061 }
5062 /* Otherwise a load-constant pseudo op, no special treatment needed here. */
5063
5064 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5065 return PARSE_OPERAND_FAIL;
5066
5067 *str = p;
5068 return PARSE_OPERAND_SUCCESS;
5069 }
5070
5071 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5072 {
5073 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5074 return PARSE_OPERAND_FAIL;
5075 }
5076 inst.operands[i].reg = reg;
5077 inst.operands[i].isreg = 1;
5078
5079 if (skip_past_comma (&p) == SUCCESS)
5080 {
5081 inst.operands[i].preind = 1;
5082
5083 if (*p == '+') p++;
5084 else if (*p == '-') p++, inst.operands[i].negative = 1;
5085
5086 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5087 {
5088 inst.operands[i].imm = reg;
5089 inst.operands[i].immisreg = 1;
5090
5091 if (skip_past_comma (&p) == SUCCESS)
5092 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5093 return PARSE_OPERAND_FAIL;
5094 }
5095 else if (skip_past_char (&p, ':') == SUCCESS)
5096 {
5097 /* FIXME: '@' should be used here, but it's filtered out by generic
5098 code before we get to see it here. This may be subject to
5099 change. */
5100 parse_operand_result result = parse_neon_alignment (&p, i);
5101
5102 if (result != PARSE_OPERAND_SUCCESS)
5103 return result;
5104 }
5105 else
5106 {
5107 if (inst.operands[i].negative)
5108 {
5109 inst.operands[i].negative = 0;
5110 p--;
5111 }
5112
5113 if (group_relocations
5114 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
5115 {
5116 struct group_reloc_table_entry *entry;
5117
5118 /* Skip over the #: or : sequence. */
5119 if (*p == '#')
5120 p += 2;
5121 else
5122 p++;
5123
5124 /* Try to parse a group relocation. Anything else is an
5125 error. */
5126 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5127 {
5128 inst.error = _("unknown group relocation");
5129 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5130 }
5131
5132 /* We now have the group relocation table entry corresponding to
5133 the name in the assembler source. Next, we parse the
5134 expression. */
5135 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5136 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5137
5138 /* Record the relocation type. */
5139 switch (group_type)
5140 {
5141 case GROUP_LDR:
5142 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5143 break;
5144
5145 case GROUP_LDRS:
5146 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5147 break;
5148
5149 case GROUP_LDC:
5150 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5151 break;
5152
5153 default:
5154 gas_assert (0);
5155 }
5156
5157 if (inst.reloc.type == 0)
5158 {
5159 inst.error = _("this group relocation is not allowed on this instruction");
5160 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5161 }
5162 }
5163 else
5164 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5165 return PARSE_OPERAND_FAIL;
5166 }
5167 }
5168 else if (skip_past_char (&p, ':') == SUCCESS)
5169 {
5170 /* FIXME: '@' should be used here, but it's filtered out by generic code
5171 before we get to see it here. This may be subject to change. */
5172 parse_operand_result result = parse_neon_alignment (&p, i);
5173
5174 if (result != PARSE_OPERAND_SUCCESS)
5175 return result;
5176 }
5177
5178 if (skip_past_char (&p, ']') == FAIL)
5179 {
5180 inst.error = _("']' expected");
5181 return PARSE_OPERAND_FAIL;
5182 }
5183
5184 if (skip_past_char (&p, '!') == SUCCESS)
5185 inst.operands[i].writeback = 1;
5186
5187 else if (skip_past_comma (&p) == SUCCESS)
5188 {
5189 if (skip_past_char (&p, '{') == SUCCESS)
5190 {
5191 /* [Rn], {expr} - unindexed, with option */
5192 if (parse_immediate (&p, &inst.operands[i].imm,
5193 0, 255, TRUE) == FAIL)
5194 return PARSE_OPERAND_FAIL;
5195
5196 if (skip_past_char (&p, '}') == FAIL)
5197 {
5198 inst.error = _("'}' expected at end of 'option' field");
5199 return PARSE_OPERAND_FAIL;
5200 }
5201 if (inst.operands[i].preind)
5202 {
5203 inst.error = _("cannot combine index with option");
5204 return PARSE_OPERAND_FAIL;
5205 }
5206 *str = p;
5207 return PARSE_OPERAND_SUCCESS;
5208 }
5209 else
5210 {
5211 inst.operands[i].postind = 1;
5212 inst.operands[i].writeback = 1;
5213
5214 if (inst.operands[i].preind)
5215 {
5216 inst.error = _("cannot combine pre- and post-indexing");
5217 return PARSE_OPERAND_FAIL;
5218 }
5219
5220 if (*p == '+') p++;
5221 else if (*p == '-') p++, inst.operands[i].negative = 1;
5222
5223 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5224 {
5225 /* We might be using the immediate for alignment already. If we
5226 are, OR the register number into the low-order bits. */
5227 if (inst.operands[i].immisalign)
5228 inst.operands[i].imm |= reg;
5229 else
5230 inst.operands[i].imm = reg;
5231 inst.operands[i].immisreg = 1;
5232
5233 if (skip_past_comma (&p) == SUCCESS)
5234 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5235 return PARSE_OPERAND_FAIL;
5236 }
5237 else
5238 {
5239 if (inst.operands[i].negative)
5240 {
5241 inst.operands[i].negative = 0;
5242 p--;
5243 }
5244 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5245 return PARSE_OPERAND_FAIL;
5246 }
5247 }
5248 }
5249
5250 /* If at this point neither .preind nor .postind is set, we have a
5251 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5252 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5253 {
5254 inst.operands[i].preind = 1;
5255 inst.reloc.exp.X_op = O_constant;
5256 inst.reloc.exp.X_add_number = 0;
5257 }
5258 *str = p;
5259 return PARSE_OPERAND_SUCCESS;
5260 }
5261
5262 static int
5263 parse_address (char **str, int i)
5264 {
5265 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
5266 ? SUCCESS : FAIL;
5267 }
5268
5269 static parse_operand_result
5270 parse_address_group_reloc (char **str, int i, group_reloc_type type)
5271 {
5272 return parse_address_main (str, i, 1, type);
5273 }
5274
5275 /* Parse an operand for a MOVW or MOVT instruction. */
5276 static int
5277 parse_half (char **str)
5278 {
5279 char * p;
5280
5281 p = *str;
5282 skip_past_char (&p, '#');
5283 if (strncasecmp (p, ":lower16:", 9) == 0)
5284 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5285 else if (strncasecmp (p, ":upper16:", 9) == 0)
5286 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5287
5288 if (inst.reloc.type != BFD_RELOC_UNUSED)
5289 {
5290 p += 9;
5291 skip_whitespace (p);
5292 }
5293
5294 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5295 return FAIL;
5296
5297 if (inst.reloc.type == BFD_RELOC_UNUSED)
5298 {
5299 if (inst.reloc.exp.X_op != O_constant)
5300 {
5301 inst.error = _("constant expression expected");
5302 return FAIL;
5303 }
5304 if (inst.reloc.exp.X_add_number < 0
5305 || inst.reloc.exp.X_add_number > 0xffff)
5306 {
5307 inst.error = _("immediate value out of range");
5308 return FAIL;
5309 }
5310 }
5311 *str = p;
5312 return SUCCESS;
5313 }
5314
5315 /* Miscellaneous. */
5316
5317 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5318 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5319 static int
5320 parse_psr (char **str)
5321 {
5322 char *p;
5323 unsigned long psr_field;
5324 const struct asm_psr *psr;
5325 char *start;
5326
5327 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5328 feature for ease of use and backwards compatibility. */
5329 p = *str;
5330 if (strncasecmp (p, "SPSR", 4) == 0)
5331 psr_field = SPSR_BIT;
5332 else if (strncasecmp (p, "CPSR", 4) == 0
5333 || (strncasecmp (p, "APSR", 4) == 0
5334 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m)))
5335 psr_field = 0;
5336 else
5337 {
5338 start = p;
5339 do
5340 p++;
5341 while (ISALNUM (*p) || *p == '_');
5342
5343 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5344 p - start);
5345 if (!psr)
5346 return FAIL;
5347
5348 *str = p;
5349 return psr->field;
5350 }
5351
5352 p += 4;
5353 if (*p == '_')
5354 {
5355 /* A suffix follows. */
5356 p++;
5357 start = p;
5358
5359 do
5360 p++;
5361 while (ISALNUM (*p) || *p == '_');
5362
5363 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
5364 p - start);
5365 if (!psr)
5366 goto error;
5367
5368 psr_field |= psr->field;
5369 }
5370 else
5371 {
5372 if (ISALNUM (*p))
5373 goto error; /* Garbage after "[CS]PSR". */
5374
5375 psr_field |= (PSR_c | PSR_f);
5376 }
5377 *str = p;
5378 return psr_field;
5379
5380 error:
5381 inst.error = _("flag for {c}psr instruction expected");
5382 return FAIL;
5383 }
5384
5385 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5386 value suitable for splatting into the AIF field of the instruction. */
5387
5388 static int
5389 parse_cps_flags (char **str)
5390 {
5391 int val = 0;
5392 int saw_a_flag = 0;
5393 char *s = *str;
5394
5395 for (;;)
5396 switch (*s++)
5397 {
5398 case '\0': case ',':
5399 goto done;
5400
5401 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5402 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5403 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
5404
5405 default:
5406 inst.error = _("unrecognized CPS flag");
5407 return FAIL;
5408 }
5409
5410 done:
5411 if (saw_a_flag == 0)
5412 {
5413 inst.error = _("missing CPS flags");
5414 return FAIL;
5415 }
5416
5417 *str = s - 1;
5418 return val;
5419 }
5420
5421 /* Parse an endian specifier ("BE" or "LE", case insensitive);
5422 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
5423
5424 static int
5425 parse_endian_specifier (char **str)
5426 {
5427 int little_endian;
5428 char *s = *str;
5429
5430 if (strncasecmp (s, "BE", 2))
5431 little_endian = 0;
5432 else if (strncasecmp (s, "LE", 2))
5433 little_endian = 1;
5434 else
5435 {
5436 inst.error = _("valid endian specifiers are be or le");
5437 return FAIL;
5438 }
5439
5440 if (ISALNUM (s[2]) || s[2] == '_')
5441 {
5442 inst.error = _("valid endian specifiers are be or le");
5443 return FAIL;
5444 }
5445
5446 *str = s + 2;
5447 return little_endian;
5448 }
5449
5450 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5451 value suitable for poking into the rotate field of an sxt or sxta
5452 instruction, or FAIL on error. */
5453
5454 static int
5455 parse_ror (char **str)
5456 {
5457 int rot;
5458 char *s = *str;
5459
5460 if (strncasecmp (s, "ROR", 3) == 0)
5461 s += 3;
5462 else
5463 {
5464 inst.error = _("missing rotation field after comma");
5465 return FAIL;
5466 }
5467
5468 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5469 return FAIL;
5470
5471 switch (rot)
5472 {
5473 case 0: *str = s; return 0x0;
5474 case 8: *str = s; return 0x1;
5475 case 16: *str = s; return 0x2;
5476 case 24: *str = s; return 0x3;
5477
5478 default:
5479 inst.error = _("rotation can only be 0, 8, 16, or 24");
5480 return FAIL;
5481 }
5482 }
5483
5484 /* Parse a conditional code (from conds[] below). The value returned is in the
5485 range 0 .. 14, or FAIL. */
5486 static int
5487 parse_cond (char **str)
5488 {
5489 char *q;
5490 const struct asm_cond *c;
5491 int n;
5492 /* Condition codes are always 2 characters, so matching up to
5493 3 characters is sufficient. */
5494 char cond[3];
5495
5496 q = *str;
5497 n = 0;
5498 while (ISALPHA (*q) && n < 3)
5499 {
5500 cond[n] = TOLOWER (*q);
5501 q++;
5502 n++;
5503 }
5504
5505 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
5506 if (!c)
5507 {
5508 inst.error = _("condition required");
5509 return FAIL;
5510 }
5511
5512 *str = q;
5513 return c->value;
5514 }
5515
5516 /* Parse an option for a barrier instruction. Returns the encoding for the
5517 option, or FAIL. */
5518 static int
5519 parse_barrier (char **str)
5520 {
5521 char *p, *q;
5522 const struct asm_barrier_opt *o;
5523
5524 p = q = *str;
5525 while (ISALPHA (*q))
5526 q++;
5527
5528 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
5529 q - p);
5530 if (!o)
5531 return FAIL;
5532
5533 *str = q;
5534 return o->value;
5535 }
5536
5537 /* Parse the operands of a table branch instruction. Similar to a memory
5538 operand. */
5539 static int
5540 parse_tb (char **str)
5541 {
5542 char * p = *str;
5543 int reg;
5544
5545 if (skip_past_char (&p, '[') == FAIL)
5546 {
5547 inst.error = _("'[' expected");
5548 return FAIL;
5549 }
5550
5551 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5552 {
5553 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5554 return FAIL;
5555 }
5556 inst.operands[0].reg = reg;
5557
5558 if (skip_past_comma (&p) == FAIL)
5559 {
5560 inst.error = _("',' expected");
5561 return FAIL;
5562 }
5563
5564 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5565 {
5566 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5567 return FAIL;
5568 }
5569 inst.operands[0].imm = reg;
5570
5571 if (skip_past_comma (&p) == SUCCESS)
5572 {
5573 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5574 return FAIL;
5575 if (inst.reloc.exp.X_add_number != 1)
5576 {
5577 inst.error = _("invalid shift");
5578 return FAIL;
5579 }
5580 inst.operands[0].shifted = 1;
5581 }
5582
5583 if (skip_past_char (&p, ']') == FAIL)
5584 {
5585 inst.error = _("']' expected");
5586 return FAIL;
5587 }
5588 *str = p;
5589 return SUCCESS;
5590 }
5591
5592 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5593 information on the types the operands can take and how they are encoded.
5594 Up to four operands may be read; this function handles setting the
5595 ".present" field for each read operand itself.
5596 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5597 else returns FAIL. */
5598
5599 static int
5600 parse_neon_mov (char **str, int *which_operand)
5601 {
5602 int i = *which_operand, val;
5603 enum arm_reg_type rtype;
5604 char *ptr = *str;
5605 struct neon_type_el optype;
5606
5607 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5608 {
5609 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5610 inst.operands[i].reg = val;
5611 inst.operands[i].isscalar = 1;
5612 inst.operands[i].vectype = optype;
5613 inst.operands[i++].present = 1;
5614
5615 if (skip_past_comma (&ptr) == FAIL)
5616 goto wanted_comma;
5617
5618 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5619 goto wanted_arm;
5620
5621 inst.operands[i].reg = val;
5622 inst.operands[i].isreg = 1;
5623 inst.operands[i].present = 1;
5624 }
5625 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
5626 != FAIL)
5627 {
5628 /* Cases 0, 1, 2, 3, 5 (D only). */
5629 if (skip_past_comma (&ptr) == FAIL)
5630 goto wanted_comma;
5631
5632 inst.operands[i].reg = val;
5633 inst.operands[i].isreg = 1;
5634 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5635 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5636 inst.operands[i].isvec = 1;
5637 inst.operands[i].vectype = optype;
5638 inst.operands[i++].present = 1;
5639
5640 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5641 {
5642 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5643 Case 13: VMOV <Sd>, <Rm> */
5644 inst.operands[i].reg = val;
5645 inst.operands[i].isreg = 1;
5646 inst.operands[i].present = 1;
5647
5648 if (rtype == REG_TYPE_NQ)
5649 {
5650 first_error (_("can't use Neon quad register here"));
5651 return FAIL;
5652 }
5653 else if (rtype != REG_TYPE_VFS)
5654 {
5655 i++;
5656 if (skip_past_comma (&ptr) == FAIL)
5657 goto wanted_comma;
5658 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5659 goto wanted_arm;
5660 inst.operands[i].reg = val;
5661 inst.operands[i].isreg = 1;
5662 inst.operands[i].present = 1;
5663 }
5664 }
5665 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5666 &optype)) != FAIL)
5667 {
5668 /* Case 0: VMOV<c><q> <Qd>, <Qm>
5669 Case 1: VMOV<c><q> <Dd>, <Dm>
5670 Case 8: VMOV.F32 <Sd>, <Sm>
5671 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5672
5673 inst.operands[i].reg = val;
5674 inst.operands[i].isreg = 1;
5675 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5676 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5677 inst.operands[i].isvec = 1;
5678 inst.operands[i].vectype = optype;
5679 inst.operands[i].present = 1;
5680
5681 if (skip_past_comma (&ptr) == SUCCESS)
5682 {
5683 /* Case 15. */
5684 i++;
5685
5686 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5687 goto wanted_arm;
5688
5689 inst.operands[i].reg = val;
5690 inst.operands[i].isreg = 1;
5691 inst.operands[i++].present = 1;
5692
5693 if (skip_past_comma (&ptr) == FAIL)
5694 goto wanted_comma;
5695
5696 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5697 goto wanted_arm;
5698
5699 inst.operands[i].reg = val;
5700 inst.operands[i].isreg = 1;
5701 inst.operands[i++].present = 1;
5702 }
5703 }
5704 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5705 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5706 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5707 Case 10: VMOV.F32 <Sd>, #<imm>
5708 Case 11: VMOV.F64 <Dd>, #<imm> */
5709 inst.operands[i].immisfloat = 1;
5710 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5711 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5712 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5713 ;
5714 else
5715 {
5716 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5717 return FAIL;
5718 }
5719 }
5720 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5721 {
5722 /* Cases 6, 7. */
5723 inst.operands[i].reg = val;
5724 inst.operands[i].isreg = 1;
5725 inst.operands[i++].present = 1;
5726
5727 if (skip_past_comma (&ptr) == FAIL)
5728 goto wanted_comma;
5729
5730 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5731 {
5732 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5733 inst.operands[i].reg = val;
5734 inst.operands[i].isscalar = 1;
5735 inst.operands[i].present = 1;
5736 inst.operands[i].vectype = optype;
5737 }
5738 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5739 {
5740 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5741 inst.operands[i].reg = val;
5742 inst.operands[i].isreg = 1;
5743 inst.operands[i++].present = 1;
5744
5745 if (skip_past_comma (&ptr) == FAIL)
5746 goto wanted_comma;
5747
5748 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
5749 == FAIL)
5750 {
5751 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5752 return FAIL;
5753 }
5754
5755 inst.operands[i].reg = val;
5756 inst.operands[i].isreg = 1;
5757 inst.operands[i].isvec = 1;
5758 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5759 inst.operands[i].vectype = optype;
5760 inst.operands[i].present = 1;
5761
5762 if (rtype == REG_TYPE_VFS)
5763 {
5764 /* Case 14. */
5765 i++;
5766 if (skip_past_comma (&ptr) == FAIL)
5767 goto wanted_comma;
5768 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5769 &optype)) == FAIL)
5770 {
5771 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5772 return FAIL;
5773 }
5774 inst.operands[i].reg = val;
5775 inst.operands[i].isreg = 1;
5776 inst.operands[i].isvec = 1;
5777 inst.operands[i].issingle = 1;
5778 inst.operands[i].vectype = optype;
5779 inst.operands[i].present = 1;
5780 }
5781 }
5782 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5783 != FAIL)
5784 {
5785 /* Case 13. */
5786 inst.operands[i].reg = val;
5787 inst.operands[i].isreg = 1;
5788 inst.operands[i].isvec = 1;
5789 inst.operands[i].issingle = 1;
5790 inst.operands[i].vectype = optype;
5791 inst.operands[i++].present = 1;
5792 }
5793 }
5794 else
5795 {
5796 first_error (_("parse error"));
5797 return FAIL;
5798 }
5799
5800 /* Successfully parsed the operands. Update args. */
5801 *which_operand = i;
5802 *str = ptr;
5803 return SUCCESS;
5804
5805 wanted_comma:
5806 first_error (_("expected comma"));
5807 return FAIL;
5808
5809 wanted_arm:
5810 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5811 return FAIL;
5812 }
5813
5814 /* Use this macro when the operand constraints are different
5815 for ARM and THUMB (e.g. ldrd). */
5816 #define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
5817 ((arm_operand) | ((thumb_operand) << 16))
5818
5819 /* Matcher codes for parse_operands. */
5820 enum operand_parse_code
5821 {
5822 OP_stop, /* end of line */
5823
5824 OP_RR, /* ARM register */
5825 OP_RRnpc, /* ARM register, not r15 */
5826 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
5827 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5828 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
5829 optional trailing ! */
5830 OP_RRw, /* ARM register, not r15, optional trailing ! */
5831 OP_RCP, /* Coprocessor number */
5832 OP_RCN, /* Coprocessor register */
5833 OP_RF, /* FPA register */
5834 OP_RVS, /* VFP single precision register */
5835 OP_RVD, /* VFP double precision register (0..15) */
5836 OP_RND, /* Neon double precision register (0..31) */
5837 OP_RNQ, /* Neon quad precision register */
5838 OP_RVSD, /* VFP single or double precision register */
5839 OP_RNDQ, /* Neon double or quad precision register */
5840 OP_RNSDQ, /* Neon single, double or quad precision register */
5841 OP_RNSC, /* Neon scalar D[X] */
5842 OP_RVC, /* VFP control register */
5843 OP_RMF, /* Maverick F register */
5844 OP_RMD, /* Maverick D register */
5845 OP_RMFX, /* Maverick FX register */
5846 OP_RMDX, /* Maverick DX register */
5847 OP_RMAX, /* Maverick AX register */
5848 OP_RMDS, /* Maverick DSPSC register */
5849 OP_RIWR, /* iWMMXt wR register */
5850 OP_RIWC, /* iWMMXt wC register */
5851 OP_RIWG, /* iWMMXt wCG register */
5852 OP_RXA, /* XScale accumulator register */
5853
5854 OP_REGLST, /* ARM register list */
5855 OP_VRSLST, /* VFP single-precision register list */
5856 OP_VRDLST, /* VFP double-precision register list */
5857 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5858 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5859 OP_NSTRLST, /* Neon element/structure list */
5860
5861 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
5862 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5863 OP_RR_RNSC, /* ARM reg or Neon scalar. */
5864 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5865 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5866 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5867 OP_VMOV, /* Neon VMOV operands. */
5868 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5869 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
5870 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5871
5872 OP_I0, /* immediate zero */
5873 OP_I7, /* immediate value 0 .. 7 */
5874 OP_I15, /* 0 .. 15 */
5875 OP_I16, /* 1 .. 16 */
5876 OP_I16z, /* 0 .. 16 */
5877 OP_I31, /* 0 .. 31 */
5878 OP_I31w, /* 0 .. 31, optional trailing ! */
5879 OP_I32, /* 1 .. 32 */
5880 OP_I32z, /* 0 .. 32 */
5881 OP_I63, /* 0 .. 63 */
5882 OP_I63s, /* -64 .. 63 */
5883 OP_I64, /* 1 .. 64 */
5884 OP_I64z, /* 0 .. 64 */
5885 OP_I255, /* 0 .. 255 */
5886
5887 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5888 OP_I7b, /* 0 .. 7 */
5889 OP_I15b, /* 0 .. 15 */
5890 OP_I31b, /* 0 .. 31 */
5891
5892 OP_SH, /* shifter operand */
5893 OP_SHG, /* shifter operand with possible group relocation */
5894 OP_ADDR, /* Memory address expression (any mode) */
5895 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5896 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5897 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
5898 OP_EXP, /* arbitrary expression */
5899 OP_EXPi, /* same, with optional immediate prefix */
5900 OP_EXPr, /* same, with optional relocation suffix */
5901 OP_HALF, /* 0 .. 65535 or low/high reloc. */
5902
5903 OP_CPSF, /* CPS flags */
5904 OP_ENDI, /* Endianness specifier */
5905 OP_PSR, /* CPSR/SPSR mask for msr */
5906 OP_COND, /* conditional code */
5907 OP_TB, /* Table branch. */
5908
5909 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5910 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5911
5912 OP_RRnpc_I0, /* ARM register or literal 0 */
5913 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5914 OP_RR_EXi, /* ARM register or expression with imm prefix */
5915 OP_RF_IF, /* FPA register or immediate */
5916 OP_RIWR_RIWC, /* iWMMXt R or C reg */
5917 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
5918
5919 /* Optional operands. */
5920 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5921 OP_oI31b, /* 0 .. 31 */
5922 OP_oI32b, /* 1 .. 32 */
5923 OP_oIffffb, /* 0 .. 65535 */
5924 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5925
5926 OP_oRR, /* ARM register */
5927 OP_oRRnpc, /* ARM register, not the PC */
5928 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
5929 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5930 OP_oRND, /* Optional Neon double precision register */
5931 OP_oRNQ, /* Optional Neon quad precision register */
5932 OP_oRNDQ, /* Optional Neon double or quad precision register */
5933 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
5934 OP_oSHll, /* LSL immediate */
5935 OP_oSHar, /* ASR immediate */
5936 OP_oSHllar, /* LSL or ASR immediate */
5937 OP_oROR, /* ROR 0/8/16/24 */
5938 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
5939
5940 /* Some pre-defined mixed (ARM/THUMB) operands. */
5941 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
5942 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
5943 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
5944
5945 OP_FIRST_OPTIONAL = OP_oI7b
5946 };
5947
5948 /* Generic instruction operand parser. This does no encoding and no
5949 semantic validation; it merely squirrels values away in the inst
5950 structure. Returns SUCCESS or FAIL depending on whether the
5951 specified grammar matched. */
5952 static int
5953 parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
5954 {
5955 unsigned const int *upat = pattern;
5956 char *backtrack_pos = 0;
5957 const char *backtrack_error = 0;
5958 int i, val, backtrack_index = 0;
5959 enum arm_reg_type rtype;
5960 parse_operand_result result;
5961 unsigned int op_parse_code;
5962
5963 #define po_char_or_fail(chr) \
5964 do \
5965 { \
5966 if (skip_past_char (&str, chr) == FAIL) \
5967 goto bad_args; \
5968 } \
5969 while (0)
5970
5971 #define po_reg_or_fail(regtype) \
5972 do \
5973 { \
5974 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5975 & inst.operands[i].vectype); \
5976 if (val == FAIL) \
5977 { \
5978 first_error (_(reg_expected_msgs[regtype])); \
5979 goto failure; \
5980 } \
5981 inst.operands[i].reg = val; \
5982 inst.operands[i].isreg = 1; \
5983 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5984 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5985 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5986 || rtype == REG_TYPE_VFD \
5987 || rtype == REG_TYPE_NQ); \
5988 } \
5989 while (0)
5990
5991 #define po_reg_or_goto(regtype, label) \
5992 do \
5993 { \
5994 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5995 & inst.operands[i].vectype); \
5996 if (val == FAIL) \
5997 goto label; \
5998 \
5999 inst.operands[i].reg = val; \
6000 inst.operands[i].isreg = 1; \
6001 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6002 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6003 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6004 || rtype == REG_TYPE_VFD \
6005 || rtype == REG_TYPE_NQ); \
6006 } \
6007 while (0)
6008
6009 #define po_imm_or_fail(min, max, popt) \
6010 do \
6011 { \
6012 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6013 goto failure; \
6014 inst.operands[i].imm = val; \
6015 } \
6016 while (0)
6017
6018 #define po_scalar_or_goto(elsz, label) \
6019 do \
6020 { \
6021 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6022 if (val == FAIL) \
6023 goto label; \
6024 inst.operands[i].reg = val; \
6025 inst.operands[i].isscalar = 1; \
6026 } \
6027 while (0)
6028
6029 #define po_misc_or_fail(expr) \
6030 do \
6031 { \
6032 if (expr) \
6033 goto failure; \
6034 } \
6035 while (0)
6036
6037 #define po_misc_or_fail_no_backtrack(expr) \
6038 do \
6039 { \
6040 result = expr; \
6041 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6042 backtrack_pos = 0; \
6043 if (result != PARSE_OPERAND_SUCCESS) \
6044 goto failure; \
6045 } \
6046 while (0)
6047
6048 #define po_barrier_or_imm(str) \
6049 do \
6050 { \
6051 val = parse_barrier (&str); \
6052 if (val == FAIL) \
6053 { \
6054 if (ISALPHA (*str)) \
6055 goto failure; \
6056 else \
6057 goto immediate; \
6058 } \
6059 else \
6060 { \
6061 if ((inst.instruction & 0xf0) == 0x60 \
6062 && val != 0xf) \
6063 { \
6064 /* ISB can only take SY as an option. */ \
6065 inst.error = _("invalid barrier type"); \
6066 goto failure; \
6067 } \
6068 } \
6069 } \
6070 while (0)
6071
6072 skip_whitespace (str);
6073
6074 for (i = 0; upat[i] != OP_stop; i++)
6075 {
6076 op_parse_code = upat[i];
6077 if (op_parse_code >= 1<<16)
6078 op_parse_code = thumb ? (op_parse_code >> 16)
6079 : (op_parse_code & ((1<<16)-1));
6080
6081 if (op_parse_code >= OP_FIRST_OPTIONAL)
6082 {
6083 /* Remember where we are in case we need to backtrack. */
6084 gas_assert (!backtrack_pos);
6085 backtrack_pos = str;
6086 backtrack_error = inst.error;
6087 backtrack_index = i;
6088 }
6089
6090 if (i > 0 && (i > 1 || inst.operands[0].present))
6091 po_char_or_fail (',');
6092
6093 switch (op_parse_code)
6094 {
6095 /* Registers */
6096 case OP_oRRnpc:
6097 case OP_oRRnpcsp:
6098 case OP_RRnpc:
6099 case OP_RRnpcsp:
6100 case OP_oRR:
6101 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6102 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6103 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6104 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6105 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6106 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
6107 case OP_oRND:
6108 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
6109 case OP_RVC:
6110 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6111 break;
6112 /* Also accept generic coprocessor regs for unknown registers. */
6113 coproc_reg:
6114 po_reg_or_fail (REG_TYPE_CN);
6115 break;
6116 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6117 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6118 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6119 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6120 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6121 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6122 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6123 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6124 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6125 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
6126 case OP_oRNQ:
6127 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
6128 case OP_oRNDQ:
6129 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
6130 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6131 case OP_oRNSDQ:
6132 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6133
6134 /* Neon scalar. Using an element size of 8 means that some invalid
6135 scalars are accepted here, so deal with those in later code. */
6136 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6137
6138 case OP_RNDQ_I0:
6139 {
6140 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6141 break;
6142 try_imm0:
6143 po_imm_or_fail (0, 0, TRUE);
6144 }
6145 break;
6146
6147 case OP_RVSD_I0:
6148 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6149 break;
6150
6151 case OP_RR_RNSC:
6152 {
6153 po_scalar_or_goto (8, try_rr);
6154 break;
6155 try_rr:
6156 po_reg_or_fail (REG_TYPE_RN);
6157 }
6158 break;
6159
6160 case OP_RNSDQ_RNSC:
6161 {
6162 po_scalar_or_goto (8, try_nsdq);
6163 break;
6164 try_nsdq:
6165 po_reg_or_fail (REG_TYPE_NSDQ);
6166 }
6167 break;
6168
6169 case OP_RNDQ_RNSC:
6170 {
6171 po_scalar_or_goto (8, try_ndq);
6172 break;
6173 try_ndq:
6174 po_reg_or_fail (REG_TYPE_NDQ);
6175 }
6176 break;
6177
6178 case OP_RND_RNSC:
6179 {
6180 po_scalar_or_goto (8, try_vfd);
6181 break;
6182 try_vfd:
6183 po_reg_or_fail (REG_TYPE_VFD);
6184 }
6185 break;
6186
6187 case OP_VMOV:
6188 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6189 not careful then bad things might happen. */
6190 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6191 break;
6192
6193 case OP_RNDQ_Ibig:
6194 {
6195 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6196 break;
6197 try_immbig:
6198 /* There's a possibility of getting a 64-bit immediate here, so
6199 we need special handling. */
6200 if (parse_big_immediate (&str, i) == FAIL)
6201 {
6202 inst.error = _("immediate value is out of range");
6203 goto failure;
6204 }
6205 }
6206 break;
6207
6208 case OP_RNDQ_I63b:
6209 {
6210 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6211 break;
6212 try_shimm:
6213 po_imm_or_fail (0, 63, TRUE);
6214 }
6215 break;
6216
6217 case OP_RRnpcb:
6218 po_char_or_fail ('[');
6219 po_reg_or_fail (REG_TYPE_RN);
6220 po_char_or_fail (']');
6221 break;
6222
6223 case OP_RRnpctw:
6224 case OP_RRw:
6225 case OP_oRRw:
6226 po_reg_or_fail (REG_TYPE_RN);
6227 if (skip_past_char (&str, '!') == SUCCESS)
6228 inst.operands[i].writeback = 1;
6229 break;
6230
6231 /* Immediates */
6232 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6233 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6234 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
6235 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
6236 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6237 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
6238 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
6239 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
6240 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6241 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6242 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
6243 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
6244
6245 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6246 case OP_oI7b:
6247 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6248 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6249 case OP_oI31b:
6250 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
6251 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6252 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6253
6254 /* Immediate variants */
6255 case OP_oI255c:
6256 po_char_or_fail ('{');
6257 po_imm_or_fail (0, 255, TRUE);
6258 po_char_or_fail ('}');
6259 break;
6260
6261 case OP_I31w:
6262 /* The expression parser chokes on a trailing !, so we have
6263 to find it first and zap it. */
6264 {
6265 char *s = str;
6266 while (*s && *s != ',')
6267 s++;
6268 if (s[-1] == '!')
6269 {
6270 s[-1] = '\0';
6271 inst.operands[i].writeback = 1;
6272 }
6273 po_imm_or_fail (0, 31, TRUE);
6274 if (str == s - 1)
6275 str = s;
6276 }
6277 break;
6278
6279 /* Expressions */
6280 case OP_EXPi: EXPi:
6281 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6282 GE_OPT_PREFIX));
6283 break;
6284
6285 case OP_EXP:
6286 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6287 GE_NO_PREFIX));
6288 break;
6289
6290 case OP_EXPr: EXPr:
6291 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6292 GE_NO_PREFIX));
6293 if (inst.reloc.exp.X_op == O_symbol)
6294 {
6295 val = parse_reloc (&str);
6296 if (val == -1)
6297 {
6298 inst.error = _("unrecognized relocation suffix");
6299 goto failure;
6300 }
6301 else if (val != BFD_RELOC_UNUSED)
6302 {
6303 inst.operands[i].imm = val;
6304 inst.operands[i].hasreloc = 1;
6305 }
6306 }
6307 break;
6308
6309 /* Operand for MOVW or MOVT. */
6310 case OP_HALF:
6311 po_misc_or_fail (parse_half (&str));
6312 break;
6313
6314 /* Register or expression. */
6315 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6316 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
6317
6318 /* Register or immediate. */
6319 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6320 I0: po_imm_or_fail (0, 0, FALSE); break;
6321
6322 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6323 IF:
6324 if (!is_immediate_prefix (*str))
6325 goto bad_args;
6326 str++;
6327 val = parse_fpa_immediate (&str);
6328 if (val == FAIL)
6329 goto failure;
6330 /* FPA immediates are encoded as registers 8-15.
6331 parse_fpa_immediate has already applied the offset. */
6332 inst.operands[i].reg = val;
6333 inst.operands[i].isreg = 1;
6334 break;
6335
6336 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6337 I32z: po_imm_or_fail (0, 32, FALSE); break;
6338
6339 /* Two kinds of register. */
6340 case OP_RIWR_RIWC:
6341 {
6342 struct reg_entry *rege = arm_reg_parse_multi (&str);
6343 if (!rege
6344 || (rege->type != REG_TYPE_MMXWR
6345 && rege->type != REG_TYPE_MMXWC
6346 && rege->type != REG_TYPE_MMXWCG))
6347 {
6348 inst.error = _("iWMMXt data or control register expected");
6349 goto failure;
6350 }
6351 inst.operands[i].reg = rege->number;
6352 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6353 }
6354 break;
6355
6356 case OP_RIWC_RIWG:
6357 {
6358 struct reg_entry *rege = arm_reg_parse_multi (&str);
6359 if (!rege
6360 || (rege->type != REG_TYPE_MMXWC
6361 && rege->type != REG_TYPE_MMXWCG))
6362 {
6363 inst.error = _("iWMMXt control register expected");
6364 goto failure;
6365 }
6366 inst.operands[i].reg = rege->number;
6367 inst.operands[i].isreg = 1;
6368 }
6369 break;
6370
6371 /* Misc */
6372 case OP_CPSF: val = parse_cps_flags (&str); break;
6373 case OP_ENDI: val = parse_endian_specifier (&str); break;
6374 case OP_oROR: val = parse_ror (&str); break;
6375 case OP_PSR: val = parse_psr (&str); break;
6376 case OP_COND: val = parse_cond (&str); break;
6377 case OP_oBARRIER_I15:
6378 po_barrier_or_imm (str); break;
6379 immediate:
6380 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
6381 goto failure;
6382 break;
6383
6384 case OP_RVC_PSR:
6385 po_reg_or_goto (REG_TYPE_VFC, try_banked_reg);
6386 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
6387 break;
6388 try_banked_reg:
6389 po_reg_or_goto (REG_TYPE_RNB, try_psr);
6390 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
6391 {
6392 inst.error = _("Banked registers are not available with this "
6393 "architecture.");
6394 goto failure;
6395 }
6396 break;
6397 try_psr:
6398 val = parse_psr (&str);
6399 break;
6400
6401 case OP_APSR_RR:
6402 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6403 break;
6404 try_apsr:
6405 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6406 instruction). */
6407 if (strncasecmp (str, "APSR_", 5) == 0)
6408 {
6409 unsigned found = 0;
6410 str += 5;
6411 while (found < 15)
6412 switch (*str++)
6413 {
6414 case 'c': found = (found & 1) ? 16 : found | 1; break;
6415 case 'n': found = (found & 2) ? 16 : found | 2; break;
6416 case 'z': found = (found & 4) ? 16 : found | 4; break;
6417 case 'v': found = (found & 8) ? 16 : found | 8; break;
6418 default: found = 16;
6419 }
6420 if (found != 15)
6421 goto failure;
6422 inst.operands[i].isvec = 1;
6423 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6424 inst.operands[i].reg = REG_PC;
6425 }
6426 else
6427 goto failure;
6428 break;
6429
6430 case OP_TB:
6431 po_misc_or_fail (parse_tb (&str));
6432 break;
6433
6434 /* Register lists. */
6435 case OP_REGLST:
6436 val = parse_reg_list (&str);
6437 if (*str == '^')
6438 {
6439 inst.operands[1].writeback = 1;
6440 str++;
6441 }
6442 break;
6443
6444 case OP_VRSLST:
6445 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
6446 break;
6447
6448 case OP_VRDLST:
6449 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
6450 break;
6451
6452 case OP_VRSDLST:
6453 /* Allow Q registers too. */
6454 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6455 REGLIST_NEON_D);
6456 if (val == FAIL)
6457 {
6458 inst.error = NULL;
6459 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6460 REGLIST_VFP_S);
6461 inst.operands[i].issingle = 1;
6462 }
6463 break;
6464
6465 case OP_NRDLST:
6466 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6467 REGLIST_NEON_D);
6468 break;
6469
6470 case OP_NSTRLST:
6471 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6472 &inst.operands[i].vectype);
6473 break;
6474
6475 /* Addressing modes */
6476 case OP_ADDR:
6477 po_misc_or_fail (parse_address (&str, i));
6478 break;
6479
6480 case OP_ADDRGLDR:
6481 po_misc_or_fail_no_backtrack (
6482 parse_address_group_reloc (&str, i, GROUP_LDR));
6483 break;
6484
6485 case OP_ADDRGLDRS:
6486 po_misc_or_fail_no_backtrack (
6487 parse_address_group_reloc (&str, i, GROUP_LDRS));
6488 break;
6489
6490 case OP_ADDRGLDC:
6491 po_misc_or_fail_no_backtrack (
6492 parse_address_group_reloc (&str, i, GROUP_LDC));
6493 break;
6494
6495 case OP_SH:
6496 po_misc_or_fail (parse_shifter_operand (&str, i));
6497 break;
6498
6499 case OP_SHG:
6500 po_misc_or_fail_no_backtrack (
6501 parse_shifter_operand_group_reloc (&str, i));
6502 break;
6503
6504 case OP_oSHll:
6505 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6506 break;
6507
6508 case OP_oSHar:
6509 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6510 break;
6511
6512 case OP_oSHllar:
6513 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6514 break;
6515
6516 default:
6517 as_fatal (_("unhandled operand code %d"), op_parse_code);
6518 }
6519
6520 /* Various value-based sanity checks and shared operations. We
6521 do not signal immediate failures for the register constraints;
6522 this allows a syntax error to take precedence. */
6523 switch (op_parse_code)
6524 {
6525 case OP_oRRnpc:
6526 case OP_RRnpc:
6527 case OP_RRnpcb:
6528 case OP_RRw:
6529 case OP_oRRw:
6530 case OP_RRnpc_I0:
6531 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6532 inst.error = BAD_PC;
6533 break;
6534
6535 case OP_oRRnpcsp:
6536 case OP_RRnpcsp:
6537 if (inst.operands[i].isreg)
6538 {
6539 if (inst.operands[i].reg == REG_PC)
6540 inst.error = BAD_PC;
6541 else if (inst.operands[i].reg == REG_SP)
6542 inst.error = BAD_SP;
6543 }
6544 break;
6545
6546 case OP_RRnpctw:
6547 if (inst.operands[i].isreg
6548 && inst.operands[i].reg == REG_PC
6549 && (inst.operands[i].writeback || thumb))
6550 inst.error = BAD_PC;
6551 break;
6552
6553 case OP_CPSF:
6554 case OP_ENDI:
6555 case OP_oROR:
6556 case OP_PSR:
6557 case OP_RVC_PSR:
6558 case OP_COND:
6559 case OP_oBARRIER_I15:
6560 case OP_REGLST:
6561 case OP_VRSLST:
6562 case OP_VRDLST:
6563 case OP_VRSDLST:
6564 case OP_NRDLST:
6565 case OP_NSTRLST:
6566 if (val == FAIL)
6567 goto failure;
6568 inst.operands[i].imm = val;
6569 break;
6570
6571 default:
6572 break;
6573 }
6574
6575 /* If we get here, this operand was successfully parsed. */
6576 inst.operands[i].present = 1;
6577 continue;
6578
6579 bad_args:
6580 inst.error = BAD_ARGS;
6581
6582 failure:
6583 if (!backtrack_pos)
6584 {
6585 /* The parse routine should already have set inst.error, but set a
6586 default here just in case. */
6587 if (!inst.error)
6588 inst.error = _("syntax error");
6589 return FAIL;
6590 }
6591
6592 /* Do not backtrack over a trailing optional argument that
6593 absorbed some text. We will only fail again, with the
6594 'garbage following instruction' error message, which is
6595 probably less helpful than the current one. */
6596 if (backtrack_index == i && backtrack_pos != str
6597 && upat[i+1] == OP_stop)
6598 {
6599 if (!inst.error)
6600 inst.error = _("syntax error");
6601 return FAIL;
6602 }
6603
6604 /* Try again, skipping the optional argument at backtrack_pos. */
6605 str = backtrack_pos;
6606 inst.error = backtrack_error;
6607 inst.operands[backtrack_index].present = 0;
6608 i = backtrack_index;
6609 backtrack_pos = 0;
6610 }
6611
6612 /* Check that we have parsed all the arguments. */
6613 if (*str != '\0' && !inst.error)
6614 inst.error = _("garbage following instruction");
6615
6616 return inst.error ? FAIL : SUCCESS;
6617 }
6618
6619 #undef po_char_or_fail
6620 #undef po_reg_or_fail
6621 #undef po_reg_or_goto
6622 #undef po_imm_or_fail
6623 #undef po_scalar_or_fail
6624 #undef po_barrier_or_imm
6625
6626 /* Shorthand macro for instruction encoding functions issuing errors. */
6627 #define constraint(expr, err) \
6628 do \
6629 { \
6630 if (expr) \
6631 { \
6632 inst.error = err; \
6633 return; \
6634 } \
6635 } \
6636 while (0)
6637
6638 /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6639 instructions are unpredictable if these registers are used. This
6640 is the BadReg predicate in ARM's Thumb-2 documentation. */
6641 #define reject_bad_reg(reg) \
6642 do \
6643 if (reg == REG_SP || reg == REG_PC) \
6644 { \
6645 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6646 return; \
6647 } \
6648 while (0)
6649
6650 /* If REG is R13 (the stack pointer), warn that its use is
6651 deprecated. */
6652 #define warn_deprecated_sp(reg) \
6653 do \
6654 if (warn_on_deprecated && reg == REG_SP) \
6655 as_warn (_("use of r13 is deprecated")); \
6656 while (0)
6657
6658 /* Functions for operand encoding. ARM, then Thumb. */
6659
6660 #define rotate_left(v, n) (v << n | v >> (32 - n))
6661
6662 /* If VAL can be encoded in the immediate field of an ARM instruction,
6663 return the encoded form. Otherwise, return FAIL. */
6664
6665 static unsigned int
6666 encode_arm_immediate (unsigned int val)
6667 {
6668 unsigned int a, i;
6669
6670 for (i = 0; i < 32; i += 2)
6671 if ((a = rotate_left (val, i)) <= 0xff)
6672 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6673
6674 return FAIL;
6675 }
6676
6677 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6678 return the encoded form. Otherwise, return FAIL. */
6679 static unsigned int
6680 encode_thumb32_immediate (unsigned int val)
6681 {
6682 unsigned int a, i;
6683
6684 if (val <= 0xff)
6685 return val;
6686
6687 for (i = 1; i <= 24; i++)
6688 {
6689 a = val >> i;
6690 if ((val & ~(0xff << i)) == 0)
6691 return ((val >> i) & 0x7f) | ((32 - i) << 7);
6692 }
6693
6694 a = val & 0xff;
6695 if (val == ((a << 16) | a))
6696 return 0x100 | a;
6697 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6698 return 0x300 | a;
6699
6700 a = val & 0xff00;
6701 if (val == ((a << 16) | a))
6702 return 0x200 | (a >> 8);
6703
6704 return FAIL;
6705 }
6706 /* Encode a VFP SP or DP register number into inst.instruction. */
6707
6708 static void
6709 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6710 {
6711 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6712 && reg > 15)
6713 {
6714 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
6715 {
6716 if (thumb_mode)
6717 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
6718 fpu_vfp_ext_d32);
6719 else
6720 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
6721 fpu_vfp_ext_d32);
6722 }
6723 else
6724 {
6725 first_error (_("D register out of range for selected VFP version"));
6726 return;
6727 }
6728 }
6729
6730 switch (pos)
6731 {
6732 case VFP_REG_Sd:
6733 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6734 break;
6735
6736 case VFP_REG_Sn:
6737 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6738 break;
6739
6740 case VFP_REG_Sm:
6741 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6742 break;
6743
6744 case VFP_REG_Dd:
6745 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6746 break;
6747
6748 case VFP_REG_Dn:
6749 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6750 break;
6751
6752 case VFP_REG_Dm:
6753 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6754 break;
6755
6756 default:
6757 abort ();
6758 }
6759 }
6760
6761 /* Encode a <shift> in an ARM-format instruction. The immediate,
6762 if any, is handled by md_apply_fix. */
6763 static void
6764 encode_arm_shift (int i)
6765 {
6766 if (inst.operands[i].shift_kind == SHIFT_RRX)
6767 inst.instruction |= SHIFT_ROR << 5;
6768 else
6769 {
6770 inst.instruction |= inst.operands[i].shift_kind << 5;
6771 if (inst.operands[i].immisreg)
6772 {
6773 inst.instruction |= SHIFT_BY_REG;
6774 inst.instruction |= inst.operands[i].imm << 8;
6775 }
6776 else
6777 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6778 }
6779 }
6780
6781 static void
6782 encode_arm_shifter_operand (int i)
6783 {
6784 if (inst.operands[i].isreg)
6785 {
6786 inst.instruction |= inst.operands[i].reg;
6787 encode_arm_shift (i);
6788 }
6789 else
6790 inst.instruction |= INST_IMMEDIATE;
6791 }
6792
6793 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
6794 static void
6795 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
6796 {
6797 gas_assert (inst.operands[i].isreg);
6798 inst.instruction |= inst.operands[i].reg << 16;
6799
6800 if (inst.operands[i].preind)
6801 {
6802 if (is_t)
6803 {
6804 inst.error = _("instruction does not accept preindexed addressing");
6805 return;
6806 }
6807 inst.instruction |= PRE_INDEX;
6808 if (inst.operands[i].writeback)
6809 inst.instruction |= WRITE_BACK;
6810
6811 }
6812 else if (inst.operands[i].postind)
6813 {
6814 gas_assert (inst.operands[i].writeback);
6815 if (is_t)
6816 inst.instruction |= WRITE_BACK;
6817 }
6818 else /* unindexed - only for coprocessor */
6819 {
6820 inst.error = _("instruction does not accept unindexed addressing");
6821 return;
6822 }
6823
6824 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6825 && (((inst.instruction & 0x000f0000) >> 16)
6826 == ((inst.instruction & 0x0000f000) >> 12)))
6827 as_warn ((inst.instruction & LOAD_BIT)
6828 ? _("destination register same as write-back base")
6829 : _("source register same as write-back base"));
6830 }
6831
6832 /* inst.operands[i] was set up by parse_address. Encode it into an
6833 ARM-format mode 2 load or store instruction. If is_t is true,
6834 reject forms that cannot be used with a T instruction (i.e. not
6835 post-indexed). */
6836 static void
6837 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
6838 {
6839 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
6840
6841 encode_arm_addr_mode_common (i, is_t);
6842
6843 if (inst.operands[i].immisreg)
6844 {
6845 constraint ((inst.operands[i].imm == REG_PC
6846 || (is_pc && inst.operands[i].writeback)),
6847 BAD_PC_ADDRESSING);
6848 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6849 inst.instruction |= inst.operands[i].imm;
6850 if (!inst.operands[i].negative)
6851 inst.instruction |= INDEX_UP;
6852 if (inst.operands[i].shifted)
6853 {
6854 if (inst.operands[i].shift_kind == SHIFT_RRX)
6855 inst.instruction |= SHIFT_ROR << 5;
6856 else
6857 {
6858 inst.instruction |= inst.operands[i].shift_kind << 5;
6859 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6860 }
6861 }
6862 }
6863 else /* immediate offset in inst.reloc */
6864 {
6865 if (is_pc && !inst.reloc.pc_rel)
6866 {
6867 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
6868
6869 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
6870 cannot use PC in addressing.
6871 PC cannot be used in writeback addressing, either. */
6872 constraint ((is_t || inst.operands[i].writeback),
6873 BAD_PC_ADDRESSING);
6874
6875 /* Use of PC in str is deprecated for ARMv7. */
6876 if (warn_on_deprecated
6877 && !is_load
6878 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
6879 as_warn (_("use of PC in this instruction is deprecated"));
6880 }
6881
6882 if (inst.reloc.type == BFD_RELOC_UNUSED)
6883 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
6884 }
6885 }
6886
6887 /* inst.operands[i] was set up by parse_address. Encode it into an
6888 ARM-format mode 3 load or store instruction. Reject forms that
6889 cannot be used with such instructions. If is_t is true, reject
6890 forms that cannot be used with a T instruction (i.e. not
6891 post-indexed). */
6892 static void
6893 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
6894 {
6895 if (inst.operands[i].immisreg && inst.operands[i].shifted)
6896 {
6897 inst.error = _("instruction does not accept scaled register index");
6898 return;
6899 }
6900
6901 encode_arm_addr_mode_common (i, is_t);
6902
6903 if (inst.operands[i].immisreg)
6904 {
6905 constraint ((inst.operands[i].imm == REG_PC
6906 || inst.operands[i].reg == REG_PC),
6907 BAD_PC_ADDRESSING);
6908 inst.instruction |= inst.operands[i].imm;
6909 if (!inst.operands[i].negative)
6910 inst.instruction |= INDEX_UP;
6911 }
6912 else /* immediate offset in inst.reloc */
6913 {
6914 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
6915 && inst.operands[i].writeback),
6916 BAD_PC_WRITEBACK);
6917 inst.instruction |= HWOFFSET_IMM;
6918 if (inst.reloc.type == BFD_RELOC_UNUSED)
6919 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
6920 }
6921 }
6922
6923 /* inst.operands[i] was set up by parse_address. Encode it into an
6924 ARM-format instruction. Reject all forms which cannot be encoded
6925 into a coprocessor load/store instruction. If wb_ok is false,
6926 reject use of writeback; if unind_ok is false, reject use of
6927 unindexed addressing. If reloc_override is not 0, use it instead
6928 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6929 (in which case it is preserved). */
6930
6931 static int
6932 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
6933 {
6934 inst.instruction |= inst.operands[i].reg << 16;
6935
6936 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
6937
6938 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
6939 {
6940 gas_assert (!inst.operands[i].writeback);
6941 if (!unind_ok)
6942 {
6943 inst.error = _("instruction does not support unindexed addressing");
6944 return FAIL;
6945 }
6946 inst.instruction |= inst.operands[i].imm;
6947 inst.instruction |= INDEX_UP;
6948 return SUCCESS;
6949 }
6950
6951 if (inst.operands[i].preind)
6952 inst.instruction |= PRE_INDEX;
6953
6954 if (inst.operands[i].writeback)
6955 {
6956 if (inst.operands[i].reg == REG_PC)
6957 {
6958 inst.error = _("pc may not be used with write-back");
6959 return FAIL;
6960 }
6961 if (!wb_ok)
6962 {
6963 inst.error = _("instruction does not support writeback");
6964 return FAIL;
6965 }
6966 inst.instruction |= WRITE_BACK;
6967 }
6968
6969 if (reloc_override)
6970 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
6971 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6972 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6973 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6974 {
6975 if (thumb_mode)
6976 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6977 else
6978 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6979 }
6980
6981 return SUCCESS;
6982 }
6983
6984 /* inst.reloc.exp describes an "=expr" load pseudo-operation.
6985 Determine whether it can be performed with a move instruction; if
6986 it can, convert inst.instruction to that move instruction and
6987 return TRUE; if it can't, convert inst.instruction to a literal-pool
6988 load and return FALSE. If this is not a valid thing to do in the
6989 current context, set inst.error and return TRUE.
6990
6991 inst.operands[i] describes the destination register. */
6992
6993 static bfd_boolean
6994 move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6995 {
6996 unsigned long tbit;
6997
6998 if (thumb_p)
6999 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7000 else
7001 tbit = LOAD_BIT;
7002
7003 if ((inst.instruction & tbit) == 0)
7004 {
7005 inst.error = _("invalid pseudo operation");
7006 return TRUE;
7007 }
7008 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
7009 {
7010 inst.error = _("constant expression expected");
7011 return TRUE;
7012 }
7013 if (inst.reloc.exp.X_op == O_constant)
7014 {
7015 if (thumb_p)
7016 {
7017 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
7018 {
7019 /* This can be done with a mov(1) instruction. */
7020 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7021 inst.instruction |= inst.reloc.exp.X_add_number;
7022 return TRUE;
7023 }
7024 }
7025 else
7026 {
7027 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
7028 if (value != FAIL)
7029 {
7030 /* This can be done with a mov instruction. */
7031 inst.instruction &= LITERAL_MASK;
7032 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7033 inst.instruction |= value & 0xfff;
7034 return TRUE;
7035 }
7036
7037 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
7038 if (value != FAIL)
7039 {
7040 /* This can be done with a mvn instruction. */
7041 inst.instruction &= LITERAL_MASK;
7042 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
7043 inst.instruction |= value & 0xfff;
7044 return TRUE;
7045 }
7046 }
7047 }
7048
7049 if (add_to_lit_pool () == FAIL)
7050 {
7051 inst.error = _("literal pool insertion failed");
7052 return TRUE;
7053 }
7054 inst.operands[1].reg = REG_PC;
7055 inst.operands[1].isreg = 1;
7056 inst.operands[1].preind = 1;
7057 inst.reloc.pc_rel = 1;
7058 inst.reloc.type = (thumb_p
7059 ? BFD_RELOC_ARM_THUMB_OFFSET
7060 : (mode_3
7061 ? BFD_RELOC_ARM_HWLITERAL
7062 : BFD_RELOC_ARM_LITERAL));
7063 return FALSE;
7064 }
7065
7066 /* Functions for instruction encoding, sorted by sub-architecture.
7067 First some generics; their names are taken from the conventional
7068 bit positions for register arguments in ARM format instructions. */
7069
7070 static void
7071 do_noargs (void)
7072 {
7073 }
7074
7075 static void
7076 do_rd (void)
7077 {
7078 inst.instruction |= inst.operands[0].reg << 12;
7079 }
7080
7081 static void
7082 do_rd_rm (void)
7083 {
7084 inst.instruction |= inst.operands[0].reg << 12;
7085 inst.instruction |= inst.operands[1].reg;
7086 }
7087
7088 static void
7089 do_rd_rn (void)
7090 {
7091 inst.instruction |= inst.operands[0].reg << 12;
7092 inst.instruction |= inst.operands[1].reg << 16;
7093 }
7094
7095 static void
7096 do_rn_rd (void)
7097 {
7098 inst.instruction |= inst.operands[0].reg << 16;
7099 inst.instruction |= inst.operands[1].reg << 12;
7100 }
7101
7102 static void
7103 do_rd_rm_rn (void)
7104 {
7105 unsigned Rn = inst.operands[2].reg;
7106 /* Enforce restrictions on SWP instruction. */
7107 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
7108 {
7109 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
7110 _("Rn must not overlap other operands"));
7111
7112 /* SWP{b} is deprecated for ARMv6* and ARMv7. */
7113 if (warn_on_deprecated
7114 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7115 as_warn (_("swp{b} use is deprecated for this architecture"));
7116
7117 }
7118 inst.instruction |= inst.operands[0].reg << 12;
7119 inst.instruction |= inst.operands[1].reg;
7120 inst.instruction |= Rn << 16;
7121 }
7122
7123 static void
7124 do_rd_rn_rm (void)
7125 {
7126 inst.instruction |= inst.operands[0].reg << 12;
7127 inst.instruction |= inst.operands[1].reg << 16;
7128 inst.instruction |= inst.operands[2].reg;
7129 }
7130
7131 static void
7132 do_rm_rd_rn (void)
7133 {
7134 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
7135 constraint (((inst.reloc.exp.X_op != O_constant
7136 && inst.reloc.exp.X_op != O_illegal)
7137 || inst.reloc.exp.X_add_number != 0),
7138 BAD_ADDR_MODE);
7139 inst.instruction |= inst.operands[0].reg;
7140 inst.instruction |= inst.operands[1].reg << 12;
7141 inst.instruction |= inst.operands[2].reg << 16;
7142 }
7143
7144 static void
7145 do_imm0 (void)
7146 {
7147 inst.instruction |= inst.operands[0].imm;
7148 }
7149
7150 static void
7151 do_rd_cpaddr (void)
7152 {
7153 inst.instruction |= inst.operands[0].reg << 12;
7154 encode_arm_cp_address (1, TRUE, TRUE, 0);
7155 }
7156
7157 /* ARM instructions, in alphabetical order by function name (except
7158 that wrapper functions appear immediately after the function they
7159 wrap). */
7160
7161 /* This is a pseudo-op of the form "adr rd, label" to be converted
7162 into a relative address of the form "add rd, pc, #label-.-8". */
7163
7164 static void
7165 do_adr (void)
7166 {
7167 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
7168
7169 /* Frag hacking will turn this into a sub instruction if the offset turns
7170 out to be negative. */
7171 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7172 inst.reloc.pc_rel = 1;
7173 inst.reloc.exp.X_add_number -= 8;
7174 }
7175
7176 /* This is a pseudo-op of the form "adrl rd, label" to be converted
7177 into a relative address of the form:
7178 add rd, pc, #low(label-.-8)"
7179 add rd, rd, #high(label-.-8)" */
7180
7181 static void
7182 do_adrl (void)
7183 {
7184 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
7185
7186 /* Frag hacking will turn this into a sub instruction if the offset turns
7187 out to be negative. */
7188 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
7189 inst.reloc.pc_rel = 1;
7190 inst.size = INSN_SIZE * 2;
7191 inst.reloc.exp.X_add_number -= 8;
7192 }
7193
7194 static void
7195 do_arit (void)
7196 {
7197 if (!inst.operands[1].present)
7198 inst.operands[1].reg = inst.operands[0].reg;
7199 inst.instruction |= inst.operands[0].reg << 12;
7200 inst.instruction |= inst.operands[1].reg << 16;
7201 encode_arm_shifter_operand (2);
7202 }
7203
7204 static void
7205 do_barrier (void)
7206 {
7207 if (inst.operands[0].present)
7208 {
7209 constraint ((inst.instruction & 0xf0) != 0x40
7210 && inst.operands[0].imm > 0xf
7211 && inst.operands[0].imm < 0x0,
7212 _("bad barrier type"));
7213 inst.instruction |= inst.operands[0].imm;
7214 }
7215 else
7216 inst.instruction |= 0xf;
7217 }
7218
7219 static void
7220 do_bfc (void)
7221 {
7222 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
7223 constraint (msb > 32, _("bit-field extends past end of register"));
7224 /* The instruction encoding stores the LSB and MSB,
7225 not the LSB and width. */
7226 inst.instruction |= inst.operands[0].reg << 12;
7227 inst.instruction |= inst.operands[1].imm << 7;
7228 inst.instruction |= (msb - 1) << 16;
7229 }
7230
7231 static void
7232 do_bfi (void)
7233 {
7234 unsigned int msb;
7235
7236 /* #0 in second position is alternative syntax for bfc, which is
7237 the same instruction but with REG_PC in the Rm field. */
7238 if (!inst.operands[1].isreg)
7239 inst.operands[1].reg = REG_PC;
7240
7241 msb = inst.operands[2].imm + inst.operands[3].imm;
7242 constraint (msb > 32, _("bit-field extends past end of register"));
7243 /* The instruction encoding stores the LSB and MSB,
7244 not the LSB and width. */
7245 inst.instruction |= inst.operands[0].reg << 12;
7246 inst.instruction |= inst.operands[1].reg;
7247 inst.instruction |= inst.operands[2].imm << 7;
7248 inst.instruction |= (msb - 1) << 16;
7249 }
7250
7251 static void
7252 do_bfx (void)
7253 {
7254 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
7255 _("bit-field extends past end of register"));
7256 inst.instruction |= inst.operands[0].reg << 12;
7257 inst.instruction |= inst.operands[1].reg;
7258 inst.instruction |= inst.operands[2].imm << 7;
7259 inst.instruction |= (inst.operands[3].imm - 1) << 16;
7260 }
7261
7262 /* ARM V5 breakpoint instruction (argument parse)
7263 BKPT <16 bit unsigned immediate>
7264 Instruction is not conditional.
7265 The bit pattern given in insns[] has the COND_ALWAYS condition,
7266 and it is an error if the caller tried to override that. */
7267
7268 static void
7269 do_bkpt (void)
7270 {
7271 /* Top 12 of 16 bits to bits 19:8. */
7272 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
7273
7274 /* Bottom 4 of 16 bits to bits 3:0. */
7275 inst.instruction |= inst.operands[0].imm & 0xf;
7276 }
7277
7278 static void
7279 encode_branch (int default_reloc)
7280 {
7281 if (inst.operands[0].hasreloc)
7282 {
7283 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
7284 _("the only suffix valid here is '(plt)'"));
7285 inst.reloc.type = BFD_RELOC_ARM_PLT32;
7286 }
7287 else
7288 {
7289 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
7290 }
7291 inst.reloc.pc_rel = 1;
7292 }
7293
7294 static void
7295 do_branch (void)
7296 {
7297 #ifdef OBJ_ELF
7298 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7299 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7300 else
7301 #endif
7302 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7303 }
7304
7305 static void
7306 do_bl (void)
7307 {
7308 #ifdef OBJ_ELF
7309 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7310 {
7311 if (inst.cond == COND_ALWAYS)
7312 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
7313 else
7314 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7315 }
7316 else
7317 #endif
7318 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7319 }
7320
7321 /* ARM V5 branch-link-exchange instruction (argument parse)
7322 BLX <target_addr> ie BLX(1)
7323 BLX{<condition>} <Rm> ie BLX(2)
7324 Unfortunately, there are two different opcodes for this mnemonic.
7325 So, the insns[].value is not used, and the code here zaps values
7326 into inst.instruction.
7327 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
7328
7329 static void
7330 do_blx (void)
7331 {
7332 if (inst.operands[0].isreg)
7333 {
7334 /* Arg is a register; the opcode provided by insns[] is correct.
7335 It is not illegal to do "blx pc", just useless. */
7336 if (inst.operands[0].reg == REG_PC)
7337 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
7338
7339 inst.instruction |= inst.operands[0].reg;
7340 }
7341 else
7342 {
7343 /* Arg is an address; this instruction cannot be executed
7344 conditionally, and the opcode must be adjusted.
7345 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
7346 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
7347 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7348 inst.instruction = 0xfa000000;
7349 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
7350 }
7351 }
7352
7353 static void
7354 do_bx (void)
7355 {
7356 bfd_boolean want_reloc;
7357
7358 if (inst.operands[0].reg == REG_PC)
7359 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
7360
7361 inst.instruction |= inst.operands[0].reg;
7362 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
7363 it is for ARMv4t or earlier. */
7364 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
7365 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
7366 want_reloc = TRUE;
7367
7368 #ifdef OBJ_ELF
7369 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
7370 #endif
7371 want_reloc = FALSE;
7372
7373 if (want_reloc)
7374 inst.reloc.type = BFD_RELOC_ARM_V4BX;
7375 }
7376
7377
7378 /* ARM v5TEJ. Jump to Jazelle code. */
7379
7380 static void
7381 do_bxj (void)
7382 {
7383 if (inst.operands[0].reg == REG_PC)
7384 as_tsktsk (_("use of r15 in bxj is not really useful"));
7385
7386 inst.instruction |= inst.operands[0].reg;
7387 }
7388
7389 /* Co-processor data operation:
7390 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
7391 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
7392 static void
7393 do_cdp (void)
7394 {
7395 inst.instruction |= inst.operands[0].reg << 8;
7396 inst.instruction |= inst.operands[1].imm << 20;
7397 inst.instruction |= inst.operands[2].reg << 12;
7398 inst.instruction |= inst.operands[3].reg << 16;
7399 inst.instruction |= inst.operands[4].reg;
7400 inst.instruction |= inst.operands[5].imm << 5;
7401 }
7402
7403 static void
7404 do_cmp (void)
7405 {
7406 inst.instruction |= inst.operands[0].reg << 16;
7407 encode_arm_shifter_operand (1);
7408 }
7409
7410 /* Transfer between coprocessor and ARM registers.
7411 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
7412 MRC2
7413 MCR{cond}
7414 MCR2
7415
7416 No special properties. */
7417
7418 static void
7419 do_co_reg (void)
7420 {
7421 unsigned Rd;
7422
7423 Rd = inst.operands[2].reg;
7424 if (thumb_mode)
7425 {
7426 if (inst.instruction == 0xee000010
7427 || inst.instruction == 0xfe000010)
7428 /* MCR, MCR2 */
7429 reject_bad_reg (Rd);
7430 else
7431 /* MRC, MRC2 */
7432 constraint (Rd == REG_SP, BAD_SP);
7433 }
7434 else
7435 {
7436 /* MCR */
7437 if (inst.instruction == 0xe000010)
7438 constraint (Rd == REG_PC, BAD_PC);
7439 }
7440
7441
7442 inst.instruction |= inst.operands[0].reg << 8;
7443 inst.instruction |= inst.operands[1].imm << 21;
7444 inst.instruction |= Rd << 12;
7445 inst.instruction |= inst.operands[3].reg << 16;
7446 inst.instruction |= inst.operands[4].reg;
7447 inst.instruction |= inst.operands[5].imm << 5;
7448 }
7449
7450 /* Transfer between coprocessor register and pair of ARM registers.
7451 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7452 MCRR2
7453 MRRC{cond}
7454 MRRC2
7455
7456 Two XScale instructions are special cases of these:
7457
7458 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7459 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
7460
7461 Result unpredictable if Rd or Rn is R15. */
7462
7463 static void
7464 do_co_reg2c (void)
7465 {
7466 unsigned Rd, Rn;
7467
7468 Rd = inst.operands[2].reg;
7469 Rn = inst.operands[3].reg;
7470
7471 if (thumb_mode)
7472 {
7473 reject_bad_reg (Rd);
7474 reject_bad_reg (Rn);
7475 }
7476 else
7477 {
7478 constraint (Rd == REG_PC, BAD_PC);
7479 constraint (Rn == REG_PC, BAD_PC);
7480 }
7481
7482 inst.instruction |= inst.operands[0].reg << 8;
7483 inst.instruction |= inst.operands[1].imm << 4;
7484 inst.instruction |= Rd << 12;
7485 inst.instruction |= Rn << 16;
7486 inst.instruction |= inst.operands[4].reg;
7487 }
7488
7489 static void
7490 do_cpsi (void)
7491 {
7492 inst.instruction |= inst.operands[0].imm << 6;
7493 if (inst.operands[1].present)
7494 {
7495 inst.instruction |= CPSI_MMOD;
7496 inst.instruction |= inst.operands[1].imm;
7497 }
7498 }
7499
7500 static void
7501 do_dbg (void)
7502 {
7503 inst.instruction |= inst.operands[0].imm;
7504 }
7505
7506 static void
7507 do_div (void)
7508 {
7509 unsigned Rd, Rn, Rm;
7510
7511 Rd = inst.operands[0].reg;
7512 Rn = (inst.operands[1].present
7513 ? inst.operands[1].reg : Rd);
7514 Rm = inst.operands[2].reg;
7515
7516 constraint ((Rd == REG_PC), BAD_PC);
7517 constraint ((Rn == REG_PC), BAD_PC);
7518 constraint ((Rm == REG_PC), BAD_PC);
7519
7520 inst.instruction |= Rd << 16;
7521 inst.instruction |= Rn << 0;
7522 inst.instruction |= Rm << 8;
7523 }
7524
7525 static void
7526 do_it (void)
7527 {
7528 /* There is no IT instruction in ARM mode. We
7529 process it to do the validation as if in
7530 thumb mode, just in case the code gets
7531 assembled for thumb using the unified syntax. */
7532
7533 inst.size = 0;
7534 if (unified_syntax)
7535 {
7536 set_it_insn_type (IT_INSN);
7537 now_it.mask = (inst.instruction & 0xf) | 0x10;
7538 now_it.cc = inst.operands[0].imm;
7539 }
7540 }
7541
7542 static void
7543 do_ldmstm (void)
7544 {
7545 int base_reg = inst.operands[0].reg;
7546 int range = inst.operands[1].imm;
7547
7548 inst.instruction |= base_reg << 16;
7549 inst.instruction |= range;
7550
7551 if (inst.operands[1].writeback)
7552 inst.instruction |= LDM_TYPE_2_OR_3;
7553
7554 if (inst.operands[0].writeback)
7555 {
7556 inst.instruction |= WRITE_BACK;
7557 /* Check for unpredictable uses of writeback. */
7558 if (inst.instruction & LOAD_BIT)
7559 {
7560 /* Not allowed in LDM type 2. */
7561 if ((inst.instruction & LDM_TYPE_2_OR_3)
7562 && ((range & (1 << REG_PC)) == 0))
7563 as_warn (_("writeback of base register is UNPREDICTABLE"));
7564 /* Only allowed if base reg not in list for other types. */
7565 else if (range & (1 << base_reg))
7566 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7567 }
7568 else /* STM. */
7569 {
7570 /* Not allowed for type 2. */
7571 if (inst.instruction & LDM_TYPE_2_OR_3)
7572 as_warn (_("writeback of base register is UNPREDICTABLE"));
7573 /* Only allowed if base reg not in list, or first in list. */
7574 else if ((range & (1 << base_reg))
7575 && (range & ((1 << base_reg) - 1)))
7576 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
7577 }
7578 }
7579 }
7580
7581 /* ARMv5TE load-consecutive (argument parse)
7582 Mode is like LDRH.
7583
7584 LDRccD R, mode
7585 STRccD R, mode. */
7586
7587 static void
7588 do_ldrd (void)
7589 {
7590 constraint (inst.operands[0].reg % 2 != 0,
7591 _("first destination register must be even"));
7592 constraint (inst.operands[1].present
7593 && inst.operands[1].reg != inst.operands[0].reg + 1,
7594 _("can only load two consecutive registers"));
7595 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7596 constraint (!inst.operands[2].isreg, _("'[' expected"));
7597
7598 if (!inst.operands[1].present)
7599 inst.operands[1].reg = inst.operands[0].reg + 1;
7600
7601 if (inst.instruction & LOAD_BIT)
7602 {
7603 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7604 register and the first register written; we have to diagnose
7605 overlap between the base and the second register written here. */
7606
7607 if (inst.operands[2].reg == inst.operands[1].reg
7608 && (inst.operands[2].writeback || inst.operands[2].postind))
7609 as_warn (_("base register written back, and overlaps "
7610 "second destination register"));
7611
7612 /* For an index-register load, the index register must not overlap the
7613 destination (even if not write-back). */
7614 else if (inst.operands[2].immisreg
7615 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7616 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
7617 as_warn (_("index register overlaps destination register"));
7618 }
7619
7620 inst.instruction |= inst.operands[0].reg << 12;
7621 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
7622 }
7623
7624 static void
7625 do_ldrex (void)
7626 {
7627 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7628 || inst.operands[1].postind || inst.operands[1].writeback
7629 || inst.operands[1].immisreg || inst.operands[1].shifted
7630 || inst.operands[1].negative
7631 /* This can arise if the programmer has written
7632 strex rN, rM, foo
7633 or if they have mistakenly used a register name as the last
7634 operand, eg:
7635 strex rN, rM, rX
7636 It is very difficult to distinguish between these two cases
7637 because "rX" might actually be a label. ie the register
7638 name has been occluded by a symbol of the same name. So we
7639 just generate a general 'bad addressing mode' type error
7640 message and leave it up to the programmer to discover the
7641 true cause and fix their mistake. */
7642 || (inst.operands[1].reg == REG_PC),
7643 BAD_ADDR_MODE);
7644
7645 constraint (inst.reloc.exp.X_op != O_constant
7646 || inst.reloc.exp.X_add_number != 0,
7647 _("offset must be zero in ARM encoding"));
7648
7649 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
7650
7651 inst.instruction |= inst.operands[0].reg << 12;
7652 inst.instruction |= inst.operands[1].reg << 16;
7653 inst.reloc.type = BFD_RELOC_UNUSED;
7654 }
7655
7656 static void
7657 do_ldrexd (void)
7658 {
7659 constraint (inst.operands[0].reg % 2 != 0,
7660 _("even register required"));
7661 constraint (inst.operands[1].present
7662 && inst.operands[1].reg != inst.operands[0].reg + 1,
7663 _("can only load two consecutive registers"));
7664 /* If op 1 were present and equal to PC, this function wouldn't
7665 have been called in the first place. */
7666 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7667
7668 inst.instruction |= inst.operands[0].reg << 12;
7669 inst.instruction |= inst.operands[2].reg << 16;
7670 }
7671
7672 static void
7673 do_ldst (void)
7674 {
7675 inst.instruction |= inst.operands[0].reg << 12;
7676 if (!inst.operands[1].isreg)
7677 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
7678 return;
7679 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
7680 }
7681
7682 static void
7683 do_ldstt (void)
7684 {
7685 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7686 reject [Rn,...]. */
7687 if (inst.operands[1].preind)
7688 {
7689 constraint (inst.reloc.exp.X_op != O_constant
7690 || inst.reloc.exp.X_add_number != 0,
7691 _("this instruction requires a post-indexed address"));
7692
7693 inst.operands[1].preind = 0;
7694 inst.operands[1].postind = 1;
7695 inst.operands[1].writeback = 1;
7696 }
7697 inst.instruction |= inst.operands[0].reg << 12;
7698 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7699 }
7700
7701 /* Halfword and signed-byte load/store operations. */
7702
7703 static void
7704 do_ldstv4 (void)
7705 {
7706 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
7707 inst.instruction |= inst.operands[0].reg << 12;
7708 if (!inst.operands[1].isreg)
7709 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
7710 return;
7711 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
7712 }
7713
7714 static void
7715 do_ldsttv4 (void)
7716 {
7717 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7718 reject [Rn,...]. */
7719 if (inst.operands[1].preind)
7720 {
7721 constraint (inst.reloc.exp.X_op != O_constant
7722 || inst.reloc.exp.X_add_number != 0,
7723 _("this instruction requires a post-indexed address"));
7724
7725 inst.operands[1].preind = 0;
7726 inst.operands[1].postind = 1;
7727 inst.operands[1].writeback = 1;
7728 }
7729 inst.instruction |= inst.operands[0].reg << 12;
7730 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7731 }
7732
7733 /* Co-processor register load/store.
7734 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7735 static void
7736 do_lstc (void)
7737 {
7738 inst.instruction |= inst.operands[0].reg << 8;
7739 inst.instruction |= inst.operands[1].reg << 12;
7740 encode_arm_cp_address (2, TRUE, TRUE, 0);
7741 }
7742
7743 static void
7744 do_mlas (void)
7745 {
7746 /* This restriction does not apply to mls (nor to mla in v6 or later). */
7747 if (inst.operands[0].reg == inst.operands[1].reg
7748 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
7749 && !(inst.instruction & 0x00400000))
7750 as_tsktsk (_("Rd and Rm should be different in mla"));
7751
7752 inst.instruction |= inst.operands[0].reg << 16;
7753 inst.instruction |= inst.operands[1].reg;
7754 inst.instruction |= inst.operands[2].reg << 8;
7755 inst.instruction |= inst.operands[3].reg << 12;
7756 }
7757
7758 static void
7759 do_mov (void)
7760 {
7761 inst.instruction |= inst.operands[0].reg << 12;
7762 encode_arm_shifter_operand (1);
7763 }
7764
7765 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7766 static void
7767 do_mov16 (void)
7768 {
7769 bfd_vma imm;
7770 bfd_boolean top;
7771
7772 top = (inst.instruction & 0x00400000) != 0;
7773 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7774 _(":lower16: not allowed this instruction"));
7775 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7776 _(":upper16: not allowed instruction"));
7777 inst.instruction |= inst.operands[0].reg << 12;
7778 if (inst.reloc.type == BFD_RELOC_UNUSED)
7779 {
7780 imm = inst.reloc.exp.X_add_number;
7781 /* The value is in two pieces: 0:11, 16:19. */
7782 inst.instruction |= (imm & 0x00000fff);
7783 inst.instruction |= (imm & 0x0000f000) << 4;
7784 }
7785 }
7786
7787 static void do_vfp_nsyn_opcode (const char *);
7788
7789 static int
7790 do_vfp_nsyn_mrs (void)
7791 {
7792 if (inst.operands[0].isvec)
7793 {
7794 if (inst.operands[1].reg != 1)
7795 first_error (_("operand 1 must be FPSCR"));
7796 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7797 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7798 do_vfp_nsyn_opcode ("fmstat");
7799 }
7800 else if (inst.operands[1].isvec)
7801 do_vfp_nsyn_opcode ("fmrx");
7802 else
7803 return FAIL;
7804
7805 return SUCCESS;
7806 }
7807
7808 static int
7809 do_vfp_nsyn_msr (void)
7810 {
7811 if (inst.operands[0].isvec)
7812 do_vfp_nsyn_opcode ("fmxr");
7813 else
7814 return FAIL;
7815
7816 return SUCCESS;
7817 }
7818
7819 static void
7820 do_vmrs (void)
7821 {
7822 unsigned Rt = inst.operands[0].reg;
7823
7824 if (thumb_mode && inst.operands[0].reg == REG_SP)
7825 {
7826 inst.error = BAD_SP;
7827 return;
7828 }
7829
7830 /* APSR_ sets isvec. All other refs to PC are illegal. */
7831 if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC)
7832 {
7833 inst.error = BAD_PC;
7834 return;
7835 }
7836
7837 if (inst.operands[1].reg != 1)
7838 first_error (_("operand 1 must be FPSCR"));
7839
7840 inst.instruction |= (Rt << 12);
7841 }
7842
7843 static void
7844 do_vmsr (void)
7845 {
7846 unsigned Rt = inst.operands[1].reg;
7847
7848 if (thumb_mode)
7849 reject_bad_reg (Rt);
7850 else if (Rt == REG_PC)
7851 {
7852 inst.error = BAD_PC;
7853 return;
7854 }
7855
7856 if (inst.operands[0].reg != 1)
7857 first_error (_("operand 0 must be FPSCR"));
7858
7859 inst.instruction |= (Rt << 12);
7860 }
7861
7862 static void
7863 do_mrs (void)
7864 {
7865 unsigned br;
7866
7867 if (do_vfp_nsyn_mrs () == SUCCESS)
7868 return;
7869
7870 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
7871 inst.instruction |= inst.operands[0].reg << 12;
7872
7873 if (inst.operands[1].isreg)
7874 {
7875 br = inst.operands[1].reg;
7876 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
7877 as_bad (_("bad register for mrs"));
7878 }
7879 else
7880 {
7881 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7882 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7883 != (PSR_c|PSR_f),
7884 _("'CPSR' or 'SPSR' expected"));
7885 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
7886 }
7887
7888 inst.instruction |= br;
7889 }
7890
7891 /* Two possible forms:
7892 "{C|S}PSR_<field>, Rm",
7893 "{C|S}PSR_f, #expression". */
7894
7895 static void
7896 do_msr (void)
7897 {
7898 if (do_vfp_nsyn_msr () == SUCCESS)
7899 return;
7900
7901 inst.instruction |= inst.operands[0].imm;
7902 if (inst.operands[1].isreg)
7903 inst.instruction |= inst.operands[1].reg;
7904 else
7905 {
7906 inst.instruction |= INST_IMMEDIATE;
7907 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7908 inst.reloc.pc_rel = 0;
7909 }
7910 }
7911
7912 static void
7913 do_mul (void)
7914 {
7915 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
7916
7917 if (!inst.operands[2].present)
7918 inst.operands[2].reg = inst.operands[0].reg;
7919 inst.instruction |= inst.operands[0].reg << 16;
7920 inst.instruction |= inst.operands[1].reg;
7921 inst.instruction |= inst.operands[2].reg << 8;
7922
7923 if (inst.operands[0].reg == inst.operands[1].reg
7924 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7925 as_tsktsk (_("Rd and Rm should be different in mul"));
7926 }
7927
7928 /* Long Multiply Parser
7929 UMULL RdLo, RdHi, Rm, Rs
7930 SMULL RdLo, RdHi, Rm, Rs
7931 UMLAL RdLo, RdHi, Rm, Rs
7932 SMLAL RdLo, RdHi, Rm, Rs. */
7933
7934 static void
7935 do_mull (void)
7936 {
7937 inst.instruction |= inst.operands[0].reg << 12;
7938 inst.instruction |= inst.operands[1].reg << 16;
7939 inst.instruction |= inst.operands[2].reg;
7940 inst.instruction |= inst.operands[3].reg << 8;
7941
7942 /* rdhi and rdlo must be different. */
7943 if (inst.operands[0].reg == inst.operands[1].reg)
7944 as_tsktsk (_("rdhi and rdlo must be different"));
7945
7946 /* rdhi, rdlo and rm must all be different before armv6. */
7947 if ((inst.operands[0].reg == inst.operands[2].reg
7948 || inst.operands[1].reg == inst.operands[2].reg)
7949 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7950 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7951 }
7952
7953 static void
7954 do_nop (void)
7955 {
7956 if (inst.operands[0].present
7957 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
7958 {
7959 /* Architectural NOP hints are CPSR sets with no bits selected. */
7960 inst.instruction &= 0xf0000000;
7961 inst.instruction |= 0x0320f000;
7962 if (inst.operands[0].present)
7963 inst.instruction |= inst.operands[0].imm;
7964 }
7965 }
7966
7967 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7968 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7969 Condition defaults to COND_ALWAYS.
7970 Error if Rd, Rn or Rm are R15. */
7971
7972 static void
7973 do_pkhbt (void)
7974 {
7975 inst.instruction |= inst.operands[0].reg << 12;
7976 inst.instruction |= inst.operands[1].reg << 16;
7977 inst.instruction |= inst.operands[2].reg;
7978 if (inst.operands[3].present)
7979 encode_arm_shift (3);
7980 }
7981
7982 /* ARM V6 PKHTB (Argument Parse). */
7983
7984 static void
7985 do_pkhtb (void)
7986 {
7987 if (!inst.operands[3].present)
7988 {
7989 /* If the shift specifier is omitted, turn the instruction
7990 into pkhbt rd, rm, rn. */
7991 inst.instruction &= 0xfff00010;
7992 inst.instruction |= inst.operands[0].reg << 12;
7993 inst.instruction |= inst.operands[1].reg;
7994 inst.instruction |= inst.operands[2].reg << 16;
7995 }
7996 else
7997 {
7998 inst.instruction |= inst.operands[0].reg << 12;
7999 inst.instruction |= inst.operands[1].reg << 16;
8000 inst.instruction |= inst.operands[2].reg;
8001 encode_arm_shift (3);
8002 }
8003 }
8004
8005 /* ARMv5TE: Preload-Cache
8006 MP Extensions: Preload for write
8007
8008 PLD(W) <addr_mode>
8009
8010 Syntactically, like LDR with B=1, W=0, L=1. */
8011
8012 static void
8013 do_pld (void)
8014 {
8015 constraint (!inst.operands[0].isreg,
8016 _("'[' expected after PLD mnemonic"));
8017 constraint (inst.operands[0].postind,
8018 _("post-indexed expression used in preload instruction"));
8019 constraint (inst.operands[0].writeback,
8020 _("writeback used in preload instruction"));
8021 constraint (!inst.operands[0].preind,
8022 _("unindexed addressing used in preload instruction"));
8023 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8024 }
8025
8026 /* ARMv7: PLI <addr_mode> */
8027 static void
8028 do_pli (void)
8029 {
8030 constraint (!inst.operands[0].isreg,
8031 _("'[' expected after PLI mnemonic"));
8032 constraint (inst.operands[0].postind,
8033 _("post-indexed expression used in preload instruction"));
8034 constraint (inst.operands[0].writeback,
8035 _("writeback used in preload instruction"));
8036 constraint (!inst.operands[0].preind,
8037 _("unindexed addressing used in preload instruction"));
8038 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8039 inst.instruction &= ~PRE_INDEX;
8040 }
8041
8042 static void
8043 do_push_pop (void)
8044 {
8045 inst.operands[1] = inst.operands[0];
8046 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
8047 inst.operands[0].isreg = 1;
8048 inst.operands[0].writeback = 1;
8049 inst.operands[0].reg = REG_SP;
8050 do_ldmstm ();
8051 }
8052
8053 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
8054 word at the specified address and the following word
8055 respectively.
8056 Unconditionally executed.
8057 Error if Rn is R15. */
8058
8059 static void
8060 do_rfe (void)
8061 {
8062 inst.instruction |= inst.operands[0].reg << 16;
8063 if (inst.operands[0].writeback)
8064 inst.instruction |= WRITE_BACK;
8065 }
8066
8067 /* ARM V6 ssat (argument parse). */
8068
8069 static void
8070 do_ssat (void)
8071 {
8072 inst.instruction |= inst.operands[0].reg << 12;
8073 inst.instruction |= (inst.operands[1].imm - 1) << 16;
8074 inst.instruction |= inst.operands[2].reg;
8075
8076 if (inst.operands[3].present)
8077 encode_arm_shift (3);
8078 }
8079
8080 /* ARM V6 usat (argument parse). */
8081
8082 static void
8083 do_usat (void)
8084 {
8085 inst.instruction |= inst.operands[0].reg << 12;
8086 inst.instruction |= inst.operands[1].imm << 16;
8087 inst.instruction |= inst.operands[2].reg;
8088
8089 if (inst.operands[3].present)
8090 encode_arm_shift (3);
8091 }
8092
8093 /* ARM V6 ssat16 (argument parse). */
8094
8095 static void
8096 do_ssat16 (void)
8097 {
8098 inst.instruction |= inst.operands[0].reg << 12;
8099 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
8100 inst.instruction |= inst.operands[2].reg;
8101 }
8102
8103 static void
8104 do_usat16 (void)
8105 {
8106 inst.instruction |= inst.operands[0].reg << 12;
8107 inst.instruction |= inst.operands[1].imm << 16;
8108 inst.instruction |= inst.operands[2].reg;
8109 }
8110
8111 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
8112 preserving the other bits.
8113
8114 setend <endian_specifier>, where <endian_specifier> is either
8115 BE or LE. */
8116
8117 static void
8118 do_setend (void)
8119 {
8120 if (inst.operands[0].imm)
8121 inst.instruction |= 0x200;
8122 }
8123
8124 static void
8125 do_shift (void)
8126 {
8127 unsigned int Rm = (inst.operands[1].present
8128 ? inst.operands[1].reg
8129 : inst.operands[0].reg);
8130
8131 inst.instruction |= inst.operands[0].reg << 12;
8132 inst.instruction |= Rm;
8133 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
8134 {
8135 inst.instruction |= inst.operands[2].reg << 8;
8136 inst.instruction |= SHIFT_BY_REG;
8137 }
8138 else
8139 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
8140 }
8141
8142 static void
8143 do_smc (void)
8144 {
8145 inst.reloc.type = BFD_RELOC_ARM_SMC;
8146 inst.reloc.pc_rel = 0;
8147 }
8148
8149 static void
8150 do_hvc (void)
8151 {
8152 inst.reloc.type = BFD_RELOC_ARM_HVC;
8153 inst.reloc.pc_rel = 0;
8154 }
8155
8156 static void
8157 do_swi (void)
8158 {
8159 inst.reloc.type = BFD_RELOC_ARM_SWI;
8160 inst.reloc.pc_rel = 0;
8161 }
8162
8163 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
8164 SMLAxy{cond} Rd,Rm,Rs,Rn
8165 SMLAWy{cond} Rd,Rm,Rs,Rn
8166 Error if any register is R15. */
8167
8168 static void
8169 do_smla (void)
8170 {
8171 inst.instruction |= inst.operands[0].reg << 16;
8172 inst.instruction |= inst.operands[1].reg;
8173 inst.instruction |= inst.operands[2].reg << 8;
8174 inst.instruction |= inst.operands[3].reg << 12;
8175 }
8176
8177 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
8178 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
8179 Error if any register is R15.
8180 Warning if Rdlo == Rdhi. */
8181
8182 static void
8183 do_smlal (void)
8184 {
8185 inst.instruction |= inst.operands[0].reg << 12;
8186 inst.instruction |= inst.operands[1].reg << 16;
8187 inst.instruction |= inst.operands[2].reg;
8188 inst.instruction |= inst.operands[3].reg << 8;
8189
8190 if (inst.operands[0].reg == inst.operands[1].reg)
8191 as_tsktsk (_("rdhi and rdlo must be different"));
8192 }
8193
8194 /* ARM V5E (El Segundo) signed-multiply (argument parse)
8195 SMULxy{cond} Rd,Rm,Rs
8196 Error if any register is R15. */
8197
8198 static void
8199 do_smul (void)
8200 {
8201 inst.instruction |= inst.operands[0].reg << 16;
8202 inst.instruction |= inst.operands[1].reg;
8203 inst.instruction |= inst.operands[2].reg << 8;
8204 }
8205
8206 /* ARM V6 srs (argument parse). The variable fields in the encoding are
8207 the same for both ARM and Thumb-2. */
8208
8209 static void
8210 do_srs (void)
8211 {
8212 int reg;
8213
8214 if (inst.operands[0].present)
8215 {
8216 reg = inst.operands[0].reg;
8217 constraint (reg != REG_SP, _("SRS base register must be r13"));
8218 }
8219 else
8220 reg = REG_SP;
8221
8222 inst.instruction |= reg << 16;
8223 inst.instruction |= inst.operands[1].imm;
8224 if (inst.operands[0].writeback || inst.operands[1].writeback)
8225 inst.instruction |= WRITE_BACK;
8226 }
8227
8228 /* ARM V6 strex (argument parse). */
8229
8230 static void
8231 do_strex (void)
8232 {
8233 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8234 || inst.operands[2].postind || inst.operands[2].writeback
8235 || inst.operands[2].immisreg || inst.operands[2].shifted
8236 || inst.operands[2].negative
8237 /* See comment in do_ldrex(). */
8238 || (inst.operands[2].reg == REG_PC),
8239 BAD_ADDR_MODE);
8240
8241 constraint (inst.operands[0].reg == inst.operands[1].reg
8242 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8243
8244 constraint (inst.reloc.exp.X_op != O_constant
8245 || inst.reloc.exp.X_add_number != 0,
8246 _("offset must be zero in ARM encoding"));
8247
8248 inst.instruction |= inst.operands[0].reg << 12;
8249 inst.instruction |= inst.operands[1].reg;
8250 inst.instruction |= inst.operands[2].reg << 16;
8251 inst.reloc.type = BFD_RELOC_UNUSED;
8252 }
8253
8254 static void
8255 do_strexd (void)
8256 {
8257 constraint (inst.operands[1].reg % 2 != 0,
8258 _("even register required"));
8259 constraint (inst.operands[2].present
8260 && inst.operands[2].reg != inst.operands[1].reg + 1,
8261 _("can only store two consecutive registers"));
8262 /* If op 2 were present and equal to PC, this function wouldn't
8263 have been called in the first place. */
8264 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
8265
8266 constraint (inst.operands[0].reg == inst.operands[1].reg
8267 || inst.operands[0].reg == inst.operands[1].reg + 1
8268 || inst.operands[0].reg == inst.operands[3].reg,
8269 BAD_OVERLAP);
8270
8271 inst.instruction |= inst.operands[0].reg << 12;
8272 inst.instruction |= inst.operands[1].reg;
8273 inst.instruction |= inst.operands[3].reg << 16;
8274 }
8275
8276 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
8277 extends it to 32-bits, and adds the result to a value in another
8278 register. You can specify a rotation by 0, 8, 16, or 24 bits
8279 before extracting the 16-bit value.
8280 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
8281 Condition defaults to COND_ALWAYS.
8282 Error if any register uses R15. */
8283
8284 static void
8285 do_sxtah (void)
8286 {
8287 inst.instruction |= inst.operands[0].reg << 12;
8288 inst.instruction |= inst.operands[1].reg << 16;
8289 inst.instruction |= inst.operands[2].reg;
8290 inst.instruction |= inst.operands[3].imm << 10;
8291 }
8292
8293 /* ARM V6 SXTH.
8294
8295 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
8296 Condition defaults to COND_ALWAYS.
8297 Error if any register uses R15. */
8298
8299 static void
8300 do_sxth (void)
8301 {
8302 inst.instruction |= inst.operands[0].reg << 12;
8303 inst.instruction |= inst.operands[1].reg;
8304 inst.instruction |= inst.operands[2].imm << 10;
8305 }
8306 \f
8307 /* VFP instructions. In a logical order: SP variant first, monad
8308 before dyad, arithmetic then move then load/store. */
8309
8310 static void
8311 do_vfp_sp_monadic (void)
8312 {
8313 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8314 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
8315 }
8316
8317 static void
8318 do_vfp_sp_dyadic (void)
8319 {
8320 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8321 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8322 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
8323 }
8324
8325 static void
8326 do_vfp_sp_compare_z (void)
8327 {
8328 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8329 }
8330
8331 static void
8332 do_vfp_dp_sp_cvt (void)
8333 {
8334 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8335 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
8336 }
8337
8338 static void
8339 do_vfp_sp_dp_cvt (void)
8340 {
8341 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8342 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8343 }
8344
8345 static void
8346 do_vfp_reg_from_sp (void)
8347 {
8348 inst.instruction |= inst.operands[0].reg << 12;
8349 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8350 }
8351
8352 static void
8353 do_vfp_reg2_from_sp2 (void)
8354 {
8355 constraint (inst.operands[2].imm != 2,
8356 _("only two consecutive VFP SP registers allowed here"));
8357 inst.instruction |= inst.operands[0].reg << 12;
8358 inst.instruction |= inst.operands[1].reg << 16;
8359 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
8360 }
8361
8362 static void
8363 do_vfp_sp_from_reg (void)
8364 {
8365 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
8366 inst.instruction |= inst.operands[1].reg << 12;
8367 }
8368
8369 static void
8370 do_vfp_sp2_from_reg2 (void)
8371 {
8372 constraint (inst.operands[0].imm != 2,
8373 _("only two consecutive VFP SP registers allowed here"));
8374 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
8375 inst.instruction |= inst.operands[1].reg << 12;
8376 inst.instruction |= inst.operands[2].reg << 16;
8377 }
8378
8379 static void
8380 do_vfp_sp_ldst (void)
8381 {
8382 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8383 encode_arm_cp_address (1, FALSE, TRUE, 0);
8384 }
8385
8386 static void
8387 do_vfp_dp_ldst (void)
8388 {
8389 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8390 encode_arm_cp_address (1, FALSE, TRUE, 0);
8391 }
8392
8393
8394 static void
8395 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
8396 {
8397 if (inst.operands[0].writeback)
8398 inst.instruction |= WRITE_BACK;
8399 else
8400 constraint (ldstm_type != VFP_LDSTMIA,
8401 _("this addressing mode requires base-register writeback"));
8402 inst.instruction |= inst.operands[0].reg << 16;
8403 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
8404 inst.instruction |= inst.operands[1].imm;
8405 }
8406
8407 static void
8408 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
8409 {
8410 int count;
8411
8412 if (inst.operands[0].writeback)
8413 inst.instruction |= WRITE_BACK;
8414 else
8415 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
8416 _("this addressing mode requires base-register writeback"));
8417
8418 inst.instruction |= inst.operands[0].reg << 16;
8419 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8420
8421 count = inst.operands[1].imm << 1;
8422 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
8423 count += 1;
8424
8425 inst.instruction |= count;
8426 }
8427
8428 static void
8429 do_vfp_sp_ldstmia (void)
8430 {
8431 vfp_sp_ldstm (VFP_LDSTMIA);
8432 }
8433
8434 static void
8435 do_vfp_sp_ldstmdb (void)
8436 {
8437 vfp_sp_ldstm (VFP_LDSTMDB);
8438 }
8439
8440 static void
8441 do_vfp_dp_ldstmia (void)
8442 {
8443 vfp_dp_ldstm (VFP_LDSTMIA);
8444 }
8445
8446 static void
8447 do_vfp_dp_ldstmdb (void)
8448 {
8449 vfp_dp_ldstm (VFP_LDSTMDB);
8450 }
8451
8452 static void
8453 do_vfp_xp_ldstmia (void)
8454 {
8455 vfp_dp_ldstm (VFP_LDSTMIAX);
8456 }
8457
8458 static void
8459 do_vfp_xp_ldstmdb (void)
8460 {
8461 vfp_dp_ldstm (VFP_LDSTMDBX);
8462 }
8463
8464 static void
8465 do_vfp_dp_rd_rm (void)
8466 {
8467 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8468 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8469 }
8470
8471 static void
8472 do_vfp_dp_rn_rd (void)
8473 {
8474 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
8475 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8476 }
8477
8478 static void
8479 do_vfp_dp_rd_rn (void)
8480 {
8481 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8482 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8483 }
8484
8485 static void
8486 do_vfp_dp_rd_rn_rm (void)
8487 {
8488 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8489 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8490 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
8491 }
8492
8493 static void
8494 do_vfp_dp_rd (void)
8495 {
8496 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8497 }
8498
8499 static void
8500 do_vfp_dp_rm_rd_rn (void)
8501 {
8502 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
8503 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8504 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8505 }
8506
8507 /* VFPv3 instructions. */
8508 static void
8509 do_vfp_sp_const (void)
8510 {
8511 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8512 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8513 inst.instruction |= (inst.operands[1].imm & 0x0f);
8514 }
8515
8516 static void
8517 do_vfp_dp_const (void)
8518 {
8519 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8520 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8521 inst.instruction |= (inst.operands[1].imm & 0x0f);
8522 }
8523
8524 static void
8525 vfp_conv (int srcsize)
8526 {
8527 unsigned immbits = srcsize - inst.operands[1].imm;
8528 inst.instruction |= (immbits & 1) << 5;
8529 inst.instruction |= (immbits >> 1);
8530 }
8531
8532 static void
8533 do_vfp_sp_conv_16 (void)
8534 {
8535 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8536 vfp_conv (16);
8537 }
8538
8539 static void
8540 do_vfp_dp_conv_16 (void)
8541 {
8542 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8543 vfp_conv (16);
8544 }
8545
8546 static void
8547 do_vfp_sp_conv_32 (void)
8548 {
8549 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8550 vfp_conv (32);
8551 }
8552
8553 static void
8554 do_vfp_dp_conv_32 (void)
8555 {
8556 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8557 vfp_conv (32);
8558 }
8559 \f
8560 /* FPA instructions. Also in a logical order. */
8561
8562 static void
8563 do_fpa_cmp (void)
8564 {
8565 inst.instruction |= inst.operands[0].reg << 16;
8566 inst.instruction |= inst.operands[1].reg;
8567 }
8568
8569 static void
8570 do_fpa_ldmstm (void)
8571 {
8572 inst.instruction |= inst.operands[0].reg << 12;
8573 switch (inst.operands[1].imm)
8574 {
8575 case 1: inst.instruction |= CP_T_X; break;
8576 case 2: inst.instruction |= CP_T_Y; break;
8577 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
8578 case 4: break;
8579 default: abort ();
8580 }
8581
8582 if (inst.instruction & (PRE_INDEX | INDEX_UP))
8583 {
8584 /* The instruction specified "ea" or "fd", so we can only accept
8585 [Rn]{!}. The instruction does not really support stacking or
8586 unstacking, so we have to emulate these by setting appropriate
8587 bits and offsets. */
8588 constraint (inst.reloc.exp.X_op != O_constant
8589 || inst.reloc.exp.X_add_number != 0,
8590 _("this instruction does not support indexing"));
8591
8592 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
8593 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
8594
8595 if (!(inst.instruction & INDEX_UP))
8596 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
8597
8598 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
8599 {
8600 inst.operands[2].preind = 0;
8601 inst.operands[2].postind = 1;
8602 }
8603 }
8604
8605 encode_arm_cp_address (2, TRUE, TRUE, 0);
8606 }
8607 \f
8608 /* iWMMXt instructions: strictly in alphabetical order. */
8609
8610 static void
8611 do_iwmmxt_tandorc (void)
8612 {
8613 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
8614 }
8615
8616 static void
8617 do_iwmmxt_textrc (void)
8618 {
8619 inst.instruction |= inst.operands[0].reg << 12;
8620 inst.instruction |= inst.operands[1].imm;
8621 }
8622
8623 static void
8624 do_iwmmxt_textrm (void)
8625 {
8626 inst.instruction |= inst.operands[0].reg << 12;
8627 inst.instruction |= inst.operands[1].reg << 16;
8628 inst.instruction |= inst.operands[2].imm;
8629 }
8630
8631 static void
8632 do_iwmmxt_tinsr (void)
8633 {
8634 inst.instruction |= inst.operands[0].reg << 16;
8635 inst.instruction |= inst.operands[1].reg << 12;
8636 inst.instruction |= inst.operands[2].imm;
8637 }
8638
8639 static void
8640 do_iwmmxt_tmia (void)
8641 {
8642 inst.instruction |= inst.operands[0].reg << 5;
8643 inst.instruction |= inst.operands[1].reg;
8644 inst.instruction |= inst.operands[2].reg << 12;
8645 }
8646
8647 static void
8648 do_iwmmxt_waligni (void)
8649 {
8650 inst.instruction |= inst.operands[0].reg << 12;
8651 inst.instruction |= inst.operands[1].reg << 16;
8652 inst.instruction |= inst.operands[2].reg;
8653 inst.instruction |= inst.operands[3].imm << 20;
8654 }
8655
8656 static void
8657 do_iwmmxt_wmerge (void)
8658 {
8659 inst.instruction |= inst.operands[0].reg << 12;
8660 inst.instruction |= inst.operands[1].reg << 16;
8661 inst.instruction |= inst.operands[2].reg;
8662 inst.instruction |= inst.operands[3].imm << 21;
8663 }
8664
8665 static void
8666 do_iwmmxt_wmov (void)
8667 {
8668 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
8669 inst.instruction |= inst.operands[0].reg << 12;
8670 inst.instruction |= inst.operands[1].reg << 16;
8671 inst.instruction |= inst.operands[1].reg;
8672 }
8673
8674 static void
8675 do_iwmmxt_wldstbh (void)
8676 {
8677 int reloc;
8678 inst.instruction |= inst.operands[0].reg << 12;
8679 if (thumb_mode)
8680 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
8681 else
8682 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
8683 encode_arm_cp_address (1, TRUE, FALSE, reloc);
8684 }
8685
8686 static void
8687 do_iwmmxt_wldstw (void)
8688 {
8689 /* RIWR_RIWC clears .isreg for a control register. */
8690 if (!inst.operands[0].isreg)
8691 {
8692 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8693 inst.instruction |= 0xf0000000;
8694 }
8695
8696 inst.instruction |= inst.operands[0].reg << 12;
8697 encode_arm_cp_address (1, TRUE, TRUE, 0);
8698 }
8699
8700 static void
8701 do_iwmmxt_wldstd (void)
8702 {
8703 inst.instruction |= inst.operands[0].reg << 12;
8704 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
8705 && inst.operands[1].immisreg)
8706 {
8707 inst.instruction &= ~0x1a000ff;
8708 inst.instruction |= (0xf << 28);
8709 if (inst.operands[1].preind)
8710 inst.instruction |= PRE_INDEX;
8711 if (!inst.operands[1].negative)
8712 inst.instruction |= INDEX_UP;
8713 if (inst.operands[1].writeback)
8714 inst.instruction |= WRITE_BACK;
8715 inst.instruction |= inst.operands[1].reg << 16;
8716 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8717 inst.instruction |= inst.operands[1].imm;
8718 }
8719 else
8720 encode_arm_cp_address (1, TRUE, FALSE, 0);
8721 }
8722
8723 static void
8724 do_iwmmxt_wshufh (void)
8725 {
8726 inst.instruction |= inst.operands[0].reg << 12;
8727 inst.instruction |= inst.operands[1].reg << 16;
8728 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8729 inst.instruction |= (inst.operands[2].imm & 0x0f);
8730 }
8731
8732 static void
8733 do_iwmmxt_wzero (void)
8734 {
8735 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8736 inst.instruction |= inst.operands[0].reg;
8737 inst.instruction |= inst.operands[0].reg << 12;
8738 inst.instruction |= inst.operands[0].reg << 16;
8739 }
8740
8741 static void
8742 do_iwmmxt_wrwrwr_or_imm5 (void)
8743 {
8744 if (inst.operands[2].isreg)
8745 do_rd_rn_rm ();
8746 else {
8747 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8748 _("immediate operand requires iWMMXt2"));
8749 do_rd_rn ();
8750 if (inst.operands[2].imm == 0)
8751 {
8752 switch ((inst.instruction >> 20) & 0xf)
8753 {
8754 case 4:
8755 case 5:
8756 case 6:
8757 case 7:
8758 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8759 inst.operands[2].imm = 16;
8760 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8761 break;
8762 case 8:
8763 case 9:
8764 case 10:
8765 case 11:
8766 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8767 inst.operands[2].imm = 32;
8768 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8769 break;
8770 case 12:
8771 case 13:
8772 case 14:
8773 case 15:
8774 {
8775 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8776 unsigned long wrn;
8777 wrn = (inst.instruction >> 16) & 0xf;
8778 inst.instruction &= 0xff0fff0f;
8779 inst.instruction |= wrn;
8780 /* Bail out here; the instruction is now assembled. */
8781 return;
8782 }
8783 }
8784 }
8785 /* Map 32 -> 0, etc. */
8786 inst.operands[2].imm &= 0x1f;
8787 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8788 }
8789 }
8790 \f
8791 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8792 operations first, then control, shift, and load/store. */
8793
8794 /* Insns like "foo X,Y,Z". */
8795
8796 static void
8797 do_mav_triple (void)
8798 {
8799 inst.instruction |= inst.operands[0].reg << 16;
8800 inst.instruction |= inst.operands[1].reg;
8801 inst.instruction |= inst.operands[2].reg << 12;
8802 }
8803
8804 /* Insns like "foo W,X,Y,Z".
8805 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
8806
8807 static void
8808 do_mav_quad (void)
8809 {
8810 inst.instruction |= inst.operands[0].reg << 5;
8811 inst.instruction |= inst.operands[1].reg << 12;
8812 inst.instruction |= inst.operands[2].reg << 16;
8813 inst.instruction |= inst.operands[3].reg;
8814 }
8815
8816 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8817 static void
8818 do_mav_dspsc (void)
8819 {
8820 inst.instruction |= inst.operands[1].reg << 12;
8821 }
8822
8823 /* Maverick shift immediate instructions.
8824 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8825 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
8826
8827 static void
8828 do_mav_shift (void)
8829 {
8830 int imm = inst.operands[2].imm;
8831
8832 inst.instruction |= inst.operands[0].reg << 12;
8833 inst.instruction |= inst.operands[1].reg << 16;
8834
8835 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8836 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8837 Bit 4 should be 0. */
8838 imm = (imm & 0xf) | ((imm & 0x70) << 1);
8839
8840 inst.instruction |= imm;
8841 }
8842 \f
8843 /* XScale instructions. Also sorted arithmetic before move. */
8844
8845 /* Xscale multiply-accumulate (argument parse)
8846 MIAcc acc0,Rm,Rs
8847 MIAPHcc acc0,Rm,Rs
8848 MIAxycc acc0,Rm,Rs. */
8849
8850 static void
8851 do_xsc_mia (void)
8852 {
8853 inst.instruction |= inst.operands[1].reg;
8854 inst.instruction |= inst.operands[2].reg << 12;
8855 }
8856
8857 /* Xscale move-accumulator-register (argument parse)
8858
8859 MARcc acc0,RdLo,RdHi. */
8860
8861 static void
8862 do_xsc_mar (void)
8863 {
8864 inst.instruction |= inst.operands[1].reg << 12;
8865 inst.instruction |= inst.operands[2].reg << 16;
8866 }
8867
8868 /* Xscale move-register-accumulator (argument parse)
8869
8870 MRAcc RdLo,RdHi,acc0. */
8871
8872 static void
8873 do_xsc_mra (void)
8874 {
8875 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8876 inst.instruction |= inst.operands[0].reg << 12;
8877 inst.instruction |= inst.operands[1].reg << 16;
8878 }
8879 \f
8880 /* Encoding functions relevant only to Thumb. */
8881
8882 /* inst.operands[i] is a shifted-register operand; encode
8883 it into inst.instruction in the format used by Thumb32. */
8884
8885 static void
8886 encode_thumb32_shifted_operand (int i)
8887 {
8888 unsigned int value = inst.reloc.exp.X_add_number;
8889 unsigned int shift = inst.operands[i].shift_kind;
8890
8891 constraint (inst.operands[i].immisreg,
8892 _("shift by register not allowed in thumb mode"));
8893 inst.instruction |= inst.operands[i].reg;
8894 if (shift == SHIFT_RRX)
8895 inst.instruction |= SHIFT_ROR << 4;
8896 else
8897 {
8898 constraint (inst.reloc.exp.X_op != O_constant,
8899 _("expression too complex"));
8900
8901 constraint (value > 32
8902 || (value == 32 && (shift == SHIFT_LSL
8903 || shift == SHIFT_ROR)),
8904 _("shift expression is too large"));
8905
8906 if (value == 0)
8907 shift = SHIFT_LSL;
8908 else if (value == 32)
8909 value = 0;
8910
8911 inst.instruction |= shift << 4;
8912 inst.instruction |= (value & 0x1c) << 10;
8913 inst.instruction |= (value & 0x03) << 6;
8914 }
8915 }
8916
8917
8918 /* inst.operands[i] was set up by parse_address. Encode it into a
8919 Thumb32 format load or store instruction. Reject forms that cannot
8920 be used with such instructions. If is_t is true, reject forms that
8921 cannot be used with a T instruction; if is_d is true, reject forms
8922 that cannot be used with a D instruction. If it is a store insn,
8923 reject PC in Rn. */
8924
8925 static void
8926 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8927 {
8928 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8929
8930 constraint (!inst.operands[i].isreg,
8931 _("Instruction does not support =N addresses"));
8932
8933 inst.instruction |= inst.operands[i].reg << 16;
8934 if (inst.operands[i].immisreg)
8935 {
8936 constraint (is_pc, BAD_PC_ADDRESSING);
8937 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8938 constraint (inst.operands[i].negative,
8939 _("Thumb does not support negative register indexing"));
8940 constraint (inst.operands[i].postind,
8941 _("Thumb does not support register post-indexing"));
8942 constraint (inst.operands[i].writeback,
8943 _("Thumb does not support register indexing with writeback"));
8944 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8945 _("Thumb supports only LSL in shifted register indexing"));
8946
8947 inst.instruction |= inst.operands[i].imm;
8948 if (inst.operands[i].shifted)
8949 {
8950 constraint (inst.reloc.exp.X_op != O_constant,
8951 _("expression too complex"));
8952 constraint (inst.reloc.exp.X_add_number < 0
8953 || inst.reloc.exp.X_add_number > 3,
8954 _("shift out of range"));
8955 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8956 }
8957 inst.reloc.type = BFD_RELOC_UNUSED;
8958 }
8959 else if (inst.operands[i].preind)
8960 {
8961 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
8962 constraint (is_t && inst.operands[i].writeback,
8963 _("cannot use writeback with this instruction"));
8964 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0)
8965 && !inst.reloc.pc_rel, BAD_PC_ADDRESSING);
8966
8967 if (is_d)
8968 {
8969 inst.instruction |= 0x01000000;
8970 if (inst.operands[i].writeback)
8971 inst.instruction |= 0x00200000;
8972 }
8973 else
8974 {
8975 inst.instruction |= 0x00000c00;
8976 if (inst.operands[i].writeback)
8977 inst.instruction |= 0x00000100;
8978 }
8979 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8980 }
8981 else if (inst.operands[i].postind)
8982 {
8983 gas_assert (inst.operands[i].writeback);
8984 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8985 constraint (is_t, _("cannot use post-indexing with this instruction"));
8986
8987 if (is_d)
8988 inst.instruction |= 0x00200000;
8989 else
8990 inst.instruction |= 0x00000900;
8991 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8992 }
8993 else /* unindexed - only for coprocessor */
8994 inst.error = _("instruction does not accept unindexed addressing");
8995 }
8996
8997 /* Table of Thumb instructions which exist in both 16- and 32-bit
8998 encodings (the latter only in post-V6T2 cores). The index is the
8999 value used in the insns table below. When there is more than one
9000 possible 16-bit encoding for the instruction, this table always
9001 holds variant (1).
9002 Also contains several pseudo-instructions used during relaxation. */
9003 #define T16_32_TAB \
9004 X(_adc, 4140, eb400000), \
9005 X(_adcs, 4140, eb500000), \
9006 X(_add, 1c00, eb000000), \
9007 X(_adds, 1c00, eb100000), \
9008 X(_addi, 0000, f1000000), \
9009 X(_addis, 0000, f1100000), \
9010 X(_add_pc,000f, f20f0000), \
9011 X(_add_sp,000d, f10d0000), \
9012 X(_adr, 000f, f20f0000), \
9013 X(_and, 4000, ea000000), \
9014 X(_ands, 4000, ea100000), \
9015 X(_asr, 1000, fa40f000), \
9016 X(_asrs, 1000, fa50f000), \
9017 X(_b, e000, f000b000), \
9018 X(_bcond, d000, f0008000), \
9019 X(_bic, 4380, ea200000), \
9020 X(_bics, 4380, ea300000), \
9021 X(_cmn, 42c0, eb100f00), \
9022 X(_cmp, 2800, ebb00f00), \
9023 X(_cpsie, b660, f3af8400), \
9024 X(_cpsid, b670, f3af8600), \
9025 X(_cpy, 4600, ea4f0000), \
9026 X(_dec_sp,80dd, f1ad0d00), \
9027 X(_eor, 4040, ea800000), \
9028 X(_eors, 4040, ea900000), \
9029 X(_inc_sp,00dd, f10d0d00), \
9030 X(_ldmia, c800, e8900000), \
9031 X(_ldr, 6800, f8500000), \
9032 X(_ldrb, 7800, f8100000), \
9033 X(_ldrh, 8800, f8300000), \
9034 X(_ldrsb, 5600, f9100000), \
9035 X(_ldrsh, 5e00, f9300000), \
9036 X(_ldr_pc,4800, f85f0000), \
9037 X(_ldr_pc2,4800, f85f0000), \
9038 X(_ldr_sp,9800, f85d0000), \
9039 X(_lsl, 0000, fa00f000), \
9040 X(_lsls, 0000, fa10f000), \
9041 X(_lsr, 0800, fa20f000), \
9042 X(_lsrs, 0800, fa30f000), \
9043 X(_mov, 2000, ea4f0000), \
9044 X(_movs, 2000, ea5f0000), \
9045 X(_mul, 4340, fb00f000), \
9046 X(_muls, 4340, ffffffff), /* no 32b muls */ \
9047 X(_mvn, 43c0, ea6f0000), \
9048 X(_mvns, 43c0, ea7f0000), \
9049 X(_neg, 4240, f1c00000), /* rsb #0 */ \
9050 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
9051 X(_orr, 4300, ea400000), \
9052 X(_orrs, 4300, ea500000), \
9053 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
9054 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
9055 X(_rev, ba00, fa90f080), \
9056 X(_rev16, ba40, fa90f090), \
9057 X(_revsh, bac0, fa90f0b0), \
9058 X(_ror, 41c0, fa60f000), \
9059 X(_rors, 41c0, fa70f000), \
9060 X(_sbc, 4180, eb600000), \
9061 X(_sbcs, 4180, eb700000), \
9062 X(_stmia, c000, e8800000), \
9063 X(_str, 6000, f8400000), \
9064 X(_strb, 7000, f8000000), \
9065 X(_strh, 8000, f8200000), \
9066 X(_str_sp,9000, f84d0000), \
9067 X(_sub, 1e00, eba00000), \
9068 X(_subs, 1e00, ebb00000), \
9069 X(_subi, 8000, f1a00000), \
9070 X(_subis, 8000, f1b00000), \
9071 X(_sxtb, b240, fa4ff080), \
9072 X(_sxth, b200, fa0ff080), \
9073 X(_tst, 4200, ea100f00), \
9074 X(_uxtb, b2c0, fa5ff080), \
9075 X(_uxth, b280, fa1ff080), \
9076 X(_nop, bf00, f3af8000), \
9077 X(_yield, bf10, f3af8001), \
9078 X(_wfe, bf20, f3af8002), \
9079 X(_wfi, bf30, f3af8003), \
9080 X(_sev, bf40, f3af8004),
9081
9082 /* To catch errors in encoding functions, the codes are all offset by
9083 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
9084 as 16-bit instructions. */
9085 #define X(a,b,c) T_MNEM##a
9086 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
9087 #undef X
9088
9089 #define X(a,b,c) 0x##b
9090 static const unsigned short thumb_op16[] = { T16_32_TAB };
9091 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
9092 #undef X
9093
9094 #define X(a,b,c) 0x##c
9095 static const unsigned int thumb_op32[] = { T16_32_TAB };
9096 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
9097 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
9098 #undef X
9099 #undef T16_32_TAB
9100
9101 /* Thumb instruction encoders, in alphabetical order. */
9102
9103 /* ADDW or SUBW. */
9104
9105 static void
9106 do_t_add_sub_w (void)
9107 {
9108 int Rd, Rn;
9109
9110 Rd = inst.operands[0].reg;
9111 Rn = inst.operands[1].reg;
9112
9113 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
9114 is the SP-{plus,minus}-immediate form of the instruction. */
9115 if (Rn == REG_SP)
9116 constraint (Rd == REG_PC, BAD_PC);
9117 else
9118 reject_bad_reg (Rd);
9119
9120 inst.instruction |= (Rn << 16) | (Rd << 8);
9121 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9122 }
9123
9124 /* Parse an add or subtract instruction. We get here with inst.instruction
9125 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
9126
9127 static void
9128 do_t_add_sub (void)
9129 {
9130 int Rd, Rs, Rn;
9131
9132 Rd = inst.operands[0].reg;
9133 Rs = (inst.operands[1].present
9134 ? inst.operands[1].reg /* Rd, Rs, foo */
9135 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9136
9137 if (Rd == REG_PC)
9138 set_it_insn_type_last ();
9139
9140 if (unified_syntax)
9141 {
9142 bfd_boolean flags;
9143 bfd_boolean narrow;
9144 int opcode;
9145
9146 flags = (inst.instruction == T_MNEM_adds
9147 || inst.instruction == T_MNEM_subs);
9148 if (flags)
9149 narrow = !in_it_block ();
9150 else
9151 narrow = in_it_block ();
9152 if (!inst.operands[2].isreg)
9153 {
9154 int add;
9155
9156 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9157
9158 add = (inst.instruction == T_MNEM_add
9159 || inst.instruction == T_MNEM_adds);
9160 opcode = 0;
9161 if (inst.size_req != 4)
9162 {
9163 /* Attempt to use a narrow opcode, with relaxation if
9164 appropriate. */
9165 if (Rd == REG_SP && Rs == REG_SP && !flags)
9166 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
9167 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
9168 opcode = T_MNEM_add_sp;
9169 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
9170 opcode = T_MNEM_add_pc;
9171 else if (Rd <= 7 && Rs <= 7 && narrow)
9172 {
9173 if (flags)
9174 opcode = add ? T_MNEM_addis : T_MNEM_subis;
9175 else
9176 opcode = add ? T_MNEM_addi : T_MNEM_subi;
9177 }
9178 if (opcode)
9179 {
9180 inst.instruction = THUMB_OP16(opcode);
9181 inst.instruction |= (Rd << 4) | Rs;
9182 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9183 if (inst.size_req != 2)
9184 inst.relax = opcode;
9185 }
9186 else
9187 constraint (inst.size_req == 2, BAD_HIREG);
9188 }
9189 if (inst.size_req == 4
9190 || (inst.size_req != 2 && !opcode))
9191 {
9192 if (Rd == REG_PC)
9193 {
9194 constraint (add, BAD_PC);
9195 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
9196 _("only SUBS PC, LR, #const allowed"));
9197 constraint (inst.reloc.exp.X_op != O_constant,
9198 _("expression too complex"));
9199 constraint (inst.reloc.exp.X_add_number < 0
9200 || inst.reloc.exp.X_add_number > 0xff,
9201 _("immediate value out of range"));
9202 inst.instruction = T2_SUBS_PC_LR
9203 | inst.reloc.exp.X_add_number;
9204 inst.reloc.type = BFD_RELOC_UNUSED;
9205 return;
9206 }
9207 else if (Rs == REG_PC)
9208 {
9209 /* Always use addw/subw. */
9210 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
9211 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9212 }
9213 else
9214 {
9215 inst.instruction = THUMB_OP32 (inst.instruction);
9216 inst.instruction = (inst.instruction & 0xe1ffffff)
9217 | 0x10000000;
9218 if (flags)
9219 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9220 else
9221 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
9222 }
9223 inst.instruction |= Rd << 8;
9224 inst.instruction |= Rs << 16;
9225 }
9226 }
9227 else
9228 {
9229 Rn = inst.operands[2].reg;
9230 /* See if we can do this with a 16-bit instruction. */
9231 if (!inst.operands[2].shifted && inst.size_req != 4)
9232 {
9233 if (Rd > 7 || Rs > 7 || Rn > 7)
9234 narrow = FALSE;
9235
9236 if (narrow)
9237 {
9238 inst.instruction = ((inst.instruction == T_MNEM_adds
9239 || inst.instruction == T_MNEM_add)
9240 ? T_OPCODE_ADD_R3
9241 : T_OPCODE_SUB_R3);
9242 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9243 return;
9244 }
9245
9246 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
9247 {
9248 /* Thumb-1 cores (except v6-M) require at least one high
9249 register in a narrow non flag setting add. */
9250 if (Rd > 7 || Rn > 7
9251 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
9252 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
9253 {
9254 if (Rd == Rn)
9255 {
9256 Rn = Rs;
9257 Rs = Rd;
9258 }
9259 inst.instruction = T_OPCODE_ADD_HI;
9260 inst.instruction |= (Rd & 8) << 4;
9261 inst.instruction |= (Rd & 7);
9262 inst.instruction |= Rn << 3;
9263 return;
9264 }
9265 }
9266 }
9267
9268 constraint (Rd == REG_PC, BAD_PC);
9269 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9270 constraint (Rs == REG_PC, BAD_PC);
9271 reject_bad_reg (Rn);
9272
9273 /* If we get here, it can't be done in 16 bits. */
9274 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
9275 _("shift must be constant"));
9276 inst.instruction = THUMB_OP32 (inst.instruction);
9277 inst.instruction |= Rd << 8;
9278 inst.instruction |= Rs << 16;
9279 encode_thumb32_shifted_operand (2);
9280 }
9281 }
9282 else
9283 {
9284 constraint (inst.instruction == T_MNEM_adds
9285 || inst.instruction == T_MNEM_subs,
9286 BAD_THUMB32);
9287
9288 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
9289 {
9290 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
9291 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
9292 BAD_HIREG);
9293
9294 inst.instruction = (inst.instruction == T_MNEM_add
9295 ? 0x0000 : 0x8000);
9296 inst.instruction |= (Rd << 4) | Rs;
9297 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9298 return;
9299 }
9300
9301 Rn = inst.operands[2].reg;
9302 constraint (inst.operands[2].shifted, _("unshifted register required"));
9303
9304 /* We now have Rd, Rs, and Rn set to registers. */
9305 if (Rd > 7 || Rs > 7 || Rn > 7)
9306 {
9307 /* Can't do this for SUB. */
9308 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
9309 inst.instruction = T_OPCODE_ADD_HI;
9310 inst.instruction |= (Rd & 8) << 4;
9311 inst.instruction |= (Rd & 7);
9312 if (Rs == Rd)
9313 inst.instruction |= Rn << 3;
9314 else if (Rn == Rd)
9315 inst.instruction |= Rs << 3;
9316 else
9317 constraint (1, _("dest must overlap one source register"));
9318 }
9319 else
9320 {
9321 inst.instruction = (inst.instruction == T_MNEM_add
9322 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
9323 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9324 }
9325 }
9326 }
9327
9328 static void
9329 do_t_adr (void)
9330 {
9331 unsigned Rd;
9332
9333 Rd = inst.operands[0].reg;
9334 reject_bad_reg (Rd);
9335
9336 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
9337 {
9338 /* Defer to section relaxation. */
9339 inst.relax = inst.instruction;
9340 inst.instruction = THUMB_OP16 (inst.instruction);
9341 inst.instruction |= Rd << 4;
9342 }
9343 else if (unified_syntax && inst.size_req != 2)
9344 {
9345 /* Generate a 32-bit opcode. */
9346 inst.instruction = THUMB_OP32 (inst.instruction);
9347 inst.instruction |= Rd << 8;
9348 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
9349 inst.reloc.pc_rel = 1;
9350 }
9351 else
9352 {
9353 /* Generate a 16-bit opcode. */
9354 inst.instruction = THUMB_OP16 (inst.instruction);
9355 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9356 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
9357 inst.reloc.pc_rel = 1;
9358
9359 inst.instruction |= Rd << 4;
9360 }
9361 }
9362
9363 /* Arithmetic instructions for which there is just one 16-bit
9364 instruction encoding, and it allows only two low registers.
9365 For maximal compatibility with ARM syntax, we allow three register
9366 operands even when Thumb-32 instructions are not available, as long
9367 as the first two are identical. For instance, both "sbc r0,r1" and
9368 "sbc r0,r0,r1" are allowed. */
9369 static void
9370 do_t_arit3 (void)
9371 {
9372 int Rd, Rs, Rn;
9373
9374 Rd = inst.operands[0].reg;
9375 Rs = (inst.operands[1].present
9376 ? inst.operands[1].reg /* Rd, Rs, foo */
9377 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9378 Rn = inst.operands[2].reg;
9379
9380 reject_bad_reg (Rd);
9381 reject_bad_reg (Rs);
9382 if (inst.operands[2].isreg)
9383 reject_bad_reg (Rn);
9384
9385 if (unified_syntax)
9386 {
9387 if (!inst.operands[2].isreg)
9388 {
9389 /* For an immediate, we always generate a 32-bit opcode;
9390 section relaxation will shrink it later if possible. */
9391 inst.instruction = THUMB_OP32 (inst.instruction);
9392 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9393 inst.instruction |= Rd << 8;
9394 inst.instruction |= Rs << 16;
9395 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9396 }
9397 else
9398 {
9399 bfd_boolean narrow;
9400
9401 /* See if we can do this with a 16-bit instruction. */
9402 if (THUMB_SETS_FLAGS (inst.instruction))
9403 narrow = !in_it_block ();
9404 else
9405 narrow = in_it_block ();
9406
9407 if (Rd > 7 || Rn > 7 || Rs > 7)
9408 narrow = FALSE;
9409 if (inst.operands[2].shifted)
9410 narrow = FALSE;
9411 if (inst.size_req == 4)
9412 narrow = FALSE;
9413
9414 if (narrow
9415 && Rd == Rs)
9416 {
9417 inst.instruction = THUMB_OP16 (inst.instruction);
9418 inst.instruction |= Rd;
9419 inst.instruction |= Rn << 3;
9420 return;
9421 }
9422
9423 /* If we get here, it can't be done in 16 bits. */
9424 constraint (inst.operands[2].shifted
9425 && inst.operands[2].immisreg,
9426 _("shift must be constant"));
9427 inst.instruction = THUMB_OP32 (inst.instruction);
9428 inst.instruction |= Rd << 8;
9429 inst.instruction |= Rs << 16;
9430 encode_thumb32_shifted_operand (2);
9431 }
9432 }
9433 else
9434 {
9435 /* On its face this is a lie - the instruction does set the
9436 flags. However, the only supported mnemonic in this mode
9437 says it doesn't. */
9438 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9439
9440 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9441 _("unshifted register required"));
9442 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9443 constraint (Rd != Rs,
9444 _("dest and source1 must be the same register"));
9445
9446 inst.instruction = THUMB_OP16 (inst.instruction);
9447 inst.instruction |= Rd;
9448 inst.instruction |= Rn << 3;
9449 }
9450 }
9451
9452 /* Similarly, but for instructions where the arithmetic operation is
9453 commutative, so we can allow either of them to be different from
9454 the destination operand in a 16-bit instruction. For instance, all
9455 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
9456 accepted. */
9457 static void
9458 do_t_arit3c (void)
9459 {
9460 int Rd, Rs, Rn;
9461
9462 Rd = inst.operands[0].reg;
9463 Rs = (inst.operands[1].present
9464 ? inst.operands[1].reg /* Rd, Rs, foo */
9465 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9466 Rn = inst.operands[2].reg;
9467
9468 reject_bad_reg (Rd);
9469 reject_bad_reg (Rs);
9470 if (inst.operands[2].isreg)
9471 reject_bad_reg (Rn);
9472
9473 if (unified_syntax)
9474 {
9475 if (!inst.operands[2].isreg)
9476 {
9477 /* For an immediate, we always generate a 32-bit opcode;
9478 section relaxation will shrink it later if possible. */
9479 inst.instruction = THUMB_OP32 (inst.instruction);
9480 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9481 inst.instruction |= Rd << 8;
9482 inst.instruction |= Rs << 16;
9483 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9484 }
9485 else
9486 {
9487 bfd_boolean narrow;
9488
9489 /* See if we can do this with a 16-bit instruction. */
9490 if (THUMB_SETS_FLAGS (inst.instruction))
9491 narrow = !in_it_block ();
9492 else
9493 narrow = in_it_block ();
9494
9495 if (Rd > 7 || Rn > 7 || Rs > 7)
9496 narrow = FALSE;
9497 if (inst.operands[2].shifted)
9498 narrow = FALSE;
9499 if (inst.size_req == 4)
9500 narrow = FALSE;
9501
9502 if (narrow)
9503 {
9504 if (Rd == Rs)
9505 {
9506 inst.instruction = THUMB_OP16 (inst.instruction);
9507 inst.instruction |= Rd;
9508 inst.instruction |= Rn << 3;
9509 return;
9510 }
9511 if (Rd == Rn)
9512 {
9513 inst.instruction = THUMB_OP16 (inst.instruction);
9514 inst.instruction |= Rd;
9515 inst.instruction |= Rs << 3;
9516 return;
9517 }
9518 }
9519
9520 /* If we get here, it can't be done in 16 bits. */
9521 constraint (inst.operands[2].shifted
9522 && inst.operands[2].immisreg,
9523 _("shift must be constant"));
9524 inst.instruction = THUMB_OP32 (inst.instruction);
9525 inst.instruction |= Rd << 8;
9526 inst.instruction |= Rs << 16;
9527 encode_thumb32_shifted_operand (2);
9528 }
9529 }
9530 else
9531 {
9532 /* On its face this is a lie - the instruction does set the
9533 flags. However, the only supported mnemonic in this mode
9534 says it doesn't. */
9535 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9536
9537 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9538 _("unshifted register required"));
9539 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9540
9541 inst.instruction = THUMB_OP16 (inst.instruction);
9542 inst.instruction |= Rd;
9543
9544 if (Rd == Rs)
9545 inst.instruction |= Rn << 3;
9546 else if (Rd == Rn)
9547 inst.instruction |= Rs << 3;
9548 else
9549 constraint (1, _("dest must overlap one source register"));
9550 }
9551 }
9552
9553 static void
9554 do_t_barrier (void)
9555 {
9556 if (inst.operands[0].present)
9557 {
9558 constraint ((inst.instruction & 0xf0) != 0x40
9559 && inst.operands[0].imm > 0xf
9560 && inst.operands[0].imm < 0x0,
9561 _("bad barrier type"));
9562 inst.instruction |= inst.operands[0].imm;
9563 }
9564 else
9565 inst.instruction |= 0xf;
9566 }
9567
9568 static void
9569 do_t_bfc (void)
9570 {
9571 unsigned Rd;
9572 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9573 constraint (msb > 32, _("bit-field extends past end of register"));
9574 /* The instruction encoding stores the LSB and MSB,
9575 not the LSB and width. */
9576 Rd = inst.operands[0].reg;
9577 reject_bad_reg (Rd);
9578 inst.instruction |= Rd << 8;
9579 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
9580 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
9581 inst.instruction |= msb - 1;
9582 }
9583
9584 static void
9585 do_t_bfi (void)
9586 {
9587 int Rd, Rn;
9588 unsigned int msb;
9589
9590 Rd = inst.operands[0].reg;
9591 reject_bad_reg (Rd);
9592
9593 /* #0 in second position is alternative syntax for bfc, which is
9594 the same instruction but with REG_PC in the Rm field. */
9595 if (!inst.operands[1].isreg)
9596 Rn = REG_PC;
9597 else
9598 {
9599 Rn = inst.operands[1].reg;
9600 reject_bad_reg (Rn);
9601 }
9602
9603 msb = inst.operands[2].imm + inst.operands[3].imm;
9604 constraint (msb > 32, _("bit-field extends past end of register"));
9605 /* The instruction encoding stores the LSB and MSB,
9606 not the LSB and width. */
9607 inst.instruction |= Rd << 8;
9608 inst.instruction |= Rn << 16;
9609 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9610 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9611 inst.instruction |= msb - 1;
9612 }
9613
9614 static void
9615 do_t_bfx (void)
9616 {
9617 unsigned Rd, Rn;
9618
9619 Rd = inst.operands[0].reg;
9620 Rn = inst.operands[1].reg;
9621
9622 reject_bad_reg (Rd);
9623 reject_bad_reg (Rn);
9624
9625 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9626 _("bit-field extends past end of register"));
9627 inst.instruction |= Rd << 8;
9628 inst.instruction |= Rn << 16;
9629 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9630 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9631 inst.instruction |= inst.operands[3].imm - 1;
9632 }
9633
9634 /* ARM V5 Thumb BLX (argument parse)
9635 BLX <target_addr> which is BLX(1)
9636 BLX <Rm> which is BLX(2)
9637 Unfortunately, there are two different opcodes for this mnemonic.
9638 So, the insns[].value is not used, and the code here zaps values
9639 into inst.instruction.
9640
9641 ??? How to take advantage of the additional two bits of displacement
9642 available in Thumb32 mode? Need new relocation? */
9643
9644 static void
9645 do_t_blx (void)
9646 {
9647 set_it_insn_type_last ();
9648
9649 if (inst.operands[0].isreg)
9650 {
9651 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9652 /* We have a register, so this is BLX(2). */
9653 inst.instruction |= inst.operands[0].reg << 3;
9654 }
9655 else
9656 {
9657 /* No register. This must be BLX(1). */
9658 inst.instruction = 0xf000e800;
9659 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
9660 inst.reloc.pc_rel = 1;
9661 }
9662 }
9663
9664 static void
9665 do_t_branch (void)
9666 {
9667 int opcode;
9668 int cond;
9669
9670 cond = inst.cond;
9671 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
9672
9673 if (in_it_block ())
9674 {
9675 /* Conditional branches inside IT blocks are encoded as unconditional
9676 branches. */
9677 cond = COND_ALWAYS;
9678 }
9679 else
9680 cond = inst.cond;
9681
9682 if (cond != COND_ALWAYS)
9683 opcode = T_MNEM_bcond;
9684 else
9685 opcode = inst.instruction;
9686
9687 if (unified_syntax && inst.size_req == 4)
9688 {
9689 inst.instruction = THUMB_OP32(opcode);
9690 if (cond == COND_ALWAYS)
9691 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
9692 else
9693 {
9694 gas_assert (cond != 0xF);
9695 inst.instruction |= cond << 22;
9696 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
9697 }
9698 }
9699 else
9700 {
9701 inst.instruction = THUMB_OP16(opcode);
9702 if (cond == COND_ALWAYS)
9703 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
9704 else
9705 {
9706 inst.instruction |= cond << 8;
9707 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
9708 }
9709 /* Allow section relaxation. */
9710 if (unified_syntax && inst.size_req != 2)
9711 inst.relax = opcode;
9712 }
9713
9714 inst.reloc.pc_rel = 1;
9715 }
9716
9717 static void
9718 do_t_bkpt (void)
9719 {
9720 constraint (inst.cond != COND_ALWAYS,
9721 _("instruction is always unconditional"));
9722 if (inst.operands[0].present)
9723 {
9724 constraint (inst.operands[0].imm > 255,
9725 _("immediate value out of range"));
9726 inst.instruction |= inst.operands[0].imm;
9727 set_it_insn_type (NEUTRAL_IT_INSN);
9728 }
9729 }
9730
9731 static void
9732 do_t_branch23 (void)
9733 {
9734 set_it_insn_type_last ();
9735 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
9736 inst.reloc.pc_rel = 1;
9737
9738 #if defined(OBJ_COFF)
9739 /* If the destination of the branch is a defined symbol which does not have
9740 the THUMB_FUNC attribute, then we must be calling a function which has
9741 the (interfacearm) attribute. We look for the Thumb entry point to that
9742 function and change the branch to refer to that function instead. */
9743 if ( inst.reloc.exp.X_op == O_symbol
9744 && inst.reloc.exp.X_add_symbol != NULL
9745 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
9746 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
9747 inst.reloc.exp.X_add_symbol =
9748 find_real_start (inst.reloc.exp.X_add_symbol);
9749 #endif
9750 }
9751
9752 static void
9753 do_t_bx (void)
9754 {
9755 set_it_insn_type_last ();
9756 inst.instruction |= inst.operands[0].reg << 3;
9757 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
9758 should cause the alignment to be checked once it is known. This is
9759 because BX PC only works if the instruction is word aligned. */
9760 }
9761
9762 static void
9763 do_t_bxj (void)
9764 {
9765 int Rm;
9766
9767 set_it_insn_type_last ();
9768 Rm = inst.operands[0].reg;
9769 reject_bad_reg (Rm);
9770 inst.instruction |= Rm << 16;
9771 }
9772
9773 static void
9774 do_t_clz (void)
9775 {
9776 unsigned Rd;
9777 unsigned Rm;
9778
9779 Rd = inst.operands[0].reg;
9780 Rm = inst.operands[1].reg;
9781
9782 reject_bad_reg (Rd);
9783 reject_bad_reg (Rm);
9784
9785 inst.instruction |= Rd << 8;
9786 inst.instruction |= Rm << 16;
9787 inst.instruction |= Rm;
9788 }
9789
9790 static void
9791 do_t_cps (void)
9792 {
9793 set_it_insn_type (OUTSIDE_IT_INSN);
9794 inst.instruction |= inst.operands[0].imm;
9795 }
9796
9797 static void
9798 do_t_cpsi (void)
9799 {
9800 set_it_insn_type (OUTSIDE_IT_INSN);
9801 if (unified_syntax
9802 && (inst.operands[1].present || inst.size_req == 4)
9803 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
9804 {
9805 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9806 inst.instruction = 0xf3af8000;
9807 inst.instruction |= imod << 9;
9808 inst.instruction |= inst.operands[0].imm << 5;
9809 if (inst.operands[1].present)
9810 inst.instruction |= 0x100 | inst.operands[1].imm;
9811 }
9812 else
9813 {
9814 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9815 && (inst.operands[0].imm & 4),
9816 _("selected processor does not support 'A' form "
9817 "of this instruction"));
9818 constraint (inst.operands[1].present || inst.size_req == 4,
9819 _("Thumb does not support the 2-argument "
9820 "form of this instruction"));
9821 inst.instruction |= inst.operands[0].imm;
9822 }
9823 }
9824
9825 /* THUMB CPY instruction (argument parse). */
9826
9827 static void
9828 do_t_cpy (void)
9829 {
9830 if (inst.size_req == 4)
9831 {
9832 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9833 inst.instruction |= inst.operands[0].reg << 8;
9834 inst.instruction |= inst.operands[1].reg;
9835 }
9836 else
9837 {
9838 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9839 inst.instruction |= (inst.operands[0].reg & 0x7);
9840 inst.instruction |= inst.operands[1].reg << 3;
9841 }
9842 }
9843
9844 static void
9845 do_t_cbz (void)
9846 {
9847 set_it_insn_type (OUTSIDE_IT_INSN);
9848 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9849 inst.instruction |= inst.operands[0].reg;
9850 inst.reloc.pc_rel = 1;
9851 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9852 }
9853
9854 static void
9855 do_t_dbg (void)
9856 {
9857 inst.instruction |= inst.operands[0].imm;
9858 }
9859
9860 static void
9861 do_t_div (void)
9862 {
9863 unsigned Rd, Rn, Rm;
9864
9865 Rd = inst.operands[0].reg;
9866 Rn = (inst.operands[1].present
9867 ? inst.operands[1].reg : Rd);
9868 Rm = inst.operands[2].reg;
9869
9870 reject_bad_reg (Rd);
9871 reject_bad_reg (Rn);
9872 reject_bad_reg (Rm);
9873
9874 inst.instruction |= Rd << 8;
9875 inst.instruction |= Rn << 16;
9876 inst.instruction |= Rm;
9877 }
9878
9879 static void
9880 do_t_hint (void)
9881 {
9882 if (unified_syntax && inst.size_req == 4)
9883 inst.instruction = THUMB_OP32 (inst.instruction);
9884 else
9885 inst.instruction = THUMB_OP16 (inst.instruction);
9886 }
9887
9888 static void
9889 do_t_it (void)
9890 {
9891 unsigned int cond = inst.operands[0].imm;
9892
9893 set_it_insn_type (IT_INSN);
9894 now_it.mask = (inst.instruction & 0xf) | 0x10;
9895 now_it.cc = cond;
9896
9897 /* If the condition is a negative condition, invert the mask. */
9898 if ((cond & 0x1) == 0x0)
9899 {
9900 unsigned int mask = inst.instruction & 0x000f;
9901
9902 if ((mask & 0x7) == 0)
9903 /* no conversion needed */;
9904 else if ((mask & 0x3) == 0)
9905 mask ^= 0x8;
9906 else if ((mask & 0x1) == 0)
9907 mask ^= 0xC;
9908 else
9909 mask ^= 0xE;
9910
9911 inst.instruction &= 0xfff0;
9912 inst.instruction |= mask;
9913 }
9914
9915 inst.instruction |= cond << 4;
9916 }
9917
9918 /* Helper function used for both push/pop and ldm/stm. */
9919 static void
9920 encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9921 {
9922 bfd_boolean load;
9923
9924 load = (inst.instruction & (1 << 20)) != 0;
9925
9926 if (mask & (1 << 13))
9927 inst.error = _("SP not allowed in register list");
9928
9929 if ((mask & (1 << base)) != 0
9930 && writeback)
9931 inst.error = _("having the base register in the register list when "
9932 "using write back is UNPREDICTABLE");
9933
9934 if (load)
9935 {
9936 if (mask & (1 << 15))
9937 {
9938 if (mask & (1 << 14))
9939 inst.error = _("LR and PC should not both be in register list");
9940 else
9941 set_it_insn_type_last ();
9942 }
9943 }
9944 else
9945 {
9946 if (mask & (1 << 15))
9947 inst.error = _("PC not allowed in register list");
9948 }
9949
9950 if ((mask & (mask - 1)) == 0)
9951 {
9952 /* Single register transfers implemented as str/ldr. */
9953 if (writeback)
9954 {
9955 if (inst.instruction & (1 << 23))
9956 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9957 else
9958 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9959 }
9960 else
9961 {
9962 if (inst.instruction & (1 << 23))
9963 inst.instruction = 0x00800000; /* ia -> [base] */
9964 else
9965 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9966 }
9967
9968 inst.instruction |= 0xf8400000;
9969 if (load)
9970 inst.instruction |= 0x00100000;
9971
9972 mask = ffs (mask) - 1;
9973 mask <<= 12;
9974 }
9975 else if (writeback)
9976 inst.instruction |= WRITE_BACK;
9977
9978 inst.instruction |= mask;
9979 inst.instruction |= base << 16;
9980 }
9981
9982 static void
9983 do_t_ldmstm (void)
9984 {
9985 /* This really doesn't seem worth it. */
9986 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9987 _("expression too complex"));
9988 constraint (inst.operands[1].writeback,
9989 _("Thumb load/store multiple does not support {reglist}^"));
9990
9991 if (unified_syntax)
9992 {
9993 bfd_boolean narrow;
9994 unsigned mask;
9995
9996 narrow = FALSE;
9997 /* See if we can use a 16-bit instruction. */
9998 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9999 && inst.size_req != 4
10000 && !(inst.operands[1].imm & ~0xff))
10001 {
10002 mask = 1 << inst.operands[0].reg;
10003
10004 if (inst.operands[0].reg <= 7)
10005 {
10006 if (inst.instruction == T_MNEM_stmia
10007 ? inst.operands[0].writeback
10008 : (inst.operands[0].writeback
10009 == !(inst.operands[1].imm & mask)))
10010 {
10011 if (inst.instruction == T_MNEM_stmia
10012 && (inst.operands[1].imm & mask)
10013 && (inst.operands[1].imm & (mask - 1)))
10014 as_warn (_("value stored for r%d is UNKNOWN"),
10015 inst.operands[0].reg);
10016
10017 inst.instruction = THUMB_OP16 (inst.instruction);
10018 inst.instruction |= inst.operands[0].reg << 8;
10019 inst.instruction |= inst.operands[1].imm;
10020 narrow = TRUE;
10021 }
10022 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10023 {
10024 /* This means 1 register in reg list one of 3 situations:
10025 1. Instruction is stmia, but without writeback.
10026 2. lmdia without writeback, but with Rn not in
10027 reglist.
10028 3. ldmia with writeback, but with Rn in reglist.
10029 Case 3 is UNPREDICTABLE behaviour, so we handle
10030 case 1 and 2 which can be converted into a 16-bit
10031 str or ldr. The SP cases are handled below. */
10032 unsigned long opcode;
10033 /* First, record an error for Case 3. */
10034 if (inst.operands[1].imm & mask
10035 && inst.operands[0].writeback)
10036 inst.error =
10037 _("having the base register in the register list when "
10038 "using write back is UNPREDICTABLE");
10039
10040 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
10041 : T_MNEM_ldr);
10042 inst.instruction = THUMB_OP16 (opcode);
10043 inst.instruction |= inst.operands[0].reg << 3;
10044 inst.instruction |= (ffs (inst.operands[1].imm)-1);
10045 narrow = TRUE;
10046 }
10047 }
10048 else if (inst.operands[0] .reg == REG_SP)
10049 {
10050 if (inst.operands[0].writeback)
10051 {
10052 inst.instruction =
10053 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10054 ? T_MNEM_push : T_MNEM_pop);
10055 inst.instruction |= inst.operands[1].imm;
10056 narrow = TRUE;
10057 }
10058 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10059 {
10060 inst.instruction =
10061 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10062 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
10063 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
10064 narrow = TRUE;
10065 }
10066 }
10067 }
10068
10069 if (!narrow)
10070 {
10071 if (inst.instruction < 0xffff)
10072 inst.instruction = THUMB_OP32 (inst.instruction);
10073
10074 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
10075 inst.operands[0].writeback);
10076 }
10077 }
10078 else
10079 {
10080 constraint (inst.operands[0].reg > 7
10081 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
10082 constraint (inst.instruction != T_MNEM_ldmia
10083 && inst.instruction != T_MNEM_stmia,
10084 _("Thumb-2 instruction only valid in unified syntax"));
10085 if (inst.instruction == T_MNEM_stmia)
10086 {
10087 if (!inst.operands[0].writeback)
10088 as_warn (_("this instruction will write back the base register"));
10089 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
10090 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
10091 as_warn (_("value stored for r%d is UNKNOWN"),
10092 inst.operands[0].reg);
10093 }
10094 else
10095 {
10096 if (!inst.operands[0].writeback
10097 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
10098 as_warn (_("this instruction will write back the base register"));
10099 else if (inst.operands[0].writeback
10100 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
10101 as_warn (_("this instruction will not write back the base register"));
10102 }
10103
10104 inst.instruction = THUMB_OP16 (inst.instruction);
10105 inst.instruction |= inst.operands[0].reg << 8;
10106 inst.instruction |= inst.operands[1].imm;
10107 }
10108 }
10109
10110 static void
10111 do_t_ldrex (void)
10112 {
10113 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
10114 || inst.operands[1].postind || inst.operands[1].writeback
10115 || inst.operands[1].immisreg || inst.operands[1].shifted
10116 || inst.operands[1].negative,
10117 BAD_ADDR_MODE);
10118
10119 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
10120
10121 inst.instruction |= inst.operands[0].reg << 12;
10122 inst.instruction |= inst.operands[1].reg << 16;
10123 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
10124 }
10125
10126 static void
10127 do_t_ldrexd (void)
10128 {
10129 if (!inst.operands[1].present)
10130 {
10131 constraint (inst.operands[0].reg == REG_LR,
10132 _("r14 not allowed as first register "
10133 "when second register is omitted"));
10134 inst.operands[1].reg = inst.operands[0].reg + 1;
10135 }
10136 constraint (inst.operands[0].reg == inst.operands[1].reg,
10137 BAD_OVERLAP);
10138
10139 inst.instruction |= inst.operands[0].reg << 12;
10140 inst.instruction |= inst.operands[1].reg << 8;
10141 inst.instruction |= inst.operands[2].reg << 16;
10142 }
10143
10144 static void
10145 do_t_ldst (void)
10146 {
10147 unsigned long opcode;
10148 int Rn;
10149
10150 if (inst.operands[0].isreg
10151 && !inst.operands[0].preind
10152 && inst.operands[0].reg == REG_PC)
10153 set_it_insn_type_last ();
10154
10155 opcode = inst.instruction;
10156 if (unified_syntax)
10157 {
10158 if (!inst.operands[1].isreg)
10159 {
10160 if (opcode <= 0xffff)
10161 inst.instruction = THUMB_OP32 (opcode);
10162 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10163 return;
10164 }
10165 if (inst.operands[1].isreg
10166 && !inst.operands[1].writeback
10167 && !inst.operands[1].shifted && !inst.operands[1].postind
10168 && !inst.operands[1].negative && inst.operands[0].reg <= 7
10169 && opcode <= 0xffff
10170 && inst.size_req != 4)
10171 {
10172 /* Insn may have a 16-bit form. */
10173 Rn = inst.operands[1].reg;
10174 if (inst.operands[1].immisreg)
10175 {
10176 inst.instruction = THUMB_OP16 (opcode);
10177 /* [Rn, Rik] */
10178 if (Rn <= 7 && inst.operands[1].imm <= 7)
10179 goto op16;
10180 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
10181 reject_bad_reg (inst.operands[1].imm);
10182 }
10183 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
10184 && opcode != T_MNEM_ldrsb)
10185 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
10186 || (Rn == REG_SP && opcode == T_MNEM_str))
10187 {
10188 /* [Rn, #const] */
10189 if (Rn > 7)
10190 {
10191 if (Rn == REG_PC)
10192 {
10193 if (inst.reloc.pc_rel)
10194 opcode = T_MNEM_ldr_pc2;
10195 else
10196 opcode = T_MNEM_ldr_pc;
10197 }
10198 else
10199 {
10200 if (opcode == T_MNEM_ldr)
10201 opcode = T_MNEM_ldr_sp;
10202 else
10203 opcode = T_MNEM_str_sp;
10204 }
10205 inst.instruction = inst.operands[0].reg << 8;
10206 }
10207 else
10208 {
10209 inst.instruction = inst.operands[0].reg;
10210 inst.instruction |= inst.operands[1].reg << 3;
10211 }
10212 inst.instruction |= THUMB_OP16 (opcode);
10213 if (inst.size_req == 2)
10214 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10215 else
10216 inst.relax = opcode;
10217 return;
10218 }
10219 }
10220 /* Definitely a 32-bit variant. */
10221
10222 /* Do some validations regarding addressing modes. */
10223 if (inst.operands[1].immisreg && opcode != T_MNEM_ldr
10224 && opcode != T_MNEM_str)
10225 reject_bad_reg (inst.operands[1].imm);
10226
10227 inst.instruction = THUMB_OP32 (opcode);
10228 inst.instruction |= inst.operands[0].reg << 12;
10229 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
10230 return;
10231 }
10232
10233 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10234
10235 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
10236 {
10237 /* Only [Rn,Rm] is acceptable. */
10238 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
10239 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
10240 || inst.operands[1].postind || inst.operands[1].shifted
10241 || inst.operands[1].negative,
10242 _("Thumb does not support this addressing mode"));
10243 inst.instruction = THUMB_OP16 (inst.instruction);
10244 goto op16;
10245 }
10246
10247 inst.instruction = THUMB_OP16 (inst.instruction);
10248 if (!inst.operands[1].isreg)
10249 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10250 return;
10251
10252 constraint (!inst.operands[1].preind
10253 || inst.operands[1].shifted
10254 || inst.operands[1].writeback,
10255 _("Thumb does not support this addressing mode"));
10256 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
10257 {
10258 constraint (inst.instruction & 0x0600,
10259 _("byte or halfword not valid for base register"));
10260 constraint (inst.operands[1].reg == REG_PC
10261 && !(inst.instruction & THUMB_LOAD_BIT),
10262 _("r15 based store not allowed"));
10263 constraint (inst.operands[1].immisreg,
10264 _("invalid base register for register offset"));
10265
10266 if (inst.operands[1].reg == REG_PC)
10267 inst.instruction = T_OPCODE_LDR_PC;
10268 else if (inst.instruction & THUMB_LOAD_BIT)
10269 inst.instruction = T_OPCODE_LDR_SP;
10270 else
10271 inst.instruction = T_OPCODE_STR_SP;
10272
10273 inst.instruction |= inst.operands[0].reg << 8;
10274 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10275 return;
10276 }
10277
10278 constraint (inst.operands[1].reg > 7, BAD_HIREG);
10279 if (!inst.operands[1].immisreg)
10280 {
10281 /* Immediate offset. */
10282 inst.instruction |= inst.operands[0].reg;
10283 inst.instruction |= inst.operands[1].reg << 3;
10284 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10285 return;
10286 }
10287
10288 /* Register offset. */
10289 constraint (inst.operands[1].imm > 7, BAD_HIREG);
10290 constraint (inst.operands[1].negative,
10291 _("Thumb does not support this addressing mode"));
10292
10293 op16:
10294 switch (inst.instruction)
10295 {
10296 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
10297 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
10298 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
10299 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
10300 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
10301 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
10302 case 0x5600 /* ldrsb */:
10303 case 0x5e00 /* ldrsh */: break;
10304 default: abort ();
10305 }
10306
10307 inst.instruction |= inst.operands[0].reg;
10308 inst.instruction |= inst.operands[1].reg << 3;
10309 inst.instruction |= inst.operands[1].imm << 6;
10310 }
10311
10312 static void
10313 do_t_ldstd (void)
10314 {
10315 if (!inst.operands[1].present)
10316 {
10317 inst.operands[1].reg = inst.operands[0].reg + 1;
10318 constraint (inst.operands[0].reg == REG_LR,
10319 _("r14 not allowed here"));
10320 }
10321 inst.instruction |= inst.operands[0].reg << 12;
10322 inst.instruction |= inst.operands[1].reg << 8;
10323 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
10324 }
10325
10326 static void
10327 do_t_ldstt (void)
10328 {
10329 inst.instruction |= inst.operands[0].reg << 12;
10330 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
10331 }
10332
10333 static void
10334 do_t_mla (void)
10335 {
10336 unsigned Rd, Rn, Rm, Ra;
10337
10338 Rd = inst.operands[0].reg;
10339 Rn = inst.operands[1].reg;
10340 Rm = inst.operands[2].reg;
10341 Ra = inst.operands[3].reg;
10342
10343 reject_bad_reg (Rd);
10344 reject_bad_reg (Rn);
10345 reject_bad_reg (Rm);
10346 reject_bad_reg (Ra);
10347
10348 inst.instruction |= Rd << 8;
10349 inst.instruction |= Rn << 16;
10350 inst.instruction |= Rm;
10351 inst.instruction |= Ra << 12;
10352 }
10353
10354 static void
10355 do_t_mlal (void)
10356 {
10357 unsigned RdLo, RdHi, Rn, Rm;
10358
10359 RdLo = inst.operands[0].reg;
10360 RdHi = inst.operands[1].reg;
10361 Rn = inst.operands[2].reg;
10362 Rm = inst.operands[3].reg;
10363
10364 reject_bad_reg (RdLo);
10365 reject_bad_reg (RdHi);
10366 reject_bad_reg (Rn);
10367 reject_bad_reg (Rm);
10368
10369 inst.instruction |= RdLo << 12;
10370 inst.instruction |= RdHi << 8;
10371 inst.instruction |= Rn << 16;
10372 inst.instruction |= Rm;
10373 }
10374
10375 static void
10376 do_t_mov_cmp (void)
10377 {
10378 unsigned Rn, Rm;
10379
10380 Rn = inst.operands[0].reg;
10381 Rm = inst.operands[1].reg;
10382
10383 if (Rn == REG_PC)
10384 set_it_insn_type_last ();
10385
10386 if (unified_syntax)
10387 {
10388 int r0off = (inst.instruction == T_MNEM_mov
10389 || inst.instruction == T_MNEM_movs) ? 8 : 16;
10390 unsigned long opcode;
10391 bfd_boolean narrow;
10392 bfd_boolean low_regs;
10393
10394 low_regs = (Rn <= 7 && Rm <= 7);
10395 opcode = inst.instruction;
10396 if (in_it_block ())
10397 narrow = opcode != T_MNEM_movs;
10398 else
10399 narrow = opcode != T_MNEM_movs || low_regs;
10400 if (inst.size_req == 4
10401 || inst.operands[1].shifted)
10402 narrow = FALSE;
10403
10404 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
10405 if (opcode == T_MNEM_movs && inst.operands[1].isreg
10406 && !inst.operands[1].shifted
10407 && Rn == REG_PC
10408 && Rm == REG_LR)
10409 {
10410 inst.instruction = T2_SUBS_PC_LR;
10411 return;
10412 }
10413
10414 if (opcode == T_MNEM_cmp)
10415 {
10416 constraint (Rn == REG_PC, BAD_PC);
10417 if (narrow)
10418 {
10419 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
10420 but valid. */
10421 warn_deprecated_sp (Rm);
10422 /* R15 was documented as a valid choice for Rm in ARMv6,
10423 but as UNPREDICTABLE in ARMv7. ARM's proprietary
10424 tools reject R15, so we do too. */
10425 constraint (Rm == REG_PC, BAD_PC);
10426 }
10427 else
10428 reject_bad_reg (Rm);
10429 }
10430 else if (opcode == T_MNEM_mov
10431 || opcode == T_MNEM_movs)
10432 {
10433 if (inst.operands[1].isreg)
10434 {
10435 if (opcode == T_MNEM_movs)
10436 {
10437 reject_bad_reg (Rn);
10438 reject_bad_reg (Rm);
10439 }
10440 else if (narrow)
10441 {
10442 /* This is mov.n. */
10443 if ((Rn == REG_SP || Rn == REG_PC)
10444 && (Rm == REG_SP || Rm == REG_PC))
10445 {
10446 as_warn (_("Use of r%u as a source register is "
10447 "deprecated when r%u is the destination "
10448 "register."), Rm, Rn);
10449 }
10450 }
10451 else
10452 {
10453 /* This is mov.w. */
10454 constraint (Rn == REG_PC, BAD_PC);
10455 constraint (Rm == REG_PC, BAD_PC);
10456 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
10457 }
10458 }
10459 else
10460 reject_bad_reg (Rn);
10461 }
10462
10463 if (!inst.operands[1].isreg)
10464 {
10465 /* Immediate operand. */
10466 if (!in_it_block () && opcode == T_MNEM_mov)
10467 narrow = 0;
10468 if (low_regs && narrow)
10469 {
10470 inst.instruction = THUMB_OP16 (opcode);
10471 inst.instruction |= Rn << 8;
10472 if (inst.size_req == 2)
10473 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10474 else
10475 inst.relax = opcode;
10476 }
10477 else
10478 {
10479 inst.instruction = THUMB_OP32 (inst.instruction);
10480 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10481 inst.instruction |= Rn << r0off;
10482 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10483 }
10484 }
10485 else if (inst.operands[1].shifted && inst.operands[1].immisreg
10486 && (inst.instruction == T_MNEM_mov
10487 || inst.instruction == T_MNEM_movs))
10488 {
10489 /* Register shifts are encoded as separate shift instructions. */
10490 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
10491
10492 if (in_it_block ())
10493 narrow = !flags;
10494 else
10495 narrow = flags;
10496
10497 if (inst.size_req == 4)
10498 narrow = FALSE;
10499
10500 if (!low_regs || inst.operands[1].imm > 7)
10501 narrow = FALSE;
10502
10503 if (Rn != Rm)
10504 narrow = FALSE;
10505
10506 switch (inst.operands[1].shift_kind)
10507 {
10508 case SHIFT_LSL:
10509 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
10510 break;
10511 case SHIFT_ASR:
10512 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
10513 break;
10514 case SHIFT_LSR:
10515 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
10516 break;
10517 case SHIFT_ROR:
10518 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
10519 break;
10520 default:
10521 abort ();
10522 }
10523
10524 inst.instruction = opcode;
10525 if (narrow)
10526 {
10527 inst.instruction |= Rn;
10528 inst.instruction |= inst.operands[1].imm << 3;
10529 }
10530 else
10531 {
10532 if (flags)
10533 inst.instruction |= CONDS_BIT;
10534
10535 inst.instruction |= Rn << 8;
10536 inst.instruction |= Rm << 16;
10537 inst.instruction |= inst.operands[1].imm;
10538 }
10539 }
10540 else if (!narrow)
10541 {
10542 /* Some mov with immediate shift have narrow variants.
10543 Register shifts are handled above. */
10544 if (low_regs && inst.operands[1].shifted
10545 && (inst.instruction == T_MNEM_mov
10546 || inst.instruction == T_MNEM_movs))
10547 {
10548 if (in_it_block ())
10549 narrow = (inst.instruction == T_MNEM_mov);
10550 else
10551 narrow = (inst.instruction == T_MNEM_movs);
10552 }
10553
10554 if (narrow)
10555 {
10556 switch (inst.operands[1].shift_kind)
10557 {
10558 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10559 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10560 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10561 default: narrow = FALSE; break;
10562 }
10563 }
10564
10565 if (narrow)
10566 {
10567 inst.instruction |= Rn;
10568 inst.instruction |= Rm << 3;
10569 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10570 }
10571 else
10572 {
10573 inst.instruction = THUMB_OP32 (inst.instruction);
10574 inst.instruction |= Rn << r0off;
10575 encode_thumb32_shifted_operand (1);
10576 }
10577 }
10578 else
10579 switch (inst.instruction)
10580 {
10581 case T_MNEM_mov:
10582 inst.instruction = T_OPCODE_MOV_HR;
10583 inst.instruction |= (Rn & 0x8) << 4;
10584 inst.instruction |= (Rn & 0x7);
10585 inst.instruction |= Rm << 3;
10586 break;
10587
10588 case T_MNEM_movs:
10589 /* We know we have low registers at this point.
10590 Generate LSLS Rd, Rs, #0. */
10591 inst.instruction = T_OPCODE_LSL_I;
10592 inst.instruction |= Rn;
10593 inst.instruction |= Rm << 3;
10594 break;
10595
10596 case T_MNEM_cmp:
10597 if (low_regs)
10598 {
10599 inst.instruction = T_OPCODE_CMP_LR;
10600 inst.instruction |= Rn;
10601 inst.instruction |= Rm << 3;
10602 }
10603 else
10604 {
10605 inst.instruction = T_OPCODE_CMP_HR;
10606 inst.instruction |= (Rn & 0x8) << 4;
10607 inst.instruction |= (Rn & 0x7);
10608 inst.instruction |= Rm << 3;
10609 }
10610 break;
10611 }
10612 return;
10613 }
10614
10615 inst.instruction = THUMB_OP16 (inst.instruction);
10616
10617 /* PR 10443: Do not silently ignore shifted operands. */
10618 constraint (inst.operands[1].shifted,
10619 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
10620
10621 if (inst.operands[1].isreg)
10622 {
10623 if (Rn < 8 && Rm < 8)
10624 {
10625 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
10626 since a MOV instruction produces unpredictable results. */
10627 if (inst.instruction == T_OPCODE_MOV_I8)
10628 inst.instruction = T_OPCODE_ADD_I3;
10629 else
10630 inst.instruction = T_OPCODE_CMP_LR;
10631
10632 inst.instruction |= Rn;
10633 inst.instruction |= Rm << 3;
10634 }
10635 else
10636 {
10637 if (inst.instruction == T_OPCODE_MOV_I8)
10638 inst.instruction = T_OPCODE_MOV_HR;
10639 else
10640 inst.instruction = T_OPCODE_CMP_HR;
10641 do_t_cpy ();
10642 }
10643 }
10644 else
10645 {
10646 constraint (Rn > 7,
10647 _("only lo regs allowed with immediate"));
10648 inst.instruction |= Rn << 8;
10649 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10650 }
10651 }
10652
10653 static void
10654 do_t_mov16 (void)
10655 {
10656 unsigned Rd;
10657 bfd_vma imm;
10658 bfd_boolean top;
10659
10660 top = (inst.instruction & 0x00800000) != 0;
10661 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
10662 {
10663 constraint (top, _(":lower16: not allowed this instruction"));
10664 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
10665 }
10666 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
10667 {
10668 constraint (!top, _(":upper16: not allowed this instruction"));
10669 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
10670 }
10671
10672 Rd = inst.operands[0].reg;
10673 reject_bad_reg (Rd);
10674
10675 inst.instruction |= Rd << 8;
10676 if (inst.reloc.type == BFD_RELOC_UNUSED)
10677 {
10678 imm = inst.reloc.exp.X_add_number;
10679 inst.instruction |= (imm & 0xf000) << 4;
10680 inst.instruction |= (imm & 0x0800) << 15;
10681 inst.instruction |= (imm & 0x0700) << 4;
10682 inst.instruction |= (imm & 0x00ff);
10683 }
10684 }
10685
10686 static void
10687 do_t_mvn_tst (void)
10688 {
10689 unsigned Rn, Rm;
10690
10691 Rn = inst.operands[0].reg;
10692 Rm = inst.operands[1].reg;
10693
10694 if (inst.instruction == T_MNEM_cmp
10695 || inst.instruction == T_MNEM_cmn)
10696 constraint (Rn == REG_PC, BAD_PC);
10697 else
10698 reject_bad_reg (Rn);
10699 reject_bad_reg (Rm);
10700
10701 if (unified_syntax)
10702 {
10703 int r0off = (inst.instruction == T_MNEM_mvn
10704 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
10705 bfd_boolean narrow;
10706
10707 if (inst.size_req == 4
10708 || inst.instruction > 0xffff
10709 || inst.operands[1].shifted
10710 || Rn > 7 || Rm > 7)
10711 narrow = FALSE;
10712 else if (inst.instruction == T_MNEM_cmn)
10713 narrow = TRUE;
10714 else if (THUMB_SETS_FLAGS (inst.instruction))
10715 narrow = !in_it_block ();
10716 else
10717 narrow = in_it_block ();
10718
10719 if (!inst.operands[1].isreg)
10720 {
10721 /* For an immediate, we always generate a 32-bit opcode;
10722 section relaxation will shrink it later if possible. */
10723 if (inst.instruction < 0xffff)
10724 inst.instruction = THUMB_OP32 (inst.instruction);
10725 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10726 inst.instruction |= Rn << r0off;
10727 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10728 }
10729 else
10730 {
10731 /* See if we can do this with a 16-bit instruction. */
10732 if (narrow)
10733 {
10734 inst.instruction = THUMB_OP16 (inst.instruction);
10735 inst.instruction |= Rn;
10736 inst.instruction |= Rm << 3;
10737 }
10738 else
10739 {
10740 constraint (inst.operands[1].shifted
10741 && inst.operands[1].immisreg,
10742 _("shift must be constant"));
10743 if (inst.instruction < 0xffff)
10744 inst.instruction = THUMB_OP32 (inst.instruction);
10745 inst.instruction |= Rn << r0off;
10746 encode_thumb32_shifted_operand (1);
10747 }
10748 }
10749 }
10750 else
10751 {
10752 constraint (inst.instruction > 0xffff
10753 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
10754 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
10755 _("unshifted register required"));
10756 constraint (Rn > 7 || Rm > 7,
10757 BAD_HIREG);
10758
10759 inst.instruction = THUMB_OP16 (inst.instruction);
10760 inst.instruction |= Rn;
10761 inst.instruction |= Rm << 3;
10762 }
10763 }
10764
10765 static void
10766 do_t_mrs (void)
10767 {
10768 unsigned Rd;
10769
10770 if (do_vfp_nsyn_mrs () == SUCCESS)
10771 return;
10772
10773 Rd = inst.operands[0].reg;
10774 reject_bad_reg (Rd);
10775 inst.instruction |= Rd << 8;
10776
10777 if (inst.operands[1].isreg)
10778 {
10779 unsigned br = inst.operands[1].reg;
10780 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
10781 as_bad (_("bad register for mrs"));
10782
10783 inst.instruction |= br & (0xf << 16);
10784 inst.instruction |= (br & 0x300) >> 4;
10785 inst.instruction |= (br & SPSR_BIT) >> 2;
10786 }
10787 else
10788 {
10789 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
10790
10791 if (flags == 0)
10792 {
10793 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
10794 _("selected processor does not support "
10795 "requested special purpose register"));
10796 }
10797 else
10798 {
10799 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10800 _("selected processor does not support "
10801 "requested special purpose register"));
10802 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10803 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
10804 _("'CPSR' or 'SPSR' expected"));
10805 }
10806
10807 inst.instruction |= (flags & SPSR_BIT) >> 2;
10808 inst.instruction |= inst.operands[1].imm & 0xff;
10809 inst.instruction |= 0xf0000;
10810 }
10811 }
10812
10813 static void
10814 do_t_msr (void)
10815 {
10816 int flags;
10817 unsigned Rn;
10818
10819 if (do_vfp_nsyn_msr () == SUCCESS)
10820 return;
10821
10822 constraint (!inst.operands[1].isreg,
10823 _("Thumb encoding does not support an immediate here"));
10824
10825 if (inst.operands[0].isreg)
10826 flags = (int)(inst.operands[0].reg);
10827 else
10828 flags = inst.operands[0].imm;
10829
10830 if (flags & ~0xff)
10831 {
10832 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10833 _("selected processor does not support "
10834 "requested special purpose register"));
10835 }
10836 else
10837 {
10838 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
10839 _("selected processor does not support "
10840 "requested special purpose register"));
10841 flags |= PSR_f;
10842 }
10843
10844 Rn = inst.operands[1].reg;
10845 reject_bad_reg (Rn);
10846
10847 inst.instruction |= (flags & SPSR_BIT) >> 2;
10848 inst.instruction |= (flags & 0xf0000) >> 8;
10849 inst.instruction |= (flags & 0x300) >> 4;
10850 inst.instruction |= (flags & 0xff);
10851 inst.instruction |= Rn << 16;
10852 }
10853
10854 static void
10855 do_t_mul (void)
10856 {
10857 bfd_boolean narrow;
10858 unsigned Rd, Rn, Rm;
10859
10860 if (!inst.operands[2].present)
10861 inst.operands[2].reg = inst.operands[0].reg;
10862
10863 Rd = inst.operands[0].reg;
10864 Rn = inst.operands[1].reg;
10865 Rm = inst.operands[2].reg;
10866
10867 if (unified_syntax)
10868 {
10869 if (inst.size_req == 4
10870 || (Rd != Rn
10871 && Rd != Rm)
10872 || Rn > 7
10873 || Rm > 7)
10874 narrow = FALSE;
10875 else if (inst.instruction == T_MNEM_muls)
10876 narrow = !in_it_block ();
10877 else
10878 narrow = in_it_block ();
10879 }
10880 else
10881 {
10882 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
10883 constraint (Rn > 7 || Rm > 7,
10884 BAD_HIREG);
10885 narrow = TRUE;
10886 }
10887
10888 if (narrow)
10889 {
10890 /* 16-bit MULS/Conditional MUL. */
10891 inst.instruction = THUMB_OP16 (inst.instruction);
10892 inst.instruction |= Rd;
10893
10894 if (Rd == Rn)
10895 inst.instruction |= Rm << 3;
10896 else if (Rd == Rm)
10897 inst.instruction |= Rn << 3;
10898 else
10899 constraint (1, _("dest must overlap one source register"));
10900 }
10901 else
10902 {
10903 constraint (inst.instruction != T_MNEM_mul,
10904 _("Thumb-2 MUL must not set flags"));
10905 /* 32-bit MUL. */
10906 inst.instruction = THUMB_OP32 (inst.instruction);
10907 inst.instruction |= Rd << 8;
10908 inst.instruction |= Rn << 16;
10909 inst.instruction |= Rm << 0;
10910
10911 reject_bad_reg (Rd);
10912 reject_bad_reg (Rn);
10913 reject_bad_reg (Rm);
10914 }
10915 }
10916
10917 static void
10918 do_t_mull (void)
10919 {
10920 unsigned RdLo, RdHi, Rn, Rm;
10921
10922 RdLo = inst.operands[0].reg;
10923 RdHi = inst.operands[1].reg;
10924 Rn = inst.operands[2].reg;
10925 Rm = inst.operands[3].reg;
10926
10927 reject_bad_reg (RdLo);
10928 reject_bad_reg (RdHi);
10929 reject_bad_reg (Rn);
10930 reject_bad_reg (Rm);
10931
10932 inst.instruction |= RdLo << 12;
10933 inst.instruction |= RdHi << 8;
10934 inst.instruction |= Rn << 16;
10935 inst.instruction |= Rm;
10936
10937 if (RdLo == RdHi)
10938 as_tsktsk (_("rdhi and rdlo must be different"));
10939 }
10940
10941 static void
10942 do_t_nop (void)
10943 {
10944 set_it_insn_type (NEUTRAL_IT_INSN);
10945
10946 if (unified_syntax)
10947 {
10948 if (inst.size_req == 4 || inst.operands[0].imm > 15)
10949 {
10950 inst.instruction = THUMB_OP32 (inst.instruction);
10951 inst.instruction |= inst.operands[0].imm;
10952 }
10953 else
10954 {
10955 /* PR9722: Check for Thumb2 availability before
10956 generating a thumb2 nop instruction. */
10957 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
10958 {
10959 inst.instruction = THUMB_OP16 (inst.instruction);
10960 inst.instruction |= inst.operands[0].imm << 4;
10961 }
10962 else
10963 inst.instruction = 0x46c0;
10964 }
10965 }
10966 else
10967 {
10968 constraint (inst.operands[0].present,
10969 _("Thumb does not support NOP with hints"));
10970 inst.instruction = 0x46c0;
10971 }
10972 }
10973
10974 static void
10975 do_t_neg (void)
10976 {
10977 if (unified_syntax)
10978 {
10979 bfd_boolean narrow;
10980
10981 if (THUMB_SETS_FLAGS (inst.instruction))
10982 narrow = !in_it_block ();
10983 else
10984 narrow = in_it_block ();
10985 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10986 narrow = FALSE;
10987 if (inst.size_req == 4)
10988 narrow = FALSE;
10989
10990 if (!narrow)
10991 {
10992 inst.instruction = THUMB_OP32 (inst.instruction);
10993 inst.instruction |= inst.operands[0].reg << 8;
10994 inst.instruction |= inst.operands[1].reg << 16;
10995 }
10996 else
10997 {
10998 inst.instruction = THUMB_OP16 (inst.instruction);
10999 inst.instruction |= inst.operands[0].reg;
11000 inst.instruction |= inst.operands[1].reg << 3;
11001 }
11002 }
11003 else
11004 {
11005 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
11006 BAD_HIREG);
11007 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11008
11009 inst.instruction = THUMB_OP16 (inst.instruction);
11010 inst.instruction |= inst.operands[0].reg;
11011 inst.instruction |= inst.operands[1].reg << 3;
11012 }
11013 }
11014
11015 static void
11016 do_t_orn (void)
11017 {
11018 unsigned Rd, Rn;
11019
11020 Rd = inst.operands[0].reg;
11021 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
11022
11023 reject_bad_reg (Rd);
11024 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
11025 reject_bad_reg (Rn);
11026
11027 inst.instruction |= Rd << 8;
11028 inst.instruction |= Rn << 16;
11029
11030 if (!inst.operands[2].isreg)
11031 {
11032 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11033 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11034 }
11035 else
11036 {
11037 unsigned Rm;
11038
11039 Rm = inst.operands[2].reg;
11040 reject_bad_reg (Rm);
11041
11042 constraint (inst.operands[2].shifted
11043 && inst.operands[2].immisreg,
11044 _("shift must be constant"));
11045 encode_thumb32_shifted_operand (2);
11046 }
11047 }
11048
11049 static void
11050 do_t_pkhbt (void)
11051 {
11052 unsigned Rd, Rn, Rm;
11053
11054 Rd = inst.operands[0].reg;
11055 Rn = inst.operands[1].reg;
11056 Rm = inst.operands[2].reg;
11057
11058 reject_bad_reg (Rd);
11059 reject_bad_reg (Rn);
11060 reject_bad_reg (Rm);
11061
11062 inst.instruction |= Rd << 8;
11063 inst.instruction |= Rn << 16;
11064 inst.instruction |= Rm;
11065 if (inst.operands[3].present)
11066 {
11067 unsigned int val = inst.reloc.exp.X_add_number;
11068 constraint (inst.reloc.exp.X_op != O_constant,
11069 _("expression too complex"));
11070 inst.instruction |= (val & 0x1c) << 10;
11071 inst.instruction |= (val & 0x03) << 6;
11072 }
11073 }
11074
11075 static void
11076 do_t_pkhtb (void)
11077 {
11078 if (!inst.operands[3].present)
11079 {
11080 unsigned Rtmp;
11081
11082 inst.instruction &= ~0x00000020;
11083
11084 /* PR 10168. Swap the Rm and Rn registers. */
11085 Rtmp = inst.operands[1].reg;
11086 inst.operands[1].reg = inst.operands[2].reg;
11087 inst.operands[2].reg = Rtmp;
11088 }
11089 do_t_pkhbt ();
11090 }
11091
11092 static void
11093 do_t_pld (void)
11094 {
11095 if (inst.operands[0].immisreg)
11096 reject_bad_reg (inst.operands[0].imm);
11097
11098 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
11099 }
11100
11101 static void
11102 do_t_push_pop (void)
11103 {
11104 unsigned mask;
11105
11106 constraint (inst.operands[0].writeback,
11107 _("push/pop do not support {reglist}^"));
11108 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11109 _("expression too complex"));
11110
11111 mask = inst.operands[0].imm;
11112 if ((mask & ~0xff) == 0)
11113 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
11114 else if ((inst.instruction == T_MNEM_push
11115 && (mask & ~0xff) == 1 << REG_LR)
11116 || (inst.instruction == T_MNEM_pop
11117 && (mask & ~0xff) == 1 << REG_PC))
11118 {
11119 inst.instruction = THUMB_OP16 (inst.instruction);
11120 inst.instruction |= THUMB_PP_PC_LR;
11121 inst.instruction |= mask & 0xff;
11122 }
11123 else if (unified_syntax)
11124 {
11125 inst.instruction = THUMB_OP32 (inst.instruction);
11126 encode_thumb2_ldmstm (13, mask, TRUE);
11127 }
11128 else
11129 {
11130 inst.error = _("invalid register list to push/pop instruction");
11131 return;
11132 }
11133 }
11134
11135 static void
11136 do_t_rbit (void)
11137 {
11138 unsigned Rd, Rm;
11139
11140 Rd = inst.operands[0].reg;
11141 Rm = inst.operands[1].reg;
11142
11143 reject_bad_reg (Rd);
11144 reject_bad_reg (Rm);
11145
11146 inst.instruction |= Rd << 8;
11147 inst.instruction |= Rm << 16;
11148 inst.instruction |= Rm;
11149 }
11150
11151 static void
11152 do_t_rev (void)
11153 {
11154 unsigned Rd, Rm;
11155
11156 Rd = inst.operands[0].reg;
11157 Rm = inst.operands[1].reg;
11158
11159 reject_bad_reg (Rd);
11160 reject_bad_reg (Rm);
11161
11162 if (Rd <= 7 && Rm <= 7
11163 && inst.size_req != 4)
11164 {
11165 inst.instruction = THUMB_OP16 (inst.instruction);
11166 inst.instruction |= Rd;
11167 inst.instruction |= Rm << 3;
11168 }
11169 else if (unified_syntax)
11170 {
11171 inst.instruction = THUMB_OP32 (inst.instruction);
11172 inst.instruction |= Rd << 8;
11173 inst.instruction |= Rm << 16;
11174 inst.instruction |= Rm;
11175 }
11176 else
11177 inst.error = BAD_HIREG;
11178 }
11179
11180 static void
11181 do_t_rrx (void)
11182 {
11183 unsigned Rd, Rm;
11184
11185 Rd = inst.operands[0].reg;
11186 Rm = inst.operands[1].reg;
11187
11188 reject_bad_reg (Rd);
11189 reject_bad_reg (Rm);
11190
11191 inst.instruction |= Rd << 8;
11192 inst.instruction |= Rm;
11193 }
11194
11195 static void
11196 do_t_rsb (void)
11197 {
11198 unsigned Rd, Rs;
11199
11200 Rd = inst.operands[0].reg;
11201 Rs = (inst.operands[1].present
11202 ? inst.operands[1].reg /* Rd, Rs, foo */
11203 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11204
11205 reject_bad_reg (Rd);
11206 reject_bad_reg (Rs);
11207 if (inst.operands[2].isreg)
11208 reject_bad_reg (inst.operands[2].reg);
11209
11210 inst.instruction |= Rd << 8;
11211 inst.instruction |= Rs << 16;
11212 if (!inst.operands[2].isreg)
11213 {
11214 bfd_boolean narrow;
11215
11216 if ((inst.instruction & 0x00100000) != 0)
11217 narrow = !in_it_block ();
11218 else
11219 narrow = in_it_block ();
11220
11221 if (Rd > 7 || Rs > 7)
11222 narrow = FALSE;
11223
11224 if (inst.size_req == 4 || !unified_syntax)
11225 narrow = FALSE;
11226
11227 if (inst.reloc.exp.X_op != O_constant
11228 || inst.reloc.exp.X_add_number != 0)
11229 narrow = FALSE;
11230
11231 /* Turn rsb #0 into 16-bit neg. We should probably do this via
11232 relaxation, but it doesn't seem worth the hassle. */
11233 if (narrow)
11234 {
11235 inst.reloc.type = BFD_RELOC_UNUSED;
11236 inst.instruction = THUMB_OP16 (T_MNEM_negs);
11237 inst.instruction |= Rs << 3;
11238 inst.instruction |= Rd;
11239 }
11240 else
11241 {
11242 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11243 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11244 }
11245 }
11246 else
11247 encode_thumb32_shifted_operand (2);
11248 }
11249
11250 static void
11251 do_t_setend (void)
11252 {
11253 set_it_insn_type (OUTSIDE_IT_INSN);
11254 if (inst.operands[0].imm)
11255 inst.instruction |= 0x8;
11256 }
11257
11258 static void
11259 do_t_shift (void)
11260 {
11261 if (!inst.operands[1].present)
11262 inst.operands[1].reg = inst.operands[0].reg;
11263
11264 if (unified_syntax)
11265 {
11266 bfd_boolean narrow;
11267 int shift_kind;
11268
11269 switch (inst.instruction)
11270 {
11271 case T_MNEM_asr:
11272 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
11273 case T_MNEM_lsl:
11274 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
11275 case T_MNEM_lsr:
11276 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
11277 case T_MNEM_ror:
11278 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
11279 default: abort ();
11280 }
11281
11282 if (THUMB_SETS_FLAGS (inst.instruction))
11283 narrow = !in_it_block ();
11284 else
11285 narrow = in_it_block ();
11286 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11287 narrow = FALSE;
11288 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
11289 narrow = FALSE;
11290 if (inst.operands[2].isreg
11291 && (inst.operands[1].reg != inst.operands[0].reg
11292 || inst.operands[2].reg > 7))
11293 narrow = FALSE;
11294 if (inst.size_req == 4)
11295 narrow = FALSE;
11296
11297 reject_bad_reg (inst.operands[0].reg);
11298 reject_bad_reg (inst.operands[1].reg);
11299
11300 if (!narrow)
11301 {
11302 if (inst.operands[2].isreg)
11303 {
11304 reject_bad_reg (inst.operands[2].reg);
11305 inst.instruction = THUMB_OP32 (inst.instruction);
11306 inst.instruction |= inst.operands[0].reg << 8;
11307 inst.instruction |= inst.operands[1].reg << 16;
11308 inst.instruction |= inst.operands[2].reg;
11309 }
11310 else
11311 {
11312 inst.operands[1].shifted = 1;
11313 inst.operands[1].shift_kind = shift_kind;
11314 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
11315 ? T_MNEM_movs : T_MNEM_mov);
11316 inst.instruction |= inst.operands[0].reg << 8;
11317 encode_thumb32_shifted_operand (1);
11318 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
11319 inst.reloc.type = BFD_RELOC_UNUSED;
11320 }
11321 }
11322 else
11323 {
11324 if (inst.operands[2].isreg)
11325 {
11326 switch (shift_kind)
11327 {
11328 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
11329 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
11330 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
11331 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
11332 default: abort ();
11333 }
11334
11335 inst.instruction |= inst.operands[0].reg;
11336 inst.instruction |= inst.operands[2].reg << 3;
11337 }
11338 else
11339 {
11340 switch (shift_kind)
11341 {
11342 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11343 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11344 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11345 default: abort ();
11346 }
11347 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11348 inst.instruction |= inst.operands[0].reg;
11349 inst.instruction |= inst.operands[1].reg << 3;
11350 }
11351 }
11352 }
11353 else
11354 {
11355 constraint (inst.operands[0].reg > 7
11356 || inst.operands[1].reg > 7, BAD_HIREG);
11357 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11358
11359 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
11360 {
11361 constraint (inst.operands[2].reg > 7, BAD_HIREG);
11362 constraint (inst.operands[0].reg != inst.operands[1].reg,
11363 _("source1 and dest must be same register"));
11364
11365 switch (inst.instruction)
11366 {
11367 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
11368 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
11369 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
11370 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
11371 default: abort ();
11372 }
11373
11374 inst.instruction |= inst.operands[0].reg;
11375 inst.instruction |= inst.operands[2].reg << 3;
11376 }
11377 else
11378 {
11379 switch (inst.instruction)
11380 {
11381 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
11382 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
11383 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
11384 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
11385 default: abort ();
11386 }
11387 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11388 inst.instruction |= inst.operands[0].reg;
11389 inst.instruction |= inst.operands[1].reg << 3;
11390 }
11391 }
11392 }
11393
11394 static void
11395 do_t_simd (void)
11396 {
11397 unsigned Rd, Rn, Rm;
11398
11399 Rd = inst.operands[0].reg;
11400 Rn = inst.operands[1].reg;
11401 Rm = inst.operands[2].reg;
11402
11403 reject_bad_reg (Rd);
11404 reject_bad_reg (Rn);
11405 reject_bad_reg (Rm);
11406
11407 inst.instruction |= Rd << 8;
11408 inst.instruction |= Rn << 16;
11409 inst.instruction |= Rm;
11410 }
11411
11412 static void
11413 do_t_simd2 (void)
11414 {
11415 unsigned Rd, Rn, Rm;
11416
11417 Rd = inst.operands[0].reg;
11418 Rm = inst.operands[1].reg;
11419 Rn = inst.operands[2].reg;
11420
11421 reject_bad_reg (Rd);
11422 reject_bad_reg (Rn);
11423 reject_bad_reg (Rm);
11424
11425 inst.instruction |= Rd << 8;
11426 inst.instruction |= Rn << 16;
11427 inst.instruction |= Rm;
11428 }
11429
11430 static void
11431 do_t_smc (void)
11432 {
11433 unsigned int value = inst.reloc.exp.X_add_number;
11434 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
11435 _("SMC is not permitted on this architecture"));
11436 constraint (inst.reloc.exp.X_op != O_constant,
11437 _("expression too complex"));
11438 inst.reloc.type = BFD_RELOC_UNUSED;
11439 inst.instruction |= (value & 0xf000) >> 12;
11440 inst.instruction |= (value & 0x0ff0);
11441 inst.instruction |= (value & 0x000f) << 16;
11442 }
11443
11444 static void
11445 do_t_hvc (void)
11446 {
11447 unsigned int value = inst.reloc.exp.X_add_number;
11448
11449 inst.reloc.type = BFD_RELOC_UNUSED;
11450 inst.instruction |= (value & 0x0fff);
11451 inst.instruction |= (value & 0xf000) << 4;
11452 }
11453
11454 static void
11455 do_t_ssat_usat (int bias)
11456 {
11457 unsigned Rd, Rn;
11458
11459 Rd = inst.operands[0].reg;
11460 Rn = inst.operands[2].reg;
11461
11462 reject_bad_reg (Rd);
11463 reject_bad_reg (Rn);
11464
11465 inst.instruction |= Rd << 8;
11466 inst.instruction |= inst.operands[1].imm - bias;
11467 inst.instruction |= Rn << 16;
11468
11469 if (inst.operands[3].present)
11470 {
11471 offsetT shift_amount = inst.reloc.exp.X_add_number;
11472
11473 inst.reloc.type = BFD_RELOC_UNUSED;
11474
11475 constraint (inst.reloc.exp.X_op != O_constant,
11476 _("expression too complex"));
11477
11478 if (shift_amount != 0)
11479 {
11480 constraint (shift_amount > 31,
11481 _("shift expression is too large"));
11482
11483 if (inst.operands[3].shift_kind == SHIFT_ASR)
11484 inst.instruction |= 0x00200000; /* sh bit. */
11485
11486 inst.instruction |= (shift_amount & 0x1c) << 10;
11487 inst.instruction |= (shift_amount & 0x03) << 6;
11488 }
11489 }
11490 }
11491
11492 static void
11493 do_t_ssat (void)
11494 {
11495 do_t_ssat_usat (1);
11496 }
11497
11498 static void
11499 do_t_ssat16 (void)
11500 {
11501 unsigned Rd, Rn;
11502
11503 Rd = inst.operands[0].reg;
11504 Rn = inst.operands[2].reg;
11505
11506 reject_bad_reg (Rd);
11507 reject_bad_reg (Rn);
11508
11509 inst.instruction |= Rd << 8;
11510 inst.instruction |= inst.operands[1].imm - 1;
11511 inst.instruction |= Rn << 16;
11512 }
11513
11514 static void
11515 do_t_strex (void)
11516 {
11517 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
11518 || inst.operands[2].postind || inst.operands[2].writeback
11519 || inst.operands[2].immisreg || inst.operands[2].shifted
11520 || inst.operands[2].negative,
11521 BAD_ADDR_MODE);
11522
11523 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
11524
11525 inst.instruction |= inst.operands[0].reg << 8;
11526 inst.instruction |= inst.operands[1].reg << 12;
11527 inst.instruction |= inst.operands[2].reg << 16;
11528 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11529 }
11530
11531 static void
11532 do_t_strexd (void)
11533 {
11534 if (!inst.operands[2].present)
11535 inst.operands[2].reg = inst.operands[1].reg + 1;
11536
11537 constraint (inst.operands[0].reg == inst.operands[1].reg
11538 || inst.operands[0].reg == inst.operands[2].reg
11539 || inst.operands[0].reg == inst.operands[3].reg,
11540 BAD_OVERLAP);
11541
11542 inst.instruction |= inst.operands[0].reg;
11543 inst.instruction |= inst.operands[1].reg << 12;
11544 inst.instruction |= inst.operands[2].reg << 8;
11545 inst.instruction |= inst.operands[3].reg << 16;
11546 }
11547
11548 static void
11549 do_t_sxtah (void)
11550 {
11551 unsigned Rd, Rn, Rm;
11552
11553 Rd = inst.operands[0].reg;
11554 Rn = inst.operands[1].reg;
11555 Rm = inst.operands[2].reg;
11556
11557 reject_bad_reg (Rd);
11558 reject_bad_reg (Rn);
11559 reject_bad_reg (Rm);
11560
11561 inst.instruction |= Rd << 8;
11562 inst.instruction |= Rn << 16;
11563 inst.instruction |= Rm;
11564 inst.instruction |= inst.operands[3].imm << 4;
11565 }
11566
11567 static void
11568 do_t_sxth (void)
11569 {
11570 unsigned Rd, Rm;
11571
11572 Rd = inst.operands[0].reg;
11573 Rm = inst.operands[1].reg;
11574
11575 reject_bad_reg (Rd);
11576 reject_bad_reg (Rm);
11577
11578 if (inst.instruction <= 0xffff
11579 && inst.size_req != 4
11580 && Rd <= 7 && Rm <= 7
11581 && (!inst.operands[2].present || inst.operands[2].imm == 0))
11582 {
11583 inst.instruction = THUMB_OP16 (inst.instruction);
11584 inst.instruction |= Rd;
11585 inst.instruction |= Rm << 3;
11586 }
11587 else if (unified_syntax)
11588 {
11589 if (inst.instruction <= 0xffff)
11590 inst.instruction = THUMB_OP32 (inst.instruction);
11591 inst.instruction |= Rd << 8;
11592 inst.instruction |= Rm;
11593 inst.instruction |= inst.operands[2].imm << 4;
11594 }
11595 else
11596 {
11597 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
11598 _("Thumb encoding does not support rotation"));
11599 constraint (1, BAD_HIREG);
11600 }
11601 }
11602
11603 static void
11604 do_t_swi (void)
11605 {
11606 /* We have to do the following check manually as ARM_EXT_OS only applies
11607 to ARM_EXT_V6M. */
11608 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
11609 {
11610 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os))
11611 as_bad (_("SVC is not permitted on this architecture"));
11612 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
11613 }
11614
11615 inst.reloc.type = BFD_RELOC_ARM_SWI;
11616 }
11617
11618 static void
11619 do_t_tb (void)
11620 {
11621 unsigned Rn, Rm;
11622 int half;
11623
11624 half = (inst.instruction & 0x10) != 0;
11625 set_it_insn_type_last ();
11626 constraint (inst.operands[0].immisreg,
11627 _("instruction requires register index"));
11628
11629 Rn = inst.operands[0].reg;
11630 Rm = inst.operands[0].imm;
11631
11632 constraint (Rn == REG_SP, BAD_SP);
11633 reject_bad_reg (Rm);
11634
11635 constraint (!half && inst.operands[0].shifted,
11636 _("instruction does not allow shifted index"));
11637 inst.instruction |= (Rn << 16) | Rm;
11638 }
11639
11640 static void
11641 do_t_usat (void)
11642 {
11643 do_t_ssat_usat (0);
11644 }
11645
11646 static void
11647 do_t_usat16 (void)
11648 {
11649 unsigned Rd, Rn;
11650
11651 Rd = inst.operands[0].reg;
11652 Rn = inst.operands[2].reg;
11653
11654 reject_bad_reg (Rd);
11655 reject_bad_reg (Rn);
11656
11657 inst.instruction |= Rd << 8;
11658 inst.instruction |= inst.operands[1].imm;
11659 inst.instruction |= Rn << 16;
11660 }
11661
11662 /* Neon instruction encoder helpers. */
11663
11664 /* Encodings for the different types for various Neon opcodes. */
11665
11666 /* An "invalid" code for the following tables. */
11667 #define N_INV -1u
11668
11669 struct neon_tab_entry
11670 {
11671 unsigned integer;
11672 unsigned float_or_poly;
11673 unsigned scalar_or_imm;
11674 };
11675
11676 /* Map overloaded Neon opcodes to their respective encodings. */
11677 #define NEON_ENC_TAB \
11678 X(vabd, 0x0000700, 0x1200d00, N_INV), \
11679 X(vmax, 0x0000600, 0x0000f00, N_INV), \
11680 X(vmin, 0x0000610, 0x0200f00, N_INV), \
11681 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
11682 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
11683 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
11684 X(vadd, 0x0000800, 0x0000d00, N_INV), \
11685 X(vsub, 0x1000800, 0x0200d00, N_INV), \
11686 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
11687 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
11688 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
11689 /* Register variants of the following two instructions are encoded as
11690 vcge / vcgt with the operands reversed. */ \
11691 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
11692 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
11693 X(vfma, N_INV, 0x0000c10, N_INV), \
11694 X(vfms, N_INV, 0x0200c10, N_INV), \
11695 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
11696 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
11697 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
11698 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
11699 X(vmlal, 0x0800800, N_INV, 0x0800240), \
11700 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
11701 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
11702 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
11703 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
11704 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
11705 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
11706 X(vshl, 0x0000400, N_INV, 0x0800510), \
11707 X(vqshl, 0x0000410, N_INV, 0x0800710), \
11708 X(vand, 0x0000110, N_INV, 0x0800030), \
11709 X(vbic, 0x0100110, N_INV, 0x0800030), \
11710 X(veor, 0x1000110, N_INV, N_INV), \
11711 X(vorn, 0x0300110, N_INV, 0x0800010), \
11712 X(vorr, 0x0200110, N_INV, 0x0800010), \
11713 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
11714 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
11715 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
11716 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
11717 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
11718 X(vst1, 0x0000000, 0x0800000, N_INV), \
11719 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
11720 X(vst2, 0x0000100, 0x0800100, N_INV), \
11721 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
11722 X(vst3, 0x0000200, 0x0800200, N_INV), \
11723 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
11724 X(vst4, 0x0000300, 0x0800300, N_INV), \
11725 X(vmovn, 0x1b20200, N_INV, N_INV), \
11726 X(vtrn, 0x1b20080, N_INV, N_INV), \
11727 X(vqmovn, 0x1b20200, N_INV, N_INV), \
11728 X(vqmovun, 0x1b20240, N_INV, N_INV), \
11729 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
11730 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
11731 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
11732 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
11733 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
11734 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
11735 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
11736 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
11737 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
11738
11739 enum neon_opc
11740 {
11741 #define X(OPC,I,F,S) N_MNEM_##OPC
11742 NEON_ENC_TAB
11743 #undef X
11744 };
11745
11746 static const struct neon_tab_entry neon_enc_tab[] =
11747 {
11748 #define X(OPC,I,F,S) { (I), (F), (S) }
11749 NEON_ENC_TAB
11750 #undef X
11751 };
11752
11753 /* Do not use these macros; instead, use NEON_ENCODE defined below. */
11754 #define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11755 #define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11756 #define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11757 #define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11758 #define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11759 #define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11760 #define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11761 #define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11762 #define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11763 #define NEON_ENC_SINGLE_(X) \
11764 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
11765 #define NEON_ENC_DOUBLE_(X) \
11766 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
11767
11768 #define NEON_ENCODE(type, inst) \
11769 do \
11770 { \
11771 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
11772 inst.is_neon = 1; \
11773 } \
11774 while (0)
11775
11776 #define check_neon_suffixes \
11777 do \
11778 { \
11779 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
11780 { \
11781 as_bad (_("invalid neon suffix for non neon instruction")); \
11782 return; \
11783 } \
11784 } \
11785 while (0)
11786
11787 /* Define shapes for instruction operands. The following mnemonic characters
11788 are used in this table:
11789
11790 F - VFP S<n> register
11791 D - Neon D<n> register
11792 Q - Neon Q<n> register
11793 I - Immediate
11794 S - Scalar
11795 R - ARM register
11796 L - D<n> register list
11797
11798 This table is used to generate various data:
11799 - enumerations of the form NS_DDR to be used as arguments to
11800 neon_select_shape.
11801 - a table classifying shapes into single, double, quad, mixed.
11802 - a table used to drive neon_select_shape. */
11803
11804 #define NEON_SHAPE_DEF \
11805 X(3, (D, D, D), DOUBLE), \
11806 X(3, (Q, Q, Q), QUAD), \
11807 X(3, (D, D, I), DOUBLE), \
11808 X(3, (Q, Q, I), QUAD), \
11809 X(3, (D, D, S), DOUBLE), \
11810 X(3, (Q, Q, S), QUAD), \
11811 X(2, (D, D), DOUBLE), \
11812 X(2, (Q, Q), QUAD), \
11813 X(2, (D, S), DOUBLE), \
11814 X(2, (Q, S), QUAD), \
11815 X(2, (D, R), DOUBLE), \
11816 X(2, (Q, R), QUAD), \
11817 X(2, (D, I), DOUBLE), \
11818 X(2, (Q, I), QUAD), \
11819 X(3, (D, L, D), DOUBLE), \
11820 X(2, (D, Q), MIXED), \
11821 X(2, (Q, D), MIXED), \
11822 X(3, (D, Q, I), MIXED), \
11823 X(3, (Q, D, I), MIXED), \
11824 X(3, (Q, D, D), MIXED), \
11825 X(3, (D, Q, Q), MIXED), \
11826 X(3, (Q, Q, D), MIXED), \
11827 X(3, (Q, D, S), MIXED), \
11828 X(3, (D, Q, S), MIXED), \
11829 X(4, (D, D, D, I), DOUBLE), \
11830 X(4, (Q, Q, Q, I), QUAD), \
11831 X(2, (F, F), SINGLE), \
11832 X(3, (F, F, F), SINGLE), \
11833 X(2, (F, I), SINGLE), \
11834 X(2, (F, D), MIXED), \
11835 X(2, (D, F), MIXED), \
11836 X(3, (F, F, I), MIXED), \
11837 X(4, (R, R, F, F), SINGLE), \
11838 X(4, (F, F, R, R), SINGLE), \
11839 X(3, (D, R, R), DOUBLE), \
11840 X(3, (R, R, D), DOUBLE), \
11841 X(2, (S, R), SINGLE), \
11842 X(2, (R, S), SINGLE), \
11843 X(2, (F, R), SINGLE), \
11844 X(2, (R, F), SINGLE)
11845
11846 #define S2(A,B) NS_##A##B
11847 #define S3(A,B,C) NS_##A##B##C
11848 #define S4(A,B,C,D) NS_##A##B##C##D
11849
11850 #define X(N, L, C) S##N L
11851
11852 enum neon_shape
11853 {
11854 NEON_SHAPE_DEF,
11855 NS_NULL
11856 };
11857
11858 #undef X
11859 #undef S2
11860 #undef S3
11861 #undef S4
11862
11863 enum neon_shape_class
11864 {
11865 SC_SINGLE,
11866 SC_DOUBLE,
11867 SC_QUAD,
11868 SC_MIXED
11869 };
11870
11871 #define X(N, L, C) SC_##C
11872
11873 static enum neon_shape_class neon_shape_class[] =
11874 {
11875 NEON_SHAPE_DEF
11876 };
11877
11878 #undef X
11879
11880 enum neon_shape_el
11881 {
11882 SE_F,
11883 SE_D,
11884 SE_Q,
11885 SE_I,
11886 SE_S,
11887 SE_R,
11888 SE_L
11889 };
11890
11891 /* Register widths of above. */
11892 static unsigned neon_shape_el_size[] =
11893 {
11894 32,
11895 64,
11896 128,
11897 0,
11898 32,
11899 32,
11900 0
11901 };
11902
11903 struct neon_shape_info
11904 {
11905 unsigned els;
11906 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
11907 };
11908
11909 #define S2(A,B) { SE_##A, SE_##B }
11910 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
11911 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
11912
11913 #define X(N, L, C) { N, S##N L }
11914
11915 static struct neon_shape_info neon_shape_tab[] =
11916 {
11917 NEON_SHAPE_DEF
11918 };
11919
11920 #undef X
11921 #undef S2
11922 #undef S3
11923 #undef S4
11924
11925 /* Bit masks used in type checking given instructions.
11926 'N_EQK' means the type must be the same as (or based on in some way) the key
11927 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
11928 set, various other bits can be set as well in order to modify the meaning of
11929 the type constraint. */
11930
11931 enum neon_type_mask
11932 {
11933 N_S8 = 0x0000001,
11934 N_S16 = 0x0000002,
11935 N_S32 = 0x0000004,
11936 N_S64 = 0x0000008,
11937 N_U8 = 0x0000010,
11938 N_U16 = 0x0000020,
11939 N_U32 = 0x0000040,
11940 N_U64 = 0x0000080,
11941 N_I8 = 0x0000100,
11942 N_I16 = 0x0000200,
11943 N_I32 = 0x0000400,
11944 N_I64 = 0x0000800,
11945 N_8 = 0x0001000,
11946 N_16 = 0x0002000,
11947 N_32 = 0x0004000,
11948 N_64 = 0x0008000,
11949 N_P8 = 0x0010000,
11950 N_P16 = 0x0020000,
11951 N_F16 = 0x0040000,
11952 N_F32 = 0x0080000,
11953 N_F64 = 0x0100000,
11954 N_KEY = 0x1000000, /* Key element (main type specifier). */
11955 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
11956 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
11957 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
11958 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
11959 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
11960 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
11961 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
11962 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
11963 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
11964 N_UTYP = 0,
11965 N_MAX_NONSPECIAL = N_F64
11966 };
11967
11968 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
11969
11970 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
11971 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
11972 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
11973 #define N_SUF_32 (N_SU_32 | N_F32)
11974 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
11975 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
11976
11977 /* Pass this as the first type argument to neon_check_type to ignore types
11978 altogether. */
11979 #define N_IGNORE_TYPE (N_KEY | N_EQK)
11980
11981 /* Select a "shape" for the current instruction (describing register types or
11982 sizes) from a list of alternatives. Return NS_NULL if the current instruction
11983 doesn't fit. For non-polymorphic shapes, checking is usually done as a
11984 function of operand parsing, so this function doesn't need to be called.
11985 Shapes should be listed in order of decreasing length. */
11986
11987 static enum neon_shape
11988 neon_select_shape (enum neon_shape shape, ...)
11989 {
11990 va_list ap;
11991 enum neon_shape first_shape = shape;
11992
11993 /* Fix missing optional operands. FIXME: we don't know at this point how
11994 many arguments we should have, so this makes the assumption that we have
11995 > 1. This is true of all current Neon opcodes, I think, but may not be
11996 true in the future. */
11997 if (!inst.operands[1].present)
11998 inst.operands[1] = inst.operands[0];
11999
12000 va_start (ap, shape);
12001
12002 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
12003 {
12004 unsigned j;
12005 int matches = 1;
12006
12007 for (j = 0; j < neon_shape_tab[shape].els; j++)
12008 {
12009 if (!inst.operands[j].present)
12010 {
12011 matches = 0;
12012 break;
12013 }
12014
12015 switch (neon_shape_tab[shape].el[j])
12016 {
12017 case SE_F:
12018 if (!(inst.operands[j].isreg
12019 && inst.operands[j].isvec
12020 && inst.operands[j].issingle
12021 && !inst.operands[j].isquad))
12022 matches = 0;
12023 break;
12024
12025 case SE_D:
12026 if (!(inst.operands[j].isreg
12027 && inst.operands[j].isvec
12028 && !inst.operands[j].isquad
12029 && !inst.operands[j].issingle))
12030 matches = 0;
12031 break;
12032
12033 case SE_R:
12034 if (!(inst.operands[j].isreg
12035 && !inst.operands[j].isvec))
12036 matches = 0;
12037 break;
12038
12039 case SE_Q:
12040 if (!(inst.operands[j].isreg
12041 && inst.operands[j].isvec
12042 && inst.operands[j].isquad
12043 && !inst.operands[j].issingle))
12044 matches = 0;
12045 break;
12046
12047 case SE_I:
12048 if (!(!inst.operands[j].isreg
12049 && !inst.operands[j].isscalar))
12050 matches = 0;
12051 break;
12052
12053 case SE_S:
12054 if (!(!inst.operands[j].isreg
12055 && inst.operands[j].isscalar))
12056 matches = 0;
12057 break;
12058
12059 case SE_L:
12060 break;
12061 }
12062 if (!matches)
12063 break;
12064 }
12065 if (matches)
12066 break;
12067 }
12068
12069 va_end (ap);
12070
12071 if (shape == NS_NULL && first_shape != NS_NULL)
12072 first_error (_("invalid instruction shape"));
12073
12074 return shape;
12075 }
12076
12077 /* True if SHAPE is predominantly a quadword operation (most of the time, this
12078 means the Q bit should be set). */
12079
12080 static int
12081 neon_quad (enum neon_shape shape)
12082 {
12083 return neon_shape_class[shape] == SC_QUAD;
12084 }
12085
12086 static void
12087 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
12088 unsigned *g_size)
12089 {
12090 /* Allow modification to be made to types which are constrained to be
12091 based on the key element, based on bits set alongside N_EQK. */
12092 if ((typebits & N_EQK) != 0)
12093 {
12094 if ((typebits & N_HLF) != 0)
12095 *g_size /= 2;
12096 else if ((typebits & N_DBL) != 0)
12097 *g_size *= 2;
12098 if ((typebits & N_SGN) != 0)
12099 *g_type = NT_signed;
12100 else if ((typebits & N_UNS) != 0)
12101 *g_type = NT_unsigned;
12102 else if ((typebits & N_INT) != 0)
12103 *g_type = NT_integer;
12104 else if ((typebits & N_FLT) != 0)
12105 *g_type = NT_float;
12106 else if ((typebits & N_SIZ) != 0)
12107 *g_type = NT_untyped;
12108 }
12109 }
12110
12111 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
12112 operand type, i.e. the single type specified in a Neon instruction when it
12113 is the only one given. */
12114
12115 static struct neon_type_el
12116 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
12117 {
12118 struct neon_type_el dest = *key;
12119
12120 gas_assert ((thisarg & N_EQK) != 0);
12121
12122 neon_modify_type_size (thisarg, &dest.type, &dest.size);
12123
12124 return dest;
12125 }
12126
12127 /* Convert Neon type and size into compact bitmask representation. */
12128
12129 static enum neon_type_mask
12130 type_chk_of_el_type (enum neon_el_type type, unsigned size)
12131 {
12132 switch (type)
12133 {
12134 case NT_untyped:
12135 switch (size)
12136 {
12137 case 8: return N_8;
12138 case 16: return N_16;
12139 case 32: return N_32;
12140 case 64: return N_64;
12141 default: ;
12142 }
12143 break;
12144
12145 case NT_integer:
12146 switch (size)
12147 {
12148 case 8: return N_I8;
12149 case 16: return N_I16;
12150 case 32: return N_I32;
12151 case 64: return N_I64;
12152 default: ;
12153 }
12154 break;
12155
12156 case NT_float:
12157 switch (size)
12158 {
12159 case 16: return N_F16;
12160 case 32: return N_F32;
12161 case 64: return N_F64;
12162 default: ;
12163 }
12164 break;
12165
12166 case NT_poly:
12167 switch (size)
12168 {
12169 case 8: return N_P8;
12170 case 16: return N_P16;
12171 default: ;
12172 }
12173 break;
12174
12175 case NT_signed:
12176 switch (size)
12177 {
12178 case 8: return N_S8;
12179 case 16: return N_S16;
12180 case 32: return N_S32;
12181 case 64: return N_S64;
12182 default: ;
12183 }
12184 break;
12185
12186 case NT_unsigned:
12187 switch (size)
12188 {
12189 case 8: return N_U8;
12190 case 16: return N_U16;
12191 case 32: return N_U32;
12192 case 64: return N_U64;
12193 default: ;
12194 }
12195 break;
12196
12197 default: ;
12198 }
12199
12200 return N_UTYP;
12201 }
12202
12203 /* Convert compact Neon bitmask type representation to a type and size. Only
12204 handles the case where a single bit is set in the mask. */
12205
12206 static int
12207 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
12208 enum neon_type_mask mask)
12209 {
12210 if ((mask & N_EQK) != 0)
12211 return FAIL;
12212
12213 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
12214 *size = 8;
12215 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
12216 *size = 16;
12217 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
12218 *size = 32;
12219 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
12220 *size = 64;
12221 else
12222 return FAIL;
12223
12224 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
12225 *type = NT_signed;
12226 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
12227 *type = NT_unsigned;
12228 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
12229 *type = NT_integer;
12230 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
12231 *type = NT_untyped;
12232 else if ((mask & (N_P8 | N_P16)) != 0)
12233 *type = NT_poly;
12234 else if ((mask & (N_F32 | N_F64)) != 0)
12235 *type = NT_float;
12236 else
12237 return FAIL;
12238
12239 return SUCCESS;
12240 }
12241
12242 /* Modify a bitmask of allowed types. This is only needed for type
12243 relaxation. */
12244
12245 static unsigned
12246 modify_types_allowed (unsigned allowed, unsigned mods)
12247 {
12248 unsigned size;
12249 enum neon_el_type type;
12250 unsigned destmask;
12251 int i;
12252
12253 destmask = 0;
12254
12255 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
12256 {
12257 if (el_type_of_type_chk (&type, &size,
12258 (enum neon_type_mask) (allowed & i)) == SUCCESS)
12259 {
12260 neon_modify_type_size (mods, &type, &size);
12261 destmask |= type_chk_of_el_type (type, size);
12262 }
12263 }
12264
12265 return destmask;
12266 }
12267
12268 /* Check type and return type classification.
12269 The manual states (paraphrase): If one datatype is given, it indicates the
12270 type given in:
12271 - the second operand, if there is one
12272 - the operand, if there is no second operand
12273 - the result, if there are no operands.
12274 This isn't quite good enough though, so we use a concept of a "key" datatype
12275 which is set on a per-instruction basis, which is the one which matters when
12276 only one data type is written.
12277 Note: this function has side-effects (e.g. filling in missing operands). All
12278 Neon instructions should call it before performing bit encoding. */
12279
12280 static struct neon_type_el
12281 neon_check_type (unsigned els, enum neon_shape ns, ...)
12282 {
12283 va_list ap;
12284 unsigned i, pass, key_el = 0;
12285 unsigned types[NEON_MAX_TYPE_ELS];
12286 enum neon_el_type k_type = NT_invtype;
12287 unsigned k_size = -1u;
12288 struct neon_type_el badtype = {NT_invtype, -1};
12289 unsigned key_allowed = 0;
12290
12291 /* Optional registers in Neon instructions are always (not) in operand 1.
12292 Fill in the missing operand here, if it was omitted. */
12293 if (els > 1 && !inst.operands[1].present)
12294 inst.operands[1] = inst.operands[0];
12295
12296 /* Suck up all the varargs. */
12297 va_start (ap, ns);
12298 for (i = 0; i < els; i++)
12299 {
12300 unsigned thisarg = va_arg (ap, unsigned);
12301 if (thisarg == N_IGNORE_TYPE)
12302 {
12303 va_end (ap);
12304 return badtype;
12305 }
12306 types[i] = thisarg;
12307 if ((thisarg & N_KEY) != 0)
12308 key_el = i;
12309 }
12310 va_end (ap);
12311
12312 if (inst.vectype.elems > 0)
12313 for (i = 0; i < els; i++)
12314 if (inst.operands[i].vectype.type != NT_invtype)
12315 {
12316 first_error (_("types specified in both the mnemonic and operands"));
12317 return badtype;
12318 }
12319
12320 /* Duplicate inst.vectype elements here as necessary.
12321 FIXME: No idea if this is exactly the same as the ARM assembler,
12322 particularly when an insn takes one register and one non-register
12323 operand. */
12324 if (inst.vectype.elems == 1 && els > 1)
12325 {
12326 unsigned j;
12327 inst.vectype.elems = els;
12328 inst.vectype.el[key_el] = inst.vectype.el[0];
12329 for (j = 0; j < els; j++)
12330 if (j != key_el)
12331 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12332 types[j]);
12333 }
12334 else if (inst.vectype.elems == 0 && els > 0)
12335 {
12336 unsigned j;
12337 /* No types were given after the mnemonic, so look for types specified
12338 after each operand. We allow some flexibility here; as long as the
12339 "key" operand has a type, we can infer the others. */
12340 for (j = 0; j < els; j++)
12341 if (inst.operands[j].vectype.type != NT_invtype)
12342 inst.vectype.el[j] = inst.operands[j].vectype;
12343
12344 if (inst.operands[key_el].vectype.type != NT_invtype)
12345 {
12346 for (j = 0; j < els; j++)
12347 if (inst.operands[j].vectype.type == NT_invtype)
12348 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12349 types[j]);
12350 }
12351 else
12352 {
12353 first_error (_("operand types can't be inferred"));
12354 return badtype;
12355 }
12356 }
12357 else if (inst.vectype.elems != els)
12358 {
12359 first_error (_("type specifier has the wrong number of parts"));
12360 return badtype;
12361 }
12362
12363 for (pass = 0; pass < 2; pass++)
12364 {
12365 for (i = 0; i < els; i++)
12366 {
12367 unsigned thisarg = types[i];
12368 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
12369 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
12370 enum neon_el_type g_type = inst.vectype.el[i].type;
12371 unsigned g_size = inst.vectype.el[i].size;
12372
12373 /* Decay more-specific signed & unsigned types to sign-insensitive
12374 integer types if sign-specific variants are unavailable. */
12375 if ((g_type == NT_signed || g_type == NT_unsigned)
12376 && (types_allowed & N_SU_ALL) == 0)
12377 g_type = NT_integer;
12378
12379 /* If only untyped args are allowed, decay any more specific types to
12380 them. Some instructions only care about signs for some element
12381 sizes, so handle that properly. */
12382 if ((g_size == 8 && (types_allowed & N_8) != 0)
12383 || (g_size == 16 && (types_allowed & N_16) != 0)
12384 || (g_size == 32 && (types_allowed & N_32) != 0)
12385 || (g_size == 64 && (types_allowed & N_64) != 0))
12386 g_type = NT_untyped;
12387
12388 if (pass == 0)
12389 {
12390 if ((thisarg & N_KEY) != 0)
12391 {
12392 k_type = g_type;
12393 k_size = g_size;
12394 key_allowed = thisarg & ~N_KEY;
12395 }
12396 }
12397 else
12398 {
12399 if ((thisarg & N_VFP) != 0)
12400 {
12401 enum neon_shape_el regshape;
12402 unsigned regwidth, match;
12403
12404 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
12405 if (ns == NS_NULL)
12406 {
12407 first_error (_("invalid instruction shape"));
12408 return badtype;
12409 }
12410 regshape = neon_shape_tab[ns].el[i];
12411 regwidth = neon_shape_el_size[regshape];
12412
12413 /* In VFP mode, operands must match register widths. If we
12414 have a key operand, use its width, else use the width of
12415 the current operand. */
12416 if (k_size != -1u)
12417 match = k_size;
12418 else
12419 match = g_size;
12420
12421 if (regwidth != match)
12422 {
12423 first_error (_("operand size must match register width"));
12424 return badtype;
12425 }
12426 }
12427
12428 if ((thisarg & N_EQK) == 0)
12429 {
12430 unsigned given_type = type_chk_of_el_type (g_type, g_size);
12431
12432 if ((given_type & types_allowed) == 0)
12433 {
12434 first_error (_("bad type in Neon instruction"));
12435 return badtype;
12436 }
12437 }
12438 else
12439 {
12440 enum neon_el_type mod_k_type = k_type;
12441 unsigned mod_k_size = k_size;
12442 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
12443 if (g_type != mod_k_type || g_size != mod_k_size)
12444 {
12445 first_error (_("inconsistent types in Neon instruction"));
12446 return badtype;
12447 }
12448 }
12449 }
12450 }
12451 }
12452
12453 return inst.vectype.el[key_el];
12454 }
12455
12456 /* Neon-style VFP instruction forwarding. */
12457
12458 /* Thumb VFP instructions have 0xE in the condition field. */
12459
12460 static void
12461 do_vfp_cond_or_thumb (void)
12462 {
12463 inst.is_neon = 1;
12464
12465 if (thumb_mode)
12466 inst.instruction |= 0xe0000000;
12467 else
12468 inst.instruction |= inst.cond << 28;
12469 }
12470
12471 /* Look up and encode a simple mnemonic, for use as a helper function for the
12472 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
12473 etc. It is assumed that operand parsing has already been done, and that the
12474 operands are in the form expected by the given opcode (this isn't necessarily
12475 the same as the form in which they were parsed, hence some massaging must
12476 take place before this function is called).
12477 Checks current arch version against that in the looked-up opcode. */
12478
12479 static void
12480 do_vfp_nsyn_opcode (const char *opname)
12481 {
12482 const struct asm_opcode *opcode;
12483
12484 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
12485
12486 if (!opcode)
12487 abort ();
12488
12489 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
12490 thumb_mode ? *opcode->tvariant : *opcode->avariant),
12491 _(BAD_FPU));
12492
12493 inst.is_neon = 1;
12494
12495 if (thumb_mode)
12496 {
12497 inst.instruction = opcode->tvalue;
12498 opcode->tencode ();
12499 }
12500 else
12501 {
12502 inst.instruction = (inst.cond << 28) | opcode->avalue;
12503 opcode->aencode ();
12504 }
12505 }
12506
12507 static void
12508 do_vfp_nsyn_add_sub (enum neon_shape rs)
12509 {
12510 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
12511
12512 if (rs == NS_FFF)
12513 {
12514 if (is_add)
12515 do_vfp_nsyn_opcode ("fadds");
12516 else
12517 do_vfp_nsyn_opcode ("fsubs");
12518 }
12519 else
12520 {
12521 if (is_add)
12522 do_vfp_nsyn_opcode ("faddd");
12523 else
12524 do_vfp_nsyn_opcode ("fsubd");
12525 }
12526 }
12527
12528 /* Check operand types to see if this is a VFP instruction, and if so call
12529 PFN (). */
12530
12531 static int
12532 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
12533 {
12534 enum neon_shape rs;
12535 struct neon_type_el et;
12536
12537 switch (args)
12538 {
12539 case 2:
12540 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12541 et = neon_check_type (2, rs,
12542 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12543 break;
12544
12545 case 3:
12546 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12547 et = neon_check_type (3, rs,
12548 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12549 break;
12550
12551 default:
12552 abort ();
12553 }
12554
12555 if (et.type != NT_invtype)
12556 {
12557 pfn (rs);
12558 return SUCCESS;
12559 }
12560
12561 inst.error = NULL;
12562 return FAIL;
12563 }
12564
12565 static void
12566 do_vfp_nsyn_mla_mls (enum neon_shape rs)
12567 {
12568 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
12569
12570 if (rs == NS_FFF)
12571 {
12572 if (is_mla)
12573 do_vfp_nsyn_opcode ("fmacs");
12574 else
12575 do_vfp_nsyn_opcode ("fnmacs");
12576 }
12577 else
12578 {
12579 if (is_mla)
12580 do_vfp_nsyn_opcode ("fmacd");
12581 else
12582 do_vfp_nsyn_opcode ("fnmacd");
12583 }
12584 }
12585
12586 static void
12587 do_vfp_nsyn_fma_fms (enum neon_shape rs)
12588 {
12589 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
12590
12591 if (rs == NS_FFF)
12592 {
12593 if (is_fma)
12594 do_vfp_nsyn_opcode ("ffmas");
12595 else
12596 do_vfp_nsyn_opcode ("ffnmas");
12597 }
12598 else
12599 {
12600 if (is_fma)
12601 do_vfp_nsyn_opcode ("ffmad");
12602 else
12603 do_vfp_nsyn_opcode ("ffnmad");
12604 }
12605 }
12606
12607 static void
12608 do_vfp_nsyn_mul (enum neon_shape rs)
12609 {
12610 if (rs == NS_FFF)
12611 do_vfp_nsyn_opcode ("fmuls");
12612 else
12613 do_vfp_nsyn_opcode ("fmuld");
12614 }
12615
12616 static void
12617 do_vfp_nsyn_abs_neg (enum neon_shape rs)
12618 {
12619 int is_neg = (inst.instruction & 0x80) != 0;
12620 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
12621
12622 if (rs == NS_FF)
12623 {
12624 if (is_neg)
12625 do_vfp_nsyn_opcode ("fnegs");
12626 else
12627 do_vfp_nsyn_opcode ("fabss");
12628 }
12629 else
12630 {
12631 if (is_neg)
12632 do_vfp_nsyn_opcode ("fnegd");
12633 else
12634 do_vfp_nsyn_opcode ("fabsd");
12635 }
12636 }
12637
12638 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
12639 insns belong to Neon, and are handled elsewhere. */
12640
12641 static void
12642 do_vfp_nsyn_ldm_stm (int is_dbmode)
12643 {
12644 int is_ldm = (inst.instruction & (1 << 20)) != 0;
12645 if (is_ldm)
12646 {
12647 if (is_dbmode)
12648 do_vfp_nsyn_opcode ("fldmdbs");
12649 else
12650 do_vfp_nsyn_opcode ("fldmias");
12651 }
12652 else
12653 {
12654 if (is_dbmode)
12655 do_vfp_nsyn_opcode ("fstmdbs");
12656 else
12657 do_vfp_nsyn_opcode ("fstmias");
12658 }
12659 }
12660
12661 static void
12662 do_vfp_nsyn_sqrt (void)
12663 {
12664 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12665 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12666
12667 if (rs == NS_FF)
12668 do_vfp_nsyn_opcode ("fsqrts");
12669 else
12670 do_vfp_nsyn_opcode ("fsqrtd");
12671 }
12672
12673 static void
12674 do_vfp_nsyn_div (void)
12675 {
12676 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12677 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12678 N_F32 | N_F64 | N_KEY | N_VFP);
12679
12680 if (rs == NS_FFF)
12681 do_vfp_nsyn_opcode ("fdivs");
12682 else
12683 do_vfp_nsyn_opcode ("fdivd");
12684 }
12685
12686 static void
12687 do_vfp_nsyn_nmul (void)
12688 {
12689 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12690 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12691 N_F32 | N_F64 | N_KEY | N_VFP);
12692
12693 if (rs == NS_FFF)
12694 {
12695 NEON_ENCODE (SINGLE, inst);
12696 do_vfp_sp_dyadic ();
12697 }
12698 else
12699 {
12700 NEON_ENCODE (DOUBLE, inst);
12701 do_vfp_dp_rd_rn_rm ();
12702 }
12703 do_vfp_cond_or_thumb ();
12704 }
12705
12706 static void
12707 do_vfp_nsyn_cmp (void)
12708 {
12709 if (inst.operands[1].isreg)
12710 {
12711 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12712 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12713
12714 if (rs == NS_FF)
12715 {
12716 NEON_ENCODE (SINGLE, inst);
12717 do_vfp_sp_monadic ();
12718 }
12719 else
12720 {
12721 NEON_ENCODE (DOUBLE, inst);
12722 do_vfp_dp_rd_rm ();
12723 }
12724 }
12725 else
12726 {
12727 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
12728 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
12729
12730 switch (inst.instruction & 0x0fffffff)
12731 {
12732 case N_MNEM_vcmp:
12733 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
12734 break;
12735 case N_MNEM_vcmpe:
12736 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
12737 break;
12738 default:
12739 abort ();
12740 }
12741
12742 if (rs == NS_FI)
12743 {
12744 NEON_ENCODE (SINGLE, inst);
12745 do_vfp_sp_compare_z ();
12746 }
12747 else
12748 {
12749 NEON_ENCODE (DOUBLE, inst);
12750 do_vfp_dp_rd ();
12751 }
12752 }
12753 do_vfp_cond_or_thumb ();
12754 }
12755
12756 static void
12757 nsyn_insert_sp (void)
12758 {
12759 inst.operands[1] = inst.operands[0];
12760 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
12761 inst.operands[0].reg = REG_SP;
12762 inst.operands[0].isreg = 1;
12763 inst.operands[0].writeback = 1;
12764 inst.operands[0].present = 1;
12765 }
12766
12767 static void
12768 do_vfp_nsyn_push (void)
12769 {
12770 nsyn_insert_sp ();
12771 if (inst.operands[1].issingle)
12772 do_vfp_nsyn_opcode ("fstmdbs");
12773 else
12774 do_vfp_nsyn_opcode ("fstmdbd");
12775 }
12776
12777 static void
12778 do_vfp_nsyn_pop (void)
12779 {
12780 nsyn_insert_sp ();
12781 if (inst.operands[1].issingle)
12782 do_vfp_nsyn_opcode ("fldmias");
12783 else
12784 do_vfp_nsyn_opcode ("fldmiad");
12785 }
12786
12787 /* Fix up Neon data-processing instructions, ORing in the correct bits for
12788 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
12789
12790 static void
12791 neon_dp_fixup (struct arm_it* insn)
12792 {
12793 unsigned int i = insn->instruction;
12794 insn->is_neon = 1;
12795
12796 if (thumb_mode)
12797 {
12798 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
12799 if (i & (1 << 24))
12800 i |= 1 << 28;
12801
12802 i &= ~(1 << 24);
12803
12804 i |= 0xef000000;
12805 }
12806 else
12807 i |= 0xf2000000;
12808
12809 insn->instruction = i;
12810 }
12811
12812 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
12813 (0, 1, 2, 3). */
12814
12815 static unsigned
12816 neon_logbits (unsigned x)
12817 {
12818 return ffs (x) - 4;
12819 }
12820
12821 #define LOW4(R) ((R) & 0xf)
12822 #define HI1(R) (((R) >> 4) & 1)
12823
12824 /* Encode insns with bit pattern:
12825
12826 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12827 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
12828
12829 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
12830 different meaning for some instruction. */
12831
12832 static void
12833 neon_three_same (int isquad, int ubit, int size)
12834 {
12835 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12836 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12837 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12838 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12839 inst.instruction |= LOW4 (inst.operands[2].reg);
12840 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12841 inst.instruction |= (isquad != 0) << 6;
12842 inst.instruction |= (ubit != 0) << 24;
12843 if (size != -1)
12844 inst.instruction |= neon_logbits (size) << 20;
12845
12846 neon_dp_fixup (&inst);
12847 }
12848
12849 /* Encode instructions of the form:
12850
12851 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
12852 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
12853
12854 Don't write size if SIZE == -1. */
12855
12856 static void
12857 neon_two_same (int qbit, int ubit, int size)
12858 {
12859 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12860 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12861 inst.instruction |= LOW4 (inst.operands[1].reg);
12862 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12863 inst.instruction |= (qbit != 0) << 6;
12864 inst.instruction |= (ubit != 0) << 24;
12865
12866 if (size != -1)
12867 inst.instruction |= neon_logbits (size) << 18;
12868
12869 neon_dp_fixup (&inst);
12870 }
12871
12872 /* Neon instruction encoders, in approximate order of appearance. */
12873
12874 static void
12875 do_neon_dyadic_i_su (void)
12876 {
12877 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12878 struct neon_type_el et = neon_check_type (3, rs,
12879 N_EQK, N_EQK, N_SU_32 | N_KEY);
12880 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12881 }
12882
12883 static void
12884 do_neon_dyadic_i64_su (void)
12885 {
12886 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12887 struct neon_type_el et = neon_check_type (3, rs,
12888 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12889 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12890 }
12891
12892 static void
12893 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
12894 unsigned immbits)
12895 {
12896 unsigned size = et.size >> 3;
12897 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12898 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12899 inst.instruction |= LOW4 (inst.operands[1].reg);
12900 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12901 inst.instruction |= (isquad != 0) << 6;
12902 inst.instruction |= immbits << 16;
12903 inst.instruction |= (size >> 3) << 7;
12904 inst.instruction |= (size & 0x7) << 19;
12905 if (write_ubit)
12906 inst.instruction |= (uval != 0) << 24;
12907
12908 neon_dp_fixup (&inst);
12909 }
12910
12911 static void
12912 do_neon_shl_imm (void)
12913 {
12914 if (!inst.operands[2].isreg)
12915 {
12916 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12917 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
12918 NEON_ENCODE (IMMED, inst);
12919 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
12920 }
12921 else
12922 {
12923 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12924 struct neon_type_el et = neon_check_type (3, rs,
12925 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
12926 unsigned int tmp;
12927
12928 /* VSHL/VQSHL 3-register variants have syntax such as:
12929 vshl.xx Dd, Dm, Dn
12930 whereas other 3-register operations encoded by neon_three_same have
12931 syntax like:
12932 vadd.xx Dd, Dn, Dm
12933 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
12934 here. */
12935 tmp = inst.operands[2].reg;
12936 inst.operands[2].reg = inst.operands[1].reg;
12937 inst.operands[1].reg = tmp;
12938 NEON_ENCODE (INTEGER, inst);
12939 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12940 }
12941 }
12942
12943 static void
12944 do_neon_qshl_imm (void)
12945 {
12946 if (!inst.operands[2].isreg)
12947 {
12948 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12949 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
12950
12951 NEON_ENCODE (IMMED, inst);
12952 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
12953 inst.operands[2].imm);
12954 }
12955 else
12956 {
12957 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12958 struct neon_type_el et = neon_check_type (3, rs,
12959 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
12960 unsigned int tmp;
12961
12962 /* See note in do_neon_shl_imm. */
12963 tmp = inst.operands[2].reg;
12964 inst.operands[2].reg = inst.operands[1].reg;
12965 inst.operands[1].reg = tmp;
12966 NEON_ENCODE (INTEGER, inst);
12967 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12968 }
12969 }
12970
12971 static void
12972 do_neon_rshl (void)
12973 {
12974 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12975 struct neon_type_el et = neon_check_type (3, rs,
12976 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12977 unsigned int tmp;
12978
12979 tmp = inst.operands[2].reg;
12980 inst.operands[2].reg = inst.operands[1].reg;
12981 inst.operands[1].reg = tmp;
12982 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12983 }
12984
12985 static int
12986 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
12987 {
12988 /* Handle .I8 pseudo-instructions. */
12989 if (size == 8)
12990 {
12991 /* Unfortunately, this will make everything apart from zero out-of-range.
12992 FIXME is this the intended semantics? There doesn't seem much point in
12993 accepting .I8 if so. */
12994 immediate |= immediate << 8;
12995 size = 16;
12996 }
12997
12998 if (size >= 32)
12999 {
13000 if (immediate == (immediate & 0x000000ff))
13001 {
13002 *immbits = immediate;
13003 return 0x1;
13004 }
13005 else if (immediate == (immediate & 0x0000ff00))
13006 {
13007 *immbits = immediate >> 8;
13008 return 0x3;
13009 }
13010 else if (immediate == (immediate & 0x00ff0000))
13011 {
13012 *immbits = immediate >> 16;
13013 return 0x5;
13014 }
13015 else if (immediate == (immediate & 0xff000000))
13016 {
13017 *immbits = immediate >> 24;
13018 return 0x7;
13019 }
13020 if ((immediate & 0xffff) != (immediate >> 16))
13021 goto bad_immediate;
13022 immediate &= 0xffff;
13023 }
13024
13025 if (immediate == (immediate & 0x000000ff))
13026 {
13027 *immbits = immediate;
13028 return 0x9;
13029 }
13030 else if (immediate == (immediate & 0x0000ff00))
13031 {
13032 *immbits = immediate >> 8;
13033 return 0xb;
13034 }
13035
13036 bad_immediate:
13037 first_error (_("immediate value out of range"));
13038 return FAIL;
13039 }
13040
13041 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
13042 A, B, C, D. */
13043
13044 static int
13045 neon_bits_same_in_bytes (unsigned imm)
13046 {
13047 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
13048 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
13049 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
13050 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
13051 }
13052
13053 /* For immediate of above form, return 0bABCD. */
13054
13055 static unsigned
13056 neon_squash_bits (unsigned imm)
13057 {
13058 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
13059 | ((imm & 0x01000000) >> 21);
13060 }
13061
13062 /* Compress quarter-float representation to 0b...000 abcdefgh. */
13063
13064 static unsigned
13065 neon_qfloat_bits (unsigned imm)
13066 {
13067 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
13068 }
13069
13070 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
13071 the instruction. *OP is passed as the initial value of the op field, and
13072 may be set to a different value depending on the constant (i.e.
13073 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
13074 MVN). If the immediate looks like a repeated pattern then also
13075 try smaller element sizes. */
13076
13077 static int
13078 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
13079 unsigned *immbits, int *op, int size,
13080 enum neon_el_type type)
13081 {
13082 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
13083 float. */
13084 if (type == NT_float && !float_p)
13085 return FAIL;
13086
13087 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
13088 {
13089 if (size != 32 || *op == 1)
13090 return FAIL;
13091 *immbits = neon_qfloat_bits (immlo);
13092 return 0xf;
13093 }
13094
13095 if (size == 64)
13096 {
13097 if (neon_bits_same_in_bytes (immhi)
13098 && neon_bits_same_in_bytes (immlo))
13099 {
13100 if (*op == 1)
13101 return FAIL;
13102 *immbits = (neon_squash_bits (immhi) << 4)
13103 | neon_squash_bits (immlo);
13104 *op = 1;
13105 return 0xe;
13106 }
13107
13108 if (immhi != immlo)
13109 return FAIL;
13110 }
13111
13112 if (size >= 32)
13113 {
13114 if (immlo == (immlo & 0x000000ff))
13115 {
13116 *immbits = immlo;
13117 return 0x0;
13118 }
13119 else if (immlo == (immlo & 0x0000ff00))
13120 {
13121 *immbits = immlo >> 8;
13122 return 0x2;
13123 }
13124 else if (immlo == (immlo & 0x00ff0000))
13125 {
13126 *immbits = immlo >> 16;
13127 return 0x4;
13128 }
13129 else if (immlo == (immlo & 0xff000000))
13130 {
13131 *immbits = immlo >> 24;
13132 return 0x6;
13133 }
13134 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
13135 {
13136 *immbits = (immlo >> 8) & 0xff;
13137 return 0xc;
13138 }
13139 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
13140 {
13141 *immbits = (immlo >> 16) & 0xff;
13142 return 0xd;
13143 }
13144
13145 if ((immlo & 0xffff) != (immlo >> 16))
13146 return FAIL;
13147 immlo &= 0xffff;
13148 }
13149
13150 if (size >= 16)
13151 {
13152 if (immlo == (immlo & 0x000000ff))
13153 {
13154 *immbits = immlo;
13155 return 0x8;
13156 }
13157 else if (immlo == (immlo & 0x0000ff00))
13158 {
13159 *immbits = immlo >> 8;
13160 return 0xa;
13161 }
13162
13163 if ((immlo & 0xff) != (immlo >> 8))
13164 return FAIL;
13165 immlo &= 0xff;
13166 }
13167
13168 if (immlo == (immlo & 0x000000ff))
13169 {
13170 /* Don't allow MVN with 8-bit immediate. */
13171 if (*op == 1)
13172 return FAIL;
13173 *immbits = immlo;
13174 return 0xe;
13175 }
13176
13177 return FAIL;
13178 }
13179
13180 /* Write immediate bits [7:0] to the following locations:
13181
13182 |28/24|23 19|18 16|15 4|3 0|
13183 | 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|
13184
13185 This function is used by VMOV/VMVN/VORR/VBIC. */
13186
13187 static void
13188 neon_write_immbits (unsigned immbits)
13189 {
13190 inst.instruction |= immbits & 0xf;
13191 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
13192 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
13193 }
13194
13195 /* Invert low-order SIZE bits of XHI:XLO. */
13196
13197 static void
13198 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
13199 {
13200 unsigned immlo = xlo ? *xlo : 0;
13201 unsigned immhi = xhi ? *xhi : 0;
13202
13203 switch (size)
13204 {
13205 case 8:
13206 immlo = (~immlo) & 0xff;
13207 break;
13208
13209 case 16:
13210 immlo = (~immlo) & 0xffff;
13211 break;
13212
13213 case 64:
13214 immhi = (~immhi) & 0xffffffff;
13215 /* fall through. */
13216
13217 case 32:
13218 immlo = (~immlo) & 0xffffffff;
13219 break;
13220
13221 default:
13222 abort ();
13223 }
13224
13225 if (xlo)
13226 *xlo = immlo;
13227
13228 if (xhi)
13229 *xhi = immhi;
13230 }
13231
13232 static void
13233 do_neon_logic (void)
13234 {
13235 if (inst.operands[2].present && inst.operands[2].isreg)
13236 {
13237 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13238 neon_check_type (3, rs, N_IGNORE_TYPE);
13239 /* U bit and size field were set as part of the bitmask. */
13240 NEON_ENCODE (INTEGER, inst);
13241 neon_three_same (neon_quad (rs), 0, -1);
13242 }
13243 else
13244 {
13245 const int three_ops_form = (inst.operands[2].present
13246 && !inst.operands[2].isreg);
13247 const int immoperand = (three_ops_form ? 2 : 1);
13248 enum neon_shape rs = (three_ops_form
13249 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
13250 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
13251 struct neon_type_el et = neon_check_type (2, rs,
13252 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
13253 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
13254 unsigned immbits;
13255 int cmode;
13256
13257 if (et.type == NT_invtype)
13258 return;
13259
13260 if (three_ops_form)
13261 constraint (inst.operands[0].reg != inst.operands[1].reg,
13262 _("first and second operands shall be the same register"));
13263
13264 NEON_ENCODE (IMMED, inst);
13265
13266 immbits = inst.operands[immoperand].imm;
13267 if (et.size == 64)
13268 {
13269 /* .i64 is a pseudo-op, so the immediate must be a repeating
13270 pattern. */
13271 if (immbits != (inst.operands[immoperand].regisimm ?
13272 inst.operands[immoperand].reg : 0))
13273 {
13274 /* Set immbits to an invalid constant. */
13275 immbits = 0xdeadbeef;
13276 }
13277 }
13278
13279 switch (opcode)
13280 {
13281 case N_MNEM_vbic:
13282 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13283 break;
13284
13285 case N_MNEM_vorr:
13286 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13287 break;
13288
13289 case N_MNEM_vand:
13290 /* Pseudo-instruction for VBIC. */
13291 neon_invert_size (&immbits, 0, et.size);
13292 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13293 break;
13294
13295 case N_MNEM_vorn:
13296 /* Pseudo-instruction for VORR. */
13297 neon_invert_size (&immbits, 0, et.size);
13298 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13299 break;
13300
13301 default:
13302 abort ();
13303 }
13304
13305 if (cmode == FAIL)
13306 return;
13307
13308 inst.instruction |= neon_quad (rs) << 6;
13309 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13310 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13311 inst.instruction |= cmode << 8;
13312 neon_write_immbits (immbits);
13313
13314 neon_dp_fixup (&inst);
13315 }
13316 }
13317
13318 static void
13319 do_neon_bitfield (void)
13320 {
13321 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13322 neon_check_type (3, rs, N_IGNORE_TYPE);
13323 neon_three_same (neon_quad (rs), 0, -1);
13324 }
13325
13326 static void
13327 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
13328 unsigned destbits)
13329 {
13330 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13331 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
13332 types | N_KEY);
13333 if (et.type == NT_float)
13334 {
13335 NEON_ENCODE (FLOAT, inst);
13336 neon_three_same (neon_quad (rs), 0, -1);
13337 }
13338 else
13339 {
13340 NEON_ENCODE (INTEGER, inst);
13341 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
13342 }
13343 }
13344
13345 static void
13346 do_neon_dyadic_if_su (void)
13347 {
13348 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
13349 }
13350
13351 static void
13352 do_neon_dyadic_if_su_d (void)
13353 {
13354 /* This version only allow D registers, but that constraint is enforced during
13355 operand parsing so we don't need to do anything extra here. */
13356 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
13357 }
13358
13359 static void
13360 do_neon_dyadic_if_i_d (void)
13361 {
13362 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13363 affected if we specify unsigned args. */
13364 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13365 }
13366
13367 enum vfp_or_neon_is_neon_bits
13368 {
13369 NEON_CHECK_CC = 1,
13370 NEON_CHECK_ARCH = 2
13371 };
13372
13373 /* Call this function if an instruction which may have belonged to the VFP or
13374 Neon instruction sets, but turned out to be a Neon instruction (due to the
13375 operand types involved, etc.). We have to check and/or fix-up a couple of
13376 things:
13377
13378 - Make sure the user hasn't attempted to make a Neon instruction
13379 conditional.
13380 - Alter the value in the condition code field if necessary.
13381 - Make sure that the arch supports Neon instructions.
13382
13383 Which of these operations take place depends on bits from enum
13384 vfp_or_neon_is_neon_bits.
13385
13386 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
13387 current instruction's condition is COND_ALWAYS, the condition field is
13388 changed to inst.uncond_value. This is necessary because instructions shared
13389 between VFP and Neon may be conditional for the VFP variants only, and the
13390 unconditional Neon version must have, e.g., 0xF in the condition field. */
13391
13392 static int
13393 vfp_or_neon_is_neon (unsigned check)
13394 {
13395 /* Conditions are always legal in Thumb mode (IT blocks). */
13396 if (!thumb_mode && (check & NEON_CHECK_CC))
13397 {
13398 if (inst.cond != COND_ALWAYS)
13399 {
13400 first_error (_(BAD_COND));
13401 return FAIL;
13402 }
13403 if (inst.uncond_value != -1)
13404 inst.instruction |= inst.uncond_value << 28;
13405 }
13406
13407 if ((check & NEON_CHECK_ARCH)
13408 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
13409 {
13410 first_error (_(BAD_FPU));
13411 return FAIL;
13412 }
13413
13414 return SUCCESS;
13415 }
13416
13417 static void
13418 do_neon_addsub_if_i (void)
13419 {
13420 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
13421 return;
13422
13423 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13424 return;
13425
13426 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13427 affected if we specify unsigned args. */
13428 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
13429 }
13430
13431 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
13432 result to be:
13433 V<op> A,B (A is operand 0, B is operand 2)
13434 to mean:
13435 V<op> A,B,A
13436 not:
13437 V<op> A,B,B
13438 so handle that case specially. */
13439
13440 static void
13441 neon_exchange_operands (void)
13442 {
13443 void *scratch = alloca (sizeof (inst.operands[0]));
13444 if (inst.operands[1].present)
13445 {
13446 /* Swap operands[1] and operands[2]. */
13447 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
13448 inst.operands[1] = inst.operands[2];
13449 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
13450 }
13451 else
13452 {
13453 inst.operands[1] = inst.operands[2];
13454 inst.operands[2] = inst.operands[0];
13455 }
13456 }
13457
13458 static void
13459 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
13460 {
13461 if (inst.operands[2].isreg)
13462 {
13463 if (invert)
13464 neon_exchange_operands ();
13465 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
13466 }
13467 else
13468 {
13469 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13470 struct neon_type_el et = neon_check_type (2, rs,
13471 N_EQK | N_SIZ, immtypes | N_KEY);
13472
13473 NEON_ENCODE (IMMED, inst);
13474 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13475 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13476 inst.instruction |= LOW4 (inst.operands[1].reg);
13477 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13478 inst.instruction |= neon_quad (rs) << 6;
13479 inst.instruction |= (et.type == NT_float) << 10;
13480 inst.instruction |= neon_logbits (et.size) << 18;
13481
13482 neon_dp_fixup (&inst);
13483 }
13484 }
13485
13486 static void
13487 do_neon_cmp (void)
13488 {
13489 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
13490 }
13491
13492 static void
13493 do_neon_cmp_inv (void)
13494 {
13495 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
13496 }
13497
13498 static void
13499 do_neon_ceq (void)
13500 {
13501 neon_compare (N_IF_32, N_IF_32, FALSE);
13502 }
13503
13504 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
13505 scalars, which are encoded in 5 bits, M : Rm.
13506 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
13507 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
13508 index in M. */
13509
13510 static unsigned
13511 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
13512 {
13513 unsigned regno = NEON_SCALAR_REG (scalar);
13514 unsigned elno = NEON_SCALAR_INDEX (scalar);
13515
13516 switch (elsize)
13517 {
13518 case 16:
13519 if (regno > 7 || elno > 3)
13520 goto bad_scalar;
13521 return regno | (elno << 3);
13522
13523 case 32:
13524 if (regno > 15 || elno > 1)
13525 goto bad_scalar;
13526 return regno | (elno << 4);
13527
13528 default:
13529 bad_scalar:
13530 first_error (_("scalar out of range for multiply instruction"));
13531 }
13532
13533 return 0;
13534 }
13535
13536 /* Encode multiply / multiply-accumulate scalar instructions. */
13537
13538 static void
13539 neon_mul_mac (struct neon_type_el et, int ubit)
13540 {
13541 unsigned scalar;
13542
13543 /* Give a more helpful error message if we have an invalid type. */
13544 if (et.type == NT_invtype)
13545 return;
13546
13547 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
13548 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13549 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13550 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13551 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13552 inst.instruction |= LOW4 (scalar);
13553 inst.instruction |= HI1 (scalar) << 5;
13554 inst.instruction |= (et.type == NT_float) << 8;
13555 inst.instruction |= neon_logbits (et.size) << 20;
13556 inst.instruction |= (ubit != 0) << 24;
13557
13558 neon_dp_fixup (&inst);
13559 }
13560
13561 static void
13562 do_neon_mac_maybe_scalar (void)
13563 {
13564 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
13565 return;
13566
13567 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13568 return;
13569
13570 if (inst.operands[2].isscalar)
13571 {
13572 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
13573 struct neon_type_el et = neon_check_type (3, rs,
13574 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
13575 NEON_ENCODE (SCALAR, inst);
13576 neon_mul_mac (et, neon_quad (rs));
13577 }
13578 else
13579 {
13580 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13581 affected if we specify unsigned args. */
13582 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13583 }
13584 }
13585
13586 static void
13587 do_neon_fmac (void)
13588 {
13589 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
13590 return;
13591
13592 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13593 return;
13594
13595 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13596 }
13597
13598 static void
13599 do_neon_tst (void)
13600 {
13601 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13602 struct neon_type_el et = neon_check_type (3, rs,
13603 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
13604 neon_three_same (neon_quad (rs), 0, et.size);
13605 }
13606
13607 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
13608 same types as the MAC equivalents. The polynomial type for this instruction
13609 is encoded the same as the integer type. */
13610
13611 static void
13612 do_neon_mul (void)
13613 {
13614 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
13615 return;
13616
13617 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13618 return;
13619
13620 if (inst.operands[2].isscalar)
13621 do_neon_mac_maybe_scalar ();
13622 else
13623 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
13624 }
13625
13626 static void
13627 do_neon_qdmulh (void)
13628 {
13629 if (inst.operands[2].isscalar)
13630 {
13631 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
13632 struct neon_type_el et = neon_check_type (3, rs,
13633 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
13634 NEON_ENCODE (SCALAR, inst);
13635 neon_mul_mac (et, neon_quad (rs));
13636 }
13637 else
13638 {
13639 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13640 struct neon_type_el et = neon_check_type (3, rs,
13641 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
13642 NEON_ENCODE (INTEGER, inst);
13643 /* The U bit (rounding) comes from bit mask. */
13644 neon_three_same (neon_quad (rs), 0, et.size);
13645 }
13646 }
13647
13648 static void
13649 do_neon_fcmp_absolute (void)
13650 {
13651 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13652 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
13653 /* Size field comes from bit mask. */
13654 neon_three_same (neon_quad (rs), 1, -1);
13655 }
13656
13657 static void
13658 do_neon_fcmp_absolute_inv (void)
13659 {
13660 neon_exchange_operands ();
13661 do_neon_fcmp_absolute ();
13662 }
13663
13664 static void
13665 do_neon_step (void)
13666 {
13667 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13668 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
13669 neon_three_same (neon_quad (rs), 0, -1);
13670 }
13671
13672 static void
13673 do_neon_abs_neg (void)
13674 {
13675 enum neon_shape rs;
13676 struct neon_type_el et;
13677
13678 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
13679 return;
13680
13681 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13682 return;
13683
13684 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13685 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
13686
13687 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13688 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13689 inst.instruction |= LOW4 (inst.operands[1].reg);
13690 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13691 inst.instruction |= neon_quad (rs) << 6;
13692 inst.instruction |= (et.type == NT_float) << 10;
13693 inst.instruction |= neon_logbits (et.size) << 18;
13694
13695 neon_dp_fixup (&inst);
13696 }
13697
13698 static void
13699 do_neon_sli (void)
13700 {
13701 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13702 struct neon_type_el et = neon_check_type (2, rs,
13703 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13704 int imm = inst.operands[2].imm;
13705 constraint (imm < 0 || (unsigned)imm >= et.size,
13706 _("immediate out of range for insert"));
13707 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
13708 }
13709
13710 static void
13711 do_neon_sri (void)
13712 {
13713 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13714 struct neon_type_el et = neon_check_type (2, rs,
13715 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13716 int imm = inst.operands[2].imm;
13717 constraint (imm < 1 || (unsigned)imm > et.size,
13718 _("immediate out of range for insert"));
13719 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
13720 }
13721
13722 static void
13723 do_neon_qshlu_imm (void)
13724 {
13725 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13726 struct neon_type_el et = neon_check_type (2, rs,
13727 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
13728 int imm = inst.operands[2].imm;
13729 constraint (imm < 0 || (unsigned)imm >= et.size,
13730 _("immediate out of range for shift"));
13731 /* Only encodes the 'U present' variant of the instruction.
13732 In this case, signed types have OP (bit 8) set to 0.
13733 Unsigned types have OP set to 1. */
13734 inst.instruction |= (et.type == NT_unsigned) << 8;
13735 /* The rest of the bits are the same as other immediate shifts. */
13736 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
13737 }
13738
13739 static void
13740 do_neon_qmovn (void)
13741 {
13742 struct neon_type_el et = neon_check_type (2, NS_DQ,
13743 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13744 /* Saturating move where operands can be signed or unsigned, and the
13745 destination has the same signedness. */
13746 NEON_ENCODE (INTEGER, inst);
13747 if (et.type == NT_unsigned)
13748 inst.instruction |= 0xc0;
13749 else
13750 inst.instruction |= 0x80;
13751 neon_two_same (0, 1, et.size / 2);
13752 }
13753
13754 static void
13755 do_neon_qmovun (void)
13756 {
13757 struct neon_type_el et = neon_check_type (2, NS_DQ,
13758 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13759 /* Saturating move with unsigned results. Operands must be signed. */
13760 NEON_ENCODE (INTEGER, inst);
13761 neon_two_same (0, 1, et.size / 2);
13762 }
13763
13764 static void
13765 do_neon_rshift_sat_narrow (void)
13766 {
13767 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13768 or unsigned. If operands are unsigned, results must also be unsigned. */
13769 struct neon_type_el et = neon_check_type (2, NS_DQI,
13770 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13771 int imm = inst.operands[2].imm;
13772 /* This gets the bounds check, size encoding and immediate bits calculation
13773 right. */
13774 et.size /= 2;
13775
13776 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
13777 VQMOVN.I<size> <Dd>, <Qm>. */
13778 if (imm == 0)
13779 {
13780 inst.operands[2].present = 0;
13781 inst.instruction = N_MNEM_vqmovn;
13782 do_neon_qmovn ();
13783 return;
13784 }
13785
13786 constraint (imm < 1 || (unsigned)imm > et.size,
13787 _("immediate out of range"));
13788 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
13789 }
13790
13791 static void
13792 do_neon_rshift_sat_narrow_u (void)
13793 {
13794 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13795 or unsigned. If operands are unsigned, results must also be unsigned. */
13796 struct neon_type_el et = neon_check_type (2, NS_DQI,
13797 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13798 int imm = inst.operands[2].imm;
13799 /* This gets the bounds check, size encoding and immediate bits calculation
13800 right. */
13801 et.size /= 2;
13802
13803 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
13804 VQMOVUN.I<size> <Dd>, <Qm>. */
13805 if (imm == 0)
13806 {
13807 inst.operands[2].present = 0;
13808 inst.instruction = N_MNEM_vqmovun;
13809 do_neon_qmovun ();
13810 return;
13811 }
13812
13813 constraint (imm < 1 || (unsigned)imm > et.size,
13814 _("immediate out of range"));
13815 /* FIXME: The manual is kind of unclear about what value U should have in
13816 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
13817 must be 1. */
13818 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
13819 }
13820
13821 static void
13822 do_neon_movn (void)
13823 {
13824 struct neon_type_el et = neon_check_type (2, NS_DQ,
13825 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
13826 NEON_ENCODE (INTEGER, inst);
13827 neon_two_same (0, 1, et.size / 2);
13828 }
13829
13830 static void
13831 do_neon_rshift_narrow (void)
13832 {
13833 struct neon_type_el et = neon_check_type (2, NS_DQI,
13834 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
13835 int imm = inst.operands[2].imm;
13836 /* This gets the bounds check, size encoding and immediate bits calculation
13837 right. */
13838 et.size /= 2;
13839
13840 /* If immediate is zero then we are a pseudo-instruction for
13841 VMOVN.I<size> <Dd>, <Qm> */
13842 if (imm == 0)
13843 {
13844 inst.operands[2].present = 0;
13845 inst.instruction = N_MNEM_vmovn;
13846 do_neon_movn ();
13847 return;
13848 }
13849
13850 constraint (imm < 1 || (unsigned)imm > et.size,
13851 _("immediate out of range for narrowing operation"));
13852 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
13853 }
13854
13855 static void
13856 do_neon_shll (void)
13857 {
13858 /* FIXME: Type checking when lengthening. */
13859 struct neon_type_el et = neon_check_type (2, NS_QDI,
13860 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
13861 unsigned imm = inst.operands[2].imm;
13862
13863 if (imm == et.size)
13864 {
13865 /* Maximum shift variant. */
13866 NEON_ENCODE (INTEGER, inst);
13867 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13868 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13869 inst.instruction |= LOW4 (inst.operands[1].reg);
13870 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13871 inst.instruction |= neon_logbits (et.size) << 18;
13872
13873 neon_dp_fixup (&inst);
13874 }
13875 else
13876 {
13877 /* A more-specific type check for non-max versions. */
13878 et = neon_check_type (2, NS_QDI,
13879 N_EQK | N_DBL, N_SU_32 | N_KEY);
13880 NEON_ENCODE (IMMED, inst);
13881 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
13882 }
13883 }
13884
13885 /* Check the various types for the VCVT instruction, and return which version
13886 the current instruction is. */
13887
13888 static int
13889 neon_cvt_flavour (enum neon_shape rs)
13890 {
13891 #define CVT_VAR(C,X,Y) \
13892 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
13893 if (et.type != NT_invtype) \
13894 { \
13895 inst.error = NULL; \
13896 return (C); \
13897 }
13898 struct neon_type_el et;
13899 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
13900 || rs == NS_FF) ? N_VFP : 0;
13901 /* The instruction versions which take an immediate take one register
13902 argument, which is extended to the width of the full register. Thus the
13903 "source" and "destination" registers must have the same width. Hack that
13904 here by making the size equal to the key (wider, in this case) operand. */
13905 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
13906
13907 CVT_VAR (0, N_S32, N_F32);
13908 CVT_VAR (1, N_U32, N_F32);
13909 CVT_VAR (2, N_F32, N_S32);
13910 CVT_VAR (3, N_F32, N_U32);
13911 /* Half-precision conversions. */
13912 CVT_VAR (4, N_F32, N_F16);
13913 CVT_VAR (5, N_F16, N_F32);
13914
13915 whole_reg = N_VFP;
13916
13917 /* VFP instructions. */
13918 CVT_VAR (6, N_F32, N_F64);
13919 CVT_VAR (7, N_F64, N_F32);
13920 CVT_VAR (8, N_S32, N_F64 | key);
13921 CVT_VAR (9, N_U32, N_F64 | key);
13922 CVT_VAR (10, N_F64 | key, N_S32);
13923 CVT_VAR (11, N_F64 | key, N_U32);
13924 /* VFP instructions with bitshift. */
13925 CVT_VAR (12, N_F32 | key, N_S16);
13926 CVT_VAR (13, N_F32 | key, N_U16);
13927 CVT_VAR (14, N_F64 | key, N_S16);
13928 CVT_VAR (15, N_F64 | key, N_U16);
13929 CVT_VAR (16, N_S16, N_F32 | key);
13930 CVT_VAR (17, N_U16, N_F32 | key);
13931 CVT_VAR (18, N_S16, N_F64 | key);
13932 CVT_VAR (19, N_U16, N_F64 | key);
13933
13934 return -1;
13935 #undef CVT_VAR
13936 }
13937
13938 /* Neon-syntax VFP conversions. */
13939
13940 static void
13941 do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
13942 {
13943 const char *opname = 0;
13944
13945 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
13946 {
13947 /* Conversions with immediate bitshift. */
13948 const char *enc[] =
13949 {
13950 "ftosls",
13951 "ftouls",
13952 "fsltos",
13953 "fultos",
13954 NULL,
13955 NULL,
13956 NULL,
13957 NULL,
13958 "ftosld",
13959 "ftould",
13960 "fsltod",
13961 "fultod",
13962 "fshtos",
13963 "fuhtos",
13964 "fshtod",
13965 "fuhtod",
13966 "ftoshs",
13967 "ftouhs",
13968 "ftoshd",
13969 "ftouhd"
13970 };
13971
13972 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13973 {
13974 opname = enc[flavour];
13975 constraint (inst.operands[0].reg != inst.operands[1].reg,
13976 _("operands 0 and 1 must be the same register"));
13977 inst.operands[1] = inst.operands[2];
13978 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
13979 }
13980 }
13981 else
13982 {
13983 /* Conversions without bitshift. */
13984 const char *enc[] =
13985 {
13986 "ftosis",
13987 "ftouis",
13988 "fsitos",
13989 "fuitos",
13990 "NULL",
13991 "NULL",
13992 "fcvtsd",
13993 "fcvtds",
13994 "ftosid",
13995 "ftouid",
13996 "fsitod",
13997 "fuitod"
13998 };
13999
14000 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
14001 opname = enc[flavour];
14002 }
14003
14004 if (opname)
14005 do_vfp_nsyn_opcode (opname);
14006 }
14007
14008 static void
14009 do_vfp_nsyn_cvtz (void)
14010 {
14011 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
14012 int flavour = neon_cvt_flavour (rs);
14013 const char *enc[] =
14014 {
14015 "ftosizs",
14016 "ftouizs",
14017 NULL,
14018 NULL,
14019 NULL,
14020 NULL,
14021 NULL,
14022 NULL,
14023 "ftosizd",
14024 "ftouizd"
14025 };
14026
14027 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
14028 do_vfp_nsyn_opcode (enc[flavour]);
14029 }
14030
14031 static void
14032 do_neon_cvt_1 (bfd_boolean round_to_zero ATTRIBUTE_UNUSED)
14033 {
14034 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
14035 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
14036 int flavour = neon_cvt_flavour (rs);
14037
14038 /* PR11109: Handle round-to-zero for VCVT conversions. */
14039 if (round_to_zero
14040 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
14041 && (flavour == 0 || flavour == 1 || flavour == 8 || flavour == 9)
14042 && (rs == NS_FD || rs == NS_FF))
14043 {
14044 do_vfp_nsyn_cvtz ();
14045 return;
14046 }
14047
14048 /* VFP rather than Neon conversions. */
14049 if (flavour >= 6)
14050 {
14051 do_vfp_nsyn_cvt (rs, flavour);
14052 return;
14053 }
14054
14055 switch (rs)
14056 {
14057 case NS_DDI:
14058 case NS_QQI:
14059 {
14060 unsigned immbits;
14061 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
14062
14063 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14064 return;
14065
14066 /* Fixed-point conversion with #0 immediate is encoded as an
14067 integer conversion. */
14068 if (inst.operands[2].present && inst.operands[2].imm == 0)
14069 goto int_encode;
14070 immbits = 32 - inst.operands[2].imm;
14071 NEON_ENCODE (IMMED, inst);
14072 if (flavour != -1)
14073 inst.instruction |= enctab[flavour];
14074 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14075 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14076 inst.instruction |= LOW4 (inst.operands[1].reg);
14077 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14078 inst.instruction |= neon_quad (rs) << 6;
14079 inst.instruction |= 1 << 21;
14080 inst.instruction |= immbits << 16;
14081
14082 neon_dp_fixup (&inst);
14083 }
14084 break;
14085
14086 case NS_DD:
14087 case NS_QQ:
14088 int_encode:
14089 {
14090 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
14091
14092 NEON_ENCODE (INTEGER, inst);
14093
14094 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14095 return;
14096
14097 if (flavour != -1)
14098 inst.instruction |= enctab[flavour];
14099
14100 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14101 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14102 inst.instruction |= LOW4 (inst.operands[1].reg);
14103 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14104 inst.instruction |= neon_quad (rs) << 6;
14105 inst.instruction |= 2 << 18;
14106
14107 neon_dp_fixup (&inst);
14108 }
14109 break;
14110
14111 /* Half-precision conversions for Advanced SIMD -- neon. */
14112 case NS_QD:
14113 case NS_DQ:
14114
14115 if ((rs == NS_DQ)
14116 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
14117 {
14118 as_bad (_("operand size must match register width"));
14119 break;
14120 }
14121
14122 if ((rs == NS_QD)
14123 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
14124 {
14125 as_bad (_("operand size must match register width"));
14126 break;
14127 }
14128
14129 if (rs == NS_DQ)
14130 inst.instruction = 0x3b60600;
14131 else
14132 inst.instruction = 0x3b60700;
14133
14134 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14135 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14136 inst.instruction |= LOW4 (inst.operands[1].reg);
14137 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14138 neon_dp_fixup (&inst);
14139 break;
14140
14141 default:
14142 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
14143 do_vfp_nsyn_cvt (rs, flavour);
14144 }
14145 }
14146
14147 static void
14148 do_neon_cvtr (void)
14149 {
14150 do_neon_cvt_1 (FALSE);
14151 }
14152
14153 static void
14154 do_neon_cvt (void)
14155 {
14156 do_neon_cvt_1 (TRUE);
14157 }
14158
14159 static void
14160 do_neon_cvtb (void)
14161 {
14162 inst.instruction = 0xeb20a40;
14163
14164 /* The sizes are attached to the mnemonic. */
14165 if (inst.vectype.el[0].type != NT_invtype
14166 && inst.vectype.el[0].size == 16)
14167 inst.instruction |= 0x00010000;
14168
14169 /* Programmer's syntax: the sizes are attached to the operands. */
14170 else if (inst.operands[0].vectype.type != NT_invtype
14171 && inst.operands[0].vectype.size == 16)
14172 inst.instruction |= 0x00010000;
14173
14174 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
14175 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
14176 do_vfp_cond_or_thumb ();
14177 }
14178
14179
14180 static void
14181 do_neon_cvtt (void)
14182 {
14183 do_neon_cvtb ();
14184 inst.instruction |= 0x80;
14185 }
14186
14187 static void
14188 neon_move_immediate (void)
14189 {
14190 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
14191 struct neon_type_el et = neon_check_type (2, rs,
14192 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
14193 unsigned immlo, immhi = 0, immbits;
14194 int op, cmode, float_p;
14195
14196 constraint (et.type == NT_invtype,
14197 _("operand size must be specified for immediate VMOV"));
14198
14199 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
14200 op = (inst.instruction & (1 << 5)) != 0;
14201
14202 immlo = inst.operands[1].imm;
14203 if (inst.operands[1].regisimm)
14204 immhi = inst.operands[1].reg;
14205
14206 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
14207 _("immediate has bits set outside the operand size"));
14208
14209 float_p = inst.operands[1].immisfloat;
14210
14211 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
14212 et.size, et.type)) == FAIL)
14213 {
14214 /* Invert relevant bits only. */
14215 neon_invert_size (&immlo, &immhi, et.size);
14216 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
14217 with one or the other; those cases are caught by
14218 neon_cmode_for_move_imm. */
14219 op = !op;
14220 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
14221 &op, et.size, et.type)) == FAIL)
14222 {
14223 first_error (_("immediate out of range"));
14224 return;
14225 }
14226 }
14227
14228 inst.instruction &= ~(1 << 5);
14229 inst.instruction |= op << 5;
14230
14231 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14232 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14233 inst.instruction |= neon_quad (rs) << 6;
14234 inst.instruction |= cmode << 8;
14235
14236 neon_write_immbits (immbits);
14237 }
14238
14239 static void
14240 do_neon_mvn (void)
14241 {
14242 if (inst.operands[1].isreg)
14243 {
14244 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14245
14246 NEON_ENCODE (INTEGER, inst);
14247 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14248 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14249 inst.instruction |= LOW4 (inst.operands[1].reg);
14250 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14251 inst.instruction |= neon_quad (rs) << 6;
14252 }
14253 else
14254 {
14255 NEON_ENCODE (IMMED, inst);
14256 neon_move_immediate ();
14257 }
14258
14259 neon_dp_fixup (&inst);
14260 }
14261
14262 /* Encode instructions of form:
14263
14264 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14265 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
14266
14267 static void
14268 neon_mixed_length (struct neon_type_el et, unsigned size)
14269 {
14270 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14271 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14272 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14273 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14274 inst.instruction |= LOW4 (inst.operands[2].reg);
14275 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14276 inst.instruction |= (et.type == NT_unsigned) << 24;
14277 inst.instruction |= neon_logbits (size) << 20;
14278
14279 neon_dp_fixup (&inst);
14280 }
14281
14282 static void
14283 do_neon_dyadic_long (void)
14284 {
14285 /* FIXME: Type checking for lengthening op. */
14286 struct neon_type_el et = neon_check_type (3, NS_QDD,
14287 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
14288 neon_mixed_length (et, et.size);
14289 }
14290
14291 static void
14292 do_neon_abal (void)
14293 {
14294 struct neon_type_el et = neon_check_type (3, NS_QDD,
14295 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
14296 neon_mixed_length (et, et.size);
14297 }
14298
14299 static void
14300 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
14301 {
14302 if (inst.operands[2].isscalar)
14303 {
14304 struct neon_type_el et = neon_check_type (3, NS_QDS,
14305 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
14306 NEON_ENCODE (SCALAR, inst);
14307 neon_mul_mac (et, et.type == NT_unsigned);
14308 }
14309 else
14310 {
14311 struct neon_type_el et = neon_check_type (3, NS_QDD,
14312 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
14313 NEON_ENCODE (INTEGER, inst);
14314 neon_mixed_length (et, et.size);
14315 }
14316 }
14317
14318 static void
14319 do_neon_mac_maybe_scalar_long (void)
14320 {
14321 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
14322 }
14323
14324 static void
14325 do_neon_dyadic_wide (void)
14326 {
14327 struct neon_type_el et = neon_check_type (3, NS_QQD,
14328 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
14329 neon_mixed_length (et, et.size);
14330 }
14331
14332 static void
14333 do_neon_dyadic_narrow (void)
14334 {
14335 struct neon_type_el et = neon_check_type (3, NS_QDD,
14336 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
14337 /* Operand sign is unimportant, and the U bit is part of the opcode,
14338 so force the operand type to integer. */
14339 et.type = NT_integer;
14340 neon_mixed_length (et, et.size / 2);
14341 }
14342
14343 static void
14344 do_neon_mul_sat_scalar_long (void)
14345 {
14346 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
14347 }
14348
14349 static void
14350 do_neon_vmull (void)
14351 {
14352 if (inst.operands[2].isscalar)
14353 do_neon_mac_maybe_scalar_long ();
14354 else
14355 {
14356 struct neon_type_el et = neon_check_type (3, NS_QDD,
14357 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
14358 if (et.type == NT_poly)
14359 NEON_ENCODE (POLY, inst);
14360 else
14361 NEON_ENCODE (INTEGER, inst);
14362 /* For polynomial encoding, size field must be 0b00 and the U bit must be
14363 zero. Should be OK as-is. */
14364 neon_mixed_length (et, et.size);
14365 }
14366 }
14367
14368 static void
14369 do_neon_ext (void)
14370 {
14371 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
14372 struct neon_type_el et = neon_check_type (3, rs,
14373 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14374 unsigned imm = (inst.operands[3].imm * et.size) / 8;
14375
14376 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
14377 _("shift out of range"));
14378 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14379 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14380 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14381 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14382 inst.instruction |= LOW4 (inst.operands[2].reg);
14383 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14384 inst.instruction |= neon_quad (rs) << 6;
14385 inst.instruction |= imm << 8;
14386
14387 neon_dp_fixup (&inst);
14388 }
14389
14390 static void
14391 do_neon_rev (void)
14392 {
14393 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14394 struct neon_type_el et = neon_check_type (2, rs,
14395 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14396 unsigned op = (inst.instruction >> 7) & 3;
14397 /* N (width of reversed regions) is encoded as part of the bitmask. We
14398 extract it here to check the elements to be reversed are smaller.
14399 Otherwise we'd get a reserved instruction. */
14400 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
14401 gas_assert (elsize != 0);
14402 constraint (et.size >= elsize,
14403 _("elements must be smaller than reversal region"));
14404 neon_two_same (neon_quad (rs), 1, et.size);
14405 }
14406
14407 static void
14408 do_neon_dup (void)
14409 {
14410 if (inst.operands[1].isscalar)
14411 {
14412 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
14413 struct neon_type_el et = neon_check_type (2, rs,
14414 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14415 unsigned sizebits = et.size >> 3;
14416 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
14417 int logsize = neon_logbits (et.size);
14418 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
14419
14420 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
14421 return;
14422
14423 NEON_ENCODE (SCALAR, inst);
14424 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14425 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14426 inst.instruction |= LOW4 (dm);
14427 inst.instruction |= HI1 (dm) << 5;
14428 inst.instruction |= neon_quad (rs) << 6;
14429 inst.instruction |= x << 17;
14430 inst.instruction |= sizebits << 16;
14431
14432 neon_dp_fixup (&inst);
14433 }
14434 else
14435 {
14436 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
14437 struct neon_type_el et = neon_check_type (2, rs,
14438 N_8 | N_16 | N_32 | N_KEY, N_EQK);
14439 /* Duplicate ARM register to lanes of vector. */
14440 NEON_ENCODE (ARMREG, inst);
14441 switch (et.size)
14442 {
14443 case 8: inst.instruction |= 0x400000; break;
14444 case 16: inst.instruction |= 0x000020; break;
14445 case 32: inst.instruction |= 0x000000; break;
14446 default: break;
14447 }
14448 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14449 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
14450 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
14451 inst.instruction |= neon_quad (rs) << 21;
14452 /* The encoding for this instruction is identical for the ARM and Thumb
14453 variants, except for the condition field. */
14454 do_vfp_cond_or_thumb ();
14455 }
14456 }
14457
14458 /* VMOV has particularly many variations. It can be one of:
14459 0. VMOV<c><q> <Qd>, <Qm>
14460 1. VMOV<c><q> <Dd>, <Dm>
14461 (Register operations, which are VORR with Rm = Rn.)
14462 2. VMOV<c><q>.<dt> <Qd>, #<imm>
14463 3. VMOV<c><q>.<dt> <Dd>, #<imm>
14464 (Immediate loads.)
14465 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
14466 (ARM register to scalar.)
14467 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
14468 (Two ARM registers to vector.)
14469 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
14470 (Scalar to ARM register.)
14471 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
14472 (Vector to two ARM registers.)
14473 8. VMOV.F32 <Sd>, <Sm>
14474 9. VMOV.F64 <Dd>, <Dm>
14475 (VFP register moves.)
14476 10. VMOV.F32 <Sd>, #imm
14477 11. VMOV.F64 <Dd>, #imm
14478 (VFP float immediate load.)
14479 12. VMOV <Rd>, <Sm>
14480 (VFP single to ARM reg.)
14481 13. VMOV <Sd>, <Rm>
14482 (ARM reg to VFP single.)
14483 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
14484 (Two ARM regs to two VFP singles.)
14485 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
14486 (Two VFP singles to two ARM regs.)
14487
14488 These cases can be disambiguated using neon_select_shape, except cases 1/9
14489 and 3/11 which depend on the operand type too.
14490
14491 All the encoded bits are hardcoded by this function.
14492
14493 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
14494 Cases 5, 7 may be used with VFPv2 and above.
14495
14496 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
14497 can specify a type where it doesn't make sense to, and is ignored). */
14498
14499 static void
14500 do_neon_mov (void)
14501 {
14502 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
14503 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
14504 NS_NULL);
14505 struct neon_type_el et;
14506 const char *ldconst = 0;
14507
14508 switch (rs)
14509 {
14510 case NS_DD: /* case 1/9. */
14511 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14512 /* It is not an error here if no type is given. */
14513 inst.error = NULL;
14514 if (et.type == NT_float && et.size == 64)
14515 {
14516 do_vfp_nsyn_opcode ("fcpyd");
14517 break;
14518 }
14519 /* fall through. */
14520
14521 case NS_QQ: /* case 0/1. */
14522 {
14523 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14524 return;
14525 /* The architecture manual I have doesn't explicitly state which
14526 value the U bit should have for register->register moves, but
14527 the equivalent VORR instruction has U = 0, so do that. */
14528 inst.instruction = 0x0200110;
14529 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14530 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14531 inst.instruction |= LOW4 (inst.operands[1].reg);
14532 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14533 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14534 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14535 inst.instruction |= neon_quad (rs) << 6;
14536
14537 neon_dp_fixup (&inst);
14538 }
14539 break;
14540
14541 case NS_DI: /* case 3/11. */
14542 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14543 inst.error = NULL;
14544 if (et.type == NT_float && et.size == 64)
14545 {
14546 /* case 11 (fconstd). */
14547 ldconst = "fconstd";
14548 goto encode_fconstd;
14549 }
14550 /* fall through. */
14551
14552 case NS_QI: /* case 2/3. */
14553 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14554 return;
14555 inst.instruction = 0x0800010;
14556 neon_move_immediate ();
14557 neon_dp_fixup (&inst);
14558 break;
14559
14560 case NS_SR: /* case 4. */
14561 {
14562 unsigned bcdebits = 0;
14563 int logsize;
14564 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
14565 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
14566
14567 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
14568 logsize = neon_logbits (et.size);
14569
14570 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14571 _(BAD_FPU));
14572 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14573 && et.size != 32, _(BAD_FPU));
14574 constraint (et.type == NT_invtype, _("bad type for scalar"));
14575 constraint (x >= 64 / et.size, _("scalar index out of range"));
14576
14577 switch (et.size)
14578 {
14579 case 8: bcdebits = 0x8; break;
14580 case 16: bcdebits = 0x1; break;
14581 case 32: bcdebits = 0x0; break;
14582 default: ;
14583 }
14584
14585 bcdebits |= x << logsize;
14586
14587 inst.instruction = 0xe000b10;
14588 do_vfp_cond_or_thumb ();
14589 inst.instruction |= LOW4 (dn) << 16;
14590 inst.instruction |= HI1 (dn) << 7;
14591 inst.instruction |= inst.operands[1].reg << 12;
14592 inst.instruction |= (bcdebits & 3) << 5;
14593 inst.instruction |= (bcdebits >> 2) << 21;
14594 }
14595 break;
14596
14597 case NS_DRR: /* case 5 (fmdrr). */
14598 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
14599 _(BAD_FPU));
14600
14601 inst.instruction = 0xc400b10;
14602 do_vfp_cond_or_thumb ();
14603 inst.instruction |= LOW4 (inst.operands[0].reg);
14604 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
14605 inst.instruction |= inst.operands[1].reg << 12;
14606 inst.instruction |= inst.operands[2].reg << 16;
14607 break;
14608
14609 case NS_RS: /* case 6. */
14610 {
14611 unsigned logsize;
14612 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
14613 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
14614 unsigned abcdebits = 0;
14615
14616 et = neon_check_type (2, NS_NULL,
14617 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
14618 logsize = neon_logbits (et.size);
14619
14620 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14621 _(BAD_FPU));
14622 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14623 && et.size != 32, _(BAD_FPU));
14624 constraint (et.type == NT_invtype, _("bad type for scalar"));
14625 constraint (x >= 64 / et.size, _("scalar index out of range"));
14626
14627 switch (et.size)
14628 {
14629 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
14630 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
14631 case 32: abcdebits = 0x00; break;
14632 default: ;
14633 }
14634
14635 abcdebits |= x << logsize;
14636 inst.instruction = 0xe100b10;
14637 do_vfp_cond_or_thumb ();
14638 inst.instruction |= LOW4 (dn) << 16;
14639 inst.instruction |= HI1 (dn) << 7;
14640 inst.instruction |= inst.operands[0].reg << 12;
14641 inst.instruction |= (abcdebits & 3) << 5;
14642 inst.instruction |= (abcdebits >> 2) << 21;
14643 }
14644 break;
14645
14646 case NS_RRD: /* case 7 (fmrrd). */
14647 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
14648 _(BAD_FPU));
14649
14650 inst.instruction = 0xc500b10;
14651 do_vfp_cond_or_thumb ();
14652 inst.instruction |= inst.operands[0].reg << 12;
14653 inst.instruction |= inst.operands[1].reg << 16;
14654 inst.instruction |= LOW4 (inst.operands[2].reg);
14655 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14656 break;
14657
14658 case NS_FF: /* case 8 (fcpys). */
14659 do_vfp_nsyn_opcode ("fcpys");
14660 break;
14661
14662 case NS_FI: /* case 10 (fconsts). */
14663 ldconst = "fconsts";
14664 encode_fconstd:
14665 if (is_quarter_float (inst.operands[1].imm))
14666 {
14667 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
14668 do_vfp_nsyn_opcode (ldconst);
14669 }
14670 else
14671 first_error (_("immediate out of range"));
14672 break;
14673
14674 case NS_RF: /* case 12 (fmrs). */
14675 do_vfp_nsyn_opcode ("fmrs");
14676 break;
14677
14678 case NS_FR: /* case 13 (fmsr). */
14679 do_vfp_nsyn_opcode ("fmsr");
14680 break;
14681
14682 /* The encoders for the fmrrs and fmsrr instructions expect three operands
14683 (one of which is a list), but we have parsed four. Do some fiddling to
14684 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
14685 expect. */
14686 case NS_RRFF: /* case 14 (fmrrs). */
14687 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
14688 _("VFP registers must be adjacent"));
14689 inst.operands[2].imm = 2;
14690 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14691 do_vfp_nsyn_opcode ("fmrrs");
14692 break;
14693
14694 case NS_FFRR: /* case 15 (fmsrr). */
14695 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
14696 _("VFP registers must be adjacent"));
14697 inst.operands[1] = inst.operands[2];
14698 inst.operands[2] = inst.operands[3];
14699 inst.operands[0].imm = 2;
14700 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14701 do_vfp_nsyn_opcode ("fmsrr");
14702 break;
14703
14704 default:
14705 abort ();
14706 }
14707 }
14708
14709 static void
14710 do_neon_rshift_round_imm (void)
14711 {
14712 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14713 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
14714 int imm = inst.operands[2].imm;
14715
14716 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
14717 if (imm == 0)
14718 {
14719 inst.operands[2].present = 0;
14720 do_neon_mov ();
14721 return;
14722 }
14723
14724 constraint (imm < 1 || (unsigned)imm > et.size,
14725 _("immediate out of range for shift"));
14726 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
14727 et.size - imm);
14728 }
14729
14730 static void
14731 do_neon_movl (void)
14732 {
14733 struct neon_type_el et = neon_check_type (2, NS_QD,
14734 N_EQK | N_DBL, N_SU_32 | N_KEY);
14735 unsigned sizebits = et.size >> 3;
14736 inst.instruction |= sizebits << 19;
14737 neon_two_same (0, et.type == NT_unsigned, -1);
14738 }
14739
14740 static void
14741 do_neon_trn (void)
14742 {
14743 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14744 struct neon_type_el et = neon_check_type (2, rs,
14745 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14746 NEON_ENCODE (INTEGER, inst);
14747 neon_two_same (neon_quad (rs), 1, et.size);
14748 }
14749
14750 static void
14751 do_neon_zip_uzp (void)
14752 {
14753 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14754 struct neon_type_el et = neon_check_type (2, rs,
14755 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14756 if (rs == NS_DD && et.size == 32)
14757 {
14758 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
14759 inst.instruction = N_MNEM_vtrn;
14760 do_neon_trn ();
14761 return;
14762 }
14763 neon_two_same (neon_quad (rs), 1, et.size);
14764 }
14765
14766 static void
14767 do_neon_sat_abs_neg (void)
14768 {
14769 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14770 struct neon_type_el et = neon_check_type (2, rs,
14771 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
14772 neon_two_same (neon_quad (rs), 1, et.size);
14773 }
14774
14775 static void
14776 do_neon_pair_long (void)
14777 {
14778 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14779 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
14780 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
14781 inst.instruction |= (et.type == NT_unsigned) << 7;
14782 neon_two_same (neon_quad (rs), 1, et.size);
14783 }
14784
14785 static void
14786 do_neon_recip_est (void)
14787 {
14788 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14789 struct neon_type_el et = neon_check_type (2, rs,
14790 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
14791 inst.instruction |= (et.type == NT_float) << 8;
14792 neon_two_same (neon_quad (rs), 1, et.size);
14793 }
14794
14795 static void
14796 do_neon_cls (void)
14797 {
14798 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14799 struct neon_type_el et = neon_check_type (2, rs,
14800 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
14801 neon_two_same (neon_quad (rs), 1, et.size);
14802 }
14803
14804 static void
14805 do_neon_clz (void)
14806 {
14807 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14808 struct neon_type_el et = neon_check_type (2, rs,
14809 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
14810 neon_two_same (neon_quad (rs), 1, et.size);
14811 }
14812
14813 static void
14814 do_neon_cnt (void)
14815 {
14816 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14817 struct neon_type_el et = neon_check_type (2, rs,
14818 N_EQK | N_INT, N_8 | N_KEY);
14819 neon_two_same (neon_quad (rs), 1, et.size);
14820 }
14821
14822 static void
14823 do_neon_swp (void)
14824 {
14825 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14826 neon_two_same (neon_quad (rs), 1, -1);
14827 }
14828
14829 static void
14830 do_neon_tbl_tbx (void)
14831 {
14832 unsigned listlenbits;
14833 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
14834
14835 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
14836 {
14837 first_error (_("bad list length for table lookup"));
14838 return;
14839 }
14840
14841 listlenbits = inst.operands[1].imm - 1;
14842 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14843 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14844 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14845 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14846 inst.instruction |= LOW4 (inst.operands[2].reg);
14847 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14848 inst.instruction |= listlenbits << 8;
14849
14850 neon_dp_fixup (&inst);
14851 }
14852
14853 static void
14854 do_neon_ldm_stm (void)
14855 {
14856 /* P, U and L bits are part of bitmask. */
14857 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
14858 unsigned offsetbits = inst.operands[1].imm * 2;
14859
14860 if (inst.operands[1].issingle)
14861 {
14862 do_vfp_nsyn_ldm_stm (is_dbmode);
14863 return;
14864 }
14865
14866 constraint (is_dbmode && !inst.operands[0].writeback,
14867 _("writeback (!) must be used for VLDMDB and VSTMDB"));
14868
14869 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14870 _("register list must contain at least 1 and at most 16 "
14871 "registers"));
14872
14873 inst.instruction |= inst.operands[0].reg << 16;
14874 inst.instruction |= inst.operands[0].writeback << 21;
14875 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14876 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
14877
14878 inst.instruction |= offsetbits;
14879
14880 do_vfp_cond_or_thumb ();
14881 }
14882
14883 static void
14884 do_neon_ldr_str (void)
14885 {
14886 int is_ldr = (inst.instruction & (1 << 20)) != 0;
14887
14888 if (inst.operands[0].issingle)
14889 {
14890 if (is_ldr)
14891 do_vfp_nsyn_opcode ("flds");
14892 else
14893 do_vfp_nsyn_opcode ("fsts");
14894 }
14895 else
14896 {
14897 if (is_ldr)
14898 do_vfp_nsyn_opcode ("fldd");
14899 else
14900 do_vfp_nsyn_opcode ("fstd");
14901 }
14902 }
14903
14904 /* "interleave" version also handles non-interleaving register VLD1/VST1
14905 instructions. */
14906
14907 static void
14908 do_neon_ld_st_interleave (void)
14909 {
14910 struct neon_type_el et = neon_check_type (1, NS_NULL,
14911 N_8 | N_16 | N_32 | N_64);
14912 unsigned alignbits = 0;
14913 unsigned idx;
14914 /* The bits in this table go:
14915 0: register stride of one (0) or two (1)
14916 1,2: register list length, minus one (1, 2, 3, 4).
14917 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
14918 We use -1 for invalid entries. */
14919 const int typetable[] =
14920 {
14921 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
14922 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
14923 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
14924 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
14925 };
14926 int typebits;
14927
14928 if (et.type == NT_invtype)
14929 return;
14930
14931 if (inst.operands[1].immisalign)
14932 switch (inst.operands[1].imm >> 8)
14933 {
14934 case 64: alignbits = 1; break;
14935 case 128:
14936 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
14937 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
14938 goto bad_alignment;
14939 alignbits = 2;
14940 break;
14941 case 256:
14942 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
14943 goto bad_alignment;
14944 alignbits = 3;
14945 break;
14946 default:
14947 bad_alignment:
14948 first_error (_("bad alignment"));
14949 return;
14950 }
14951
14952 inst.instruction |= alignbits << 4;
14953 inst.instruction |= neon_logbits (et.size) << 6;
14954
14955 /* Bits [4:6] of the immediate in a list specifier encode register stride
14956 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
14957 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
14958 up the right value for "type" in a table based on this value and the given
14959 list style, then stick it back. */
14960 idx = ((inst.operands[0].imm >> 4) & 7)
14961 | (((inst.instruction >> 8) & 3) << 3);
14962
14963 typebits = typetable[idx];
14964
14965 constraint (typebits == -1, _("bad list type for instruction"));
14966
14967 inst.instruction &= ~0xf00;
14968 inst.instruction |= typebits << 8;
14969 }
14970
14971 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
14972 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
14973 otherwise. The variable arguments are a list of pairs of legal (size, align)
14974 values, terminated with -1. */
14975
14976 static int
14977 neon_alignment_bit (int size, int align, int *do_align, ...)
14978 {
14979 va_list ap;
14980 int result = FAIL, thissize, thisalign;
14981
14982 if (!inst.operands[1].immisalign)
14983 {
14984 *do_align = 0;
14985 return SUCCESS;
14986 }
14987
14988 va_start (ap, do_align);
14989
14990 do
14991 {
14992 thissize = va_arg (ap, int);
14993 if (thissize == -1)
14994 break;
14995 thisalign = va_arg (ap, int);
14996
14997 if (size == thissize && align == thisalign)
14998 result = SUCCESS;
14999 }
15000 while (result != SUCCESS);
15001
15002 va_end (ap);
15003
15004 if (result == SUCCESS)
15005 *do_align = 1;
15006 else
15007 first_error (_("unsupported alignment for instruction"));
15008
15009 return result;
15010 }
15011
15012 static void
15013 do_neon_ld_st_lane (void)
15014 {
15015 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
15016 int align_good, do_align = 0;
15017 int logsize = neon_logbits (et.size);
15018 int align = inst.operands[1].imm >> 8;
15019 int n = (inst.instruction >> 8) & 3;
15020 int max_el = 64 / et.size;
15021
15022 if (et.type == NT_invtype)
15023 return;
15024
15025 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
15026 _("bad list length"));
15027 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
15028 _("scalar index out of range"));
15029 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
15030 && et.size == 8,
15031 _("stride of 2 unavailable when element size is 8"));
15032
15033 switch (n)
15034 {
15035 case 0: /* VLD1 / VST1. */
15036 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
15037 32, 32, -1);
15038 if (align_good == FAIL)
15039 return;
15040 if (do_align)
15041 {
15042 unsigned alignbits = 0;
15043 switch (et.size)
15044 {
15045 case 16: alignbits = 0x1; break;
15046 case 32: alignbits = 0x3; break;
15047 default: ;
15048 }
15049 inst.instruction |= alignbits << 4;
15050 }
15051 break;
15052
15053 case 1: /* VLD2 / VST2. */
15054 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
15055 32, 64, -1);
15056 if (align_good == FAIL)
15057 return;
15058 if (do_align)
15059 inst.instruction |= 1 << 4;
15060 break;
15061
15062 case 2: /* VLD3 / VST3. */
15063 constraint (inst.operands[1].immisalign,
15064 _("can't use alignment with this instruction"));
15065 break;
15066
15067 case 3: /* VLD4 / VST4. */
15068 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15069 16, 64, 32, 64, 32, 128, -1);
15070 if (align_good == FAIL)
15071 return;
15072 if (do_align)
15073 {
15074 unsigned alignbits = 0;
15075 switch (et.size)
15076 {
15077 case 8: alignbits = 0x1; break;
15078 case 16: alignbits = 0x1; break;
15079 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
15080 default: ;
15081 }
15082 inst.instruction |= alignbits << 4;
15083 }
15084 break;
15085
15086 default: ;
15087 }
15088
15089 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
15090 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15091 inst.instruction |= 1 << (4 + logsize);
15092
15093 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
15094 inst.instruction |= logsize << 10;
15095 }
15096
15097 /* Encode single n-element structure to all lanes VLD<n> instructions. */
15098
15099 static void
15100 do_neon_ld_dup (void)
15101 {
15102 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
15103 int align_good, do_align = 0;
15104
15105 if (et.type == NT_invtype)
15106 return;
15107
15108 switch ((inst.instruction >> 8) & 3)
15109 {
15110 case 0: /* VLD1. */
15111 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
15112 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15113 &do_align, 16, 16, 32, 32, -1);
15114 if (align_good == FAIL)
15115 return;
15116 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
15117 {
15118 case 1: break;
15119 case 2: inst.instruction |= 1 << 5; break;
15120 default: first_error (_("bad list length")); return;
15121 }
15122 inst.instruction |= neon_logbits (et.size) << 6;
15123 break;
15124
15125 case 1: /* VLD2. */
15126 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15127 &do_align, 8, 16, 16, 32, 32, 64, -1);
15128 if (align_good == FAIL)
15129 return;
15130 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
15131 _("bad list length"));
15132 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15133 inst.instruction |= 1 << 5;
15134 inst.instruction |= neon_logbits (et.size) << 6;
15135 break;
15136
15137 case 2: /* VLD3. */
15138 constraint (inst.operands[1].immisalign,
15139 _("can't use alignment with this instruction"));
15140 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
15141 _("bad list length"));
15142 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15143 inst.instruction |= 1 << 5;
15144 inst.instruction |= neon_logbits (et.size) << 6;
15145 break;
15146
15147 case 3: /* VLD4. */
15148 {
15149 int align = inst.operands[1].imm >> 8;
15150 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15151 16, 64, 32, 64, 32, 128, -1);
15152 if (align_good == FAIL)
15153 return;
15154 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
15155 _("bad list length"));
15156 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15157 inst.instruction |= 1 << 5;
15158 if (et.size == 32 && align == 128)
15159 inst.instruction |= 0x3 << 6;
15160 else
15161 inst.instruction |= neon_logbits (et.size) << 6;
15162 }
15163 break;
15164
15165 default: ;
15166 }
15167
15168 inst.instruction |= do_align << 4;
15169 }
15170
15171 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
15172 apart from bits [11:4]. */
15173
15174 static void
15175 do_neon_ldx_stx (void)
15176 {
15177 if (inst.operands[1].isreg)
15178 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
15179
15180 switch (NEON_LANE (inst.operands[0].imm))
15181 {
15182 case NEON_INTERLEAVE_LANES:
15183 NEON_ENCODE (INTERLV, inst);
15184 do_neon_ld_st_interleave ();
15185 break;
15186
15187 case NEON_ALL_LANES:
15188 NEON_ENCODE (DUP, inst);
15189 do_neon_ld_dup ();
15190 break;
15191
15192 default:
15193 NEON_ENCODE (LANE, inst);
15194 do_neon_ld_st_lane ();
15195 }
15196
15197 /* L bit comes from bit mask. */
15198 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15199 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15200 inst.instruction |= inst.operands[1].reg << 16;
15201
15202 if (inst.operands[1].postind)
15203 {
15204 int postreg = inst.operands[1].imm & 0xf;
15205 constraint (!inst.operands[1].immisreg,
15206 _("post-index must be a register"));
15207 constraint (postreg == 0xd || postreg == 0xf,
15208 _("bad register for post-index"));
15209 inst.instruction |= postreg;
15210 }
15211 else if (inst.operands[1].writeback)
15212 {
15213 inst.instruction |= 0xd;
15214 }
15215 else
15216 inst.instruction |= 0xf;
15217
15218 if (thumb_mode)
15219 inst.instruction |= 0xf9000000;
15220 else
15221 inst.instruction |= 0xf4000000;
15222 }
15223 \f
15224 /* Overall per-instruction processing. */
15225
15226 /* We need to be able to fix up arbitrary expressions in some statements.
15227 This is so that we can handle symbols that are an arbitrary distance from
15228 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
15229 which returns part of an address in a form which will be valid for
15230 a data instruction. We do this by pushing the expression into a symbol
15231 in the expr_section, and creating a fix for that. */
15232
15233 static void
15234 fix_new_arm (fragS * frag,
15235 int where,
15236 short int size,
15237 expressionS * exp,
15238 int pc_rel,
15239 int reloc)
15240 {
15241 fixS * new_fix;
15242
15243 switch (exp->X_op)
15244 {
15245 case O_constant:
15246 case O_symbol:
15247 case O_add:
15248 case O_subtract:
15249 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
15250 (enum bfd_reloc_code_real) reloc);
15251 break;
15252
15253 default:
15254 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
15255 pc_rel, (enum bfd_reloc_code_real) reloc);
15256 break;
15257 }
15258
15259 /* Mark whether the fix is to a THUMB instruction, or an ARM
15260 instruction. */
15261 new_fix->tc_fix_data = thumb_mode;
15262 }
15263
15264 /* Create a frg for an instruction requiring relaxation. */
15265 static void
15266 output_relax_insn (void)
15267 {
15268 char * to;
15269 symbolS *sym;
15270 int offset;
15271
15272 /* The size of the instruction is unknown, so tie the debug info to the
15273 start of the instruction. */
15274 dwarf2_emit_insn (0);
15275
15276 switch (inst.reloc.exp.X_op)
15277 {
15278 case O_symbol:
15279 sym = inst.reloc.exp.X_add_symbol;
15280 offset = inst.reloc.exp.X_add_number;
15281 break;
15282 case O_constant:
15283 sym = NULL;
15284 offset = inst.reloc.exp.X_add_number;
15285 break;
15286 default:
15287 sym = make_expr_symbol (&inst.reloc.exp);
15288 offset = 0;
15289 break;
15290 }
15291 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
15292 inst.relax, sym, offset, NULL/*offset, opcode*/);
15293 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
15294 }
15295
15296 /* Write a 32-bit thumb instruction to buf. */
15297 static void
15298 put_thumb32_insn (char * buf, unsigned long insn)
15299 {
15300 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
15301 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
15302 }
15303
15304 static void
15305 output_inst (const char * str)
15306 {
15307 char * to = NULL;
15308
15309 if (inst.error)
15310 {
15311 as_bad ("%s -- `%s'", inst.error, str);
15312 return;
15313 }
15314 if (inst.relax)
15315 {
15316 output_relax_insn ();
15317 return;
15318 }
15319 if (inst.size == 0)
15320 return;
15321
15322 to = frag_more (inst.size);
15323 /* PR 9814: Record the thumb mode into the current frag so that we know
15324 what type of NOP padding to use, if necessary. We override any previous
15325 setting so that if the mode has changed then the NOPS that we use will
15326 match the encoding of the last instruction in the frag. */
15327 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
15328
15329 if (thumb_mode && (inst.size > THUMB_SIZE))
15330 {
15331 gas_assert (inst.size == (2 * THUMB_SIZE));
15332 put_thumb32_insn (to, inst.instruction);
15333 }
15334 else if (inst.size > INSN_SIZE)
15335 {
15336 gas_assert (inst.size == (2 * INSN_SIZE));
15337 md_number_to_chars (to, inst.instruction, INSN_SIZE);
15338 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
15339 }
15340 else
15341 md_number_to_chars (to, inst.instruction, inst.size);
15342
15343 if (inst.reloc.type != BFD_RELOC_UNUSED)
15344 fix_new_arm (frag_now, to - frag_now->fr_literal,
15345 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
15346 inst.reloc.type);
15347
15348 dwarf2_emit_insn (inst.size);
15349 }
15350
15351 static char *
15352 output_it_inst (int cond, int mask, char * to)
15353 {
15354 unsigned long instruction = 0xbf00;
15355
15356 mask &= 0xf;
15357 instruction |= mask;
15358 instruction |= cond << 4;
15359
15360 if (to == NULL)
15361 {
15362 to = frag_more (2);
15363 #ifdef OBJ_ELF
15364 dwarf2_emit_insn (2);
15365 #endif
15366 }
15367
15368 md_number_to_chars (to, instruction, 2);
15369
15370 return to;
15371 }
15372
15373 /* Tag values used in struct asm_opcode's tag field. */
15374 enum opcode_tag
15375 {
15376 OT_unconditional, /* Instruction cannot be conditionalized.
15377 The ARM condition field is still 0xE. */
15378 OT_unconditionalF, /* Instruction cannot be conditionalized
15379 and carries 0xF in its ARM condition field. */
15380 OT_csuffix, /* Instruction takes a conditional suffix. */
15381 OT_csuffixF, /* Some forms of the instruction take a conditional
15382 suffix, others place 0xF where the condition field
15383 would be. */
15384 OT_cinfix3, /* Instruction takes a conditional infix,
15385 beginning at character index 3. (In
15386 unified mode, it becomes a suffix.) */
15387 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
15388 tsts, cmps, cmns, and teqs. */
15389 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
15390 character index 3, even in unified mode. Used for
15391 legacy instructions where suffix and infix forms
15392 may be ambiguous. */
15393 OT_csuf_or_in3, /* Instruction takes either a conditional
15394 suffix or an infix at character index 3. */
15395 OT_odd_infix_unc, /* This is the unconditional variant of an
15396 instruction that takes a conditional infix
15397 at an unusual position. In unified mode,
15398 this variant will accept a suffix. */
15399 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
15400 are the conditional variants of instructions that
15401 take conditional infixes in unusual positions.
15402 The infix appears at character index
15403 (tag - OT_odd_infix_0). These are not accepted
15404 in unified mode. */
15405 };
15406
15407 /* Subroutine of md_assemble, responsible for looking up the primary
15408 opcode from the mnemonic the user wrote. STR points to the
15409 beginning of the mnemonic.
15410
15411 This is not simply a hash table lookup, because of conditional
15412 variants. Most instructions have conditional variants, which are
15413 expressed with a _conditional affix_ to the mnemonic. If we were
15414 to encode each conditional variant as a literal string in the opcode
15415 table, it would have approximately 20,000 entries.
15416
15417 Most mnemonics take this affix as a suffix, and in unified syntax,
15418 'most' is upgraded to 'all'. However, in the divided syntax, some
15419 instructions take the affix as an infix, notably the s-variants of
15420 the arithmetic instructions. Of those instructions, all but six
15421 have the infix appear after the third character of the mnemonic.
15422
15423 Accordingly, the algorithm for looking up primary opcodes given
15424 an identifier is:
15425
15426 1. Look up the identifier in the opcode table.
15427 If we find a match, go to step U.
15428
15429 2. Look up the last two characters of the identifier in the
15430 conditions table. If we find a match, look up the first N-2
15431 characters of the identifier in the opcode table. If we
15432 find a match, go to step CE.
15433
15434 3. Look up the fourth and fifth characters of the identifier in
15435 the conditions table. If we find a match, extract those
15436 characters from the identifier, and look up the remaining
15437 characters in the opcode table. If we find a match, go
15438 to step CM.
15439
15440 4. Fail.
15441
15442 U. Examine the tag field of the opcode structure, in case this is
15443 one of the six instructions with its conditional infix in an
15444 unusual place. If it is, the tag tells us where to find the
15445 infix; look it up in the conditions table and set inst.cond
15446 accordingly. Otherwise, this is an unconditional instruction.
15447 Again set inst.cond accordingly. Return the opcode structure.
15448
15449 CE. Examine the tag field to make sure this is an instruction that
15450 should receive a conditional suffix. If it is not, fail.
15451 Otherwise, set inst.cond from the suffix we already looked up,
15452 and return the opcode structure.
15453
15454 CM. Examine the tag field to make sure this is an instruction that
15455 should receive a conditional infix after the third character.
15456 If it is not, fail. Otherwise, undo the edits to the current
15457 line of input and proceed as for case CE. */
15458
15459 static const struct asm_opcode *
15460 opcode_lookup (char **str)
15461 {
15462 char *end, *base;
15463 char *affix;
15464 const struct asm_opcode *opcode;
15465 const struct asm_cond *cond;
15466 char save[2];
15467
15468 /* Scan up to the end of the mnemonic, which must end in white space,
15469 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
15470 for (base = end = *str; *end != '\0'; end++)
15471 if (*end == ' ' || *end == '.')
15472 break;
15473
15474 if (end == base)
15475 return NULL;
15476
15477 /* Handle a possible width suffix and/or Neon type suffix. */
15478 if (end[0] == '.')
15479 {
15480 int offset = 2;
15481
15482 /* The .w and .n suffixes are only valid if the unified syntax is in
15483 use. */
15484 if (unified_syntax && end[1] == 'w')
15485 inst.size_req = 4;
15486 else if (unified_syntax && end[1] == 'n')
15487 inst.size_req = 2;
15488 else
15489 offset = 0;
15490
15491 inst.vectype.elems = 0;
15492
15493 *str = end + offset;
15494
15495 if (end[offset] == '.')
15496 {
15497 /* See if we have a Neon type suffix (possible in either unified or
15498 non-unified ARM syntax mode). */
15499 if (parse_neon_type (&inst.vectype, str) == FAIL)
15500 return NULL;
15501 }
15502 else if (end[offset] != '\0' && end[offset] != ' ')
15503 return NULL;
15504 }
15505 else
15506 *str = end;
15507
15508 /* Look for unaffixed or special-case affixed mnemonic. */
15509 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15510 end - base);
15511 if (opcode)
15512 {
15513 /* step U */
15514 if (opcode->tag < OT_odd_infix_0)
15515 {
15516 inst.cond = COND_ALWAYS;
15517 return opcode;
15518 }
15519
15520 if (warn_on_deprecated && unified_syntax)
15521 as_warn (_("conditional infixes are deprecated in unified syntax"));
15522 affix = base + (opcode->tag - OT_odd_infix_0);
15523 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15524 gas_assert (cond);
15525
15526 inst.cond = cond->value;
15527 return opcode;
15528 }
15529
15530 /* Cannot have a conditional suffix on a mnemonic of less than two
15531 characters. */
15532 if (end - base < 3)
15533 return NULL;
15534
15535 /* Look for suffixed mnemonic. */
15536 affix = end - 2;
15537 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15538 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15539 affix - base);
15540 if (opcode && cond)
15541 {
15542 /* step CE */
15543 switch (opcode->tag)
15544 {
15545 case OT_cinfix3_legacy:
15546 /* Ignore conditional suffixes matched on infix only mnemonics. */
15547 break;
15548
15549 case OT_cinfix3:
15550 case OT_cinfix3_deprecated:
15551 case OT_odd_infix_unc:
15552 if (!unified_syntax)
15553 return 0;
15554 /* else fall through */
15555
15556 case OT_csuffix:
15557 case OT_csuffixF:
15558 case OT_csuf_or_in3:
15559 inst.cond = cond->value;
15560 return opcode;
15561
15562 case OT_unconditional:
15563 case OT_unconditionalF:
15564 if (thumb_mode)
15565 inst.cond = cond->value;
15566 else
15567 {
15568 /* Delayed diagnostic. */
15569 inst.error = BAD_COND;
15570 inst.cond = COND_ALWAYS;
15571 }
15572 return opcode;
15573
15574 default:
15575 return NULL;
15576 }
15577 }
15578
15579 /* Cannot have a usual-position infix on a mnemonic of less than
15580 six characters (five would be a suffix). */
15581 if (end - base < 6)
15582 return NULL;
15583
15584 /* Look for infixed mnemonic in the usual position. */
15585 affix = base + 3;
15586 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15587 if (!cond)
15588 return NULL;
15589
15590 memcpy (save, affix, 2);
15591 memmove (affix, affix + 2, (end - affix) - 2);
15592 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15593 (end - base) - 2);
15594 memmove (affix + 2, affix, (end - affix) - 2);
15595 memcpy (affix, save, 2);
15596
15597 if (opcode
15598 && (opcode->tag == OT_cinfix3
15599 || opcode->tag == OT_cinfix3_deprecated
15600 || opcode->tag == OT_csuf_or_in3
15601 || opcode->tag == OT_cinfix3_legacy))
15602 {
15603 /* Step CM. */
15604 if (warn_on_deprecated && unified_syntax
15605 && (opcode->tag == OT_cinfix3
15606 || opcode->tag == OT_cinfix3_deprecated))
15607 as_warn (_("conditional infixes are deprecated in unified syntax"));
15608
15609 inst.cond = cond->value;
15610 return opcode;
15611 }
15612
15613 return NULL;
15614 }
15615
15616 /* This function generates an initial IT instruction, leaving its block
15617 virtually open for the new instructions. Eventually,
15618 the mask will be updated by now_it_add_mask () each time
15619 a new instruction needs to be included in the IT block.
15620 Finally, the block is closed with close_automatic_it_block ().
15621 The block closure can be requested either from md_assemble (),
15622 a tencode (), or due to a label hook. */
15623
15624 static void
15625 new_automatic_it_block (int cond)
15626 {
15627 now_it.state = AUTOMATIC_IT_BLOCK;
15628 now_it.mask = 0x18;
15629 now_it.cc = cond;
15630 now_it.block_length = 1;
15631 mapping_state (MAP_THUMB);
15632 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
15633 }
15634
15635 /* Close an automatic IT block.
15636 See comments in new_automatic_it_block (). */
15637
15638 static void
15639 close_automatic_it_block (void)
15640 {
15641 now_it.mask = 0x10;
15642 now_it.block_length = 0;
15643 }
15644
15645 /* Update the mask of the current automatically-generated IT
15646 instruction. See comments in new_automatic_it_block (). */
15647
15648 static void
15649 now_it_add_mask (int cond)
15650 {
15651 #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
15652 #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
15653 | ((bitvalue) << (nbit)))
15654 const int resulting_bit = (cond & 1);
15655
15656 now_it.mask &= 0xf;
15657 now_it.mask = SET_BIT_VALUE (now_it.mask,
15658 resulting_bit,
15659 (5 - now_it.block_length));
15660 now_it.mask = SET_BIT_VALUE (now_it.mask,
15661 1,
15662 ((5 - now_it.block_length) - 1) );
15663 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
15664
15665 #undef CLEAR_BIT
15666 #undef SET_BIT_VALUE
15667 }
15668
15669 /* The IT blocks handling machinery is accessed through the these functions:
15670 it_fsm_pre_encode () from md_assemble ()
15671 set_it_insn_type () optional, from the tencode functions
15672 set_it_insn_type_last () ditto
15673 in_it_block () ditto
15674 it_fsm_post_encode () from md_assemble ()
15675 force_automatic_it_block_close () from label habdling functions
15676
15677 Rationale:
15678 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
15679 initializing the IT insn type with a generic initial value depending
15680 on the inst.condition.
15681 2) During the tencode function, two things may happen:
15682 a) The tencode function overrides the IT insn type by
15683 calling either set_it_insn_type (type) or set_it_insn_type_last ().
15684 b) The tencode function queries the IT block state by
15685 calling in_it_block () (i.e. to determine narrow/not narrow mode).
15686
15687 Both set_it_insn_type and in_it_block run the internal FSM state
15688 handling function (handle_it_state), because: a) setting the IT insn
15689 type may incur in an invalid state (exiting the function),
15690 and b) querying the state requires the FSM to be updated.
15691 Specifically we want to avoid creating an IT block for conditional
15692 branches, so it_fsm_pre_encode is actually a guess and we can't
15693 determine whether an IT block is required until the tencode () routine
15694 has decided what type of instruction this actually it.
15695 Because of this, if set_it_insn_type and in_it_block have to be used,
15696 set_it_insn_type has to be called first.
15697
15698 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
15699 determines the insn IT type depending on the inst.cond code.
15700 When a tencode () routine encodes an instruction that can be
15701 either outside an IT block, or, in the case of being inside, has to be
15702 the last one, set_it_insn_type_last () will determine the proper
15703 IT instruction type based on the inst.cond code. Otherwise,
15704 set_it_insn_type can be called for overriding that logic or
15705 for covering other cases.
15706
15707 Calling handle_it_state () may not transition the IT block state to
15708 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
15709 still queried. Instead, if the FSM determines that the state should
15710 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
15711 after the tencode () function: that's what it_fsm_post_encode () does.
15712
15713 Since in_it_block () calls the state handling function to get an
15714 updated state, an error may occur (due to invalid insns combination).
15715 In that case, inst.error is set.
15716 Therefore, inst.error has to be checked after the execution of
15717 the tencode () routine.
15718
15719 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
15720 any pending state change (if any) that didn't take place in
15721 handle_it_state () as explained above. */
15722
15723 static void
15724 it_fsm_pre_encode (void)
15725 {
15726 if (inst.cond != COND_ALWAYS)
15727 inst.it_insn_type = INSIDE_IT_INSN;
15728 else
15729 inst.it_insn_type = OUTSIDE_IT_INSN;
15730
15731 now_it.state_handled = 0;
15732 }
15733
15734 /* IT state FSM handling function. */
15735
15736 static int
15737 handle_it_state (void)
15738 {
15739 now_it.state_handled = 1;
15740
15741 switch (now_it.state)
15742 {
15743 case OUTSIDE_IT_BLOCK:
15744 switch (inst.it_insn_type)
15745 {
15746 case OUTSIDE_IT_INSN:
15747 break;
15748
15749 case INSIDE_IT_INSN:
15750 case INSIDE_IT_LAST_INSN:
15751 if (thumb_mode == 0)
15752 {
15753 if (unified_syntax
15754 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
15755 as_tsktsk (_("Warning: conditional outside an IT block"\
15756 " for Thumb."));
15757 }
15758 else
15759 {
15760 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
15761 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
15762 {
15763 /* Automatically generate the IT instruction. */
15764 new_automatic_it_block (inst.cond);
15765 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
15766 close_automatic_it_block ();
15767 }
15768 else
15769 {
15770 inst.error = BAD_OUT_IT;
15771 return FAIL;
15772 }
15773 }
15774 break;
15775
15776 case IF_INSIDE_IT_LAST_INSN:
15777 case NEUTRAL_IT_INSN:
15778 break;
15779
15780 case IT_INSN:
15781 now_it.state = MANUAL_IT_BLOCK;
15782 now_it.block_length = 0;
15783 break;
15784 }
15785 break;
15786
15787 case AUTOMATIC_IT_BLOCK:
15788 /* Three things may happen now:
15789 a) We should increment current it block size;
15790 b) We should close current it block (closing insn or 4 insns);
15791 c) We should close current it block and start a new one (due
15792 to incompatible conditions or
15793 4 insns-length block reached). */
15794
15795 switch (inst.it_insn_type)
15796 {
15797 case OUTSIDE_IT_INSN:
15798 /* The closure of the block shall happen immediatelly,
15799 so any in_it_block () call reports the block as closed. */
15800 force_automatic_it_block_close ();
15801 break;
15802
15803 case INSIDE_IT_INSN:
15804 case INSIDE_IT_LAST_INSN:
15805 case IF_INSIDE_IT_LAST_INSN:
15806 now_it.block_length++;
15807
15808 if (now_it.block_length > 4
15809 || !now_it_compatible (inst.cond))
15810 {
15811 force_automatic_it_block_close ();
15812 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
15813 new_automatic_it_block (inst.cond);
15814 }
15815 else
15816 {
15817 now_it_add_mask (inst.cond);
15818 }
15819
15820 if (now_it.state == AUTOMATIC_IT_BLOCK
15821 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
15822 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
15823 close_automatic_it_block ();
15824 break;
15825
15826 case NEUTRAL_IT_INSN:
15827 now_it.block_length++;
15828
15829 if (now_it.block_length > 4)
15830 force_automatic_it_block_close ();
15831 else
15832 now_it_add_mask (now_it.cc & 1);
15833 break;
15834
15835 case IT_INSN:
15836 close_automatic_it_block ();
15837 now_it.state = MANUAL_IT_BLOCK;
15838 break;
15839 }
15840 break;
15841
15842 case MANUAL_IT_BLOCK:
15843 {
15844 /* Check conditional suffixes. */
15845 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
15846 int is_last;
15847 now_it.mask <<= 1;
15848 now_it.mask &= 0x1f;
15849 is_last = (now_it.mask == 0x10);
15850
15851 switch (inst.it_insn_type)
15852 {
15853 case OUTSIDE_IT_INSN:
15854 inst.error = BAD_NOT_IT;
15855 return FAIL;
15856
15857 case INSIDE_IT_INSN:
15858 if (cond != inst.cond)
15859 {
15860 inst.error = BAD_IT_COND;
15861 return FAIL;
15862 }
15863 break;
15864
15865 case INSIDE_IT_LAST_INSN:
15866 case IF_INSIDE_IT_LAST_INSN:
15867 if (cond != inst.cond)
15868 {
15869 inst.error = BAD_IT_COND;
15870 return FAIL;
15871 }
15872 if (!is_last)
15873 {
15874 inst.error = BAD_BRANCH;
15875 return FAIL;
15876 }
15877 break;
15878
15879 case NEUTRAL_IT_INSN:
15880 /* The BKPT instruction is unconditional even in an IT block. */
15881 break;
15882
15883 case IT_INSN:
15884 inst.error = BAD_IT_IT;
15885 return FAIL;
15886 }
15887 }
15888 break;
15889 }
15890
15891 return SUCCESS;
15892 }
15893
15894 static void
15895 it_fsm_post_encode (void)
15896 {
15897 int is_last;
15898
15899 if (!now_it.state_handled)
15900 handle_it_state ();
15901
15902 is_last = (now_it.mask == 0x10);
15903 if (is_last)
15904 {
15905 now_it.state = OUTSIDE_IT_BLOCK;
15906 now_it.mask = 0;
15907 }
15908 }
15909
15910 static void
15911 force_automatic_it_block_close (void)
15912 {
15913 if (now_it.state == AUTOMATIC_IT_BLOCK)
15914 {
15915 close_automatic_it_block ();
15916 now_it.state = OUTSIDE_IT_BLOCK;
15917 now_it.mask = 0;
15918 }
15919 }
15920
15921 static int
15922 in_it_block (void)
15923 {
15924 if (!now_it.state_handled)
15925 handle_it_state ();
15926
15927 return now_it.state != OUTSIDE_IT_BLOCK;
15928 }
15929
15930 void
15931 md_assemble (char *str)
15932 {
15933 char *p = str;
15934 const struct asm_opcode * opcode;
15935
15936 /* Align the previous label if needed. */
15937 if (last_label_seen != NULL)
15938 {
15939 symbol_set_frag (last_label_seen, frag_now);
15940 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
15941 S_SET_SEGMENT (last_label_seen, now_seg);
15942 }
15943
15944 memset (&inst, '\0', sizeof (inst));
15945 inst.reloc.type = BFD_RELOC_UNUSED;
15946
15947 opcode = opcode_lookup (&p);
15948 if (!opcode)
15949 {
15950 /* It wasn't an instruction, but it might be a register alias of
15951 the form alias .req reg, or a Neon .dn/.qn directive. */
15952 if (! create_register_alias (str, p)
15953 && ! create_neon_reg_alias (str, p))
15954 as_bad (_("bad instruction `%s'"), str);
15955
15956 return;
15957 }
15958
15959 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
15960 as_warn (_("s suffix on comparison instruction is deprecated"));
15961
15962 /* The value which unconditional instructions should have in place of the
15963 condition field. */
15964 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
15965
15966 if (thumb_mode)
15967 {
15968 arm_feature_set variant;
15969
15970 variant = cpu_variant;
15971 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
15972 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
15973 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
15974 /* Check that this instruction is supported for this CPU. */
15975 if (!opcode->tvariant
15976 || (thumb_mode == 1
15977 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
15978 {
15979 as_bad (_("selected processor does not support Thumb mode `%s'"), str);
15980 return;
15981 }
15982 if (inst.cond != COND_ALWAYS && !unified_syntax
15983 && opcode->tencode != do_t_branch)
15984 {
15985 as_bad (_("Thumb does not support conditional execution"));
15986 return;
15987 }
15988
15989 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
15990 {
15991 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
15992 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
15993 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
15994 {
15995 /* Two things are addressed here.
15996 1) Implicit require narrow instructions on Thumb-1.
15997 This avoids relaxation accidentally introducing Thumb-2
15998 instructions.
15999 2) Reject wide instructions in non Thumb-2 cores. */
16000 if (inst.size_req == 0)
16001 inst.size_req = 2;
16002 else if (inst.size_req == 4)
16003 {
16004 as_bad (_("selected processor does not support Thumb-2 mode `%s'"), str);
16005 return;
16006 }
16007 }
16008 }
16009
16010 inst.instruction = opcode->tvalue;
16011
16012 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
16013 {
16014 /* Prepare the it_insn_type for those encodings that don't set
16015 it. */
16016 it_fsm_pre_encode ();
16017
16018 opcode->tencode ();
16019
16020 it_fsm_post_encode ();
16021 }
16022
16023 if (!(inst.error || inst.relax))
16024 {
16025 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
16026 inst.size = (inst.instruction > 0xffff ? 4 : 2);
16027 if (inst.size_req && inst.size_req != inst.size)
16028 {
16029 as_bad (_("cannot honor width suffix -- `%s'"), str);
16030 return;
16031 }
16032 }
16033
16034 /* Something has gone badly wrong if we try to relax a fixed size
16035 instruction. */
16036 gas_assert (inst.size_req == 0 || !inst.relax);
16037
16038 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
16039 *opcode->tvariant);
16040 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
16041 set those bits when Thumb-2 32-bit instructions are seen. ie.
16042 anything other than bl/blx and v6-M instructions.
16043 This is overly pessimistic for relaxable instructions. */
16044 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
16045 || inst.relax)
16046 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
16047 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
16048 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
16049 arm_ext_v6t2);
16050
16051 check_neon_suffixes;
16052
16053 if (!inst.error)
16054 {
16055 mapping_state (MAP_THUMB);
16056 }
16057 }
16058 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
16059 {
16060 bfd_boolean is_bx;
16061
16062 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
16063 is_bx = (opcode->aencode == do_bx);
16064
16065 /* Check that this instruction is supported for this CPU. */
16066 if (!(is_bx && fix_v4bx)
16067 && !(opcode->avariant &&
16068 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
16069 {
16070 as_bad (_("selected processor does not support ARM mode `%s'"), str);
16071 return;
16072 }
16073 if (inst.size_req)
16074 {
16075 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
16076 return;
16077 }
16078
16079 inst.instruction = opcode->avalue;
16080 if (opcode->tag == OT_unconditionalF)
16081 inst.instruction |= 0xF << 28;
16082 else
16083 inst.instruction |= inst.cond << 28;
16084 inst.size = INSN_SIZE;
16085 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
16086 {
16087 it_fsm_pre_encode ();
16088 opcode->aencode ();
16089 it_fsm_post_encode ();
16090 }
16091 /* Arm mode bx is marked as both v4T and v5 because it's still required
16092 on a hypothetical non-thumb v5 core. */
16093 if (is_bx)
16094 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
16095 else
16096 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
16097 *opcode->avariant);
16098
16099 check_neon_suffixes;
16100
16101 if (!inst.error)
16102 {
16103 mapping_state (MAP_ARM);
16104 }
16105 }
16106 else
16107 {
16108 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
16109 "-- `%s'"), str);
16110 return;
16111 }
16112 output_inst (str);
16113 }
16114
16115 static void
16116 check_it_blocks_finished (void)
16117 {
16118 #ifdef OBJ_ELF
16119 asection *sect;
16120
16121 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
16122 if (seg_info (sect)->tc_segment_info_data.current_it.state
16123 == MANUAL_IT_BLOCK)
16124 {
16125 as_warn (_("section '%s' finished with an open IT block."),
16126 sect->name);
16127 }
16128 #else
16129 if (now_it.state == MANUAL_IT_BLOCK)
16130 as_warn (_("file finished with an open IT block."));
16131 #endif
16132 }
16133
16134 /* Various frobbings of labels and their addresses. */
16135
16136 void
16137 arm_start_line_hook (void)
16138 {
16139 last_label_seen = NULL;
16140 }
16141
16142 void
16143 arm_frob_label (symbolS * sym)
16144 {
16145 last_label_seen = sym;
16146
16147 ARM_SET_THUMB (sym, thumb_mode);
16148
16149 #if defined OBJ_COFF || defined OBJ_ELF
16150 ARM_SET_INTERWORK (sym, support_interwork);
16151 #endif
16152
16153 force_automatic_it_block_close ();
16154
16155 /* Note - do not allow local symbols (.Lxxx) to be labelled
16156 as Thumb functions. This is because these labels, whilst
16157 they exist inside Thumb code, are not the entry points for
16158 possible ARM->Thumb calls. Also, these labels can be used
16159 as part of a computed goto or switch statement. eg gcc
16160 can generate code that looks like this:
16161
16162 ldr r2, [pc, .Laaa]
16163 lsl r3, r3, #2
16164 ldr r2, [r3, r2]
16165 mov pc, r2
16166
16167 .Lbbb: .word .Lxxx
16168 .Lccc: .word .Lyyy
16169 ..etc...
16170 .Laaa: .word Lbbb
16171
16172 The first instruction loads the address of the jump table.
16173 The second instruction converts a table index into a byte offset.
16174 The third instruction gets the jump address out of the table.
16175 The fourth instruction performs the jump.
16176
16177 If the address stored at .Laaa is that of a symbol which has the
16178 Thumb_Func bit set, then the linker will arrange for this address
16179 to have the bottom bit set, which in turn would mean that the
16180 address computation performed by the third instruction would end
16181 up with the bottom bit set. Since the ARM is capable of unaligned
16182 word loads, the instruction would then load the incorrect address
16183 out of the jump table, and chaos would ensue. */
16184 if (label_is_thumb_function_name
16185 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
16186 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
16187 {
16188 /* When the address of a Thumb function is taken the bottom
16189 bit of that address should be set. This will allow
16190 interworking between Arm and Thumb functions to work
16191 correctly. */
16192
16193 THUMB_SET_FUNC (sym, 1);
16194
16195 label_is_thumb_function_name = FALSE;
16196 }
16197
16198 dwarf2_emit_label (sym);
16199 }
16200
16201 bfd_boolean
16202 arm_data_in_code (void)
16203 {
16204 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
16205 {
16206 *input_line_pointer = '/';
16207 input_line_pointer += 5;
16208 *input_line_pointer = 0;
16209 return TRUE;
16210 }
16211
16212 return FALSE;
16213 }
16214
16215 char *
16216 arm_canonicalize_symbol_name (char * name)
16217 {
16218 int len;
16219
16220 if (thumb_mode && (len = strlen (name)) > 5
16221 && streq (name + len - 5, "/data"))
16222 *(name + len - 5) = 0;
16223
16224 return name;
16225 }
16226 \f
16227 /* Table of all register names defined by default. The user can
16228 define additional names with .req. Note that all register names
16229 should appear in both upper and lowercase variants. Some registers
16230 also have mixed-case names. */
16231
16232 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
16233 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
16234 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
16235 #define REGSET(p,t) \
16236 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
16237 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
16238 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
16239 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
16240 #define REGSETH(p,t) \
16241 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
16242 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
16243 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
16244 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
16245 #define REGSET2(p,t) \
16246 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
16247 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
16248 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
16249 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
16250 #define SPLRBANK(base,bank,t) \
16251 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
16252 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
16253 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
16254 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
16255 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
16256 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
16257
16258 static const struct reg_entry reg_names[] =
16259 {
16260 /* ARM integer registers. */
16261 REGSET(r, RN), REGSET(R, RN),
16262
16263 /* ATPCS synonyms. */
16264 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
16265 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
16266 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
16267
16268 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
16269 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
16270 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
16271
16272 /* Well-known aliases. */
16273 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
16274 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
16275
16276 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
16277 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
16278
16279 /* Coprocessor numbers. */
16280 REGSET(p, CP), REGSET(P, CP),
16281
16282 /* Coprocessor register numbers. The "cr" variants are for backward
16283 compatibility. */
16284 REGSET(c, CN), REGSET(C, CN),
16285 REGSET(cr, CN), REGSET(CR, CN),
16286
16287 /* ARM banked registers. */
16288 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
16289 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
16290 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
16291 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
16292 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
16293 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
16294 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
16295
16296 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
16297 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
16298 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
16299 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
16300 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
16301 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(SP_fiq,512|(13<<16),RNB),
16302 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
16303 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
16304
16305 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
16306 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
16307 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
16308 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
16309 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
16310 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
16311 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
16312 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
16313 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
16314
16315 /* FPA registers. */
16316 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
16317 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
16318
16319 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
16320 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
16321
16322 /* VFP SP registers. */
16323 REGSET(s,VFS), REGSET(S,VFS),
16324 REGSETH(s,VFS), REGSETH(S,VFS),
16325
16326 /* VFP DP Registers. */
16327 REGSET(d,VFD), REGSET(D,VFD),
16328 /* Extra Neon DP registers. */
16329 REGSETH(d,VFD), REGSETH(D,VFD),
16330
16331 /* Neon QP registers. */
16332 REGSET2(q,NQ), REGSET2(Q,NQ),
16333
16334 /* VFP control registers. */
16335 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
16336 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
16337 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
16338 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
16339 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
16340 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
16341
16342 /* Maverick DSP coprocessor registers. */
16343 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
16344 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
16345
16346 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
16347 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
16348 REGDEF(dspsc,0,DSPSC),
16349
16350 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
16351 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
16352 REGDEF(DSPSC,0,DSPSC),
16353
16354 /* iWMMXt data registers - p0, c0-15. */
16355 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
16356
16357 /* iWMMXt control registers - p1, c0-3. */
16358 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
16359 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
16360 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
16361 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
16362
16363 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
16364 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
16365 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
16366 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
16367 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
16368
16369 /* XScale accumulator registers. */
16370 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
16371 };
16372 #undef REGDEF
16373 #undef REGNUM
16374 #undef REGSET
16375
16376 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
16377 within psr_required_here. */
16378 static const struct asm_psr psrs[] =
16379 {
16380 /* Backward compatibility notation. Note that "all" is no longer
16381 truly all possible PSR bits. */
16382 {"all", PSR_c | PSR_f},
16383 {"flg", PSR_f},
16384 {"ctl", PSR_c},
16385
16386 /* Individual flags. */
16387 {"f", PSR_f},
16388 {"c", PSR_c},
16389 {"x", PSR_x},
16390 {"s", PSR_s},
16391 {"g", PSR_s},
16392
16393 /* Combinations of flags. */
16394 {"fs", PSR_f | PSR_s},
16395 {"fx", PSR_f | PSR_x},
16396 {"fc", PSR_f | PSR_c},
16397 {"sf", PSR_s | PSR_f},
16398 {"sx", PSR_s | PSR_x},
16399 {"sc", PSR_s | PSR_c},
16400 {"xf", PSR_x | PSR_f},
16401 {"xs", PSR_x | PSR_s},
16402 {"xc", PSR_x | PSR_c},
16403 {"cf", PSR_c | PSR_f},
16404 {"cs", PSR_c | PSR_s},
16405 {"cx", PSR_c | PSR_x},
16406 {"fsx", PSR_f | PSR_s | PSR_x},
16407 {"fsc", PSR_f | PSR_s | PSR_c},
16408 {"fxs", PSR_f | PSR_x | PSR_s},
16409 {"fxc", PSR_f | PSR_x | PSR_c},
16410 {"fcs", PSR_f | PSR_c | PSR_s},
16411 {"fcx", PSR_f | PSR_c | PSR_x},
16412 {"sfx", PSR_s | PSR_f | PSR_x},
16413 {"sfc", PSR_s | PSR_f | PSR_c},
16414 {"sxf", PSR_s | PSR_x | PSR_f},
16415 {"sxc", PSR_s | PSR_x | PSR_c},
16416 {"scf", PSR_s | PSR_c | PSR_f},
16417 {"scx", PSR_s | PSR_c | PSR_x},
16418 {"xfs", PSR_x | PSR_f | PSR_s},
16419 {"xfc", PSR_x | PSR_f | PSR_c},
16420 {"xsf", PSR_x | PSR_s | PSR_f},
16421 {"xsc", PSR_x | PSR_s | PSR_c},
16422 {"xcf", PSR_x | PSR_c | PSR_f},
16423 {"xcs", PSR_x | PSR_c | PSR_s},
16424 {"cfs", PSR_c | PSR_f | PSR_s},
16425 {"cfx", PSR_c | PSR_f | PSR_x},
16426 {"csf", PSR_c | PSR_s | PSR_f},
16427 {"csx", PSR_c | PSR_s | PSR_x},
16428 {"cxf", PSR_c | PSR_x | PSR_f},
16429 {"cxs", PSR_c | PSR_x | PSR_s},
16430 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
16431 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
16432 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
16433 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
16434 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
16435 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
16436 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
16437 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
16438 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
16439 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
16440 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
16441 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
16442 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
16443 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
16444 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
16445 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
16446 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
16447 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
16448 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
16449 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
16450 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
16451 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
16452 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
16453 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
16454
16455 /* APSR flags */
16456 {"nzcvq", PSR_f},
16457 {"nzcvqg", PSR_s | PSR_f}
16458 };
16459
16460 /* Table of V7M psr names. */
16461 static const struct asm_psr v7m_psrs[] =
16462 {
16463 {"apsr", 0 }, {"APSR", 0 },
16464 {"iapsr", 1 }, {"IAPSR", 1 },
16465 {"eapsr", 2 }, {"EAPSR", 2 },
16466 {"psr", 3 }, {"PSR", 3 },
16467 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
16468 {"ipsr", 5 }, {"IPSR", 5 },
16469 {"epsr", 6 }, {"EPSR", 6 },
16470 {"iepsr", 7 }, {"IEPSR", 7 },
16471 {"msp", 8 }, {"MSP", 8 },
16472 {"psp", 9 }, {"PSP", 9 },
16473 {"primask", 16}, {"PRIMASK", 16},
16474 {"basepri", 17}, {"BASEPRI", 17},
16475 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
16476 {"faultmask", 19}, {"FAULTMASK", 19},
16477 {"control", 20}, {"CONTROL", 20}
16478 };
16479
16480 /* Table of all shift-in-operand names. */
16481 static const struct asm_shift_name shift_names [] =
16482 {
16483 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
16484 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
16485 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
16486 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
16487 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
16488 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
16489 };
16490
16491 /* Table of all explicit relocation names. */
16492 #ifdef OBJ_ELF
16493 static struct reloc_entry reloc_names[] =
16494 {
16495 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
16496 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
16497 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
16498 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
16499 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
16500 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
16501 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
16502 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
16503 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
16504 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
16505 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
16506 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL}
16507 };
16508 #endif
16509
16510 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
16511 static const struct asm_cond conds[] =
16512 {
16513 {"eq", 0x0},
16514 {"ne", 0x1},
16515 {"cs", 0x2}, {"hs", 0x2},
16516 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
16517 {"mi", 0x4},
16518 {"pl", 0x5},
16519 {"vs", 0x6},
16520 {"vc", 0x7},
16521 {"hi", 0x8},
16522 {"ls", 0x9},
16523 {"ge", 0xa},
16524 {"lt", 0xb},
16525 {"gt", 0xc},
16526 {"le", 0xd},
16527 {"al", 0xe}
16528 };
16529
16530 static struct asm_barrier_opt barrier_opt_names[] =
16531 {
16532 { "sy", 0xf }, { "SY", 0xf },
16533 { "un", 0x7 }, { "UN", 0x7 },
16534 { "st", 0xe }, { "ST", 0xe },
16535 { "unst", 0x6 }, { "UNST", 0x6 },
16536 { "ish", 0xb }, { "ISH", 0xb },
16537 { "sh", 0xb }, { "SH", 0xb },
16538 { "ishst", 0xa }, { "ISHST", 0xa },
16539 { "shst", 0xa }, { "SHST", 0xa },
16540 { "nsh", 0x7 }, { "NSH", 0x7 },
16541 { "nshst", 0x6 }, { "NSHST", 0x6 },
16542 { "osh", 0x3 }, { "OSH", 0x3 },
16543 { "oshst", 0x2 }, { "OSHST", 0x2 }
16544 };
16545
16546 /* Table of ARM-format instructions. */
16547
16548 /* Macros for gluing together operand strings. N.B. In all cases
16549 other than OPS0, the trailing OP_stop comes from default
16550 zero-initialization of the unspecified elements of the array. */
16551 #define OPS0() { OP_stop, }
16552 #define OPS1(a) { OP_##a, }
16553 #define OPS2(a,b) { OP_##a,OP_##b, }
16554 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
16555 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
16556 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
16557 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
16558
16559 /* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
16560 This is useful when mixing operands for ARM and THUMB, i.e. using the
16561 MIX_ARM_THUMB_OPERANDS macro.
16562 In order to use these macros, prefix the number of operands with _
16563 e.g. _3. */
16564 #define OPS_1(a) { a, }
16565 #define OPS_2(a,b) { a,b, }
16566 #define OPS_3(a,b,c) { a,b,c, }
16567 #define OPS_4(a,b,c,d) { a,b,c,d, }
16568 #define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
16569 #define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
16570
16571 /* These macros abstract out the exact format of the mnemonic table and
16572 save some repeated characters. */
16573
16574 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
16575 #define TxCE(mnem, op, top, nops, ops, ae, te) \
16576 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
16577 THUMB_VARIANT, do_##ae, do_##te }
16578
16579 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
16580 a T_MNEM_xyz enumerator. */
16581 #define TCE(mnem, aop, top, nops, ops, ae, te) \
16582 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
16583 #define tCE(mnem, aop, top, nops, ops, ae, te) \
16584 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
16585
16586 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
16587 infix after the third character. */
16588 #define TxC3(mnem, op, top, nops, ops, ae, te) \
16589 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
16590 THUMB_VARIANT, do_##ae, do_##te }
16591 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
16592 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
16593 THUMB_VARIANT, do_##ae, do_##te }
16594 #define TC3(mnem, aop, top, nops, ops, ae, te) \
16595 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
16596 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
16597 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
16598 #define tC3(mnem, aop, top, nops, ops, ae, te) \
16599 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
16600 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
16601 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
16602
16603 /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
16604 appear in the condition table. */
16605 #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
16606 { m1 #m2 m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
16607 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
16608
16609 #define TxCM(m1, m2, op, top, nops, ops, ae, te) \
16610 TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \
16611 TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \
16612 TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \
16613 TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \
16614 TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \
16615 TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \
16616 TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \
16617 TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \
16618 TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \
16619 TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \
16620 TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \
16621 TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \
16622 TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \
16623 TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \
16624 TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \
16625 TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \
16626 TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \
16627 TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \
16628 TxCM_ (m1, al, m2, op, top, nops, ops, ae, te)
16629
16630 #define TCM(m1,m2, aop, top, nops, ops, ae, te) \
16631 TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te)
16632 #define tCM(m1,m2, aop, top, nops, ops, ae, te) \
16633 TxCM (m1,m2, aop, T_MNEM##top, nops, ops, ae, te)
16634
16635 /* Mnemonic that cannot be conditionalized. The ARM condition-code
16636 field is still 0xE. Many of the Thumb variants can be executed
16637 conditionally, so this is checked separately. */
16638 #define TUE(mnem, op, top, nops, ops, ae, te) \
16639 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
16640 THUMB_VARIANT, do_##ae, do_##te }
16641
16642 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
16643 condition code field. */
16644 #define TUF(mnem, op, top, nops, ops, ae, te) \
16645 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
16646 THUMB_VARIANT, do_##ae, do_##te }
16647
16648 /* ARM-only variants of all the above. */
16649 #define CE(mnem, op, nops, ops, ae) \
16650 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16651
16652 #define C3(mnem, op, nops, ops, ae) \
16653 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16654
16655 /* Legacy mnemonics that always have conditional infix after the third
16656 character. */
16657 #define CL(mnem, op, nops, ops, ae) \
16658 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
16659 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16660
16661 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
16662 #define cCE(mnem, op, nops, ops, ae) \
16663 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16664
16665 /* Legacy coprocessor instructions where conditional infix and conditional
16666 suffix are ambiguous. For consistency this includes all FPA instructions,
16667 not just the potentially ambiguous ones. */
16668 #define cCL(mnem, op, nops, ops, ae) \
16669 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
16670 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16671
16672 /* Coprocessor, takes either a suffix or a position-3 infix
16673 (for an FPA corner case). */
16674 #define C3E(mnem, op, nops, ops, ae) \
16675 { mnem, OPS##nops ops, OT_csuf_or_in3, \
16676 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16677
16678 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
16679 { m1 #m2 m3, OPS##nops ops, \
16680 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
16681 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16682
16683 #define CM(m1, m2, op, nops, ops, ae) \
16684 xCM_ (m1, , m2, op, nops, ops, ae), \
16685 xCM_ (m1, eq, m2, op, nops, ops, ae), \
16686 xCM_ (m1, ne, m2, op, nops, ops, ae), \
16687 xCM_ (m1, cs, m2, op, nops, ops, ae), \
16688 xCM_ (m1, hs, m2, op, nops, ops, ae), \
16689 xCM_ (m1, cc, m2, op, nops, ops, ae), \
16690 xCM_ (m1, ul, m2, op, nops, ops, ae), \
16691 xCM_ (m1, lo, m2, op, nops, ops, ae), \
16692 xCM_ (m1, mi, m2, op, nops, ops, ae), \
16693 xCM_ (m1, pl, m2, op, nops, ops, ae), \
16694 xCM_ (m1, vs, m2, op, nops, ops, ae), \
16695 xCM_ (m1, vc, m2, op, nops, ops, ae), \
16696 xCM_ (m1, hi, m2, op, nops, ops, ae), \
16697 xCM_ (m1, ls, m2, op, nops, ops, ae), \
16698 xCM_ (m1, ge, m2, op, nops, ops, ae), \
16699 xCM_ (m1, lt, m2, op, nops, ops, ae), \
16700 xCM_ (m1, gt, m2, op, nops, ops, ae), \
16701 xCM_ (m1, le, m2, op, nops, ops, ae), \
16702 xCM_ (m1, al, m2, op, nops, ops, ae)
16703
16704 #define UE(mnem, op, nops, ops, ae) \
16705 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16706
16707 #define UF(mnem, op, nops, ops, ae) \
16708 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16709
16710 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
16711 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
16712 use the same encoding function for each. */
16713 #define NUF(mnem, op, nops, ops, enc) \
16714 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
16715 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16716
16717 /* Neon data processing, version which indirects through neon_enc_tab for
16718 the various overloaded versions of opcodes. */
16719 #define nUF(mnem, op, nops, ops, enc) \
16720 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
16721 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16722
16723 /* Neon insn with conditional suffix for the ARM version, non-overloaded
16724 version. */
16725 #define NCE_tag(mnem, op, nops, ops, enc, tag) \
16726 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
16727 THUMB_VARIANT, do_##enc, do_##enc }
16728
16729 #define NCE(mnem, op, nops, ops, enc) \
16730 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
16731
16732 #define NCEF(mnem, op, nops, ops, enc) \
16733 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
16734
16735 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
16736 #define nCE_tag(mnem, op, nops, ops, enc, tag) \
16737 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
16738 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16739
16740 #define nCE(mnem, op, nops, ops, enc) \
16741 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
16742
16743 #define nCEF(mnem, op, nops, ops, enc) \
16744 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
16745
16746 #define do_0 0
16747
16748 static const struct asm_opcode insns[] =
16749 {
16750 #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
16751 #define THUMB_VARIANT &arm_ext_v4t
16752 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
16753 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
16754 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
16755 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
16756 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
16757 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
16758 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
16759 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
16760 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
16761 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
16762 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
16763 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
16764 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
16765 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
16766 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
16767 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
16768
16769 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
16770 for setting PSR flag bits. They are obsolete in V6 and do not
16771 have Thumb equivalents. */
16772 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16773 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16774 CL("tstp", 110f000, 2, (RR, SH), cmp),
16775 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16776 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16777 CL("cmpp", 150f000, 2, (RR, SH), cmp),
16778 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16779 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16780 CL("cmnp", 170f000, 2, (RR, SH), cmp),
16781
16782 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
16783 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
16784 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
16785 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
16786
16787 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
16788 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
16789 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
16790 OP_RRnpc),
16791 OP_ADDRGLDR),ldst, t_ldst),
16792 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
16793
16794 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16795 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16796 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16797 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16798 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16799 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16800
16801 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
16802 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
16803 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
16804 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
16805
16806 /* Pseudo ops. */
16807 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
16808 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
16809 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
16810
16811 /* Thumb-compatibility pseudo ops. */
16812 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
16813 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
16814 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
16815 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
16816 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
16817 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
16818 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
16819 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
16820 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
16821 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
16822 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
16823 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
16824
16825 /* These may simplify to neg. */
16826 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
16827 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16828
16829 #undef THUMB_VARIANT
16830 #define THUMB_VARIANT & arm_ext_v6
16831
16832 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
16833
16834 /* V1 instructions with no Thumb analogue prior to V6T2. */
16835 #undef THUMB_VARIANT
16836 #define THUMB_VARIANT & arm_ext_v6t2
16837
16838 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16839 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16840 CL("teqp", 130f000, 2, (RR, SH), cmp),
16841
16842 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
16843 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
16844 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
16845 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
16846
16847 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16848 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16849
16850 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16851 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16852
16853 /* V1 instructions with no Thumb analogue at all. */
16854 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
16855 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
16856
16857 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
16858 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
16859 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
16860 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
16861 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
16862 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
16863 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
16864 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
16865
16866 #undef ARM_VARIANT
16867 #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
16868 #undef THUMB_VARIANT
16869 #define THUMB_VARIANT & arm_ext_v4t
16870
16871 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
16872 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
16873
16874 #undef THUMB_VARIANT
16875 #define THUMB_VARIANT & arm_ext_v6t2
16876
16877 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
16878 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
16879
16880 /* Generic coprocessor instructions. */
16881 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16882 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16883 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16884 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16885 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16886 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16887 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
16888
16889 #undef ARM_VARIANT
16890 #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
16891
16892 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
16893 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
16894
16895 #undef ARM_VARIANT
16896 #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
16897 #undef THUMB_VARIANT
16898 #define THUMB_VARIANT & arm_ext_msr
16899
16900 TCE("mrs", 1000000, f3e08000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
16901 TCE("msr", 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
16902
16903 #undef ARM_VARIANT
16904 #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
16905 #undef THUMB_VARIANT
16906 #define THUMB_VARIANT & arm_ext_v6t2
16907
16908 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16909 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16910 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16911 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16912 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16913 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16914 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16915 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16916
16917 #undef ARM_VARIANT
16918 #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
16919 #undef THUMB_VARIANT
16920 #define THUMB_VARIANT & arm_ext_v4t
16921
16922 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16923 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16924 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16925 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16926 tCM("ld","sh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16927 tCM("ld","sb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16928
16929 #undef ARM_VARIANT
16930 #define ARM_VARIANT & arm_ext_v4t_5
16931
16932 /* ARM Architecture 4T. */
16933 /* Note: bx (and blx) are required on V5, even if the processor does
16934 not support Thumb. */
16935 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
16936
16937 #undef ARM_VARIANT
16938 #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
16939 #undef THUMB_VARIANT
16940 #define THUMB_VARIANT & arm_ext_v5t
16941
16942 /* Note: blx has 2 variants; the .value coded here is for
16943 BLX(2). Only this variant has conditional execution. */
16944 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
16945 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
16946
16947 #undef THUMB_VARIANT
16948 #define THUMB_VARIANT & arm_ext_v6t2
16949
16950 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
16951 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16952 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16953 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16954 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16955 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16956 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16957 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16958
16959 #undef ARM_VARIANT
16960 #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
16961 #undef THUMB_VARIANT
16962 #define THUMB_VARIANT &arm_ext_v5exp
16963
16964 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16965 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16966 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16967 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16968
16969 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16970 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16971
16972 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16973 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16974 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16975 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16976
16977 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16978 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16979 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16980 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16981
16982 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16983 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16984
16985 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16986 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16987 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16988 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16989
16990 #undef ARM_VARIANT
16991 #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
16992 #undef THUMB_VARIANT
16993 #define THUMB_VARIANT &arm_ext_v6t2
16994
16995 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
16996 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
16997 ldrd, t_ldstd),
16998 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
16999 ADDRGLDRS), ldrd, t_ldstd),
17000
17001 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17002 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17003
17004 #undef ARM_VARIANT
17005 #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
17006
17007 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
17008
17009 #undef ARM_VARIANT
17010 #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
17011 #undef THUMB_VARIANT
17012 #define THUMB_VARIANT & arm_ext_v6
17013
17014 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
17015 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
17016 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17017 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17018 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17019 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17020 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17021 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17022 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17023 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
17024
17025 #undef THUMB_VARIANT
17026 #define THUMB_VARIANT & arm_ext_v6t2
17027
17028 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
17029 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17030 strex, t_strex),
17031 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17032 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17033
17034 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
17035 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
17036
17037 /* ARM V6 not included in V7M. */
17038 #undef THUMB_VARIANT
17039 #define THUMB_VARIANT & arm_ext_v6_notm
17040 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
17041 UF(rfeib, 9900a00, 1, (RRw), rfe),
17042 UF(rfeda, 8100a00, 1, (RRw), rfe),
17043 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
17044 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
17045 UF(rfefa, 9900a00, 1, (RRw), rfe),
17046 UF(rfeea, 8100a00, 1, (RRw), rfe),
17047 TUF("rfeed", 9100a00, e810c000, 1, (RRw), rfe, rfe),
17048 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
17049 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
17050 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
17051 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
17052
17053 /* ARM V6 not included in V7M (eg. integer SIMD). */
17054 #undef THUMB_VARIANT
17055 #define THUMB_VARIANT & arm_ext_v6_dsp
17056 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
17057 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
17058 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
17059 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17060 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17061 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17062 /* Old name for QASX. */
17063 TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17064 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17065 /* Old name for QSAX. */
17066 TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17067 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17068 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17069 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17070 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17071 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17072 /* Old name for SASX. */
17073 TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17074 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17075 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17076 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17077 /* Old name for SHASX. */
17078 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17079 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17080 /* Old name for SHSAX. */
17081 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17082 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17083 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17084 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17085 /* Old name for SSAX. */
17086 TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17087 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17088 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17089 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17090 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17091 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17092 /* Old name for UASX. */
17093 TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17094 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17095 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17096 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17097 /* Old name for UHASX. */
17098 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17099 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17100 /* Old name for UHSAX. */
17101 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17102 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17103 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17104 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17105 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17106 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17107 /* Old name for UQASX. */
17108 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17109 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17110 /* Old name for UQSAX. */
17111 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17112 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17113 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17114 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17115 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17116 /* Old name for USAX. */
17117 TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17118 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17119 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17120 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17121 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17122 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17123 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17124 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17125 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17126 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17127 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17128 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17129 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17130 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17131 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17132 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17133 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17134 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17135 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17136 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17137 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17138 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17139 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17140 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17141 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17142 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17143 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17144 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17145 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17146 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
17147 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
17148 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17149 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17150 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
17151
17152 #undef ARM_VARIANT
17153 #define ARM_VARIANT & arm_ext_v6k
17154 #undef THUMB_VARIANT
17155 #define THUMB_VARIANT & arm_ext_v6k
17156
17157 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
17158 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
17159 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
17160 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
17161
17162 #undef THUMB_VARIANT
17163 #define THUMB_VARIANT & arm_ext_v6_notm
17164 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
17165 ldrexd, t_ldrexd),
17166 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
17167 RRnpcb), strexd, t_strexd),
17168
17169 #undef THUMB_VARIANT
17170 #define THUMB_VARIANT & arm_ext_v6t2
17171 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
17172 rd_rn, rd_rn),
17173 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
17174 rd_rn, rd_rn),
17175 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17176 strex, rm_rd_rn),
17177 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17178 strex, rm_rd_rn),
17179 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
17180
17181 #undef ARM_VARIANT
17182 #define ARM_VARIANT & arm_ext_sec
17183 #undef THUMB_VARIANT
17184 #define THUMB_VARIANT & arm_ext_sec
17185
17186 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
17187
17188 #undef ARM_VARIANT
17189 #define ARM_VARIANT & arm_ext_virt
17190 #undef THUMB_VARIANT
17191 #define THUMB_VARIANT & arm_ext_virt
17192
17193 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
17194 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
17195
17196 #undef ARM_VARIANT
17197 #define ARM_VARIANT & arm_ext_v6t2
17198 #undef THUMB_VARIANT
17199 #define THUMB_VARIANT & arm_ext_v6t2
17200
17201 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
17202 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
17203 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
17204 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
17205
17206 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
17207 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
17208 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
17209 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
17210
17211 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17212 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17213 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17214 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17215
17216 /* Thumb-only instructions. */
17217 #undef ARM_VARIANT
17218 #define ARM_VARIANT NULL
17219 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
17220 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
17221
17222 /* ARM does not really have an IT instruction, so always allow it.
17223 The opcode is copied from Thumb in order to allow warnings in
17224 -mimplicit-it=[never | arm] modes. */
17225 #undef ARM_VARIANT
17226 #define ARM_VARIANT & arm_ext_v1
17227
17228 TUE("it", bf08, bf08, 1, (COND), it, t_it),
17229 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
17230 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
17231 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
17232 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
17233 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
17234 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
17235 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
17236 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
17237 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
17238 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
17239 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
17240 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
17241 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
17242 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
17243 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
17244 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
17245 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
17246
17247 /* Thumb2 only instructions. */
17248 #undef ARM_VARIANT
17249 #define ARM_VARIANT NULL
17250
17251 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17252 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17253 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
17254 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
17255 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
17256 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
17257
17258 /* Hardware division instructions. */
17259 #undef ARM_VARIANT
17260 #define ARM_VARIANT & arm_ext_adiv
17261 #undef THUMB_VARIANT
17262 #define THUMB_VARIANT & arm_ext_div
17263
17264 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
17265 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
17266
17267 /* ARM V6M/V7 instructions. */
17268 #undef ARM_VARIANT
17269 #define ARM_VARIANT & arm_ext_barrier
17270 #undef THUMB_VARIANT
17271 #define THUMB_VARIANT & arm_ext_barrier
17272
17273 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, t_barrier),
17274 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, t_barrier),
17275 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, t_barrier),
17276
17277 /* ARM V7 instructions. */
17278 #undef ARM_VARIANT
17279 #define ARM_VARIANT & arm_ext_v7
17280 #undef THUMB_VARIANT
17281 #define THUMB_VARIANT & arm_ext_v7
17282
17283 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
17284 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
17285
17286 #undef ARM_VARIANT
17287 #define ARM_VARIANT & arm_ext_mp
17288 #undef THUMB_VARIANT
17289 #define THUMB_VARIANT & arm_ext_mp
17290
17291 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
17292
17293 #undef ARM_VARIANT
17294 #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
17295
17296 cCE("wfs", e200110, 1, (RR), rd),
17297 cCE("rfs", e300110, 1, (RR), rd),
17298 cCE("wfc", e400110, 1, (RR), rd),
17299 cCE("rfc", e500110, 1, (RR), rd),
17300
17301 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
17302 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
17303 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
17304 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
17305
17306 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
17307 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
17308 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
17309 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
17310
17311 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
17312 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
17313 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
17314 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
17315 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
17316 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
17317 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
17318 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
17319 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
17320 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
17321 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
17322 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
17323
17324 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
17325 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
17326 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
17327 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
17328 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
17329 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
17330 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
17331 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
17332 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
17333 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
17334 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
17335 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
17336
17337 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
17338 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
17339 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
17340 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
17341 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
17342 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
17343 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
17344 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
17345 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
17346 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
17347 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
17348 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
17349
17350 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
17351 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
17352 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
17353 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
17354 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
17355 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
17356 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
17357 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
17358 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
17359 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
17360 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
17361 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
17362
17363 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
17364 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
17365 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
17366 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
17367 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
17368 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
17369 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
17370 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
17371 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
17372 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
17373 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
17374 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
17375
17376 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
17377 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
17378 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
17379 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
17380 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
17381 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
17382 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
17383 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
17384 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
17385 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
17386 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
17387 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
17388
17389 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
17390 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
17391 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
17392 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
17393 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
17394 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
17395 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
17396 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
17397 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
17398 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
17399 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
17400 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
17401
17402 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
17403 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
17404 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
17405 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
17406 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
17407 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
17408 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
17409 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
17410 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
17411 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
17412 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
17413 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
17414
17415 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
17416 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
17417 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
17418 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
17419 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
17420 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
17421 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
17422 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
17423 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
17424 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
17425 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
17426 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
17427
17428 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
17429 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
17430 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
17431 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
17432 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
17433 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
17434 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
17435 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
17436 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
17437 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
17438 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
17439 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
17440
17441 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
17442 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
17443 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
17444 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
17445 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
17446 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
17447 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
17448 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
17449 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
17450 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
17451 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
17452 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
17453
17454 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
17455 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
17456 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
17457 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
17458 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
17459 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
17460 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
17461 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
17462 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
17463 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
17464 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
17465 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
17466
17467 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
17468 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
17469 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
17470 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
17471 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
17472 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
17473 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
17474 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
17475 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
17476 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
17477 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
17478 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
17479
17480 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
17481 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
17482 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
17483 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
17484 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
17485 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
17486 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
17487 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
17488 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
17489 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
17490 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
17491 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
17492
17493 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
17494 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
17495 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
17496 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
17497 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
17498 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
17499 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
17500 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
17501 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
17502 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
17503 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
17504 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
17505
17506 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
17507 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
17508 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
17509 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
17510 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
17511 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
17512 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
17513 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
17514 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
17515 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
17516 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
17517 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
17518
17519 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
17520 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
17521 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
17522 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
17523 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
17524 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17525 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17526 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17527 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
17528 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
17529 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
17530 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
17531
17532 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
17533 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
17534 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
17535 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
17536 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
17537 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17538 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17539 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17540 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
17541 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
17542 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
17543 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
17544
17545 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
17546 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
17547 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
17548 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
17549 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
17550 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17551 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17552 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17553 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
17554 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
17555 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
17556 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
17557
17558 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
17559 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
17560 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
17561 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
17562 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
17563 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17564 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17565 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17566 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
17567 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
17568 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
17569 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
17570
17571 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
17572 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
17573 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
17574 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
17575 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
17576 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17577 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17578 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17579 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
17580 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
17581 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
17582 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
17583
17584 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
17585 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
17586 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
17587 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
17588 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
17589 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17590 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17591 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17592 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
17593 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
17594 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
17595 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
17596
17597 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
17598 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
17599 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
17600 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
17601 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
17602 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17603 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17604 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17605 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
17606 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
17607 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
17608 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
17609
17610 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
17611 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
17612 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
17613 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
17614 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
17615 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17616 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17617 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17618 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
17619 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
17620 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
17621 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
17622
17623 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
17624 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
17625 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
17626 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
17627 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
17628 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17629 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17630 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17631 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
17632 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
17633 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
17634 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
17635
17636 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
17637 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
17638 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
17639 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
17640 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
17641 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17642 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17643 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17644 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
17645 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
17646 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
17647 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
17648
17649 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17650 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17651 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17652 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17653 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17654 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17655 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17656 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17657 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17658 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17659 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17660 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17661
17662 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17663 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17664 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17665 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17666 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17667 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17668 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17669 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17670 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17671 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17672 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17673 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17674
17675 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17676 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17677 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17678 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17679 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17680 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17681 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17682 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17683 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17684 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17685 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17686 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17687
17688 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
17689 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
17690 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
17691 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
17692
17693 cCL("flts", e000110, 2, (RF, RR), rn_rd),
17694 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
17695 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
17696 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
17697 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
17698 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
17699 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
17700 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
17701 cCL("flte", e080110, 2, (RF, RR), rn_rd),
17702 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
17703 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
17704 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
17705
17706 /* The implementation of the FIX instruction is broken on some
17707 assemblers, in that it accepts a precision specifier as well as a
17708 rounding specifier, despite the fact that this is meaningless.
17709 To be more compatible, we accept it as well, though of course it
17710 does not set any bits. */
17711 cCE("fix", e100110, 2, (RR, RF), rd_rm),
17712 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
17713 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
17714 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
17715 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
17716 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
17717 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
17718 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
17719 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
17720 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
17721 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
17722 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
17723 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
17724
17725 /* Instructions that were new with the real FPA, call them V2. */
17726 #undef ARM_VARIANT
17727 #define ARM_VARIANT & fpu_fpa_ext_v2
17728
17729 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17730 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17731 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17732 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17733 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17734 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17735
17736 #undef ARM_VARIANT
17737 #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
17738
17739 /* Moves and type conversions. */
17740 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
17741 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
17742 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
17743 cCE("fmstat", ef1fa10, 0, (), noargs),
17744 cCE("vmrs", ef10a10, 2, (APSR_RR, RVC), vmrs),
17745 cCE("vmsr", ee10a10, 2, (RVC, RR), vmsr),
17746 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
17747 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
17748 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
17749 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17750 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
17751 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17752 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
17753 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
17754
17755 /* Memory operations. */
17756 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
17757 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
17758 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17759 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17760 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17761 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17762 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17763 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17764 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
17765 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
17766 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17767 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17768 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17769 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17770 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17771 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17772 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
17773 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
17774
17775 /* Monadic operations. */
17776 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
17777 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
17778 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
17779
17780 /* Dyadic operations. */
17781 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17782 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17783 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17784 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17785 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17786 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17787 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17788 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17789 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17790
17791 /* Comparisons. */
17792 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
17793 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
17794 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
17795 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
17796
17797 /* Double precision load/store are still present on single precision
17798 implementations. */
17799 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
17800 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
17801 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17802 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17803 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
17804 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
17805 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17806 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17807 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
17808 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
17809
17810 #undef ARM_VARIANT
17811 #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
17812
17813 /* Moves and type conversions. */
17814 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17815 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17816 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17817 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
17818 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
17819 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
17820 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
17821 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17822 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
17823 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17824 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17825 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17826 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17827
17828 /* Monadic operations. */
17829 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17830 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17831 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17832
17833 /* Dyadic operations. */
17834 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17835 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17836 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17837 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17838 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17839 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17840 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17841 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17842 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17843
17844 /* Comparisons. */
17845 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17846 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
17847 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17848 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
17849
17850 #undef ARM_VARIANT
17851 #define ARM_VARIANT & fpu_vfp_ext_v2
17852
17853 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
17854 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
17855 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
17856 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
17857
17858 /* Instructions which may belong to either the Neon or VFP instruction sets.
17859 Individual encoder functions perform additional architecture checks. */
17860 #undef ARM_VARIANT
17861 #define ARM_VARIANT & fpu_vfp_ext_v1xd
17862 #undef THUMB_VARIANT
17863 #define THUMB_VARIANT & fpu_vfp_ext_v1xd
17864
17865 /* These mnemonics are unique to VFP. */
17866 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
17867 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
17868 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17869 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17870 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17871 nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
17872 nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
17873 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
17874 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
17875 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
17876
17877 /* Mnemonics shared by Neon and VFP. */
17878 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
17879 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
17880 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
17881
17882 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
17883 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
17884
17885 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17886 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17887
17888 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17889 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17890 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17891 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17892 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17893 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17894 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
17895 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
17896
17897 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
17898 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
17899 nCEF(vcvtb, _vcvt, 2, (RVS, RVS), neon_cvtb),
17900 nCEF(vcvtt, _vcvt, 2, (RVS, RVS), neon_cvtt),
17901
17902
17903 /* NOTE: All VMOV encoding is special-cased! */
17904 NCE(vmov, 0, 1, (VMOV), neon_mov),
17905 NCE(vmovq, 0, 1, (VMOV), neon_mov),
17906
17907 #undef THUMB_VARIANT
17908 #define THUMB_VARIANT & fpu_neon_ext_v1
17909 #undef ARM_VARIANT
17910 #define ARM_VARIANT & fpu_neon_ext_v1
17911
17912 /* Data processing with three registers of the same length. */
17913 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
17914 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
17915 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
17916 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17917 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17918 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17919 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17920 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17921 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17922 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
17923 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17924 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
17925 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17926 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
17927 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17928 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
17929 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17930 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
17931 /* If not immediate, fall back to neon_dyadic_i64_su.
17932 shl_imm should accept I8 I16 I32 I64,
17933 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
17934 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
17935 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
17936 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
17937 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
17938 /* Logic ops, types optional & ignored. */
17939 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17940 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17941 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17942 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17943 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17944 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17945 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17946 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17947 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
17948 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
17949 /* Bitfield ops, untyped. */
17950 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17951 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17952 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17953 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17954 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17955 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17956 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
17957 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17958 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17959 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17960 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17961 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17962 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17963 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
17964 back to neon_dyadic_if_su. */
17965 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17966 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17967 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17968 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17969 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17970 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
17971 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17972 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
17973 /* Comparison. Type I8 I16 I32 F32. */
17974 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
17975 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
17976 /* As above, D registers only. */
17977 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
17978 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
17979 /* Int and float variants, signedness unimportant. */
17980 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17981 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17982 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
17983 /* Add/sub take types I8 I16 I32 I64 F32. */
17984 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
17985 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
17986 /* vtst takes sizes 8, 16, 32. */
17987 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
17988 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
17989 /* VMUL takes I8 I16 I32 F32 P8. */
17990 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
17991 /* VQD{R}MULH takes S16 S32. */
17992 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17993 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
17994 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17995 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
17996 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17997 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
17998 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17999 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
18000 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
18001 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
18002 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
18003 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
18004 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
18005 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
18006 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
18007 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
18008
18009 /* Two address, int/float. Types S8 S16 S32 F32. */
18010 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
18011 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
18012
18013 /* Data processing with two registers and a shift amount. */
18014 /* Right shifts, and variants with rounding.
18015 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
18016 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
18017 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
18018 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
18019 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
18020 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
18021 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
18022 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
18023 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
18024 /* Shift and insert. Sizes accepted 8 16 32 64. */
18025 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
18026 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
18027 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
18028 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
18029 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
18030 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
18031 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
18032 /* Right shift immediate, saturating & narrowing, with rounding variants.
18033 Types accepted S16 S32 S64 U16 U32 U64. */
18034 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
18035 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
18036 /* As above, unsigned. Types accepted S16 S32 S64. */
18037 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
18038 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
18039 /* Right shift narrowing. Types accepted I16 I32 I64. */
18040 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
18041 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
18042 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
18043 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
18044 /* CVT with optional immediate for fixed-point variant. */
18045 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
18046
18047 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
18048 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
18049
18050 /* Data processing, three registers of different lengths. */
18051 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
18052 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
18053 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
18054 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
18055 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
18056 /* If not scalar, fall back to neon_dyadic_long.
18057 Vector types as above, scalar types S16 S32 U16 U32. */
18058 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
18059 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
18060 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
18061 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
18062 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
18063 /* Dyadic, narrowing insns. Types I16 I32 I64. */
18064 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18065 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18066 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18067 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18068 /* Saturating doubling multiplies. Types S16 S32. */
18069 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
18070 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
18071 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
18072 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
18073 S16 S32 U16 U32. */
18074 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
18075
18076 /* Extract. Size 8. */
18077 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
18078 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
18079
18080 /* Two registers, miscellaneous. */
18081 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
18082 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
18083 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
18084 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
18085 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
18086 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
18087 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
18088 /* Vector replicate. Sizes 8 16 32. */
18089 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
18090 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
18091 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
18092 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
18093 /* VMOVN. Types I16 I32 I64. */
18094 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
18095 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
18096 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
18097 /* VQMOVUN. Types S16 S32 S64. */
18098 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
18099 /* VZIP / VUZP. Sizes 8 16 32. */
18100 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
18101 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
18102 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
18103 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
18104 /* VQABS / VQNEG. Types S8 S16 S32. */
18105 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
18106 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
18107 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
18108 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
18109 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
18110 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
18111 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
18112 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
18113 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
18114 /* Reciprocal estimates. Types U32 F32. */
18115 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
18116 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
18117 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
18118 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
18119 /* VCLS. Types S8 S16 S32. */
18120 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
18121 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
18122 /* VCLZ. Types I8 I16 I32. */
18123 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
18124 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
18125 /* VCNT. Size 8. */
18126 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
18127 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
18128 /* Two address, untyped. */
18129 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
18130 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
18131 /* VTRN. Sizes 8 16 32. */
18132 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
18133 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
18134
18135 /* Table lookup. Size 8. */
18136 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
18137 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
18138
18139 #undef THUMB_VARIANT
18140 #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
18141 #undef ARM_VARIANT
18142 #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
18143
18144 /* Neon element/structure load/store. */
18145 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
18146 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
18147 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
18148 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
18149 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
18150 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
18151 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
18152 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
18153
18154 #undef THUMB_VARIANT
18155 #define THUMB_VARIANT &fpu_vfp_ext_v3xd
18156 #undef ARM_VARIANT
18157 #define ARM_VARIANT &fpu_vfp_ext_v3xd
18158 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
18159 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18160 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18161 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18162 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18163 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18164 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18165 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18166 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18167
18168 #undef THUMB_VARIANT
18169 #define THUMB_VARIANT & fpu_vfp_ext_v3
18170 #undef ARM_VARIANT
18171 #define ARM_VARIANT & fpu_vfp_ext_v3
18172
18173 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
18174 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
18175 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
18176 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
18177 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
18178 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
18179 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
18180 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
18181 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
18182
18183 #undef ARM_VARIANT
18184 #define ARM_VARIANT &fpu_vfp_ext_fma
18185 #undef THUMB_VARIANT
18186 #define THUMB_VARIANT &fpu_vfp_ext_fma
18187 /* Mnemonics shared by Neon and VFP. These are included in the
18188 VFP FMA variant; NEON and VFP FMA always includes the NEON
18189 FMA instructions. */
18190 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
18191 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
18192 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
18193 the v form should always be used. */
18194 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18195 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18196 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18197 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18198 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18199 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18200
18201 #undef THUMB_VARIANT
18202 #undef ARM_VARIANT
18203 #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
18204
18205 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18206 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18207 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18208 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18209 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18210 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18211 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
18212 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
18213
18214 #undef ARM_VARIANT
18215 #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
18216
18217 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
18218 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
18219 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
18220 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
18221 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
18222 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
18223 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
18224 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
18225 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
18226 cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18227 cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18228 cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18229 cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18230 cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18231 cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18232 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18233 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18234 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18235 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
18236 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
18237 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18238 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18239 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18240 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18241 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18242 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18243 cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn),
18244 cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn),
18245 cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn),
18246 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
18247 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
18248 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
18249 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
18250 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
18251 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
18252 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
18253 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
18254 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18255 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18256 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18257 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18258 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18259 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18260 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18261 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18262 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18263 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
18264 cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18265 cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18266 cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18267 cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18268 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18269 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18270 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18271 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18272 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18273 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18274 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18275 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18276 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18277 cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18278 cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18279 cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18280 cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18281 cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18282 cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18283 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18284 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18285 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18286 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18287 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18288 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18289 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18290 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18291 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18292 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18293 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18294 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18295 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18296 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18297 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18298 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18299 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18300 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18301 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18302 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18303 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18304 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18305 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
18306 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18307 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18308 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18309 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18310 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18311 cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18312 cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18313 cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18314 cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18315 cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18316 cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18317 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18318 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18319 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18320 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18321 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18322 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18323 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18324 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18325 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18326 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18327 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
18328 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18329 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18330 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18331 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18332 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18333 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18334 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18335 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18336 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18337 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18338 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18339 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18340 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18341 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18342 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18343 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18344 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18345 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18346 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18347 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18348 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18349 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18350 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18351 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18352 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18353 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18354 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18355 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18356 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18357 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18358 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18359 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
18360 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
18361 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
18362 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
18363 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
18364 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
18365 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18366 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18367 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18368 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
18369 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
18370 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
18371 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
18372 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
18373 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
18374 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18375 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18376 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18377 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18378 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
18379
18380 #undef ARM_VARIANT
18381 #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
18382
18383 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
18384 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
18385 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
18386 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
18387 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
18388 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
18389 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18390 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18391 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18392 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18393 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18394 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18395 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18396 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18397 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18398 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18399 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18400 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18401 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18402 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18403 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
18404 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18405 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18406 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18407 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18408 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18409 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18410 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18411 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18412 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18413 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18414 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18415 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18416 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18417 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18418 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18419 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18420 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18421 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18422 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18423 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18424 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18425 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18426 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18427 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18428 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18429 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18430 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18431 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18432 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18433 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18434 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18435 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18436 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18437 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18438 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18439 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18440
18441 #undef ARM_VARIANT
18442 #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
18443
18444 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18445 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18446 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18447 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18448 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18449 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18450 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18451 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18452 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
18453 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
18454 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
18455 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
18456 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
18457 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
18458 cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd),
18459 cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn),
18460 cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd),
18461 cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn),
18462 cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn),
18463 cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn),
18464 cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn),
18465 cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn),
18466 cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn),
18467 cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn),
18468 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
18469 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
18470 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
18471 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
18472 cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc),
18473 cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd),
18474 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
18475 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
18476 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
18477 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
18478 cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn),
18479 cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn),
18480 cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn),
18481 cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn),
18482 cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn),
18483 cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn),
18484 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
18485 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
18486 cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple),
18487 cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple),
18488 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
18489 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
18490 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
18491 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
18492 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
18493 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
18494 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
18495 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
18496 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
18497 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
18498 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
18499 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
18500 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
18501 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
18502 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
18503 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
18504 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
18505 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
18506 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
18507 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
18508 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18509 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18510 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18511 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18512 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18513 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18514 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18515 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18516 cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18517 cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18518 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
18519 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
18520 };
18521 #undef ARM_VARIANT
18522 #undef THUMB_VARIANT
18523 #undef TCE
18524 #undef TCM
18525 #undef TUE
18526 #undef TUF
18527 #undef TCC
18528 #undef cCE
18529 #undef cCL
18530 #undef C3E
18531 #undef CE
18532 #undef CM
18533 #undef UE
18534 #undef UF
18535 #undef UT
18536 #undef NUF
18537 #undef nUF
18538 #undef NCE
18539 #undef nCE
18540 #undef OPS0
18541 #undef OPS1
18542 #undef OPS2
18543 #undef OPS3
18544 #undef OPS4
18545 #undef OPS5
18546 #undef OPS6
18547 #undef do_0
18548 \f
18549 /* MD interface: bits in the object file. */
18550
18551 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
18552 for use in the a.out file, and stores them in the array pointed to by buf.
18553 This knows about the endian-ness of the target machine and does
18554 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
18555 2 (short) and 4 (long) Floating numbers are put out as a series of
18556 LITTLENUMS (shorts, here at least). */
18557
18558 void
18559 md_number_to_chars (char * buf, valueT val, int n)
18560 {
18561 if (target_big_endian)
18562 number_to_chars_bigendian (buf, val, n);
18563 else
18564 number_to_chars_littleendian (buf, val, n);
18565 }
18566
18567 static valueT
18568 md_chars_to_number (char * buf, int n)
18569 {
18570 valueT result = 0;
18571 unsigned char * where = (unsigned char *) buf;
18572
18573 if (target_big_endian)
18574 {
18575 while (n--)
18576 {
18577 result <<= 8;
18578 result |= (*where++ & 255);
18579 }
18580 }
18581 else
18582 {
18583 while (n--)
18584 {
18585 result <<= 8;
18586 result |= (where[n] & 255);
18587 }
18588 }
18589
18590 return result;
18591 }
18592
18593 /* MD interface: Sections. */
18594
18595 /* Estimate the size of a frag before relaxing. Assume everything fits in
18596 2 bytes. */
18597
18598 int
18599 md_estimate_size_before_relax (fragS * fragp,
18600 segT segtype ATTRIBUTE_UNUSED)
18601 {
18602 fragp->fr_var = 2;
18603 return 2;
18604 }
18605
18606 /* Convert a machine dependent frag. */
18607
18608 void
18609 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
18610 {
18611 unsigned long insn;
18612 unsigned long old_op;
18613 char *buf;
18614 expressionS exp;
18615 fixS *fixp;
18616 int reloc_type;
18617 int pc_rel;
18618 int opcode;
18619
18620 buf = fragp->fr_literal + fragp->fr_fix;
18621
18622 old_op = bfd_get_16(abfd, buf);
18623 if (fragp->fr_symbol)
18624 {
18625 exp.X_op = O_symbol;
18626 exp.X_add_symbol = fragp->fr_symbol;
18627 }
18628 else
18629 {
18630 exp.X_op = O_constant;
18631 }
18632 exp.X_add_number = fragp->fr_offset;
18633 opcode = fragp->fr_subtype;
18634 switch (opcode)
18635 {
18636 case T_MNEM_ldr_pc:
18637 case T_MNEM_ldr_pc2:
18638 case T_MNEM_ldr_sp:
18639 case T_MNEM_str_sp:
18640 case T_MNEM_ldr:
18641 case T_MNEM_ldrb:
18642 case T_MNEM_ldrh:
18643 case T_MNEM_str:
18644 case T_MNEM_strb:
18645 case T_MNEM_strh:
18646 if (fragp->fr_var == 4)
18647 {
18648 insn = THUMB_OP32 (opcode);
18649 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
18650 {
18651 insn |= (old_op & 0x700) << 4;
18652 }
18653 else
18654 {
18655 insn |= (old_op & 7) << 12;
18656 insn |= (old_op & 0x38) << 13;
18657 }
18658 insn |= 0x00000c00;
18659 put_thumb32_insn (buf, insn);
18660 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
18661 }
18662 else
18663 {
18664 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
18665 }
18666 pc_rel = (opcode == T_MNEM_ldr_pc2);
18667 break;
18668 case T_MNEM_adr:
18669 if (fragp->fr_var == 4)
18670 {
18671 insn = THUMB_OP32 (opcode);
18672 insn |= (old_op & 0xf0) << 4;
18673 put_thumb32_insn (buf, insn);
18674 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
18675 }
18676 else
18677 {
18678 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18679 exp.X_add_number -= 4;
18680 }
18681 pc_rel = 1;
18682 break;
18683 case T_MNEM_mov:
18684 case T_MNEM_movs:
18685 case T_MNEM_cmp:
18686 case T_MNEM_cmn:
18687 if (fragp->fr_var == 4)
18688 {
18689 int r0off = (opcode == T_MNEM_mov
18690 || opcode == T_MNEM_movs) ? 0 : 8;
18691 insn = THUMB_OP32 (opcode);
18692 insn = (insn & 0xe1ffffff) | 0x10000000;
18693 insn |= (old_op & 0x700) << r0off;
18694 put_thumb32_insn (buf, insn);
18695 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
18696 }
18697 else
18698 {
18699 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
18700 }
18701 pc_rel = 0;
18702 break;
18703 case T_MNEM_b:
18704 if (fragp->fr_var == 4)
18705 {
18706 insn = THUMB_OP32(opcode);
18707 put_thumb32_insn (buf, insn);
18708 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
18709 }
18710 else
18711 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
18712 pc_rel = 1;
18713 break;
18714 case T_MNEM_bcond:
18715 if (fragp->fr_var == 4)
18716 {
18717 insn = THUMB_OP32(opcode);
18718 insn |= (old_op & 0xf00) << 14;
18719 put_thumb32_insn (buf, insn);
18720 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
18721 }
18722 else
18723 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
18724 pc_rel = 1;
18725 break;
18726 case T_MNEM_add_sp:
18727 case T_MNEM_add_pc:
18728 case T_MNEM_inc_sp:
18729 case T_MNEM_dec_sp:
18730 if (fragp->fr_var == 4)
18731 {
18732 /* ??? Choose between add and addw. */
18733 insn = THUMB_OP32 (opcode);
18734 insn |= (old_op & 0xf0) << 4;
18735 put_thumb32_insn (buf, insn);
18736 if (opcode == T_MNEM_add_pc)
18737 reloc_type = BFD_RELOC_ARM_T32_IMM12;
18738 else
18739 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
18740 }
18741 else
18742 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18743 pc_rel = 0;
18744 break;
18745
18746 case T_MNEM_addi:
18747 case T_MNEM_addis:
18748 case T_MNEM_subi:
18749 case T_MNEM_subis:
18750 if (fragp->fr_var == 4)
18751 {
18752 insn = THUMB_OP32 (opcode);
18753 insn |= (old_op & 0xf0) << 4;
18754 insn |= (old_op & 0xf) << 16;
18755 put_thumb32_insn (buf, insn);
18756 if (insn & (1 << 20))
18757 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
18758 else
18759 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
18760 }
18761 else
18762 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18763 pc_rel = 0;
18764 break;
18765 default:
18766 abort ();
18767 }
18768 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
18769 (enum bfd_reloc_code_real) reloc_type);
18770 fixp->fx_file = fragp->fr_file;
18771 fixp->fx_line = fragp->fr_line;
18772 fragp->fr_fix += fragp->fr_var;
18773 }
18774
18775 /* Return the size of a relaxable immediate operand instruction.
18776 SHIFT and SIZE specify the form of the allowable immediate. */
18777 static int
18778 relax_immediate (fragS *fragp, int size, int shift)
18779 {
18780 offsetT offset;
18781 offsetT mask;
18782 offsetT low;
18783
18784 /* ??? Should be able to do better than this. */
18785 if (fragp->fr_symbol)
18786 return 4;
18787
18788 low = (1 << shift) - 1;
18789 mask = (1 << (shift + size)) - (1 << shift);
18790 offset = fragp->fr_offset;
18791 /* Force misaligned offsets to 32-bit variant. */
18792 if (offset & low)
18793 return 4;
18794 if (offset & ~mask)
18795 return 4;
18796 return 2;
18797 }
18798
18799 /* Get the address of a symbol during relaxation. */
18800 static addressT
18801 relaxed_symbol_addr (fragS *fragp, long stretch)
18802 {
18803 fragS *sym_frag;
18804 addressT addr;
18805 symbolS *sym;
18806
18807 sym = fragp->fr_symbol;
18808 sym_frag = symbol_get_frag (sym);
18809 know (S_GET_SEGMENT (sym) != absolute_section
18810 || sym_frag == &zero_address_frag);
18811 addr = S_GET_VALUE (sym) + fragp->fr_offset;
18812
18813 /* If frag has yet to be reached on this pass, assume it will
18814 move by STRETCH just as we did. If this is not so, it will
18815 be because some frag between grows, and that will force
18816 another pass. */
18817
18818 if (stretch != 0
18819 && sym_frag->relax_marker != fragp->relax_marker)
18820 {
18821 fragS *f;
18822
18823 /* Adjust stretch for any alignment frag. Note that if have
18824 been expanding the earlier code, the symbol may be
18825 defined in what appears to be an earlier frag. FIXME:
18826 This doesn't handle the fr_subtype field, which specifies
18827 a maximum number of bytes to skip when doing an
18828 alignment. */
18829 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
18830 {
18831 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
18832 {
18833 if (stretch < 0)
18834 stretch = - ((- stretch)
18835 & ~ ((1 << (int) f->fr_offset) - 1));
18836 else
18837 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
18838 if (stretch == 0)
18839 break;
18840 }
18841 }
18842 if (f != NULL)
18843 addr += stretch;
18844 }
18845
18846 return addr;
18847 }
18848
18849 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
18850 load. */
18851 static int
18852 relax_adr (fragS *fragp, asection *sec, long stretch)
18853 {
18854 addressT addr;
18855 offsetT val;
18856
18857 /* Assume worst case for symbols not known to be in the same section. */
18858 if (fragp->fr_symbol == NULL
18859 || !S_IS_DEFINED (fragp->fr_symbol)
18860 || sec != S_GET_SEGMENT (fragp->fr_symbol)
18861 || S_IS_WEAK (fragp->fr_symbol))
18862 return 4;
18863
18864 val = relaxed_symbol_addr (fragp, stretch);
18865 addr = fragp->fr_address + fragp->fr_fix;
18866 addr = (addr + 4) & ~3;
18867 /* Force misaligned targets to 32-bit variant. */
18868 if (val & 3)
18869 return 4;
18870 val -= addr;
18871 if (val < 0 || val > 1020)
18872 return 4;
18873 return 2;
18874 }
18875
18876 /* Return the size of a relaxable add/sub immediate instruction. */
18877 static int
18878 relax_addsub (fragS *fragp, asection *sec)
18879 {
18880 char *buf;
18881 int op;
18882
18883 buf = fragp->fr_literal + fragp->fr_fix;
18884 op = bfd_get_16(sec->owner, buf);
18885 if ((op & 0xf) == ((op >> 4) & 0xf))
18886 return relax_immediate (fragp, 8, 0);
18887 else
18888 return relax_immediate (fragp, 3, 0);
18889 }
18890
18891
18892 /* Return the size of a relaxable branch instruction. BITS is the
18893 size of the offset field in the narrow instruction. */
18894
18895 static int
18896 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
18897 {
18898 addressT addr;
18899 offsetT val;
18900 offsetT limit;
18901
18902 /* Assume worst case for symbols not known to be in the same section. */
18903 if (!S_IS_DEFINED (fragp->fr_symbol)
18904 || sec != S_GET_SEGMENT (fragp->fr_symbol)
18905 || S_IS_WEAK (fragp->fr_symbol))
18906 return 4;
18907
18908 #ifdef OBJ_ELF
18909 if (S_IS_DEFINED (fragp->fr_symbol)
18910 && ARM_IS_FUNC (fragp->fr_symbol))
18911 return 4;
18912 #endif
18913
18914 val = relaxed_symbol_addr (fragp, stretch);
18915 addr = fragp->fr_address + fragp->fr_fix + 4;
18916 val -= addr;
18917
18918 /* Offset is a signed value *2 */
18919 limit = 1 << bits;
18920 if (val >= limit || val < -limit)
18921 return 4;
18922 return 2;
18923 }
18924
18925
18926 /* Relax a machine dependent frag. This returns the amount by which
18927 the current size of the frag should change. */
18928
18929 int
18930 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
18931 {
18932 int oldsize;
18933 int newsize;
18934
18935 oldsize = fragp->fr_var;
18936 switch (fragp->fr_subtype)
18937 {
18938 case T_MNEM_ldr_pc2:
18939 newsize = relax_adr (fragp, sec, stretch);
18940 break;
18941 case T_MNEM_ldr_pc:
18942 case T_MNEM_ldr_sp:
18943 case T_MNEM_str_sp:
18944 newsize = relax_immediate (fragp, 8, 2);
18945 break;
18946 case T_MNEM_ldr:
18947 case T_MNEM_str:
18948 newsize = relax_immediate (fragp, 5, 2);
18949 break;
18950 case T_MNEM_ldrh:
18951 case T_MNEM_strh:
18952 newsize = relax_immediate (fragp, 5, 1);
18953 break;
18954 case T_MNEM_ldrb:
18955 case T_MNEM_strb:
18956 newsize = relax_immediate (fragp, 5, 0);
18957 break;
18958 case T_MNEM_adr:
18959 newsize = relax_adr (fragp, sec, stretch);
18960 break;
18961 case T_MNEM_mov:
18962 case T_MNEM_movs:
18963 case T_MNEM_cmp:
18964 case T_MNEM_cmn:
18965 newsize = relax_immediate (fragp, 8, 0);
18966 break;
18967 case T_MNEM_b:
18968 newsize = relax_branch (fragp, sec, 11, stretch);
18969 break;
18970 case T_MNEM_bcond:
18971 newsize = relax_branch (fragp, sec, 8, stretch);
18972 break;
18973 case T_MNEM_add_sp:
18974 case T_MNEM_add_pc:
18975 newsize = relax_immediate (fragp, 8, 2);
18976 break;
18977 case T_MNEM_inc_sp:
18978 case T_MNEM_dec_sp:
18979 newsize = relax_immediate (fragp, 7, 2);
18980 break;
18981 case T_MNEM_addi:
18982 case T_MNEM_addis:
18983 case T_MNEM_subi:
18984 case T_MNEM_subis:
18985 newsize = relax_addsub (fragp, sec);
18986 break;
18987 default:
18988 abort ();
18989 }
18990
18991 fragp->fr_var = newsize;
18992 /* Freeze wide instructions that are at or before the same location as
18993 in the previous pass. This avoids infinite loops.
18994 Don't freeze them unconditionally because targets may be artificially
18995 misaligned by the expansion of preceding frags. */
18996 if (stretch <= 0 && newsize > 2)
18997 {
18998 md_convert_frag (sec->owner, sec, fragp);
18999 frag_wane (fragp);
19000 }
19001
19002 return newsize - oldsize;
19003 }
19004
19005 /* Round up a section size to the appropriate boundary. */
19006
19007 valueT
19008 md_section_align (segT segment ATTRIBUTE_UNUSED,
19009 valueT size)
19010 {
19011 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
19012 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
19013 {
19014 /* For a.out, force the section size to be aligned. If we don't do
19015 this, BFD will align it for us, but it will not write out the
19016 final bytes of the section. This may be a bug in BFD, but it is
19017 easier to fix it here since that is how the other a.out targets
19018 work. */
19019 int align;
19020
19021 align = bfd_get_section_alignment (stdoutput, segment);
19022 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
19023 }
19024 #endif
19025
19026 return size;
19027 }
19028
19029 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
19030 of an rs_align_code fragment. */
19031
19032 void
19033 arm_handle_align (fragS * fragP)
19034 {
19035 static char const arm_noop[2][2][4] =
19036 {
19037 { /* ARMv1 */
19038 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
19039 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
19040 },
19041 { /* ARMv6k */
19042 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
19043 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
19044 },
19045 };
19046 static char const thumb_noop[2][2][2] =
19047 {
19048 { /* Thumb-1 */
19049 {0xc0, 0x46}, /* LE */
19050 {0x46, 0xc0}, /* BE */
19051 },
19052 { /* Thumb-2 */
19053 {0x00, 0xbf}, /* LE */
19054 {0xbf, 0x00} /* BE */
19055 }
19056 };
19057 static char const wide_thumb_noop[2][4] =
19058 { /* Wide Thumb-2 */
19059 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
19060 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
19061 };
19062
19063 unsigned bytes, fix, noop_size;
19064 char * p;
19065 const char * noop;
19066 const char *narrow_noop = NULL;
19067 #ifdef OBJ_ELF
19068 enum mstate state;
19069 #endif
19070
19071 if (fragP->fr_type != rs_align_code)
19072 return;
19073
19074 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
19075 p = fragP->fr_literal + fragP->fr_fix;
19076 fix = 0;
19077
19078 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
19079 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
19080
19081 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
19082
19083 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
19084 {
19085 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
19086 {
19087 narrow_noop = thumb_noop[1][target_big_endian];
19088 noop = wide_thumb_noop[target_big_endian];
19089 }
19090 else
19091 noop = thumb_noop[0][target_big_endian];
19092 noop_size = 2;
19093 #ifdef OBJ_ELF
19094 state = MAP_THUMB;
19095 #endif
19096 }
19097 else
19098 {
19099 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
19100 [target_big_endian];
19101 noop_size = 4;
19102 #ifdef OBJ_ELF
19103 state = MAP_ARM;
19104 #endif
19105 }
19106
19107 fragP->fr_var = noop_size;
19108
19109 if (bytes & (noop_size - 1))
19110 {
19111 fix = bytes & (noop_size - 1);
19112 #ifdef OBJ_ELF
19113 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
19114 #endif
19115 memset (p, 0, fix);
19116 p += fix;
19117 bytes -= fix;
19118 }
19119
19120 if (narrow_noop)
19121 {
19122 if (bytes & noop_size)
19123 {
19124 /* Insert a narrow noop. */
19125 memcpy (p, narrow_noop, noop_size);
19126 p += noop_size;
19127 bytes -= noop_size;
19128 fix += noop_size;
19129 }
19130
19131 /* Use wide noops for the remainder */
19132 noop_size = 4;
19133 }
19134
19135 while (bytes >= noop_size)
19136 {
19137 memcpy (p, noop, noop_size);
19138 p += noop_size;
19139 bytes -= noop_size;
19140 fix += noop_size;
19141 }
19142
19143 fragP->fr_fix += fix;
19144 }
19145
19146 /* Called from md_do_align. Used to create an alignment
19147 frag in a code section. */
19148
19149 void
19150 arm_frag_align_code (int n, int max)
19151 {
19152 char * p;
19153
19154 /* We assume that there will never be a requirement
19155 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
19156 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
19157 {
19158 char err_msg[128];
19159
19160 sprintf (err_msg,
19161 _("alignments greater than %d bytes not supported in .text sections."),
19162 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
19163 as_fatal ("%s", err_msg);
19164 }
19165
19166 p = frag_var (rs_align_code,
19167 MAX_MEM_FOR_RS_ALIGN_CODE,
19168 1,
19169 (relax_substateT) max,
19170 (symbolS *) NULL,
19171 (offsetT) n,
19172 (char *) NULL);
19173 *p = 0;
19174 }
19175
19176 /* Perform target specific initialisation of a frag.
19177 Note - despite the name this initialisation is not done when the frag
19178 is created, but only when its type is assigned. A frag can be created
19179 and used a long time before its type is set, so beware of assuming that
19180 this initialisationis performed first. */
19181
19182 #ifndef OBJ_ELF
19183 void
19184 arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
19185 {
19186 /* Record whether this frag is in an ARM or a THUMB area. */
19187 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
19188 }
19189
19190 #else /* OBJ_ELF is defined. */
19191 void
19192 arm_init_frag (fragS * fragP, int max_chars)
19193 {
19194 /* If the current ARM vs THUMB mode has not already
19195 been recorded into this frag then do so now. */
19196 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
19197 {
19198 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
19199
19200 /* Record a mapping symbol for alignment frags. We will delete this
19201 later if the alignment ends up empty. */
19202 switch (fragP->fr_type)
19203 {
19204 case rs_align:
19205 case rs_align_test:
19206 case rs_fill:
19207 mapping_state_2 (MAP_DATA, max_chars);
19208 break;
19209 case rs_align_code:
19210 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
19211 break;
19212 default:
19213 break;
19214 }
19215 }
19216 }
19217
19218 /* When we change sections we need to issue a new mapping symbol. */
19219
19220 void
19221 arm_elf_change_section (void)
19222 {
19223 /* Link an unlinked unwind index table section to the .text section. */
19224 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
19225 && elf_linked_to_section (now_seg) == NULL)
19226 elf_linked_to_section (now_seg) = text_section;
19227 }
19228
19229 int
19230 arm_elf_section_type (const char * str, size_t len)
19231 {
19232 if (len == 5 && strncmp (str, "exidx", 5) == 0)
19233 return SHT_ARM_EXIDX;
19234
19235 return -1;
19236 }
19237 \f
19238 /* Code to deal with unwinding tables. */
19239
19240 static void add_unwind_adjustsp (offsetT);
19241
19242 /* Generate any deferred unwind frame offset. */
19243
19244 static void
19245 flush_pending_unwind (void)
19246 {
19247 offsetT offset;
19248
19249 offset = unwind.pending_offset;
19250 unwind.pending_offset = 0;
19251 if (offset != 0)
19252 add_unwind_adjustsp (offset);
19253 }
19254
19255 /* Add an opcode to this list for this function. Two-byte opcodes should
19256 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
19257 order. */
19258
19259 static void
19260 add_unwind_opcode (valueT op, int length)
19261 {
19262 /* Add any deferred stack adjustment. */
19263 if (unwind.pending_offset)
19264 flush_pending_unwind ();
19265
19266 unwind.sp_restored = 0;
19267
19268 if (unwind.opcode_count + length > unwind.opcode_alloc)
19269 {
19270 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
19271 if (unwind.opcodes)
19272 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
19273 unwind.opcode_alloc);
19274 else
19275 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
19276 }
19277 while (length > 0)
19278 {
19279 length--;
19280 unwind.opcodes[unwind.opcode_count] = op & 0xff;
19281 op >>= 8;
19282 unwind.opcode_count++;
19283 }
19284 }
19285
19286 /* Add unwind opcodes to adjust the stack pointer. */
19287
19288 static void
19289 add_unwind_adjustsp (offsetT offset)
19290 {
19291 valueT op;
19292
19293 if (offset > 0x200)
19294 {
19295 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
19296 char bytes[5];
19297 int n;
19298 valueT o;
19299
19300 /* Long form: 0xb2, uleb128. */
19301 /* This might not fit in a word so add the individual bytes,
19302 remembering the list is built in reverse order. */
19303 o = (valueT) ((offset - 0x204) >> 2);
19304 if (o == 0)
19305 add_unwind_opcode (0, 1);
19306
19307 /* Calculate the uleb128 encoding of the offset. */
19308 n = 0;
19309 while (o)
19310 {
19311 bytes[n] = o & 0x7f;
19312 o >>= 7;
19313 if (o)
19314 bytes[n] |= 0x80;
19315 n++;
19316 }
19317 /* Add the insn. */
19318 for (; n; n--)
19319 add_unwind_opcode (bytes[n - 1], 1);
19320 add_unwind_opcode (0xb2, 1);
19321 }
19322 else if (offset > 0x100)
19323 {
19324 /* Two short opcodes. */
19325 add_unwind_opcode (0x3f, 1);
19326 op = (offset - 0x104) >> 2;
19327 add_unwind_opcode (op, 1);
19328 }
19329 else if (offset > 0)
19330 {
19331 /* Short opcode. */
19332 op = (offset - 4) >> 2;
19333 add_unwind_opcode (op, 1);
19334 }
19335 else if (offset < 0)
19336 {
19337 offset = -offset;
19338 while (offset > 0x100)
19339 {
19340 add_unwind_opcode (0x7f, 1);
19341 offset -= 0x100;
19342 }
19343 op = ((offset - 4) >> 2) | 0x40;
19344 add_unwind_opcode (op, 1);
19345 }
19346 }
19347
19348 /* Finish the list of unwind opcodes for this function. */
19349 static void
19350 finish_unwind_opcodes (void)
19351 {
19352 valueT op;
19353
19354 if (unwind.fp_used)
19355 {
19356 /* Adjust sp as necessary. */
19357 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
19358 flush_pending_unwind ();
19359
19360 /* After restoring sp from the frame pointer. */
19361 op = 0x90 | unwind.fp_reg;
19362 add_unwind_opcode (op, 1);
19363 }
19364 else
19365 flush_pending_unwind ();
19366 }
19367
19368
19369 /* Start an exception table entry. If idx is nonzero this is an index table
19370 entry. */
19371
19372 static void
19373 start_unwind_section (const segT text_seg, int idx)
19374 {
19375 const char * text_name;
19376 const char * prefix;
19377 const char * prefix_once;
19378 const char * group_name;
19379 size_t prefix_len;
19380 size_t text_len;
19381 char * sec_name;
19382 size_t sec_name_len;
19383 int type;
19384 int flags;
19385 int linkonce;
19386
19387 if (idx)
19388 {
19389 prefix = ELF_STRING_ARM_unwind;
19390 prefix_once = ELF_STRING_ARM_unwind_once;
19391 type = SHT_ARM_EXIDX;
19392 }
19393 else
19394 {
19395 prefix = ELF_STRING_ARM_unwind_info;
19396 prefix_once = ELF_STRING_ARM_unwind_info_once;
19397 type = SHT_PROGBITS;
19398 }
19399
19400 text_name = segment_name (text_seg);
19401 if (streq (text_name, ".text"))
19402 text_name = "";
19403
19404 if (strncmp (text_name, ".gnu.linkonce.t.",
19405 strlen (".gnu.linkonce.t.")) == 0)
19406 {
19407 prefix = prefix_once;
19408 text_name += strlen (".gnu.linkonce.t.");
19409 }
19410
19411 prefix_len = strlen (prefix);
19412 text_len = strlen (text_name);
19413 sec_name_len = prefix_len + text_len;
19414 sec_name = (char *) xmalloc (sec_name_len + 1);
19415 memcpy (sec_name, prefix, prefix_len);
19416 memcpy (sec_name + prefix_len, text_name, text_len);
19417 sec_name[prefix_len + text_len] = '\0';
19418
19419 flags = SHF_ALLOC;
19420 linkonce = 0;
19421 group_name = 0;
19422
19423 /* Handle COMDAT group. */
19424 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
19425 {
19426 group_name = elf_group_name (text_seg);
19427 if (group_name == NULL)
19428 {
19429 as_bad (_("Group section `%s' has no group signature"),
19430 segment_name (text_seg));
19431 ignore_rest_of_line ();
19432 return;
19433 }
19434 flags |= SHF_GROUP;
19435 linkonce = 1;
19436 }
19437
19438 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
19439
19440 /* Set the section link for index tables. */
19441 if (idx)
19442 elf_linked_to_section (now_seg) = text_seg;
19443 }
19444
19445
19446 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
19447 personality routine data. Returns zero, or the index table value for
19448 and inline entry. */
19449
19450 static valueT
19451 create_unwind_entry (int have_data)
19452 {
19453 int size;
19454 addressT where;
19455 char *ptr;
19456 /* The current word of data. */
19457 valueT data;
19458 /* The number of bytes left in this word. */
19459 int n;
19460
19461 finish_unwind_opcodes ();
19462
19463 /* Remember the current text section. */
19464 unwind.saved_seg = now_seg;
19465 unwind.saved_subseg = now_subseg;
19466
19467 start_unwind_section (now_seg, 0);
19468
19469 if (unwind.personality_routine == NULL)
19470 {
19471 if (unwind.personality_index == -2)
19472 {
19473 if (have_data)
19474 as_bad (_("handlerdata in cantunwind frame"));
19475 return 1; /* EXIDX_CANTUNWIND. */
19476 }
19477
19478 /* Use a default personality routine if none is specified. */
19479 if (unwind.personality_index == -1)
19480 {
19481 if (unwind.opcode_count > 3)
19482 unwind.personality_index = 1;
19483 else
19484 unwind.personality_index = 0;
19485 }
19486
19487 /* Space for the personality routine entry. */
19488 if (unwind.personality_index == 0)
19489 {
19490 if (unwind.opcode_count > 3)
19491 as_bad (_("too many unwind opcodes for personality routine 0"));
19492
19493 if (!have_data)
19494 {
19495 /* All the data is inline in the index table. */
19496 data = 0x80;
19497 n = 3;
19498 while (unwind.opcode_count > 0)
19499 {
19500 unwind.opcode_count--;
19501 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19502 n--;
19503 }
19504
19505 /* Pad with "finish" opcodes. */
19506 while (n--)
19507 data = (data << 8) | 0xb0;
19508
19509 return data;
19510 }
19511 size = 0;
19512 }
19513 else
19514 /* We get two opcodes "free" in the first word. */
19515 size = unwind.opcode_count - 2;
19516 }
19517 else
19518 /* An extra byte is required for the opcode count. */
19519 size = unwind.opcode_count + 1;
19520
19521 size = (size + 3) >> 2;
19522 if (size > 0xff)
19523 as_bad (_("too many unwind opcodes"));
19524
19525 frag_align (2, 0, 0);
19526 record_alignment (now_seg, 2);
19527 unwind.table_entry = expr_build_dot ();
19528
19529 /* Allocate the table entry. */
19530 ptr = frag_more ((size << 2) + 4);
19531 where = frag_now_fix () - ((size << 2) + 4);
19532
19533 switch (unwind.personality_index)
19534 {
19535 case -1:
19536 /* ??? Should this be a PLT generating relocation? */
19537 /* Custom personality routine. */
19538 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
19539 BFD_RELOC_ARM_PREL31);
19540
19541 where += 4;
19542 ptr += 4;
19543
19544 /* Set the first byte to the number of additional words. */
19545 data = size - 1;
19546 n = 3;
19547 break;
19548
19549 /* ABI defined personality routines. */
19550 case 0:
19551 /* Three opcodes bytes are packed into the first word. */
19552 data = 0x80;
19553 n = 3;
19554 break;
19555
19556 case 1:
19557 case 2:
19558 /* The size and first two opcode bytes go in the first word. */
19559 data = ((0x80 + unwind.personality_index) << 8) | size;
19560 n = 2;
19561 break;
19562
19563 default:
19564 /* Should never happen. */
19565 abort ();
19566 }
19567
19568 /* Pack the opcodes into words (MSB first), reversing the list at the same
19569 time. */
19570 while (unwind.opcode_count > 0)
19571 {
19572 if (n == 0)
19573 {
19574 md_number_to_chars (ptr, data, 4);
19575 ptr += 4;
19576 n = 4;
19577 data = 0;
19578 }
19579 unwind.opcode_count--;
19580 n--;
19581 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19582 }
19583
19584 /* Finish off the last word. */
19585 if (n < 4)
19586 {
19587 /* Pad with "finish" opcodes. */
19588 while (n--)
19589 data = (data << 8) | 0xb0;
19590
19591 md_number_to_chars (ptr, data, 4);
19592 }
19593
19594 if (!have_data)
19595 {
19596 /* Add an empty descriptor if there is no user-specified data. */
19597 ptr = frag_more (4);
19598 md_number_to_chars (ptr, 0, 4);
19599 }
19600
19601 return 0;
19602 }
19603
19604
19605 /* Initialize the DWARF-2 unwind information for this procedure. */
19606
19607 void
19608 tc_arm_frame_initial_instructions (void)
19609 {
19610 cfi_add_CFA_def_cfa (REG_SP, 0);
19611 }
19612 #endif /* OBJ_ELF */
19613
19614 /* Convert REGNAME to a DWARF-2 register number. */
19615
19616 int
19617 tc_arm_regname_to_dw2regnum (char *regname)
19618 {
19619 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
19620
19621 if (reg == FAIL)
19622 return -1;
19623
19624 return reg;
19625 }
19626
19627 #ifdef TE_PE
19628 void
19629 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
19630 {
19631 expressionS exp;
19632
19633 exp.X_op = O_secrel;
19634 exp.X_add_symbol = symbol;
19635 exp.X_add_number = 0;
19636 emit_expr (&exp, size);
19637 }
19638 #endif
19639
19640 /* MD interface: Symbol and relocation handling. */
19641
19642 /* Return the address within the segment that a PC-relative fixup is
19643 relative to. For ARM, PC-relative fixups applied to instructions
19644 are generally relative to the location of the fixup plus 8 bytes.
19645 Thumb branches are offset by 4, and Thumb loads relative to PC
19646 require special handling. */
19647
19648 long
19649 md_pcrel_from_section (fixS * fixP, segT seg)
19650 {
19651 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
19652
19653 /* If this is pc-relative and we are going to emit a relocation
19654 then we just want to put out any pipeline compensation that the linker
19655 will need. Otherwise we want to use the calculated base.
19656 For WinCE we skip the bias for externals as well, since this
19657 is how the MS ARM-CE assembler behaves and we want to be compatible. */
19658 if (fixP->fx_pcrel
19659 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
19660 || (arm_force_relocation (fixP)
19661 #ifdef TE_WINCE
19662 && !S_IS_EXTERNAL (fixP->fx_addsy)
19663 #endif
19664 )))
19665 base = 0;
19666
19667
19668 switch (fixP->fx_r_type)
19669 {
19670 /* PC relative addressing on the Thumb is slightly odd as the
19671 bottom two bits of the PC are forced to zero for the
19672 calculation. This happens *after* application of the
19673 pipeline offset. However, Thumb adrl already adjusts for
19674 this, so we need not do it again. */
19675 case BFD_RELOC_ARM_THUMB_ADD:
19676 return base & ~3;
19677
19678 case BFD_RELOC_ARM_THUMB_OFFSET:
19679 case BFD_RELOC_ARM_T32_OFFSET_IMM:
19680 case BFD_RELOC_ARM_T32_ADD_PC12:
19681 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
19682 return (base + 4) & ~3;
19683
19684 /* Thumb branches are simply offset by +4. */
19685 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19686 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19687 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19688 case BFD_RELOC_THUMB_PCREL_BRANCH20:
19689 case BFD_RELOC_THUMB_PCREL_BRANCH25:
19690 return base + 4;
19691
19692 case BFD_RELOC_THUMB_PCREL_BRANCH23:
19693 if (fixP->fx_addsy
19694 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19695 && (!S_IS_EXTERNAL (fixP->fx_addsy))
19696 && ARM_IS_FUNC (fixP->fx_addsy)
19697 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19698 base = fixP->fx_where + fixP->fx_frag->fr_address;
19699 return base + 4;
19700
19701 /* BLX is like branches above, but forces the low two bits of PC to
19702 zero. */
19703 case BFD_RELOC_THUMB_PCREL_BLX:
19704 if (fixP->fx_addsy
19705 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19706 && (!S_IS_EXTERNAL (fixP->fx_addsy))
19707 && THUMB_IS_FUNC (fixP->fx_addsy)
19708 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19709 base = fixP->fx_where + fixP->fx_frag->fr_address;
19710 return (base + 4) & ~3;
19711
19712 /* ARM mode branches are offset by +8. However, the Windows CE
19713 loader expects the relocation not to take this into account. */
19714 case BFD_RELOC_ARM_PCREL_BLX:
19715 if (fixP->fx_addsy
19716 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19717 && (!S_IS_EXTERNAL (fixP->fx_addsy))
19718 && ARM_IS_FUNC (fixP->fx_addsy)
19719 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19720 base = fixP->fx_where + fixP->fx_frag->fr_address;
19721 return base + 8;
19722
19723 case BFD_RELOC_ARM_PCREL_CALL:
19724 if (fixP->fx_addsy
19725 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19726 && (!S_IS_EXTERNAL (fixP->fx_addsy))
19727 && THUMB_IS_FUNC (fixP->fx_addsy)
19728 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19729 base = fixP->fx_where + fixP->fx_frag->fr_address;
19730 return base + 8;
19731
19732 case BFD_RELOC_ARM_PCREL_BRANCH:
19733 case BFD_RELOC_ARM_PCREL_JUMP:
19734 case BFD_RELOC_ARM_PLT32:
19735 #ifdef TE_WINCE
19736 /* When handling fixups immediately, because we have already
19737 discovered the value of a symbol, or the address of the frag involved
19738 we must account for the offset by +8, as the OS loader will never see the reloc.
19739 see fixup_segment() in write.c
19740 The S_IS_EXTERNAL test handles the case of global symbols.
19741 Those need the calculated base, not just the pipe compensation the linker will need. */
19742 if (fixP->fx_pcrel
19743 && fixP->fx_addsy != NULL
19744 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19745 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
19746 return base + 8;
19747 return base;
19748 #else
19749 return base + 8;
19750 #endif
19751
19752
19753 /* ARM mode loads relative to PC are also offset by +8. Unlike
19754 branches, the Windows CE loader *does* expect the relocation
19755 to take this into account. */
19756 case BFD_RELOC_ARM_OFFSET_IMM:
19757 case BFD_RELOC_ARM_OFFSET_IMM8:
19758 case BFD_RELOC_ARM_HWLITERAL:
19759 case BFD_RELOC_ARM_LITERAL:
19760 case BFD_RELOC_ARM_CP_OFF_IMM:
19761 return base + 8;
19762
19763
19764 /* Other PC-relative relocations are un-offset. */
19765 default:
19766 return base;
19767 }
19768 }
19769
19770 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
19771 Otherwise we have no need to default values of symbols. */
19772
19773 symbolS *
19774 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
19775 {
19776 #ifdef OBJ_ELF
19777 if (name[0] == '_' && name[1] == 'G'
19778 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
19779 {
19780 if (!GOT_symbol)
19781 {
19782 if (symbol_find (name))
19783 as_bad (_("GOT already in the symbol table"));
19784
19785 GOT_symbol = symbol_new (name, undefined_section,
19786 (valueT) 0, & zero_address_frag);
19787 }
19788
19789 return GOT_symbol;
19790 }
19791 #endif
19792
19793 return NULL;
19794 }
19795
19796 /* Subroutine of md_apply_fix. Check to see if an immediate can be
19797 computed as two separate immediate values, added together. We
19798 already know that this value cannot be computed by just one ARM
19799 instruction. */
19800
19801 static unsigned int
19802 validate_immediate_twopart (unsigned int val,
19803 unsigned int * highpart)
19804 {
19805 unsigned int a;
19806 unsigned int i;
19807
19808 for (i = 0; i < 32; i += 2)
19809 if (((a = rotate_left (val, i)) & 0xff) != 0)
19810 {
19811 if (a & 0xff00)
19812 {
19813 if (a & ~ 0xffff)
19814 continue;
19815 * highpart = (a >> 8) | ((i + 24) << 7);
19816 }
19817 else if (a & 0xff0000)
19818 {
19819 if (a & 0xff000000)
19820 continue;
19821 * highpart = (a >> 16) | ((i + 16) << 7);
19822 }
19823 else
19824 {
19825 gas_assert (a & 0xff000000);
19826 * highpart = (a >> 24) | ((i + 8) << 7);
19827 }
19828
19829 return (a & 0xff) | (i << 7);
19830 }
19831
19832 return FAIL;
19833 }
19834
19835 static int
19836 validate_offset_imm (unsigned int val, int hwse)
19837 {
19838 if ((hwse && val > 255) || val > 4095)
19839 return FAIL;
19840 return val;
19841 }
19842
19843 /* Subroutine of md_apply_fix. Do those data_ops which can take a
19844 negative immediate constant by altering the instruction. A bit of
19845 a hack really.
19846 MOV <-> MVN
19847 AND <-> BIC
19848 ADC <-> SBC
19849 by inverting the second operand, and
19850 ADD <-> SUB
19851 CMP <-> CMN
19852 by negating the second operand. */
19853
19854 static int
19855 negate_data_op (unsigned long * instruction,
19856 unsigned long value)
19857 {
19858 int op, new_inst;
19859 unsigned long negated, inverted;
19860
19861 negated = encode_arm_immediate (-value);
19862 inverted = encode_arm_immediate (~value);
19863
19864 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
19865 switch (op)
19866 {
19867 /* First negates. */
19868 case OPCODE_SUB: /* ADD <-> SUB */
19869 new_inst = OPCODE_ADD;
19870 value = negated;
19871 break;
19872
19873 case OPCODE_ADD:
19874 new_inst = OPCODE_SUB;
19875 value = negated;
19876 break;
19877
19878 case OPCODE_CMP: /* CMP <-> CMN */
19879 new_inst = OPCODE_CMN;
19880 value = negated;
19881 break;
19882
19883 case OPCODE_CMN:
19884 new_inst = OPCODE_CMP;
19885 value = negated;
19886 break;
19887
19888 /* Now Inverted ops. */
19889 case OPCODE_MOV: /* MOV <-> MVN */
19890 new_inst = OPCODE_MVN;
19891 value = inverted;
19892 break;
19893
19894 case OPCODE_MVN:
19895 new_inst = OPCODE_MOV;
19896 value = inverted;
19897 break;
19898
19899 case OPCODE_AND: /* AND <-> BIC */
19900 new_inst = OPCODE_BIC;
19901 value = inverted;
19902 break;
19903
19904 case OPCODE_BIC:
19905 new_inst = OPCODE_AND;
19906 value = inverted;
19907 break;
19908
19909 case OPCODE_ADC: /* ADC <-> SBC */
19910 new_inst = OPCODE_SBC;
19911 value = inverted;
19912 break;
19913
19914 case OPCODE_SBC:
19915 new_inst = OPCODE_ADC;
19916 value = inverted;
19917 break;
19918
19919 /* We cannot do anything. */
19920 default:
19921 return FAIL;
19922 }
19923
19924 if (value == (unsigned) FAIL)
19925 return FAIL;
19926
19927 *instruction &= OPCODE_MASK;
19928 *instruction |= new_inst << DATA_OP_SHIFT;
19929 return value;
19930 }
19931
19932 /* Like negate_data_op, but for Thumb-2. */
19933
19934 static unsigned int
19935 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
19936 {
19937 int op, new_inst;
19938 int rd;
19939 unsigned int negated, inverted;
19940
19941 negated = encode_thumb32_immediate (-value);
19942 inverted = encode_thumb32_immediate (~value);
19943
19944 rd = (*instruction >> 8) & 0xf;
19945 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
19946 switch (op)
19947 {
19948 /* ADD <-> SUB. Includes CMP <-> CMN. */
19949 case T2_OPCODE_SUB:
19950 new_inst = T2_OPCODE_ADD;
19951 value = negated;
19952 break;
19953
19954 case T2_OPCODE_ADD:
19955 new_inst = T2_OPCODE_SUB;
19956 value = negated;
19957 break;
19958
19959 /* ORR <-> ORN. Includes MOV <-> MVN. */
19960 case T2_OPCODE_ORR:
19961 new_inst = T2_OPCODE_ORN;
19962 value = inverted;
19963 break;
19964
19965 case T2_OPCODE_ORN:
19966 new_inst = T2_OPCODE_ORR;
19967 value = inverted;
19968 break;
19969
19970 /* AND <-> BIC. TST has no inverted equivalent. */
19971 case T2_OPCODE_AND:
19972 new_inst = T2_OPCODE_BIC;
19973 if (rd == 15)
19974 value = FAIL;
19975 else
19976 value = inverted;
19977 break;
19978
19979 case T2_OPCODE_BIC:
19980 new_inst = T2_OPCODE_AND;
19981 value = inverted;
19982 break;
19983
19984 /* ADC <-> SBC */
19985 case T2_OPCODE_ADC:
19986 new_inst = T2_OPCODE_SBC;
19987 value = inverted;
19988 break;
19989
19990 case T2_OPCODE_SBC:
19991 new_inst = T2_OPCODE_ADC;
19992 value = inverted;
19993 break;
19994
19995 /* We cannot do anything. */
19996 default:
19997 return FAIL;
19998 }
19999
20000 if (value == (unsigned int)FAIL)
20001 return FAIL;
20002
20003 *instruction &= T2_OPCODE_MASK;
20004 *instruction |= new_inst << T2_DATA_OP_SHIFT;
20005 return value;
20006 }
20007
20008 /* Read a 32-bit thumb instruction from buf. */
20009 static unsigned long
20010 get_thumb32_insn (char * buf)
20011 {
20012 unsigned long insn;
20013 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
20014 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20015
20016 return insn;
20017 }
20018
20019
20020 /* We usually want to set the low bit on the address of thumb function
20021 symbols. In particular .word foo - . should have the low bit set.
20022 Generic code tries to fold the difference of two symbols to
20023 a constant. Prevent this and force a relocation when the first symbols
20024 is a thumb function. */
20025
20026 bfd_boolean
20027 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
20028 {
20029 if (op == O_subtract
20030 && l->X_op == O_symbol
20031 && r->X_op == O_symbol
20032 && THUMB_IS_FUNC (l->X_add_symbol))
20033 {
20034 l->X_op = O_subtract;
20035 l->X_op_symbol = r->X_add_symbol;
20036 l->X_add_number -= r->X_add_number;
20037 return TRUE;
20038 }
20039
20040 /* Process as normal. */
20041 return FALSE;
20042 }
20043
20044 /* Encode Thumb2 unconditional branches and calls. The encoding
20045 for the 2 are identical for the immediate values. */
20046
20047 static void
20048 encode_thumb2_b_bl_offset (char * buf, offsetT value)
20049 {
20050 #define T2I1I2MASK ((1 << 13) | (1 << 11))
20051 offsetT newval;
20052 offsetT newval2;
20053 addressT S, I1, I2, lo, hi;
20054
20055 S = (value >> 24) & 0x01;
20056 I1 = (value >> 23) & 0x01;
20057 I2 = (value >> 22) & 0x01;
20058 hi = (value >> 12) & 0x3ff;
20059 lo = (value >> 1) & 0x7ff;
20060 newval = md_chars_to_number (buf, THUMB_SIZE);
20061 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20062 newval |= (S << 10) | hi;
20063 newval2 &= ~T2I1I2MASK;
20064 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
20065 md_number_to_chars (buf, newval, THUMB_SIZE);
20066 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20067 }
20068
20069 void
20070 md_apply_fix (fixS * fixP,
20071 valueT * valP,
20072 segT seg)
20073 {
20074 offsetT value = * valP;
20075 offsetT newval;
20076 unsigned int newimm;
20077 unsigned long temp;
20078 int sign;
20079 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
20080
20081 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
20082
20083 /* Note whether this will delete the relocation. */
20084
20085 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
20086 fixP->fx_done = 1;
20087
20088 /* On a 64-bit host, silently truncate 'value' to 32 bits for
20089 consistency with the behaviour on 32-bit hosts. Remember value
20090 for emit_reloc. */
20091 value &= 0xffffffff;
20092 value ^= 0x80000000;
20093 value -= 0x80000000;
20094
20095 *valP = value;
20096 fixP->fx_addnumber = value;
20097
20098 /* Same treatment for fixP->fx_offset. */
20099 fixP->fx_offset &= 0xffffffff;
20100 fixP->fx_offset ^= 0x80000000;
20101 fixP->fx_offset -= 0x80000000;
20102
20103 switch (fixP->fx_r_type)
20104 {
20105 case BFD_RELOC_NONE:
20106 /* This will need to go in the object file. */
20107 fixP->fx_done = 0;
20108 break;
20109
20110 case BFD_RELOC_ARM_IMMEDIATE:
20111 /* We claim that this fixup has been processed here,
20112 even if in fact we generate an error because we do
20113 not have a reloc for it, so tc_gen_reloc will reject it. */
20114 fixP->fx_done = 1;
20115
20116 if (fixP->fx_addsy)
20117 {
20118 const char *msg = 0;
20119
20120 if (! S_IS_DEFINED (fixP->fx_addsy))
20121 msg = _("undefined symbol %s used as an immediate value");
20122 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
20123 msg = _("symbol %s is in a different section");
20124 else if (S_IS_WEAK (fixP->fx_addsy))
20125 msg = _("symbol %s is weak and may be overridden later");
20126
20127 if (msg)
20128 {
20129 as_bad_where (fixP->fx_file, fixP->fx_line,
20130 msg, S_GET_NAME (fixP->fx_addsy));
20131 break;
20132 }
20133 }
20134
20135 newimm = encode_arm_immediate (value);
20136 temp = md_chars_to_number (buf, INSN_SIZE);
20137
20138 /* If the instruction will fail, see if we can fix things up by
20139 changing the opcode. */
20140 if (newimm == (unsigned int) FAIL
20141 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
20142 {
20143 as_bad_where (fixP->fx_file, fixP->fx_line,
20144 _("invalid constant (%lx) after fixup"),
20145 (unsigned long) value);
20146 break;
20147 }
20148
20149 newimm |= (temp & 0xfffff000);
20150 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
20151 break;
20152
20153 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
20154 {
20155 unsigned int highpart = 0;
20156 unsigned int newinsn = 0xe1a00000; /* nop. */
20157
20158 if (fixP->fx_addsy)
20159 {
20160 const char *msg = 0;
20161
20162 if (! S_IS_DEFINED (fixP->fx_addsy))
20163 msg = _("undefined symbol %s used as an immediate value");
20164 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
20165 msg = _("symbol %s is in a different section");
20166 else if (S_IS_WEAK (fixP->fx_addsy))
20167 msg = _("symbol %s is weak and may be overridden later");
20168
20169 if (msg)
20170 {
20171 as_bad_where (fixP->fx_file, fixP->fx_line,
20172 msg, S_GET_NAME (fixP->fx_addsy));
20173 break;
20174 }
20175 }
20176
20177 newimm = encode_arm_immediate (value);
20178 temp = md_chars_to_number (buf, INSN_SIZE);
20179
20180 /* If the instruction will fail, see if we can fix things up by
20181 changing the opcode. */
20182 if (newimm == (unsigned int) FAIL
20183 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
20184 {
20185 /* No ? OK - try using two ADD instructions to generate
20186 the value. */
20187 newimm = validate_immediate_twopart (value, & highpart);
20188
20189 /* Yes - then make sure that the second instruction is
20190 also an add. */
20191 if (newimm != (unsigned int) FAIL)
20192 newinsn = temp;
20193 /* Still No ? Try using a negated value. */
20194 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
20195 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
20196 /* Otherwise - give up. */
20197 else
20198 {
20199 as_bad_where (fixP->fx_file, fixP->fx_line,
20200 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
20201 (long) value);
20202 break;
20203 }
20204
20205 /* Replace the first operand in the 2nd instruction (which
20206 is the PC) with the destination register. We have
20207 already added in the PC in the first instruction and we
20208 do not want to do it again. */
20209 newinsn &= ~ 0xf0000;
20210 newinsn |= ((newinsn & 0x0f000) << 4);
20211 }
20212
20213 newimm |= (temp & 0xfffff000);
20214 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
20215
20216 highpart |= (newinsn & 0xfffff000);
20217 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
20218 }
20219 break;
20220
20221 case BFD_RELOC_ARM_OFFSET_IMM:
20222 if (!fixP->fx_done && seg->use_rela_p)
20223 value = 0;
20224
20225 case BFD_RELOC_ARM_LITERAL:
20226 sign = value >= 0;
20227
20228 if (value < 0)
20229 value = - value;
20230
20231 if (validate_offset_imm (value, 0) == FAIL)
20232 {
20233 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
20234 as_bad_where (fixP->fx_file, fixP->fx_line,
20235 _("invalid literal constant: pool needs to be closer"));
20236 else
20237 as_bad_where (fixP->fx_file, fixP->fx_line,
20238 _("bad immediate value for offset (%ld)"),
20239 (long) value);
20240 break;
20241 }
20242
20243 newval = md_chars_to_number (buf, INSN_SIZE);
20244 newval &= 0xff7ff000;
20245 newval |= value | (sign ? INDEX_UP : 0);
20246 md_number_to_chars (buf, newval, INSN_SIZE);
20247 break;
20248
20249 case BFD_RELOC_ARM_OFFSET_IMM8:
20250 case BFD_RELOC_ARM_HWLITERAL:
20251 sign = value >= 0;
20252
20253 if (value < 0)
20254 value = - value;
20255
20256 if (validate_offset_imm (value, 1) == FAIL)
20257 {
20258 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
20259 as_bad_where (fixP->fx_file, fixP->fx_line,
20260 _("invalid literal constant: pool needs to be closer"));
20261 else
20262 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
20263 (long) value);
20264 break;
20265 }
20266
20267 newval = md_chars_to_number (buf, INSN_SIZE);
20268 newval &= 0xff7ff0f0;
20269 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
20270 md_number_to_chars (buf, newval, INSN_SIZE);
20271 break;
20272
20273 case BFD_RELOC_ARM_T32_OFFSET_U8:
20274 if (value < 0 || value > 1020 || value % 4 != 0)
20275 as_bad_where (fixP->fx_file, fixP->fx_line,
20276 _("bad immediate value for offset (%ld)"), (long) value);
20277 value /= 4;
20278
20279 newval = md_chars_to_number (buf+2, THUMB_SIZE);
20280 newval |= value;
20281 md_number_to_chars (buf+2, newval, THUMB_SIZE);
20282 break;
20283
20284 case BFD_RELOC_ARM_T32_OFFSET_IMM:
20285 /* This is a complicated relocation used for all varieties of Thumb32
20286 load/store instruction with immediate offset:
20287
20288 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
20289 *4, optional writeback(W)
20290 (doubleword load/store)
20291
20292 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
20293 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
20294 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
20295 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
20296 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
20297
20298 Uppercase letters indicate bits that are already encoded at
20299 this point. Lowercase letters are our problem. For the
20300 second block of instructions, the secondary opcode nybble
20301 (bits 8..11) is present, and bit 23 is zero, even if this is
20302 a PC-relative operation. */
20303 newval = md_chars_to_number (buf, THUMB_SIZE);
20304 newval <<= 16;
20305 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
20306
20307 if ((newval & 0xf0000000) == 0xe0000000)
20308 {
20309 /* Doubleword load/store: 8-bit offset, scaled by 4. */
20310 if (value >= 0)
20311 newval |= (1 << 23);
20312 else
20313 value = -value;
20314 if (value % 4 != 0)
20315 {
20316 as_bad_where (fixP->fx_file, fixP->fx_line,
20317 _("offset not a multiple of 4"));
20318 break;
20319 }
20320 value /= 4;
20321 if (value > 0xff)
20322 {
20323 as_bad_where (fixP->fx_file, fixP->fx_line,
20324 _("offset out of range"));
20325 break;
20326 }
20327 newval &= ~0xff;
20328 }
20329 else if ((newval & 0x000f0000) == 0x000f0000)
20330 {
20331 /* PC-relative, 12-bit offset. */
20332 if (value >= 0)
20333 newval |= (1 << 23);
20334 else
20335 value = -value;
20336 if (value > 0xfff)
20337 {
20338 as_bad_where (fixP->fx_file, fixP->fx_line,
20339 _("offset out of range"));
20340 break;
20341 }
20342 newval &= ~0xfff;
20343 }
20344 else if ((newval & 0x00000100) == 0x00000100)
20345 {
20346 /* Writeback: 8-bit, +/- offset. */
20347 if (value >= 0)
20348 newval |= (1 << 9);
20349 else
20350 value = -value;
20351 if (value > 0xff)
20352 {
20353 as_bad_where (fixP->fx_file, fixP->fx_line,
20354 _("offset out of range"));
20355 break;
20356 }
20357 newval &= ~0xff;
20358 }
20359 else if ((newval & 0x00000f00) == 0x00000e00)
20360 {
20361 /* T-instruction: positive 8-bit offset. */
20362 if (value < 0 || value > 0xff)
20363 {
20364 as_bad_where (fixP->fx_file, fixP->fx_line,
20365 _("offset out of range"));
20366 break;
20367 }
20368 newval &= ~0xff;
20369 newval |= value;
20370 }
20371 else
20372 {
20373 /* Positive 12-bit or negative 8-bit offset. */
20374 int limit;
20375 if (value >= 0)
20376 {
20377 newval |= (1 << 23);
20378 limit = 0xfff;
20379 }
20380 else
20381 {
20382 value = -value;
20383 limit = 0xff;
20384 }
20385 if (value > limit)
20386 {
20387 as_bad_where (fixP->fx_file, fixP->fx_line,
20388 _("offset out of range"));
20389 break;
20390 }
20391 newval &= ~limit;
20392 }
20393
20394 newval |= value;
20395 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
20396 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
20397 break;
20398
20399 case BFD_RELOC_ARM_SHIFT_IMM:
20400 newval = md_chars_to_number (buf, INSN_SIZE);
20401 if (((unsigned long) value) > 32
20402 || (value == 32
20403 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
20404 {
20405 as_bad_where (fixP->fx_file, fixP->fx_line,
20406 _("shift expression is too large"));
20407 break;
20408 }
20409
20410 if (value == 0)
20411 /* Shifts of zero must be done as lsl. */
20412 newval &= ~0x60;
20413 else if (value == 32)
20414 value = 0;
20415 newval &= 0xfffff07f;
20416 newval |= (value & 0x1f) << 7;
20417 md_number_to_chars (buf, newval, INSN_SIZE);
20418 break;
20419
20420 case BFD_RELOC_ARM_T32_IMMEDIATE:
20421 case BFD_RELOC_ARM_T32_ADD_IMM:
20422 case BFD_RELOC_ARM_T32_IMM12:
20423 case BFD_RELOC_ARM_T32_ADD_PC12:
20424 /* We claim that this fixup has been processed here,
20425 even if in fact we generate an error because we do
20426 not have a reloc for it, so tc_gen_reloc will reject it. */
20427 fixP->fx_done = 1;
20428
20429 if (fixP->fx_addsy
20430 && ! S_IS_DEFINED (fixP->fx_addsy))
20431 {
20432 as_bad_where (fixP->fx_file, fixP->fx_line,
20433 _("undefined symbol %s used as an immediate value"),
20434 S_GET_NAME (fixP->fx_addsy));
20435 break;
20436 }
20437
20438 newval = md_chars_to_number (buf, THUMB_SIZE);
20439 newval <<= 16;
20440 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
20441
20442 newimm = FAIL;
20443 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
20444 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
20445 {
20446 newimm = encode_thumb32_immediate (value);
20447 if (newimm == (unsigned int) FAIL)
20448 newimm = thumb32_negate_data_op (&newval, value);
20449 }
20450 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
20451 && newimm == (unsigned int) FAIL)
20452 {
20453 /* Turn add/sum into addw/subw. */
20454 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
20455 newval = (newval & 0xfeffffff) | 0x02000000;
20456 /* No flat 12-bit imm encoding for addsw/subsw. */
20457 if ((newval & 0x00100000) == 0)
20458 {
20459 /* 12 bit immediate for addw/subw. */
20460 if (value < 0)
20461 {
20462 value = -value;
20463 newval ^= 0x00a00000;
20464 }
20465 if (value > 0xfff)
20466 newimm = (unsigned int) FAIL;
20467 else
20468 newimm = value;
20469 }
20470 }
20471
20472 if (newimm == (unsigned int)FAIL)
20473 {
20474 as_bad_where (fixP->fx_file, fixP->fx_line,
20475 _("invalid constant (%lx) after fixup"),
20476 (unsigned long) value);
20477 break;
20478 }
20479
20480 newval |= (newimm & 0x800) << 15;
20481 newval |= (newimm & 0x700) << 4;
20482 newval |= (newimm & 0x0ff);
20483
20484 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
20485 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
20486 break;
20487
20488 case BFD_RELOC_ARM_SMC:
20489 if (((unsigned long) value) > 0xffff)
20490 as_bad_where (fixP->fx_file, fixP->fx_line,
20491 _("invalid smc expression"));
20492 newval = md_chars_to_number (buf, INSN_SIZE);
20493 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
20494 md_number_to_chars (buf, newval, INSN_SIZE);
20495 break;
20496
20497 case BFD_RELOC_ARM_HVC:
20498 if (((unsigned long) value) > 0xffff)
20499 as_bad_where (fixP->fx_file, fixP->fx_line,
20500 _("invalid hvc expression"));
20501 newval = md_chars_to_number (buf, INSN_SIZE);
20502 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
20503 md_number_to_chars (buf, newval, INSN_SIZE);
20504 break;
20505
20506 case BFD_RELOC_ARM_SWI:
20507 if (fixP->tc_fix_data != 0)
20508 {
20509 if (((unsigned long) value) > 0xff)
20510 as_bad_where (fixP->fx_file, fixP->fx_line,
20511 _("invalid swi expression"));
20512 newval = md_chars_to_number (buf, THUMB_SIZE);
20513 newval |= value;
20514 md_number_to_chars (buf, newval, THUMB_SIZE);
20515 }
20516 else
20517 {
20518 if (((unsigned long) value) > 0x00ffffff)
20519 as_bad_where (fixP->fx_file, fixP->fx_line,
20520 _("invalid swi expression"));
20521 newval = md_chars_to_number (buf, INSN_SIZE);
20522 newval |= value;
20523 md_number_to_chars (buf, newval, INSN_SIZE);
20524 }
20525 break;
20526
20527 case BFD_RELOC_ARM_MULTI:
20528 if (((unsigned long) value) > 0xffff)
20529 as_bad_where (fixP->fx_file, fixP->fx_line,
20530 _("invalid expression in load/store multiple"));
20531 newval = value | md_chars_to_number (buf, INSN_SIZE);
20532 md_number_to_chars (buf, newval, INSN_SIZE);
20533 break;
20534
20535 #ifdef OBJ_ELF
20536 case BFD_RELOC_ARM_PCREL_CALL:
20537
20538 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20539 && fixP->fx_addsy
20540 && !S_IS_EXTERNAL (fixP->fx_addsy)
20541 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20542 && THUMB_IS_FUNC (fixP->fx_addsy))
20543 /* Flip the bl to blx. This is a simple flip
20544 bit here because we generate PCREL_CALL for
20545 unconditional bls. */
20546 {
20547 newval = md_chars_to_number (buf, INSN_SIZE);
20548 newval = newval | 0x10000000;
20549 md_number_to_chars (buf, newval, INSN_SIZE);
20550 temp = 1;
20551 fixP->fx_done = 1;
20552 }
20553 else
20554 temp = 3;
20555 goto arm_branch_common;
20556
20557 case BFD_RELOC_ARM_PCREL_JUMP:
20558 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20559 && fixP->fx_addsy
20560 && !S_IS_EXTERNAL (fixP->fx_addsy)
20561 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20562 && THUMB_IS_FUNC (fixP->fx_addsy))
20563 {
20564 /* This would map to a bl<cond>, b<cond>,
20565 b<always> to a Thumb function. We
20566 need to force a relocation for this particular
20567 case. */
20568 newval = md_chars_to_number (buf, INSN_SIZE);
20569 fixP->fx_done = 0;
20570 }
20571
20572 case BFD_RELOC_ARM_PLT32:
20573 #endif
20574 case BFD_RELOC_ARM_PCREL_BRANCH:
20575 temp = 3;
20576 goto arm_branch_common;
20577
20578 case BFD_RELOC_ARM_PCREL_BLX:
20579
20580 temp = 1;
20581 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20582 && fixP->fx_addsy
20583 && !S_IS_EXTERNAL (fixP->fx_addsy)
20584 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20585 && ARM_IS_FUNC (fixP->fx_addsy))
20586 {
20587 /* Flip the blx to a bl and warn. */
20588 const char *name = S_GET_NAME (fixP->fx_addsy);
20589 newval = 0xeb000000;
20590 as_warn_where (fixP->fx_file, fixP->fx_line,
20591 _("blx to '%s' an ARM ISA state function changed to bl"),
20592 name);
20593 md_number_to_chars (buf, newval, INSN_SIZE);
20594 temp = 3;
20595 fixP->fx_done = 1;
20596 }
20597
20598 #ifdef OBJ_ELF
20599 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
20600 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
20601 #endif
20602
20603 arm_branch_common:
20604 /* We are going to store value (shifted right by two) in the
20605 instruction, in a 24 bit, signed field. Bits 26 through 32 either
20606 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
20607 also be be clear. */
20608 if (value & temp)
20609 as_bad_where (fixP->fx_file, fixP->fx_line,
20610 _("misaligned branch destination"));
20611 if ((value & (offsetT)0xfe000000) != (offsetT)0
20612 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
20613 as_bad_where (fixP->fx_file, fixP->fx_line,
20614 _("branch out of range"));
20615
20616 if (fixP->fx_done || !seg->use_rela_p)
20617 {
20618 newval = md_chars_to_number (buf, INSN_SIZE);
20619 newval |= (value >> 2) & 0x00ffffff;
20620 /* Set the H bit on BLX instructions. */
20621 if (temp == 1)
20622 {
20623 if (value & 2)
20624 newval |= 0x01000000;
20625 else
20626 newval &= ~0x01000000;
20627 }
20628 md_number_to_chars (buf, newval, INSN_SIZE);
20629 }
20630 break;
20631
20632 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
20633 /* CBZ can only branch forward. */
20634
20635 /* Attempts to use CBZ to branch to the next instruction
20636 (which, strictly speaking, are prohibited) will be turned into
20637 no-ops.
20638
20639 FIXME: It may be better to remove the instruction completely and
20640 perform relaxation. */
20641 if (value == -2)
20642 {
20643 newval = md_chars_to_number (buf, THUMB_SIZE);
20644 newval = 0xbf00; /* NOP encoding T1 */
20645 md_number_to_chars (buf, newval, THUMB_SIZE);
20646 }
20647 else
20648 {
20649 if (value & ~0x7e)
20650 as_bad_where (fixP->fx_file, fixP->fx_line,
20651 _("branch out of range"));
20652
20653 if (fixP->fx_done || !seg->use_rela_p)
20654 {
20655 newval = md_chars_to_number (buf, THUMB_SIZE);
20656 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
20657 md_number_to_chars (buf, newval, THUMB_SIZE);
20658 }
20659 }
20660 break;
20661
20662 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
20663 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
20664 as_bad_where (fixP->fx_file, fixP->fx_line,
20665 _("branch out of range"));
20666
20667 if (fixP->fx_done || !seg->use_rela_p)
20668 {
20669 newval = md_chars_to_number (buf, THUMB_SIZE);
20670 newval |= (value & 0x1ff) >> 1;
20671 md_number_to_chars (buf, newval, THUMB_SIZE);
20672 }
20673 break;
20674
20675 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
20676 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
20677 as_bad_where (fixP->fx_file, fixP->fx_line,
20678 _("branch out of range"));
20679
20680 if (fixP->fx_done || !seg->use_rela_p)
20681 {
20682 newval = md_chars_to_number (buf, THUMB_SIZE);
20683 newval |= (value & 0xfff) >> 1;
20684 md_number_to_chars (buf, newval, THUMB_SIZE);
20685 }
20686 break;
20687
20688 case BFD_RELOC_THUMB_PCREL_BRANCH20:
20689 if (fixP->fx_addsy
20690 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20691 && !S_IS_EXTERNAL (fixP->fx_addsy)
20692 && S_IS_DEFINED (fixP->fx_addsy)
20693 && ARM_IS_FUNC (fixP->fx_addsy)
20694 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20695 {
20696 /* Force a relocation for a branch 20 bits wide. */
20697 fixP->fx_done = 0;
20698 }
20699 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
20700 as_bad_where (fixP->fx_file, fixP->fx_line,
20701 _("conditional branch out of range"));
20702
20703 if (fixP->fx_done || !seg->use_rela_p)
20704 {
20705 offsetT newval2;
20706 addressT S, J1, J2, lo, hi;
20707
20708 S = (value & 0x00100000) >> 20;
20709 J2 = (value & 0x00080000) >> 19;
20710 J1 = (value & 0x00040000) >> 18;
20711 hi = (value & 0x0003f000) >> 12;
20712 lo = (value & 0x00000ffe) >> 1;
20713
20714 newval = md_chars_to_number (buf, THUMB_SIZE);
20715 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20716 newval |= (S << 10) | hi;
20717 newval2 |= (J1 << 13) | (J2 << 11) | lo;
20718 md_number_to_chars (buf, newval, THUMB_SIZE);
20719 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20720 }
20721 break;
20722
20723 case BFD_RELOC_THUMB_PCREL_BLX:
20724
20725 /* If there is a blx from a thumb state function to
20726 another thumb function flip this to a bl and warn
20727 about it. */
20728
20729 if (fixP->fx_addsy
20730 && S_IS_DEFINED (fixP->fx_addsy)
20731 && !S_IS_EXTERNAL (fixP->fx_addsy)
20732 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20733 && THUMB_IS_FUNC (fixP->fx_addsy))
20734 {
20735 const char *name = S_GET_NAME (fixP->fx_addsy);
20736 as_warn_where (fixP->fx_file, fixP->fx_line,
20737 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
20738 name);
20739 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20740 newval = newval | 0x1000;
20741 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20742 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20743 fixP->fx_done = 1;
20744 }
20745
20746
20747 goto thumb_bl_common;
20748
20749 case BFD_RELOC_THUMB_PCREL_BRANCH23:
20750
20751 /* A bl from Thumb state ISA to an internal ARM state function
20752 is converted to a blx. */
20753 if (fixP->fx_addsy
20754 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20755 && !S_IS_EXTERNAL (fixP->fx_addsy)
20756 && S_IS_DEFINED (fixP->fx_addsy)
20757 && ARM_IS_FUNC (fixP->fx_addsy)
20758 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20759 {
20760 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20761 newval = newval & ~0x1000;
20762 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20763 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
20764 fixP->fx_done = 1;
20765 }
20766
20767 thumb_bl_common:
20768
20769 #ifdef OBJ_ELF
20770 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 &&
20771 fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20772 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20773 #endif
20774
20775 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20776 /* For a BLX instruction, make sure that the relocation is rounded up
20777 to a word boundary. This follows the semantics of the instruction
20778 which specifies that bit 1 of the target address will come from bit
20779 1 of the base address. */
20780 value = (value + 1) & ~ 1;
20781
20782
20783 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
20784 {
20785 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
20786 {
20787 as_bad_where (fixP->fx_file, fixP->fx_line,
20788 _("branch out of range"));
20789 }
20790 else if ((value & ~0x1ffffff)
20791 && ((value & ~0x1ffffff) != ~0x1ffffff))
20792 {
20793 as_bad_where (fixP->fx_file, fixP->fx_line,
20794 _("Thumb2 branch out of range"));
20795 }
20796 }
20797
20798 if (fixP->fx_done || !seg->use_rela_p)
20799 encode_thumb2_b_bl_offset (buf, value);
20800
20801 break;
20802
20803 case BFD_RELOC_THUMB_PCREL_BRANCH25:
20804 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
20805 as_bad_where (fixP->fx_file, fixP->fx_line,
20806 _("branch out of range"));
20807
20808 if (fixP->fx_done || !seg->use_rela_p)
20809 encode_thumb2_b_bl_offset (buf, value);
20810
20811 break;
20812
20813 case BFD_RELOC_8:
20814 if (fixP->fx_done || !seg->use_rela_p)
20815 md_number_to_chars (buf, value, 1);
20816 break;
20817
20818 case BFD_RELOC_16:
20819 if (fixP->fx_done || !seg->use_rela_p)
20820 md_number_to_chars (buf, value, 2);
20821 break;
20822
20823 #ifdef OBJ_ELF
20824 case BFD_RELOC_ARM_TLS_GD32:
20825 case BFD_RELOC_ARM_TLS_LE32:
20826 case BFD_RELOC_ARM_TLS_IE32:
20827 case BFD_RELOC_ARM_TLS_LDM32:
20828 case BFD_RELOC_ARM_TLS_LDO32:
20829 S_SET_THREAD_LOCAL (fixP->fx_addsy);
20830 /* fall through */
20831
20832 case BFD_RELOC_ARM_GOT32:
20833 case BFD_RELOC_ARM_GOTOFF:
20834 if (fixP->fx_done || !seg->use_rela_p)
20835 md_number_to_chars (buf, 0, 4);
20836 break;
20837
20838 case BFD_RELOC_ARM_GOT_PREL:
20839 if (fixP->fx_done || !seg->use_rela_p)
20840 md_number_to_chars (buf, value, 4);
20841 break;
20842
20843 case BFD_RELOC_ARM_TARGET2:
20844 /* TARGET2 is not partial-inplace, so we need to write the
20845 addend here for REL targets, because it won't be written out
20846 during reloc processing later. */
20847 if (fixP->fx_done || !seg->use_rela_p)
20848 md_number_to_chars (buf, fixP->fx_offset, 4);
20849 break;
20850 #endif
20851
20852 case BFD_RELOC_RVA:
20853 case BFD_RELOC_32:
20854 case BFD_RELOC_ARM_TARGET1:
20855 case BFD_RELOC_ARM_ROSEGREL32:
20856 case BFD_RELOC_ARM_SBREL32:
20857 case BFD_RELOC_32_PCREL:
20858 #ifdef TE_PE
20859 case BFD_RELOC_32_SECREL:
20860 #endif
20861 if (fixP->fx_done || !seg->use_rela_p)
20862 #ifdef TE_WINCE
20863 /* For WinCE we only do this for pcrel fixups. */
20864 if (fixP->fx_done || fixP->fx_pcrel)
20865 #endif
20866 md_number_to_chars (buf, value, 4);
20867 break;
20868
20869 #ifdef OBJ_ELF
20870 case BFD_RELOC_ARM_PREL31:
20871 if (fixP->fx_done || !seg->use_rela_p)
20872 {
20873 newval = md_chars_to_number (buf, 4) & 0x80000000;
20874 if ((value ^ (value >> 1)) & 0x40000000)
20875 {
20876 as_bad_where (fixP->fx_file, fixP->fx_line,
20877 _("rel31 relocation overflow"));
20878 }
20879 newval |= value & 0x7fffffff;
20880 md_number_to_chars (buf, newval, 4);
20881 }
20882 break;
20883 #endif
20884
20885 case BFD_RELOC_ARM_CP_OFF_IMM:
20886 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
20887 if (value < -1023 || value > 1023 || (value & 3))
20888 as_bad_where (fixP->fx_file, fixP->fx_line,
20889 _("co-processor offset out of range"));
20890 cp_off_common:
20891 sign = value >= 0;
20892 if (value < 0)
20893 value = -value;
20894 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20895 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20896 newval = md_chars_to_number (buf, INSN_SIZE);
20897 else
20898 newval = get_thumb32_insn (buf);
20899 newval &= 0xff7fff00;
20900 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
20901 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20902 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20903 md_number_to_chars (buf, newval, INSN_SIZE);
20904 else
20905 put_thumb32_insn (buf, newval);
20906 break;
20907
20908 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
20909 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
20910 if (value < -255 || value > 255)
20911 as_bad_where (fixP->fx_file, fixP->fx_line,
20912 _("co-processor offset out of range"));
20913 value *= 4;
20914 goto cp_off_common;
20915
20916 case BFD_RELOC_ARM_THUMB_OFFSET:
20917 newval = md_chars_to_number (buf, THUMB_SIZE);
20918 /* Exactly what ranges, and where the offset is inserted depends
20919 on the type of instruction, we can establish this from the
20920 top 4 bits. */
20921 switch (newval >> 12)
20922 {
20923 case 4: /* PC load. */
20924 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
20925 forced to zero for these loads; md_pcrel_from has already
20926 compensated for this. */
20927 if (value & 3)
20928 as_bad_where (fixP->fx_file, fixP->fx_line,
20929 _("invalid offset, target not word aligned (0x%08lX)"),
20930 (((unsigned long) fixP->fx_frag->fr_address
20931 + (unsigned long) fixP->fx_where) & ~3)
20932 + (unsigned long) value);
20933
20934 if (value & ~0x3fc)
20935 as_bad_where (fixP->fx_file, fixP->fx_line,
20936 _("invalid offset, value too big (0x%08lX)"),
20937 (long) value);
20938
20939 newval |= value >> 2;
20940 break;
20941
20942 case 9: /* SP load/store. */
20943 if (value & ~0x3fc)
20944 as_bad_where (fixP->fx_file, fixP->fx_line,
20945 _("invalid offset, value too big (0x%08lX)"),
20946 (long) value);
20947 newval |= value >> 2;
20948 break;
20949
20950 case 6: /* Word load/store. */
20951 if (value & ~0x7c)
20952 as_bad_where (fixP->fx_file, fixP->fx_line,
20953 _("invalid offset, value too big (0x%08lX)"),
20954 (long) value);
20955 newval |= value << 4; /* 6 - 2. */
20956 break;
20957
20958 case 7: /* Byte load/store. */
20959 if (value & ~0x1f)
20960 as_bad_where (fixP->fx_file, fixP->fx_line,
20961 _("invalid offset, value too big (0x%08lX)"),
20962 (long) value);
20963 newval |= value << 6;
20964 break;
20965
20966 case 8: /* Halfword load/store. */
20967 if (value & ~0x3e)
20968 as_bad_where (fixP->fx_file, fixP->fx_line,
20969 _("invalid offset, value too big (0x%08lX)"),
20970 (long) value);
20971 newval |= value << 5; /* 6 - 1. */
20972 break;
20973
20974 default:
20975 as_bad_where (fixP->fx_file, fixP->fx_line,
20976 "Unable to process relocation for thumb opcode: %lx",
20977 (unsigned long) newval);
20978 break;
20979 }
20980 md_number_to_chars (buf, newval, THUMB_SIZE);
20981 break;
20982
20983 case BFD_RELOC_ARM_THUMB_ADD:
20984 /* This is a complicated relocation, since we use it for all of
20985 the following immediate relocations:
20986
20987 3bit ADD/SUB
20988 8bit ADD/SUB
20989 9bit ADD/SUB SP word-aligned
20990 10bit ADD PC/SP word-aligned
20991
20992 The type of instruction being processed is encoded in the
20993 instruction field:
20994
20995 0x8000 SUB
20996 0x00F0 Rd
20997 0x000F Rs
20998 */
20999 newval = md_chars_to_number (buf, THUMB_SIZE);
21000 {
21001 int rd = (newval >> 4) & 0xf;
21002 int rs = newval & 0xf;
21003 int subtract = !!(newval & 0x8000);
21004
21005 /* Check for HI regs, only very restricted cases allowed:
21006 Adjusting SP, and using PC or SP to get an address. */
21007 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
21008 || (rs > 7 && rs != REG_SP && rs != REG_PC))
21009 as_bad_where (fixP->fx_file, fixP->fx_line,
21010 _("invalid Hi register with immediate"));
21011
21012 /* If value is negative, choose the opposite instruction. */
21013 if (value < 0)
21014 {
21015 value = -value;
21016 subtract = !subtract;
21017 if (value < 0)
21018 as_bad_where (fixP->fx_file, fixP->fx_line,
21019 _("immediate value out of range"));
21020 }
21021
21022 if (rd == REG_SP)
21023 {
21024 if (value & ~0x1fc)
21025 as_bad_where (fixP->fx_file, fixP->fx_line,
21026 _("invalid immediate for stack address calculation"));
21027 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
21028 newval |= value >> 2;
21029 }
21030 else if (rs == REG_PC || rs == REG_SP)
21031 {
21032 if (subtract || value & ~0x3fc)
21033 as_bad_where (fixP->fx_file, fixP->fx_line,
21034 _("invalid immediate for address calculation (value = 0x%08lX)"),
21035 (unsigned long) value);
21036 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
21037 newval |= rd << 8;
21038 newval |= value >> 2;
21039 }
21040 else if (rs == rd)
21041 {
21042 if (value & ~0xff)
21043 as_bad_where (fixP->fx_file, fixP->fx_line,
21044 _("immediate value out of range"));
21045 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
21046 newval |= (rd << 8) | value;
21047 }
21048 else
21049 {
21050 if (value & ~0x7)
21051 as_bad_where (fixP->fx_file, fixP->fx_line,
21052 _("immediate value out of range"));
21053 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
21054 newval |= rd | (rs << 3) | (value << 6);
21055 }
21056 }
21057 md_number_to_chars (buf, newval, THUMB_SIZE);
21058 break;
21059
21060 case BFD_RELOC_ARM_THUMB_IMM:
21061 newval = md_chars_to_number (buf, THUMB_SIZE);
21062 if (value < 0 || value > 255)
21063 as_bad_where (fixP->fx_file, fixP->fx_line,
21064 _("invalid immediate: %ld is out of range"),
21065 (long) value);
21066 newval |= value;
21067 md_number_to_chars (buf, newval, THUMB_SIZE);
21068 break;
21069
21070 case BFD_RELOC_ARM_THUMB_SHIFT:
21071 /* 5bit shift value (0..32). LSL cannot take 32. */
21072 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
21073 temp = newval & 0xf800;
21074 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
21075 as_bad_where (fixP->fx_file, fixP->fx_line,
21076 _("invalid shift value: %ld"), (long) value);
21077 /* Shifts of zero must be encoded as LSL. */
21078 if (value == 0)
21079 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
21080 /* Shifts of 32 are encoded as zero. */
21081 else if (value == 32)
21082 value = 0;
21083 newval |= value << 6;
21084 md_number_to_chars (buf, newval, THUMB_SIZE);
21085 break;
21086
21087 case BFD_RELOC_VTABLE_INHERIT:
21088 case BFD_RELOC_VTABLE_ENTRY:
21089 fixP->fx_done = 0;
21090 return;
21091
21092 case BFD_RELOC_ARM_MOVW:
21093 case BFD_RELOC_ARM_MOVT:
21094 case BFD_RELOC_ARM_THUMB_MOVW:
21095 case BFD_RELOC_ARM_THUMB_MOVT:
21096 if (fixP->fx_done || !seg->use_rela_p)
21097 {
21098 /* REL format relocations are limited to a 16-bit addend. */
21099 if (!fixP->fx_done)
21100 {
21101 if (value < -0x8000 || value > 0x7fff)
21102 as_bad_where (fixP->fx_file, fixP->fx_line,
21103 _("offset out of range"));
21104 }
21105 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
21106 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
21107 {
21108 value >>= 16;
21109 }
21110
21111 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
21112 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
21113 {
21114 newval = get_thumb32_insn (buf);
21115 newval &= 0xfbf08f00;
21116 newval |= (value & 0xf000) << 4;
21117 newval |= (value & 0x0800) << 15;
21118 newval |= (value & 0x0700) << 4;
21119 newval |= (value & 0x00ff);
21120 put_thumb32_insn (buf, newval);
21121 }
21122 else
21123 {
21124 newval = md_chars_to_number (buf, 4);
21125 newval &= 0xfff0f000;
21126 newval |= value & 0x0fff;
21127 newval |= (value & 0xf000) << 4;
21128 md_number_to_chars (buf, newval, 4);
21129 }
21130 }
21131 return;
21132
21133 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21134 case BFD_RELOC_ARM_ALU_PC_G0:
21135 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21136 case BFD_RELOC_ARM_ALU_PC_G1:
21137 case BFD_RELOC_ARM_ALU_PC_G2:
21138 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21139 case BFD_RELOC_ARM_ALU_SB_G0:
21140 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21141 case BFD_RELOC_ARM_ALU_SB_G1:
21142 case BFD_RELOC_ARM_ALU_SB_G2:
21143 gas_assert (!fixP->fx_done);
21144 if (!seg->use_rela_p)
21145 {
21146 bfd_vma insn;
21147 bfd_vma encoded_addend;
21148 bfd_vma addend_abs = abs (value);
21149
21150 /* Check that the absolute value of the addend can be
21151 expressed as an 8-bit constant plus a rotation. */
21152 encoded_addend = encode_arm_immediate (addend_abs);
21153 if (encoded_addend == (unsigned int) FAIL)
21154 as_bad_where (fixP->fx_file, fixP->fx_line,
21155 _("the offset 0x%08lX is not representable"),
21156 (unsigned long) addend_abs);
21157
21158 /* Extract the instruction. */
21159 insn = md_chars_to_number (buf, INSN_SIZE);
21160
21161 /* If the addend is positive, use an ADD instruction.
21162 Otherwise use a SUB. Take care not to destroy the S bit. */
21163 insn &= 0xff1fffff;
21164 if (value < 0)
21165 insn |= 1 << 22;
21166 else
21167 insn |= 1 << 23;
21168
21169 /* Place the encoded addend into the first 12 bits of the
21170 instruction. */
21171 insn &= 0xfffff000;
21172 insn |= encoded_addend;
21173
21174 /* Update the instruction. */
21175 md_number_to_chars (buf, insn, INSN_SIZE);
21176 }
21177 break;
21178
21179 case BFD_RELOC_ARM_LDR_PC_G0:
21180 case BFD_RELOC_ARM_LDR_PC_G1:
21181 case BFD_RELOC_ARM_LDR_PC_G2:
21182 case BFD_RELOC_ARM_LDR_SB_G0:
21183 case BFD_RELOC_ARM_LDR_SB_G1:
21184 case BFD_RELOC_ARM_LDR_SB_G2:
21185 gas_assert (!fixP->fx_done);
21186 if (!seg->use_rela_p)
21187 {
21188 bfd_vma insn;
21189 bfd_vma addend_abs = abs (value);
21190
21191 /* Check that the absolute value of the addend can be
21192 encoded in 12 bits. */
21193 if (addend_abs >= 0x1000)
21194 as_bad_where (fixP->fx_file, fixP->fx_line,
21195 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
21196 (unsigned long) addend_abs);
21197
21198 /* Extract the instruction. */
21199 insn = md_chars_to_number (buf, INSN_SIZE);
21200
21201 /* If the addend is negative, clear bit 23 of the instruction.
21202 Otherwise set it. */
21203 if (value < 0)
21204 insn &= ~(1 << 23);
21205 else
21206 insn |= 1 << 23;
21207
21208 /* Place the absolute value of the addend into the first 12 bits
21209 of the instruction. */
21210 insn &= 0xfffff000;
21211 insn |= addend_abs;
21212
21213 /* Update the instruction. */
21214 md_number_to_chars (buf, insn, INSN_SIZE);
21215 }
21216 break;
21217
21218 case BFD_RELOC_ARM_LDRS_PC_G0:
21219 case BFD_RELOC_ARM_LDRS_PC_G1:
21220 case BFD_RELOC_ARM_LDRS_PC_G2:
21221 case BFD_RELOC_ARM_LDRS_SB_G0:
21222 case BFD_RELOC_ARM_LDRS_SB_G1:
21223 case BFD_RELOC_ARM_LDRS_SB_G2:
21224 gas_assert (!fixP->fx_done);
21225 if (!seg->use_rela_p)
21226 {
21227 bfd_vma insn;
21228 bfd_vma addend_abs = abs (value);
21229
21230 /* Check that the absolute value of the addend can be
21231 encoded in 8 bits. */
21232 if (addend_abs >= 0x100)
21233 as_bad_where (fixP->fx_file, fixP->fx_line,
21234 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
21235 (unsigned long) addend_abs);
21236
21237 /* Extract the instruction. */
21238 insn = md_chars_to_number (buf, INSN_SIZE);
21239
21240 /* If the addend is negative, clear bit 23 of the instruction.
21241 Otherwise set it. */
21242 if (value < 0)
21243 insn &= ~(1 << 23);
21244 else
21245 insn |= 1 << 23;
21246
21247 /* Place the first four bits of the absolute value of the addend
21248 into the first 4 bits of the instruction, and the remaining
21249 four into bits 8 .. 11. */
21250 insn &= 0xfffff0f0;
21251 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
21252
21253 /* Update the instruction. */
21254 md_number_to_chars (buf, insn, INSN_SIZE);
21255 }
21256 break;
21257
21258 case BFD_RELOC_ARM_LDC_PC_G0:
21259 case BFD_RELOC_ARM_LDC_PC_G1:
21260 case BFD_RELOC_ARM_LDC_PC_G2:
21261 case BFD_RELOC_ARM_LDC_SB_G0:
21262 case BFD_RELOC_ARM_LDC_SB_G1:
21263 case BFD_RELOC_ARM_LDC_SB_G2:
21264 gas_assert (!fixP->fx_done);
21265 if (!seg->use_rela_p)
21266 {
21267 bfd_vma insn;
21268 bfd_vma addend_abs = abs (value);
21269
21270 /* Check that the absolute value of the addend is a multiple of
21271 four and, when divided by four, fits in 8 bits. */
21272 if (addend_abs & 0x3)
21273 as_bad_where (fixP->fx_file, fixP->fx_line,
21274 _("bad offset 0x%08lX (must be word-aligned)"),
21275 (unsigned long) addend_abs);
21276
21277 if ((addend_abs >> 2) > 0xff)
21278 as_bad_where (fixP->fx_file, fixP->fx_line,
21279 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
21280 (unsigned long) addend_abs);
21281
21282 /* Extract the instruction. */
21283 insn = md_chars_to_number (buf, INSN_SIZE);
21284
21285 /* If the addend is negative, clear bit 23 of the instruction.
21286 Otherwise set it. */
21287 if (value < 0)
21288 insn &= ~(1 << 23);
21289 else
21290 insn |= 1 << 23;
21291
21292 /* Place the addend (divided by four) into the first eight
21293 bits of the instruction. */
21294 insn &= 0xfffffff0;
21295 insn |= addend_abs >> 2;
21296
21297 /* Update the instruction. */
21298 md_number_to_chars (buf, insn, INSN_SIZE);
21299 }
21300 break;
21301
21302 case BFD_RELOC_ARM_V4BX:
21303 /* This will need to go in the object file. */
21304 fixP->fx_done = 0;
21305 break;
21306
21307 case BFD_RELOC_UNUSED:
21308 default:
21309 as_bad_where (fixP->fx_file, fixP->fx_line,
21310 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
21311 }
21312 }
21313
21314 /* Translate internal representation of relocation info to BFD target
21315 format. */
21316
21317 arelent *
21318 tc_gen_reloc (asection *section, fixS *fixp)
21319 {
21320 arelent * reloc;
21321 bfd_reloc_code_real_type code;
21322
21323 reloc = (arelent *) xmalloc (sizeof (arelent));
21324
21325 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
21326 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
21327 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
21328
21329 if (fixp->fx_pcrel)
21330 {
21331 if (section->use_rela_p)
21332 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
21333 else
21334 fixp->fx_offset = reloc->address;
21335 }
21336 reloc->addend = fixp->fx_offset;
21337
21338 switch (fixp->fx_r_type)
21339 {
21340 case BFD_RELOC_8:
21341 if (fixp->fx_pcrel)
21342 {
21343 code = BFD_RELOC_8_PCREL;
21344 break;
21345 }
21346
21347 case BFD_RELOC_16:
21348 if (fixp->fx_pcrel)
21349 {
21350 code = BFD_RELOC_16_PCREL;
21351 break;
21352 }
21353
21354 case BFD_RELOC_32:
21355 if (fixp->fx_pcrel)
21356 {
21357 code = BFD_RELOC_32_PCREL;
21358 break;
21359 }
21360
21361 case BFD_RELOC_ARM_MOVW:
21362 if (fixp->fx_pcrel)
21363 {
21364 code = BFD_RELOC_ARM_MOVW_PCREL;
21365 break;
21366 }
21367
21368 case BFD_RELOC_ARM_MOVT:
21369 if (fixp->fx_pcrel)
21370 {
21371 code = BFD_RELOC_ARM_MOVT_PCREL;
21372 break;
21373 }
21374
21375 case BFD_RELOC_ARM_THUMB_MOVW:
21376 if (fixp->fx_pcrel)
21377 {
21378 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
21379 break;
21380 }
21381
21382 case BFD_RELOC_ARM_THUMB_MOVT:
21383 if (fixp->fx_pcrel)
21384 {
21385 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
21386 break;
21387 }
21388
21389 case BFD_RELOC_NONE:
21390 case BFD_RELOC_ARM_PCREL_BRANCH:
21391 case BFD_RELOC_ARM_PCREL_BLX:
21392 case BFD_RELOC_RVA:
21393 case BFD_RELOC_THUMB_PCREL_BRANCH7:
21394 case BFD_RELOC_THUMB_PCREL_BRANCH9:
21395 case BFD_RELOC_THUMB_PCREL_BRANCH12:
21396 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21397 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21398 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21399 case BFD_RELOC_VTABLE_ENTRY:
21400 case BFD_RELOC_VTABLE_INHERIT:
21401 #ifdef TE_PE
21402 case BFD_RELOC_32_SECREL:
21403 #endif
21404 code = fixp->fx_r_type;
21405 break;
21406
21407 case BFD_RELOC_THUMB_PCREL_BLX:
21408 #ifdef OBJ_ELF
21409 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
21410 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
21411 else
21412 #endif
21413 code = BFD_RELOC_THUMB_PCREL_BLX;
21414 break;
21415
21416 case BFD_RELOC_ARM_LITERAL:
21417 case BFD_RELOC_ARM_HWLITERAL:
21418 /* If this is called then the a literal has
21419 been referenced across a section boundary. */
21420 as_bad_where (fixp->fx_file, fixp->fx_line,
21421 _("literal referenced across section boundary"));
21422 return NULL;
21423
21424 #ifdef OBJ_ELF
21425 case BFD_RELOC_ARM_GOT32:
21426 case BFD_RELOC_ARM_GOTOFF:
21427 case BFD_RELOC_ARM_GOT_PREL:
21428 case BFD_RELOC_ARM_PLT32:
21429 case BFD_RELOC_ARM_TARGET1:
21430 case BFD_RELOC_ARM_ROSEGREL32:
21431 case BFD_RELOC_ARM_SBREL32:
21432 case BFD_RELOC_ARM_PREL31:
21433 case BFD_RELOC_ARM_TARGET2:
21434 case BFD_RELOC_ARM_TLS_LE32:
21435 case BFD_RELOC_ARM_TLS_LDO32:
21436 case BFD_RELOC_ARM_PCREL_CALL:
21437 case BFD_RELOC_ARM_PCREL_JUMP:
21438 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21439 case BFD_RELOC_ARM_ALU_PC_G0:
21440 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21441 case BFD_RELOC_ARM_ALU_PC_G1:
21442 case BFD_RELOC_ARM_ALU_PC_G2:
21443 case BFD_RELOC_ARM_LDR_PC_G0:
21444 case BFD_RELOC_ARM_LDR_PC_G1:
21445 case BFD_RELOC_ARM_LDR_PC_G2:
21446 case BFD_RELOC_ARM_LDRS_PC_G0:
21447 case BFD_RELOC_ARM_LDRS_PC_G1:
21448 case BFD_RELOC_ARM_LDRS_PC_G2:
21449 case BFD_RELOC_ARM_LDC_PC_G0:
21450 case BFD_RELOC_ARM_LDC_PC_G1:
21451 case BFD_RELOC_ARM_LDC_PC_G2:
21452 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21453 case BFD_RELOC_ARM_ALU_SB_G0:
21454 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21455 case BFD_RELOC_ARM_ALU_SB_G1:
21456 case BFD_RELOC_ARM_ALU_SB_G2:
21457 case BFD_RELOC_ARM_LDR_SB_G0:
21458 case BFD_RELOC_ARM_LDR_SB_G1:
21459 case BFD_RELOC_ARM_LDR_SB_G2:
21460 case BFD_RELOC_ARM_LDRS_SB_G0:
21461 case BFD_RELOC_ARM_LDRS_SB_G1:
21462 case BFD_RELOC_ARM_LDRS_SB_G2:
21463 case BFD_RELOC_ARM_LDC_SB_G0:
21464 case BFD_RELOC_ARM_LDC_SB_G1:
21465 case BFD_RELOC_ARM_LDC_SB_G2:
21466 case BFD_RELOC_ARM_V4BX:
21467 code = fixp->fx_r_type;
21468 break;
21469
21470 case BFD_RELOC_ARM_TLS_GD32:
21471 case BFD_RELOC_ARM_TLS_IE32:
21472 case BFD_RELOC_ARM_TLS_LDM32:
21473 /* BFD will include the symbol's address in the addend.
21474 But we don't want that, so subtract it out again here. */
21475 if (!S_IS_COMMON (fixp->fx_addsy))
21476 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
21477 code = fixp->fx_r_type;
21478 break;
21479 #endif
21480
21481 case BFD_RELOC_ARM_IMMEDIATE:
21482 as_bad_where (fixp->fx_file, fixp->fx_line,
21483 _("internal relocation (type: IMMEDIATE) not fixed up"));
21484 return NULL;
21485
21486 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
21487 as_bad_where (fixp->fx_file, fixp->fx_line,
21488 _("ADRL used for a symbol not defined in the same file"));
21489 return NULL;
21490
21491 case BFD_RELOC_ARM_OFFSET_IMM:
21492 if (section->use_rela_p)
21493 {
21494 code = fixp->fx_r_type;
21495 break;
21496 }
21497
21498 if (fixp->fx_addsy != NULL
21499 && !S_IS_DEFINED (fixp->fx_addsy)
21500 && S_IS_LOCAL (fixp->fx_addsy))
21501 {
21502 as_bad_where (fixp->fx_file, fixp->fx_line,
21503 _("undefined local label `%s'"),
21504 S_GET_NAME (fixp->fx_addsy));
21505 return NULL;
21506 }
21507
21508 as_bad_where (fixp->fx_file, fixp->fx_line,
21509 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
21510 return NULL;
21511
21512 default:
21513 {
21514 char * type;
21515
21516 switch (fixp->fx_r_type)
21517 {
21518 case BFD_RELOC_NONE: type = "NONE"; break;
21519 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
21520 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
21521 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
21522 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
21523 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
21524 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
21525 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
21526 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
21527 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
21528 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
21529 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
21530 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
21531 default: type = _("<unknown>"); break;
21532 }
21533 as_bad_where (fixp->fx_file, fixp->fx_line,
21534 _("cannot represent %s relocation in this object file format"),
21535 type);
21536 return NULL;
21537 }
21538 }
21539
21540 #ifdef OBJ_ELF
21541 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
21542 && GOT_symbol
21543 && fixp->fx_addsy == GOT_symbol)
21544 {
21545 code = BFD_RELOC_ARM_GOTPC;
21546 reloc->addend = fixp->fx_offset = reloc->address;
21547 }
21548 #endif
21549
21550 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
21551
21552 if (reloc->howto == NULL)
21553 {
21554 as_bad_where (fixp->fx_file, fixp->fx_line,
21555 _("cannot represent %s relocation in this object file format"),
21556 bfd_get_reloc_code_name (code));
21557 return NULL;
21558 }
21559
21560 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
21561 vtable entry to be used in the relocation's section offset. */
21562 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
21563 reloc->address = fixp->fx_offset;
21564
21565 return reloc;
21566 }
21567
21568 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
21569
21570 void
21571 cons_fix_new_arm (fragS * frag,
21572 int where,
21573 int size,
21574 expressionS * exp)
21575 {
21576 bfd_reloc_code_real_type type;
21577 int pcrel = 0;
21578
21579 /* Pick a reloc.
21580 FIXME: @@ Should look at CPU word size. */
21581 switch (size)
21582 {
21583 case 1:
21584 type = BFD_RELOC_8;
21585 break;
21586 case 2:
21587 type = BFD_RELOC_16;
21588 break;
21589 case 4:
21590 default:
21591 type = BFD_RELOC_32;
21592 break;
21593 case 8:
21594 type = BFD_RELOC_64;
21595 break;
21596 }
21597
21598 #ifdef TE_PE
21599 if (exp->X_op == O_secrel)
21600 {
21601 exp->X_op = O_symbol;
21602 type = BFD_RELOC_32_SECREL;
21603 }
21604 #endif
21605
21606 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
21607 }
21608
21609 #if defined (OBJ_COFF)
21610 void
21611 arm_validate_fix (fixS * fixP)
21612 {
21613 /* If the destination of the branch is a defined symbol which does not have
21614 the THUMB_FUNC attribute, then we must be calling a function which has
21615 the (interfacearm) attribute. We look for the Thumb entry point to that
21616 function and change the branch to refer to that function instead. */
21617 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
21618 && fixP->fx_addsy != NULL
21619 && S_IS_DEFINED (fixP->fx_addsy)
21620 && ! THUMB_IS_FUNC (fixP->fx_addsy))
21621 {
21622 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
21623 }
21624 }
21625 #endif
21626
21627
21628 int
21629 arm_force_relocation (struct fix * fixp)
21630 {
21631 #if defined (OBJ_COFF) && defined (TE_PE)
21632 if (fixp->fx_r_type == BFD_RELOC_RVA)
21633 return 1;
21634 #endif
21635
21636 /* In case we have a call or a branch to a function in ARM ISA mode from
21637 a thumb function or vice-versa force the relocation. These relocations
21638 are cleared off for some cores that might have blx and simple transformations
21639 are possible. */
21640
21641 #ifdef OBJ_ELF
21642 switch (fixp->fx_r_type)
21643 {
21644 case BFD_RELOC_ARM_PCREL_JUMP:
21645 case BFD_RELOC_ARM_PCREL_CALL:
21646 case BFD_RELOC_THUMB_PCREL_BLX:
21647 if (THUMB_IS_FUNC (fixp->fx_addsy))
21648 return 1;
21649 break;
21650
21651 case BFD_RELOC_ARM_PCREL_BLX:
21652 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21653 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21654 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21655 if (ARM_IS_FUNC (fixp->fx_addsy))
21656 return 1;
21657 break;
21658
21659 default:
21660 break;
21661 }
21662 #endif
21663
21664 /* Resolve these relocations even if the symbol is extern or weak. */
21665 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
21666 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
21667 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
21668 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
21669 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
21670 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
21671 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
21672 return 0;
21673
21674 /* Always leave these relocations for the linker. */
21675 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21676 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21677 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
21678 return 1;
21679
21680 /* Always generate relocations against function symbols. */
21681 if (fixp->fx_r_type == BFD_RELOC_32
21682 && fixp->fx_addsy
21683 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
21684 return 1;
21685
21686 return generic_force_reloc (fixp);
21687 }
21688
21689 #if defined (OBJ_ELF) || defined (OBJ_COFF)
21690 /* Relocations against function names must be left unadjusted,
21691 so that the linker can use this information to generate interworking
21692 stubs. The MIPS version of this function
21693 also prevents relocations that are mips-16 specific, but I do not
21694 know why it does this.
21695
21696 FIXME:
21697 There is one other problem that ought to be addressed here, but
21698 which currently is not: Taking the address of a label (rather
21699 than a function) and then later jumping to that address. Such
21700 addresses also ought to have their bottom bit set (assuming that
21701 they reside in Thumb code), but at the moment they will not. */
21702
21703 bfd_boolean
21704 arm_fix_adjustable (fixS * fixP)
21705 {
21706 if (fixP->fx_addsy == NULL)
21707 return 1;
21708
21709 /* Preserve relocations against symbols with function type. */
21710 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
21711 return FALSE;
21712
21713 if (THUMB_IS_FUNC (fixP->fx_addsy)
21714 && fixP->fx_subsy == NULL)
21715 return FALSE;
21716
21717 /* We need the symbol name for the VTABLE entries. */
21718 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
21719 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
21720 return FALSE;
21721
21722 /* Don't allow symbols to be discarded on GOT related relocs. */
21723 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
21724 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
21725 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
21726 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
21727 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
21728 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
21729 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
21730 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
21731 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
21732 return FALSE;
21733
21734 /* Similarly for group relocations. */
21735 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21736 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21737 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
21738 return FALSE;
21739
21740 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
21741 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
21742 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
21743 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
21744 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
21745 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
21746 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
21747 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
21748 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
21749 return FALSE;
21750
21751 return TRUE;
21752 }
21753 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
21754
21755 #ifdef OBJ_ELF
21756
21757 const char *
21758 elf32_arm_target_format (void)
21759 {
21760 #ifdef TE_SYMBIAN
21761 return (target_big_endian
21762 ? "elf32-bigarm-symbian"
21763 : "elf32-littlearm-symbian");
21764 #elif defined (TE_VXWORKS)
21765 return (target_big_endian
21766 ? "elf32-bigarm-vxworks"
21767 : "elf32-littlearm-vxworks");
21768 #else
21769 if (target_big_endian)
21770 return "elf32-bigarm";
21771 else
21772 return "elf32-littlearm";
21773 #endif
21774 }
21775
21776 void
21777 armelf_frob_symbol (symbolS * symp,
21778 int * puntp)
21779 {
21780 elf_frob_symbol (symp, puntp);
21781 }
21782 #endif
21783
21784 /* MD interface: Finalization. */
21785
21786 void
21787 arm_cleanup (void)
21788 {
21789 literal_pool * pool;
21790
21791 /* Ensure that all the IT blocks are properly closed. */
21792 check_it_blocks_finished ();
21793
21794 for (pool = list_of_pools; pool; pool = pool->next)
21795 {
21796 /* Put it at the end of the relevant section. */
21797 subseg_set (pool->section, pool->sub_section);
21798 #ifdef OBJ_ELF
21799 arm_elf_change_section ();
21800 #endif
21801 s_ltorg (0);
21802 }
21803 }
21804
21805 #ifdef OBJ_ELF
21806 /* Remove any excess mapping symbols generated for alignment frags in
21807 SEC. We may have created a mapping symbol before a zero byte
21808 alignment; remove it if there's a mapping symbol after the
21809 alignment. */
21810 static void
21811 check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
21812 void *dummy ATTRIBUTE_UNUSED)
21813 {
21814 segment_info_type *seginfo = seg_info (sec);
21815 fragS *fragp;
21816
21817 if (seginfo == NULL || seginfo->frchainP == NULL)
21818 return;
21819
21820 for (fragp = seginfo->frchainP->frch_root;
21821 fragp != NULL;
21822 fragp = fragp->fr_next)
21823 {
21824 symbolS *sym = fragp->tc_frag_data.last_map;
21825 fragS *next = fragp->fr_next;
21826
21827 /* Variable-sized frags have been converted to fixed size by
21828 this point. But if this was variable-sized to start with,
21829 there will be a fixed-size frag after it. So don't handle
21830 next == NULL. */
21831 if (sym == NULL || next == NULL)
21832 continue;
21833
21834 if (S_GET_VALUE (sym) < next->fr_address)
21835 /* Not at the end of this frag. */
21836 continue;
21837 know (S_GET_VALUE (sym) == next->fr_address);
21838
21839 do
21840 {
21841 if (next->tc_frag_data.first_map != NULL)
21842 {
21843 /* Next frag starts with a mapping symbol. Discard this
21844 one. */
21845 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21846 break;
21847 }
21848
21849 if (next->fr_next == NULL)
21850 {
21851 /* This mapping symbol is at the end of the section. Discard
21852 it. */
21853 know (next->fr_fix == 0 && next->fr_var == 0);
21854 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21855 break;
21856 }
21857
21858 /* As long as we have empty frags without any mapping symbols,
21859 keep looking. */
21860 /* If the next frag is non-empty and does not start with a
21861 mapping symbol, then this mapping symbol is required. */
21862 if (next->fr_address != next->fr_next->fr_address)
21863 break;
21864
21865 next = next->fr_next;
21866 }
21867 while (next != NULL);
21868 }
21869 }
21870 #endif
21871
21872 /* Adjust the symbol table. This marks Thumb symbols as distinct from
21873 ARM ones. */
21874
21875 void
21876 arm_adjust_symtab (void)
21877 {
21878 #ifdef OBJ_COFF
21879 symbolS * sym;
21880
21881 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
21882 {
21883 if (ARM_IS_THUMB (sym))
21884 {
21885 if (THUMB_IS_FUNC (sym))
21886 {
21887 /* Mark the symbol as a Thumb function. */
21888 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
21889 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
21890 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
21891
21892 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
21893 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
21894 else
21895 as_bad (_("%s: unexpected function type: %d"),
21896 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
21897 }
21898 else switch (S_GET_STORAGE_CLASS (sym))
21899 {
21900 case C_EXT:
21901 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
21902 break;
21903 case C_STAT:
21904 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
21905 break;
21906 case C_LABEL:
21907 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
21908 break;
21909 default:
21910 /* Do nothing. */
21911 break;
21912 }
21913 }
21914
21915 if (ARM_IS_INTERWORK (sym))
21916 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
21917 }
21918 #endif
21919 #ifdef OBJ_ELF
21920 symbolS * sym;
21921 char bind;
21922
21923 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
21924 {
21925 if (ARM_IS_THUMB (sym))
21926 {
21927 elf_symbol_type * elf_sym;
21928
21929 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
21930 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
21931
21932 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
21933 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
21934 {
21935 /* If it's a .thumb_func, declare it as so,
21936 otherwise tag label as .code 16. */
21937 if (THUMB_IS_FUNC (sym))
21938 elf_sym->internal_elf_sym.st_info =
21939 ELF_ST_INFO (bind, STT_ARM_TFUNC);
21940 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
21941 elf_sym->internal_elf_sym.st_info =
21942 ELF_ST_INFO (bind, STT_ARM_16BIT);
21943 }
21944 }
21945 }
21946
21947 /* Remove any overlapping mapping symbols generated by alignment frags. */
21948 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
21949 #endif
21950 }
21951
21952 /* MD interface: Initialization. */
21953
21954 static void
21955 set_constant_flonums (void)
21956 {
21957 int i;
21958
21959 for (i = 0; i < NUM_FLOAT_VALS; i++)
21960 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
21961 abort ();
21962 }
21963
21964 /* Auto-select Thumb mode if it's the only available instruction set for the
21965 given architecture. */
21966
21967 static void
21968 autoselect_thumb_from_cpu_variant (void)
21969 {
21970 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
21971 opcode_select (16);
21972 }
21973
21974 void
21975 md_begin (void)
21976 {
21977 unsigned mach;
21978 unsigned int i;
21979
21980 if ( (arm_ops_hsh = hash_new ()) == NULL
21981 || (arm_cond_hsh = hash_new ()) == NULL
21982 || (arm_shift_hsh = hash_new ()) == NULL
21983 || (arm_psr_hsh = hash_new ()) == NULL
21984 || (arm_v7m_psr_hsh = hash_new ()) == NULL
21985 || (arm_reg_hsh = hash_new ()) == NULL
21986 || (arm_reloc_hsh = hash_new ()) == NULL
21987 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
21988 as_fatal (_("virtual memory exhausted"));
21989
21990 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
21991 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
21992 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
21993 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
21994 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
21995 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
21996 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
21997 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
21998 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
21999 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
22000 (void *) (v7m_psrs + i));
22001 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
22002 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
22003 for (i = 0;
22004 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
22005 i++)
22006 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
22007 (void *) (barrier_opt_names + i));
22008 #ifdef OBJ_ELF
22009 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
22010 hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i));
22011 #endif
22012
22013 set_constant_flonums ();
22014
22015 /* Set the cpu variant based on the command-line options. We prefer
22016 -mcpu= over -march= if both are set (as for GCC); and we prefer
22017 -mfpu= over any other way of setting the floating point unit.
22018 Use of legacy options with new options are faulted. */
22019 if (legacy_cpu)
22020 {
22021 if (mcpu_cpu_opt || march_cpu_opt)
22022 as_bad (_("use of old and new-style options to set CPU type"));
22023
22024 mcpu_cpu_opt = legacy_cpu;
22025 }
22026 else if (!mcpu_cpu_opt)
22027 mcpu_cpu_opt = march_cpu_opt;
22028
22029 if (legacy_fpu)
22030 {
22031 if (mfpu_opt)
22032 as_bad (_("use of old and new-style options to set FPU type"));
22033
22034 mfpu_opt = legacy_fpu;
22035 }
22036 else if (!mfpu_opt)
22037 {
22038 #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
22039 || defined (TE_NetBSD) || defined (TE_VXWORKS))
22040 /* Some environments specify a default FPU. If they don't, infer it
22041 from the processor. */
22042 if (mcpu_fpu_opt)
22043 mfpu_opt = mcpu_fpu_opt;
22044 else
22045 mfpu_opt = march_fpu_opt;
22046 #else
22047 mfpu_opt = &fpu_default;
22048 #endif
22049 }
22050
22051 if (!mfpu_opt)
22052 {
22053 if (mcpu_cpu_opt != NULL)
22054 mfpu_opt = &fpu_default;
22055 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
22056 mfpu_opt = &fpu_arch_vfp_v2;
22057 else
22058 mfpu_opt = &fpu_arch_fpa;
22059 }
22060
22061 #ifdef CPU_DEFAULT
22062 if (!mcpu_cpu_opt)
22063 {
22064 mcpu_cpu_opt = &cpu_default;
22065 selected_cpu = cpu_default;
22066 }
22067 #else
22068 if (mcpu_cpu_opt)
22069 selected_cpu = *mcpu_cpu_opt;
22070 else
22071 mcpu_cpu_opt = &arm_arch_any;
22072 #endif
22073
22074 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
22075
22076 autoselect_thumb_from_cpu_variant ();
22077
22078 arm_arch_used = thumb_arch_used = arm_arch_none;
22079
22080 #if defined OBJ_COFF || defined OBJ_ELF
22081 {
22082 unsigned int flags = 0;
22083
22084 #if defined OBJ_ELF
22085 flags = meabi_flags;
22086
22087 switch (meabi_flags)
22088 {
22089 case EF_ARM_EABI_UNKNOWN:
22090 #endif
22091 /* Set the flags in the private structure. */
22092 if (uses_apcs_26) flags |= F_APCS26;
22093 if (support_interwork) flags |= F_INTERWORK;
22094 if (uses_apcs_float) flags |= F_APCS_FLOAT;
22095 if (pic_code) flags |= F_PIC;
22096 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
22097 flags |= F_SOFT_FLOAT;
22098
22099 switch (mfloat_abi_opt)
22100 {
22101 case ARM_FLOAT_ABI_SOFT:
22102 case ARM_FLOAT_ABI_SOFTFP:
22103 flags |= F_SOFT_FLOAT;
22104 break;
22105
22106 case ARM_FLOAT_ABI_HARD:
22107 if (flags & F_SOFT_FLOAT)
22108 as_bad (_("hard-float conflicts with specified fpu"));
22109 break;
22110 }
22111
22112 /* Using pure-endian doubles (even if soft-float). */
22113 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
22114 flags |= F_VFP_FLOAT;
22115
22116 #if defined OBJ_ELF
22117 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
22118 flags |= EF_ARM_MAVERICK_FLOAT;
22119 break;
22120
22121 case EF_ARM_EABI_VER4:
22122 case EF_ARM_EABI_VER5:
22123 /* No additional flags to set. */
22124 break;
22125
22126 default:
22127 abort ();
22128 }
22129 #endif
22130 bfd_set_private_flags (stdoutput, flags);
22131
22132 /* We have run out flags in the COFF header to encode the
22133 status of ATPCS support, so instead we create a dummy,
22134 empty, debug section called .arm.atpcs. */
22135 if (atpcs)
22136 {
22137 asection * sec;
22138
22139 sec = bfd_make_section (stdoutput, ".arm.atpcs");
22140
22141 if (sec != NULL)
22142 {
22143 bfd_set_section_flags
22144 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
22145 bfd_set_section_size (stdoutput, sec, 0);
22146 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
22147 }
22148 }
22149 }
22150 #endif
22151
22152 /* Record the CPU type as well. */
22153 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
22154 mach = bfd_mach_arm_iWMMXt2;
22155 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
22156 mach = bfd_mach_arm_iWMMXt;
22157 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
22158 mach = bfd_mach_arm_XScale;
22159 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
22160 mach = bfd_mach_arm_ep9312;
22161 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
22162 mach = bfd_mach_arm_5TE;
22163 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
22164 {
22165 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
22166 mach = bfd_mach_arm_5T;
22167 else
22168 mach = bfd_mach_arm_5;
22169 }
22170 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
22171 {
22172 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
22173 mach = bfd_mach_arm_4T;
22174 else
22175 mach = bfd_mach_arm_4;
22176 }
22177 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
22178 mach = bfd_mach_arm_3M;
22179 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
22180 mach = bfd_mach_arm_3;
22181 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
22182 mach = bfd_mach_arm_2a;
22183 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
22184 mach = bfd_mach_arm_2;
22185 else
22186 mach = bfd_mach_arm_unknown;
22187
22188 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
22189 }
22190
22191 /* Command line processing. */
22192
22193 /* md_parse_option
22194 Invocation line includes a switch not recognized by the base assembler.
22195 See if it's a processor-specific option.
22196
22197 This routine is somewhat complicated by the need for backwards
22198 compatibility (since older releases of gcc can't be changed).
22199 The new options try to make the interface as compatible as
22200 possible with GCC.
22201
22202 New options (supported) are:
22203
22204 -mcpu=<cpu name> Assemble for selected processor
22205 -march=<architecture name> Assemble for selected architecture
22206 -mfpu=<fpu architecture> Assemble for selected FPU.
22207 -EB/-mbig-endian Big-endian
22208 -EL/-mlittle-endian Little-endian
22209 -k Generate PIC code
22210 -mthumb Start in Thumb mode
22211 -mthumb-interwork Code supports ARM/Thumb interworking
22212
22213 -m[no-]warn-deprecated Warn about deprecated features
22214
22215 For now we will also provide support for:
22216
22217 -mapcs-32 32-bit Program counter
22218 -mapcs-26 26-bit Program counter
22219 -macps-float Floats passed in FP registers
22220 -mapcs-reentrant Reentrant code
22221 -matpcs
22222 (sometime these will probably be replaced with -mapcs=<list of options>
22223 and -matpcs=<list of options>)
22224
22225 The remaining options are only supported for back-wards compatibility.
22226 Cpu variants, the arm part is optional:
22227 -m[arm]1 Currently not supported.
22228 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
22229 -m[arm]3 Arm 3 processor
22230 -m[arm]6[xx], Arm 6 processors
22231 -m[arm]7[xx][t][[d]m] Arm 7 processors
22232 -m[arm]8[10] Arm 8 processors
22233 -m[arm]9[20][tdmi] Arm 9 processors
22234 -mstrongarm[110[0]] StrongARM processors
22235 -mxscale XScale processors
22236 -m[arm]v[2345[t[e]]] Arm architectures
22237 -mall All (except the ARM1)
22238 FP variants:
22239 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
22240 -mfpe-old (No float load/store multiples)
22241 -mvfpxd VFP Single precision
22242 -mvfp All VFP
22243 -mno-fpu Disable all floating point instructions
22244
22245 The following CPU names are recognized:
22246 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
22247 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
22248 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
22249 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
22250 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
22251 arm10t arm10e, arm1020t, arm1020e, arm10200e,
22252 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
22253
22254 */
22255
22256 const char * md_shortopts = "m:k";
22257
22258 #ifdef ARM_BI_ENDIAN
22259 #define OPTION_EB (OPTION_MD_BASE + 0)
22260 #define OPTION_EL (OPTION_MD_BASE + 1)
22261 #else
22262 #if TARGET_BYTES_BIG_ENDIAN
22263 #define OPTION_EB (OPTION_MD_BASE + 0)
22264 #else
22265 #define OPTION_EL (OPTION_MD_BASE + 1)
22266 #endif
22267 #endif
22268 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
22269
22270 struct option md_longopts[] =
22271 {
22272 #ifdef OPTION_EB
22273 {"EB", no_argument, NULL, OPTION_EB},
22274 #endif
22275 #ifdef OPTION_EL
22276 {"EL", no_argument, NULL, OPTION_EL},
22277 #endif
22278 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
22279 {NULL, no_argument, NULL, 0}
22280 };
22281
22282 size_t md_longopts_size = sizeof (md_longopts);
22283
22284 struct arm_option_table
22285 {
22286 char *option; /* Option name to match. */
22287 char *help; /* Help information. */
22288 int *var; /* Variable to change. */
22289 int value; /* What to change it to. */
22290 char *deprecated; /* If non-null, print this message. */
22291 };
22292
22293 struct arm_option_table arm_opts[] =
22294 {
22295 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
22296 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
22297 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
22298 &support_interwork, 1, NULL},
22299 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
22300 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
22301 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
22302 1, NULL},
22303 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
22304 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
22305 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
22306 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
22307 NULL},
22308
22309 /* These are recognized by the assembler, but have no affect on code. */
22310 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
22311 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
22312
22313 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
22314 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
22315 &warn_on_deprecated, 0, NULL},
22316 {NULL, NULL, NULL, 0, NULL}
22317 };
22318
22319 struct arm_legacy_option_table
22320 {
22321 char *option; /* Option name to match. */
22322 const arm_feature_set **var; /* Variable to change. */
22323 const arm_feature_set value; /* What to change it to. */
22324 char *deprecated; /* If non-null, print this message. */
22325 };
22326
22327 const struct arm_legacy_option_table arm_legacy_opts[] =
22328 {
22329 /* DON'T add any new processors to this list -- we want the whole list
22330 to go away... Add them to the processors table instead. */
22331 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22332 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22333 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22334 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22335 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22336 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22337 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22338 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22339 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22340 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22341 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22342 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22343 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22344 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22345 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22346 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22347 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22348 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22349 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22350 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22351 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22352 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22353 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22354 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22355 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22356 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22357 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22358 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22359 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22360 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22361 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22362 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22363 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22364 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22365 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22366 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22367 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22368 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22369 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22370 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22371 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22372 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22373 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22374 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22375 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22376 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22377 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22378 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22379 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22380 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22381 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22382 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22383 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22384 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22385 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22386 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22387 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22388 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22389 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22390 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22391 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22392 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22393 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22394 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22395 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22396 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22397 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22398 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22399 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
22400 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
22401 N_("use -mcpu=strongarm110")},
22402 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
22403 N_("use -mcpu=strongarm1100")},
22404 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
22405 N_("use -mcpu=strongarm1110")},
22406 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
22407 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
22408 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
22409
22410 /* Architecture variants -- don't add any more to this list either. */
22411 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22412 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22413 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22414 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22415 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22416 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22417 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22418 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22419 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22420 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22421 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22422 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22423 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22424 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22425 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22426 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22427 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
22428 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
22429
22430 /* Floating point variants -- don't add any more to this list either. */
22431 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
22432 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
22433 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
22434 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
22435 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
22436
22437 {NULL, NULL, ARM_ARCH_NONE, NULL}
22438 };
22439
22440 struct arm_cpu_option_table
22441 {
22442 char *name;
22443 const arm_feature_set value;
22444 /* For some CPUs we assume an FPU unless the user explicitly sets
22445 -mfpu=... */
22446 const arm_feature_set default_fpu;
22447 /* The canonical name of the CPU, or NULL to use NAME converted to upper
22448 case. */
22449 const char *canonical_name;
22450 };
22451
22452 /* This list should, at a minimum, contain all the cpu names
22453 recognized by GCC. */
22454 static const struct arm_cpu_option_table arm_cpus[] =
22455 {
22456 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
22457 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
22458 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
22459 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22460 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22461 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22462 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22463 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22464 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22465 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22466 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22467 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22468 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22469 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22470 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22471 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22472 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22473 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22474 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22475 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22476 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22477 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22478 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22479 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22480 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22481 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22482 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22483 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22484 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22485 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22486 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22487 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22488 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22489 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22490 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22491 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22492 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22493 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22494 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22495 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
22496 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22497 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22498 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22499 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22500 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22501 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22502 /* For V5 or later processors we default to using VFP; but the user
22503 should really set the FPU type explicitly. */
22504 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22505 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22506 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22507 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22508 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
22509 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22510 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
22511 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22512 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22513 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
22514 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22515 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22516 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22517 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22518 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22519 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
22520 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22521 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22522 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22523 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
22524 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
22525 {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL},
22526 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22527 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
22528 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
22529 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
22530 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
22531 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"},
22532 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"},
22533 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
22534 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
22535 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
22536 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
22537 {"cortex-a5", ARM_ARCH_V7A_MP_SEC,
22538 FPU_NONE, "Cortex-A5"},
22539 {"cortex-a8", ARM_ARCH_V7A_SEC,
22540 ARM_FEATURE (0, FPU_VFP_V3
22541 | FPU_NEON_EXT_V1),
22542 "Cortex-A8"},
22543 {"cortex-a9", ARM_ARCH_V7A_MP_SEC,
22544 ARM_FEATURE (0, FPU_VFP_V3
22545 | FPU_NEON_EXT_V1),
22546 "Cortex-A9"},
22547 {"cortex-a15", ARM_ARCH_V7A_IDIV_MP_SEC_VIRT,
22548 FPU_ARCH_NEON_VFP_V4,
22549 "Cortex-A15"},
22550 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"},
22551 {"cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
22552 "Cortex-R4F"},
22553 {"cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"},
22554 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"},
22555 {"cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"},
22556 {"cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"},
22557 /* ??? XSCALE is really an architecture. */
22558 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
22559 /* ??? iwmmxt is not a processor. */
22560 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
22561 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
22562 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
22563 /* Maverick */
22564 {"ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
22565 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
22566 };
22567
22568 struct arm_arch_option_table
22569 {
22570 char *name;
22571 const arm_feature_set value;
22572 const arm_feature_set default_fpu;
22573 };
22574
22575 /* This list should, at a minimum, contain all the architecture names
22576 recognized by GCC. */
22577 static const struct arm_arch_option_table arm_archs[] =
22578 {
22579 {"all", ARM_ANY, FPU_ARCH_FPA},
22580 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
22581 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
22582 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
22583 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
22584 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
22585 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
22586 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
22587 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
22588 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
22589 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
22590 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
22591 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
22592 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
22593 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
22594 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
22595 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
22596 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
22597 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
22598 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
22599 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
22600 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
22601 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
22602 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
22603 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
22604 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
22605 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
22606 {"armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP},
22607 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
22608 /* The official spelling of the ARMv7 profile variants is the dashed form.
22609 Accept the non-dashed form for compatibility with old toolchains. */
22610 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22611 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22612 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
22613 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22614 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22615 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
22616 {"armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP},
22617 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
22618 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
22619 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
22620 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
22621 };
22622
22623 /* ISA extensions in the co-processor and main instruction set space. */
22624 struct arm_option_extension_value_table
22625 {
22626 char *name;
22627 const arm_feature_set value;
22628 const arm_feature_set allowed_archs;
22629 };
22630
22631 /* The following table must be in alphabetical order with a NULL last entry.
22632 */
22633 static const struct arm_option_extension_value_table arm_extensions[] =
22634 {
22635 {"idiv", ARM_FEATURE (ARM_EXT_ADIV | ARM_EXT_DIV, 0),
22636 ARM_FEATURE (ARM_EXT_V7A, 0)},
22637 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT), ARM_ANY},
22638 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2), ARM_ANY},
22639 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK), ARM_ANY},
22640 {"mp", ARM_FEATURE (ARM_EXT_MP, 0),
22641 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)},
22642 {"os", ARM_FEATURE (ARM_EXT_OS, 0),
22643 ARM_FEATURE (ARM_EXT_V6M, 0)},
22644 {"sec", ARM_FEATURE (ARM_EXT_SEC, 0),
22645 ARM_FEATURE (ARM_EXT_V6K | ARM_EXT_V7A, 0)},
22646 {"virt", ARM_FEATURE (ARM_EXT_VIRT | ARM_EXT_ADIV | ARM_EXT_DIV, 0),
22647 ARM_FEATURE (ARM_EXT_V7A, 0)},
22648 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE), ARM_ANY},
22649 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
22650 };
22651
22652 /* ISA floating-point and Advanced SIMD extensions. */
22653 struct arm_option_fpu_value_table
22654 {
22655 char *name;
22656 const arm_feature_set value;
22657 };
22658
22659 /* This list should, at a minimum, contain all the fpu names
22660 recognized by GCC. */
22661 static const struct arm_option_fpu_value_table arm_fpus[] =
22662 {
22663 {"softfpa", FPU_NONE},
22664 {"fpe", FPU_ARCH_FPE},
22665 {"fpe2", FPU_ARCH_FPE},
22666 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
22667 {"fpa", FPU_ARCH_FPA},
22668 {"fpa10", FPU_ARCH_FPA},
22669 {"fpa11", FPU_ARCH_FPA},
22670 {"arm7500fe", FPU_ARCH_FPA},
22671 {"softvfp", FPU_ARCH_VFP},
22672 {"softvfp+vfp", FPU_ARCH_VFP_V2},
22673 {"vfp", FPU_ARCH_VFP_V2},
22674 {"vfp9", FPU_ARCH_VFP_V2},
22675 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
22676 {"vfp10", FPU_ARCH_VFP_V2},
22677 {"vfp10-r0", FPU_ARCH_VFP_V1},
22678 {"vfpxd", FPU_ARCH_VFP_V1xD},
22679 {"vfpv2", FPU_ARCH_VFP_V2},
22680 {"vfpv3", FPU_ARCH_VFP_V3},
22681 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
22682 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
22683 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
22684 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
22685 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
22686 {"arm1020t", FPU_ARCH_VFP_V1},
22687 {"arm1020e", FPU_ARCH_VFP_V2},
22688 {"arm1136jfs", FPU_ARCH_VFP_V2},
22689 {"arm1136jf-s", FPU_ARCH_VFP_V2},
22690 {"maverick", FPU_ARCH_MAVERICK},
22691 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
22692 {"neon-fp16", FPU_ARCH_NEON_FP16},
22693 {"vfpv4", FPU_ARCH_VFP_V4},
22694 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
22695 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
22696 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
22697 {NULL, ARM_ARCH_NONE}
22698 };
22699
22700 struct arm_option_value_table
22701 {
22702 char *name;
22703 long value;
22704 };
22705
22706 static const struct arm_option_value_table arm_float_abis[] =
22707 {
22708 {"hard", ARM_FLOAT_ABI_HARD},
22709 {"softfp", ARM_FLOAT_ABI_SOFTFP},
22710 {"soft", ARM_FLOAT_ABI_SOFT},
22711 {NULL, 0}
22712 };
22713
22714 #ifdef OBJ_ELF
22715 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
22716 static const struct arm_option_value_table arm_eabis[] =
22717 {
22718 {"gnu", EF_ARM_EABI_UNKNOWN},
22719 {"4", EF_ARM_EABI_VER4},
22720 {"5", EF_ARM_EABI_VER5},
22721 {NULL, 0}
22722 };
22723 #endif
22724
22725 struct arm_long_option_table
22726 {
22727 char * option; /* Substring to match. */
22728 char * help; /* Help information. */
22729 int (* func) (char * subopt); /* Function to decode sub-option. */
22730 char * deprecated; /* If non-null, print this message. */
22731 };
22732
22733 static bfd_boolean
22734 arm_parse_extension (char * str, const arm_feature_set **opt_p)
22735 {
22736 arm_feature_set *ext_set = (arm_feature_set *)
22737 xmalloc (sizeof (arm_feature_set));
22738
22739 /* We insist on extensions being specified in alphabetical order, and with
22740 extensions being added before being removed. We achieve this by having
22741 the global ARM_EXTENSIONS table in alphabetical order, and using the
22742 ADDING_VALUE variable to indicate whether we are adding an extension (1)
22743 or removing it (0) and only allowing it to change in the order
22744 -1 -> 1 -> 0. */
22745 const struct arm_option_extension_value_table * opt = NULL;
22746 int adding_value = -1;
22747
22748 /* Copy the feature set, so that we can modify it. */
22749 *ext_set = **opt_p;
22750 *opt_p = ext_set;
22751
22752 while (str != NULL && *str != 0)
22753 {
22754 char * ext;
22755 size_t optlen;
22756
22757 if (*str != '+')
22758 {
22759 as_bad (_("invalid architectural extension"));
22760 return FALSE;
22761 }
22762
22763 str++;
22764 ext = strchr (str, '+');
22765
22766 if (ext != NULL)
22767 optlen = ext - str;
22768 else
22769 optlen = strlen (str);
22770
22771 if (optlen >= 2
22772 && strncmp (str, "no", 2) == 0)
22773 {
22774 if (adding_value != 0)
22775 {
22776 adding_value = 0;
22777 opt = arm_extensions;
22778 }
22779
22780 optlen -= 2;
22781 str += 2;
22782 }
22783 else if (optlen > 0)
22784 {
22785 if (adding_value == -1)
22786 {
22787 adding_value = 1;
22788 opt = arm_extensions;
22789 }
22790 else if (adding_value != 1)
22791 {
22792 as_bad (_("must specify extensions to add before specifying "
22793 "those to remove"));
22794 return FALSE;
22795 }
22796 }
22797
22798 if (optlen == 0)
22799 {
22800 as_bad (_("missing architectural extension"));
22801 return FALSE;
22802 }
22803
22804 gas_assert (adding_value != -1);
22805 gas_assert (opt != NULL);
22806
22807 /* Scan over the options table trying to find an exact match. */
22808 for (; opt->name != NULL; opt++)
22809 if (strncmp (opt->name, str, optlen) == 0
22810 && strlen (opt->name) == optlen)
22811 {
22812 /* Check we can apply the extension to this architecture. */
22813 if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs))
22814 {
22815 as_bad (_("extension does not apply to the base architecture"));
22816 return FALSE;
22817 }
22818
22819 /* Add or remove the extension. */
22820 if (adding_value)
22821 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
22822 else
22823 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->value);
22824
22825 break;
22826 }
22827
22828 if (opt->name == NULL)
22829 {
22830 /* Did we fail to find an extension because it wasn't specified in
22831 alphabetical order, or because it does not exist? */
22832
22833 for (opt = arm_extensions; opt->name != NULL; opt++)
22834 if (strncmp (opt->name, str, optlen) == 0)
22835 break;
22836
22837 if (opt->name == NULL)
22838 as_bad (_("unknown architectural extension `%s'"), str);
22839 else
22840 as_bad (_("architectural extensions must be specified in "
22841 "alphabetical order"));
22842
22843 return FALSE;
22844 }
22845 else
22846 {
22847 /* We should skip the extension we've just matched the next time
22848 round. */
22849 opt++;
22850 }
22851
22852 str = ext;
22853 };
22854
22855 return TRUE;
22856 }
22857
22858 static bfd_boolean
22859 arm_parse_cpu (char * str)
22860 {
22861 const struct arm_cpu_option_table * opt;
22862 char * ext = strchr (str, '+');
22863 int optlen;
22864
22865 if (ext != NULL)
22866 optlen = ext - str;
22867 else
22868 optlen = strlen (str);
22869
22870 if (optlen == 0)
22871 {
22872 as_bad (_("missing cpu name `%s'"), str);
22873 return FALSE;
22874 }
22875
22876 for (opt = arm_cpus; opt->name != NULL; opt++)
22877 if (strncmp (opt->name, str, optlen) == 0)
22878 {
22879 mcpu_cpu_opt = &opt->value;
22880 mcpu_fpu_opt = &opt->default_fpu;
22881 if (opt->canonical_name)
22882 strcpy (selected_cpu_name, opt->canonical_name);
22883 else
22884 {
22885 int i;
22886
22887 for (i = 0; i < optlen; i++)
22888 selected_cpu_name[i] = TOUPPER (opt->name[i]);
22889 selected_cpu_name[i] = 0;
22890 }
22891
22892 if (ext != NULL)
22893 return arm_parse_extension (ext, &mcpu_cpu_opt);
22894
22895 return TRUE;
22896 }
22897
22898 as_bad (_("unknown cpu `%s'"), str);
22899 return FALSE;
22900 }
22901
22902 static bfd_boolean
22903 arm_parse_arch (char * str)
22904 {
22905 const struct arm_arch_option_table *opt;
22906 char *ext = strchr (str, '+');
22907 int optlen;
22908
22909 if (ext != NULL)
22910 optlen = ext - str;
22911 else
22912 optlen = strlen (str);
22913
22914 if (optlen == 0)
22915 {
22916 as_bad (_("missing architecture name `%s'"), str);
22917 return FALSE;
22918 }
22919
22920 for (opt = arm_archs; opt->name != NULL; opt++)
22921 if (strncmp (opt->name, str, optlen) == 0)
22922 {
22923 march_cpu_opt = &opt->value;
22924 march_fpu_opt = &opt->default_fpu;
22925 strcpy (selected_cpu_name, opt->name);
22926
22927 if (ext != NULL)
22928 return arm_parse_extension (ext, &march_cpu_opt);
22929
22930 return TRUE;
22931 }
22932
22933 as_bad (_("unknown architecture `%s'\n"), str);
22934 return FALSE;
22935 }
22936
22937 static bfd_boolean
22938 arm_parse_fpu (char * str)
22939 {
22940 const struct arm_option_fpu_value_table * opt;
22941
22942 for (opt = arm_fpus; opt->name != NULL; opt++)
22943 if (streq (opt->name, str))
22944 {
22945 mfpu_opt = &opt->value;
22946 return TRUE;
22947 }
22948
22949 as_bad (_("unknown floating point format `%s'\n"), str);
22950 return FALSE;
22951 }
22952
22953 static bfd_boolean
22954 arm_parse_float_abi (char * str)
22955 {
22956 const struct arm_option_value_table * opt;
22957
22958 for (opt = arm_float_abis; opt->name != NULL; opt++)
22959 if (streq (opt->name, str))
22960 {
22961 mfloat_abi_opt = opt->value;
22962 return TRUE;
22963 }
22964
22965 as_bad (_("unknown floating point abi `%s'\n"), str);
22966 return FALSE;
22967 }
22968
22969 #ifdef OBJ_ELF
22970 static bfd_boolean
22971 arm_parse_eabi (char * str)
22972 {
22973 const struct arm_option_value_table *opt;
22974
22975 for (opt = arm_eabis; opt->name != NULL; opt++)
22976 if (streq (opt->name, str))
22977 {
22978 meabi_flags = opt->value;
22979 return TRUE;
22980 }
22981 as_bad (_("unknown EABI `%s'\n"), str);
22982 return FALSE;
22983 }
22984 #endif
22985
22986 static bfd_boolean
22987 arm_parse_it_mode (char * str)
22988 {
22989 bfd_boolean ret = TRUE;
22990
22991 if (streq ("arm", str))
22992 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
22993 else if (streq ("thumb", str))
22994 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
22995 else if (streq ("always", str))
22996 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
22997 else if (streq ("never", str))
22998 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
22999 else
23000 {
23001 as_bad (_("unknown implicit IT mode `%s', should be "\
23002 "arm, thumb, always, or never."), str);
23003 ret = FALSE;
23004 }
23005
23006 return ret;
23007 }
23008
23009 struct arm_long_option_table arm_long_opts[] =
23010 {
23011 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
23012 arm_parse_cpu, NULL},
23013 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
23014 arm_parse_arch, NULL},
23015 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
23016 arm_parse_fpu, NULL},
23017 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
23018 arm_parse_float_abi, NULL},
23019 #ifdef OBJ_ELF
23020 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
23021 arm_parse_eabi, NULL},
23022 #endif
23023 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
23024 arm_parse_it_mode, NULL},
23025 {NULL, NULL, 0, NULL}
23026 };
23027
23028 int
23029 md_parse_option (int c, char * arg)
23030 {
23031 struct arm_option_table *opt;
23032 const struct arm_legacy_option_table *fopt;
23033 struct arm_long_option_table *lopt;
23034
23035 switch (c)
23036 {
23037 #ifdef OPTION_EB
23038 case OPTION_EB:
23039 target_big_endian = 1;
23040 break;
23041 #endif
23042
23043 #ifdef OPTION_EL
23044 case OPTION_EL:
23045 target_big_endian = 0;
23046 break;
23047 #endif
23048
23049 case OPTION_FIX_V4BX:
23050 fix_v4bx = TRUE;
23051 break;
23052
23053 case 'a':
23054 /* Listing option. Just ignore these, we don't support additional
23055 ones. */
23056 return 0;
23057
23058 default:
23059 for (opt = arm_opts; opt->option != NULL; opt++)
23060 {
23061 if (c == opt->option[0]
23062 && ((arg == NULL && opt->option[1] == 0)
23063 || streq (arg, opt->option + 1)))
23064 {
23065 /* If the option is deprecated, tell the user. */
23066 if (warn_on_deprecated && opt->deprecated != NULL)
23067 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
23068 arg ? arg : "", _(opt->deprecated));
23069
23070 if (opt->var != NULL)
23071 *opt->var = opt->value;
23072
23073 return 1;
23074 }
23075 }
23076
23077 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
23078 {
23079 if (c == fopt->option[0]
23080 && ((arg == NULL && fopt->option[1] == 0)
23081 || streq (arg, fopt->option + 1)))
23082 {
23083 /* If the option is deprecated, tell the user. */
23084 if (warn_on_deprecated && fopt->deprecated != NULL)
23085 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
23086 arg ? arg : "", _(fopt->deprecated));
23087
23088 if (fopt->var != NULL)
23089 *fopt->var = &fopt->value;
23090
23091 return 1;
23092 }
23093 }
23094
23095 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
23096 {
23097 /* These options are expected to have an argument. */
23098 if (c == lopt->option[0]
23099 && arg != NULL
23100 && strncmp (arg, lopt->option + 1,
23101 strlen (lopt->option + 1)) == 0)
23102 {
23103 /* If the option is deprecated, tell the user. */
23104 if (warn_on_deprecated && lopt->deprecated != NULL)
23105 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
23106 _(lopt->deprecated));
23107
23108 /* Call the sup-option parser. */
23109 return lopt->func (arg + strlen (lopt->option) - 1);
23110 }
23111 }
23112
23113 return 0;
23114 }
23115
23116 return 1;
23117 }
23118
23119 void
23120 md_show_usage (FILE * fp)
23121 {
23122 struct arm_option_table *opt;
23123 struct arm_long_option_table *lopt;
23124
23125 fprintf (fp, _(" ARM-specific assembler options:\n"));
23126
23127 for (opt = arm_opts; opt->option != NULL; opt++)
23128 if (opt->help != NULL)
23129 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
23130
23131 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
23132 if (lopt->help != NULL)
23133 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
23134
23135 #ifdef OPTION_EB
23136 fprintf (fp, _("\
23137 -EB assemble code for a big-endian cpu\n"));
23138 #endif
23139
23140 #ifdef OPTION_EL
23141 fprintf (fp, _("\
23142 -EL assemble code for a little-endian cpu\n"));
23143 #endif
23144
23145 fprintf (fp, _("\
23146 --fix-v4bx Allow BX in ARMv4 code\n"));
23147 }
23148
23149
23150 #ifdef OBJ_ELF
23151 typedef struct
23152 {
23153 int val;
23154 arm_feature_set flags;
23155 } cpu_arch_ver_table;
23156
23157 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
23158 least features first. */
23159 static const cpu_arch_ver_table cpu_arch_ver[] =
23160 {
23161 {1, ARM_ARCH_V4},
23162 {2, ARM_ARCH_V4T},
23163 {3, ARM_ARCH_V5},
23164 {3, ARM_ARCH_V5T},
23165 {4, ARM_ARCH_V5TE},
23166 {5, ARM_ARCH_V5TEJ},
23167 {6, ARM_ARCH_V6},
23168 {9, ARM_ARCH_V6K},
23169 {7, ARM_ARCH_V6Z},
23170 {11, ARM_ARCH_V6M},
23171 {12, ARM_ARCH_V6SM},
23172 {8, ARM_ARCH_V6T2},
23173 {10, ARM_ARCH_V7A},
23174 {10, ARM_ARCH_V7R},
23175 {10, ARM_ARCH_V7M},
23176 {0, ARM_ARCH_NONE}
23177 };
23178
23179 /* Set an attribute if it has not already been set by the user. */
23180 static void
23181 aeabi_set_attribute_int (int tag, int value)
23182 {
23183 if (tag < 1
23184 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
23185 || !attributes_set_explicitly[tag])
23186 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
23187 }
23188
23189 static void
23190 aeabi_set_attribute_string (int tag, const char *value)
23191 {
23192 if (tag < 1
23193 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
23194 || !attributes_set_explicitly[tag])
23195 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
23196 }
23197
23198 /* Set the public EABI object attributes. */
23199 static void
23200 aeabi_set_public_attributes (void)
23201 {
23202 int arch;
23203 int virt_sec = 0;
23204 arm_feature_set flags;
23205 arm_feature_set tmp;
23206 const cpu_arch_ver_table *p;
23207
23208 /* Choose the architecture based on the capabilities of the requested cpu
23209 (if any) and/or the instructions actually used. */
23210 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
23211 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
23212 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
23213 /*Allow the user to override the reported architecture. */
23214 if (object_arch)
23215 {
23216 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
23217 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
23218 }
23219
23220 tmp = flags;
23221 arch = 0;
23222 for (p = cpu_arch_ver; p->val; p++)
23223 {
23224 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
23225 {
23226 arch = p->val;
23227 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
23228 }
23229 }
23230
23231 /* The table lookup above finds the last architecture to contribute
23232 a new feature. Unfortunately, Tag13 is a subset of the union of
23233 v6T2 and v7-M, so it is never seen as contributing a new feature.
23234 We can not search for the last entry which is entirely used,
23235 because if no CPU is specified we build up only those flags
23236 actually used. Perhaps we should separate out the specified
23237 and implicit cases. Avoid taking this path for -march=all by
23238 checking for contradictory v7-A / v7-M features. */
23239 if (arch == 10
23240 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
23241 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
23242 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
23243 arch = 13;
23244
23245 /* Tag_CPU_name. */
23246 if (selected_cpu_name[0])
23247 {
23248 char *q;
23249
23250 q = selected_cpu_name;
23251 if (strncmp (q, "armv", 4) == 0)
23252 {
23253 int i;
23254
23255 q += 4;
23256 for (i = 0; q[i]; i++)
23257 q[i] = TOUPPER (q[i]);
23258 }
23259 aeabi_set_attribute_string (Tag_CPU_name, q);
23260 }
23261
23262 /* Tag_CPU_arch. */
23263 aeabi_set_attribute_int (Tag_CPU_arch, arch);
23264
23265 /* Tag_CPU_arch_profile. */
23266 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
23267 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A');
23268 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
23269 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R');
23270 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
23271 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M');
23272
23273 /* Tag_ARM_ISA_use. */
23274 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
23275 || arch == 0)
23276 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
23277
23278 /* Tag_THUMB_ISA_use. */
23279 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
23280 || arch == 0)
23281 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
23282 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
23283
23284 /* Tag_VFP_arch. */
23285 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
23286 aeabi_set_attribute_int (Tag_VFP_arch,
23287 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
23288 ? 5 : 6);
23289 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
23290 aeabi_set_attribute_int (Tag_VFP_arch, 3);
23291 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
23292 aeabi_set_attribute_int (Tag_VFP_arch, 4);
23293 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
23294 aeabi_set_attribute_int (Tag_VFP_arch, 2);
23295 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
23296 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
23297 aeabi_set_attribute_int (Tag_VFP_arch, 1);
23298
23299 /* Tag_ABI_HardFP_use. */
23300 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
23301 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
23302 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
23303
23304 /* Tag_WMMX_arch. */
23305 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
23306 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
23307 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
23308 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
23309
23310 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
23311 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
23312 aeabi_set_attribute_int
23313 (Tag_Advanced_SIMD_arch, (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma)
23314 ? 2 : 1));
23315
23316 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
23317 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16))
23318 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
23319
23320 /* Tag_DIV_use. */
23321 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv))
23322 aeabi_set_attribute_int (Tag_DIV_use, 2);
23323 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_div))
23324 aeabi_set_attribute_int (Tag_DIV_use, 0);
23325 else
23326 aeabi_set_attribute_int (Tag_DIV_use, 1);
23327
23328 /* Tag_MP_extension_use. */
23329 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
23330 aeabi_set_attribute_int (Tag_MPextension_use, 1);
23331
23332 /* Tag Virtualization_use. */
23333 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
23334 virt_sec |= 1;
23335 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
23336 virt_sec |= 2;
23337 if (virt_sec != 0)
23338 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
23339 }
23340
23341 /* Add the default contents for the .ARM.attributes section. */
23342 void
23343 arm_md_end (void)
23344 {
23345 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
23346 return;
23347
23348 aeabi_set_public_attributes ();
23349 }
23350 #endif /* OBJ_ELF */
23351
23352
23353 /* Parse a .cpu directive. */
23354
23355 static void
23356 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
23357 {
23358 const struct arm_cpu_option_table *opt;
23359 char *name;
23360 char saved_char;
23361
23362 name = input_line_pointer;
23363 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
23364 input_line_pointer++;
23365 saved_char = *input_line_pointer;
23366 *input_line_pointer = 0;
23367
23368 /* Skip the first "all" entry. */
23369 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
23370 if (streq (opt->name, name))
23371 {
23372 mcpu_cpu_opt = &opt->value;
23373 selected_cpu = opt->value;
23374 if (opt->canonical_name)
23375 strcpy (selected_cpu_name, opt->canonical_name);
23376 else
23377 {
23378 int i;
23379 for (i = 0; opt->name[i]; i++)
23380 selected_cpu_name[i] = TOUPPER (opt->name[i]);
23381 selected_cpu_name[i] = 0;
23382 }
23383 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
23384 *input_line_pointer = saved_char;
23385 demand_empty_rest_of_line ();
23386 return;
23387 }
23388 as_bad (_("unknown cpu `%s'"), name);
23389 *input_line_pointer = saved_char;
23390 ignore_rest_of_line ();
23391 }
23392
23393
23394 /* Parse a .arch directive. */
23395
23396 static void
23397 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
23398 {
23399 const struct arm_arch_option_table *opt;
23400 char saved_char;
23401 char *name;
23402
23403 name = input_line_pointer;
23404 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
23405 input_line_pointer++;
23406 saved_char = *input_line_pointer;
23407 *input_line_pointer = 0;
23408
23409 /* Skip the first "all" entry. */
23410 for (opt = arm_archs + 1; opt->name != NULL; opt++)
23411 if (streq (opt->name, name))
23412 {
23413 mcpu_cpu_opt = &opt->value;
23414 selected_cpu = opt->value;
23415 strcpy (selected_cpu_name, opt->name);
23416 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
23417 *input_line_pointer = saved_char;
23418 demand_empty_rest_of_line ();
23419 return;
23420 }
23421
23422 as_bad (_("unknown architecture `%s'\n"), name);
23423 *input_line_pointer = saved_char;
23424 ignore_rest_of_line ();
23425 }
23426
23427
23428 /* Parse a .object_arch directive. */
23429
23430 static void
23431 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
23432 {
23433 const struct arm_arch_option_table *opt;
23434 char saved_char;
23435 char *name;
23436
23437 name = input_line_pointer;
23438 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
23439 input_line_pointer++;
23440 saved_char = *input_line_pointer;
23441 *input_line_pointer = 0;
23442
23443 /* Skip the first "all" entry. */
23444 for (opt = arm_archs + 1; opt->name != NULL; opt++)
23445 if (streq (opt->name, name))
23446 {
23447 object_arch = &opt->value;
23448 *input_line_pointer = saved_char;
23449 demand_empty_rest_of_line ();
23450 return;
23451 }
23452
23453 as_bad (_("unknown architecture `%s'\n"), name);
23454 *input_line_pointer = saved_char;
23455 ignore_rest_of_line ();
23456 }
23457
23458 /* Parse a .arch_extension directive. */
23459
23460 static void
23461 s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
23462 {
23463 const struct arm_option_extension_value_table *opt;
23464 char saved_char;
23465 char *name;
23466 int adding_value = 1;
23467
23468 name = input_line_pointer;
23469 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
23470 input_line_pointer++;
23471 saved_char = *input_line_pointer;
23472 *input_line_pointer = 0;
23473
23474 if (strlen (name) >= 2
23475 && strncmp (name, "no", 2) == 0)
23476 {
23477 adding_value = 0;
23478 name += 2;
23479 }
23480
23481 for (opt = arm_extensions; opt->name != NULL; opt++)
23482 if (streq (opt->name, name))
23483 {
23484 if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs))
23485 {
23486 as_bad (_("architectural extension `%s' is not allowed for the "
23487 "current base architecture"), name);
23488 break;
23489 }
23490
23491 if (adding_value)
23492 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu, opt->value);
23493 else
23494 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->value);
23495
23496 mcpu_cpu_opt = &selected_cpu;
23497 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
23498 *input_line_pointer = saved_char;
23499 demand_empty_rest_of_line ();
23500 return;
23501 }
23502
23503 if (opt->name == NULL)
23504 as_bad (_("unknown architecture `%s'\n"), name);
23505
23506 *input_line_pointer = saved_char;
23507 ignore_rest_of_line ();
23508 }
23509
23510 /* Parse a .fpu directive. */
23511
23512 static void
23513 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
23514 {
23515 const struct arm_option_fpu_value_table *opt;
23516 char saved_char;
23517 char *name;
23518
23519 name = input_line_pointer;
23520 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
23521 input_line_pointer++;
23522 saved_char = *input_line_pointer;
23523 *input_line_pointer = 0;
23524
23525 for (opt = arm_fpus; opt->name != NULL; opt++)
23526 if (streq (opt->name, name))
23527 {
23528 mfpu_opt = &opt->value;
23529 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
23530 *input_line_pointer = saved_char;
23531 demand_empty_rest_of_line ();
23532 return;
23533 }
23534
23535 as_bad (_("unknown floating point format `%s'\n"), name);
23536 *input_line_pointer = saved_char;
23537 ignore_rest_of_line ();
23538 }
23539
23540 /* Copy symbol information. */
23541
23542 void
23543 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
23544 {
23545 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
23546 }
23547
23548 #ifdef OBJ_ELF
23549 /* Given a symbolic attribute NAME, return the proper integer value.
23550 Returns -1 if the attribute is not known. */
23551
23552 int
23553 arm_convert_symbolic_attribute (const char *name)
23554 {
23555 static const struct
23556 {
23557 const char * name;
23558 const int tag;
23559 }
23560 attribute_table[] =
23561 {
23562 /* When you modify this table you should
23563 also modify the list in doc/c-arm.texi. */
23564 #define T(tag) {#tag, tag}
23565 T (Tag_CPU_raw_name),
23566 T (Tag_CPU_name),
23567 T (Tag_CPU_arch),
23568 T (Tag_CPU_arch_profile),
23569 T (Tag_ARM_ISA_use),
23570 T (Tag_THUMB_ISA_use),
23571 T (Tag_FP_arch),
23572 T (Tag_VFP_arch),
23573 T (Tag_WMMX_arch),
23574 T (Tag_Advanced_SIMD_arch),
23575 T (Tag_PCS_config),
23576 T (Tag_ABI_PCS_R9_use),
23577 T (Tag_ABI_PCS_RW_data),
23578 T (Tag_ABI_PCS_RO_data),
23579 T (Tag_ABI_PCS_GOT_use),
23580 T (Tag_ABI_PCS_wchar_t),
23581 T (Tag_ABI_FP_rounding),
23582 T (Tag_ABI_FP_denormal),
23583 T (Tag_ABI_FP_exceptions),
23584 T (Tag_ABI_FP_user_exceptions),
23585 T (Tag_ABI_FP_number_model),
23586 T (Tag_ABI_align_needed),
23587 T (Tag_ABI_align8_needed),
23588 T (Tag_ABI_align_preserved),
23589 T (Tag_ABI_align8_preserved),
23590 T (Tag_ABI_enum_size),
23591 T (Tag_ABI_HardFP_use),
23592 T (Tag_ABI_VFP_args),
23593 T (Tag_ABI_WMMX_args),
23594 T (Tag_ABI_optimization_goals),
23595 T (Tag_ABI_FP_optimization_goals),
23596 T (Tag_compatibility),
23597 T (Tag_CPU_unaligned_access),
23598 T (Tag_FP_HP_extension),
23599 T (Tag_VFP_HP_extension),
23600 T (Tag_ABI_FP_16bit_format),
23601 T (Tag_MPextension_use),
23602 T (Tag_DIV_use),
23603 T (Tag_nodefaults),
23604 T (Tag_also_compatible_with),
23605 T (Tag_conformance),
23606 T (Tag_T2EE_use),
23607 T (Tag_Virtualization_use),
23608 /* We deliberately do not include Tag_MPextension_use_legacy. */
23609 #undef T
23610 };
23611 unsigned int i;
23612
23613 if (name == NULL)
23614 return -1;
23615
23616 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
23617 if (streq (name, attribute_table[i].name))
23618 return attribute_table[i].tag;
23619
23620 return -1;
23621 }
23622
23623
23624 /* Apply sym value for relocations only in the case that
23625 they are for local symbols and you have the respective
23626 architectural feature for blx and simple switches. */
23627 int
23628 arm_apply_sym_value (struct fix * fixP)
23629 {
23630 if (fixP->fx_addsy
23631 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23632 && !S_IS_EXTERNAL (fixP->fx_addsy))
23633 {
23634 switch (fixP->fx_r_type)
23635 {
23636 case BFD_RELOC_ARM_PCREL_BLX:
23637 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23638 if (ARM_IS_FUNC (fixP->fx_addsy))
23639 return 1;
23640 break;
23641
23642 case BFD_RELOC_ARM_PCREL_CALL:
23643 case BFD_RELOC_THUMB_PCREL_BLX:
23644 if (THUMB_IS_FUNC (fixP->fx_addsy))
23645 return 1;
23646 break;
23647
23648 default:
23649 break;
23650 }
23651
23652 }
23653 return 0;
23654 }
23655 #endif /* OBJ_ELF */
This page took 0.55196 seconds and 5 git commands to generate.