* ld-selective/selective.exp: Fix selective testcases for MIPS.
[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
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 2, or (at your option)
16 any later version.
17
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with GAS; see the file COPYING. If not, write to the Free
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 02110-1301, USA. */
27
28 #include <limits.h>
29 #include <stdarg.h>
30 #define NO_RELOC 0
31 #include "as.h"
32 #include "safe-ctype.h"
33 #include "subsegs.h"
34 #include "obstack.h"
35
36 #include "opcode/arm.h"
37
38 #ifdef OBJ_ELF
39 #include "elf/arm.h"
40 #include "dwarf2dbg.h"
41 #include "dw2gencfi.h"
42 #endif
43
44 /* XXX Set this to 1 after the next binutils release. */
45 #define WARN_DEPRECATED 0
46
47 #ifdef OBJ_ELF
48 /* Must be at least the size of the largest unwind opcode (currently two). */
49 #define ARM_OPCODE_CHUNK_SIZE 8
50
51 /* This structure holds the unwinding state. */
52
53 static struct
54 {
55 symbolS * proc_start;
56 symbolS * table_entry;
57 symbolS * personality_routine;
58 int personality_index;
59 /* The segment containing the function. */
60 segT saved_seg;
61 subsegT saved_subseg;
62 /* Opcodes generated from this function. */
63 unsigned char * opcodes;
64 int opcode_count;
65 int opcode_alloc;
66 /* The number of bytes pushed to the stack. */
67 offsetT frame_size;
68 /* We don't add stack adjustment opcodes immediately so that we can merge
69 multiple adjustments. We can also omit the final adjustment
70 when using a frame pointer. */
71 offsetT pending_offset;
72 /* These two fields are set by both unwind_movsp and unwind_setfp. They
73 hold the reg+offset to use when restoring sp from a frame pointer. */
74 offsetT fp_offset;
75 int fp_reg;
76 /* Nonzero if an unwind_setfp directive has been seen. */
77 unsigned fp_used:1;
78 /* Nonzero if the last opcode restores sp from fp_reg. */
79 unsigned sp_restored:1;
80 } unwind;
81
82 /* Bit N indicates that an R_ARM_NONE relocation has been output for
83 __aeabi_unwind_cpp_prN already if set. This enables dependencies to be
84 emitted only once per section, to save unnecessary bloat. */
85 static unsigned int marked_pr_dependency = 0;
86
87 #endif /* OBJ_ELF */
88
89 /* Results from operand parsing worker functions. */
90
91 typedef enum
92 {
93 PARSE_OPERAND_SUCCESS,
94 PARSE_OPERAND_FAIL,
95 PARSE_OPERAND_FAIL_NO_BACKTRACK
96 } parse_operand_result;
97
98 enum arm_float_abi
99 {
100 ARM_FLOAT_ABI_HARD,
101 ARM_FLOAT_ABI_SOFTFP,
102 ARM_FLOAT_ABI_SOFT
103 };
104
105 /* Types of processor to assemble for. */
106 #ifndef CPU_DEFAULT
107 #if defined __XSCALE__
108 #define CPU_DEFAULT ARM_ARCH_XSCALE
109 #else
110 #if defined __thumb__
111 #define CPU_DEFAULT ARM_ARCH_V5T
112 #endif
113 #endif
114 #endif
115
116 #ifndef FPU_DEFAULT
117 # ifdef TE_LINUX
118 # define FPU_DEFAULT FPU_ARCH_FPA
119 # elif defined (TE_NetBSD)
120 # ifdef OBJ_ELF
121 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
122 # else
123 /* Legacy a.out format. */
124 # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
125 # endif
126 # elif defined (TE_VXWORKS)
127 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
128 # else
129 /* For backwards compatibility, default to FPA. */
130 # define FPU_DEFAULT FPU_ARCH_FPA
131 # endif
132 #endif /* ifndef FPU_DEFAULT */
133
134 #define streq(a, b) (strcmp (a, b) == 0)
135
136 static arm_feature_set cpu_variant;
137 static arm_feature_set arm_arch_used;
138 static arm_feature_set thumb_arch_used;
139
140 /* Flags stored in private area of BFD structure. */
141 static int uses_apcs_26 = FALSE;
142 static int atpcs = FALSE;
143 static int support_interwork = FALSE;
144 static int uses_apcs_float = FALSE;
145 static int pic_code = FALSE;
146
147 /* Variables that we set while parsing command-line options. Once all
148 options have been read we re-process these values to set the real
149 assembly flags. */
150 static const arm_feature_set *legacy_cpu = NULL;
151 static const arm_feature_set *legacy_fpu = NULL;
152
153 static const arm_feature_set *mcpu_cpu_opt = NULL;
154 static const arm_feature_set *mcpu_fpu_opt = NULL;
155 static const arm_feature_set *march_cpu_opt = NULL;
156 static const arm_feature_set *march_fpu_opt = NULL;
157 static const arm_feature_set *mfpu_opt = NULL;
158
159 /* Constants for known architecture features. */
160 static const arm_feature_set fpu_default = FPU_DEFAULT;
161 static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
162 static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
163 static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
164 static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
165 static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
166 static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
167 static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
168 static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
169
170 #ifdef CPU_DEFAULT
171 static const arm_feature_set cpu_default = CPU_DEFAULT;
172 #endif
173
174 static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
175 static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
176 static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
177 static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
178 static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
179 static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
180 static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
181 static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
182 static const arm_feature_set arm_ext_v4t_5 =
183 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
184 static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
185 static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
186 static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
187 static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
188 static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
189 static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
190 static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
191 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
192 static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 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
199 static const arm_feature_set arm_arch_any = ARM_ANY;
200 static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
201 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
202 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
203
204 static const arm_feature_set arm_cext_iwmmxt =
205 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
206 static const arm_feature_set arm_cext_xscale =
207 ARM_FEATURE (0, ARM_CEXT_XSCALE);
208 static const arm_feature_set arm_cext_maverick =
209 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
210 static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
211 static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
212 static const arm_feature_set fpu_vfp_ext_v1xd =
213 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
214 static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
215 static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
216 static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
217 static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
218 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
219 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
220
221 static int mfloat_abi_opt = -1;
222 /* Record user cpu selection for object attributes. */
223 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
224 /* Must be long enough to hold any of the names in arm_cpus. */
225 static char selected_cpu_name[16];
226 #ifdef OBJ_ELF
227 # ifdef EABI_DEFAULT
228 static int meabi_flags = EABI_DEFAULT;
229 # else
230 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
231 # endif
232 #endif
233
234 #ifdef OBJ_ELF
235 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
236 symbolS * GOT_symbol;
237 #endif
238
239 /* 0: assemble for ARM,
240 1: assemble for Thumb,
241 2: assemble for Thumb even though target CPU does not support thumb
242 instructions. */
243 static int thumb_mode = 0;
244
245 /* If unified_syntax is true, we are processing the new unified
246 ARM/Thumb syntax. Important differences from the old ARM mode:
247
248 - Immediate operands do not require a # prefix.
249 - Conditional affixes always appear at the end of the
250 instruction. (For backward compatibility, those instructions
251 that formerly had them in the middle, continue to accept them
252 there.)
253 - The IT instruction may appear, and if it does is validated
254 against subsequent conditional affixes. It does not generate
255 machine code.
256
257 Important differences from the old Thumb mode:
258
259 - Immediate operands do not require a # prefix.
260 - Most of the V6T2 instructions are only available in unified mode.
261 - The .N and .W suffixes are recognized and honored (it is an error
262 if they cannot be honored).
263 - All instructions set the flags if and only if they have an 's' affix.
264 - Conditional affixes may be used. They are validated against
265 preceding IT instructions. Unlike ARM mode, you cannot use a
266 conditional affix except in the scope of an IT instruction. */
267
268 static bfd_boolean unified_syntax = FALSE;
269
270 enum neon_el_type
271 {
272 NT_invtype,
273 NT_untyped,
274 NT_integer,
275 NT_float,
276 NT_poly,
277 NT_signed,
278 NT_unsigned
279 };
280
281 struct neon_type_el
282 {
283 enum neon_el_type type;
284 unsigned size;
285 };
286
287 #define NEON_MAX_TYPE_ELS 4
288
289 struct neon_type
290 {
291 struct neon_type_el el[NEON_MAX_TYPE_ELS];
292 unsigned elems;
293 };
294
295 struct arm_it
296 {
297 const char * error;
298 unsigned long instruction;
299 int size;
300 int size_req;
301 int cond;
302 /* "uncond_value" is set to the value in place of the conditional field in
303 unconditional versions of the instruction, or -1 if nothing is
304 appropriate. */
305 int uncond_value;
306 struct neon_type vectype;
307 /* Set to the opcode if the instruction needs relaxation.
308 Zero if the instruction is not relaxed. */
309 unsigned long relax;
310 struct
311 {
312 bfd_reloc_code_real_type type;
313 expressionS exp;
314 int pc_rel;
315 } reloc;
316
317 struct
318 {
319 unsigned reg;
320 signed int imm;
321 struct neon_type_el vectype;
322 unsigned present : 1; /* Operand present. */
323 unsigned isreg : 1; /* Operand was a register. */
324 unsigned immisreg : 1; /* .imm field is a second register. */
325 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
326 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
327 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
328 instructions. This allows us to disambiguate ARM <-> vector insns. */
329 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
330 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
331 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
332 unsigned issingle : 1; /* Operand is VFP single-precision register. */
333 unsigned hasreloc : 1; /* Operand has relocation suffix. */
334 unsigned writeback : 1; /* Operand has trailing ! */
335 unsigned preind : 1; /* Preindexed address. */
336 unsigned postind : 1; /* Postindexed address. */
337 unsigned negative : 1; /* Index register was negated. */
338 unsigned shifted : 1; /* Shift applied to operation. */
339 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
340 } operands[6];
341 };
342
343 static struct arm_it inst;
344
345 #define NUM_FLOAT_VALS 8
346
347 const char * fp_const[] =
348 {
349 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
350 };
351
352 /* Number of littlenums required to hold an extended precision number. */
353 #define MAX_LITTLENUMS 6
354
355 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
356
357 #define FAIL (-1)
358 #define SUCCESS (0)
359
360 #define SUFF_S 1
361 #define SUFF_D 2
362 #define SUFF_E 3
363 #define SUFF_P 4
364
365 #define CP_T_X 0x00008000
366 #define CP_T_Y 0x00400000
367
368 #define CONDS_BIT 0x00100000
369 #define LOAD_BIT 0x00100000
370
371 #define DOUBLE_LOAD_FLAG 0x00000001
372
373 struct asm_cond
374 {
375 const char * template;
376 unsigned long value;
377 };
378
379 #define COND_ALWAYS 0xE
380
381 struct asm_psr
382 {
383 const char *template;
384 unsigned long field;
385 };
386
387 struct asm_barrier_opt
388 {
389 const char *template;
390 unsigned long value;
391 };
392
393 /* The bit that distinguishes CPSR and SPSR. */
394 #define SPSR_BIT (1 << 22)
395
396 /* The individual PSR flag bits. */
397 #define PSR_c (1 << 16)
398 #define PSR_x (1 << 17)
399 #define PSR_s (1 << 18)
400 #define PSR_f (1 << 19)
401
402 struct reloc_entry
403 {
404 char *name;
405 bfd_reloc_code_real_type reloc;
406 };
407
408 enum vfp_reg_pos
409 {
410 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
411 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
412 };
413
414 enum vfp_ldstm_type
415 {
416 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
417 };
418
419 /* Bits for DEFINED field in neon_typed_alias. */
420 #define NTA_HASTYPE 1
421 #define NTA_HASINDEX 2
422
423 struct neon_typed_alias
424 {
425 unsigned char defined;
426 unsigned char index;
427 struct neon_type_el eltype;
428 };
429
430 /* ARM register categories. This includes coprocessor numbers and various
431 architecture extensions' registers. */
432 enum arm_reg_type
433 {
434 REG_TYPE_RN,
435 REG_TYPE_CP,
436 REG_TYPE_CN,
437 REG_TYPE_FN,
438 REG_TYPE_VFS,
439 REG_TYPE_VFD,
440 REG_TYPE_NQ,
441 REG_TYPE_VFSD,
442 REG_TYPE_NDQ,
443 REG_TYPE_NSDQ,
444 REG_TYPE_VFC,
445 REG_TYPE_MVF,
446 REG_TYPE_MVD,
447 REG_TYPE_MVFX,
448 REG_TYPE_MVDX,
449 REG_TYPE_MVAX,
450 REG_TYPE_DSPSC,
451 REG_TYPE_MMXWR,
452 REG_TYPE_MMXWC,
453 REG_TYPE_MMXWCG,
454 REG_TYPE_XSCALE,
455 };
456
457 /* Structure for a hash table entry for a register.
458 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
459 information which states whether a vector type or index is specified (for a
460 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
461 struct reg_entry
462 {
463 const char *name;
464 unsigned char number;
465 unsigned char type;
466 unsigned char builtin;
467 struct neon_typed_alias *neon;
468 };
469
470 /* Diagnostics used when we don't get a register of the expected type. */
471 const char *const reg_expected_msgs[] =
472 {
473 N_("ARM register expected"),
474 N_("bad or missing co-processor number"),
475 N_("co-processor register expected"),
476 N_("FPA register expected"),
477 N_("VFP single precision register expected"),
478 N_("VFP/Neon double precision register expected"),
479 N_("Neon quad precision register expected"),
480 N_("VFP single or double precision register expected"),
481 N_("Neon double or quad precision register expected"),
482 N_("VFP single, double or Neon quad precision register expected"),
483 N_("VFP system register expected"),
484 N_("Maverick MVF register expected"),
485 N_("Maverick MVD register expected"),
486 N_("Maverick MVFX register expected"),
487 N_("Maverick MVDX register expected"),
488 N_("Maverick MVAX register expected"),
489 N_("Maverick DSPSC register expected"),
490 N_("iWMMXt data register expected"),
491 N_("iWMMXt control register expected"),
492 N_("iWMMXt scalar register expected"),
493 N_("XScale accumulator register expected"),
494 };
495
496 /* Some well known registers that we refer to directly elsewhere. */
497 #define REG_SP 13
498 #define REG_LR 14
499 #define REG_PC 15
500
501 /* ARM instructions take 4bytes in the object file, Thumb instructions
502 take 2: */
503 #define INSN_SIZE 4
504
505 struct asm_opcode
506 {
507 /* Basic string to match. */
508 const char *template;
509
510 /* Parameters to instruction. */
511 unsigned char operands[8];
512
513 /* Conditional tag - see opcode_lookup. */
514 unsigned int tag : 4;
515
516 /* Basic instruction code. */
517 unsigned int avalue : 28;
518
519 /* Thumb-format instruction code. */
520 unsigned int tvalue;
521
522 /* Which architecture variant provides this instruction. */
523 const arm_feature_set *avariant;
524 const arm_feature_set *tvariant;
525
526 /* Function to call to encode instruction in ARM format. */
527 void (* aencode) (void);
528
529 /* Function to call to encode instruction in Thumb format. */
530 void (* tencode) (void);
531 };
532
533 /* Defines for various bits that we will want to toggle. */
534 #define INST_IMMEDIATE 0x02000000
535 #define OFFSET_REG 0x02000000
536 #define HWOFFSET_IMM 0x00400000
537 #define SHIFT_BY_REG 0x00000010
538 #define PRE_INDEX 0x01000000
539 #define INDEX_UP 0x00800000
540 #define WRITE_BACK 0x00200000
541 #define LDM_TYPE_2_OR_3 0x00400000
542
543 #define LITERAL_MASK 0xf000f000
544 #define OPCODE_MASK 0xfe1fffff
545 #define V4_STR_BIT 0x00000020
546
547 #define DATA_OP_SHIFT 21
548
549 #define T2_OPCODE_MASK 0xfe1fffff
550 #define T2_DATA_OP_SHIFT 21
551
552 /* Codes to distinguish the arithmetic instructions. */
553 #define OPCODE_AND 0
554 #define OPCODE_EOR 1
555 #define OPCODE_SUB 2
556 #define OPCODE_RSB 3
557 #define OPCODE_ADD 4
558 #define OPCODE_ADC 5
559 #define OPCODE_SBC 6
560 #define OPCODE_RSC 7
561 #define OPCODE_TST 8
562 #define OPCODE_TEQ 9
563 #define OPCODE_CMP 10
564 #define OPCODE_CMN 11
565 #define OPCODE_ORR 12
566 #define OPCODE_MOV 13
567 #define OPCODE_BIC 14
568 #define OPCODE_MVN 15
569
570 #define T2_OPCODE_AND 0
571 #define T2_OPCODE_BIC 1
572 #define T2_OPCODE_ORR 2
573 #define T2_OPCODE_ORN 3
574 #define T2_OPCODE_EOR 4
575 #define T2_OPCODE_ADD 8
576 #define T2_OPCODE_ADC 10
577 #define T2_OPCODE_SBC 11
578 #define T2_OPCODE_SUB 13
579 #define T2_OPCODE_RSB 14
580
581 #define T_OPCODE_MUL 0x4340
582 #define T_OPCODE_TST 0x4200
583 #define T_OPCODE_CMN 0x42c0
584 #define T_OPCODE_NEG 0x4240
585 #define T_OPCODE_MVN 0x43c0
586
587 #define T_OPCODE_ADD_R3 0x1800
588 #define T_OPCODE_SUB_R3 0x1a00
589 #define T_OPCODE_ADD_HI 0x4400
590 #define T_OPCODE_ADD_ST 0xb000
591 #define T_OPCODE_SUB_ST 0xb080
592 #define T_OPCODE_ADD_SP 0xa800
593 #define T_OPCODE_ADD_PC 0xa000
594 #define T_OPCODE_ADD_I8 0x3000
595 #define T_OPCODE_SUB_I8 0x3800
596 #define T_OPCODE_ADD_I3 0x1c00
597 #define T_OPCODE_SUB_I3 0x1e00
598
599 #define T_OPCODE_ASR_R 0x4100
600 #define T_OPCODE_LSL_R 0x4080
601 #define T_OPCODE_LSR_R 0x40c0
602 #define T_OPCODE_ROR_R 0x41c0
603 #define T_OPCODE_ASR_I 0x1000
604 #define T_OPCODE_LSL_I 0x0000
605 #define T_OPCODE_LSR_I 0x0800
606
607 #define T_OPCODE_MOV_I8 0x2000
608 #define T_OPCODE_CMP_I8 0x2800
609 #define T_OPCODE_CMP_LR 0x4280
610 #define T_OPCODE_MOV_HR 0x4600
611 #define T_OPCODE_CMP_HR 0x4500
612
613 #define T_OPCODE_LDR_PC 0x4800
614 #define T_OPCODE_LDR_SP 0x9800
615 #define T_OPCODE_STR_SP 0x9000
616 #define T_OPCODE_LDR_IW 0x6800
617 #define T_OPCODE_STR_IW 0x6000
618 #define T_OPCODE_LDR_IH 0x8800
619 #define T_OPCODE_STR_IH 0x8000
620 #define T_OPCODE_LDR_IB 0x7800
621 #define T_OPCODE_STR_IB 0x7000
622 #define T_OPCODE_LDR_RW 0x5800
623 #define T_OPCODE_STR_RW 0x5000
624 #define T_OPCODE_LDR_RH 0x5a00
625 #define T_OPCODE_STR_RH 0x5200
626 #define T_OPCODE_LDR_RB 0x5c00
627 #define T_OPCODE_STR_RB 0x5400
628
629 #define T_OPCODE_PUSH 0xb400
630 #define T_OPCODE_POP 0xbc00
631
632 #define T_OPCODE_BRANCH 0xe000
633
634 #define THUMB_SIZE 2 /* Size of thumb instruction. */
635 #define THUMB_PP_PC_LR 0x0100
636 #define THUMB_LOAD_BIT 0x0800
637 #define THUMB2_LOAD_BIT 0x00100000
638
639 #define BAD_ARGS _("bad arguments to instruction")
640 #define BAD_PC _("r15 not allowed here")
641 #define BAD_COND _("instruction cannot be conditional")
642 #define BAD_OVERLAP _("registers may not be the same")
643 #define BAD_HIREG _("lo register required")
644 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
645 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
646 #define BAD_BRANCH _("branch must be last instruction in IT block")
647 #define BAD_NOT_IT _("instruction not allowed in IT block")
648 #define BAD_FPU _("selected FPU does not support instruction")
649
650 static struct hash_control *arm_ops_hsh;
651 static struct hash_control *arm_cond_hsh;
652 static struct hash_control *arm_shift_hsh;
653 static struct hash_control *arm_psr_hsh;
654 static struct hash_control *arm_v7m_psr_hsh;
655 static struct hash_control *arm_reg_hsh;
656 static struct hash_control *arm_reloc_hsh;
657 static struct hash_control *arm_barrier_opt_hsh;
658
659 /* Stuff needed to resolve the label ambiguity
660 As:
661 ...
662 label: <insn>
663 may differ from:
664 ...
665 label:
666 <insn>
667 */
668
669 symbolS * last_label_seen;
670 static int label_is_thumb_function_name = FALSE;
671 \f
672 /* Literal pool structure. Held on a per-section
673 and per-sub-section basis. */
674
675 #define MAX_LITERAL_POOL_SIZE 1024
676 typedef struct literal_pool
677 {
678 expressionS literals [MAX_LITERAL_POOL_SIZE];
679 unsigned int next_free_entry;
680 unsigned int id;
681 symbolS * symbol;
682 segT section;
683 subsegT sub_section;
684 struct literal_pool * next;
685 } literal_pool;
686
687 /* Pointer to a linked list of literal pools. */
688 literal_pool * list_of_pools = NULL;
689
690 /* State variables for IT block handling. */
691 static bfd_boolean current_it_mask = 0;
692 static int current_cc;
693
694 \f
695 /* Pure syntax. */
696
697 /* This array holds the chars that always start a comment. If the
698 pre-processor is disabled, these aren't very useful. */
699 const char comment_chars[] = "@";
700
701 /* This array holds the chars that only start a comment at the beginning of
702 a line. If the line seems to have the form '# 123 filename'
703 .line and .file directives will appear in the pre-processed output. */
704 /* Note that input_file.c hand checks for '#' at the beginning of the
705 first line of the input file. This is because the compiler outputs
706 #NO_APP at the beginning of its output. */
707 /* Also note that comments like this one will always work. */
708 const char line_comment_chars[] = "#";
709
710 const char line_separator_chars[] = ";";
711
712 /* Chars that can be used to separate mant
713 from exp in floating point numbers. */
714 const char EXP_CHARS[] = "eE";
715
716 /* Chars that mean this number is a floating point constant. */
717 /* As in 0f12.456 */
718 /* or 0d1.2345e12 */
719
720 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
721
722 /* Prefix characters that indicate the start of an immediate
723 value. */
724 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
725
726 /* Separator character handling. */
727
728 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
729
730 static inline int
731 skip_past_char (char ** str, char c)
732 {
733 if (**str == c)
734 {
735 (*str)++;
736 return SUCCESS;
737 }
738 else
739 return FAIL;
740 }
741 #define skip_past_comma(str) skip_past_char (str, ',')
742
743 /* Arithmetic expressions (possibly involving symbols). */
744
745 /* Return TRUE if anything in the expression is a bignum. */
746
747 static int
748 walk_no_bignums (symbolS * sp)
749 {
750 if (symbol_get_value_expression (sp)->X_op == O_big)
751 return 1;
752
753 if (symbol_get_value_expression (sp)->X_add_symbol)
754 {
755 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
756 || (symbol_get_value_expression (sp)->X_op_symbol
757 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
758 }
759
760 return 0;
761 }
762
763 static int in_my_get_expression = 0;
764
765 /* Third argument to my_get_expression. */
766 #define GE_NO_PREFIX 0
767 #define GE_IMM_PREFIX 1
768 #define GE_OPT_PREFIX 2
769 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
770 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
771 #define GE_OPT_PREFIX_BIG 3
772
773 static int
774 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
775 {
776 char * save_in;
777 segT seg;
778
779 /* In unified syntax, all prefixes are optional. */
780 if (unified_syntax)
781 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
782 : GE_OPT_PREFIX;
783
784 switch (prefix_mode)
785 {
786 case GE_NO_PREFIX: break;
787 case GE_IMM_PREFIX:
788 if (!is_immediate_prefix (**str))
789 {
790 inst.error = _("immediate expression requires a # prefix");
791 return FAIL;
792 }
793 (*str)++;
794 break;
795 case GE_OPT_PREFIX:
796 case GE_OPT_PREFIX_BIG:
797 if (is_immediate_prefix (**str))
798 (*str)++;
799 break;
800 default: abort ();
801 }
802
803 memset (ep, 0, sizeof (expressionS));
804
805 save_in = input_line_pointer;
806 input_line_pointer = *str;
807 in_my_get_expression = 1;
808 seg = expression (ep);
809 in_my_get_expression = 0;
810
811 if (ep->X_op == O_illegal)
812 {
813 /* We found a bad expression in md_operand(). */
814 *str = input_line_pointer;
815 input_line_pointer = save_in;
816 if (inst.error == NULL)
817 inst.error = _("bad expression");
818 return 1;
819 }
820
821 #ifdef OBJ_AOUT
822 if (seg != absolute_section
823 && seg != text_section
824 && seg != data_section
825 && seg != bss_section
826 && seg != undefined_section)
827 {
828 inst.error = _("bad segment");
829 *str = input_line_pointer;
830 input_line_pointer = save_in;
831 return 1;
832 }
833 #endif
834
835 /* Get rid of any bignums now, so that we don't generate an error for which
836 we can't establish a line number later on. Big numbers are never valid
837 in instructions, which is where this routine is always called. */
838 if (prefix_mode != GE_OPT_PREFIX_BIG
839 && (ep->X_op == O_big
840 || (ep->X_add_symbol
841 && (walk_no_bignums (ep->X_add_symbol)
842 || (ep->X_op_symbol
843 && walk_no_bignums (ep->X_op_symbol))))))
844 {
845 inst.error = _("invalid constant");
846 *str = input_line_pointer;
847 input_line_pointer = save_in;
848 return 1;
849 }
850
851 *str = input_line_pointer;
852 input_line_pointer = save_in;
853 return 0;
854 }
855
856 /* Turn a string in input_line_pointer into a floating point constant
857 of type TYPE, and store the appropriate bytes in *LITP. The number
858 of LITTLENUMS emitted is stored in *SIZEP. An error message is
859 returned, or NULL on OK.
860
861 Note that fp constants aren't represent in the normal way on the ARM.
862 In big endian mode, things are as expected. However, in little endian
863 mode fp constants are big-endian word-wise, and little-endian byte-wise
864 within the words. For example, (double) 1.1 in big endian mode is
865 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
866 the byte sequence 99 99 f1 3f 9a 99 99 99.
867
868 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
869
870 char *
871 md_atof (int type, char * litP, int * sizeP)
872 {
873 int prec;
874 LITTLENUM_TYPE words[MAX_LITTLENUMS];
875 char *t;
876 int i;
877
878 switch (type)
879 {
880 case 'f':
881 case 'F':
882 case 's':
883 case 'S':
884 prec = 2;
885 break;
886
887 case 'd':
888 case 'D':
889 case 'r':
890 case 'R':
891 prec = 4;
892 break;
893
894 case 'x':
895 case 'X':
896 prec = 6;
897 break;
898
899 case 'p':
900 case 'P':
901 prec = 6;
902 break;
903
904 default:
905 *sizeP = 0;
906 return _("bad call to MD_ATOF()");
907 }
908
909 t = atof_ieee (input_line_pointer, type, words);
910 if (t)
911 input_line_pointer = t;
912 *sizeP = prec * 2;
913
914 if (target_big_endian)
915 {
916 for (i = 0; i < prec; i++)
917 {
918 md_number_to_chars (litP, (valueT) words[i], 2);
919 litP += 2;
920 }
921 }
922 else
923 {
924 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
925 for (i = prec - 1; i >= 0; i--)
926 {
927 md_number_to_chars (litP, (valueT) words[i], 2);
928 litP += 2;
929 }
930 else
931 /* For a 4 byte float the order of elements in `words' is 1 0.
932 For an 8 byte float the order is 1 0 3 2. */
933 for (i = 0; i < prec; i += 2)
934 {
935 md_number_to_chars (litP, (valueT) words[i + 1], 2);
936 md_number_to_chars (litP + 2, (valueT) words[i], 2);
937 litP += 4;
938 }
939 }
940
941 return 0;
942 }
943
944 /* We handle all bad expressions here, so that we can report the faulty
945 instruction in the error message. */
946 void
947 md_operand (expressionS * expr)
948 {
949 if (in_my_get_expression)
950 expr->X_op = O_illegal;
951 }
952
953 /* Immediate values. */
954
955 /* Generic immediate-value read function for use in directives.
956 Accepts anything that 'expression' can fold to a constant.
957 *val receives the number. */
958 #ifdef OBJ_ELF
959 static int
960 immediate_for_directive (int *val)
961 {
962 expressionS exp;
963 exp.X_op = O_illegal;
964
965 if (is_immediate_prefix (*input_line_pointer))
966 {
967 input_line_pointer++;
968 expression (&exp);
969 }
970
971 if (exp.X_op != O_constant)
972 {
973 as_bad (_("expected #constant"));
974 ignore_rest_of_line ();
975 return FAIL;
976 }
977 *val = exp.X_add_number;
978 return SUCCESS;
979 }
980 #endif
981
982 /* Register parsing. */
983
984 /* Generic register parser. CCP points to what should be the
985 beginning of a register name. If it is indeed a valid register
986 name, advance CCP over it and return the reg_entry structure;
987 otherwise return NULL. Does not issue diagnostics. */
988
989 static struct reg_entry *
990 arm_reg_parse_multi (char **ccp)
991 {
992 char *start = *ccp;
993 char *p;
994 struct reg_entry *reg;
995
996 #ifdef REGISTER_PREFIX
997 if (*start != REGISTER_PREFIX)
998 return NULL;
999 start++;
1000 #endif
1001 #ifdef OPTIONAL_REGISTER_PREFIX
1002 if (*start == OPTIONAL_REGISTER_PREFIX)
1003 start++;
1004 #endif
1005
1006 p = start;
1007 if (!ISALPHA (*p) || !is_name_beginner (*p))
1008 return NULL;
1009
1010 do
1011 p++;
1012 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1013
1014 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1015
1016 if (!reg)
1017 return NULL;
1018
1019 *ccp = p;
1020 return reg;
1021 }
1022
1023 static int
1024 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1025 enum arm_reg_type type)
1026 {
1027 /* Alternative syntaxes are accepted for a few register classes. */
1028 switch (type)
1029 {
1030 case REG_TYPE_MVF:
1031 case REG_TYPE_MVD:
1032 case REG_TYPE_MVFX:
1033 case REG_TYPE_MVDX:
1034 /* Generic coprocessor register names are allowed for these. */
1035 if (reg && reg->type == REG_TYPE_CN)
1036 return reg->number;
1037 break;
1038
1039 case REG_TYPE_CP:
1040 /* For backward compatibility, a bare number is valid here. */
1041 {
1042 unsigned long processor = strtoul (start, ccp, 10);
1043 if (*ccp != start && processor <= 15)
1044 return processor;
1045 }
1046
1047 case REG_TYPE_MMXWC:
1048 /* WC includes WCG. ??? I'm not sure this is true for all
1049 instructions that take WC registers. */
1050 if (reg && reg->type == REG_TYPE_MMXWCG)
1051 return reg->number;
1052 break;
1053
1054 default:
1055 break;
1056 }
1057
1058 return FAIL;
1059 }
1060
1061 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1062 return value is the register number or FAIL. */
1063
1064 static int
1065 arm_reg_parse (char **ccp, enum arm_reg_type type)
1066 {
1067 char *start = *ccp;
1068 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1069 int ret;
1070
1071 /* Do not allow a scalar (reg+index) to parse as a register. */
1072 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1073 return FAIL;
1074
1075 if (reg && reg->type == type)
1076 return reg->number;
1077
1078 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1079 return ret;
1080
1081 *ccp = start;
1082 return FAIL;
1083 }
1084
1085 /* Parse a Neon type specifier. *STR should point at the leading '.'
1086 character. Does no verification at this stage that the type fits the opcode
1087 properly. E.g.,
1088
1089 .i32.i32.s16
1090 .s32.f32
1091 .u16
1092
1093 Can all be legally parsed by this function.
1094
1095 Fills in neon_type struct pointer with parsed information, and updates STR
1096 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1097 type, FAIL if not. */
1098
1099 static int
1100 parse_neon_type (struct neon_type *type, char **str)
1101 {
1102 char *ptr = *str;
1103
1104 if (type)
1105 type->elems = 0;
1106
1107 while (type->elems < NEON_MAX_TYPE_ELS)
1108 {
1109 enum neon_el_type thistype = NT_untyped;
1110 unsigned thissize = -1u;
1111
1112 if (*ptr != '.')
1113 break;
1114
1115 ptr++;
1116
1117 /* Just a size without an explicit type. */
1118 if (ISDIGIT (*ptr))
1119 goto parsesize;
1120
1121 switch (TOLOWER (*ptr))
1122 {
1123 case 'i': thistype = NT_integer; break;
1124 case 'f': thistype = NT_float; break;
1125 case 'p': thistype = NT_poly; break;
1126 case 's': thistype = NT_signed; break;
1127 case 'u': thistype = NT_unsigned; break;
1128 case 'd':
1129 thistype = NT_float;
1130 thissize = 64;
1131 ptr++;
1132 goto done;
1133 default:
1134 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1135 return FAIL;
1136 }
1137
1138 ptr++;
1139
1140 /* .f is an abbreviation for .f32. */
1141 if (thistype == NT_float && !ISDIGIT (*ptr))
1142 thissize = 32;
1143 else
1144 {
1145 parsesize:
1146 thissize = strtoul (ptr, &ptr, 10);
1147
1148 if (thissize != 8 && thissize != 16 && thissize != 32
1149 && thissize != 64)
1150 {
1151 as_bad (_("bad size %d in type specifier"), thissize);
1152 return FAIL;
1153 }
1154 }
1155
1156 done:
1157 if (type)
1158 {
1159 type->el[type->elems].type = thistype;
1160 type->el[type->elems].size = thissize;
1161 type->elems++;
1162 }
1163 }
1164
1165 /* Empty/missing type is not a successful parse. */
1166 if (type->elems == 0)
1167 return FAIL;
1168
1169 *str = ptr;
1170
1171 return SUCCESS;
1172 }
1173
1174 /* Errors may be set multiple times during parsing or bit encoding
1175 (particularly in the Neon bits), but usually the earliest error which is set
1176 will be the most meaningful. Avoid overwriting it with later (cascading)
1177 errors by calling this function. */
1178
1179 static void
1180 first_error (const char *err)
1181 {
1182 if (!inst.error)
1183 inst.error = err;
1184 }
1185
1186 /* Parse a single type, e.g. ".s32", leading period included. */
1187 static int
1188 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1189 {
1190 char *str = *ccp;
1191 struct neon_type optype;
1192
1193 if (*str == '.')
1194 {
1195 if (parse_neon_type (&optype, &str) == SUCCESS)
1196 {
1197 if (optype.elems == 1)
1198 *vectype = optype.el[0];
1199 else
1200 {
1201 first_error (_("only one type should be specified for operand"));
1202 return FAIL;
1203 }
1204 }
1205 else
1206 {
1207 first_error (_("vector type expected"));
1208 return FAIL;
1209 }
1210 }
1211 else
1212 return FAIL;
1213
1214 *ccp = str;
1215
1216 return SUCCESS;
1217 }
1218
1219 /* Special meanings for indices (which have a range of 0-7), which will fit into
1220 a 4-bit integer. */
1221
1222 #define NEON_ALL_LANES 15
1223 #define NEON_INTERLEAVE_LANES 14
1224
1225 /* Parse either a register or a scalar, with an optional type. Return the
1226 register number, and optionally fill in the actual type of the register
1227 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1228 type/index information in *TYPEINFO. */
1229
1230 static int
1231 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1232 enum arm_reg_type *rtype,
1233 struct neon_typed_alias *typeinfo)
1234 {
1235 char *str = *ccp;
1236 struct reg_entry *reg = arm_reg_parse_multi (&str);
1237 struct neon_typed_alias atype;
1238 struct neon_type_el parsetype;
1239
1240 atype.defined = 0;
1241 atype.index = -1;
1242 atype.eltype.type = NT_invtype;
1243 atype.eltype.size = -1;
1244
1245 /* Try alternate syntax for some types of register. Note these are mutually
1246 exclusive with the Neon syntax extensions. */
1247 if (reg == NULL)
1248 {
1249 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1250 if (altreg != FAIL)
1251 *ccp = str;
1252 if (typeinfo)
1253 *typeinfo = atype;
1254 return altreg;
1255 }
1256
1257 /* Undo polymorphism when a set of register types may be accepted. */
1258 if ((type == REG_TYPE_NDQ
1259 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1260 || (type == REG_TYPE_VFSD
1261 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1262 || (type == REG_TYPE_NSDQ
1263 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1264 || reg->type == REG_TYPE_NQ)))
1265 type = reg->type;
1266
1267 if (type != reg->type)
1268 return FAIL;
1269
1270 if (reg->neon)
1271 atype = *reg->neon;
1272
1273 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1274 {
1275 if ((atype.defined & NTA_HASTYPE) != 0)
1276 {
1277 first_error (_("can't redefine type for operand"));
1278 return FAIL;
1279 }
1280 atype.defined |= NTA_HASTYPE;
1281 atype.eltype = parsetype;
1282 }
1283
1284 if (skip_past_char (&str, '[') == SUCCESS)
1285 {
1286 if (type != REG_TYPE_VFD)
1287 {
1288 first_error (_("only D registers may be indexed"));
1289 return FAIL;
1290 }
1291
1292 if ((atype.defined & NTA_HASINDEX) != 0)
1293 {
1294 first_error (_("can't change index for operand"));
1295 return FAIL;
1296 }
1297
1298 atype.defined |= NTA_HASINDEX;
1299
1300 if (skip_past_char (&str, ']') == SUCCESS)
1301 atype.index = NEON_ALL_LANES;
1302 else
1303 {
1304 expressionS exp;
1305
1306 my_get_expression (&exp, &str, GE_NO_PREFIX);
1307
1308 if (exp.X_op != O_constant)
1309 {
1310 first_error (_("constant expression required"));
1311 return FAIL;
1312 }
1313
1314 if (skip_past_char (&str, ']') == FAIL)
1315 return FAIL;
1316
1317 atype.index = exp.X_add_number;
1318 }
1319 }
1320
1321 if (typeinfo)
1322 *typeinfo = atype;
1323
1324 if (rtype)
1325 *rtype = type;
1326
1327 *ccp = str;
1328
1329 return reg->number;
1330 }
1331
1332 /* Like arm_reg_parse, but allow allow the following extra features:
1333 - If RTYPE is non-zero, return the (possibly restricted) type of the
1334 register (e.g. Neon double or quad reg when either has been requested).
1335 - If this is a Neon vector type with additional type information, fill
1336 in the struct pointed to by VECTYPE (if non-NULL).
1337 This function will fault on encountering a scalar.
1338 */
1339
1340 static int
1341 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1342 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1343 {
1344 struct neon_typed_alias atype;
1345 char *str = *ccp;
1346 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1347
1348 if (reg == FAIL)
1349 return FAIL;
1350
1351 /* Do not allow a scalar (reg+index) to parse as a register. */
1352 if ((atype.defined & NTA_HASINDEX) != 0)
1353 {
1354 first_error (_("register operand expected, but got scalar"));
1355 return FAIL;
1356 }
1357
1358 if (vectype)
1359 *vectype = atype.eltype;
1360
1361 *ccp = str;
1362
1363 return reg;
1364 }
1365
1366 #define NEON_SCALAR_REG(X) ((X) >> 4)
1367 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1368
1369 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1370 have enough information to be able to do a good job bounds-checking. So, we
1371 just do easy checks here, and do further checks later. */
1372
1373 static int
1374 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1375 {
1376 int reg;
1377 char *str = *ccp;
1378 struct neon_typed_alias atype;
1379
1380 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
1381
1382 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1383 return FAIL;
1384
1385 if (atype.index == NEON_ALL_LANES)
1386 {
1387 first_error (_("scalar must have an index"));
1388 return FAIL;
1389 }
1390 else if (atype.index >= 64 / elsize)
1391 {
1392 first_error (_("scalar index out of range"));
1393 return FAIL;
1394 }
1395
1396 if (type)
1397 *type = atype.eltype;
1398
1399 *ccp = str;
1400
1401 return reg * 16 + atype.index;
1402 }
1403
1404 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1405 static long
1406 parse_reg_list (char ** strp)
1407 {
1408 char * str = * strp;
1409 long range = 0;
1410 int another_range;
1411
1412 /* We come back here if we get ranges concatenated by '+' or '|'. */
1413 do
1414 {
1415 another_range = 0;
1416
1417 if (*str == '{')
1418 {
1419 int in_range = 0;
1420 int cur_reg = -1;
1421
1422 str++;
1423 do
1424 {
1425 int reg;
1426
1427 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1428 {
1429 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
1430 return FAIL;
1431 }
1432
1433 if (in_range)
1434 {
1435 int i;
1436
1437 if (reg <= cur_reg)
1438 {
1439 first_error (_("bad range in register list"));
1440 return FAIL;
1441 }
1442
1443 for (i = cur_reg + 1; i < reg; i++)
1444 {
1445 if (range & (1 << i))
1446 as_tsktsk
1447 (_("Warning: duplicated register (r%d) in register list"),
1448 i);
1449 else
1450 range |= 1 << i;
1451 }
1452 in_range = 0;
1453 }
1454
1455 if (range & (1 << reg))
1456 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1457 reg);
1458 else if (reg <= cur_reg)
1459 as_tsktsk (_("Warning: register range not in ascending order"));
1460
1461 range |= 1 << reg;
1462 cur_reg = reg;
1463 }
1464 while (skip_past_comma (&str) != FAIL
1465 || (in_range = 1, *str++ == '-'));
1466 str--;
1467
1468 if (*str++ != '}')
1469 {
1470 first_error (_("missing `}'"));
1471 return FAIL;
1472 }
1473 }
1474 else
1475 {
1476 expressionS expr;
1477
1478 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1479 return FAIL;
1480
1481 if (expr.X_op == O_constant)
1482 {
1483 if (expr.X_add_number
1484 != (expr.X_add_number & 0x0000ffff))
1485 {
1486 inst.error = _("invalid register mask");
1487 return FAIL;
1488 }
1489
1490 if ((range & expr.X_add_number) != 0)
1491 {
1492 int regno = range & expr.X_add_number;
1493
1494 regno &= -regno;
1495 regno = (1 << regno) - 1;
1496 as_tsktsk
1497 (_("Warning: duplicated register (r%d) in register list"),
1498 regno);
1499 }
1500
1501 range |= expr.X_add_number;
1502 }
1503 else
1504 {
1505 if (inst.reloc.type != 0)
1506 {
1507 inst.error = _("expression too complex");
1508 return FAIL;
1509 }
1510
1511 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1512 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1513 inst.reloc.pc_rel = 0;
1514 }
1515 }
1516
1517 if (*str == '|' || *str == '+')
1518 {
1519 str++;
1520 another_range = 1;
1521 }
1522 }
1523 while (another_range);
1524
1525 *strp = str;
1526 return range;
1527 }
1528
1529 /* Types of registers in a list. */
1530
1531 enum reg_list_els
1532 {
1533 REGLIST_VFP_S,
1534 REGLIST_VFP_D,
1535 REGLIST_NEON_D
1536 };
1537
1538 /* Parse a VFP register list. If the string is invalid return FAIL.
1539 Otherwise return the number of registers, and set PBASE to the first
1540 register. Parses registers of type ETYPE.
1541 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1542 - Q registers can be used to specify pairs of D registers
1543 - { } can be omitted from around a singleton register list
1544 FIXME: This is not implemented, as it would require backtracking in
1545 some cases, e.g.:
1546 vtbl.8 d3,d4,d5
1547 This could be done (the meaning isn't really ambiguous), but doesn't
1548 fit in well with the current parsing framework.
1549 - 32 D registers may be used (also true for VFPv3).
1550 FIXME: Types are ignored in these register lists, which is probably a
1551 bug. */
1552
1553 static int
1554 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
1555 {
1556 char *str = *ccp;
1557 int base_reg;
1558 int new_base;
1559 enum arm_reg_type regtype = 0;
1560 int max_regs = 0;
1561 int count = 0;
1562 int warned = 0;
1563 unsigned long mask = 0;
1564 int i;
1565
1566 if (*str != '{')
1567 {
1568 inst.error = _("expecting {");
1569 return FAIL;
1570 }
1571
1572 str++;
1573
1574 switch (etype)
1575 {
1576 case REGLIST_VFP_S:
1577 regtype = REG_TYPE_VFS;
1578 max_regs = 32;
1579 break;
1580
1581 case REGLIST_VFP_D:
1582 regtype = REG_TYPE_VFD;
1583 break;
1584
1585 case REGLIST_NEON_D:
1586 regtype = REG_TYPE_NDQ;
1587 break;
1588 }
1589
1590 if (etype != REGLIST_VFP_S)
1591 {
1592 /* VFPv3 allows 32 D registers. */
1593 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
1594 {
1595 max_regs = 32;
1596 if (thumb_mode)
1597 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1598 fpu_vfp_ext_v3);
1599 else
1600 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1601 fpu_vfp_ext_v3);
1602 }
1603 else
1604 max_regs = 16;
1605 }
1606
1607 base_reg = max_regs;
1608
1609 do
1610 {
1611 int setmask = 1, addregs = 1;
1612
1613 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
1614
1615 if (new_base == FAIL)
1616 {
1617 first_error (_(reg_expected_msgs[regtype]));
1618 return FAIL;
1619 }
1620
1621 if (new_base >= max_regs)
1622 {
1623 first_error (_("register out of range in list"));
1624 return FAIL;
1625 }
1626
1627 /* Note: a value of 2 * n is returned for the register Q<n>. */
1628 if (regtype == REG_TYPE_NQ)
1629 {
1630 setmask = 3;
1631 addregs = 2;
1632 }
1633
1634 if (new_base < base_reg)
1635 base_reg = new_base;
1636
1637 if (mask & (setmask << new_base))
1638 {
1639 first_error (_("invalid register list"));
1640 return FAIL;
1641 }
1642
1643 if ((mask >> new_base) != 0 && ! warned)
1644 {
1645 as_tsktsk (_("register list not in ascending order"));
1646 warned = 1;
1647 }
1648
1649 mask |= setmask << new_base;
1650 count += addregs;
1651
1652 if (*str == '-') /* We have the start of a range expression */
1653 {
1654 int high_range;
1655
1656 str++;
1657
1658 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
1659 == FAIL)
1660 {
1661 inst.error = gettext (reg_expected_msgs[regtype]);
1662 return FAIL;
1663 }
1664
1665 if (high_range >= max_regs)
1666 {
1667 first_error (_("register out of range in list"));
1668 return FAIL;
1669 }
1670
1671 if (regtype == REG_TYPE_NQ)
1672 high_range = high_range + 1;
1673
1674 if (high_range <= new_base)
1675 {
1676 inst.error = _("register range not in ascending order");
1677 return FAIL;
1678 }
1679
1680 for (new_base += addregs; new_base <= high_range; new_base += addregs)
1681 {
1682 if (mask & (setmask << new_base))
1683 {
1684 inst.error = _("invalid register list");
1685 return FAIL;
1686 }
1687
1688 mask |= setmask << new_base;
1689 count += addregs;
1690 }
1691 }
1692 }
1693 while (skip_past_comma (&str) != FAIL);
1694
1695 str++;
1696
1697 /* Sanity check -- should have raised a parse error above. */
1698 if (count == 0 || count > max_regs)
1699 abort ();
1700
1701 *pbase = base_reg;
1702
1703 /* Final test -- the registers must be consecutive. */
1704 mask >>= base_reg;
1705 for (i = 0; i < count; i++)
1706 {
1707 if ((mask & (1u << i)) == 0)
1708 {
1709 inst.error = _("non-contiguous register range");
1710 return FAIL;
1711 }
1712 }
1713
1714 *ccp = str;
1715
1716 return count;
1717 }
1718
1719 /* True if two alias types are the same. */
1720
1721 static int
1722 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1723 {
1724 if (!a && !b)
1725 return 1;
1726
1727 if (!a || !b)
1728 return 0;
1729
1730 if (a->defined != b->defined)
1731 return 0;
1732
1733 if ((a->defined & NTA_HASTYPE) != 0
1734 && (a->eltype.type != b->eltype.type
1735 || a->eltype.size != b->eltype.size))
1736 return 0;
1737
1738 if ((a->defined & NTA_HASINDEX) != 0
1739 && (a->index != b->index))
1740 return 0;
1741
1742 return 1;
1743 }
1744
1745 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1746 The base register is put in *PBASE.
1747 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
1748 the return value.
1749 The register stride (minus one) is put in bit 4 of the return value.
1750 Bits [6:5] encode the list length (minus one).
1751 The type of the list elements is put in *ELTYPE, if non-NULL. */
1752
1753 #define NEON_LANE(X) ((X) & 0xf)
1754 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
1755 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1756
1757 static int
1758 parse_neon_el_struct_list (char **str, unsigned *pbase,
1759 struct neon_type_el *eltype)
1760 {
1761 char *ptr = *str;
1762 int base_reg = -1;
1763 int reg_incr = -1;
1764 int count = 0;
1765 int lane = -1;
1766 int leading_brace = 0;
1767 enum arm_reg_type rtype = REG_TYPE_NDQ;
1768 int addregs = 1;
1769 const char *const incr_error = "register stride must be 1 or 2";
1770 const char *const type_error = "mismatched element/structure types in list";
1771 struct neon_typed_alias firsttype;
1772
1773 if (skip_past_char (&ptr, '{') == SUCCESS)
1774 leading_brace = 1;
1775
1776 do
1777 {
1778 struct neon_typed_alias atype;
1779 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1780
1781 if (getreg == FAIL)
1782 {
1783 first_error (_(reg_expected_msgs[rtype]));
1784 return FAIL;
1785 }
1786
1787 if (base_reg == -1)
1788 {
1789 base_reg = getreg;
1790 if (rtype == REG_TYPE_NQ)
1791 {
1792 reg_incr = 1;
1793 addregs = 2;
1794 }
1795 firsttype = atype;
1796 }
1797 else if (reg_incr == -1)
1798 {
1799 reg_incr = getreg - base_reg;
1800 if (reg_incr < 1 || reg_incr > 2)
1801 {
1802 first_error (_(incr_error));
1803 return FAIL;
1804 }
1805 }
1806 else if (getreg != base_reg + reg_incr * count)
1807 {
1808 first_error (_(incr_error));
1809 return FAIL;
1810 }
1811
1812 if (!neon_alias_types_same (&atype, &firsttype))
1813 {
1814 first_error (_(type_error));
1815 return FAIL;
1816 }
1817
1818 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1819 modes. */
1820 if (ptr[0] == '-')
1821 {
1822 struct neon_typed_alias htype;
1823 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1824 if (lane == -1)
1825 lane = NEON_INTERLEAVE_LANES;
1826 else if (lane != NEON_INTERLEAVE_LANES)
1827 {
1828 first_error (_(type_error));
1829 return FAIL;
1830 }
1831 if (reg_incr == -1)
1832 reg_incr = 1;
1833 else if (reg_incr != 1)
1834 {
1835 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
1836 return FAIL;
1837 }
1838 ptr++;
1839 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
1840 if (hireg == FAIL)
1841 {
1842 first_error (_(reg_expected_msgs[rtype]));
1843 return FAIL;
1844 }
1845 if (!neon_alias_types_same (&htype, &firsttype))
1846 {
1847 first_error (_(type_error));
1848 return FAIL;
1849 }
1850 count += hireg + dregs - getreg;
1851 continue;
1852 }
1853
1854 /* If we're using Q registers, we can't use [] or [n] syntax. */
1855 if (rtype == REG_TYPE_NQ)
1856 {
1857 count += 2;
1858 continue;
1859 }
1860
1861 if ((atype.defined & NTA_HASINDEX) != 0)
1862 {
1863 if (lane == -1)
1864 lane = atype.index;
1865 else if (lane != atype.index)
1866 {
1867 first_error (_(type_error));
1868 return FAIL;
1869 }
1870 }
1871 else if (lane == -1)
1872 lane = NEON_INTERLEAVE_LANES;
1873 else if (lane != NEON_INTERLEAVE_LANES)
1874 {
1875 first_error (_(type_error));
1876 return FAIL;
1877 }
1878 count++;
1879 }
1880 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
1881
1882 /* No lane set by [x]. We must be interleaving structures. */
1883 if (lane == -1)
1884 lane = NEON_INTERLEAVE_LANES;
1885
1886 /* Sanity check. */
1887 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
1888 || (count > 1 && reg_incr == -1))
1889 {
1890 first_error (_("error parsing element/structure list"));
1891 return FAIL;
1892 }
1893
1894 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
1895 {
1896 first_error (_("expected }"));
1897 return FAIL;
1898 }
1899
1900 if (reg_incr == -1)
1901 reg_incr = 1;
1902
1903 if (eltype)
1904 *eltype = firsttype.eltype;
1905
1906 *pbase = base_reg;
1907 *str = ptr;
1908
1909 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
1910 }
1911
1912 /* Parse an explicit relocation suffix on an expression. This is
1913 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1914 arm_reloc_hsh contains no entries, so this function can only
1915 succeed if there is no () after the word. Returns -1 on error,
1916 BFD_RELOC_UNUSED if there wasn't any suffix. */
1917 static int
1918 parse_reloc (char **str)
1919 {
1920 struct reloc_entry *r;
1921 char *p, *q;
1922
1923 if (**str != '(')
1924 return BFD_RELOC_UNUSED;
1925
1926 p = *str + 1;
1927 q = p;
1928
1929 while (*q && *q != ')' && *q != ',')
1930 q++;
1931 if (*q != ')')
1932 return -1;
1933
1934 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1935 return -1;
1936
1937 *str = q + 1;
1938 return r->reloc;
1939 }
1940
1941 /* Directives: register aliases. */
1942
1943 static struct reg_entry *
1944 insert_reg_alias (char *str, int number, int type)
1945 {
1946 struct reg_entry *new;
1947 const char *name;
1948
1949 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1950 {
1951 if (new->builtin)
1952 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
1953
1954 /* Only warn about a redefinition if it's not defined as the
1955 same register. */
1956 else if (new->number != number || new->type != type)
1957 as_warn (_("ignoring redefinition of register alias '%s'"), str);
1958
1959 return 0;
1960 }
1961
1962 name = xstrdup (str);
1963 new = xmalloc (sizeof (struct reg_entry));
1964
1965 new->name = name;
1966 new->number = number;
1967 new->type = type;
1968 new->builtin = FALSE;
1969 new->neon = NULL;
1970
1971 if (hash_insert (arm_reg_hsh, name, (PTR) new))
1972 abort ();
1973
1974 return new;
1975 }
1976
1977 static void
1978 insert_neon_reg_alias (char *str, int number, int type,
1979 struct neon_typed_alias *atype)
1980 {
1981 struct reg_entry *reg = insert_reg_alias (str, number, type);
1982
1983 if (!reg)
1984 {
1985 first_error (_("attempt to redefine typed alias"));
1986 return;
1987 }
1988
1989 if (atype)
1990 {
1991 reg->neon = xmalloc (sizeof (struct neon_typed_alias));
1992 *reg->neon = *atype;
1993 }
1994 }
1995
1996 /* Look for the .req directive. This is of the form:
1997
1998 new_register_name .req existing_register_name
1999
2000 If we find one, or if it looks sufficiently like one that we want to
2001 handle any error here, return non-zero. Otherwise return zero. */
2002
2003 static int
2004 create_register_alias (char * newname, char *p)
2005 {
2006 struct reg_entry *old;
2007 char *oldname, *nbuf;
2008 size_t nlen;
2009
2010 /* The input scrubber ensures that whitespace after the mnemonic is
2011 collapsed to single spaces. */
2012 oldname = p;
2013 if (strncmp (oldname, " .req ", 6) != 0)
2014 return 0;
2015
2016 oldname += 6;
2017 if (*oldname == '\0')
2018 return 0;
2019
2020 old = hash_find (arm_reg_hsh, oldname);
2021 if (!old)
2022 {
2023 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2024 return 1;
2025 }
2026
2027 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2028 the desired alias name, and p points to its end. If not, then
2029 the desired alias name is in the global original_case_string. */
2030 #ifdef TC_CASE_SENSITIVE
2031 nlen = p - newname;
2032 #else
2033 newname = original_case_string;
2034 nlen = strlen (newname);
2035 #endif
2036
2037 nbuf = alloca (nlen + 1);
2038 memcpy (nbuf, newname, nlen);
2039 nbuf[nlen] = '\0';
2040
2041 /* Create aliases under the new name as stated; an all-lowercase
2042 version of the new name; and an all-uppercase version of the new
2043 name. */
2044 insert_reg_alias (nbuf, old->number, old->type);
2045
2046 for (p = nbuf; *p; p++)
2047 *p = TOUPPER (*p);
2048
2049 if (strncmp (nbuf, newname, nlen))
2050 insert_reg_alias (nbuf, old->number, old->type);
2051
2052 for (p = nbuf; *p; p++)
2053 *p = TOLOWER (*p);
2054
2055 if (strncmp (nbuf, newname, nlen))
2056 insert_reg_alias (nbuf, old->number, old->type);
2057
2058 return 1;
2059 }
2060
2061 /* Create a Neon typed/indexed register alias using directives, e.g.:
2062 X .dn d5.s32[1]
2063 Y .qn 6.s16
2064 Z .dn d7
2065 T .dn Z[0]
2066 These typed registers can be used instead of the types specified after the
2067 Neon mnemonic, so long as all operands given have types. Types can also be
2068 specified directly, e.g.:
2069 vadd d0.s32, d1.s32, d2.s32
2070 */
2071
2072 static int
2073 create_neon_reg_alias (char *newname, char *p)
2074 {
2075 enum arm_reg_type basetype;
2076 struct reg_entry *basereg;
2077 struct reg_entry mybasereg;
2078 struct neon_type ntype;
2079 struct neon_typed_alias typeinfo;
2080 char *namebuf, *nameend;
2081 int namelen;
2082
2083 typeinfo.defined = 0;
2084 typeinfo.eltype.type = NT_invtype;
2085 typeinfo.eltype.size = -1;
2086 typeinfo.index = -1;
2087
2088 nameend = p;
2089
2090 if (strncmp (p, " .dn ", 5) == 0)
2091 basetype = REG_TYPE_VFD;
2092 else if (strncmp (p, " .qn ", 5) == 0)
2093 basetype = REG_TYPE_NQ;
2094 else
2095 return 0;
2096
2097 p += 5;
2098
2099 if (*p == '\0')
2100 return 0;
2101
2102 basereg = arm_reg_parse_multi (&p);
2103
2104 if (basereg && basereg->type != basetype)
2105 {
2106 as_bad (_("bad type for register"));
2107 return 0;
2108 }
2109
2110 if (basereg == NULL)
2111 {
2112 expressionS exp;
2113 /* Try parsing as an integer. */
2114 my_get_expression (&exp, &p, GE_NO_PREFIX);
2115 if (exp.X_op != O_constant)
2116 {
2117 as_bad (_("expression must be constant"));
2118 return 0;
2119 }
2120 basereg = &mybasereg;
2121 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2122 : exp.X_add_number;
2123 basereg->neon = 0;
2124 }
2125
2126 if (basereg->neon)
2127 typeinfo = *basereg->neon;
2128
2129 if (parse_neon_type (&ntype, &p) == SUCCESS)
2130 {
2131 /* We got a type. */
2132 if (typeinfo.defined & NTA_HASTYPE)
2133 {
2134 as_bad (_("can't redefine the type of a register alias"));
2135 return 0;
2136 }
2137
2138 typeinfo.defined |= NTA_HASTYPE;
2139 if (ntype.elems != 1)
2140 {
2141 as_bad (_("you must specify a single type only"));
2142 return 0;
2143 }
2144 typeinfo.eltype = ntype.el[0];
2145 }
2146
2147 if (skip_past_char (&p, '[') == SUCCESS)
2148 {
2149 expressionS exp;
2150 /* We got a scalar index. */
2151
2152 if (typeinfo.defined & NTA_HASINDEX)
2153 {
2154 as_bad (_("can't redefine the index of a scalar alias"));
2155 return 0;
2156 }
2157
2158 my_get_expression (&exp, &p, GE_NO_PREFIX);
2159
2160 if (exp.X_op != O_constant)
2161 {
2162 as_bad (_("scalar index must be constant"));
2163 return 0;
2164 }
2165
2166 typeinfo.defined |= NTA_HASINDEX;
2167 typeinfo.index = exp.X_add_number;
2168
2169 if (skip_past_char (&p, ']') == FAIL)
2170 {
2171 as_bad (_("expecting ]"));
2172 return 0;
2173 }
2174 }
2175
2176 namelen = nameend - newname;
2177 namebuf = alloca (namelen + 1);
2178 strncpy (namebuf, newname, namelen);
2179 namebuf[namelen] = '\0';
2180
2181 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2182 typeinfo.defined != 0 ? &typeinfo : NULL);
2183
2184 /* Insert name in all uppercase. */
2185 for (p = namebuf; *p; p++)
2186 *p = TOUPPER (*p);
2187
2188 if (strncmp (namebuf, newname, namelen))
2189 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2190 typeinfo.defined != 0 ? &typeinfo : NULL);
2191
2192 /* Insert name in all lowercase. */
2193 for (p = namebuf; *p; p++)
2194 *p = TOLOWER (*p);
2195
2196 if (strncmp (namebuf, newname, namelen))
2197 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2198 typeinfo.defined != 0 ? &typeinfo : NULL);
2199
2200 return 1;
2201 }
2202
2203 /* Should never be called, as .req goes between the alias and the
2204 register name, not at the beginning of the line. */
2205 static void
2206 s_req (int a ATTRIBUTE_UNUSED)
2207 {
2208 as_bad (_("invalid syntax for .req directive"));
2209 }
2210
2211 static void
2212 s_dn (int a ATTRIBUTE_UNUSED)
2213 {
2214 as_bad (_("invalid syntax for .dn directive"));
2215 }
2216
2217 static void
2218 s_qn (int a ATTRIBUTE_UNUSED)
2219 {
2220 as_bad (_("invalid syntax for .qn directive"));
2221 }
2222
2223 /* The .unreq directive deletes an alias which was previously defined
2224 by .req. For example:
2225
2226 my_alias .req r11
2227 .unreq my_alias */
2228
2229 static void
2230 s_unreq (int a ATTRIBUTE_UNUSED)
2231 {
2232 char * name;
2233 char saved_char;
2234
2235 name = input_line_pointer;
2236
2237 while (*input_line_pointer != 0
2238 && *input_line_pointer != ' '
2239 && *input_line_pointer != '\n')
2240 ++input_line_pointer;
2241
2242 saved_char = *input_line_pointer;
2243 *input_line_pointer = 0;
2244
2245 if (!*name)
2246 as_bad (_("invalid syntax for .unreq directive"));
2247 else
2248 {
2249 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
2250
2251 if (!reg)
2252 as_bad (_("unknown register alias '%s'"), name);
2253 else if (reg->builtin)
2254 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2255 name);
2256 else
2257 {
2258 hash_delete (arm_reg_hsh, name);
2259 free ((char *) reg->name);
2260 if (reg->neon)
2261 free (reg->neon);
2262 free (reg);
2263 }
2264 }
2265
2266 *input_line_pointer = saved_char;
2267 demand_empty_rest_of_line ();
2268 }
2269
2270 /* Directives: Instruction set selection. */
2271
2272 #ifdef OBJ_ELF
2273 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2274 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2275 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2276 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2277
2278 static enum mstate mapstate = MAP_UNDEFINED;
2279
2280 static void
2281 mapping_state (enum mstate state)
2282 {
2283 symbolS * symbolP;
2284 const char * symname;
2285 int type;
2286
2287 if (mapstate == state)
2288 /* The mapping symbol has already been emitted.
2289 There is nothing else to do. */
2290 return;
2291
2292 mapstate = state;
2293
2294 switch (state)
2295 {
2296 case MAP_DATA:
2297 symname = "$d";
2298 type = BSF_NO_FLAGS;
2299 break;
2300 case MAP_ARM:
2301 symname = "$a";
2302 type = BSF_NO_FLAGS;
2303 break;
2304 case MAP_THUMB:
2305 symname = "$t";
2306 type = BSF_NO_FLAGS;
2307 break;
2308 case MAP_UNDEFINED:
2309 return;
2310 default:
2311 abort ();
2312 }
2313
2314 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2315
2316 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
2317 symbol_table_insert (symbolP);
2318 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2319
2320 switch (state)
2321 {
2322 case MAP_ARM:
2323 THUMB_SET_FUNC (symbolP, 0);
2324 ARM_SET_THUMB (symbolP, 0);
2325 ARM_SET_INTERWORK (symbolP, support_interwork);
2326 break;
2327
2328 case MAP_THUMB:
2329 THUMB_SET_FUNC (symbolP, 1);
2330 ARM_SET_THUMB (symbolP, 1);
2331 ARM_SET_INTERWORK (symbolP, support_interwork);
2332 break;
2333
2334 case MAP_DATA:
2335 default:
2336 return;
2337 }
2338 }
2339 #else
2340 #define mapping_state(x) /* nothing */
2341 #endif
2342
2343 /* Find the real, Thumb encoded start of a Thumb function. */
2344
2345 static symbolS *
2346 find_real_start (symbolS * symbolP)
2347 {
2348 char * real_start;
2349 const char * name = S_GET_NAME (symbolP);
2350 symbolS * new_target;
2351
2352 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2353 #define STUB_NAME ".real_start_of"
2354
2355 if (name == NULL)
2356 abort ();
2357
2358 /* The compiler may generate BL instructions to local labels because
2359 it needs to perform a branch to a far away location. These labels
2360 do not have a corresponding ".real_start_of" label. We check
2361 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2362 the ".real_start_of" convention for nonlocal branches. */
2363 if (S_IS_LOCAL (symbolP) || name[0] == '.')
2364 return symbolP;
2365
2366 real_start = ACONCAT ((STUB_NAME, name, NULL));
2367 new_target = symbol_find (real_start);
2368
2369 if (new_target == NULL)
2370 {
2371 as_warn ("Failed to find real start of function: %s\n", name);
2372 new_target = symbolP;
2373 }
2374
2375 return new_target;
2376 }
2377
2378 static void
2379 opcode_select (int width)
2380 {
2381 switch (width)
2382 {
2383 case 16:
2384 if (! thumb_mode)
2385 {
2386 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
2387 as_bad (_("selected processor does not support THUMB opcodes"));
2388
2389 thumb_mode = 1;
2390 /* No need to force the alignment, since we will have been
2391 coming from ARM mode, which is word-aligned. */
2392 record_alignment (now_seg, 1);
2393 }
2394 mapping_state (MAP_THUMB);
2395 break;
2396
2397 case 32:
2398 if (thumb_mode)
2399 {
2400 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
2401 as_bad (_("selected processor does not support ARM opcodes"));
2402
2403 thumb_mode = 0;
2404
2405 if (!need_pass_2)
2406 frag_align (2, 0, 0);
2407
2408 record_alignment (now_seg, 1);
2409 }
2410 mapping_state (MAP_ARM);
2411 break;
2412
2413 default:
2414 as_bad (_("invalid instruction size selected (%d)"), width);
2415 }
2416 }
2417
2418 static void
2419 s_arm (int ignore ATTRIBUTE_UNUSED)
2420 {
2421 opcode_select (32);
2422 demand_empty_rest_of_line ();
2423 }
2424
2425 static void
2426 s_thumb (int ignore ATTRIBUTE_UNUSED)
2427 {
2428 opcode_select (16);
2429 demand_empty_rest_of_line ();
2430 }
2431
2432 static void
2433 s_code (int unused ATTRIBUTE_UNUSED)
2434 {
2435 int temp;
2436
2437 temp = get_absolute_expression ();
2438 switch (temp)
2439 {
2440 case 16:
2441 case 32:
2442 opcode_select (temp);
2443 break;
2444
2445 default:
2446 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2447 }
2448 }
2449
2450 static void
2451 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2452 {
2453 /* If we are not already in thumb mode go into it, EVEN if
2454 the target processor does not support thumb instructions.
2455 This is used by gcc/config/arm/lib1funcs.asm for example
2456 to compile interworking support functions even if the
2457 target processor should not support interworking. */
2458 if (! thumb_mode)
2459 {
2460 thumb_mode = 2;
2461 record_alignment (now_seg, 1);
2462 }
2463
2464 demand_empty_rest_of_line ();
2465 }
2466
2467 static void
2468 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2469 {
2470 s_thumb (0);
2471
2472 /* The following label is the name/address of the start of a Thumb function.
2473 We need to know this for the interworking support. */
2474 label_is_thumb_function_name = TRUE;
2475 }
2476
2477 /* Perform a .set directive, but also mark the alias as
2478 being a thumb function. */
2479
2480 static void
2481 s_thumb_set (int equiv)
2482 {
2483 /* XXX the following is a duplicate of the code for s_set() in read.c
2484 We cannot just call that code as we need to get at the symbol that
2485 is created. */
2486 char * name;
2487 char delim;
2488 char * end_name;
2489 symbolS * symbolP;
2490
2491 /* Especial apologies for the random logic:
2492 This just grew, and could be parsed much more simply!
2493 Dean - in haste. */
2494 name = input_line_pointer;
2495 delim = get_symbol_end ();
2496 end_name = input_line_pointer;
2497 *end_name = delim;
2498
2499 if (*input_line_pointer != ',')
2500 {
2501 *end_name = 0;
2502 as_bad (_("expected comma after name \"%s\""), name);
2503 *end_name = delim;
2504 ignore_rest_of_line ();
2505 return;
2506 }
2507
2508 input_line_pointer++;
2509 *end_name = 0;
2510
2511 if (name[0] == '.' && name[1] == '\0')
2512 {
2513 /* XXX - this should not happen to .thumb_set. */
2514 abort ();
2515 }
2516
2517 if ((symbolP = symbol_find (name)) == NULL
2518 && (symbolP = md_undefined_symbol (name)) == NULL)
2519 {
2520 #ifndef NO_LISTING
2521 /* When doing symbol listings, play games with dummy fragments living
2522 outside the normal fragment chain to record the file and line info
2523 for this symbol. */
2524 if (listing & LISTING_SYMBOLS)
2525 {
2526 extern struct list_info_struct * listing_tail;
2527 fragS * dummy_frag = xmalloc (sizeof (fragS));
2528
2529 memset (dummy_frag, 0, sizeof (fragS));
2530 dummy_frag->fr_type = rs_fill;
2531 dummy_frag->line = listing_tail;
2532 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2533 dummy_frag->fr_symbol = symbolP;
2534 }
2535 else
2536 #endif
2537 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2538
2539 #ifdef OBJ_COFF
2540 /* "set" symbols are local unless otherwise specified. */
2541 SF_SET_LOCAL (symbolP);
2542 #endif /* OBJ_COFF */
2543 } /* Make a new symbol. */
2544
2545 symbol_table_insert (symbolP);
2546
2547 * end_name = delim;
2548
2549 if (equiv
2550 && S_IS_DEFINED (symbolP)
2551 && S_GET_SEGMENT (symbolP) != reg_section)
2552 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2553
2554 pseudo_set (symbolP);
2555
2556 demand_empty_rest_of_line ();
2557
2558 /* XXX Now we come to the Thumb specific bit of code. */
2559
2560 THUMB_SET_FUNC (symbolP, 1);
2561 ARM_SET_THUMB (symbolP, 1);
2562 #if defined OBJ_ELF || defined OBJ_COFF
2563 ARM_SET_INTERWORK (symbolP, support_interwork);
2564 #endif
2565 }
2566
2567 /* Directives: Mode selection. */
2568
2569 /* .syntax [unified|divided] - choose the new unified syntax
2570 (same for Arm and Thumb encoding, modulo slight differences in what
2571 can be represented) or the old divergent syntax for each mode. */
2572 static void
2573 s_syntax (int unused ATTRIBUTE_UNUSED)
2574 {
2575 char *name, delim;
2576
2577 name = input_line_pointer;
2578 delim = get_symbol_end ();
2579
2580 if (!strcasecmp (name, "unified"))
2581 unified_syntax = TRUE;
2582 else if (!strcasecmp (name, "divided"))
2583 unified_syntax = FALSE;
2584 else
2585 {
2586 as_bad (_("unrecognized syntax mode \"%s\""), name);
2587 return;
2588 }
2589 *input_line_pointer = delim;
2590 demand_empty_rest_of_line ();
2591 }
2592
2593 /* Directives: sectioning and alignment. */
2594
2595 /* Same as s_align_ptwo but align 0 => align 2. */
2596
2597 static void
2598 s_align (int unused ATTRIBUTE_UNUSED)
2599 {
2600 int temp;
2601 long temp_fill;
2602 long max_alignment = 15;
2603
2604 temp = get_absolute_expression ();
2605 if (temp > max_alignment)
2606 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2607 else if (temp < 0)
2608 {
2609 as_bad (_("alignment negative. 0 assumed."));
2610 temp = 0;
2611 }
2612
2613 if (*input_line_pointer == ',')
2614 {
2615 input_line_pointer++;
2616 temp_fill = get_absolute_expression ();
2617 }
2618 else
2619 temp_fill = 0;
2620
2621 if (!temp)
2622 temp = 2;
2623
2624 /* Only make a frag if we HAVE to. */
2625 if (temp && !need_pass_2)
2626 frag_align (temp, (int) temp_fill, 0);
2627 demand_empty_rest_of_line ();
2628
2629 record_alignment (now_seg, temp);
2630 }
2631
2632 static void
2633 s_bss (int ignore ATTRIBUTE_UNUSED)
2634 {
2635 /* We don't support putting frags in the BSS segment, we fake it by
2636 marking in_bss, then looking at s_skip for clues. */
2637 subseg_set (bss_section, 0);
2638 demand_empty_rest_of_line ();
2639 mapping_state (MAP_DATA);
2640 }
2641
2642 static void
2643 s_even (int ignore ATTRIBUTE_UNUSED)
2644 {
2645 /* Never make frag if expect extra pass. */
2646 if (!need_pass_2)
2647 frag_align (1, 0, 0);
2648
2649 record_alignment (now_seg, 1);
2650
2651 demand_empty_rest_of_line ();
2652 }
2653
2654 /* Directives: Literal pools. */
2655
2656 static literal_pool *
2657 find_literal_pool (void)
2658 {
2659 literal_pool * pool;
2660
2661 for (pool = list_of_pools; pool != NULL; pool = pool->next)
2662 {
2663 if (pool->section == now_seg
2664 && pool->sub_section == now_subseg)
2665 break;
2666 }
2667
2668 return pool;
2669 }
2670
2671 static literal_pool *
2672 find_or_make_literal_pool (void)
2673 {
2674 /* Next literal pool ID number. */
2675 static unsigned int latest_pool_num = 1;
2676 literal_pool * pool;
2677
2678 pool = find_literal_pool ();
2679
2680 if (pool == NULL)
2681 {
2682 /* Create a new pool. */
2683 pool = xmalloc (sizeof (* pool));
2684 if (! pool)
2685 return NULL;
2686
2687 pool->next_free_entry = 0;
2688 pool->section = now_seg;
2689 pool->sub_section = now_subseg;
2690 pool->next = list_of_pools;
2691 pool->symbol = NULL;
2692
2693 /* Add it to the list. */
2694 list_of_pools = pool;
2695 }
2696
2697 /* New pools, and emptied pools, will have a NULL symbol. */
2698 if (pool->symbol == NULL)
2699 {
2700 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2701 (valueT) 0, &zero_address_frag);
2702 pool->id = latest_pool_num ++;
2703 }
2704
2705 /* Done. */
2706 return pool;
2707 }
2708
2709 /* Add the literal in the global 'inst'
2710 structure to the relevent literal pool. */
2711
2712 static int
2713 add_to_lit_pool (void)
2714 {
2715 literal_pool * pool;
2716 unsigned int entry;
2717
2718 pool = find_or_make_literal_pool ();
2719
2720 /* Check if this literal value is already in the pool. */
2721 for (entry = 0; entry < pool->next_free_entry; entry ++)
2722 {
2723 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2724 && (inst.reloc.exp.X_op == O_constant)
2725 && (pool->literals[entry].X_add_number
2726 == inst.reloc.exp.X_add_number)
2727 && (pool->literals[entry].X_unsigned
2728 == inst.reloc.exp.X_unsigned))
2729 break;
2730
2731 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2732 && (inst.reloc.exp.X_op == O_symbol)
2733 && (pool->literals[entry].X_add_number
2734 == inst.reloc.exp.X_add_number)
2735 && (pool->literals[entry].X_add_symbol
2736 == inst.reloc.exp.X_add_symbol)
2737 && (pool->literals[entry].X_op_symbol
2738 == inst.reloc.exp.X_op_symbol))
2739 break;
2740 }
2741
2742 /* Do we need to create a new entry? */
2743 if (entry == pool->next_free_entry)
2744 {
2745 if (entry >= MAX_LITERAL_POOL_SIZE)
2746 {
2747 inst.error = _("literal pool overflow");
2748 return FAIL;
2749 }
2750
2751 pool->literals[entry] = inst.reloc.exp;
2752 pool->next_free_entry += 1;
2753 }
2754
2755 inst.reloc.exp.X_op = O_symbol;
2756 inst.reloc.exp.X_add_number = ((int) entry) * 4;
2757 inst.reloc.exp.X_add_symbol = pool->symbol;
2758
2759 return SUCCESS;
2760 }
2761
2762 /* Can't use symbol_new here, so have to create a symbol and then at
2763 a later date assign it a value. Thats what these functions do. */
2764
2765 static void
2766 symbol_locate (symbolS * symbolP,
2767 const char * name, /* It is copied, the caller can modify. */
2768 segT segment, /* Segment identifier (SEG_<something>). */
2769 valueT valu, /* Symbol value. */
2770 fragS * frag) /* Associated fragment. */
2771 {
2772 unsigned int name_length;
2773 char * preserved_copy_of_name;
2774
2775 name_length = strlen (name) + 1; /* +1 for \0. */
2776 obstack_grow (&notes, name, name_length);
2777 preserved_copy_of_name = obstack_finish (&notes);
2778
2779 #ifdef tc_canonicalize_symbol_name
2780 preserved_copy_of_name =
2781 tc_canonicalize_symbol_name (preserved_copy_of_name);
2782 #endif
2783
2784 S_SET_NAME (symbolP, preserved_copy_of_name);
2785
2786 S_SET_SEGMENT (symbolP, segment);
2787 S_SET_VALUE (symbolP, valu);
2788 symbol_clear_list_pointers (symbolP);
2789
2790 symbol_set_frag (symbolP, frag);
2791
2792 /* Link to end of symbol chain. */
2793 {
2794 extern int symbol_table_frozen;
2795
2796 if (symbol_table_frozen)
2797 abort ();
2798 }
2799
2800 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
2801
2802 obj_symbol_new_hook (symbolP);
2803
2804 #ifdef tc_symbol_new_hook
2805 tc_symbol_new_hook (symbolP);
2806 #endif
2807
2808 #ifdef DEBUG_SYMS
2809 verify_symbol_chain (symbol_rootP, symbol_lastP);
2810 #endif /* DEBUG_SYMS */
2811 }
2812
2813
2814 static void
2815 s_ltorg (int ignored ATTRIBUTE_UNUSED)
2816 {
2817 unsigned int entry;
2818 literal_pool * pool;
2819 char sym_name[20];
2820
2821 pool = find_literal_pool ();
2822 if (pool == NULL
2823 || pool->symbol == NULL
2824 || pool->next_free_entry == 0)
2825 return;
2826
2827 mapping_state (MAP_DATA);
2828
2829 /* Align pool as you have word accesses.
2830 Only make a frag if we have to. */
2831 if (!need_pass_2)
2832 frag_align (2, 0, 0);
2833
2834 record_alignment (now_seg, 2);
2835
2836 sprintf (sym_name, "$$lit_\002%x", pool->id);
2837
2838 symbol_locate (pool->symbol, sym_name, now_seg,
2839 (valueT) frag_now_fix (), frag_now);
2840 symbol_table_insert (pool->symbol);
2841
2842 ARM_SET_THUMB (pool->symbol, thumb_mode);
2843
2844 #if defined OBJ_COFF || defined OBJ_ELF
2845 ARM_SET_INTERWORK (pool->symbol, support_interwork);
2846 #endif
2847
2848 for (entry = 0; entry < pool->next_free_entry; entry ++)
2849 /* First output the expression in the instruction to the pool. */
2850 emit_expr (&(pool->literals[entry]), 4); /* .word */
2851
2852 /* Mark the pool as empty. */
2853 pool->next_free_entry = 0;
2854 pool->symbol = NULL;
2855 }
2856
2857 #ifdef OBJ_ELF
2858 /* Forward declarations for functions below, in the MD interface
2859 section. */
2860 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
2861 static valueT create_unwind_entry (int);
2862 static void start_unwind_section (const segT, int);
2863 static void add_unwind_opcode (valueT, int);
2864 static void flush_pending_unwind (void);
2865
2866 /* Directives: Data. */
2867
2868 static void
2869 s_arm_elf_cons (int nbytes)
2870 {
2871 expressionS exp;
2872
2873 #ifdef md_flush_pending_output
2874 md_flush_pending_output ();
2875 #endif
2876
2877 if (is_it_end_of_statement ())
2878 {
2879 demand_empty_rest_of_line ();
2880 return;
2881 }
2882
2883 #ifdef md_cons_align
2884 md_cons_align (nbytes);
2885 #endif
2886
2887 mapping_state (MAP_DATA);
2888 do
2889 {
2890 int reloc;
2891 char *base = input_line_pointer;
2892
2893 expression (& exp);
2894
2895 if (exp.X_op != O_symbol)
2896 emit_expr (&exp, (unsigned int) nbytes);
2897 else
2898 {
2899 char *before_reloc = input_line_pointer;
2900 reloc = parse_reloc (&input_line_pointer);
2901 if (reloc == -1)
2902 {
2903 as_bad (_("unrecognized relocation suffix"));
2904 ignore_rest_of_line ();
2905 return;
2906 }
2907 else if (reloc == BFD_RELOC_UNUSED)
2908 emit_expr (&exp, (unsigned int) nbytes);
2909 else
2910 {
2911 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
2912 int size = bfd_get_reloc_size (howto);
2913
2914 if (reloc == BFD_RELOC_ARM_PLT32)
2915 {
2916 as_bad (_("(plt) is only valid on branch targets"));
2917 reloc = BFD_RELOC_UNUSED;
2918 size = 0;
2919 }
2920
2921 if (size > nbytes)
2922 as_bad (_("%s relocations do not fit in %d bytes"),
2923 howto->name, nbytes);
2924 else
2925 {
2926 /* We've parsed an expression stopping at O_symbol.
2927 But there may be more expression left now that we
2928 have parsed the relocation marker. Parse it again.
2929 XXX Surely there is a cleaner way to do this. */
2930 char *p = input_line_pointer;
2931 int offset;
2932 char *save_buf = alloca (input_line_pointer - base);
2933 memcpy (save_buf, base, input_line_pointer - base);
2934 memmove (base + (input_line_pointer - before_reloc),
2935 base, before_reloc - base);
2936
2937 input_line_pointer = base + (input_line_pointer-before_reloc);
2938 expression (&exp);
2939 memcpy (base, save_buf, p - base);
2940
2941 offset = nbytes - size;
2942 p = frag_more ((int) nbytes);
2943 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
2944 size, &exp, 0, reloc);
2945 }
2946 }
2947 }
2948 }
2949 while (*input_line_pointer++ == ',');
2950
2951 /* Put terminator back into stream. */
2952 input_line_pointer --;
2953 demand_empty_rest_of_line ();
2954 }
2955
2956
2957 /* Parse a .rel31 directive. */
2958
2959 static void
2960 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
2961 {
2962 expressionS exp;
2963 char *p;
2964 valueT highbit;
2965
2966 highbit = 0;
2967 if (*input_line_pointer == '1')
2968 highbit = 0x80000000;
2969 else if (*input_line_pointer != '0')
2970 as_bad (_("expected 0 or 1"));
2971
2972 input_line_pointer++;
2973 if (*input_line_pointer != ',')
2974 as_bad (_("missing comma"));
2975 input_line_pointer++;
2976
2977 #ifdef md_flush_pending_output
2978 md_flush_pending_output ();
2979 #endif
2980
2981 #ifdef md_cons_align
2982 md_cons_align (4);
2983 #endif
2984
2985 mapping_state (MAP_DATA);
2986
2987 expression (&exp);
2988
2989 p = frag_more (4);
2990 md_number_to_chars (p, highbit, 4);
2991 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
2992 BFD_RELOC_ARM_PREL31);
2993
2994 demand_empty_rest_of_line ();
2995 }
2996
2997 /* Directives: AEABI stack-unwind tables. */
2998
2999 /* Parse an unwind_fnstart directive. Simply records the current location. */
3000
3001 static void
3002 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3003 {
3004 demand_empty_rest_of_line ();
3005 /* Mark the start of the function. */
3006 unwind.proc_start = expr_build_dot ();
3007
3008 /* Reset the rest of the unwind info. */
3009 unwind.opcode_count = 0;
3010 unwind.table_entry = NULL;
3011 unwind.personality_routine = NULL;
3012 unwind.personality_index = -1;
3013 unwind.frame_size = 0;
3014 unwind.fp_offset = 0;
3015 unwind.fp_reg = 13;
3016 unwind.fp_used = 0;
3017 unwind.sp_restored = 0;
3018 }
3019
3020
3021 /* Parse a handlerdata directive. Creates the exception handling table entry
3022 for the function. */
3023
3024 static void
3025 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3026 {
3027 demand_empty_rest_of_line ();
3028 if (unwind.table_entry)
3029 as_bad (_("dupicate .handlerdata directive"));
3030
3031 create_unwind_entry (1);
3032 }
3033
3034 /* Parse an unwind_fnend directive. Generates the index table entry. */
3035
3036 static void
3037 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3038 {
3039 long where;
3040 char *ptr;
3041 valueT val;
3042
3043 demand_empty_rest_of_line ();
3044
3045 /* Add eh table entry. */
3046 if (unwind.table_entry == NULL)
3047 val = create_unwind_entry (0);
3048 else
3049 val = 0;
3050
3051 /* Add index table entry. This is two words. */
3052 start_unwind_section (unwind.saved_seg, 1);
3053 frag_align (2, 0, 0);
3054 record_alignment (now_seg, 2);
3055
3056 ptr = frag_more (8);
3057 where = frag_now_fix () - 8;
3058
3059 /* Self relative offset of the function start. */
3060 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3061 BFD_RELOC_ARM_PREL31);
3062
3063 /* Indicate dependency on EHABI-defined personality routines to the
3064 linker, if it hasn't been done already. */
3065 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3066 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3067 {
3068 static const char *const name[] = {
3069 "__aeabi_unwind_cpp_pr0",
3070 "__aeabi_unwind_cpp_pr1",
3071 "__aeabi_unwind_cpp_pr2"
3072 };
3073 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3074 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3075 marked_pr_dependency |= 1 << unwind.personality_index;
3076 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3077 = marked_pr_dependency;
3078 }
3079
3080 if (val)
3081 /* Inline exception table entry. */
3082 md_number_to_chars (ptr + 4, val, 4);
3083 else
3084 /* Self relative offset of the table entry. */
3085 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3086 BFD_RELOC_ARM_PREL31);
3087
3088 /* Restore the original section. */
3089 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3090 }
3091
3092
3093 /* Parse an unwind_cantunwind directive. */
3094
3095 static void
3096 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3097 {
3098 demand_empty_rest_of_line ();
3099 if (unwind.personality_routine || unwind.personality_index != -1)
3100 as_bad (_("personality routine specified for cantunwind frame"));
3101
3102 unwind.personality_index = -2;
3103 }
3104
3105
3106 /* Parse a personalityindex directive. */
3107
3108 static void
3109 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3110 {
3111 expressionS exp;
3112
3113 if (unwind.personality_routine || unwind.personality_index != -1)
3114 as_bad (_("duplicate .personalityindex directive"));
3115
3116 expression (&exp);
3117
3118 if (exp.X_op != O_constant
3119 || exp.X_add_number < 0 || exp.X_add_number > 15)
3120 {
3121 as_bad (_("bad personality routine number"));
3122 ignore_rest_of_line ();
3123 return;
3124 }
3125
3126 unwind.personality_index = exp.X_add_number;
3127
3128 demand_empty_rest_of_line ();
3129 }
3130
3131
3132 /* Parse a personality directive. */
3133
3134 static void
3135 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3136 {
3137 char *name, *p, c;
3138
3139 if (unwind.personality_routine || unwind.personality_index != -1)
3140 as_bad (_("duplicate .personality directive"));
3141
3142 name = input_line_pointer;
3143 c = get_symbol_end ();
3144 p = input_line_pointer;
3145 unwind.personality_routine = symbol_find_or_make (name);
3146 *p = c;
3147 demand_empty_rest_of_line ();
3148 }
3149
3150
3151 /* Parse a directive saving core registers. */
3152
3153 static void
3154 s_arm_unwind_save_core (void)
3155 {
3156 valueT op;
3157 long range;
3158 int n;
3159
3160 range = parse_reg_list (&input_line_pointer);
3161 if (range == FAIL)
3162 {
3163 as_bad (_("expected register list"));
3164 ignore_rest_of_line ();
3165 return;
3166 }
3167
3168 demand_empty_rest_of_line ();
3169
3170 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3171 into .unwind_save {..., sp...}. We aren't bothered about the value of
3172 ip because it is clobbered by calls. */
3173 if (unwind.sp_restored && unwind.fp_reg == 12
3174 && (range & 0x3000) == 0x1000)
3175 {
3176 unwind.opcode_count--;
3177 unwind.sp_restored = 0;
3178 range = (range | 0x2000) & ~0x1000;
3179 unwind.pending_offset = 0;
3180 }
3181
3182 /* Pop r4-r15. */
3183 if (range & 0xfff0)
3184 {
3185 /* See if we can use the short opcodes. These pop a block of up to 8
3186 registers starting with r4, plus maybe r14. */
3187 for (n = 0; n < 8; n++)
3188 {
3189 /* Break at the first non-saved register. */
3190 if ((range & (1 << (n + 4))) == 0)
3191 break;
3192 }
3193 /* See if there are any other bits set. */
3194 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3195 {
3196 /* Use the long form. */
3197 op = 0x8000 | ((range >> 4) & 0xfff);
3198 add_unwind_opcode (op, 2);
3199 }
3200 else
3201 {
3202 /* Use the short form. */
3203 if (range & 0x4000)
3204 op = 0xa8; /* Pop r14. */
3205 else
3206 op = 0xa0; /* Do not pop r14. */
3207 op |= (n - 1);
3208 add_unwind_opcode (op, 1);
3209 }
3210 }
3211
3212 /* Pop r0-r3. */
3213 if (range & 0xf)
3214 {
3215 op = 0xb100 | (range & 0xf);
3216 add_unwind_opcode (op, 2);
3217 }
3218
3219 /* Record the number of bytes pushed. */
3220 for (n = 0; n < 16; n++)
3221 {
3222 if (range & (1 << n))
3223 unwind.frame_size += 4;
3224 }
3225 }
3226
3227
3228 /* Parse a directive saving FPA registers. */
3229
3230 static void
3231 s_arm_unwind_save_fpa (int reg)
3232 {
3233 expressionS exp;
3234 int num_regs;
3235 valueT op;
3236
3237 /* Get Number of registers to transfer. */
3238 if (skip_past_comma (&input_line_pointer) != FAIL)
3239 expression (&exp);
3240 else
3241 exp.X_op = O_illegal;
3242
3243 if (exp.X_op != O_constant)
3244 {
3245 as_bad (_("expected , <constant>"));
3246 ignore_rest_of_line ();
3247 return;
3248 }
3249
3250 num_regs = exp.X_add_number;
3251
3252 if (num_regs < 1 || num_regs > 4)
3253 {
3254 as_bad (_("number of registers must be in the range [1:4]"));
3255 ignore_rest_of_line ();
3256 return;
3257 }
3258
3259 demand_empty_rest_of_line ();
3260
3261 if (reg == 4)
3262 {
3263 /* Short form. */
3264 op = 0xb4 | (num_regs - 1);
3265 add_unwind_opcode (op, 1);
3266 }
3267 else
3268 {
3269 /* Long form. */
3270 op = 0xc800 | (reg << 4) | (num_regs - 1);
3271 add_unwind_opcode (op, 2);
3272 }
3273 unwind.frame_size += num_regs * 12;
3274 }
3275
3276
3277 /* Parse a directive saving VFP registers for ARMv6 and above. */
3278
3279 static void
3280 s_arm_unwind_save_vfp_armv6 (void)
3281 {
3282 int count;
3283 unsigned int start;
3284 valueT op;
3285 int num_vfpv3_regs = 0;
3286 int num_regs_below_16;
3287
3288 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3289 if (count == FAIL)
3290 {
3291 as_bad (_("expected register list"));
3292 ignore_rest_of_line ();
3293 return;
3294 }
3295
3296 demand_empty_rest_of_line ();
3297
3298 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3299 than FSTMX/FLDMX-style ones). */
3300
3301 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3302 if (start >= 16)
3303 num_vfpv3_regs = count;
3304 else if (start + count > 16)
3305 num_vfpv3_regs = start + count - 16;
3306
3307 if (num_vfpv3_regs > 0)
3308 {
3309 int start_offset = start > 16 ? start - 16 : 0;
3310 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3311 add_unwind_opcode (op, 2);
3312 }
3313
3314 /* Generate opcode for registers numbered in the range 0 .. 15. */
3315 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3316 assert (num_regs_below_16 + num_vfpv3_regs == count);
3317 if (num_regs_below_16 > 0)
3318 {
3319 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3320 add_unwind_opcode (op, 2);
3321 }
3322
3323 unwind.frame_size += count * 8;
3324 }
3325
3326
3327 /* Parse a directive saving VFP registers for pre-ARMv6. */
3328
3329 static void
3330 s_arm_unwind_save_vfp (void)
3331 {
3332 int count;
3333 unsigned int reg;
3334 valueT op;
3335
3336 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
3337 if (count == FAIL)
3338 {
3339 as_bad (_("expected register list"));
3340 ignore_rest_of_line ();
3341 return;
3342 }
3343
3344 demand_empty_rest_of_line ();
3345
3346 if (reg == 8)
3347 {
3348 /* Short form. */
3349 op = 0xb8 | (count - 1);
3350 add_unwind_opcode (op, 1);
3351 }
3352 else
3353 {
3354 /* Long form. */
3355 op = 0xb300 | (reg << 4) | (count - 1);
3356 add_unwind_opcode (op, 2);
3357 }
3358 unwind.frame_size += count * 8 + 4;
3359 }
3360
3361
3362 /* Parse a directive saving iWMMXt data registers. */
3363
3364 static void
3365 s_arm_unwind_save_mmxwr (void)
3366 {
3367 int reg;
3368 int hi_reg;
3369 int i;
3370 unsigned mask = 0;
3371 valueT op;
3372
3373 if (*input_line_pointer == '{')
3374 input_line_pointer++;
3375
3376 do
3377 {
3378 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3379
3380 if (reg == FAIL)
3381 {
3382 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3383 goto error;
3384 }
3385
3386 if (mask >> reg)
3387 as_tsktsk (_("register list not in ascending order"));
3388 mask |= 1 << reg;
3389
3390 if (*input_line_pointer == '-')
3391 {
3392 input_line_pointer++;
3393 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3394 if (hi_reg == FAIL)
3395 {
3396 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3397 goto error;
3398 }
3399 else if (reg >= hi_reg)
3400 {
3401 as_bad (_("bad register range"));
3402 goto error;
3403 }
3404 for (; reg < hi_reg; reg++)
3405 mask |= 1 << reg;
3406 }
3407 }
3408 while (skip_past_comma (&input_line_pointer) != FAIL);
3409
3410 if (*input_line_pointer == '}')
3411 input_line_pointer++;
3412
3413 demand_empty_rest_of_line ();
3414
3415 /* Generate any deferred opcodes because we're going to be looking at
3416 the list. */
3417 flush_pending_unwind ();
3418
3419 for (i = 0; i < 16; i++)
3420 {
3421 if (mask & (1 << i))
3422 unwind.frame_size += 8;
3423 }
3424
3425 /* Attempt to combine with a previous opcode. We do this because gcc
3426 likes to output separate unwind directives for a single block of
3427 registers. */
3428 if (unwind.opcode_count > 0)
3429 {
3430 i = unwind.opcodes[unwind.opcode_count - 1];
3431 if ((i & 0xf8) == 0xc0)
3432 {
3433 i &= 7;
3434 /* Only merge if the blocks are contiguous. */
3435 if (i < 6)
3436 {
3437 if ((mask & 0xfe00) == (1 << 9))
3438 {
3439 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3440 unwind.opcode_count--;
3441 }
3442 }
3443 else if (i == 6 && unwind.opcode_count >= 2)
3444 {
3445 i = unwind.opcodes[unwind.opcode_count - 2];
3446 reg = i >> 4;
3447 i &= 0xf;
3448
3449 op = 0xffff << (reg - 1);
3450 if (reg > 0
3451 || ((mask & op) == (1u << (reg - 1))))
3452 {
3453 op = (1 << (reg + i + 1)) - 1;
3454 op &= ~((1 << reg) - 1);
3455 mask |= op;
3456 unwind.opcode_count -= 2;
3457 }
3458 }
3459 }
3460 }
3461
3462 hi_reg = 15;
3463 /* We want to generate opcodes in the order the registers have been
3464 saved, ie. descending order. */
3465 for (reg = 15; reg >= -1; reg--)
3466 {
3467 /* Save registers in blocks. */
3468 if (reg < 0
3469 || !(mask & (1 << reg)))
3470 {
3471 /* We found an unsaved reg. Generate opcodes to save the
3472 preceeding block. */
3473 if (reg != hi_reg)
3474 {
3475 if (reg == 9)
3476 {
3477 /* Short form. */
3478 op = 0xc0 | (hi_reg - 10);
3479 add_unwind_opcode (op, 1);
3480 }
3481 else
3482 {
3483 /* Long form. */
3484 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3485 add_unwind_opcode (op, 2);
3486 }
3487 }
3488 hi_reg = reg - 1;
3489 }
3490 }
3491
3492 return;
3493 error:
3494 ignore_rest_of_line ();
3495 }
3496
3497 static void
3498 s_arm_unwind_save_mmxwcg (void)
3499 {
3500 int reg;
3501 int hi_reg;
3502 unsigned mask = 0;
3503 valueT op;
3504
3505 if (*input_line_pointer == '{')
3506 input_line_pointer++;
3507
3508 do
3509 {
3510 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3511
3512 if (reg == FAIL)
3513 {
3514 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3515 goto error;
3516 }
3517
3518 reg -= 8;
3519 if (mask >> reg)
3520 as_tsktsk (_("register list not in ascending order"));
3521 mask |= 1 << reg;
3522
3523 if (*input_line_pointer == '-')
3524 {
3525 input_line_pointer++;
3526 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3527 if (hi_reg == FAIL)
3528 {
3529 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3530 goto error;
3531 }
3532 else if (reg >= hi_reg)
3533 {
3534 as_bad (_("bad register range"));
3535 goto error;
3536 }
3537 for (; reg < hi_reg; reg++)
3538 mask |= 1 << reg;
3539 }
3540 }
3541 while (skip_past_comma (&input_line_pointer) != FAIL);
3542
3543 if (*input_line_pointer == '}')
3544 input_line_pointer++;
3545
3546 demand_empty_rest_of_line ();
3547
3548 /* Generate any deferred opcodes because we're going to be looking at
3549 the list. */
3550 flush_pending_unwind ();
3551
3552 for (reg = 0; reg < 16; reg++)
3553 {
3554 if (mask & (1 << reg))
3555 unwind.frame_size += 4;
3556 }
3557 op = 0xc700 | mask;
3558 add_unwind_opcode (op, 2);
3559 return;
3560 error:
3561 ignore_rest_of_line ();
3562 }
3563
3564
3565 /* Parse an unwind_save directive.
3566 If the argument is non-zero, this is a .vsave directive. */
3567
3568 static void
3569 s_arm_unwind_save (int arch_v6)
3570 {
3571 char *peek;
3572 struct reg_entry *reg;
3573 bfd_boolean had_brace = FALSE;
3574
3575 /* Figure out what sort of save we have. */
3576 peek = input_line_pointer;
3577
3578 if (*peek == '{')
3579 {
3580 had_brace = TRUE;
3581 peek++;
3582 }
3583
3584 reg = arm_reg_parse_multi (&peek);
3585
3586 if (!reg)
3587 {
3588 as_bad (_("register expected"));
3589 ignore_rest_of_line ();
3590 return;
3591 }
3592
3593 switch (reg->type)
3594 {
3595 case REG_TYPE_FN:
3596 if (had_brace)
3597 {
3598 as_bad (_("FPA .unwind_save does not take a register list"));
3599 ignore_rest_of_line ();
3600 return;
3601 }
3602 s_arm_unwind_save_fpa (reg->number);
3603 return;
3604
3605 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
3606 case REG_TYPE_VFD:
3607 if (arch_v6)
3608 s_arm_unwind_save_vfp_armv6 ();
3609 else
3610 s_arm_unwind_save_vfp ();
3611 return;
3612 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
3613 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
3614
3615 default:
3616 as_bad (_(".unwind_save does not support this kind of register"));
3617 ignore_rest_of_line ();
3618 }
3619 }
3620
3621
3622 /* Parse an unwind_movsp directive. */
3623
3624 static void
3625 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
3626 {
3627 int reg;
3628 valueT op;
3629
3630 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3631 if (reg == FAIL)
3632 {
3633 as_bad (_(reg_expected_msgs[REG_TYPE_RN]));
3634 ignore_rest_of_line ();
3635 return;
3636 }
3637 demand_empty_rest_of_line ();
3638
3639 if (reg == REG_SP || reg == REG_PC)
3640 {
3641 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
3642 return;
3643 }
3644
3645 if (unwind.fp_reg != REG_SP)
3646 as_bad (_("unexpected .unwind_movsp directive"));
3647
3648 /* Generate opcode to restore the value. */
3649 op = 0x90 | reg;
3650 add_unwind_opcode (op, 1);
3651
3652 /* Record the information for later. */
3653 unwind.fp_reg = reg;
3654 unwind.fp_offset = unwind.frame_size;
3655 unwind.sp_restored = 1;
3656 }
3657
3658 /* Parse an unwind_pad directive. */
3659
3660 static void
3661 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
3662 {
3663 int offset;
3664
3665 if (immediate_for_directive (&offset) == FAIL)
3666 return;
3667
3668 if (offset & 3)
3669 {
3670 as_bad (_("stack increment must be multiple of 4"));
3671 ignore_rest_of_line ();
3672 return;
3673 }
3674
3675 /* Don't generate any opcodes, just record the details for later. */
3676 unwind.frame_size += offset;
3677 unwind.pending_offset += offset;
3678
3679 demand_empty_rest_of_line ();
3680 }
3681
3682 /* Parse an unwind_setfp directive. */
3683
3684 static void
3685 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
3686 {
3687 int sp_reg;
3688 int fp_reg;
3689 int offset;
3690
3691 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3692 if (skip_past_comma (&input_line_pointer) == FAIL)
3693 sp_reg = FAIL;
3694 else
3695 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3696
3697 if (fp_reg == FAIL || sp_reg == FAIL)
3698 {
3699 as_bad (_("expected <reg>, <reg>"));
3700 ignore_rest_of_line ();
3701 return;
3702 }
3703
3704 /* Optional constant. */
3705 if (skip_past_comma (&input_line_pointer) != FAIL)
3706 {
3707 if (immediate_for_directive (&offset) == FAIL)
3708 return;
3709 }
3710 else
3711 offset = 0;
3712
3713 demand_empty_rest_of_line ();
3714
3715 if (sp_reg != 13 && sp_reg != unwind.fp_reg)
3716 {
3717 as_bad (_("register must be either sp or set by a previous"
3718 "unwind_movsp directive"));
3719 return;
3720 }
3721
3722 /* Don't generate any opcodes, just record the information for later. */
3723 unwind.fp_reg = fp_reg;
3724 unwind.fp_used = 1;
3725 if (sp_reg == 13)
3726 unwind.fp_offset = unwind.frame_size - offset;
3727 else
3728 unwind.fp_offset -= offset;
3729 }
3730
3731 /* Parse an unwind_raw directive. */
3732
3733 static void
3734 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
3735 {
3736 expressionS exp;
3737 /* This is an arbitrary limit. */
3738 unsigned char op[16];
3739 int count;
3740
3741 expression (&exp);
3742 if (exp.X_op == O_constant
3743 && skip_past_comma (&input_line_pointer) != FAIL)
3744 {
3745 unwind.frame_size += exp.X_add_number;
3746 expression (&exp);
3747 }
3748 else
3749 exp.X_op = O_illegal;
3750
3751 if (exp.X_op != O_constant)
3752 {
3753 as_bad (_("expected <offset>, <opcode>"));
3754 ignore_rest_of_line ();
3755 return;
3756 }
3757
3758 count = 0;
3759
3760 /* Parse the opcode. */
3761 for (;;)
3762 {
3763 if (count >= 16)
3764 {
3765 as_bad (_("unwind opcode too long"));
3766 ignore_rest_of_line ();
3767 }
3768 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
3769 {
3770 as_bad (_("invalid unwind opcode"));
3771 ignore_rest_of_line ();
3772 return;
3773 }
3774 op[count++] = exp.X_add_number;
3775
3776 /* Parse the next byte. */
3777 if (skip_past_comma (&input_line_pointer) == FAIL)
3778 break;
3779
3780 expression (&exp);
3781 }
3782
3783 /* Add the opcode bytes in reverse order. */
3784 while (count--)
3785 add_unwind_opcode (op[count], 1);
3786
3787 demand_empty_rest_of_line ();
3788 }
3789
3790
3791 /* Parse a .eabi_attribute directive. */
3792
3793 static void
3794 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
3795 {
3796 expressionS exp;
3797 bfd_boolean is_string;
3798 int tag;
3799 unsigned int i = 0;
3800 char *s = NULL;
3801 char saved_char;
3802
3803 expression (& exp);
3804 if (exp.X_op != O_constant)
3805 goto bad;
3806
3807 tag = exp.X_add_number;
3808 if (tag == 4 || tag == 5 || tag == 32 || (tag > 32 && (tag & 1) != 0))
3809 is_string = 1;
3810 else
3811 is_string = 0;
3812
3813 if (skip_past_comma (&input_line_pointer) == FAIL)
3814 goto bad;
3815 if (tag == 32 || !is_string)
3816 {
3817 expression (& exp);
3818 if (exp.X_op != O_constant)
3819 {
3820 as_bad (_("expected numeric constant"));
3821 ignore_rest_of_line ();
3822 return;
3823 }
3824 i = exp.X_add_number;
3825 }
3826 if (tag == Tag_compatibility
3827 && skip_past_comma (&input_line_pointer) == FAIL)
3828 {
3829 as_bad (_("expected comma"));
3830 ignore_rest_of_line ();
3831 return;
3832 }
3833 if (is_string)
3834 {
3835 skip_whitespace(input_line_pointer);
3836 if (*input_line_pointer != '"')
3837 goto bad_string;
3838 input_line_pointer++;
3839 s = input_line_pointer;
3840 while (*input_line_pointer && *input_line_pointer != '"')
3841 input_line_pointer++;
3842 if (*input_line_pointer != '"')
3843 goto bad_string;
3844 saved_char = *input_line_pointer;
3845 *input_line_pointer = 0;
3846 }
3847 else
3848 {
3849 s = NULL;
3850 saved_char = 0;
3851 }
3852
3853 if (tag == Tag_compatibility)
3854 elf32_arm_add_eabi_attr_compat (stdoutput, i, s);
3855 else if (is_string)
3856 elf32_arm_add_eabi_attr_string (stdoutput, tag, s);
3857 else
3858 elf32_arm_add_eabi_attr_int (stdoutput, tag, i);
3859
3860 if (s)
3861 {
3862 *input_line_pointer = saved_char;
3863 input_line_pointer++;
3864 }
3865 demand_empty_rest_of_line ();
3866 return;
3867 bad_string:
3868 as_bad (_("bad string constant"));
3869 ignore_rest_of_line ();
3870 return;
3871 bad:
3872 as_bad (_("expected <tag> , <value>"));
3873 ignore_rest_of_line ();
3874 }
3875 #endif /* OBJ_ELF */
3876
3877 static void s_arm_arch (int);
3878 static void s_arm_cpu (int);
3879 static void s_arm_fpu (int);
3880
3881 /* This table describes all the machine specific pseudo-ops the assembler
3882 has to support. The fields are:
3883 pseudo-op name without dot
3884 function to call to execute this pseudo-op
3885 Integer arg to pass to the function. */
3886
3887 const pseudo_typeS md_pseudo_table[] =
3888 {
3889 /* Never called because '.req' does not start a line. */
3890 { "req", s_req, 0 },
3891 /* Following two are likewise never called. */
3892 { "dn", s_dn, 0 },
3893 { "qn", s_qn, 0 },
3894 { "unreq", s_unreq, 0 },
3895 { "bss", s_bss, 0 },
3896 { "align", s_align, 0 },
3897 { "arm", s_arm, 0 },
3898 { "thumb", s_thumb, 0 },
3899 { "code", s_code, 0 },
3900 { "force_thumb", s_force_thumb, 0 },
3901 { "thumb_func", s_thumb_func, 0 },
3902 { "thumb_set", s_thumb_set, 0 },
3903 { "even", s_even, 0 },
3904 { "ltorg", s_ltorg, 0 },
3905 { "pool", s_ltorg, 0 },
3906 { "syntax", s_syntax, 0 },
3907 { "cpu", s_arm_cpu, 0 },
3908 { "arch", s_arm_arch, 0 },
3909 { "fpu", s_arm_fpu, 0 },
3910 #ifdef OBJ_ELF
3911 { "word", s_arm_elf_cons, 4 },
3912 { "long", s_arm_elf_cons, 4 },
3913 { "rel31", s_arm_rel31, 0 },
3914 { "fnstart", s_arm_unwind_fnstart, 0 },
3915 { "fnend", s_arm_unwind_fnend, 0 },
3916 { "cantunwind", s_arm_unwind_cantunwind, 0 },
3917 { "personality", s_arm_unwind_personality, 0 },
3918 { "personalityindex", s_arm_unwind_personalityindex, 0 },
3919 { "handlerdata", s_arm_unwind_handlerdata, 0 },
3920 { "save", s_arm_unwind_save, 0 },
3921 { "vsave", s_arm_unwind_save, 1 },
3922 { "movsp", s_arm_unwind_movsp, 0 },
3923 { "pad", s_arm_unwind_pad, 0 },
3924 { "setfp", s_arm_unwind_setfp, 0 },
3925 { "unwind_raw", s_arm_unwind_raw, 0 },
3926 { "eabi_attribute", s_arm_eabi_attribute, 0 },
3927 #else
3928 { "word", cons, 4},
3929 #endif
3930 { "extend", float_cons, 'x' },
3931 { "ldouble", float_cons, 'x' },
3932 { "packed", float_cons, 'p' },
3933 { 0, 0, 0 }
3934 };
3935 \f
3936 /* Parser functions used exclusively in instruction operands. */
3937
3938 /* Generic immediate-value read function for use in insn parsing.
3939 STR points to the beginning of the immediate (the leading #);
3940 VAL receives the value; if the value is outside [MIN, MAX]
3941 issue an error. PREFIX_OPT is true if the immediate prefix is
3942 optional. */
3943
3944 static int
3945 parse_immediate (char **str, int *val, int min, int max,
3946 bfd_boolean prefix_opt)
3947 {
3948 expressionS exp;
3949 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
3950 if (exp.X_op != O_constant)
3951 {
3952 inst.error = _("constant expression required");
3953 return FAIL;
3954 }
3955
3956 if (exp.X_add_number < min || exp.X_add_number > max)
3957 {
3958 inst.error = _("immediate value out of range");
3959 return FAIL;
3960 }
3961
3962 *val = exp.X_add_number;
3963 return SUCCESS;
3964 }
3965
3966 /* Less-generic immediate-value read function with the possibility of loading a
3967 big (64-bit) immediate, as required by Neon VMOV and VMVN immediate
3968 instructions. Puts the result directly in inst.operands[i]. */
3969
3970 static int
3971 parse_big_immediate (char **str, int i)
3972 {
3973 expressionS exp;
3974 char *ptr = *str;
3975
3976 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
3977
3978 if (exp.X_op == O_constant)
3979 inst.operands[i].imm = exp.X_add_number;
3980 else if (exp.X_op == O_big
3981 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
3982 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
3983 {
3984 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
3985 /* Bignums have their least significant bits in
3986 generic_bignum[0]. Make sure we put 32 bits in imm and
3987 32 bits in reg, in a (hopefully) portable way. */
3988 assert (parts != 0);
3989 inst.operands[i].imm = 0;
3990 for (j = 0; j < parts; j++, idx++)
3991 inst.operands[i].imm |= generic_bignum[idx]
3992 << (LITTLENUM_NUMBER_OF_BITS * j);
3993 inst.operands[i].reg = 0;
3994 for (j = 0; j < parts; j++, idx++)
3995 inst.operands[i].reg |= generic_bignum[idx]
3996 << (LITTLENUM_NUMBER_OF_BITS * j);
3997 inst.operands[i].regisimm = 1;
3998 }
3999 else
4000 return FAIL;
4001
4002 *str = ptr;
4003
4004 return SUCCESS;
4005 }
4006
4007 /* Returns the pseudo-register number of an FPA immediate constant,
4008 or FAIL if there isn't a valid constant here. */
4009
4010 static int
4011 parse_fpa_immediate (char ** str)
4012 {
4013 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4014 char * save_in;
4015 expressionS exp;
4016 int i;
4017 int j;
4018
4019 /* First try and match exact strings, this is to guarantee
4020 that some formats will work even for cross assembly. */
4021
4022 for (i = 0; fp_const[i]; i++)
4023 {
4024 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4025 {
4026 char *start = *str;
4027
4028 *str += strlen (fp_const[i]);
4029 if (is_end_of_line[(unsigned char) **str])
4030 return i + 8;
4031 *str = start;
4032 }
4033 }
4034
4035 /* Just because we didn't get a match doesn't mean that the constant
4036 isn't valid, just that it is in a format that we don't
4037 automatically recognize. Try parsing it with the standard
4038 expression routines. */
4039
4040 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
4041
4042 /* Look for a raw floating point number. */
4043 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4044 && is_end_of_line[(unsigned char) *save_in])
4045 {
4046 for (i = 0; i < NUM_FLOAT_VALS; i++)
4047 {
4048 for (j = 0; j < MAX_LITTLENUMS; j++)
4049 {
4050 if (words[j] != fp_values[i][j])
4051 break;
4052 }
4053
4054 if (j == MAX_LITTLENUMS)
4055 {
4056 *str = save_in;
4057 return i + 8;
4058 }
4059 }
4060 }
4061
4062 /* Try and parse a more complex expression, this will probably fail
4063 unless the code uses a floating point prefix (eg "0f"). */
4064 save_in = input_line_pointer;
4065 input_line_pointer = *str;
4066 if (expression (&exp) == absolute_section
4067 && exp.X_op == O_big
4068 && exp.X_add_number < 0)
4069 {
4070 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4071 Ditto for 15. */
4072 if (gen_to_words (words, 5, (long) 15) == 0)
4073 {
4074 for (i = 0; i < NUM_FLOAT_VALS; i++)
4075 {
4076 for (j = 0; j < MAX_LITTLENUMS; j++)
4077 {
4078 if (words[j] != fp_values[i][j])
4079 break;
4080 }
4081
4082 if (j == MAX_LITTLENUMS)
4083 {
4084 *str = input_line_pointer;
4085 input_line_pointer = save_in;
4086 return i + 8;
4087 }
4088 }
4089 }
4090 }
4091
4092 *str = input_line_pointer;
4093 input_line_pointer = save_in;
4094 inst.error = _("invalid FPA immediate expression");
4095 return FAIL;
4096 }
4097
4098 /* Returns 1 if a number has "quarter-precision" float format
4099 0baBbbbbbc defgh000 00000000 00000000. */
4100
4101 static int
4102 is_quarter_float (unsigned imm)
4103 {
4104 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4105 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4106 }
4107
4108 /* Parse an 8-bit "quarter-precision" floating point number of the form:
4109 0baBbbbbbc defgh000 00000000 00000000.
4110 The minus-zero case needs special handling, since it can't be encoded in the
4111 "quarter-precision" float format, but can nonetheless be loaded as an integer
4112 constant. */
4113
4114 static unsigned
4115 parse_qfloat_immediate (char **ccp, int *immed)
4116 {
4117 char *str = *ccp;
4118 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4119
4120 skip_past_char (&str, '#');
4121
4122 if ((str = atof_ieee (str, 's', words)) != NULL)
4123 {
4124 unsigned fpword = 0;
4125 int i;
4126
4127 /* Our FP word must be 32 bits (single-precision FP). */
4128 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4129 {
4130 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4131 fpword |= words[i];
4132 }
4133
4134 if (is_quarter_float (fpword) || fpword == 0x80000000)
4135 *immed = fpword;
4136 else
4137 return FAIL;
4138
4139 *ccp = str;
4140
4141 return SUCCESS;
4142 }
4143
4144 return FAIL;
4145 }
4146
4147 /* Shift operands. */
4148 enum shift_kind
4149 {
4150 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4151 };
4152
4153 struct asm_shift_name
4154 {
4155 const char *name;
4156 enum shift_kind kind;
4157 };
4158
4159 /* Third argument to parse_shift. */
4160 enum parse_shift_mode
4161 {
4162 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4163 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4164 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4165 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4166 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4167 };
4168
4169 /* Parse a <shift> specifier on an ARM data processing instruction.
4170 This has three forms:
4171
4172 (LSL|LSR|ASL|ASR|ROR) Rs
4173 (LSL|LSR|ASL|ASR|ROR) #imm
4174 RRX
4175
4176 Note that ASL is assimilated to LSL in the instruction encoding, and
4177 RRX to ROR #0 (which cannot be written as such). */
4178
4179 static int
4180 parse_shift (char **str, int i, enum parse_shift_mode mode)
4181 {
4182 const struct asm_shift_name *shift_name;
4183 enum shift_kind shift;
4184 char *s = *str;
4185 char *p = s;
4186 int reg;
4187
4188 for (p = *str; ISALPHA (*p); p++)
4189 ;
4190
4191 if (p == *str)
4192 {
4193 inst.error = _("shift expression expected");
4194 return FAIL;
4195 }
4196
4197 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
4198
4199 if (shift_name == NULL)
4200 {
4201 inst.error = _("shift expression expected");
4202 return FAIL;
4203 }
4204
4205 shift = shift_name->kind;
4206
4207 switch (mode)
4208 {
4209 case NO_SHIFT_RESTRICT:
4210 case SHIFT_IMMEDIATE: break;
4211
4212 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4213 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4214 {
4215 inst.error = _("'LSL' or 'ASR' required");
4216 return FAIL;
4217 }
4218 break;
4219
4220 case SHIFT_LSL_IMMEDIATE:
4221 if (shift != SHIFT_LSL)
4222 {
4223 inst.error = _("'LSL' required");
4224 return FAIL;
4225 }
4226 break;
4227
4228 case SHIFT_ASR_IMMEDIATE:
4229 if (shift != SHIFT_ASR)
4230 {
4231 inst.error = _("'ASR' required");
4232 return FAIL;
4233 }
4234 break;
4235
4236 default: abort ();
4237 }
4238
4239 if (shift != SHIFT_RRX)
4240 {
4241 /* Whitespace can appear here if the next thing is a bare digit. */
4242 skip_whitespace (p);
4243
4244 if (mode == NO_SHIFT_RESTRICT
4245 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4246 {
4247 inst.operands[i].imm = reg;
4248 inst.operands[i].immisreg = 1;
4249 }
4250 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4251 return FAIL;
4252 }
4253 inst.operands[i].shift_kind = shift;
4254 inst.operands[i].shifted = 1;
4255 *str = p;
4256 return SUCCESS;
4257 }
4258
4259 /* Parse a <shifter_operand> for an ARM data processing instruction:
4260
4261 #<immediate>
4262 #<immediate>, <rotate>
4263 <Rm>
4264 <Rm>, <shift>
4265
4266 where <shift> is defined by parse_shift above, and <rotate> is a
4267 multiple of 2 between 0 and 30. Validation of immediate operands
4268 is deferred to md_apply_fix. */
4269
4270 static int
4271 parse_shifter_operand (char **str, int i)
4272 {
4273 int value;
4274 expressionS expr;
4275
4276 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
4277 {
4278 inst.operands[i].reg = value;
4279 inst.operands[i].isreg = 1;
4280
4281 /* parse_shift will override this if appropriate */
4282 inst.reloc.exp.X_op = O_constant;
4283 inst.reloc.exp.X_add_number = 0;
4284
4285 if (skip_past_comma (str) == FAIL)
4286 return SUCCESS;
4287
4288 /* Shift operation on register. */
4289 return parse_shift (str, i, NO_SHIFT_RESTRICT);
4290 }
4291
4292 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4293 return FAIL;
4294
4295 if (skip_past_comma (str) == SUCCESS)
4296 {
4297 /* #x, y -- ie explicit rotation by Y. */
4298 if (my_get_expression (&expr, str, GE_NO_PREFIX))
4299 return FAIL;
4300
4301 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4302 {
4303 inst.error = _("constant expression expected");
4304 return FAIL;
4305 }
4306
4307 value = expr.X_add_number;
4308 if (value < 0 || value > 30 || value % 2 != 0)
4309 {
4310 inst.error = _("invalid rotation");
4311 return FAIL;
4312 }
4313 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4314 {
4315 inst.error = _("invalid constant");
4316 return FAIL;
4317 }
4318
4319 /* Convert to decoded value. md_apply_fix will put it back. */
4320 inst.reloc.exp.X_add_number
4321 = (((inst.reloc.exp.X_add_number << (32 - value))
4322 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
4323 }
4324
4325 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4326 inst.reloc.pc_rel = 0;
4327 return SUCCESS;
4328 }
4329
4330 /* Group relocation information. Each entry in the table contains the
4331 textual name of the relocation as may appear in assembler source
4332 and must end with a colon.
4333 Along with this textual name are the relocation codes to be used if
4334 the corresponding instruction is an ALU instruction (ADD or SUB only),
4335 an LDR, an LDRS, or an LDC. */
4336
4337 struct group_reloc_table_entry
4338 {
4339 const char *name;
4340 int alu_code;
4341 int ldr_code;
4342 int ldrs_code;
4343 int ldc_code;
4344 };
4345
4346 typedef enum
4347 {
4348 /* Varieties of non-ALU group relocation. */
4349
4350 GROUP_LDR,
4351 GROUP_LDRS,
4352 GROUP_LDC
4353 } group_reloc_type;
4354
4355 static struct group_reloc_table_entry group_reloc_table[] =
4356 { /* Program counter relative: */
4357 { "pc_g0_nc",
4358 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4359 0, /* LDR */
4360 0, /* LDRS */
4361 0 }, /* LDC */
4362 { "pc_g0",
4363 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4364 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4365 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4366 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4367 { "pc_g1_nc",
4368 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4369 0, /* LDR */
4370 0, /* LDRS */
4371 0 }, /* LDC */
4372 { "pc_g1",
4373 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4374 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4375 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4376 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4377 { "pc_g2",
4378 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4379 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4380 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4381 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4382 /* Section base relative */
4383 { "sb_g0_nc",
4384 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4385 0, /* LDR */
4386 0, /* LDRS */
4387 0 }, /* LDC */
4388 { "sb_g0",
4389 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4390 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4391 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4392 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4393 { "sb_g1_nc",
4394 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4395 0, /* LDR */
4396 0, /* LDRS */
4397 0 }, /* LDC */
4398 { "sb_g1",
4399 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4400 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4401 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4402 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4403 { "sb_g2",
4404 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4405 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4406 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4407 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4408
4409 /* Given the address of a pointer pointing to the textual name of a group
4410 relocation as may appear in assembler source, attempt to find its details
4411 in group_reloc_table. The pointer will be updated to the character after
4412 the trailing colon. On failure, FAIL will be returned; SUCCESS
4413 otherwise. On success, *entry will be updated to point at the relevant
4414 group_reloc_table entry. */
4415
4416 static int
4417 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4418 {
4419 unsigned int i;
4420 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4421 {
4422 int length = strlen (group_reloc_table[i].name);
4423
4424 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0 &&
4425 (*str)[length] == ':')
4426 {
4427 *out = &group_reloc_table[i];
4428 *str += (length + 1);
4429 return SUCCESS;
4430 }
4431 }
4432
4433 return FAIL;
4434 }
4435
4436 /* Parse a <shifter_operand> for an ARM data processing instruction
4437 (as for parse_shifter_operand) where group relocations are allowed:
4438
4439 #<immediate>
4440 #<immediate>, <rotate>
4441 #:<group_reloc>:<expression>
4442 <Rm>
4443 <Rm>, <shift>
4444
4445 where <group_reloc> is one of the strings defined in group_reloc_table.
4446 The hashes are optional.
4447
4448 Everything else is as for parse_shifter_operand. */
4449
4450 static parse_operand_result
4451 parse_shifter_operand_group_reloc (char **str, int i)
4452 {
4453 /* Determine if we have the sequence of characters #: or just :
4454 coming next. If we do, then we check for a group relocation.
4455 If we don't, punt the whole lot to parse_shifter_operand. */
4456
4457 if (((*str)[0] == '#' && (*str)[1] == ':')
4458 || (*str)[0] == ':')
4459 {
4460 struct group_reloc_table_entry *entry;
4461
4462 if ((*str)[0] == '#')
4463 (*str) += 2;
4464 else
4465 (*str)++;
4466
4467 /* Try to parse a group relocation. Anything else is an error. */
4468 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4469 {
4470 inst.error = _("unknown group relocation");
4471 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4472 }
4473
4474 /* We now have the group relocation table entry corresponding to
4475 the name in the assembler source. Next, we parse the expression. */
4476 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4477 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4478
4479 /* Record the relocation type (always the ALU variant here). */
4480 inst.reloc.type = entry->alu_code;
4481 assert (inst.reloc.type != 0);
4482
4483 return PARSE_OPERAND_SUCCESS;
4484 }
4485 else
4486 return parse_shifter_operand (str, i) == SUCCESS
4487 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4488
4489 /* Never reached. */
4490 }
4491
4492 /* Parse all forms of an ARM address expression. Information is written
4493 to inst.operands[i] and/or inst.reloc.
4494
4495 Preindexed addressing (.preind=1):
4496
4497 [Rn, #offset] .reg=Rn .reloc.exp=offset
4498 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4499 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4500 .shift_kind=shift .reloc.exp=shift_imm
4501
4502 These three may have a trailing ! which causes .writeback to be set also.
4503
4504 Postindexed addressing (.postind=1, .writeback=1):
4505
4506 [Rn], #offset .reg=Rn .reloc.exp=offset
4507 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4508 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4509 .shift_kind=shift .reloc.exp=shift_imm
4510
4511 Unindexed addressing (.preind=0, .postind=0):
4512
4513 [Rn], {option} .reg=Rn .imm=option .immisreg=0
4514
4515 Other:
4516
4517 [Rn]{!} shorthand for [Rn,#0]{!}
4518 =immediate .isreg=0 .reloc.exp=immediate
4519 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
4520
4521 It is the caller's responsibility to check for addressing modes not
4522 supported by the instruction, and to set inst.reloc.type. */
4523
4524 static parse_operand_result
4525 parse_address_main (char **str, int i, int group_relocations,
4526 group_reloc_type group_type)
4527 {
4528 char *p = *str;
4529 int reg;
4530
4531 if (skip_past_char (&p, '[') == FAIL)
4532 {
4533 if (skip_past_char (&p, '=') == FAIL)
4534 {
4535 /* bare address - translate to PC-relative offset */
4536 inst.reloc.pc_rel = 1;
4537 inst.operands[i].reg = REG_PC;
4538 inst.operands[i].isreg = 1;
4539 inst.operands[i].preind = 1;
4540 }
4541 /* else a load-constant pseudo op, no special treatment needed here */
4542
4543 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4544 return PARSE_OPERAND_FAIL;
4545
4546 *str = p;
4547 return PARSE_OPERAND_SUCCESS;
4548 }
4549
4550 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
4551 {
4552 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4553 return PARSE_OPERAND_FAIL;
4554 }
4555 inst.operands[i].reg = reg;
4556 inst.operands[i].isreg = 1;
4557
4558 if (skip_past_comma (&p) == SUCCESS)
4559 {
4560 inst.operands[i].preind = 1;
4561
4562 if (*p == '+') p++;
4563 else if (*p == '-') p++, inst.operands[i].negative = 1;
4564
4565 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4566 {
4567 inst.operands[i].imm = reg;
4568 inst.operands[i].immisreg = 1;
4569
4570 if (skip_past_comma (&p) == SUCCESS)
4571 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4572 return PARSE_OPERAND_FAIL;
4573 }
4574 else if (skip_past_char (&p, ':') == SUCCESS)
4575 {
4576 /* FIXME: '@' should be used here, but it's filtered out by generic
4577 code before we get to see it here. This may be subject to
4578 change. */
4579 expressionS exp;
4580 my_get_expression (&exp, &p, GE_NO_PREFIX);
4581 if (exp.X_op != O_constant)
4582 {
4583 inst.error = _("alignment must be constant");
4584 return PARSE_OPERAND_FAIL;
4585 }
4586 inst.operands[i].imm = exp.X_add_number << 8;
4587 inst.operands[i].immisalign = 1;
4588 /* Alignments are not pre-indexes. */
4589 inst.operands[i].preind = 0;
4590 }
4591 else
4592 {
4593 if (inst.operands[i].negative)
4594 {
4595 inst.operands[i].negative = 0;
4596 p--;
4597 }
4598
4599 if (group_relocations &&
4600 ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4601
4602 {
4603 struct group_reloc_table_entry *entry;
4604
4605 /* Skip over the #: or : sequence. */
4606 if (*p == '#')
4607 p += 2;
4608 else
4609 p++;
4610
4611 /* Try to parse a group relocation. Anything else is an
4612 error. */
4613 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
4614 {
4615 inst.error = _("unknown group relocation");
4616 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4617 }
4618
4619 /* We now have the group relocation table entry corresponding to
4620 the name in the assembler source. Next, we parse the
4621 expression. */
4622 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4623 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4624
4625 /* Record the relocation type. */
4626 switch (group_type)
4627 {
4628 case GROUP_LDR:
4629 inst.reloc.type = entry->ldr_code;
4630 break;
4631
4632 case GROUP_LDRS:
4633 inst.reloc.type = entry->ldrs_code;
4634 break;
4635
4636 case GROUP_LDC:
4637 inst.reloc.type = entry->ldc_code;
4638 break;
4639
4640 default:
4641 assert (0);
4642 }
4643
4644 if (inst.reloc.type == 0)
4645 {
4646 inst.error = _("this group relocation is not allowed on this instruction");
4647 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4648 }
4649 }
4650 else
4651 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4652 return PARSE_OPERAND_FAIL;
4653 }
4654 }
4655
4656 if (skip_past_char (&p, ']') == FAIL)
4657 {
4658 inst.error = _("']' expected");
4659 return PARSE_OPERAND_FAIL;
4660 }
4661
4662 if (skip_past_char (&p, '!') == SUCCESS)
4663 inst.operands[i].writeback = 1;
4664
4665 else if (skip_past_comma (&p) == SUCCESS)
4666 {
4667 if (skip_past_char (&p, '{') == SUCCESS)
4668 {
4669 /* [Rn], {expr} - unindexed, with option */
4670 if (parse_immediate (&p, &inst.operands[i].imm,
4671 0, 255, TRUE) == FAIL)
4672 return PARSE_OPERAND_FAIL;
4673
4674 if (skip_past_char (&p, '}') == FAIL)
4675 {
4676 inst.error = _("'}' expected at end of 'option' field");
4677 return PARSE_OPERAND_FAIL;
4678 }
4679 if (inst.operands[i].preind)
4680 {
4681 inst.error = _("cannot combine index with option");
4682 return PARSE_OPERAND_FAIL;
4683 }
4684 *str = p;
4685 return PARSE_OPERAND_SUCCESS;
4686 }
4687 else
4688 {
4689 inst.operands[i].postind = 1;
4690 inst.operands[i].writeback = 1;
4691
4692 if (inst.operands[i].preind)
4693 {
4694 inst.error = _("cannot combine pre- and post-indexing");
4695 return PARSE_OPERAND_FAIL;
4696 }
4697
4698 if (*p == '+') p++;
4699 else if (*p == '-') p++, inst.operands[i].negative = 1;
4700
4701 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4702 {
4703 /* We might be using the immediate for alignment already. If we
4704 are, OR the register number into the low-order bits. */
4705 if (inst.operands[i].immisalign)
4706 inst.operands[i].imm |= reg;
4707 else
4708 inst.operands[i].imm = reg;
4709 inst.operands[i].immisreg = 1;
4710
4711 if (skip_past_comma (&p) == SUCCESS)
4712 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4713 return PARSE_OPERAND_FAIL;
4714 }
4715 else
4716 {
4717 if (inst.operands[i].negative)
4718 {
4719 inst.operands[i].negative = 0;
4720 p--;
4721 }
4722 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4723 return PARSE_OPERAND_FAIL;
4724 }
4725 }
4726 }
4727
4728 /* If at this point neither .preind nor .postind is set, we have a
4729 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
4730 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
4731 {
4732 inst.operands[i].preind = 1;
4733 inst.reloc.exp.X_op = O_constant;
4734 inst.reloc.exp.X_add_number = 0;
4735 }
4736 *str = p;
4737 return PARSE_OPERAND_SUCCESS;
4738 }
4739
4740 static int
4741 parse_address (char **str, int i)
4742 {
4743 return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS
4744 ? SUCCESS : FAIL;
4745 }
4746
4747 static parse_operand_result
4748 parse_address_group_reloc (char **str, int i, group_reloc_type type)
4749 {
4750 return parse_address_main (str, i, 1, type);
4751 }
4752
4753 /* Parse an operand for a MOVW or MOVT instruction. */
4754 static int
4755 parse_half (char **str)
4756 {
4757 char * p;
4758
4759 p = *str;
4760 skip_past_char (&p, '#');
4761 if (strncasecmp (p, ":lower16:", 9) == 0)
4762 inst.reloc.type = BFD_RELOC_ARM_MOVW;
4763 else if (strncasecmp (p, ":upper16:", 9) == 0)
4764 inst.reloc.type = BFD_RELOC_ARM_MOVT;
4765
4766 if (inst.reloc.type != BFD_RELOC_UNUSED)
4767 {
4768 p += 9;
4769 skip_whitespace(p);
4770 }
4771
4772 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4773 return FAIL;
4774
4775 if (inst.reloc.type == BFD_RELOC_UNUSED)
4776 {
4777 if (inst.reloc.exp.X_op != O_constant)
4778 {
4779 inst.error = _("constant expression expected");
4780 return FAIL;
4781 }
4782 if (inst.reloc.exp.X_add_number < 0
4783 || inst.reloc.exp.X_add_number > 0xffff)
4784 {
4785 inst.error = _("immediate value out of range");
4786 return FAIL;
4787 }
4788 }
4789 *str = p;
4790 return SUCCESS;
4791 }
4792
4793 /* Miscellaneous. */
4794
4795 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
4796 or a bitmask suitable to be or-ed into the ARM msr instruction. */
4797 static int
4798 parse_psr (char **str)
4799 {
4800 char *p;
4801 unsigned long psr_field;
4802 const struct asm_psr *psr;
4803 char *start;
4804
4805 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
4806 feature for ease of use and backwards compatibility. */
4807 p = *str;
4808 if (strncasecmp (p, "SPSR", 4) == 0)
4809 psr_field = SPSR_BIT;
4810 else if (strncasecmp (p, "CPSR", 4) == 0)
4811 psr_field = 0;
4812 else
4813 {
4814 start = p;
4815 do
4816 p++;
4817 while (ISALNUM (*p) || *p == '_');
4818
4819 psr = hash_find_n (arm_v7m_psr_hsh, start, p - start);
4820 if (!psr)
4821 return FAIL;
4822
4823 *str = p;
4824 return psr->field;
4825 }
4826
4827 p += 4;
4828 if (*p == '_')
4829 {
4830 /* A suffix follows. */
4831 p++;
4832 start = p;
4833
4834 do
4835 p++;
4836 while (ISALNUM (*p) || *p == '_');
4837
4838 psr = hash_find_n (arm_psr_hsh, start, p - start);
4839 if (!psr)
4840 goto error;
4841
4842 psr_field |= psr->field;
4843 }
4844 else
4845 {
4846 if (ISALNUM (*p))
4847 goto error; /* Garbage after "[CS]PSR". */
4848
4849 psr_field |= (PSR_c | PSR_f);
4850 }
4851 *str = p;
4852 return psr_field;
4853
4854 error:
4855 inst.error = _("flag for {c}psr instruction expected");
4856 return FAIL;
4857 }
4858
4859 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
4860 value suitable for splatting into the AIF field of the instruction. */
4861
4862 static int
4863 parse_cps_flags (char **str)
4864 {
4865 int val = 0;
4866 int saw_a_flag = 0;
4867 char *s = *str;
4868
4869 for (;;)
4870 switch (*s++)
4871 {
4872 case '\0': case ',':
4873 goto done;
4874
4875 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
4876 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
4877 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
4878
4879 default:
4880 inst.error = _("unrecognized CPS flag");
4881 return FAIL;
4882 }
4883
4884 done:
4885 if (saw_a_flag == 0)
4886 {
4887 inst.error = _("missing CPS flags");
4888 return FAIL;
4889 }
4890
4891 *str = s - 1;
4892 return val;
4893 }
4894
4895 /* Parse an endian specifier ("BE" or "LE", case insensitive);
4896 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
4897
4898 static int
4899 parse_endian_specifier (char **str)
4900 {
4901 int little_endian;
4902 char *s = *str;
4903
4904 if (strncasecmp (s, "BE", 2))
4905 little_endian = 0;
4906 else if (strncasecmp (s, "LE", 2))
4907 little_endian = 1;
4908 else
4909 {
4910 inst.error = _("valid endian specifiers are be or le");
4911 return FAIL;
4912 }
4913
4914 if (ISALNUM (s[2]) || s[2] == '_')
4915 {
4916 inst.error = _("valid endian specifiers are be or le");
4917 return FAIL;
4918 }
4919
4920 *str = s + 2;
4921 return little_endian;
4922 }
4923
4924 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
4925 value suitable for poking into the rotate field of an sxt or sxta
4926 instruction, or FAIL on error. */
4927
4928 static int
4929 parse_ror (char **str)
4930 {
4931 int rot;
4932 char *s = *str;
4933
4934 if (strncasecmp (s, "ROR", 3) == 0)
4935 s += 3;
4936 else
4937 {
4938 inst.error = _("missing rotation field after comma");
4939 return FAIL;
4940 }
4941
4942 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
4943 return FAIL;
4944
4945 switch (rot)
4946 {
4947 case 0: *str = s; return 0x0;
4948 case 8: *str = s; return 0x1;
4949 case 16: *str = s; return 0x2;
4950 case 24: *str = s; return 0x3;
4951
4952 default:
4953 inst.error = _("rotation can only be 0, 8, 16, or 24");
4954 return FAIL;
4955 }
4956 }
4957
4958 /* Parse a conditional code (from conds[] below). The value returned is in the
4959 range 0 .. 14, or FAIL. */
4960 static int
4961 parse_cond (char **str)
4962 {
4963 char *p, *q;
4964 const struct asm_cond *c;
4965
4966 p = q = *str;
4967 while (ISALPHA (*q))
4968 q++;
4969
4970 c = hash_find_n (arm_cond_hsh, p, q - p);
4971 if (!c)
4972 {
4973 inst.error = _("condition required");
4974 return FAIL;
4975 }
4976
4977 *str = q;
4978 return c->value;
4979 }
4980
4981 /* Parse an option for a barrier instruction. Returns the encoding for the
4982 option, or FAIL. */
4983 static int
4984 parse_barrier (char **str)
4985 {
4986 char *p, *q;
4987 const struct asm_barrier_opt *o;
4988
4989 p = q = *str;
4990 while (ISALPHA (*q))
4991 q++;
4992
4993 o = hash_find_n (arm_barrier_opt_hsh, p, q - p);
4994 if (!o)
4995 return FAIL;
4996
4997 *str = q;
4998 return o->value;
4999 }
5000
5001 /* Parse the operands of a table branch instruction. Similar to a memory
5002 operand. */
5003 static int
5004 parse_tb (char **str)
5005 {
5006 char * p = *str;
5007 int reg;
5008
5009 if (skip_past_char (&p, '[') == FAIL)
5010 {
5011 inst.error = _("'[' expected");
5012 return FAIL;
5013 }
5014
5015 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5016 {
5017 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5018 return FAIL;
5019 }
5020 inst.operands[0].reg = reg;
5021
5022 if (skip_past_comma (&p) == FAIL)
5023 {
5024 inst.error = _("',' expected");
5025 return FAIL;
5026 }
5027
5028 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5029 {
5030 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5031 return FAIL;
5032 }
5033 inst.operands[0].imm = reg;
5034
5035 if (skip_past_comma (&p) == SUCCESS)
5036 {
5037 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5038 return FAIL;
5039 if (inst.reloc.exp.X_add_number != 1)
5040 {
5041 inst.error = _("invalid shift");
5042 return FAIL;
5043 }
5044 inst.operands[0].shifted = 1;
5045 }
5046
5047 if (skip_past_char (&p, ']') == FAIL)
5048 {
5049 inst.error = _("']' expected");
5050 return FAIL;
5051 }
5052 *str = p;
5053 return SUCCESS;
5054 }
5055
5056 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5057 information on the types the operands can take and how they are encoded.
5058 Up to four operands may be read; this function handles setting the
5059 ".present" field for each read operand itself.
5060 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5061 else returns FAIL. */
5062
5063 static int
5064 parse_neon_mov (char **str, int *which_operand)
5065 {
5066 int i = *which_operand, val;
5067 enum arm_reg_type rtype;
5068 char *ptr = *str;
5069 struct neon_type_el optype;
5070
5071 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5072 {
5073 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5074 inst.operands[i].reg = val;
5075 inst.operands[i].isscalar = 1;
5076 inst.operands[i].vectype = optype;
5077 inst.operands[i++].present = 1;
5078
5079 if (skip_past_comma (&ptr) == FAIL)
5080 goto wanted_comma;
5081
5082 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5083 goto wanted_arm;
5084
5085 inst.operands[i].reg = val;
5086 inst.operands[i].isreg = 1;
5087 inst.operands[i].present = 1;
5088 }
5089 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
5090 != FAIL)
5091 {
5092 /* Cases 0, 1, 2, 3, 5 (D only). */
5093 if (skip_past_comma (&ptr) == FAIL)
5094 goto wanted_comma;
5095
5096 inst.operands[i].reg = val;
5097 inst.operands[i].isreg = 1;
5098 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5099 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5100 inst.operands[i].isvec = 1;
5101 inst.operands[i].vectype = optype;
5102 inst.operands[i++].present = 1;
5103
5104 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5105 {
5106 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5107 Case 13: VMOV <Sd>, <Rm> */
5108 inst.operands[i].reg = val;
5109 inst.operands[i].isreg = 1;
5110 inst.operands[i].present = 1;
5111
5112 if (rtype == REG_TYPE_NQ)
5113 {
5114 first_error (_("can't use Neon quad register here"));
5115 return FAIL;
5116 }
5117 else if (rtype != REG_TYPE_VFS)
5118 {
5119 i++;
5120 if (skip_past_comma (&ptr) == FAIL)
5121 goto wanted_comma;
5122 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5123 goto wanted_arm;
5124 inst.operands[i].reg = val;
5125 inst.operands[i].isreg = 1;
5126 inst.operands[i].present = 1;
5127 }
5128 }
5129 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5130 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5131 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5132 Case 10: VMOV.F32 <Sd>, #<imm>
5133 Case 11: VMOV.F64 <Dd>, #<imm> */
5134 ;
5135 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5136 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5137 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5138 ;
5139 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5140 &optype)) != FAIL)
5141 {
5142 /* Case 0: VMOV<c><q> <Qd>, <Qm>
5143 Case 1: VMOV<c><q> <Dd>, <Dm>
5144 Case 8: VMOV.F32 <Sd>, <Sm>
5145 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5146
5147 inst.operands[i].reg = val;
5148 inst.operands[i].isreg = 1;
5149 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5150 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5151 inst.operands[i].isvec = 1;
5152 inst.operands[i].vectype = optype;
5153 inst.operands[i].present = 1;
5154
5155 if (skip_past_comma (&ptr) == SUCCESS)
5156 {
5157 /* Case 15. */
5158 i++;
5159
5160 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5161 goto wanted_arm;
5162
5163 inst.operands[i].reg = val;
5164 inst.operands[i].isreg = 1;
5165 inst.operands[i++].present = 1;
5166
5167 if (skip_past_comma (&ptr) == FAIL)
5168 goto wanted_comma;
5169
5170 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5171 goto wanted_arm;
5172
5173 inst.operands[i].reg = val;
5174 inst.operands[i].isreg = 1;
5175 inst.operands[i++].present = 1;
5176 }
5177 }
5178 else
5179 {
5180 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5181 return FAIL;
5182 }
5183 }
5184 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5185 {
5186 /* Cases 6, 7. */
5187 inst.operands[i].reg = val;
5188 inst.operands[i].isreg = 1;
5189 inst.operands[i++].present = 1;
5190
5191 if (skip_past_comma (&ptr) == FAIL)
5192 goto wanted_comma;
5193
5194 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5195 {
5196 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5197 inst.operands[i].reg = val;
5198 inst.operands[i].isscalar = 1;
5199 inst.operands[i].present = 1;
5200 inst.operands[i].vectype = optype;
5201 }
5202 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5203 {
5204 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5205 inst.operands[i].reg = val;
5206 inst.operands[i].isreg = 1;
5207 inst.operands[i++].present = 1;
5208
5209 if (skip_past_comma (&ptr) == FAIL)
5210 goto wanted_comma;
5211
5212 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
5213 == FAIL)
5214 {
5215 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5216 return FAIL;
5217 }
5218
5219 inst.operands[i].reg = val;
5220 inst.operands[i].isreg = 1;
5221 inst.operands[i].isvec = 1;
5222 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5223 inst.operands[i].vectype = optype;
5224 inst.operands[i].present = 1;
5225
5226 if (rtype == REG_TYPE_VFS)
5227 {
5228 /* Case 14. */
5229 i++;
5230 if (skip_past_comma (&ptr) == FAIL)
5231 goto wanted_comma;
5232 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5233 &optype)) == FAIL)
5234 {
5235 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5236 return FAIL;
5237 }
5238 inst.operands[i].reg = val;
5239 inst.operands[i].isreg = 1;
5240 inst.operands[i].isvec = 1;
5241 inst.operands[i].issingle = 1;
5242 inst.operands[i].vectype = optype;
5243 inst.operands[i].present = 1;
5244 }
5245 }
5246 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5247 != FAIL)
5248 {
5249 /* Case 13. */
5250 inst.operands[i].reg = val;
5251 inst.operands[i].isreg = 1;
5252 inst.operands[i].isvec = 1;
5253 inst.operands[i].issingle = 1;
5254 inst.operands[i].vectype = optype;
5255 inst.operands[i++].present = 1;
5256 }
5257 }
5258 else
5259 {
5260 first_error (_("parse error"));
5261 return FAIL;
5262 }
5263
5264 /* Successfully parsed the operands. Update args. */
5265 *which_operand = i;
5266 *str = ptr;
5267 return SUCCESS;
5268
5269 wanted_comma:
5270 first_error (_("expected comma"));
5271 return FAIL;
5272
5273 wanted_arm:
5274 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5275 return FAIL;
5276 }
5277
5278 /* Matcher codes for parse_operands. */
5279 enum operand_parse_code
5280 {
5281 OP_stop, /* end of line */
5282
5283 OP_RR, /* ARM register */
5284 OP_RRnpc, /* ARM register, not r15 */
5285 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5286 OP_RRw, /* ARM register, not r15, optional trailing ! */
5287 OP_RCP, /* Coprocessor number */
5288 OP_RCN, /* Coprocessor register */
5289 OP_RF, /* FPA register */
5290 OP_RVS, /* VFP single precision register */
5291 OP_RVD, /* VFP double precision register (0..15) */
5292 OP_RND, /* Neon double precision register (0..31) */
5293 OP_RNQ, /* Neon quad precision register */
5294 OP_RVSD, /* VFP single or double precision register */
5295 OP_RNDQ, /* Neon double or quad precision register */
5296 OP_RNSDQ, /* Neon single, double or quad precision register */
5297 OP_RNSC, /* Neon scalar D[X] */
5298 OP_RVC, /* VFP control register */
5299 OP_RMF, /* Maverick F register */
5300 OP_RMD, /* Maverick D register */
5301 OP_RMFX, /* Maverick FX register */
5302 OP_RMDX, /* Maverick DX register */
5303 OP_RMAX, /* Maverick AX register */
5304 OP_RMDS, /* Maverick DSPSC register */
5305 OP_RIWR, /* iWMMXt wR register */
5306 OP_RIWC, /* iWMMXt wC register */
5307 OP_RIWG, /* iWMMXt wCG register */
5308 OP_RXA, /* XScale accumulator register */
5309
5310 OP_REGLST, /* ARM register list */
5311 OP_VRSLST, /* VFP single-precision register list */
5312 OP_VRDLST, /* VFP double-precision register list */
5313 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5314 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5315 OP_NSTRLST, /* Neon element/structure list */
5316
5317 OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */
5318 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
5319 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5320 OP_RR_RNSC, /* ARM reg or Neon scalar. */
5321 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5322 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5323 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5324 OP_VMOV, /* Neon VMOV operands. */
5325 OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */
5326 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
5327
5328 OP_I0, /* immediate zero */
5329 OP_I7, /* immediate value 0 .. 7 */
5330 OP_I15, /* 0 .. 15 */
5331 OP_I16, /* 1 .. 16 */
5332 OP_I16z, /* 0 .. 16 */
5333 OP_I31, /* 0 .. 31 */
5334 OP_I31w, /* 0 .. 31, optional trailing ! */
5335 OP_I32, /* 1 .. 32 */
5336 OP_I32z, /* 0 .. 32 */
5337 OP_I63, /* 0 .. 63 */
5338 OP_I63s, /* -64 .. 63 */
5339 OP_I64, /* 1 .. 64 */
5340 OP_I64z, /* 0 .. 64 */
5341 OP_I255, /* 0 .. 255 */
5342
5343 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5344 OP_I7b, /* 0 .. 7 */
5345 OP_I15b, /* 0 .. 15 */
5346 OP_I31b, /* 0 .. 31 */
5347
5348 OP_SH, /* shifter operand */
5349 OP_SHG, /* shifter operand with possible group relocation */
5350 OP_ADDR, /* Memory address expression (any mode) */
5351 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5352 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5353 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
5354 OP_EXP, /* arbitrary expression */
5355 OP_EXPi, /* same, with optional immediate prefix */
5356 OP_EXPr, /* same, with optional relocation suffix */
5357 OP_HALF, /* 0 .. 65535 or low/high reloc. */
5358
5359 OP_CPSF, /* CPS flags */
5360 OP_ENDI, /* Endianness specifier */
5361 OP_PSR, /* CPSR/SPSR mask for msr */
5362 OP_COND, /* conditional code */
5363 OP_TB, /* Table branch. */
5364
5365 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5366 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5367
5368 OP_RRnpc_I0, /* ARM register or literal 0 */
5369 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5370 OP_RR_EXi, /* ARM register or expression with imm prefix */
5371 OP_RF_IF, /* FPA register or immediate */
5372 OP_RIWR_RIWC, /* iWMMXt R or C reg */
5373
5374 /* Optional operands. */
5375 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5376 OP_oI31b, /* 0 .. 31 */
5377 OP_oI32b, /* 1 .. 32 */
5378 OP_oIffffb, /* 0 .. 65535 */
5379 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5380
5381 OP_oRR, /* ARM register */
5382 OP_oRRnpc, /* ARM register, not the PC */
5383 OP_oRND, /* Optional Neon double precision register */
5384 OP_oRNQ, /* Optional Neon quad precision register */
5385 OP_oRNDQ, /* Optional Neon double or quad precision register */
5386 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
5387 OP_oSHll, /* LSL immediate */
5388 OP_oSHar, /* ASR immediate */
5389 OP_oSHllar, /* LSL or ASR immediate */
5390 OP_oROR, /* ROR 0/8/16/24 */
5391 OP_oBARRIER, /* Option argument for a barrier instruction. */
5392
5393 OP_FIRST_OPTIONAL = OP_oI7b
5394 };
5395
5396 /* Generic instruction operand parser. This does no encoding and no
5397 semantic validation; it merely squirrels values away in the inst
5398 structure. Returns SUCCESS or FAIL depending on whether the
5399 specified grammar matched. */
5400 static int
5401 parse_operands (char *str, const unsigned char *pattern)
5402 {
5403 unsigned const char *upat = pattern;
5404 char *backtrack_pos = 0;
5405 const char *backtrack_error = 0;
5406 int i, val, backtrack_index = 0;
5407 enum arm_reg_type rtype;
5408 parse_operand_result result;
5409
5410 #define po_char_or_fail(chr) do { \
5411 if (skip_past_char (&str, chr) == FAIL) \
5412 goto bad_args; \
5413 } while (0)
5414
5415 #define po_reg_or_fail(regtype) do { \
5416 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5417 &inst.operands[i].vectype); \
5418 if (val == FAIL) \
5419 { \
5420 first_error (_(reg_expected_msgs[regtype])); \
5421 goto failure; \
5422 } \
5423 inst.operands[i].reg = val; \
5424 inst.operands[i].isreg = 1; \
5425 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5426 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5427 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5428 || rtype == REG_TYPE_VFD \
5429 || rtype == REG_TYPE_NQ); \
5430 } while (0)
5431
5432 #define po_reg_or_goto(regtype, label) do { \
5433 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5434 &inst.operands[i].vectype); \
5435 if (val == FAIL) \
5436 goto label; \
5437 \
5438 inst.operands[i].reg = val; \
5439 inst.operands[i].isreg = 1; \
5440 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5441 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5442 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5443 || rtype == REG_TYPE_VFD \
5444 || rtype == REG_TYPE_NQ); \
5445 } while (0)
5446
5447 #define po_imm_or_fail(min, max, popt) do { \
5448 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5449 goto failure; \
5450 inst.operands[i].imm = val; \
5451 } while (0)
5452
5453 #define po_scalar_or_goto(elsz, label) do { \
5454 val = parse_scalar (&str, elsz, &inst.operands[i].vectype); \
5455 if (val == FAIL) \
5456 goto label; \
5457 inst.operands[i].reg = val; \
5458 inst.operands[i].isscalar = 1; \
5459 } while (0)
5460
5461 #define po_misc_or_fail(expr) do { \
5462 if (expr) \
5463 goto failure; \
5464 } while (0)
5465
5466 #define po_misc_or_fail_no_backtrack(expr) do { \
5467 result = expr; \
5468 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK)\
5469 backtrack_pos = 0; \
5470 if (result != PARSE_OPERAND_SUCCESS) \
5471 goto failure; \
5472 } while (0)
5473
5474 skip_whitespace (str);
5475
5476 for (i = 0; upat[i] != OP_stop; i++)
5477 {
5478 if (upat[i] >= OP_FIRST_OPTIONAL)
5479 {
5480 /* Remember where we are in case we need to backtrack. */
5481 assert (!backtrack_pos);
5482 backtrack_pos = str;
5483 backtrack_error = inst.error;
5484 backtrack_index = i;
5485 }
5486
5487 if (i > 0)
5488 po_char_or_fail (',');
5489
5490 switch (upat[i])
5491 {
5492 /* Registers */
5493 case OP_oRRnpc:
5494 case OP_RRnpc:
5495 case OP_oRR:
5496 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5497 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5498 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
5499 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
5500 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
5501 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5502 case OP_oRND:
5503 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
5504 case OP_RVC: po_reg_or_fail (REG_TYPE_VFC); break;
5505 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
5506 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
5507 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
5508 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
5509 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
5510 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
5511 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
5512 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
5513 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
5514 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5515 case OP_oRNQ:
5516 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
5517 case OP_oRNDQ:
5518 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
5519 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
5520 case OP_oRNSDQ:
5521 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5522
5523 /* Neon scalar. Using an element size of 8 means that some invalid
5524 scalars are accepted here, so deal with those in later code. */
5525 case OP_RNSC: po_scalar_or_goto (8, failure); break;
5526
5527 /* WARNING: We can expand to two operands here. This has the potential
5528 to totally confuse the backtracking mechanism! It will be OK at
5529 least as long as we don't try to use optional args as well,
5530 though. */
5531 case OP_NILO:
5532 {
5533 po_reg_or_goto (REG_TYPE_NDQ, try_imm);
5534 i++;
5535 skip_past_comma (&str);
5536 po_reg_or_goto (REG_TYPE_NDQ, one_reg_only);
5537 break;
5538 one_reg_only:
5539 /* Optional register operand was omitted. Unfortunately, it's in
5540 operands[i-1] and we need it to be in inst.operands[i]. Fix that
5541 here (this is a bit grotty). */
5542 inst.operands[i] = inst.operands[i-1];
5543 inst.operands[i-1].present = 0;
5544 break;
5545 try_imm:
5546 /* Immediate gets verified properly later, so accept any now. */
5547 po_imm_or_fail (INT_MIN, INT_MAX, TRUE);
5548 }
5549 break;
5550
5551 case OP_RNDQ_I0:
5552 {
5553 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
5554 break;
5555 try_imm0:
5556 po_imm_or_fail (0, 0, TRUE);
5557 }
5558 break;
5559
5560 case OP_RVSD_I0:
5561 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
5562 break;
5563
5564 case OP_RR_RNSC:
5565 {
5566 po_scalar_or_goto (8, try_rr);
5567 break;
5568 try_rr:
5569 po_reg_or_fail (REG_TYPE_RN);
5570 }
5571 break;
5572
5573 case OP_RNSDQ_RNSC:
5574 {
5575 po_scalar_or_goto (8, try_nsdq);
5576 break;
5577 try_nsdq:
5578 po_reg_or_fail (REG_TYPE_NSDQ);
5579 }
5580 break;
5581
5582 case OP_RNDQ_RNSC:
5583 {
5584 po_scalar_or_goto (8, try_ndq);
5585 break;
5586 try_ndq:
5587 po_reg_or_fail (REG_TYPE_NDQ);
5588 }
5589 break;
5590
5591 case OP_RND_RNSC:
5592 {
5593 po_scalar_or_goto (8, try_vfd);
5594 break;
5595 try_vfd:
5596 po_reg_or_fail (REG_TYPE_VFD);
5597 }
5598 break;
5599
5600 case OP_VMOV:
5601 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
5602 not careful then bad things might happen. */
5603 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
5604 break;
5605
5606 case OP_RNDQ_IMVNb:
5607 {
5608 po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm);
5609 break;
5610 try_mvnimm:
5611 /* There's a possibility of getting a 64-bit immediate here, so
5612 we need special handling. */
5613 if (parse_big_immediate (&str, i) == FAIL)
5614 {
5615 inst.error = _("immediate value is out of range");
5616 goto failure;
5617 }
5618 }
5619 break;
5620
5621 case OP_RNDQ_I63b:
5622 {
5623 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
5624 break;
5625 try_shimm:
5626 po_imm_or_fail (0, 63, TRUE);
5627 }
5628 break;
5629
5630 case OP_RRnpcb:
5631 po_char_or_fail ('[');
5632 po_reg_or_fail (REG_TYPE_RN);
5633 po_char_or_fail (']');
5634 break;
5635
5636 case OP_RRw:
5637 po_reg_or_fail (REG_TYPE_RN);
5638 if (skip_past_char (&str, '!') == SUCCESS)
5639 inst.operands[i].writeback = 1;
5640 break;
5641
5642 /* Immediates */
5643 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
5644 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
5645 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5646 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
5647 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
5648 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5649 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
5650 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5651 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
5652 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
5653 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
5654 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
5655
5656 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
5657 case OP_oI7b:
5658 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
5659 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
5660 case OP_oI31b:
5661 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5662 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
5663 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
5664
5665 /* Immediate variants */
5666 case OP_oI255c:
5667 po_char_or_fail ('{');
5668 po_imm_or_fail (0, 255, TRUE);
5669 po_char_or_fail ('}');
5670 break;
5671
5672 case OP_I31w:
5673 /* The expression parser chokes on a trailing !, so we have
5674 to find it first and zap it. */
5675 {
5676 char *s = str;
5677 while (*s && *s != ',')
5678 s++;
5679 if (s[-1] == '!')
5680 {
5681 s[-1] = '\0';
5682 inst.operands[i].writeback = 1;
5683 }
5684 po_imm_or_fail (0, 31, TRUE);
5685 if (str == s - 1)
5686 str = s;
5687 }
5688 break;
5689
5690 /* Expressions */
5691 case OP_EXPi: EXPi:
5692 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5693 GE_OPT_PREFIX));
5694 break;
5695
5696 case OP_EXP:
5697 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5698 GE_NO_PREFIX));
5699 break;
5700
5701 case OP_EXPr: EXPr:
5702 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5703 GE_NO_PREFIX));
5704 if (inst.reloc.exp.X_op == O_symbol)
5705 {
5706 val = parse_reloc (&str);
5707 if (val == -1)
5708 {
5709 inst.error = _("unrecognized relocation suffix");
5710 goto failure;
5711 }
5712 else if (val != BFD_RELOC_UNUSED)
5713 {
5714 inst.operands[i].imm = val;
5715 inst.operands[i].hasreloc = 1;
5716 }
5717 }
5718 break;
5719
5720 /* Operand for MOVW or MOVT. */
5721 case OP_HALF:
5722 po_misc_or_fail (parse_half (&str));
5723 break;
5724
5725 /* Register or expression */
5726 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
5727 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
5728
5729 /* Register or immediate */
5730 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
5731 I0: po_imm_or_fail (0, 0, FALSE); break;
5732
5733 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
5734 IF:
5735 if (!is_immediate_prefix (*str))
5736 goto bad_args;
5737 str++;
5738 val = parse_fpa_immediate (&str);
5739 if (val == FAIL)
5740 goto failure;
5741 /* FPA immediates are encoded as registers 8-15.
5742 parse_fpa_immediate has already applied the offset. */
5743 inst.operands[i].reg = val;
5744 inst.operands[i].isreg = 1;
5745 break;
5746
5747 /* Two kinds of register */
5748 case OP_RIWR_RIWC:
5749 {
5750 struct reg_entry *rege = arm_reg_parse_multi (&str);
5751 if (rege->type != REG_TYPE_MMXWR
5752 && rege->type != REG_TYPE_MMXWC
5753 && rege->type != REG_TYPE_MMXWCG)
5754 {
5755 inst.error = _("iWMMXt data or control register expected");
5756 goto failure;
5757 }
5758 inst.operands[i].reg = rege->number;
5759 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
5760 }
5761 break;
5762
5763 /* Misc */
5764 case OP_CPSF: val = parse_cps_flags (&str); break;
5765 case OP_ENDI: val = parse_endian_specifier (&str); break;
5766 case OP_oROR: val = parse_ror (&str); break;
5767 case OP_PSR: val = parse_psr (&str); break;
5768 case OP_COND: val = parse_cond (&str); break;
5769 case OP_oBARRIER:val = parse_barrier (&str); break;
5770
5771 case OP_RVC_PSR:
5772 po_reg_or_goto (REG_TYPE_VFC, try_psr);
5773 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
5774 break;
5775 try_psr:
5776 val = parse_psr (&str);
5777 break;
5778
5779 case OP_APSR_RR:
5780 po_reg_or_goto (REG_TYPE_RN, try_apsr);
5781 break;
5782 try_apsr:
5783 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
5784 instruction). */
5785 if (strncasecmp (str, "APSR_", 5) == 0)
5786 {
5787 unsigned found = 0;
5788 str += 5;
5789 while (found < 15)
5790 switch (*str++)
5791 {
5792 case 'c': found = (found & 1) ? 16 : found | 1; break;
5793 case 'n': found = (found & 2) ? 16 : found | 2; break;
5794 case 'z': found = (found & 4) ? 16 : found | 4; break;
5795 case 'v': found = (found & 8) ? 16 : found | 8; break;
5796 default: found = 16;
5797 }
5798 if (found != 15)
5799 goto failure;
5800 inst.operands[i].isvec = 1;
5801 }
5802 else
5803 goto failure;
5804 break;
5805
5806 case OP_TB:
5807 po_misc_or_fail (parse_tb (&str));
5808 break;
5809
5810 /* Register lists */
5811 case OP_REGLST:
5812 val = parse_reg_list (&str);
5813 if (*str == '^')
5814 {
5815 inst.operands[1].writeback = 1;
5816 str++;
5817 }
5818 break;
5819
5820 case OP_VRSLST:
5821 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
5822 break;
5823
5824 case OP_VRDLST:
5825 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
5826 break;
5827
5828 case OP_VRSDLST:
5829 /* Allow Q registers too. */
5830 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5831 REGLIST_NEON_D);
5832 if (val == FAIL)
5833 {
5834 inst.error = NULL;
5835 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5836 REGLIST_VFP_S);
5837 inst.operands[i].issingle = 1;
5838 }
5839 break;
5840
5841 case OP_NRDLST:
5842 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5843 REGLIST_NEON_D);
5844 break;
5845
5846 case OP_NSTRLST:
5847 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
5848 &inst.operands[i].vectype);
5849 break;
5850
5851 /* Addressing modes */
5852 case OP_ADDR:
5853 po_misc_or_fail (parse_address (&str, i));
5854 break;
5855
5856 case OP_ADDRGLDR:
5857 po_misc_or_fail_no_backtrack (
5858 parse_address_group_reloc (&str, i, GROUP_LDR));
5859 break;
5860
5861 case OP_ADDRGLDRS:
5862 po_misc_or_fail_no_backtrack (
5863 parse_address_group_reloc (&str, i, GROUP_LDRS));
5864 break;
5865
5866 case OP_ADDRGLDC:
5867 po_misc_or_fail_no_backtrack (
5868 parse_address_group_reloc (&str, i, GROUP_LDC));
5869 break;
5870
5871 case OP_SH:
5872 po_misc_or_fail (parse_shifter_operand (&str, i));
5873 break;
5874
5875 case OP_SHG:
5876 po_misc_or_fail_no_backtrack (
5877 parse_shifter_operand_group_reloc (&str, i));
5878 break;
5879
5880 case OP_oSHll:
5881 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
5882 break;
5883
5884 case OP_oSHar:
5885 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
5886 break;
5887
5888 case OP_oSHllar:
5889 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
5890 break;
5891
5892 default:
5893 as_fatal ("unhandled operand code %d", upat[i]);
5894 }
5895
5896 /* Various value-based sanity checks and shared operations. We
5897 do not signal immediate failures for the register constraints;
5898 this allows a syntax error to take precedence. */
5899 switch (upat[i])
5900 {
5901 case OP_oRRnpc:
5902 case OP_RRnpc:
5903 case OP_RRnpcb:
5904 case OP_RRw:
5905 case OP_RRnpc_I0:
5906 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
5907 inst.error = BAD_PC;
5908 break;
5909
5910 case OP_CPSF:
5911 case OP_ENDI:
5912 case OP_oROR:
5913 case OP_PSR:
5914 case OP_RVC_PSR:
5915 case OP_COND:
5916 case OP_oBARRIER:
5917 case OP_REGLST:
5918 case OP_VRSLST:
5919 case OP_VRDLST:
5920 case OP_VRSDLST:
5921 case OP_NRDLST:
5922 case OP_NSTRLST:
5923 if (val == FAIL)
5924 goto failure;
5925 inst.operands[i].imm = val;
5926 break;
5927
5928 default:
5929 break;
5930 }
5931
5932 /* If we get here, this operand was successfully parsed. */
5933 inst.operands[i].present = 1;
5934 continue;
5935
5936 bad_args:
5937 inst.error = BAD_ARGS;
5938
5939 failure:
5940 if (!backtrack_pos)
5941 {
5942 /* The parse routine should already have set inst.error, but set a
5943 defaut here just in case. */
5944 if (!inst.error)
5945 inst.error = _("syntax error");
5946 return FAIL;
5947 }
5948
5949 /* Do not backtrack over a trailing optional argument that
5950 absorbed some text. We will only fail again, with the
5951 'garbage following instruction' error message, which is
5952 probably less helpful than the current one. */
5953 if (backtrack_index == i && backtrack_pos != str
5954 && upat[i+1] == OP_stop)
5955 {
5956 if (!inst.error)
5957 inst.error = _("syntax error");
5958 return FAIL;
5959 }
5960
5961 /* Try again, skipping the optional argument at backtrack_pos. */
5962 str = backtrack_pos;
5963 inst.error = backtrack_error;
5964 inst.operands[backtrack_index].present = 0;
5965 i = backtrack_index;
5966 backtrack_pos = 0;
5967 }
5968
5969 /* Check that we have parsed all the arguments. */
5970 if (*str != '\0' && !inst.error)
5971 inst.error = _("garbage following instruction");
5972
5973 return inst.error ? FAIL : SUCCESS;
5974 }
5975
5976 #undef po_char_or_fail
5977 #undef po_reg_or_fail
5978 #undef po_reg_or_goto
5979 #undef po_imm_or_fail
5980 #undef po_scalar_or_fail
5981 \f
5982 /* Shorthand macro for instruction encoding functions issuing errors. */
5983 #define constraint(expr, err) do { \
5984 if (expr) \
5985 { \
5986 inst.error = err; \
5987 return; \
5988 } \
5989 } while (0)
5990
5991 /* Functions for operand encoding. ARM, then Thumb. */
5992
5993 #define rotate_left(v, n) (v << n | v >> (32 - n))
5994
5995 /* If VAL can be encoded in the immediate field of an ARM instruction,
5996 return the encoded form. Otherwise, return FAIL. */
5997
5998 static unsigned int
5999 encode_arm_immediate (unsigned int val)
6000 {
6001 unsigned int a, i;
6002
6003 for (i = 0; i < 32; i += 2)
6004 if ((a = rotate_left (val, i)) <= 0xff)
6005 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6006
6007 return FAIL;
6008 }
6009
6010 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6011 return the encoded form. Otherwise, return FAIL. */
6012 static unsigned int
6013 encode_thumb32_immediate (unsigned int val)
6014 {
6015 unsigned int a, i;
6016
6017 if (val <= 0xff)
6018 return val;
6019
6020 for (i = 1; i <= 24; i++)
6021 {
6022 a = val >> i;
6023 if ((val & ~(0xff << i)) == 0)
6024 return ((val >> i) & 0x7f) | ((32 - i) << 7);
6025 }
6026
6027 a = val & 0xff;
6028 if (val == ((a << 16) | a))
6029 return 0x100 | a;
6030 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6031 return 0x300 | a;
6032
6033 a = val & 0xff00;
6034 if (val == ((a << 16) | a))
6035 return 0x200 | (a >> 8);
6036
6037 return FAIL;
6038 }
6039 /* Encode a VFP SP or DP register number into inst.instruction. */
6040
6041 static void
6042 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6043 {
6044 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6045 && reg > 15)
6046 {
6047 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
6048 {
6049 if (thumb_mode)
6050 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
6051 fpu_vfp_ext_v3);
6052 else
6053 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
6054 fpu_vfp_ext_v3);
6055 }
6056 else
6057 {
6058 first_error (_("D register out of range for selected VFP version"));
6059 return;
6060 }
6061 }
6062
6063 switch (pos)
6064 {
6065 case VFP_REG_Sd:
6066 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6067 break;
6068
6069 case VFP_REG_Sn:
6070 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6071 break;
6072
6073 case VFP_REG_Sm:
6074 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6075 break;
6076
6077 case VFP_REG_Dd:
6078 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6079 break;
6080
6081 case VFP_REG_Dn:
6082 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6083 break;
6084
6085 case VFP_REG_Dm:
6086 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6087 break;
6088
6089 default:
6090 abort ();
6091 }
6092 }
6093
6094 /* Encode a <shift> in an ARM-format instruction. The immediate,
6095 if any, is handled by md_apply_fix. */
6096 static void
6097 encode_arm_shift (int i)
6098 {
6099 if (inst.operands[i].shift_kind == SHIFT_RRX)
6100 inst.instruction |= SHIFT_ROR << 5;
6101 else
6102 {
6103 inst.instruction |= inst.operands[i].shift_kind << 5;
6104 if (inst.operands[i].immisreg)
6105 {
6106 inst.instruction |= SHIFT_BY_REG;
6107 inst.instruction |= inst.operands[i].imm << 8;
6108 }
6109 else
6110 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6111 }
6112 }
6113
6114 static void
6115 encode_arm_shifter_operand (int i)
6116 {
6117 if (inst.operands[i].isreg)
6118 {
6119 inst.instruction |= inst.operands[i].reg;
6120 encode_arm_shift (i);
6121 }
6122 else
6123 inst.instruction |= INST_IMMEDIATE;
6124 }
6125
6126 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
6127 static void
6128 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
6129 {
6130 assert (inst.operands[i].isreg);
6131 inst.instruction |= inst.operands[i].reg << 16;
6132
6133 if (inst.operands[i].preind)
6134 {
6135 if (is_t)
6136 {
6137 inst.error = _("instruction does not accept preindexed addressing");
6138 return;
6139 }
6140 inst.instruction |= PRE_INDEX;
6141 if (inst.operands[i].writeback)
6142 inst.instruction |= WRITE_BACK;
6143
6144 }
6145 else if (inst.operands[i].postind)
6146 {
6147 assert (inst.operands[i].writeback);
6148 if (is_t)
6149 inst.instruction |= WRITE_BACK;
6150 }
6151 else /* unindexed - only for coprocessor */
6152 {
6153 inst.error = _("instruction does not accept unindexed addressing");
6154 return;
6155 }
6156
6157 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6158 && (((inst.instruction & 0x000f0000) >> 16)
6159 == ((inst.instruction & 0x0000f000) >> 12)))
6160 as_warn ((inst.instruction & LOAD_BIT)
6161 ? _("destination register same as write-back base")
6162 : _("source register same as write-back base"));
6163 }
6164
6165 /* inst.operands[i] was set up by parse_address. Encode it into an
6166 ARM-format mode 2 load or store instruction. If is_t is true,
6167 reject forms that cannot be used with a T instruction (i.e. not
6168 post-indexed). */
6169 static void
6170 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
6171 {
6172 encode_arm_addr_mode_common (i, is_t);
6173
6174 if (inst.operands[i].immisreg)
6175 {
6176 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6177 inst.instruction |= inst.operands[i].imm;
6178 if (!inst.operands[i].negative)
6179 inst.instruction |= INDEX_UP;
6180 if (inst.operands[i].shifted)
6181 {
6182 if (inst.operands[i].shift_kind == SHIFT_RRX)
6183 inst.instruction |= SHIFT_ROR << 5;
6184 else
6185 {
6186 inst.instruction |= inst.operands[i].shift_kind << 5;
6187 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6188 }
6189 }
6190 }
6191 else /* immediate offset in inst.reloc */
6192 {
6193 if (inst.reloc.type == BFD_RELOC_UNUSED)
6194 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
6195 }
6196 }
6197
6198 /* inst.operands[i] was set up by parse_address. Encode it into an
6199 ARM-format mode 3 load or store instruction. Reject forms that
6200 cannot be used with such instructions. If is_t is true, reject
6201 forms that cannot be used with a T instruction (i.e. not
6202 post-indexed). */
6203 static void
6204 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
6205 {
6206 if (inst.operands[i].immisreg && inst.operands[i].shifted)
6207 {
6208 inst.error = _("instruction does not accept scaled register index");
6209 return;
6210 }
6211
6212 encode_arm_addr_mode_common (i, is_t);
6213
6214 if (inst.operands[i].immisreg)
6215 {
6216 inst.instruction |= inst.operands[i].imm;
6217 if (!inst.operands[i].negative)
6218 inst.instruction |= INDEX_UP;
6219 }
6220 else /* immediate offset in inst.reloc */
6221 {
6222 inst.instruction |= HWOFFSET_IMM;
6223 if (inst.reloc.type == BFD_RELOC_UNUSED)
6224 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
6225 }
6226 }
6227
6228 /* inst.operands[i] was set up by parse_address. Encode it into an
6229 ARM-format instruction. Reject all forms which cannot be encoded
6230 into a coprocessor load/store instruction. If wb_ok is false,
6231 reject use of writeback; if unind_ok is false, reject use of
6232 unindexed addressing. If reloc_override is not 0, use it instead
6233 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6234 (in which case it is preserved). */
6235
6236 static int
6237 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
6238 {
6239 inst.instruction |= inst.operands[i].reg << 16;
6240
6241 assert (!(inst.operands[i].preind && inst.operands[i].postind));
6242
6243 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
6244 {
6245 assert (!inst.operands[i].writeback);
6246 if (!unind_ok)
6247 {
6248 inst.error = _("instruction does not support unindexed addressing");
6249 return FAIL;
6250 }
6251 inst.instruction |= inst.operands[i].imm;
6252 inst.instruction |= INDEX_UP;
6253 return SUCCESS;
6254 }
6255
6256 if (inst.operands[i].preind)
6257 inst.instruction |= PRE_INDEX;
6258
6259 if (inst.operands[i].writeback)
6260 {
6261 if (inst.operands[i].reg == REG_PC)
6262 {
6263 inst.error = _("pc may not be used with write-back");
6264 return FAIL;
6265 }
6266 if (!wb_ok)
6267 {
6268 inst.error = _("instruction does not support writeback");
6269 return FAIL;
6270 }
6271 inst.instruction |= WRITE_BACK;
6272 }
6273
6274 if (reloc_override)
6275 inst.reloc.type = reloc_override;
6276 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6277 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6278 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6279 {
6280 if (thumb_mode)
6281 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6282 else
6283 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6284 }
6285
6286 return SUCCESS;
6287 }
6288
6289 /* inst.reloc.exp describes an "=expr" load pseudo-operation.
6290 Determine whether it can be performed with a move instruction; if
6291 it can, convert inst.instruction to that move instruction and
6292 return 1; if it can't, convert inst.instruction to a literal-pool
6293 load and return 0. If this is not a valid thing to do in the
6294 current context, set inst.error and return 1.
6295
6296 inst.operands[i] describes the destination register. */
6297
6298 static int
6299 move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6300 {
6301 unsigned long tbit;
6302
6303 if (thumb_p)
6304 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6305 else
6306 tbit = LOAD_BIT;
6307
6308 if ((inst.instruction & tbit) == 0)
6309 {
6310 inst.error = _("invalid pseudo operation");
6311 return 1;
6312 }
6313 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
6314 {
6315 inst.error = _("constant expression expected");
6316 return 1;
6317 }
6318 if (inst.reloc.exp.X_op == O_constant)
6319 {
6320 if (thumb_p)
6321 {
6322 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
6323 {
6324 /* This can be done with a mov(1) instruction. */
6325 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6326 inst.instruction |= inst.reloc.exp.X_add_number;
6327 return 1;
6328 }
6329 }
6330 else
6331 {
6332 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6333 if (value != FAIL)
6334 {
6335 /* This can be done with a mov instruction. */
6336 inst.instruction &= LITERAL_MASK;
6337 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6338 inst.instruction |= value & 0xfff;
6339 return 1;
6340 }
6341
6342 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6343 if (value != FAIL)
6344 {
6345 /* This can be done with a mvn instruction. */
6346 inst.instruction &= LITERAL_MASK;
6347 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6348 inst.instruction |= value & 0xfff;
6349 return 1;
6350 }
6351 }
6352 }
6353
6354 if (add_to_lit_pool () == FAIL)
6355 {
6356 inst.error = _("literal pool insertion failed");
6357 return 1;
6358 }
6359 inst.operands[1].reg = REG_PC;
6360 inst.operands[1].isreg = 1;
6361 inst.operands[1].preind = 1;
6362 inst.reloc.pc_rel = 1;
6363 inst.reloc.type = (thumb_p
6364 ? BFD_RELOC_ARM_THUMB_OFFSET
6365 : (mode_3
6366 ? BFD_RELOC_ARM_HWLITERAL
6367 : BFD_RELOC_ARM_LITERAL));
6368 return 0;
6369 }
6370
6371 /* Functions for instruction encoding, sorted by subarchitecture.
6372 First some generics; their names are taken from the conventional
6373 bit positions for register arguments in ARM format instructions. */
6374
6375 static void
6376 do_noargs (void)
6377 {
6378 }
6379
6380 static void
6381 do_rd (void)
6382 {
6383 inst.instruction |= inst.operands[0].reg << 12;
6384 }
6385
6386 static void
6387 do_rd_rm (void)
6388 {
6389 inst.instruction |= inst.operands[0].reg << 12;
6390 inst.instruction |= inst.operands[1].reg;
6391 }
6392
6393 static void
6394 do_rd_rn (void)
6395 {
6396 inst.instruction |= inst.operands[0].reg << 12;
6397 inst.instruction |= inst.operands[1].reg << 16;
6398 }
6399
6400 static void
6401 do_rn_rd (void)
6402 {
6403 inst.instruction |= inst.operands[0].reg << 16;
6404 inst.instruction |= inst.operands[1].reg << 12;
6405 }
6406
6407 static void
6408 do_rd_rm_rn (void)
6409 {
6410 unsigned Rn = inst.operands[2].reg;
6411 /* Enforce restrictions on SWP instruction. */
6412 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6413 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6414 _("Rn must not overlap other operands"));
6415 inst.instruction |= inst.operands[0].reg << 12;
6416 inst.instruction |= inst.operands[1].reg;
6417 inst.instruction |= Rn << 16;
6418 }
6419
6420 static void
6421 do_rd_rn_rm (void)
6422 {
6423 inst.instruction |= inst.operands[0].reg << 12;
6424 inst.instruction |= inst.operands[1].reg << 16;
6425 inst.instruction |= inst.operands[2].reg;
6426 }
6427
6428 static void
6429 do_rm_rd_rn (void)
6430 {
6431 inst.instruction |= inst.operands[0].reg;
6432 inst.instruction |= inst.operands[1].reg << 12;
6433 inst.instruction |= inst.operands[2].reg << 16;
6434 }
6435
6436 static void
6437 do_imm0 (void)
6438 {
6439 inst.instruction |= inst.operands[0].imm;
6440 }
6441
6442 static void
6443 do_rd_cpaddr (void)
6444 {
6445 inst.instruction |= inst.operands[0].reg << 12;
6446 encode_arm_cp_address (1, TRUE, TRUE, 0);
6447 }
6448
6449 /* ARM instructions, in alphabetical order by function name (except
6450 that wrapper functions appear immediately after the function they
6451 wrap). */
6452
6453 /* This is a pseudo-op of the form "adr rd, label" to be converted
6454 into a relative address of the form "add rd, pc, #label-.-8". */
6455
6456 static void
6457 do_adr (void)
6458 {
6459 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
6460
6461 /* Frag hacking will turn this into a sub instruction if the offset turns
6462 out to be negative. */
6463 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
6464 inst.reloc.pc_rel = 1;
6465 inst.reloc.exp.X_add_number -= 8;
6466 }
6467
6468 /* This is a pseudo-op of the form "adrl rd, label" to be converted
6469 into a relative address of the form:
6470 add rd, pc, #low(label-.-8)"
6471 add rd, rd, #high(label-.-8)" */
6472
6473 static void
6474 do_adrl (void)
6475 {
6476 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
6477
6478 /* Frag hacking will turn this into a sub instruction if the offset turns
6479 out to be negative. */
6480 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
6481 inst.reloc.pc_rel = 1;
6482 inst.size = INSN_SIZE * 2;
6483 inst.reloc.exp.X_add_number -= 8;
6484 }
6485
6486 static void
6487 do_arit (void)
6488 {
6489 if (!inst.operands[1].present)
6490 inst.operands[1].reg = inst.operands[0].reg;
6491 inst.instruction |= inst.operands[0].reg << 12;
6492 inst.instruction |= inst.operands[1].reg << 16;
6493 encode_arm_shifter_operand (2);
6494 }
6495
6496 static void
6497 do_barrier (void)
6498 {
6499 if (inst.operands[0].present)
6500 {
6501 constraint ((inst.instruction & 0xf0) != 0x40
6502 && inst.operands[0].imm != 0xf,
6503 "bad barrier type");
6504 inst.instruction |= inst.operands[0].imm;
6505 }
6506 else
6507 inst.instruction |= 0xf;
6508 }
6509
6510 static void
6511 do_bfc (void)
6512 {
6513 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6514 constraint (msb > 32, _("bit-field extends past end of register"));
6515 /* The instruction encoding stores the LSB and MSB,
6516 not the LSB and width. */
6517 inst.instruction |= inst.operands[0].reg << 12;
6518 inst.instruction |= inst.operands[1].imm << 7;
6519 inst.instruction |= (msb - 1) << 16;
6520 }
6521
6522 static void
6523 do_bfi (void)
6524 {
6525 unsigned int msb;
6526
6527 /* #0 in second position is alternative syntax for bfc, which is
6528 the same instruction but with REG_PC in the Rm field. */
6529 if (!inst.operands[1].isreg)
6530 inst.operands[1].reg = REG_PC;
6531
6532 msb = inst.operands[2].imm + inst.operands[3].imm;
6533 constraint (msb > 32, _("bit-field extends past end of register"));
6534 /* The instruction encoding stores the LSB and MSB,
6535 not the LSB and width. */
6536 inst.instruction |= inst.operands[0].reg << 12;
6537 inst.instruction |= inst.operands[1].reg;
6538 inst.instruction |= inst.operands[2].imm << 7;
6539 inst.instruction |= (msb - 1) << 16;
6540 }
6541
6542 static void
6543 do_bfx (void)
6544 {
6545 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6546 _("bit-field extends past end of register"));
6547 inst.instruction |= inst.operands[0].reg << 12;
6548 inst.instruction |= inst.operands[1].reg;
6549 inst.instruction |= inst.operands[2].imm << 7;
6550 inst.instruction |= (inst.operands[3].imm - 1) << 16;
6551 }
6552
6553 /* ARM V5 breakpoint instruction (argument parse)
6554 BKPT <16 bit unsigned immediate>
6555 Instruction is not conditional.
6556 The bit pattern given in insns[] has the COND_ALWAYS condition,
6557 and it is an error if the caller tried to override that. */
6558
6559 static void
6560 do_bkpt (void)
6561 {
6562 /* Top 12 of 16 bits to bits 19:8. */
6563 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
6564
6565 /* Bottom 4 of 16 bits to bits 3:0. */
6566 inst.instruction |= inst.operands[0].imm & 0xf;
6567 }
6568
6569 static void
6570 encode_branch (int default_reloc)
6571 {
6572 if (inst.operands[0].hasreloc)
6573 {
6574 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
6575 _("the only suffix valid here is '(plt)'"));
6576 inst.reloc.type = BFD_RELOC_ARM_PLT32;
6577 }
6578 else
6579 {
6580 inst.reloc.type = default_reloc;
6581 }
6582 inst.reloc.pc_rel = 1;
6583 }
6584
6585 static void
6586 do_branch (void)
6587 {
6588 #ifdef OBJ_ELF
6589 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6590 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6591 else
6592 #endif
6593 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6594 }
6595
6596 static void
6597 do_bl (void)
6598 {
6599 #ifdef OBJ_ELF
6600 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6601 {
6602 if (inst.cond == COND_ALWAYS)
6603 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6604 else
6605 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6606 }
6607 else
6608 #endif
6609 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6610 }
6611
6612 /* ARM V5 branch-link-exchange instruction (argument parse)
6613 BLX <target_addr> ie BLX(1)
6614 BLX{<condition>} <Rm> ie BLX(2)
6615 Unfortunately, there are two different opcodes for this mnemonic.
6616 So, the insns[].value is not used, and the code here zaps values
6617 into inst.instruction.
6618 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
6619
6620 static void
6621 do_blx (void)
6622 {
6623 if (inst.operands[0].isreg)
6624 {
6625 /* Arg is a register; the opcode provided by insns[] is correct.
6626 It is not illegal to do "blx pc", just useless. */
6627 if (inst.operands[0].reg == REG_PC)
6628 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
6629
6630 inst.instruction |= inst.operands[0].reg;
6631 }
6632 else
6633 {
6634 /* Arg is an address; this instruction cannot be executed
6635 conditionally, and the opcode must be adjusted. */
6636 constraint (inst.cond != COND_ALWAYS, BAD_COND);
6637 inst.instruction = 0xfa000000;
6638 #ifdef OBJ_ELF
6639 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6640 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6641 else
6642 #endif
6643 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
6644 }
6645 }
6646
6647 static void
6648 do_bx (void)
6649 {
6650 if (inst.operands[0].reg == REG_PC)
6651 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
6652
6653 inst.instruction |= inst.operands[0].reg;
6654 }
6655
6656
6657 /* ARM v5TEJ. Jump to Jazelle code. */
6658
6659 static void
6660 do_bxj (void)
6661 {
6662 if (inst.operands[0].reg == REG_PC)
6663 as_tsktsk (_("use of r15 in bxj is not really useful"));
6664
6665 inst.instruction |= inst.operands[0].reg;
6666 }
6667
6668 /* Co-processor data operation:
6669 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
6670 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
6671 static void
6672 do_cdp (void)
6673 {
6674 inst.instruction |= inst.operands[0].reg << 8;
6675 inst.instruction |= inst.operands[1].imm << 20;
6676 inst.instruction |= inst.operands[2].reg << 12;
6677 inst.instruction |= inst.operands[3].reg << 16;
6678 inst.instruction |= inst.operands[4].reg;
6679 inst.instruction |= inst.operands[5].imm << 5;
6680 }
6681
6682 static void
6683 do_cmp (void)
6684 {
6685 inst.instruction |= inst.operands[0].reg << 16;
6686 encode_arm_shifter_operand (1);
6687 }
6688
6689 /* Transfer between coprocessor and ARM registers.
6690 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
6691 MRC2
6692 MCR{cond}
6693 MCR2
6694
6695 No special properties. */
6696
6697 static void
6698 do_co_reg (void)
6699 {
6700 inst.instruction |= inst.operands[0].reg << 8;
6701 inst.instruction |= inst.operands[1].imm << 21;
6702 inst.instruction |= inst.operands[2].reg << 12;
6703 inst.instruction |= inst.operands[3].reg << 16;
6704 inst.instruction |= inst.operands[4].reg;
6705 inst.instruction |= inst.operands[5].imm << 5;
6706 }
6707
6708 /* Transfer between coprocessor register and pair of ARM registers.
6709 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
6710 MCRR2
6711 MRRC{cond}
6712 MRRC2
6713
6714 Two XScale instructions are special cases of these:
6715
6716 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
6717 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
6718
6719 Result unpredicatable if Rd or Rn is R15. */
6720
6721 static void
6722 do_co_reg2c (void)
6723 {
6724 inst.instruction |= inst.operands[0].reg << 8;
6725 inst.instruction |= inst.operands[1].imm << 4;
6726 inst.instruction |= inst.operands[2].reg << 12;
6727 inst.instruction |= inst.operands[3].reg << 16;
6728 inst.instruction |= inst.operands[4].reg;
6729 }
6730
6731 static void
6732 do_cpsi (void)
6733 {
6734 inst.instruction |= inst.operands[0].imm << 6;
6735 inst.instruction |= inst.operands[1].imm;
6736 }
6737
6738 static void
6739 do_dbg (void)
6740 {
6741 inst.instruction |= inst.operands[0].imm;
6742 }
6743
6744 static void
6745 do_it (void)
6746 {
6747 /* There is no IT instruction in ARM mode. We
6748 process it but do not generate code for it. */
6749 inst.size = 0;
6750 }
6751
6752 static void
6753 do_ldmstm (void)
6754 {
6755 int base_reg = inst.operands[0].reg;
6756 int range = inst.operands[1].imm;
6757
6758 inst.instruction |= base_reg << 16;
6759 inst.instruction |= range;
6760
6761 if (inst.operands[1].writeback)
6762 inst.instruction |= LDM_TYPE_2_OR_3;
6763
6764 if (inst.operands[0].writeback)
6765 {
6766 inst.instruction |= WRITE_BACK;
6767 /* Check for unpredictable uses of writeback. */
6768 if (inst.instruction & LOAD_BIT)
6769 {
6770 /* Not allowed in LDM type 2. */
6771 if ((inst.instruction & LDM_TYPE_2_OR_3)
6772 && ((range & (1 << REG_PC)) == 0))
6773 as_warn (_("writeback of base register is UNPREDICTABLE"));
6774 /* Only allowed if base reg not in list for other types. */
6775 else if (range & (1 << base_reg))
6776 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
6777 }
6778 else /* STM. */
6779 {
6780 /* Not allowed for type 2. */
6781 if (inst.instruction & LDM_TYPE_2_OR_3)
6782 as_warn (_("writeback of base register is UNPREDICTABLE"));
6783 /* Only allowed if base reg not in list, or first in list. */
6784 else if ((range & (1 << base_reg))
6785 && (range & ((1 << base_reg) - 1)))
6786 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
6787 }
6788 }
6789 }
6790
6791 /* ARMv5TE load-consecutive (argument parse)
6792 Mode is like LDRH.
6793
6794 LDRccD R, mode
6795 STRccD R, mode. */
6796
6797 static void
6798 do_ldrd (void)
6799 {
6800 constraint (inst.operands[0].reg % 2 != 0,
6801 _("first destination register must be even"));
6802 constraint (inst.operands[1].present
6803 && inst.operands[1].reg != inst.operands[0].reg + 1,
6804 _("can only load two consecutive registers"));
6805 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
6806 constraint (!inst.operands[2].isreg, _("'[' expected"));
6807
6808 if (!inst.operands[1].present)
6809 inst.operands[1].reg = inst.operands[0].reg + 1;
6810
6811 if (inst.instruction & LOAD_BIT)
6812 {
6813 /* encode_arm_addr_mode_3 will diagnose overlap between the base
6814 register and the first register written; we have to diagnose
6815 overlap between the base and the second register written here. */
6816
6817 if (inst.operands[2].reg == inst.operands[1].reg
6818 && (inst.operands[2].writeback || inst.operands[2].postind))
6819 as_warn (_("base register written back, and overlaps "
6820 "second destination register"));
6821
6822 /* For an index-register load, the index register must not overlap the
6823 destination (even if not write-back). */
6824 else if (inst.operands[2].immisreg
6825 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
6826 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
6827 as_warn (_("index register overlaps destination register"));
6828 }
6829
6830 inst.instruction |= inst.operands[0].reg << 12;
6831 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
6832 }
6833
6834 static void
6835 do_ldrex (void)
6836 {
6837 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
6838 || inst.operands[1].postind || inst.operands[1].writeback
6839 || inst.operands[1].immisreg || inst.operands[1].shifted
6840 || inst.operands[1].negative
6841 /* This can arise if the programmer has written
6842 strex rN, rM, foo
6843 or if they have mistakenly used a register name as the last
6844 operand, eg:
6845 strex rN, rM, rX
6846 It is very difficult to distinguish between these two cases
6847 because "rX" might actually be a label. ie the register
6848 name has been occluded by a symbol of the same name. So we
6849 just generate a general 'bad addressing mode' type error
6850 message and leave it up to the programmer to discover the
6851 true cause and fix their mistake. */
6852 || (inst.operands[1].reg == REG_PC),
6853 BAD_ADDR_MODE);
6854
6855 constraint (inst.reloc.exp.X_op != O_constant
6856 || inst.reloc.exp.X_add_number != 0,
6857 _("offset must be zero in ARM encoding"));
6858
6859 inst.instruction |= inst.operands[0].reg << 12;
6860 inst.instruction |= inst.operands[1].reg << 16;
6861 inst.reloc.type = BFD_RELOC_UNUSED;
6862 }
6863
6864 static void
6865 do_ldrexd (void)
6866 {
6867 constraint (inst.operands[0].reg % 2 != 0,
6868 _("even register required"));
6869 constraint (inst.operands[1].present
6870 && inst.operands[1].reg != inst.operands[0].reg + 1,
6871 _("can only load two consecutive registers"));
6872 /* If op 1 were present and equal to PC, this function wouldn't
6873 have been called in the first place. */
6874 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
6875
6876 inst.instruction |= inst.operands[0].reg << 12;
6877 inst.instruction |= inst.operands[2].reg << 16;
6878 }
6879
6880 static void
6881 do_ldst (void)
6882 {
6883 inst.instruction |= inst.operands[0].reg << 12;
6884 if (!inst.operands[1].isreg)
6885 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
6886 return;
6887 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
6888 }
6889
6890 static void
6891 do_ldstt (void)
6892 {
6893 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
6894 reject [Rn,...]. */
6895 if (inst.operands[1].preind)
6896 {
6897 constraint (inst.reloc.exp.X_op != O_constant ||
6898 inst.reloc.exp.X_add_number != 0,
6899 _("this instruction requires a post-indexed address"));
6900
6901 inst.operands[1].preind = 0;
6902 inst.operands[1].postind = 1;
6903 inst.operands[1].writeback = 1;
6904 }
6905 inst.instruction |= inst.operands[0].reg << 12;
6906 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
6907 }
6908
6909 /* Halfword and signed-byte load/store operations. */
6910
6911 static void
6912 do_ldstv4 (void)
6913 {
6914 inst.instruction |= inst.operands[0].reg << 12;
6915 if (!inst.operands[1].isreg)
6916 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
6917 return;
6918 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
6919 }
6920
6921 static void
6922 do_ldsttv4 (void)
6923 {
6924 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
6925 reject [Rn,...]. */
6926 if (inst.operands[1].preind)
6927 {
6928 constraint (inst.reloc.exp.X_op != O_constant ||
6929 inst.reloc.exp.X_add_number != 0,
6930 _("this instruction requires a post-indexed address"));
6931
6932 inst.operands[1].preind = 0;
6933 inst.operands[1].postind = 1;
6934 inst.operands[1].writeback = 1;
6935 }
6936 inst.instruction |= inst.operands[0].reg << 12;
6937 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
6938 }
6939
6940 /* Co-processor register load/store.
6941 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
6942 static void
6943 do_lstc (void)
6944 {
6945 inst.instruction |= inst.operands[0].reg << 8;
6946 inst.instruction |= inst.operands[1].reg << 12;
6947 encode_arm_cp_address (2, TRUE, TRUE, 0);
6948 }
6949
6950 static void
6951 do_mlas (void)
6952 {
6953 /* This restriction does not apply to mls (nor to mla in v6, but
6954 that's hard to detect at present). */
6955 if (inst.operands[0].reg == inst.operands[1].reg
6956 && !(inst.instruction & 0x00400000))
6957 as_tsktsk (_("rd and rm should be different in mla"));
6958
6959 inst.instruction |= inst.operands[0].reg << 16;
6960 inst.instruction |= inst.operands[1].reg;
6961 inst.instruction |= inst.operands[2].reg << 8;
6962 inst.instruction |= inst.operands[3].reg << 12;
6963
6964 }
6965
6966 static void
6967 do_mov (void)
6968 {
6969 inst.instruction |= inst.operands[0].reg << 12;
6970 encode_arm_shifter_operand (1);
6971 }
6972
6973 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
6974 static void
6975 do_mov16 (void)
6976 {
6977 bfd_vma imm;
6978 bfd_boolean top;
6979
6980 top = (inst.instruction & 0x00400000) != 0;
6981 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
6982 _(":lower16: not allowed this instruction"));
6983 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
6984 _(":upper16: not allowed instruction"));
6985 inst.instruction |= inst.operands[0].reg << 12;
6986 if (inst.reloc.type == BFD_RELOC_UNUSED)
6987 {
6988 imm = inst.reloc.exp.X_add_number;
6989 /* The value is in two pieces: 0:11, 16:19. */
6990 inst.instruction |= (imm & 0x00000fff);
6991 inst.instruction |= (imm & 0x0000f000) << 4;
6992 }
6993 }
6994
6995 static void do_vfp_nsyn_opcode (const char *);
6996
6997 static int
6998 do_vfp_nsyn_mrs (void)
6999 {
7000 if (inst.operands[0].isvec)
7001 {
7002 if (inst.operands[1].reg != 1)
7003 first_error (_("operand 1 must be FPSCR"));
7004 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7005 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7006 do_vfp_nsyn_opcode ("fmstat");
7007 }
7008 else if (inst.operands[1].isvec)
7009 do_vfp_nsyn_opcode ("fmrx");
7010 else
7011 return FAIL;
7012
7013 return SUCCESS;
7014 }
7015
7016 static int
7017 do_vfp_nsyn_msr (void)
7018 {
7019 if (inst.operands[0].isvec)
7020 do_vfp_nsyn_opcode ("fmxr");
7021 else
7022 return FAIL;
7023
7024 return SUCCESS;
7025 }
7026
7027 static void
7028 do_mrs (void)
7029 {
7030 if (do_vfp_nsyn_mrs () == SUCCESS)
7031 return;
7032
7033 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7034 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7035 != (PSR_c|PSR_f),
7036 _("'CPSR' or 'SPSR' expected"));
7037 inst.instruction |= inst.operands[0].reg << 12;
7038 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7039 }
7040
7041 /* Two possible forms:
7042 "{C|S}PSR_<field>, Rm",
7043 "{C|S}PSR_f, #expression". */
7044
7045 static void
7046 do_msr (void)
7047 {
7048 if (do_vfp_nsyn_msr () == SUCCESS)
7049 return;
7050
7051 inst.instruction |= inst.operands[0].imm;
7052 if (inst.operands[1].isreg)
7053 inst.instruction |= inst.operands[1].reg;
7054 else
7055 {
7056 inst.instruction |= INST_IMMEDIATE;
7057 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7058 inst.reloc.pc_rel = 0;
7059 }
7060 }
7061
7062 static void
7063 do_mul (void)
7064 {
7065 if (!inst.operands[2].present)
7066 inst.operands[2].reg = inst.operands[0].reg;
7067 inst.instruction |= inst.operands[0].reg << 16;
7068 inst.instruction |= inst.operands[1].reg;
7069 inst.instruction |= inst.operands[2].reg << 8;
7070
7071 if (inst.operands[0].reg == inst.operands[1].reg)
7072 as_tsktsk (_("rd and rm should be different in mul"));
7073 }
7074
7075 /* Long Multiply Parser
7076 UMULL RdLo, RdHi, Rm, Rs
7077 SMULL RdLo, RdHi, Rm, Rs
7078 UMLAL RdLo, RdHi, Rm, Rs
7079 SMLAL RdLo, RdHi, Rm, Rs. */
7080
7081 static void
7082 do_mull (void)
7083 {
7084 inst.instruction |= inst.operands[0].reg << 12;
7085 inst.instruction |= inst.operands[1].reg << 16;
7086 inst.instruction |= inst.operands[2].reg;
7087 inst.instruction |= inst.operands[3].reg << 8;
7088
7089 /* rdhi, rdlo and rm must all be different. */
7090 if (inst.operands[0].reg == inst.operands[1].reg
7091 || inst.operands[0].reg == inst.operands[2].reg
7092 || inst.operands[1].reg == inst.operands[2].reg)
7093 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7094 }
7095
7096 static void
7097 do_nop (void)
7098 {
7099 if (inst.operands[0].present)
7100 {
7101 /* Architectural NOP hints are CPSR sets with no bits selected. */
7102 inst.instruction &= 0xf0000000;
7103 inst.instruction |= 0x0320f000 + inst.operands[0].imm;
7104 }
7105 }
7106
7107 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7108 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7109 Condition defaults to COND_ALWAYS.
7110 Error if Rd, Rn or Rm are R15. */
7111
7112 static void
7113 do_pkhbt (void)
7114 {
7115 inst.instruction |= inst.operands[0].reg << 12;
7116 inst.instruction |= inst.operands[1].reg << 16;
7117 inst.instruction |= inst.operands[2].reg;
7118 if (inst.operands[3].present)
7119 encode_arm_shift (3);
7120 }
7121
7122 /* ARM V6 PKHTB (Argument Parse). */
7123
7124 static void
7125 do_pkhtb (void)
7126 {
7127 if (!inst.operands[3].present)
7128 {
7129 /* If the shift specifier is omitted, turn the instruction
7130 into pkhbt rd, rm, rn. */
7131 inst.instruction &= 0xfff00010;
7132 inst.instruction |= inst.operands[0].reg << 12;
7133 inst.instruction |= inst.operands[1].reg;
7134 inst.instruction |= inst.operands[2].reg << 16;
7135 }
7136 else
7137 {
7138 inst.instruction |= inst.operands[0].reg << 12;
7139 inst.instruction |= inst.operands[1].reg << 16;
7140 inst.instruction |= inst.operands[2].reg;
7141 encode_arm_shift (3);
7142 }
7143 }
7144
7145 /* ARMv5TE: Preload-Cache
7146
7147 PLD <addr_mode>
7148
7149 Syntactically, like LDR with B=1, W=0, L=1. */
7150
7151 static void
7152 do_pld (void)
7153 {
7154 constraint (!inst.operands[0].isreg,
7155 _("'[' expected after PLD mnemonic"));
7156 constraint (inst.operands[0].postind,
7157 _("post-indexed expression used in preload instruction"));
7158 constraint (inst.operands[0].writeback,
7159 _("writeback used in preload instruction"));
7160 constraint (!inst.operands[0].preind,
7161 _("unindexed addressing used in preload instruction"));
7162 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7163 }
7164
7165 /* ARMv7: PLI <addr_mode> */
7166 static void
7167 do_pli (void)
7168 {
7169 constraint (!inst.operands[0].isreg,
7170 _("'[' expected after PLI mnemonic"));
7171 constraint (inst.operands[0].postind,
7172 _("post-indexed expression used in preload instruction"));
7173 constraint (inst.operands[0].writeback,
7174 _("writeback used in preload instruction"));
7175 constraint (!inst.operands[0].preind,
7176 _("unindexed addressing used in preload instruction"));
7177 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7178 inst.instruction &= ~PRE_INDEX;
7179 }
7180
7181 static void
7182 do_push_pop (void)
7183 {
7184 inst.operands[1] = inst.operands[0];
7185 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7186 inst.operands[0].isreg = 1;
7187 inst.operands[0].writeback = 1;
7188 inst.operands[0].reg = REG_SP;
7189 do_ldmstm ();
7190 }
7191
7192 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7193 word at the specified address and the following word
7194 respectively.
7195 Unconditionally executed.
7196 Error if Rn is R15. */
7197
7198 static void
7199 do_rfe (void)
7200 {
7201 inst.instruction |= inst.operands[0].reg << 16;
7202 if (inst.operands[0].writeback)
7203 inst.instruction |= WRITE_BACK;
7204 }
7205
7206 /* ARM V6 ssat (argument parse). */
7207
7208 static void
7209 do_ssat (void)
7210 {
7211 inst.instruction |= inst.operands[0].reg << 12;
7212 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7213 inst.instruction |= inst.operands[2].reg;
7214
7215 if (inst.operands[3].present)
7216 encode_arm_shift (3);
7217 }
7218
7219 /* ARM V6 usat (argument parse). */
7220
7221 static void
7222 do_usat (void)
7223 {
7224 inst.instruction |= inst.operands[0].reg << 12;
7225 inst.instruction |= inst.operands[1].imm << 16;
7226 inst.instruction |= inst.operands[2].reg;
7227
7228 if (inst.operands[3].present)
7229 encode_arm_shift (3);
7230 }
7231
7232 /* ARM V6 ssat16 (argument parse). */
7233
7234 static void
7235 do_ssat16 (void)
7236 {
7237 inst.instruction |= inst.operands[0].reg << 12;
7238 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7239 inst.instruction |= inst.operands[2].reg;
7240 }
7241
7242 static void
7243 do_usat16 (void)
7244 {
7245 inst.instruction |= inst.operands[0].reg << 12;
7246 inst.instruction |= inst.operands[1].imm << 16;
7247 inst.instruction |= inst.operands[2].reg;
7248 }
7249
7250 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7251 preserving the other bits.
7252
7253 setend <endian_specifier>, where <endian_specifier> is either
7254 BE or LE. */
7255
7256 static void
7257 do_setend (void)
7258 {
7259 if (inst.operands[0].imm)
7260 inst.instruction |= 0x200;
7261 }
7262
7263 static void
7264 do_shift (void)
7265 {
7266 unsigned int Rm = (inst.operands[1].present
7267 ? inst.operands[1].reg
7268 : inst.operands[0].reg);
7269
7270 inst.instruction |= inst.operands[0].reg << 12;
7271 inst.instruction |= Rm;
7272 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
7273 {
7274 inst.instruction |= inst.operands[2].reg << 8;
7275 inst.instruction |= SHIFT_BY_REG;
7276 }
7277 else
7278 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7279 }
7280
7281 static void
7282 do_smc (void)
7283 {
7284 inst.reloc.type = BFD_RELOC_ARM_SMC;
7285 inst.reloc.pc_rel = 0;
7286 }
7287
7288 static void
7289 do_swi (void)
7290 {
7291 inst.reloc.type = BFD_RELOC_ARM_SWI;
7292 inst.reloc.pc_rel = 0;
7293 }
7294
7295 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7296 SMLAxy{cond} Rd,Rm,Rs,Rn
7297 SMLAWy{cond} Rd,Rm,Rs,Rn
7298 Error if any register is R15. */
7299
7300 static void
7301 do_smla (void)
7302 {
7303 inst.instruction |= inst.operands[0].reg << 16;
7304 inst.instruction |= inst.operands[1].reg;
7305 inst.instruction |= inst.operands[2].reg << 8;
7306 inst.instruction |= inst.operands[3].reg << 12;
7307 }
7308
7309 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7310 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7311 Error if any register is R15.
7312 Warning if Rdlo == Rdhi. */
7313
7314 static void
7315 do_smlal (void)
7316 {
7317 inst.instruction |= inst.operands[0].reg << 12;
7318 inst.instruction |= inst.operands[1].reg << 16;
7319 inst.instruction |= inst.operands[2].reg;
7320 inst.instruction |= inst.operands[3].reg << 8;
7321
7322 if (inst.operands[0].reg == inst.operands[1].reg)
7323 as_tsktsk (_("rdhi and rdlo must be different"));
7324 }
7325
7326 /* ARM V5E (El Segundo) signed-multiply (argument parse)
7327 SMULxy{cond} Rd,Rm,Rs
7328 Error if any register is R15. */
7329
7330 static void
7331 do_smul (void)
7332 {
7333 inst.instruction |= inst.operands[0].reg << 16;
7334 inst.instruction |= inst.operands[1].reg;
7335 inst.instruction |= inst.operands[2].reg << 8;
7336 }
7337
7338 /* ARM V6 srs (argument parse). */
7339
7340 static void
7341 do_srs (void)
7342 {
7343 inst.instruction |= inst.operands[0].imm;
7344 if (inst.operands[0].writeback)
7345 inst.instruction |= WRITE_BACK;
7346 }
7347
7348 /* ARM V6 strex (argument parse). */
7349
7350 static void
7351 do_strex (void)
7352 {
7353 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7354 || inst.operands[2].postind || inst.operands[2].writeback
7355 || inst.operands[2].immisreg || inst.operands[2].shifted
7356 || inst.operands[2].negative
7357 /* See comment in do_ldrex(). */
7358 || (inst.operands[2].reg == REG_PC),
7359 BAD_ADDR_MODE);
7360
7361 constraint (inst.operands[0].reg == inst.operands[1].reg
7362 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
7363
7364 constraint (inst.reloc.exp.X_op != O_constant
7365 || inst.reloc.exp.X_add_number != 0,
7366 _("offset must be zero in ARM encoding"));
7367
7368 inst.instruction |= inst.operands[0].reg << 12;
7369 inst.instruction |= inst.operands[1].reg;
7370 inst.instruction |= inst.operands[2].reg << 16;
7371 inst.reloc.type = BFD_RELOC_UNUSED;
7372 }
7373
7374 static void
7375 do_strexd (void)
7376 {
7377 constraint (inst.operands[1].reg % 2 != 0,
7378 _("even register required"));
7379 constraint (inst.operands[2].present
7380 && inst.operands[2].reg != inst.operands[1].reg + 1,
7381 _("can only store two consecutive registers"));
7382 /* If op 2 were present and equal to PC, this function wouldn't
7383 have been called in the first place. */
7384 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
7385
7386 constraint (inst.operands[0].reg == inst.operands[1].reg
7387 || inst.operands[0].reg == inst.operands[1].reg + 1
7388 || inst.operands[0].reg == inst.operands[3].reg,
7389 BAD_OVERLAP);
7390
7391 inst.instruction |= inst.operands[0].reg << 12;
7392 inst.instruction |= inst.operands[1].reg;
7393 inst.instruction |= inst.operands[3].reg << 16;
7394 }
7395
7396 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
7397 extends it to 32-bits, and adds the result to a value in another
7398 register. You can specify a rotation by 0, 8, 16, or 24 bits
7399 before extracting the 16-bit value.
7400 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
7401 Condition defaults to COND_ALWAYS.
7402 Error if any register uses R15. */
7403
7404 static void
7405 do_sxtah (void)
7406 {
7407 inst.instruction |= inst.operands[0].reg << 12;
7408 inst.instruction |= inst.operands[1].reg << 16;
7409 inst.instruction |= inst.operands[2].reg;
7410 inst.instruction |= inst.operands[3].imm << 10;
7411 }
7412
7413 /* ARM V6 SXTH.
7414
7415 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
7416 Condition defaults to COND_ALWAYS.
7417 Error if any register uses R15. */
7418
7419 static void
7420 do_sxth (void)
7421 {
7422 inst.instruction |= inst.operands[0].reg << 12;
7423 inst.instruction |= inst.operands[1].reg;
7424 inst.instruction |= inst.operands[2].imm << 10;
7425 }
7426 \f
7427 /* VFP instructions. In a logical order: SP variant first, monad
7428 before dyad, arithmetic then move then load/store. */
7429
7430 static void
7431 do_vfp_sp_monadic (void)
7432 {
7433 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7434 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
7435 }
7436
7437 static void
7438 do_vfp_sp_dyadic (void)
7439 {
7440 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7441 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7442 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
7443 }
7444
7445 static void
7446 do_vfp_sp_compare_z (void)
7447 {
7448 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7449 }
7450
7451 static void
7452 do_vfp_dp_sp_cvt (void)
7453 {
7454 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7455 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
7456 }
7457
7458 static void
7459 do_vfp_sp_dp_cvt (void)
7460 {
7461 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7462 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7463 }
7464
7465 static void
7466 do_vfp_reg_from_sp (void)
7467 {
7468 inst.instruction |= inst.operands[0].reg << 12;
7469 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7470 }
7471
7472 static void
7473 do_vfp_reg2_from_sp2 (void)
7474 {
7475 constraint (inst.operands[2].imm != 2,
7476 _("only two consecutive VFP SP registers allowed here"));
7477 inst.instruction |= inst.operands[0].reg << 12;
7478 inst.instruction |= inst.operands[1].reg << 16;
7479 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
7480 }
7481
7482 static void
7483 do_vfp_sp_from_reg (void)
7484 {
7485 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
7486 inst.instruction |= inst.operands[1].reg << 12;
7487 }
7488
7489 static void
7490 do_vfp_sp2_from_reg2 (void)
7491 {
7492 constraint (inst.operands[0].imm != 2,
7493 _("only two consecutive VFP SP registers allowed here"));
7494 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
7495 inst.instruction |= inst.operands[1].reg << 12;
7496 inst.instruction |= inst.operands[2].reg << 16;
7497 }
7498
7499 static void
7500 do_vfp_sp_ldst (void)
7501 {
7502 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7503 encode_arm_cp_address (1, FALSE, TRUE, 0);
7504 }
7505
7506 static void
7507 do_vfp_dp_ldst (void)
7508 {
7509 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7510 encode_arm_cp_address (1, FALSE, TRUE, 0);
7511 }
7512
7513
7514 static void
7515 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
7516 {
7517 if (inst.operands[0].writeback)
7518 inst.instruction |= WRITE_BACK;
7519 else
7520 constraint (ldstm_type != VFP_LDSTMIA,
7521 _("this addressing mode requires base-register writeback"));
7522 inst.instruction |= inst.operands[0].reg << 16;
7523 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
7524 inst.instruction |= inst.operands[1].imm;
7525 }
7526
7527 static void
7528 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
7529 {
7530 int count;
7531
7532 if (inst.operands[0].writeback)
7533 inst.instruction |= WRITE_BACK;
7534 else
7535 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
7536 _("this addressing mode requires base-register writeback"));
7537
7538 inst.instruction |= inst.operands[0].reg << 16;
7539 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7540
7541 count = inst.operands[1].imm << 1;
7542 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
7543 count += 1;
7544
7545 inst.instruction |= count;
7546 }
7547
7548 static void
7549 do_vfp_sp_ldstmia (void)
7550 {
7551 vfp_sp_ldstm (VFP_LDSTMIA);
7552 }
7553
7554 static void
7555 do_vfp_sp_ldstmdb (void)
7556 {
7557 vfp_sp_ldstm (VFP_LDSTMDB);
7558 }
7559
7560 static void
7561 do_vfp_dp_ldstmia (void)
7562 {
7563 vfp_dp_ldstm (VFP_LDSTMIA);
7564 }
7565
7566 static void
7567 do_vfp_dp_ldstmdb (void)
7568 {
7569 vfp_dp_ldstm (VFP_LDSTMDB);
7570 }
7571
7572 static void
7573 do_vfp_xp_ldstmia (void)
7574 {
7575 vfp_dp_ldstm (VFP_LDSTMIAX);
7576 }
7577
7578 static void
7579 do_vfp_xp_ldstmdb (void)
7580 {
7581 vfp_dp_ldstm (VFP_LDSTMDBX);
7582 }
7583
7584 static void
7585 do_vfp_dp_rd_rm (void)
7586 {
7587 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7588 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7589 }
7590
7591 static void
7592 do_vfp_dp_rn_rd (void)
7593 {
7594 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
7595 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7596 }
7597
7598 static void
7599 do_vfp_dp_rd_rn (void)
7600 {
7601 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7602 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7603 }
7604
7605 static void
7606 do_vfp_dp_rd_rn_rm (void)
7607 {
7608 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7609 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7610 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
7611 }
7612
7613 static void
7614 do_vfp_dp_rd (void)
7615 {
7616 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7617 }
7618
7619 static void
7620 do_vfp_dp_rm_rd_rn (void)
7621 {
7622 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
7623 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7624 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
7625 }
7626
7627 /* VFPv3 instructions. */
7628 static void
7629 do_vfp_sp_const (void)
7630 {
7631 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7632 inst.instruction |= (inst.operands[1].imm & 15) << 16;
7633 inst.instruction |= (inst.operands[1].imm >> 4);
7634 }
7635
7636 static void
7637 do_vfp_dp_const (void)
7638 {
7639 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7640 inst.instruction |= (inst.operands[1].imm & 15) << 16;
7641 inst.instruction |= (inst.operands[1].imm >> 4);
7642 }
7643
7644 static void
7645 vfp_conv (int srcsize)
7646 {
7647 unsigned immbits = srcsize - inst.operands[1].imm;
7648 inst.instruction |= (immbits & 1) << 5;
7649 inst.instruction |= (immbits >> 1);
7650 }
7651
7652 static void
7653 do_vfp_sp_conv_16 (void)
7654 {
7655 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7656 vfp_conv (16);
7657 }
7658
7659 static void
7660 do_vfp_dp_conv_16 (void)
7661 {
7662 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7663 vfp_conv (16);
7664 }
7665
7666 static void
7667 do_vfp_sp_conv_32 (void)
7668 {
7669 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7670 vfp_conv (32);
7671 }
7672
7673 static void
7674 do_vfp_dp_conv_32 (void)
7675 {
7676 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7677 vfp_conv (32);
7678 }
7679
7680 \f
7681 /* FPA instructions. Also in a logical order. */
7682
7683 static void
7684 do_fpa_cmp (void)
7685 {
7686 inst.instruction |= inst.operands[0].reg << 16;
7687 inst.instruction |= inst.operands[1].reg;
7688 }
7689
7690 static void
7691 do_fpa_ldmstm (void)
7692 {
7693 inst.instruction |= inst.operands[0].reg << 12;
7694 switch (inst.operands[1].imm)
7695 {
7696 case 1: inst.instruction |= CP_T_X; break;
7697 case 2: inst.instruction |= CP_T_Y; break;
7698 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
7699 case 4: break;
7700 default: abort ();
7701 }
7702
7703 if (inst.instruction & (PRE_INDEX | INDEX_UP))
7704 {
7705 /* The instruction specified "ea" or "fd", so we can only accept
7706 [Rn]{!}. The instruction does not really support stacking or
7707 unstacking, so we have to emulate these by setting appropriate
7708 bits and offsets. */
7709 constraint (inst.reloc.exp.X_op != O_constant
7710 || inst.reloc.exp.X_add_number != 0,
7711 _("this instruction does not support indexing"));
7712
7713 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
7714 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
7715
7716 if (!(inst.instruction & INDEX_UP))
7717 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
7718
7719 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
7720 {
7721 inst.operands[2].preind = 0;
7722 inst.operands[2].postind = 1;
7723 }
7724 }
7725
7726 encode_arm_cp_address (2, TRUE, TRUE, 0);
7727 }
7728
7729 \f
7730 /* iWMMXt instructions: strictly in alphabetical order. */
7731
7732 static void
7733 do_iwmmxt_tandorc (void)
7734 {
7735 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
7736 }
7737
7738 static void
7739 do_iwmmxt_textrc (void)
7740 {
7741 inst.instruction |= inst.operands[0].reg << 12;
7742 inst.instruction |= inst.operands[1].imm;
7743 }
7744
7745 static void
7746 do_iwmmxt_textrm (void)
7747 {
7748 inst.instruction |= inst.operands[0].reg << 12;
7749 inst.instruction |= inst.operands[1].reg << 16;
7750 inst.instruction |= inst.operands[2].imm;
7751 }
7752
7753 static void
7754 do_iwmmxt_tinsr (void)
7755 {
7756 inst.instruction |= inst.operands[0].reg << 16;
7757 inst.instruction |= inst.operands[1].reg << 12;
7758 inst.instruction |= inst.operands[2].imm;
7759 }
7760
7761 static void
7762 do_iwmmxt_tmia (void)
7763 {
7764 inst.instruction |= inst.operands[0].reg << 5;
7765 inst.instruction |= inst.operands[1].reg;
7766 inst.instruction |= inst.operands[2].reg << 12;
7767 }
7768
7769 static void
7770 do_iwmmxt_waligni (void)
7771 {
7772 inst.instruction |= inst.operands[0].reg << 12;
7773 inst.instruction |= inst.operands[1].reg << 16;
7774 inst.instruction |= inst.operands[2].reg;
7775 inst.instruction |= inst.operands[3].imm << 20;
7776 }
7777
7778 static void
7779 do_iwmmxt_wmov (void)
7780 {
7781 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
7782 inst.instruction |= inst.operands[0].reg << 12;
7783 inst.instruction |= inst.operands[1].reg << 16;
7784 inst.instruction |= inst.operands[1].reg;
7785 }
7786
7787 static void
7788 do_iwmmxt_wldstbh (void)
7789 {
7790 int reloc;
7791 inst.instruction |= inst.operands[0].reg << 12;
7792 if (thumb_mode)
7793 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
7794 else
7795 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
7796 encode_arm_cp_address (1, TRUE, FALSE, reloc);
7797 }
7798
7799 static void
7800 do_iwmmxt_wldstw (void)
7801 {
7802 /* RIWR_RIWC clears .isreg for a control register. */
7803 if (!inst.operands[0].isreg)
7804 {
7805 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7806 inst.instruction |= 0xf0000000;
7807 }
7808
7809 inst.instruction |= inst.operands[0].reg << 12;
7810 encode_arm_cp_address (1, TRUE, TRUE, 0);
7811 }
7812
7813 static void
7814 do_iwmmxt_wldstd (void)
7815 {
7816 inst.instruction |= inst.operands[0].reg << 12;
7817 encode_arm_cp_address (1, TRUE, FALSE, 0);
7818 }
7819
7820 static void
7821 do_iwmmxt_wshufh (void)
7822 {
7823 inst.instruction |= inst.operands[0].reg << 12;
7824 inst.instruction |= inst.operands[1].reg << 16;
7825 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
7826 inst.instruction |= (inst.operands[2].imm & 0x0f);
7827 }
7828
7829 static void
7830 do_iwmmxt_wzero (void)
7831 {
7832 /* WZERO reg is an alias for WANDN reg, reg, reg. */
7833 inst.instruction |= inst.operands[0].reg;
7834 inst.instruction |= inst.operands[0].reg << 12;
7835 inst.instruction |= inst.operands[0].reg << 16;
7836 }
7837 \f
7838 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
7839 operations first, then control, shift, and load/store. */
7840
7841 /* Insns like "foo X,Y,Z". */
7842
7843 static void
7844 do_mav_triple (void)
7845 {
7846 inst.instruction |= inst.operands[0].reg << 16;
7847 inst.instruction |= inst.operands[1].reg;
7848 inst.instruction |= inst.operands[2].reg << 12;
7849 }
7850
7851 /* Insns like "foo W,X,Y,Z".
7852 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
7853
7854 static void
7855 do_mav_quad (void)
7856 {
7857 inst.instruction |= inst.operands[0].reg << 5;
7858 inst.instruction |= inst.operands[1].reg << 12;
7859 inst.instruction |= inst.operands[2].reg << 16;
7860 inst.instruction |= inst.operands[3].reg;
7861 }
7862
7863 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
7864 static void
7865 do_mav_dspsc (void)
7866 {
7867 inst.instruction |= inst.operands[1].reg << 12;
7868 }
7869
7870 /* Maverick shift immediate instructions.
7871 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
7872 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
7873
7874 static void
7875 do_mav_shift (void)
7876 {
7877 int imm = inst.operands[2].imm;
7878
7879 inst.instruction |= inst.operands[0].reg << 12;
7880 inst.instruction |= inst.operands[1].reg << 16;
7881
7882 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
7883 Bits 5-7 of the insn should have bits 4-6 of the immediate.
7884 Bit 4 should be 0. */
7885 imm = (imm & 0xf) | ((imm & 0x70) << 1);
7886
7887 inst.instruction |= imm;
7888 }
7889 \f
7890 /* XScale instructions. Also sorted arithmetic before move. */
7891
7892 /* Xscale multiply-accumulate (argument parse)
7893 MIAcc acc0,Rm,Rs
7894 MIAPHcc acc0,Rm,Rs
7895 MIAxycc acc0,Rm,Rs. */
7896
7897 static void
7898 do_xsc_mia (void)
7899 {
7900 inst.instruction |= inst.operands[1].reg;
7901 inst.instruction |= inst.operands[2].reg << 12;
7902 }
7903
7904 /* Xscale move-accumulator-register (argument parse)
7905
7906 MARcc acc0,RdLo,RdHi. */
7907
7908 static void
7909 do_xsc_mar (void)
7910 {
7911 inst.instruction |= inst.operands[1].reg << 12;
7912 inst.instruction |= inst.operands[2].reg << 16;
7913 }
7914
7915 /* Xscale move-register-accumulator (argument parse)
7916
7917 MRAcc RdLo,RdHi,acc0. */
7918
7919 static void
7920 do_xsc_mra (void)
7921 {
7922 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
7923 inst.instruction |= inst.operands[0].reg << 12;
7924 inst.instruction |= inst.operands[1].reg << 16;
7925 }
7926 \f
7927 /* Encoding functions relevant only to Thumb. */
7928
7929 /* inst.operands[i] is a shifted-register operand; encode
7930 it into inst.instruction in the format used by Thumb32. */
7931
7932 static void
7933 encode_thumb32_shifted_operand (int i)
7934 {
7935 unsigned int value = inst.reloc.exp.X_add_number;
7936 unsigned int shift = inst.operands[i].shift_kind;
7937
7938 constraint (inst.operands[i].immisreg,
7939 _("shift by register not allowed in thumb mode"));
7940 inst.instruction |= inst.operands[i].reg;
7941 if (shift == SHIFT_RRX)
7942 inst.instruction |= SHIFT_ROR << 4;
7943 else
7944 {
7945 constraint (inst.reloc.exp.X_op != O_constant,
7946 _("expression too complex"));
7947
7948 constraint (value > 32
7949 || (value == 32 && (shift == SHIFT_LSL
7950 || shift == SHIFT_ROR)),
7951 _("shift expression is too large"));
7952
7953 if (value == 0)
7954 shift = SHIFT_LSL;
7955 else if (value == 32)
7956 value = 0;
7957
7958 inst.instruction |= shift << 4;
7959 inst.instruction |= (value & 0x1c) << 10;
7960 inst.instruction |= (value & 0x03) << 6;
7961 }
7962 }
7963
7964
7965 /* inst.operands[i] was set up by parse_address. Encode it into a
7966 Thumb32 format load or store instruction. Reject forms that cannot
7967 be used with such instructions. If is_t is true, reject forms that
7968 cannot be used with a T instruction; if is_d is true, reject forms
7969 that cannot be used with a D instruction. */
7970
7971 static void
7972 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
7973 {
7974 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7975
7976 constraint (!inst.operands[i].isreg,
7977 _("Instruction does not support =N addresses"));
7978
7979 inst.instruction |= inst.operands[i].reg << 16;
7980 if (inst.operands[i].immisreg)
7981 {
7982 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
7983 constraint (is_t || is_d, _("cannot use register index with this instruction"));
7984 constraint (inst.operands[i].negative,
7985 _("Thumb does not support negative register indexing"));
7986 constraint (inst.operands[i].postind,
7987 _("Thumb does not support register post-indexing"));
7988 constraint (inst.operands[i].writeback,
7989 _("Thumb does not support register indexing with writeback"));
7990 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
7991 _("Thumb supports only LSL in shifted register indexing"));
7992
7993 inst.instruction |= inst.operands[i].imm;
7994 if (inst.operands[i].shifted)
7995 {
7996 constraint (inst.reloc.exp.X_op != O_constant,
7997 _("expression too complex"));
7998 constraint (inst.reloc.exp.X_add_number < 0
7999 || inst.reloc.exp.X_add_number > 3,
8000 _("shift out of range"));
8001 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8002 }
8003 inst.reloc.type = BFD_RELOC_UNUSED;
8004 }
8005 else if (inst.operands[i].preind)
8006 {
8007 constraint (is_pc && inst.operands[i].writeback,
8008 _("cannot use writeback with PC-relative addressing"));
8009 constraint (is_t && inst.operands[i].writeback,
8010 _("cannot use writeback with this instruction"));
8011
8012 if (is_d)
8013 {
8014 inst.instruction |= 0x01000000;
8015 if (inst.operands[i].writeback)
8016 inst.instruction |= 0x00200000;
8017 }
8018 else
8019 {
8020 inst.instruction |= 0x00000c00;
8021 if (inst.operands[i].writeback)
8022 inst.instruction |= 0x00000100;
8023 }
8024 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8025 }
8026 else if (inst.operands[i].postind)
8027 {
8028 assert (inst.operands[i].writeback);
8029 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8030 constraint (is_t, _("cannot use post-indexing with this instruction"));
8031
8032 if (is_d)
8033 inst.instruction |= 0x00200000;
8034 else
8035 inst.instruction |= 0x00000900;
8036 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8037 }
8038 else /* unindexed - only for coprocessor */
8039 inst.error = _("instruction does not accept unindexed addressing");
8040 }
8041
8042 /* Table of Thumb instructions which exist in both 16- and 32-bit
8043 encodings (the latter only in post-V6T2 cores). The index is the
8044 value used in the insns table below. When there is more than one
8045 possible 16-bit encoding for the instruction, this table always
8046 holds variant (1).
8047 Also contains several pseudo-instructions used during relaxation. */
8048 #define T16_32_TAB \
8049 X(adc, 4140, eb400000), \
8050 X(adcs, 4140, eb500000), \
8051 X(add, 1c00, eb000000), \
8052 X(adds, 1c00, eb100000), \
8053 X(addi, 0000, f1000000), \
8054 X(addis, 0000, f1100000), \
8055 X(add_pc,000f, f20f0000), \
8056 X(add_sp,000d, f10d0000), \
8057 X(adr, 000f, f20f0000), \
8058 X(and, 4000, ea000000), \
8059 X(ands, 4000, ea100000), \
8060 X(asr, 1000, fa40f000), \
8061 X(asrs, 1000, fa50f000), \
8062 X(b, e000, f000b000), \
8063 X(bcond, d000, f0008000), \
8064 X(bic, 4380, ea200000), \
8065 X(bics, 4380, ea300000), \
8066 X(cmn, 42c0, eb100f00), \
8067 X(cmp, 2800, ebb00f00), \
8068 X(cpsie, b660, f3af8400), \
8069 X(cpsid, b670, f3af8600), \
8070 X(cpy, 4600, ea4f0000), \
8071 X(dec_sp,80dd, f1bd0d00), \
8072 X(eor, 4040, ea800000), \
8073 X(eors, 4040, ea900000), \
8074 X(inc_sp,00dd, f10d0d00), \
8075 X(ldmia, c800, e8900000), \
8076 X(ldr, 6800, f8500000), \
8077 X(ldrb, 7800, f8100000), \
8078 X(ldrh, 8800, f8300000), \
8079 X(ldrsb, 5600, f9100000), \
8080 X(ldrsh, 5e00, f9300000), \
8081 X(ldr_pc,4800, f85f0000), \
8082 X(ldr_pc2,4800, f85f0000), \
8083 X(ldr_sp,9800, f85d0000), \
8084 X(lsl, 0000, fa00f000), \
8085 X(lsls, 0000, fa10f000), \
8086 X(lsr, 0800, fa20f000), \
8087 X(lsrs, 0800, fa30f000), \
8088 X(mov, 2000, ea4f0000), \
8089 X(movs, 2000, ea5f0000), \
8090 X(mul, 4340, fb00f000), \
8091 X(muls, 4340, ffffffff), /* no 32b muls */ \
8092 X(mvn, 43c0, ea6f0000), \
8093 X(mvns, 43c0, ea7f0000), \
8094 X(neg, 4240, f1c00000), /* rsb #0 */ \
8095 X(negs, 4240, f1d00000), /* rsbs #0 */ \
8096 X(orr, 4300, ea400000), \
8097 X(orrs, 4300, ea500000), \
8098 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8099 X(push, b400, e92d0000), /* stmdb sp!,... */ \
8100 X(rev, ba00, fa90f080), \
8101 X(rev16, ba40, fa90f090), \
8102 X(revsh, bac0, fa90f0b0), \
8103 X(ror, 41c0, fa60f000), \
8104 X(rors, 41c0, fa70f000), \
8105 X(sbc, 4180, eb600000), \
8106 X(sbcs, 4180, eb700000), \
8107 X(stmia, c000, e8800000), \
8108 X(str, 6000, f8400000), \
8109 X(strb, 7000, f8000000), \
8110 X(strh, 8000, f8200000), \
8111 X(str_sp,9000, f84d0000), \
8112 X(sub, 1e00, eba00000), \
8113 X(subs, 1e00, ebb00000), \
8114 X(subi, 8000, f1a00000), \
8115 X(subis, 8000, f1b00000), \
8116 X(sxtb, b240, fa4ff080), \
8117 X(sxth, b200, fa0ff080), \
8118 X(tst, 4200, ea100f00), \
8119 X(uxtb, b2c0, fa5ff080), \
8120 X(uxth, b280, fa1ff080), \
8121 X(nop, bf00, f3af8000), \
8122 X(yield, bf10, f3af8001), \
8123 X(wfe, bf20, f3af8002), \
8124 X(wfi, bf30, f3af8003), \
8125 X(sev, bf40, f3af9004), /* typo, 8004? */
8126
8127 /* To catch errors in encoding functions, the codes are all offset by
8128 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8129 as 16-bit instructions. */
8130 #define X(a,b,c) T_MNEM_##a
8131 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8132 #undef X
8133
8134 #define X(a,b,c) 0x##b
8135 static const unsigned short thumb_op16[] = { T16_32_TAB };
8136 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8137 #undef X
8138
8139 #define X(a,b,c) 0x##c
8140 static const unsigned int thumb_op32[] = { T16_32_TAB };
8141 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8142 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
8143 #undef X
8144 #undef T16_32_TAB
8145
8146 /* Thumb instruction encoders, in alphabetical order. */
8147
8148 /* ADDW or SUBW. */
8149 static void
8150 do_t_add_sub_w (void)
8151 {
8152 int Rd, Rn;
8153
8154 Rd = inst.operands[0].reg;
8155 Rn = inst.operands[1].reg;
8156
8157 constraint (Rd == 15, _("PC not allowed as destination"));
8158 inst.instruction |= (Rn << 16) | (Rd << 8);
8159 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8160 }
8161
8162 /* Parse an add or subtract instruction. We get here with inst.instruction
8163 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8164
8165 static void
8166 do_t_add_sub (void)
8167 {
8168 int Rd, Rs, Rn;
8169
8170 Rd = inst.operands[0].reg;
8171 Rs = (inst.operands[1].present
8172 ? inst.operands[1].reg /* Rd, Rs, foo */
8173 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8174
8175 if (unified_syntax)
8176 {
8177 bfd_boolean flags;
8178 bfd_boolean narrow;
8179 int opcode;
8180
8181 flags = (inst.instruction == T_MNEM_adds
8182 || inst.instruction == T_MNEM_subs);
8183 if (flags)
8184 narrow = (current_it_mask == 0);
8185 else
8186 narrow = (current_it_mask != 0);
8187 if (!inst.operands[2].isreg)
8188 {
8189 int add;
8190
8191 add = (inst.instruction == T_MNEM_add
8192 || inst.instruction == T_MNEM_adds);
8193 opcode = 0;
8194 if (inst.size_req != 4)
8195 {
8196 /* Attempt to use a narrow opcode, with relaxation if
8197 appropriate. */
8198 if (Rd == REG_SP && Rs == REG_SP && !flags)
8199 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8200 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8201 opcode = T_MNEM_add_sp;
8202 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8203 opcode = T_MNEM_add_pc;
8204 else if (Rd <= 7 && Rs <= 7 && narrow)
8205 {
8206 if (flags)
8207 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8208 else
8209 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8210 }
8211 if (opcode)
8212 {
8213 inst.instruction = THUMB_OP16(opcode);
8214 inst.instruction |= (Rd << 4) | Rs;
8215 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8216 if (inst.size_req != 2)
8217 inst.relax = opcode;
8218 }
8219 else
8220 constraint (inst.size_req == 2, BAD_HIREG);
8221 }
8222 if (inst.size_req == 4
8223 || (inst.size_req != 2 && !opcode))
8224 {
8225 if (Rs == REG_PC)
8226 {
8227 /* Always use addw/subw. */
8228 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8229 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8230 }
8231 else
8232 {
8233 inst.instruction = THUMB_OP32 (inst.instruction);
8234 inst.instruction = (inst.instruction & 0xe1ffffff)
8235 | 0x10000000;
8236 if (flags)
8237 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8238 else
8239 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
8240 }
8241 inst.instruction |= inst.operands[0].reg << 8;
8242 inst.instruction |= inst.operands[1].reg << 16;
8243 }
8244 }
8245 else
8246 {
8247 Rn = inst.operands[2].reg;
8248 /* See if we can do this with a 16-bit instruction. */
8249 if (!inst.operands[2].shifted && inst.size_req != 4)
8250 {
8251 if (Rd > 7 || Rs > 7 || Rn > 7)
8252 narrow = FALSE;
8253
8254 if (narrow)
8255 {
8256 inst.instruction = ((inst.instruction == T_MNEM_adds
8257 || inst.instruction == T_MNEM_add)
8258 ? T_OPCODE_ADD_R3
8259 : T_OPCODE_SUB_R3);
8260 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8261 return;
8262 }
8263
8264 if (inst.instruction == T_MNEM_add)
8265 {
8266 if (Rd == Rs)
8267 {
8268 inst.instruction = T_OPCODE_ADD_HI;
8269 inst.instruction |= (Rd & 8) << 4;
8270 inst.instruction |= (Rd & 7);
8271 inst.instruction |= Rn << 3;
8272 return;
8273 }
8274 /* ... because addition is commutative! */
8275 else if (Rd == Rn)
8276 {
8277 inst.instruction = T_OPCODE_ADD_HI;
8278 inst.instruction |= (Rd & 8) << 4;
8279 inst.instruction |= (Rd & 7);
8280 inst.instruction |= Rs << 3;
8281 return;
8282 }
8283 }
8284 }
8285 /* If we get here, it can't be done in 16 bits. */
8286 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
8287 _("shift must be constant"));
8288 inst.instruction = THUMB_OP32 (inst.instruction);
8289 inst.instruction |= Rd << 8;
8290 inst.instruction |= Rs << 16;
8291 encode_thumb32_shifted_operand (2);
8292 }
8293 }
8294 else
8295 {
8296 constraint (inst.instruction == T_MNEM_adds
8297 || inst.instruction == T_MNEM_subs,
8298 BAD_THUMB32);
8299
8300 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
8301 {
8302 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
8303 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
8304 BAD_HIREG);
8305
8306 inst.instruction = (inst.instruction == T_MNEM_add
8307 ? 0x0000 : 0x8000);
8308 inst.instruction |= (Rd << 4) | Rs;
8309 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8310 return;
8311 }
8312
8313 Rn = inst.operands[2].reg;
8314 constraint (inst.operands[2].shifted, _("unshifted register required"));
8315
8316 /* We now have Rd, Rs, and Rn set to registers. */
8317 if (Rd > 7 || Rs > 7 || Rn > 7)
8318 {
8319 /* Can't do this for SUB. */
8320 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
8321 inst.instruction = T_OPCODE_ADD_HI;
8322 inst.instruction |= (Rd & 8) << 4;
8323 inst.instruction |= (Rd & 7);
8324 if (Rs == Rd)
8325 inst.instruction |= Rn << 3;
8326 else if (Rn == Rd)
8327 inst.instruction |= Rs << 3;
8328 else
8329 constraint (1, _("dest must overlap one source register"));
8330 }
8331 else
8332 {
8333 inst.instruction = (inst.instruction == T_MNEM_add
8334 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
8335 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8336 }
8337 }
8338 }
8339
8340 static void
8341 do_t_adr (void)
8342 {
8343 if (unified_syntax && inst.size_req == 0 && inst.operands[0].reg <= 7)
8344 {
8345 /* Defer to section relaxation. */
8346 inst.relax = inst.instruction;
8347 inst.instruction = THUMB_OP16 (inst.instruction);
8348 inst.instruction |= inst.operands[0].reg << 4;
8349 }
8350 else if (unified_syntax && inst.size_req != 2)
8351 {
8352 /* Generate a 32-bit opcode. */
8353 inst.instruction = THUMB_OP32 (inst.instruction);
8354 inst.instruction |= inst.operands[0].reg << 8;
8355 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
8356 inst.reloc.pc_rel = 1;
8357 }
8358 else
8359 {
8360 /* Generate a 16-bit opcode. */
8361 inst.instruction = THUMB_OP16 (inst.instruction);
8362 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8363 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
8364 inst.reloc.pc_rel = 1;
8365
8366 inst.instruction |= inst.operands[0].reg << 4;
8367 }
8368 }
8369
8370 /* Arithmetic instructions for which there is just one 16-bit
8371 instruction encoding, and it allows only two low registers.
8372 For maximal compatibility with ARM syntax, we allow three register
8373 operands even when Thumb-32 instructions are not available, as long
8374 as the first two are identical. For instance, both "sbc r0,r1" and
8375 "sbc r0,r0,r1" are allowed. */
8376 static void
8377 do_t_arit3 (void)
8378 {
8379 int Rd, Rs, Rn;
8380
8381 Rd = inst.operands[0].reg;
8382 Rs = (inst.operands[1].present
8383 ? inst.operands[1].reg /* Rd, Rs, foo */
8384 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8385 Rn = inst.operands[2].reg;
8386
8387 if (unified_syntax)
8388 {
8389 if (!inst.operands[2].isreg)
8390 {
8391 /* For an immediate, we always generate a 32-bit opcode;
8392 section relaxation will shrink it later if possible. */
8393 inst.instruction = THUMB_OP32 (inst.instruction);
8394 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8395 inst.instruction |= Rd << 8;
8396 inst.instruction |= Rs << 16;
8397 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8398 }
8399 else
8400 {
8401 bfd_boolean narrow;
8402
8403 /* See if we can do this with a 16-bit instruction. */
8404 if (THUMB_SETS_FLAGS (inst.instruction))
8405 narrow = current_it_mask == 0;
8406 else
8407 narrow = current_it_mask != 0;
8408
8409 if (Rd > 7 || Rn > 7 || Rs > 7)
8410 narrow = FALSE;
8411 if (inst.operands[2].shifted)
8412 narrow = FALSE;
8413 if (inst.size_req == 4)
8414 narrow = FALSE;
8415
8416 if (narrow
8417 && Rd == Rs)
8418 {
8419 inst.instruction = THUMB_OP16 (inst.instruction);
8420 inst.instruction |= Rd;
8421 inst.instruction |= Rn << 3;
8422 return;
8423 }
8424
8425 /* If we get here, it can't be done in 16 bits. */
8426 constraint (inst.operands[2].shifted
8427 && inst.operands[2].immisreg,
8428 _("shift must be constant"));
8429 inst.instruction = THUMB_OP32 (inst.instruction);
8430 inst.instruction |= Rd << 8;
8431 inst.instruction |= Rs << 16;
8432 encode_thumb32_shifted_operand (2);
8433 }
8434 }
8435 else
8436 {
8437 /* On its face this is a lie - the instruction does set the
8438 flags. However, the only supported mnemonic in this mode
8439 says it doesn't. */
8440 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
8441
8442 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8443 _("unshifted register required"));
8444 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8445 constraint (Rd != Rs,
8446 _("dest and source1 must be the same register"));
8447
8448 inst.instruction = THUMB_OP16 (inst.instruction);
8449 inst.instruction |= Rd;
8450 inst.instruction |= Rn << 3;
8451 }
8452 }
8453
8454 /* Similarly, but for instructions where the arithmetic operation is
8455 commutative, so we can allow either of them to be different from
8456 the destination operand in a 16-bit instruction. For instance, all
8457 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
8458 accepted. */
8459 static void
8460 do_t_arit3c (void)
8461 {
8462 int Rd, Rs, Rn;
8463
8464 Rd = inst.operands[0].reg;
8465 Rs = (inst.operands[1].present
8466 ? inst.operands[1].reg /* Rd, Rs, foo */
8467 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8468 Rn = inst.operands[2].reg;
8469
8470 if (unified_syntax)
8471 {
8472 if (!inst.operands[2].isreg)
8473 {
8474 /* For an immediate, we always generate a 32-bit opcode;
8475 section relaxation will shrink it later if possible. */
8476 inst.instruction = THUMB_OP32 (inst.instruction);
8477 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8478 inst.instruction |= Rd << 8;
8479 inst.instruction |= Rs << 16;
8480 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8481 }
8482 else
8483 {
8484 bfd_boolean narrow;
8485
8486 /* See if we can do this with a 16-bit instruction. */
8487 if (THUMB_SETS_FLAGS (inst.instruction))
8488 narrow = current_it_mask == 0;
8489 else
8490 narrow = current_it_mask != 0;
8491
8492 if (Rd > 7 || Rn > 7 || Rs > 7)
8493 narrow = FALSE;
8494 if (inst.operands[2].shifted)
8495 narrow = FALSE;
8496 if (inst.size_req == 4)
8497 narrow = FALSE;
8498
8499 if (narrow)
8500 {
8501 if (Rd == Rs)
8502 {
8503 inst.instruction = THUMB_OP16 (inst.instruction);
8504 inst.instruction |= Rd;
8505 inst.instruction |= Rn << 3;
8506 return;
8507 }
8508 if (Rd == Rn)
8509 {
8510 inst.instruction = THUMB_OP16 (inst.instruction);
8511 inst.instruction |= Rd;
8512 inst.instruction |= Rs << 3;
8513 return;
8514 }
8515 }
8516
8517 /* If we get here, it can't be done in 16 bits. */
8518 constraint (inst.operands[2].shifted
8519 && inst.operands[2].immisreg,
8520 _("shift must be constant"));
8521 inst.instruction = THUMB_OP32 (inst.instruction);
8522 inst.instruction |= Rd << 8;
8523 inst.instruction |= Rs << 16;
8524 encode_thumb32_shifted_operand (2);
8525 }
8526 }
8527 else
8528 {
8529 /* On its face this is a lie - the instruction does set the
8530 flags. However, the only supported mnemonic in this mode
8531 says it doesn't. */
8532 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
8533
8534 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8535 _("unshifted register required"));
8536 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8537
8538 inst.instruction = THUMB_OP16 (inst.instruction);
8539 inst.instruction |= Rd;
8540
8541 if (Rd == Rs)
8542 inst.instruction |= Rn << 3;
8543 else if (Rd == Rn)
8544 inst.instruction |= Rs << 3;
8545 else
8546 constraint (1, _("dest must overlap one source register"));
8547 }
8548 }
8549
8550 static void
8551 do_t_barrier (void)
8552 {
8553 if (inst.operands[0].present)
8554 {
8555 constraint ((inst.instruction & 0xf0) != 0x40
8556 && inst.operands[0].imm != 0xf,
8557 "bad barrier type");
8558 inst.instruction |= inst.operands[0].imm;
8559 }
8560 else
8561 inst.instruction |= 0xf;
8562 }
8563
8564 static void
8565 do_t_bfc (void)
8566 {
8567 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8568 constraint (msb > 32, _("bit-field extends past end of register"));
8569 /* The instruction encoding stores the LSB and MSB,
8570 not the LSB and width. */
8571 inst.instruction |= inst.operands[0].reg << 8;
8572 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
8573 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
8574 inst.instruction |= msb - 1;
8575 }
8576
8577 static void
8578 do_t_bfi (void)
8579 {
8580 unsigned int msb;
8581
8582 /* #0 in second position is alternative syntax for bfc, which is
8583 the same instruction but with REG_PC in the Rm field. */
8584 if (!inst.operands[1].isreg)
8585 inst.operands[1].reg = REG_PC;
8586
8587 msb = inst.operands[2].imm + inst.operands[3].imm;
8588 constraint (msb > 32, _("bit-field extends past end of register"));
8589 /* The instruction encoding stores the LSB and MSB,
8590 not the LSB and width. */
8591 inst.instruction |= inst.operands[0].reg << 8;
8592 inst.instruction |= inst.operands[1].reg << 16;
8593 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8594 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8595 inst.instruction |= msb - 1;
8596 }
8597
8598 static void
8599 do_t_bfx (void)
8600 {
8601 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8602 _("bit-field extends past end of register"));
8603 inst.instruction |= inst.operands[0].reg << 8;
8604 inst.instruction |= inst.operands[1].reg << 16;
8605 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8606 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8607 inst.instruction |= inst.operands[3].imm - 1;
8608 }
8609
8610 /* ARM V5 Thumb BLX (argument parse)
8611 BLX <target_addr> which is BLX(1)
8612 BLX <Rm> which is BLX(2)
8613 Unfortunately, there are two different opcodes for this mnemonic.
8614 So, the insns[].value is not used, and the code here zaps values
8615 into inst.instruction.
8616
8617 ??? How to take advantage of the additional two bits of displacement
8618 available in Thumb32 mode? Need new relocation? */
8619
8620 static void
8621 do_t_blx (void)
8622 {
8623 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8624 if (inst.operands[0].isreg)
8625 /* We have a register, so this is BLX(2). */
8626 inst.instruction |= inst.operands[0].reg << 3;
8627 else
8628 {
8629 /* No register. This must be BLX(1). */
8630 inst.instruction = 0xf000e800;
8631 #ifdef OBJ_ELF
8632 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8633 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
8634 else
8635 #endif
8636 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
8637 inst.reloc.pc_rel = 1;
8638 }
8639 }
8640
8641 static void
8642 do_t_branch (void)
8643 {
8644 int opcode;
8645 int cond;
8646
8647 if (current_it_mask)
8648 {
8649 /* Conditional branches inside IT blocks are encoded as unconditional
8650 branches. */
8651 cond = COND_ALWAYS;
8652 /* A branch must be the last instruction in an IT block. */
8653 constraint (current_it_mask != 0x10, BAD_BRANCH);
8654 }
8655 else
8656 cond = inst.cond;
8657
8658 if (cond != COND_ALWAYS)
8659 opcode = T_MNEM_bcond;
8660 else
8661 opcode = inst.instruction;
8662
8663 if (unified_syntax && inst.size_req == 4)
8664 {
8665 inst.instruction = THUMB_OP32(opcode);
8666 if (cond == COND_ALWAYS)
8667 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
8668 else
8669 {
8670 assert (cond != 0xF);
8671 inst.instruction |= cond << 22;
8672 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
8673 }
8674 }
8675 else
8676 {
8677 inst.instruction = THUMB_OP16(opcode);
8678 if (cond == COND_ALWAYS)
8679 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
8680 else
8681 {
8682 inst.instruction |= cond << 8;
8683 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
8684 }
8685 /* Allow section relaxation. */
8686 if (unified_syntax && inst.size_req != 2)
8687 inst.relax = opcode;
8688 }
8689
8690 inst.reloc.pc_rel = 1;
8691 }
8692
8693 static void
8694 do_t_bkpt (void)
8695 {
8696 constraint (inst.cond != COND_ALWAYS,
8697 _("instruction is always unconditional"));
8698 if (inst.operands[0].present)
8699 {
8700 constraint (inst.operands[0].imm > 255,
8701 _("immediate value out of range"));
8702 inst.instruction |= inst.operands[0].imm;
8703 }
8704 }
8705
8706 static void
8707 do_t_branch23 (void)
8708 {
8709 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8710 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
8711 inst.reloc.pc_rel = 1;
8712
8713 /* If the destination of the branch is a defined symbol which does not have
8714 the THUMB_FUNC attribute, then we must be calling a function which has
8715 the (interfacearm) attribute. We look for the Thumb entry point to that
8716 function and change the branch to refer to that function instead. */
8717 if ( inst.reloc.exp.X_op == O_symbol
8718 && inst.reloc.exp.X_add_symbol != NULL
8719 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8720 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8721 inst.reloc.exp.X_add_symbol =
8722 find_real_start (inst.reloc.exp.X_add_symbol);
8723 }
8724
8725 static void
8726 do_t_bx (void)
8727 {
8728 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8729 inst.instruction |= inst.operands[0].reg << 3;
8730 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
8731 should cause the alignment to be checked once it is known. This is
8732 because BX PC only works if the instruction is word aligned. */
8733 }
8734
8735 static void
8736 do_t_bxj (void)
8737 {
8738 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8739 if (inst.operands[0].reg == REG_PC)
8740 as_tsktsk (_("use of r15 in bxj is not really useful"));
8741
8742 inst.instruction |= inst.operands[0].reg << 16;
8743 }
8744
8745 static void
8746 do_t_clz (void)
8747 {
8748 inst.instruction |= inst.operands[0].reg << 8;
8749 inst.instruction |= inst.operands[1].reg << 16;
8750 inst.instruction |= inst.operands[1].reg;
8751 }
8752
8753 static void
8754 do_t_cps (void)
8755 {
8756 constraint (current_it_mask, BAD_NOT_IT);
8757 inst.instruction |= inst.operands[0].imm;
8758 }
8759
8760 static void
8761 do_t_cpsi (void)
8762 {
8763 constraint (current_it_mask, BAD_NOT_IT);
8764 if (unified_syntax
8765 && (inst.operands[1].present || inst.size_req == 4)
8766 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
8767 {
8768 unsigned int imod = (inst.instruction & 0x0030) >> 4;
8769 inst.instruction = 0xf3af8000;
8770 inst.instruction |= imod << 9;
8771 inst.instruction |= inst.operands[0].imm << 5;
8772 if (inst.operands[1].present)
8773 inst.instruction |= 0x100 | inst.operands[1].imm;
8774 }
8775 else
8776 {
8777 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
8778 && (inst.operands[0].imm & 4),
8779 _("selected processor does not support 'A' form "
8780 "of this instruction"));
8781 constraint (inst.operands[1].present || inst.size_req == 4,
8782 _("Thumb does not support the 2-argument "
8783 "form of this instruction"));
8784 inst.instruction |= inst.operands[0].imm;
8785 }
8786 }
8787
8788 /* THUMB CPY instruction (argument parse). */
8789
8790 static void
8791 do_t_cpy (void)
8792 {
8793 if (inst.size_req == 4)
8794 {
8795 inst.instruction = THUMB_OP32 (T_MNEM_mov);
8796 inst.instruction |= inst.operands[0].reg << 8;
8797 inst.instruction |= inst.operands[1].reg;
8798 }
8799 else
8800 {
8801 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
8802 inst.instruction |= (inst.operands[0].reg & 0x7);
8803 inst.instruction |= inst.operands[1].reg << 3;
8804 }
8805 }
8806
8807 static void
8808 do_t_czb (void)
8809 {
8810 constraint (current_it_mask, BAD_NOT_IT);
8811 constraint (inst.operands[0].reg > 7, BAD_HIREG);
8812 inst.instruction |= inst.operands[0].reg;
8813 inst.reloc.pc_rel = 1;
8814 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
8815 }
8816
8817 static void
8818 do_t_dbg (void)
8819 {
8820 inst.instruction |= inst.operands[0].imm;
8821 }
8822
8823 static void
8824 do_t_div (void)
8825 {
8826 if (!inst.operands[1].present)
8827 inst.operands[1].reg = inst.operands[0].reg;
8828 inst.instruction |= inst.operands[0].reg << 8;
8829 inst.instruction |= inst.operands[1].reg << 16;
8830 inst.instruction |= inst.operands[2].reg;
8831 }
8832
8833 static void
8834 do_t_hint (void)
8835 {
8836 if (unified_syntax && inst.size_req == 4)
8837 inst.instruction = THUMB_OP32 (inst.instruction);
8838 else
8839 inst.instruction = THUMB_OP16 (inst.instruction);
8840 }
8841
8842 static void
8843 do_t_it (void)
8844 {
8845 unsigned int cond = inst.operands[0].imm;
8846
8847 constraint (current_it_mask, BAD_NOT_IT);
8848 current_it_mask = (inst.instruction & 0xf) | 0x10;
8849 current_cc = cond;
8850
8851 /* If the condition is a negative condition, invert the mask. */
8852 if ((cond & 0x1) == 0x0)
8853 {
8854 unsigned int mask = inst.instruction & 0x000f;
8855
8856 if ((mask & 0x7) == 0)
8857 /* no conversion needed */;
8858 else if ((mask & 0x3) == 0)
8859 mask ^= 0x8;
8860 else if ((mask & 0x1) == 0)
8861 mask ^= 0xC;
8862 else
8863 mask ^= 0xE;
8864
8865 inst.instruction &= 0xfff0;
8866 inst.instruction |= mask;
8867 }
8868
8869 inst.instruction |= cond << 4;
8870 }
8871
8872 static void
8873 do_t_ldmstm (void)
8874 {
8875 /* This really doesn't seem worth it. */
8876 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
8877 _("expression too complex"));
8878 constraint (inst.operands[1].writeback,
8879 _("Thumb load/store multiple does not support {reglist}^"));
8880
8881 if (unified_syntax)
8882 {
8883 /* See if we can use a 16-bit instruction. */
8884 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
8885 && inst.size_req != 4
8886 && inst.operands[0].reg <= 7
8887 && !(inst.operands[1].imm & ~0xff)
8888 && (inst.instruction == T_MNEM_stmia
8889 ? inst.operands[0].writeback
8890 : (inst.operands[0].writeback
8891 == !(inst.operands[1].imm & (1 << inst.operands[0].reg)))))
8892 {
8893 if (inst.instruction == T_MNEM_stmia
8894 && (inst.operands[1].imm & (1 << inst.operands[0].reg))
8895 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
8896 as_warn (_("value stored for r%d is UNPREDICTABLE"),
8897 inst.operands[0].reg);
8898
8899 inst.instruction = THUMB_OP16 (inst.instruction);
8900 inst.instruction |= inst.operands[0].reg << 8;
8901 inst.instruction |= inst.operands[1].imm;
8902 }
8903 else
8904 {
8905 if (inst.operands[1].imm & (1 << 13))
8906 as_warn (_("SP should not be in register list"));
8907 if (inst.instruction == T_MNEM_stmia)
8908 {
8909 if (inst.operands[1].imm & (1 << 15))
8910 as_warn (_("PC should not be in register list"));
8911 if (inst.operands[1].imm & (1 << inst.operands[0].reg))
8912 as_warn (_("value stored for r%d is UNPREDICTABLE"),
8913 inst.operands[0].reg);
8914 }
8915 else
8916 {
8917 if (inst.operands[1].imm & (1 << 14)
8918 && inst.operands[1].imm & (1 << 15))
8919 as_warn (_("LR and PC should not both be in register list"));
8920 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
8921 && inst.operands[0].writeback)
8922 as_warn (_("base register should not be in register list "
8923 "when written back"));
8924 }
8925 if (inst.instruction < 0xffff)
8926 inst.instruction = THUMB_OP32 (inst.instruction);
8927 inst.instruction |= inst.operands[0].reg << 16;
8928 inst.instruction |= inst.operands[1].imm;
8929 if (inst.operands[0].writeback)
8930 inst.instruction |= WRITE_BACK;
8931 }
8932 }
8933 else
8934 {
8935 constraint (inst.operands[0].reg > 7
8936 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
8937 if (inst.instruction == T_MNEM_stmia)
8938 {
8939 if (!inst.operands[0].writeback)
8940 as_warn (_("this instruction will write back the base register"));
8941 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
8942 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
8943 as_warn (_("value stored for r%d is UNPREDICTABLE"),
8944 inst.operands[0].reg);
8945 }
8946 else
8947 {
8948 if (!inst.operands[0].writeback
8949 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
8950 as_warn (_("this instruction will write back the base register"));
8951 else if (inst.operands[0].writeback
8952 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
8953 as_warn (_("this instruction will not write back the base register"));
8954 }
8955
8956 inst.instruction = THUMB_OP16 (inst.instruction);
8957 inst.instruction |= inst.operands[0].reg << 8;
8958 inst.instruction |= inst.operands[1].imm;
8959 }
8960 }
8961
8962 static void
8963 do_t_ldrex (void)
8964 {
8965 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8966 || inst.operands[1].postind || inst.operands[1].writeback
8967 || inst.operands[1].immisreg || inst.operands[1].shifted
8968 || inst.operands[1].negative,
8969 BAD_ADDR_MODE);
8970
8971 inst.instruction |= inst.operands[0].reg << 12;
8972 inst.instruction |= inst.operands[1].reg << 16;
8973 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
8974 }
8975
8976 static void
8977 do_t_ldrexd (void)
8978 {
8979 if (!inst.operands[1].present)
8980 {
8981 constraint (inst.operands[0].reg == REG_LR,
8982 _("r14 not allowed as first register "
8983 "when second register is omitted"));
8984 inst.operands[1].reg = inst.operands[0].reg + 1;
8985 }
8986 constraint (inst.operands[0].reg == inst.operands[1].reg,
8987 BAD_OVERLAP);
8988
8989 inst.instruction |= inst.operands[0].reg << 12;
8990 inst.instruction |= inst.operands[1].reg << 8;
8991 inst.instruction |= inst.operands[2].reg << 16;
8992 }
8993
8994 static void
8995 do_t_ldst (void)
8996 {
8997 unsigned long opcode;
8998 int Rn;
8999
9000 opcode = inst.instruction;
9001 if (unified_syntax)
9002 {
9003 if (!inst.operands[1].isreg)
9004 {
9005 if (opcode <= 0xffff)
9006 inst.instruction = THUMB_OP32 (opcode);
9007 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9008 return;
9009 }
9010 if (inst.operands[1].isreg
9011 && !inst.operands[1].writeback
9012 && !inst.operands[1].shifted && !inst.operands[1].postind
9013 && !inst.operands[1].negative && inst.operands[0].reg <= 7
9014 && opcode <= 0xffff
9015 && inst.size_req != 4)
9016 {
9017 /* Insn may have a 16-bit form. */
9018 Rn = inst.operands[1].reg;
9019 if (inst.operands[1].immisreg)
9020 {
9021 inst.instruction = THUMB_OP16 (opcode);
9022 /* [Rn, Ri] */
9023 if (Rn <= 7 && inst.operands[1].imm <= 7)
9024 goto op16;
9025 }
9026 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9027 && opcode != T_MNEM_ldrsb)
9028 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9029 || (Rn == REG_SP && opcode == T_MNEM_str))
9030 {
9031 /* [Rn, #const] */
9032 if (Rn > 7)
9033 {
9034 if (Rn == REG_PC)
9035 {
9036 if (inst.reloc.pc_rel)
9037 opcode = T_MNEM_ldr_pc2;
9038 else
9039 opcode = T_MNEM_ldr_pc;
9040 }
9041 else
9042 {
9043 if (opcode == T_MNEM_ldr)
9044 opcode = T_MNEM_ldr_sp;
9045 else
9046 opcode = T_MNEM_str_sp;
9047 }
9048 inst.instruction = inst.operands[0].reg << 8;
9049 }
9050 else
9051 {
9052 inst.instruction = inst.operands[0].reg;
9053 inst.instruction |= inst.operands[1].reg << 3;
9054 }
9055 inst.instruction |= THUMB_OP16 (opcode);
9056 if (inst.size_req == 2)
9057 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9058 else
9059 inst.relax = opcode;
9060 return;
9061 }
9062 }
9063 /* Definitely a 32-bit variant. */
9064 inst.instruction = THUMB_OP32 (opcode);
9065 inst.instruction |= inst.operands[0].reg << 12;
9066 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
9067 return;
9068 }
9069
9070 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9071
9072 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
9073 {
9074 /* Only [Rn,Rm] is acceptable. */
9075 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
9076 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
9077 || inst.operands[1].postind || inst.operands[1].shifted
9078 || inst.operands[1].negative,
9079 _("Thumb does not support this addressing mode"));
9080 inst.instruction = THUMB_OP16 (inst.instruction);
9081 goto op16;
9082 }
9083
9084 inst.instruction = THUMB_OP16 (inst.instruction);
9085 if (!inst.operands[1].isreg)
9086 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9087 return;
9088
9089 constraint (!inst.operands[1].preind
9090 || inst.operands[1].shifted
9091 || inst.operands[1].writeback,
9092 _("Thumb does not support this addressing mode"));
9093 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
9094 {
9095 constraint (inst.instruction & 0x0600,
9096 _("byte or halfword not valid for base register"));
9097 constraint (inst.operands[1].reg == REG_PC
9098 && !(inst.instruction & THUMB_LOAD_BIT),
9099 _("r15 based store not allowed"));
9100 constraint (inst.operands[1].immisreg,
9101 _("invalid base register for register offset"));
9102
9103 if (inst.operands[1].reg == REG_PC)
9104 inst.instruction = T_OPCODE_LDR_PC;
9105 else if (inst.instruction & THUMB_LOAD_BIT)
9106 inst.instruction = T_OPCODE_LDR_SP;
9107 else
9108 inst.instruction = T_OPCODE_STR_SP;
9109
9110 inst.instruction |= inst.operands[0].reg << 8;
9111 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9112 return;
9113 }
9114
9115 constraint (inst.operands[1].reg > 7, BAD_HIREG);
9116 if (!inst.operands[1].immisreg)
9117 {
9118 /* Immediate offset. */
9119 inst.instruction |= inst.operands[0].reg;
9120 inst.instruction |= inst.operands[1].reg << 3;
9121 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9122 return;
9123 }
9124
9125 /* Register offset. */
9126 constraint (inst.operands[1].imm > 7, BAD_HIREG);
9127 constraint (inst.operands[1].negative,
9128 _("Thumb does not support this addressing mode"));
9129
9130 op16:
9131 switch (inst.instruction)
9132 {
9133 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
9134 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
9135 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
9136 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
9137 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
9138 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
9139 case 0x5600 /* ldrsb */:
9140 case 0x5e00 /* ldrsh */: break;
9141 default: abort ();
9142 }
9143
9144 inst.instruction |= inst.operands[0].reg;
9145 inst.instruction |= inst.operands[1].reg << 3;
9146 inst.instruction |= inst.operands[1].imm << 6;
9147 }
9148
9149 static void
9150 do_t_ldstd (void)
9151 {
9152 if (!inst.operands[1].present)
9153 {
9154 inst.operands[1].reg = inst.operands[0].reg + 1;
9155 constraint (inst.operands[0].reg == REG_LR,
9156 _("r14 not allowed here"));
9157 }
9158 inst.instruction |= inst.operands[0].reg << 12;
9159 inst.instruction |= inst.operands[1].reg << 8;
9160 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
9161
9162 }
9163
9164 static void
9165 do_t_ldstt (void)
9166 {
9167 inst.instruction |= inst.operands[0].reg << 12;
9168 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
9169 }
9170
9171 static void
9172 do_t_mla (void)
9173 {
9174 inst.instruction |= inst.operands[0].reg << 8;
9175 inst.instruction |= inst.operands[1].reg << 16;
9176 inst.instruction |= inst.operands[2].reg;
9177 inst.instruction |= inst.operands[3].reg << 12;
9178 }
9179
9180 static void
9181 do_t_mlal (void)
9182 {
9183 inst.instruction |= inst.operands[0].reg << 12;
9184 inst.instruction |= inst.operands[1].reg << 8;
9185 inst.instruction |= inst.operands[2].reg << 16;
9186 inst.instruction |= inst.operands[3].reg;
9187 }
9188
9189 static void
9190 do_t_mov_cmp (void)
9191 {
9192 if (unified_syntax)
9193 {
9194 int r0off = (inst.instruction == T_MNEM_mov
9195 || inst.instruction == T_MNEM_movs) ? 8 : 16;
9196 unsigned long opcode;
9197 bfd_boolean narrow;
9198 bfd_boolean low_regs;
9199
9200 low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7);
9201 opcode = inst.instruction;
9202 if (current_it_mask)
9203 narrow = opcode != T_MNEM_movs;
9204 else
9205 narrow = opcode != T_MNEM_movs || low_regs;
9206 if (inst.size_req == 4
9207 || inst.operands[1].shifted)
9208 narrow = FALSE;
9209
9210 if (!inst.operands[1].isreg)
9211 {
9212 /* Immediate operand. */
9213 if (current_it_mask == 0 && opcode == T_MNEM_mov)
9214 narrow = 0;
9215 if (low_regs && narrow)
9216 {
9217 inst.instruction = THUMB_OP16 (opcode);
9218 inst.instruction |= inst.operands[0].reg << 8;
9219 if (inst.size_req == 2)
9220 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9221 else
9222 inst.relax = opcode;
9223 }
9224 else
9225 {
9226 inst.instruction = THUMB_OP32 (inst.instruction);
9227 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9228 inst.instruction |= inst.operands[0].reg << r0off;
9229 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9230 }
9231 }
9232 else if (!narrow)
9233 {
9234 inst.instruction = THUMB_OP32 (inst.instruction);
9235 inst.instruction |= inst.operands[0].reg << r0off;
9236 encode_thumb32_shifted_operand (1);
9237 }
9238 else
9239 switch (inst.instruction)
9240 {
9241 case T_MNEM_mov:
9242 inst.instruction = T_OPCODE_MOV_HR;
9243 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9244 inst.instruction |= (inst.operands[0].reg & 0x7);
9245 inst.instruction |= inst.operands[1].reg << 3;
9246 break;
9247
9248 case T_MNEM_movs:
9249 /* We know we have low registers at this point.
9250 Generate ADD Rd, Rs, #0. */
9251 inst.instruction = T_OPCODE_ADD_I3;
9252 inst.instruction |= inst.operands[0].reg;
9253 inst.instruction |= inst.operands[1].reg << 3;
9254 break;
9255
9256 case T_MNEM_cmp:
9257 if (low_regs)
9258 {
9259 inst.instruction = T_OPCODE_CMP_LR;
9260 inst.instruction |= inst.operands[0].reg;
9261 inst.instruction |= inst.operands[1].reg << 3;
9262 }
9263 else
9264 {
9265 inst.instruction = T_OPCODE_CMP_HR;
9266 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9267 inst.instruction |= (inst.operands[0].reg & 0x7);
9268 inst.instruction |= inst.operands[1].reg << 3;
9269 }
9270 break;
9271 }
9272 return;
9273 }
9274
9275 inst.instruction = THUMB_OP16 (inst.instruction);
9276 if (inst.operands[1].isreg)
9277 {
9278 if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8)
9279 {
9280 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
9281 since a MOV instruction produces unpredictable results. */
9282 if (inst.instruction == T_OPCODE_MOV_I8)
9283 inst.instruction = T_OPCODE_ADD_I3;
9284 else
9285 inst.instruction = T_OPCODE_CMP_LR;
9286
9287 inst.instruction |= inst.operands[0].reg;
9288 inst.instruction |= inst.operands[1].reg << 3;
9289 }
9290 else
9291 {
9292 if (inst.instruction == T_OPCODE_MOV_I8)
9293 inst.instruction = T_OPCODE_MOV_HR;
9294 else
9295 inst.instruction = T_OPCODE_CMP_HR;
9296 do_t_cpy ();
9297 }
9298 }
9299 else
9300 {
9301 constraint (inst.operands[0].reg > 7,
9302 _("only lo regs allowed with immediate"));
9303 inst.instruction |= inst.operands[0].reg << 8;
9304 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9305 }
9306 }
9307
9308 static void
9309 do_t_mov16 (void)
9310 {
9311 bfd_vma imm;
9312 bfd_boolean top;
9313
9314 top = (inst.instruction & 0x00800000) != 0;
9315 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
9316 {
9317 constraint (top, _(":lower16: not allowed this instruction"));
9318 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
9319 }
9320 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
9321 {
9322 constraint (!top, _(":upper16: not allowed this instruction"));
9323 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
9324 }
9325
9326 inst.instruction |= inst.operands[0].reg << 8;
9327 if (inst.reloc.type == BFD_RELOC_UNUSED)
9328 {
9329 imm = inst.reloc.exp.X_add_number;
9330 inst.instruction |= (imm & 0xf000) << 4;
9331 inst.instruction |= (imm & 0x0800) << 15;
9332 inst.instruction |= (imm & 0x0700) << 4;
9333 inst.instruction |= (imm & 0x00ff);
9334 }
9335 }
9336
9337 static void
9338 do_t_mvn_tst (void)
9339 {
9340 if (unified_syntax)
9341 {
9342 int r0off = (inst.instruction == T_MNEM_mvn
9343 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
9344 bfd_boolean narrow;
9345
9346 if (inst.size_req == 4
9347 || inst.instruction > 0xffff
9348 || inst.operands[1].shifted
9349 || inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9350 narrow = FALSE;
9351 else if (inst.instruction == T_MNEM_cmn)
9352 narrow = TRUE;
9353 else if (THUMB_SETS_FLAGS (inst.instruction))
9354 narrow = (current_it_mask == 0);
9355 else
9356 narrow = (current_it_mask != 0);
9357
9358 if (!inst.operands[1].isreg)
9359 {
9360 /* For an immediate, we always generate a 32-bit opcode;
9361 section relaxation will shrink it later if possible. */
9362 if (inst.instruction < 0xffff)
9363 inst.instruction = THUMB_OP32 (inst.instruction);
9364 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9365 inst.instruction |= inst.operands[0].reg << r0off;
9366 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9367 }
9368 else
9369 {
9370 /* See if we can do this with a 16-bit instruction. */
9371 if (narrow)
9372 {
9373 inst.instruction = THUMB_OP16 (inst.instruction);
9374 inst.instruction |= inst.operands[0].reg;
9375 inst.instruction |= inst.operands[1].reg << 3;
9376 }
9377 else
9378 {
9379 constraint (inst.operands[1].shifted
9380 && inst.operands[1].immisreg,
9381 _("shift must be constant"));
9382 if (inst.instruction < 0xffff)
9383 inst.instruction = THUMB_OP32 (inst.instruction);
9384 inst.instruction |= inst.operands[0].reg << r0off;
9385 encode_thumb32_shifted_operand (1);
9386 }
9387 }
9388 }
9389 else
9390 {
9391 constraint (inst.instruction > 0xffff
9392 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
9393 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
9394 _("unshifted register required"));
9395 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9396 BAD_HIREG);
9397
9398 inst.instruction = THUMB_OP16 (inst.instruction);
9399 inst.instruction |= inst.operands[0].reg;
9400 inst.instruction |= inst.operands[1].reg << 3;
9401 }
9402 }
9403
9404 static void
9405 do_t_mrs (void)
9406 {
9407 int flags;
9408
9409 if (do_vfp_nsyn_mrs () == SUCCESS)
9410 return;
9411
9412 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
9413 if (flags == 0)
9414 {
9415 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m),
9416 _("selected processor does not support "
9417 "requested special purpose register"));
9418 }
9419 else
9420 {
9421 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9422 _("selected processor does not support "
9423 "requested special purpose register %x"));
9424 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9425 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
9426 _("'CPSR' or 'SPSR' expected"));
9427 }
9428
9429 inst.instruction |= inst.operands[0].reg << 8;
9430 inst.instruction |= (flags & SPSR_BIT) >> 2;
9431 inst.instruction |= inst.operands[1].imm & 0xff;
9432 }
9433
9434 static void
9435 do_t_msr (void)
9436 {
9437 int flags;
9438
9439 if (do_vfp_nsyn_msr () == SUCCESS)
9440 return;
9441
9442 constraint (!inst.operands[1].isreg,
9443 _("Thumb encoding does not support an immediate here"));
9444 flags = inst.operands[0].imm;
9445 if (flags & ~0xff)
9446 {
9447 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9448 _("selected processor does not support "
9449 "requested special purpose register"));
9450 }
9451 else
9452 {
9453 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m),
9454 _("selected processor does not support "
9455 "requested special purpose register"));
9456 flags |= PSR_f;
9457 }
9458 inst.instruction |= (flags & SPSR_BIT) >> 2;
9459 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
9460 inst.instruction |= (flags & 0xff);
9461 inst.instruction |= inst.operands[1].reg << 16;
9462 }
9463
9464 static void
9465 do_t_mul (void)
9466 {
9467 if (!inst.operands[2].present)
9468 inst.operands[2].reg = inst.operands[0].reg;
9469
9470 /* There is no 32-bit MULS and no 16-bit MUL. */
9471 if (unified_syntax && inst.instruction == T_MNEM_mul)
9472 {
9473 inst.instruction = THUMB_OP32 (inst.instruction);
9474 inst.instruction |= inst.operands[0].reg << 8;
9475 inst.instruction |= inst.operands[1].reg << 16;
9476 inst.instruction |= inst.operands[2].reg << 0;
9477 }
9478 else
9479 {
9480 constraint (!unified_syntax
9481 && inst.instruction == T_MNEM_muls, BAD_THUMB32);
9482 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9483 BAD_HIREG);
9484
9485 inst.instruction = THUMB_OP16 (inst.instruction);
9486 inst.instruction |= inst.operands[0].reg;
9487
9488 if (inst.operands[0].reg == inst.operands[1].reg)
9489 inst.instruction |= inst.operands[2].reg << 3;
9490 else if (inst.operands[0].reg == inst.operands[2].reg)
9491 inst.instruction |= inst.operands[1].reg << 3;
9492 else
9493 constraint (1, _("dest must overlap one source register"));
9494 }
9495 }
9496
9497 static void
9498 do_t_mull (void)
9499 {
9500 inst.instruction |= inst.operands[0].reg << 12;
9501 inst.instruction |= inst.operands[1].reg << 8;
9502 inst.instruction |= inst.operands[2].reg << 16;
9503 inst.instruction |= inst.operands[3].reg;
9504
9505 if (inst.operands[0].reg == inst.operands[1].reg)
9506 as_tsktsk (_("rdhi and rdlo must be different"));
9507 }
9508
9509 static void
9510 do_t_nop (void)
9511 {
9512 if (unified_syntax)
9513 {
9514 if (inst.size_req == 4 || inst.operands[0].imm > 15)
9515 {
9516 inst.instruction = THUMB_OP32 (inst.instruction);
9517 inst.instruction |= inst.operands[0].imm;
9518 }
9519 else
9520 {
9521 inst.instruction = THUMB_OP16 (inst.instruction);
9522 inst.instruction |= inst.operands[0].imm << 4;
9523 }
9524 }
9525 else
9526 {
9527 constraint (inst.operands[0].present,
9528 _("Thumb does not support NOP with hints"));
9529 inst.instruction = 0x46c0;
9530 }
9531 }
9532
9533 static void
9534 do_t_neg (void)
9535 {
9536 if (unified_syntax)
9537 {
9538 bfd_boolean narrow;
9539
9540 if (THUMB_SETS_FLAGS (inst.instruction))
9541 narrow = (current_it_mask == 0);
9542 else
9543 narrow = (current_it_mask != 0);
9544 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9545 narrow = FALSE;
9546 if (inst.size_req == 4)
9547 narrow = FALSE;
9548
9549 if (!narrow)
9550 {
9551 inst.instruction = THUMB_OP32 (inst.instruction);
9552 inst.instruction |= inst.operands[0].reg << 8;
9553 inst.instruction |= inst.operands[1].reg << 16;
9554 }
9555 else
9556 {
9557 inst.instruction = THUMB_OP16 (inst.instruction);
9558 inst.instruction |= inst.operands[0].reg;
9559 inst.instruction |= inst.operands[1].reg << 3;
9560 }
9561 }
9562 else
9563 {
9564 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9565 BAD_HIREG);
9566 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9567
9568 inst.instruction = THUMB_OP16 (inst.instruction);
9569 inst.instruction |= inst.operands[0].reg;
9570 inst.instruction |= inst.operands[1].reg << 3;
9571 }
9572 }
9573
9574 static void
9575 do_t_pkhbt (void)
9576 {
9577 inst.instruction |= inst.operands[0].reg << 8;
9578 inst.instruction |= inst.operands[1].reg << 16;
9579 inst.instruction |= inst.operands[2].reg;
9580 if (inst.operands[3].present)
9581 {
9582 unsigned int val = inst.reloc.exp.X_add_number;
9583 constraint (inst.reloc.exp.X_op != O_constant,
9584 _("expression too complex"));
9585 inst.instruction |= (val & 0x1c) << 10;
9586 inst.instruction |= (val & 0x03) << 6;
9587 }
9588 }
9589
9590 static void
9591 do_t_pkhtb (void)
9592 {
9593 if (!inst.operands[3].present)
9594 inst.instruction &= ~0x00000020;
9595 do_t_pkhbt ();
9596 }
9597
9598 static void
9599 do_t_pld (void)
9600 {
9601 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
9602 }
9603
9604 static void
9605 do_t_push_pop (void)
9606 {
9607 unsigned mask;
9608
9609 constraint (inst.operands[0].writeback,
9610 _("push/pop do not support {reglist}^"));
9611 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9612 _("expression too complex"));
9613
9614 mask = inst.operands[0].imm;
9615 if ((mask & ~0xff) == 0)
9616 inst.instruction = THUMB_OP16 (inst.instruction);
9617 else if ((inst.instruction == T_MNEM_push
9618 && (mask & ~0xff) == 1 << REG_LR)
9619 || (inst.instruction == T_MNEM_pop
9620 && (mask & ~0xff) == 1 << REG_PC))
9621 {
9622 inst.instruction = THUMB_OP16 (inst.instruction);
9623 inst.instruction |= THUMB_PP_PC_LR;
9624 mask &= 0xff;
9625 }
9626 else if (unified_syntax)
9627 {
9628 if (mask & (1 << 13))
9629 inst.error = _("SP not allowed in register list");
9630 if (inst.instruction == T_MNEM_push)
9631 {
9632 if (mask & (1 << 15))
9633 inst.error = _("PC not allowed in register list");
9634 }
9635 else
9636 {
9637 if (mask & (1 << 14)
9638 && mask & (1 << 15))
9639 inst.error = _("LR and PC should not both be in register list");
9640 }
9641 if ((mask & (mask - 1)) == 0)
9642 {
9643 /* Single register push/pop implemented as str/ldr. */
9644 if (inst.instruction == T_MNEM_push)
9645 inst.instruction = 0xf84d0d04; /* str reg, [sp, #-4]! */
9646 else
9647 inst.instruction = 0xf85d0b04; /* ldr reg, [sp], #4 */
9648 mask = ffs(mask) - 1;
9649 mask <<= 12;
9650 }
9651 else
9652 inst.instruction = THUMB_OP32 (inst.instruction);
9653 }
9654 else
9655 {
9656 inst.error = _("invalid register list to push/pop instruction");
9657 return;
9658 }
9659
9660 inst.instruction |= mask;
9661 }
9662
9663 static void
9664 do_t_rbit (void)
9665 {
9666 inst.instruction |= inst.operands[0].reg << 8;
9667 inst.instruction |= inst.operands[1].reg << 16;
9668 }
9669
9670 static void
9671 do_t_rev (void)
9672 {
9673 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
9674 && inst.size_req != 4)
9675 {
9676 inst.instruction = THUMB_OP16 (inst.instruction);
9677 inst.instruction |= inst.operands[0].reg;
9678 inst.instruction |= inst.operands[1].reg << 3;
9679 }
9680 else if (unified_syntax)
9681 {
9682 inst.instruction = THUMB_OP32 (inst.instruction);
9683 inst.instruction |= inst.operands[0].reg << 8;
9684 inst.instruction |= inst.operands[1].reg << 16;
9685 inst.instruction |= inst.operands[1].reg;
9686 }
9687 else
9688 inst.error = BAD_HIREG;
9689 }
9690
9691 static void
9692 do_t_rsb (void)
9693 {
9694 int Rd, Rs;
9695
9696 Rd = inst.operands[0].reg;
9697 Rs = (inst.operands[1].present
9698 ? inst.operands[1].reg /* Rd, Rs, foo */
9699 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9700
9701 inst.instruction |= Rd << 8;
9702 inst.instruction |= Rs << 16;
9703 if (!inst.operands[2].isreg)
9704 {
9705 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9706 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9707 }
9708 else
9709 encode_thumb32_shifted_operand (2);
9710 }
9711
9712 static void
9713 do_t_setend (void)
9714 {
9715 constraint (current_it_mask, BAD_NOT_IT);
9716 if (inst.operands[0].imm)
9717 inst.instruction |= 0x8;
9718 }
9719
9720 static void
9721 do_t_shift (void)
9722 {
9723 if (!inst.operands[1].present)
9724 inst.operands[1].reg = inst.operands[0].reg;
9725
9726 if (unified_syntax)
9727 {
9728 bfd_boolean narrow;
9729 int shift_kind;
9730
9731 switch (inst.instruction)
9732 {
9733 case T_MNEM_asr:
9734 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
9735 case T_MNEM_lsl:
9736 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
9737 case T_MNEM_lsr:
9738 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
9739 case T_MNEM_ror:
9740 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
9741 default: abort ();
9742 }
9743
9744 if (THUMB_SETS_FLAGS (inst.instruction))
9745 narrow = (current_it_mask == 0);
9746 else
9747 narrow = (current_it_mask != 0);
9748 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9749 narrow = FALSE;
9750 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
9751 narrow = FALSE;
9752 if (inst.operands[2].isreg
9753 && (inst.operands[1].reg != inst.operands[0].reg
9754 || inst.operands[2].reg > 7))
9755 narrow = FALSE;
9756 if (inst.size_req == 4)
9757 narrow = FALSE;
9758
9759 if (!narrow)
9760 {
9761 if (inst.operands[2].isreg)
9762 {
9763 inst.instruction = THUMB_OP32 (inst.instruction);
9764 inst.instruction |= inst.operands[0].reg << 8;
9765 inst.instruction |= inst.operands[1].reg << 16;
9766 inst.instruction |= inst.operands[2].reg;
9767 }
9768 else
9769 {
9770 inst.operands[1].shifted = 1;
9771 inst.operands[1].shift_kind = shift_kind;
9772 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
9773 ? T_MNEM_movs : T_MNEM_mov);
9774 inst.instruction |= inst.operands[0].reg << 8;
9775 encode_thumb32_shifted_operand (1);
9776 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
9777 inst.reloc.type = BFD_RELOC_UNUSED;
9778 }
9779 }
9780 else
9781 {
9782 if (inst.operands[2].isreg)
9783 {
9784 switch (shift_kind)
9785 {
9786 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
9787 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
9788 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
9789 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
9790 default: abort ();
9791 }
9792
9793 inst.instruction |= inst.operands[0].reg;
9794 inst.instruction |= inst.operands[2].reg << 3;
9795 }
9796 else
9797 {
9798 switch (shift_kind)
9799 {
9800 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
9801 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
9802 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
9803 default: abort ();
9804 }
9805 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
9806 inst.instruction |= inst.operands[0].reg;
9807 inst.instruction |= inst.operands[1].reg << 3;
9808 }
9809 }
9810 }
9811 else
9812 {
9813 constraint (inst.operands[0].reg > 7
9814 || inst.operands[1].reg > 7, BAD_HIREG);
9815 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9816
9817 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
9818 {
9819 constraint (inst.operands[2].reg > 7, BAD_HIREG);
9820 constraint (inst.operands[0].reg != inst.operands[1].reg,
9821 _("source1 and dest must be same register"));
9822
9823 switch (inst.instruction)
9824 {
9825 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
9826 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
9827 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
9828 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
9829 default: abort ();
9830 }
9831
9832 inst.instruction |= inst.operands[0].reg;
9833 inst.instruction |= inst.operands[2].reg << 3;
9834 }
9835 else
9836 {
9837 switch (inst.instruction)
9838 {
9839 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
9840 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
9841 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
9842 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
9843 default: abort ();
9844 }
9845 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
9846 inst.instruction |= inst.operands[0].reg;
9847 inst.instruction |= inst.operands[1].reg << 3;
9848 }
9849 }
9850 }
9851
9852 static void
9853 do_t_simd (void)
9854 {
9855 inst.instruction |= inst.operands[0].reg << 8;
9856 inst.instruction |= inst.operands[1].reg << 16;
9857 inst.instruction |= inst.operands[2].reg;
9858 }
9859
9860 static void
9861 do_t_smc (void)
9862 {
9863 unsigned int value = inst.reloc.exp.X_add_number;
9864 constraint (inst.reloc.exp.X_op != O_constant,
9865 _("expression too complex"));
9866 inst.reloc.type = BFD_RELOC_UNUSED;
9867 inst.instruction |= (value & 0xf000) >> 12;
9868 inst.instruction |= (value & 0x0ff0);
9869 inst.instruction |= (value & 0x000f) << 16;
9870 }
9871
9872 static void
9873 do_t_ssat (void)
9874 {
9875 inst.instruction |= inst.operands[0].reg << 8;
9876 inst.instruction |= inst.operands[1].imm - 1;
9877 inst.instruction |= inst.operands[2].reg << 16;
9878
9879 if (inst.operands[3].present)
9880 {
9881 constraint (inst.reloc.exp.X_op != O_constant,
9882 _("expression too complex"));
9883
9884 if (inst.reloc.exp.X_add_number != 0)
9885 {
9886 if (inst.operands[3].shift_kind == SHIFT_ASR)
9887 inst.instruction |= 0x00200000; /* sh bit */
9888 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
9889 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
9890 }
9891 inst.reloc.type = BFD_RELOC_UNUSED;
9892 }
9893 }
9894
9895 static void
9896 do_t_ssat16 (void)
9897 {
9898 inst.instruction |= inst.operands[0].reg << 8;
9899 inst.instruction |= inst.operands[1].imm - 1;
9900 inst.instruction |= inst.operands[2].reg << 16;
9901 }
9902
9903 static void
9904 do_t_strex (void)
9905 {
9906 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9907 || inst.operands[2].postind || inst.operands[2].writeback
9908 || inst.operands[2].immisreg || inst.operands[2].shifted
9909 || inst.operands[2].negative,
9910 BAD_ADDR_MODE);
9911
9912 inst.instruction |= inst.operands[0].reg << 8;
9913 inst.instruction |= inst.operands[1].reg << 12;
9914 inst.instruction |= inst.operands[2].reg << 16;
9915 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9916 }
9917
9918 static void
9919 do_t_strexd (void)
9920 {
9921 if (!inst.operands[2].present)
9922 inst.operands[2].reg = inst.operands[1].reg + 1;
9923
9924 constraint (inst.operands[0].reg == inst.operands[1].reg
9925 || inst.operands[0].reg == inst.operands[2].reg
9926 || inst.operands[0].reg == inst.operands[3].reg
9927 || inst.operands[1].reg == inst.operands[2].reg,
9928 BAD_OVERLAP);
9929
9930 inst.instruction |= inst.operands[0].reg;
9931 inst.instruction |= inst.operands[1].reg << 12;
9932 inst.instruction |= inst.operands[2].reg << 8;
9933 inst.instruction |= inst.operands[3].reg << 16;
9934 }
9935
9936 static void
9937 do_t_sxtah (void)
9938 {
9939 inst.instruction |= inst.operands[0].reg << 8;
9940 inst.instruction |= inst.operands[1].reg << 16;
9941 inst.instruction |= inst.operands[2].reg;
9942 inst.instruction |= inst.operands[3].imm << 4;
9943 }
9944
9945 static void
9946 do_t_sxth (void)
9947 {
9948 if (inst.instruction <= 0xffff && inst.size_req != 4
9949 && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
9950 && (!inst.operands[2].present || inst.operands[2].imm == 0))
9951 {
9952 inst.instruction = THUMB_OP16 (inst.instruction);
9953 inst.instruction |= inst.operands[0].reg;
9954 inst.instruction |= inst.operands[1].reg << 3;
9955 }
9956 else if (unified_syntax)
9957 {
9958 if (inst.instruction <= 0xffff)
9959 inst.instruction = THUMB_OP32 (inst.instruction);
9960 inst.instruction |= inst.operands[0].reg << 8;
9961 inst.instruction |= inst.operands[1].reg;
9962 inst.instruction |= inst.operands[2].imm << 4;
9963 }
9964 else
9965 {
9966 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
9967 _("Thumb encoding does not support rotation"));
9968 constraint (1, BAD_HIREG);
9969 }
9970 }
9971
9972 static void
9973 do_t_swi (void)
9974 {
9975 inst.reloc.type = BFD_RELOC_ARM_SWI;
9976 }
9977
9978 static void
9979 do_t_tb (void)
9980 {
9981 int half;
9982
9983 half = (inst.instruction & 0x10) != 0;
9984 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
9985 constraint (inst.operands[0].immisreg,
9986 _("instruction requires register index"));
9987 constraint (inst.operands[0].imm == 15,
9988 _("PC is not a valid index register"));
9989 constraint (!half && inst.operands[0].shifted,
9990 _("instruction does not allow shifted index"));
9991 inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm;
9992 }
9993
9994 static void
9995 do_t_usat (void)
9996 {
9997 inst.instruction |= inst.operands[0].reg << 8;
9998 inst.instruction |= inst.operands[1].imm;
9999 inst.instruction |= inst.operands[2].reg << 16;
10000
10001 if (inst.operands[3].present)
10002 {
10003 constraint (inst.reloc.exp.X_op != O_constant,
10004 _("expression too complex"));
10005 if (inst.reloc.exp.X_add_number != 0)
10006 {
10007 if (inst.operands[3].shift_kind == SHIFT_ASR)
10008 inst.instruction |= 0x00200000; /* sh bit */
10009
10010 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10011 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10012 }
10013 inst.reloc.type = BFD_RELOC_UNUSED;
10014 }
10015 }
10016
10017 static void
10018 do_t_usat16 (void)
10019 {
10020 inst.instruction |= inst.operands[0].reg << 8;
10021 inst.instruction |= inst.operands[1].imm;
10022 inst.instruction |= inst.operands[2].reg << 16;
10023 }
10024
10025 /* Neon instruction encoder helpers. */
10026
10027 /* Encodings for the different types for various Neon opcodes. */
10028
10029 /* An "invalid" code for the following tables. */
10030 #define N_INV -1u
10031
10032 struct neon_tab_entry
10033 {
10034 unsigned integer;
10035 unsigned float_or_poly;
10036 unsigned scalar_or_imm;
10037 };
10038
10039 /* Map overloaded Neon opcodes to their respective encodings. */
10040 #define NEON_ENC_TAB \
10041 X(vabd, 0x0000700, 0x1200d00, N_INV), \
10042 X(vmax, 0x0000600, 0x0000f00, N_INV), \
10043 X(vmin, 0x0000610, 0x0200f00, N_INV), \
10044 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
10045 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
10046 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
10047 X(vadd, 0x0000800, 0x0000d00, N_INV), \
10048 X(vsub, 0x1000800, 0x0200d00, N_INV), \
10049 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
10050 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
10051 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
10052 /* Register variants of the following two instructions are encoded as
10053 vcge / vcgt with the operands reversed. */ \
10054 X(vclt, 0x0000310, 0x1000e00, 0x1b10200), \
10055 X(vcle, 0x0000300, 0x1200e00, 0x1b10180), \
10056 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
10057 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
10058 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
10059 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
10060 X(vmlal, 0x0800800, N_INV, 0x0800240), \
10061 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
10062 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
10063 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
10064 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
10065 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
10066 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
10067 X(vshl, 0x0000400, N_INV, 0x0800510), \
10068 X(vqshl, 0x0000410, N_INV, 0x0800710), \
10069 X(vand, 0x0000110, N_INV, 0x0800030), \
10070 X(vbic, 0x0100110, N_INV, 0x0800030), \
10071 X(veor, 0x1000110, N_INV, N_INV), \
10072 X(vorn, 0x0300110, N_INV, 0x0800010), \
10073 X(vorr, 0x0200110, N_INV, 0x0800010), \
10074 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
10075 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
10076 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
10077 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
10078 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
10079 X(vst1, 0x0000000, 0x0800000, N_INV), \
10080 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
10081 X(vst2, 0x0000100, 0x0800100, N_INV), \
10082 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
10083 X(vst3, 0x0000200, 0x0800200, N_INV), \
10084 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
10085 X(vst4, 0x0000300, 0x0800300, N_INV), \
10086 X(vmovn, 0x1b20200, N_INV, N_INV), \
10087 X(vtrn, 0x1b20080, N_INV, N_INV), \
10088 X(vqmovn, 0x1b20200, N_INV, N_INV), \
10089 X(vqmovun, 0x1b20240, N_INV, N_INV), \
10090 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
10091 X(vnmla, 0xe000a40, 0xe000b40, N_INV), \
10092 X(vnmls, 0xe100a40, 0xe100b40, N_INV), \
10093 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
10094 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
10095 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
10096 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
10097
10098 enum neon_opc
10099 {
10100 #define X(OPC,I,F,S) N_MNEM_##OPC
10101 NEON_ENC_TAB
10102 #undef X
10103 };
10104
10105 static const struct neon_tab_entry neon_enc_tab[] =
10106 {
10107 #define X(OPC,I,F,S) { (I), (F), (S) }
10108 NEON_ENC_TAB
10109 #undef X
10110 };
10111
10112 #define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10113 #define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10114 #define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10115 #define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10116 #define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10117 #define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10118 #define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10119 #define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10120 #define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10121 #define NEON_ENC_SINGLE(X) \
10122 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
10123 #define NEON_ENC_DOUBLE(X) \
10124 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
10125
10126 /* Define shapes for instruction operands. The following mnemonic characters
10127 are used in this table:
10128
10129 F - VFP S<n> register
10130 D - Neon D<n> register
10131 Q - Neon Q<n> register
10132 I - Immediate
10133 S - Scalar
10134 R - ARM register
10135 L - D<n> register list
10136
10137 This table is used to generate various data:
10138 - enumerations of the form NS_DDR to be used as arguments to
10139 neon_select_shape.
10140 - a table classifying shapes into single, double, quad, mixed.
10141 - a table used to drive neon_select_shape.
10142 */
10143
10144 #define NEON_SHAPE_DEF \
10145 X(3, (D, D, D), DOUBLE), \
10146 X(3, (Q, Q, Q), QUAD), \
10147 X(3, (D, D, I), DOUBLE), \
10148 X(3, (Q, Q, I), QUAD), \
10149 X(3, (D, D, S), DOUBLE), \
10150 X(3, (Q, Q, S), QUAD), \
10151 X(2, (D, D), DOUBLE), \
10152 X(2, (Q, Q), QUAD), \
10153 X(2, (D, S), DOUBLE), \
10154 X(2, (Q, S), QUAD), \
10155 X(2, (D, R), DOUBLE), \
10156 X(2, (Q, R), QUAD), \
10157 X(2, (D, I), DOUBLE), \
10158 X(2, (Q, I), QUAD), \
10159 X(3, (D, L, D), DOUBLE), \
10160 X(2, (D, Q), MIXED), \
10161 X(2, (Q, D), MIXED), \
10162 X(3, (D, Q, I), MIXED), \
10163 X(3, (Q, D, I), MIXED), \
10164 X(3, (Q, D, D), MIXED), \
10165 X(3, (D, Q, Q), MIXED), \
10166 X(3, (Q, Q, D), MIXED), \
10167 X(3, (Q, D, S), MIXED), \
10168 X(3, (D, Q, S), MIXED), \
10169 X(4, (D, D, D, I), DOUBLE), \
10170 X(4, (Q, Q, Q, I), QUAD), \
10171 X(2, (F, F), SINGLE), \
10172 X(3, (F, F, F), SINGLE), \
10173 X(2, (F, I), SINGLE), \
10174 X(2, (F, D), MIXED), \
10175 X(2, (D, F), MIXED), \
10176 X(3, (F, F, I), MIXED), \
10177 X(4, (R, R, F, F), SINGLE), \
10178 X(4, (F, F, R, R), SINGLE), \
10179 X(3, (D, R, R), DOUBLE), \
10180 X(3, (R, R, D), DOUBLE), \
10181 X(2, (S, R), SINGLE), \
10182 X(2, (R, S), SINGLE), \
10183 X(2, (F, R), SINGLE), \
10184 X(2, (R, F), SINGLE)
10185
10186 #define S2(A,B) NS_##A##B
10187 #define S3(A,B,C) NS_##A##B##C
10188 #define S4(A,B,C,D) NS_##A##B##C##D
10189
10190 #define X(N, L, C) S##N L
10191
10192 enum neon_shape
10193 {
10194 NEON_SHAPE_DEF,
10195 NS_NULL
10196 };
10197
10198 #undef X
10199 #undef S2
10200 #undef S3
10201 #undef S4
10202
10203 enum neon_shape_class
10204 {
10205 SC_SINGLE,
10206 SC_DOUBLE,
10207 SC_QUAD,
10208 SC_MIXED
10209 };
10210
10211 #define X(N, L, C) SC_##C
10212
10213 static enum neon_shape_class neon_shape_class[] =
10214 {
10215 NEON_SHAPE_DEF
10216 };
10217
10218 #undef X
10219
10220 enum neon_shape_el
10221 {
10222 SE_F,
10223 SE_D,
10224 SE_Q,
10225 SE_I,
10226 SE_S,
10227 SE_R,
10228 SE_L
10229 };
10230
10231 /* Register widths of above. */
10232 static unsigned neon_shape_el_size[] =
10233 {
10234 32,
10235 64,
10236 128,
10237 0,
10238 32,
10239 32,
10240 0
10241 };
10242
10243 struct neon_shape_info
10244 {
10245 unsigned els;
10246 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
10247 };
10248
10249 #define S2(A,B) { SE_##A, SE_##B }
10250 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
10251 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
10252
10253 #define X(N, L, C) { N, S##N L }
10254
10255 static struct neon_shape_info neon_shape_tab[] =
10256 {
10257 NEON_SHAPE_DEF
10258 };
10259
10260 #undef X
10261 #undef S2
10262 #undef S3
10263 #undef S4
10264
10265 /* Bit masks used in type checking given instructions.
10266 'N_EQK' means the type must be the same as (or based on in some way) the key
10267 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
10268 set, various other bits can be set as well in order to modify the meaning of
10269 the type constraint. */
10270
10271 enum neon_type_mask
10272 {
10273 N_S8 = 0x000001,
10274 N_S16 = 0x000002,
10275 N_S32 = 0x000004,
10276 N_S64 = 0x000008,
10277 N_U8 = 0x000010,
10278 N_U16 = 0x000020,
10279 N_U32 = 0x000040,
10280 N_U64 = 0x000080,
10281 N_I8 = 0x000100,
10282 N_I16 = 0x000200,
10283 N_I32 = 0x000400,
10284 N_I64 = 0x000800,
10285 N_8 = 0x001000,
10286 N_16 = 0x002000,
10287 N_32 = 0x004000,
10288 N_64 = 0x008000,
10289 N_P8 = 0x010000,
10290 N_P16 = 0x020000,
10291 N_F32 = 0x040000,
10292 N_F64 = 0x080000,
10293 N_KEY = 0x100000, /* key element (main type specifier). */
10294 N_EQK = 0x200000, /* given operand has the same type & size as the key. */
10295 N_VFP = 0x400000, /* VFP mode: operand size must match register width. */
10296 N_DBL = 0x000001, /* if N_EQK, this operand is twice the size. */
10297 N_HLF = 0x000002, /* if N_EQK, this operand is half the size. */
10298 N_SGN = 0x000004, /* if N_EQK, this operand is forced to be signed. */
10299 N_UNS = 0x000008, /* if N_EQK, this operand is forced to be unsigned. */
10300 N_INT = 0x000010, /* if N_EQK, this operand is forced to be integer. */
10301 N_FLT = 0x000020, /* if N_EQK, this operand is forced to be float. */
10302 N_SIZ = 0x000040, /* if N_EQK, this operand is forced to be size-only. */
10303 N_UTYP = 0,
10304 N_MAX_NONSPECIAL = N_F64
10305 };
10306
10307 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
10308
10309 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
10310 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
10311 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
10312 #define N_SUF_32 (N_SU_32 | N_F32)
10313 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
10314 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
10315
10316 /* Pass this as the first type argument to neon_check_type to ignore types
10317 altogether. */
10318 #define N_IGNORE_TYPE (N_KEY | N_EQK)
10319
10320 /* Select a "shape" for the current instruction (describing register types or
10321 sizes) from a list of alternatives. Return NS_NULL if the current instruction
10322 doesn't fit. For non-polymorphic shapes, checking is usually done as a
10323 function of operand parsing, so this function doesn't need to be called.
10324 Shapes should be listed in order of decreasing length. */
10325
10326 static enum neon_shape
10327 neon_select_shape (enum neon_shape shape, ...)
10328 {
10329 va_list ap;
10330 enum neon_shape first_shape = shape;
10331
10332 /* Fix missing optional operands. FIXME: we don't know at this point how
10333 many arguments we should have, so this makes the assumption that we have
10334 > 1. This is true of all current Neon opcodes, I think, but may not be
10335 true in the future. */
10336 if (!inst.operands[1].present)
10337 inst.operands[1] = inst.operands[0];
10338
10339 va_start (ap, shape);
10340
10341 for (; shape != NS_NULL; shape = va_arg (ap, int))
10342 {
10343 unsigned j;
10344 int matches = 1;
10345
10346 for (j = 0; j < neon_shape_tab[shape].els; j++)
10347 {
10348 if (!inst.operands[j].present)
10349 {
10350 matches = 0;
10351 break;
10352 }
10353
10354 switch (neon_shape_tab[shape].el[j])
10355 {
10356 case SE_F:
10357 if (!(inst.operands[j].isreg
10358 && inst.operands[j].isvec
10359 && inst.operands[j].issingle
10360 && !inst.operands[j].isquad))
10361 matches = 0;
10362 break;
10363
10364 case SE_D:
10365 if (!(inst.operands[j].isreg
10366 && inst.operands[j].isvec
10367 && !inst.operands[j].isquad
10368 && !inst.operands[j].issingle))
10369 matches = 0;
10370 break;
10371
10372 case SE_R:
10373 if (!(inst.operands[j].isreg
10374 && !inst.operands[j].isvec))
10375 matches = 0;
10376 break;
10377
10378 case SE_Q:
10379 if (!(inst.operands[j].isreg
10380 && inst.operands[j].isvec
10381 && inst.operands[j].isquad
10382 && !inst.operands[j].issingle))
10383 matches = 0;
10384 break;
10385
10386 case SE_I:
10387 if (!(!inst.operands[j].isreg
10388 && !inst.operands[j].isscalar))
10389 matches = 0;
10390 break;
10391
10392 case SE_S:
10393 if (!(!inst.operands[j].isreg
10394 && inst.operands[j].isscalar))
10395 matches = 0;
10396 break;
10397
10398 case SE_L:
10399 break;
10400 }
10401 }
10402 if (matches)
10403 break;
10404 }
10405
10406 va_end (ap);
10407
10408 if (shape == NS_NULL && first_shape != NS_NULL)
10409 first_error (_("invalid instruction shape"));
10410
10411 return shape;
10412 }
10413
10414 /* True if SHAPE is predominantly a quadword operation (most of the time, this
10415 means the Q bit should be set). */
10416
10417 static int
10418 neon_quad (enum neon_shape shape)
10419 {
10420 return neon_shape_class[shape] == SC_QUAD;
10421 }
10422
10423 static void
10424 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
10425 unsigned *g_size)
10426 {
10427 /* Allow modification to be made to types which are constrained to be
10428 based on the key element, based on bits set alongside N_EQK. */
10429 if ((typebits & N_EQK) != 0)
10430 {
10431 if ((typebits & N_HLF) != 0)
10432 *g_size /= 2;
10433 else if ((typebits & N_DBL) != 0)
10434 *g_size *= 2;
10435 if ((typebits & N_SGN) != 0)
10436 *g_type = NT_signed;
10437 else if ((typebits & N_UNS) != 0)
10438 *g_type = NT_unsigned;
10439 else if ((typebits & N_INT) != 0)
10440 *g_type = NT_integer;
10441 else if ((typebits & N_FLT) != 0)
10442 *g_type = NT_float;
10443 else if ((typebits & N_SIZ) != 0)
10444 *g_type = NT_untyped;
10445 }
10446 }
10447
10448 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
10449 operand type, i.e. the single type specified in a Neon instruction when it
10450 is the only one given. */
10451
10452 static struct neon_type_el
10453 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
10454 {
10455 struct neon_type_el dest = *key;
10456
10457 assert ((thisarg & N_EQK) != 0);
10458
10459 neon_modify_type_size (thisarg, &dest.type, &dest.size);
10460
10461 return dest;
10462 }
10463
10464 /* Convert Neon type and size into compact bitmask representation. */
10465
10466 static enum neon_type_mask
10467 type_chk_of_el_type (enum neon_el_type type, unsigned size)
10468 {
10469 switch (type)
10470 {
10471 case NT_untyped:
10472 switch (size)
10473 {
10474 case 8: return N_8;
10475 case 16: return N_16;
10476 case 32: return N_32;
10477 case 64: return N_64;
10478 default: ;
10479 }
10480 break;
10481
10482 case NT_integer:
10483 switch (size)
10484 {
10485 case 8: return N_I8;
10486 case 16: return N_I16;
10487 case 32: return N_I32;
10488 case 64: return N_I64;
10489 default: ;
10490 }
10491 break;
10492
10493 case NT_float:
10494 switch (size)
10495 {
10496 case 32: return N_F32;
10497 case 64: return N_F64;
10498 default: ;
10499 }
10500 break;
10501
10502 case NT_poly:
10503 switch (size)
10504 {
10505 case 8: return N_P8;
10506 case 16: return N_P16;
10507 default: ;
10508 }
10509 break;
10510
10511 case NT_signed:
10512 switch (size)
10513 {
10514 case 8: return N_S8;
10515 case 16: return N_S16;
10516 case 32: return N_S32;
10517 case 64: return N_S64;
10518 default: ;
10519 }
10520 break;
10521
10522 case NT_unsigned:
10523 switch (size)
10524 {
10525 case 8: return N_U8;
10526 case 16: return N_U16;
10527 case 32: return N_U32;
10528 case 64: return N_U64;
10529 default: ;
10530 }
10531 break;
10532
10533 default: ;
10534 }
10535
10536 return N_UTYP;
10537 }
10538
10539 /* Convert compact Neon bitmask type representation to a type and size. Only
10540 handles the case where a single bit is set in the mask. */
10541
10542 static int
10543 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
10544 enum neon_type_mask mask)
10545 {
10546 if ((mask & N_EQK) != 0)
10547 return FAIL;
10548
10549 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
10550 *size = 8;
10551 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
10552 *size = 16;
10553 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
10554 *size = 32;
10555 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
10556 *size = 64;
10557 else
10558 return FAIL;
10559
10560 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
10561 *type = NT_signed;
10562 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
10563 *type = NT_unsigned;
10564 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
10565 *type = NT_integer;
10566 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
10567 *type = NT_untyped;
10568 else if ((mask & (N_P8 | N_P16)) != 0)
10569 *type = NT_poly;
10570 else if ((mask & (N_F32 | N_F64)) != 0)
10571 *type = NT_float;
10572 else
10573 return FAIL;
10574
10575 return SUCCESS;
10576 }
10577
10578 /* Modify a bitmask of allowed types. This is only needed for type
10579 relaxation. */
10580
10581 static unsigned
10582 modify_types_allowed (unsigned allowed, unsigned mods)
10583 {
10584 unsigned size;
10585 enum neon_el_type type;
10586 unsigned destmask;
10587 int i;
10588
10589 destmask = 0;
10590
10591 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
10592 {
10593 if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS)
10594 {
10595 neon_modify_type_size (mods, &type, &size);
10596 destmask |= type_chk_of_el_type (type, size);
10597 }
10598 }
10599
10600 return destmask;
10601 }
10602
10603 /* Check type and return type classification.
10604 The manual states (paraphrase): If one datatype is given, it indicates the
10605 type given in:
10606 - the second operand, if there is one
10607 - the operand, if there is no second operand
10608 - the result, if there are no operands.
10609 This isn't quite good enough though, so we use a concept of a "key" datatype
10610 which is set on a per-instruction basis, which is the one which matters when
10611 only one data type is written.
10612 Note: this function has side-effects (e.g. filling in missing operands). All
10613 Neon instructions should call it before performing bit encoding. */
10614
10615 static struct neon_type_el
10616 neon_check_type (unsigned els, enum neon_shape ns, ...)
10617 {
10618 va_list ap;
10619 unsigned i, pass, key_el = 0;
10620 unsigned types[NEON_MAX_TYPE_ELS];
10621 enum neon_el_type k_type = NT_invtype;
10622 unsigned k_size = -1u;
10623 struct neon_type_el badtype = {NT_invtype, -1};
10624 unsigned key_allowed = 0;
10625
10626 /* Optional registers in Neon instructions are always (not) in operand 1.
10627 Fill in the missing operand here, if it was omitted. */
10628 if (els > 1 && !inst.operands[1].present)
10629 inst.operands[1] = inst.operands[0];
10630
10631 /* Suck up all the varargs. */
10632 va_start (ap, ns);
10633 for (i = 0; i < els; i++)
10634 {
10635 unsigned thisarg = va_arg (ap, unsigned);
10636 if (thisarg == N_IGNORE_TYPE)
10637 {
10638 va_end (ap);
10639 return badtype;
10640 }
10641 types[i] = thisarg;
10642 if ((thisarg & N_KEY) != 0)
10643 key_el = i;
10644 }
10645 va_end (ap);
10646
10647 if (inst.vectype.elems > 0)
10648 for (i = 0; i < els; i++)
10649 if (inst.operands[i].vectype.type != NT_invtype)
10650 {
10651 first_error (_("types specified in both the mnemonic and operands"));
10652 return badtype;
10653 }
10654
10655 /* Duplicate inst.vectype elements here as necessary.
10656 FIXME: No idea if this is exactly the same as the ARM assembler,
10657 particularly when an insn takes one register and one non-register
10658 operand. */
10659 if (inst.vectype.elems == 1 && els > 1)
10660 {
10661 unsigned j;
10662 inst.vectype.elems = els;
10663 inst.vectype.el[key_el] = inst.vectype.el[0];
10664 for (j = 0; j < els; j++)
10665 if (j != key_el)
10666 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
10667 types[j]);
10668 }
10669 else if (inst.vectype.elems == 0 && els > 0)
10670 {
10671 unsigned j;
10672 /* No types were given after the mnemonic, so look for types specified
10673 after each operand. We allow some flexibility here; as long as the
10674 "key" operand has a type, we can infer the others. */
10675 for (j = 0; j < els; j++)
10676 if (inst.operands[j].vectype.type != NT_invtype)
10677 inst.vectype.el[j] = inst.operands[j].vectype;
10678
10679 if (inst.operands[key_el].vectype.type != NT_invtype)
10680 {
10681 for (j = 0; j < els; j++)
10682 if (inst.operands[j].vectype.type == NT_invtype)
10683 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
10684 types[j]);
10685 }
10686 else
10687 {
10688 first_error (_("operand types can't be inferred"));
10689 return badtype;
10690 }
10691 }
10692 else if (inst.vectype.elems != els)
10693 {
10694 first_error (_("type specifier has the wrong number of parts"));
10695 return badtype;
10696 }
10697
10698 for (pass = 0; pass < 2; pass++)
10699 {
10700 for (i = 0; i < els; i++)
10701 {
10702 unsigned thisarg = types[i];
10703 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
10704 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
10705 enum neon_el_type g_type = inst.vectype.el[i].type;
10706 unsigned g_size = inst.vectype.el[i].size;
10707
10708 /* Decay more-specific signed & unsigned types to sign-insensitive
10709 integer types if sign-specific variants are unavailable. */
10710 if ((g_type == NT_signed || g_type == NT_unsigned)
10711 && (types_allowed & N_SU_ALL) == 0)
10712 g_type = NT_integer;
10713
10714 /* If only untyped args are allowed, decay any more specific types to
10715 them. Some instructions only care about signs for some element
10716 sizes, so handle that properly. */
10717 if ((g_size == 8 && (types_allowed & N_8) != 0)
10718 || (g_size == 16 && (types_allowed & N_16) != 0)
10719 || (g_size == 32 && (types_allowed & N_32) != 0)
10720 || (g_size == 64 && (types_allowed & N_64) != 0))
10721 g_type = NT_untyped;
10722
10723 if (pass == 0)
10724 {
10725 if ((thisarg & N_KEY) != 0)
10726 {
10727 k_type = g_type;
10728 k_size = g_size;
10729 key_allowed = thisarg & ~N_KEY;
10730 }
10731 }
10732 else
10733 {
10734 if ((thisarg & N_VFP) != 0)
10735 {
10736 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
10737 unsigned regwidth = neon_shape_el_size[regshape], match;
10738
10739 /* In VFP mode, operands must match register widths. If we
10740 have a key operand, use its width, else use the width of
10741 the current operand. */
10742 if (k_size != -1u)
10743 match = k_size;
10744 else
10745 match = g_size;
10746
10747 if (regwidth != match)
10748 {
10749 first_error (_("operand size must match register width"));
10750 return badtype;
10751 }
10752 }
10753
10754 if ((thisarg & N_EQK) == 0)
10755 {
10756 unsigned given_type = type_chk_of_el_type (g_type, g_size);
10757
10758 if ((given_type & types_allowed) == 0)
10759 {
10760 first_error (_("bad type in Neon instruction"));
10761 return badtype;
10762 }
10763 }
10764 else
10765 {
10766 enum neon_el_type mod_k_type = k_type;
10767 unsigned mod_k_size = k_size;
10768 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
10769 if (g_type != mod_k_type || g_size != mod_k_size)
10770 {
10771 first_error (_("inconsistent types in Neon instruction"));
10772 return badtype;
10773 }
10774 }
10775 }
10776 }
10777 }
10778
10779 return inst.vectype.el[key_el];
10780 }
10781
10782 /* Neon-style VFP instruction forwarding. */
10783
10784 /* Thumb VFP instructions have 0xE in the condition field. */
10785
10786 static void
10787 do_vfp_cond_or_thumb (void)
10788 {
10789 if (thumb_mode)
10790 inst.instruction |= 0xe0000000;
10791 else
10792 inst.instruction |= inst.cond << 28;
10793 }
10794
10795 /* Look up and encode a simple mnemonic, for use as a helper function for the
10796 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
10797 etc. It is assumed that operand parsing has already been done, and that the
10798 operands are in the form expected by the given opcode (this isn't necessarily
10799 the same as the form in which they were parsed, hence some massaging must
10800 take place before this function is called).
10801 Checks current arch version against that in the looked-up opcode. */
10802
10803 static void
10804 do_vfp_nsyn_opcode (const char *opname)
10805 {
10806 const struct asm_opcode *opcode;
10807
10808 opcode = hash_find (arm_ops_hsh, opname);
10809
10810 if (!opcode)
10811 abort ();
10812
10813 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
10814 thumb_mode ? *opcode->tvariant : *opcode->avariant),
10815 _(BAD_FPU));
10816
10817 if (thumb_mode)
10818 {
10819 inst.instruction = opcode->tvalue;
10820 opcode->tencode ();
10821 }
10822 else
10823 {
10824 inst.instruction = (inst.cond << 28) | opcode->avalue;
10825 opcode->aencode ();
10826 }
10827 }
10828
10829 static void
10830 do_vfp_nsyn_add_sub (enum neon_shape rs)
10831 {
10832 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
10833
10834 if (rs == NS_FFF)
10835 {
10836 if (is_add)
10837 do_vfp_nsyn_opcode ("fadds");
10838 else
10839 do_vfp_nsyn_opcode ("fsubs");
10840 }
10841 else
10842 {
10843 if (is_add)
10844 do_vfp_nsyn_opcode ("faddd");
10845 else
10846 do_vfp_nsyn_opcode ("fsubd");
10847 }
10848 }
10849
10850 /* Check operand types to see if this is a VFP instruction, and if so call
10851 PFN (). */
10852
10853 static int
10854 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
10855 {
10856 enum neon_shape rs;
10857 struct neon_type_el et;
10858
10859 switch (args)
10860 {
10861 case 2:
10862 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
10863 et = neon_check_type (2, rs,
10864 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
10865 break;
10866
10867 case 3:
10868 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
10869 et = neon_check_type (3, rs,
10870 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
10871 break;
10872
10873 default:
10874 abort ();
10875 }
10876
10877 if (et.type != NT_invtype)
10878 {
10879 pfn (rs);
10880 return SUCCESS;
10881 }
10882 else
10883 inst.error = NULL;
10884
10885 return FAIL;
10886 }
10887
10888 static void
10889 do_vfp_nsyn_mla_mls (enum neon_shape rs)
10890 {
10891 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
10892
10893 if (rs == NS_FFF)
10894 {
10895 if (is_mla)
10896 do_vfp_nsyn_opcode ("fmacs");
10897 else
10898 do_vfp_nsyn_opcode ("fmscs");
10899 }
10900 else
10901 {
10902 if (is_mla)
10903 do_vfp_nsyn_opcode ("fmacd");
10904 else
10905 do_vfp_nsyn_opcode ("fmscd");
10906 }
10907 }
10908
10909 static void
10910 do_vfp_nsyn_mul (enum neon_shape rs)
10911 {
10912 if (rs == NS_FFF)
10913 do_vfp_nsyn_opcode ("fmuls");
10914 else
10915 do_vfp_nsyn_opcode ("fmuld");
10916 }
10917
10918 static void
10919 do_vfp_nsyn_abs_neg (enum neon_shape rs)
10920 {
10921 int is_neg = (inst.instruction & 0x80) != 0;
10922 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
10923
10924 if (rs == NS_FF)
10925 {
10926 if (is_neg)
10927 do_vfp_nsyn_opcode ("fnegs");
10928 else
10929 do_vfp_nsyn_opcode ("fabss");
10930 }
10931 else
10932 {
10933 if (is_neg)
10934 do_vfp_nsyn_opcode ("fnegd");
10935 else
10936 do_vfp_nsyn_opcode ("fabsd");
10937 }
10938 }
10939
10940 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
10941 insns belong to Neon, and are handled elsewhere. */
10942
10943 static void
10944 do_vfp_nsyn_ldm_stm (int is_dbmode)
10945 {
10946 int is_ldm = (inst.instruction & (1 << 20)) != 0;
10947 if (is_ldm)
10948 {
10949 if (is_dbmode)
10950 do_vfp_nsyn_opcode ("fldmdbs");
10951 else
10952 do_vfp_nsyn_opcode ("fldmias");
10953 }
10954 else
10955 {
10956 if (is_dbmode)
10957 do_vfp_nsyn_opcode ("fstmdbs");
10958 else
10959 do_vfp_nsyn_opcode ("fstmias");
10960 }
10961 }
10962
10963 static void
10964 do_vfp_nsyn_sqrt (void)
10965 {
10966 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
10967 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
10968
10969 if (rs == NS_FF)
10970 do_vfp_nsyn_opcode ("fsqrts");
10971 else
10972 do_vfp_nsyn_opcode ("fsqrtd");
10973 }
10974
10975 static void
10976 do_vfp_nsyn_div (void)
10977 {
10978 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
10979 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
10980 N_F32 | N_F64 | N_KEY | N_VFP);
10981
10982 if (rs == NS_FFF)
10983 do_vfp_nsyn_opcode ("fdivs");
10984 else
10985 do_vfp_nsyn_opcode ("fdivd");
10986 }
10987
10988 static void
10989 do_vfp_nsyn_nmul (void)
10990 {
10991 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
10992 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
10993 N_F32 | N_F64 | N_KEY | N_VFP);
10994
10995 if (rs == NS_FFF)
10996 {
10997 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
10998 do_vfp_sp_dyadic ();
10999 }
11000 else
11001 {
11002 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11003 do_vfp_dp_rd_rn_rm ();
11004 }
11005 do_vfp_cond_or_thumb ();
11006 }
11007
11008 static void
11009 do_vfp_nsyn_cmp (void)
11010 {
11011 if (inst.operands[1].isreg)
11012 {
11013 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11014 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11015
11016 if (rs == NS_FF)
11017 {
11018 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11019 do_vfp_sp_monadic ();
11020 }
11021 else
11022 {
11023 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11024 do_vfp_dp_rd_rm ();
11025 }
11026 }
11027 else
11028 {
11029 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
11030 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
11031
11032 switch (inst.instruction & 0x0fffffff)
11033 {
11034 case N_MNEM_vcmp:
11035 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
11036 break;
11037 case N_MNEM_vcmpe:
11038 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
11039 break;
11040 default:
11041 abort ();
11042 }
11043
11044 if (rs == NS_FI)
11045 {
11046 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11047 do_vfp_sp_compare_z ();
11048 }
11049 else
11050 {
11051 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11052 do_vfp_dp_rd ();
11053 }
11054 }
11055 do_vfp_cond_or_thumb ();
11056 }
11057
11058 static void
11059 nsyn_insert_sp (void)
11060 {
11061 inst.operands[1] = inst.operands[0];
11062 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
11063 inst.operands[0].reg = 13;
11064 inst.operands[0].isreg = 1;
11065 inst.operands[0].writeback = 1;
11066 inst.operands[0].present = 1;
11067 }
11068
11069 static void
11070 do_vfp_nsyn_push (void)
11071 {
11072 nsyn_insert_sp ();
11073 if (inst.operands[1].issingle)
11074 do_vfp_nsyn_opcode ("fstmdbs");
11075 else
11076 do_vfp_nsyn_opcode ("fstmdbd");
11077 }
11078
11079 static void
11080 do_vfp_nsyn_pop (void)
11081 {
11082 nsyn_insert_sp ();
11083 if (inst.operands[1].issingle)
11084 do_vfp_nsyn_opcode ("fldmdbs");
11085 else
11086 do_vfp_nsyn_opcode ("fldmdbd");
11087 }
11088
11089 /* Fix up Neon data-processing instructions, ORing in the correct bits for
11090 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
11091
11092 static unsigned
11093 neon_dp_fixup (unsigned i)
11094 {
11095 if (thumb_mode)
11096 {
11097 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
11098 if (i & (1 << 24))
11099 i |= 1 << 28;
11100
11101 i &= ~(1 << 24);
11102
11103 i |= 0xef000000;
11104 }
11105 else
11106 i |= 0xf2000000;
11107
11108 return i;
11109 }
11110
11111 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
11112 (0, 1, 2, 3). */
11113
11114 static unsigned
11115 neon_logbits (unsigned x)
11116 {
11117 return ffs (x) - 4;
11118 }
11119
11120 #define LOW4(R) ((R) & 0xf)
11121 #define HI1(R) (((R) >> 4) & 1)
11122
11123 /* Encode insns with bit pattern:
11124
11125 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
11126 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
11127
11128 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
11129 different meaning for some instruction. */
11130
11131 static void
11132 neon_three_same (int isquad, int ubit, int size)
11133 {
11134 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11135 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11136 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
11137 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
11138 inst.instruction |= LOW4 (inst.operands[2].reg);
11139 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
11140 inst.instruction |= (isquad != 0) << 6;
11141 inst.instruction |= (ubit != 0) << 24;
11142 if (size != -1)
11143 inst.instruction |= neon_logbits (size) << 20;
11144
11145 inst.instruction = neon_dp_fixup (inst.instruction);
11146 }
11147
11148 /* Encode instructions of the form:
11149
11150 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
11151 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
11152
11153 Don't write size if SIZE == -1. */
11154
11155 static void
11156 neon_two_same (int qbit, int ubit, int size)
11157 {
11158 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11159 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11160 inst.instruction |= LOW4 (inst.operands[1].reg);
11161 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11162 inst.instruction |= (qbit != 0) << 6;
11163 inst.instruction |= (ubit != 0) << 24;
11164
11165 if (size != -1)
11166 inst.instruction |= neon_logbits (size) << 18;
11167
11168 inst.instruction = neon_dp_fixup (inst.instruction);
11169 }
11170
11171 /* Neon instruction encoders, in approximate order of appearance. */
11172
11173 static void
11174 do_neon_dyadic_i_su (void)
11175 {
11176 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11177 struct neon_type_el et = neon_check_type (3, rs,
11178 N_EQK, N_EQK, N_SU_32 | N_KEY);
11179 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11180 }
11181
11182 static void
11183 do_neon_dyadic_i64_su (void)
11184 {
11185 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11186 struct neon_type_el et = neon_check_type (3, rs,
11187 N_EQK, N_EQK, N_SU_ALL | N_KEY);
11188 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11189 }
11190
11191 static void
11192 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
11193 unsigned immbits)
11194 {
11195 unsigned size = et.size >> 3;
11196 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11197 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11198 inst.instruction |= LOW4 (inst.operands[1].reg);
11199 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11200 inst.instruction |= (isquad != 0) << 6;
11201 inst.instruction |= immbits << 16;
11202 inst.instruction |= (size >> 3) << 7;
11203 inst.instruction |= (size & 0x7) << 19;
11204 if (write_ubit)
11205 inst.instruction |= (uval != 0) << 24;
11206
11207 inst.instruction = neon_dp_fixup (inst.instruction);
11208 }
11209
11210 static void
11211 do_neon_shl_imm (void)
11212 {
11213 if (!inst.operands[2].isreg)
11214 {
11215 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11216 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
11217 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11218 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
11219 }
11220 else
11221 {
11222 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11223 struct neon_type_el et = neon_check_type (3, rs,
11224 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
11225 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11226 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11227 }
11228 }
11229
11230 static void
11231 do_neon_qshl_imm (void)
11232 {
11233 if (!inst.operands[2].isreg)
11234 {
11235 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11236 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
11237 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11238 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
11239 inst.operands[2].imm);
11240 }
11241 else
11242 {
11243 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11244 struct neon_type_el et = neon_check_type (3, rs,
11245 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
11246 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11247 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11248 }
11249 }
11250
11251 static int
11252 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
11253 {
11254 /* Handle .I8 and .I64 as pseudo-instructions. */
11255 switch (size)
11256 {
11257 case 8:
11258 /* Unfortunately, this will make everything apart from zero out-of-range.
11259 FIXME is this the intended semantics? There doesn't seem much point in
11260 accepting .I8 if so. */
11261 immediate |= immediate << 8;
11262 size = 16;
11263 break;
11264 case 64:
11265 /* Similarly, anything other than zero will be replicated in bits [63:32],
11266 which probably isn't want we want if we specified .I64. */
11267 if (immediate != 0)
11268 goto bad_immediate;
11269 size = 32;
11270 break;
11271 default: ;
11272 }
11273
11274 if (immediate == (immediate & 0x000000ff))
11275 {
11276 *immbits = immediate;
11277 return (size == 16) ? 0x9 : 0x1;
11278 }
11279 else if (immediate == (immediate & 0x0000ff00))
11280 {
11281 *immbits = immediate >> 8;
11282 return (size == 16) ? 0xb : 0x3;
11283 }
11284 else if (immediate == (immediate & 0x00ff0000))
11285 {
11286 *immbits = immediate >> 16;
11287 return 0x5;
11288 }
11289 else if (immediate == (immediate & 0xff000000))
11290 {
11291 *immbits = immediate >> 24;
11292 return 0x7;
11293 }
11294
11295 bad_immediate:
11296 first_error (_("immediate value out of range"));
11297 return FAIL;
11298 }
11299
11300 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
11301 A, B, C, D. */
11302
11303 static int
11304 neon_bits_same_in_bytes (unsigned imm)
11305 {
11306 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
11307 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
11308 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
11309 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
11310 }
11311
11312 /* For immediate of above form, return 0bABCD. */
11313
11314 static unsigned
11315 neon_squash_bits (unsigned imm)
11316 {
11317 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
11318 | ((imm & 0x01000000) >> 21);
11319 }
11320
11321 /* Compress quarter-float representation to 0b...000 abcdefgh. */
11322
11323 static unsigned
11324 neon_qfloat_bits (unsigned imm)
11325 {
11326 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
11327 }
11328
11329 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
11330 the instruction. *OP is passed as the initial value of the op field, and
11331 may be set to a different value depending on the constant (i.e.
11332 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
11333 MVN). */
11334
11335 static int
11336 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, unsigned *immbits,
11337 int *op, int size, enum neon_el_type type)
11338 {
11339 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
11340 {
11341 if (size != 32 || *op == 1)
11342 return FAIL;
11343 *immbits = neon_qfloat_bits (immlo);
11344 return 0xf;
11345 }
11346 else if (size == 64 && neon_bits_same_in_bytes (immhi)
11347 && neon_bits_same_in_bytes (immlo))
11348 {
11349 /* Check this one first so we don't have to bother with immhi in later
11350 tests. */
11351 if (*op == 1)
11352 return FAIL;
11353 *immbits = (neon_squash_bits (immhi) << 4) | neon_squash_bits (immlo);
11354 *op = 1;
11355 return 0xe;
11356 }
11357 else if (immhi != 0)
11358 return FAIL;
11359 else if (immlo == (immlo & 0x000000ff))
11360 {
11361 /* 64-bit case was already handled. Don't allow MVN with 8-bit
11362 immediate. */
11363 if ((size != 8 && size != 16 && size != 32)
11364 || (size == 8 && *op == 1))
11365 return FAIL;
11366 *immbits = immlo;
11367 return (size == 8) ? 0xe : (size == 16) ? 0x8 : 0x0;
11368 }
11369 else if (immlo == (immlo & 0x0000ff00))
11370 {
11371 if (size != 16 && size != 32)
11372 return FAIL;
11373 *immbits = immlo >> 8;
11374 return (size == 16) ? 0xa : 0x2;
11375 }
11376 else if (immlo == (immlo & 0x00ff0000))
11377 {
11378 if (size != 32)
11379 return FAIL;
11380 *immbits = immlo >> 16;
11381 return 0x4;
11382 }
11383 else if (immlo == (immlo & 0xff000000))
11384 {
11385 if (size != 32)
11386 return FAIL;
11387 *immbits = immlo >> 24;
11388 return 0x6;
11389 }
11390 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
11391 {
11392 if (size != 32)
11393 return FAIL;
11394 *immbits = (immlo >> 8) & 0xff;
11395 return 0xc;
11396 }
11397 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
11398 {
11399 if (size != 32)
11400 return FAIL;
11401 *immbits = (immlo >> 16) & 0xff;
11402 return 0xd;
11403 }
11404
11405 return FAIL;
11406 }
11407
11408 /* Write immediate bits [7:0] to the following locations:
11409
11410 |28/24|23 19|18 16|15 4|3 0|
11411 | 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|
11412
11413 This function is used by VMOV/VMVN/VORR/VBIC. */
11414
11415 static void
11416 neon_write_immbits (unsigned immbits)
11417 {
11418 inst.instruction |= immbits & 0xf;
11419 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
11420 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
11421 }
11422
11423 /* Invert low-order SIZE bits of XHI:XLO. */
11424
11425 static void
11426 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
11427 {
11428 unsigned immlo = xlo ? *xlo : 0;
11429 unsigned immhi = xhi ? *xhi : 0;
11430
11431 switch (size)
11432 {
11433 case 8:
11434 immlo = (~immlo) & 0xff;
11435 break;
11436
11437 case 16:
11438 immlo = (~immlo) & 0xffff;
11439 break;
11440
11441 case 64:
11442 immhi = (~immhi) & 0xffffffff;
11443 /* fall through. */
11444
11445 case 32:
11446 immlo = (~immlo) & 0xffffffff;
11447 break;
11448
11449 default:
11450 abort ();
11451 }
11452
11453 if (xlo)
11454 *xlo = immlo;
11455
11456 if (xhi)
11457 *xhi = immhi;
11458 }
11459
11460 static void
11461 do_neon_logic (void)
11462 {
11463 if (inst.operands[2].present && inst.operands[2].isreg)
11464 {
11465 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11466 neon_check_type (3, rs, N_IGNORE_TYPE);
11467 /* U bit and size field were set as part of the bitmask. */
11468 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11469 neon_three_same (neon_quad (rs), 0, -1);
11470 }
11471 else
11472 {
11473 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
11474 struct neon_type_el et = neon_check_type (2, rs,
11475 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
11476 enum neon_opc opcode = inst.instruction & 0x0fffffff;
11477 unsigned immbits;
11478 int cmode;
11479
11480 if (et.type == NT_invtype)
11481 return;
11482
11483 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11484
11485 switch (opcode)
11486 {
11487 case N_MNEM_vbic:
11488 cmode = neon_cmode_for_logic_imm (inst.operands[1].imm, &immbits,
11489 et.size);
11490 break;
11491
11492 case N_MNEM_vorr:
11493 cmode = neon_cmode_for_logic_imm (inst.operands[1].imm, &immbits,
11494 et.size);
11495 break;
11496
11497 case N_MNEM_vand:
11498 /* Pseudo-instruction for VBIC. */
11499 immbits = inst.operands[1].imm;
11500 neon_invert_size (&immbits, 0, et.size);
11501 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11502 break;
11503
11504 case N_MNEM_vorn:
11505 /* Pseudo-instruction for VORR. */
11506 immbits = inst.operands[1].imm;
11507 neon_invert_size (&immbits, 0, et.size);
11508 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11509 break;
11510
11511 default:
11512 abort ();
11513 }
11514
11515 if (cmode == FAIL)
11516 return;
11517
11518 inst.instruction |= neon_quad (rs) << 6;
11519 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11520 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11521 inst.instruction |= cmode << 8;
11522 neon_write_immbits (immbits);
11523
11524 inst.instruction = neon_dp_fixup (inst.instruction);
11525 }
11526 }
11527
11528 static void
11529 do_neon_bitfield (void)
11530 {
11531 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11532 neon_check_type (3, rs, N_IGNORE_TYPE);
11533 neon_three_same (neon_quad (rs), 0, -1);
11534 }
11535
11536 static void
11537 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
11538 unsigned destbits)
11539 {
11540 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11541 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
11542 types | N_KEY);
11543 if (et.type == NT_float)
11544 {
11545 inst.instruction = NEON_ENC_FLOAT (inst.instruction);
11546 neon_three_same (neon_quad (rs), 0, -1);
11547 }
11548 else
11549 {
11550 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11551 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
11552 }
11553 }
11554
11555 static void
11556 do_neon_dyadic_if_su (void)
11557 {
11558 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
11559 }
11560
11561 static void
11562 do_neon_dyadic_if_su_d (void)
11563 {
11564 /* This version only allow D registers, but that constraint is enforced during
11565 operand parsing so we don't need to do anything extra here. */
11566 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
11567 }
11568
11569 static void
11570 do_neon_dyadic_if_i (void)
11571 {
11572 neon_dyadic_misc (NT_unsigned, N_IF_32, 0);
11573 }
11574
11575 static void
11576 do_neon_dyadic_if_i_d (void)
11577 {
11578 neon_dyadic_misc (NT_unsigned, N_IF_32, 0);
11579 }
11580
11581 enum vfp_or_neon_is_neon_bits
11582 {
11583 NEON_CHECK_CC = 1,
11584 NEON_CHECK_ARCH = 2
11585 };
11586
11587 /* Call this function if an instruction which may have belonged to the VFP or
11588 Neon instruction sets, but turned out to be a Neon instruction (due to the
11589 operand types involved, etc.). We have to check and/or fix-up a couple of
11590 things:
11591
11592 - Make sure the user hasn't attempted to make a Neon instruction
11593 conditional.
11594 - Alter the value in the condition code field if necessary.
11595 - Make sure that the arch supports Neon instructions.
11596
11597 Which of these operations take place depends on bits from enum
11598 vfp_or_neon_is_neon_bits.
11599
11600 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
11601 current instruction's condition is COND_ALWAYS, the condition field is
11602 changed to inst.uncond_value. This is necessary because instructions shared
11603 between VFP and Neon may be conditional for the VFP variants only, and the
11604 unconditional Neon version must have, e.g., 0xF in the condition field. */
11605
11606 static int
11607 vfp_or_neon_is_neon (unsigned check)
11608 {
11609 /* Conditions are always legal in Thumb mode (IT blocks). */
11610 if (!thumb_mode && (check & NEON_CHECK_CC))
11611 {
11612 if (inst.cond != COND_ALWAYS)
11613 {
11614 first_error (_(BAD_COND));
11615 return FAIL;
11616 }
11617 if (inst.uncond_value != -1)
11618 inst.instruction |= inst.uncond_value << 28;
11619 }
11620
11621 if ((check & NEON_CHECK_ARCH)
11622 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
11623 {
11624 first_error (_(BAD_FPU));
11625 return FAIL;
11626 }
11627
11628 return SUCCESS;
11629 }
11630
11631 static void
11632 do_neon_addsub_if_i (void)
11633 {
11634 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
11635 return;
11636
11637 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
11638 return;
11639
11640 /* The "untyped" case can't happen. Do this to stop the "U" bit being
11641 affected if we specify unsigned args. */
11642 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
11643 }
11644
11645 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
11646 result to be:
11647 V<op> A,B (A is operand 0, B is operand 2)
11648 to mean:
11649 V<op> A,B,A
11650 not:
11651 V<op> A,B,B
11652 so handle that case specially. */
11653
11654 static void
11655 neon_exchange_operands (void)
11656 {
11657 void *scratch = alloca (sizeof (inst.operands[0]));
11658 if (inst.operands[1].present)
11659 {
11660 /* Swap operands[1] and operands[2]. */
11661 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
11662 inst.operands[1] = inst.operands[2];
11663 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
11664 }
11665 else
11666 {
11667 inst.operands[1] = inst.operands[2];
11668 inst.operands[2] = inst.operands[0];
11669 }
11670 }
11671
11672 static void
11673 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
11674 {
11675 if (inst.operands[2].isreg)
11676 {
11677 if (invert)
11678 neon_exchange_operands ();
11679 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
11680 }
11681 else
11682 {
11683 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11684 struct neon_type_el et = neon_check_type (2, rs,
11685 N_EQK | N_SIZ, immtypes | N_KEY);
11686
11687 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11688 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11689 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11690 inst.instruction |= LOW4 (inst.operands[1].reg);
11691 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11692 inst.instruction |= neon_quad (rs) << 6;
11693 inst.instruction |= (et.type == NT_float) << 10;
11694 inst.instruction |= neon_logbits (et.size) << 18;
11695
11696 inst.instruction = neon_dp_fixup (inst.instruction);
11697 }
11698 }
11699
11700 static void
11701 do_neon_cmp (void)
11702 {
11703 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
11704 }
11705
11706 static void
11707 do_neon_cmp_inv (void)
11708 {
11709 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
11710 }
11711
11712 static void
11713 do_neon_ceq (void)
11714 {
11715 neon_compare (N_IF_32, N_IF_32, FALSE);
11716 }
11717
11718 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
11719 scalars, which are encoded in 5 bits, M : Rm.
11720 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
11721 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
11722 index in M. */
11723
11724 static unsigned
11725 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
11726 {
11727 unsigned regno = NEON_SCALAR_REG (scalar);
11728 unsigned elno = NEON_SCALAR_INDEX (scalar);
11729
11730 switch (elsize)
11731 {
11732 case 16:
11733 if (regno > 7 || elno > 3)
11734 goto bad_scalar;
11735 return regno | (elno << 3);
11736
11737 case 32:
11738 if (regno > 15 || elno > 1)
11739 goto bad_scalar;
11740 return regno | (elno << 4);
11741
11742 default:
11743 bad_scalar:
11744 first_error (_("scalar out of range for multiply instruction"));
11745 }
11746
11747 return 0;
11748 }
11749
11750 /* Encode multiply / multiply-accumulate scalar instructions. */
11751
11752 static void
11753 neon_mul_mac (struct neon_type_el et, int ubit)
11754 {
11755 unsigned scalar;
11756
11757 /* Give a more helpful error message if we have an invalid type. */
11758 if (et.type == NT_invtype)
11759 return;
11760
11761 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
11762 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11763 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11764 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
11765 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
11766 inst.instruction |= LOW4 (scalar);
11767 inst.instruction |= HI1 (scalar) << 5;
11768 inst.instruction |= (et.type == NT_float) << 8;
11769 inst.instruction |= neon_logbits (et.size) << 20;
11770 inst.instruction |= (ubit != 0) << 24;
11771
11772 inst.instruction = neon_dp_fixup (inst.instruction);
11773 }
11774
11775 static void
11776 do_neon_mac_maybe_scalar (void)
11777 {
11778 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
11779 return;
11780
11781 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
11782 return;
11783
11784 if (inst.operands[2].isscalar)
11785 {
11786 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
11787 struct neon_type_el et = neon_check_type (3, rs,
11788 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
11789 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
11790 neon_mul_mac (et, neon_quad (rs));
11791 }
11792 else
11793 do_neon_dyadic_if_i ();
11794 }
11795
11796 static void
11797 do_neon_tst (void)
11798 {
11799 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11800 struct neon_type_el et = neon_check_type (3, rs,
11801 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
11802 neon_three_same (neon_quad (rs), 0, et.size);
11803 }
11804
11805 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
11806 same types as the MAC equivalents. The polynomial type for this instruction
11807 is encoded the same as the integer type. */
11808
11809 static void
11810 do_neon_mul (void)
11811 {
11812 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
11813 return;
11814
11815 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
11816 return;
11817
11818 if (inst.operands[2].isscalar)
11819 do_neon_mac_maybe_scalar ();
11820 else
11821 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
11822 }
11823
11824 static void
11825 do_neon_qdmulh (void)
11826 {
11827 if (inst.operands[2].isscalar)
11828 {
11829 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
11830 struct neon_type_el et = neon_check_type (3, rs,
11831 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
11832 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
11833 neon_mul_mac (et, neon_quad (rs));
11834 }
11835 else
11836 {
11837 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11838 struct neon_type_el et = neon_check_type (3, rs,
11839 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
11840 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11841 /* The U bit (rounding) comes from bit mask. */
11842 neon_three_same (neon_quad (rs), 0, et.size);
11843 }
11844 }
11845
11846 static void
11847 do_neon_fcmp_absolute (void)
11848 {
11849 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11850 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
11851 /* Size field comes from bit mask. */
11852 neon_three_same (neon_quad (rs), 1, -1);
11853 }
11854
11855 static void
11856 do_neon_fcmp_absolute_inv (void)
11857 {
11858 neon_exchange_operands ();
11859 do_neon_fcmp_absolute ();
11860 }
11861
11862 static void
11863 do_neon_step (void)
11864 {
11865 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11866 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
11867 neon_three_same (neon_quad (rs), 0, -1);
11868 }
11869
11870 static void
11871 do_neon_abs_neg (void)
11872 {
11873 enum neon_shape rs;
11874 struct neon_type_el et;
11875
11876 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
11877 return;
11878
11879 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
11880 return;
11881
11882 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
11883 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
11884
11885 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11886 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11887 inst.instruction |= LOW4 (inst.operands[1].reg);
11888 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11889 inst.instruction |= neon_quad (rs) << 6;
11890 inst.instruction |= (et.type == NT_float) << 10;
11891 inst.instruction |= neon_logbits (et.size) << 18;
11892
11893 inst.instruction = neon_dp_fixup (inst.instruction);
11894 }
11895
11896 static void
11897 do_neon_sli (void)
11898 {
11899 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11900 struct neon_type_el et = neon_check_type (2, rs,
11901 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
11902 int imm = inst.operands[2].imm;
11903 constraint (imm < 0 || (unsigned)imm >= et.size,
11904 _("immediate out of range for insert"));
11905 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
11906 }
11907
11908 static void
11909 do_neon_sri (void)
11910 {
11911 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11912 struct neon_type_el et = neon_check_type (2, rs,
11913 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
11914 int imm = inst.operands[2].imm;
11915 constraint (imm < 1 || (unsigned)imm > et.size,
11916 _("immediate out of range for insert"));
11917 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
11918 }
11919
11920 static void
11921 do_neon_qshlu_imm (void)
11922 {
11923 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
11924 struct neon_type_el et = neon_check_type (2, rs,
11925 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
11926 int imm = inst.operands[2].imm;
11927 constraint (imm < 0 || (unsigned)imm >= et.size,
11928 _("immediate out of range for shift"));
11929 /* Only encodes the 'U present' variant of the instruction.
11930 In this case, signed types have OP (bit 8) set to 0.
11931 Unsigned types have OP set to 1. */
11932 inst.instruction |= (et.type == NT_unsigned) << 8;
11933 /* The rest of the bits are the same as other immediate shifts. */
11934 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
11935 }
11936
11937 static void
11938 do_neon_qmovn (void)
11939 {
11940 struct neon_type_el et = neon_check_type (2, NS_DQ,
11941 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
11942 /* Saturating move where operands can be signed or unsigned, and the
11943 destination has the same signedness. */
11944 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11945 if (et.type == NT_unsigned)
11946 inst.instruction |= 0xc0;
11947 else
11948 inst.instruction |= 0x80;
11949 neon_two_same (0, 1, et.size / 2);
11950 }
11951
11952 static void
11953 do_neon_qmovun (void)
11954 {
11955 struct neon_type_el et = neon_check_type (2, NS_DQ,
11956 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
11957 /* Saturating move with unsigned results. Operands must be signed. */
11958 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11959 neon_two_same (0, 1, et.size / 2);
11960 }
11961
11962 static void
11963 do_neon_rshift_sat_narrow (void)
11964 {
11965 /* FIXME: Types for narrowing. If operands are signed, results can be signed
11966 or unsigned. If operands are unsigned, results must also be unsigned. */
11967 struct neon_type_el et = neon_check_type (2, NS_DQI,
11968 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
11969 int imm = inst.operands[2].imm;
11970 /* This gets the bounds check, size encoding and immediate bits calculation
11971 right. */
11972 et.size /= 2;
11973
11974 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
11975 VQMOVN.I<size> <Dd>, <Qm>. */
11976 if (imm == 0)
11977 {
11978 inst.operands[2].present = 0;
11979 inst.instruction = N_MNEM_vqmovn;
11980 do_neon_qmovn ();
11981 return;
11982 }
11983
11984 constraint (imm < 1 || (unsigned)imm > et.size,
11985 _("immediate out of range"));
11986 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
11987 }
11988
11989 static void
11990 do_neon_rshift_sat_narrow_u (void)
11991 {
11992 /* FIXME: Types for narrowing. If operands are signed, results can be signed
11993 or unsigned. If operands are unsigned, results must also be unsigned. */
11994 struct neon_type_el et = neon_check_type (2, NS_DQI,
11995 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
11996 int imm = inst.operands[2].imm;
11997 /* This gets the bounds check, size encoding and immediate bits calculation
11998 right. */
11999 et.size /= 2;
12000
12001 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
12002 VQMOVUN.I<size> <Dd>, <Qm>. */
12003 if (imm == 0)
12004 {
12005 inst.operands[2].present = 0;
12006 inst.instruction = N_MNEM_vqmovun;
12007 do_neon_qmovun ();
12008 return;
12009 }
12010
12011 constraint (imm < 1 || (unsigned)imm > et.size,
12012 _("immediate out of range"));
12013 /* FIXME: The manual is kind of unclear about what value U should have in
12014 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
12015 must be 1. */
12016 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
12017 }
12018
12019 static void
12020 do_neon_movn (void)
12021 {
12022 struct neon_type_el et = neon_check_type (2, NS_DQ,
12023 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12024 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12025 neon_two_same (0, 1, et.size / 2);
12026 }
12027
12028 static void
12029 do_neon_rshift_narrow (void)
12030 {
12031 struct neon_type_el et = neon_check_type (2, NS_DQI,
12032 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12033 int imm = inst.operands[2].imm;
12034 /* This gets the bounds check, size encoding and immediate bits calculation
12035 right. */
12036 et.size /= 2;
12037
12038 /* If immediate is zero then we are a pseudo-instruction for
12039 VMOVN.I<size> <Dd>, <Qm> */
12040 if (imm == 0)
12041 {
12042 inst.operands[2].present = 0;
12043 inst.instruction = N_MNEM_vmovn;
12044 do_neon_movn ();
12045 return;
12046 }
12047
12048 constraint (imm < 1 || (unsigned)imm > et.size,
12049 _("immediate out of range for narrowing operation"));
12050 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
12051 }
12052
12053 static void
12054 do_neon_shll (void)
12055 {
12056 /* FIXME: Type checking when lengthening. */
12057 struct neon_type_el et = neon_check_type (2, NS_QDI,
12058 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
12059 unsigned imm = inst.operands[2].imm;
12060
12061 if (imm == et.size)
12062 {
12063 /* Maximum shift variant. */
12064 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12065 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12066 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12067 inst.instruction |= LOW4 (inst.operands[1].reg);
12068 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12069 inst.instruction |= neon_logbits (et.size) << 18;
12070
12071 inst.instruction = neon_dp_fixup (inst.instruction);
12072 }
12073 else
12074 {
12075 /* A more-specific type check for non-max versions. */
12076 et = neon_check_type (2, NS_QDI,
12077 N_EQK | N_DBL, N_SU_32 | N_KEY);
12078 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12079 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
12080 }
12081 }
12082
12083 /* Check the various types for the VCVT instruction, and return which version
12084 the current instruction is. */
12085
12086 static int
12087 neon_cvt_flavour (enum neon_shape rs)
12088 {
12089 #define CVT_VAR(C,X,Y) \
12090 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
12091 if (et.type != NT_invtype) \
12092 { \
12093 inst.error = NULL; \
12094 return (C); \
12095 }
12096 struct neon_type_el et;
12097 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
12098 || rs == NS_FF) ? N_VFP : 0;
12099 /* The instruction versions which take an immediate take one register
12100 argument, which is extended to the width of the full register. Thus the
12101 "source" and "destination" registers must have the same width. Hack that
12102 here by making the size equal to the key (wider, in this case) operand. */
12103 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
12104
12105 CVT_VAR (0, N_S32, N_F32);
12106 CVT_VAR (1, N_U32, N_F32);
12107 CVT_VAR (2, N_F32, N_S32);
12108 CVT_VAR (3, N_F32, N_U32);
12109
12110 whole_reg = N_VFP;
12111
12112 /* VFP instructions. */
12113 CVT_VAR (4, N_F32, N_F64);
12114 CVT_VAR (5, N_F64, N_F32);
12115 CVT_VAR (6, N_S32, N_F64 | key);
12116 CVT_VAR (7, N_U32, N_F64 | key);
12117 CVT_VAR (8, N_F64 | key, N_S32);
12118 CVT_VAR (9, N_F64 | key, N_U32);
12119 /* VFP instructions with bitshift. */
12120 CVT_VAR (10, N_F32 | key, N_S16);
12121 CVT_VAR (11, N_F32 | key, N_U16);
12122 CVT_VAR (12, N_F64 | key, N_S16);
12123 CVT_VAR (13, N_F64 | key, N_U16);
12124 CVT_VAR (14, N_S16, N_F32 | key);
12125 CVT_VAR (15, N_U16, N_F32 | key);
12126 CVT_VAR (16, N_S16, N_F64 | key);
12127 CVT_VAR (17, N_U16, N_F64 | key);
12128
12129 return -1;
12130 #undef CVT_VAR
12131 }
12132
12133 /* Neon-syntax VFP conversions. */
12134
12135 static void
12136 do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
12137 {
12138 const char *opname = 0;
12139
12140 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
12141 {
12142 /* Conversions with immediate bitshift. */
12143 const char *enc[] =
12144 {
12145 "ftosls",
12146 "ftouls",
12147 "fsltos",
12148 "fultos",
12149 NULL,
12150 NULL,
12151 "ftosld",
12152 "ftould",
12153 "fsltod",
12154 "fultod",
12155 "fshtos",
12156 "fuhtos",
12157 "fshtod",
12158 "fuhtod",
12159 "ftoshs",
12160 "ftouhs",
12161 "ftoshd",
12162 "ftouhd"
12163 };
12164
12165 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12166 {
12167 opname = enc[flavour];
12168 constraint (inst.operands[0].reg != inst.operands[1].reg,
12169 _("operands 0 and 1 must be the same register"));
12170 inst.operands[1] = inst.operands[2];
12171 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
12172 }
12173 }
12174 else
12175 {
12176 /* Conversions without bitshift. */
12177 const char *enc[] =
12178 {
12179 "ftosis",
12180 "ftouis",
12181 "fsitos",
12182 "fuitos",
12183 "fcvtsd",
12184 "fcvtds",
12185 "ftosid",
12186 "ftouid",
12187 "fsitod",
12188 "fuitod"
12189 };
12190
12191 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12192 opname = enc[flavour];
12193 }
12194
12195 if (opname)
12196 do_vfp_nsyn_opcode (opname);
12197 }
12198
12199 static void
12200 do_vfp_nsyn_cvtz (void)
12201 {
12202 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
12203 int flavour = neon_cvt_flavour (rs);
12204 const char *enc[] =
12205 {
12206 "ftosizs",
12207 "ftouizs",
12208 NULL,
12209 NULL,
12210 NULL,
12211 NULL,
12212 "ftosizd",
12213 "ftouizd"
12214 };
12215
12216 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
12217 do_vfp_nsyn_opcode (enc[flavour]);
12218 }
12219
12220 static void
12221 do_neon_cvt (void)
12222 {
12223 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
12224 NS_FD, NS_DF, NS_FF, NS_NULL);
12225 int flavour = neon_cvt_flavour (rs);
12226
12227 /* VFP rather than Neon conversions. */
12228 if (flavour >= 4)
12229 {
12230 do_vfp_nsyn_cvt (rs, flavour);
12231 return;
12232 }
12233
12234 switch (rs)
12235 {
12236 case NS_DDI:
12237 case NS_QQI:
12238 {
12239 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12240 return;
12241
12242 /* Fixed-point conversion with #0 immediate is encoded as an
12243 integer conversion. */
12244 if (inst.operands[2].present && inst.operands[2].imm == 0)
12245 goto int_encode;
12246 unsigned immbits = 32 - inst.operands[2].imm;
12247 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
12248 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12249 if (flavour != -1)
12250 inst.instruction |= enctab[flavour];
12251 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12252 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12253 inst.instruction |= LOW4 (inst.operands[1].reg);
12254 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12255 inst.instruction |= neon_quad (rs) << 6;
12256 inst.instruction |= 1 << 21;
12257 inst.instruction |= immbits << 16;
12258
12259 inst.instruction = neon_dp_fixup (inst.instruction);
12260 }
12261 break;
12262
12263 case NS_DD:
12264 case NS_QQ:
12265 int_encode:
12266 {
12267 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
12268
12269 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12270
12271 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12272 return;
12273
12274 if (flavour != -1)
12275 inst.instruction |= enctab[flavour];
12276
12277 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12278 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12279 inst.instruction |= LOW4 (inst.operands[1].reg);
12280 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12281 inst.instruction |= neon_quad (rs) << 6;
12282 inst.instruction |= 2 << 18;
12283
12284 inst.instruction = neon_dp_fixup (inst.instruction);
12285 }
12286 break;
12287
12288 default:
12289 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
12290 do_vfp_nsyn_cvt (rs, flavour);
12291 }
12292 }
12293
12294 static void
12295 neon_move_immediate (void)
12296 {
12297 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
12298 struct neon_type_el et = neon_check_type (2, rs,
12299 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
12300 unsigned immlo, immhi = 0, immbits;
12301 int op, cmode;
12302
12303 constraint (et.type == NT_invtype,
12304 _("operand size must be specified for immediate VMOV"));
12305
12306 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
12307 op = (inst.instruction & (1 << 5)) != 0;
12308
12309 immlo = inst.operands[1].imm;
12310 if (inst.operands[1].regisimm)
12311 immhi = inst.operands[1].reg;
12312
12313 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
12314 _("immediate has bits set outside the operand size"));
12315
12316 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, &immbits, &op,
12317 et.size, et.type)) == FAIL)
12318 {
12319 /* Invert relevant bits only. */
12320 neon_invert_size (&immlo, &immhi, et.size);
12321 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
12322 with one or the other; those cases are caught by
12323 neon_cmode_for_move_imm. */
12324 op = !op;
12325 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, &immbits, &op,
12326 et.size, et.type)) == FAIL)
12327 {
12328 first_error (_("immediate out of range"));
12329 return;
12330 }
12331 }
12332
12333 inst.instruction &= ~(1 << 5);
12334 inst.instruction |= op << 5;
12335
12336 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12337 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12338 inst.instruction |= neon_quad (rs) << 6;
12339 inst.instruction |= cmode << 8;
12340
12341 neon_write_immbits (immbits);
12342 }
12343
12344 static void
12345 do_neon_mvn (void)
12346 {
12347 if (inst.operands[1].isreg)
12348 {
12349 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12350
12351 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12352 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12353 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12354 inst.instruction |= LOW4 (inst.operands[1].reg);
12355 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12356 inst.instruction |= neon_quad (rs) << 6;
12357 }
12358 else
12359 {
12360 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12361 neon_move_immediate ();
12362 }
12363
12364 inst.instruction = neon_dp_fixup (inst.instruction);
12365 }
12366
12367 /* Encode instructions of form:
12368
12369 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12370 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm |
12371
12372 */
12373
12374 static void
12375 neon_mixed_length (struct neon_type_el et, unsigned size)
12376 {
12377 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12378 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12379 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12380 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12381 inst.instruction |= LOW4 (inst.operands[2].reg);
12382 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12383 inst.instruction |= (et.type == NT_unsigned) << 24;
12384 inst.instruction |= neon_logbits (size) << 20;
12385
12386 inst.instruction = neon_dp_fixup (inst.instruction);
12387 }
12388
12389 static void
12390 do_neon_dyadic_long (void)
12391 {
12392 /* FIXME: Type checking for lengthening op. */
12393 struct neon_type_el et = neon_check_type (3, NS_QDD,
12394 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
12395 neon_mixed_length (et, et.size);
12396 }
12397
12398 static void
12399 do_neon_abal (void)
12400 {
12401 struct neon_type_el et = neon_check_type (3, NS_QDD,
12402 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
12403 neon_mixed_length (et, et.size);
12404 }
12405
12406 static void
12407 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
12408 {
12409 if (inst.operands[2].isscalar)
12410 {
12411 struct neon_type_el et = neon_check_type (3, NS_QDS,
12412 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
12413 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12414 neon_mul_mac (et, et.type == NT_unsigned);
12415 }
12416 else
12417 {
12418 struct neon_type_el et = neon_check_type (3, NS_QDD,
12419 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
12420 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12421 neon_mixed_length (et, et.size);
12422 }
12423 }
12424
12425 static void
12426 do_neon_mac_maybe_scalar_long (void)
12427 {
12428 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
12429 }
12430
12431 static void
12432 do_neon_dyadic_wide (void)
12433 {
12434 struct neon_type_el et = neon_check_type (3, NS_QQD,
12435 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
12436 neon_mixed_length (et, et.size);
12437 }
12438
12439 static void
12440 do_neon_dyadic_narrow (void)
12441 {
12442 struct neon_type_el et = neon_check_type (3, NS_QDD,
12443 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
12444 neon_mixed_length (et, et.size / 2);
12445 }
12446
12447 static void
12448 do_neon_mul_sat_scalar_long (void)
12449 {
12450 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
12451 }
12452
12453 static void
12454 do_neon_vmull (void)
12455 {
12456 if (inst.operands[2].isscalar)
12457 do_neon_mac_maybe_scalar_long ();
12458 else
12459 {
12460 struct neon_type_el et = neon_check_type (3, NS_QDD,
12461 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
12462 if (et.type == NT_poly)
12463 inst.instruction = NEON_ENC_POLY (inst.instruction);
12464 else
12465 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12466 /* For polynomial encoding, size field must be 0b00 and the U bit must be
12467 zero. Should be OK as-is. */
12468 neon_mixed_length (et, et.size);
12469 }
12470 }
12471
12472 static void
12473 do_neon_ext (void)
12474 {
12475 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
12476 struct neon_type_el et = neon_check_type (3, rs,
12477 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12478 unsigned imm = (inst.operands[3].imm * et.size) / 8;
12479 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12480 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12481 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12482 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12483 inst.instruction |= LOW4 (inst.operands[2].reg);
12484 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12485 inst.instruction |= neon_quad (rs) << 6;
12486 inst.instruction |= imm << 8;
12487
12488 inst.instruction = neon_dp_fixup (inst.instruction);
12489 }
12490
12491 static void
12492 do_neon_rev (void)
12493 {
12494 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12495 struct neon_type_el et = neon_check_type (2, rs,
12496 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12497 unsigned op = (inst.instruction >> 7) & 3;
12498 /* N (width of reversed regions) is encoded as part of the bitmask. We
12499 extract it here to check the elements to be reversed are smaller.
12500 Otherwise we'd get a reserved instruction. */
12501 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
12502 assert (elsize != 0);
12503 constraint (et.size >= elsize,
12504 _("elements must be smaller than reversal region"));
12505 neon_two_same (neon_quad (rs), 1, et.size);
12506 }
12507
12508 static void
12509 do_neon_dup (void)
12510 {
12511 if (inst.operands[1].isscalar)
12512 {
12513 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
12514 struct neon_type_el et = neon_check_type (2, rs,
12515 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12516 unsigned sizebits = et.size >> 3;
12517 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
12518 int logsize = neon_logbits (et.size);
12519 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
12520
12521 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
12522 return;
12523
12524 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12525 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12526 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12527 inst.instruction |= LOW4 (dm);
12528 inst.instruction |= HI1 (dm) << 5;
12529 inst.instruction |= neon_quad (rs) << 6;
12530 inst.instruction |= x << 17;
12531 inst.instruction |= sizebits << 16;
12532
12533 inst.instruction = neon_dp_fixup (inst.instruction);
12534 }
12535 else
12536 {
12537 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
12538 struct neon_type_el et = neon_check_type (2, rs,
12539 N_8 | N_16 | N_32 | N_KEY, N_EQK);
12540 /* Duplicate ARM register to lanes of vector. */
12541 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
12542 switch (et.size)
12543 {
12544 case 8: inst.instruction |= 0x400000; break;
12545 case 16: inst.instruction |= 0x000020; break;
12546 case 32: inst.instruction |= 0x000000; break;
12547 default: break;
12548 }
12549 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
12550 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
12551 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
12552 inst.instruction |= neon_quad (rs) << 21;
12553 /* The encoding for this instruction is identical for the ARM and Thumb
12554 variants, except for the condition field. */
12555 do_vfp_cond_or_thumb ();
12556 }
12557 }
12558
12559 /* VMOV has particularly many variations. It can be one of:
12560 0. VMOV<c><q> <Qd>, <Qm>
12561 1. VMOV<c><q> <Dd>, <Dm>
12562 (Register operations, which are VORR with Rm = Rn.)
12563 2. VMOV<c><q>.<dt> <Qd>, #<imm>
12564 3. VMOV<c><q>.<dt> <Dd>, #<imm>
12565 (Immediate loads.)
12566 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
12567 (ARM register to scalar.)
12568 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
12569 (Two ARM registers to vector.)
12570 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
12571 (Scalar to ARM register.)
12572 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
12573 (Vector to two ARM registers.)
12574 8. VMOV.F32 <Sd>, <Sm>
12575 9. VMOV.F64 <Dd>, <Dm>
12576 (VFP register moves.)
12577 10. VMOV.F32 <Sd>, #imm
12578 11. VMOV.F64 <Dd>, #imm
12579 (VFP float immediate load.)
12580 12. VMOV <Rd>, <Sm>
12581 (VFP single to ARM reg.)
12582 13. VMOV <Sd>, <Rm>
12583 (ARM reg to VFP single.)
12584 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
12585 (Two ARM regs to two VFP singles.)
12586 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
12587 (Two VFP singles to two ARM regs.)
12588
12589 These cases can be disambiguated using neon_select_shape, except cases 1/9
12590 and 3/11 which depend on the operand type too.
12591
12592 All the encoded bits are hardcoded by this function.
12593
12594 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
12595 Cases 5, 7 may be used with VFPv2 and above.
12596
12597 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
12598 can specify a type where it doesn't make sense to, and is ignored).
12599 */
12600
12601 static void
12602 do_neon_mov (void)
12603 {
12604 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
12605 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
12606 NS_NULL);
12607 struct neon_type_el et;
12608 const char *ldconst = 0;
12609
12610 switch (rs)
12611 {
12612 case NS_DD: /* case 1/9. */
12613 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
12614 /* It is not an error here if no type is given. */
12615 inst.error = NULL;
12616 if (et.type == NT_float && et.size == 64)
12617 {
12618 do_vfp_nsyn_opcode ("fcpyd");
12619 break;
12620 }
12621 /* fall through. */
12622
12623 case NS_QQ: /* case 0/1. */
12624 {
12625 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12626 return;
12627 /* The architecture manual I have doesn't explicitly state which
12628 value the U bit should have for register->register moves, but
12629 the equivalent VORR instruction has U = 0, so do that. */
12630 inst.instruction = 0x0200110;
12631 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12632 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12633 inst.instruction |= LOW4 (inst.operands[1].reg);
12634 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12635 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12636 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12637 inst.instruction |= neon_quad (rs) << 6;
12638
12639 inst.instruction = neon_dp_fixup (inst.instruction);
12640 }
12641 break;
12642
12643 case NS_DI: /* case 3/11. */
12644 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
12645 inst.error = NULL;
12646 if (et.type == NT_float && et.size == 64)
12647 {
12648 /* case 11 (fconstd). */
12649 ldconst = "fconstd";
12650 goto encode_fconstd;
12651 }
12652 /* fall through. */
12653
12654 case NS_QI: /* case 2/3. */
12655 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12656 return;
12657 inst.instruction = 0x0800010;
12658 neon_move_immediate ();
12659 inst.instruction = neon_dp_fixup (inst.instruction);
12660 break;
12661
12662 case NS_SR: /* case 4. */
12663 {
12664 unsigned bcdebits = 0;
12665 struct neon_type_el et = neon_check_type (2, NS_NULL,
12666 N_8 | N_16 | N_32 | N_KEY, N_EQK);
12667 int logsize = neon_logbits (et.size);
12668 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
12669 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
12670
12671 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
12672 _(BAD_FPU));
12673 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
12674 && et.size != 32, _(BAD_FPU));
12675 constraint (et.type == NT_invtype, _("bad type for scalar"));
12676 constraint (x >= 64 / et.size, _("scalar index out of range"));
12677
12678 switch (et.size)
12679 {
12680 case 8: bcdebits = 0x8; break;
12681 case 16: bcdebits = 0x1; break;
12682 case 32: bcdebits = 0x0; break;
12683 default: ;
12684 }
12685
12686 bcdebits |= x << logsize;
12687
12688 inst.instruction = 0xe000b10;
12689 do_vfp_cond_or_thumb ();
12690 inst.instruction |= LOW4 (dn) << 16;
12691 inst.instruction |= HI1 (dn) << 7;
12692 inst.instruction |= inst.operands[1].reg << 12;
12693 inst.instruction |= (bcdebits & 3) << 5;
12694 inst.instruction |= (bcdebits >> 2) << 21;
12695 }
12696 break;
12697
12698 case NS_DRR: /* case 5 (fmdrr). */
12699 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
12700 _(BAD_FPU));
12701
12702 inst.instruction = 0xc400b10;
12703 do_vfp_cond_or_thumb ();
12704 inst.instruction |= LOW4 (inst.operands[0].reg);
12705 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
12706 inst.instruction |= inst.operands[1].reg << 12;
12707 inst.instruction |= inst.operands[2].reg << 16;
12708 break;
12709
12710 case NS_RS: /* case 6. */
12711 {
12712 struct neon_type_el et = neon_check_type (2, NS_NULL,
12713 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
12714 unsigned logsize = neon_logbits (et.size);
12715 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
12716 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
12717 unsigned abcdebits = 0;
12718
12719 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
12720 _(BAD_FPU));
12721 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
12722 && et.size != 32, _(BAD_FPU));
12723 constraint (et.type == NT_invtype, _("bad type for scalar"));
12724 constraint (x >= 64 / et.size, _("scalar index out of range"));
12725
12726 switch (et.size)
12727 {
12728 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
12729 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
12730 case 32: abcdebits = 0x00; break;
12731 default: ;
12732 }
12733
12734 abcdebits |= x << logsize;
12735 inst.instruction = 0xe100b10;
12736 do_vfp_cond_or_thumb ();
12737 inst.instruction |= LOW4 (dn) << 16;
12738 inst.instruction |= HI1 (dn) << 7;
12739 inst.instruction |= inst.operands[0].reg << 12;
12740 inst.instruction |= (abcdebits & 3) << 5;
12741 inst.instruction |= (abcdebits >> 2) << 21;
12742 }
12743 break;
12744
12745 case NS_RRD: /* case 7 (fmrrd). */
12746 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
12747 _(BAD_FPU));
12748
12749 inst.instruction = 0xc500b10;
12750 do_vfp_cond_or_thumb ();
12751 inst.instruction |= inst.operands[0].reg << 12;
12752 inst.instruction |= inst.operands[1].reg << 16;
12753 inst.instruction |= LOW4 (inst.operands[2].reg);
12754 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12755 break;
12756
12757 case NS_FF: /* case 8 (fcpys). */
12758 do_vfp_nsyn_opcode ("fcpys");
12759 break;
12760
12761 case NS_FI: /* case 10 (fconsts). */
12762 ldconst = "fconsts";
12763 encode_fconstd:
12764 if (is_quarter_float (inst.operands[1].imm))
12765 {
12766 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
12767 do_vfp_nsyn_opcode (ldconst);
12768 }
12769 else
12770 first_error (_("immediate out of range"));
12771 break;
12772
12773 case NS_RF: /* case 12 (fmrs). */
12774 do_vfp_nsyn_opcode ("fmrs");
12775 break;
12776
12777 case NS_FR: /* case 13 (fmsr). */
12778 do_vfp_nsyn_opcode ("fmsr");
12779 break;
12780
12781 /* The encoders for the fmrrs and fmsrr instructions expect three operands
12782 (one of which is a list), but we have parsed four. Do some fiddling to
12783 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
12784 expect. */
12785 case NS_RRFF: /* case 14 (fmrrs). */
12786 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
12787 _("VFP registers must be adjacent"));
12788 inst.operands[2].imm = 2;
12789 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
12790 do_vfp_nsyn_opcode ("fmrrs");
12791 break;
12792
12793 case NS_FFRR: /* case 15 (fmsrr). */
12794 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
12795 _("VFP registers must be adjacent"));
12796 inst.operands[1] = inst.operands[2];
12797 inst.operands[2] = inst.operands[3];
12798 inst.operands[0].imm = 2;
12799 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
12800 do_vfp_nsyn_opcode ("fmsrr");
12801 break;
12802
12803 default:
12804 abort ();
12805 }
12806 }
12807
12808 static void
12809 do_neon_rshift_round_imm (void)
12810 {
12811 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12812 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
12813 int imm = inst.operands[2].imm;
12814
12815 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
12816 if (imm == 0)
12817 {
12818 inst.operands[2].present = 0;
12819 do_neon_mov ();
12820 return;
12821 }
12822
12823 constraint (imm < 1 || (unsigned)imm > et.size,
12824 _("immediate out of range for shift"));
12825 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
12826 et.size - imm);
12827 }
12828
12829 static void
12830 do_neon_movl (void)
12831 {
12832 struct neon_type_el et = neon_check_type (2, NS_QD,
12833 N_EQK | N_DBL, N_SU_32 | N_KEY);
12834 unsigned sizebits = et.size >> 3;
12835 inst.instruction |= sizebits << 19;
12836 neon_two_same (0, et.type == NT_unsigned, -1);
12837 }
12838
12839 static void
12840 do_neon_trn (void)
12841 {
12842 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12843 struct neon_type_el et = neon_check_type (2, rs,
12844 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12845 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12846 neon_two_same (neon_quad (rs), 1, et.size);
12847 }
12848
12849 static void
12850 do_neon_zip_uzp (void)
12851 {
12852 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12853 struct neon_type_el et = neon_check_type (2, rs,
12854 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12855 if (rs == NS_DD && et.size == 32)
12856 {
12857 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
12858 inst.instruction = N_MNEM_vtrn;
12859 do_neon_trn ();
12860 return;
12861 }
12862 neon_two_same (neon_quad (rs), 1, et.size);
12863 }
12864
12865 static void
12866 do_neon_sat_abs_neg (void)
12867 {
12868 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12869 struct neon_type_el et = neon_check_type (2, rs,
12870 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
12871 neon_two_same (neon_quad (rs), 1, et.size);
12872 }
12873
12874 static void
12875 do_neon_pair_long (void)
12876 {
12877 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12878 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
12879 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
12880 inst.instruction |= (et.type == NT_unsigned) << 7;
12881 neon_two_same (neon_quad (rs), 1, et.size);
12882 }
12883
12884 static void
12885 do_neon_recip_est (void)
12886 {
12887 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12888 struct neon_type_el et = neon_check_type (2, rs,
12889 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
12890 inst.instruction |= (et.type == NT_float) << 8;
12891 neon_two_same (neon_quad (rs), 1, et.size);
12892 }
12893
12894 static void
12895 do_neon_cls (void)
12896 {
12897 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12898 struct neon_type_el et = neon_check_type (2, rs,
12899 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
12900 neon_two_same (neon_quad (rs), 1, et.size);
12901 }
12902
12903 static void
12904 do_neon_clz (void)
12905 {
12906 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12907 struct neon_type_el et = neon_check_type (2, rs,
12908 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
12909 neon_two_same (neon_quad (rs), 1, et.size);
12910 }
12911
12912 static void
12913 do_neon_cnt (void)
12914 {
12915 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12916 struct neon_type_el et = neon_check_type (2, rs,
12917 N_EQK | N_INT, N_8 | N_KEY);
12918 neon_two_same (neon_quad (rs), 1, et.size);
12919 }
12920
12921 static void
12922 do_neon_swp (void)
12923 {
12924 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12925 neon_two_same (neon_quad (rs), 1, -1);
12926 }
12927
12928 static void
12929 do_neon_tbl_tbx (void)
12930 {
12931 unsigned listlenbits;
12932 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
12933
12934 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
12935 {
12936 first_error (_("bad list length for table lookup"));
12937 return;
12938 }
12939
12940 listlenbits = inst.operands[1].imm - 1;
12941 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12942 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12943 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12944 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12945 inst.instruction |= LOW4 (inst.operands[2].reg);
12946 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12947 inst.instruction |= listlenbits << 8;
12948
12949 inst.instruction = neon_dp_fixup (inst.instruction);
12950 }
12951
12952 static void
12953 do_neon_ldm_stm (void)
12954 {
12955 /* P, U and L bits are part of bitmask. */
12956 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
12957 unsigned offsetbits = inst.operands[1].imm * 2;
12958
12959 if (inst.operands[1].issingle)
12960 {
12961 do_vfp_nsyn_ldm_stm (is_dbmode);
12962 return;
12963 }
12964
12965 constraint (is_dbmode && !inst.operands[0].writeback,
12966 _("writeback (!) must be used for VLDMDB and VSTMDB"));
12967
12968 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
12969 _("register list must contain at least 1 and at most 16 "
12970 "registers"));
12971
12972 inst.instruction |= inst.operands[0].reg << 16;
12973 inst.instruction |= inst.operands[0].writeback << 21;
12974 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
12975 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
12976
12977 inst.instruction |= offsetbits;
12978
12979 do_vfp_cond_or_thumb ();
12980 }
12981
12982 static void
12983 do_neon_ldr_str (void)
12984 {
12985 int is_ldr = (inst.instruction & (1 << 20)) != 0;
12986
12987 if (inst.operands[0].issingle)
12988 {
12989 if (is_ldr)
12990 do_vfp_nsyn_opcode ("flds");
12991 else
12992 do_vfp_nsyn_opcode ("fsts");
12993 }
12994 else
12995 {
12996 if (is_ldr)
12997 do_vfp_nsyn_opcode ("fldd");
12998 else
12999 do_vfp_nsyn_opcode ("fstd");
13000 }
13001 }
13002
13003 /* "interleave" version also handles non-interleaving register VLD1/VST1
13004 instructions. */
13005
13006 static void
13007 do_neon_ld_st_interleave (void)
13008 {
13009 struct neon_type_el et = neon_check_type (1, NS_NULL,
13010 N_8 | N_16 | N_32 | N_64);
13011 unsigned alignbits = 0;
13012 unsigned idx;
13013 /* The bits in this table go:
13014 0: register stride of one (0) or two (1)
13015 1,2: register list length, minus one (1, 2, 3, 4).
13016 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
13017 We use -1 for invalid entries. */
13018 const int typetable[] =
13019 {
13020 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
13021 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
13022 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
13023 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
13024 };
13025 int typebits;
13026
13027 if (et.type == NT_invtype)
13028 return;
13029
13030 if (inst.operands[1].immisalign)
13031 switch (inst.operands[1].imm >> 8)
13032 {
13033 case 64: alignbits = 1; break;
13034 case 128:
13035 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13036 goto bad_alignment;
13037 alignbits = 2;
13038 break;
13039 case 256:
13040 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13041 goto bad_alignment;
13042 alignbits = 3;
13043 break;
13044 default:
13045 bad_alignment:
13046 first_error (_("bad alignment"));
13047 return;
13048 }
13049
13050 inst.instruction |= alignbits << 4;
13051 inst.instruction |= neon_logbits (et.size) << 6;
13052
13053 /* Bits [4:6] of the immediate in a list specifier encode register stride
13054 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
13055 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
13056 up the right value for "type" in a table based on this value and the given
13057 list style, then stick it back. */
13058 idx = ((inst.operands[0].imm >> 4) & 7)
13059 | (((inst.instruction >> 8) & 3) << 3);
13060
13061 typebits = typetable[idx];
13062
13063 constraint (typebits == -1, _("bad list type for instruction"));
13064
13065 inst.instruction &= ~0xf00;
13066 inst.instruction |= typebits << 8;
13067 }
13068
13069 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
13070 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
13071 otherwise. The variable arguments are a list of pairs of legal (size, align)
13072 values, terminated with -1. */
13073
13074 static int
13075 neon_alignment_bit (int size, int align, int *do_align, ...)
13076 {
13077 va_list ap;
13078 int result = FAIL, thissize, thisalign;
13079
13080 if (!inst.operands[1].immisalign)
13081 {
13082 *do_align = 0;
13083 return SUCCESS;
13084 }
13085
13086 va_start (ap, do_align);
13087
13088 do
13089 {
13090 thissize = va_arg (ap, int);
13091 if (thissize == -1)
13092 break;
13093 thisalign = va_arg (ap, int);
13094
13095 if (size == thissize && align == thisalign)
13096 result = SUCCESS;
13097 }
13098 while (result != SUCCESS);
13099
13100 va_end (ap);
13101
13102 if (result == SUCCESS)
13103 *do_align = 1;
13104 else
13105 first_error (_("unsupported alignment for instruction"));
13106
13107 return result;
13108 }
13109
13110 static void
13111 do_neon_ld_st_lane (void)
13112 {
13113 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
13114 int align_good, do_align = 0;
13115 int logsize = neon_logbits (et.size);
13116 int align = inst.operands[1].imm >> 8;
13117 int n = (inst.instruction >> 8) & 3;
13118 int max_el = 64 / et.size;
13119
13120 if (et.type == NT_invtype)
13121 return;
13122
13123 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
13124 _("bad list length"));
13125 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
13126 _("scalar index out of range"));
13127 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
13128 && et.size == 8,
13129 _("stride of 2 unavailable when element size is 8"));
13130
13131 switch (n)
13132 {
13133 case 0: /* VLD1 / VST1. */
13134 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
13135 32, 32, -1);
13136 if (align_good == FAIL)
13137 return;
13138 if (do_align)
13139 {
13140 unsigned alignbits = 0;
13141 switch (et.size)
13142 {
13143 case 16: alignbits = 0x1; break;
13144 case 32: alignbits = 0x3; break;
13145 default: ;
13146 }
13147 inst.instruction |= alignbits << 4;
13148 }
13149 break;
13150
13151 case 1: /* VLD2 / VST2. */
13152 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
13153 32, 64, -1);
13154 if (align_good == FAIL)
13155 return;
13156 if (do_align)
13157 inst.instruction |= 1 << 4;
13158 break;
13159
13160 case 2: /* VLD3 / VST3. */
13161 constraint (inst.operands[1].immisalign,
13162 _("can't use alignment with this instruction"));
13163 break;
13164
13165 case 3: /* VLD4 / VST4. */
13166 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13167 16, 64, 32, 64, 32, 128, -1);
13168 if (align_good == FAIL)
13169 return;
13170 if (do_align)
13171 {
13172 unsigned alignbits = 0;
13173 switch (et.size)
13174 {
13175 case 8: alignbits = 0x1; break;
13176 case 16: alignbits = 0x1; break;
13177 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
13178 default: ;
13179 }
13180 inst.instruction |= alignbits << 4;
13181 }
13182 break;
13183
13184 default: ;
13185 }
13186
13187 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
13188 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13189 inst.instruction |= 1 << (4 + logsize);
13190
13191 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
13192 inst.instruction |= logsize << 10;
13193 }
13194
13195 /* Encode single n-element structure to all lanes VLD<n> instructions. */
13196
13197 static void
13198 do_neon_ld_dup (void)
13199 {
13200 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
13201 int align_good, do_align = 0;
13202
13203 if (et.type == NT_invtype)
13204 return;
13205
13206 switch ((inst.instruction >> 8) & 3)
13207 {
13208 case 0: /* VLD1. */
13209 assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
13210 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13211 &do_align, 16, 16, 32, 32, -1);
13212 if (align_good == FAIL)
13213 return;
13214 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
13215 {
13216 case 1: break;
13217 case 2: inst.instruction |= 1 << 5; break;
13218 default: first_error (_("bad list length")); return;
13219 }
13220 inst.instruction |= neon_logbits (et.size) << 6;
13221 break;
13222
13223 case 1: /* VLD2. */
13224 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13225 &do_align, 8, 16, 16, 32, 32, 64, -1);
13226 if (align_good == FAIL)
13227 return;
13228 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
13229 _("bad list length"));
13230 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13231 inst.instruction |= 1 << 5;
13232 inst.instruction |= neon_logbits (et.size) << 6;
13233 break;
13234
13235 case 2: /* VLD3. */
13236 constraint (inst.operands[1].immisalign,
13237 _("can't use alignment with this instruction"));
13238 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
13239 _("bad list length"));
13240 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13241 inst.instruction |= 1 << 5;
13242 inst.instruction |= neon_logbits (et.size) << 6;
13243 break;
13244
13245 case 3: /* VLD4. */
13246 {
13247 int align = inst.operands[1].imm >> 8;
13248 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13249 16, 64, 32, 64, 32, 128, -1);
13250 if (align_good == FAIL)
13251 return;
13252 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
13253 _("bad list length"));
13254 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13255 inst.instruction |= 1 << 5;
13256 if (et.size == 32 && align == 128)
13257 inst.instruction |= 0x3 << 6;
13258 else
13259 inst.instruction |= neon_logbits (et.size) << 6;
13260 }
13261 break;
13262
13263 default: ;
13264 }
13265
13266 inst.instruction |= do_align << 4;
13267 }
13268
13269 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
13270 apart from bits [11:4]. */
13271
13272 static void
13273 do_neon_ldx_stx (void)
13274 {
13275 switch (NEON_LANE (inst.operands[0].imm))
13276 {
13277 case NEON_INTERLEAVE_LANES:
13278 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
13279 do_neon_ld_st_interleave ();
13280 break;
13281
13282 case NEON_ALL_LANES:
13283 inst.instruction = NEON_ENC_DUP (inst.instruction);
13284 do_neon_ld_dup ();
13285 break;
13286
13287 default:
13288 inst.instruction = NEON_ENC_LANE (inst.instruction);
13289 do_neon_ld_st_lane ();
13290 }
13291
13292 /* L bit comes from bit mask. */
13293 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13294 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13295 inst.instruction |= inst.operands[1].reg << 16;
13296
13297 if (inst.operands[1].postind)
13298 {
13299 int postreg = inst.operands[1].imm & 0xf;
13300 constraint (!inst.operands[1].immisreg,
13301 _("post-index must be a register"));
13302 constraint (postreg == 0xd || postreg == 0xf,
13303 _("bad register for post-index"));
13304 inst.instruction |= postreg;
13305 }
13306 else if (inst.operands[1].writeback)
13307 {
13308 inst.instruction |= 0xd;
13309 }
13310 else
13311 inst.instruction |= 0xf;
13312
13313 if (thumb_mode)
13314 inst.instruction |= 0xf9000000;
13315 else
13316 inst.instruction |= 0xf4000000;
13317 }
13318
13319 \f
13320 /* Overall per-instruction processing. */
13321
13322 /* We need to be able to fix up arbitrary expressions in some statements.
13323 This is so that we can handle symbols that are an arbitrary distance from
13324 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
13325 which returns part of an address in a form which will be valid for
13326 a data instruction. We do this by pushing the expression into a symbol
13327 in the expr_section, and creating a fix for that. */
13328
13329 static void
13330 fix_new_arm (fragS * frag,
13331 int where,
13332 short int size,
13333 expressionS * exp,
13334 int pc_rel,
13335 int reloc)
13336 {
13337 fixS * new_fix;
13338
13339 switch (exp->X_op)
13340 {
13341 case O_constant:
13342 case O_symbol:
13343 case O_add:
13344 case O_subtract:
13345 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
13346 break;
13347
13348 default:
13349 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
13350 pc_rel, reloc);
13351 break;
13352 }
13353
13354 /* Mark whether the fix is to a THUMB instruction, or an ARM
13355 instruction. */
13356 new_fix->tc_fix_data = thumb_mode;
13357 }
13358
13359 /* Create a frg for an instruction requiring relaxation. */
13360 static void
13361 output_relax_insn (void)
13362 {
13363 char * to;
13364 symbolS *sym;
13365 int offset;
13366
13367 #ifdef OBJ_ELF
13368 /* The size of the instruction is unknown, so tie the debug info to the
13369 start of the instruction. */
13370 dwarf2_emit_insn (0);
13371 #endif
13372
13373 switch (inst.reloc.exp.X_op)
13374 {
13375 case O_symbol:
13376 sym = inst.reloc.exp.X_add_symbol;
13377 offset = inst.reloc.exp.X_add_number;
13378 break;
13379 case O_constant:
13380 sym = NULL;
13381 offset = inst.reloc.exp.X_add_number;
13382 break;
13383 default:
13384 sym = make_expr_symbol (&inst.reloc.exp);
13385 offset = 0;
13386 break;
13387 }
13388 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
13389 inst.relax, sym, offset, NULL/*offset, opcode*/);
13390 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
13391 }
13392
13393 /* Write a 32-bit thumb instruction to buf. */
13394 static void
13395 put_thumb32_insn (char * buf, unsigned long insn)
13396 {
13397 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
13398 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
13399 }
13400
13401 static void
13402 output_inst (const char * str)
13403 {
13404 char * to = NULL;
13405
13406 if (inst.error)
13407 {
13408 as_bad ("%s -- `%s'", inst.error, str);
13409 return;
13410 }
13411 if (inst.relax) {
13412 output_relax_insn();
13413 return;
13414 }
13415 if (inst.size == 0)
13416 return;
13417
13418 to = frag_more (inst.size);
13419
13420 if (thumb_mode && (inst.size > THUMB_SIZE))
13421 {
13422 assert (inst.size == (2 * THUMB_SIZE));
13423 put_thumb32_insn (to, inst.instruction);
13424 }
13425 else if (inst.size > INSN_SIZE)
13426 {
13427 assert (inst.size == (2 * INSN_SIZE));
13428 md_number_to_chars (to, inst.instruction, INSN_SIZE);
13429 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
13430 }
13431 else
13432 md_number_to_chars (to, inst.instruction, inst.size);
13433
13434 if (inst.reloc.type != BFD_RELOC_UNUSED)
13435 fix_new_arm (frag_now, to - frag_now->fr_literal,
13436 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
13437 inst.reloc.type);
13438
13439 #ifdef OBJ_ELF
13440 dwarf2_emit_insn (inst.size);
13441 #endif
13442 }
13443
13444 /* Tag values used in struct asm_opcode's tag field. */
13445 enum opcode_tag
13446 {
13447 OT_unconditional, /* Instruction cannot be conditionalized.
13448 The ARM condition field is still 0xE. */
13449 OT_unconditionalF, /* Instruction cannot be conditionalized
13450 and carries 0xF in its ARM condition field. */
13451 OT_csuffix, /* Instruction takes a conditional suffix. */
13452 OT_csuffixF, /* Some forms of the instruction take a conditional
13453 suffix, others place 0xF where the condition field
13454 would be. */
13455 OT_cinfix3, /* Instruction takes a conditional infix,
13456 beginning at character index 3. (In
13457 unified mode, it becomes a suffix.) */
13458 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
13459 tsts, cmps, cmns, and teqs. */
13460 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
13461 character index 3, even in unified mode. Used for
13462 legacy instructions where suffix and infix forms
13463 may be ambiguous. */
13464 OT_csuf_or_in3, /* Instruction takes either a conditional
13465 suffix or an infix at character index 3. */
13466 OT_odd_infix_unc, /* This is the unconditional variant of an
13467 instruction that takes a conditional infix
13468 at an unusual position. In unified mode,
13469 this variant will accept a suffix. */
13470 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
13471 are the conditional variants of instructions that
13472 take conditional infixes in unusual positions.
13473 The infix appears at character index
13474 (tag - OT_odd_infix_0). These are not accepted
13475 in unified mode. */
13476 };
13477
13478 /* Subroutine of md_assemble, responsible for looking up the primary
13479 opcode from the mnemonic the user wrote. STR points to the
13480 beginning of the mnemonic.
13481
13482 This is not simply a hash table lookup, because of conditional
13483 variants. Most instructions have conditional variants, which are
13484 expressed with a _conditional affix_ to the mnemonic. If we were
13485 to encode each conditional variant as a literal string in the opcode
13486 table, it would have approximately 20,000 entries.
13487
13488 Most mnemonics take this affix as a suffix, and in unified syntax,
13489 'most' is upgraded to 'all'. However, in the divided syntax, some
13490 instructions take the affix as an infix, notably the s-variants of
13491 the arithmetic instructions. Of those instructions, all but six
13492 have the infix appear after the third character of the mnemonic.
13493
13494 Accordingly, the algorithm for looking up primary opcodes given
13495 an identifier is:
13496
13497 1. Look up the identifier in the opcode table.
13498 If we find a match, go to step U.
13499
13500 2. Look up the last two characters of the identifier in the
13501 conditions table. If we find a match, look up the first N-2
13502 characters of the identifier in the opcode table. If we
13503 find a match, go to step CE.
13504
13505 3. Look up the fourth and fifth characters of the identifier in
13506 the conditions table. If we find a match, extract those
13507 characters from the identifier, and look up the remaining
13508 characters in the opcode table. If we find a match, go
13509 to step CM.
13510
13511 4. Fail.
13512
13513 U. Examine the tag field of the opcode structure, in case this is
13514 one of the six instructions with its conditional infix in an
13515 unusual place. If it is, the tag tells us where to find the
13516 infix; look it up in the conditions table and set inst.cond
13517 accordingly. Otherwise, this is an unconditional instruction.
13518 Again set inst.cond accordingly. Return the opcode structure.
13519
13520 CE. Examine the tag field to make sure this is an instruction that
13521 should receive a conditional suffix. If it is not, fail.
13522 Otherwise, set inst.cond from the suffix we already looked up,
13523 and return the opcode structure.
13524
13525 CM. Examine the tag field to make sure this is an instruction that
13526 should receive a conditional infix after the third character.
13527 If it is not, fail. Otherwise, undo the edits to the current
13528 line of input and proceed as for case CE. */
13529
13530 static const struct asm_opcode *
13531 opcode_lookup (char **str)
13532 {
13533 char *end, *base;
13534 char *affix;
13535 const struct asm_opcode *opcode;
13536 const struct asm_cond *cond;
13537 char save[2];
13538
13539 /* Scan up to the end of the mnemonic, which must end in white space,
13540 '.' (in unified mode only), or end of string. */
13541 for (base = end = *str; *end != '\0'; end++)
13542 if (*end == ' ' || (unified_syntax && *end == '.'))
13543 break;
13544
13545 if (end == base)
13546 return 0;
13547
13548 /* Handle a possible width suffix and/or Neon type suffix. */
13549 if (end[0] == '.')
13550 {
13551 int offset = 2;
13552
13553 if (end[1] == 'w')
13554 inst.size_req = 4;
13555 else if (end[1] == 'n')
13556 inst.size_req = 2;
13557 else
13558 offset = 0;
13559
13560 inst.vectype.elems = 0;
13561
13562 *str = end + offset;
13563
13564 if (end[offset] == '.')
13565 {
13566 /* See if we have a Neon type suffix. */
13567 if (parse_neon_type (&inst.vectype, str) == FAIL)
13568 return 0;
13569 }
13570 else if (end[offset] != '\0' && end[offset] != ' ')
13571 return 0;
13572 }
13573 else
13574 *str = end;
13575
13576 /* Look for unaffixed or special-case affixed mnemonic. */
13577 opcode = hash_find_n (arm_ops_hsh, base, end - base);
13578 if (opcode)
13579 {
13580 /* step U */
13581 if (opcode->tag < OT_odd_infix_0)
13582 {
13583 inst.cond = COND_ALWAYS;
13584 return opcode;
13585 }
13586
13587 if (unified_syntax)
13588 as_warn (_("conditional infixes are deprecated in unified syntax"));
13589 affix = base + (opcode->tag - OT_odd_infix_0);
13590 cond = hash_find_n (arm_cond_hsh, affix, 2);
13591 assert (cond);
13592
13593 inst.cond = cond->value;
13594 return opcode;
13595 }
13596
13597 /* Cannot have a conditional suffix on a mnemonic of less than two
13598 characters. */
13599 if (end - base < 3)
13600 return 0;
13601
13602 /* Look for suffixed mnemonic. */
13603 affix = end - 2;
13604 cond = hash_find_n (arm_cond_hsh, affix, 2);
13605 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
13606 if (opcode && cond)
13607 {
13608 /* step CE */
13609 switch (opcode->tag)
13610 {
13611 case OT_cinfix3_legacy:
13612 /* Ignore conditional suffixes matched on infix only mnemonics. */
13613 break;
13614
13615 case OT_cinfix3:
13616 case OT_cinfix3_deprecated:
13617 case OT_odd_infix_unc:
13618 if (!unified_syntax)
13619 return 0;
13620 /* else fall through */
13621
13622 case OT_csuffix:
13623 case OT_csuffixF:
13624 case OT_csuf_or_in3:
13625 inst.cond = cond->value;
13626 return opcode;
13627
13628 case OT_unconditional:
13629 case OT_unconditionalF:
13630 if (thumb_mode)
13631 {
13632 inst.cond = cond->value;
13633 }
13634 else
13635 {
13636 /* delayed diagnostic */
13637 inst.error = BAD_COND;
13638 inst.cond = COND_ALWAYS;
13639 }
13640 return opcode;
13641
13642 default:
13643 return 0;
13644 }
13645 }
13646
13647 /* Cannot have a usual-position infix on a mnemonic of less than
13648 six characters (five would be a suffix). */
13649 if (end - base < 6)
13650 return 0;
13651
13652 /* Look for infixed mnemonic in the usual position. */
13653 affix = base + 3;
13654 cond = hash_find_n (arm_cond_hsh, affix, 2);
13655 if (!cond)
13656 return 0;
13657
13658 memcpy (save, affix, 2);
13659 memmove (affix, affix + 2, (end - affix) - 2);
13660 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
13661 memmove (affix + 2, affix, (end - affix) - 2);
13662 memcpy (affix, save, 2);
13663
13664 if (opcode
13665 && (opcode->tag == OT_cinfix3
13666 || opcode->tag == OT_cinfix3_deprecated
13667 || opcode->tag == OT_csuf_or_in3
13668 || opcode->tag == OT_cinfix3_legacy))
13669 {
13670 /* step CM */
13671 if (unified_syntax
13672 && (opcode->tag == OT_cinfix3
13673 || opcode->tag == OT_cinfix3_deprecated))
13674 as_warn (_("conditional infixes are deprecated in unified syntax"));
13675
13676 inst.cond = cond->value;
13677 return opcode;
13678 }
13679
13680 return 0;
13681 }
13682
13683 void
13684 md_assemble (char *str)
13685 {
13686 char *p = str;
13687 const struct asm_opcode * opcode;
13688
13689 /* Align the previous label if needed. */
13690 if (last_label_seen != NULL)
13691 {
13692 symbol_set_frag (last_label_seen, frag_now);
13693 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
13694 S_SET_SEGMENT (last_label_seen, now_seg);
13695 }
13696
13697 memset (&inst, '\0', sizeof (inst));
13698 inst.reloc.type = BFD_RELOC_UNUSED;
13699
13700 opcode = opcode_lookup (&p);
13701 if (!opcode)
13702 {
13703 /* It wasn't an instruction, but it might be a register alias of
13704 the form alias .req reg, or a Neon .dn/.qn directive. */
13705 if (!create_register_alias (str, p)
13706 && !create_neon_reg_alias (str, p))
13707 as_bad (_("bad instruction `%s'"), str);
13708
13709 return;
13710 }
13711
13712 if (opcode->tag == OT_cinfix3_deprecated)
13713 as_warn (_("s suffix on comparison instruction is deprecated"));
13714
13715 /* The value which unconditional instructions should have in place of the
13716 condition field. */
13717 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
13718
13719 if (thumb_mode)
13720 {
13721 arm_feature_set variant;
13722
13723 variant = cpu_variant;
13724 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
13725 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
13726 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
13727 /* Check that this instruction is supported for this CPU. */
13728 if (!opcode->tvariant
13729 || (thumb_mode == 1
13730 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
13731 {
13732 as_bad (_("selected processor does not support `%s'"), str);
13733 return;
13734 }
13735 if (inst.cond != COND_ALWAYS && !unified_syntax
13736 && opcode->tencode != do_t_branch)
13737 {
13738 as_bad (_("Thumb does not support conditional execution"));
13739 return;
13740 }
13741
13742 /* Check conditional suffixes. */
13743 if (current_it_mask)
13744 {
13745 int cond;
13746 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
13747 current_it_mask <<= 1;
13748 current_it_mask &= 0x1f;
13749 /* The BKPT instruction is unconditional even in an IT block. */
13750 if (!inst.error
13751 && cond != inst.cond && opcode->tencode != do_t_bkpt)
13752 {
13753 as_bad (_("incorrect condition in IT block"));
13754 return;
13755 }
13756 }
13757 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
13758 {
13759 as_bad (_("thumb conditional instrunction not in IT block"));
13760 return;
13761 }
13762
13763 mapping_state (MAP_THUMB);
13764 inst.instruction = opcode->tvalue;
13765
13766 if (!parse_operands (p, opcode->operands))
13767 opcode->tencode ();
13768
13769 /* Clear current_it_mask at the end of an IT block. */
13770 if (current_it_mask == 0x10)
13771 current_it_mask = 0;
13772
13773 if (!(inst.error || inst.relax))
13774 {
13775 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
13776 inst.size = (inst.instruction > 0xffff ? 4 : 2);
13777 if (inst.size_req && inst.size_req != inst.size)
13778 {
13779 as_bad (_("cannot honor width suffix -- `%s'"), str);
13780 return;
13781 }
13782 }
13783 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
13784 *opcode->tvariant);
13785 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
13786 set those bits when Thumb-2 32-bit instructions are seen. ie.
13787 anything other than bl/blx.
13788 This is overly pessimistic for relaxable instructions. */
13789 if ((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
13790 || inst.relax)
13791 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
13792 arm_ext_v6t2);
13793 }
13794 else
13795 {
13796 /* Check that this instruction is supported for this CPU. */
13797 if (!opcode->avariant ||
13798 !ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant))
13799 {
13800 as_bad (_("selected processor does not support `%s'"), str);
13801 return;
13802 }
13803 if (inst.size_req)
13804 {
13805 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
13806 return;
13807 }
13808
13809 mapping_state (MAP_ARM);
13810 inst.instruction = opcode->avalue;
13811 if (opcode->tag == OT_unconditionalF)
13812 inst.instruction |= 0xF << 28;
13813 else
13814 inst.instruction |= inst.cond << 28;
13815 inst.size = INSN_SIZE;
13816 if (!parse_operands (p, opcode->operands))
13817 opcode->aencode ();
13818 /* Arm mode bx is marked as both v4T and v5 because it's still required
13819 on a hypothetical non-thumb v5 core. */
13820 if (ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v4t)
13821 || ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v5))
13822 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
13823 else
13824 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
13825 *opcode->avariant);
13826 }
13827 output_inst (str);
13828 }
13829
13830 /* Various frobbings of labels and their addresses. */
13831
13832 void
13833 arm_start_line_hook (void)
13834 {
13835 last_label_seen = NULL;
13836 }
13837
13838 void
13839 arm_frob_label (symbolS * sym)
13840 {
13841 last_label_seen = sym;
13842
13843 ARM_SET_THUMB (sym, thumb_mode);
13844
13845 #if defined OBJ_COFF || defined OBJ_ELF
13846 ARM_SET_INTERWORK (sym, support_interwork);
13847 #endif
13848
13849 /* Note - do not allow local symbols (.Lxxx) to be labeled
13850 as Thumb functions. This is because these labels, whilst
13851 they exist inside Thumb code, are not the entry points for
13852 possible ARM->Thumb calls. Also, these labels can be used
13853 as part of a computed goto or switch statement. eg gcc
13854 can generate code that looks like this:
13855
13856 ldr r2, [pc, .Laaa]
13857 lsl r3, r3, #2
13858 ldr r2, [r3, r2]
13859 mov pc, r2
13860
13861 .Lbbb: .word .Lxxx
13862 .Lccc: .word .Lyyy
13863 ..etc...
13864 .Laaa: .word Lbbb
13865
13866 The first instruction loads the address of the jump table.
13867 The second instruction converts a table index into a byte offset.
13868 The third instruction gets the jump address out of the table.
13869 The fourth instruction performs the jump.
13870
13871 If the address stored at .Laaa is that of a symbol which has the
13872 Thumb_Func bit set, then the linker will arrange for this address
13873 to have the bottom bit set, which in turn would mean that the
13874 address computation performed by the third instruction would end
13875 up with the bottom bit set. Since the ARM is capable of unaligned
13876 word loads, the instruction would then load the incorrect address
13877 out of the jump table, and chaos would ensue. */
13878 if (label_is_thumb_function_name
13879 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
13880 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
13881 {
13882 /* When the address of a Thumb function is taken the bottom
13883 bit of that address should be set. This will allow
13884 interworking between Arm and Thumb functions to work
13885 correctly. */
13886
13887 THUMB_SET_FUNC (sym, 1);
13888
13889 label_is_thumb_function_name = FALSE;
13890 }
13891
13892 #ifdef OBJ_ELF
13893 dwarf2_emit_label (sym);
13894 #endif
13895 }
13896
13897 int
13898 arm_data_in_code (void)
13899 {
13900 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
13901 {
13902 *input_line_pointer = '/';
13903 input_line_pointer += 5;
13904 *input_line_pointer = 0;
13905 return 1;
13906 }
13907
13908 return 0;
13909 }
13910
13911 char *
13912 arm_canonicalize_symbol_name (char * name)
13913 {
13914 int len;
13915
13916 if (thumb_mode && (len = strlen (name)) > 5
13917 && streq (name + len - 5, "/data"))
13918 *(name + len - 5) = 0;
13919
13920 return name;
13921 }
13922 \f
13923 /* Table of all register names defined by default. The user can
13924 define additional names with .req. Note that all register names
13925 should appear in both upper and lowercase variants. Some registers
13926 also have mixed-case names. */
13927
13928 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
13929 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
13930 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
13931 #define REGSET(p,t) \
13932 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
13933 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
13934 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
13935 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
13936 #define REGSETH(p,t) \
13937 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
13938 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
13939 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
13940 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
13941 #define REGSET2(p,t) \
13942 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
13943 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
13944 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
13945 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
13946
13947 static const struct reg_entry reg_names[] =
13948 {
13949 /* ARM integer registers. */
13950 REGSET(r, RN), REGSET(R, RN),
13951
13952 /* ATPCS synonyms. */
13953 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
13954 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
13955 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
13956
13957 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
13958 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
13959 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
13960
13961 /* Well-known aliases. */
13962 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
13963 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
13964
13965 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
13966 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
13967
13968 /* Coprocessor numbers. */
13969 REGSET(p, CP), REGSET(P, CP),
13970
13971 /* Coprocessor register numbers. The "cr" variants are for backward
13972 compatibility. */
13973 REGSET(c, CN), REGSET(C, CN),
13974 REGSET(cr, CN), REGSET(CR, CN),
13975
13976 /* FPA registers. */
13977 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
13978 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
13979
13980 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
13981 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
13982
13983 /* VFP SP registers. */
13984 REGSET(s,VFS), REGSET(S,VFS),
13985 REGSETH(s,VFS), REGSETH(S,VFS),
13986
13987 /* VFP DP Registers. */
13988 REGSET(d,VFD), REGSET(D,VFD),
13989 /* Extra Neon DP registers. */
13990 REGSETH(d,VFD), REGSETH(D,VFD),
13991
13992 /* Neon QP registers. */
13993 REGSET2(q,NQ), REGSET2(Q,NQ),
13994
13995 /* VFP control registers. */
13996 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
13997 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
13998
13999 /* Maverick DSP coprocessor registers. */
14000 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
14001 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
14002
14003 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
14004 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
14005 REGDEF(dspsc,0,DSPSC),
14006
14007 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
14008 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
14009 REGDEF(DSPSC,0,DSPSC),
14010
14011 /* iWMMXt data registers - p0, c0-15. */
14012 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
14013
14014 /* iWMMXt control registers - p1, c0-3. */
14015 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
14016 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
14017 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
14018 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
14019
14020 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
14021 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
14022 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
14023 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
14024 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
14025
14026 /* XScale accumulator registers. */
14027 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
14028 };
14029 #undef REGDEF
14030 #undef REGNUM
14031 #undef REGSET
14032
14033 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
14034 within psr_required_here. */
14035 static const struct asm_psr psrs[] =
14036 {
14037 /* Backward compatibility notation. Note that "all" is no longer
14038 truly all possible PSR bits. */
14039 {"all", PSR_c | PSR_f},
14040 {"flg", PSR_f},
14041 {"ctl", PSR_c},
14042
14043 /* Individual flags. */
14044 {"f", PSR_f},
14045 {"c", PSR_c},
14046 {"x", PSR_x},
14047 {"s", PSR_s},
14048 /* Combinations of flags. */
14049 {"fs", PSR_f | PSR_s},
14050 {"fx", PSR_f | PSR_x},
14051 {"fc", PSR_f | PSR_c},
14052 {"sf", PSR_s | PSR_f},
14053 {"sx", PSR_s | PSR_x},
14054 {"sc", PSR_s | PSR_c},
14055 {"xf", PSR_x | PSR_f},
14056 {"xs", PSR_x | PSR_s},
14057 {"xc", PSR_x | PSR_c},
14058 {"cf", PSR_c | PSR_f},
14059 {"cs", PSR_c | PSR_s},
14060 {"cx", PSR_c | PSR_x},
14061 {"fsx", PSR_f | PSR_s | PSR_x},
14062 {"fsc", PSR_f | PSR_s | PSR_c},
14063 {"fxs", PSR_f | PSR_x | PSR_s},
14064 {"fxc", PSR_f | PSR_x | PSR_c},
14065 {"fcs", PSR_f | PSR_c | PSR_s},
14066 {"fcx", PSR_f | PSR_c | PSR_x},
14067 {"sfx", PSR_s | PSR_f | PSR_x},
14068 {"sfc", PSR_s | PSR_f | PSR_c},
14069 {"sxf", PSR_s | PSR_x | PSR_f},
14070 {"sxc", PSR_s | PSR_x | PSR_c},
14071 {"scf", PSR_s | PSR_c | PSR_f},
14072 {"scx", PSR_s | PSR_c | PSR_x},
14073 {"xfs", PSR_x | PSR_f | PSR_s},
14074 {"xfc", PSR_x | PSR_f | PSR_c},
14075 {"xsf", PSR_x | PSR_s | PSR_f},
14076 {"xsc", PSR_x | PSR_s | PSR_c},
14077 {"xcf", PSR_x | PSR_c | PSR_f},
14078 {"xcs", PSR_x | PSR_c | PSR_s},
14079 {"cfs", PSR_c | PSR_f | PSR_s},
14080 {"cfx", PSR_c | PSR_f | PSR_x},
14081 {"csf", PSR_c | PSR_s | PSR_f},
14082 {"csx", PSR_c | PSR_s | PSR_x},
14083 {"cxf", PSR_c | PSR_x | PSR_f},
14084 {"cxs", PSR_c | PSR_x | PSR_s},
14085 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
14086 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
14087 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
14088 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
14089 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
14090 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
14091 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
14092 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
14093 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
14094 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
14095 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
14096 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
14097 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
14098 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
14099 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
14100 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
14101 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
14102 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
14103 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
14104 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
14105 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
14106 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
14107 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
14108 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
14109 };
14110
14111 /* Table of V7M psr names. */
14112 static const struct asm_psr v7m_psrs[] =
14113 {
14114 {"apsr", 0 },
14115 {"iapsr", 1 },
14116 {"eapsr", 2 },
14117 {"psr", 3 },
14118 {"ipsr", 5 },
14119 {"epsr", 6 },
14120 {"iepsr", 7 },
14121 {"msp", 8 },
14122 {"psp", 9 },
14123 {"primask", 16},
14124 {"basepri", 17},
14125 {"basepri_max", 18},
14126 {"faultmask", 19},
14127 {"control", 20}
14128 };
14129
14130 /* Table of all shift-in-operand names. */
14131 static const struct asm_shift_name shift_names [] =
14132 {
14133 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
14134 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
14135 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
14136 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
14137 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
14138 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
14139 };
14140
14141 /* Table of all explicit relocation names. */
14142 #ifdef OBJ_ELF
14143 static struct reloc_entry reloc_names[] =
14144 {
14145 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
14146 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
14147 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
14148 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
14149 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
14150 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
14151 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
14152 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
14153 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
14154 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
14155 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
14156 };
14157 #endif
14158
14159 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
14160 static const struct asm_cond conds[] =
14161 {
14162 {"eq", 0x0},
14163 {"ne", 0x1},
14164 {"cs", 0x2}, {"hs", 0x2},
14165 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
14166 {"mi", 0x4},
14167 {"pl", 0x5},
14168 {"vs", 0x6},
14169 {"vc", 0x7},
14170 {"hi", 0x8},
14171 {"ls", 0x9},
14172 {"ge", 0xa},
14173 {"lt", 0xb},
14174 {"gt", 0xc},
14175 {"le", 0xd},
14176 {"al", 0xe}
14177 };
14178
14179 static struct asm_barrier_opt barrier_opt_names[] =
14180 {
14181 { "sy", 0xf },
14182 { "un", 0x7 },
14183 { "st", 0xe },
14184 { "unst", 0x6 }
14185 };
14186
14187 /* Table of ARM-format instructions. */
14188
14189 /* Macros for gluing together operand strings. N.B. In all cases
14190 other than OPS0, the trailing OP_stop comes from default
14191 zero-initialization of the unspecified elements of the array. */
14192 #define OPS0() { OP_stop, }
14193 #define OPS1(a) { OP_##a, }
14194 #define OPS2(a,b) { OP_##a,OP_##b, }
14195 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
14196 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
14197 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
14198 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
14199
14200 /* These macros abstract out the exact format of the mnemonic table and
14201 save some repeated characters. */
14202
14203 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
14204 #define TxCE(mnem, op, top, nops, ops, ae, te) \
14205 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
14206 THUMB_VARIANT, do_##ae, do_##te }
14207
14208 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
14209 a T_MNEM_xyz enumerator. */
14210 #define TCE(mnem, aop, top, nops, ops, ae, te) \
14211 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
14212 #define tCE(mnem, aop, top, nops, ops, ae, te) \
14213 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14214
14215 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
14216 infix after the third character. */
14217 #define TxC3(mnem, op, top, nops, ops, ae, te) \
14218 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
14219 THUMB_VARIANT, do_##ae, do_##te }
14220 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
14221 { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
14222 THUMB_VARIANT, do_##ae, do_##te }
14223 #define TC3(mnem, aop, top, nops, ops, ae, te) \
14224 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
14225 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
14226 TxC3w(mnem, aop, 0x##top, nops, ops, ae, te)
14227 #define tC3(mnem, aop, top, nops, ops, ae, te) \
14228 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14229 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
14230 TxC3w(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14231
14232 /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
14233 appear in the condition table. */
14234 #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
14235 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14236 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
14237
14238 #define TxCM(m1, m2, op, top, nops, ops, ae, te) \
14239 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
14240 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
14241 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
14242 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
14243 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
14244 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
14245 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
14246 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
14247 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
14248 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
14249 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
14250 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
14251 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
14252 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
14253 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
14254 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
14255 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
14256 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
14257 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
14258
14259 #define TCM(m1,m2, aop, top, nops, ops, ae, te) \
14260 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
14261 #define tCM(m1,m2, aop, top, nops, ops, ae, te) \
14262 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
14263
14264 /* Mnemonic that cannot be conditionalized. The ARM condition-code
14265 field is still 0xE. Many of the Thumb variants can be executed
14266 conditionally, so this is checked separately. */
14267 #define TUE(mnem, op, top, nops, ops, ae, te) \
14268 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
14269 THUMB_VARIANT, do_##ae, do_##te }
14270
14271 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
14272 condition code field. */
14273 #define TUF(mnem, op, top, nops, ops, ae, te) \
14274 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
14275 THUMB_VARIANT, do_##ae, do_##te }
14276
14277 /* ARM-only variants of all the above. */
14278 #define CE(mnem, op, nops, ops, ae) \
14279 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14280
14281 #define C3(mnem, op, nops, ops, ae) \
14282 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14283
14284 /* Legacy mnemonics that always have conditional infix after the third
14285 character. */
14286 #define CL(mnem, op, nops, ops, ae) \
14287 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14288 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14289
14290 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
14291 #define cCE(mnem, op, nops, ops, ae) \
14292 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14293
14294 /* Legacy coprocessor instructions where conditional infix and conditional
14295 suffix are ambiguous. For consistency this includes all FPA instructions,
14296 not just the potentially ambiguous ones. */
14297 #define cCL(mnem, op, nops, ops, ae) \
14298 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14299 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14300
14301 /* Coprocessor, takes either a suffix or a position-3 infix
14302 (for an FPA corner case). */
14303 #define C3E(mnem, op, nops, ops, ae) \
14304 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
14305 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14306
14307 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
14308 { #m1 #m2 #m3, OPS##nops ops, \
14309 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14310 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14311
14312 #define CM(m1, m2, op, nops, ops, ae) \
14313 xCM_(m1, , m2, op, nops, ops, ae), \
14314 xCM_(m1, eq, m2, op, nops, ops, ae), \
14315 xCM_(m1, ne, m2, op, nops, ops, ae), \
14316 xCM_(m1, cs, m2, op, nops, ops, ae), \
14317 xCM_(m1, hs, m2, op, nops, ops, ae), \
14318 xCM_(m1, cc, m2, op, nops, ops, ae), \
14319 xCM_(m1, ul, m2, op, nops, ops, ae), \
14320 xCM_(m1, lo, m2, op, nops, ops, ae), \
14321 xCM_(m1, mi, m2, op, nops, ops, ae), \
14322 xCM_(m1, pl, m2, op, nops, ops, ae), \
14323 xCM_(m1, vs, m2, op, nops, ops, ae), \
14324 xCM_(m1, vc, m2, op, nops, ops, ae), \
14325 xCM_(m1, hi, m2, op, nops, ops, ae), \
14326 xCM_(m1, ls, m2, op, nops, ops, ae), \
14327 xCM_(m1, ge, m2, op, nops, ops, ae), \
14328 xCM_(m1, lt, m2, op, nops, ops, ae), \
14329 xCM_(m1, gt, m2, op, nops, ops, ae), \
14330 xCM_(m1, le, m2, op, nops, ops, ae), \
14331 xCM_(m1, al, m2, op, nops, ops, ae)
14332
14333 #define UE(mnem, op, nops, ops, ae) \
14334 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14335
14336 #define UF(mnem, op, nops, ops, ae) \
14337 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14338
14339 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
14340 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
14341 use the same encoding function for each. */
14342 #define NUF(mnem, op, nops, ops, enc) \
14343 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
14344 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14345
14346 /* Neon data processing, version which indirects through neon_enc_tab for
14347 the various overloaded versions of opcodes. */
14348 #define nUF(mnem, op, nops, ops, enc) \
14349 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \
14350 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14351
14352 /* Neon insn with conditional suffix for the ARM version, non-overloaded
14353 version. */
14354 #define NCE_tag(mnem, op, nops, ops, enc, tag) \
14355 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
14356 THUMB_VARIANT, do_##enc, do_##enc }
14357
14358 #define NCE(mnem, op, nops, ops, enc) \
14359 NCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14360
14361 #define NCEF(mnem, op, nops, ops, enc) \
14362 NCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14363
14364 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
14365 #define nCE_tag(mnem, op, nops, ops, enc, tag) \
14366 { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \
14367 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14368
14369 #define nCE(mnem, op, nops, ops, enc) \
14370 nCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14371
14372 #define nCEF(mnem, op, nops, ops, enc) \
14373 nCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14374
14375 #define do_0 0
14376
14377 /* Thumb-only, unconditional. */
14378 #define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
14379
14380 static const struct asm_opcode insns[] =
14381 {
14382 #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
14383 #define THUMB_VARIANT &arm_ext_v4t
14384 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
14385 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
14386 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
14387 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
14388 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
14389 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
14390 tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub),
14391 tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub),
14392 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
14393 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
14394 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
14395 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
14396 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
14397 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
14398 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
14399 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
14400
14401 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
14402 for setting PSR flag bits. They are obsolete in V6 and do not
14403 have Thumb equivalents. */
14404 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
14405 tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
14406 CL(tstp, 110f000, 2, (RR, SH), cmp),
14407 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
14408 tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
14409 CL(cmpp, 150f000, 2, (RR, SH), cmp),
14410 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
14411 tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
14412 CL(cmnp, 170f000, 2, (RR, SH), cmp),
14413
14414 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
14415 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
14416 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
14417 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
14418
14419 tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
14420 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
14421 tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst),
14422 tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
14423
14424 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14425 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14426 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14427 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14428 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14429 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14430
14431 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
14432 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
14433 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
14434 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
14435
14436 /* Pseudo ops. */
14437 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
14438 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
14439 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
14440
14441 /* Thumb-compatibility pseudo ops. */
14442 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
14443 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
14444 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
14445 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
14446 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
14447 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
14448 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
14449 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
14450 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
14451 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
14452 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
14453 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
14454
14455 #undef THUMB_VARIANT
14456 #define THUMB_VARIANT &arm_ext_v6
14457 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
14458
14459 /* V1 instructions with no Thumb analogue prior to V6T2. */
14460 #undef THUMB_VARIANT
14461 #define THUMB_VARIANT &arm_ext_v6t2
14462 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
14463 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
14464 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
14465 TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
14466 CL(teqp, 130f000, 2, (RR, SH), cmp),
14467
14468 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
14469 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
14470 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
14471 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
14472
14473 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14474 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14475
14476 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14477 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14478
14479 /* V1 instructions with no Thumb analogue at all. */
14480 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
14481 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
14482
14483 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
14484 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
14485 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
14486 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
14487 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
14488 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
14489 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
14490 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
14491
14492 #undef ARM_VARIANT
14493 #define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
14494 #undef THUMB_VARIANT
14495 #define THUMB_VARIANT &arm_ext_v4t
14496 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
14497 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
14498
14499 #undef THUMB_VARIANT
14500 #define THUMB_VARIANT &arm_ext_v6t2
14501 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
14502 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
14503
14504 /* Generic coprocessor instructions. */
14505 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
14506 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14507 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14508 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14509 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14510 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
14511 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
14512
14513 #undef ARM_VARIANT
14514 #define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
14515 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
14516 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
14517
14518 #undef ARM_VARIANT
14519 #define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
14520 TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
14521 TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
14522
14523 #undef ARM_VARIANT
14524 #define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
14525 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
14526 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
14527 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
14528 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
14529 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
14530 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
14531 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
14532 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
14533
14534 #undef ARM_VARIANT
14535 #define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
14536 #undef THUMB_VARIANT
14537 #define THUMB_VARIANT &arm_ext_v4t
14538 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14539 tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14540 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14541 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14542 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14543 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14544
14545 #undef ARM_VARIANT
14546 #define ARM_VARIANT &arm_ext_v4t_5
14547 /* ARM Architecture 4T. */
14548 /* Note: bx (and blx) are required on V5, even if the processor does
14549 not support Thumb. */
14550 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
14551
14552 #undef ARM_VARIANT
14553 #define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
14554 #undef THUMB_VARIANT
14555 #define THUMB_VARIANT &arm_ext_v5t
14556 /* Note: blx has 2 variants; the .value coded here is for
14557 BLX(2). Only this variant has conditional execution. */
14558 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
14559 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
14560
14561 #undef THUMB_VARIANT
14562 #define THUMB_VARIANT &arm_ext_v6t2
14563 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
14564 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14565 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14566 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14567 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14568 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
14569 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
14570 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
14571
14572 #undef ARM_VARIANT
14573 #define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
14574 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
14575 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
14576 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
14577 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
14578
14579 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
14580 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
14581
14582 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
14583 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
14584 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
14585 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
14586
14587 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14588 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14589 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14590 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14591
14592 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14593 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14594
14595 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
14596 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
14597 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
14598 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
14599
14600 #undef ARM_VARIANT
14601 #define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
14602 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
14603 TC3(ldrd, 00000d0, e9500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
14604 TC3(strd, 00000f0, e9400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
14605
14606 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
14607 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
14608
14609 #undef ARM_VARIANT
14610 #define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
14611 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
14612
14613 #undef ARM_VARIANT
14614 #define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
14615 #undef THUMB_VARIANT
14616 #define THUMB_VARIANT &arm_ext_v6
14617 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
14618 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
14619 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
14620 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
14621 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
14622 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
14623 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
14624 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
14625 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
14626 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
14627
14628 #undef THUMB_VARIANT
14629 #define THUMB_VARIANT &arm_ext_v6t2
14630 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
14631 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
14632 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
14633
14634 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
14635 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
14636
14637 /* ARM V6 not included in V7M (eg. integer SIMD). */
14638 #undef THUMB_VARIANT
14639 #define THUMB_VARIANT &arm_ext_v6_notm
14640 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
14641 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
14642 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
14643 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14644 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14645 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14646 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14647 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14648 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14649 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14650 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14651 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14652 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14653 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14654 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14655 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14656 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14657 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14658 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14659 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14660 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14661 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14662 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14663 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14664 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14665 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14666 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14667 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14668 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14669 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14670 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14671 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14672 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14673 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14674 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14675 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14676 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14677 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14678 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14679 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
14680 UF(rfeib, 9900a00, 1, (RRw), rfe),
14681 UF(rfeda, 8100a00, 1, (RRw), rfe),
14682 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
14683 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
14684 UF(rfefa, 9900a00, 1, (RRw), rfe),
14685 UF(rfeea, 8100a00, 1, (RRw), rfe),
14686 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
14687 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
14688 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
14689 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
14690 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
14691 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
14692 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
14693 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
14694 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
14695 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14696 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14697 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14698 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
14699 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
14700 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14701 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14702 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
14703 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
14704 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14705 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14706 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14707 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14708 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14709 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14710 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14711 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14712 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14713 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14714 TUF(srsia, 8cd0500, e980c000, 1, (I31w), srs, srs),
14715 UF(srsib, 9cd0500, 1, (I31w), srs),
14716 UF(srsda, 84d0500, 1, (I31w), srs),
14717 TUF(srsdb, 94d0500, e800c000, 1, (I31w), srs, srs),
14718 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
14719 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
14720 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
14721 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14722 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14723 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
14724
14725 #undef ARM_VARIANT
14726 #define ARM_VARIANT &arm_ext_v6k
14727 #undef THUMB_VARIANT
14728 #define THUMB_VARIANT &arm_ext_v6k
14729 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
14730 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
14731 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
14732 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
14733
14734 #undef THUMB_VARIANT
14735 #define THUMB_VARIANT &arm_ext_v6_notm
14736 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
14737 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
14738
14739 #undef THUMB_VARIANT
14740 #define THUMB_VARIANT &arm_ext_v6t2
14741 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
14742 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
14743 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
14744 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
14745 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
14746
14747 #undef ARM_VARIANT
14748 #define ARM_VARIANT &arm_ext_v6z
14749 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
14750
14751 #undef ARM_VARIANT
14752 #define ARM_VARIANT &arm_ext_v6t2
14753 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
14754 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
14755 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
14756 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
14757
14758 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
14759 TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
14760 TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
14761 TCE(rbit, 3ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
14762
14763 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
14764 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
14765 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
14766 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
14767
14768 UT(cbnz, b900, 2, (RR, EXP), t_czb),
14769 UT(cbz, b100, 2, (RR, EXP), t_czb),
14770 /* ARM does not really have an IT instruction. */
14771 TUE(it, 0, bf08, 1, (COND), it, t_it),
14772 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
14773 TUE(ite, 0, bf04, 1, (COND), it, t_it),
14774 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
14775 TUE(itet, 0, bf06, 1, (COND), it, t_it),
14776 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
14777 TUE(itee, 0, bf02, 1, (COND), it, t_it),
14778 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
14779 TUE(itett, 0, bf07, 1, (COND), it, t_it),
14780 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
14781 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
14782 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
14783 TUE(itete, 0, bf05, 1, (COND), it, t_it),
14784 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
14785 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
14786
14787 /* Thumb2 only instructions. */
14788 #undef ARM_VARIANT
14789 #define ARM_VARIANT NULL
14790
14791 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
14792 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
14793 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
14794 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
14795
14796 /* Thumb-2 hardware division instructions (R and M profiles only). */
14797 #undef THUMB_VARIANT
14798 #define THUMB_VARIANT &arm_ext_div
14799 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
14800 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
14801
14802 /* ARM V7 instructions. */
14803 #undef ARM_VARIANT
14804 #define ARM_VARIANT &arm_ext_v7
14805 #undef THUMB_VARIANT
14806 #define THUMB_VARIANT &arm_ext_v7
14807 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
14808 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
14809 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
14810 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
14811 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
14812
14813 #undef ARM_VARIANT
14814 #define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
14815 cCE(wfs, e200110, 1, (RR), rd),
14816 cCE(rfs, e300110, 1, (RR), rd),
14817 cCE(wfc, e400110, 1, (RR), rd),
14818 cCE(rfc, e500110, 1, (RR), rd),
14819
14820 cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
14821 cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
14822 cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
14823 cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
14824
14825 cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
14826 cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
14827 cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
14828 cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
14829
14830 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
14831 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
14832 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
14833 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
14834 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
14835 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
14836 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
14837 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
14838 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
14839 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
14840 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
14841 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
14842
14843 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
14844 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
14845 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
14846 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
14847 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
14848 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
14849 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
14850 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
14851 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
14852 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
14853 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
14854 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
14855
14856 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
14857 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
14858 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
14859 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
14860 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
14861 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
14862 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
14863 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
14864 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
14865 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
14866 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
14867 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
14868
14869 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
14870 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
14871 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
14872 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
14873 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
14874 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
14875 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
14876 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
14877 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
14878 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
14879 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
14880 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
14881
14882 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
14883 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
14884 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
14885 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
14886 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
14887 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
14888 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
14889 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
14890 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
14891 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
14892 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
14893 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
14894
14895 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
14896 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
14897 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
14898 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
14899 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
14900 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
14901 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
14902 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
14903 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
14904 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
14905 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
14906 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
14907
14908 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
14909 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
14910 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
14911 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
14912 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
14913 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
14914 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
14915 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
14916 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
14917 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
14918 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
14919 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
14920
14921 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
14922 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
14923 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
14924 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
14925 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
14926 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
14927 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
14928 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
14929 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
14930 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
14931 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
14932 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
14933
14934 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
14935 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
14936 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
14937 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
14938 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
14939 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
14940 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
14941 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
14942 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
14943 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
14944 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
14945 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
14946
14947 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
14948 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
14949 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
14950 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
14951 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
14952 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
14953 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
14954 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
14955 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
14956 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
14957 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
14958 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
14959
14960 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
14961 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
14962 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
14963 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
14964 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
14965 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
14966 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
14967 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
14968 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
14969 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
14970 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
14971 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
14972
14973 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
14974 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
14975 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
14976 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
14977 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
14978 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
14979 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
14980 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
14981 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
14982 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
14983 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
14984 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
14985
14986 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
14987 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
14988 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
14989 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
14990 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
14991 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
14992 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
14993 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
14994 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
14995 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
14996 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
14997 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
14998
14999 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
15000 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
15001 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
15002 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
15003 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
15004 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
15005 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
15006 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
15007 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
15008 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
15009 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
15010 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
15011
15012 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
15013 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
15014 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
15015 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
15016 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
15017 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
15018 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
15019 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
15020 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
15021 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
15022 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
15023 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
15024
15025 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
15026 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
15027 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
15028 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
15029 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
15030 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
15031 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
15032 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
15033 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
15034 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
15035 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
15036 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
15037
15038 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
15039 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
15040 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
15041 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
15042 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
15043 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15044 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15045 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15046 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
15047 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
15048 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
15049 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
15050
15051 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
15052 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
15053 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
15054 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
15055 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
15056 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15057 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15058 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15059 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
15060 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
15061 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
15062 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
15063
15064 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
15065 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
15066 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
15067 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
15068 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
15069 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15070 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15071 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15072 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
15073 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
15074 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
15075 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
15076
15077 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
15078 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
15079 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
15080 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
15081 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
15082 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15083 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15084 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15085 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
15086 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
15087 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
15088 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
15089
15090 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
15091 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
15092 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
15093 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
15094 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
15095 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15096 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15097 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15098 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
15099 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
15100 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
15101 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
15102
15103 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
15104 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
15105 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
15106 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
15107 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
15108 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15109 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15110 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15111 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
15112 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
15113 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
15114 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
15115
15116 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
15117 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
15118 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
15119 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
15120 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
15121 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15122 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15123 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15124 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
15125 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
15126 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
15127 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
15128
15129 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
15130 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
15131 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
15132 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
15133 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
15134 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15135 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15136 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15137 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
15138 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
15139 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
15140 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
15141
15142 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
15143 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
15144 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
15145 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
15146 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
15147 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15148 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15149 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15150 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
15151 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
15152 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
15153 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
15154
15155 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
15156 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
15157 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
15158 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
15159 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
15160 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15161 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15162 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15163 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
15164 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
15165 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
15166 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
15167
15168 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15169 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15170 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15171 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15172 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15173 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15174 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15175 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15176 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15177 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15178 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15179 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15180
15181 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15182 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15183 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15184 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15185 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15186 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15187 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15188 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15189 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15190 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15191 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15192 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15193
15194 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15195 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15196 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15197 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15198 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15199 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15200 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15201 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15202 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15203 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15204 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15205 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15206
15207 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
15208 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
15209 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
15210 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
15211
15212 cCL(flts, e000110, 2, (RF, RR), rn_rd),
15213 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
15214 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
15215 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
15216 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
15217 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
15218 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
15219 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
15220 cCL(flte, e080110, 2, (RF, RR), rn_rd),
15221 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
15222 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
15223 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
15224
15225 /* The implementation of the FIX instruction is broken on some
15226 assemblers, in that it accepts a precision specifier as well as a
15227 rounding specifier, despite the fact that this is meaningless.
15228 To be more compatible, we accept it as well, though of course it
15229 does not set any bits. */
15230 cCE(fix, e100110, 2, (RR, RF), rd_rm),
15231 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
15232 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
15233 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
15234 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
15235 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
15236 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
15237 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
15238 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
15239 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
15240 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
15241 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
15242 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
15243
15244 /* Instructions that were new with the real FPA, call them V2. */
15245 #undef ARM_VARIANT
15246 #define ARM_VARIANT &fpu_fpa_ext_v2
15247 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15248 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15249 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15250 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15251 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15252 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15253
15254 #undef ARM_VARIANT
15255 #define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
15256 /* Moves and type conversions. */
15257 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
15258 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
15259 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
15260 cCE(fmstat, ef1fa10, 0, (), noargs),
15261 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
15262 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
15263 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
15264 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15265 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
15266 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15267 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
15268 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
15269
15270 /* Memory operations. */
15271 cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15272 cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15273 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15274 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15275 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15276 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15277 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15278 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15279 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15280 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15281 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15282 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15283 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15284 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15285 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15286 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15287 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15288 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15289
15290 /* Monadic operations. */
15291 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
15292 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
15293 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
15294
15295 /* Dyadic operations. */
15296 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15297 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15298 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15299 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15300 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15301 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15302 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15303 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15304 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15305
15306 /* Comparisons. */
15307 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
15308 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
15309 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
15310 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
15311
15312 #undef ARM_VARIANT
15313 #define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
15314 /* Moves and type conversions. */
15315 cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15316 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15317 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15318 cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
15319 cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
15320 cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
15321 cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
15322 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15323 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
15324 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15325 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15326 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15327 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15328
15329 /* Memory operations. */
15330 cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
15331 cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
15332 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15333 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15334 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15335 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15336 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15337 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15338 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15339 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15340
15341 /* Monadic operations. */
15342 cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15343 cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15344 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15345
15346 /* Dyadic operations. */
15347 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15348 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15349 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15350 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15351 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15352 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15353 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15354 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15355 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15356
15357 /* Comparisons. */
15358 cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15359 cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd),
15360 cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15361 cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd),
15362
15363 #undef ARM_VARIANT
15364 #define ARM_VARIANT &fpu_vfp_ext_v2
15365 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
15366 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
15367 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
15368 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
15369
15370 /* Instructions which may belong to either the Neon or VFP instruction sets.
15371 Individual encoder functions perform additional architecture checks. */
15372 #undef ARM_VARIANT
15373 #define ARM_VARIANT &fpu_vfp_ext_v1xd
15374 #undef THUMB_VARIANT
15375 #define THUMB_VARIANT &fpu_vfp_ext_v1xd
15376 /* These mnemonics are unique to VFP. */
15377 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
15378 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
15379 nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15380 nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15381 nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15382 nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15383 nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15384 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
15385 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
15386 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
15387
15388 /* Mnemonics shared by Neon and VFP. */
15389 nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
15390 nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15391 nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15392
15393 nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15394 nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15395
15396 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15397 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15398
15399 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15400 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15401 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15402 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15403 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15404 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15405 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
15406 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
15407
15408 nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
15409
15410 /* NOTE: All VMOV encoding is special-cased! */
15411 NCE(vmov, 0, 1, (VMOV), neon_mov),
15412 NCE(vmovq, 0, 1, (VMOV), neon_mov),
15413
15414 #undef THUMB_VARIANT
15415 #define THUMB_VARIANT &fpu_neon_ext_v1
15416 #undef ARM_VARIANT
15417 #define ARM_VARIANT &fpu_neon_ext_v1
15418 /* Data processing with three registers of the same length. */
15419 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
15420 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
15421 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
15422 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15423 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15424 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15425 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15426 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15427 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15428 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
15429 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15430 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15431 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15432 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15433 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15434 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15435 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15436 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15437 /* If not immediate, fall back to neon_dyadic_i64_su.
15438 shl_imm should accept I8 I16 I32 I64,
15439 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
15440 nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
15441 nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
15442 nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
15443 nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
15444 /* Logic ops, types optional & ignored. */
15445 nUF(vand, vand, 2, (RNDQ, NILO), neon_logic),
15446 nUF(vandq, vand, 2, (RNQ, NILO), neon_logic),
15447 nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic),
15448 nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic),
15449 nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic),
15450 nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic),
15451 nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic),
15452 nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic),
15453 nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
15454 nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
15455 /* Bitfield ops, untyped. */
15456 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15457 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15458 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15459 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15460 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15461 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15462 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
15463 nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15464 nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15465 nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15466 nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15467 nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15468 nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15469 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
15470 back to neon_dyadic_if_su. */
15471 nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
15472 nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
15473 nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
15474 nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
15475 nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
15476 nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
15477 nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
15478 nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
15479 /* Comparison. Type I8 I16 I32 F32. Non-immediate -> neon_dyadic_if_i. */
15480 nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
15481 nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
15482 /* As above, D registers only. */
15483 nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
15484 nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
15485 /* Int and float variants, signedness unimportant. */
15486 /* If not scalar, fall back to neon_dyadic_if_i. */
15487 nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
15488 nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
15489 nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
15490 /* Add/sub take types I8 I16 I32 I64 F32. */
15491 nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
15492 nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
15493 /* vtst takes sizes 8, 16, 32. */
15494 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
15495 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
15496 /* VMUL takes I8 I16 I32 F32 P8. */
15497 nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
15498 /* VQD{R}MULH takes S16 S32. */
15499 nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
15500 nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
15501 nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
15502 nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
15503 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
15504 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
15505 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
15506 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
15507 NUF(vaclt, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
15508 NUF(vacltq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
15509 NUF(vacle, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
15510 NUF(vacleq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
15511 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
15512 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
15513 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
15514 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
15515
15516 /* Two address, int/float. Types S8 S16 S32 F32. */
15517 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
15518 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
15519
15520 /* Data processing with two registers and a shift amount. */
15521 /* Right shifts, and variants with rounding.
15522 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
15523 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
15524 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
15525 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
15526 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
15527 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
15528 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
15529 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
15530 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
15531 /* Shift and insert. Sizes accepted 8 16 32 64. */
15532 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
15533 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
15534 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
15535 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
15536 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
15537 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
15538 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
15539 /* Right shift immediate, saturating & narrowing, with rounding variants.
15540 Types accepted S16 S32 S64 U16 U32 U64. */
15541 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
15542 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
15543 /* As above, unsigned. Types accepted S16 S32 S64. */
15544 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
15545 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
15546 /* Right shift narrowing. Types accepted I16 I32 I64. */
15547 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
15548 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
15549 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
15550 nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll),
15551 /* CVT with optional immediate for fixed-point variant. */
15552 nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
15553
15554 nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
15555 nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
15556
15557 /* Data processing, three registers of different lengths. */
15558 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
15559 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
15560 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
15561 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
15562 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
15563 /* If not scalar, fall back to neon_dyadic_long.
15564 Vector types as above, scalar types S16 S32 U16 U32. */
15565 nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
15566 nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
15567 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
15568 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
15569 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
15570 /* Dyadic, narrowing insns. Types I16 I32 I64. */
15571 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
15572 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
15573 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
15574 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
15575 /* Saturating doubling multiplies. Types S16 S32. */
15576 nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
15577 nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
15578 nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
15579 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
15580 S16 S32 U16 U32. */
15581 nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
15582
15583 /* Extract. Size 8. */
15584 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I7), neon_ext),
15585 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I7), neon_ext),
15586
15587 /* Two registers, miscellaneous. */
15588 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
15589 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
15590 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
15591 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
15592 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
15593 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
15594 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
15595 /* Vector replicate. Sizes 8 16 32. */
15596 nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup),
15597 nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup),
15598 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
15599 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
15600 /* VMOVN. Types I16 I32 I64. */
15601 nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn),
15602 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
15603 nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn),
15604 /* VQMOVUN. Types S16 S32 S64. */
15605 nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun),
15606 /* VZIP / VUZP. Sizes 8 16 32. */
15607 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
15608 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
15609 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
15610 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
15611 /* VQABS / VQNEG. Types S8 S16 S32. */
15612 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
15613 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
15614 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
15615 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
15616 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
15617 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
15618 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
15619 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
15620 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
15621 /* Reciprocal estimates. Types U32 F32. */
15622 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
15623 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
15624 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
15625 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
15626 /* VCLS. Types S8 S16 S32. */
15627 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
15628 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
15629 /* VCLZ. Types I8 I16 I32. */
15630 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
15631 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
15632 /* VCNT. Size 8. */
15633 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
15634 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
15635 /* Two address, untyped. */
15636 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
15637 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
15638 /* VTRN. Sizes 8 16 32. */
15639 nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn),
15640 nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn),
15641
15642 /* Table lookup. Size 8. */
15643 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
15644 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
15645
15646 #undef THUMB_VARIANT
15647 #define THUMB_VARIANT &fpu_vfp_v3_or_neon_ext
15648 #undef ARM_VARIANT
15649 #define ARM_VARIANT &fpu_vfp_v3_or_neon_ext
15650 /* Neon element/structure load/store. */
15651 nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
15652 nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
15653 nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
15654 nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
15655 nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
15656 nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
15657 nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
15658 nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
15659
15660 #undef THUMB_VARIANT
15661 #define THUMB_VARIANT &fpu_vfp_ext_v3
15662 #undef ARM_VARIANT
15663 #define ARM_VARIANT &fpu_vfp_ext_v3
15664 cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const),
15665 cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const),
15666 cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
15667 cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
15668 cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
15669 cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
15670 cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
15671 cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
15672 cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
15673 cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
15674 cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
15675 cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
15676 cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
15677 cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
15678 cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
15679 cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
15680 cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
15681 cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
15682
15683 #undef THUMB_VARIANT
15684 #undef ARM_VARIANT
15685 #define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
15686 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
15687 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
15688 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
15689 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
15690 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
15691 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
15692 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
15693 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
15694
15695 #undef ARM_VARIANT
15696 #define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
15697 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
15698 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
15699 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
15700 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
15701 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
15702 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
15703 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
15704 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
15705 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
15706 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
15707 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
15708 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
15709 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
15710 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
15711 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
15712 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
15713 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
15714 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
15715 cCE(tmcr, e000110, 2, (RIWC, RR), rn_rd),
15716 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
15717 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
15718 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
15719 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
15720 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
15721 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
15722 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
15723 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
15724 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
15725 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
15726 cCE(tmrc, e100110, 2, (RR, RIWC), rd_rn),
15727 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
15728 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
15729 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
15730 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
15731 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
15732 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
15733 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
15734 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15735 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15736 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15737 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15738 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15739 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15740 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15741 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15742 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15743 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
15744 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15745 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15746 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15747 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15748 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15749 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15750 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15751 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15752 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15753 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15754 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15755 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15756 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15757 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15758 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15759 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15760 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15761 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15762 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15763 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
15764 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
15765 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
15766 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
15767 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15768 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15769 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15770 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15771 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15772 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15773 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15774 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15775 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15776 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15777 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15778 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15779 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15780 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15781 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15782 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15783 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15784 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15785 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
15786 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15787 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15788 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15789 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15790 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15791 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15792 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15793 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15794 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15795 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15796 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15797 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15798 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15799 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15800 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15801 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15802 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15803 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15804 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15805 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15806 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15807 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
15808 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15809 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15810 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15811 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15812 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15813 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15814 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15815 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15816 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15817 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15818 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15819 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15820 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15821 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15822 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15823 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15824 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15825 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15826 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
15827 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
15828 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
15829 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
15830 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15831 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15832 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15833 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15834 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15835 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15836 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15837 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15838 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15839 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
15840 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
15841 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
15842 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
15843 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
15844 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
15845 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15846 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15847 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15848 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
15849 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
15850 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
15851 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
15852 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
15853 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
15854 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15855 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15856 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15857 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15858 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
15859
15860 #undef ARM_VARIANT
15861 #define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
15862 cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
15863 cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
15864 cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
15865 cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
15866 cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
15867 cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
15868 cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
15869 cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
15870 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
15871 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
15872 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
15873 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
15874 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
15875 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
15876 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
15877 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
15878 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
15879 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
15880 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
15881 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
15882 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
15883 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
15884 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
15885 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
15886 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
15887 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
15888 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
15889 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
15890 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
15891 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
15892 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
15893 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
15894 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
15895 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
15896 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
15897 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
15898 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
15899 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
15900 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
15901 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
15902 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
15903 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
15904 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
15905 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
15906 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
15907 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
15908 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
15909 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
15910 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
15911 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
15912 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
15913 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
15914 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
15915 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
15916 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
15917 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
15918 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
15919 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
15920 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
15921 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
15922 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
15923 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
15924 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
15925 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
15926 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
15927 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
15928 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
15929 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
15930 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
15931 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
15932 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
15933 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
15934 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
15935 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
15936 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
15937 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
15938 };
15939 #undef ARM_VARIANT
15940 #undef THUMB_VARIANT
15941 #undef TCE
15942 #undef TCM
15943 #undef TUE
15944 #undef TUF
15945 #undef TCC
15946 #undef cCE
15947 #undef cCL
15948 #undef C3E
15949 #undef CE
15950 #undef CM
15951 #undef UE
15952 #undef UF
15953 #undef UT
15954 #undef NUF
15955 #undef nUF
15956 #undef NCE
15957 #undef nCE
15958 #undef OPS0
15959 #undef OPS1
15960 #undef OPS2
15961 #undef OPS3
15962 #undef OPS4
15963 #undef OPS5
15964 #undef OPS6
15965 #undef do_0
15966 \f
15967 /* MD interface: bits in the object file. */
15968
15969 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
15970 for use in the a.out file, and stores them in the array pointed to by buf.
15971 This knows about the endian-ness of the target machine and does
15972 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
15973 2 (short) and 4 (long) Floating numbers are put out as a series of
15974 LITTLENUMS (shorts, here at least). */
15975
15976 void
15977 md_number_to_chars (char * buf, valueT val, int n)
15978 {
15979 if (target_big_endian)
15980 number_to_chars_bigendian (buf, val, n);
15981 else
15982 number_to_chars_littleendian (buf, val, n);
15983 }
15984
15985 static valueT
15986 md_chars_to_number (char * buf, int n)
15987 {
15988 valueT result = 0;
15989 unsigned char * where = (unsigned char *) buf;
15990
15991 if (target_big_endian)
15992 {
15993 while (n--)
15994 {
15995 result <<= 8;
15996 result |= (*where++ & 255);
15997 }
15998 }
15999 else
16000 {
16001 while (n--)
16002 {
16003 result <<= 8;
16004 result |= (where[n] & 255);
16005 }
16006 }
16007
16008 return result;
16009 }
16010
16011 /* MD interface: Sections. */
16012
16013 /* Estimate the size of a frag before relaxing. Assume everything fits in
16014 2 bytes. */
16015
16016 int
16017 md_estimate_size_before_relax (fragS * fragp,
16018 segT segtype ATTRIBUTE_UNUSED)
16019 {
16020 fragp->fr_var = 2;
16021 return 2;
16022 }
16023
16024 /* Convert a machine dependent frag. */
16025
16026 void
16027 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
16028 {
16029 unsigned long insn;
16030 unsigned long old_op;
16031 char *buf;
16032 expressionS exp;
16033 fixS *fixp;
16034 int reloc_type;
16035 int pc_rel;
16036 int opcode;
16037
16038 buf = fragp->fr_literal + fragp->fr_fix;
16039
16040 old_op = bfd_get_16(abfd, buf);
16041 if (fragp->fr_symbol) {
16042 exp.X_op = O_symbol;
16043 exp.X_add_symbol = fragp->fr_symbol;
16044 } else {
16045 exp.X_op = O_constant;
16046 }
16047 exp.X_add_number = fragp->fr_offset;
16048 opcode = fragp->fr_subtype;
16049 switch (opcode)
16050 {
16051 case T_MNEM_ldr_pc:
16052 case T_MNEM_ldr_pc2:
16053 case T_MNEM_ldr_sp:
16054 case T_MNEM_str_sp:
16055 case T_MNEM_ldr:
16056 case T_MNEM_ldrb:
16057 case T_MNEM_ldrh:
16058 case T_MNEM_str:
16059 case T_MNEM_strb:
16060 case T_MNEM_strh:
16061 if (fragp->fr_var == 4)
16062 {
16063 insn = THUMB_OP32(opcode);
16064 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
16065 {
16066 insn |= (old_op & 0x700) << 4;
16067 }
16068 else
16069 {
16070 insn |= (old_op & 7) << 12;
16071 insn |= (old_op & 0x38) << 13;
16072 }
16073 insn |= 0x00000c00;
16074 put_thumb32_insn (buf, insn);
16075 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
16076 }
16077 else
16078 {
16079 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
16080 }
16081 pc_rel = (opcode == T_MNEM_ldr_pc2);
16082 break;
16083 case T_MNEM_adr:
16084 if (fragp->fr_var == 4)
16085 {
16086 insn = THUMB_OP32 (opcode);
16087 insn |= (old_op & 0xf0) << 4;
16088 put_thumb32_insn (buf, insn);
16089 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
16090 }
16091 else
16092 {
16093 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16094 exp.X_add_number -= 4;
16095 }
16096 pc_rel = 1;
16097 break;
16098 case T_MNEM_mov:
16099 case T_MNEM_movs:
16100 case T_MNEM_cmp:
16101 case T_MNEM_cmn:
16102 if (fragp->fr_var == 4)
16103 {
16104 int r0off = (opcode == T_MNEM_mov
16105 || opcode == T_MNEM_movs) ? 0 : 8;
16106 insn = THUMB_OP32 (opcode);
16107 insn = (insn & 0xe1ffffff) | 0x10000000;
16108 insn |= (old_op & 0x700) << r0off;
16109 put_thumb32_insn (buf, insn);
16110 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16111 }
16112 else
16113 {
16114 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
16115 }
16116 pc_rel = 0;
16117 break;
16118 case T_MNEM_b:
16119 if (fragp->fr_var == 4)
16120 {
16121 insn = THUMB_OP32(opcode);
16122 put_thumb32_insn (buf, insn);
16123 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
16124 }
16125 else
16126 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
16127 pc_rel = 1;
16128 break;
16129 case T_MNEM_bcond:
16130 if (fragp->fr_var == 4)
16131 {
16132 insn = THUMB_OP32(opcode);
16133 insn |= (old_op & 0xf00) << 14;
16134 put_thumb32_insn (buf, insn);
16135 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
16136 }
16137 else
16138 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
16139 pc_rel = 1;
16140 break;
16141 case T_MNEM_add_sp:
16142 case T_MNEM_add_pc:
16143 case T_MNEM_inc_sp:
16144 case T_MNEM_dec_sp:
16145 if (fragp->fr_var == 4)
16146 {
16147 /* ??? Choose between add and addw. */
16148 insn = THUMB_OP32 (opcode);
16149 insn |= (old_op & 0xf0) << 4;
16150 put_thumb32_insn (buf, insn);
16151 if (opcode == T_MNEM_add_pc)
16152 reloc_type = BFD_RELOC_ARM_T32_IMM12;
16153 else
16154 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16155 }
16156 else
16157 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16158 pc_rel = 0;
16159 break;
16160
16161 case T_MNEM_addi:
16162 case T_MNEM_addis:
16163 case T_MNEM_subi:
16164 case T_MNEM_subis:
16165 if (fragp->fr_var == 4)
16166 {
16167 insn = THUMB_OP32 (opcode);
16168 insn |= (old_op & 0xf0) << 4;
16169 insn |= (old_op & 0xf) << 16;
16170 put_thumb32_insn (buf, insn);
16171 if (insn & (1 << 20))
16172 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16173 else
16174 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16175 }
16176 else
16177 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16178 pc_rel = 0;
16179 break;
16180 default:
16181 abort();
16182 }
16183 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
16184 reloc_type);
16185 fixp->fx_file = fragp->fr_file;
16186 fixp->fx_line = fragp->fr_line;
16187 fragp->fr_fix += fragp->fr_var;
16188 }
16189
16190 /* Return the size of a relaxable immediate operand instruction.
16191 SHIFT and SIZE specify the form of the allowable immediate. */
16192 static int
16193 relax_immediate (fragS *fragp, int size, int shift)
16194 {
16195 offsetT offset;
16196 offsetT mask;
16197 offsetT low;
16198
16199 /* ??? Should be able to do better than this. */
16200 if (fragp->fr_symbol)
16201 return 4;
16202
16203 low = (1 << shift) - 1;
16204 mask = (1 << (shift + size)) - (1 << shift);
16205 offset = fragp->fr_offset;
16206 /* Force misaligned offsets to 32-bit variant. */
16207 if (offset & low)
16208 return -4;
16209 if (offset & ~mask)
16210 return 4;
16211 return 2;
16212 }
16213
16214 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
16215 load. */
16216 static int
16217 relax_adr (fragS *fragp, asection *sec)
16218 {
16219 addressT addr;
16220 offsetT val;
16221
16222 /* Assume worst case for symbols not known to be in the same section. */
16223 if (!S_IS_DEFINED(fragp->fr_symbol)
16224 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16225 return 4;
16226
16227 val = S_GET_VALUE(fragp->fr_symbol) + fragp->fr_offset;
16228 addr = fragp->fr_address + fragp->fr_fix;
16229 addr = (addr + 4) & ~3;
16230 /* Fix the insn as the 4-byte version if the target address is not
16231 sufficiently aligned. This is prevents an infinite loop when two
16232 instructions have contradictory range/alignment requirements. */
16233 if (val & 3)
16234 return -4;
16235 val -= addr;
16236 if (val < 0 || val > 1020)
16237 return 4;
16238 return 2;
16239 }
16240
16241 /* Return the size of a relaxable add/sub immediate instruction. */
16242 static int
16243 relax_addsub (fragS *fragp, asection *sec)
16244 {
16245 char *buf;
16246 int op;
16247
16248 buf = fragp->fr_literal + fragp->fr_fix;
16249 op = bfd_get_16(sec->owner, buf);
16250 if ((op & 0xf) == ((op >> 4) & 0xf))
16251 return relax_immediate (fragp, 8, 0);
16252 else
16253 return relax_immediate (fragp, 3, 0);
16254 }
16255
16256
16257 /* Return the size of a relaxable branch instruction. BITS is the
16258 size of the offset field in the narrow instruction. */
16259
16260 static int
16261 relax_branch (fragS *fragp, asection *sec, int bits)
16262 {
16263 addressT addr;
16264 offsetT val;
16265 offsetT limit;
16266
16267 /* Assume worst case for symbols not known to be in the same section. */
16268 if (!S_IS_DEFINED(fragp->fr_symbol)
16269 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16270 return 4;
16271
16272 val = S_GET_VALUE(fragp->fr_symbol) + fragp->fr_offset;
16273 addr = fragp->fr_address + fragp->fr_fix + 4;
16274 val -= addr;
16275
16276 /* Offset is a signed value *2 */
16277 limit = 1 << bits;
16278 if (val >= limit || val < -limit)
16279 return 4;
16280 return 2;
16281 }
16282
16283
16284 /* Relax a machine dependent frag. This returns the amount by which
16285 the current size of the frag should change. */
16286
16287 int
16288 arm_relax_frag (asection *sec, fragS *fragp, long stretch ATTRIBUTE_UNUSED)
16289 {
16290 int oldsize;
16291 int newsize;
16292
16293 oldsize = fragp->fr_var;
16294 switch (fragp->fr_subtype)
16295 {
16296 case T_MNEM_ldr_pc2:
16297 newsize = relax_adr(fragp, sec);
16298 break;
16299 case T_MNEM_ldr_pc:
16300 case T_MNEM_ldr_sp:
16301 case T_MNEM_str_sp:
16302 newsize = relax_immediate(fragp, 8, 2);
16303 break;
16304 case T_MNEM_ldr:
16305 case T_MNEM_str:
16306 newsize = relax_immediate(fragp, 5, 2);
16307 break;
16308 case T_MNEM_ldrh:
16309 case T_MNEM_strh:
16310 newsize = relax_immediate(fragp, 5, 1);
16311 break;
16312 case T_MNEM_ldrb:
16313 case T_MNEM_strb:
16314 newsize = relax_immediate(fragp, 5, 0);
16315 break;
16316 case T_MNEM_adr:
16317 newsize = relax_adr(fragp, sec);
16318 break;
16319 case T_MNEM_mov:
16320 case T_MNEM_movs:
16321 case T_MNEM_cmp:
16322 case T_MNEM_cmn:
16323 newsize = relax_immediate(fragp, 8, 0);
16324 break;
16325 case T_MNEM_b:
16326 newsize = relax_branch(fragp, sec, 11);
16327 break;
16328 case T_MNEM_bcond:
16329 newsize = relax_branch(fragp, sec, 8);
16330 break;
16331 case T_MNEM_add_sp:
16332 case T_MNEM_add_pc:
16333 newsize = relax_immediate (fragp, 8, 2);
16334 break;
16335 case T_MNEM_inc_sp:
16336 case T_MNEM_dec_sp:
16337 newsize = relax_immediate (fragp, 7, 2);
16338 break;
16339 case T_MNEM_addi:
16340 case T_MNEM_addis:
16341 case T_MNEM_subi:
16342 case T_MNEM_subis:
16343 newsize = relax_addsub (fragp, sec);
16344 break;
16345 default:
16346 abort();
16347 }
16348 if (newsize < 0)
16349 {
16350 fragp->fr_var = -newsize;
16351 md_convert_frag (sec->owner, sec, fragp);
16352 frag_wane(fragp);
16353 return -(newsize + oldsize);
16354 }
16355 fragp->fr_var = newsize;
16356 return newsize - oldsize;
16357 }
16358
16359 /* Round up a section size to the appropriate boundary. */
16360
16361 valueT
16362 md_section_align (segT segment ATTRIBUTE_UNUSED,
16363 valueT size)
16364 {
16365 #ifdef OBJ_ELF
16366 return size;
16367 #else
16368 /* Round all sects to multiple of 4. */
16369 return (size + 3) & ~3;
16370 #endif
16371 }
16372
16373 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
16374 of an rs_align_code fragment. */
16375
16376 void
16377 arm_handle_align (fragS * fragP)
16378 {
16379 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
16380 static char const thumb_noop[2] = { 0xc0, 0x46 };
16381 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
16382 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
16383
16384 int bytes, fix, noop_size;
16385 char * p;
16386 const char * noop;
16387
16388 if (fragP->fr_type != rs_align_code)
16389 return;
16390
16391 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
16392 p = fragP->fr_literal + fragP->fr_fix;
16393 fix = 0;
16394
16395 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
16396 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
16397
16398 if (fragP->tc_frag_data)
16399 {
16400 if (target_big_endian)
16401 noop = thumb_bigend_noop;
16402 else
16403 noop = thumb_noop;
16404 noop_size = sizeof (thumb_noop);
16405 }
16406 else
16407 {
16408 if (target_big_endian)
16409 noop = arm_bigend_noop;
16410 else
16411 noop = arm_noop;
16412 noop_size = sizeof (arm_noop);
16413 }
16414
16415 if (bytes & (noop_size - 1))
16416 {
16417 fix = bytes & (noop_size - 1);
16418 memset (p, 0, fix);
16419 p += fix;
16420 bytes -= fix;
16421 }
16422
16423 while (bytes >= noop_size)
16424 {
16425 memcpy (p, noop, noop_size);
16426 p += noop_size;
16427 bytes -= noop_size;
16428 fix += noop_size;
16429 }
16430
16431 fragP->fr_fix += fix;
16432 fragP->fr_var = noop_size;
16433 }
16434
16435 /* Called from md_do_align. Used to create an alignment
16436 frag in a code section. */
16437
16438 void
16439 arm_frag_align_code (int n, int max)
16440 {
16441 char * p;
16442
16443 /* We assume that there will never be a requirement
16444 to support alignments greater than 32 bytes. */
16445 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
16446 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
16447
16448 p = frag_var (rs_align_code,
16449 MAX_MEM_FOR_RS_ALIGN_CODE,
16450 1,
16451 (relax_substateT) max,
16452 (symbolS *) NULL,
16453 (offsetT) n,
16454 (char *) NULL);
16455 *p = 0;
16456 }
16457
16458 /* Perform target specific initialisation of a frag. */
16459
16460 void
16461 arm_init_frag (fragS * fragP)
16462 {
16463 /* Record whether this frag is in an ARM or a THUMB area. */
16464 fragP->tc_frag_data = thumb_mode;
16465 }
16466
16467 #ifdef OBJ_ELF
16468 /* When we change sections we need to issue a new mapping symbol. */
16469
16470 void
16471 arm_elf_change_section (void)
16472 {
16473 flagword flags;
16474 segment_info_type *seginfo;
16475
16476 /* Link an unlinked unwind index table section to the .text section. */
16477 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
16478 && elf_linked_to_section (now_seg) == NULL)
16479 elf_linked_to_section (now_seg) = text_section;
16480
16481 if (!SEG_NORMAL (now_seg))
16482 return;
16483
16484 flags = bfd_get_section_flags (stdoutput, now_seg);
16485
16486 /* We can ignore sections that only contain debug info. */
16487 if ((flags & SEC_ALLOC) == 0)
16488 return;
16489
16490 seginfo = seg_info (now_seg);
16491 mapstate = seginfo->tc_segment_info_data.mapstate;
16492 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
16493 }
16494
16495 int
16496 arm_elf_section_type (const char * str, size_t len)
16497 {
16498 if (len == 5 && strncmp (str, "exidx", 5) == 0)
16499 return SHT_ARM_EXIDX;
16500
16501 return -1;
16502 }
16503 \f
16504 /* Code to deal with unwinding tables. */
16505
16506 static void add_unwind_adjustsp (offsetT);
16507
16508 /* Cenerate and deferred unwind frame offset. */
16509
16510 static void
16511 flush_pending_unwind (void)
16512 {
16513 offsetT offset;
16514
16515 offset = unwind.pending_offset;
16516 unwind.pending_offset = 0;
16517 if (offset != 0)
16518 add_unwind_adjustsp (offset);
16519 }
16520
16521 /* Add an opcode to this list for this function. Two-byte opcodes should
16522 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
16523 order. */
16524
16525 static void
16526 add_unwind_opcode (valueT op, int length)
16527 {
16528 /* Add any deferred stack adjustment. */
16529 if (unwind.pending_offset)
16530 flush_pending_unwind ();
16531
16532 unwind.sp_restored = 0;
16533
16534 if (unwind.opcode_count + length > unwind.opcode_alloc)
16535 {
16536 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
16537 if (unwind.opcodes)
16538 unwind.opcodes = xrealloc (unwind.opcodes,
16539 unwind.opcode_alloc);
16540 else
16541 unwind.opcodes = xmalloc (unwind.opcode_alloc);
16542 }
16543 while (length > 0)
16544 {
16545 length--;
16546 unwind.opcodes[unwind.opcode_count] = op & 0xff;
16547 op >>= 8;
16548 unwind.opcode_count++;
16549 }
16550 }
16551
16552 /* Add unwind opcodes to adjust the stack pointer. */
16553
16554 static void
16555 add_unwind_adjustsp (offsetT offset)
16556 {
16557 valueT op;
16558
16559 if (offset > 0x200)
16560 {
16561 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
16562 char bytes[5];
16563 int n;
16564 valueT o;
16565
16566 /* Long form: 0xb2, uleb128. */
16567 /* This might not fit in a word so add the individual bytes,
16568 remembering the list is built in reverse order. */
16569 o = (valueT) ((offset - 0x204) >> 2);
16570 if (o == 0)
16571 add_unwind_opcode (0, 1);
16572
16573 /* Calculate the uleb128 encoding of the offset. */
16574 n = 0;
16575 while (o)
16576 {
16577 bytes[n] = o & 0x7f;
16578 o >>= 7;
16579 if (o)
16580 bytes[n] |= 0x80;
16581 n++;
16582 }
16583 /* Add the insn. */
16584 for (; n; n--)
16585 add_unwind_opcode (bytes[n - 1], 1);
16586 add_unwind_opcode (0xb2, 1);
16587 }
16588 else if (offset > 0x100)
16589 {
16590 /* Two short opcodes. */
16591 add_unwind_opcode (0x3f, 1);
16592 op = (offset - 0x104) >> 2;
16593 add_unwind_opcode (op, 1);
16594 }
16595 else if (offset > 0)
16596 {
16597 /* Short opcode. */
16598 op = (offset - 4) >> 2;
16599 add_unwind_opcode (op, 1);
16600 }
16601 else if (offset < 0)
16602 {
16603 offset = -offset;
16604 while (offset > 0x100)
16605 {
16606 add_unwind_opcode (0x7f, 1);
16607 offset -= 0x100;
16608 }
16609 op = ((offset - 4) >> 2) | 0x40;
16610 add_unwind_opcode (op, 1);
16611 }
16612 }
16613
16614 /* Finish the list of unwind opcodes for this function. */
16615 static void
16616 finish_unwind_opcodes (void)
16617 {
16618 valueT op;
16619
16620 if (unwind.fp_used)
16621 {
16622 /* Adjust sp as necessary. */
16623 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
16624 flush_pending_unwind ();
16625
16626 /* After restoring sp from the frame pointer. */
16627 op = 0x90 | unwind.fp_reg;
16628 add_unwind_opcode (op, 1);
16629 }
16630 else
16631 flush_pending_unwind ();
16632 }
16633
16634
16635 /* Start an exception table entry. If idx is nonzero this is an index table
16636 entry. */
16637
16638 static void
16639 start_unwind_section (const segT text_seg, int idx)
16640 {
16641 const char * text_name;
16642 const char * prefix;
16643 const char * prefix_once;
16644 const char * group_name;
16645 size_t prefix_len;
16646 size_t text_len;
16647 char * sec_name;
16648 size_t sec_name_len;
16649 int type;
16650 int flags;
16651 int linkonce;
16652
16653 if (idx)
16654 {
16655 prefix = ELF_STRING_ARM_unwind;
16656 prefix_once = ELF_STRING_ARM_unwind_once;
16657 type = SHT_ARM_EXIDX;
16658 }
16659 else
16660 {
16661 prefix = ELF_STRING_ARM_unwind_info;
16662 prefix_once = ELF_STRING_ARM_unwind_info_once;
16663 type = SHT_PROGBITS;
16664 }
16665
16666 text_name = segment_name (text_seg);
16667 if (streq (text_name, ".text"))
16668 text_name = "";
16669
16670 if (strncmp (text_name, ".gnu.linkonce.t.",
16671 strlen (".gnu.linkonce.t.")) == 0)
16672 {
16673 prefix = prefix_once;
16674 text_name += strlen (".gnu.linkonce.t.");
16675 }
16676
16677 prefix_len = strlen (prefix);
16678 text_len = strlen (text_name);
16679 sec_name_len = prefix_len + text_len;
16680 sec_name = xmalloc (sec_name_len + 1);
16681 memcpy (sec_name, prefix, prefix_len);
16682 memcpy (sec_name + prefix_len, text_name, text_len);
16683 sec_name[prefix_len + text_len] = '\0';
16684
16685 flags = SHF_ALLOC;
16686 linkonce = 0;
16687 group_name = 0;
16688
16689 /* Handle COMDAT group. */
16690 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
16691 {
16692 group_name = elf_group_name (text_seg);
16693 if (group_name == NULL)
16694 {
16695 as_bad ("Group section `%s' has no group signature",
16696 segment_name (text_seg));
16697 ignore_rest_of_line ();
16698 return;
16699 }
16700 flags |= SHF_GROUP;
16701 linkonce = 1;
16702 }
16703
16704 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
16705
16706 /* Set the setion link for index tables. */
16707 if (idx)
16708 elf_linked_to_section (now_seg) = text_seg;
16709 }
16710
16711
16712 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
16713 personality routine data. Returns zero, or the index table value for
16714 and inline entry. */
16715
16716 static valueT
16717 create_unwind_entry (int have_data)
16718 {
16719 int size;
16720 addressT where;
16721 char *ptr;
16722 /* The current word of data. */
16723 valueT data;
16724 /* The number of bytes left in this word. */
16725 int n;
16726
16727 finish_unwind_opcodes ();
16728
16729 /* Remember the current text section. */
16730 unwind.saved_seg = now_seg;
16731 unwind.saved_subseg = now_subseg;
16732
16733 start_unwind_section (now_seg, 0);
16734
16735 if (unwind.personality_routine == NULL)
16736 {
16737 if (unwind.personality_index == -2)
16738 {
16739 if (have_data)
16740 as_bad (_("handerdata in cantunwind frame"));
16741 return 1; /* EXIDX_CANTUNWIND. */
16742 }
16743
16744 /* Use a default personality routine if none is specified. */
16745 if (unwind.personality_index == -1)
16746 {
16747 if (unwind.opcode_count > 3)
16748 unwind.personality_index = 1;
16749 else
16750 unwind.personality_index = 0;
16751 }
16752
16753 /* Space for the personality routine entry. */
16754 if (unwind.personality_index == 0)
16755 {
16756 if (unwind.opcode_count > 3)
16757 as_bad (_("too many unwind opcodes for personality routine 0"));
16758
16759 if (!have_data)
16760 {
16761 /* All the data is inline in the index table. */
16762 data = 0x80;
16763 n = 3;
16764 while (unwind.opcode_count > 0)
16765 {
16766 unwind.opcode_count--;
16767 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
16768 n--;
16769 }
16770
16771 /* Pad with "finish" opcodes. */
16772 while (n--)
16773 data = (data << 8) | 0xb0;
16774
16775 return data;
16776 }
16777 size = 0;
16778 }
16779 else
16780 /* We get two opcodes "free" in the first word. */
16781 size = unwind.opcode_count - 2;
16782 }
16783 else
16784 /* An extra byte is required for the opcode count. */
16785 size = unwind.opcode_count + 1;
16786
16787 size = (size + 3) >> 2;
16788 if (size > 0xff)
16789 as_bad (_("too many unwind opcodes"));
16790
16791 frag_align (2, 0, 0);
16792 record_alignment (now_seg, 2);
16793 unwind.table_entry = expr_build_dot ();
16794
16795 /* Allocate the table entry. */
16796 ptr = frag_more ((size << 2) + 4);
16797 where = frag_now_fix () - ((size << 2) + 4);
16798
16799 switch (unwind.personality_index)
16800 {
16801 case -1:
16802 /* ??? Should this be a PLT generating relocation? */
16803 /* Custom personality routine. */
16804 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
16805 BFD_RELOC_ARM_PREL31);
16806
16807 where += 4;
16808 ptr += 4;
16809
16810 /* Set the first byte to the number of additional words. */
16811 data = size - 1;
16812 n = 3;
16813 break;
16814
16815 /* ABI defined personality routines. */
16816 case 0:
16817 /* Three opcodes bytes are packed into the first word. */
16818 data = 0x80;
16819 n = 3;
16820 break;
16821
16822 case 1:
16823 case 2:
16824 /* The size and first two opcode bytes go in the first word. */
16825 data = ((0x80 + unwind.personality_index) << 8) | size;
16826 n = 2;
16827 break;
16828
16829 default:
16830 /* Should never happen. */
16831 abort ();
16832 }
16833
16834 /* Pack the opcodes into words (MSB first), reversing the list at the same
16835 time. */
16836 while (unwind.opcode_count > 0)
16837 {
16838 if (n == 0)
16839 {
16840 md_number_to_chars (ptr, data, 4);
16841 ptr += 4;
16842 n = 4;
16843 data = 0;
16844 }
16845 unwind.opcode_count--;
16846 n--;
16847 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
16848 }
16849
16850 /* Finish off the last word. */
16851 if (n < 4)
16852 {
16853 /* Pad with "finish" opcodes. */
16854 while (n--)
16855 data = (data << 8) | 0xb0;
16856
16857 md_number_to_chars (ptr, data, 4);
16858 }
16859
16860 if (!have_data)
16861 {
16862 /* Add an empty descriptor if there is no user-specified data. */
16863 ptr = frag_more (4);
16864 md_number_to_chars (ptr, 0, 4);
16865 }
16866
16867 return 0;
16868 }
16869
16870 /* Convert REGNAME to a DWARF-2 register number. */
16871
16872 int
16873 tc_arm_regname_to_dw2regnum (char *regname)
16874 {
16875 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
16876
16877 if (reg == FAIL)
16878 return -1;
16879
16880 return reg;
16881 }
16882
16883 /* Initialize the DWARF-2 unwind information for this procedure. */
16884
16885 void
16886 tc_arm_frame_initial_instructions (void)
16887 {
16888 cfi_add_CFA_def_cfa (REG_SP, 0);
16889 }
16890 #endif /* OBJ_ELF */
16891
16892
16893 /* MD interface: Symbol and relocation handling. */
16894
16895 /* Return the address within the segment that a PC-relative fixup is
16896 relative to. For ARM, PC-relative fixups applied to instructions
16897 are generally relative to the location of the fixup plus 8 bytes.
16898 Thumb branches are offset by 4, and Thumb loads relative to PC
16899 require special handling. */
16900
16901 long
16902 md_pcrel_from_section (fixS * fixP, segT seg)
16903 {
16904 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
16905
16906 /* If this is pc-relative and we are going to emit a relocation
16907 then we just want to put out any pipeline compensation that the linker
16908 will need. Otherwise we want to use the calculated base.
16909 For WinCE we skip the bias for externals as well, since this
16910 is how the MS ARM-CE assembler behaves and we want to be compatible. */
16911 if (fixP->fx_pcrel
16912 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
16913 || (arm_force_relocation (fixP)
16914 #ifdef TE_WINCE
16915 && !S_IS_EXTERNAL (fixP->fx_addsy)
16916 #endif
16917 )))
16918 base = 0;
16919
16920 switch (fixP->fx_r_type)
16921 {
16922 /* PC relative addressing on the Thumb is slightly odd as the
16923 bottom two bits of the PC are forced to zero for the
16924 calculation. This happens *after* application of the
16925 pipeline offset. However, Thumb adrl already adjusts for
16926 this, so we need not do it again. */
16927 case BFD_RELOC_ARM_THUMB_ADD:
16928 return base & ~3;
16929
16930 case BFD_RELOC_ARM_THUMB_OFFSET:
16931 case BFD_RELOC_ARM_T32_OFFSET_IMM:
16932 case BFD_RELOC_ARM_T32_ADD_PC12:
16933 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
16934 return (base + 4) & ~3;
16935
16936 /* Thumb branches are simply offset by +4. */
16937 case BFD_RELOC_THUMB_PCREL_BRANCH7:
16938 case BFD_RELOC_THUMB_PCREL_BRANCH9:
16939 case BFD_RELOC_THUMB_PCREL_BRANCH12:
16940 case BFD_RELOC_THUMB_PCREL_BRANCH20:
16941 case BFD_RELOC_THUMB_PCREL_BRANCH23:
16942 case BFD_RELOC_THUMB_PCREL_BRANCH25:
16943 case BFD_RELOC_THUMB_PCREL_BLX:
16944 return base + 4;
16945
16946 /* ARM mode branches are offset by +8. However, the Windows CE
16947 loader expects the relocation not to take this into account. */
16948 case BFD_RELOC_ARM_PCREL_BRANCH:
16949 case BFD_RELOC_ARM_PCREL_CALL:
16950 case BFD_RELOC_ARM_PCREL_JUMP:
16951 case BFD_RELOC_ARM_PCREL_BLX:
16952 case BFD_RELOC_ARM_PLT32:
16953 #ifdef TE_WINCE
16954 /* When handling fixups immediately, because we have already
16955 discovered the value of a symbol, or the address of the frag involved
16956 we must account for the offset by +8, as the OS loader will never see the reloc.
16957 see fixup_segment() in write.c
16958 The S_IS_EXTERNAL test handles the case of global symbols.
16959 Those need the calculated base, not just the pipe compensation the linker will need. */
16960 if (fixP->fx_pcrel
16961 && fixP->fx_addsy != NULL
16962 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
16963 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
16964 return base + 8;
16965 return base;
16966 #else
16967 return base + 8;
16968 #endif
16969
16970 /* ARM mode loads relative to PC are also offset by +8. Unlike
16971 branches, the Windows CE loader *does* expect the relocation
16972 to take this into account. */
16973 case BFD_RELOC_ARM_OFFSET_IMM:
16974 case BFD_RELOC_ARM_OFFSET_IMM8:
16975 case BFD_RELOC_ARM_HWLITERAL:
16976 case BFD_RELOC_ARM_LITERAL:
16977 case BFD_RELOC_ARM_CP_OFF_IMM:
16978 return base + 8;
16979
16980
16981 /* Other PC-relative relocations are un-offset. */
16982 default:
16983 return base;
16984 }
16985 }
16986
16987 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
16988 Otherwise we have no need to default values of symbols. */
16989
16990 symbolS *
16991 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
16992 {
16993 #ifdef OBJ_ELF
16994 if (name[0] == '_' && name[1] == 'G'
16995 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
16996 {
16997 if (!GOT_symbol)
16998 {
16999 if (symbol_find (name))
17000 as_bad ("GOT already in the symbol table");
17001
17002 GOT_symbol = symbol_new (name, undefined_section,
17003 (valueT) 0, & zero_address_frag);
17004 }
17005
17006 return GOT_symbol;
17007 }
17008 #endif
17009
17010 return 0;
17011 }
17012
17013 /* Subroutine of md_apply_fix. Check to see if an immediate can be
17014 computed as two separate immediate values, added together. We
17015 already know that this value cannot be computed by just one ARM
17016 instruction. */
17017
17018 static unsigned int
17019 validate_immediate_twopart (unsigned int val,
17020 unsigned int * highpart)
17021 {
17022 unsigned int a;
17023 unsigned int i;
17024
17025 for (i = 0; i < 32; i += 2)
17026 if (((a = rotate_left (val, i)) & 0xff) != 0)
17027 {
17028 if (a & 0xff00)
17029 {
17030 if (a & ~ 0xffff)
17031 continue;
17032 * highpart = (a >> 8) | ((i + 24) << 7);
17033 }
17034 else if (a & 0xff0000)
17035 {
17036 if (a & 0xff000000)
17037 continue;
17038 * highpart = (a >> 16) | ((i + 16) << 7);
17039 }
17040 else
17041 {
17042 assert (a & 0xff000000);
17043 * highpart = (a >> 24) | ((i + 8) << 7);
17044 }
17045
17046 return (a & 0xff) | (i << 7);
17047 }
17048
17049 return FAIL;
17050 }
17051
17052 static int
17053 validate_offset_imm (unsigned int val, int hwse)
17054 {
17055 if ((hwse && val > 255) || val > 4095)
17056 return FAIL;
17057 return val;
17058 }
17059
17060 /* Subroutine of md_apply_fix. Do those data_ops which can take a
17061 negative immediate constant by altering the instruction. A bit of
17062 a hack really.
17063 MOV <-> MVN
17064 AND <-> BIC
17065 ADC <-> SBC
17066 by inverting the second operand, and
17067 ADD <-> SUB
17068 CMP <-> CMN
17069 by negating the second operand. */
17070
17071 static int
17072 negate_data_op (unsigned long * instruction,
17073 unsigned long value)
17074 {
17075 int op, new_inst;
17076 unsigned long negated, inverted;
17077
17078 negated = encode_arm_immediate (-value);
17079 inverted = encode_arm_immediate (~value);
17080
17081 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
17082 switch (op)
17083 {
17084 /* First negates. */
17085 case OPCODE_SUB: /* ADD <-> SUB */
17086 new_inst = OPCODE_ADD;
17087 value = negated;
17088 break;
17089
17090 case OPCODE_ADD:
17091 new_inst = OPCODE_SUB;
17092 value = negated;
17093 break;
17094
17095 case OPCODE_CMP: /* CMP <-> CMN */
17096 new_inst = OPCODE_CMN;
17097 value = negated;
17098 break;
17099
17100 case OPCODE_CMN:
17101 new_inst = OPCODE_CMP;
17102 value = negated;
17103 break;
17104
17105 /* Now Inverted ops. */
17106 case OPCODE_MOV: /* MOV <-> MVN */
17107 new_inst = OPCODE_MVN;
17108 value = inverted;
17109 break;
17110
17111 case OPCODE_MVN:
17112 new_inst = OPCODE_MOV;
17113 value = inverted;
17114 break;
17115
17116 case OPCODE_AND: /* AND <-> BIC */
17117 new_inst = OPCODE_BIC;
17118 value = inverted;
17119 break;
17120
17121 case OPCODE_BIC:
17122 new_inst = OPCODE_AND;
17123 value = inverted;
17124 break;
17125
17126 case OPCODE_ADC: /* ADC <-> SBC */
17127 new_inst = OPCODE_SBC;
17128 value = inverted;
17129 break;
17130
17131 case OPCODE_SBC:
17132 new_inst = OPCODE_ADC;
17133 value = inverted;
17134 break;
17135
17136 /* We cannot do anything. */
17137 default:
17138 return FAIL;
17139 }
17140
17141 if (value == (unsigned) FAIL)
17142 return FAIL;
17143
17144 *instruction &= OPCODE_MASK;
17145 *instruction |= new_inst << DATA_OP_SHIFT;
17146 return value;
17147 }
17148
17149 /* Like negate_data_op, but for Thumb-2. */
17150
17151 static unsigned int
17152 thumb32_negate_data_op (offsetT *instruction, offsetT value)
17153 {
17154 int op, new_inst;
17155 int rd;
17156 offsetT negated, inverted;
17157
17158 negated = encode_thumb32_immediate (-value);
17159 inverted = encode_thumb32_immediate (~value);
17160
17161 rd = (*instruction >> 8) & 0xf;
17162 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
17163 switch (op)
17164 {
17165 /* ADD <-> SUB. Includes CMP <-> CMN. */
17166 case T2_OPCODE_SUB:
17167 new_inst = T2_OPCODE_ADD;
17168 value = negated;
17169 break;
17170
17171 case T2_OPCODE_ADD:
17172 new_inst = T2_OPCODE_SUB;
17173 value = negated;
17174 break;
17175
17176 /* ORR <-> ORN. Includes MOV <-> MVN. */
17177 case T2_OPCODE_ORR:
17178 new_inst = T2_OPCODE_ORN;
17179 value = inverted;
17180 break;
17181
17182 case T2_OPCODE_ORN:
17183 new_inst = T2_OPCODE_ORR;
17184 value = inverted;
17185 break;
17186
17187 /* AND <-> BIC. TST has no inverted equivalent. */
17188 case T2_OPCODE_AND:
17189 new_inst = T2_OPCODE_BIC;
17190 if (rd == 15)
17191 value = FAIL;
17192 else
17193 value = inverted;
17194 break;
17195
17196 case T2_OPCODE_BIC:
17197 new_inst = T2_OPCODE_AND;
17198 value = inverted;
17199 break;
17200
17201 /* ADC <-> SBC */
17202 case T2_OPCODE_ADC:
17203 new_inst = T2_OPCODE_SBC;
17204 value = inverted;
17205 break;
17206
17207 case T2_OPCODE_SBC:
17208 new_inst = T2_OPCODE_ADC;
17209 value = inverted;
17210 break;
17211
17212 /* We cannot do anything. */
17213 default:
17214 return FAIL;
17215 }
17216
17217 if (value == FAIL)
17218 return FAIL;
17219
17220 *instruction &= T2_OPCODE_MASK;
17221 *instruction |= new_inst << T2_DATA_OP_SHIFT;
17222 return value;
17223 }
17224
17225 /* Read a 32-bit thumb instruction from buf. */
17226 static unsigned long
17227 get_thumb32_insn (char * buf)
17228 {
17229 unsigned long insn;
17230 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
17231 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
17232
17233 return insn;
17234 }
17235
17236
17237 /* We usually want to set the low bit on the address of thumb function
17238 symbols. In particular .word foo - . should have the low bit set.
17239 Generic code tries to fold the difference of two symbols to
17240 a constant. Prevent this and force a relocation when the first symbols
17241 is a thumb function. */
17242 int
17243 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
17244 {
17245 if (op == O_subtract
17246 && l->X_op == O_symbol
17247 && r->X_op == O_symbol
17248 && THUMB_IS_FUNC (l->X_add_symbol))
17249 {
17250 l->X_op = O_subtract;
17251 l->X_op_symbol = r->X_add_symbol;
17252 l->X_add_number -= r->X_add_number;
17253 return 1;
17254 }
17255 /* Process as normal. */
17256 return 0;
17257 }
17258
17259 void
17260 md_apply_fix (fixS * fixP,
17261 valueT * valP,
17262 segT seg)
17263 {
17264 offsetT value = * valP;
17265 offsetT newval;
17266 unsigned int newimm;
17267 unsigned long temp;
17268 int sign;
17269 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
17270
17271 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
17272
17273 /* Note whether this will delete the relocation. */
17274
17275 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
17276 fixP->fx_done = 1;
17277
17278 /* On a 64-bit host, silently truncate 'value' to 32 bits for
17279 consistency with the behavior on 32-bit hosts. Remember value
17280 for emit_reloc. */
17281 value &= 0xffffffff;
17282 value ^= 0x80000000;
17283 value -= 0x80000000;
17284
17285 *valP = value;
17286 fixP->fx_addnumber = value;
17287
17288 /* Same treatment for fixP->fx_offset. */
17289 fixP->fx_offset &= 0xffffffff;
17290 fixP->fx_offset ^= 0x80000000;
17291 fixP->fx_offset -= 0x80000000;
17292
17293 switch (fixP->fx_r_type)
17294 {
17295 case BFD_RELOC_NONE:
17296 /* This will need to go in the object file. */
17297 fixP->fx_done = 0;
17298 break;
17299
17300 case BFD_RELOC_ARM_IMMEDIATE:
17301 /* We claim that this fixup has been processed here,
17302 even if in fact we generate an error because we do
17303 not have a reloc for it, so tc_gen_reloc will reject it. */
17304 fixP->fx_done = 1;
17305
17306 if (fixP->fx_addsy
17307 && ! S_IS_DEFINED (fixP->fx_addsy))
17308 {
17309 as_bad_where (fixP->fx_file, fixP->fx_line,
17310 _("undefined symbol %s used as an immediate value"),
17311 S_GET_NAME (fixP->fx_addsy));
17312 break;
17313 }
17314
17315 newimm = encode_arm_immediate (value);
17316 temp = md_chars_to_number (buf, INSN_SIZE);
17317
17318 /* If the instruction will fail, see if we can fix things up by
17319 changing the opcode. */
17320 if (newimm == (unsigned int) FAIL
17321 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
17322 {
17323 as_bad_where (fixP->fx_file, fixP->fx_line,
17324 _("invalid constant (%lx) after fixup"),
17325 (unsigned long) value);
17326 break;
17327 }
17328
17329 newimm |= (temp & 0xfffff000);
17330 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
17331 break;
17332
17333 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
17334 {
17335 unsigned int highpart = 0;
17336 unsigned int newinsn = 0xe1a00000; /* nop. */
17337
17338 newimm = encode_arm_immediate (value);
17339 temp = md_chars_to_number (buf, INSN_SIZE);
17340
17341 /* If the instruction will fail, see if we can fix things up by
17342 changing the opcode. */
17343 if (newimm == (unsigned int) FAIL
17344 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
17345 {
17346 /* No ? OK - try using two ADD instructions to generate
17347 the value. */
17348 newimm = validate_immediate_twopart (value, & highpart);
17349
17350 /* Yes - then make sure that the second instruction is
17351 also an add. */
17352 if (newimm != (unsigned int) FAIL)
17353 newinsn = temp;
17354 /* Still No ? Try using a negated value. */
17355 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
17356 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
17357 /* Otherwise - give up. */
17358 else
17359 {
17360 as_bad_where (fixP->fx_file, fixP->fx_line,
17361 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
17362 (long) value);
17363 break;
17364 }
17365
17366 /* Replace the first operand in the 2nd instruction (which
17367 is the PC) with the destination register. We have
17368 already added in the PC in the first instruction and we
17369 do not want to do it again. */
17370 newinsn &= ~ 0xf0000;
17371 newinsn |= ((newinsn & 0x0f000) << 4);
17372 }
17373
17374 newimm |= (temp & 0xfffff000);
17375 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
17376
17377 highpart |= (newinsn & 0xfffff000);
17378 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
17379 }
17380 break;
17381
17382 case BFD_RELOC_ARM_OFFSET_IMM:
17383 if (!fixP->fx_done && seg->use_rela_p)
17384 value = 0;
17385
17386 case BFD_RELOC_ARM_LITERAL:
17387 sign = value >= 0;
17388
17389 if (value < 0)
17390 value = - value;
17391
17392 if (validate_offset_imm (value, 0) == FAIL)
17393 {
17394 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
17395 as_bad_where (fixP->fx_file, fixP->fx_line,
17396 _("invalid literal constant: pool needs to be closer"));
17397 else
17398 as_bad_where (fixP->fx_file, fixP->fx_line,
17399 _("bad immediate value for offset (%ld)"),
17400 (long) value);
17401 break;
17402 }
17403
17404 newval = md_chars_to_number (buf, INSN_SIZE);
17405 newval &= 0xff7ff000;
17406 newval |= value | (sign ? INDEX_UP : 0);
17407 md_number_to_chars (buf, newval, INSN_SIZE);
17408 break;
17409
17410 case BFD_RELOC_ARM_OFFSET_IMM8:
17411 case BFD_RELOC_ARM_HWLITERAL:
17412 sign = value >= 0;
17413
17414 if (value < 0)
17415 value = - value;
17416
17417 if (validate_offset_imm (value, 1) == FAIL)
17418 {
17419 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
17420 as_bad_where (fixP->fx_file, fixP->fx_line,
17421 _("invalid literal constant: pool needs to be closer"));
17422 else
17423 as_bad (_("bad immediate value for half-word offset (%ld)"),
17424 (long) value);
17425 break;
17426 }
17427
17428 newval = md_chars_to_number (buf, INSN_SIZE);
17429 newval &= 0xff7ff0f0;
17430 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
17431 md_number_to_chars (buf, newval, INSN_SIZE);
17432 break;
17433
17434 case BFD_RELOC_ARM_T32_OFFSET_U8:
17435 if (value < 0 || value > 1020 || value % 4 != 0)
17436 as_bad_where (fixP->fx_file, fixP->fx_line,
17437 _("bad immediate value for offset (%ld)"), (long) value);
17438 value /= 4;
17439
17440 newval = md_chars_to_number (buf+2, THUMB_SIZE);
17441 newval |= value;
17442 md_number_to_chars (buf+2, newval, THUMB_SIZE);
17443 break;
17444
17445 case BFD_RELOC_ARM_T32_OFFSET_IMM:
17446 /* This is a complicated relocation used for all varieties of Thumb32
17447 load/store instruction with immediate offset:
17448
17449 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
17450 *4, optional writeback(W)
17451 (doubleword load/store)
17452
17453 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
17454 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
17455 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
17456 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
17457 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
17458
17459 Uppercase letters indicate bits that are already encoded at
17460 this point. Lowercase letters are our problem. For the
17461 second block of instructions, the secondary opcode nybble
17462 (bits 8..11) is present, and bit 23 is zero, even if this is
17463 a PC-relative operation. */
17464 newval = md_chars_to_number (buf, THUMB_SIZE);
17465 newval <<= 16;
17466 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
17467
17468 if ((newval & 0xf0000000) == 0xe0000000)
17469 {
17470 /* Doubleword load/store: 8-bit offset, scaled by 4. */
17471 if (value >= 0)
17472 newval |= (1 << 23);
17473 else
17474 value = -value;
17475 if (value % 4 != 0)
17476 {
17477 as_bad_where (fixP->fx_file, fixP->fx_line,
17478 _("offset not a multiple of 4"));
17479 break;
17480 }
17481 value /= 4;
17482 if (value > 0xff)
17483 {
17484 as_bad_where (fixP->fx_file, fixP->fx_line,
17485 _("offset out of range"));
17486 break;
17487 }
17488 newval &= ~0xff;
17489 }
17490 else if ((newval & 0x000f0000) == 0x000f0000)
17491 {
17492 /* PC-relative, 12-bit offset. */
17493 if (value >= 0)
17494 newval |= (1 << 23);
17495 else
17496 value = -value;
17497 if (value > 0xfff)
17498 {
17499 as_bad_where (fixP->fx_file, fixP->fx_line,
17500 _("offset out of range"));
17501 break;
17502 }
17503 newval &= ~0xfff;
17504 }
17505 else if ((newval & 0x00000100) == 0x00000100)
17506 {
17507 /* Writeback: 8-bit, +/- offset. */
17508 if (value >= 0)
17509 newval |= (1 << 9);
17510 else
17511 value = -value;
17512 if (value > 0xff)
17513 {
17514 as_bad_where (fixP->fx_file, fixP->fx_line,
17515 _("offset out of range"));
17516 break;
17517 }
17518 newval &= ~0xff;
17519 }
17520 else if ((newval & 0x00000f00) == 0x00000e00)
17521 {
17522 /* T-instruction: positive 8-bit offset. */
17523 if (value < 0 || value > 0xff)
17524 {
17525 as_bad_where (fixP->fx_file, fixP->fx_line,
17526 _("offset out of range"));
17527 break;
17528 }
17529 newval &= ~0xff;
17530 newval |= value;
17531 }
17532 else
17533 {
17534 /* Positive 12-bit or negative 8-bit offset. */
17535 int limit;
17536 if (value >= 0)
17537 {
17538 newval |= (1 << 23);
17539 limit = 0xfff;
17540 }
17541 else
17542 {
17543 value = -value;
17544 limit = 0xff;
17545 }
17546 if (value > limit)
17547 {
17548 as_bad_where (fixP->fx_file, fixP->fx_line,
17549 _("offset out of range"));
17550 break;
17551 }
17552 newval &= ~limit;
17553 }
17554
17555 newval |= value;
17556 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
17557 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
17558 break;
17559
17560 case BFD_RELOC_ARM_SHIFT_IMM:
17561 newval = md_chars_to_number (buf, INSN_SIZE);
17562 if (((unsigned long) value) > 32
17563 || (value == 32
17564 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
17565 {
17566 as_bad_where (fixP->fx_file, fixP->fx_line,
17567 _("shift expression is too large"));
17568 break;
17569 }
17570
17571 if (value == 0)
17572 /* Shifts of zero must be done as lsl. */
17573 newval &= ~0x60;
17574 else if (value == 32)
17575 value = 0;
17576 newval &= 0xfffff07f;
17577 newval |= (value & 0x1f) << 7;
17578 md_number_to_chars (buf, newval, INSN_SIZE);
17579 break;
17580
17581 case BFD_RELOC_ARM_T32_IMMEDIATE:
17582 case BFD_RELOC_ARM_T32_ADD_IMM:
17583 case BFD_RELOC_ARM_T32_IMM12:
17584 case BFD_RELOC_ARM_T32_ADD_PC12:
17585 /* We claim that this fixup has been processed here,
17586 even if in fact we generate an error because we do
17587 not have a reloc for it, so tc_gen_reloc will reject it. */
17588 fixP->fx_done = 1;
17589
17590 if (fixP->fx_addsy
17591 && ! S_IS_DEFINED (fixP->fx_addsy))
17592 {
17593 as_bad_where (fixP->fx_file, fixP->fx_line,
17594 _("undefined symbol %s used as an immediate value"),
17595 S_GET_NAME (fixP->fx_addsy));
17596 break;
17597 }
17598
17599 newval = md_chars_to_number (buf, THUMB_SIZE);
17600 newval <<= 16;
17601 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
17602
17603 newimm = FAIL;
17604 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
17605 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
17606 {
17607 newimm = encode_thumb32_immediate (value);
17608 if (newimm == (unsigned int) FAIL)
17609 newimm = thumb32_negate_data_op (&newval, value);
17610 }
17611 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
17612 && newimm == (unsigned int) FAIL)
17613 {
17614 /* Turn add/sum into addw/subw. */
17615 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
17616 newval = (newval & 0xfeffffff) | 0x02000000;
17617
17618 /* 12 bit immediate for addw/subw. */
17619 if (value < 0)
17620 {
17621 value = -value;
17622 newval ^= 0x00a00000;
17623 }
17624 if (value > 0xfff)
17625 newimm = (unsigned int) FAIL;
17626 else
17627 newimm = value;
17628 }
17629
17630 if (newimm == (unsigned int)FAIL)
17631 {
17632 as_bad_where (fixP->fx_file, fixP->fx_line,
17633 _("invalid constant (%lx) after fixup"),
17634 (unsigned long) value);
17635 break;
17636 }
17637
17638 newval |= (newimm & 0x800) << 15;
17639 newval |= (newimm & 0x700) << 4;
17640 newval |= (newimm & 0x0ff);
17641
17642 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
17643 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
17644 break;
17645
17646 case BFD_RELOC_ARM_SMC:
17647 if (((unsigned long) value) > 0xffff)
17648 as_bad_where (fixP->fx_file, fixP->fx_line,
17649 _("invalid smc expression"));
17650 newval = md_chars_to_number (buf, INSN_SIZE);
17651 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
17652 md_number_to_chars (buf, newval, INSN_SIZE);
17653 break;
17654
17655 case BFD_RELOC_ARM_SWI:
17656 if (fixP->tc_fix_data != 0)
17657 {
17658 if (((unsigned long) value) > 0xff)
17659 as_bad_where (fixP->fx_file, fixP->fx_line,
17660 _("invalid swi expression"));
17661 newval = md_chars_to_number (buf, THUMB_SIZE);
17662 newval |= value;
17663 md_number_to_chars (buf, newval, THUMB_SIZE);
17664 }
17665 else
17666 {
17667 if (((unsigned long) value) > 0x00ffffff)
17668 as_bad_where (fixP->fx_file, fixP->fx_line,
17669 _("invalid swi expression"));
17670 newval = md_chars_to_number (buf, INSN_SIZE);
17671 newval |= value;
17672 md_number_to_chars (buf, newval, INSN_SIZE);
17673 }
17674 break;
17675
17676 case BFD_RELOC_ARM_MULTI:
17677 if (((unsigned long) value) > 0xffff)
17678 as_bad_where (fixP->fx_file, fixP->fx_line,
17679 _("invalid expression in load/store multiple"));
17680 newval = value | md_chars_to_number (buf, INSN_SIZE);
17681 md_number_to_chars (buf, newval, INSN_SIZE);
17682 break;
17683
17684 #ifdef OBJ_ELF
17685 case BFD_RELOC_ARM_PCREL_CALL:
17686 newval = md_chars_to_number (buf, INSN_SIZE);
17687 if ((newval & 0xf0000000) == 0xf0000000)
17688 temp = 1;
17689 else
17690 temp = 3;
17691 goto arm_branch_common;
17692
17693 case BFD_RELOC_ARM_PCREL_JUMP:
17694 case BFD_RELOC_ARM_PLT32:
17695 #endif
17696 case BFD_RELOC_ARM_PCREL_BRANCH:
17697 temp = 3;
17698 goto arm_branch_common;
17699
17700 case BFD_RELOC_ARM_PCREL_BLX:
17701 temp = 1;
17702 arm_branch_common:
17703 /* We are going to store value (shifted right by two) in the
17704 instruction, in a 24 bit, signed field. Bits 26 through 32 either
17705 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
17706 also be be clear. */
17707 if (value & temp)
17708 as_bad_where (fixP->fx_file, fixP->fx_line,
17709 _("misaligned branch destination"));
17710 if ((value & (offsetT)0xfe000000) != (offsetT)0
17711 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
17712 as_bad_where (fixP->fx_file, fixP->fx_line,
17713 _("branch out of range"));
17714
17715 if (fixP->fx_done || !seg->use_rela_p)
17716 {
17717 newval = md_chars_to_number (buf, INSN_SIZE);
17718 newval |= (value >> 2) & 0x00ffffff;
17719 /* Set the H bit on BLX instructions. */
17720 if (temp == 1)
17721 {
17722 if (value & 2)
17723 newval |= 0x01000000;
17724 else
17725 newval &= ~0x01000000;
17726 }
17727 md_number_to_chars (buf, newval, INSN_SIZE);
17728 }
17729 break;
17730
17731 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CZB */
17732 /* CZB can only branch forward. */
17733 if (value & ~0x7e)
17734 as_bad_where (fixP->fx_file, fixP->fx_line,
17735 _("branch out of range"));
17736
17737 if (fixP->fx_done || !seg->use_rela_p)
17738 {
17739 newval = md_chars_to_number (buf, THUMB_SIZE);
17740 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
17741 md_number_to_chars (buf, newval, THUMB_SIZE);
17742 }
17743 break;
17744
17745 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
17746 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
17747 as_bad_where (fixP->fx_file, fixP->fx_line,
17748 _("branch out of range"));
17749
17750 if (fixP->fx_done || !seg->use_rela_p)
17751 {
17752 newval = md_chars_to_number (buf, THUMB_SIZE);
17753 newval |= (value & 0x1ff) >> 1;
17754 md_number_to_chars (buf, newval, THUMB_SIZE);
17755 }
17756 break;
17757
17758 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
17759 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
17760 as_bad_where (fixP->fx_file, fixP->fx_line,
17761 _("branch out of range"));
17762
17763 if (fixP->fx_done || !seg->use_rela_p)
17764 {
17765 newval = md_chars_to_number (buf, THUMB_SIZE);
17766 newval |= (value & 0xfff) >> 1;
17767 md_number_to_chars (buf, newval, THUMB_SIZE);
17768 }
17769 break;
17770
17771 case BFD_RELOC_THUMB_PCREL_BRANCH20:
17772 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
17773 as_bad_where (fixP->fx_file, fixP->fx_line,
17774 _("conditional branch out of range"));
17775
17776 if (fixP->fx_done || !seg->use_rela_p)
17777 {
17778 offsetT newval2;
17779 addressT S, J1, J2, lo, hi;
17780
17781 S = (value & 0x00100000) >> 20;
17782 J2 = (value & 0x00080000) >> 19;
17783 J1 = (value & 0x00040000) >> 18;
17784 hi = (value & 0x0003f000) >> 12;
17785 lo = (value & 0x00000ffe) >> 1;
17786
17787 newval = md_chars_to_number (buf, THUMB_SIZE);
17788 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
17789 newval |= (S << 10) | hi;
17790 newval2 |= (J1 << 13) | (J2 << 11) | lo;
17791 md_number_to_chars (buf, newval, THUMB_SIZE);
17792 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
17793 }
17794 break;
17795
17796 case BFD_RELOC_THUMB_PCREL_BLX:
17797 case BFD_RELOC_THUMB_PCREL_BRANCH23:
17798 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
17799 as_bad_where (fixP->fx_file, fixP->fx_line,
17800 _("branch out of range"));
17801
17802 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
17803 /* For a BLX instruction, make sure that the relocation is rounded up
17804 to a word boundary. This follows the semantics of the instruction
17805 which specifies that bit 1 of the target address will come from bit
17806 1 of the base address. */
17807 value = (value + 1) & ~ 1;
17808
17809 if (fixP->fx_done || !seg->use_rela_p)
17810 {
17811 offsetT newval2;
17812
17813 newval = md_chars_to_number (buf, THUMB_SIZE);
17814 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
17815 newval |= (value & 0x7fffff) >> 12;
17816 newval2 |= (value & 0xfff) >> 1;
17817 md_number_to_chars (buf, newval, THUMB_SIZE);
17818 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
17819 }
17820 break;
17821
17822 case BFD_RELOC_THUMB_PCREL_BRANCH25:
17823 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
17824 as_bad_where (fixP->fx_file, fixP->fx_line,
17825 _("branch out of range"));
17826
17827 if (fixP->fx_done || !seg->use_rela_p)
17828 {
17829 offsetT newval2;
17830 addressT S, I1, I2, lo, hi;
17831
17832 S = (value & 0x01000000) >> 24;
17833 I1 = (value & 0x00800000) >> 23;
17834 I2 = (value & 0x00400000) >> 22;
17835 hi = (value & 0x003ff000) >> 12;
17836 lo = (value & 0x00000ffe) >> 1;
17837
17838 I1 = !(I1 ^ S);
17839 I2 = !(I2 ^ S);
17840
17841 newval = md_chars_to_number (buf, THUMB_SIZE);
17842 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
17843 newval |= (S << 10) | hi;
17844 newval2 |= (I1 << 13) | (I2 << 11) | lo;
17845 md_number_to_chars (buf, newval, THUMB_SIZE);
17846 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
17847 }
17848 break;
17849
17850 case BFD_RELOC_8:
17851 if (fixP->fx_done || !seg->use_rela_p)
17852 md_number_to_chars (buf, value, 1);
17853 break;
17854
17855 case BFD_RELOC_16:
17856 if (fixP->fx_done || !seg->use_rela_p)
17857 md_number_to_chars (buf, value, 2);
17858 break;
17859
17860 #ifdef OBJ_ELF
17861 case BFD_RELOC_ARM_TLS_GD32:
17862 case BFD_RELOC_ARM_TLS_LE32:
17863 case BFD_RELOC_ARM_TLS_IE32:
17864 case BFD_RELOC_ARM_TLS_LDM32:
17865 case BFD_RELOC_ARM_TLS_LDO32:
17866 S_SET_THREAD_LOCAL (fixP->fx_addsy);
17867 /* fall through */
17868
17869 case BFD_RELOC_ARM_GOT32:
17870 case BFD_RELOC_ARM_GOTOFF:
17871 case BFD_RELOC_ARM_TARGET2:
17872 if (fixP->fx_done || !seg->use_rela_p)
17873 md_number_to_chars (buf, 0, 4);
17874 break;
17875 #endif
17876
17877 case BFD_RELOC_RVA:
17878 case BFD_RELOC_32:
17879 case BFD_RELOC_ARM_TARGET1:
17880 case BFD_RELOC_ARM_ROSEGREL32:
17881 case BFD_RELOC_ARM_SBREL32:
17882 case BFD_RELOC_32_PCREL:
17883 if (fixP->fx_done || !seg->use_rela_p)
17884 #ifdef TE_WINCE
17885 /* For WinCE we only do this for pcrel fixups. */
17886 if (fixP->fx_done || fixP->fx_pcrel)
17887 #endif
17888 md_number_to_chars (buf, value, 4);
17889 break;
17890
17891 #ifdef OBJ_ELF
17892 case BFD_RELOC_ARM_PREL31:
17893 if (fixP->fx_done || !seg->use_rela_p)
17894 {
17895 newval = md_chars_to_number (buf, 4) & 0x80000000;
17896 if ((value ^ (value >> 1)) & 0x40000000)
17897 {
17898 as_bad_where (fixP->fx_file, fixP->fx_line,
17899 _("rel31 relocation overflow"));
17900 }
17901 newval |= value & 0x7fffffff;
17902 md_number_to_chars (buf, newval, 4);
17903 }
17904 break;
17905 #endif
17906
17907 case BFD_RELOC_ARM_CP_OFF_IMM:
17908 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
17909 if (value < -1023 || value > 1023 || (value & 3))
17910 as_bad_where (fixP->fx_file, fixP->fx_line,
17911 _("co-processor offset out of range"));
17912 cp_off_common:
17913 sign = value >= 0;
17914 if (value < 0)
17915 value = -value;
17916 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
17917 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
17918 newval = md_chars_to_number (buf, INSN_SIZE);
17919 else
17920 newval = get_thumb32_insn (buf);
17921 newval &= 0xff7fff00;
17922 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
17923 if (value == 0)
17924 newval &= ~WRITE_BACK;
17925 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
17926 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
17927 md_number_to_chars (buf, newval, INSN_SIZE);
17928 else
17929 put_thumb32_insn (buf, newval);
17930 break;
17931
17932 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
17933 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
17934 if (value < -255 || value > 255)
17935 as_bad_where (fixP->fx_file, fixP->fx_line,
17936 _("co-processor offset out of range"));
17937 value *= 4;
17938 goto cp_off_common;
17939
17940 case BFD_RELOC_ARM_THUMB_OFFSET:
17941 newval = md_chars_to_number (buf, THUMB_SIZE);
17942 /* Exactly what ranges, and where the offset is inserted depends
17943 on the type of instruction, we can establish this from the
17944 top 4 bits. */
17945 switch (newval >> 12)
17946 {
17947 case 4: /* PC load. */
17948 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
17949 forced to zero for these loads; md_pcrel_from has already
17950 compensated for this. */
17951 if (value & 3)
17952 as_bad_where (fixP->fx_file, fixP->fx_line,
17953 _("invalid offset, target not word aligned (0x%08lX)"),
17954 (((unsigned long) fixP->fx_frag->fr_address
17955 + (unsigned long) fixP->fx_where) & ~3)
17956 + (unsigned long) value);
17957
17958 if (value & ~0x3fc)
17959 as_bad_where (fixP->fx_file, fixP->fx_line,
17960 _("invalid offset, value too big (0x%08lX)"),
17961 (long) value);
17962
17963 newval |= value >> 2;
17964 break;
17965
17966 case 9: /* SP load/store. */
17967 if (value & ~0x3fc)
17968 as_bad_where (fixP->fx_file, fixP->fx_line,
17969 _("invalid offset, value too big (0x%08lX)"),
17970 (long) value);
17971 newval |= value >> 2;
17972 break;
17973
17974 case 6: /* Word load/store. */
17975 if (value & ~0x7c)
17976 as_bad_where (fixP->fx_file, fixP->fx_line,
17977 _("invalid offset, value too big (0x%08lX)"),
17978 (long) value);
17979 newval |= value << 4; /* 6 - 2. */
17980 break;
17981
17982 case 7: /* Byte load/store. */
17983 if (value & ~0x1f)
17984 as_bad_where (fixP->fx_file, fixP->fx_line,
17985 _("invalid offset, value too big (0x%08lX)"),
17986 (long) value);
17987 newval |= value << 6;
17988 break;
17989
17990 case 8: /* Halfword load/store. */
17991 if (value & ~0x3e)
17992 as_bad_where (fixP->fx_file, fixP->fx_line,
17993 _("invalid offset, value too big (0x%08lX)"),
17994 (long) value);
17995 newval |= value << 5; /* 6 - 1. */
17996 break;
17997
17998 default:
17999 as_bad_where (fixP->fx_file, fixP->fx_line,
18000 "Unable to process relocation for thumb opcode: %lx",
18001 (unsigned long) newval);
18002 break;
18003 }
18004 md_number_to_chars (buf, newval, THUMB_SIZE);
18005 break;
18006
18007 case BFD_RELOC_ARM_THUMB_ADD:
18008 /* This is a complicated relocation, since we use it for all of
18009 the following immediate relocations:
18010
18011 3bit ADD/SUB
18012 8bit ADD/SUB
18013 9bit ADD/SUB SP word-aligned
18014 10bit ADD PC/SP word-aligned
18015
18016 The type of instruction being processed is encoded in the
18017 instruction field:
18018
18019 0x8000 SUB
18020 0x00F0 Rd
18021 0x000F Rs
18022 */
18023 newval = md_chars_to_number (buf, THUMB_SIZE);
18024 {
18025 int rd = (newval >> 4) & 0xf;
18026 int rs = newval & 0xf;
18027 int subtract = !!(newval & 0x8000);
18028
18029 /* Check for HI regs, only very restricted cases allowed:
18030 Adjusting SP, and using PC or SP to get an address. */
18031 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
18032 || (rs > 7 && rs != REG_SP && rs != REG_PC))
18033 as_bad_where (fixP->fx_file, fixP->fx_line,
18034 _("invalid Hi register with immediate"));
18035
18036 /* If value is negative, choose the opposite instruction. */
18037 if (value < 0)
18038 {
18039 value = -value;
18040 subtract = !subtract;
18041 if (value < 0)
18042 as_bad_where (fixP->fx_file, fixP->fx_line,
18043 _("immediate value out of range"));
18044 }
18045
18046 if (rd == REG_SP)
18047 {
18048 if (value & ~0x1fc)
18049 as_bad_where (fixP->fx_file, fixP->fx_line,
18050 _("invalid immediate for stack address calculation"));
18051 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
18052 newval |= value >> 2;
18053 }
18054 else if (rs == REG_PC || rs == REG_SP)
18055 {
18056 if (subtract || value & ~0x3fc)
18057 as_bad_where (fixP->fx_file, fixP->fx_line,
18058 _("invalid immediate for address calculation (value = 0x%08lX)"),
18059 (unsigned long) value);
18060 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
18061 newval |= rd << 8;
18062 newval |= value >> 2;
18063 }
18064 else if (rs == rd)
18065 {
18066 if (value & ~0xff)
18067 as_bad_where (fixP->fx_file, fixP->fx_line,
18068 _("immediate value out of range"));
18069 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
18070 newval |= (rd << 8) | value;
18071 }
18072 else
18073 {
18074 if (value & ~0x7)
18075 as_bad_where (fixP->fx_file, fixP->fx_line,
18076 _("immediate value out of range"));
18077 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
18078 newval |= rd | (rs << 3) | (value << 6);
18079 }
18080 }
18081 md_number_to_chars (buf, newval, THUMB_SIZE);
18082 break;
18083
18084 case BFD_RELOC_ARM_THUMB_IMM:
18085 newval = md_chars_to_number (buf, THUMB_SIZE);
18086 if (value < 0 || value > 255)
18087 as_bad_where (fixP->fx_file, fixP->fx_line,
18088 _("invalid immediate: %ld is too large"),
18089 (long) value);
18090 newval |= value;
18091 md_number_to_chars (buf, newval, THUMB_SIZE);
18092 break;
18093
18094 case BFD_RELOC_ARM_THUMB_SHIFT:
18095 /* 5bit shift value (0..32). LSL cannot take 32. */
18096 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
18097 temp = newval & 0xf800;
18098 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
18099 as_bad_where (fixP->fx_file, fixP->fx_line,
18100 _("invalid shift value: %ld"), (long) value);
18101 /* Shifts of zero must be encoded as LSL. */
18102 if (value == 0)
18103 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
18104 /* Shifts of 32 are encoded as zero. */
18105 else if (value == 32)
18106 value = 0;
18107 newval |= value << 6;
18108 md_number_to_chars (buf, newval, THUMB_SIZE);
18109 break;
18110
18111 case BFD_RELOC_VTABLE_INHERIT:
18112 case BFD_RELOC_VTABLE_ENTRY:
18113 fixP->fx_done = 0;
18114 return;
18115
18116 case BFD_RELOC_ARM_MOVW:
18117 case BFD_RELOC_ARM_MOVT:
18118 case BFD_RELOC_ARM_THUMB_MOVW:
18119 case BFD_RELOC_ARM_THUMB_MOVT:
18120 if (fixP->fx_done || !seg->use_rela_p)
18121 {
18122 /* REL format relocations are limited to a 16-bit addend. */
18123 if (!fixP->fx_done)
18124 {
18125 if (value < -0x1000 || value > 0xffff)
18126 as_bad_where (fixP->fx_file, fixP->fx_line,
18127 _("offset too big"));
18128 }
18129 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
18130 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18131 {
18132 value >>= 16;
18133 }
18134
18135 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
18136 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18137 {
18138 newval = get_thumb32_insn (buf);
18139 newval &= 0xfbf08f00;
18140 newval |= (value & 0xf000) << 4;
18141 newval |= (value & 0x0800) << 15;
18142 newval |= (value & 0x0700) << 4;
18143 newval |= (value & 0x00ff);
18144 put_thumb32_insn (buf, newval);
18145 }
18146 else
18147 {
18148 newval = md_chars_to_number (buf, 4);
18149 newval &= 0xfff0f000;
18150 newval |= value & 0x0fff;
18151 newval |= (value & 0xf000) << 4;
18152 md_number_to_chars (buf, newval, 4);
18153 }
18154 }
18155 return;
18156
18157 case BFD_RELOC_ARM_ALU_PC_G0_NC:
18158 case BFD_RELOC_ARM_ALU_PC_G0:
18159 case BFD_RELOC_ARM_ALU_PC_G1_NC:
18160 case BFD_RELOC_ARM_ALU_PC_G1:
18161 case BFD_RELOC_ARM_ALU_PC_G2:
18162 case BFD_RELOC_ARM_ALU_SB_G0_NC:
18163 case BFD_RELOC_ARM_ALU_SB_G0:
18164 case BFD_RELOC_ARM_ALU_SB_G1_NC:
18165 case BFD_RELOC_ARM_ALU_SB_G1:
18166 case BFD_RELOC_ARM_ALU_SB_G2:
18167 assert (!fixP->fx_done);
18168 if (!seg->use_rela_p)
18169 {
18170 bfd_vma insn;
18171 bfd_vma encoded_addend;
18172 bfd_vma addend_abs = abs (value);
18173
18174 /* Check that the absolute value of the addend can be
18175 expressed as an 8-bit constant plus a rotation. */
18176 encoded_addend = encode_arm_immediate (addend_abs);
18177 if (encoded_addend == (unsigned int) FAIL)
18178 as_bad_where (fixP->fx_file, fixP->fx_line,
18179 _("the offset 0x%08lX is not representable"),
18180 addend_abs);
18181
18182 /* Extract the instruction. */
18183 insn = md_chars_to_number (buf, INSN_SIZE);
18184
18185 /* If the addend is positive, use an ADD instruction.
18186 Otherwise use a SUB. Take care not to destroy the S bit. */
18187 insn &= 0xff1fffff;
18188 if (value < 0)
18189 insn |= 1 << 22;
18190 else
18191 insn |= 1 << 23;
18192
18193 /* Place the encoded addend into the first 12 bits of the
18194 instruction. */
18195 insn &= 0xfffff000;
18196 insn |= encoded_addend;
18197
18198 /* Update the instruction. */
18199 md_number_to_chars (buf, insn, INSN_SIZE);
18200 }
18201 break;
18202
18203 case BFD_RELOC_ARM_LDR_PC_G0:
18204 case BFD_RELOC_ARM_LDR_PC_G1:
18205 case BFD_RELOC_ARM_LDR_PC_G2:
18206 case BFD_RELOC_ARM_LDR_SB_G0:
18207 case BFD_RELOC_ARM_LDR_SB_G1:
18208 case BFD_RELOC_ARM_LDR_SB_G2:
18209 assert (!fixP->fx_done);
18210 if (!seg->use_rela_p)
18211 {
18212 bfd_vma insn;
18213 bfd_vma addend_abs = abs (value);
18214
18215 /* Check that the absolute value of the addend can be
18216 encoded in 12 bits. */
18217 if (addend_abs >= 0x1000)
18218 as_bad_where (fixP->fx_file, fixP->fx_line,
18219 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
18220 addend_abs);
18221
18222 /* Extract the instruction. */
18223 insn = md_chars_to_number (buf, INSN_SIZE);
18224
18225 /* If the addend is negative, clear bit 23 of the instruction.
18226 Otherwise set it. */
18227 if (value < 0)
18228 insn &= ~(1 << 23);
18229 else
18230 insn |= 1 << 23;
18231
18232 /* Place the absolute value of the addend into the first 12 bits
18233 of the instruction. */
18234 insn &= 0xfffff000;
18235 insn |= addend_abs;
18236
18237 /* Update the instruction. */
18238 md_number_to_chars (buf, insn, INSN_SIZE);
18239 }
18240 break;
18241
18242 case BFD_RELOC_ARM_LDRS_PC_G0:
18243 case BFD_RELOC_ARM_LDRS_PC_G1:
18244 case BFD_RELOC_ARM_LDRS_PC_G2:
18245 case BFD_RELOC_ARM_LDRS_SB_G0:
18246 case BFD_RELOC_ARM_LDRS_SB_G1:
18247 case BFD_RELOC_ARM_LDRS_SB_G2:
18248 assert (!fixP->fx_done);
18249 if (!seg->use_rela_p)
18250 {
18251 bfd_vma insn;
18252 bfd_vma addend_abs = abs (value);
18253
18254 /* Check that the absolute value of the addend can be
18255 encoded in 8 bits. */
18256 if (addend_abs >= 0x100)
18257 as_bad_where (fixP->fx_file, fixP->fx_line,
18258 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
18259 addend_abs);
18260
18261 /* Extract the instruction. */
18262 insn = md_chars_to_number (buf, INSN_SIZE);
18263
18264 /* If the addend is negative, clear bit 23 of the instruction.
18265 Otherwise set it. */
18266 if (value < 0)
18267 insn &= ~(1 << 23);
18268 else
18269 insn |= 1 << 23;
18270
18271 /* Place the first four bits of the absolute value of the addend
18272 into the first 4 bits of the instruction, and the remaining
18273 four into bits 8 .. 11. */
18274 insn &= 0xfffff0f0;
18275 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
18276
18277 /* Update the instruction. */
18278 md_number_to_chars (buf, insn, INSN_SIZE);
18279 }
18280 break;
18281
18282 case BFD_RELOC_ARM_LDC_PC_G0:
18283 case BFD_RELOC_ARM_LDC_PC_G1:
18284 case BFD_RELOC_ARM_LDC_PC_G2:
18285 case BFD_RELOC_ARM_LDC_SB_G0:
18286 case BFD_RELOC_ARM_LDC_SB_G1:
18287 case BFD_RELOC_ARM_LDC_SB_G2:
18288 assert (!fixP->fx_done);
18289 if (!seg->use_rela_p)
18290 {
18291 bfd_vma insn;
18292 bfd_vma addend_abs = abs (value);
18293
18294 /* Check that the absolute value of the addend is a multiple of
18295 four and, when divided by four, fits in 8 bits. */
18296 if (addend_abs & 0x3)
18297 as_bad_where (fixP->fx_file, fixP->fx_line,
18298 _("bad offset 0x%08lX (must be word-aligned)"),
18299 addend_abs);
18300
18301 if ((addend_abs >> 2) > 0xff)
18302 as_bad_where (fixP->fx_file, fixP->fx_line,
18303 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
18304 addend_abs);
18305
18306 /* Extract the instruction. */
18307 insn = md_chars_to_number (buf, INSN_SIZE);
18308
18309 /* If the addend is negative, clear bit 23 of the instruction.
18310 Otherwise set it. */
18311 if (value < 0)
18312 insn &= ~(1 << 23);
18313 else
18314 insn |= 1 << 23;
18315
18316 /* Place the addend (divided by four) into the first eight
18317 bits of the instruction. */
18318 insn &= 0xfffffff0;
18319 insn |= addend_abs >> 2;
18320
18321 /* Update the instruction. */
18322 md_number_to_chars (buf, insn, INSN_SIZE);
18323 }
18324 break;
18325
18326 case BFD_RELOC_UNUSED:
18327 default:
18328 as_bad_where (fixP->fx_file, fixP->fx_line,
18329 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
18330 }
18331 }
18332
18333 /* Translate internal representation of relocation info to BFD target
18334 format. */
18335
18336 arelent *
18337 tc_gen_reloc (asection *section, fixS *fixp)
18338 {
18339 arelent * reloc;
18340 bfd_reloc_code_real_type code;
18341
18342 reloc = xmalloc (sizeof (arelent));
18343
18344 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
18345 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
18346 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
18347
18348 if (fixp->fx_pcrel)
18349 {
18350 if (section->use_rela_p)
18351 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
18352 else
18353 fixp->fx_offset = reloc->address;
18354 }
18355 reloc->addend = fixp->fx_offset;
18356
18357 switch (fixp->fx_r_type)
18358 {
18359 case BFD_RELOC_8:
18360 if (fixp->fx_pcrel)
18361 {
18362 code = BFD_RELOC_8_PCREL;
18363 break;
18364 }
18365
18366 case BFD_RELOC_16:
18367 if (fixp->fx_pcrel)
18368 {
18369 code = BFD_RELOC_16_PCREL;
18370 break;
18371 }
18372
18373 case BFD_RELOC_32:
18374 if (fixp->fx_pcrel)
18375 {
18376 code = BFD_RELOC_32_PCREL;
18377 break;
18378 }
18379
18380 case BFD_RELOC_ARM_MOVW:
18381 if (fixp->fx_pcrel)
18382 {
18383 code = BFD_RELOC_ARM_MOVW_PCREL;
18384 break;
18385 }
18386
18387 case BFD_RELOC_ARM_MOVT:
18388 if (fixp->fx_pcrel)
18389 {
18390 code = BFD_RELOC_ARM_MOVT_PCREL;
18391 break;
18392 }
18393
18394 case BFD_RELOC_ARM_THUMB_MOVW:
18395 if (fixp->fx_pcrel)
18396 {
18397 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
18398 break;
18399 }
18400
18401 case BFD_RELOC_ARM_THUMB_MOVT:
18402 if (fixp->fx_pcrel)
18403 {
18404 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
18405 break;
18406 }
18407
18408 case BFD_RELOC_NONE:
18409 case BFD_RELOC_ARM_PCREL_BRANCH:
18410 case BFD_RELOC_ARM_PCREL_BLX:
18411 case BFD_RELOC_RVA:
18412 case BFD_RELOC_THUMB_PCREL_BRANCH7:
18413 case BFD_RELOC_THUMB_PCREL_BRANCH9:
18414 case BFD_RELOC_THUMB_PCREL_BRANCH12:
18415 case BFD_RELOC_THUMB_PCREL_BRANCH20:
18416 case BFD_RELOC_THUMB_PCREL_BRANCH23:
18417 case BFD_RELOC_THUMB_PCREL_BRANCH25:
18418 case BFD_RELOC_THUMB_PCREL_BLX:
18419 case BFD_RELOC_VTABLE_ENTRY:
18420 case BFD_RELOC_VTABLE_INHERIT:
18421 code = fixp->fx_r_type;
18422 break;
18423
18424 case BFD_RELOC_ARM_LITERAL:
18425 case BFD_RELOC_ARM_HWLITERAL:
18426 /* If this is called then the a literal has
18427 been referenced across a section boundary. */
18428 as_bad_where (fixp->fx_file, fixp->fx_line,
18429 _("literal referenced across section boundary"));
18430 return NULL;
18431
18432 #ifdef OBJ_ELF
18433 case BFD_RELOC_ARM_GOT32:
18434 case BFD_RELOC_ARM_GOTOFF:
18435 case BFD_RELOC_ARM_PLT32:
18436 case BFD_RELOC_ARM_TARGET1:
18437 case BFD_RELOC_ARM_ROSEGREL32:
18438 case BFD_RELOC_ARM_SBREL32:
18439 case BFD_RELOC_ARM_PREL31:
18440 case BFD_RELOC_ARM_TARGET2:
18441 case BFD_RELOC_ARM_TLS_LE32:
18442 case BFD_RELOC_ARM_TLS_LDO32:
18443 case BFD_RELOC_ARM_PCREL_CALL:
18444 case BFD_RELOC_ARM_PCREL_JUMP:
18445 case BFD_RELOC_ARM_ALU_PC_G0_NC:
18446 case BFD_RELOC_ARM_ALU_PC_G0:
18447 case BFD_RELOC_ARM_ALU_PC_G1_NC:
18448 case BFD_RELOC_ARM_ALU_PC_G1:
18449 case BFD_RELOC_ARM_ALU_PC_G2:
18450 case BFD_RELOC_ARM_LDR_PC_G0:
18451 case BFD_RELOC_ARM_LDR_PC_G1:
18452 case BFD_RELOC_ARM_LDR_PC_G2:
18453 case BFD_RELOC_ARM_LDRS_PC_G0:
18454 case BFD_RELOC_ARM_LDRS_PC_G1:
18455 case BFD_RELOC_ARM_LDRS_PC_G2:
18456 case BFD_RELOC_ARM_LDC_PC_G0:
18457 case BFD_RELOC_ARM_LDC_PC_G1:
18458 case BFD_RELOC_ARM_LDC_PC_G2:
18459 case BFD_RELOC_ARM_ALU_SB_G0_NC:
18460 case BFD_RELOC_ARM_ALU_SB_G0:
18461 case BFD_RELOC_ARM_ALU_SB_G1_NC:
18462 case BFD_RELOC_ARM_ALU_SB_G1:
18463 case BFD_RELOC_ARM_ALU_SB_G2:
18464 case BFD_RELOC_ARM_LDR_SB_G0:
18465 case BFD_RELOC_ARM_LDR_SB_G1:
18466 case BFD_RELOC_ARM_LDR_SB_G2:
18467 case BFD_RELOC_ARM_LDRS_SB_G0:
18468 case BFD_RELOC_ARM_LDRS_SB_G1:
18469 case BFD_RELOC_ARM_LDRS_SB_G2:
18470 case BFD_RELOC_ARM_LDC_SB_G0:
18471 case BFD_RELOC_ARM_LDC_SB_G1:
18472 case BFD_RELOC_ARM_LDC_SB_G2:
18473 code = fixp->fx_r_type;
18474 break;
18475
18476 case BFD_RELOC_ARM_TLS_GD32:
18477 case BFD_RELOC_ARM_TLS_IE32:
18478 case BFD_RELOC_ARM_TLS_LDM32:
18479 /* BFD will include the symbol's address in the addend.
18480 But we don't want that, so subtract it out again here. */
18481 if (!S_IS_COMMON (fixp->fx_addsy))
18482 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
18483 code = fixp->fx_r_type;
18484 break;
18485 #endif
18486
18487 case BFD_RELOC_ARM_IMMEDIATE:
18488 as_bad_where (fixp->fx_file, fixp->fx_line,
18489 _("internal relocation (type: IMMEDIATE) not fixed up"));
18490 return NULL;
18491
18492 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
18493 as_bad_where (fixp->fx_file, fixp->fx_line,
18494 _("ADRL used for a symbol not defined in the same file"));
18495 return NULL;
18496
18497 case BFD_RELOC_ARM_OFFSET_IMM:
18498 if (section->use_rela_p)
18499 {
18500 code = fixp->fx_r_type;
18501 break;
18502 }
18503
18504 if (fixp->fx_addsy != NULL
18505 && !S_IS_DEFINED (fixp->fx_addsy)
18506 && S_IS_LOCAL (fixp->fx_addsy))
18507 {
18508 as_bad_where (fixp->fx_file, fixp->fx_line,
18509 _("undefined local label `%s'"),
18510 S_GET_NAME (fixp->fx_addsy));
18511 return NULL;
18512 }
18513
18514 as_bad_where (fixp->fx_file, fixp->fx_line,
18515 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
18516 return NULL;
18517
18518 default:
18519 {
18520 char * type;
18521
18522 switch (fixp->fx_r_type)
18523 {
18524 case BFD_RELOC_NONE: type = "NONE"; break;
18525 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
18526 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
18527 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
18528 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
18529 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
18530 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
18531 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
18532 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
18533 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
18534 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
18535 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
18536 default: type = _("<unknown>"); break;
18537 }
18538 as_bad_where (fixp->fx_file, fixp->fx_line,
18539 _("cannot represent %s relocation in this object file format"),
18540 type);
18541 return NULL;
18542 }
18543 }
18544
18545 #ifdef OBJ_ELF
18546 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
18547 && GOT_symbol
18548 && fixp->fx_addsy == GOT_symbol)
18549 {
18550 code = BFD_RELOC_ARM_GOTPC;
18551 reloc->addend = fixp->fx_offset = reloc->address;
18552 }
18553 #endif
18554
18555 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
18556
18557 if (reloc->howto == NULL)
18558 {
18559 as_bad_where (fixp->fx_file, fixp->fx_line,
18560 _("cannot represent %s relocation in this object file format"),
18561 bfd_get_reloc_code_name (code));
18562 return NULL;
18563 }
18564
18565 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
18566 vtable entry to be used in the relocation's section offset. */
18567 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
18568 reloc->address = fixp->fx_offset;
18569
18570 return reloc;
18571 }
18572
18573 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
18574
18575 void
18576 cons_fix_new_arm (fragS * frag,
18577 int where,
18578 int size,
18579 expressionS * exp)
18580 {
18581 bfd_reloc_code_real_type type;
18582 int pcrel = 0;
18583
18584 /* Pick a reloc.
18585 FIXME: @@ Should look at CPU word size. */
18586 switch (size)
18587 {
18588 case 1:
18589 type = BFD_RELOC_8;
18590 break;
18591 case 2:
18592 type = BFD_RELOC_16;
18593 break;
18594 case 4:
18595 default:
18596 type = BFD_RELOC_32;
18597 break;
18598 case 8:
18599 type = BFD_RELOC_64;
18600 break;
18601 }
18602
18603 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
18604 }
18605
18606 #if defined OBJ_COFF || defined OBJ_ELF
18607 void
18608 arm_validate_fix (fixS * fixP)
18609 {
18610 /* If the destination of the branch is a defined symbol which does not have
18611 the THUMB_FUNC attribute, then we must be calling a function which has
18612 the (interfacearm) attribute. We look for the Thumb entry point to that
18613 function and change the branch to refer to that function instead. */
18614 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
18615 && fixP->fx_addsy != NULL
18616 && S_IS_DEFINED (fixP->fx_addsy)
18617 && ! THUMB_IS_FUNC (fixP->fx_addsy))
18618 {
18619 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
18620 }
18621 }
18622 #endif
18623
18624 int
18625 arm_force_relocation (struct fix * fixp)
18626 {
18627 #if defined (OBJ_COFF) && defined (TE_PE)
18628 if (fixp->fx_r_type == BFD_RELOC_RVA)
18629 return 1;
18630 #endif
18631
18632 /* Resolve these relocations even if the symbol is extern or weak. */
18633 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
18634 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
18635 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
18636 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
18637 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
18638 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
18639 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
18640 return 0;
18641
18642 /* Always leave these relocations for the linker. */
18643 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
18644 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
18645 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
18646 return 1;
18647
18648 return generic_force_reloc (fixp);
18649 }
18650
18651 #ifdef OBJ_COFF
18652 bfd_boolean
18653 arm_fix_adjustable (fixS * fixP)
18654 {
18655 /* This is a little hack to help the gas/arm/adrl.s test. It prevents
18656 local labels from being added to the output symbol table when they
18657 are used with the ADRL pseudo op. The ADRL relocation should always
18658 be resolved before the binbary is emitted, so it is safe to say that
18659 it is adjustable. */
18660 if (fixP->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE)
18661 return 1;
18662
18663 /* This is a hack for the gas/all/redef2.s test. This test causes symbols
18664 to be cloned, and without this test relocs would still be generated
18665 against the original, pre-cloned symbol. Such symbols would not appear
18666 in the symbol table however, and so a valid reloc could not be
18667 generated. So check to see if the fixup is against a symbol which has
18668 been removed from the symbol chain, and if it is, then allow it to be
18669 adjusted into a reloc against a section symbol. */
18670 if (fixP->fx_addsy != NULL
18671 && ! S_IS_LOCAL (fixP->fx_addsy)
18672 && symbol_next (fixP->fx_addsy) == NULL
18673 && symbol_next (fixP->fx_addsy) == symbol_previous (fixP->fx_addsy))
18674 return 1;
18675
18676 return 0;
18677 }
18678 #endif
18679
18680 #ifdef OBJ_ELF
18681 /* Relocations against function names must be left unadjusted,
18682 so that the linker can use this information to generate interworking
18683 stubs. The MIPS version of this function
18684 also prevents relocations that are mips-16 specific, but I do not
18685 know why it does this.
18686
18687 FIXME:
18688 There is one other problem that ought to be addressed here, but
18689 which currently is not: Taking the address of a label (rather
18690 than a function) and then later jumping to that address. Such
18691 addresses also ought to have their bottom bit set (assuming that
18692 they reside in Thumb code), but at the moment they will not. */
18693
18694 bfd_boolean
18695 arm_fix_adjustable (fixS * fixP)
18696 {
18697 if (fixP->fx_addsy == NULL)
18698 return 1;
18699
18700 /* Preserve relocations against symbols with function type. */
18701 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
18702 return 0;
18703
18704 if (THUMB_IS_FUNC (fixP->fx_addsy)
18705 && fixP->fx_subsy == NULL)
18706 return 0;
18707
18708 /* We need the symbol name for the VTABLE entries. */
18709 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
18710 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
18711 return 0;
18712
18713 /* Don't allow symbols to be discarded on GOT related relocs. */
18714 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
18715 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
18716 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
18717 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
18718 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
18719 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
18720 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
18721 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
18722 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
18723 return 0;
18724
18725 /* Similarly for group relocations. */
18726 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
18727 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
18728 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
18729 return 0;
18730
18731 return 1;
18732 }
18733
18734 const char *
18735 elf32_arm_target_format (void)
18736 {
18737 #ifdef TE_SYMBIAN
18738 return (target_big_endian
18739 ? "elf32-bigarm-symbian"
18740 : "elf32-littlearm-symbian");
18741 #elif defined (TE_VXWORKS)
18742 return (target_big_endian
18743 ? "elf32-bigarm-vxworks"
18744 : "elf32-littlearm-vxworks");
18745 #else
18746 if (target_big_endian)
18747 return "elf32-bigarm";
18748 else
18749 return "elf32-littlearm";
18750 #endif
18751 }
18752
18753 void
18754 armelf_frob_symbol (symbolS * symp,
18755 int * puntp)
18756 {
18757 elf_frob_symbol (symp, puntp);
18758 }
18759 #endif
18760
18761 /* MD interface: Finalization. */
18762
18763 /* A good place to do this, although this was probably not intended
18764 for this kind of use. We need to dump the literal pool before
18765 references are made to a null symbol pointer. */
18766
18767 void
18768 arm_cleanup (void)
18769 {
18770 literal_pool * pool;
18771
18772 for (pool = list_of_pools; pool; pool = pool->next)
18773 {
18774 /* Put it at the end of the relevent section. */
18775 subseg_set (pool->section, pool->sub_section);
18776 #ifdef OBJ_ELF
18777 arm_elf_change_section ();
18778 #endif
18779 s_ltorg (0);
18780 }
18781 }
18782
18783 /* Adjust the symbol table. This marks Thumb symbols as distinct from
18784 ARM ones. */
18785
18786 void
18787 arm_adjust_symtab (void)
18788 {
18789 #ifdef OBJ_COFF
18790 symbolS * sym;
18791
18792 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
18793 {
18794 if (ARM_IS_THUMB (sym))
18795 {
18796 if (THUMB_IS_FUNC (sym))
18797 {
18798 /* Mark the symbol as a Thumb function. */
18799 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
18800 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
18801 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
18802
18803 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
18804 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
18805 else
18806 as_bad (_("%s: unexpected function type: %d"),
18807 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
18808 }
18809 else switch (S_GET_STORAGE_CLASS (sym))
18810 {
18811 case C_EXT:
18812 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
18813 break;
18814 case C_STAT:
18815 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
18816 break;
18817 case C_LABEL:
18818 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
18819 break;
18820 default:
18821 /* Do nothing. */
18822 break;
18823 }
18824 }
18825
18826 if (ARM_IS_INTERWORK (sym))
18827 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
18828 }
18829 #endif
18830 #ifdef OBJ_ELF
18831 symbolS * sym;
18832 char bind;
18833
18834 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
18835 {
18836 if (ARM_IS_THUMB (sym))
18837 {
18838 elf_symbol_type * elf_sym;
18839
18840 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
18841 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
18842
18843 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
18844 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
18845 {
18846 /* If it's a .thumb_func, declare it as so,
18847 otherwise tag label as .code 16. */
18848 if (THUMB_IS_FUNC (sym))
18849 elf_sym->internal_elf_sym.st_info =
18850 ELF_ST_INFO (bind, STT_ARM_TFUNC);
18851 else
18852 elf_sym->internal_elf_sym.st_info =
18853 ELF_ST_INFO (bind, STT_ARM_16BIT);
18854 }
18855 }
18856 }
18857 #endif
18858 }
18859
18860 /* MD interface: Initialization. */
18861
18862 static void
18863 set_constant_flonums (void)
18864 {
18865 int i;
18866
18867 for (i = 0; i < NUM_FLOAT_VALS; i++)
18868 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
18869 abort ();
18870 }
18871
18872 void
18873 md_begin (void)
18874 {
18875 unsigned mach;
18876 unsigned int i;
18877
18878 if ( (arm_ops_hsh = hash_new ()) == NULL
18879 || (arm_cond_hsh = hash_new ()) == NULL
18880 || (arm_shift_hsh = hash_new ()) == NULL
18881 || (arm_psr_hsh = hash_new ()) == NULL
18882 || (arm_v7m_psr_hsh = hash_new ()) == NULL
18883 || (arm_reg_hsh = hash_new ()) == NULL
18884 || (arm_reloc_hsh = hash_new ()) == NULL
18885 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
18886 as_fatal (_("virtual memory exhausted"));
18887
18888 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
18889 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
18890 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
18891 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
18892 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
18893 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
18894 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
18895 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
18896 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
18897 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (PTR) (v7m_psrs + i));
18898 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
18899 hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i));
18900 for (i = 0;
18901 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
18902 i++)
18903 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
18904 (PTR) (barrier_opt_names + i));
18905 #ifdef OBJ_ELF
18906 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
18907 hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i));
18908 #endif
18909
18910 set_constant_flonums ();
18911
18912 /* Set the cpu variant based on the command-line options. We prefer
18913 -mcpu= over -march= if both are set (as for GCC); and we prefer
18914 -mfpu= over any other way of setting the floating point unit.
18915 Use of legacy options with new options are faulted. */
18916 if (legacy_cpu)
18917 {
18918 if (mcpu_cpu_opt || march_cpu_opt)
18919 as_bad (_("use of old and new-style options to set CPU type"));
18920
18921 mcpu_cpu_opt = legacy_cpu;
18922 }
18923 else if (!mcpu_cpu_opt)
18924 mcpu_cpu_opt = march_cpu_opt;
18925
18926 if (legacy_fpu)
18927 {
18928 if (mfpu_opt)
18929 as_bad (_("use of old and new-style options to set FPU type"));
18930
18931 mfpu_opt = legacy_fpu;
18932 }
18933 else if (!mfpu_opt)
18934 {
18935 #if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
18936 /* Some environments specify a default FPU. If they don't, infer it
18937 from the processor. */
18938 if (mcpu_fpu_opt)
18939 mfpu_opt = mcpu_fpu_opt;
18940 else
18941 mfpu_opt = march_fpu_opt;
18942 #else
18943 mfpu_opt = &fpu_default;
18944 #endif
18945 }
18946
18947 if (!mfpu_opt)
18948 {
18949 if (!mcpu_cpu_opt)
18950 mfpu_opt = &fpu_default;
18951 else if (ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
18952 mfpu_opt = &fpu_arch_vfp_v2;
18953 else
18954 mfpu_opt = &fpu_arch_fpa;
18955 }
18956
18957 #ifdef CPU_DEFAULT
18958 if (!mcpu_cpu_opt)
18959 {
18960 mcpu_cpu_opt = &cpu_default;
18961 selected_cpu = cpu_default;
18962 }
18963 #else
18964 if (mcpu_cpu_opt)
18965 selected_cpu = *mcpu_cpu_opt;
18966 else
18967 mcpu_cpu_opt = &arm_arch_any;
18968 #endif
18969
18970 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
18971
18972 arm_arch_used = thumb_arch_used = arm_arch_none;
18973
18974 #if defined OBJ_COFF || defined OBJ_ELF
18975 {
18976 unsigned int flags = 0;
18977
18978 #if defined OBJ_ELF
18979 flags = meabi_flags;
18980
18981 switch (meabi_flags)
18982 {
18983 case EF_ARM_EABI_UNKNOWN:
18984 #endif
18985 /* Set the flags in the private structure. */
18986 if (uses_apcs_26) flags |= F_APCS26;
18987 if (support_interwork) flags |= F_INTERWORK;
18988 if (uses_apcs_float) flags |= F_APCS_FLOAT;
18989 if (pic_code) flags |= F_PIC;
18990 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
18991 flags |= F_SOFT_FLOAT;
18992
18993 switch (mfloat_abi_opt)
18994 {
18995 case ARM_FLOAT_ABI_SOFT:
18996 case ARM_FLOAT_ABI_SOFTFP:
18997 flags |= F_SOFT_FLOAT;
18998 break;
18999
19000 case ARM_FLOAT_ABI_HARD:
19001 if (flags & F_SOFT_FLOAT)
19002 as_bad (_("hard-float conflicts with specified fpu"));
19003 break;
19004 }
19005
19006 /* Using pure-endian doubles (even if soft-float). */
19007 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
19008 flags |= F_VFP_FLOAT;
19009
19010 #if defined OBJ_ELF
19011 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
19012 flags |= EF_ARM_MAVERICK_FLOAT;
19013 break;
19014
19015 case EF_ARM_EABI_VER4:
19016 case EF_ARM_EABI_VER5:
19017 /* No additional flags to set. */
19018 break;
19019
19020 default:
19021 abort ();
19022 }
19023 #endif
19024 bfd_set_private_flags (stdoutput, flags);
19025
19026 /* We have run out flags in the COFF header to encode the
19027 status of ATPCS support, so instead we create a dummy,
19028 empty, debug section called .arm.atpcs. */
19029 if (atpcs)
19030 {
19031 asection * sec;
19032
19033 sec = bfd_make_section (stdoutput, ".arm.atpcs");
19034
19035 if (sec != NULL)
19036 {
19037 bfd_set_section_flags
19038 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
19039 bfd_set_section_size (stdoutput, sec, 0);
19040 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
19041 }
19042 }
19043 }
19044 #endif
19045
19046 /* Record the CPU type as well. */
19047 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
19048 mach = bfd_mach_arm_iWMMXt;
19049 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
19050 mach = bfd_mach_arm_XScale;
19051 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
19052 mach = bfd_mach_arm_ep9312;
19053 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
19054 mach = bfd_mach_arm_5TE;
19055 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
19056 {
19057 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
19058 mach = bfd_mach_arm_5T;
19059 else
19060 mach = bfd_mach_arm_5;
19061 }
19062 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
19063 {
19064 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
19065 mach = bfd_mach_arm_4T;
19066 else
19067 mach = bfd_mach_arm_4;
19068 }
19069 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
19070 mach = bfd_mach_arm_3M;
19071 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
19072 mach = bfd_mach_arm_3;
19073 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
19074 mach = bfd_mach_arm_2a;
19075 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
19076 mach = bfd_mach_arm_2;
19077 else
19078 mach = bfd_mach_arm_unknown;
19079
19080 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
19081 }
19082
19083 /* Command line processing. */
19084
19085 /* md_parse_option
19086 Invocation line includes a switch not recognized by the base assembler.
19087 See if it's a processor-specific option.
19088
19089 This routine is somewhat complicated by the need for backwards
19090 compatibility (since older releases of gcc can't be changed).
19091 The new options try to make the interface as compatible as
19092 possible with GCC.
19093
19094 New options (supported) are:
19095
19096 -mcpu=<cpu name> Assemble for selected processor
19097 -march=<architecture name> Assemble for selected architecture
19098 -mfpu=<fpu architecture> Assemble for selected FPU.
19099 -EB/-mbig-endian Big-endian
19100 -EL/-mlittle-endian Little-endian
19101 -k Generate PIC code
19102 -mthumb Start in Thumb mode
19103 -mthumb-interwork Code supports ARM/Thumb interworking
19104
19105 For now we will also provide support for:
19106
19107 -mapcs-32 32-bit Program counter
19108 -mapcs-26 26-bit Program counter
19109 -macps-float Floats passed in FP registers
19110 -mapcs-reentrant Reentrant code
19111 -matpcs
19112 (sometime these will probably be replaced with -mapcs=<list of options>
19113 and -matpcs=<list of options>)
19114
19115 The remaining options are only supported for back-wards compatibility.
19116 Cpu variants, the arm part is optional:
19117 -m[arm]1 Currently not supported.
19118 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
19119 -m[arm]3 Arm 3 processor
19120 -m[arm]6[xx], Arm 6 processors
19121 -m[arm]7[xx][t][[d]m] Arm 7 processors
19122 -m[arm]8[10] Arm 8 processors
19123 -m[arm]9[20][tdmi] Arm 9 processors
19124 -mstrongarm[110[0]] StrongARM processors
19125 -mxscale XScale processors
19126 -m[arm]v[2345[t[e]]] Arm architectures
19127 -mall All (except the ARM1)
19128 FP variants:
19129 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
19130 -mfpe-old (No float load/store multiples)
19131 -mvfpxd VFP Single precision
19132 -mvfp All VFP
19133 -mno-fpu Disable all floating point instructions
19134
19135 The following CPU names are recognized:
19136 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
19137 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
19138 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
19139 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
19140 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
19141 arm10t arm10e, arm1020t, arm1020e, arm10200e,
19142 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
19143
19144 */
19145
19146 const char * md_shortopts = "m:k";
19147
19148 #ifdef ARM_BI_ENDIAN
19149 #define OPTION_EB (OPTION_MD_BASE + 0)
19150 #define OPTION_EL (OPTION_MD_BASE + 1)
19151 #else
19152 #if TARGET_BYTES_BIG_ENDIAN
19153 #define OPTION_EB (OPTION_MD_BASE + 0)
19154 #else
19155 #define OPTION_EL (OPTION_MD_BASE + 1)
19156 #endif
19157 #endif
19158
19159 struct option md_longopts[] =
19160 {
19161 #ifdef OPTION_EB
19162 {"EB", no_argument, NULL, OPTION_EB},
19163 #endif
19164 #ifdef OPTION_EL
19165 {"EL", no_argument, NULL, OPTION_EL},
19166 #endif
19167 {NULL, no_argument, NULL, 0}
19168 };
19169
19170 size_t md_longopts_size = sizeof (md_longopts);
19171
19172 struct arm_option_table
19173 {
19174 char *option; /* Option name to match. */
19175 char *help; /* Help information. */
19176 int *var; /* Variable to change. */
19177 int value; /* What to change it to. */
19178 char *deprecated; /* If non-null, print this message. */
19179 };
19180
19181 struct arm_option_table arm_opts[] =
19182 {
19183 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
19184 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
19185 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
19186 &support_interwork, 1, NULL},
19187 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
19188 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
19189 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
19190 1, NULL},
19191 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
19192 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
19193 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
19194 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
19195 NULL},
19196
19197 /* These are recognized by the assembler, but have no affect on code. */
19198 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
19199 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
19200 {NULL, NULL, NULL, 0, NULL}
19201 };
19202
19203 struct arm_legacy_option_table
19204 {
19205 char *option; /* Option name to match. */
19206 const arm_feature_set **var; /* Variable to change. */
19207 const arm_feature_set value; /* What to change it to. */
19208 char *deprecated; /* If non-null, print this message. */
19209 };
19210
19211 const struct arm_legacy_option_table arm_legacy_opts[] =
19212 {
19213 /* DON'T add any new processors to this list -- we want the whole list
19214 to go away... Add them to the processors table instead. */
19215 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19216 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19217 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19218 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19219 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19220 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19221 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19222 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19223 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19224 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19225 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19226 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19227 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19228 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19229 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19230 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19231 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19232 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19233 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19234 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19235 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19236 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19237 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19238 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19239 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19240 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19241 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19242 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19243 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19244 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19245 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19246 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19247 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19248 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19249 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19250 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19251 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19252 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19253 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19254 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19255 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19256 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19257 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19258 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19259 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19260 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19261 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19262 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19263 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19264 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19265 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19266 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19267 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19268 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19269 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19270 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19271 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19272 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19273 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19274 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19275 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19276 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19277 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19278 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19279 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19280 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19281 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19282 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19283 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
19284 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
19285 N_("use -mcpu=strongarm110")},
19286 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
19287 N_("use -mcpu=strongarm1100")},
19288 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
19289 N_("use -mcpu=strongarm1110")},
19290 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
19291 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
19292 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
19293
19294 /* Architecture variants -- don't add any more to this list either. */
19295 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19296 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19297 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19298 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19299 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19300 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19301 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
19302 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
19303 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
19304 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
19305 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
19306 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
19307 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
19308 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
19309 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
19310 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
19311 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
19312 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
19313
19314 /* Floating point variants -- don't add any more to this list either. */
19315 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
19316 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
19317 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
19318 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
19319 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
19320
19321 {NULL, NULL, ARM_ARCH_NONE, NULL}
19322 };
19323
19324 struct arm_cpu_option_table
19325 {
19326 char *name;
19327 const arm_feature_set value;
19328 /* For some CPUs we assume an FPU unless the user explicitly sets
19329 -mfpu=... */
19330 const arm_feature_set default_fpu;
19331 /* The canonical name of the CPU, or NULL to use NAME converted to upper
19332 case. */
19333 const char *canonical_name;
19334 };
19335
19336 /* This list should, at a minimum, contain all the cpu names
19337 recognized by GCC. */
19338 static const struct arm_cpu_option_table arm_cpus[] =
19339 {
19340 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
19341 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
19342 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
19343 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
19344 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
19345 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19346 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19347 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19348 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19349 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19350 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19351 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
19352 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19353 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
19354 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19355 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
19356 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19357 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19358 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19359 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19360 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19361 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19362 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19363 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19364 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19365 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19366 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19367 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19368 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19369 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19370 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19371 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19372 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19373 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19374 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19375 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19376 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19377 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19378 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19379 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
19380 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19381 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19382 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19383 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19384 /* For V5 or later processors we default to using VFP; but the user
19385 should really set the FPU type explicitly. */
19386 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
19387 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19388 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
19389 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
19390 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
19391 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
19392 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
19393 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19394 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
19395 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
19396 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19397 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19398 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
19399 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
19400 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19401 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
19402 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
19403 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19404 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19405 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
19406 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
19407 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
19408 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
19409 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
19410 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
19411 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
19412 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
19413 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
19414 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
19415 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
19416 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
19417 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
19418 | FPU_NEON_EXT_V1),
19419 NULL},
19420 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
19421 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
19422 /* ??? XSCALE is really an architecture. */
19423 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
19424 /* ??? iwmmxt is not a processor. */
19425 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
19426 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
19427 /* Maverick */
19428 {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
19429 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
19430 };
19431
19432 struct arm_arch_option_table
19433 {
19434 char *name;
19435 const arm_feature_set value;
19436 const arm_feature_set default_fpu;
19437 };
19438
19439 /* This list should, at a minimum, contain all the architecture names
19440 recognized by GCC. */
19441 static const struct arm_arch_option_table arm_archs[] =
19442 {
19443 {"all", ARM_ANY, FPU_ARCH_FPA},
19444 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
19445 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
19446 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
19447 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
19448 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
19449 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
19450 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
19451 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
19452 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
19453 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
19454 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
19455 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
19456 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
19457 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
19458 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
19459 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
19460 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
19461 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
19462 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
19463 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
19464 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
19465 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
19466 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
19467 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
19468 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
19469 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
19470 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
19471 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
19472 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
19473 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
19474 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
19475 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
19476 };
19477
19478 /* ISA extensions in the co-processor space. */
19479 struct arm_option_cpu_value_table
19480 {
19481 char *name;
19482 const arm_feature_set value;
19483 };
19484
19485 static const struct arm_option_cpu_value_table arm_extensions[] =
19486 {
19487 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
19488 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
19489 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
19490 {NULL, ARM_ARCH_NONE}
19491 };
19492
19493 /* This list should, at a minimum, contain all the fpu names
19494 recognized by GCC. */
19495 static const struct arm_option_cpu_value_table arm_fpus[] =
19496 {
19497 {"softfpa", FPU_NONE},
19498 {"fpe", FPU_ARCH_FPE},
19499 {"fpe2", FPU_ARCH_FPE},
19500 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
19501 {"fpa", FPU_ARCH_FPA},
19502 {"fpa10", FPU_ARCH_FPA},
19503 {"fpa11", FPU_ARCH_FPA},
19504 {"arm7500fe", FPU_ARCH_FPA},
19505 {"softvfp", FPU_ARCH_VFP},
19506 {"softvfp+vfp", FPU_ARCH_VFP_V2},
19507 {"vfp", FPU_ARCH_VFP_V2},
19508 {"vfp9", FPU_ARCH_VFP_V2},
19509 {"vfp3", FPU_ARCH_VFP_V3},
19510 {"vfp10", FPU_ARCH_VFP_V2},
19511 {"vfp10-r0", FPU_ARCH_VFP_V1},
19512 {"vfpxd", FPU_ARCH_VFP_V1xD},
19513 {"arm1020t", FPU_ARCH_VFP_V1},
19514 {"arm1020e", FPU_ARCH_VFP_V2},
19515 {"arm1136jfs", FPU_ARCH_VFP_V2},
19516 {"arm1136jf-s", FPU_ARCH_VFP_V2},
19517 {"maverick", FPU_ARCH_MAVERICK},
19518 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
19519 {NULL, ARM_ARCH_NONE}
19520 };
19521
19522 struct arm_option_value_table
19523 {
19524 char *name;
19525 long value;
19526 };
19527
19528 static const struct arm_option_value_table arm_float_abis[] =
19529 {
19530 {"hard", ARM_FLOAT_ABI_HARD},
19531 {"softfp", ARM_FLOAT_ABI_SOFTFP},
19532 {"soft", ARM_FLOAT_ABI_SOFT},
19533 {NULL, 0}
19534 };
19535
19536 #ifdef OBJ_ELF
19537 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
19538 static const struct arm_option_value_table arm_eabis[] =
19539 {
19540 {"gnu", EF_ARM_EABI_UNKNOWN},
19541 {"4", EF_ARM_EABI_VER4},
19542 {"5", EF_ARM_EABI_VER5},
19543 {NULL, 0}
19544 };
19545 #endif
19546
19547 struct arm_long_option_table
19548 {
19549 char * option; /* Substring to match. */
19550 char * help; /* Help information. */
19551 int (* func) (char * subopt); /* Function to decode sub-option. */
19552 char * deprecated; /* If non-null, print this message. */
19553 };
19554
19555 static int
19556 arm_parse_extension (char * str, const arm_feature_set **opt_p)
19557 {
19558 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
19559
19560 /* Copy the feature set, so that we can modify it. */
19561 *ext_set = **opt_p;
19562 *opt_p = ext_set;
19563
19564 while (str != NULL && *str != 0)
19565 {
19566 const struct arm_option_cpu_value_table * opt;
19567 char * ext;
19568 int optlen;
19569
19570 if (*str != '+')
19571 {
19572 as_bad (_("invalid architectural extension"));
19573 return 0;
19574 }
19575
19576 str++;
19577 ext = strchr (str, '+');
19578
19579 if (ext != NULL)
19580 optlen = ext - str;
19581 else
19582 optlen = strlen (str);
19583
19584 if (optlen == 0)
19585 {
19586 as_bad (_("missing architectural extension"));
19587 return 0;
19588 }
19589
19590 for (opt = arm_extensions; opt->name != NULL; opt++)
19591 if (strncmp (opt->name, str, optlen) == 0)
19592 {
19593 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
19594 break;
19595 }
19596
19597 if (opt->name == NULL)
19598 {
19599 as_bad (_("unknown architectural extnsion `%s'"), str);
19600 return 0;
19601 }
19602
19603 str = ext;
19604 };
19605
19606 return 1;
19607 }
19608
19609 static int
19610 arm_parse_cpu (char * str)
19611 {
19612 const struct arm_cpu_option_table * opt;
19613 char * ext = strchr (str, '+');
19614 int optlen;
19615
19616 if (ext != NULL)
19617 optlen = ext - str;
19618 else
19619 optlen = strlen (str);
19620
19621 if (optlen == 0)
19622 {
19623 as_bad (_("missing cpu name `%s'"), str);
19624 return 0;
19625 }
19626
19627 for (opt = arm_cpus; opt->name != NULL; opt++)
19628 if (strncmp (opt->name, str, optlen) == 0)
19629 {
19630 mcpu_cpu_opt = &opt->value;
19631 mcpu_fpu_opt = &opt->default_fpu;
19632 if (opt->canonical_name)
19633 strcpy(selected_cpu_name, opt->canonical_name);
19634 else
19635 {
19636 int i;
19637 for (i = 0; i < optlen; i++)
19638 selected_cpu_name[i] = TOUPPER (opt->name[i]);
19639 selected_cpu_name[i] = 0;
19640 }
19641
19642 if (ext != NULL)
19643 return arm_parse_extension (ext, &mcpu_cpu_opt);
19644
19645 return 1;
19646 }
19647
19648 as_bad (_("unknown cpu `%s'"), str);
19649 return 0;
19650 }
19651
19652 static int
19653 arm_parse_arch (char * str)
19654 {
19655 const struct arm_arch_option_table *opt;
19656 char *ext = strchr (str, '+');
19657 int optlen;
19658
19659 if (ext != NULL)
19660 optlen = ext - str;
19661 else
19662 optlen = strlen (str);
19663
19664 if (optlen == 0)
19665 {
19666 as_bad (_("missing architecture name `%s'"), str);
19667 return 0;
19668 }
19669
19670 for (opt = arm_archs; opt->name != NULL; opt++)
19671 if (streq (opt->name, str))
19672 {
19673 march_cpu_opt = &opt->value;
19674 march_fpu_opt = &opt->default_fpu;
19675 strcpy(selected_cpu_name, opt->name);
19676
19677 if (ext != NULL)
19678 return arm_parse_extension (ext, &march_cpu_opt);
19679
19680 return 1;
19681 }
19682
19683 as_bad (_("unknown architecture `%s'\n"), str);
19684 return 0;
19685 }
19686
19687 static int
19688 arm_parse_fpu (char * str)
19689 {
19690 const struct arm_option_cpu_value_table * opt;
19691
19692 for (opt = arm_fpus; opt->name != NULL; opt++)
19693 if (streq (opt->name, str))
19694 {
19695 mfpu_opt = &opt->value;
19696 return 1;
19697 }
19698
19699 as_bad (_("unknown floating point format `%s'\n"), str);
19700 return 0;
19701 }
19702
19703 static int
19704 arm_parse_float_abi (char * str)
19705 {
19706 const struct arm_option_value_table * opt;
19707
19708 for (opt = arm_float_abis; opt->name != NULL; opt++)
19709 if (streq (opt->name, str))
19710 {
19711 mfloat_abi_opt = opt->value;
19712 return 1;
19713 }
19714
19715 as_bad (_("unknown floating point abi `%s'\n"), str);
19716 return 0;
19717 }
19718
19719 #ifdef OBJ_ELF
19720 static int
19721 arm_parse_eabi (char * str)
19722 {
19723 const struct arm_option_value_table *opt;
19724
19725 for (opt = arm_eabis; opt->name != NULL; opt++)
19726 if (streq (opt->name, str))
19727 {
19728 meabi_flags = opt->value;
19729 return 1;
19730 }
19731 as_bad (_("unknown EABI `%s'\n"), str);
19732 return 0;
19733 }
19734 #endif
19735
19736 struct arm_long_option_table arm_long_opts[] =
19737 {
19738 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
19739 arm_parse_cpu, NULL},
19740 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
19741 arm_parse_arch, NULL},
19742 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
19743 arm_parse_fpu, NULL},
19744 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
19745 arm_parse_float_abi, NULL},
19746 #ifdef OBJ_ELF
19747 {"meabi=", N_("<ver>\t assemble for eabi version <ver>"),
19748 arm_parse_eabi, NULL},
19749 #endif
19750 {NULL, NULL, 0, NULL}
19751 };
19752
19753 int
19754 md_parse_option (int c, char * arg)
19755 {
19756 struct arm_option_table *opt;
19757 const struct arm_legacy_option_table *fopt;
19758 struct arm_long_option_table *lopt;
19759
19760 switch (c)
19761 {
19762 #ifdef OPTION_EB
19763 case OPTION_EB:
19764 target_big_endian = 1;
19765 break;
19766 #endif
19767
19768 #ifdef OPTION_EL
19769 case OPTION_EL:
19770 target_big_endian = 0;
19771 break;
19772 #endif
19773
19774 case 'a':
19775 /* Listing option. Just ignore these, we don't support additional
19776 ones. */
19777 return 0;
19778
19779 default:
19780 for (opt = arm_opts; opt->option != NULL; opt++)
19781 {
19782 if (c == opt->option[0]
19783 && ((arg == NULL && opt->option[1] == 0)
19784 || streq (arg, opt->option + 1)))
19785 {
19786 #if WARN_DEPRECATED
19787 /* If the option is deprecated, tell the user. */
19788 if (opt->deprecated != NULL)
19789 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
19790 arg ? arg : "", _(opt->deprecated));
19791 #endif
19792
19793 if (opt->var != NULL)
19794 *opt->var = opt->value;
19795
19796 return 1;
19797 }
19798 }
19799
19800 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
19801 {
19802 if (c == fopt->option[0]
19803 && ((arg == NULL && fopt->option[1] == 0)
19804 || streq (arg, fopt->option + 1)))
19805 {
19806 #if WARN_DEPRECATED
19807 /* If the option is deprecated, tell the user. */
19808 if (fopt->deprecated != NULL)
19809 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
19810 arg ? arg : "", _(fopt->deprecated));
19811 #endif
19812
19813 if (fopt->var != NULL)
19814 *fopt->var = &fopt->value;
19815
19816 return 1;
19817 }
19818 }
19819
19820 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
19821 {
19822 /* These options are expected to have an argument. */
19823 if (c == lopt->option[0]
19824 && arg != NULL
19825 && strncmp (arg, lopt->option + 1,
19826 strlen (lopt->option + 1)) == 0)
19827 {
19828 #if WARN_DEPRECATED
19829 /* If the option is deprecated, tell the user. */
19830 if (lopt->deprecated != NULL)
19831 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
19832 _(lopt->deprecated));
19833 #endif
19834
19835 /* Call the sup-option parser. */
19836 return lopt->func (arg + strlen (lopt->option) - 1);
19837 }
19838 }
19839
19840 return 0;
19841 }
19842
19843 return 1;
19844 }
19845
19846 void
19847 md_show_usage (FILE * fp)
19848 {
19849 struct arm_option_table *opt;
19850 struct arm_long_option_table *lopt;
19851
19852 fprintf (fp, _(" ARM-specific assembler options:\n"));
19853
19854 for (opt = arm_opts; opt->option != NULL; opt++)
19855 if (opt->help != NULL)
19856 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
19857
19858 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
19859 if (lopt->help != NULL)
19860 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
19861
19862 #ifdef OPTION_EB
19863 fprintf (fp, _("\
19864 -EB assemble code for a big-endian cpu\n"));
19865 #endif
19866
19867 #ifdef OPTION_EL
19868 fprintf (fp, _("\
19869 -EL assemble code for a little-endian cpu\n"));
19870 #endif
19871 }
19872
19873
19874 #ifdef OBJ_ELF
19875 typedef struct
19876 {
19877 int val;
19878 arm_feature_set flags;
19879 } cpu_arch_ver_table;
19880
19881 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
19882 least features first. */
19883 static const cpu_arch_ver_table cpu_arch_ver[] =
19884 {
19885 {1, ARM_ARCH_V4},
19886 {2, ARM_ARCH_V4T},
19887 {3, ARM_ARCH_V5},
19888 {4, ARM_ARCH_V5TE},
19889 {5, ARM_ARCH_V5TEJ},
19890 {6, ARM_ARCH_V6},
19891 {7, ARM_ARCH_V6Z},
19892 {8, ARM_ARCH_V6K},
19893 {9, ARM_ARCH_V6T2},
19894 {10, ARM_ARCH_V7A},
19895 {10, ARM_ARCH_V7R},
19896 {10, ARM_ARCH_V7M},
19897 {0, ARM_ARCH_NONE}
19898 };
19899
19900 /* Set the public EABI object attributes. */
19901 static void
19902 aeabi_set_public_attributes (void)
19903 {
19904 int arch;
19905 arm_feature_set flags;
19906 arm_feature_set tmp;
19907 const cpu_arch_ver_table *p;
19908
19909 /* Choose the architecture based on the capabilities of the requested cpu
19910 (if any) and/or the instructions actually used. */
19911 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
19912 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
19913 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
19914
19915 tmp = flags;
19916 arch = 0;
19917 for (p = cpu_arch_ver; p->val; p++)
19918 {
19919 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
19920 {
19921 arch = p->val;
19922 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
19923 }
19924 }
19925
19926 /* Tag_CPU_name. */
19927 if (selected_cpu_name[0])
19928 {
19929 char *p;
19930
19931 p = selected_cpu_name;
19932 if (strncmp(p, "armv", 4) == 0)
19933 {
19934 int i;
19935
19936 p += 4;
19937 for (i = 0; p[i]; i++)
19938 p[i] = TOUPPER (p[i]);
19939 }
19940 elf32_arm_add_eabi_attr_string (stdoutput, 5, p);
19941 }
19942 /* Tag_CPU_arch. */
19943 elf32_arm_add_eabi_attr_int (stdoutput, 6, arch);
19944 /* Tag_CPU_arch_profile. */
19945 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
19946 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'A');
19947 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
19948 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'R');
19949 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m))
19950 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'M');
19951 /* Tag_ARM_ISA_use. */
19952 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_full))
19953 elf32_arm_add_eabi_attr_int (stdoutput, 8, 1);
19954 /* Tag_THUMB_ISA_use. */
19955 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_full))
19956 elf32_arm_add_eabi_attr_int (stdoutput, 9,
19957 ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2) ? 2 : 1);
19958 /* Tag_VFP_arch. */
19959 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v3)
19960 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v3))
19961 elf32_arm_add_eabi_attr_int (stdoutput, 10, 3);
19962 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v2)
19963 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v2))
19964 elf32_arm_add_eabi_attr_int (stdoutput, 10, 2);
19965 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1)
19966 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1)
19967 || ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1xd)
19968 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1xd))
19969 elf32_arm_add_eabi_attr_int (stdoutput, 10, 1);
19970 /* Tag_WMMX_arch. */
19971 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_cext_iwmmxt)
19972 || ARM_CPU_HAS_FEATURE (arm_arch_used, arm_cext_iwmmxt))
19973 elf32_arm_add_eabi_attr_int (stdoutput, 11, 1);
19974 /* Tag_NEON_arch. */
19975 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_neon_ext_v1)
19976 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_neon_ext_v1))
19977 elf32_arm_add_eabi_attr_int (stdoutput, 12, 1);
19978 }
19979
19980 /* Add the .ARM.attributes section. */
19981 void
19982 arm_md_end (void)
19983 {
19984 segT s;
19985 char *p;
19986 addressT addr;
19987 offsetT size;
19988
19989 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
19990 return;
19991
19992 aeabi_set_public_attributes ();
19993 size = elf32_arm_eabi_attr_size (stdoutput);
19994 s = subseg_new (".ARM.attributes", 0);
19995 bfd_set_section_flags (stdoutput, s, SEC_READONLY | SEC_DATA);
19996 addr = frag_now_fix ();
19997 p = frag_more (size);
19998 elf32_arm_set_eabi_attr_contents (stdoutput, (bfd_byte *)p, size);
19999 }
20000 #endif /* OBJ_ELF */
20001
20002
20003 /* Parse a .cpu directive. */
20004
20005 static void
20006 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
20007 {
20008 const struct arm_cpu_option_table *opt;
20009 char *name;
20010 char saved_char;
20011
20012 name = input_line_pointer;
20013 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
20014 input_line_pointer++;
20015 saved_char = *input_line_pointer;
20016 *input_line_pointer = 0;
20017
20018 /* Skip the first "all" entry. */
20019 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
20020 if (streq (opt->name, name))
20021 {
20022 mcpu_cpu_opt = &opt->value;
20023 selected_cpu = opt->value;
20024 if (opt->canonical_name)
20025 strcpy(selected_cpu_name, opt->canonical_name);
20026 else
20027 {
20028 int i;
20029 for (i = 0; opt->name[i]; i++)
20030 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20031 selected_cpu_name[i] = 0;
20032 }
20033 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20034 *input_line_pointer = saved_char;
20035 demand_empty_rest_of_line ();
20036 return;
20037 }
20038 as_bad (_("unknown cpu `%s'"), name);
20039 *input_line_pointer = saved_char;
20040 ignore_rest_of_line ();
20041 }
20042
20043
20044 /* Parse a .arch directive. */
20045
20046 static void
20047 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
20048 {
20049 const struct arm_arch_option_table *opt;
20050 char saved_char;
20051 char *name;
20052
20053 name = input_line_pointer;
20054 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
20055 input_line_pointer++;
20056 saved_char = *input_line_pointer;
20057 *input_line_pointer = 0;
20058
20059 /* Skip the first "all" entry. */
20060 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20061 if (streq (opt->name, name))
20062 {
20063 mcpu_cpu_opt = &opt->value;
20064 selected_cpu = opt->value;
20065 strcpy(selected_cpu_name, opt->name);
20066 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20067 *input_line_pointer = saved_char;
20068 demand_empty_rest_of_line ();
20069 return;
20070 }
20071
20072 as_bad (_("unknown architecture `%s'\n"), name);
20073 *input_line_pointer = saved_char;
20074 ignore_rest_of_line ();
20075 }
20076
20077
20078 /* Parse a .fpu directive. */
20079
20080 static void
20081 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
20082 {
20083 const struct arm_option_cpu_value_table *opt;
20084 char saved_char;
20085 char *name;
20086
20087 name = input_line_pointer;
20088 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
20089 input_line_pointer++;
20090 saved_char = *input_line_pointer;
20091 *input_line_pointer = 0;
20092
20093 for (opt = arm_fpus; opt->name != NULL; opt++)
20094 if (streq (opt->name, name))
20095 {
20096 mfpu_opt = &opt->value;
20097 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20098 *input_line_pointer = saved_char;
20099 demand_empty_rest_of_line ();
20100 return;
20101 }
20102
20103 as_bad (_("unknown floating point format `%s'\n"), name);
20104 *input_line_pointer = saved_char;
20105 ignore_rest_of_line ();
20106 }
20107
This page took 0.497723 seconds and 4 git commands to generate.