Rationalize ARM .align
[binutils-gdb.git] / gas / config / tc-arm.c
1 /* tc-arm.c -- Assemble for the ARM
2 Copyright (C) 1994-2015 Free Software Foundation, Inc.
3 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
4 Modified by David Taylor (dtaylor@armltd.co.uk)
5 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
6 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
7 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
8
9 This file is part of GAS, the GNU Assembler.
10
11 GAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3, or (at your option)
14 any later version.
15
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with GAS; see the file COPYING. If not, write to the Free
23 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 02110-1301, USA. */
25
26 #include "as.h"
27 #include <limits.h>
28 #include <stdarg.h>
29 #define NO_RELOC 0
30 #include "safe-ctype.h"
31 #include "subsegs.h"
32 #include "obstack.h"
33 #include "libiberty.h"
34 #include "opcode/arm.h"
35
36 #ifdef OBJ_ELF
37 #include "elf/arm.h"
38 #include "dw2gencfi.h"
39 #endif
40
41 #include "dwarf2dbg.h"
42
43 #ifdef OBJ_ELF
44 /* Must be at least the size of the largest unwind opcode (currently two). */
45 #define ARM_OPCODE_CHUNK_SIZE 8
46
47 /* This structure holds the unwinding state. */
48
49 static struct
50 {
51 symbolS * proc_start;
52 symbolS * table_entry;
53 symbolS * personality_routine;
54 int personality_index;
55 /* The segment containing the function. */
56 segT saved_seg;
57 subsegT saved_subseg;
58 /* Opcodes generated from this function. */
59 unsigned char * opcodes;
60 int opcode_count;
61 int opcode_alloc;
62 /* The number of bytes pushed to the stack. */
63 offsetT frame_size;
64 /* We don't add stack adjustment opcodes immediately so that we can merge
65 multiple adjustments. We can also omit the final adjustment
66 when using a frame pointer. */
67 offsetT pending_offset;
68 /* These two fields are set by both unwind_movsp and unwind_setfp. They
69 hold the reg+offset to use when restoring sp from a frame pointer. */
70 offsetT fp_offset;
71 int fp_reg;
72 /* Nonzero if an unwind_setfp directive has been seen. */
73 unsigned fp_used:1;
74 /* Nonzero if the last opcode restores sp from fp_reg. */
75 unsigned sp_restored:1;
76 } unwind;
77
78 #endif /* OBJ_ELF */
79
80 /* Results from operand parsing worker functions. */
81
82 typedef enum
83 {
84 PARSE_OPERAND_SUCCESS,
85 PARSE_OPERAND_FAIL,
86 PARSE_OPERAND_FAIL_NO_BACKTRACK
87 } parse_operand_result;
88
89 enum arm_float_abi
90 {
91 ARM_FLOAT_ABI_HARD,
92 ARM_FLOAT_ABI_SOFTFP,
93 ARM_FLOAT_ABI_SOFT
94 };
95
96 /* Types of processor to assemble for. */
97 #ifndef CPU_DEFAULT
98 /* The code that was here used to select a default CPU depending on compiler
99 pre-defines which were only present when doing native builds, thus
100 changing gas' default behaviour depending upon the build host.
101
102 If you have a target that requires a default CPU option then the you
103 should define CPU_DEFAULT here. */
104 #endif
105
106 #ifndef FPU_DEFAULT
107 # ifdef TE_LINUX
108 # define FPU_DEFAULT FPU_ARCH_FPA
109 # elif defined (TE_NetBSD)
110 # ifdef OBJ_ELF
111 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
112 # else
113 /* Legacy a.out format. */
114 # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
115 # endif
116 # elif defined (TE_VXWORKS)
117 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
118 # else
119 /* For backwards compatibility, default to FPA. */
120 # define FPU_DEFAULT FPU_ARCH_FPA
121 # endif
122 #endif /* ifndef FPU_DEFAULT */
123
124 #define streq(a, b) (strcmp (a, b) == 0)
125
126 static arm_feature_set cpu_variant;
127 static arm_feature_set arm_arch_used;
128 static arm_feature_set thumb_arch_used;
129
130 /* Flags stored in private area of BFD structure. */
131 static int uses_apcs_26 = FALSE;
132 static int atpcs = FALSE;
133 static int support_interwork = FALSE;
134 static int uses_apcs_float = FALSE;
135 static int pic_code = FALSE;
136 static int fix_v4bx = FALSE;
137 /* Warn on using deprecated features. */
138 static int warn_on_deprecated = TRUE;
139
140 /* Understand CodeComposer Studio assembly syntax. */
141 bfd_boolean codecomposer_syntax = FALSE;
142
143 /* Variables that we set while parsing command-line options. Once all
144 options have been read we re-process these values to set the real
145 assembly flags. */
146 static const arm_feature_set *legacy_cpu = NULL;
147 static const arm_feature_set *legacy_fpu = NULL;
148
149 static const arm_feature_set *mcpu_cpu_opt = NULL;
150 static const arm_feature_set *mcpu_fpu_opt = NULL;
151 static const arm_feature_set *march_cpu_opt = NULL;
152 static const arm_feature_set *march_fpu_opt = NULL;
153 static const arm_feature_set *mfpu_opt = NULL;
154 static const arm_feature_set *object_arch = NULL;
155
156 /* Constants for known architecture features. */
157 static const arm_feature_set fpu_default = FPU_DEFAULT;
158 static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
159 static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
160 static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
161 static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
162 static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
163 static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
164 static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
165 static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
166
167 #ifdef CPU_DEFAULT
168 static const arm_feature_set cpu_default = CPU_DEFAULT;
169 #endif
170
171 static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
172 static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
173 static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S);
174 static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3);
175 static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M);
176 static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4);
177 static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T);
178 static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5);
179 static const arm_feature_set arm_ext_v4t_5 =
180 ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5);
181 static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T);
182 static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E);
183 static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP);
184 static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J);
185 static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6);
186 static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K);
187 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2);
188 static const arm_feature_set arm_ext_v6m = ARM_FEATURE_CORE_LOW (ARM_EXT_V6M);
189 static const arm_feature_set arm_ext_v6_notm =
190 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
191 static const arm_feature_set arm_ext_v6_dsp =
192 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
193 static const arm_feature_set arm_ext_barrier =
194 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
195 static const arm_feature_set arm_ext_msr =
196 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
197 static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
198 static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
199 static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
200 static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
201 static const arm_feature_set arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
202 static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
203 static const arm_feature_set arm_ext_m =
204 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M);
205 static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
206 static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
207 static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
208 static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
209 static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
210 static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
211
212 static const arm_feature_set arm_arch_any = ARM_ANY;
213 static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1, -1);
214 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
215 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
216 static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY;
217
218 static const arm_feature_set arm_cext_iwmmxt2 =
219 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
220 static const arm_feature_set arm_cext_iwmmxt =
221 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
222 static const arm_feature_set arm_cext_xscale =
223 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
224 static const arm_feature_set arm_cext_maverick =
225 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
226 static const arm_feature_set fpu_fpa_ext_v1 =
227 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
228 static const arm_feature_set fpu_fpa_ext_v2 =
229 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
230 static const arm_feature_set fpu_vfp_ext_v1xd =
231 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
232 static const arm_feature_set fpu_vfp_ext_v1 =
233 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
234 static const arm_feature_set fpu_vfp_ext_v2 =
235 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
236 static const arm_feature_set fpu_vfp_ext_v3xd =
237 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
238 static const arm_feature_set fpu_vfp_ext_v3 =
239 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
240 static const arm_feature_set fpu_vfp_ext_d32 =
241 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
242 static const arm_feature_set fpu_neon_ext_v1 =
243 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
244 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
245 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
246 static const arm_feature_set fpu_vfp_fp16 =
247 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
248 static const arm_feature_set fpu_neon_ext_fma =
249 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
250 static const arm_feature_set fpu_vfp_ext_fma =
251 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
252 static const arm_feature_set fpu_vfp_ext_armv8 =
253 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
254 static const arm_feature_set fpu_vfp_ext_armv8xd =
255 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
256 static const arm_feature_set fpu_neon_ext_armv8 =
257 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
258 static const arm_feature_set fpu_crypto_ext_armv8 =
259 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
260 static const arm_feature_set crc_ext_armv8 =
261 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
262 static const arm_feature_set fpu_neon_ext_v8_1 =
263 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8 | FPU_NEON_EXT_RDMA);
264
265 static int mfloat_abi_opt = -1;
266 /* Record user cpu selection for object attributes. */
267 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
268 /* Must be long enough to hold any of the names in arm_cpus. */
269 static char selected_cpu_name[16];
270
271 extern FLONUM_TYPE generic_floating_point_number;
272
273 /* Return if no cpu was selected on command-line. */
274 static bfd_boolean
275 no_cpu_selected (void)
276 {
277 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
278 }
279
280 #ifdef OBJ_ELF
281 # ifdef EABI_DEFAULT
282 static int meabi_flags = EABI_DEFAULT;
283 # else
284 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
285 # endif
286
287 static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
288
289 bfd_boolean
290 arm_is_eabi (void)
291 {
292 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
293 }
294 #endif
295
296 #ifdef OBJ_ELF
297 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
298 symbolS * GOT_symbol;
299 #endif
300
301 /* 0: assemble for ARM,
302 1: assemble for Thumb,
303 2: assemble for Thumb even though target CPU does not support thumb
304 instructions. */
305 static int thumb_mode = 0;
306 /* A value distinct from the possible values for thumb_mode that we
307 can use to record whether thumb_mode has been copied into the
308 tc_frag_data field of a frag. */
309 #define MODE_RECORDED (1 << 4)
310
311 /* Specifies the intrinsic IT insn behavior mode. */
312 enum implicit_it_mode
313 {
314 IMPLICIT_IT_MODE_NEVER = 0x00,
315 IMPLICIT_IT_MODE_ARM = 0x01,
316 IMPLICIT_IT_MODE_THUMB = 0x02,
317 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
318 };
319 static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
320
321 /* If unified_syntax is true, we are processing the new unified
322 ARM/Thumb syntax. Important differences from the old ARM mode:
323
324 - Immediate operands do not require a # prefix.
325 - Conditional affixes always appear at the end of the
326 instruction. (For backward compatibility, those instructions
327 that formerly had them in the middle, continue to accept them
328 there.)
329 - The IT instruction may appear, and if it does is validated
330 against subsequent conditional affixes. It does not generate
331 machine code.
332
333 Important differences from the old Thumb mode:
334
335 - Immediate operands do not require a # prefix.
336 - Most of the V6T2 instructions are only available in unified mode.
337 - The .N and .W suffixes are recognized and honored (it is an error
338 if they cannot be honored).
339 - All instructions set the flags if and only if they have an 's' affix.
340 - Conditional affixes may be used. They are validated against
341 preceding IT instructions. Unlike ARM mode, you cannot use a
342 conditional affix except in the scope of an IT instruction. */
343
344 static bfd_boolean unified_syntax = FALSE;
345
346 /* An immediate operand can start with #, and ld*, st*, pld operands
347 can contain [ and ]. We need to tell APP not to elide whitespace
348 before a [, which can appear as the first operand for pld.
349 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
350 const char arm_symbol_chars[] = "#[]{}";
351
352 enum neon_el_type
353 {
354 NT_invtype,
355 NT_untyped,
356 NT_integer,
357 NT_float,
358 NT_poly,
359 NT_signed,
360 NT_unsigned
361 };
362
363 struct neon_type_el
364 {
365 enum neon_el_type type;
366 unsigned size;
367 };
368
369 #define NEON_MAX_TYPE_ELS 4
370
371 struct neon_type
372 {
373 struct neon_type_el el[NEON_MAX_TYPE_ELS];
374 unsigned elems;
375 };
376
377 enum it_instruction_type
378 {
379 OUTSIDE_IT_INSN,
380 INSIDE_IT_INSN,
381 INSIDE_IT_LAST_INSN,
382 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
383 if inside, should be the last one. */
384 NEUTRAL_IT_INSN, /* This could be either inside or outside,
385 i.e. BKPT and NOP. */
386 IT_INSN /* The IT insn has been parsed. */
387 };
388
389 /* The maximum number of operands we need. */
390 #define ARM_IT_MAX_OPERANDS 6
391
392 struct arm_it
393 {
394 const char * error;
395 unsigned long instruction;
396 int size;
397 int size_req;
398 int cond;
399 /* "uncond_value" is set to the value in place of the conditional field in
400 unconditional versions of the instruction, or -1 if nothing is
401 appropriate. */
402 int uncond_value;
403 struct neon_type vectype;
404 /* This does not indicate an actual NEON instruction, only that
405 the mnemonic accepts neon-style type suffixes. */
406 int is_neon;
407 /* Set to the opcode if the instruction needs relaxation.
408 Zero if the instruction is not relaxed. */
409 unsigned long relax;
410 struct
411 {
412 bfd_reloc_code_real_type type;
413 expressionS exp;
414 int pc_rel;
415 } reloc;
416
417 enum it_instruction_type it_insn_type;
418
419 struct
420 {
421 unsigned reg;
422 signed int imm;
423 struct neon_type_el vectype;
424 unsigned present : 1; /* Operand present. */
425 unsigned isreg : 1; /* Operand was a register. */
426 unsigned immisreg : 1; /* .imm field is a second register. */
427 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
428 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
429 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
430 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
431 instructions. This allows us to disambiguate ARM <-> vector insns. */
432 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
433 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
434 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
435 unsigned issingle : 1; /* Operand is VFP single-precision register. */
436 unsigned hasreloc : 1; /* Operand has relocation suffix. */
437 unsigned writeback : 1; /* Operand has trailing ! */
438 unsigned preind : 1; /* Preindexed address. */
439 unsigned postind : 1; /* Postindexed address. */
440 unsigned negative : 1; /* Index register was negated. */
441 unsigned shifted : 1; /* Shift applied to operation. */
442 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
443 } operands[ARM_IT_MAX_OPERANDS];
444 };
445
446 static struct arm_it inst;
447
448 #define NUM_FLOAT_VALS 8
449
450 const char * fp_const[] =
451 {
452 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
453 };
454
455 /* Number of littlenums required to hold an extended precision number. */
456 #define MAX_LITTLENUMS 6
457
458 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
459
460 #define FAIL (-1)
461 #define SUCCESS (0)
462
463 #define SUFF_S 1
464 #define SUFF_D 2
465 #define SUFF_E 3
466 #define SUFF_P 4
467
468 #define CP_T_X 0x00008000
469 #define CP_T_Y 0x00400000
470
471 #define CONDS_BIT 0x00100000
472 #define LOAD_BIT 0x00100000
473
474 #define DOUBLE_LOAD_FLAG 0x00000001
475
476 struct asm_cond
477 {
478 const char * template_name;
479 unsigned long value;
480 };
481
482 #define COND_ALWAYS 0xE
483
484 struct asm_psr
485 {
486 const char * template_name;
487 unsigned long field;
488 };
489
490 struct asm_barrier_opt
491 {
492 const char * template_name;
493 unsigned long value;
494 const arm_feature_set arch;
495 };
496
497 /* The bit that distinguishes CPSR and SPSR. */
498 #define SPSR_BIT (1 << 22)
499
500 /* The individual PSR flag bits. */
501 #define PSR_c (1 << 16)
502 #define PSR_x (1 << 17)
503 #define PSR_s (1 << 18)
504 #define PSR_f (1 << 19)
505
506 struct reloc_entry
507 {
508 char * name;
509 bfd_reloc_code_real_type reloc;
510 };
511
512 enum vfp_reg_pos
513 {
514 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
515 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
516 };
517
518 enum vfp_ldstm_type
519 {
520 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
521 };
522
523 /* Bits for DEFINED field in neon_typed_alias. */
524 #define NTA_HASTYPE 1
525 #define NTA_HASINDEX 2
526
527 struct neon_typed_alias
528 {
529 unsigned char defined;
530 unsigned char index;
531 struct neon_type_el eltype;
532 };
533
534 /* ARM register categories. This includes coprocessor numbers and various
535 architecture extensions' registers. */
536 enum arm_reg_type
537 {
538 REG_TYPE_RN,
539 REG_TYPE_CP,
540 REG_TYPE_CN,
541 REG_TYPE_FN,
542 REG_TYPE_VFS,
543 REG_TYPE_VFD,
544 REG_TYPE_NQ,
545 REG_TYPE_VFSD,
546 REG_TYPE_NDQ,
547 REG_TYPE_NSDQ,
548 REG_TYPE_VFC,
549 REG_TYPE_MVF,
550 REG_TYPE_MVD,
551 REG_TYPE_MVFX,
552 REG_TYPE_MVDX,
553 REG_TYPE_MVAX,
554 REG_TYPE_DSPSC,
555 REG_TYPE_MMXWR,
556 REG_TYPE_MMXWC,
557 REG_TYPE_MMXWCG,
558 REG_TYPE_XSCALE,
559 REG_TYPE_RNB
560 };
561
562 /* Structure for a hash table entry for a register.
563 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
564 information which states whether a vector type or index is specified (for a
565 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
566 struct reg_entry
567 {
568 const char * name;
569 unsigned int number;
570 unsigned char type;
571 unsigned char builtin;
572 struct neon_typed_alias * neon;
573 };
574
575 /* Diagnostics used when we don't get a register of the expected type. */
576 const char * const reg_expected_msgs[] =
577 {
578 N_("ARM register expected"),
579 N_("bad or missing co-processor number"),
580 N_("co-processor register expected"),
581 N_("FPA register expected"),
582 N_("VFP single precision register expected"),
583 N_("VFP/Neon double precision register expected"),
584 N_("Neon quad precision register expected"),
585 N_("VFP single or double precision register expected"),
586 N_("Neon double or quad precision register expected"),
587 N_("VFP single, double or Neon quad precision register expected"),
588 N_("VFP system register expected"),
589 N_("Maverick MVF register expected"),
590 N_("Maverick MVD register expected"),
591 N_("Maverick MVFX register expected"),
592 N_("Maverick MVDX register expected"),
593 N_("Maverick MVAX register expected"),
594 N_("Maverick DSPSC register expected"),
595 N_("iWMMXt data register expected"),
596 N_("iWMMXt control register expected"),
597 N_("iWMMXt scalar register expected"),
598 N_("XScale accumulator register expected"),
599 };
600
601 /* Some well known registers that we refer to directly elsewhere. */
602 #define REG_R12 12
603 #define REG_SP 13
604 #define REG_LR 14
605 #define REG_PC 15
606
607 /* ARM instructions take 4bytes in the object file, Thumb instructions
608 take 2: */
609 #define INSN_SIZE 4
610
611 struct asm_opcode
612 {
613 /* Basic string to match. */
614 const char * template_name;
615
616 /* Parameters to instruction. */
617 unsigned int operands[8];
618
619 /* Conditional tag - see opcode_lookup. */
620 unsigned int tag : 4;
621
622 /* Basic instruction code. */
623 unsigned int avalue : 28;
624
625 /* Thumb-format instruction code. */
626 unsigned int tvalue;
627
628 /* Which architecture variant provides this instruction. */
629 const arm_feature_set * avariant;
630 const arm_feature_set * tvariant;
631
632 /* Function to call to encode instruction in ARM format. */
633 void (* aencode) (void);
634
635 /* Function to call to encode instruction in Thumb format. */
636 void (* tencode) (void);
637 };
638
639 /* Defines for various bits that we will want to toggle. */
640 #define INST_IMMEDIATE 0x02000000
641 #define OFFSET_REG 0x02000000
642 #define HWOFFSET_IMM 0x00400000
643 #define SHIFT_BY_REG 0x00000010
644 #define PRE_INDEX 0x01000000
645 #define INDEX_UP 0x00800000
646 #define WRITE_BACK 0x00200000
647 #define LDM_TYPE_2_OR_3 0x00400000
648 #define CPSI_MMOD 0x00020000
649
650 #define LITERAL_MASK 0xf000f000
651 #define OPCODE_MASK 0xfe1fffff
652 #define V4_STR_BIT 0x00000020
653 #define VLDR_VMOV_SAME 0x0040f000
654
655 #define T2_SUBS_PC_LR 0xf3de8f00
656
657 #define DATA_OP_SHIFT 21
658
659 #define T2_OPCODE_MASK 0xfe1fffff
660 #define T2_DATA_OP_SHIFT 21
661
662 #define A_COND_MASK 0xf0000000
663 #define A_PUSH_POP_OP_MASK 0x0fff0000
664
665 /* Opcodes for pushing/poping registers to/from the stack. */
666 #define A1_OPCODE_PUSH 0x092d0000
667 #define A2_OPCODE_PUSH 0x052d0004
668 #define A2_OPCODE_POP 0x049d0004
669
670 /* Codes to distinguish the arithmetic instructions. */
671 #define OPCODE_AND 0
672 #define OPCODE_EOR 1
673 #define OPCODE_SUB 2
674 #define OPCODE_RSB 3
675 #define OPCODE_ADD 4
676 #define OPCODE_ADC 5
677 #define OPCODE_SBC 6
678 #define OPCODE_RSC 7
679 #define OPCODE_TST 8
680 #define OPCODE_TEQ 9
681 #define OPCODE_CMP 10
682 #define OPCODE_CMN 11
683 #define OPCODE_ORR 12
684 #define OPCODE_MOV 13
685 #define OPCODE_BIC 14
686 #define OPCODE_MVN 15
687
688 #define T2_OPCODE_AND 0
689 #define T2_OPCODE_BIC 1
690 #define T2_OPCODE_ORR 2
691 #define T2_OPCODE_ORN 3
692 #define T2_OPCODE_EOR 4
693 #define T2_OPCODE_ADD 8
694 #define T2_OPCODE_ADC 10
695 #define T2_OPCODE_SBC 11
696 #define T2_OPCODE_SUB 13
697 #define T2_OPCODE_RSB 14
698
699 #define T_OPCODE_MUL 0x4340
700 #define T_OPCODE_TST 0x4200
701 #define T_OPCODE_CMN 0x42c0
702 #define T_OPCODE_NEG 0x4240
703 #define T_OPCODE_MVN 0x43c0
704
705 #define T_OPCODE_ADD_R3 0x1800
706 #define T_OPCODE_SUB_R3 0x1a00
707 #define T_OPCODE_ADD_HI 0x4400
708 #define T_OPCODE_ADD_ST 0xb000
709 #define T_OPCODE_SUB_ST 0xb080
710 #define T_OPCODE_ADD_SP 0xa800
711 #define T_OPCODE_ADD_PC 0xa000
712 #define T_OPCODE_ADD_I8 0x3000
713 #define T_OPCODE_SUB_I8 0x3800
714 #define T_OPCODE_ADD_I3 0x1c00
715 #define T_OPCODE_SUB_I3 0x1e00
716
717 #define T_OPCODE_ASR_R 0x4100
718 #define T_OPCODE_LSL_R 0x4080
719 #define T_OPCODE_LSR_R 0x40c0
720 #define T_OPCODE_ROR_R 0x41c0
721 #define T_OPCODE_ASR_I 0x1000
722 #define T_OPCODE_LSL_I 0x0000
723 #define T_OPCODE_LSR_I 0x0800
724
725 #define T_OPCODE_MOV_I8 0x2000
726 #define T_OPCODE_CMP_I8 0x2800
727 #define T_OPCODE_CMP_LR 0x4280
728 #define T_OPCODE_MOV_HR 0x4600
729 #define T_OPCODE_CMP_HR 0x4500
730
731 #define T_OPCODE_LDR_PC 0x4800
732 #define T_OPCODE_LDR_SP 0x9800
733 #define T_OPCODE_STR_SP 0x9000
734 #define T_OPCODE_LDR_IW 0x6800
735 #define T_OPCODE_STR_IW 0x6000
736 #define T_OPCODE_LDR_IH 0x8800
737 #define T_OPCODE_STR_IH 0x8000
738 #define T_OPCODE_LDR_IB 0x7800
739 #define T_OPCODE_STR_IB 0x7000
740 #define T_OPCODE_LDR_RW 0x5800
741 #define T_OPCODE_STR_RW 0x5000
742 #define T_OPCODE_LDR_RH 0x5a00
743 #define T_OPCODE_STR_RH 0x5200
744 #define T_OPCODE_LDR_RB 0x5c00
745 #define T_OPCODE_STR_RB 0x5400
746
747 #define T_OPCODE_PUSH 0xb400
748 #define T_OPCODE_POP 0xbc00
749
750 #define T_OPCODE_BRANCH 0xe000
751
752 #define THUMB_SIZE 2 /* Size of thumb instruction. */
753 #define THUMB_PP_PC_LR 0x0100
754 #define THUMB_LOAD_BIT 0x0800
755 #define THUMB2_LOAD_BIT 0x00100000
756
757 #define BAD_ARGS _("bad arguments to instruction")
758 #define BAD_SP _("r13 not allowed here")
759 #define BAD_PC _("r15 not allowed here")
760 #define BAD_COND _("instruction cannot be conditional")
761 #define BAD_OVERLAP _("registers may not be the same")
762 #define BAD_HIREG _("lo register required")
763 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
764 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
765 #define BAD_BRANCH _("branch must be last instruction in IT block")
766 #define BAD_NOT_IT _("instruction not allowed in IT block")
767 #define BAD_FPU _("selected FPU does not support instruction")
768 #define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
769 #define BAD_IT_COND _("incorrect condition in IT block")
770 #define BAD_IT_IT _("IT falling in the range of a previous IT block")
771 #define MISSING_FNSTART _("missing .fnstart before unwinding directive")
772 #define BAD_PC_ADDRESSING \
773 _("cannot use register index with PC-relative addressing")
774 #define BAD_PC_WRITEBACK \
775 _("cannot use writeback with PC-relative addressing")
776 #define BAD_RANGE _("branch out of range")
777 #define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
778
779 static struct hash_control * arm_ops_hsh;
780 static struct hash_control * arm_cond_hsh;
781 static struct hash_control * arm_shift_hsh;
782 static struct hash_control * arm_psr_hsh;
783 static struct hash_control * arm_v7m_psr_hsh;
784 static struct hash_control * arm_reg_hsh;
785 static struct hash_control * arm_reloc_hsh;
786 static struct hash_control * arm_barrier_opt_hsh;
787
788 /* Stuff needed to resolve the label ambiguity
789 As:
790 ...
791 label: <insn>
792 may differ from:
793 ...
794 label:
795 <insn> */
796
797 symbolS * last_label_seen;
798 static int label_is_thumb_function_name = FALSE;
799
800 /* Literal pool structure. Held on a per-section
801 and per-sub-section basis. */
802
803 #define MAX_LITERAL_POOL_SIZE 1024
804 typedef struct literal_pool
805 {
806 expressionS literals [MAX_LITERAL_POOL_SIZE];
807 unsigned int next_free_entry;
808 unsigned int id;
809 symbolS * symbol;
810 segT section;
811 subsegT sub_section;
812 #ifdef OBJ_ELF
813 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
814 #endif
815 struct literal_pool * next;
816 unsigned int alignment;
817 } literal_pool;
818
819 /* Pointer to a linked list of literal pools. */
820 literal_pool * list_of_pools = NULL;
821
822 typedef enum asmfunc_states
823 {
824 OUTSIDE_ASMFUNC,
825 WAITING_ASMFUNC_NAME,
826 WAITING_ENDASMFUNC
827 } asmfunc_states;
828
829 static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
830
831 #ifdef OBJ_ELF
832 # define now_it seg_info (now_seg)->tc_segment_info_data.current_it
833 #else
834 static struct current_it now_it;
835 #endif
836
837 static inline int
838 now_it_compatible (int cond)
839 {
840 return (cond & ~1) == (now_it.cc & ~1);
841 }
842
843 static inline int
844 conditional_insn (void)
845 {
846 return inst.cond != COND_ALWAYS;
847 }
848
849 static int in_it_block (void);
850
851 static int handle_it_state (void);
852
853 static void force_automatic_it_block_close (void);
854
855 static void it_fsm_post_encode (void);
856
857 #define set_it_insn_type(type) \
858 do \
859 { \
860 inst.it_insn_type = type; \
861 if (handle_it_state () == FAIL) \
862 return; \
863 } \
864 while (0)
865
866 #define set_it_insn_type_nonvoid(type, failret) \
867 do \
868 { \
869 inst.it_insn_type = type; \
870 if (handle_it_state () == FAIL) \
871 return failret; \
872 } \
873 while(0)
874
875 #define set_it_insn_type_last() \
876 do \
877 { \
878 if (inst.cond == COND_ALWAYS) \
879 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
880 else \
881 set_it_insn_type (INSIDE_IT_LAST_INSN); \
882 } \
883 while (0)
884
885 /* Pure syntax. */
886
887 /* This array holds the chars that always start a comment. If the
888 pre-processor is disabled, these aren't very useful. */
889 char arm_comment_chars[] = "@";
890
891 /* This array holds the chars that only start a comment at the beginning of
892 a line. If the line seems to have the form '# 123 filename'
893 .line and .file directives will appear in the pre-processed output. */
894 /* Note that input_file.c hand checks for '#' at the beginning of the
895 first line of the input file. This is because the compiler outputs
896 #NO_APP at the beginning of its output. */
897 /* Also note that comments like this one will always work. */
898 const char line_comment_chars[] = "#";
899
900 char arm_line_separator_chars[] = ";";
901
902 /* Chars that can be used to separate mant
903 from exp in floating point numbers. */
904 const char EXP_CHARS[] = "eE";
905
906 /* Chars that mean this number is a floating point constant. */
907 /* As in 0f12.456 */
908 /* or 0d1.2345e12 */
909
910 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
911
912 /* Prefix characters that indicate the start of an immediate
913 value. */
914 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
915
916 /* Separator character handling. */
917
918 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
919
920 static inline int
921 skip_past_char (char ** str, char c)
922 {
923 /* PR gas/14987: Allow for whitespace before the expected character. */
924 skip_whitespace (*str);
925
926 if (**str == c)
927 {
928 (*str)++;
929 return SUCCESS;
930 }
931 else
932 return FAIL;
933 }
934
935 #define skip_past_comma(str) skip_past_char (str, ',')
936
937 /* Arithmetic expressions (possibly involving symbols). */
938
939 /* Return TRUE if anything in the expression is a bignum. */
940
941 static int
942 walk_no_bignums (symbolS * sp)
943 {
944 if (symbol_get_value_expression (sp)->X_op == O_big)
945 return 1;
946
947 if (symbol_get_value_expression (sp)->X_add_symbol)
948 {
949 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
950 || (symbol_get_value_expression (sp)->X_op_symbol
951 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
952 }
953
954 return 0;
955 }
956
957 static int in_my_get_expression = 0;
958
959 /* Third argument to my_get_expression. */
960 #define GE_NO_PREFIX 0
961 #define GE_IMM_PREFIX 1
962 #define GE_OPT_PREFIX 2
963 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
964 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
965 #define GE_OPT_PREFIX_BIG 3
966
967 static int
968 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
969 {
970 char * save_in;
971 segT seg;
972
973 /* In unified syntax, all prefixes are optional. */
974 if (unified_syntax)
975 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
976 : GE_OPT_PREFIX;
977
978 switch (prefix_mode)
979 {
980 case GE_NO_PREFIX: break;
981 case GE_IMM_PREFIX:
982 if (!is_immediate_prefix (**str))
983 {
984 inst.error = _("immediate expression requires a # prefix");
985 return FAIL;
986 }
987 (*str)++;
988 break;
989 case GE_OPT_PREFIX:
990 case GE_OPT_PREFIX_BIG:
991 if (is_immediate_prefix (**str))
992 (*str)++;
993 break;
994 default: abort ();
995 }
996
997 memset (ep, 0, sizeof (expressionS));
998
999 save_in = input_line_pointer;
1000 input_line_pointer = *str;
1001 in_my_get_expression = 1;
1002 seg = expression (ep);
1003 in_my_get_expression = 0;
1004
1005 if (ep->X_op == O_illegal || ep->X_op == O_absent)
1006 {
1007 /* We found a bad or missing expression in md_operand(). */
1008 *str = input_line_pointer;
1009 input_line_pointer = save_in;
1010 if (inst.error == NULL)
1011 inst.error = (ep->X_op == O_absent
1012 ? _("missing expression") :_("bad expression"));
1013 return 1;
1014 }
1015
1016 #ifdef OBJ_AOUT
1017 if (seg != absolute_section
1018 && seg != text_section
1019 && seg != data_section
1020 && seg != bss_section
1021 && seg != undefined_section)
1022 {
1023 inst.error = _("bad segment");
1024 *str = input_line_pointer;
1025 input_line_pointer = save_in;
1026 return 1;
1027 }
1028 #else
1029 (void) seg;
1030 #endif
1031
1032 /* Get rid of any bignums now, so that we don't generate an error for which
1033 we can't establish a line number later on. Big numbers are never valid
1034 in instructions, which is where this routine is always called. */
1035 if (prefix_mode != GE_OPT_PREFIX_BIG
1036 && (ep->X_op == O_big
1037 || (ep->X_add_symbol
1038 && (walk_no_bignums (ep->X_add_symbol)
1039 || (ep->X_op_symbol
1040 && walk_no_bignums (ep->X_op_symbol))))))
1041 {
1042 inst.error = _("invalid constant");
1043 *str = input_line_pointer;
1044 input_line_pointer = save_in;
1045 return 1;
1046 }
1047
1048 *str = input_line_pointer;
1049 input_line_pointer = save_in;
1050 return 0;
1051 }
1052
1053 /* Turn a string in input_line_pointer into a floating point constant
1054 of type TYPE, and store the appropriate bytes in *LITP. The number
1055 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1056 returned, or NULL on OK.
1057
1058 Note that fp constants aren't represent in the normal way on the ARM.
1059 In big endian mode, things are as expected. However, in little endian
1060 mode fp constants are big-endian word-wise, and little-endian byte-wise
1061 within the words. For example, (double) 1.1 in big endian mode is
1062 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1063 the byte sequence 99 99 f1 3f 9a 99 99 99.
1064
1065 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
1066
1067 char *
1068 md_atof (int type, char * litP, int * sizeP)
1069 {
1070 int prec;
1071 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1072 char *t;
1073 int i;
1074
1075 switch (type)
1076 {
1077 case 'f':
1078 case 'F':
1079 case 's':
1080 case 'S':
1081 prec = 2;
1082 break;
1083
1084 case 'd':
1085 case 'D':
1086 case 'r':
1087 case 'R':
1088 prec = 4;
1089 break;
1090
1091 case 'x':
1092 case 'X':
1093 prec = 5;
1094 break;
1095
1096 case 'p':
1097 case 'P':
1098 prec = 5;
1099 break;
1100
1101 default:
1102 *sizeP = 0;
1103 return _("Unrecognized or unsupported floating point constant");
1104 }
1105
1106 t = atof_ieee (input_line_pointer, type, words);
1107 if (t)
1108 input_line_pointer = t;
1109 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1110
1111 if (target_big_endian)
1112 {
1113 for (i = 0; i < prec; i++)
1114 {
1115 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1116 litP += sizeof (LITTLENUM_TYPE);
1117 }
1118 }
1119 else
1120 {
1121 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
1122 for (i = prec - 1; i >= 0; i--)
1123 {
1124 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1125 litP += sizeof (LITTLENUM_TYPE);
1126 }
1127 else
1128 /* For a 4 byte float the order of elements in `words' is 1 0.
1129 For an 8 byte float the order is 1 0 3 2. */
1130 for (i = 0; i < prec; i += 2)
1131 {
1132 md_number_to_chars (litP, (valueT) words[i + 1],
1133 sizeof (LITTLENUM_TYPE));
1134 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1135 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1136 litP += 2 * sizeof (LITTLENUM_TYPE);
1137 }
1138 }
1139
1140 return NULL;
1141 }
1142
1143 /* We handle all bad expressions here, so that we can report the faulty
1144 instruction in the error message. */
1145 void
1146 md_operand (expressionS * exp)
1147 {
1148 if (in_my_get_expression)
1149 exp->X_op = O_illegal;
1150 }
1151
1152 /* Immediate values. */
1153
1154 /* Generic immediate-value read function for use in directives.
1155 Accepts anything that 'expression' can fold to a constant.
1156 *val receives the number. */
1157 #ifdef OBJ_ELF
1158 static int
1159 immediate_for_directive (int *val)
1160 {
1161 expressionS exp;
1162 exp.X_op = O_illegal;
1163
1164 if (is_immediate_prefix (*input_line_pointer))
1165 {
1166 input_line_pointer++;
1167 expression (&exp);
1168 }
1169
1170 if (exp.X_op != O_constant)
1171 {
1172 as_bad (_("expected #constant"));
1173 ignore_rest_of_line ();
1174 return FAIL;
1175 }
1176 *val = exp.X_add_number;
1177 return SUCCESS;
1178 }
1179 #endif
1180
1181 /* Register parsing. */
1182
1183 /* Generic register parser. CCP points to what should be the
1184 beginning of a register name. If it is indeed a valid register
1185 name, advance CCP over it and return the reg_entry structure;
1186 otherwise return NULL. Does not issue diagnostics. */
1187
1188 static struct reg_entry *
1189 arm_reg_parse_multi (char **ccp)
1190 {
1191 char *start = *ccp;
1192 char *p;
1193 struct reg_entry *reg;
1194
1195 skip_whitespace (start);
1196
1197 #ifdef REGISTER_PREFIX
1198 if (*start != REGISTER_PREFIX)
1199 return NULL;
1200 start++;
1201 #endif
1202 #ifdef OPTIONAL_REGISTER_PREFIX
1203 if (*start == OPTIONAL_REGISTER_PREFIX)
1204 start++;
1205 #endif
1206
1207 p = start;
1208 if (!ISALPHA (*p) || !is_name_beginner (*p))
1209 return NULL;
1210
1211 do
1212 p++;
1213 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1214
1215 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1216
1217 if (!reg)
1218 return NULL;
1219
1220 *ccp = p;
1221 return reg;
1222 }
1223
1224 static int
1225 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1226 enum arm_reg_type type)
1227 {
1228 /* Alternative syntaxes are accepted for a few register classes. */
1229 switch (type)
1230 {
1231 case REG_TYPE_MVF:
1232 case REG_TYPE_MVD:
1233 case REG_TYPE_MVFX:
1234 case REG_TYPE_MVDX:
1235 /* Generic coprocessor register names are allowed for these. */
1236 if (reg && reg->type == REG_TYPE_CN)
1237 return reg->number;
1238 break;
1239
1240 case REG_TYPE_CP:
1241 /* For backward compatibility, a bare number is valid here. */
1242 {
1243 unsigned long processor = strtoul (start, ccp, 10);
1244 if (*ccp != start && processor <= 15)
1245 return processor;
1246 }
1247
1248 case REG_TYPE_MMXWC:
1249 /* WC includes WCG. ??? I'm not sure this is true for all
1250 instructions that take WC registers. */
1251 if (reg && reg->type == REG_TYPE_MMXWCG)
1252 return reg->number;
1253 break;
1254
1255 default:
1256 break;
1257 }
1258
1259 return FAIL;
1260 }
1261
1262 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1263 return value is the register number or FAIL. */
1264
1265 static int
1266 arm_reg_parse (char **ccp, enum arm_reg_type type)
1267 {
1268 char *start = *ccp;
1269 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1270 int ret;
1271
1272 /* Do not allow a scalar (reg+index) to parse as a register. */
1273 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1274 return FAIL;
1275
1276 if (reg && reg->type == type)
1277 return reg->number;
1278
1279 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1280 return ret;
1281
1282 *ccp = start;
1283 return FAIL;
1284 }
1285
1286 /* Parse a Neon type specifier. *STR should point at the leading '.'
1287 character. Does no verification at this stage that the type fits the opcode
1288 properly. E.g.,
1289
1290 .i32.i32.s16
1291 .s32.f32
1292 .u16
1293
1294 Can all be legally parsed by this function.
1295
1296 Fills in neon_type struct pointer with parsed information, and updates STR
1297 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1298 type, FAIL if not. */
1299
1300 static int
1301 parse_neon_type (struct neon_type *type, char **str)
1302 {
1303 char *ptr = *str;
1304
1305 if (type)
1306 type->elems = 0;
1307
1308 while (type->elems < NEON_MAX_TYPE_ELS)
1309 {
1310 enum neon_el_type thistype = NT_untyped;
1311 unsigned thissize = -1u;
1312
1313 if (*ptr != '.')
1314 break;
1315
1316 ptr++;
1317
1318 /* Just a size without an explicit type. */
1319 if (ISDIGIT (*ptr))
1320 goto parsesize;
1321
1322 switch (TOLOWER (*ptr))
1323 {
1324 case 'i': thistype = NT_integer; break;
1325 case 'f': thistype = NT_float; break;
1326 case 'p': thistype = NT_poly; break;
1327 case 's': thistype = NT_signed; break;
1328 case 'u': thistype = NT_unsigned; break;
1329 case 'd':
1330 thistype = NT_float;
1331 thissize = 64;
1332 ptr++;
1333 goto done;
1334 default:
1335 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1336 return FAIL;
1337 }
1338
1339 ptr++;
1340
1341 /* .f is an abbreviation for .f32. */
1342 if (thistype == NT_float && !ISDIGIT (*ptr))
1343 thissize = 32;
1344 else
1345 {
1346 parsesize:
1347 thissize = strtoul (ptr, &ptr, 10);
1348
1349 if (thissize != 8 && thissize != 16 && thissize != 32
1350 && thissize != 64)
1351 {
1352 as_bad (_("bad size %d in type specifier"), thissize);
1353 return FAIL;
1354 }
1355 }
1356
1357 done:
1358 if (type)
1359 {
1360 type->el[type->elems].type = thistype;
1361 type->el[type->elems].size = thissize;
1362 type->elems++;
1363 }
1364 }
1365
1366 /* Empty/missing type is not a successful parse. */
1367 if (type->elems == 0)
1368 return FAIL;
1369
1370 *str = ptr;
1371
1372 return SUCCESS;
1373 }
1374
1375 /* Errors may be set multiple times during parsing or bit encoding
1376 (particularly in the Neon bits), but usually the earliest error which is set
1377 will be the most meaningful. Avoid overwriting it with later (cascading)
1378 errors by calling this function. */
1379
1380 static void
1381 first_error (const char *err)
1382 {
1383 if (!inst.error)
1384 inst.error = err;
1385 }
1386
1387 /* Parse a single type, e.g. ".s32", leading period included. */
1388 static int
1389 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1390 {
1391 char *str = *ccp;
1392 struct neon_type optype;
1393
1394 if (*str == '.')
1395 {
1396 if (parse_neon_type (&optype, &str) == SUCCESS)
1397 {
1398 if (optype.elems == 1)
1399 *vectype = optype.el[0];
1400 else
1401 {
1402 first_error (_("only one type should be specified for operand"));
1403 return FAIL;
1404 }
1405 }
1406 else
1407 {
1408 first_error (_("vector type expected"));
1409 return FAIL;
1410 }
1411 }
1412 else
1413 return FAIL;
1414
1415 *ccp = str;
1416
1417 return SUCCESS;
1418 }
1419
1420 /* Special meanings for indices (which have a range of 0-7), which will fit into
1421 a 4-bit integer. */
1422
1423 #define NEON_ALL_LANES 15
1424 #define NEON_INTERLEAVE_LANES 14
1425
1426 /* Parse either a register or a scalar, with an optional type. Return the
1427 register number, and optionally fill in the actual type of the register
1428 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1429 type/index information in *TYPEINFO. */
1430
1431 static int
1432 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1433 enum arm_reg_type *rtype,
1434 struct neon_typed_alias *typeinfo)
1435 {
1436 char *str = *ccp;
1437 struct reg_entry *reg = arm_reg_parse_multi (&str);
1438 struct neon_typed_alias atype;
1439 struct neon_type_el parsetype;
1440
1441 atype.defined = 0;
1442 atype.index = -1;
1443 atype.eltype.type = NT_invtype;
1444 atype.eltype.size = -1;
1445
1446 /* Try alternate syntax for some types of register. Note these are mutually
1447 exclusive with the Neon syntax extensions. */
1448 if (reg == NULL)
1449 {
1450 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1451 if (altreg != FAIL)
1452 *ccp = str;
1453 if (typeinfo)
1454 *typeinfo = atype;
1455 return altreg;
1456 }
1457
1458 /* Undo polymorphism when a set of register types may be accepted. */
1459 if ((type == REG_TYPE_NDQ
1460 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1461 || (type == REG_TYPE_VFSD
1462 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1463 || (type == REG_TYPE_NSDQ
1464 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1465 || reg->type == REG_TYPE_NQ))
1466 || (type == REG_TYPE_MMXWC
1467 && (reg->type == REG_TYPE_MMXWCG)))
1468 type = (enum arm_reg_type) reg->type;
1469
1470 if (type != reg->type)
1471 return FAIL;
1472
1473 if (reg->neon)
1474 atype = *reg->neon;
1475
1476 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1477 {
1478 if ((atype.defined & NTA_HASTYPE) != 0)
1479 {
1480 first_error (_("can't redefine type for operand"));
1481 return FAIL;
1482 }
1483 atype.defined |= NTA_HASTYPE;
1484 atype.eltype = parsetype;
1485 }
1486
1487 if (skip_past_char (&str, '[') == SUCCESS)
1488 {
1489 if (type != REG_TYPE_VFD)
1490 {
1491 first_error (_("only D registers may be indexed"));
1492 return FAIL;
1493 }
1494
1495 if ((atype.defined & NTA_HASINDEX) != 0)
1496 {
1497 first_error (_("can't change index for operand"));
1498 return FAIL;
1499 }
1500
1501 atype.defined |= NTA_HASINDEX;
1502
1503 if (skip_past_char (&str, ']') == SUCCESS)
1504 atype.index = NEON_ALL_LANES;
1505 else
1506 {
1507 expressionS exp;
1508
1509 my_get_expression (&exp, &str, GE_NO_PREFIX);
1510
1511 if (exp.X_op != O_constant)
1512 {
1513 first_error (_("constant expression required"));
1514 return FAIL;
1515 }
1516
1517 if (skip_past_char (&str, ']') == FAIL)
1518 return FAIL;
1519
1520 atype.index = exp.X_add_number;
1521 }
1522 }
1523
1524 if (typeinfo)
1525 *typeinfo = atype;
1526
1527 if (rtype)
1528 *rtype = type;
1529
1530 *ccp = str;
1531
1532 return reg->number;
1533 }
1534
1535 /* Like arm_reg_parse, but allow allow the following extra features:
1536 - If RTYPE is non-zero, return the (possibly restricted) type of the
1537 register (e.g. Neon double or quad reg when either has been requested).
1538 - If this is a Neon vector type with additional type information, fill
1539 in the struct pointed to by VECTYPE (if non-NULL).
1540 This function will fault on encountering a scalar. */
1541
1542 static int
1543 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1544 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1545 {
1546 struct neon_typed_alias atype;
1547 char *str = *ccp;
1548 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1549
1550 if (reg == FAIL)
1551 return FAIL;
1552
1553 /* Do not allow regname(... to parse as a register. */
1554 if (*str == '(')
1555 return FAIL;
1556
1557 /* Do not allow a scalar (reg+index) to parse as a register. */
1558 if ((atype.defined & NTA_HASINDEX) != 0)
1559 {
1560 first_error (_("register operand expected, but got scalar"));
1561 return FAIL;
1562 }
1563
1564 if (vectype)
1565 *vectype = atype.eltype;
1566
1567 *ccp = str;
1568
1569 return reg;
1570 }
1571
1572 #define NEON_SCALAR_REG(X) ((X) >> 4)
1573 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1574
1575 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1576 have enough information to be able to do a good job bounds-checking. So, we
1577 just do easy checks here, and do further checks later. */
1578
1579 static int
1580 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1581 {
1582 int reg;
1583 char *str = *ccp;
1584 struct neon_typed_alias atype;
1585
1586 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
1587
1588 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1589 return FAIL;
1590
1591 if (atype.index == NEON_ALL_LANES)
1592 {
1593 first_error (_("scalar must have an index"));
1594 return FAIL;
1595 }
1596 else if (atype.index >= 64 / elsize)
1597 {
1598 first_error (_("scalar index out of range"));
1599 return FAIL;
1600 }
1601
1602 if (type)
1603 *type = atype.eltype;
1604
1605 *ccp = str;
1606
1607 return reg * 16 + atype.index;
1608 }
1609
1610 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1611
1612 static long
1613 parse_reg_list (char ** strp)
1614 {
1615 char * str = * strp;
1616 long range = 0;
1617 int another_range;
1618
1619 /* We come back here if we get ranges concatenated by '+' or '|'. */
1620 do
1621 {
1622 skip_whitespace (str);
1623
1624 another_range = 0;
1625
1626 if (*str == '{')
1627 {
1628 int in_range = 0;
1629 int cur_reg = -1;
1630
1631 str++;
1632 do
1633 {
1634 int reg;
1635
1636 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1637 {
1638 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
1639 return FAIL;
1640 }
1641
1642 if (in_range)
1643 {
1644 int i;
1645
1646 if (reg <= cur_reg)
1647 {
1648 first_error (_("bad range in register list"));
1649 return FAIL;
1650 }
1651
1652 for (i = cur_reg + 1; i < reg; i++)
1653 {
1654 if (range & (1 << i))
1655 as_tsktsk
1656 (_("Warning: duplicated register (r%d) in register list"),
1657 i);
1658 else
1659 range |= 1 << i;
1660 }
1661 in_range = 0;
1662 }
1663
1664 if (range & (1 << reg))
1665 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1666 reg);
1667 else if (reg <= cur_reg)
1668 as_tsktsk (_("Warning: register range not in ascending order"));
1669
1670 range |= 1 << reg;
1671 cur_reg = reg;
1672 }
1673 while (skip_past_comma (&str) != FAIL
1674 || (in_range = 1, *str++ == '-'));
1675 str--;
1676
1677 if (skip_past_char (&str, '}') == FAIL)
1678 {
1679 first_error (_("missing `}'"));
1680 return FAIL;
1681 }
1682 }
1683 else
1684 {
1685 expressionS exp;
1686
1687 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
1688 return FAIL;
1689
1690 if (exp.X_op == O_constant)
1691 {
1692 if (exp.X_add_number
1693 != (exp.X_add_number & 0x0000ffff))
1694 {
1695 inst.error = _("invalid register mask");
1696 return FAIL;
1697 }
1698
1699 if ((range & exp.X_add_number) != 0)
1700 {
1701 int regno = range & exp.X_add_number;
1702
1703 regno &= -regno;
1704 regno = (1 << regno) - 1;
1705 as_tsktsk
1706 (_("Warning: duplicated register (r%d) in register list"),
1707 regno);
1708 }
1709
1710 range |= exp.X_add_number;
1711 }
1712 else
1713 {
1714 if (inst.reloc.type != 0)
1715 {
1716 inst.error = _("expression too complex");
1717 return FAIL;
1718 }
1719
1720 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
1721 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1722 inst.reloc.pc_rel = 0;
1723 }
1724 }
1725
1726 if (*str == '|' || *str == '+')
1727 {
1728 str++;
1729 another_range = 1;
1730 }
1731 }
1732 while (another_range);
1733
1734 *strp = str;
1735 return range;
1736 }
1737
1738 /* Types of registers in a list. */
1739
1740 enum reg_list_els
1741 {
1742 REGLIST_VFP_S,
1743 REGLIST_VFP_D,
1744 REGLIST_NEON_D
1745 };
1746
1747 /* Parse a VFP register list. If the string is invalid return FAIL.
1748 Otherwise return the number of registers, and set PBASE to the first
1749 register. Parses registers of type ETYPE.
1750 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1751 - Q registers can be used to specify pairs of D registers
1752 - { } can be omitted from around a singleton register list
1753 FIXME: This is not implemented, as it would require backtracking in
1754 some cases, e.g.:
1755 vtbl.8 d3,d4,d5
1756 This could be done (the meaning isn't really ambiguous), but doesn't
1757 fit in well with the current parsing framework.
1758 - 32 D registers may be used (also true for VFPv3).
1759 FIXME: Types are ignored in these register lists, which is probably a
1760 bug. */
1761
1762 static int
1763 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
1764 {
1765 char *str = *ccp;
1766 int base_reg;
1767 int new_base;
1768 enum arm_reg_type regtype = (enum arm_reg_type) 0;
1769 int max_regs = 0;
1770 int count = 0;
1771 int warned = 0;
1772 unsigned long mask = 0;
1773 int i;
1774
1775 if (skip_past_char (&str, '{') == FAIL)
1776 {
1777 inst.error = _("expecting {");
1778 return FAIL;
1779 }
1780
1781 switch (etype)
1782 {
1783 case REGLIST_VFP_S:
1784 regtype = REG_TYPE_VFS;
1785 max_regs = 32;
1786 break;
1787
1788 case REGLIST_VFP_D:
1789 regtype = REG_TYPE_VFD;
1790 break;
1791
1792 case REGLIST_NEON_D:
1793 regtype = REG_TYPE_NDQ;
1794 break;
1795 }
1796
1797 if (etype != REGLIST_VFP_S)
1798 {
1799 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1800 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
1801 {
1802 max_regs = 32;
1803 if (thumb_mode)
1804 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1805 fpu_vfp_ext_d32);
1806 else
1807 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1808 fpu_vfp_ext_d32);
1809 }
1810 else
1811 max_regs = 16;
1812 }
1813
1814 base_reg = max_regs;
1815
1816 do
1817 {
1818 int setmask = 1, addregs = 1;
1819
1820 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
1821
1822 if (new_base == FAIL)
1823 {
1824 first_error (_(reg_expected_msgs[regtype]));
1825 return FAIL;
1826 }
1827
1828 if (new_base >= max_regs)
1829 {
1830 first_error (_("register out of range in list"));
1831 return FAIL;
1832 }
1833
1834 /* Note: a value of 2 * n is returned for the register Q<n>. */
1835 if (regtype == REG_TYPE_NQ)
1836 {
1837 setmask = 3;
1838 addregs = 2;
1839 }
1840
1841 if (new_base < base_reg)
1842 base_reg = new_base;
1843
1844 if (mask & (setmask << new_base))
1845 {
1846 first_error (_("invalid register list"));
1847 return FAIL;
1848 }
1849
1850 if ((mask >> new_base) != 0 && ! warned)
1851 {
1852 as_tsktsk (_("register list not in ascending order"));
1853 warned = 1;
1854 }
1855
1856 mask |= setmask << new_base;
1857 count += addregs;
1858
1859 if (*str == '-') /* We have the start of a range expression */
1860 {
1861 int high_range;
1862
1863 str++;
1864
1865 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
1866 == FAIL)
1867 {
1868 inst.error = gettext (reg_expected_msgs[regtype]);
1869 return FAIL;
1870 }
1871
1872 if (high_range >= max_regs)
1873 {
1874 first_error (_("register out of range in list"));
1875 return FAIL;
1876 }
1877
1878 if (regtype == REG_TYPE_NQ)
1879 high_range = high_range + 1;
1880
1881 if (high_range <= new_base)
1882 {
1883 inst.error = _("register range not in ascending order");
1884 return FAIL;
1885 }
1886
1887 for (new_base += addregs; new_base <= high_range; new_base += addregs)
1888 {
1889 if (mask & (setmask << new_base))
1890 {
1891 inst.error = _("invalid register list");
1892 return FAIL;
1893 }
1894
1895 mask |= setmask << new_base;
1896 count += addregs;
1897 }
1898 }
1899 }
1900 while (skip_past_comma (&str) != FAIL);
1901
1902 str++;
1903
1904 /* Sanity check -- should have raised a parse error above. */
1905 if (count == 0 || count > max_regs)
1906 abort ();
1907
1908 *pbase = base_reg;
1909
1910 /* Final test -- the registers must be consecutive. */
1911 mask >>= base_reg;
1912 for (i = 0; i < count; i++)
1913 {
1914 if ((mask & (1u << i)) == 0)
1915 {
1916 inst.error = _("non-contiguous register range");
1917 return FAIL;
1918 }
1919 }
1920
1921 *ccp = str;
1922
1923 return count;
1924 }
1925
1926 /* True if two alias types are the same. */
1927
1928 static bfd_boolean
1929 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1930 {
1931 if (!a && !b)
1932 return TRUE;
1933
1934 if (!a || !b)
1935 return FALSE;
1936
1937 if (a->defined != b->defined)
1938 return FALSE;
1939
1940 if ((a->defined & NTA_HASTYPE) != 0
1941 && (a->eltype.type != b->eltype.type
1942 || a->eltype.size != b->eltype.size))
1943 return FALSE;
1944
1945 if ((a->defined & NTA_HASINDEX) != 0
1946 && (a->index != b->index))
1947 return FALSE;
1948
1949 return TRUE;
1950 }
1951
1952 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1953 The base register is put in *PBASE.
1954 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
1955 the return value.
1956 The register stride (minus one) is put in bit 4 of the return value.
1957 Bits [6:5] encode the list length (minus one).
1958 The type of the list elements is put in *ELTYPE, if non-NULL. */
1959
1960 #define NEON_LANE(X) ((X) & 0xf)
1961 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
1962 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1963
1964 static int
1965 parse_neon_el_struct_list (char **str, unsigned *pbase,
1966 struct neon_type_el *eltype)
1967 {
1968 char *ptr = *str;
1969 int base_reg = -1;
1970 int reg_incr = -1;
1971 int count = 0;
1972 int lane = -1;
1973 int leading_brace = 0;
1974 enum arm_reg_type rtype = REG_TYPE_NDQ;
1975 const char *const incr_error = _("register stride must be 1 or 2");
1976 const char *const type_error = _("mismatched element/structure types in list");
1977 struct neon_typed_alias firsttype;
1978
1979 if (skip_past_char (&ptr, '{') == SUCCESS)
1980 leading_brace = 1;
1981
1982 do
1983 {
1984 struct neon_typed_alias atype;
1985 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1986
1987 if (getreg == FAIL)
1988 {
1989 first_error (_(reg_expected_msgs[rtype]));
1990 return FAIL;
1991 }
1992
1993 if (base_reg == -1)
1994 {
1995 base_reg = getreg;
1996 if (rtype == REG_TYPE_NQ)
1997 {
1998 reg_incr = 1;
1999 }
2000 firsttype = atype;
2001 }
2002 else if (reg_incr == -1)
2003 {
2004 reg_incr = getreg - base_reg;
2005 if (reg_incr < 1 || reg_incr > 2)
2006 {
2007 first_error (_(incr_error));
2008 return FAIL;
2009 }
2010 }
2011 else if (getreg != base_reg + reg_incr * count)
2012 {
2013 first_error (_(incr_error));
2014 return FAIL;
2015 }
2016
2017 if (! neon_alias_types_same (&atype, &firsttype))
2018 {
2019 first_error (_(type_error));
2020 return FAIL;
2021 }
2022
2023 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
2024 modes. */
2025 if (ptr[0] == '-')
2026 {
2027 struct neon_typed_alias htype;
2028 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2029 if (lane == -1)
2030 lane = NEON_INTERLEAVE_LANES;
2031 else if (lane != NEON_INTERLEAVE_LANES)
2032 {
2033 first_error (_(type_error));
2034 return FAIL;
2035 }
2036 if (reg_incr == -1)
2037 reg_incr = 1;
2038 else if (reg_incr != 1)
2039 {
2040 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2041 return FAIL;
2042 }
2043 ptr++;
2044 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2045 if (hireg == FAIL)
2046 {
2047 first_error (_(reg_expected_msgs[rtype]));
2048 return FAIL;
2049 }
2050 if (! neon_alias_types_same (&htype, &firsttype))
2051 {
2052 first_error (_(type_error));
2053 return FAIL;
2054 }
2055 count += hireg + dregs - getreg;
2056 continue;
2057 }
2058
2059 /* If we're using Q registers, we can't use [] or [n] syntax. */
2060 if (rtype == REG_TYPE_NQ)
2061 {
2062 count += 2;
2063 continue;
2064 }
2065
2066 if ((atype.defined & NTA_HASINDEX) != 0)
2067 {
2068 if (lane == -1)
2069 lane = atype.index;
2070 else if (lane != atype.index)
2071 {
2072 first_error (_(type_error));
2073 return FAIL;
2074 }
2075 }
2076 else if (lane == -1)
2077 lane = NEON_INTERLEAVE_LANES;
2078 else if (lane != NEON_INTERLEAVE_LANES)
2079 {
2080 first_error (_(type_error));
2081 return FAIL;
2082 }
2083 count++;
2084 }
2085 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
2086
2087 /* No lane set by [x]. We must be interleaving structures. */
2088 if (lane == -1)
2089 lane = NEON_INTERLEAVE_LANES;
2090
2091 /* Sanity check. */
2092 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2093 || (count > 1 && reg_incr == -1))
2094 {
2095 first_error (_("error parsing element/structure list"));
2096 return FAIL;
2097 }
2098
2099 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2100 {
2101 first_error (_("expected }"));
2102 return FAIL;
2103 }
2104
2105 if (reg_incr == -1)
2106 reg_incr = 1;
2107
2108 if (eltype)
2109 *eltype = firsttype.eltype;
2110
2111 *pbase = base_reg;
2112 *str = ptr;
2113
2114 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2115 }
2116
2117 /* Parse an explicit relocation suffix on an expression. This is
2118 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2119 arm_reloc_hsh contains no entries, so this function can only
2120 succeed if there is no () after the word. Returns -1 on error,
2121 BFD_RELOC_UNUSED if there wasn't any suffix. */
2122
2123 static int
2124 parse_reloc (char **str)
2125 {
2126 struct reloc_entry *r;
2127 char *p, *q;
2128
2129 if (**str != '(')
2130 return BFD_RELOC_UNUSED;
2131
2132 p = *str + 1;
2133 q = p;
2134
2135 while (*q && *q != ')' && *q != ',')
2136 q++;
2137 if (*q != ')')
2138 return -1;
2139
2140 if ((r = (struct reloc_entry *)
2141 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
2142 return -1;
2143
2144 *str = q + 1;
2145 return r->reloc;
2146 }
2147
2148 /* Directives: register aliases. */
2149
2150 static struct reg_entry *
2151 insert_reg_alias (char *str, unsigned number, int type)
2152 {
2153 struct reg_entry *new_reg;
2154 const char *name;
2155
2156 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
2157 {
2158 if (new_reg->builtin)
2159 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
2160
2161 /* Only warn about a redefinition if it's not defined as the
2162 same register. */
2163 else if (new_reg->number != number || new_reg->type != type)
2164 as_warn (_("ignoring redefinition of register alias '%s'"), str);
2165
2166 return NULL;
2167 }
2168
2169 name = xstrdup (str);
2170 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
2171
2172 new_reg->name = name;
2173 new_reg->number = number;
2174 new_reg->type = type;
2175 new_reg->builtin = FALSE;
2176 new_reg->neon = NULL;
2177
2178 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
2179 abort ();
2180
2181 return new_reg;
2182 }
2183
2184 static void
2185 insert_neon_reg_alias (char *str, int number, int type,
2186 struct neon_typed_alias *atype)
2187 {
2188 struct reg_entry *reg = insert_reg_alias (str, number, type);
2189
2190 if (!reg)
2191 {
2192 first_error (_("attempt to redefine typed alias"));
2193 return;
2194 }
2195
2196 if (atype)
2197 {
2198 reg->neon = (struct neon_typed_alias *)
2199 xmalloc (sizeof (struct neon_typed_alias));
2200 *reg->neon = *atype;
2201 }
2202 }
2203
2204 /* Look for the .req directive. This is of the form:
2205
2206 new_register_name .req existing_register_name
2207
2208 If we find one, or if it looks sufficiently like one that we want to
2209 handle any error here, return TRUE. Otherwise return FALSE. */
2210
2211 static bfd_boolean
2212 create_register_alias (char * newname, char *p)
2213 {
2214 struct reg_entry *old;
2215 char *oldname, *nbuf;
2216 size_t nlen;
2217
2218 /* The input scrubber ensures that whitespace after the mnemonic is
2219 collapsed to single spaces. */
2220 oldname = p;
2221 if (strncmp (oldname, " .req ", 6) != 0)
2222 return FALSE;
2223
2224 oldname += 6;
2225 if (*oldname == '\0')
2226 return FALSE;
2227
2228 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
2229 if (!old)
2230 {
2231 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2232 return TRUE;
2233 }
2234
2235 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2236 the desired alias name, and p points to its end. If not, then
2237 the desired alias name is in the global original_case_string. */
2238 #ifdef TC_CASE_SENSITIVE
2239 nlen = p - newname;
2240 #else
2241 newname = original_case_string;
2242 nlen = strlen (newname);
2243 #endif
2244
2245 nbuf = (char *) alloca (nlen + 1);
2246 memcpy (nbuf, newname, nlen);
2247 nbuf[nlen] = '\0';
2248
2249 /* Create aliases under the new name as stated; an all-lowercase
2250 version of the new name; and an all-uppercase version of the new
2251 name. */
2252 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2253 {
2254 for (p = nbuf; *p; p++)
2255 *p = TOUPPER (*p);
2256
2257 if (strncmp (nbuf, newname, nlen))
2258 {
2259 /* If this attempt to create an additional alias fails, do not bother
2260 trying to create the all-lower case alias. We will fail and issue
2261 a second, duplicate error message. This situation arises when the
2262 programmer does something like:
2263 foo .req r0
2264 Foo .req r1
2265 The second .req creates the "Foo" alias but then fails to create
2266 the artificial FOO alias because it has already been created by the
2267 first .req. */
2268 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2269 return TRUE;
2270 }
2271
2272 for (p = nbuf; *p; p++)
2273 *p = TOLOWER (*p);
2274
2275 if (strncmp (nbuf, newname, nlen))
2276 insert_reg_alias (nbuf, old->number, old->type);
2277 }
2278
2279 return TRUE;
2280 }
2281
2282 /* Create a Neon typed/indexed register alias using directives, e.g.:
2283 X .dn d5.s32[1]
2284 Y .qn 6.s16
2285 Z .dn d7
2286 T .dn Z[0]
2287 These typed registers can be used instead of the types specified after the
2288 Neon mnemonic, so long as all operands given have types. Types can also be
2289 specified directly, e.g.:
2290 vadd d0.s32, d1.s32, d2.s32 */
2291
2292 static bfd_boolean
2293 create_neon_reg_alias (char *newname, char *p)
2294 {
2295 enum arm_reg_type basetype;
2296 struct reg_entry *basereg;
2297 struct reg_entry mybasereg;
2298 struct neon_type ntype;
2299 struct neon_typed_alias typeinfo;
2300 char *namebuf, *nameend ATTRIBUTE_UNUSED;
2301 int namelen;
2302
2303 typeinfo.defined = 0;
2304 typeinfo.eltype.type = NT_invtype;
2305 typeinfo.eltype.size = -1;
2306 typeinfo.index = -1;
2307
2308 nameend = p;
2309
2310 if (strncmp (p, " .dn ", 5) == 0)
2311 basetype = REG_TYPE_VFD;
2312 else if (strncmp (p, " .qn ", 5) == 0)
2313 basetype = REG_TYPE_NQ;
2314 else
2315 return FALSE;
2316
2317 p += 5;
2318
2319 if (*p == '\0')
2320 return FALSE;
2321
2322 basereg = arm_reg_parse_multi (&p);
2323
2324 if (basereg && basereg->type != basetype)
2325 {
2326 as_bad (_("bad type for register"));
2327 return FALSE;
2328 }
2329
2330 if (basereg == NULL)
2331 {
2332 expressionS exp;
2333 /* Try parsing as an integer. */
2334 my_get_expression (&exp, &p, GE_NO_PREFIX);
2335 if (exp.X_op != O_constant)
2336 {
2337 as_bad (_("expression must be constant"));
2338 return FALSE;
2339 }
2340 basereg = &mybasereg;
2341 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2342 : exp.X_add_number;
2343 basereg->neon = 0;
2344 }
2345
2346 if (basereg->neon)
2347 typeinfo = *basereg->neon;
2348
2349 if (parse_neon_type (&ntype, &p) == SUCCESS)
2350 {
2351 /* We got a type. */
2352 if (typeinfo.defined & NTA_HASTYPE)
2353 {
2354 as_bad (_("can't redefine the type of a register alias"));
2355 return FALSE;
2356 }
2357
2358 typeinfo.defined |= NTA_HASTYPE;
2359 if (ntype.elems != 1)
2360 {
2361 as_bad (_("you must specify a single type only"));
2362 return FALSE;
2363 }
2364 typeinfo.eltype = ntype.el[0];
2365 }
2366
2367 if (skip_past_char (&p, '[') == SUCCESS)
2368 {
2369 expressionS exp;
2370 /* We got a scalar index. */
2371
2372 if (typeinfo.defined & NTA_HASINDEX)
2373 {
2374 as_bad (_("can't redefine the index of a scalar alias"));
2375 return FALSE;
2376 }
2377
2378 my_get_expression (&exp, &p, GE_NO_PREFIX);
2379
2380 if (exp.X_op != O_constant)
2381 {
2382 as_bad (_("scalar index must be constant"));
2383 return FALSE;
2384 }
2385
2386 typeinfo.defined |= NTA_HASINDEX;
2387 typeinfo.index = exp.X_add_number;
2388
2389 if (skip_past_char (&p, ']') == FAIL)
2390 {
2391 as_bad (_("expecting ]"));
2392 return FALSE;
2393 }
2394 }
2395
2396 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2397 the desired alias name, and p points to its end. If not, then
2398 the desired alias name is in the global original_case_string. */
2399 #ifdef TC_CASE_SENSITIVE
2400 namelen = nameend - newname;
2401 #else
2402 newname = original_case_string;
2403 namelen = strlen (newname);
2404 #endif
2405
2406 namebuf = (char *) alloca (namelen + 1);
2407 strncpy (namebuf, newname, namelen);
2408 namebuf[namelen] = '\0';
2409
2410 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2411 typeinfo.defined != 0 ? &typeinfo : NULL);
2412
2413 /* Insert name in all uppercase. */
2414 for (p = namebuf; *p; p++)
2415 *p = TOUPPER (*p);
2416
2417 if (strncmp (namebuf, newname, namelen))
2418 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2419 typeinfo.defined != 0 ? &typeinfo : NULL);
2420
2421 /* Insert name in all lowercase. */
2422 for (p = namebuf; *p; p++)
2423 *p = TOLOWER (*p);
2424
2425 if (strncmp (namebuf, newname, namelen))
2426 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2427 typeinfo.defined != 0 ? &typeinfo : NULL);
2428
2429 return TRUE;
2430 }
2431
2432 /* Should never be called, as .req goes between the alias and the
2433 register name, not at the beginning of the line. */
2434
2435 static void
2436 s_req (int a ATTRIBUTE_UNUSED)
2437 {
2438 as_bad (_("invalid syntax for .req directive"));
2439 }
2440
2441 static void
2442 s_dn (int a ATTRIBUTE_UNUSED)
2443 {
2444 as_bad (_("invalid syntax for .dn directive"));
2445 }
2446
2447 static void
2448 s_qn (int a ATTRIBUTE_UNUSED)
2449 {
2450 as_bad (_("invalid syntax for .qn directive"));
2451 }
2452
2453 /* The .unreq directive deletes an alias which was previously defined
2454 by .req. For example:
2455
2456 my_alias .req r11
2457 .unreq my_alias */
2458
2459 static void
2460 s_unreq (int a ATTRIBUTE_UNUSED)
2461 {
2462 char * name;
2463 char saved_char;
2464
2465 name = input_line_pointer;
2466
2467 while (*input_line_pointer != 0
2468 && *input_line_pointer != ' '
2469 && *input_line_pointer != '\n')
2470 ++input_line_pointer;
2471
2472 saved_char = *input_line_pointer;
2473 *input_line_pointer = 0;
2474
2475 if (!*name)
2476 as_bad (_("invalid syntax for .unreq directive"));
2477 else
2478 {
2479 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2480 name);
2481
2482 if (!reg)
2483 as_bad (_("unknown register alias '%s'"), name);
2484 else if (reg->builtin)
2485 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
2486 name);
2487 else
2488 {
2489 char * p;
2490 char * nbuf;
2491
2492 hash_delete (arm_reg_hsh, name, FALSE);
2493 free ((char *) reg->name);
2494 if (reg->neon)
2495 free (reg->neon);
2496 free (reg);
2497
2498 /* Also locate the all upper case and all lower case versions.
2499 Do not complain if we cannot find one or the other as it
2500 was probably deleted above. */
2501
2502 nbuf = strdup (name);
2503 for (p = nbuf; *p; p++)
2504 *p = TOUPPER (*p);
2505 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2506 if (reg)
2507 {
2508 hash_delete (arm_reg_hsh, nbuf, FALSE);
2509 free ((char *) reg->name);
2510 if (reg->neon)
2511 free (reg->neon);
2512 free (reg);
2513 }
2514
2515 for (p = nbuf; *p; p++)
2516 *p = TOLOWER (*p);
2517 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2518 if (reg)
2519 {
2520 hash_delete (arm_reg_hsh, nbuf, FALSE);
2521 free ((char *) reg->name);
2522 if (reg->neon)
2523 free (reg->neon);
2524 free (reg);
2525 }
2526
2527 free (nbuf);
2528 }
2529 }
2530
2531 *input_line_pointer = saved_char;
2532 demand_empty_rest_of_line ();
2533 }
2534
2535 /* Directives: Instruction set selection. */
2536
2537 #ifdef OBJ_ELF
2538 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2539 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2540 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2541 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2542
2543 /* Create a new mapping symbol for the transition to STATE. */
2544
2545 static void
2546 make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
2547 {
2548 symbolS * symbolP;
2549 const char * symname;
2550 int type;
2551
2552 switch (state)
2553 {
2554 case MAP_DATA:
2555 symname = "$d";
2556 type = BSF_NO_FLAGS;
2557 break;
2558 case MAP_ARM:
2559 symname = "$a";
2560 type = BSF_NO_FLAGS;
2561 break;
2562 case MAP_THUMB:
2563 symname = "$t";
2564 type = BSF_NO_FLAGS;
2565 break;
2566 default:
2567 abort ();
2568 }
2569
2570 symbolP = symbol_new (symname, now_seg, value, frag);
2571 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2572
2573 switch (state)
2574 {
2575 case MAP_ARM:
2576 THUMB_SET_FUNC (symbolP, 0);
2577 ARM_SET_THUMB (symbolP, 0);
2578 ARM_SET_INTERWORK (symbolP, support_interwork);
2579 break;
2580
2581 case MAP_THUMB:
2582 THUMB_SET_FUNC (symbolP, 1);
2583 ARM_SET_THUMB (symbolP, 1);
2584 ARM_SET_INTERWORK (symbolP, support_interwork);
2585 break;
2586
2587 case MAP_DATA:
2588 default:
2589 break;
2590 }
2591
2592 /* Save the mapping symbols for future reference. Also check that
2593 we do not place two mapping symbols at the same offset within a
2594 frag. We'll handle overlap between frags in
2595 check_mapping_symbols.
2596
2597 If .fill or other data filling directive generates zero sized data,
2598 the mapping symbol for the following code will have the same value
2599 as the one generated for the data filling directive. In this case,
2600 we replace the old symbol with the new one at the same address. */
2601 if (value == 0)
2602 {
2603 if (frag->tc_frag_data.first_map != NULL)
2604 {
2605 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2606 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2607 }
2608 frag->tc_frag_data.first_map = symbolP;
2609 }
2610 if (frag->tc_frag_data.last_map != NULL)
2611 {
2612 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
2613 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2614 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2615 }
2616 frag->tc_frag_data.last_map = symbolP;
2617 }
2618
2619 /* We must sometimes convert a region marked as code to data during
2620 code alignment, if an odd number of bytes have to be padded. The
2621 code mapping symbol is pushed to an aligned address. */
2622
2623 static void
2624 insert_data_mapping_symbol (enum mstate state,
2625 valueT value, fragS *frag, offsetT bytes)
2626 {
2627 /* If there was already a mapping symbol, remove it. */
2628 if (frag->tc_frag_data.last_map != NULL
2629 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2630 {
2631 symbolS *symp = frag->tc_frag_data.last_map;
2632
2633 if (value == 0)
2634 {
2635 know (frag->tc_frag_data.first_map == symp);
2636 frag->tc_frag_data.first_map = NULL;
2637 }
2638 frag->tc_frag_data.last_map = NULL;
2639 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
2640 }
2641
2642 make_mapping_symbol (MAP_DATA, value, frag);
2643 make_mapping_symbol (state, value + bytes, frag);
2644 }
2645
2646 static void mapping_state_2 (enum mstate state, int max_chars);
2647
2648 /* Set the mapping state to STATE. Only call this when about to
2649 emit some STATE bytes to the file. */
2650
2651 #define TRANSITION(from, to) (mapstate == (from) && state == (to))
2652 void
2653 mapping_state (enum mstate state)
2654 {
2655 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2656
2657 if (mapstate == state)
2658 /* The mapping symbol has already been emitted.
2659 There is nothing else to do. */
2660 return;
2661
2662 if (state == MAP_ARM || state == MAP_THUMB)
2663 /* PR gas/12931
2664 All ARM instructions require 4-byte alignment.
2665 (Almost) all Thumb instructions require 2-byte alignment.
2666
2667 When emitting instructions into any section, mark the section
2668 appropriately.
2669
2670 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2671 but themselves require 2-byte alignment; this applies to some
2672 PC- relative forms. However, these cases will invovle implicit
2673 literal pool generation or an explicit .align >=2, both of
2674 which will cause the section to me marked with sufficient
2675 alignment. Thus, we don't handle those cases here. */
2676 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2677
2678 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
2679 /* This case will be evaluated later. */
2680 return;
2681
2682 mapping_state_2 (state, 0);
2683 }
2684
2685 /* Same as mapping_state, but MAX_CHARS bytes have already been
2686 allocated. Put the mapping symbol that far back. */
2687
2688 static void
2689 mapping_state_2 (enum mstate state, int max_chars)
2690 {
2691 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2692
2693 if (!SEG_NORMAL (now_seg))
2694 return;
2695
2696 if (mapstate == state)
2697 /* The mapping symbol has already been emitted.
2698 There is nothing else to do. */
2699 return;
2700
2701 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2702 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2703 {
2704 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2705 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2706
2707 if (add_symbol)
2708 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2709 }
2710
2711 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2712 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
2713 }
2714 #undef TRANSITION
2715 #else
2716 #define mapping_state(x) ((void)0)
2717 #define mapping_state_2(x, y) ((void)0)
2718 #endif
2719
2720 /* Find the real, Thumb encoded start of a Thumb function. */
2721
2722 #ifdef OBJ_COFF
2723 static symbolS *
2724 find_real_start (symbolS * symbolP)
2725 {
2726 char * real_start;
2727 const char * name = S_GET_NAME (symbolP);
2728 symbolS * new_target;
2729
2730 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2731 #define STUB_NAME ".real_start_of"
2732
2733 if (name == NULL)
2734 abort ();
2735
2736 /* The compiler may generate BL instructions to local labels because
2737 it needs to perform a branch to a far away location. These labels
2738 do not have a corresponding ".real_start_of" label. We check
2739 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2740 the ".real_start_of" convention for nonlocal branches. */
2741 if (S_IS_LOCAL (symbolP) || name[0] == '.')
2742 return symbolP;
2743
2744 real_start = ACONCAT ((STUB_NAME, name, NULL));
2745 new_target = symbol_find (real_start);
2746
2747 if (new_target == NULL)
2748 {
2749 as_warn (_("Failed to find real start of function: %s\n"), name);
2750 new_target = symbolP;
2751 }
2752
2753 return new_target;
2754 }
2755 #endif
2756
2757 static void
2758 opcode_select (int width)
2759 {
2760 switch (width)
2761 {
2762 case 16:
2763 if (! thumb_mode)
2764 {
2765 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
2766 as_bad (_("selected processor does not support THUMB opcodes"));
2767
2768 thumb_mode = 1;
2769 /* No need to force the alignment, since we will have been
2770 coming from ARM mode, which is word-aligned. */
2771 record_alignment (now_seg, 1);
2772 }
2773 break;
2774
2775 case 32:
2776 if (thumb_mode)
2777 {
2778 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
2779 as_bad (_("selected processor does not support ARM opcodes"));
2780
2781 thumb_mode = 0;
2782
2783 if (!need_pass_2)
2784 frag_align (2, 0, 0);
2785
2786 record_alignment (now_seg, 1);
2787 }
2788 break;
2789
2790 default:
2791 as_bad (_("invalid instruction size selected (%d)"), width);
2792 }
2793 }
2794
2795 static void
2796 s_arm (int ignore ATTRIBUTE_UNUSED)
2797 {
2798 opcode_select (32);
2799 demand_empty_rest_of_line ();
2800 }
2801
2802 static void
2803 s_thumb (int ignore ATTRIBUTE_UNUSED)
2804 {
2805 opcode_select (16);
2806 demand_empty_rest_of_line ();
2807 }
2808
2809 static void
2810 s_code (int unused ATTRIBUTE_UNUSED)
2811 {
2812 int temp;
2813
2814 temp = get_absolute_expression ();
2815 switch (temp)
2816 {
2817 case 16:
2818 case 32:
2819 opcode_select (temp);
2820 break;
2821
2822 default:
2823 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2824 }
2825 }
2826
2827 static void
2828 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2829 {
2830 /* If we are not already in thumb mode go into it, EVEN if
2831 the target processor does not support thumb instructions.
2832 This is used by gcc/config/arm/lib1funcs.asm for example
2833 to compile interworking support functions even if the
2834 target processor should not support interworking. */
2835 if (! thumb_mode)
2836 {
2837 thumb_mode = 2;
2838 record_alignment (now_seg, 1);
2839 }
2840
2841 demand_empty_rest_of_line ();
2842 }
2843
2844 static void
2845 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2846 {
2847 s_thumb (0);
2848
2849 /* The following label is the name/address of the start of a Thumb function.
2850 We need to know this for the interworking support. */
2851 label_is_thumb_function_name = TRUE;
2852 }
2853
2854 /* Perform a .set directive, but also mark the alias as
2855 being a thumb function. */
2856
2857 static void
2858 s_thumb_set (int equiv)
2859 {
2860 /* XXX the following is a duplicate of the code for s_set() in read.c
2861 We cannot just call that code as we need to get at the symbol that
2862 is created. */
2863 char * name;
2864 char delim;
2865 char * end_name;
2866 symbolS * symbolP;
2867
2868 /* Especial apologies for the random logic:
2869 This just grew, and could be parsed much more simply!
2870 Dean - in haste. */
2871 name = input_line_pointer;
2872 delim = get_symbol_end ();
2873 end_name = input_line_pointer;
2874 *end_name = delim;
2875
2876 if (*input_line_pointer != ',')
2877 {
2878 *end_name = 0;
2879 as_bad (_("expected comma after name \"%s\""), name);
2880 *end_name = delim;
2881 ignore_rest_of_line ();
2882 return;
2883 }
2884
2885 input_line_pointer++;
2886 *end_name = 0;
2887
2888 if (name[0] == '.' && name[1] == '\0')
2889 {
2890 /* XXX - this should not happen to .thumb_set. */
2891 abort ();
2892 }
2893
2894 if ((symbolP = symbol_find (name)) == NULL
2895 && (symbolP = md_undefined_symbol (name)) == NULL)
2896 {
2897 #ifndef NO_LISTING
2898 /* When doing symbol listings, play games with dummy fragments living
2899 outside the normal fragment chain to record the file and line info
2900 for this symbol. */
2901 if (listing & LISTING_SYMBOLS)
2902 {
2903 extern struct list_info_struct * listing_tail;
2904 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
2905
2906 memset (dummy_frag, 0, sizeof (fragS));
2907 dummy_frag->fr_type = rs_fill;
2908 dummy_frag->line = listing_tail;
2909 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2910 dummy_frag->fr_symbol = symbolP;
2911 }
2912 else
2913 #endif
2914 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2915
2916 #ifdef OBJ_COFF
2917 /* "set" symbols are local unless otherwise specified. */
2918 SF_SET_LOCAL (symbolP);
2919 #endif /* OBJ_COFF */
2920 } /* Make a new symbol. */
2921
2922 symbol_table_insert (symbolP);
2923
2924 * end_name = delim;
2925
2926 if (equiv
2927 && S_IS_DEFINED (symbolP)
2928 && S_GET_SEGMENT (symbolP) != reg_section)
2929 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2930
2931 pseudo_set (symbolP);
2932
2933 demand_empty_rest_of_line ();
2934
2935 /* XXX Now we come to the Thumb specific bit of code. */
2936
2937 THUMB_SET_FUNC (symbolP, 1);
2938 ARM_SET_THUMB (symbolP, 1);
2939 #if defined OBJ_ELF || defined OBJ_COFF
2940 ARM_SET_INTERWORK (symbolP, support_interwork);
2941 #endif
2942 }
2943
2944 /* Directives: Mode selection. */
2945
2946 /* .syntax [unified|divided] - choose the new unified syntax
2947 (same for Arm and Thumb encoding, modulo slight differences in what
2948 can be represented) or the old divergent syntax for each mode. */
2949 static void
2950 s_syntax (int unused ATTRIBUTE_UNUSED)
2951 {
2952 char *name, delim;
2953
2954 name = input_line_pointer;
2955 delim = get_symbol_end ();
2956
2957 if (!strcasecmp (name, "unified"))
2958 unified_syntax = TRUE;
2959 else if (!strcasecmp (name, "divided"))
2960 unified_syntax = FALSE;
2961 else
2962 {
2963 as_bad (_("unrecognized syntax mode \"%s\""), name);
2964 return;
2965 }
2966 *input_line_pointer = delim;
2967 demand_empty_rest_of_line ();
2968 }
2969
2970 /* Directives: sectioning and alignment. */
2971
2972 static void
2973 s_bss (int ignore ATTRIBUTE_UNUSED)
2974 {
2975 /* We don't support putting frags in the BSS segment, we fake it by
2976 marking in_bss, then looking at s_skip for clues. */
2977 subseg_set (bss_section, 0);
2978 demand_empty_rest_of_line ();
2979
2980 #ifdef md_elf_section_change_hook
2981 md_elf_section_change_hook ();
2982 #endif
2983 }
2984
2985 static void
2986 s_even (int ignore ATTRIBUTE_UNUSED)
2987 {
2988 /* Never make frag if expect extra pass. */
2989 if (!need_pass_2)
2990 frag_align (1, 0, 0);
2991
2992 record_alignment (now_seg, 1);
2993
2994 demand_empty_rest_of_line ();
2995 }
2996
2997 /* Directives: CodeComposer Studio. */
2998
2999 /* .ref (for CodeComposer Studio syntax only). */
3000 static void
3001 s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3002 {
3003 if (codecomposer_syntax)
3004 ignore_rest_of_line ();
3005 else
3006 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3007 }
3008
3009 /* If name is not NULL, then it is used for marking the beginning of a
3010 function, wherease if it is NULL then it means the function end. */
3011 static void
3012 asmfunc_debug (const char * name)
3013 {
3014 static const char * last_name = NULL;
3015
3016 if (name != NULL)
3017 {
3018 gas_assert (last_name == NULL);
3019 last_name = name;
3020
3021 if (debug_type == DEBUG_STABS)
3022 stabs_generate_asm_func (name, name);
3023 }
3024 else
3025 {
3026 gas_assert (last_name != NULL);
3027
3028 if (debug_type == DEBUG_STABS)
3029 stabs_generate_asm_endfunc (last_name, last_name);
3030
3031 last_name = NULL;
3032 }
3033 }
3034
3035 static void
3036 s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3037 {
3038 if (codecomposer_syntax)
3039 {
3040 switch (asmfunc_state)
3041 {
3042 case OUTSIDE_ASMFUNC:
3043 asmfunc_state = WAITING_ASMFUNC_NAME;
3044 break;
3045
3046 case WAITING_ASMFUNC_NAME:
3047 as_bad (_(".asmfunc repeated."));
3048 break;
3049
3050 case WAITING_ENDASMFUNC:
3051 as_bad (_(".asmfunc without function."));
3052 break;
3053 }
3054 demand_empty_rest_of_line ();
3055 }
3056 else
3057 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3058 }
3059
3060 static void
3061 s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3062 {
3063 if (codecomposer_syntax)
3064 {
3065 switch (asmfunc_state)
3066 {
3067 case OUTSIDE_ASMFUNC:
3068 as_bad (_(".endasmfunc without a .asmfunc."));
3069 break;
3070
3071 case WAITING_ASMFUNC_NAME:
3072 as_bad (_(".endasmfunc without function."));
3073 break;
3074
3075 case WAITING_ENDASMFUNC:
3076 asmfunc_state = OUTSIDE_ASMFUNC;
3077 asmfunc_debug (NULL);
3078 break;
3079 }
3080 demand_empty_rest_of_line ();
3081 }
3082 else
3083 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3084 }
3085
3086 static void
3087 s_ccs_def (int name)
3088 {
3089 if (codecomposer_syntax)
3090 s_globl (name);
3091 else
3092 as_bad (_(".def pseudo-op only available with -mccs flag."));
3093 }
3094
3095 /* Directives: Literal pools. */
3096
3097 static literal_pool *
3098 find_literal_pool (void)
3099 {
3100 literal_pool * pool;
3101
3102 for (pool = list_of_pools; pool != NULL; pool = pool->next)
3103 {
3104 if (pool->section == now_seg
3105 && pool->sub_section == now_subseg)
3106 break;
3107 }
3108
3109 return pool;
3110 }
3111
3112 static literal_pool *
3113 find_or_make_literal_pool (void)
3114 {
3115 /* Next literal pool ID number. */
3116 static unsigned int latest_pool_num = 1;
3117 literal_pool * pool;
3118
3119 pool = find_literal_pool ();
3120
3121 if (pool == NULL)
3122 {
3123 /* Create a new pool. */
3124 pool = (literal_pool *) xmalloc (sizeof (* pool));
3125 if (! pool)
3126 return NULL;
3127
3128 pool->next_free_entry = 0;
3129 pool->section = now_seg;
3130 pool->sub_section = now_subseg;
3131 pool->next = list_of_pools;
3132 pool->symbol = NULL;
3133 pool->alignment = 2;
3134
3135 /* Add it to the list. */
3136 list_of_pools = pool;
3137 }
3138
3139 /* New pools, and emptied pools, will have a NULL symbol. */
3140 if (pool->symbol == NULL)
3141 {
3142 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3143 (valueT) 0, &zero_address_frag);
3144 pool->id = latest_pool_num ++;
3145 }
3146
3147 /* Done. */
3148 return pool;
3149 }
3150
3151 /* Add the literal in the global 'inst'
3152 structure to the relevant literal pool. */
3153
3154 static int
3155 add_to_lit_pool (unsigned int nbytes)
3156 {
3157 #define PADDING_SLOT 0x1
3158 #define LIT_ENTRY_SIZE_MASK 0xFF
3159 literal_pool * pool;
3160 unsigned int entry, pool_size = 0;
3161 bfd_boolean padding_slot_p = FALSE;
3162 unsigned imm1 = 0;
3163 unsigned imm2 = 0;
3164
3165 if (nbytes == 8)
3166 {
3167 imm1 = inst.operands[1].imm;
3168 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3169 : inst.reloc.exp.X_unsigned ? 0
3170 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
3171 if (target_big_endian)
3172 {
3173 imm1 = imm2;
3174 imm2 = inst.operands[1].imm;
3175 }
3176 }
3177
3178 pool = find_or_make_literal_pool ();
3179
3180 /* Check if this literal value is already in the pool. */
3181 for (entry = 0; entry < pool->next_free_entry; entry ++)
3182 {
3183 if (nbytes == 4)
3184 {
3185 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3186 && (inst.reloc.exp.X_op == O_constant)
3187 && (pool->literals[entry].X_add_number
3188 == inst.reloc.exp.X_add_number)
3189 && (pool->literals[entry].X_md == nbytes)
3190 && (pool->literals[entry].X_unsigned
3191 == inst.reloc.exp.X_unsigned))
3192 break;
3193
3194 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3195 && (inst.reloc.exp.X_op == O_symbol)
3196 && (pool->literals[entry].X_add_number
3197 == inst.reloc.exp.X_add_number)
3198 && (pool->literals[entry].X_add_symbol
3199 == inst.reloc.exp.X_add_symbol)
3200 && (pool->literals[entry].X_op_symbol
3201 == inst.reloc.exp.X_op_symbol)
3202 && (pool->literals[entry].X_md == nbytes))
3203 break;
3204 }
3205 else if ((nbytes == 8)
3206 && !(pool_size & 0x7)
3207 && ((entry + 1) != pool->next_free_entry)
3208 && (pool->literals[entry].X_op == O_constant)
3209 && (pool->literals[entry].X_add_number == (offsetT) imm1)
3210 && (pool->literals[entry].X_unsigned
3211 == inst.reloc.exp.X_unsigned)
3212 && (pool->literals[entry + 1].X_op == O_constant)
3213 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
3214 && (pool->literals[entry + 1].X_unsigned
3215 == inst.reloc.exp.X_unsigned))
3216 break;
3217
3218 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3219 if (padding_slot_p && (nbytes == 4))
3220 break;
3221
3222 pool_size += 4;
3223 }
3224
3225 /* Do we need to create a new entry? */
3226 if (entry == pool->next_free_entry)
3227 {
3228 if (entry >= MAX_LITERAL_POOL_SIZE)
3229 {
3230 inst.error = _("literal pool overflow");
3231 return FAIL;
3232 }
3233
3234 if (nbytes == 8)
3235 {
3236 /* For 8-byte entries, we align to an 8-byte boundary,
3237 and split it into two 4-byte entries, because on 32-bit
3238 host, 8-byte constants are treated as big num, thus
3239 saved in "generic_bignum" which will be overwritten
3240 by later assignments.
3241
3242 We also need to make sure there is enough space for
3243 the split.
3244
3245 We also check to make sure the literal operand is a
3246 constant number. */
3247 if (!(inst.reloc.exp.X_op == O_constant
3248 || inst.reloc.exp.X_op == O_big))
3249 {
3250 inst.error = _("invalid type for literal pool");
3251 return FAIL;
3252 }
3253 else if (pool_size & 0x7)
3254 {
3255 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3256 {
3257 inst.error = _("literal pool overflow");
3258 return FAIL;
3259 }
3260
3261 pool->literals[entry] = inst.reloc.exp;
3262 pool->literals[entry].X_add_number = 0;
3263 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3264 pool->next_free_entry += 1;
3265 pool_size += 4;
3266 }
3267 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3268 {
3269 inst.error = _("literal pool overflow");
3270 return FAIL;
3271 }
3272
3273 pool->literals[entry] = inst.reloc.exp;
3274 pool->literals[entry].X_op = O_constant;
3275 pool->literals[entry].X_add_number = imm1;
3276 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3277 pool->literals[entry++].X_md = 4;
3278 pool->literals[entry] = inst.reloc.exp;
3279 pool->literals[entry].X_op = O_constant;
3280 pool->literals[entry].X_add_number = imm2;
3281 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3282 pool->literals[entry].X_md = 4;
3283 pool->alignment = 3;
3284 pool->next_free_entry += 1;
3285 }
3286 else
3287 {
3288 pool->literals[entry] = inst.reloc.exp;
3289 pool->literals[entry].X_md = 4;
3290 }
3291
3292 #ifdef OBJ_ELF
3293 /* PR ld/12974: Record the location of the first source line to reference
3294 this entry in the literal pool. If it turns out during linking that the
3295 symbol does not exist we will be able to give an accurate line number for
3296 the (first use of the) missing reference. */
3297 if (debug_type == DEBUG_DWARF2)
3298 dwarf2_where (pool->locs + entry);
3299 #endif
3300 pool->next_free_entry += 1;
3301 }
3302 else if (padding_slot_p)
3303 {
3304 pool->literals[entry] = inst.reloc.exp;
3305 pool->literals[entry].X_md = nbytes;
3306 }
3307
3308 inst.reloc.exp.X_op = O_symbol;
3309 inst.reloc.exp.X_add_number = pool_size;
3310 inst.reloc.exp.X_add_symbol = pool->symbol;
3311
3312 return SUCCESS;
3313 }
3314
3315 bfd_boolean
3316 tc_start_label_without_colon (char unused1 ATTRIBUTE_UNUSED, const char * rest)
3317 {
3318 bfd_boolean ret = TRUE;
3319
3320 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3321 {
3322 const char *label = rest;
3323
3324 while (!is_end_of_line[(int) label[-1]])
3325 --label;
3326
3327 if (*label == '.')
3328 {
3329 as_bad (_("Invalid label '%s'"), label);
3330 ret = FALSE;
3331 }
3332
3333 asmfunc_debug (label);
3334
3335 asmfunc_state = WAITING_ENDASMFUNC;
3336 }
3337
3338 return ret;
3339 }
3340
3341 /* Can't use symbol_new here, so have to create a symbol and then at
3342 a later date assign it a value. Thats what these functions do. */
3343
3344 static void
3345 symbol_locate (symbolS * symbolP,
3346 const char * name, /* It is copied, the caller can modify. */
3347 segT segment, /* Segment identifier (SEG_<something>). */
3348 valueT valu, /* Symbol value. */
3349 fragS * frag) /* Associated fragment. */
3350 {
3351 size_t name_length;
3352 char * preserved_copy_of_name;
3353
3354 name_length = strlen (name) + 1; /* +1 for \0. */
3355 obstack_grow (&notes, name, name_length);
3356 preserved_copy_of_name = (char *) obstack_finish (&notes);
3357
3358 #ifdef tc_canonicalize_symbol_name
3359 preserved_copy_of_name =
3360 tc_canonicalize_symbol_name (preserved_copy_of_name);
3361 #endif
3362
3363 S_SET_NAME (symbolP, preserved_copy_of_name);
3364
3365 S_SET_SEGMENT (symbolP, segment);
3366 S_SET_VALUE (symbolP, valu);
3367 symbol_clear_list_pointers (symbolP);
3368
3369 symbol_set_frag (symbolP, frag);
3370
3371 /* Link to end of symbol chain. */
3372 {
3373 extern int symbol_table_frozen;
3374
3375 if (symbol_table_frozen)
3376 abort ();
3377 }
3378
3379 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
3380
3381 obj_symbol_new_hook (symbolP);
3382
3383 #ifdef tc_symbol_new_hook
3384 tc_symbol_new_hook (symbolP);
3385 #endif
3386
3387 #ifdef DEBUG_SYMS
3388 verify_symbol_chain (symbol_rootP, symbol_lastP);
3389 #endif /* DEBUG_SYMS */
3390 }
3391
3392 static void
3393 s_ltorg (int ignored ATTRIBUTE_UNUSED)
3394 {
3395 unsigned int entry;
3396 literal_pool * pool;
3397 char sym_name[20];
3398
3399 pool = find_literal_pool ();
3400 if (pool == NULL
3401 || pool->symbol == NULL
3402 || pool->next_free_entry == 0)
3403 return;
3404
3405 /* Align pool as you have word accesses.
3406 Only make a frag if we have to. */
3407 if (!need_pass_2)
3408 frag_align (pool->alignment, 0, 0);
3409
3410 record_alignment (now_seg, 2);
3411
3412 #ifdef OBJ_ELF
3413 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3414 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
3415 #endif
3416 sprintf (sym_name, "$$lit_\002%x", pool->id);
3417
3418 symbol_locate (pool->symbol, sym_name, now_seg,
3419 (valueT) frag_now_fix (), frag_now);
3420 symbol_table_insert (pool->symbol);
3421
3422 ARM_SET_THUMB (pool->symbol, thumb_mode);
3423
3424 #if defined OBJ_COFF || defined OBJ_ELF
3425 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3426 #endif
3427
3428 for (entry = 0; entry < pool->next_free_entry; entry ++)
3429 {
3430 #ifdef OBJ_ELF
3431 if (debug_type == DEBUG_DWARF2)
3432 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3433 #endif
3434 /* First output the expression in the instruction to the pool. */
3435 emit_expr (&(pool->literals[entry]),
3436 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
3437 }
3438
3439 /* Mark the pool as empty. */
3440 pool->next_free_entry = 0;
3441 pool->symbol = NULL;
3442 }
3443
3444 #ifdef OBJ_ELF
3445 /* Forward declarations for functions below, in the MD interface
3446 section. */
3447 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3448 static valueT create_unwind_entry (int);
3449 static void start_unwind_section (const segT, int);
3450 static void add_unwind_opcode (valueT, int);
3451 static void flush_pending_unwind (void);
3452
3453 /* Directives: Data. */
3454
3455 static void
3456 s_arm_elf_cons (int nbytes)
3457 {
3458 expressionS exp;
3459
3460 #ifdef md_flush_pending_output
3461 md_flush_pending_output ();
3462 #endif
3463
3464 if (is_it_end_of_statement ())
3465 {
3466 demand_empty_rest_of_line ();
3467 return;
3468 }
3469
3470 #ifdef md_cons_align
3471 md_cons_align (nbytes);
3472 #endif
3473
3474 mapping_state (MAP_DATA);
3475 do
3476 {
3477 int reloc;
3478 char *base = input_line_pointer;
3479
3480 expression (& exp);
3481
3482 if (exp.X_op != O_symbol)
3483 emit_expr (&exp, (unsigned int) nbytes);
3484 else
3485 {
3486 char *before_reloc = input_line_pointer;
3487 reloc = parse_reloc (&input_line_pointer);
3488 if (reloc == -1)
3489 {
3490 as_bad (_("unrecognized relocation suffix"));
3491 ignore_rest_of_line ();
3492 return;
3493 }
3494 else if (reloc == BFD_RELOC_UNUSED)
3495 emit_expr (&exp, (unsigned int) nbytes);
3496 else
3497 {
3498 reloc_howto_type *howto = (reloc_howto_type *)
3499 bfd_reloc_type_lookup (stdoutput,
3500 (bfd_reloc_code_real_type) reloc);
3501 int size = bfd_get_reloc_size (howto);
3502
3503 if (reloc == BFD_RELOC_ARM_PLT32)
3504 {
3505 as_bad (_("(plt) is only valid on branch targets"));
3506 reloc = BFD_RELOC_UNUSED;
3507 size = 0;
3508 }
3509
3510 if (size > nbytes)
3511 as_bad (_("%s relocations do not fit in %d bytes"),
3512 howto->name, nbytes);
3513 else
3514 {
3515 /* We've parsed an expression stopping at O_symbol.
3516 But there may be more expression left now that we
3517 have parsed the relocation marker. Parse it again.
3518 XXX Surely there is a cleaner way to do this. */
3519 char *p = input_line_pointer;
3520 int offset;
3521 char *save_buf = (char *) alloca (input_line_pointer - base);
3522 memcpy (save_buf, base, input_line_pointer - base);
3523 memmove (base + (input_line_pointer - before_reloc),
3524 base, before_reloc - base);
3525
3526 input_line_pointer = base + (input_line_pointer-before_reloc);
3527 expression (&exp);
3528 memcpy (base, save_buf, p - base);
3529
3530 offset = nbytes - size;
3531 p = frag_more (nbytes);
3532 memset (p, 0, nbytes);
3533 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3534 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
3535 }
3536 }
3537 }
3538 }
3539 while (*input_line_pointer++ == ',');
3540
3541 /* Put terminator back into stream. */
3542 input_line_pointer --;
3543 demand_empty_rest_of_line ();
3544 }
3545
3546 /* Emit an expression containing a 32-bit thumb instruction.
3547 Implementation based on put_thumb32_insn. */
3548
3549 static void
3550 emit_thumb32_expr (expressionS * exp)
3551 {
3552 expressionS exp_high = *exp;
3553
3554 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3555 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3556 exp->X_add_number &= 0xffff;
3557 emit_expr (exp, (unsigned int) THUMB_SIZE);
3558 }
3559
3560 /* Guess the instruction size based on the opcode. */
3561
3562 static int
3563 thumb_insn_size (int opcode)
3564 {
3565 if ((unsigned int) opcode < 0xe800u)
3566 return 2;
3567 else if ((unsigned int) opcode >= 0xe8000000u)
3568 return 4;
3569 else
3570 return 0;
3571 }
3572
3573 static bfd_boolean
3574 emit_insn (expressionS *exp, int nbytes)
3575 {
3576 int size = 0;
3577
3578 if (exp->X_op == O_constant)
3579 {
3580 size = nbytes;
3581
3582 if (size == 0)
3583 size = thumb_insn_size (exp->X_add_number);
3584
3585 if (size != 0)
3586 {
3587 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3588 {
3589 as_bad (_(".inst.n operand too big. "\
3590 "Use .inst.w instead"));
3591 size = 0;
3592 }
3593 else
3594 {
3595 if (now_it.state == AUTOMATIC_IT_BLOCK)
3596 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3597 else
3598 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3599
3600 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3601 emit_thumb32_expr (exp);
3602 else
3603 emit_expr (exp, (unsigned int) size);
3604
3605 it_fsm_post_encode ();
3606 }
3607 }
3608 else
3609 as_bad (_("cannot determine Thumb instruction size. " \
3610 "Use .inst.n/.inst.w instead"));
3611 }
3612 else
3613 as_bad (_("constant expression required"));
3614
3615 return (size != 0);
3616 }
3617
3618 /* Like s_arm_elf_cons but do not use md_cons_align and
3619 set the mapping state to MAP_ARM/MAP_THUMB. */
3620
3621 static void
3622 s_arm_elf_inst (int nbytes)
3623 {
3624 if (is_it_end_of_statement ())
3625 {
3626 demand_empty_rest_of_line ();
3627 return;
3628 }
3629
3630 /* Calling mapping_state () here will not change ARM/THUMB,
3631 but will ensure not to be in DATA state. */
3632
3633 if (thumb_mode)
3634 mapping_state (MAP_THUMB);
3635 else
3636 {
3637 if (nbytes != 0)
3638 {
3639 as_bad (_("width suffixes are invalid in ARM mode"));
3640 ignore_rest_of_line ();
3641 return;
3642 }
3643
3644 nbytes = 4;
3645
3646 mapping_state (MAP_ARM);
3647 }
3648
3649 do
3650 {
3651 expressionS exp;
3652
3653 expression (& exp);
3654
3655 if (! emit_insn (& exp, nbytes))
3656 {
3657 ignore_rest_of_line ();
3658 return;
3659 }
3660 }
3661 while (*input_line_pointer++ == ',');
3662
3663 /* Put terminator back into stream. */
3664 input_line_pointer --;
3665 demand_empty_rest_of_line ();
3666 }
3667
3668 /* Parse a .rel31 directive. */
3669
3670 static void
3671 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3672 {
3673 expressionS exp;
3674 char *p;
3675 valueT highbit;
3676
3677 highbit = 0;
3678 if (*input_line_pointer == '1')
3679 highbit = 0x80000000;
3680 else if (*input_line_pointer != '0')
3681 as_bad (_("expected 0 or 1"));
3682
3683 input_line_pointer++;
3684 if (*input_line_pointer != ',')
3685 as_bad (_("missing comma"));
3686 input_line_pointer++;
3687
3688 #ifdef md_flush_pending_output
3689 md_flush_pending_output ();
3690 #endif
3691
3692 #ifdef md_cons_align
3693 md_cons_align (4);
3694 #endif
3695
3696 mapping_state (MAP_DATA);
3697
3698 expression (&exp);
3699
3700 p = frag_more (4);
3701 md_number_to_chars (p, highbit, 4);
3702 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3703 BFD_RELOC_ARM_PREL31);
3704
3705 demand_empty_rest_of_line ();
3706 }
3707
3708 /* Directives: AEABI stack-unwind tables. */
3709
3710 /* Parse an unwind_fnstart directive. Simply records the current location. */
3711
3712 static void
3713 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3714 {
3715 demand_empty_rest_of_line ();
3716 if (unwind.proc_start)
3717 {
3718 as_bad (_("duplicate .fnstart directive"));
3719 return;
3720 }
3721
3722 /* Mark the start of the function. */
3723 unwind.proc_start = expr_build_dot ();
3724
3725 /* Reset the rest of the unwind info. */
3726 unwind.opcode_count = 0;
3727 unwind.table_entry = NULL;
3728 unwind.personality_routine = NULL;
3729 unwind.personality_index = -1;
3730 unwind.frame_size = 0;
3731 unwind.fp_offset = 0;
3732 unwind.fp_reg = REG_SP;
3733 unwind.fp_used = 0;
3734 unwind.sp_restored = 0;
3735 }
3736
3737
3738 /* Parse a handlerdata directive. Creates the exception handling table entry
3739 for the function. */
3740
3741 static void
3742 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3743 {
3744 demand_empty_rest_of_line ();
3745 if (!unwind.proc_start)
3746 as_bad (MISSING_FNSTART);
3747
3748 if (unwind.table_entry)
3749 as_bad (_("duplicate .handlerdata directive"));
3750
3751 create_unwind_entry (1);
3752 }
3753
3754 /* Parse an unwind_fnend directive. Generates the index table entry. */
3755
3756 static void
3757 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3758 {
3759 long where;
3760 char *ptr;
3761 valueT val;
3762 unsigned int marked_pr_dependency;
3763
3764 demand_empty_rest_of_line ();
3765
3766 if (!unwind.proc_start)
3767 {
3768 as_bad (_(".fnend directive without .fnstart"));
3769 return;
3770 }
3771
3772 /* Add eh table entry. */
3773 if (unwind.table_entry == NULL)
3774 val = create_unwind_entry (0);
3775 else
3776 val = 0;
3777
3778 /* Add index table entry. This is two words. */
3779 start_unwind_section (unwind.saved_seg, 1);
3780 frag_align (2, 0, 0);
3781 record_alignment (now_seg, 2);
3782
3783 ptr = frag_more (8);
3784 memset (ptr, 0, 8);
3785 where = frag_now_fix () - 8;
3786
3787 /* Self relative offset of the function start. */
3788 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3789 BFD_RELOC_ARM_PREL31);
3790
3791 /* Indicate dependency on EHABI-defined personality routines to the
3792 linker, if it hasn't been done already. */
3793 marked_pr_dependency
3794 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
3795 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3796 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3797 {
3798 static const char *const name[] =
3799 {
3800 "__aeabi_unwind_cpp_pr0",
3801 "__aeabi_unwind_cpp_pr1",
3802 "__aeabi_unwind_cpp_pr2"
3803 };
3804 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3805 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3806 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3807 |= 1 << unwind.personality_index;
3808 }
3809
3810 if (val)
3811 /* Inline exception table entry. */
3812 md_number_to_chars (ptr + 4, val, 4);
3813 else
3814 /* Self relative offset of the table entry. */
3815 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3816 BFD_RELOC_ARM_PREL31);
3817
3818 /* Restore the original section. */
3819 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3820
3821 unwind.proc_start = NULL;
3822 }
3823
3824
3825 /* Parse an unwind_cantunwind directive. */
3826
3827 static void
3828 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3829 {
3830 demand_empty_rest_of_line ();
3831 if (!unwind.proc_start)
3832 as_bad (MISSING_FNSTART);
3833
3834 if (unwind.personality_routine || unwind.personality_index != -1)
3835 as_bad (_("personality routine specified for cantunwind frame"));
3836
3837 unwind.personality_index = -2;
3838 }
3839
3840
3841 /* Parse a personalityindex directive. */
3842
3843 static void
3844 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3845 {
3846 expressionS exp;
3847
3848 if (!unwind.proc_start)
3849 as_bad (MISSING_FNSTART);
3850
3851 if (unwind.personality_routine || unwind.personality_index != -1)
3852 as_bad (_("duplicate .personalityindex directive"));
3853
3854 expression (&exp);
3855
3856 if (exp.X_op != O_constant
3857 || exp.X_add_number < 0 || exp.X_add_number > 15)
3858 {
3859 as_bad (_("bad personality routine number"));
3860 ignore_rest_of_line ();
3861 return;
3862 }
3863
3864 unwind.personality_index = exp.X_add_number;
3865
3866 demand_empty_rest_of_line ();
3867 }
3868
3869
3870 /* Parse a personality directive. */
3871
3872 static void
3873 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3874 {
3875 char *name, *p, c;
3876
3877 if (!unwind.proc_start)
3878 as_bad (MISSING_FNSTART);
3879
3880 if (unwind.personality_routine || unwind.personality_index != -1)
3881 as_bad (_("duplicate .personality directive"));
3882
3883 name = input_line_pointer;
3884 c = get_symbol_end ();
3885 p = input_line_pointer;
3886 unwind.personality_routine = symbol_find_or_make (name);
3887 *p = c;
3888 demand_empty_rest_of_line ();
3889 }
3890
3891
3892 /* Parse a directive saving core registers. */
3893
3894 static void
3895 s_arm_unwind_save_core (void)
3896 {
3897 valueT op;
3898 long range;
3899 int n;
3900
3901 range = parse_reg_list (&input_line_pointer);
3902 if (range == FAIL)
3903 {
3904 as_bad (_("expected register list"));
3905 ignore_rest_of_line ();
3906 return;
3907 }
3908
3909 demand_empty_rest_of_line ();
3910
3911 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3912 into .unwind_save {..., sp...}. We aren't bothered about the value of
3913 ip because it is clobbered by calls. */
3914 if (unwind.sp_restored && unwind.fp_reg == 12
3915 && (range & 0x3000) == 0x1000)
3916 {
3917 unwind.opcode_count--;
3918 unwind.sp_restored = 0;
3919 range = (range | 0x2000) & ~0x1000;
3920 unwind.pending_offset = 0;
3921 }
3922
3923 /* Pop r4-r15. */
3924 if (range & 0xfff0)
3925 {
3926 /* See if we can use the short opcodes. These pop a block of up to 8
3927 registers starting with r4, plus maybe r14. */
3928 for (n = 0; n < 8; n++)
3929 {
3930 /* Break at the first non-saved register. */
3931 if ((range & (1 << (n + 4))) == 0)
3932 break;
3933 }
3934 /* See if there are any other bits set. */
3935 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3936 {
3937 /* Use the long form. */
3938 op = 0x8000 | ((range >> 4) & 0xfff);
3939 add_unwind_opcode (op, 2);
3940 }
3941 else
3942 {
3943 /* Use the short form. */
3944 if (range & 0x4000)
3945 op = 0xa8; /* Pop r14. */
3946 else
3947 op = 0xa0; /* Do not pop r14. */
3948 op |= (n - 1);
3949 add_unwind_opcode (op, 1);
3950 }
3951 }
3952
3953 /* Pop r0-r3. */
3954 if (range & 0xf)
3955 {
3956 op = 0xb100 | (range & 0xf);
3957 add_unwind_opcode (op, 2);
3958 }
3959
3960 /* Record the number of bytes pushed. */
3961 for (n = 0; n < 16; n++)
3962 {
3963 if (range & (1 << n))
3964 unwind.frame_size += 4;
3965 }
3966 }
3967
3968
3969 /* Parse a directive saving FPA registers. */
3970
3971 static void
3972 s_arm_unwind_save_fpa (int reg)
3973 {
3974 expressionS exp;
3975 int num_regs;
3976 valueT op;
3977
3978 /* Get Number of registers to transfer. */
3979 if (skip_past_comma (&input_line_pointer) != FAIL)
3980 expression (&exp);
3981 else
3982 exp.X_op = O_illegal;
3983
3984 if (exp.X_op != O_constant)
3985 {
3986 as_bad (_("expected , <constant>"));
3987 ignore_rest_of_line ();
3988 return;
3989 }
3990
3991 num_regs = exp.X_add_number;
3992
3993 if (num_regs < 1 || num_regs > 4)
3994 {
3995 as_bad (_("number of registers must be in the range [1:4]"));
3996 ignore_rest_of_line ();
3997 return;
3998 }
3999
4000 demand_empty_rest_of_line ();
4001
4002 if (reg == 4)
4003 {
4004 /* Short form. */
4005 op = 0xb4 | (num_regs - 1);
4006 add_unwind_opcode (op, 1);
4007 }
4008 else
4009 {
4010 /* Long form. */
4011 op = 0xc800 | (reg << 4) | (num_regs - 1);
4012 add_unwind_opcode (op, 2);
4013 }
4014 unwind.frame_size += num_regs * 12;
4015 }
4016
4017
4018 /* Parse a directive saving VFP registers for ARMv6 and above. */
4019
4020 static void
4021 s_arm_unwind_save_vfp_armv6 (void)
4022 {
4023 int count;
4024 unsigned int start;
4025 valueT op;
4026 int num_vfpv3_regs = 0;
4027 int num_regs_below_16;
4028
4029 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
4030 if (count == FAIL)
4031 {
4032 as_bad (_("expected register list"));
4033 ignore_rest_of_line ();
4034 return;
4035 }
4036
4037 demand_empty_rest_of_line ();
4038
4039 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4040 than FSTMX/FLDMX-style ones). */
4041
4042 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4043 if (start >= 16)
4044 num_vfpv3_regs = count;
4045 else if (start + count > 16)
4046 num_vfpv3_regs = start + count - 16;
4047
4048 if (num_vfpv3_regs > 0)
4049 {
4050 int start_offset = start > 16 ? start - 16 : 0;
4051 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4052 add_unwind_opcode (op, 2);
4053 }
4054
4055 /* Generate opcode for registers numbered in the range 0 .. 15. */
4056 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
4057 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
4058 if (num_regs_below_16 > 0)
4059 {
4060 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4061 add_unwind_opcode (op, 2);
4062 }
4063
4064 unwind.frame_size += count * 8;
4065 }
4066
4067
4068 /* Parse a directive saving VFP registers for pre-ARMv6. */
4069
4070 static void
4071 s_arm_unwind_save_vfp (void)
4072 {
4073 int count;
4074 unsigned int reg;
4075 valueT op;
4076
4077 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
4078 if (count == FAIL)
4079 {
4080 as_bad (_("expected register list"));
4081 ignore_rest_of_line ();
4082 return;
4083 }
4084
4085 demand_empty_rest_of_line ();
4086
4087 if (reg == 8)
4088 {
4089 /* Short form. */
4090 op = 0xb8 | (count - 1);
4091 add_unwind_opcode (op, 1);
4092 }
4093 else
4094 {
4095 /* Long form. */
4096 op = 0xb300 | (reg << 4) | (count - 1);
4097 add_unwind_opcode (op, 2);
4098 }
4099 unwind.frame_size += count * 8 + 4;
4100 }
4101
4102
4103 /* Parse a directive saving iWMMXt data registers. */
4104
4105 static void
4106 s_arm_unwind_save_mmxwr (void)
4107 {
4108 int reg;
4109 int hi_reg;
4110 int i;
4111 unsigned mask = 0;
4112 valueT op;
4113
4114 if (*input_line_pointer == '{')
4115 input_line_pointer++;
4116
4117 do
4118 {
4119 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
4120
4121 if (reg == FAIL)
4122 {
4123 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
4124 goto error;
4125 }
4126
4127 if (mask >> reg)
4128 as_tsktsk (_("register list not in ascending order"));
4129 mask |= 1 << reg;
4130
4131 if (*input_line_pointer == '-')
4132 {
4133 input_line_pointer++;
4134 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
4135 if (hi_reg == FAIL)
4136 {
4137 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
4138 goto error;
4139 }
4140 else if (reg >= hi_reg)
4141 {
4142 as_bad (_("bad register range"));
4143 goto error;
4144 }
4145 for (; reg < hi_reg; reg++)
4146 mask |= 1 << reg;
4147 }
4148 }
4149 while (skip_past_comma (&input_line_pointer) != FAIL);
4150
4151 skip_past_char (&input_line_pointer, '}');
4152
4153 demand_empty_rest_of_line ();
4154
4155 /* Generate any deferred opcodes because we're going to be looking at
4156 the list. */
4157 flush_pending_unwind ();
4158
4159 for (i = 0; i < 16; i++)
4160 {
4161 if (mask & (1 << i))
4162 unwind.frame_size += 8;
4163 }
4164
4165 /* Attempt to combine with a previous opcode. We do this because gcc
4166 likes to output separate unwind directives for a single block of
4167 registers. */
4168 if (unwind.opcode_count > 0)
4169 {
4170 i = unwind.opcodes[unwind.opcode_count - 1];
4171 if ((i & 0xf8) == 0xc0)
4172 {
4173 i &= 7;
4174 /* Only merge if the blocks are contiguous. */
4175 if (i < 6)
4176 {
4177 if ((mask & 0xfe00) == (1 << 9))
4178 {
4179 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4180 unwind.opcode_count--;
4181 }
4182 }
4183 else if (i == 6 && unwind.opcode_count >= 2)
4184 {
4185 i = unwind.opcodes[unwind.opcode_count - 2];
4186 reg = i >> 4;
4187 i &= 0xf;
4188
4189 op = 0xffff << (reg - 1);
4190 if (reg > 0
4191 && ((mask & op) == (1u << (reg - 1))))
4192 {
4193 op = (1 << (reg + i + 1)) - 1;
4194 op &= ~((1 << reg) - 1);
4195 mask |= op;
4196 unwind.opcode_count -= 2;
4197 }
4198 }
4199 }
4200 }
4201
4202 hi_reg = 15;
4203 /* We want to generate opcodes in the order the registers have been
4204 saved, ie. descending order. */
4205 for (reg = 15; reg >= -1; reg--)
4206 {
4207 /* Save registers in blocks. */
4208 if (reg < 0
4209 || !(mask & (1 << reg)))
4210 {
4211 /* We found an unsaved reg. Generate opcodes to save the
4212 preceding block. */
4213 if (reg != hi_reg)
4214 {
4215 if (reg == 9)
4216 {
4217 /* Short form. */
4218 op = 0xc0 | (hi_reg - 10);
4219 add_unwind_opcode (op, 1);
4220 }
4221 else
4222 {
4223 /* Long form. */
4224 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4225 add_unwind_opcode (op, 2);
4226 }
4227 }
4228 hi_reg = reg - 1;
4229 }
4230 }
4231
4232 return;
4233 error:
4234 ignore_rest_of_line ();
4235 }
4236
4237 static void
4238 s_arm_unwind_save_mmxwcg (void)
4239 {
4240 int reg;
4241 int hi_reg;
4242 unsigned mask = 0;
4243 valueT op;
4244
4245 if (*input_line_pointer == '{')
4246 input_line_pointer++;
4247
4248 skip_whitespace (input_line_pointer);
4249
4250 do
4251 {
4252 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4253
4254 if (reg == FAIL)
4255 {
4256 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4257 goto error;
4258 }
4259
4260 reg -= 8;
4261 if (mask >> reg)
4262 as_tsktsk (_("register list not in ascending order"));
4263 mask |= 1 << reg;
4264
4265 if (*input_line_pointer == '-')
4266 {
4267 input_line_pointer++;
4268 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4269 if (hi_reg == FAIL)
4270 {
4271 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4272 goto error;
4273 }
4274 else if (reg >= hi_reg)
4275 {
4276 as_bad (_("bad register range"));
4277 goto error;
4278 }
4279 for (; reg < hi_reg; reg++)
4280 mask |= 1 << reg;
4281 }
4282 }
4283 while (skip_past_comma (&input_line_pointer) != FAIL);
4284
4285 skip_past_char (&input_line_pointer, '}');
4286
4287 demand_empty_rest_of_line ();
4288
4289 /* Generate any deferred opcodes because we're going to be looking at
4290 the list. */
4291 flush_pending_unwind ();
4292
4293 for (reg = 0; reg < 16; reg++)
4294 {
4295 if (mask & (1 << reg))
4296 unwind.frame_size += 4;
4297 }
4298 op = 0xc700 | mask;
4299 add_unwind_opcode (op, 2);
4300 return;
4301 error:
4302 ignore_rest_of_line ();
4303 }
4304
4305
4306 /* Parse an unwind_save directive.
4307 If the argument is non-zero, this is a .vsave directive. */
4308
4309 static void
4310 s_arm_unwind_save (int arch_v6)
4311 {
4312 char *peek;
4313 struct reg_entry *reg;
4314 bfd_boolean had_brace = FALSE;
4315
4316 if (!unwind.proc_start)
4317 as_bad (MISSING_FNSTART);
4318
4319 /* Figure out what sort of save we have. */
4320 peek = input_line_pointer;
4321
4322 if (*peek == '{')
4323 {
4324 had_brace = TRUE;
4325 peek++;
4326 }
4327
4328 reg = arm_reg_parse_multi (&peek);
4329
4330 if (!reg)
4331 {
4332 as_bad (_("register expected"));
4333 ignore_rest_of_line ();
4334 return;
4335 }
4336
4337 switch (reg->type)
4338 {
4339 case REG_TYPE_FN:
4340 if (had_brace)
4341 {
4342 as_bad (_("FPA .unwind_save does not take a register list"));
4343 ignore_rest_of_line ();
4344 return;
4345 }
4346 input_line_pointer = peek;
4347 s_arm_unwind_save_fpa (reg->number);
4348 return;
4349
4350 case REG_TYPE_RN:
4351 s_arm_unwind_save_core ();
4352 return;
4353
4354 case REG_TYPE_VFD:
4355 if (arch_v6)
4356 s_arm_unwind_save_vfp_armv6 ();
4357 else
4358 s_arm_unwind_save_vfp ();
4359 return;
4360
4361 case REG_TYPE_MMXWR:
4362 s_arm_unwind_save_mmxwr ();
4363 return;
4364
4365 case REG_TYPE_MMXWCG:
4366 s_arm_unwind_save_mmxwcg ();
4367 return;
4368
4369 default:
4370 as_bad (_(".unwind_save does not support this kind of register"));
4371 ignore_rest_of_line ();
4372 }
4373 }
4374
4375
4376 /* Parse an unwind_movsp directive. */
4377
4378 static void
4379 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4380 {
4381 int reg;
4382 valueT op;
4383 int offset;
4384
4385 if (!unwind.proc_start)
4386 as_bad (MISSING_FNSTART);
4387
4388 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4389 if (reg == FAIL)
4390 {
4391 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
4392 ignore_rest_of_line ();
4393 return;
4394 }
4395
4396 /* Optional constant. */
4397 if (skip_past_comma (&input_line_pointer) != FAIL)
4398 {
4399 if (immediate_for_directive (&offset) == FAIL)
4400 return;
4401 }
4402 else
4403 offset = 0;
4404
4405 demand_empty_rest_of_line ();
4406
4407 if (reg == REG_SP || reg == REG_PC)
4408 {
4409 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
4410 return;
4411 }
4412
4413 if (unwind.fp_reg != REG_SP)
4414 as_bad (_("unexpected .unwind_movsp directive"));
4415
4416 /* Generate opcode to restore the value. */
4417 op = 0x90 | reg;
4418 add_unwind_opcode (op, 1);
4419
4420 /* Record the information for later. */
4421 unwind.fp_reg = reg;
4422 unwind.fp_offset = unwind.frame_size - offset;
4423 unwind.sp_restored = 1;
4424 }
4425
4426 /* Parse an unwind_pad directive. */
4427
4428 static void
4429 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
4430 {
4431 int offset;
4432
4433 if (!unwind.proc_start)
4434 as_bad (MISSING_FNSTART);
4435
4436 if (immediate_for_directive (&offset) == FAIL)
4437 return;
4438
4439 if (offset & 3)
4440 {
4441 as_bad (_("stack increment must be multiple of 4"));
4442 ignore_rest_of_line ();
4443 return;
4444 }
4445
4446 /* Don't generate any opcodes, just record the details for later. */
4447 unwind.frame_size += offset;
4448 unwind.pending_offset += offset;
4449
4450 demand_empty_rest_of_line ();
4451 }
4452
4453 /* Parse an unwind_setfp directive. */
4454
4455 static void
4456 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
4457 {
4458 int sp_reg;
4459 int fp_reg;
4460 int offset;
4461
4462 if (!unwind.proc_start)
4463 as_bad (MISSING_FNSTART);
4464
4465 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4466 if (skip_past_comma (&input_line_pointer) == FAIL)
4467 sp_reg = FAIL;
4468 else
4469 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4470
4471 if (fp_reg == FAIL || sp_reg == FAIL)
4472 {
4473 as_bad (_("expected <reg>, <reg>"));
4474 ignore_rest_of_line ();
4475 return;
4476 }
4477
4478 /* Optional constant. */
4479 if (skip_past_comma (&input_line_pointer) != FAIL)
4480 {
4481 if (immediate_for_directive (&offset) == FAIL)
4482 return;
4483 }
4484 else
4485 offset = 0;
4486
4487 demand_empty_rest_of_line ();
4488
4489 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
4490 {
4491 as_bad (_("register must be either sp or set by a previous"
4492 "unwind_movsp directive"));
4493 return;
4494 }
4495
4496 /* Don't generate any opcodes, just record the information for later. */
4497 unwind.fp_reg = fp_reg;
4498 unwind.fp_used = 1;
4499 if (sp_reg == REG_SP)
4500 unwind.fp_offset = unwind.frame_size - offset;
4501 else
4502 unwind.fp_offset -= offset;
4503 }
4504
4505 /* Parse an unwind_raw directive. */
4506
4507 static void
4508 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
4509 {
4510 expressionS exp;
4511 /* This is an arbitrary limit. */
4512 unsigned char op[16];
4513 int count;
4514
4515 if (!unwind.proc_start)
4516 as_bad (MISSING_FNSTART);
4517
4518 expression (&exp);
4519 if (exp.X_op == O_constant
4520 && skip_past_comma (&input_line_pointer) != FAIL)
4521 {
4522 unwind.frame_size += exp.X_add_number;
4523 expression (&exp);
4524 }
4525 else
4526 exp.X_op = O_illegal;
4527
4528 if (exp.X_op != O_constant)
4529 {
4530 as_bad (_("expected <offset>, <opcode>"));
4531 ignore_rest_of_line ();
4532 return;
4533 }
4534
4535 count = 0;
4536
4537 /* Parse the opcode. */
4538 for (;;)
4539 {
4540 if (count >= 16)
4541 {
4542 as_bad (_("unwind opcode too long"));
4543 ignore_rest_of_line ();
4544 }
4545 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
4546 {
4547 as_bad (_("invalid unwind opcode"));
4548 ignore_rest_of_line ();
4549 return;
4550 }
4551 op[count++] = exp.X_add_number;
4552
4553 /* Parse the next byte. */
4554 if (skip_past_comma (&input_line_pointer) == FAIL)
4555 break;
4556
4557 expression (&exp);
4558 }
4559
4560 /* Add the opcode bytes in reverse order. */
4561 while (count--)
4562 add_unwind_opcode (op[count], 1);
4563
4564 demand_empty_rest_of_line ();
4565 }
4566
4567
4568 /* Parse a .eabi_attribute directive. */
4569
4570 static void
4571 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4572 {
4573 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
4574
4575 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4576 attributes_set_explicitly[tag] = 1;
4577 }
4578
4579 /* Emit a tls fix for the symbol. */
4580
4581 static void
4582 s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4583 {
4584 char *p;
4585 expressionS exp;
4586 #ifdef md_flush_pending_output
4587 md_flush_pending_output ();
4588 #endif
4589
4590 #ifdef md_cons_align
4591 md_cons_align (4);
4592 #endif
4593
4594 /* Since we're just labelling the code, there's no need to define a
4595 mapping symbol. */
4596 expression (&exp);
4597 p = obstack_next_free (&frchain_now->frch_obstack);
4598 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4599 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4600 : BFD_RELOC_ARM_TLS_DESCSEQ);
4601 }
4602 #endif /* OBJ_ELF */
4603
4604 static void s_arm_arch (int);
4605 static void s_arm_object_arch (int);
4606 static void s_arm_cpu (int);
4607 static void s_arm_fpu (int);
4608 static void s_arm_arch_extension (int);
4609
4610 #ifdef TE_PE
4611
4612 static void
4613 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
4614 {
4615 expressionS exp;
4616
4617 do
4618 {
4619 expression (&exp);
4620 if (exp.X_op == O_symbol)
4621 exp.X_op = O_secrel;
4622
4623 emit_expr (&exp, 4);
4624 }
4625 while (*input_line_pointer++ == ',');
4626
4627 input_line_pointer--;
4628 demand_empty_rest_of_line ();
4629 }
4630 #endif /* TE_PE */
4631
4632 /* This table describes all the machine specific pseudo-ops the assembler
4633 has to support. The fields are:
4634 pseudo-op name without dot
4635 function to call to execute this pseudo-op
4636 Integer arg to pass to the function. */
4637
4638 const pseudo_typeS md_pseudo_table[] =
4639 {
4640 /* Never called because '.req' does not start a line. */
4641 { "req", s_req, 0 },
4642 /* Following two are likewise never called. */
4643 { "dn", s_dn, 0 },
4644 { "qn", s_qn, 0 },
4645 { "unreq", s_unreq, 0 },
4646 { "bss", s_bss, 0 },
4647 { "align", s_align_ptwo, 2 },
4648 { "arm", s_arm, 0 },
4649 { "thumb", s_thumb, 0 },
4650 { "code", s_code, 0 },
4651 { "force_thumb", s_force_thumb, 0 },
4652 { "thumb_func", s_thumb_func, 0 },
4653 { "thumb_set", s_thumb_set, 0 },
4654 { "even", s_even, 0 },
4655 { "ltorg", s_ltorg, 0 },
4656 { "pool", s_ltorg, 0 },
4657 { "syntax", s_syntax, 0 },
4658 { "cpu", s_arm_cpu, 0 },
4659 { "arch", s_arm_arch, 0 },
4660 { "object_arch", s_arm_object_arch, 0 },
4661 { "fpu", s_arm_fpu, 0 },
4662 { "arch_extension", s_arm_arch_extension, 0 },
4663 #ifdef OBJ_ELF
4664 { "word", s_arm_elf_cons, 4 },
4665 { "long", s_arm_elf_cons, 4 },
4666 { "inst.n", s_arm_elf_inst, 2 },
4667 { "inst.w", s_arm_elf_inst, 4 },
4668 { "inst", s_arm_elf_inst, 0 },
4669 { "rel31", s_arm_rel31, 0 },
4670 { "fnstart", s_arm_unwind_fnstart, 0 },
4671 { "fnend", s_arm_unwind_fnend, 0 },
4672 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4673 { "personality", s_arm_unwind_personality, 0 },
4674 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4675 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4676 { "save", s_arm_unwind_save, 0 },
4677 { "vsave", s_arm_unwind_save, 1 },
4678 { "movsp", s_arm_unwind_movsp, 0 },
4679 { "pad", s_arm_unwind_pad, 0 },
4680 { "setfp", s_arm_unwind_setfp, 0 },
4681 { "unwind_raw", s_arm_unwind_raw, 0 },
4682 { "eabi_attribute", s_arm_eabi_attribute, 0 },
4683 { "tlsdescseq", s_arm_tls_descseq, 0 },
4684 #else
4685 { "word", cons, 4},
4686
4687 /* These are used for dwarf. */
4688 {"2byte", cons, 2},
4689 {"4byte", cons, 4},
4690 {"8byte", cons, 8},
4691 /* These are used for dwarf2. */
4692 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4693 { "loc", dwarf2_directive_loc, 0 },
4694 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
4695 #endif
4696 { "extend", float_cons, 'x' },
4697 { "ldouble", float_cons, 'x' },
4698 { "packed", float_cons, 'p' },
4699 #ifdef TE_PE
4700 {"secrel32", pe_directive_secrel, 0},
4701 #endif
4702
4703 /* These are for compatibility with CodeComposer Studio. */
4704 {"ref", s_ccs_ref, 0},
4705 {"def", s_ccs_def, 0},
4706 {"asmfunc", s_ccs_asmfunc, 0},
4707 {"endasmfunc", s_ccs_endasmfunc, 0},
4708
4709 { 0, 0, 0 }
4710 };
4711 \f
4712 /* Parser functions used exclusively in instruction operands. */
4713
4714 /* Generic immediate-value read function for use in insn parsing.
4715 STR points to the beginning of the immediate (the leading #);
4716 VAL receives the value; if the value is outside [MIN, MAX]
4717 issue an error. PREFIX_OPT is true if the immediate prefix is
4718 optional. */
4719
4720 static int
4721 parse_immediate (char **str, int *val, int min, int max,
4722 bfd_boolean prefix_opt)
4723 {
4724 expressionS exp;
4725 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4726 if (exp.X_op != O_constant)
4727 {
4728 inst.error = _("constant expression required");
4729 return FAIL;
4730 }
4731
4732 if (exp.X_add_number < min || exp.X_add_number > max)
4733 {
4734 inst.error = _("immediate value out of range");
4735 return FAIL;
4736 }
4737
4738 *val = exp.X_add_number;
4739 return SUCCESS;
4740 }
4741
4742 /* Less-generic immediate-value read function with the possibility of loading a
4743 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
4744 instructions. Puts the result directly in inst.operands[i]. */
4745
4746 static int
4747 parse_big_immediate (char **str, int i, expressionS *in_exp,
4748 bfd_boolean allow_symbol_p)
4749 {
4750 expressionS exp;
4751 expressionS *exp_p = in_exp ? in_exp : &exp;
4752 char *ptr = *str;
4753
4754 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
4755
4756 if (exp_p->X_op == O_constant)
4757 {
4758 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
4759 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4760 O_constant. We have to be careful not to break compilation for
4761 32-bit X_add_number, though. */
4762 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
4763 {
4764 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
4765 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
4766 & 0xffffffff);
4767 inst.operands[i].regisimm = 1;
4768 }
4769 }
4770 else if (exp_p->X_op == O_big
4771 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
4772 {
4773 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4774
4775 /* Bignums have their least significant bits in
4776 generic_bignum[0]. Make sure we put 32 bits in imm and
4777 32 bits in reg, in a (hopefully) portable way. */
4778 gas_assert (parts != 0);
4779
4780 /* Make sure that the number is not too big.
4781 PR 11972: Bignums can now be sign-extended to the
4782 size of a .octa so check that the out of range bits
4783 are all zero or all one. */
4784 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
4785 {
4786 LITTLENUM_TYPE m = -1;
4787
4788 if (generic_bignum[parts * 2] != 0
4789 && generic_bignum[parts * 2] != m)
4790 return FAIL;
4791
4792 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
4793 if (generic_bignum[j] != generic_bignum[j-1])
4794 return FAIL;
4795 }
4796
4797 inst.operands[i].imm = 0;
4798 for (j = 0; j < parts; j++, idx++)
4799 inst.operands[i].imm |= generic_bignum[idx]
4800 << (LITTLENUM_NUMBER_OF_BITS * j);
4801 inst.operands[i].reg = 0;
4802 for (j = 0; j < parts; j++, idx++)
4803 inst.operands[i].reg |= generic_bignum[idx]
4804 << (LITTLENUM_NUMBER_OF_BITS * j);
4805 inst.operands[i].regisimm = 1;
4806 }
4807 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
4808 return FAIL;
4809
4810 *str = ptr;
4811
4812 return SUCCESS;
4813 }
4814
4815 /* Returns the pseudo-register number of an FPA immediate constant,
4816 or FAIL if there isn't a valid constant here. */
4817
4818 static int
4819 parse_fpa_immediate (char ** str)
4820 {
4821 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4822 char * save_in;
4823 expressionS exp;
4824 int i;
4825 int j;
4826
4827 /* First try and match exact strings, this is to guarantee
4828 that some formats will work even for cross assembly. */
4829
4830 for (i = 0; fp_const[i]; i++)
4831 {
4832 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4833 {
4834 char *start = *str;
4835
4836 *str += strlen (fp_const[i]);
4837 if (is_end_of_line[(unsigned char) **str])
4838 return i + 8;
4839 *str = start;
4840 }
4841 }
4842
4843 /* Just because we didn't get a match doesn't mean that the constant
4844 isn't valid, just that it is in a format that we don't
4845 automatically recognize. Try parsing it with the standard
4846 expression routines. */
4847
4848 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
4849
4850 /* Look for a raw floating point number. */
4851 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4852 && is_end_of_line[(unsigned char) *save_in])
4853 {
4854 for (i = 0; i < NUM_FLOAT_VALS; i++)
4855 {
4856 for (j = 0; j < MAX_LITTLENUMS; j++)
4857 {
4858 if (words[j] != fp_values[i][j])
4859 break;
4860 }
4861
4862 if (j == MAX_LITTLENUMS)
4863 {
4864 *str = save_in;
4865 return i + 8;
4866 }
4867 }
4868 }
4869
4870 /* Try and parse a more complex expression, this will probably fail
4871 unless the code uses a floating point prefix (eg "0f"). */
4872 save_in = input_line_pointer;
4873 input_line_pointer = *str;
4874 if (expression (&exp) == absolute_section
4875 && exp.X_op == O_big
4876 && exp.X_add_number < 0)
4877 {
4878 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4879 Ditto for 15. */
4880 #define X_PRECISION 5
4881 #define E_PRECISION 15L
4882 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
4883 {
4884 for (i = 0; i < NUM_FLOAT_VALS; i++)
4885 {
4886 for (j = 0; j < MAX_LITTLENUMS; j++)
4887 {
4888 if (words[j] != fp_values[i][j])
4889 break;
4890 }
4891
4892 if (j == MAX_LITTLENUMS)
4893 {
4894 *str = input_line_pointer;
4895 input_line_pointer = save_in;
4896 return i + 8;
4897 }
4898 }
4899 }
4900 }
4901
4902 *str = input_line_pointer;
4903 input_line_pointer = save_in;
4904 inst.error = _("invalid FPA immediate expression");
4905 return FAIL;
4906 }
4907
4908 /* Returns 1 if a number has "quarter-precision" float format
4909 0baBbbbbbc defgh000 00000000 00000000. */
4910
4911 static int
4912 is_quarter_float (unsigned imm)
4913 {
4914 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4915 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4916 }
4917
4918
4919 /* Detect the presence of a floating point or integer zero constant,
4920 i.e. #0.0 or #0. */
4921
4922 static bfd_boolean
4923 parse_ifimm_zero (char **in)
4924 {
4925 int error_code;
4926
4927 if (!is_immediate_prefix (**in))
4928 return FALSE;
4929
4930 ++*in;
4931
4932 /* Accept #0x0 as a synonym for #0. */
4933 if (strncmp (*in, "0x", 2) == 0)
4934 {
4935 int val;
4936 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
4937 return FALSE;
4938 return TRUE;
4939 }
4940
4941 error_code = atof_generic (in, ".", EXP_CHARS,
4942 &generic_floating_point_number);
4943
4944 if (!error_code
4945 && generic_floating_point_number.sign == '+'
4946 && (generic_floating_point_number.low
4947 > generic_floating_point_number.leader))
4948 return TRUE;
4949
4950 return FALSE;
4951 }
4952
4953 /* Parse an 8-bit "quarter-precision" floating point number of the form:
4954 0baBbbbbbc defgh000 00000000 00000000.
4955 The zero and minus-zero cases need special handling, since they can't be
4956 encoded in the "quarter-precision" float format, but can nonetheless be
4957 loaded as integer constants. */
4958
4959 static unsigned
4960 parse_qfloat_immediate (char **ccp, int *immed)
4961 {
4962 char *str = *ccp;
4963 char *fpnum;
4964 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4965 int found_fpchar = 0;
4966
4967 skip_past_char (&str, '#');
4968
4969 /* We must not accidentally parse an integer as a floating-point number. Make
4970 sure that the value we parse is not an integer by checking for special
4971 characters '.' or 'e'.
4972 FIXME: This is a horrible hack, but doing better is tricky because type
4973 information isn't in a very usable state at parse time. */
4974 fpnum = str;
4975 skip_whitespace (fpnum);
4976
4977 if (strncmp (fpnum, "0x", 2) == 0)
4978 return FAIL;
4979 else
4980 {
4981 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4982 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4983 {
4984 found_fpchar = 1;
4985 break;
4986 }
4987
4988 if (!found_fpchar)
4989 return FAIL;
4990 }
4991
4992 if ((str = atof_ieee (str, 's', words)) != NULL)
4993 {
4994 unsigned fpword = 0;
4995 int i;
4996
4997 /* Our FP word must be 32 bits (single-precision FP). */
4998 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4999 {
5000 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5001 fpword |= words[i];
5002 }
5003
5004 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
5005 *immed = fpword;
5006 else
5007 return FAIL;
5008
5009 *ccp = str;
5010
5011 return SUCCESS;
5012 }
5013
5014 return FAIL;
5015 }
5016
5017 /* Shift operands. */
5018 enum shift_kind
5019 {
5020 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
5021 };
5022
5023 struct asm_shift_name
5024 {
5025 const char *name;
5026 enum shift_kind kind;
5027 };
5028
5029 /* Third argument to parse_shift. */
5030 enum parse_shift_mode
5031 {
5032 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5033 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5034 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5035 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5036 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5037 };
5038
5039 /* Parse a <shift> specifier on an ARM data processing instruction.
5040 This has three forms:
5041
5042 (LSL|LSR|ASL|ASR|ROR) Rs
5043 (LSL|LSR|ASL|ASR|ROR) #imm
5044 RRX
5045
5046 Note that ASL is assimilated to LSL in the instruction encoding, and
5047 RRX to ROR #0 (which cannot be written as such). */
5048
5049 static int
5050 parse_shift (char **str, int i, enum parse_shift_mode mode)
5051 {
5052 const struct asm_shift_name *shift_name;
5053 enum shift_kind shift;
5054 char *s = *str;
5055 char *p = s;
5056 int reg;
5057
5058 for (p = *str; ISALPHA (*p); p++)
5059 ;
5060
5061 if (p == *str)
5062 {
5063 inst.error = _("shift expression expected");
5064 return FAIL;
5065 }
5066
5067 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
5068 p - *str);
5069
5070 if (shift_name == NULL)
5071 {
5072 inst.error = _("shift expression expected");
5073 return FAIL;
5074 }
5075
5076 shift = shift_name->kind;
5077
5078 switch (mode)
5079 {
5080 case NO_SHIFT_RESTRICT:
5081 case SHIFT_IMMEDIATE: break;
5082
5083 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5084 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5085 {
5086 inst.error = _("'LSL' or 'ASR' required");
5087 return FAIL;
5088 }
5089 break;
5090
5091 case SHIFT_LSL_IMMEDIATE:
5092 if (shift != SHIFT_LSL)
5093 {
5094 inst.error = _("'LSL' required");
5095 return FAIL;
5096 }
5097 break;
5098
5099 case SHIFT_ASR_IMMEDIATE:
5100 if (shift != SHIFT_ASR)
5101 {
5102 inst.error = _("'ASR' required");
5103 return FAIL;
5104 }
5105 break;
5106
5107 default: abort ();
5108 }
5109
5110 if (shift != SHIFT_RRX)
5111 {
5112 /* Whitespace can appear here if the next thing is a bare digit. */
5113 skip_whitespace (p);
5114
5115 if (mode == NO_SHIFT_RESTRICT
5116 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5117 {
5118 inst.operands[i].imm = reg;
5119 inst.operands[i].immisreg = 1;
5120 }
5121 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5122 return FAIL;
5123 }
5124 inst.operands[i].shift_kind = shift;
5125 inst.operands[i].shifted = 1;
5126 *str = p;
5127 return SUCCESS;
5128 }
5129
5130 /* Parse a <shifter_operand> for an ARM data processing instruction:
5131
5132 #<immediate>
5133 #<immediate>, <rotate>
5134 <Rm>
5135 <Rm>, <shift>
5136
5137 where <shift> is defined by parse_shift above, and <rotate> is a
5138 multiple of 2 between 0 and 30. Validation of immediate operands
5139 is deferred to md_apply_fix. */
5140
5141 static int
5142 parse_shifter_operand (char **str, int i)
5143 {
5144 int value;
5145 expressionS exp;
5146
5147 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
5148 {
5149 inst.operands[i].reg = value;
5150 inst.operands[i].isreg = 1;
5151
5152 /* parse_shift will override this if appropriate */
5153 inst.reloc.exp.X_op = O_constant;
5154 inst.reloc.exp.X_add_number = 0;
5155
5156 if (skip_past_comma (str) == FAIL)
5157 return SUCCESS;
5158
5159 /* Shift operation on register. */
5160 return parse_shift (str, i, NO_SHIFT_RESTRICT);
5161 }
5162
5163 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
5164 return FAIL;
5165
5166 if (skip_past_comma (str) == SUCCESS)
5167 {
5168 /* #x, y -- ie explicit rotation by Y. */
5169 if (my_get_expression (&exp, str, GE_NO_PREFIX))
5170 return FAIL;
5171
5172 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
5173 {
5174 inst.error = _("constant expression expected");
5175 return FAIL;
5176 }
5177
5178 value = exp.X_add_number;
5179 if (value < 0 || value > 30 || value % 2 != 0)
5180 {
5181 inst.error = _("invalid rotation");
5182 return FAIL;
5183 }
5184 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
5185 {
5186 inst.error = _("invalid constant");
5187 return FAIL;
5188 }
5189
5190 /* Encode as specified. */
5191 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
5192 return SUCCESS;
5193 }
5194
5195 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
5196 inst.reloc.pc_rel = 0;
5197 return SUCCESS;
5198 }
5199
5200 /* Group relocation information. Each entry in the table contains the
5201 textual name of the relocation as may appear in assembler source
5202 and must end with a colon.
5203 Along with this textual name are the relocation codes to be used if
5204 the corresponding instruction is an ALU instruction (ADD or SUB only),
5205 an LDR, an LDRS, or an LDC. */
5206
5207 struct group_reloc_table_entry
5208 {
5209 const char *name;
5210 int alu_code;
5211 int ldr_code;
5212 int ldrs_code;
5213 int ldc_code;
5214 };
5215
5216 typedef enum
5217 {
5218 /* Varieties of non-ALU group relocation. */
5219
5220 GROUP_LDR,
5221 GROUP_LDRS,
5222 GROUP_LDC
5223 } group_reloc_type;
5224
5225 static struct group_reloc_table_entry group_reloc_table[] =
5226 { /* Program counter relative: */
5227 { "pc_g0_nc",
5228 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5229 0, /* LDR */
5230 0, /* LDRS */
5231 0 }, /* LDC */
5232 { "pc_g0",
5233 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5234 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5235 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5236 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5237 { "pc_g1_nc",
5238 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5239 0, /* LDR */
5240 0, /* LDRS */
5241 0 }, /* LDC */
5242 { "pc_g1",
5243 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5244 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5245 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5246 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5247 { "pc_g2",
5248 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5249 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5250 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5251 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5252 /* Section base relative */
5253 { "sb_g0_nc",
5254 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5255 0, /* LDR */
5256 0, /* LDRS */
5257 0 }, /* LDC */
5258 { "sb_g0",
5259 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5260 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5261 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5262 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5263 { "sb_g1_nc",
5264 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5265 0, /* LDR */
5266 0, /* LDRS */
5267 0 }, /* LDC */
5268 { "sb_g1",
5269 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5270 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5271 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5272 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5273 { "sb_g2",
5274 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5275 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5276 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
5277 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
5278
5279 /* Given the address of a pointer pointing to the textual name of a group
5280 relocation as may appear in assembler source, attempt to find its details
5281 in group_reloc_table. The pointer will be updated to the character after
5282 the trailing colon. On failure, FAIL will be returned; SUCCESS
5283 otherwise. On success, *entry will be updated to point at the relevant
5284 group_reloc_table entry. */
5285
5286 static int
5287 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5288 {
5289 unsigned int i;
5290 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5291 {
5292 int length = strlen (group_reloc_table[i].name);
5293
5294 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5295 && (*str)[length] == ':')
5296 {
5297 *out = &group_reloc_table[i];
5298 *str += (length + 1);
5299 return SUCCESS;
5300 }
5301 }
5302
5303 return FAIL;
5304 }
5305
5306 /* Parse a <shifter_operand> for an ARM data processing instruction
5307 (as for parse_shifter_operand) where group relocations are allowed:
5308
5309 #<immediate>
5310 #<immediate>, <rotate>
5311 #:<group_reloc>:<expression>
5312 <Rm>
5313 <Rm>, <shift>
5314
5315 where <group_reloc> is one of the strings defined in group_reloc_table.
5316 The hashes are optional.
5317
5318 Everything else is as for parse_shifter_operand. */
5319
5320 static parse_operand_result
5321 parse_shifter_operand_group_reloc (char **str, int i)
5322 {
5323 /* Determine if we have the sequence of characters #: or just :
5324 coming next. If we do, then we check for a group relocation.
5325 If we don't, punt the whole lot to parse_shifter_operand. */
5326
5327 if (((*str)[0] == '#' && (*str)[1] == ':')
5328 || (*str)[0] == ':')
5329 {
5330 struct group_reloc_table_entry *entry;
5331
5332 if ((*str)[0] == '#')
5333 (*str) += 2;
5334 else
5335 (*str)++;
5336
5337 /* Try to parse a group relocation. Anything else is an error. */
5338 if (find_group_reloc_table_entry (str, &entry) == FAIL)
5339 {
5340 inst.error = _("unknown group relocation");
5341 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5342 }
5343
5344 /* We now have the group relocation table entry corresponding to
5345 the name in the assembler source. Next, we parse the expression. */
5346 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
5347 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5348
5349 /* Record the relocation type (always the ALU variant here). */
5350 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
5351 gas_assert (inst.reloc.type != 0);
5352
5353 return PARSE_OPERAND_SUCCESS;
5354 }
5355 else
5356 return parse_shifter_operand (str, i) == SUCCESS
5357 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
5358
5359 /* Never reached. */
5360 }
5361
5362 /* Parse a Neon alignment expression. Information is written to
5363 inst.operands[i]. We assume the initial ':' has been skipped.
5364
5365 align .imm = align << 8, .immisalign=1, .preind=0 */
5366 static parse_operand_result
5367 parse_neon_alignment (char **str, int i)
5368 {
5369 char *p = *str;
5370 expressionS exp;
5371
5372 my_get_expression (&exp, &p, GE_NO_PREFIX);
5373
5374 if (exp.X_op != O_constant)
5375 {
5376 inst.error = _("alignment must be constant");
5377 return PARSE_OPERAND_FAIL;
5378 }
5379
5380 inst.operands[i].imm = exp.X_add_number << 8;
5381 inst.operands[i].immisalign = 1;
5382 /* Alignments are not pre-indexes. */
5383 inst.operands[i].preind = 0;
5384
5385 *str = p;
5386 return PARSE_OPERAND_SUCCESS;
5387 }
5388
5389 /* Parse all forms of an ARM address expression. Information is written
5390 to inst.operands[i] and/or inst.reloc.
5391
5392 Preindexed addressing (.preind=1):
5393
5394 [Rn, #offset] .reg=Rn .reloc.exp=offset
5395 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5396 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5397 .shift_kind=shift .reloc.exp=shift_imm
5398
5399 These three may have a trailing ! which causes .writeback to be set also.
5400
5401 Postindexed addressing (.postind=1, .writeback=1):
5402
5403 [Rn], #offset .reg=Rn .reloc.exp=offset
5404 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5405 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5406 .shift_kind=shift .reloc.exp=shift_imm
5407
5408 Unindexed addressing (.preind=0, .postind=0):
5409
5410 [Rn], {option} .reg=Rn .imm=option .immisreg=0
5411
5412 Other:
5413
5414 [Rn]{!} shorthand for [Rn,#0]{!}
5415 =immediate .isreg=0 .reloc.exp=immediate
5416 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
5417
5418 It is the caller's responsibility to check for addressing modes not
5419 supported by the instruction, and to set inst.reloc.type. */
5420
5421 static parse_operand_result
5422 parse_address_main (char **str, int i, int group_relocations,
5423 group_reloc_type group_type)
5424 {
5425 char *p = *str;
5426 int reg;
5427
5428 if (skip_past_char (&p, '[') == FAIL)
5429 {
5430 if (skip_past_char (&p, '=') == FAIL)
5431 {
5432 /* Bare address - translate to PC-relative offset. */
5433 inst.reloc.pc_rel = 1;
5434 inst.operands[i].reg = REG_PC;
5435 inst.operands[i].isreg = 1;
5436 inst.operands[i].preind = 1;
5437
5438 if (my_get_expression (&inst.reloc.exp, &p, GE_OPT_PREFIX_BIG))
5439 return PARSE_OPERAND_FAIL;
5440 }
5441 else if (parse_big_immediate (&p, i, &inst.reloc.exp,
5442 /*allow_symbol_p=*/TRUE))
5443 return PARSE_OPERAND_FAIL;
5444
5445 *str = p;
5446 return PARSE_OPERAND_SUCCESS;
5447 }
5448
5449 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5450 skip_whitespace (p);
5451
5452 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5453 {
5454 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5455 return PARSE_OPERAND_FAIL;
5456 }
5457 inst.operands[i].reg = reg;
5458 inst.operands[i].isreg = 1;
5459
5460 if (skip_past_comma (&p) == SUCCESS)
5461 {
5462 inst.operands[i].preind = 1;
5463
5464 if (*p == '+') p++;
5465 else if (*p == '-') p++, inst.operands[i].negative = 1;
5466
5467 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5468 {
5469 inst.operands[i].imm = reg;
5470 inst.operands[i].immisreg = 1;
5471
5472 if (skip_past_comma (&p) == SUCCESS)
5473 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5474 return PARSE_OPERAND_FAIL;
5475 }
5476 else if (skip_past_char (&p, ':') == SUCCESS)
5477 {
5478 /* FIXME: '@' should be used here, but it's filtered out by generic
5479 code before we get to see it here. This may be subject to
5480 change. */
5481 parse_operand_result result = parse_neon_alignment (&p, i);
5482
5483 if (result != PARSE_OPERAND_SUCCESS)
5484 return result;
5485 }
5486 else
5487 {
5488 if (inst.operands[i].negative)
5489 {
5490 inst.operands[i].negative = 0;
5491 p--;
5492 }
5493
5494 if (group_relocations
5495 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
5496 {
5497 struct group_reloc_table_entry *entry;
5498
5499 /* Skip over the #: or : sequence. */
5500 if (*p == '#')
5501 p += 2;
5502 else
5503 p++;
5504
5505 /* Try to parse a group relocation. Anything else is an
5506 error. */
5507 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5508 {
5509 inst.error = _("unknown group relocation");
5510 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5511 }
5512
5513 /* We now have the group relocation table entry corresponding to
5514 the name in the assembler source. Next, we parse the
5515 expression. */
5516 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5517 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5518
5519 /* Record the relocation type. */
5520 switch (group_type)
5521 {
5522 case GROUP_LDR:
5523 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5524 break;
5525
5526 case GROUP_LDRS:
5527 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5528 break;
5529
5530 case GROUP_LDC:
5531 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5532 break;
5533
5534 default:
5535 gas_assert (0);
5536 }
5537
5538 if (inst.reloc.type == 0)
5539 {
5540 inst.error = _("this group relocation is not allowed on this instruction");
5541 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5542 }
5543 }
5544 else
5545 {
5546 char *q = p;
5547 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5548 return PARSE_OPERAND_FAIL;
5549 /* If the offset is 0, find out if it's a +0 or -0. */
5550 if (inst.reloc.exp.X_op == O_constant
5551 && inst.reloc.exp.X_add_number == 0)
5552 {
5553 skip_whitespace (q);
5554 if (*q == '#')
5555 {
5556 q++;
5557 skip_whitespace (q);
5558 }
5559 if (*q == '-')
5560 inst.operands[i].negative = 1;
5561 }
5562 }
5563 }
5564 }
5565 else if (skip_past_char (&p, ':') == SUCCESS)
5566 {
5567 /* FIXME: '@' should be used here, but it's filtered out by generic code
5568 before we get to see it here. This may be subject to change. */
5569 parse_operand_result result = parse_neon_alignment (&p, i);
5570
5571 if (result != PARSE_OPERAND_SUCCESS)
5572 return result;
5573 }
5574
5575 if (skip_past_char (&p, ']') == FAIL)
5576 {
5577 inst.error = _("']' expected");
5578 return PARSE_OPERAND_FAIL;
5579 }
5580
5581 if (skip_past_char (&p, '!') == SUCCESS)
5582 inst.operands[i].writeback = 1;
5583
5584 else if (skip_past_comma (&p) == SUCCESS)
5585 {
5586 if (skip_past_char (&p, '{') == SUCCESS)
5587 {
5588 /* [Rn], {expr} - unindexed, with option */
5589 if (parse_immediate (&p, &inst.operands[i].imm,
5590 0, 255, TRUE) == FAIL)
5591 return PARSE_OPERAND_FAIL;
5592
5593 if (skip_past_char (&p, '}') == FAIL)
5594 {
5595 inst.error = _("'}' expected at end of 'option' field");
5596 return PARSE_OPERAND_FAIL;
5597 }
5598 if (inst.operands[i].preind)
5599 {
5600 inst.error = _("cannot combine index with option");
5601 return PARSE_OPERAND_FAIL;
5602 }
5603 *str = p;
5604 return PARSE_OPERAND_SUCCESS;
5605 }
5606 else
5607 {
5608 inst.operands[i].postind = 1;
5609 inst.operands[i].writeback = 1;
5610
5611 if (inst.operands[i].preind)
5612 {
5613 inst.error = _("cannot combine pre- and post-indexing");
5614 return PARSE_OPERAND_FAIL;
5615 }
5616
5617 if (*p == '+') p++;
5618 else if (*p == '-') p++, inst.operands[i].negative = 1;
5619
5620 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5621 {
5622 /* We might be using the immediate for alignment already. If we
5623 are, OR the register number into the low-order bits. */
5624 if (inst.operands[i].immisalign)
5625 inst.operands[i].imm |= reg;
5626 else
5627 inst.operands[i].imm = reg;
5628 inst.operands[i].immisreg = 1;
5629
5630 if (skip_past_comma (&p) == SUCCESS)
5631 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5632 return PARSE_OPERAND_FAIL;
5633 }
5634 else
5635 {
5636 char *q = p;
5637 if (inst.operands[i].negative)
5638 {
5639 inst.operands[i].negative = 0;
5640 p--;
5641 }
5642 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5643 return PARSE_OPERAND_FAIL;
5644 /* If the offset is 0, find out if it's a +0 or -0. */
5645 if (inst.reloc.exp.X_op == O_constant
5646 && inst.reloc.exp.X_add_number == 0)
5647 {
5648 skip_whitespace (q);
5649 if (*q == '#')
5650 {
5651 q++;
5652 skip_whitespace (q);
5653 }
5654 if (*q == '-')
5655 inst.operands[i].negative = 1;
5656 }
5657 }
5658 }
5659 }
5660
5661 /* If at this point neither .preind nor .postind is set, we have a
5662 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5663 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5664 {
5665 inst.operands[i].preind = 1;
5666 inst.reloc.exp.X_op = O_constant;
5667 inst.reloc.exp.X_add_number = 0;
5668 }
5669 *str = p;
5670 return PARSE_OPERAND_SUCCESS;
5671 }
5672
5673 static int
5674 parse_address (char **str, int i)
5675 {
5676 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
5677 ? SUCCESS : FAIL;
5678 }
5679
5680 static parse_operand_result
5681 parse_address_group_reloc (char **str, int i, group_reloc_type type)
5682 {
5683 return parse_address_main (str, i, 1, type);
5684 }
5685
5686 /* Parse an operand for a MOVW or MOVT instruction. */
5687 static int
5688 parse_half (char **str)
5689 {
5690 char * p;
5691
5692 p = *str;
5693 skip_past_char (&p, '#');
5694 if (strncasecmp (p, ":lower16:", 9) == 0)
5695 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5696 else if (strncasecmp (p, ":upper16:", 9) == 0)
5697 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5698
5699 if (inst.reloc.type != BFD_RELOC_UNUSED)
5700 {
5701 p += 9;
5702 skip_whitespace (p);
5703 }
5704
5705 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5706 return FAIL;
5707
5708 if (inst.reloc.type == BFD_RELOC_UNUSED)
5709 {
5710 if (inst.reloc.exp.X_op != O_constant)
5711 {
5712 inst.error = _("constant expression expected");
5713 return FAIL;
5714 }
5715 if (inst.reloc.exp.X_add_number < 0
5716 || inst.reloc.exp.X_add_number > 0xffff)
5717 {
5718 inst.error = _("immediate value out of range");
5719 return FAIL;
5720 }
5721 }
5722 *str = p;
5723 return SUCCESS;
5724 }
5725
5726 /* Miscellaneous. */
5727
5728 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5729 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5730 static int
5731 parse_psr (char **str, bfd_boolean lhs)
5732 {
5733 char *p;
5734 unsigned long psr_field;
5735 const struct asm_psr *psr;
5736 char *start;
5737 bfd_boolean is_apsr = FALSE;
5738 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
5739
5740 /* PR gas/12698: If the user has specified -march=all then m_profile will
5741 be TRUE, but we want to ignore it in this case as we are building for any
5742 CPU type, including non-m variants. */
5743 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
5744 m_profile = FALSE;
5745
5746 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5747 feature for ease of use and backwards compatibility. */
5748 p = *str;
5749 if (strncasecmp (p, "SPSR", 4) == 0)
5750 {
5751 if (m_profile)
5752 goto unsupported_psr;
5753
5754 psr_field = SPSR_BIT;
5755 }
5756 else if (strncasecmp (p, "CPSR", 4) == 0)
5757 {
5758 if (m_profile)
5759 goto unsupported_psr;
5760
5761 psr_field = 0;
5762 }
5763 else if (strncasecmp (p, "APSR", 4) == 0)
5764 {
5765 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5766 and ARMv7-R architecture CPUs. */
5767 is_apsr = TRUE;
5768 psr_field = 0;
5769 }
5770 else if (m_profile)
5771 {
5772 start = p;
5773 do
5774 p++;
5775 while (ISALNUM (*p) || *p == '_');
5776
5777 if (strncasecmp (start, "iapsr", 5) == 0
5778 || strncasecmp (start, "eapsr", 5) == 0
5779 || strncasecmp (start, "xpsr", 4) == 0
5780 || strncasecmp (start, "psr", 3) == 0)
5781 p = start + strcspn (start, "rR") + 1;
5782
5783 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5784 p - start);
5785
5786 if (!psr)
5787 return FAIL;
5788
5789 /* If APSR is being written, a bitfield may be specified. Note that
5790 APSR itself is handled above. */
5791 if (psr->field <= 3)
5792 {
5793 psr_field = psr->field;
5794 is_apsr = TRUE;
5795 goto check_suffix;
5796 }
5797
5798 *str = p;
5799 /* M-profile MSR instructions have the mask field set to "10", except
5800 *PSR variants which modify APSR, which may use a different mask (and
5801 have been handled already). Do that by setting the PSR_f field
5802 here. */
5803 return psr->field | (lhs ? PSR_f : 0);
5804 }
5805 else
5806 goto unsupported_psr;
5807
5808 p += 4;
5809 check_suffix:
5810 if (*p == '_')
5811 {
5812 /* A suffix follows. */
5813 p++;
5814 start = p;
5815
5816 do
5817 p++;
5818 while (ISALNUM (*p) || *p == '_');
5819
5820 if (is_apsr)
5821 {
5822 /* APSR uses a notation for bits, rather than fields. */
5823 unsigned int nzcvq_bits = 0;
5824 unsigned int g_bit = 0;
5825 char *bit;
5826
5827 for (bit = start; bit != p; bit++)
5828 {
5829 switch (TOLOWER (*bit))
5830 {
5831 case 'n':
5832 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5833 break;
5834
5835 case 'z':
5836 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5837 break;
5838
5839 case 'c':
5840 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5841 break;
5842
5843 case 'v':
5844 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5845 break;
5846
5847 case 'q':
5848 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5849 break;
5850
5851 case 'g':
5852 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5853 break;
5854
5855 default:
5856 inst.error = _("unexpected bit specified after APSR");
5857 return FAIL;
5858 }
5859 }
5860
5861 if (nzcvq_bits == 0x1f)
5862 psr_field |= PSR_f;
5863
5864 if (g_bit == 0x1)
5865 {
5866 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
5867 {
5868 inst.error = _("selected processor does not "
5869 "support DSP extension");
5870 return FAIL;
5871 }
5872
5873 psr_field |= PSR_s;
5874 }
5875
5876 if ((nzcvq_bits & 0x20) != 0
5877 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5878 || (g_bit & 0x2) != 0)
5879 {
5880 inst.error = _("bad bitmask specified after APSR");
5881 return FAIL;
5882 }
5883 }
5884 else
5885 {
5886 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
5887 p - start);
5888 if (!psr)
5889 goto error;
5890
5891 psr_field |= psr->field;
5892 }
5893 }
5894 else
5895 {
5896 if (ISALNUM (*p))
5897 goto error; /* Garbage after "[CS]PSR". */
5898
5899 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
5900 is deprecated, but allow it anyway. */
5901 if (is_apsr && lhs)
5902 {
5903 psr_field |= PSR_f;
5904 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5905 "deprecated"));
5906 }
5907 else if (!m_profile)
5908 /* These bits are never right for M-profile devices: don't set them
5909 (only code paths which read/write APSR reach here). */
5910 psr_field |= (PSR_c | PSR_f);
5911 }
5912 *str = p;
5913 return psr_field;
5914
5915 unsupported_psr:
5916 inst.error = _("selected processor does not support requested special "
5917 "purpose register");
5918 return FAIL;
5919
5920 error:
5921 inst.error = _("flag for {c}psr instruction expected");
5922 return FAIL;
5923 }
5924
5925 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5926 value suitable for splatting into the AIF field of the instruction. */
5927
5928 static int
5929 parse_cps_flags (char **str)
5930 {
5931 int val = 0;
5932 int saw_a_flag = 0;
5933 char *s = *str;
5934
5935 for (;;)
5936 switch (*s++)
5937 {
5938 case '\0': case ',':
5939 goto done;
5940
5941 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5942 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5943 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
5944
5945 default:
5946 inst.error = _("unrecognized CPS flag");
5947 return FAIL;
5948 }
5949
5950 done:
5951 if (saw_a_flag == 0)
5952 {
5953 inst.error = _("missing CPS flags");
5954 return FAIL;
5955 }
5956
5957 *str = s - 1;
5958 return val;
5959 }
5960
5961 /* Parse an endian specifier ("BE" or "LE", case insensitive);
5962 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
5963
5964 static int
5965 parse_endian_specifier (char **str)
5966 {
5967 int little_endian;
5968 char *s = *str;
5969
5970 if (strncasecmp (s, "BE", 2))
5971 little_endian = 0;
5972 else if (strncasecmp (s, "LE", 2))
5973 little_endian = 1;
5974 else
5975 {
5976 inst.error = _("valid endian specifiers are be or le");
5977 return FAIL;
5978 }
5979
5980 if (ISALNUM (s[2]) || s[2] == '_')
5981 {
5982 inst.error = _("valid endian specifiers are be or le");
5983 return FAIL;
5984 }
5985
5986 *str = s + 2;
5987 return little_endian;
5988 }
5989
5990 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5991 value suitable for poking into the rotate field of an sxt or sxta
5992 instruction, or FAIL on error. */
5993
5994 static int
5995 parse_ror (char **str)
5996 {
5997 int rot;
5998 char *s = *str;
5999
6000 if (strncasecmp (s, "ROR", 3) == 0)
6001 s += 3;
6002 else
6003 {
6004 inst.error = _("missing rotation field after comma");
6005 return FAIL;
6006 }
6007
6008 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6009 return FAIL;
6010
6011 switch (rot)
6012 {
6013 case 0: *str = s; return 0x0;
6014 case 8: *str = s; return 0x1;
6015 case 16: *str = s; return 0x2;
6016 case 24: *str = s; return 0x3;
6017
6018 default:
6019 inst.error = _("rotation can only be 0, 8, 16, or 24");
6020 return FAIL;
6021 }
6022 }
6023
6024 /* Parse a conditional code (from conds[] below). The value returned is in the
6025 range 0 .. 14, or FAIL. */
6026 static int
6027 parse_cond (char **str)
6028 {
6029 char *q;
6030 const struct asm_cond *c;
6031 int n;
6032 /* Condition codes are always 2 characters, so matching up to
6033 3 characters is sufficient. */
6034 char cond[3];
6035
6036 q = *str;
6037 n = 0;
6038 while (ISALPHA (*q) && n < 3)
6039 {
6040 cond[n] = TOLOWER (*q);
6041 q++;
6042 n++;
6043 }
6044
6045 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
6046 if (!c)
6047 {
6048 inst.error = _("condition required");
6049 return FAIL;
6050 }
6051
6052 *str = q;
6053 return c->value;
6054 }
6055
6056 /* If the given feature available in the selected CPU, mark it as used.
6057 Returns TRUE iff feature is available. */
6058 static bfd_boolean
6059 mark_feature_used (const arm_feature_set *feature)
6060 {
6061 /* Ensure the option is valid on the current architecture. */
6062 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
6063 return FALSE;
6064
6065 /* Add the appropriate architecture feature for the barrier option used.
6066 */
6067 if (thumb_mode)
6068 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
6069 else
6070 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
6071
6072 return TRUE;
6073 }
6074
6075 /* Parse an option for a barrier instruction. Returns the encoding for the
6076 option, or FAIL. */
6077 static int
6078 parse_barrier (char **str)
6079 {
6080 char *p, *q;
6081 const struct asm_barrier_opt *o;
6082
6083 p = q = *str;
6084 while (ISALPHA (*q))
6085 q++;
6086
6087 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
6088 q - p);
6089 if (!o)
6090 return FAIL;
6091
6092 if (!mark_feature_used (&o->arch))
6093 return FAIL;
6094
6095 *str = q;
6096 return o->value;
6097 }
6098
6099 /* Parse the operands of a table branch instruction. Similar to a memory
6100 operand. */
6101 static int
6102 parse_tb (char **str)
6103 {
6104 char * p = *str;
6105 int reg;
6106
6107 if (skip_past_char (&p, '[') == FAIL)
6108 {
6109 inst.error = _("'[' expected");
6110 return FAIL;
6111 }
6112
6113 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
6114 {
6115 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6116 return FAIL;
6117 }
6118 inst.operands[0].reg = reg;
6119
6120 if (skip_past_comma (&p) == FAIL)
6121 {
6122 inst.error = _("',' expected");
6123 return FAIL;
6124 }
6125
6126 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
6127 {
6128 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6129 return FAIL;
6130 }
6131 inst.operands[0].imm = reg;
6132
6133 if (skip_past_comma (&p) == SUCCESS)
6134 {
6135 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6136 return FAIL;
6137 if (inst.reloc.exp.X_add_number != 1)
6138 {
6139 inst.error = _("invalid shift");
6140 return FAIL;
6141 }
6142 inst.operands[0].shifted = 1;
6143 }
6144
6145 if (skip_past_char (&p, ']') == FAIL)
6146 {
6147 inst.error = _("']' expected");
6148 return FAIL;
6149 }
6150 *str = p;
6151 return SUCCESS;
6152 }
6153
6154 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6155 information on the types the operands can take and how they are encoded.
6156 Up to four operands may be read; this function handles setting the
6157 ".present" field for each read operand itself.
6158 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6159 else returns FAIL. */
6160
6161 static int
6162 parse_neon_mov (char **str, int *which_operand)
6163 {
6164 int i = *which_operand, val;
6165 enum arm_reg_type rtype;
6166 char *ptr = *str;
6167 struct neon_type_el optype;
6168
6169 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
6170 {
6171 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6172 inst.operands[i].reg = val;
6173 inst.operands[i].isscalar = 1;
6174 inst.operands[i].vectype = optype;
6175 inst.operands[i++].present = 1;
6176
6177 if (skip_past_comma (&ptr) == FAIL)
6178 goto wanted_comma;
6179
6180 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6181 goto wanted_arm;
6182
6183 inst.operands[i].reg = val;
6184 inst.operands[i].isreg = 1;
6185 inst.operands[i].present = 1;
6186 }
6187 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
6188 != FAIL)
6189 {
6190 /* Cases 0, 1, 2, 3, 5 (D only). */
6191 if (skip_past_comma (&ptr) == FAIL)
6192 goto wanted_comma;
6193
6194 inst.operands[i].reg = val;
6195 inst.operands[i].isreg = 1;
6196 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6197 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6198 inst.operands[i].isvec = 1;
6199 inst.operands[i].vectype = optype;
6200 inst.operands[i++].present = 1;
6201
6202 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6203 {
6204 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6205 Case 13: VMOV <Sd>, <Rm> */
6206 inst.operands[i].reg = val;
6207 inst.operands[i].isreg = 1;
6208 inst.operands[i].present = 1;
6209
6210 if (rtype == REG_TYPE_NQ)
6211 {
6212 first_error (_("can't use Neon quad register here"));
6213 return FAIL;
6214 }
6215 else if (rtype != REG_TYPE_VFS)
6216 {
6217 i++;
6218 if (skip_past_comma (&ptr) == FAIL)
6219 goto wanted_comma;
6220 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6221 goto wanted_arm;
6222 inst.operands[i].reg = val;
6223 inst.operands[i].isreg = 1;
6224 inst.operands[i].present = 1;
6225 }
6226 }
6227 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
6228 &optype)) != FAIL)
6229 {
6230 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6231 Case 1: VMOV<c><q> <Dd>, <Dm>
6232 Case 8: VMOV.F32 <Sd>, <Sm>
6233 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6234
6235 inst.operands[i].reg = val;
6236 inst.operands[i].isreg = 1;
6237 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6238 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6239 inst.operands[i].isvec = 1;
6240 inst.operands[i].vectype = optype;
6241 inst.operands[i].present = 1;
6242
6243 if (skip_past_comma (&ptr) == SUCCESS)
6244 {
6245 /* Case 15. */
6246 i++;
6247
6248 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6249 goto wanted_arm;
6250
6251 inst.operands[i].reg = val;
6252 inst.operands[i].isreg = 1;
6253 inst.operands[i++].present = 1;
6254
6255 if (skip_past_comma (&ptr) == FAIL)
6256 goto wanted_comma;
6257
6258 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6259 goto wanted_arm;
6260
6261 inst.operands[i].reg = val;
6262 inst.operands[i].isreg = 1;
6263 inst.operands[i].present = 1;
6264 }
6265 }
6266 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
6267 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6268 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6269 Case 10: VMOV.F32 <Sd>, #<imm>
6270 Case 11: VMOV.F64 <Dd>, #<imm> */
6271 inst.operands[i].immisfloat = 1;
6272 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6273 == SUCCESS)
6274 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6275 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6276 ;
6277 else
6278 {
6279 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6280 return FAIL;
6281 }
6282 }
6283 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6284 {
6285 /* Cases 6, 7. */
6286 inst.operands[i].reg = val;
6287 inst.operands[i].isreg = 1;
6288 inst.operands[i++].present = 1;
6289
6290 if (skip_past_comma (&ptr) == FAIL)
6291 goto wanted_comma;
6292
6293 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
6294 {
6295 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6296 inst.operands[i].reg = val;
6297 inst.operands[i].isscalar = 1;
6298 inst.operands[i].present = 1;
6299 inst.operands[i].vectype = optype;
6300 }
6301 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6302 {
6303 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6304 inst.operands[i].reg = val;
6305 inst.operands[i].isreg = 1;
6306 inst.operands[i++].present = 1;
6307
6308 if (skip_past_comma (&ptr) == FAIL)
6309 goto wanted_comma;
6310
6311 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6312 == FAIL)
6313 {
6314 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6315 return FAIL;
6316 }
6317
6318 inst.operands[i].reg = val;
6319 inst.operands[i].isreg = 1;
6320 inst.operands[i].isvec = 1;
6321 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6322 inst.operands[i].vectype = optype;
6323 inst.operands[i].present = 1;
6324
6325 if (rtype == REG_TYPE_VFS)
6326 {
6327 /* Case 14. */
6328 i++;
6329 if (skip_past_comma (&ptr) == FAIL)
6330 goto wanted_comma;
6331 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6332 &optype)) == FAIL)
6333 {
6334 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6335 return FAIL;
6336 }
6337 inst.operands[i].reg = val;
6338 inst.operands[i].isreg = 1;
6339 inst.operands[i].isvec = 1;
6340 inst.operands[i].issingle = 1;
6341 inst.operands[i].vectype = optype;
6342 inst.operands[i].present = 1;
6343 }
6344 }
6345 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
6346 != FAIL)
6347 {
6348 /* Case 13. */
6349 inst.operands[i].reg = val;
6350 inst.operands[i].isreg = 1;
6351 inst.operands[i].isvec = 1;
6352 inst.operands[i].issingle = 1;
6353 inst.operands[i].vectype = optype;
6354 inst.operands[i].present = 1;
6355 }
6356 }
6357 else
6358 {
6359 first_error (_("parse error"));
6360 return FAIL;
6361 }
6362
6363 /* Successfully parsed the operands. Update args. */
6364 *which_operand = i;
6365 *str = ptr;
6366 return SUCCESS;
6367
6368 wanted_comma:
6369 first_error (_("expected comma"));
6370 return FAIL;
6371
6372 wanted_arm:
6373 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
6374 return FAIL;
6375 }
6376
6377 /* Use this macro when the operand constraints are different
6378 for ARM and THUMB (e.g. ldrd). */
6379 #define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6380 ((arm_operand) | ((thumb_operand) << 16))
6381
6382 /* Matcher codes for parse_operands. */
6383 enum operand_parse_code
6384 {
6385 OP_stop, /* end of line */
6386
6387 OP_RR, /* ARM register */
6388 OP_RRnpc, /* ARM register, not r15 */
6389 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
6390 OP_RRnpcb, /* ARM register, not r15, in square brackets */
6391 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
6392 optional trailing ! */
6393 OP_RRw, /* ARM register, not r15, optional trailing ! */
6394 OP_RCP, /* Coprocessor number */
6395 OP_RCN, /* Coprocessor register */
6396 OP_RF, /* FPA register */
6397 OP_RVS, /* VFP single precision register */
6398 OP_RVD, /* VFP double precision register (0..15) */
6399 OP_RND, /* Neon double precision register (0..31) */
6400 OP_RNQ, /* Neon quad precision register */
6401 OP_RVSD, /* VFP single or double precision register */
6402 OP_RNDQ, /* Neon double or quad precision register */
6403 OP_RNSDQ, /* Neon single, double or quad precision register */
6404 OP_RNSC, /* Neon scalar D[X] */
6405 OP_RVC, /* VFP control register */
6406 OP_RMF, /* Maverick F register */
6407 OP_RMD, /* Maverick D register */
6408 OP_RMFX, /* Maverick FX register */
6409 OP_RMDX, /* Maverick DX register */
6410 OP_RMAX, /* Maverick AX register */
6411 OP_RMDS, /* Maverick DSPSC register */
6412 OP_RIWR, /* iWMMXt wR register */
6413 OP_RIWC, /* iWMMXt wC register */
6414 OP_RIWG, /* iWMMXt wCG register */
6415 OP_RXA, /* XScale accumulator register */
6416
6417 OP_REGLST, /* ARM register list */
6418 OP_VRSLST, /* VFP single-precision register list */
6419 OP_VRDLST, /* VFP double-precision register list */
6420 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
6421 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6422 OP_NSTRLST, /* Neon element/structure list */
6423
6424 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
6425 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
6426 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
6427 OP_RR_RNSC, /* ARM reg or Neon scalar. */
6428 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
6429 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6430 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6431 OP_VMOV, /* Neon VMOV operands. */
6432 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
6433 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
6434 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
6435
6436 OP_I0, /* immediate zero */
6437 OP_I7, /* immediate value 0 .. 7 */
6438 OP_I15, /* 0 .. 15 */
6439 OP_I16, /* 1 .. 16 */
6440 OP_I16z, /* 0 .. 16 */
6441 OP_I31, /* 0 .. 31 */
6442 OP_I31w, /* 0 .. 31, optional trailing ! */
6443 OP_I32, /* 1 .. 32 */
6444 OP_I32z, /* 0 .. 32 */
6445 OP_I63, /* 0 .. 63 */
6446 OP_I63s, /* -64 .. 63 */
6447 OP_I64, /* 1 .. 64 */
6448 OP_I64z, /* 0 .. 64 */
6449 OP_I255, /* 0 .. 255 */
6450
6451 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6452 OP_I7b, /* 0 .. 7 */
6453 OP_I15b, /* 0 .. 15 */
6454 OP_I31b, /* 0 .. 31 */
6455
6456 OP_SH, /* shifter operand */
6457 OP_SHG, /* shifter operand with possible group relocation */
6458 OP_ADDR, /* Memory address expression (any mode) */
6459 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6460 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6461 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
6462 OP_EXP, /* arbitrary expression */
6463 OP_EXPi, /* same, with optional immediate prefix */
6464 OP_EXPr, /* same, with optional relocation suffix */
6465 OP_HALF, /* 0 .. 65535 or low/high reloc. */
6466
6467 OP_CPSF, /* CPS flags */
6468 OP_ENDI, /* Endianness specifier */
6469 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6470 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
6471 OP_COND, /* conditional code */
6472 OP_TB, /* Table branch. */
6473
6474 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6475
6476 OP_RRnpc_I0, /* ARM register or literal 0 */
6477 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
6478 OP_RR_EXi, /* ARM register or expression with imm prefix */
6479 OP_RF_IF, /* FPA register or immediate */
6480 OP_RIWR_RIWC, /* iWMMXt R or C reg */
6481 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
6482
6483 /* Optional operands. */
6484 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6485 OP_oI31b, /* 0 .. 31 */
6486 OP_oI32b, /* 1 .. 32 */
6487 OP_oI32z, /* 0 .. 32 */
6488 OP_oIffffb, /* 0 .. 65535 */
6489 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6490
6491 OP_oRR, /* ARM register */
6492 OP_oRRnpc, /* ARM register, not the PC */
6493 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
6494 OP_oRRw, /* ARM register, not r15, optional trailing ! */
6495 OP_oRND, /* Optional Neon double precision register */
6496 OP_oRNQ, /* Optional Neon quad precision register */
6497 OP_oRNDQ, /* Optional Neon double or quad precision register */
6498 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
6499 OP_oSHll, /* LSL immediate */
6500 OP_oSHar, /* ASR immediate */
6501 OP_oSHllar, /* LSL or ASR immediate */
6502 OP_oROR, /* ROR 0/8/16/24 */
6503 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
6504
6505 /* Some pre-defined mixed (ARM/THUMB) operands. */
6506 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6507 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6508 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6509
6510 OP_FIRST_OPTIONAL = OP_oI7b
6511 };
6512
6513 /* Generic instruction operand parser. This does no encoding and no
6514 semantic validation; it merely squirrels values away in the inst
6515 structure. Returns SUCCESS or FAIL depending on whether the
6516 specified grammar matched. */
6517 static int
6518 parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
6519 {
6520 unsigned const int *upat = pattern;
6521 char *backtrack_pos = 0;
6522 const char *backtrack_error = 0;
6523 int i, val = 0, backtrack_index = 0;
6524 enum arm_reg_type rtype;
6525 parse_operand_result result;
6526 unsigned int op_parse_code;
6527
6528 #define po_char_or_fail(chr) \
6529 do \
6530 { \
6531 if (skip_past_char (&str, chr) == FAIL) \
6532 goto bad_args; \
6533 } \
6534 while (0)
6535
6536 #define po_reg_or_fail(regtype) \
6537 do \
6538 { \
6539 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6540 & inst.operands[i].vectype); \
6541 if (val == FAIL) \
6542 { \
6543 first_error (_(reg_expected_msgs[regtype])); \
6544 goto failure; \
6545 } \
6546 inst.operands[i].reg = val; \
6547 inst.operands[i].isreg = 1; \
6548 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6549 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6550 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6551 || rtype == REG_TYPE_VFD \
6552 || rtype == REG_TYPE_NQ); \
6553 } \
6554 while (0)
6555
6556 #define po_reg_or_goto(regtype, label) \
6557 do \
6558 { \
6559 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6560 & inst.operands[i].vectype); \
6561 if (val == FAIL) \
6562 goto label; \
6563 \
6564 inst.operands[i].reg = val; \
6565 inst.operands[i].isreg = 1; \
6566 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6567 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6568 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6569 || rtype == REG_TYPE_VFD \
6570 || rtype == REG_TYPE_NQ); \
6571 } \
6572 while (0)
6573
6574 #define po_imm_or_fail(min, max, popt) \
6575 do \
6576 { \
6577 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6578 goto failure; \
6579 inst.operands[i].imm = val; \
6580 } \
6581 while (0)
6582
6583 #define po_scalar_or_goto(elsz, label) \
6584 do \
6585 { \
6586 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6587 if (val == FAIL) \
6588 goto label; \
6589 inst.operands[i].reg = val; \
6590 inst.operands[i].isscalar = 1; \
6591 } \
6592 while (0)
6593
6594 #define po_misc_or_fail(expr) \
6595 do \
6596 { \
6597 if (expr) \
6598 goto failure; \
6599 } \
6600 while (0)
6601
6602 #define po_misc_or_fail_no_backtrack(expr) \
6603 do \
6604 { \
6605 result = expr; \
6606 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6607 backtrack_pos = 0; \
6608 if (result != PARSE_OPERAND_SUCCESS) \
6609 goto failure; \
6610 } \
6611 while (0)
6612
6613 #define po_barrier_or_imm(str) \
6614 do \
6615 { \
6616 val = parse_barrier (&str); \
6617 if (val == FAIL && ! ISALPHA (*str)) \
6618 goto immediate; \
6619 if (val == FAIL \
6620 /* ISB can only take SY as an option. */ \
6621 || ((inst.instruction & 0xf0) == 0x60 \
6622 && val != 0xf)) \
6623 { \
6624 inst.error = _("invalid barrier type"); \
6625 backtrack_pos = 0; \
6626 goto failure; \
6627 } \
6628 } \
6629 while (0)
6630
6631 skip_whitespace (str);
6632
6633 for (i = 0; upat[i] != OP_stop; i++)
6634 {
6635 op_parse_code = upat[i];
6636 if (op_parse_code >= 1<<16)
6637 op_parse_code = thumb ? (op_parse_code >> 16)
6638 : (op_parse_code & ((1<<16)-1));
6639
6640 if (op_parse_code >= OP_FIRST_OPTIONAL)
6641 {
6642 /* Remember where we are in case we need to backtrack. */
6643 gas_assert (!backtrack_pos);
6644 backtrack_pos = str;
6645 backtrack_error = inst.error;
6646 backtrack_index = i;
6647 }
6648
6649 if (i > 0 && (i > 1 || inst.operands[0].present))
6650 po_char_or_fail (',');
6651
6652 switch (op_parse_code)
6653 {
6654 /* Registers */
6655 case OP_oRRnpc:
6656 case OP_oRRnpcsp:
6657 case OP_RRnpc:
6658 case OP_RRnpcsp:
6659 case OP_oRR:
6660 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6661 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6662 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6663 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6664 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6665 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
6666 case OP_oRND:
6667 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
6668 case OP_RVC:
6669 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6670 break;
6671 /* Also accept generic coprocessor regs for unknown registers. */
6672 coproc_reg:
6673 po_reg_or_fail (REG_TYPE_CN);
6674 break;
6675 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6676 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6677 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6678 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6679 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6680 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6681 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6682 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6683 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6684 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
6685 case OP_oRNQ:
6686 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
6687 case OP_oRNDQ:
6688 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
6689 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6690 case OP_oRNSDQ:
6691 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6692
6693 /* Neon scalar. Using an element size of 8 means that some invalid
6694 scalars are accepted here, so deal with those in later code. */
6695 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6696
6697 case OP_RNDQ_I0:
6698 {
6699 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6700 break;
6701 try_imm0:
6702 po_imm_or_fail (0, 0, TRUE);
6703 }
6704 break;
6705
6706 case OP_RVSD_I0:
6707 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6708 break;
6709
6710 case OP_RSVD_FI0:
6711 {
6712 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
6713 break;
6714 try_ifimm0:
6715 if (parse_ifimm_zero (&str))
6716 inst.operands[i].imm = 0;
6717 else
6718 {
6719 inst.error
6720 = _("only floating point zero is allowed as immediate value");
6721 goto failure;
6722 }
6723 }
6724 break;
6725
6726 case OP_RR_RNSC:
6727 {
6728 po_scalar_or_goto (8, try_rr);
6729 break;
6730 try_rr:
6731 po_reg_or_fail (REG_TYPE_RN);
6732 }
6733 break;
6734
6735 case OP_RNSDQ_RNSC:
6736 {
6737 po_scalar_or_goto (8, try_nsdq);
6738 break;
6739 try_nsdq:
6740 po_reg_or_fail (REG_TYPE_NSDQ);
6741 }
6742 break;
6743
6744 case OP_RNDQ_RNSC:
6745 {
6746 po_scalar_or_goto (8, try_ndq);
6747 break;
6748 try_ndq:
6749 po_reg_or_fail (REG_TYPE_NDQ);
6750 }
6751 break;
6752
6753 case OP_RND_RNSC:
6754 {
6755 po_scalar_or_goto (8, try_vfd);
6756 break;
6757 try_vfd:
6758 po_reg_or_fail (REG_TYPE_VFD);
6759 }
6760 break;
6761
6762 case OP_VMOV:
6763 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6764 not careful then bad things might happen. */
6765 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6766 break;
6767
6768 case OP_RNDQ_Ibig:
6769 {
6770 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6771 break;
6772 try_immbig:
6773 /* There's a possibility of getting a 64-bit immediate here, so
6774 we need special handling. */
6775 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
6776 == FAIL)
6777 {
6778 inst.error = _("immediate value is out of range");
6779 goto failure;
6780 }
6781 }
6782 break;
6783
6784 case OP_RNDQ_I63b:
6785 {
6786 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6787 break;
6788 try_shimm:
6789 po_imm_or_fail (0, 63, TRUE);
6790 }
6791 break;
6792
6793 case OP_RRnpcb:
6794 po_char_or_fail ('[');
6795 po_reg_or_fail (REG_TYPE_RN);
6796 po_char_or_fail (']');
6797 break;
6798
6799 case OP_RRnpctw:
6800 case OP_RRw:
6801 case OP_oRRw:
6802 po_reg_or_fail (REG_TYPE_RN);
6803 if (skip_past_char (&str, '!') == SUCCESS)
6804 inst.operands[i].writeback = 1;
6805 break;
6806
6807 /* Immediates */
6808 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6809 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6810 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
6811 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
6812 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6813 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
6814 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
6815 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
6816 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6817 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6818 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
6819 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
6820
6821 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6822 case OP_oI7b:
6823 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6824 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6825 case OP_oI31b:
6826 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
6827 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6828 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
6829 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6830
6831 /* Immediate variants */
6832 case OP_oI255c:
6833 po_char_or_fail ('{');
6834 po_imm_or_fail (0, 255, TRUE);
6835 po_char_or_fail ('}');
6836 break;
6837
6838 case OP_I31w:
6839 /* The expression parser chokes on a trailing !, so we have
6840 to find it first and zap it. */
6841 {
6842 char *s = str;
6843 while (*s && *s != ',')
6844 s++;
6845 if (s[-1] == '!')
6846 {
6847 s[-1] = '\0';
6848 inst.operands[i].writeback = 1;
6849 }
6850 po_imm_or_fail (0, 31, TRUE);
6851 if (str == s - 1)
6852 str = s;
6853 }
6854 break;
6855
6856 /* Expressions */
6857 case OP_EXPi: EXPi:
6858 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6859 GE_OPT_PREFIX));
6860 break;
6861
6862 case OP_EXP:
6863 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6864 GE_NO_PREFIX));
6865 break;
6866
6867 case OP_EXPr: EXPr:
6868 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6869 GE_NO_PREFIX));
6870 if (inst.reloc.exp.X_op == O_symbol)
6871 {
6872 val = parse_reloc (&str);
6873 if (val == -1)
6874 {
6875 inst.error = _("unrecognized relocation suffix");
6876 goto failure;
6877 }
6878 else if (val != BFD_RELOC_UNUSED)
6879 {
6880 inst.operands[i].imm = val;
6881 inst.operands[i].hasreloc = 1;
6882 }
6883 }
6884 break;
6885
6886 /* Operand for MOVW or MOVT. */
6887 case OP_HALF:
6888 po_misc_or_fail (parse_half (&str));
6889 break;
6890
6891 /* Register or expression. */
6892 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6893 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
6894
6895 /* Register or immediate. */
6896 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6897 I0: po_imm_or_fail (0, 0, FALSE); break;
6898
6899 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6900 IF:
6901 if (!is_immediate_prefix (*str))
6902 goto bad_args;
6903 str++;
6904 val = parse_fpa_immediate (&str);
6905 if (val == FAIL)
6906 goto failure;
6907 /* FPA immediates are encoded as registers 8-15.
6908 parse_fpa_immediate has already applied the offset. */
6909 inst.operands[i].reg = val;
6910 inst.operands[i].isreg = 1;
6911 break;
6912
6913 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6914 I32z: po_imm_or_fail (0, 32, FALSE); break;
6915
6916 /* Two kinds of register. */
6917 case OP_RIWR_RIWC:
6918 {
6919 struct reg_entry *rege = arm_reg_parse_multi (&str);
6920 if (!rege
6921 || (rege->type != REG_TYPE_MMXWR
6922 && rege->type != REG_TYPE_MMXWC
6923 && rege->type != REG_TYPE_MMXWCG))
6924 {
6925 inst.error = _("iWMMXt data or control register expected");
6926 goto failure;
6927 }
6928 inst.operands[i].reg = rege->number;
6929 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6930 }
6931 break;
6932
6933 case OP_RIWC_RIWG:
6934 {
6935 struct reg_entry *rege = arm_reg_parse_multi (&str);
6936 if (!rege
6937 || (rege->type != REG_TYPE_MMXWC
6938 && rege->type != REG_TYPE_MMXWCG))
6939 {
6940 inst.error = _("iWMMXt control register expected");
6941 goto failure;
6942 }
6943 inst.operands[i].reg = rege->number;
6944 inst.operands[i].isreg = 1;
6945 }
6946 break;
6947
6948 /* Misc */
6949 case OP_CPSF: val = parse_cps_flags (&str); break;
6950 case OP_ENDI: val = parse_endian_specifier (&str); break;
6951 case OP_oROR: val = parse_ror (&str); break;
6952 case OP_COND: val = parse_cond (&str); break;
6953 case OP_oBARRIER_I15:
6954 po_barrier_or_imm (str); break;
6955 immediate:
6956 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
6957 goto failure;
6958 break;
6959
6960 case OP_wPSR:
6961 case OP_rPSR:
6962 po_reg_or_goto (REG_TYPE_RNB, try_psr);
6963 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
6964 {
6965 inst.error = _("Banked registers are not available with this "
6966 "architecture.");
6967 goto failure;
6968 }
6969 break;
6970 try_psr:
6971 val = parse_psr (&str, op_parse_code == OP_wPSR);
6972 break;
6973
6974 case OP_APSR_RR:
6975 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6976 break;
6977 try_apsr:
6978 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6979 instruction). */
6980 if (strncasecmp (str, "APSR_", 5) == 0)
6981 {
6982 unsigned found = 0;
6983 str += 5;
6984 while (found < 15)
6985 switch (*str++)
6986 {
6987 case 'c': found = (found & 1) ? 16 : found | 1; break;
6988 case 'n': found = (found & 2) ? 16 : found | 2; break;
6989 case 'z': found = (found & 4) ? 16 : found | 4; break;
6990 case 'v': found = (found & 8) ? 16 : found | 8; break;
6991 default: found = 16;
6992 }
6993 if (found != 15)
6994 goto failure;
6995 inst.operands[i].isvec = 1;
6996 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6997 inst.operands[i].reg = REG_PC;
6998 }
6999 else
7000 goto failure;
7001 break;
7002
7003 case OP_TB:
7004 po_misc_or_fail (parse_tb (&str));
7005 break;
7006
7007 /* Register lists. */
7008 case OP_REGLST:
7009 val = parse_reg_list (&str);
7010 if (*str == '^')
7011 {
7012 inst.operands[i].writeback = 1;
7013 str++;
7014 }
7015 break;
7016
7017 case OP_VRSLST:
7018 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
7019 break;
7020
7021 case OP_VRDLST:
7022 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
7023 break;
7024
7025 case OP_VRSDLST:
7026 /* Allow Q registers too. */
7027 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7028 REGLIST_NEON_D);
7029 if (val == FAIL)
7030 {
7031 inst.error = NULL;
7032 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7033 REGLIST_VFP_S);
7034 inst.operands[i].issingle = 1;
7035 }
7036 break;
7037
7038 case OP_NRDLST:
7039 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7040 REGLIST_NEON_D);
7041 break;
7042
7043 case OP_NSTRLST:
7044 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7045 &inst.operands[i].vectype);
7046 break;
7047
7048 /* Addressing modes */
7049 case OP_ADDR:
7050 po_misc_or_fail (parse_address (&str, i));
7051 break;
7052
7053 case OP_ADDRGLDR:
7054 po_misc_or_fail_no_backtrack (
7055 parse_address_group_reloc (&str, i, GROUP_LDR));
7056 break;
7057
7058 case OP_ADDRGLDRS:
7059 po_misc_or_fail_no_backtrack (
7060 parse_address_group_reloc (&str, i, GROUP_LDRS));
7061 break;
7062
7063 case OP_ADDRGLDC:
7064 po_misc_or_fail_no_backtrack (
7065 parse_address_group_reloc (&str, i, GROUP_LDC));
7066 break;
7067
7068 case OP_SH:
7069 po_misc_or_fail (parse_shifter_operand (&str, i));
7070 break;
7071
7072 case OP_SHG:
7073 po_misc_or_fail_no_backtrack (
7074 parse_shifter_operand_group_reloc (&str, i));
7075 break;
7076
7077 case OP_oSHll:
7078 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7079 break;
7080
7081 case OP_oSHar:
7082 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7083 break;
7084
7085 case OP_oSHllar:
7086 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7087 break;
7088
7089 default:
7090 as_fatal (_("unhandled operand code %d"), op_parse_code);
7091 }
7092
7093 /* Various value-based sanity checks and shared operations. We
7094 do not signal immediate failures for the register constraints;
7095 this allows a syntax error to take precedence. */
7096 switch (op_parse_code)
7097 {
7098 case OP_oRRnpc:
7099 case OP_RRnpc:
7100 case OP_RRnpcb:
7101 case OP_RRw:
7102 case OP_oRRw:
7103 case OP_RRnpc_I0:
7104 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7105 inst.error = BAD_PC;
7106 break;
7107
7108 case OP_oRRnpcsp:
7109 case OP_RRnpcsp:
7110 if (inst.operands[i].isreg)
7111 {
7112 if (inst.operands[i].reg == REG_PC)
7113 inst.error = BAD_PC;
7114 else if (inst.operands[i].reg == REG_SP)
7115 inst.error = BAD_SP;
7116 }
7117 break;
7118
7119 case OP_RRnpctw:
7120 if (inst.operands[i].isreg
7121 && inst.operands[i].reg == REG_PC
7122 && (inst.operands[i].writeback || thumb))
7123 inst.error = BAD_PC;
7124 break;
7125
7126 case OP_CPSF:
7127 case OP_ENDI:
7128 case OP_oROR:
7129 case OP_wPSR:
7130 case OP_rPSR:
7131 case OP_COND:
7132 case OP_oBARRIER_I15:
7133 case OP_REGLST:
7134 case OP_VRSLST:
7135 case OP_VRDLST:
7136 case OP_VRSDLST:
7137 case OP_NRDLST:
7138 case OP_NSTRLST:
7139 if (val == FAIL)
7140 goto failure;
7141 inst.operands[i].imm = val;
7142 break;
7143
7144 default:
7145 break;
7146 }
7147
7148 /* If we get here, this operand was successfully parsed. */
7149 inst.operands[i].present = 1;
7150 continue;
7151
7152 bad_args:
7153 inst.error = BAD_ARGS;
7154
7155 failure:
7156 if (!backtrack_pos)
7157 {
7158 /* The parse routine should already have set inst.error, but set a
7159 default here just in case. */
7160 if (!inst.error)
7161 inst.error = _("syntax error");
7162 return FAIL;
7163 }
7164
7165 /* Do not backtrack over a trailing optional argument that
7166 absorbed some text. We will only fail again, with the
7167 'garbage following instruction' error message, which is
7168 probably less helpful than the current one. */
7169 if (backtrack_index == i && backtrack_pos != str
7170 && upat[i+1] == OP_stop)
7171 {
7172 if (!inst.error)
7173 inst.error = _("syntax error");
7174 return FAIL;
7175 }
7176
7177 /* Try again, skipping the optional argument at backtrack_pos. */
7178 str = backtrack_pos;
7179 inst.error = backtrack_error;
7180 inst.operands[backtrack_index].present = 0;
7181 i = backtrack_index;
7182 backtrack_pos = 0;
7183 }
7184
7185 /* Check that we have parsed all the arguments. */
7186 if (*str != '\0' && !inst.error)
7187 inst.error = _("garbage following instruction");
7188
7189 return inst.error ? FAIL : SUCCESS;
7190 }
7191
7192 #undef po_char_or_fail
7193 #undef po_reg_or_fail
7194 #undef po_reg_or_goto
7195 #undef po_imm_or_fail
7196 #undef po_scalar_or_fail
7197 #undef po_barrier_or_imm
7198
7199 /* Shorthand macro for instruction encoding functions issuing errors. */
7200 #define constraint(expr, err) \
7201 do \
7202 { \
7203 if (expr) \
7204 { \
7205 inst.error = err; \
7206 return; \
7207 } \
7208 } \
7209 while (0)
7210
7211 /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7212 instructions are unpredictable if these registers are used. This
7213 is the BadReg predicate in ARM's Thumb-2 documentation. */
7214 #define reject_bad_reg(reg) \
7215 do \
7216 if (reg == REG_SP || reg == REG_PC) \
7217 { \
7218 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
7219 return; \
7220 } \
7221 while (0)
7222
7223 /* If REG is R13 (the stack pointer), warn that its use is
7224 deprecated. */
7225 #define warn_deprecated_sp(reg) \
7226 do \
7227 if (warn_on_deprecated && reg == REG_SP) \
7228 as_tsktsk (_("use of r13 is deprecated")); \
7229 while (0)
7230
7231 /* Functions for operand encoding. ARM, then Thumb. */
7232
7233 #define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
7234
7235 /* If VAL can be encoded in the immediate field of an ARM instruction,
7236 return the encoded form. Otherwise, return FAIL. */
7237
7238 static unsigned int
7239 encode_arm_immediate (unsigned int val)
7240 {
7241 unsigned int a, i;
7242
7243 for (i = 0; i < 32; i += 2)
7244 if ((a = rotate_left (val, i)) <= 0xff)
7245 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7246
7247 return FAIL;
7248 }
7249
7250 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7251 return the encoded form. Otherwise, return FAIL. */
7252 static unsigned int
7253 encode_thumb32_immediate (unsigned int val)
7254 {
7255 unsigned int a, i;
7256
7257 if (val <= 0xff)
7258 return val;
7259
7260 for (i = 1; i <= 24; i++)
7261 {
7262 a = val >> i;
7263 if ((val & ~(0xff << i)) == 0)
7264 return ((val >> i) & 0x7f) | ((32 - i) << 7);
7265 }
7266
7267 a = val & 0xff;
7268 if (val == ((a << 16) | a))
7269 return 0x100 | a;
7270 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7271 return 0x300 | a;
7272
7273 a = val & 0xff00;
7274 if (val == ((a << 16) | a))
7275 return 0x200 | (a >> 8);
7276
7277 return FAIL;
7278 }
7279 /* Encode a VFP SP or DP register number into inst.instruction. */
7280
7281 static void
7282 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7283 {
7284 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7285 && reg > 15)
7286 {
7287 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
7288 {
7289 if (thumb_mode)
7290 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7291 fpu_vfp_ext_d32);
7292 else
7293 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7294 fpu_vfp_ext_d32);
7295 }
7296 else
7297 {
7298 first_error (_("D register out of range for selected VFP version"));
7299 return;
7300 }
7301 }
7302
7303 switch (pos)
7304 {
7305 case VFP_REG_Sd:
7306 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7307 break;
7308
7309 case VFP_REG_Sn:
7310 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7311 break;
7312
7313 case VFP_REG_Sm:
7314 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7315 break;
7316
7317 case VFP_REG_Dd:
7318 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7319 break;
7320
7321 case VFP_REG_Dn:
7322 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7323 break;
7324
7325 case VFP_REG_Dm:
7326 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7327 break;
7328
7329 default:
7330 abort ();
7331 }
7332 }
7333
7334 /* Encode a <shift> in an ARM-format instruction. The immediate,
7335 if any, is handled by md_apply_fix. */
7336 static void
7337 encode_arm_shift (int i)
7338 {
7339 if (inst.operands[i].shift_kind == SHIFT_RRX)
7340 inst.instruction |= SHIFT_ROR << 5;
7341 else
7342 {
7343 inst.instruction |= inst.operands[i].shift_kind << 5;
7344 if (inst.operands[i].immisreg)
7345 {
7346 inst.instruction |= SHIFT_BY_REG;
7347 inst.instruction |= inst.operands[i].imm << 8;
7348 }
7349 else
7350 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7351 }
7352 }
7353
7354 static void
7355 encode_arm_shifter_operand (int i)
7356 {
7357 if (inst.operands[i].isreg)
7358 {
7359 inst.instruction |= inst.operands[i].reg;
7360 encode_arm_shift (i);
7361 }
7362 else
7363 {
7364 inst.instruction |= INST_IMMEDIATE;
7365 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7366 inst.instruction |= inst.operands[i].imm;
7367 }
7368 }
7369
7370 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
7371 static void
7372 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
7373 {
7374 /* PR 14260:
7375 Generate an error if the operand is not a register. */
7376 constraint (!inst.operands[i].isreg,
7377 _("Instruction does not support =N addresses"));
7378
7379 inst.instruction |= inst.operands[i].reg << 16;
7380
7381 if (inst.operands[i].preind)
7382 {
7383 if (is_t)
7384 {
7385 inst.error = _("instruction does not accept preindexed addressing");
7386 return;
7387 }
7388 inst.instruction |= PRE_INDEX;
7389 if (inst.operands[i].writeback)
7390 inst.instruction |= WRITE_BACK;
7391
7392 }
7393 else if (inst.operands[i].postind)
7394 {
7395 gas_assert (inst.operands[i].writeback);
7396 if (is_t)
7397 inst.instruction |= WRITE_BACK;
7398 }
7399 else /* unindexed - only for coprocessor */
7400 {
7401 inst.error = _("instruction does not accept unindexed addressing");
7402 return;
7403 }
7404
7405 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7406 && (((inst.instruction & 0x000f0000) >> 16)
7407 == ((inst.instruction & 0x0000f000) >> 12)))
7408 as_warn ((inst.instruction & LOAD_BIT)
7409 ? _("destination register same as write-back base")
7410 : _("source register same as write-back base"));
7411 }
7412
7413 /* inst.operands[i] was set up by parse_address. Encode it into an
7414 ARM-format mode 2 load or store instruction. If is_t is true,
7415 reject forms that cannot be used with a T instruction (i.e. not
7416 post-indexed). */
7417 static void
7418 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
7419 {
7420 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7421
7422 encode_arm_addr_mode_common (i, is_t);
7423
7424 if (inst.operands[i].immisreg)
7425 {
7426 constraint ((inst.operands[i].imm == REG_PC
7427 || (is_pc && inst.operands[i].writeback)),
7428 BAD_PC_ADDRESSING);
7429 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7430 inst.instruction |= inst.operands[i].imm;
7431 if (!inst.operands[i].negative)
7432 inst.instruction |= INDEX_UP;
7433 if (inst.operands[i].shifted)
7434 {
7435 if (inst.operands[i].shift_kind == SHIFT_RRX)
7436 inst.instruction |= SHIFT_ROR << 5;
7437 else
7438 {
7439 inst.instruction |= inst.operands[i].shift_kind << 5;
7440 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7441 }
7442 }
7443 }
7444 else /* immediate offset in inst.reloc */
7445 {
7446 if (is_pc && !inst.reloc.pc_rel)
7447 {
7448 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
7449
7450 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7451 cannot use PC in addressing.
7452 PC cannot be used in writeback addressing, either. */
7453 constraint ((is_t || inst.operands[i].writeback),
7454 BAD_PC_ADDRESSING);
7455
7456 /* Use of PC in str is deprecated for ARMv7. */
7457 if (warn_on_deprecated
7458 && !is_load
7459 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
7460 as_tsktsk (_("use of PC in this instruction is deprecated"));
7461 }
7462
7463 if (inst.reloc.type == BFD_RELOC_UNUSED)
7464 {
7465 /* Prefer + for zero encoded value. */
7466 if (!inst.operands[i].negative)
7467 inst.instruction |= INDEX_UP;
7468 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7469 }
7470 }
7471 }
7472
7473 /* inst.operands[i] was set up by parse_address. Encode it into an
7474 ARM-format mode 3 load or store instruction. Reject forms that
7475 cannot be used with such instructions. If is_t is true, reject
7476 forms that cannot be used with a T instruction (i.e. not
7477 post-indexed). */
7478 static void
7479 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
7480 {
7481 if (inst.operands[i].immisreg && inst.operands[i].shifted)
7482 {
7483 inst.error = _("instruction does not accept scaled register index");
7484 return;
7485 }
7486
7487 encode_arm_addr_mode_common (i, is_t);
7488
7489 if (inst.operands[i].immisreg)
7490 {
7491 constraint ((inst.operands[i].imm == REG_PC
7492 || (is_t && inst.operands[i].reg == REG_PC)),
7493 BAD_PC_ADDRESSING);
7494 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7495 BAD_PC_WRITEBACK);
7496 inst.instruction |= inst.operands[i].imm;
7497 if (!inst.operands[i].negative)
7498 inst.instruction |= INDEX_UP;
7499 }
7500 else /* immediate offset in inst.reloc */
7501 {
7502 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7503 && inst.operands[i].writeback),
7504 BAD_PC_WRITEBACK);
7505 inst.instruction |= HWOFFSET_IMM;
7506 if (inst.reloc.type == BFD_RELOC_UNUSED)
7507 {
7508 /* Prefer + for zero encoded value. */
7509 if (!inst.operands[i].negative)
7510 inst.instruction |= INDEX_UP;
7511
7512 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7513 }
7514 }
7515 }
7516
7517 /* Write immediate bits [7:0] to the following locations:
7518
7519 |28/24|23 19|18 16|15 4|3 0|
7520 | 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|
7521
7522 This function is used by VMOV/VMVN/VORR/VBIC. */
7523
7524 static void
7525 neon_write_immbits (unsigned immbits)
7526 {
7527 inst.instruction |= immbits & 0xf;
7528 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7529 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7530 }
7531
7532 /* Invert low-order SIZE bits of XHI:XLO. */
7533
7534 static void
7535 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7536 {
7537 unsigned immlo = xlo ? *xlo : 0;
7538 unsigned immhi = xhi ? *xhi : 0;
7539
7540 switch (size)
7541 {
7542 case 8:
7543 immlo = (~immlo) & 0xff;
7544 break;
7545
7546 case 16:
7547 immlo = (~immlo) & 0xffff;
7548 break;
7549
7550 case 64:
7551 immhi = (~immhi) & 0xffffffff;
7552 /* fall through. */
7553
7554 case 32:
7555 immlo = (~immlo) & 0xffffffff;
7556 break;
7557
7558 default:
7559 abort ();
7560 }
7561
7562 if (xlo)
7563 *xlo = immlo;
7564
7565 if (xhi)
7566 *xhi = immhi;
7567 }
7568
7569 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7570 A, B, C, D. */
7571
7572 static int
7573 neon_bits_same_in_bytes (unsigned imm)
7574 {
7575 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7576 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7577 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7578 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7579 }
7580
7581 /* For immediate of above form, return 0bABCD. */
7582
7583 static unsigned
7584 neon_squash_bits (unsigned imm)
7585 {
7586 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7587 | ((imm & 0x01000000) >> 21);
7588 }
7589
7590 /* Compress quarter-float representation to 0b...000 abcdefgh. */
7591
7592 static unsigned
7593 neon_qfloat_bits (unsigned imm)
7594 {
7595 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7596 }
7597
7598 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7599 the instruction. *OP is passed as the initial value of the op field, and
7600 may be set to a different value depending on the constant (i.e.
7601 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7602 MVN). If the immediate looks like a repeated pattern then also
7603 try smaller element sizes. */
7604
7605 static int
7606 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7607 unsigned *immbits, int *op, int size,
7608 enum neon_el_type type)
7609 {
7610 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7611 float. */
7612 if (type == NT_float && !float_p)
7613 return FAIL;
7614
7615 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
7616 {
7617 if (size != 32 || *op == 1)
7618 return FAIL;
7619 *immbits = neon_qfloat_bits (immlo);
7620 return 0xf;
7621 }
7622
7623 if (size == 64)
7624 {
7625 if (neon_bits_same_in_bytes (immhi)
7626 && neon_bits_same_in_bytes (immlo))
7627 {
7628 if (*op == 1)
7629 return FAIL;
7630 *immbits = (neon_squash_bits (immhi) << 4)
7631 | neon_squash_bits (immlo);
7632 *op = 1;
7633 return 0xe;
7634 }
7635
7636 if (immhi != immlo)
7637 return FAIL;
7638 }
7639
7640 if (size >= 32)
7641 {
7642 if (immlo == (immlo & 0x000000ff))
7643 {
7644 *immbits = immlo;
7645 return 0x0;
7646 }
7647 else if (immlo == (immlo & 0x0000ff00))
7648 {
7649 *immbits = immlo >> 8;
7650 return 0x2;
7651 }
7652 else if (immlo == (immlo & 0x00ff0000))
7653 {
7654 *immbits = immlo >> 16;
7655 return 0x4;
7656 }
7657 else if (immlo == (immlo & 0xff000000))
7658 {
7659 *immbits = immlo >> 24;
7660 return 0x6;
7661 }
7662 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7663 {
7664 *immbits = (immlo >> 8) & 0xff;
7665 return 0xc;
7666 }
7667 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7668 {
7669 *immbits = (immlo >> 16) & 0xff;
7670 return 0xd;
7671 }
7672
7673 if ((immlo & 0xffff) != (immlo >> 16))
7674 return FAIL;
7675 immlo &= 0xffff;
7676 }
7677
7678 if (size >= 16)
7679 {
7680 if (immlo == (immlo & 0x000000ff))
7681 {
7682 *immbits = immlo;
7683 return 0x8;
7684 }
7685 else if (immlo == (immlo & 0x0000ff00))
7686 {
7687 *immbits = immlo >> 8;
7688 return 0xa;
7689 }
7690
7691 if ((immlo & 0xff) != (immlo >> 8))
7692 return FAIL;
7693 immlo &= 0xff;
7694 }
7695
7696 if (immlo == (immlo & 0x000000ff))
7697 {
7698 /* Don't allow MVN with 8-bit immediate. */
7699 if (*op == 1)
7700 return FAIL;
7701 *immbits = immlo;
7702 return 0xe;
7703 }
7704
7705 return FAIL;
7706 }
7707
7708 #if defined BFD_HOST_64_BIT
7709 /* Returns TRUE if double precision value V may be cast
7710 to single precision without loss of accuracy. */
7711
7712 static bfd_boolean
7713 is_double_a_single (bfd_int64_t v)
7714 {
7715 int exp = (int)((v >> 52) & 0x7FF);
7716 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
7717
7718 return (exp == 0 || exp == 0x7FF
7719 || (exp >= 1023 - 126 && exp <= 1023 + 127))
7720 && (mantissa & 0x1FFFFFFFl) == 0;
7721 }
7722
7723 /* Returns a double precision value casted to single precision
7724 (ignoring the least significant bits in exponent and mantissa). */
7725
7726 static int
7727 double_to_single (bfd_int64_t v)
7728 {
7729 int sign = (int) ((v >> 63) & 1l);
7730 int exp = (int) ((v >> 52) & 0x7FF);
7731 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
7732
7733 if (exp == 0x7FF)
7734 exp = 0xFF;
7735 else
7736 {
7737 exp = exp - 1023 + 127;
7738 if (exp >= 0xFF)
7739 {
7740 /* Infinity. */
7741 exp = 0x7F;
7742 mantissa = 0;
7743 }
7744 else if (exp < 0)
7745 {
7746 /* No denormalized numbers. */
7747 exp = 0;
7748 mantissa = 0;
7749 }
7750 }
7751 mantissa >>= 29;
7752 return (sign << 31) | (exp << 23) | mantissa;
7753 }
7754 #endif /* BFD_HOST_64_BIT */
7755
7756 enum lit_type
7757 {
7758 CONST_THUMB,
7759 CONST_ARM,
7760 CONST_VEC
7761 };
7762
7763 static void do_vfp_nsyn_opcode (const char *);
7764
7765 /* inst.reloc.exp describes an "=expr" load pseudo-operation.
7766 Determine whether it can be performed with a move instruction; if
7767 it can, convert inst.instruction to that move instruction and
7768 return TRUE; if it can't, convert inst.instruction to a literal-pool
7769 load and return FALSE. If this is not a valid thing to do in the
7770 current context, set inst.error and return TRUE.
7771
7772 inst.operands[i] describes the destination register. */
7773
7774 static bfd_boolean
7775 move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
7776 {
7777 unsigned long tbit;
7778 bfd_boolean thumb_p = (t == CONST_THUMB);
7779 bfd_boolean arm_p = (t == CONST_ARM);
7780
7781 if (thumb_p)
7782 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7783 else
7784 tbit = LOAD_BIT;
7785
7786 if ((inst.instruction & tbit) == 0)
7787 {
7788 inst.error = _("invalid pseudo operation");
7789 return TRUE;
7790 }
7791
7792 if (inst.reloc.exp.X_op != O_constant
7793 && inst.reloc.exp.X_op != O_symbol
7794 && inst.reloc.exp.X_op != O_big)
7795 {
7796 inst.error = _("constant expression expected");
7797 return TRUE;
7798 }
7799
7800 if (inst.reloc.exp.X_op == O_constant
7801 || inst.reloc.exp.X_op == O_big)
7802 {
7803 #if defined BFD_HOST_64_BIT
7804 bfd_int64_t v;
7805 #else
7806 offsetT v;
7807 #endif
7808 if (inst.reloc.exp.X_op == O_big)
7809 {
7810 LITTLENUM_TYPE w[X_PRECISION];
7811 LITTLENUM_TYPE * l;
7812
7813 if (inst.reloc.exp.X_add_number == -1)
7814 {
7815 gen_to_words (w, X_PRECISION, E_PRECISION);
7816 l = w;
7817 /* FIXME: Should we check words w[2..5] ? */
7818 }
7819 else
7820 l = generic_bignum;
7821
7822 #if defined BFD_HOST_64_BIT
7823 v =
7824 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
7825 << LITTLENUM_NUMBER_OF_BITS)
7826 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
7827 << LITTLENUM_NUMBER_OF_BITS)
7828 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
7829 << LITTLENUM_NUMBER_OF_BITS)
7830 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
7831 #else
7832 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
7833 | (l[0] & LITTLENUM_MASK);
7834 #endif
7835 }
7836 else
7837 v = inst.reloc.exp.X_add_number;
7838
7839 if (!inst.operands[i].issingle)
7840 {
7841 if (thumb_p)
7842 {
7843 if ((v & ~0xFF) == 0)
7844 {
7845 /* This can be done with a mov(1) instruction. */
7846 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7847 inst.instruction |= v;
7848 return TRUE;
7849 }
7850
7851 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)
7852 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
7853 {
7854 /* Check if on thumb2 it can be done with a mov.w or mvn.w instruction. */
7855 unsigned int newimm;
7856 bfd_boolean isNegated;
7857
7858 newimm = encode_thumb32_immediate (v);
7859 if (newimm != (unsigned int) FAIL)
7860 isNegated = FALSE;
7861 else
7862 {
7863 newimm = encode_thumb32_immediate (~ v);
7864 if (newimm != (unsigned int) FAIL)
7865 isNegated = TRUE;
7866 }
7867
7868 if (newimm != (unsigned int) FAIL)
7869 {
7870 inst.instruction = 0xf04f0000 | (inst.operands[i].reg << 8);
7871 inst.instruction |= (isNegated?0x200000:0);
7872 inst.instruction |= (newimm & 0x800) << 15;
7873 inst.instruction |= (newimm & 0x700) << 4;
7874 inst.instruction |= (newimm & 0x0ff);
7875 return TRUE;
7876 }
7877 else if ((v & ~0xFFFF) == 0 || (v & ~0xFFFF0000) == 0)
7878 {
7879 /* The number may be loaded with a movw/movt instruction. */
7880 int imm;
7881
7882 if ((inst.reloc.exp.X_add_number & ~0xFFFF) == 0)
7883 {
7884 inst.instruction= 0xf2400000;
7885 imm = v;
7886 }
7887 else
7888 {
7889 inst.instruction = 0xf2c00000;
7890 imm = v >> 16;
7891 }
7892
7893 inst.instruction |= (inst.operands[i].reg << 8);
7894 inst.instruction |= (imm & 0xf000) << 4;
7895 inst.instruction |= (imm & 0x0800) << 15;
7896 inst.instruction |= (imm & 0x0700) << 4;
7897 inst.instruction |= (imm & 0x00ff);
7898 return TRUE;
7899 }
7900 }
7901 }
7902 else if (arm_p)
7903 {
7904 int value = encode_arm_immediate (v);
7905
7906 if (value != FAIL)
7907 {
7908 /* This can be done with a mov instruction. */
7909 inst.instruction &= LITERAL_MASK;
7910 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7911 inst.instruction |= value & 0xfff;
7912 return TRUE;
7913 }
7914
7915 value = encode_arm_immediate (~ v);
7916 if (value != FAIL)
7917 {
7918 /* This can be done with a mvn instruction. */
7919 inst.instruction &= LITERAL_MASK;
7920 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
7921 inst.instruction |= value & 0xfff;
7922 return TRUE;
7923 }
7924 }
7925 else if (t == CONST_VEC)
7926 {
7927 int op = 0;
7928 unsigned immbits = 0;
7929 unsigned immlo = inst.operands[1].imm;
7930 unsigned immhi = inst.operands[1].regisimm
7931 ? inst.operands[1].reg
7932 : inst.reloc.exp.X_unsigned
7933 ? 0
7934 : ((bfd_int64_t)((int) immlo)) >> 32;
7935 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
7936 &op, 64, NT_invtype);
7937
7938 if (cmode == FAIL)
7939 {
7940 neon_invert_size (&immlo, &immhi, 64);
7941 op = !op;
7942 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
7943 &op, 64, NT_invtype);
7944 }
7945
7946 if (cmode != FAIL)
7947 {
7948 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
7949 | (1 << 23)
7950 | (cmode << 8)
7951 | (op << 5)
7952 | (1 << 4);
7953
7954 /* Fill other bits in vmov encoding for both thumb and arm. */
7955 if (thumb_mode)
7956 inst.instruction |= (0x7U << 29) | (0xF << 24);
7957 else
7958 inst.instruction |= (0xFU << 28) | (0x1 << 25);
7959 neon_write_immbits (immbits);
7960 return TRUE;
7961 }
7962 }
7963 }
7964
7965 if (t == CONST_VEC)
7966 {
7967 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
7968 if (inst.operands[i].issingle
7969 && is_quarter_float (inst.operands[1].imm)
7970 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
7971 {
7972 inst.operands[1].imm =
7973 neon_qfloat_bits (v);
7974 do_vfp_nsyn_opcode ("fconsts");
7975 return TRUE;
7976 }
7977
7978 /* If our host does not support a 64-bit type then we cannot perform
7979 the following optimization. This mean that there will be a
7980 discrepancy between the output produced by an assembler built for
7981 a 32-bit-only host and the output produced from a 64-bit host, but
7982 this cannot be helped. */
7983 #if defined BFD_HOST_64_BIT
7984 else if (!inst.operands[1].issingle
7985 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
7986 {
7987 if (is_double_a_single (v)
7988 && is_quarter_float (double_to_single (v)))
7989 {
7990 inst.operands[1].imm =
7991 neon_qfloat_bits (double_to_single (v));
7992 do_vfp_nsyn_opcode ("fconstd");
7993 return TRUE;
7994 }
7995 }
7996 #endif
7997 }
7998 }
7999
8000 if (add_to_lit_pool ((!inst.operands[i].isvec
8001 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8002 return TRUE;
8003
8004 inst.operands[1].reg = REG_PC;
8005 inst.operands[1].isreg = 1;
8006 inst.operands[1].preind = 1;
8007 inst.reloc.pc_rel = 1;
8008 inst.reloc.type = (thumb_p
8009 ? BFD_RELOC_ARM_THUMB_OFFSET
8010 : (mode_3
8011 ? BFD_RELOC_ARM_HWLITERAL
8012 : BFD_RELOC_ARM_LITERAL));
8013 return FALSE;
8014 }
8015
8016 /* inst.operands[i] was set up by parse_address. Encode it into an
8017 ARM-format instruction. Reject all forms which cannot be encoded
8018 into a coprocessor load/store instruction. If wb_ok is false,
8019 reject use of writeback; if unind_ok is false, reject use of
8020 unindexed addressing. If reloc_override is not 0, use it instead
8021 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8022 (in which case it is preserved). */
8023
8024 static int
8025 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8026 {
8027 if (!inst.operands[i].isreg)
8028 {
8029 /* PR 18256 */
8030 if (! inst.operands[0].isvec)
8031 {
8032 inst.error = _("invalid co-processor operand");
8033 return FAIL;
8034 }
8035 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8036 return SUCCESS;
8037 }
8038
8039 inst.instruction |= inst.operands[i].reg << 16;
8040
8041 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8042
8043 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8044 {
8045 gas_assert (!inst.operands[i].writeback);
8046 if (!unind_ok)
8047 {
8048 inst.error = _("instruction does not support unindexed addressing");
8049 return FAIL;
8050 }
8051 inst.instruction |= inst.operands[i].imm;
8052 inst.instruction |= INDEX_UP;
8053 return SUCCESS;
8054 }
8055
8056 if (inst.operands[i].preind)
8057 inst.instruction |= PRE_INDEX;
8058
8059 if (inst.operands[i].writeback)
8060 {
8061 if (inst.operands[i].reg == REG_PC)
8062 {
8063 inst.error = _("pc may not be used with write-back");
8064 return FAIL;
8065 }
8066 if (!wb_ok)
8067 {
8068 inst.error = _("instruction does not support writeback");
8069 return FAIL;
8070 }
8071 inst.instruction |= WRITE_BACK;
8072 }
8073
8074 if (reloc_override)
8075 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
8076 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
8077 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
8078 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
8079 {
8080 if (thumb_mode)
8081 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8082 else
8083 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
8084 }
8085
8086 /* Prefer + for zero encoded value. */
8087 if (!inst.operands[i].negative)
8088 inst.instruction |= INDEX_UP;
8089
8090 return SUCCESS;
8091 }
8092
8093 /* Functions for instruction encoding, sorted by sub-architecture.
8094 First some generics; their names are taken from the conventional
8095 bit positions for register arguments in ARM format instructions. */
8096
8097 static void
8098 do_noargs (void)
8099 {
8100 }
8101
8102 static void
8103 do_rd (void)
8104 {
8105 inst.instruction |= inst.operands[0].reg << 12;
8106 }
8107
8108 static void
8109 do_rd_rm (void)
8110 {
8111 inst.instruction |= inst.operands[0].reg << 12;
8112 inst.instruction |= inst.operands[1].reg;
8113 }
8114
8115 static void
8116 do_rm_rn (void)
8117 {
8118 inst.instruction |= inst.operands[0].reg;
8119 inst.instruction |= inst.operands[1].reg << 16;
8120 }
8121
8122 static void
8123 do_rd_rn (void)
8124 {
8125 inst.instruction |= inst.operands[0].reg << 12;
8126 inst.instruction |= inst.operands[1].reg << 16;
8127 }
8128
8129 static void
8130 do_rn_rd (void)
8131 {
8132 inst.instruction |= inst.operands[0].reg << 16;
8133 inst.instruction |= inst.operands[1].reg << 12;
8134 }
8135
8136 static bfd_boolean
8137 check_obsolete (const arm_feature_set *feature, const char *msg)
8138 {
8139 if (ARM_CPU_IS_ANY (cpu_variant))
8140 {
8141 as_tsktsk ("%s", msg);
8142 return TRUE;
8143 }
8144 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8145 {
8146 as_bad ("%s", msg);
8147 return TRUE;
8148 }
8149
8150 return FALSE;
8151 }
8152
8153 static void
8154 do_rd_rm_rn (void)
8155 {
8156 unsigned Rn = inst.operands[2].reg;
8157 /* Enforce restrictions on SWP instruction. */
8158 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
8159 {
8160 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8161 _("Rn must not overlap other operands"));
8162
8163 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8164 */
8165 if (!check_obsolete (&arm_ext_v8,
8166 _("swp{b} use is obsoleted for ARMv8 and later"))
8167 && warn_on_deprecated
8168 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
8169 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
8170 }
8171
8172 inst.instruction |= inst.operands[0].reg << 12;
8173 inst.instruction |= inst.operands[1].reg;
8174 inst.instruction |= Rn << 16;
8175 }
8176
8177 static void
8178 do_rd_rn_rm (void)
8179 {
8180 inst.instruction |= inst.operands[0].reg << 12;
8181 inst.instruction |= inst.operands[1].reg << 16;
8182 inst.instruction |= inst.operands[2].reg;
8183 }
8184
8185 static void
8186 do_rm_rd_rn (void)
8187 {
8188 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
8189 constraint (((inst.reloc.exp.X_op != O_constant
8190 && inst.reloc.exp.X_op != O_illegal)
8191 || inst.reloc.exp.X_add_number != 0),
8192 BAD_ADDR_MODE);
8193 inst.instruction |= inst.operands[0].reg;
8194 inst.instruction |= inst.operands[1].reg << 12;
8195 inst.instruction |= inst.operands[2].reg << 16;
8196 }
8197
8198 static void
8199 do_imm0 (void)
8200 {
8201 inst.instruction |= inst.operands[0].imm;
8202 }
8203
8204 static void
8205 do_rd_cpaddr (void)
8206 {
8207 inst.instruction |= inst.operands[0].reg << 12;
8208 encode_arm_cp_address (1, TRUE, TRUE, 0);
8209 }
8210
8211 /* ARM instructions, in alphabetical order by function name (except
8212 that wrapper functions appear immediately after the function they
8213 wrap). */
8214
8215 /* This is a pseudo-op of the form "adr rd, label" to be converted
8216 into a relative address of the form "add rd, pc, #label-.-8". */
8217
8218 static void
8219 do_adr (void)
8220 {
8221 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
8222
8223 /* Frag hacking will turn this into a sub instruction if the offset turns
8224 out to be negative. */
8225 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
8226 inst.reloc.pc_rel = 1;
8227 inst.reloc.exp.X_add_number -= 8;
8228 }
8229
8230 /* This is a pseudo-op of the form "adrl rd, label" to be converted
8231 into a relative address of the form:
8232 add rd, pc, #low(label-.-8)"
8233 add rd, rd, #high(label-.-8)" */
8234
8235 static void
8236 do_adrl (void)
8237 {
8238 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
8239
8240 /* Frag hacking will turn this into a sub instruction if the offset turns
8241 out to be negative. */
8242 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
8243 inst.reloc.pc_rel = 1;
8244 inst.size = INSN_SIZE * 2;
8245 inst.reloc.exp.X_add_number -= 8;
8246 }
8247
8248 static void
8249 do_arit (void)
8250 {
8251 if (!inst.operands[1].present)
8252 inst.operands[1].reg = inst.operands[0].reg;
8253 inst.instruction |= inst.operands[0].reg << 12;
8254 inst.instruction |= inst.operands[1].reg << 16;
8255 encode_arm_shifter_operand (2);
8256 }
8257
8258 static void
8259 do_barrier (void)
8260 {
8261 if (inst.operands[0].present)
8262 inst.instruction |= inst.operands[0].imm;
8263 else
8264 inst.instruction |= 0xf;
8265 }
8266
8267 static void
8268 do_bfc (void)
8269 {
8270 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8271 constraint (msb > 32, _("bit-field extends past end of register"));
8272 /* The instruction encoding stores the LSB and MSB,
8273 not the LSB and width. */
8274 inst.instruction |= inst.operands[0].reg << 12;
8275 inst.instruction |= inst.operands[1].imm << 7;
8276 inst.instruction |= (msb - 1) << 16;
8277 }
8278
8279 static void
8280 do_bfi (void)
8281 {
8282 unsigned int msb;
8283
8284 /* #0 in second position is alternative syntax for bfc, which is
8285 the same instruction but with REG_PC in the Rm field. */
8286 if (!inst.operands[1].isreg)
8287 inst.operands[1].reg = REG_PC;
8288
8289 msb = inst.operands[2].imm + inst.operands[3].imm;
8290 constraint (msb > 32, _("bit-field extends past end of register"));
8291 /* The instruction encoding stores the LSB and MSB,
8292 not the LSB and width. */
8293 inst.instruction |= inst.operands[0].reg << 12;
8294 inst.instruction |= inst.operands[1].reg;
8295 inst.instruction |= inst.operands[2].imm << 7;
8296 inst.instruction |= (msb - 1) << 16;
8297 }
8298
8299 static void
8300 do_bfx (void)
8301 {
8302 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8303 _("bit-field extends past end of register"));
8304 inst.instruction |= inst.operands[0].reg << 12;
8305 inst.instruction |= inst.operands[1].reg;
8306 inst.instruction |= inst.operands[2].imm << 7;
8307 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8308 }
8309
8310 /* ARM V5 breakpoint instruction (argument parse)
8311 BKPT <16 bit unsigned immediate>
8312 Instruction is not conditional.
8313 The bit pattern given in insns[] has the COND_ALWAYS condition,
8314 and it is an error if the caller tried to override that. */
8315
8316 static void
8317 do_bkpt (void)
8318 {
8319 /* Top 12 of 16 bits to bits 19:8. */
8320 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
8321
8322 /* Bottom 4 of 16 bits to bits 3:0. */
8323 inst.instruction |= inst.operands[0].imm & 0xf;
8324 }
8325
8326 static void
8327 encode_branch (int default_reloc)
8328 {
8329 if (inst.operands[0].hasreloc)
8330 {
8331 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8332 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8333 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
8334 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
8335 ? BFD_RELOC_ARM_PLT32
8336 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
8337 }
8338 else
8339 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
8340 inst.reloc.pc_rel = 1;
8341 }
8342
8343 static void
8344 do_branch (void)
8345 {
8346 #ifdef OBJ_ELF
8347 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8348 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8349 else
8350 #endif
8351 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8352 }
8353
8354 static void
8355 do_bl (void)
8356 {
8357 #ifdef OBJ_ELF
8358 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8359 {
8360 if (inst.cond == COND_ALWAYS)
8361 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8362 else
8363 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8364 }
8365 else
8366 #endif
8367 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8368 }
8369
8370 /* ARM V5 branch-link-exchange instruction (argument parse)
8371 BLX <target_addr> ie BLX(1)
8372 BLX{<condition>} <Rm> ie BLX(2)
8373 Unfortunately, there are two different opcodes for this mnemonic.
8374 So, the insns[].value is not used, and the code here zaps values
8375 into inst.instruction.
8376 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
8377
8378 static void
8379 do_blx (void)
8380 {
8381 if (inst.operands[0].isreg)
8382 {
8383 /* Arg is a register; the opcode provided by insns[] is correct.
8384 It is not illegal to do "blx pc", just useless. */
8385 if (inst.operands[0].reg == REG_PC)
8386 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
8387
8388 inst.instruction |= inst.operands[0].reg;
8389 }
8390 else
8391 {
8392 /* Arg is an address; this instruction cannot be executed
8393 conditionally, and the opcode must be adjusted.
8394 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8395 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
8396 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8397 inst.instruction = 0xfa000000;
8398 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
8399 }
8400 }
8401
8402 static void
8403 do_bx (void)
8404 {
8405 bfd_boolean want_reloc;
8406
8407 if (inst.operands[0].reg == REG_PC)
8408 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
8409
8410 inst.instruction |= inst.operands[0].reg;
8411 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8412 it is for ARMv4t or earlier. */
8413 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
8414 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
8415 want_reloc = TRUE;
8416
8417 #ifdef OBJ_ELF
8418 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
8419 #endif
8420 want_reloc = FALSE;
8421
8422 if (want_reloc)
8423 inst.reloc.type = BFD_RELOC_ARM_V4BX;
8424 }
8425
8426
8427 /* ARM v5TEJ. Jump to Jazelle code. */
8428
8429 static void
8430 do_bxj (void)
8431 {
8432 if (inst.operands[0].reg == REG_PC)
8433 as_tsktsk (_("use of r15 in bxj is not really useful"));
8434
8435 inst.instruction |= inst.operands[0].reg;
8436 }
8437
8438 /* Co-processor data operation:
8439 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8440 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8441 static void
8442 do_cdp (void)
8443 {
8444 inst.instruction |= inst.operands[0].reg << 8;
8445 inst.instruction |= inst.operands[1].imm << 20;
8446 inst.instruction |= inst.operands[2].reg << 12;
8447 inst.instruction |= inst.operands[3].reg << 16;
8448 inst.instruction |= inst.operands[4].reg;
8449 inst.instruction |= inst.operands[5].imm << 5;
8450 }
8451
8452 static void
8453 do_cmp (void)
8454 {
8455 inst.instruction |= inst.operands[0].reg << 16;
8456 encode_arm_shifter_operand (1);
8457 }
8458
8459 /* Transfer between coprocessor and ARM registers.
8460 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8461 MRC2
8462 MCR{cond}
8463 MCR2
8464
8465 No special properties. */
8466
8467 struct deprecated_coproc_regs_s
8468 {
8469 unsigned cp;
8470 int opc1;
8471 unsigned crn;
8472 unsigned crm;
8473 int opc2;
8474 arm_feature_set deprecated;
8475 arm_feature_set obsoleted;
8476 const char *dep_msg;
8477 const char *obs_msg;
8478 };
8479
8480 #define DEPR_ACCESS_V8 \
8481 N_("This coprocessor register access is deprecated in ARMv8")
8482
8483 /* Table of all deprecated coprocessor registers. */
8484 static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8485 {
8486 {15, 0, 7, 10, 5, /* CP15DMB. */
8487 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
8488 DEPR_ACCESS_V8, NULL},
8489 {15, 0, 7, 10, 4, /* CP15DSB. */
8490 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
8491 DEPR_ACCESS_V8, NULL},
8492 {15, 0, 7, 5, 4, /* CP15ISB. */
8493 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
8494 DEPR_ACCESS_V8, NULL},
8495 {14, 6, 1, 0, 0, /* TEEHBR. */
8496 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
8497 DEPR_ACCESS_V8, NULL},
8498 {14, 6, 0, 0, 0, /* TEECR. */
8499 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
8500 DEPR_ACCESS_V8, NULL},
8501 };
8502
8503 #undef DEPR_ACCESS_V8
8504
8505 static const size_t deprecated_coproc_reg_count =
8506 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8507
8508 static void
8509 do_co_reg (void)
8510 {
8511 unsigned Rd;
8512 size_t i;
8513
8514 Rd = inst.operands[2].reg;
8515 if (thumb_mode)
8516 {
8517 if (inst.instruction == 0xee000010
8518 || inst.instruction == 0xfe000010)
8519 /* MCR, MCR2 */
8520 reject_bad_reg (Rd);
8521 else
8522 /* MRC, MRC2 */
8523 constraint (Rd == REG_SP, BAD_SP);
8524 }
8525 else
8526 {
8527 /* MCR */
8528 if (inst.instruction == 0xe000010)
8529 constraint (Rd == REG_PC, BAD_PC);
8530 }
8531
8532 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8533 {
8534 const struct deprecated_coproc_regs_s *r =
8535 deprecated_coproc_regs + i;
8536
8537 if (inst.operands[0].reg == r->cp
8538 && inst.operands[1].imm == r->opc1
8539 && inst.operands[3].reg == r->crn
8540 && inst.operands[4].reg == r->crm
8541 && inst.operands[5].imm == r->opc2)
8542 {
8543 if (! ARM_CPU_IS_ANY (cpu_variant)
8544 && warn_on_deprecated
8545 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
8546 as_tsktsk ("%s", r->dep_msg);
8547 }
8548 }
8549
8550 inst.instruction |= inst.operands[0].reg << 8;
8551 inst.instruction |= inst.operands[1].imm << 21;
8552 inst.instruction |= Rd << 12;
8553 inst.instruction |= inst.operands[3].reg << 16;
8554 inst.instruction |= inst.operands[4].reg;
8555 inst.instruction |= inst.operands[5].imm << 5;
8556 }
8557
8558 /* Transfer between coprocessor register and pair of ARM registers.
8559 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8560 MCRR2
8561 MRRC{cond}
8562 MRRC2
8563
8564 Two XScale instructions are special cases of these:
8565
8566 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8567 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
8568
8569 Result unpredictable if Rd or Rn is R15. */
8570
8571 static void
8572 do_co_reg2c (void)
8573 {
8574 unsigned Rd, Rn;
8575
8576 Rd = inst.operands[2].reg;
8577 Rn = inst.operands[3].reg;
8578
8579 if (thumb_mode)
8580 {
8581 reject_bad_reg (Rd);
8582 reject_bad_reg (Rn);
8583 }
8584 else
8585 {
8586 constraint (Rd == REG_PC, BAD_PC);
8587 constraint (Rn == REG_PC, BAD_PC);
8588 }
8589
8590 inst.instruction |= inst.operands[0].reg << 8;
8591 inst.instruction |= inst.operands[1].imm << 4;
8592 inst.instruction |= Rd << 12;
8593 inst.instruction |= Rn << 16;
8594 inst.instruction |= inst.operands[4].reg;
8595 }
8596
8597 static void
8598 do_cpsi (void)
8599 {
8600 inst.instruction |= inst.operands[0].imm << 6;
8601 if (inst.operands[1].present)
8602 {
8603 inst.instruction |= CPSI_MMOD;
8604 inst.instruction |= inst.operands[1].imm;
8605 }
8606 }
8607
8608 static void
8609 do_dbg (void)
8610 {
8611 inst.instruction |= inst.operands[0].imm;
8612 }
8613
8614 static void
8615 do_div (void)
8616 {
8617 unsigned Rd, Rn, Rm;
8618
8619 Rd = inst.operands[0].reg;
8620 Rn = (inst.operands[1].present
8621 ? inst.operands[1].reg : Rd);
8622 Rm = inst.operands[2].reg;
8623
8624 constraint ((Rd == REG_PC), BAD_PC);
8625 constraint ((Rn == REG_PC), BAD_PC);
8626 constraint ((Rm == REG_PC), BAD_PC);
8627
8628 inst.instruction |= Rd << 16;
8629 inst.instruction |= Rn << 0;
8630 inst.instruction |= Rm << 8;
8631 }
8632
8633 static void
8634 do_it (void)
8635 {
8636 /* There is no IT instruction in ARM mode. We
8637 process it to do the validation as if in
8638 thumb mode, just in case the code gets
8639 assembled for thumb using the unified syntax. */
8640
8641 inst.size = 0;
8642 if (unified_syntax)
8643 {
8644 set_it_insn_type (IT_INSN);
8645 now_it.mask = (inst.instruction & 0xf) | 0x10;
8646 now_it.cc = inst.operands[0].imm;
8647 }
8648 }
8649
8650 /* If there is only one register in the register list,
8651 then return its register number. Otherwise return -1. */
8652 static int
8653 only_one_reg_in_list (int range)
8654 {
8655 int i = ffs (range) - 1;
8656 return (i > 15 || range != (1 << i)) ? -1 : i;
8657 }
8658
8659 static void
8660 encode_ldmstm(int from_push_pop_mnem)
8661 {
8662 int base_reg = inst.operands[0].reg;
8663 int range = inst.operands[1].imm;
8664 int one_reg;
8665
8666 inst.instruction |= base_reg << 16;
8667 inst.instruction |= range;
8668
8669 if (inst.operands[1].writeback)
8670 inst.instruction |= LDM_TYPE_2_OR_3;
8671
8672 if (inst.operands[0].writeback)
8673 {
8674 inst.instruction |= WRITE_BACK;
8675 /* Check for unpredictable uses of writeback. */
8676 if (inst.instruction & LOAD_BIT)
8677 {
8678 /* Not allowed in LDM type 2. */
8679 if ((inst.instruction & LDM_TYPE_2_OR_3)
8680 && ((range & (1 << REG_PC)) == 0))
8681 as_warn (_("writeback of base register is UNPREDICTABLE"));
8682 /* Only allowed if base reg not in list for other types. */
8683 else if (range & (1 << base_reg))
8684 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8685 }
8686 else /* STM. */
8687 {
8688 /* Not allowed for type 2. */
8689 if (inst.instruction & LDM_TYPE_2_OR_3)
8690 as_warn (_("writeback of base register is UNPREDICTABLE"));
8691 /* Only allowed if base reg not in list, or first in list. */
8692 else if ((range & (1 << base_reg))
8693 && (range & ((1 << base_reg) - 1)))
8694 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
8695 }
8696 }
8697
8698 /* If PUSH/POP has only one register, then use the A2 encoding. */
8699 one_reg = only_one_reg_in_list (range);
8700 if (from_push_pop_mnem && one_reg >= 0)
8701 {
8702 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8703
8704 inst.instruction &= A_COND_MASK;
8705 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8706 inst.instruction |= one_reg << 12;
8707 }
8708 }
8709
8710 static void
8711 do_ldmstm (void)
8712 {
8713 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
8714 }
8715
8716 /* ARMv5TE load-consecutive (argument parse)
8717 Mode is like LDRH.
8718
8719 LDRccD R, mode
8720 STRccD R, mode. */
8721
8722 static void
8723 do_ldrd (void)
8724 {
8725 constraint (inst.operands[0].reg % 2 != 0,
8726 _("first transfer register must be even"));
8727 constraint (inst.operands[1].present
8728 && inst.operands[1].reg != inst.operands[0].reg + 1,
8729 _("can only transfer two consecutive registers"));
8730 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8731 constraint (!inst.operands[2].isreg, _("'[' expected"));
8732
8733 if (!inst.operands[1].present)
8734 inst.operands[1].reg = inst.operands[0].reg + 1;
8735
8736 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8737 register and the first register written; we have to diagnose
8738 overlap between the base and the second register written here. */
8739
8740 if (inst.operands[2].reg == inst.operands[1].reg
8741 && (inst.operands[2].writeback || inst.operands[2].postind))
8742 as_warn (_("base register written back, and overlaps "
8743 "second transfer register"));
8744
8745 if (!(inst.instruction & V4_STR_BIT))
8746 {
8747 /* For an index-register load, the index register must not overlap the
8748 destination (even if not write-back). */
8749 if (inst.operands[2].immisreg
8750 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8751 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8752 as_warn (_("index register overlaps transfer register"));
8753 }
8754 inst.instruction |= inst.operands[0].reg << 12;
8755 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
8756 }
8757
8758 static void
8759 do_ldrex (void)
8760 {
8761 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8762 || inst.operands[1].postind || inst.operands[1].writeback
8763 || inst.operands[1].immisreg || inst.operands[1].shifted
8764 || inst.operands[1].negative
8765 /* This can arise if the programmer has written
8766 strex rN, rM, foo
8767 or if they have mistakenly used a register name as the last
8768 operand, eg:
8769 strex rN, rM, rX
8770 It is very difficult to distinguish between these two cases
8771 because "rX" might actually be a label. ie the register
8772 name has been occluded by a symbol of the same name. So we
8773 just generate a general 'bad addressing mode' type error
8774 message and leave it up to the programmer to discover the
8775 true cause and fix their mistake. */
8776 || (inst.operands[1].reg == REG_PC),
8777 BAD_ADDR_MODE);
8778
8779 constraint (inst.reloc.exp.X_op != O_constant
8780 || inst.reloc.exp.X_add_number != 0,
8781 _("offset must be zero in ARM encoding"));
8782
8783 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
8784
8785 inst.instruction |= inst.operands[0].reg << 12;
8786 inst.instruction |= inst.operands[1].reg << 16;
8787 inst.reloc.type = BFD_RELOC_UNUSED;
8788 }
8789
8790 static void
8791 do_ldrexd (void)
8792 {
8793 constraint (inst.operands[0].reg % 2 != 0,
8794 _("even register required"));
8795 constraint (inst.operands[1].present
8796 && inst.operands[1].reg != inst.operands[0].reg + 1,
8797 _("can only load two consecutive registers"));
8798 /* If op 1 were present and equal to PC, this function wouldn't
8799 have been called in the first place. */
8800 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8801
8802 inst.instruction |= inst.operands[0].reg << 12;
8803 inst.instruction |= inst.operands[2].reg << 16;
8804 }
8805
8806 /* In both ARM and thumb state 'ldr pc, #imm' with an immediate
8807 which is not a multiple of four is UNPREDICTABLE. */
8808 static void
8809 check_ldr_r15_aligned (void)
8810 {
8811 constraint (!(inst.operands[1].immisreg)
8812 && (inst.operands[0].reg == REG_PC
8813 && inst.operands[1].reg == REG_PC
8814 && (inst.reloc.exp.X_add_number & 0x3)),
8815 _("ldr to register 15 must be 4-byte alligned"));
8816 }
8817
8818 static void
8819 do_ldst (void)
8820 {
8821 inst.instruction |= inst.operands[0].reg << 12;
8822 if (!inst.operands[1].isreg)
8823 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
8824 return;
8825 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
8826 check_ldr_r15_aligned ();
8827 }
8828
8829 static void
8830 do_ldstt (void)
8831 {
8832 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8833 reject [Rn,...]. */
8834 if (inst.operands[1].preind)
8835 {
8836 constraint (inst.reloc.exp.X_op != O_constant
8837 || inst.reloc.exp.X_add_number != 0,
8838 _("this instruction requires a post-indexed address"));
8839
8840 inst.operands[1].preind = 0;
8841 inst.operands[1].postind = 1;
8842 inst.operands[1].writeback = 1;
8843 }
8844 inst.instruction |= inst.operands[0].reg << 12;
8845 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
8846 }
8847
8848 /* Halfword and signed-byte load/store operations. */
8849
8850 static void
8851 do_ldstv4 (void)
8852 {
8853 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
8854 inst.instruction |= inst.operands[0].reg << 12;
8855 if (!inst.operands[1].isreg)
8856 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
8857 return;
8858 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
8859 }
8860
8861 static void
8862 do_ldsttv4 (void)
8863 {
8864 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8865 reject [Rn,...]. */
8866 if (inst.operands[1].preind)
8867 {
8868 constraint (inst.reloc.exp.X_op != O_constant
8869 || inst.reloc.exp.X_add_number != 0,
8870 _("this instruction requires a post-indexed address"));
8871
8872 inst.operands[1].preind = 0;
8873 inst.operands[1].postind = 1;
8874 inst.operands[1].writeback = 1;
8875 }
8876 inst.instruction |= inst.operands[0].reg << 12;
8877 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
8878 }
8879
8880 /* Co-processor register load/store.
8881 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
8882 static void
8883 do_lstc (void)
8884 {
8885 inst.instruction |= inst.operands[0].reg << 8;
8886 inst.instruction |= inst.operands[1].reg << 12;
8887 encode_arm_cp_address (2, TRUE, TRUE, 0);
8888 }
8889
8890 static void
8891 do_mlas (void)
8892 {
8893 /* This restriction does not apply to mls (nor to mla in v6 or later). */
8894 if (inst.operands[0].reg == inst.operands[1].reg
8895 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
8896 && !(inst.instruction & 0x00400000))
8897 as_tsktsk (_("Rd and Rm should be different in mla"));
8898
8899 inst.instruction |= inst.operands[0].reg << 16;
8900 inst.instruction |= inst.operands[1].reg;
8901 inst.instruction |= inst.operands[2].reg << 8;
8902 inst.instruction |= inst.operands[3].reg << 12;
8903 }
8904
8905 static void
8906 do_mov (void)
8907 {
8908 inst.instruction |= inst.operands[0].reg << 12;
8909 encode_arm_shifter_operand (1);
8910 }
8911
8912 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
8913 static void
8914 do_mov16 (void)
8915 {
8916 bfd_vma imm;
8917 bfd_boolean top;
8918
8919 top = (inst.instruction & 0x00400000) != 0;
8920 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
8921 _(":lower16: not allowed this instruction"));
8922 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
8923 _(":upper16: not allowed instruction"));
8924 inst.instruction |= inst.operands[0].reg << 12;
8925 if (inst.reloc.type == BFD_RELOC_UNUSED)
8926 {
8927 imm = inst.reloc.exp.X_add_number;
8928 /* The value is in two pieces: 0:11, 16:19. */
8929 inst.instruction |= (imm & 0x00000fff);
8930 inst.instruction |= (imm & 0x0000f000) << 4;
8931 }
8932 }
8933
8934 static int
8935 do_vfp_nsyn_mrs (void)
8936 {
8937 if (inst.operands[0].isvec)
8938 {
8939 if (inst.operands[1].reg != 1)
8940 first_error (_("operand 1 must be FPSCR"));
8941 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
8942 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
8943 do_vfp_nsyn_opcode ("fmstat");
8944 }
8945 else if (inst.operands[1].isvec)
8946 do_vfp_nsyn_opcode ("fmrx");
8947 else
8948 return FAIL;
8949
8950 return SUCCESS;
8951 }
8952
8953 static int
8954 do_vfp_nsyn_msr (void)
8955 {
8956 if (inst.operands[0].isvec)
8957 do_vfp_nsyn_opcode ("fmxr");
8958 else
8959 return FAIL;
8960
8961 return SUCCESS;
8962 }
8963
8964 static void
8965 do_vmrs (void)
8966 {
8967 unsigned Rt = inst.operands[0].reg;
8968
8969 if (thumb_mode && Rt == REG_SP)
8970 {
8971 inst.error = BAD_SP;
8972 return;
8973 }
8974
8975 /* APSR_ sets isvec. All other refs to PC are illegal. */
8976 if (!inst.operands[0].isvec && Rt == REG_PC)
8977 {
8978 inst.error = BAD_PC;
8979 return;
8980 }
8981
8982 /* If we get through parsing the register name, we just insert the number
8983 generated into the instruction without further validation. */
8984 inst.instruction |= (inst.operands[1].reg << 16);
8985 inst.instruction |= (Rt << 12);
8986 }
8987
8988 static void
8989 do_vmsr (void)
8990 {
8991 unsigned Rt = inst.operands[1].reg;
8992
8993 if (thumb_mode)
8994 reject_bad_reg (Rt);
8995 else if (Rt == REG_PC)
8996 {
8997 inst.error = BAD_PC;
8998 return;
8999 }
9000
9001 /* If we get through parsing the register name, we just insert the number
9002 generated into the instruction without further validation. */
9003 inst.instruction |= (inst.operands[0].reg << 16);
9004 inst.instruction |= (Rt << 12);
9005 }
9006
9007 static void
9008 do_mrs (void)
9009 {
9010 unsigned br;
9011
9012 if (do_vfp_nsyn_mrs () == SUCCESS)
9013 return;
9014
9015 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9016 inst.instruction |= inst.operands[0].reg << 12;
9017
9018 if (inst.operands[1].isreg)
9019 {
9020 br = inst.operands[1].reg;
9021 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
9022 as_bad (_("bad register for mrs"));
9023 }
9024 else
9025 {
9026 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9027 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9028 != (PSR_c|PSR_f),
9029 _("'APSR', 'CPSR' or 'SPSR' expected"));
9030 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9031 }
9032
9033 inst.instruction |= br;
9034 }
9035
9036 /* Two possible forms:
9037 "{C|S}PSR_<field>, Rm",
9038 "{C|S}PSR_f, #expression". */
9039
9040 static void
9041 do_msr (void)
9042 {
9043 if (do_vfp_nsyn_msr () == SUCCESS)
9044 return;
9045
9046 inst.instruction |= inst.operands[0].imm;
9047 if (inst.operands[1].isreg)
9048 inst.instruction |= inst.operands[1].reg;
9049 else
9050 {
9051 inst.instruction |= INST_IMMEDIATE;
9052 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
9053 inst.reloc.pc_rel = 0;
9054 }
9055 }
9056
9057 static void
9058 do_mul (void)
9059 {
9060 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9061
9062 if (!inst.operands[2].present)
9063 inst.operands[2].reg = inst.operands[0].reg;
9064 inst.instruction |= inst.operands[0].reg << 16;
9065 inst.instruction |= inst.operands[1].reg;
9066 inst.instruction |= inst.operands[2].reg << 8;
9067
9068 if (inst.operands[0].reg == inst.operands[1].reg
9069 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9070 as_tsktsk (_("Rd and Rm should be different in mul"));
9071 }
9072
9073 /* Long Multiply Parser
9074 UMULL RdLo, RdHi, Rm, Rs
9075 SMULL RdLo, RdHi, Rm, Rs
9076 UMLAL RdLo, RdHi, Rm, Rs
9077 SMLAL RdLo, RdHi, Rm, Rs. */
9078
9079 static void
9080 do_mull (void)
9081 {
9082 inst.instruction |= inst.operands[0].reg << 12;
9083 inst.instruction |= inst.operands[1].reg << 16;
9084 inst.instruction |= inst.operands[2].reg;
9085 inst.instruction |= inst.operands[3].reg << 8;
9086
9087 /* rdhi and rdlo must be different. */
9088 if (inst.operands[0].reg == inst.operands[1].reg)
9089 as_tsktsk (_("rdhi and rdlo must be different"));
9090
9091 /* rdhi, rdlo and rm must all be different before armv6. */
9092 if ((inst.operands[0].reg == inst.operands[2].reg
9093 || inst.operands[1].reg == inst.operands[2].reg)
9094 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9095 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9096 }
9097
9098 static void
9099 do_nop (void)
9100 {
9101 if (inst.operands[0].present
9102 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
9103 {
9104 /* Architectural NOP hints are CPSR sets with no bits selected. */
9105 inst.instruction &= 0xf0000000;
9106 inst.instruction |= 0x0320f000;
9107 if (inst.operands[0].present)
9108 inst.instruction |= inst.operands[0].imm;
9109 }
9110 }
9111
9112 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9113 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9114 Condition defaults to COND_ALWAYS.
9115 Error if Rd, Rn or Rm are R15. */
9116
9117 static void
9118 do_pkhbt (void)
9119 {
9120 inst.instruction |= inst.operands[0].reg << 12;
9121 inst.instruction |= inst.operands[1].reg << 16;
9122 inst.instruction |= inst.operands[2].reg;
9123 if (inst.operands[3].present)
9124 encode_arm_shift (3);
9125 }
9126
9127 /* ARM V6 PKHTB (Argument Parse). */
9128
9129 static void
9130 do_pkhtb (void)
9131 {
9132 if (!inst.operands[3].present)
9133 {
9134 /* If the shift specifier is omitted, turn the instruction
9135 into pkhbt rd, rm, rn. */
9136 inst.instruction &= 0xfff00010;
9137 inst.instruction |= inst.operands[0].reg << 12;
9138 inst.instruction |= inst.operands[1].reg;
9139 inst.instruction |= inst.operands[2].reg << 16;
9140 }
9141 else
9142 {
9143 inst.instruction |= inst.operands[0].reg << 12;
9144 inst.instruction |= inst.operands[1].reg << 16;
9145 inst.instruction |= inst.operands[2].reg;
9146 encode_arm_shift (3);
9147 }
9148 }
9149
9150 /* ARMv5TE: Preload-Cache
9151 MP Extensions: Preload for write
9152
9153 PLD(W) <addr_mode>
9154
9155 Syntactically, like LDR with B=1, W=0, L=1. */
9156
9157 static void
9158 do_pld (void)
9159 {
9160 constraint (!inst.operands[0].isreg,
9161 _("'[' expected after PLD mnemonic"));
9162 constraint (inst.operands[0].postind,
9163 _("post-indexed expression used in preload instruction"));
9164 constraint (inst.operands[0].writeback,
9165 _("writeback used in preload instruction"));
9166 constraint (!inst.operands[0].preind,
9167 _("unindexed addressing used in preload instruction"));
9168 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9169 }
9170
9171 /* ARMv7: PLI <addr_mode> */
9172 static void
9173 do_pli (void)
9174 {
9175 constraint (!inst.operands[0].isreg,
9176 _("'[' expected after PLI mnemonic"));
9177 constraint (inst.operands[0].postind,
9178 _("post-indexed expression used in preload instruction"));
9179 constraint (inst.operands[0].writeback,
9180 _("writeback used in preload instruction"));
9181 constraint (!inst.operands[0].preind,
9182 _("unindexed addressing used in preload instruction"));
9183 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9184 inst.instruction &= ~PRE_INDEX;
9185 }
9186
9187 static void
9188 do_push_pop (void)
9189 {
9190 constraint (inst.operands[0].writeback,
9191 _("push/pop do not support {reglist}^"));
9192 inst.operands[1] = inst.operands[0];
9193 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9194 inst.operands[0].isreg = 1;
9195 inst.operands[0].writeback = 1;
9196 inst.operands[0].reg = REG_SP;
9197 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
9198 }
9199
9200 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9201 word at the specified address and the following word
9202 respectively.
9203 Unconditionally executed.
9204 Error if Rn is R15. */
9205
9206 static void
9207 do_rfe (void)
9208 {
9209 inst.instruction |= inst.operands[0].reg << 16;
9210 if (inst.operands[0].writeback)
9211 inst.instruction |= WRITE_BACK;
9212 }
9213
9214 /* ARM V6 ssat (argument parse). */
9215
9216 static void
9217 do_ssat (void)
9218 {
9219 inst.instruction |= inst.operands[0].reg << 12;
9220 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9221 inst.instruction |= inst.operands[2].reg;
9222
9223 if (inst.operands[3].present)
9224 encode_arm_shift (3);
9225 }
9226
9227 /* ARM V6 usat (argument parse). */
9228
9229 static void
9230 do_usat (void)
9231 {
9232 inst.instruction |= inst.operands[0].reg << 12;
9233 inst.instruction |= inst.operands[1].imm << 16;
9234 inst.instruction |= inst.operands[2].reg;
9235
9236 if (inst.operands[3].present)
9237 encode_arm_shift (3);
9238 }
9239
9240 /* ARM V6 ssat16 (argument parse). */
9241
9242 static void
9243 do_ssat16 (void)
9244 {
9245 inst.instruction |= inst.operands[0].reg << 12;
9246 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9247 inst.instruction |= inst.operands[2].reg;
9248 }
9249
9250 static void
9251 do_usat16 (void)
9252 {
9253 inst.instruction |= inst.operands[0].reg << 12;
9254 inst.instruction |= inst.operands[1].imm << 16;
9255 inst.instruction |= inst.operands[2].reg;
9256 }
9257
9258 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9259 preserving the other bits.
9260
9261 setend <endian_specifier>, where <endian_specifier> is either
9262 BE or LE. */
9263
9264 static void
9265 do_setend (void)
9266 {
9267 if (warn_on_deprecated
9268 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
9269 as_tsktsk (_("setend use is deprecated for ARMv8"));
9270
9271 if (inst.operands[0].imm)
9272 inst.instruction |= 0x200;
9273 }
9274
9275 static void
9276 do_shift (void)
9277 {
9278 unsigned int Rm = (inst.operands[1].present
9279 ? inst.operands[1].reg
9280 : inst.operands[0].reg);
9281
9282 inst.instruction |= inst.operands[0].reg << 12;
9283 inst.instruction |= Rm;
9284 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
9285 {
9286 inst.instruction |= inst.operands[2].reg << 8;
9287 inst.instruction |= SHIFT_BY_REG;
9288 /* PR 12854: Error on extraneous shifts. */
9289 constraint (inst.operands[2].shifted,
9290 _("extraneous shift as part of operand to shift insn"));
9291 }
9292 else
9293 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
9294 }
9295
9296 static void
9297 do_smc (void)
9298 {
9299 inst.reloc.type = BFD_RELOC_ARM_SMC;
9300 inst.reloc.pc_rel = 0;
9301 }
9302
9303 static void
9304 do_hvc (void)
9305 {
9306 inst.reloc.type = BFD_RELOC_ARM_HVC;
9307 inst.reloc.pc_rel = 0;
9308 }
9309
9310 static void
9311 do_swi (void)
9312 {
9313 inst.reloc.type = BFD_RELOC_ARM_SWI;
9314 inst.reloc.pc_rel = 0;
9315 }
9316
9317 static void
9318 do_setpan (void)
9319 {
9320 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9321 _("selected processor does not support SETPAN instruction"));
9322
9323 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9324 }
9325
9326 static void
9327 do_t_setpan (void)
9328 {
9329 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9330 _("selected processor does not support SETPAN instruction"));
9331
9332 inst.instruction |= (inst.operands[0].imm << 3);
9333 }
9334
9335 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9336 SMLAxy{cond} Rd,Rm,Rs,Rn
9337 SMLAWy{cond} Rd,Rm,Rs,Rn
9338 Error if any register is R15. */
9339
9340 static void
9341 do_smla (void)
9342 {
9343 inst.instruction |= inst.operands[0].reg << 16;
9344 inst.instruction |= inst.operands[1].reg;
9345 inst.instruction |= inst.operands[2].reg << 8;
9346 inst.instruction |= inst.operands[3].reg << 12;
9347 }
9348
9349 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9350 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9351 Error if any register is R15.
9352 Warning if Rdlo == Rdhi. */
9353
9354 static void
9355 do_smlal (void)
9356 {
9357 inst.instruction |= inst.operands[0].reg << 12;
9358 inst.instruction |= inst.operands[1].reg << 16;
9359 inst.instruction |= inst.operands[2].reg;
9360 inst.instruction |= inst.operands[3].reg << 8;
9361
9362 if (inst.operands[0].reg == inst.operands[1].reg)
9363 as_tsktsk (_("rdhi and rdlo must be different"));
9364 }
9365
9366 /* ARM V5E (El Segundo) signed-multiply (argument parse)
9367 SMULxy{cond} Rd,Rm,Rs
9368 Error if any register is R15. */
9369
9370 static void
9371 do_smul (void)
9372 {
9373 inst.instruction |= inst.operands[0].reg << 16;
9374 inst.instruction |= inst.operands[1].reg;
9375 inst.instruction |= inst.operands[2].reg << 8;
9376 }
9377
9378 /* ARM V6 srs (argument parse). The variable fields in the encoding are
9379 the same for both ARM and Thumb-2. */
9380
9381 static void
9382 do_srs (void)
9383 {
9384 int reg;
9385
9386 if (inst.operands[0].present)
9387 {
9388 reg = inst.operands[0].reg;
9389 constraint (reg != REG_SP, _("SRS base register must be r13"));
9390 }
9391 else
9392 reg = REG_SP;
9393
9394 inst.instruction |= reg << 16;
9395 inst.instruction |= inst.operands[1].imm;
9396 if (inst.operands[0].writeback || inst.operands[1].writeback)
9397 inst.instruction |= WRITE_BACK;
9398 }
9399
9400 /* ARM V6 strex (argument parse). */
9401
9402 static void
9403 do_strex (void)
9404 {
9405 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9406 || inst.operands[2].postind || inst.operands[2].writeback
9407 || inst.operands[2].immisreg || inst.operands[2].shifted
9408 || inst.operands[2].negative
9409 /* See comment in do_ldrex(). */
9410 || (inst.operands[2].reg == REG_PC),
9411 BAD_ADDR_MODE);
9412
9413 constraint (inst.operands[0].reg == inst.operands[1].reg
9414 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9415
9416 constraint (inst.reloc.exp.X_op != O_constant
9417 || inst.reloc.exp.X_add_number != 0,
9418 _("offset must be zero in ARM encoding"));
9419
9420 inst.instruction |= inst.operands[0].reg << 12;
9421 inst.instruction |= inst.operands[1].reg;
9422 inst.instruction |= inst.operands[2].reg << 16;
9423 inst.reloc.type = BFD_RELOC_UNUSED;
9424 }
9425
9426 static void
9427 do_t_strexbh (void)
9428 {
9429 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9430 || inst.operands[2].postind || inst.operands[2].writeback
9431 || inst.operands[2].immisreg || inst.operands[2].shifted
9432 || inst.operands[2].negative,
9433 BAD_ADDR_MODE);
9434
9435 constraint (inst.operands[0].reg == inst.operands[1].reg
9436 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9437
9438 do_rm_rd_rn ();
9439 }
9440
9441 static void
9442 do_strexd (void)
9443 {
9444 constraint (inst.operands[1].reg % 2 != 0,
9445 _("even register required"));
9446 constraint (inst.operands[2].present
9447 && inst.operands[2].reg != inst.operands[1].reg + 1,
9448 _("can only store two consecutive registers"));
9449 /* If op 2 were present and equal to PC, this function wouldn't
9450 have been called in the first place. */
9451 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
9452
9453 constraint (inst.operands[0].reg == inst.operands[1].reg
9454 || inst.operands[0].reg == inst.operands[1].reg + 1
9455 || inst.operands[0].reg == inst.operands[3].reg,
9456 BAD_OVERLAP);
9457
9458 inst.instruction |= inst.operands[0].reg << 12;
9459 inst.instruction |= inst.operands[1].reg;
9460 inst.instruction |= inst.operands[3].reg << 16;
9461 }
9462
9463 /* ARM V8 STRL. */
9464 static void
9465 do_stlex (void)
9466 {
9467 constraint (inst.operands[0].reg == inst.operands[1].reg
9468 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9469
9470 do_rd_rm_rn ();
9471 }
9472
9473 static void
9474 do_t_stlex (void)
9475 {
9476 constraint (inst.operands[0].reg == inst.operands[1].reg
9477 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9478
9479 do_rm_rd_rn ();
9480 }
9481
9482 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9483 extends it to 32-bits, and adds the result to a value in another
9484 register. You can specify a rotation by 0, 8, 16, or 24 bits
9485 before extracting the 16-bit value.
9486 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9487 Condition defaults to COND_ALWAYS.
9488 Error if any register uses R15. */
9489
9490 static void
9491 do_sxtah (void)
9492 {
9493 inst.instruction |= inst.operands[0].reg << 12;
9494 inst.instruction |= inst.operands[1].reg << 16;
9495 inst.instruction |= inst.operands[2].reg;
9496 inst.instruction |= inst.operands[3].imm << 10;
9497 }
9498
9499 /* ARM V6 SXTH.
9500
9501 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9502 Condition defaults to COND_ALWAYS.
9503 Error if any register uses R15. */
9504
9505 static void
9506 do_sxth (void)
9507 {
9508 inst.instruction |= inst.operands[0].reg << 12;
9509 inst.instruction |= inst.operands[1].reg;
9510 inst.instruction |= inst.operands[2].imm << 10;
9511 }
9512 \f
9513 /* VFP instructions. In a logical order: SP variant first, monad
9514 before dyad, arithmetic then move then load/store. */
9515
9516 static void
9517 do_vfp_sp_monadic (void)
9518 {
9519 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9520 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
9521 }
9522
9523 static void
9524 do_vfp_sp_dyadic (void)
9525 {
9526 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9527 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9528 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
9529 }
9530
9531 static void
9532 do_vfp_sp_compare_z (void)
9533 {
9534 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9535 }
9536
9537 static void
9538 do_vfp_dp_sp_cvt (void)
9539 {
9540 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9541 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
9542 }
9543
9544 static void
9545 do_vfp_sp_dp_cvt (void)
9546 {
9547 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9548 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9549 }
9550
9551 static void
9552 do_vfp_reg_from_sp (void)
9553 {
9554 inst.instruction |= inst.operands[0].reg << 12;
9555 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9556 }
9557
9558 static void
9559 do_vfp_reg2_from_sp2 (void)
9560 {
9561 constraint (inst.operands[2].imm != 2,
9562 _("only two consecutive VFP SP registers allowed here"));
9563 inst.instruction |= inst.operands[0].reg << 12;
9564 inst.instruction |= inst.operands[1].reg << 16;
9565 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
9566 }
9567
9568 static void
9569 do_vfp_sp_from_reg (void)
9570 {
9571 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
9572 inst.instruction |= inst.operands[1].reg << 12;
9573 }
9574
9575 static void
9576 do_vfp_sp2_from_reg2 (void)
9577 {
9578 constraint (inst.operands[0].imm != 2,
9579 _("only two consecutive VFP SP registers allowed here"));
9580 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
9581 inst.instruction |= inst.operands[1].reg << 12;
9582 inst.instruction |= inst.operands[2].reg << 16;
9583 }
9584
9585 static void
9586 do_vfp_sp_ldst (void)
9587 {
9588 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9589 encode_arm_cp_address (1, FALSE, TRUE, 0);
9590 }
9591
9592 static void
9593 do_vfp_dp_ldst (void)
9594 {
9595 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9596 encode_arm_cp_address (1, FALSE, TRUE, 0);
9597 }
9598
9599
9600 static void
9601 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
9602 {
9603 if (inst.operands[0].writeback)
9604 inst.instruction |= WRITE_BACK;
9605 else
9606 constraint (ldstm_type != VFP_LDSTMIA,
9607 _("this addressing mode requires base-register writeback"));
9608 inst.instruction |= inst.operands[0].reg << 16;
9609 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
9610 inst.instruction |= inst.operands[1].imm;
9611 }
9612
9613 static void
9614 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
9615 {
9616 int count;
9617
9618 if (inst.operands[0].writeback)
9619 inst.instruction |= WRITE_BACK;
9620 else
9621 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9622 _("this addressing mode requires base-register writeback"));
9623
9624 inst.instruction |= inst.operands[0].reg << 16;
9625 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9626
9627 count = inst.operands[1].imm << 1;
9628 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9629 count += 1;
9630
9631 inst.instruction |= count;
9632 }
9633
9634 static void
9635 do_vfp_sp_ldstmia (void)
9636 {
9637 vfp_sp_ldstm (VFP_LDSTMIA);
9638 }
9639
9640 static void
9641 do_vfp_sp_ldstmdb (void)
9642 {
9643 vfp_sp_ldstm (VFP_LDSTMDB);
9644 }
9645
9646 static void
9647 do_vfp_dp_ldstmia (void)
9648 {
9649 vfp_dp_ldstm (VFP_LDSTMIA);
9650 }
9651
9652 static void
9653 do_vfp_dp_ldstmdb (void)
9654 {
9655 vfp_dp_ldstm (VFP_LDSTMDB);
9656 }
9657
9658 static void
9659 do_vfp_xp_ldstmia (void)
9660 {
9661 vfp_dp_ldstm (VFP_LDSTMIAX);
9662 }
9663
9664 static void
9665 do_vfp_xp_ldstmdb (void)
9666 {
9667 vfp_dp_ldstm (VFP_LDSTMDBX);
9668 }
9669
9670 static void
9671 do_vfp_dp_rd_rm (void)
9672 {
9673 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9674 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9675 }
9676
9677 static void
9678 do_vfp_dp_rn_rd (void)
9679 {
9680 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9681 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9682 }
9683
9684 static void
9685 do_vfp_dp_rd_rn (void)
9686 {
9687 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9688 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9689 }
9690
9691 static void
9692 do_vfp_dp_rd_rn_rm (void)
9693 {
9694 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9695 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9696 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9697 }
9698
9699 static void
9700 do_vfp_dp_rd (void)
9701 {
9702 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9703 }
9704
9705 static void
9706 do_vfp_dp_rm_rd_rn (void)
9707 {
9708 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9709 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9710 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9711 }
9712
9713 /* VFPv3 instructions. */
9714 static void
9715 do_vfp_sp_const (void)
9716 {
9717 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9718 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9719 inst.instruction |= (inst.operands[1].imm & 0x0f);
9720 }
9721
9722 static void
9723 do_vfp_dp_const (void)
9724 {
9725 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9726 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9727 inst.instruction |= (inst.operands[1].imm & 0x0f);
9728 }
9729
9730 static void
9731 vfp_conv (int srcsize)
9732 {
9733 int immbits = srcsize - inst.operands[1].imm;
9734
9735 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9736 {
9737 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
9738 i.e. immbits must be in range 0 - 16. */
9739 inst.error = _("immediate value out of range, expected range [0, 16]");
9740 return;
9741 }
9742 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
9743 {
9744 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
9745 i.e. immbits must be in range 0 - 31. */
9746 inst.error = _("immediate value out of range, expected range [1, 32]");
9747 return;
9748 }
9749
9750 inst.instruction |= (immbits & 1) << 5;
9751 inst.instruction |= (immbits >> 1);
9752 }
9753
9754 static void
9755 do_vfp_sp_conv_16 (void)
9756 {
9757 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9758 vfp_conv (16);
9759 }
9760
9761 static void
9762 do_vfp_dp_conv_16 (void)
9763 {
9764 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9765 vfp_conv (16);
9766 }
9767
9768 static void
9769 do_vfp_sp_conv_32 (void)
9770 {
9771 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9772 vfp_conv (32);
9773 }
9774
9775 static void
9776 do_vfp_dp_conv_32 (void)
9777 {
9778 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9779 vfp_conv (32);
9780 }
9781 \f
9782 /* FPA instructions. Also in a logical order. */
9783
9784 static void
9785 do_fpa_cmp (void)
9786 {
9787 inst.instruction |= inst.operands[0].reg << 16;
9788 inst.instruction |= inst.operands[1].reg;
9789 }
9790
9791 static void
9792 do_fpa_ldmstm (void)
9793 {
9794 inst.instruction |= inst.operands[0].reg << 12;
9795 switch (inst.operands[1].imm)
9796 {
9797 case 1: inst.instruction |= CP_T_X; break;
9798 case 2: inst.instruction |= CP_T_Y; break;
9799 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
9800 case 4: break;
9801 default: abort ();
9802 }
9803
9804 if (inst.instruction & (PRE_INDEX | INDEX_UP))
9805 {
9806 /* The instruction specified "ea" or "fd", so we can only accept
9807 [Rn]{!}. The instruction does not really support stacking or
9808 unstacking, so we have to emulate these by setting appropriate
9809 bits and offsets. */
9810 constraint (inst.reloc.exp.X_op != O_constant
9811 || inst.reloc.exp.X_add_number != 0,
9812 _("this instruction does not support indexing"));
9813
9814 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
9815 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
9816
9817 if (!(inst.instruction & INDEX_UP))
9818 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
9819
9820 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
9821 {
9822 inst.operands[2].preind = 0;
9823 inst.operands[2].postind = 1;
9824 }
9825 }
9826
9827 encode_arm_cp_address (2, TRUE, TRUE, 0);
9828 }
9829 \f
9830 /* iWMMXt instructions: strictly in alphabetical order. */
9831
9832 static void
9833 do_iwmmxt_tandorc (void)
9834 {
9835 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
9836 }
9837
9838 static void
9839 do_iwmmxt_textrc (void)
9840 {
9841 inst.instruction |= inst.operands[0].reg << 12;
9842 inst.instruction |= inst.operands[1].imm;
9843 }
9844
9845 static void
9846 do_iwmmxt_textrm (void)
9847 {
9848 inst.instruction |= inst.operands[0].reg << 12;
9849 inst.instruction |= inst.operands[1].reg << 16;
9850 inst.instruction |= inst.operands[2].imm;
9851 }
9852
9853 static void
9854 do_iwmmxt_tinsr (void)
9855 {
9856 inst.instruction |= inst.operands[0].reg << 16;
9857 inst.instruction |= inst.operands[1].reg << 12;
9858 inst.instruction |= inst.operands[2].imm;
9859 }
9860
9861 static void
9862 do_iwmmxt_tmia (void)
9863 {
9864 inst.instruction |= inst.operands[0].reg << 5;
9865 inst.instruction |= inst.operands[1].reg;
9866 inst.instruction |= inst.operands[2].reg << 12;
9867 }
9868
9869 static void
9870 do_iwmmxt_waligni (void)
9871 {
9872 inst.instruction |= inst.operands[0].reg << 12;
9873 inst.instruction |= inst.operands[1].reg << 16;
9874 inst.instruction |= inst.operands[2].reg;
9875 inst.instruction |= inst.operands[3].imm << 20;
9876 }
9877
9878 static void
9879 do_iwmmxt_wmerge (void)
9880 {
9881 inst.instruction |= inst.operands[0].reg << 12;
9882 inst.instruction |= inst.operands[1].reg << 16;
9883 inst.instruction |= inst.operands[2].reg;
9884 inst.instruction |= inst.operands[3].imm << 21;
9885 }
9886
9887 static void
9888 do_iwmmxt_wmov (void)
9889 {
9890 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
9891 inst.instruction |= inst.operands[0].reg << 12;
9892 inst.instruction |= inst.operands[1].reg << 16;
9893 inst.instruction |= inst.operands[1].reg;
9894 }
9895
9896 static void
9897 do_iwmmxt_wldstbh (void)
9898 {
9899 int reloc;
9900 inst.instruction |= inst.operands[0].reg << 12;
9901 if (thumb_mode)
9902 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
9903 else
9904 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
9905 encode_arm_cp_address (1, TRUE, FALSE, reloc);
9906 }
9907
9908 static void
9909 do_iwmmxt_wldstw (void)
9910 {
9911 /* RIWR_RIWC clears .isreg for a control register. */
9912 if (!inst.operands[0].isreg)
9913 {
9914 constraint (inst.cond != COND_ALWAYS, BAD_COND);
9915 inst.instruction |= 0xf0000000;
9916 }
9917
9918 inst.instruction |= inst.operands[0].reg << 12;
9919 encode_arm_cp_address (1, TRUE, TRUE, 0);
9920 }
9921
9922 static void
9923 do_iwmmxt_wldstd (void)
9924 {
9925 inst.instruction |= inst.operands[0].reg << 12;
9926 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
9927 && inst.operands[1].immisreg)
9928 {
9929 inst.instruction &= ~0x1a000ff;
9930 inst.instruction |= (0xfU << 28);
9931 if (inst.operands[1].preind)
9932 inst.instruction |= PRE_INDEX;
9933 if (!inst.operands[1].negative)
9934 inst.instruction |= INDEX_UP;
9935 if (inst.operands[1].writeback)
9936 inst.instruction |= WRITE_BACK;
9937 inst.instruction |= inst.operands[1].reg << 16;
9938 inst.instruction |= inst.reloc.exp.X_add_number << 4;
9939 inst.instruction |= inst.operands[1].imm;
9940 }
9941 else
9942 encode_arm_cp_address (1, TRUE, FALSE, 0);
9943 }
9944
9945 static void
9946 do_iwmmxt_wshufh (void)
9947 {
9948 inst.instruction |= inst.operands[0].reg << 12;
9949 inst.instruction |= inst.operands[1].reg << 16;
9950 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
9951 inst.instruction |= (inst.operands[2].imm & 0x0f);
9952 }
9953
9954 static void
9955 do_iwmmxt_wzero (void)
9956 {
9957 /* WZERO reg is an alias for WANDN reg, reg, reg. */
9958 inst.instruction |= inst.operands[0].reg;
9959 inst.instruction |= inst.operands[0].reg << 12;
9960 inst.instruction |= inst.operands[0].reg << 16;
9961 }
9962
9963 static void
9964 do_iwmmxt_wrwrwr_or_imm5 (void)
9965 {
9966 if (inst.operands[2].isreg)
9967 do_rd_rn_rm ();
9968 else {
9969 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
9970 _("immediate operand requires iWMMXt2"));
9971 do_rd_rn ();
9972 if (inst.operands[2].imm == 0)
9973 {
9974 switch ((inst.instruction >> 20) & 0xf)
9975 {
9976 case 4:
9977 case 5:
9978 case 6:
9979 case 7:
9980 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
9981 inst.operands[2].imm = 16;
9982 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
9983 break;
9984 case 8:
9985 case 9:
9986 case 10:
9987 case 11:
9988 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
9989 inst.operands[2].imm = 32;
9990 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
9991 break;
9992 case 12:
9993 case 13:
9994 case 14:
9995 case 15:
9996 {
9997 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
9998 unsigned long wrn;
9999 wrn = (inst.instruction >> 16) & 0xf;
10000 inst.instruction &= 0xff0fff0f;
10001 inst.instruction |= wrn;
10002 /* Bail out here; the instruction is now assembled. */
10003 return;
10004 }
10005 }
10006 }
10007 /* Map 32 -> 0, etc. */
10008 inst.operands[2].imm &= 0x1f;
10009 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
10010 }
10011 }
10012 \f
10013 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10014 operations first, then control, shift, and load/store. */
10015
10016 /* Insns like "foo X,Y,Z". */
10017
10018 static void
10019 do_mav_triple (void)
10020 {
10021 inst.instruction |= inst.operands[0].reg << 16;
10022 inst.instruction |= inst.operands[1].reg;
10023 inst.instruction |= inst.operands[2].reg << 12;
10024 }
10025
10026 /* Insns like "foo W,X,Y,Z".
10027 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
10028
10029 static void
10030 do_mav_quad (void)
10031 {
10032 inst.instruction |= inst.operands[0].reg << 5;
10033 inst.instruction |= inst.operands[1].reg << 12;
10034 inst.instruction |= inst.operands[2].reg << 16;
10035 inst.instruction |= inst.operands[3].reg;
10036 }
10037
10038 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10039 static void
10040 do_mav_dspsc (void)
10041 {
10042 inst.instruction |= inst.operands[1].reg << 12;
10043 }
10044
10045 /* Maverick shift immediate instructions.
10046 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10047 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
10048
10049 static void
10050 do_mav_shift (void)
10051 {
10052 int imm = inst.operands[2].imm;
10053
10054 inst.instruction |= inst.operands[0].reg << 12;
10055 inst.instruction |= inst.operands[1].reg << 16;
10056
10057 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10058 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10059 Bit 4 should be 0. */
10060 imm = (imm & 0xf) | ((imm & 0x70) << 1);
10061
10062 inst.instruction |= imm;
10063 }
10064 \f
10065 /* XScale instructions. Also sorted arithmetic before move. */
10066
10067 /* Xscale multiply-accumulate (argument parse)
10068 MIAcc acc0,Rm,Rs
10069 MIAPHcc acc0,Rm,Rs
10070 MIAxycc acc0,Rm,Rs. */
10071
10072 static void
10073 do_xsc_mia (void)
10074 {
10075 inst.instruction |= inst.operands[1].reg;
10076 inst.instruction |= inst.operands[2].reg << 12;
10077 }
10078
10079 /* Xscale move-accumulator-register (argument parse)
10080
10081 MARcc acc0,RdLo,RdHi. */
10082
10083 static void
10084 do_xsc_mar (void)
10085 {
10086 inst.instruction |= inst.operands[1].reg << 12;
10087 inst.instruction |= inst.operands[2].reg << 16;
10088 }
10089
10090 /* Xscale move-register-accumulator (argument parse)
10091
10092 MRAcc RdLo,RdHi,acc0. */
10093
10094 static void
10095 do_xsc_mra (void)
10096 {
10097 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10098 inst.instruction |= inst.operands[0].reg << 12;
10099 inst.instruction |= inst.operands[1].reg << 16;
10100 }
10101 \f
10102 /* Encoding functions relevant only to Thumb. */
10103
10104 /* inst.operands[i] is a shifted-register operand; encode
10105 it into inst.instruction in the format used by Thumb32. */
10106
10107 static void
10108 encode_thumb32_shifted_operand (int i)
10109 {
10110 unsigned int value = inst.reloc.exp.X_add_number;
10111 unsigned int shift = inst.operands[i].shift_kind;
10112
10113 constraint (inst.operands[i].immisreg,
10114 _("shift by register not allowed in thumb mode"));
10115 inst.instruction |= inst.operands[i].reg;
10116 if (shift == SHIFT_RRX)
10117 inst.instruction |= SHIFT_ROR << 4;
10118 else
10119 {
10120 constraint (inst.reloc.exp.X_op != O_constant,
10121 _("expression too complex"));
10122
10123 constraint (value > 32
10124 || (value == 32 && (shift == SHIFT_LSL
10125 || shift == SHIFT_ROR)),
10126 _("shift expression is too large"));
10127
10128 if (value == 0)
10129 shift = SHIFT_LSL;
10130 else if (value == 32)
10131 value = 0;
10132
10133 inst.instruction |= shift << 4;
10134 inst.instruction |= (value & 0x1c) << 10;
10135 inst.instruction |= (value & 0x03) << 6;
10136 }
10137 }
10138
10139
10140 /* inst.operands[i] was set up by parse_address. Encode it into a
10141 Thumb32 format load or store instruction. Reject forms that cannot
10142 be used with such instructions. If is_t is true, reject forms that
10143 cannot be used with a T instruction; if is_d is true, reject forms
10144 that cannot be used with a D instruction. If it is a store insn,
10145 reject PC in Rn. */
10146
10147 static void
10148 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10149 {
10150 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
10151
10152 constraint (!inst.operands[i].isreg,
10153 _("Instruction does not support =N addresses"));
10154
10155 inst.instruction |= inst.operands[i].reg << 16;
10156 if (inst.operands[i].immisreg)
10157 {
10158 constraint (is_pc, BAD_PC_ADDRESSING);
10159 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10160 constraint (inst.operands[i].negative,
10161 _("Thumb does not support negative register indexing"));
10162 constraint (inst.operands[i].postind,
10163 _("Thumb does not support register post-indexing"));
10164 constraint (inst.operands[i].writeback,
10165 _("Thumb does not support register indexing with writeback"));
10166 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10167 _("Thumb supports only LSL in shifted register indexing"));
10168
10169 inst.instruction |= inst.operands[i].imm;
10170 if (inst.operands[i].shifted)
10171 {
10172 constraint (inst.reloc.exp.X_op != O_constant,
10173 _("expression too complex"));
10174 constraint (inst.reloc.exp.X_add_number < 0
10175 || inst.reloc.exp.X_add_number > 3,
10176 _("shift out of range"));
10177 inst.instruction |= inst.reloc.exp.X_add_number << 4;
10178 }
10179 inst.reloc.type = BFD_RELOC_UNUSED;
10180 }
10181 else if (inst.operands[i].preind)
10182 {
10183 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
10184 constraint (is_t && inst.operands[i].writeback,
10185 _("cannot use writeback with this instruction"));
10186 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10187 BAD_PC_ADDRESSING);
10188
10189 if (is_d)
10190 {
10191 inst.instruction |= 0x01000000;
10192 if (inst.operands[i].writeback)
10193 inst.instruction |= 0x00200000;
10194 }
10195 else
10196 {
10197 inst.instruction |= 0x00000c00;
10198 if (inst.operands[i].writeback)
10199 inst.instruction |= 0x00000100;
10200 }
10201 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10202 }
10203 else if (inst.operands[i].postind)
10204 {
10205 gas_assert (inst.operands[i].writeback);
10206 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10207 constraint (is_t, _("cannot use post-indexing with this instruction"));
10208
10209 if (is_d)
10210 inst.instruction |= 0x00200000;
10211 else
10212 inst.instruction |= 0x00000900;
10213 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10214 }
10215 else /* unindexed - only for coprocessor */
10216 inst.error = _("instruction does not accept unindexed addressing");
10217 }
10218
10219 /* Table of Thumb instructions which exist in both 16- and 32-bit
10220 encodings (the latter only in post-V6T2 cores). The index is the
10221 value used in the insns table below. When there is more than one
10222 possible 16-bit encoding for the instruction, this table always
10223 holds variant (1).
10224 Also contains several pseudo-instructions used during relaxation. */
10225 #define T16_32_TAB \
10226 X(_adc, 4140, eb400000), \
10227 X(_adcs, 4140, eb500000), \
10228 X(_add, 1c00, eb000000), \
10229 X(_adds, 1c00, eb100000), \
10230 X(_addi, 0000, f1000000), \
10231 X(_addis, 0000, f1100000), \
10232 X(_add_pc,000f, f20f0000), \
10233 X(_add_sp,000d, f10d0000), \
10234 X(_adr, 000f, f20f0000), \
10235 X(_and, 4000, ea000000), \
10236 X(_ands, 4000, ea100000), \
10237 X(_asr, 1000, fa40f000), \
10238 X(_asrs, 1000, fa50f000), \
10239 X(_b, e000, f000b000), \
10240 X(_bcond, d000, f0008000), \
10241 X(_bic, 4380, ea200000), \
10242 X(_bics, 4380, ea300000), \
10243 X(_cmn, 42c0, eb100f00), \
10244 X(_cmp, 2800, ebb00f00), \
10245 X(_cpsie, b660, f3af8400), \
10246 X(_cpsid, b670, f3af8600), \
10247 X(_cpy, 4600, ea4f0000), \
10248 X(_dec_sp,80dd, f1ad0d00), \
10249 X(_eor, 4040, ea800000), \
10250 X(_eors, 4040, ea900000), \
10251 X(_inc_sp,00dd, f10d0d00), \
10252 X(_ldmia, c800, e8900000), \
10253 X(_ldr, 6800, f8500000), \
10254 X(_ldrb, 7800, f8100000), \
10255 X(_ldrh, 8800, f8300000), \
10256 X(_ldrsb, 5600, f9100000), \
10257 X(_ldrsh, 5e00, f9300000), \
10258 X(_ldr_pc,4800, f85f0000), \
10259 X(_ldr_pc2,4800, f85f0000), \
10260 X(_ldr_sp,9800, f85d0000), \
10261 X(_lsl, 0000, fa00f000), \
10262 X(_lsls, 0000, fa10f000), \
10263 X(_lsr, 0800, fa20f000), \
10264 X(_lsrs, 0800, fa30f000), \
10265 X(_mov, 2000, ea4f0000), \
10266 X(_movs, 2000, ea5f0000), \
10267 X(_mul, 4340, fb00f000), \
10268 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10269 X(_mvn, 43c0, ea6f0000), \
10270 X(_mvns, 43c0, ea7f0000), \
10271 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10272 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10273 X(_orr, 4300, ea400000), \
10274 X(_orrs, 4300, ea500000), \
10275 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10276 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10277 X(_rev, ba00, fa90f080), \
10278 X(_rev16, ba40, fa90f090), \
10279 X(_revsh, bac0, fa90f0b0), \
10280 X(_ror, 41c0, fa60f000), \
10281 X(_rors, 41c0, fa70f000), \
10282 X(_sbc, 4180, eb600000), \
10283 X(_sbcs, 4180, eb700000), \
10284 X(_stmia, c000, e8800000), \
10285 X(_str, 6000, f8400000), \
10286 X(_strb, 7000, f8000000), \
10287 X(_strh, 8000, f8200000), \
10288 X(_str_sp,9000, f84d0000), \
10289 X(_sub, 1e00, eba00000), \
10290 X(_subs, 1e00, ebb00000), \
10291 X(_subi, 8000, f1a00000), \
10292 X(_subis, 8000, f1b00000), \
10293 X(_sxtb, b240, fa4ff080), \
10294 X(_sxth, b200, fa0ff080), \
10295 X(_tst, 4200, ea100f00), \
10296 X(_uxtb, b2c0, fa5ff080), \
10297 X(_uxth, b280, fa1ff080), \
10298 X(_nop, bf00, f3af8000), \
10299 X(_yield, bf10, f3af8001), \
10300 X(_wfe, bf20, f3af8002), \
10301 X(_wfi, bf30, f3af8003), \
10302 X(_sev, bf40, f3af8004), \
10303 X(_sevl, bf50, f3af8005), \
10304 X(_udf, de00, f7f0a000)
10305
10306 /* To catch errors in encoding functions, the codes are all offset by
10307 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10308 as 16-bit instructions. */
10309 #define X(a,b,c) T_MNEM##a
10310 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10311 #undef X
10312
10313 #define X(a,b,c) 0x##b
10314 static const unsigned short thumb_op16[] = { T16_32_TAB };
10315 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10316 #undef X
10317
10318 #define X(a,b,c) 0x##c
10319 static const unsigned int thumb_op32[] = { T16_32_TAB };
10320 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10321 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
10322 #undef X
10323 #undef T16_32_TAB
10324
10325 /* Thumb instruction encoders, in alphabetical order. */
10326
10327 /* ADDW or SUBW. */
10328
10329 static void
10330 do_t_add_sub_w (void)
10331 {
10332 int Rd, Rn;
10333
10334 Rd = inst.operands[0].reg;
10335 Rn = inst.operands[1].reg;
10336
10337 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10338 is the SP-{plus,minus}-immediate form of the instruction. */
10339 if (Rn == REG_SP)
10340 constraint (Rd == REG_PC, BAD_PC);
10341 else
10342 reject_bad_reg (Rd);
10343
10344 inst.instruction |= (Rn << 16) | (Rd << 8);
10345 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10346 }
10347
10348 /* Parse an add or subtract instruction. We get here with inst.instruction
10349 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
10350
10351 static void
10352 do_t_add_sub (void)
10353 {
10354 int Rd, Rs, Rn;
10355
10356 Rd = inst.operands[0].reg;
10357 Rs = (inst.operands[1].present
10358 ? inst.operands[1].reg /* Rd, Rs, foo */
10359 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10360
10361 if (Rd == REG_PC)
10362 set_it_insn_type_last ();
10363
10364 if (unified_syntax)
10365 {
10366 bfd_boolean flags;
10367 bfd_boolean narrow;
10368 int opcode;
10369
10370 flags = (inst.instruction == T_MNEM_adds
10371 || inst.instruction == T_MNEM_subs);
10372 if (flags)
10373 narrow = !in_it_block ();
10374 else
10375 narrow = in_it_block ();
10376 if (!inst.operands[2].isreg)
10377 {
10378 int add;
10379
10380 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10381
10382 add = (inst.instruction == T_MNEM_add
10383 || inst.instruction == T_MNEM_adds);
10384 opcode = 0;
10385 if (inst.size_req != 4)
10386 {
10387 /* Attempt to use a narrow opcode, with relaxation if
10388 appropriate. */
10389 if (Rd == REG_SP && Rs == REG_SP && !flags)
10390 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10391 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10392 opcode = T_MNEM_add_sp;
10393 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10394 opcode = T_MNEM_add_pc;
10395 else if (Rd <= 7 && Rs <= 7 && narrow)
10396 {
10397 if (flags)
10398 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10399 else
10400 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10401 }
10402 if (opcode)
10403 {
10404 inst.instruction = THUMB_OP16(opcode);
10405 inst.instruction |= (Rd << 4) | Rs;
10406 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10407 if (inst.size_req != 2)
10408 inst.relax = opcode;
10409 }
10410 else
10411 constraint (inst.size_req == 2, BAD_HIREG);
10412 }
10413 if (inst.size_req == 4
10414 || (inst.size_req != 2 && !opcode))
10415 {
10416 if (Rd == REG_PC)
10417 {
10418 constraint (add, BAD_PC);
10419 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10420 _("only SUBS PC, LR, #const allowed"));
10421 constraint (inst.reloc.exp.X_op != O_constant,
10422 _("expression too complex"));
10423 constraint (inst.reloc.exp.X_add_number < 0
10424 || inst.reloc.exp.X_add_number > 0xff,
10425 _("immediate value out of range"));
10426 inst.instruction = T2_SUBS_PC_LR
10427 | inst.reloc.exp.X_add_number;
10428 inst.reloc.type = BFD_RELOC_UNUSED;
10429 return;
10430 }
10431 else if (Rs == REG_PC)
10432 {
10433 /* Always use addw/subw. */
10434 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
10435 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10436 }
10437 else
10438 {
10439 inst.instruction = THUMB_OP32 (inst.instruction);
10440 inst.instruction = (inst.instruction & 0xe1ffffff)
10441 | 0x10000000;
10442 if (flags)
10443 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10444 else
10445 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
10446 }
10447 inst.instruction |= Rd << 8;
10448 inst.instruction |= Rs << 16;
10449 }
10450 }
10451 else
10452 {
10453 unsigned int value = inst.reloc.exp.X_add_number;
10454 unsigned int shift = inst.operands[2].shift_kind;
10455
10456 Rn = inst.operands[2].reg;
10457 /* See if we can do this with a 16-bit instruction. */
10458 if (!inst.operands[2].shifted && inst.size_req != 4)
10459 {
10460 if (Rd > 7 || Rs > 7 || Rn > 7)
10461 narrow = FALSE;
10462
10463 if (narrow)
10464 {
10465 inst.instruction = ((inst.instruction == T_MNEM_adds
10466 || inst.instruction == T_MNEM_add)
10467 ? T_OPCODE_ADD_R3
10468 : T_OPCODE_SUB_R3);
10469 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10470 return;
10471 }
10472
10473 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
10474 {
10475 /* Thumb-1 cores (except v6-M) require at least one high
10476 register in a narrow non flag setting add. */
10477 if (Rd > 7 || Rn > 7
10478 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10479 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
10480 {
10481 if (Rd == Rn)
10482 {
10483 Rn = Rs;
10484 Rs = Rd;
10485 }
10486 inst.instruction = T_OPCODE_ADD_HI;
10487 inst.instruction |= (Rd & 8) << 4;
10488 inst.instruction |= (Rd & 7);
10489 inst.instruction |= Rn << 3;
10490 return;
10491 }
10492 }
10493 }
10494
10495 constraint (Rd == REG_PC, BAD_PC);
10496 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10497 constraint (Rs == REG_PC, BAD_PC);
10498 reject_bad_reg (Rn);
10499
10500 /* If we get here, it can't be done in 16 bits. */
10501 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10502 _("shift must be constant"));
10503 inst.instruction = THUMB_OP32 (inst.instruction);
10504 inst.instruction |= Rd << 8;
10505 inst.instruction |= Rs << 16;
10506 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10507 _("shift value over 3 not allowed in thumb mode"));
10508 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10509 _("only LSL shift allowed in thumb mode"));
10510 encode_thumb32_shifted_operand (2);
10511 }
10512 }
10513 else
10514 {
10515 constraint (inst.instruction == T_MNEM_adds
10516 || inst.instruction == T_MNEM_subs,
10517 BAD_THUMB32);
10518
10519 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
10520 {
10521 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10522 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10523 BAD_HIREG);
10524
10525 inst.instruction = (inst.instruction == T_MNEM_add
10526 ? 0x0000 : 0x8000);
10527 inst.instruction |= (Rd << 4) | Rs;
10528 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10529 return;
10530 }
10531
10532 Rn = inst.operands[2].reg;
10533 constraint (inst.operands[2].shifted, _("unshifted register required"));
10534
10535 /* We now have Rd, Rs, and Rn set to registers. */
10536 if (Rd > 7 || Rs > 7 || Rn > 7)
10537 {
10538 /* Can't do this for SUB. */
10539 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10540 inst.instruction = T_OPCODE_ADD_HI;
10541 inst.instruction |= (Rd & 8) << 4;
10542 inst.instruction |= (Rd & 7);
10543 if (Rs == Rd)
10544 inst.instruction |= Rn << 3;
10545 else if (Rn == Rd)
10546 inst.instruction |= Rs << 3;
10547 else
10548 constraint (1, _("dest must overlap one source register"));
10549 }
10550 else
10551 {
10552 inst.instruction = (inst.instruction == T_MNEM_add
10553 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10554 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10555 }
10556 }
10557 }
10558
10559 static void
10560 do_t_adr (void)
10561 {
10562 unsigned Rd;
10563
10564 Rd = inst.operands[0].reg;
10565 reject_bad_reg (Rd);
10566
10567 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
10568 {
10569 /* Defer to section relaxation. */
10570 inst.relax = inst.instruction;
10571 inst.instruction = THUMB_OP16 (inst.instruction);
10572 inst.instruction |= Rd << 4;
10573 }
10574 else if (unified_syntax && inst.size_req != 2)
10575 {
10576 /* Generate a 32-bit opcode. */
10577 inst.instruction = THUMB_OP32 (inst.instruction);
10578 inst.instruction |= Rd << 8;
10579 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
10580 inst.reloc.pc_rel = 1;
10581 }
10582 else
10583 {
10584 /* Generate a 16-bit opcode. */
10585 inst.instruction = THUMB_OP16 (inst.instruction);
10586 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10587 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
10588 inst.reloc.pc_rel = 1;
10589
10590 inst.instruction |= Rd << 4;
10591 }
10592 }
10593
10594 /* Arithmetic instructions for which there is just one 16-bit
10595 instruction encoding, and it allows only two low registers.
10596 For maximal compatibility with ARM syntax, we allow three register
10597 operands even when Thumb-32 instructions are not available, as long
10598 as the first two are identical. For instance, both "sbc r0,r1" and
10599 "sbc r0,r0,r1" are allowed. */
10600 static void
10601 do_t_arit3 (void)
10602 {
10603 int Rd, Rs, Rn;
10604
10605 Rd = inst.operands[0].reg;
10606 Rs = (inst.operands[1].present
10607 ? inst.operands[1].reg /* Rd, Rs, foo */
10608 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10609 Rn = inst.operands[2].reg;
10610
10611 reject_bad_reg (Rd);
10612 reject_bad_reg (Rs);
10613 if (inst.operands[2].isreg)
10614 reject_bad_reg (Rn);
10615
10616 if (unified_syntax)
10617 {
10618 if (!inst.operands[2].isreg)
10619 {
10620 /* For an immediate, we always generate a 32-bit opcode;
10621 section relaxation will shrink it later if possible. */
10622 inst.instruction = THUMB_OP32 (inst.instruction);
10623 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10624 inst.instruction |= Rd << 8;
10625 inst.instruction |= Rs << 16;
10626 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10627 }
10628 else
10629 {
10630 bfd_boolean narrow;
10631
10632 /* See if we can do this with a 16-bit instruction. */
10633 if (THUMB_SETS_FLAGS (inst.instruction))
10634 narrow = !in_it_block ();
10635 else
10636 narrow = in_it_block ();
10637
10638 if (Rd > 7 || Rn > 7 || Rs > 7)
10639 narrow = FALSE;
10640 if (inst.operands[2].shifted)
10641 narrow = FALSE;
10642 if (inst.size_req == 4)
10643 narrow = FALSE;
10644
10645 if (narrow
10646 && Rd == Rs)
10647 {
10648 inst.instruction = THUMB_OP16 (inst.instruction);
10649 inst.instruction |= Rd;
10650 inst.instruction |= Rn << 3;
10651 return;
10652 }
10653
10654 /* If we get here, it can't be done in 16 bits. */
10655 constraint (inst.operands[2].shifted
10656 && inst.operands[2].immisreg,
10657 _("shift must be constant"));
10658 inst.instruction = THUMB_OP32 (inst.instruction);
10659 inst.instruction |= Rd << 8;
10660 inst.instruction |= Rs << 16;
10661 encode_thumb32_shifted_operand (2);
10662 }
10663 }
10664 else
10665 {
10666 /* On its face this is a lie - the instruction does set the
10667 flags. However, the only supported mnemonic in this mode
10668 says it doesn't. */
10669 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10670
10671 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10672 _("unshifted register required"));
10673 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10674 constraint (Rd != Rs,
10675 _("dest and source1 must be the same register"));
10676
10677 inst.instruction = THUMB_OP16 (inst.instruction);
10678 inst.instruction |= Rd;
10679 inst.instruction |= Rn << 3;
10680 }
10681 }
10682
10683 /* Similarly, but for instructions where the arithmetic operation is
10684 commutative, so we can allow either of them to be different from
10685 the destination operand in a 16-bit instruction. For instance, all
10686 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10687 accepted. */
10688 static void
10689 do_t_arit3c (void)
10690 {
10691 int Rd, Rs, Rn;
10692
10693 Rd = inst.operands[0].reg;
10694 Rs = (inst.operands[1].present
10695 ? inst.operands[1].reg /* Rd, Rs, foo */
10696 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10697 Rn = inst.operands[2].reg;
10698
10699 reject_bad_reg (Rd);
10700 reject_bad_reg (Rs);
10701 if (inst.operands[2].isreg)
10702 reject_bad_reg (Rn);
10703
10704 if (unified_syntax)
10705 {
10706 if (!inst.operands[2].isreg)
10707 {
10708 /* For an immediate, we always generate a 32-bit opcode;
10709 section relaxation will shrink it later if possible. */
10710 inst.instruction = THUMB_OP32 (inst.instruction);
10711 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10712 inst.instruction |= Rd << 8;
10713 inst.instruction |= Rs << 16;
10714 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10715 }
10716 else
10717 {
10718 bfd_boolean narrow;
10719
10720 /* See if we can do this with a 16-bit instruction. */
10721 if (THUMB_SETS_FLAGS (inst.instruction))
10722 narrow = !in_it_block ();
10723 else
10724 narrow = in_it_block ();
10725
10726 if (Rd > 7 || Rn > 7 || Rs > 7)
10727 narrow = FALSE;
10728 if (inst.operands[2].shifted)
10729 narrow = FALSE;
10730 if (inst.size_req == 4)
10731 narrow = FALSE;
10732
10733 if (narrow)
10734 {
10735 if (Rd == Rs)
10736 {
10737 inst.instruction = THUMB_OP16 (inst.instruction);
10738 inst.instruction |= Rd;
10739 inst.instruction |= Rn << 3;
10740 return;
10741 }
10742 if (Rd == Rn)
10743 {
10744 inst.instruction = THUMB_OP16 (inst.instruction);
10745 inst.instruction |= Rd;
10746 inst.instruction |= Rs << 3;
10747 return;
10748 }
10749 }
10750
10751 /* If we get here, it can't be done in 16 bits. */
10752 constraint (inst.operands[2].shifted
10753 && inst.operands[2].immisreg,
10754 _("shift must be constant"));
10755 inst.instruction = THUMB_OP32 (inst.instruction);
10756 inst.instruction |= Rd << 8;
10757 inst.instruction |= Rs << 16;
10758 encode_thumb32_shifted_operand (2);
10759 }
10760 }
10761 else
10762 {
10763 /* On its face this is a lie - the instruction does set the
10764 flags. However, the only supported mnemonic in this mode
10765 says it doesn't. */
10766 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10767
10768 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10769 _("unshifted register required"));
10770 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10771
10772 inst.instruction = THUMB_OP16 (inst.instruction);
10773 inst.instruction |= Rd;
10774
10775 if (Rd == Rs)
10776 inst.instruction |= Rn << 3;
10777 else if (Rd == Rn)
10778 inst.instruction |= Rs << 3;
10779 else
10780 constraint (1, _("dest must overlap one source register"));
10781 }
10782 }
10783
10784 static void
10785 do_t_bfc (void)
10786 {
10787 unsigned Rd;
10788 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
10789 constraint (msb > 32, _("bit-field extends past end of register"));
10790 /* The instruction encoding stores the LSB and MSB,
10791 not the LSB and width. */
10792 Rd = inst.operands[0].reg;
10793 reject_bad_reg (Rd);
10794 inst.instruction |= Rd << 8;
10795 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
10796 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
10797 inst.instruction |= msb - 1;
10798 }
10799
10800 static void
10801 do_t_bfi (void)
10802 {
10803 int Rd, Rn;
10804 unsigned int msb;
10805
10806 Rd = inst.operands[0].reg;
10807 reject_bad_reg (Rd);
10808
10809 /* #0 in second position is alternative syntax for bfc, which is
10810 the same instruction but with REG_PC in the Rm field. */
10811 if (!inst.operands[1].isreg)
10812 Rn = REG_PC;
10813 else
10814 {
10815 Rn = inst.operands[1].reg;
10816 reject_bad_reg (Rn);
10817 }
10818
10819 msb = inst.operands[2].imm + inst.operands[3].imm;
10820 constraint (msb > 32, _("bit-field extends past end of register"));
10821 /* The instruction encoding stores the LSB and MSB,
10822 not the LSB and width. */
10823 inst.instruction |= Rd << 8;
10824 inst.instruction |= Rn << 16;
10825 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10826 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10827 inst.instruction |= msb - 1;
10828 }
10829
10830 static void
10831 do_t_bfx (void)
10832 {
10833 unsigned Rd, Rn;
10834
10835 Rd = inst.operands[0].reg;
10836 Rn = inst.operands[1].reg;
10837
10838 reject_bad_reg (Rd);
10839 reject_bad_reg (Rn);
10840
10841 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
10842 _("bit-field extends past end of register"));
10843 inst.instruction |= Rd << 8;
10844 inst.instruction |= Rn << 16;
10845 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10846 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10847 inst.instruction |= inst.operands[3].imm - 1;
10848 }
10849
10850 /* ARM V5 Thumb BLX (argument parse)
10851 BLX <target_addr> which is BLX(1)
10852 BLX <Rm> which is BLX(2)
10853 Unfortunately, there are two different opcodes for this mnemonic.
10854 So, the insns[].value is not used, and the code here zaps values
10855 into inst.instruction.
10856
10857 ??? How to take advantage of the additional two bits of displacement
10858 available in Thumb32 mode? Need new relocation? */
10859
10860 static void
10861 do_t_blx (void)
10862 {
10863 set_it_insn_type_last ();
10864
10865 if (inst.operands[0].isreg)
10866 {
10867 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
10868 /* We have a register, so this is BLX(2). */
10869 inst.instruction |= inst.operands[0].reg << 3;
10870 }
10871 else
10872 {
10873 /* No register. This must be BLX(1). */
10874 inst.instruction = 0xf000e800;
10875 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
10876 }
10877 }
10878
10879 static void
10880 do_t_branch (void)
10881 {
10882 int opcode;
10883 int cond;
10884 int reloc;
10885
10886 cond = inst.cond;
10887 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
10888
10889 if (in_it_block ())
10890 {
10891 /* Conditional branches inside IT blocks are encoded as unconditional
10892 branches. */
10893 cond = COND_ALWAYS;
10894 }
10895 else
10896 cond = inst.cond;
10897
10898 if (cond != COND_ALWAYS)
10899 opcode = T_MNEM_bcond;
10900 else
10901 opcode = inst.instruction;
10902
10903 if (unified_syntax
10904 && (inst.size_req == 4
10905 || (inst.size_req != 2
10906 && (inst.operands[0].hasreloc
10907 || inst.reloc.exp.X_op == O_constant))))
10908 {
10909 inst.instruction = THUMB_OP32(opcode);
10910 if (cond == COND_ALWAYS)
10911 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
10912 else
10913 {
10914 gas_assert (cond != 0xF);
10915 inst.instruction |= cond << 22;
10916 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
10917 }
10918 }
10919 else
10920 {
10921 inst.instruction = THUMB_OP16(opcode);
10922 if (cond == COND_ALWAYS)
10923 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
10924 else
10925 {
10926 inst.instruction |= cond << 8;
10927 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
10928 }
10929 /* Allow section relaxation. */
10930 if (unified_syntax && inst.size_req != 2)
10931 inst.relax = opcode;
10932 }
10933 inst.reloc.type = reloc;
10934 inst.reloc.pc_rel = 1;
10935 }
10936
10937 /* Actually do the work for Thumb state bkpt and hlt. The only difference
10938 between the two is the maximum immediate allowed - which is passed in
10939 RANGE. */
10940 static void
10941 do_t_bkpt_hlt1 (int range)
10942 {
10943 constraint (inst.cond != COND_ALWAYS,
10944 _("instruction is always unconditional"));
10945 if (inst.operands[0].present)
10946 {
10947 constraint (inst.operands[0].imm > range,
10948 _("immediate value out of range"));
10949 inst.instruction |= inst.operands[0].imm;
10950 }
10951
10952 set_it_insn_type (NEUTRAL_IT_INSN);
10953 }
10954
10955 static void
10956 do_t_hlt (void)
10957 {
10958 do_t_bkpt_hlt1 (63);
10959 }
10960
10961 static void
10962 do_t_bkpt (void)
10963 {
10964 do_t_bkpt_hlt1 (255);
10965 }
10966
10967 static void
10968 do_t_branch23 (void)
10969 {
10970 set_it_insn_type_last ();
10971 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
10972
10973 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
10974 this file. We used to simply ignore the PLT reloc type here --
10975 the branch encoding is now needed to deal with TLSCALL relocs.
10976 So if we see a PLT reloc now, put it back to how it used to be to
10977 keep the preexisting behaviour. */
10978 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
10979 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
10980
10981 #if defined(OBJ_COFF)
10982 /* If the destination of the branch is a defined symbol which does not have
10983 the THUMB_FUNC attribute, then we must be calling a function which has
10984 the (interfacearm) attribute. We look for the Thumb entry point to that
10985 function and change the branch to refer to that function instead. */
10986 if ( inst.reloc.exp.X_op == O_symbol
10987 && inst.reloc.exp.X_add_symbol != NULL
10988 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
10989 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
10990 inst.reloc.exp.X_add_symbol =
10991 find_real_start (inst.reloc.exp.X_add_symbol);
10992 #endif
10993 }
10994
10995 static void
10996 do_t_bx (void)
10997 {
10998 set_it_insn_type_last ();
10999 inst.instruction |= inst.operands[0].reg << 3;
11000 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
11001 should cause the alignment to be checked once it is known. This is
11002 because BX PC only works if the instruction is word aligned. */
11003 }
11004
11005 static void
11006 do_t_bxj (void)
11007 {
11008 int Rm;
11009
11010 set_it_insn_type_last ();
11011 Rm = inst.operands[0].reg;
11012 reject_bad_reg (Rm);
11013 inst.instruction |= Rm << 16;
11014 }
11015
11016 static void
11017 do_t_clz (void)
11018 {
11019 unsigned Rd;
11020 unsigned Rm;
11021
11022 Rd = inst.operands[0].reg;
11023 Rm = inst.operands[1].reg;
11024
11025 reject_bad_reg (Rd);
11026 reject_bad_reg (Rm);
11027
11028 inst.instruction |= Rd << 8;
11029 inst.instruction |= Rm << 16;
11030 inst.instruction |= Rm;
11031 }
11032
11033 static void
11034 do_t_cps (void)
11035 {
11036 set_it_insn_type (OUTSIDE_IT_INSN);
11037 inst.instruction |= inst.operands[0].imm;
11038 }
11039
11040 static void
11041 do_t_cpsi (void)
11042 {
11043 set_it_insn_type (OUTSIDE_IT_INSN);
11044 if (unified_syntax
11045 && (inst.operands[1].present || inst.size_req == 4)
11046 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
11047 {
11048 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11049 inst.instruction = 0xf3af8000;
11050 inst.instruction |= imod << 9;
11051 inst.instruction |= inst.operands[0].imm << 5;
11052 if (inst.operands[1].present)
11053 inst.instruction |= 0x100 | inst.operands[1].imm;
11054 }
11055 else
11056 {
11057 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11058 && (inst.operands[0].imm & 4),
11059 _("selected processor does not support 'A' form "
11060 "of this instruction"));
11061 constraint (inst.operands[1].present || inst.size_req == 4,
11062 _("Thumb does not support the 2-argument "
11063 "form of this instruction"));
11064 inst.instruction |= inst.operands[0].imm;
11065 }
11066 }
11067
11068 /* THUMB CPY instruction (argument parse). */
11069
11070 static void
11071 do_t_cpy (void)
11072 {
11073 if (inst.size_req == 4)
11074 {
11075 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11076 inst.instruction |= inst.operands[0].reg << 8;
11077 inst.instruction |= inst.operands[1].reg;
11078 }
11079 else
11080 {
11081 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11082 inst.instruction |= (inst.operands[0].reg & 0x7);
11083 inst.instruction |= inst.operands[1].reg << 3;
11084 }
11085 }
11086
11087 static void
11088 do_t_cbz (void)
11089 {
11090 set_it_insn_type (OUTSIDE_IT_INSN);
11091 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11092 inst.instruction |= inst.operands[0].reg;
11093 inst.reloc.pc_rel = 1;
11094 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
11095 }
11096
11097 static void
11098 do_t_dbg (void)
11099 {
11100 inst.instruction |= inst.operands[0].imm;
11101 }
11102
11103 static void
11104 do_t_div (void)
11105 {
11106 unsigned Rd, Rn, Rm;
11107
11108 Rd = inst.operands[0].reg;
11109 Rn = (inst.operands[1].present
11110 ? inst.operands[1].reg : Rd);
11111 Rm = inst.operands[2].reg;
11112
11113 reject_bad_reg (Rd);
11114 reject_bad_reg (Rn);
11115 reject_bad_reg (Rm);
11116
11117 inst.instruction |= Rd << 8;
11118 inst.instruction |= Rn << 16;
11119 inst.instruction |= Rm;
11120 }
11121
11122 static void
11123 do_t_hint (void)
11124 {
11125 if (unified_syntax && inst.size_req == 4)
11126 inst.instruction = THUMB_OP32 (inst.instruction);
11127 else
11128 inst.instruction = THUMB_OP16 (inst.instruction);
11129 }
11130
11131 static void
11132 do_t_it (void)
11133 {
11134 unsigned int cond = inst.operands[0].imm;
11135
11136 set_it_insn_type (IT_INSN);
11137 now_it.mask = (inst.instruction & 0xf) | 0x10;
11138 now_it.cc = cond;
11139 now_it.warn_deprecated = FALSE;
11140
11141 /* If the condition is a negative condition, invert the mask. */
11142 if ((cond & 0x1) == 0x0)
11143 {
11144 unsigned int mask = inst.instruction & 0x000f;
11145
11146 if ((mask & 0x7) == 0)
11147 {
11148 /* No conversion needed. */
11149 now_it.block_length = 1;
11150 }
11151 else if ((mask & 0x3) == 0)
11152 {
11153 mask ^= 0x8;
11154 now_it.block_length = 2;
11155 }
11156 else if ((mask & 0x1) == 0)
11157 {
11158 mask ^= 0xC;
11159 now_it.block_length = 3;
11160 }
11161 else
11162 {
11163 mask ^= 0xE;
11164 now_it.block_length = 4;
11165 }
11166
11167 inst.instruction &= 0xfff0;
11168 inst.instruction |= mask;
11169 }
11170
11171 inst.instruction |= cond << 4;
11172 }
11173
11174 /* Helper function used for both push/pop and ldm/stm. */
11175 static void
11176 encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11177 {
11178 bfd_boolean load;
11179
11180 load = (inst.instruction & (1 << 20)) != 0;
11181
11182 if (mask & (1 << 13))
11183 inst.error = _("SP not allowed in register list");
11184
11185 if ((mask & (1 << base)) != 0
11186 && writeback)
11187 inst.error = _("having the base register in the register list when "
11188 "using write back is UNPREDICTABLE");
11189
11190 if (load)
11191 {
11192 if (mask & (1 << 15))
11193 {
11194 if (mask & (1 << 14))
11195 inst.error = _("LR and PC should not both be in register list");
11196 else
11197 set_it_insn_type_last ();
11198 }
11199 }
11200 else
11201 {
11202 if (mask & (1 << 15))
11203 inst.error = _("PC not allowed in register list");
11204 }
11205
11206 if ((mask & (mask - 1)) == 0)
11207 {
11208 /* Single register transfers implemented as str/ldr. */
11209 if (writeback)
11210 {
11211 if (inst.instruction & (1 << 23))
11212 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11213 else
11214 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11215 }
11216 else
11217 {
11218 if (inst.instruction & (1 << 23))
11219 inst.instruction = 0x00800000; /* ia -> [base] */
11220 else
11221 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11222 }
11223
11224 inst.instruction |= 0xf8400000;
11225 if (load)
11226 inst.instruction |= 0x00100000;
11227
11228 mask = ffs (mask) - 1;
11229 mask <<= 12;
11230 }
11231 else if (writeback)
11232 inst.instruction |= WRITE_BACK;
11233
11234 inst.instruction |= mask;
11235 inst.instruction |= base << 16;
11236 }
11237
11238 static void
11239 do_t_ldmstm (void)
11240 {
11241 /* This really doesn't seem worth it. */
11242 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11243 _("expression too complex"));
11244 constraint (inst.operands[1].writeback,
11245 _("Thumb load/store multiple does not support {reglist}^"));
11246
11247 if (unified_syntax)
11248 {
11249 bfd_boolean narrow;
11250 unsigned mask;
11251
11252 narrow = FALSE;
11253 /* See if we can use a 16-bit instruction. */
11254 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11255 && inst.size_req != 4
11256 && !(inst.operands[1].imm & ~0xff))
11257 {
11258 mask = 1 << inst.operands[0].reg;
11259
11260 if (inst.operands[0].reg <= 7)
11261 {
11262 if (inst.instruction == T_MNEM_stmia
11263 ? inst.operands[0].writeback
11264 : (inst.operands[0].writeback
11265 == !(inst.operands[1].imm & mask)))
11266 {
11267 if (inst.instruction == T_MNEM_stmia
11268 && (inst.operands[1].imm & mask)
11269 && (inst.operands[1].imm & (mask - 1)))
11270 as_warn (_("value stored for r%d is UNKNOWN"),
11271 inst.operands[0].reg);
11272
11273 inst.instruction = THUMB_OP16 (inst.instruction);
11274 inst.instruction |= inst.operands[0].reg << 8;
11275 inst.instruction |= inst.operands[1].imm;
11276 narrow = TRUE;
11277 }
11278 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11279 {
11280 /* This means 1 register in reg list one of 3 situations:
11281 1. Instruction is stmia, but without writeback.
11282 2. lmdia without writeback, but with Rn not in
11283 reglist.
11284 3. ldmia with writeback, but with Rn in reglist.
11285 Case 3 is UNPREDICTABLE behaviour, so we handle
11286 case 1 and 2 which can be converted into a 16-bit
11287 str or ldr. The SP cases are handled below. */
11288 unsigned long opcode;
11289 /* First, record an error for Case 3. */
11290 if (inst.operands[1].imm & mask
11291 && inst.operands[0].writeback)
11292 inst.error =
11293 _("having the base register in the register list when "
11294 "using write back is UNPREDICTABLE");
11295
11296 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
11297 : T_MNEM_ldr);
11298 inst.instruction = THUMB_OP16 (opcode);
11299 inst.instruction |= inst.operands[0].reg << 3;
11300 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11301 narrow = TRUE;
11302 }
11303 }
11304 else if (inst.operands[0] .reg == REG_SP)
11305 {
11306 if (inst.operands[0].writeback)
11307 {
11308 inst.instruction =
11309 THUMB_OP16 (inst.instruction == T_MNEM_stmia
11310 ? T_MNEM_push : T_MNEM_pop);
11311 inst.instruction |= inst.operands[1].imm;
11312 narrow = TRUE;
11313 }
11314 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11315 {
11316 inst.instruction =
11317 THUMB_OP16 (inst.instruction == T_MNEM_stmia
11318 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
11319 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
11320 narrow = TRUE;
11321 }
11322 }
11323 }
11324
11325 if (!narrow)
11326 {
11327 if (inst.instruction < 0xffff)
11328 inst.instruction = THUMB_OP32 (inst.instruction);
11329
11330 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11331 inst.operands[0].writeback);
11332 }
11333 }
11334 else
11335 {
11336 constraint (inst.operands[0].reg > 7
11337 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
11338 constraint (inst.instruction != T_MNEM_ldmia
11339 && inst.instruction != T_MNEM_stmia,
11340 _("Thumb-2 instruction only valid in unified syntax"));
11341 if (inst.instruction == T_MNEM_stmia)
11342 {
11343 if (!inst.operands[0].writeback)
11344 as_warn (_("this instruction will write back the base register"));
11345 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11346 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
11347 as_warn (_("value stored for r%d is UNKNOWN"),
11348 inst.operands[0].reg);
11349 }
11350 else
11351 {
11352 if (!inst.operands[0].writeback
11353 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11354 as_warn (_("this instruction will write back the base register"));
11355 else if (inst.operands[0].writeback
11356 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11357 as_warn (_("this instruction will not write back the base register"));
11358 }
11359
11360 inst.instruction = THUMB_OP16 (inst.instruction);
11361 inst.instruction |= inst.operands[0].reg << 8;
11362 inst.instruction |= inst.operands[1].imm;
11363 }
11364 }
11365
11366 static void
11367 do_t_ldrex (void)
11368 {
11369 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11370 || inst.operands[1].postind || inst.operands[1].writeback
11371 || inst.operands[1].immisreg || inst.operands[1].shifted
11372 || inst.operands[1].negative,
11373 BAD_ADDR_MODE);
11374
11375 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11376
11377 inst.instruction |= inst.operands[0].reg << 12;
11378 inst.instruction |= inst.operands[1].reg << 16;
11379 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11380 }
11381
11382 static void
11383 do_t_ldrexd (void)
11384 {
11385 if (!inst.operands[1].present)
11386 {
11387 constraint (inst.operands[0].reg == REG_LR,
11388 _("r14 not allowed as first register "
11389 "when second register is omitted"));
11390 inst.operands[1].reg = inst.operands[0].reg + 1;
11391 }
11392 constraint (inst.operands[0].reg == inst.operands[1].reg,
11393 BAD_OVERLAP);
11394
11395 inst.instruction |= inst.operands[0].reg << 12;
11396 inst.instruction |= inst.operands[1].reg << 8;
11397 inst.instruction |= inst.operands[2].reg << 16;
11398 }
11399
11400 static void
11401 do_t_ldst (void)
11402 {
11403 unsigned long opcode;
11404 int Rn;
11405
11406 if (inst.operands[0].isreg
11407 && !inst.operands[0].preind
11408 && inst.operands[0].reg == REG_PC)
11409 set_it_insn_type_last ();
11410
11411 opcode = inst.instruction;
11412 if (unified_syntax)
11413 {
11414 if (!inst.operands[1].isreg)
11415 {
11416 if (opcode <= 0xffff)
11417 inst.instruction = THUMB_OP32 (opcode);
11418 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
11419 return;
11420 }
11421 if (inst.operands[1].isreg
11422 && !inst.operands[1].writeback
11423 && !inst.operands[1].shifted && !inst.operands[1].postind
11424 && !inst.operands[1].negative && inst.operands[0].reg <= 7
11425 && opcode <= 0xffff
11426 && inst.size_req != 4)
11427 {
11428 /* Insn may have a 16-bit form. */
11429 Rn = inst.operands[1].reg;
11430 if (inst.operands[1].immisreg)
11431 {
11432 inst.instruction = THUMB_OP16 (opcode);
11433 /* [Rn, Rik] */
11434 if (Rn <= 7 && inst.operands[1].imm <= 7)
11435 goto op16;
11436 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11437 reject_bad_reg (inst.operands[1].imm);
11438 }
11439 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11440 && opcode != T_MNEM_ldrsb)
11441 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11442 || (Rn == REG_SP && opcode == T_MNEM_str))
11443 {
11444 /* [Rn, #const] */
11445 if (Rn > 7)
11446 {
11447 if (Rn == REG_PC)
11448 {
11449 if (inst.reloc.pc_rel)
11450 opcode = T_MNEM_ldr_pc2;
11451 else
11452 opcode = T_MNEM_ldr_pc;
11453 }
11454 else
11455 {
11456 if (opcode == T_MNEM_ldr)
11457 opcode = T_MNEM_ldr_sp;
11458 else
11459 opcode = T_MNEM_str_sp;
11460 }
11461 inst.instruction = inst.operands[0].reg << 8;
11462 }
11463 else
11464 {
11465 inst.instruction = inst.operands[0].reg;
11466 inst.instruction |= inst.operands[1].reg << 3;
11467 }
11468 inst.instruction |= THUMB_OP16 (opcode);
11469 if (inst.size_req == 2)
11470 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11471 else
11472 inst.relax = opcode;
11473 return;
11474 }
11475 }
11476 /* Definitely a 32-bit variant. */
11477
11478 /* Warning for Erratum 752419. */
11479 if (opcode == T_MNEM_ldr
11480 && inst.operands[0].reg == REG_SP
11481 && inst.operands[1].writeback == 1
11482 && !inst.operands[1].immisreg)
11483 {
11484 if (no_cpu_selected ()
11485 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
11486 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11487 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
11488 as_warn (_("This instruction may be unpredictable "
11489 "if executed on M-profile cores "
11490 "with interrupts enabled."));
11491 }
11492
11493 /* Do some validations regarding addressing modes. */
11494 if (inst.operands[1].immisreg)
11495 reject_bad_reg (inst.operands[1].imm);
11496
11497 constraint (inst.operands[1].writeback == 1
11498 && inst.operands[0].reg == inst.operands[1].reg,
11499 BAD_OVERLAP);
11500
11501 inst.instruction = THUMB_OP32 (opcode);
11502 inst.instruction |= inst.operands[0].reg << 12;
11503 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
11504 check_ldr_r15_aligned ();
11505 return;
11506 }
11507
11508 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11509
11510 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
11511 {
11512 /* Only [Rn,Rm] is acceptable. */
11513 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11514 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11515 || inst.operands[1].postind || inst.operands[1].shifted
11516 || inst.operands[1].negative,
11517 _("Thumb does not support this addressing mode"));
11518 inst.instruction = THUMB_OP16 (inst.instruction);
11519 goto op16;
11520 }
11521
11522 inst.instruction = THUMB_OP16 (inst.instruction);
11523 if (!inst.operands[1].isreg)
11524 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
11525 return;
11526
11527 constraint (!inst.operands[1].preind
11528 || inst.operands[1].shifted
11529 || inst.operands[1].writeback,
11530 _("Thumb does not support this addressing mode"));
11531 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
11532 {
11533 constraint (inst.instruction & 0x0600,
11534 _("byte or halfword not valid for base register"));
11535 constraint (inst.operands[1].reg == REG_PC
11536 && !(inst.instruction & THUMB_LOAD_BIT),
11537 _("r15 based store not allowed"));
11538 constraint (inst.operands[1].immisreg,
11539 _("invalid base register for register offset"));
11540
11541 if (inst.operands[1].reg == REG_PC)
11542 inst.instruction = T_OPCODE_LDR_PC;
11543 else if (inst.instruction & THUMB_LOAD_BIT)
11544 inst.instruction = T_OPCODE_LDR_SP;
11545 else
11546 inst.instruction = T_OPCODE_STR_SP;
11547
11548 inst.instruction |= inst.operands[0].reg << 8;
11549 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11550 return;
11551 }
11552
11553 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11554 if (!inst.operands[1].immisreg)
11555 {
11556 /* Immediate offset. */
11557 inst.instruction |= inst.operands[0].reg;
11558 inst.instruction |= inst.operands[1].reg << 3;
11559 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11560 return;
11561 }
11562
11563 /* Register offset. */
11564 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11565 constraint (inst.operands[1].negative,
11566 _("Thumb does not support this addressing mode"));
11567
11568 op16:
11569 switch (inst.instruction)
11570 {
11571 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11572 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11573 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11574 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11575 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11576 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11577 case 0x5600 /* ldrsb */:
11578 case 0x5e00 /* ldrsh */: break;
11579 default: abort ();
11580 }
11581
11582 inst.instruction |= inst.operands[0].reg;
11583 inst.instruction |= inst.operands[1].reg << 3;
11584 inst.instruction |= inst.operands[1].imm << 6;
11585 }
11586
11587 static void
11588 do_t_ldstd (void)
11589 {
11590 if (!inst.operands[1].present)
11591 {
11592 inst.operands[1].reg = inst.operands[0].reg + 1;
11593 constraint (inst.operands[0].reg == REG_LR,
11594 _("r14 not allowed here"));
11595 constraint (inst.operands[0].reg == REG_R12,
11596 _("r12 not allowed here"));
11597 }
11598
11599 if (inst.operands[2].writeback
11600 && (inst.operands[0].reg == inst.operands[2].reg
11601 || inst.operands[1].reg == inst.operands[2].reg))
11602 as_warn (_("base register written back, and overlaps "
11603 "one of transfer registers"));
11604
11605 inst.instruction |= inst.operands[0].reg << 12;
11606 inst.instruction |= inst.operands[1].reg << 8;
11607 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
11608 }
11609
11610 static void
11611 do_t_ldstt (void)
11612 {
11613 inst.instruction |= inst.operands[0].reg << 12;
11614 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11615 }
11616
11617 static void
11618 do_t_mla (void)
11619 {
11620 unsigned Rd, Rn, Rm, Ra;
11621
11622 Rd = inst.operands[0].reg;
11623 Rn = inst.operands[1].reg;
11624 Rm = inst.operands[2].reg;
11625 Ra = inst.operands[3].reg;
11626
11627 reject_bad_reg (Rd);
11628 reject_bad_reg (Rn);
11629 reject_bad_reg (Rm);
11630 reject_bad_reg (Ra);
11631
11632 inst.instruction |= Rd << 8;
11633 inst.instruction |= Rn << 16;
11634 inst.instruction |= Rm;
11635 inst.instruction |= Ra << 12;
11636 }
11637
11638 static void
11639 do_t_mlal (void)
11640 {
11641 unsigned RdLo, RdHi, Rn, Rm;
11642
11643 RdLo = inst.operands[0].reg;
11644 RdHi = inst.operands[1].reg;
11645 Rn = inst.operands[2].reg;
11646 Rm = inst.operands[3].reg;
11647
11648 reject_bad_reg (RdLo);
11649 reject_bad_reg (RdHi);
11650 reject_bad_reg (Rn);
11651 reject_bad_reg (Rm);
11652
11653 inst.instruction |= RdLo << 12;
11654 inst.instruction |= RdHi << 8;
11655 inst.instruction |= Rn << 16;
11656 inst.instruction |= Rm;
11657 }
11658
11659 static void
11660 do_t_mov_cmp (void)
11661 {
11662 unsigned Rn, Rm;
11663
11664 Rn = inst.operands[0].reg;
11665 Rm = inst.operands[1].reg;
11666
11667 if (Rn == REG_PC)
11668 set_it_insn_type_last ();
11669
11670 if (unified_syntax)
11671 {
11672 int r0off = (inst.instruction == T_MNEM_mov
11673 || inst.instruction == T_MNEM_movs) ? 8 : 16;
11674 unsigned long opcode;
11675 bfd_boolean narrow;
11676 bfd_boolean low_regs;
11677
11678 low_regs = (Rn <= 7 && Rm <= 7);
11679 opcode = inst.instruction;
11680 if (in_it_block ())
11681 narrow = opcode != T_MNEM_movs;
11682 else
11683 narrow = opcode != T_MNEM_movs || low_regs;
11684 if (inst.size_req == 4
11685 || inst.operands[1].shifted)
11686 narrow = FALSE;
11687
11688 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11689 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11690 && !inst.operands[1].shifted
11691 && Rn == REG_PC
11692 && Rm == REG_LR)
11693 {
11694 inst.instruction = T2_SUBS_PC_LR;
11695 return;
11696 }
11697
11698 if (opcode == T_MNEM_cmp)
11699 {
11700 constraint (Rn == REG_PC, BAD_PC);
11701 if (narrow)
11702 {
11703 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11704 but valid. */
11705 warn_deprecated_sp (Rm);
11706 /* R15 was documented as a valid choice for Rm in ARMv6,
11707 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11708 tools reject R15, so we do too. */
11709 constraint (Rm == REG_PC, BAD_PC);
11710 }
11711 else
11712 reject_bad_reg (Rm);
11713 }
11714 else if (opcode == T_MNEM_mov
11715 || opcode == T_MNEM_movs)
11716 {
11717 if (inst.operands[1].isreg)
11718 {
11719 if (opcode == T_MNEM_movs)
11720 {
11721 reject_bad_reg (Rn);
11722 reject_bad_reg (Rm);
11723 }
11724 else if (narrow)
11725 {
11726 /* This is mov.n. */
11727 if ((Rn == REG_SP || Rn == REG_PC)
11728 && (Rm == REG_SP || Rm == REG_PC))
11729 {
11730 as_tsktsk (_("Use of r%u as a source register is "
11731 "deprecated when r%u is the destination "
11732 "register."), Rm, Rn);
11733 }
11734 }
11735 else
11736 {
11737 /* This is mov.w. */
11738 constraint (Rn == REG_PC, BAD_PC);
11739 constraint (Rm == REG_PC, BAD_PC);
11740 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
11741 }
11742 }
11743 else
11744 reject_bad_reg (Rn);
11745 }
11746
11747 if (!inst.operands[1].isreg)
11748 {
11749 /* Immediate operand. */
11750 if (!in_it_block () && opcode == T_MNEM_mov)
11751 narrow = 0;
11752 if (low_regs && narrow)
11753 {
11754 inst.instruction = THUMB_OP16 (opcode);
11755 inst.instruction |= Rn << 8;
11756 if (inst.size_req == 2)
11757 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
11758 else
11759 inst.relax = opcode;
11760 }
11761 else
11762 {
11763 inst.instruction = THUMB_OP32 (inst.instruction);
11764 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11765 inst.instruction |= Rn << r0off;
11766 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11767 }
11768 }
11769 else if (inst.operands[1].shifted && inst.operands[1].immisreg
11770 && (inst.instruction == T_MNEM_mov
11771 || inst.instruction == T_MNEM_movs))
11772 {
11773 /* Register shifts are encoded as separate shift instructions. */
11774 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
11775
11776 if (in_it_block ())
11777 narrow = !flags;
11778 else
11779 narrow = flags;
11780
11781 if (inst.size_req == 4)
11782 narrow = FALSE;
11783
11784 if (!low_regs || inst.operands[1].imm > 7)
11785 narrow = FALSE;
11786
11787 if (Rn != Rm)
11788 narrow = FALSE;
11789
11790 switch (inst.operands[1].shift_kind)
11791 {
11792 case SHIFT_LSL:
11793 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
11794 break;
11795 case SHIFT_ASR:
11796 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
11797 break;
11798 case SHIFT_LSR:
11799 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
11800 break;
11801 case SHIFT_ROR:
11802 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
11803 break;
11804 default:
11805 abort ();
11806 }
11807
11808 inst.instruction = opcode;
11809 if (narrow)
11810 {
11811 inst.instruction |= Rn;
11812 inst.instruction |= inst.operands[1].imm << 3;
11813 }
11814 else
11815 {
11816 if (flags)
11817 inst.instruction |= CONDS_BIT;
11818
11819 inst.instruction |= Rn << 8;
11820 inst.instruction |= Rm << 16;
11821 inst.instruction |= inst.operands[1].imm;
11822 }
11823 }
11824 else if (!narrow)
11825 {
11826 /* Some mov with immediate shift have narrow variants.
11827 Register shifts are handled above. */
11828 if (low_regs && inst.operands[1].shifted
11829 && (inst.instruction == T_MNEM_mov
11830 || inst.instruction == T_MNEM_movs))
11831 {
11832 if (in_it_block ())
11833 narrow = (inst.instruction == T_MNEM_mov);
11834 else
11835 narrow = (inst.instruction == T_MNEM_movs);
11836 }
11837
11838 if (narrow)
11839 {
11840 switch (inst.operands[1].shift_kind)
11841 {
11842 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11843 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11844 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11845 default: narrow = FALSE; break;
11846 }
11847 }
11848
11849 if (narrow)
11850 {
11851 inst.instruction |= Rn;
11852 inst.instruction |= Rm << 3;
11853 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11854 }
11855 else
11856 {
11857 inst.instruction = THUMB_OP32 (inst.instruction);
11858 inst.instruction |= Rn << r0off;
11859 encode_thumb32_shifted_operand (1);
11860 }
11861 }
11862 else
11863 switch (inst.instruction)
11864 {
11865 case T_MNEM_mov:
11866 /* In v4t or v5t a move of two lowregs produces unpredictable
11867 results. Don't allow this. */
11868 if (low_regs)
11869 {
11870 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
11871 "MOV Rd, Rs with two low registers is not "
11872 "permitted on this architecture");
11873 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
11874 arm_ext_v6);
11875 }
11876
11877 inst.instruction = T_OPCODE_MOV_HR;
11878 inst.instruction |= (Rn & 0x8) << 4;
11879 inst.instruction |= (Rn & 0x7);
11880 inst.instruction |= Rm << 3;
11881 break;
11882
11883 case T_MNEM_movs:
11884 /* We know we have low registers at this point.
11885 Generate LSLS Rd, Rs, #0. */
11886 inst.instruction = T_OPCODE_LSL_I;
11887 inst.instruction |= Rn;
11888 inst.instruction |= Rm << 3;
11889 break;
11890
11891 case T_MNEM_cmp:
11892 if (low_regs)
11893 {
11894 inst.instruction = T_OPCODE_CMP_LR;
11895 inst.instruction |= Rn;
11896 inst.instruction |= Rm << 3;
11897 }
11898 else
11899 {
11900 inst.instruction = T_OPCODE_CMP_HR;
11901 inst.instruction |= (Rn & 0x8) << 4;
11902 inst.instruction |= (Rn & 0x7);
11903 inst.instruction |= Rm << 3;
11904 }
11905 break;
11906 }
11907 return;
11908 }
11909
11910 inst.instruction = THUMB_OP16 (inst.instruction);
11911
11912 /* PR 10443: Do not silently ignore shifted operands. */
11913 constraint (inst.operands[1].shifted,
11914 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
11915
11916 if (inst.operands[1].isreg)
11917 {
11918 if (Rn < 8 && Rm < 8)
11919 {
11920 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
11921 since a MOV instruction produces unpredictable results. */
11922 if (inst.instruction == T_OPCODE_MOV_I8)
11923 inst.instruction = T_OPCODE_ADD_I3;
11924 else
11925 inst.instruction = T_OPCODE_CMP_LR;
11926
11927 inst.instruction |= Rn;
11928 inst.instruction |= Rm << 3;
11929 }
11930 else
11931 {
11932 if (inst.instruction == T_OPCODE_MOV_I8)
11933 inst.instruction = T_OPCODE_MOV_HR;
11934 else
11935 inst.instruction = T_OPCODE_CMP_HR;
11936 do_t_cpy ();
11937 }
11938 }
11939 else
11940 {
11941 constraint (Rn > 7,
11942 _("only lo regs allowed with immediate"));
11943 inst.instruction |= Rn << 8;
11944 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
11945 }
11946 }
11947
11948 static void
11949 do_t_mov16 (void)
11950 {
11951 unsigned Rd;
11952 bfd_vma imm;
11953 bfd_boolean top;
11954
11955 top = (inst.instruction & 0x00800000) != 0;
11956 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
11957 {
11958 constraint (top, _(":lower16: not allowed this instruction"));
11959 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
11960 }
11961 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
11962 {
11963 constraint (!top, _(":upper16: not allowed this instruction"));
11964 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
11965 }
11966
11967 Rd = inst.operands[0].reg;
11968 reject_bad_reg (Rd);
11969
11970 inst.instruction |= Rd << 8;
11971 if (inst.reloc.type == BFD_RELOC_UNUSED)
11972 {
11973 imm = inst.reloc.exp.X_add_number;
11974 inst.instruction |= (imm & 0xf000) << 4;
11975 inst.instruction |= (imm & 0x0800) << 15;
11976 inst.instruction |= (imm & 0x0700) << 4;
11977 inst.instruction |= (imm & 0x00ff);
11978 }
11979 }
11980
11981 static void
11982 do_t_mvn_tst (void)
11983 {
11984 unsigned Rn, Rm;
11985
11986 Rn = inst.operands[0].reg;
11987 Rm = inst.operands[1].reg;
11988
11989 if (inst.instruction == T_MNEM_cmp
11990 || inst.instruction == T_MNEM_cmn)
11991 constraint (Rn == REG_PC, BAD_PC);
11992 else
11993 reject_bad_reg (Rn);
11994 reject_bad_reg (Rm);
11995
11996 if (unified_syntax)
11997 {
11998 int r0off = (inst.instruction == T_MNEM_mvn
11999 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
12000 bfd_boolean narrow;
12001
12002 if (inst.size_req == 4
12003 || inst.instruction > 0xffff
12004 || inst.operands[1].shifted
12005 || Rn > 7 || Rm > 7)
12006 narrow = FALSE;
12007 else if (inst.instruction == T_MNEM_cmn
12008 || inst.instruction == T_MNEM_tst)
12009 narrow = TRUE;
12010 else if (THUMB_SETS_FLAGS (inst.instruction))
12011 narrow = !in_it_block ();
12012 else
12013 narrow = in_it_block ();
12014
12015 if (!inst.operands[1].isreg)
12016 {
12017 /* For an immediate, we always generate a 32-bit opcode;
12018 section relaxation will shrink it later if possible. */
12019 if (inst.instruction < 0xffff)
12020 inst.instruction = THUMB_OP32 (inst.instruction);
12021 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12022 inst.instruction |= Rn << r0off;
12023 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12024 }
12025 else
12026 {
12027 /* See if we can do this with a 16-bit instruction. */
12028 if (narrow)
12029 {
12030 inst.instruction = THUMB_OP16 (inst.instruction);
12031 inst.instruction |= Rn;
12032 inst.instruction |= Rm << 3;
12033 }
12034 else
12035 {
12036 constraint (inst.operands[1].shifted
12037 && inst.operands[1].immisreg,
12038 _("shift must be constant"));
12039 if (inst.instruction < 0xffff)
12040 inst.instruction = THUMB_OP32 (inst.instruction);
12041 inst.instruction |= Rn << r0off;
12042 encode_thumb32_shifted_operand (1);
12043 }
12044 }
12045 }
12046 else
12047 {
12048 constraint (inst.instruction > 0xffff
12049 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12050 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12051 _("unshifted register required"));
12052 constraint (Rn > 7 || Rm > 7,
12053 BAD_HIREG);
12054
12055 inst.instruction = THUMB_OP16 (inst.instruction);
12056 inst.instruction |= Rn;
12057 inst.instruction |= Rm << 3;
12058 }
12059 }
12060
12061 static void
12062 do_t_mrs (void)
12063 {
12064 unsigned Rd;
12065
12066 if (do_vfp_nsyn_mrs () == SUCCESS)
12067 return;
12068
12069 Rd = inst.operands[0].reg;
12070 reject_bad_reg (Rd);
12071 inst.instruction |= Rd << 8;
12072
12073 if (inst.operands[1].isreg)
12074 {
12075 unsigned br = inst.operands[1].reg;
12076 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12077 as_bad (_("bad register for mrs"));
12078
12079 inst.instruction |= br & (0xf << 16);
12080 inst.instruction |= (br & 0x300) >> 4;
12081 inst.instruction |= (br & SPSR_BIT) >> 2;
12082 }
12083 else
12084 {
12085 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12086
12087 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
12088 {
12089 /* PR gas/12698: The constraint is only applied for m_profile.
12090 If the user has specified -march=all, we want to ignore it as
12091 we are building for any CPU type, including non-m variants. */
12092 bfd_boolean m_profile =
12093 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
12094 constraint ((flags != 0) && m_profile, _("selected processor does "
12095 "not support requested special purpose register"));
12096 }
12097 else
12098 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12099 devices). */
12100 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12101 _("'APSR', 'CPSR' or 'SPSR' expected"));
12102
12103 inst.instruction |= (flags & SPSR_BIT) >> 2;
12104 inst.instruction |= inst.operands[1].imm & 0xff;
12105 inst.instruction |= 0xf0000;
12106 }
12107 }
12108
12109 static void
12110 do_t_msr (void)
12111 {
12112 int flags;
12113 unsigned Rn;
12114
12115 if (do_vfp_nsyn_msr () == SUCCESS)
12116 return;
12117
12118 constraint (!inst.operands[1].isreg,
12119 _("Thumb encoding does not support an immediate here"));
12120
12121 if (inst.operands[0].isreg)
12122 flags = (int)(inst.operands[0].reg);
12123 else
12124 flags = inst.operands[0].imm;
12125
12126 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
12127 {
12128 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12129
12130 /* PR gas/12698: The constraint is only applied for m_profile.
12131 If the user has specified -march=all, we want to ignore it as
12132 we are building for any CPU type, including non-m variants. */
12133 bfd_boolean m_profile =
12134 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
12135 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12136 && (bits & ~(PSR_s | PSR_f)) != 0)
12137 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12138 && bits != PSR_f)) && m_profile,
12139 _("selected processor does not support requested special "
12140 "purpose register"));
12141 }
12142 else
12143 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12144 "requested special purpose register"));
12145
12146 Rn = inst.operands[1].reg;
12147 reject_bad_reg (Rn);
12148
12149 inst.instruction |= (flags & SPSR_BIT) >> 2;
12150 inst.instruction |= (flags & 0xf0000) >> 8;
12151 inst.instruction |= (flags & 0x300) >> 4;
12152 inst.instruction |= (flags & 0xff);
12153 inst.instruction |= Rn << 16;
12154 }
12155
12156 static void
12157 do_t_mul (void)
12158 {
12159 bfd_boolean narrow;
12160 unsigned Rd, Rn, Rm;
12161
12162 if (!inst.operands[2].present)
12163 inst.operands[2].reg = inst.operands[0].reg;
12164
12165 Rd = inst.operands[0].reg;
12166 Rn = inst.operands[1].reg;
12167 Rm = inst.operands[2].reg;
12168
12169 if (unified_syntax)
12170 {
12171 if (inst.size_req == 4
12172 || (Rd != Rn
12173 && Rd != Rm)
12174 || Rn > 7
12175 || Rm > 7)
12176 narrow = FALSE;
12177 else if (inst.instruction == T_MNEM_muls)
12178 narrow = !in_it_block ();
12179 else
12180 narrow = in_it_block ();
12181 }
12182 else
12183 {
12184 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
12185 constraint (Rn > 7 || Rm > 7,
12186 BAD_HIREG);
12187 narrow = TRUE;
12188 }
12189
12190 if (narrow)
12191 {
12192 /* 16-bit MULS/Conditional MUL. */
12193 inst.instruction = THUMB_OP16 (inst.instruction);
12194 inst.instruction |= Rd;
12195
12196 if (Rd == Rn)
12197 inst.instruction |= Rm << 3;
12198 else if (Rd == Rm)
12199 inst.instruction |= Rn << 3;
12200 else
12201 constraint (1, _("dest must overlap one source register"));
12202 }
12203 else
12204 {
12205 constraint (inst.instruction != T_MNEM_mul,
12206 _("Thumb-2 MUL must not set flags"));
12207 /* 32-bit MUL. */
12208 inst.instruction = THUMB_OP32 (inst.instruction);
12209 inst.instruction |= Rd << 8;
12210 inst.instruction |= Rn << 16;
12211 inst.instruction |= Rm << 0;
12212
12213 reject_bad_reg (Rd);
12214 reject_bad_reg (Rn);
12215 reject_bad_reg (Rm);
12216 }
12217 }
12218
12219 static void
12220 do_t_mull (void)
12221 {
12222 unsigned RdLo, RdHi, Rn, Rm;
12223
12224 RdLo = inst.operands[0].reg;
12225 RdHi = inst.operands[1].reg;
12226 Rn = inst.operands[2].reg;
12227 Rm = inst.operands[3].reg;
12228
12229 reject_bad_reg (RdLo);
12230 reject_bad_reg (RdHi);
12231 reject_bad_reg (Rn);
12232 reject_bad_reg (Rm);
12233
12234 inst.instruction |= RdLo << 12;
12235 inst.instruction |= RdHi << 8;
12236 inst.instruction |= Rn << 16;
12237 inst.instruction |= Rm;
12238
12239 if (RdLo == RdHi)
12240 as_tsktsk (_("rdhi and rdlo must be different"));
12241 }
12242
12243 static void
12244 do_t_nop (void)
12245 {
12246 set_it_insn_type (NEUTRAL_IT_INSN);
12247
12248 if (unified_syntax)
12249 {
12250 if (inst.size_req == 4 || inst.operands[0].imm > 15)
12251 {
12252 inst.instruction = THUMB_OP32 (inst.instruction);
12253 inst.instruction |= inst.operands[0].imm;
12254 }
12255 else
12256 {
12257 /* PR9722: Check for Thumb2 availability before
12258 generating a thumb2 nop instruction. */
12259 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
12260 {
12261 inst.instruction = THUMB_OP16 (inst.instruction);
12262 inst.instruction |= inst.operands[0].imm << 4;
12263 }
12264 else
12265 inst.instruction = 0x46c0;
12266 }
12267 }
12268 else
12269 {
12270 constraint (inst.operands[0].present,
12271 _("Thumb does not support NOP with hints"));
12272 inst.instruction = 0x46c0;
12273 }
12274 }
12275
12276 static void
12277 do_t_neg (void)
12278 {
12279 if (unified_syntax)
12280 {
12281 bfd_boolean narrow;
12282
12283 if (THUMB_SETS_FLAGS (inst.instruction))
12284 narrow = !in_it_block ();
12285 else
12286 narrow = in_it_block ();
12287 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12288 narrow = FALSE;
12289 if (inst.size_req == 4)
12290 narrow = FALSE;
12291
12292 if (!narrow)
12293 {
12294 inst.instruction = THUMB_OP32 (inst.instruction);
12295 inst.instruction |= inst.operands[0].reg << 8;
12296 inst.instruction |= inst.operands[1].reg << 16;
12297 }
12298 else
12299 {
12300 inst.instruction = THUMB_OP16 (inst.instruction);
12301 inst.instruction |= inst.operands[0].reg;
12302 inst.instruction |= inst.operands[1].reg << 3;
12303 }
12304 }
12305 else
12306 {
12307 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12308 BAD_HIREG);
12309 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12310
12311 inst.instruction = THUMB_OP16 (inst.instruction);
12312 inst.instruction |= inst.operands[0].reg;
12313 inst.instruction |= inst.operands[1].reg << 3;
12314 }
12315 }
12316
12317 static void
12318 do_t_orn (void)
12319 {
12320 unsigned Rd, Rn;
12321
12322 Rd = inst.operands[0].reg;
12323 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12324
12325 reject_bad_reg (Rd);
12326 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12327 reject_bad_reg (Rn);
12328
12329 inst.instruction |= Rd << 8;
12330 inst.instruction |= Rn << 16;
12331
12332 if (!inst.operands[2].isreg)
12333 {
12334 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12335 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12336 }
12337 else
12338 {
12339 unsigned Rm;
12340
12341 Rm = inst.operands[2].reg;
12342 reject_bad_reg (Rm);
12343
12344 constraint (inst.operands[2].shifted
12345 && inst.operands[2].immisreg,
12346 _("shift must be constant"));
12347 encode_thumb32_shifted_operand (2);
12348 }
12349 }
12350
12351 static void
12352 do_t_pkhbt (void)
12353 {
12354 unsigned Rd, Rn, Rm;
12355
12356 Rd = inst.operands[0].reg;
12357 Rn = inst.operands[1].reg;
12358 Rm = inst.operands[2].reg;
12359
12360 reject_bad_reg (Rd);
12361 reject_bad_reg (Rn);
12362 reject_bad_reg (Rm);
12363
12364 inst.instruction |= Rd << 8;
12365 inst.instruction |= Rn << 16;
12366 inst.instruction |= Rm;
12367 if (inst.operands[3].present)
12368 {
12369 unsigned int val = inst.reloc.exp.X_add_number;
12370 constraint (inst.reloc.exp.X_op != O_constant,
12371 _("expression too complex"));
12372 inst.instruction |= (val & 0x1c) << 10;
12373 inst.instruction |= (val & 0x03) << 6;
12374 }
12375 }
12376
12377 static void
12378 do_t_pkhtb (void)
12379 {
12380 if (!inst.operands[3].present)
12381 {
12382 unsigned Rtmp;
12383
12384 inst.instruction &= ~0x00000020;
12385
12386 /* PR 10168. Swap the Rm and Rn registers. */
12387 Rtmp = inst.operands[1].reg;
12388 inst.operands[1].reg = inst.operands[2].reg;
12389 inst.operands[2].reg = Rtmp;
12390 }
12391 do_t_pkhbt ();
12392 }
12393
12394 static void
12395 do_t_pld (void)
12396 {
12397 if (inst.operands[0].immisreg)
12398 reject_bad_reg (inst.operands[0].imm);
12399
12400 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12401 }
12402
12403 static void
12404 do_t_push_pop (void)
12405 {
12406 unsigned mask;
12407
12408 constraint (inst.operands[0].writeback,
12409 _("push/pop do not support {reglist}^"));
12410 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
12411 _("expression too complex"));
12412
12413 mask = inst.operands[0].imm;
12414 if (inst.size_req != 4 && (mask & ~0xff) == 0)
12415 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
12416 else if (inst.size_req != 4
12417 && (mask & ~0xff) == (1 << (inst.instruction == T_MNEM_push
12418 ? REG_LR : REG_PC)))
12419 {
12420 inst.instruction = THUMB_OP16 (inst.instruction);
12421 inst.instruction |= THUMB_PP_PC_LR;
12422 inst.instruction |= mask & 0xff;
12423 }
12424 else if (unified_syntax)
12425 {
12426 inst.instruction = THUMB_OP32 (inst.instruction);
12427 encode_thumb2_ldmstm (13, mask, TRUE);
12428 }
12429 else
12430 {
12431 inst.error = _("invalid register list to push/pop instruction");
12432 return;
12433 }
12434 }
12435
12436 static void
12437 do_t_rbit (void)
12438 {
12439 unsigned Rd, Rm;
12440
12441 Rd = inst.operands[0].reg;
12442 Rm = inst.operands[1].reg;
12443
12444 reject_bad_reg (Rd);
12445 reject_bad_reg (Rm);
12446
12447 inst.instruction |= Rd << 8;
12448 inst.instruction |= Rm << 16;
12449 inst.instruction |= Rm;
12450 }
12451
12452 static void
12453 do_t_rev (void)
12454 {
12455 unsigned Rd, Rm;
12456
12457 Rd = inst.operands[0].reg;
12458 Rm = inst.operands[1].reg;
12459
12460 reject_bad_reg (Rd);
12461 reject_bad_reg (Rm);
12462
12463 if (Rd <= 7 && Rm <= 7
12464 && inst.size_req != 4)
12465 {
12466 inst.instruction = THUMB_OP16 (inst.instruction);
12467 inst.instruction |= Rd;
12468 inst.instruction |= Rm << 3;
12469 }
12470 else if (unified_syntax)
12471 {
12472 inst.instruction = THUMB_OP32 (inst.instruction);
12473 inst.instruction |= Rd << 8;
12474 inst.instruction |= Rm << 16;
12475 inst.instruction |= Rm;
12476 }
12477 else
12478 inst.error = BAD_HIREG;
12479 }
12480
12481 static void
12482 do_t_rrx (void)
12483 {
12484 unsigned Rd, Rm;
12485
12486 Rd = inst.operands[0].reg;
12487 Rm = inst.operands[1].reg;
12488
12489 reject_bad_reg (Rd);
12490 reject_bad_reg (Rm);
12491
12492 inst.instruction |= Rd << 8;
12493 inst.instruction |= Rm;
12494 }
12495
12496 static void
12497 do_t_rsb (void)
12498 {
12499 unsigned Rd, Rs;
12500
12501 Rd = inst.operands[0].reg;
12502 Rs = (inst.operands[1].present
12503 ? inst.operands[1].reg /* Rd, Rs, foo */
12504 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
12505
12506 reject_bad_reg (Rd);
12507 reject_bad_reg (Rs);
12508 if (inst.operands[2].isreg)
12509 reject_bad_reg (inst.operands[2].reg);
12510
12511 inst.instruction |= Rd << 8;
12512 inst.instruction |= Rs << 16;
12513 if (!inst.operands[2].isreg)
12514 {
12515 bfd_boolean narrow;
12516
12517 if ((inst.instruction & 0x00100000) != 0)
12518 narrow = !in_it_block ();
12519 else
12520 narrow = in_it_block ();
12521
12522 if (Rd > 7 || Rs > 7)
12523 narrow = FALSE;
12524
12525 if (inst.size_req == 4 || !unified_syntax)
12526 narrow = FALSE;
12527
12528 if (inst.reloc.exp.X_op != O_constant
12529 || inst.reloc.exp.X_add_number != 0)
12530 narrow = FALSE;
12531
12532 /* Turn rsb #0 into 16-bit neg. We should probably do this via
12533 relaxation, but it doesn't seem worth the hassle. */
12534 if (narrow)
12535 {
12536 inst.reloc.type = BFD_RELOC_UNUSED;
12537 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12538 inst.instruction |= Rs << 3;
12539 inst.instruction |= Rd;
12540 }
12541 else
12542 {
12543 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12544 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12545 }
12546 }
12547 else
12548 encode_thumb32_shifted_operand (2);
12549 }
12550
12551 static void
12552 do_t_setend (void)
12553 {
12554 if (warn_on_deprecated
12555 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
12556 as_tsktsk (_("setend use is deprecated for ARMv8"));
12557
12558 set_it_insn_type (OUTSIDE_IT_INSN);
12559 if (inst.operands[0].imm)
12560 inst.instruction |= 0x8;
12561 }
12562
12563 static void
12564 do_t_shift (void)
12565 {
12566 if (!inst.operands[1].present)
12567 inst.operands[1].reg = inst.operands[0].reg;
12568
12569 if (unified_syntax)
12570 {
12571 bfd_boolean narrow;
12572 int shift_kind;
12573
12574 switch (inst.instruction)
12575 {
12576 case T_MNEM_asr:
12577 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12578 case T_MNEM_lsl:
12579 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12580 case T_MNEM_lsr:
12581 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12582 case T_MNEM_ror:
12583 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12584 default: abort ();
12585 }
12586
12587 if (THUMB_SETS_FLAGS (inst.instruction))
12588 narrow = !in_it_block ();
12589 else
12590 narrow = in_it_block ();
12591 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12592 narrow = FALSE;
12593 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12594 narrow = FALSE;
12595 if (inst.operands[2].isreg
12596 && (inst.operands[1].reg != inst.operands[0].reg
12597 || inst.operands[2].reg > 7))
12598 narrow = FALSE;
12599 if (inst.size_req == 4)
12600 narrow = FALSE;
12601
12602 reject_bad_reg (inst.operands[0].reg);
12603 reject_bad_reg (inst.operands[1].reg);
12604
12605 if (!narrow)
12606 {
12607 if (inst.operands[2].isreg)
12608 {
12609 reject_bad_reg (inst.operands[2].reg);
12610 inst.instruction = THUMB_OP32 (inst.instruction);
12611 inst.instruction |= inst.operands[0].reg << 8;
12612 inst.instruction |= inst.operands[1].reg << 16;
12613 inst.instruction |= inst.operands[2].reg;
12614
12615 /* PR 12854: Error on extraneous shifts. */
12616 constraint (inst.operands[2].shifted,
12617 _("extraneous shift as part of operand to shift insn"));
12618 }
12619 else
12620 {
12621 inst.operands[1].shifted = 1;
12622 inst.operands[1].shift_kind = shift_kind;
12623 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12624 ? T_MNEM_movs : T_MNEM_mov);
12625 inst.instruction |= inst.operands[0].reg << 8;
12626 encode_thumb32_shifted_operand (1);
12627 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
12628 inst.reloc.type = BFD_RELOC_UNUSED;
12629 }
12630 }
12631 else
12632 {
12633 if (inst.operands[2].isreg)
12634 {
12635 switch (shift_kind)
12636 {
12637 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12638 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12639 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12640 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
12641 default: abort ();
12642 }
12643
12644 inst.instruction |= inst.operands[0].reg;
12645 inst.instruction |= inst.operands[2].reg << 3;
12646
12647 /* PR 12854: Error on extraneous shifts. */
12648 constraint (inst.operands[2].shifted,
12649 _("extraneous shift as part of operand to shift insn"));
12650 }
12651 else
12652 {
12653 switch (shift_kind)
12654 {
12655 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12656 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12657 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
12658 default: abort ();
12659 }
12660 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12661 inst.instruction |= inst.operands[0].reg;
12662 inst.instruction |= inst.operands[1].reg << 3;
12663 }
12664 }
12665 }
12666 else
12667 {
12668 constraint (inst.operands[0].reg > 7
12669 || inst.operands[1].reg > 7, BAD_HIREG);
12670 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12671
12672 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12673 {
12674 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12675 constraint (inst.operands[0].reg != inst.operands[1].reg,
12676 _("source1 and dest must be same register"));
12677
12678 switch (inst.instruction)
12679 {
12680 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12681 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12682 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12683 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12684 default: abort ();
12685 }
12686
12687 inst.instruction |= inst.operands[0].reg;
12688 inst.instruction |= inst.operands[2].reg << 3;
12689
12690 /* PR 12854: Error on extraneous shifts. */
12691 constraint (inst.operands[2].shifted,
12692 _("extraneous shift as part of operand to shift insn"));
12693 }
12694 else
12695 {
12696 switch (inst.instruction)
12697 {
12698 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
12699 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
12700 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
12701 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12702 default: abort ();
12703 }
12704 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12705 inst.instruction |= inst.operands[0].reg;
12706 inst.instruction |= inst.operands[1].reg << 3;
12707 }
12708 }
12709 }
12710
12711 static void
12712 do_t_simd (void)
12713 {
12714 unsigned Rd, Rn, Rm;
12715
12716 Rd = inst.operands[0].reg;
12717 Rn = inst.operands[1].reg;
12718 Rm = inst.operands[2].reg;
12719
12720 reject_bad_reg (Rd);
12721 reject_bad_reg (Rn);
12722 reject_bad_reg (Rm);
12723
12724 inst.instruction |= Rd << 8;
12725 inst.instruction |= Rn << 16;
12726 inst.instruction |= Rm;
12727 }
12728
12729 static void
12730 do_t_simd2 (void)
12731 {
12732 unsigned Rd, Rn, Rm;
12733
12734 Rd = inst.operands[0].reg;
12735 Rm = inst.operands[1].reg;
12736 Rn = inst.operands[2].reg;
12737
12738 reject_bad_reg (Rd);
12739 reject_bad_reg (Rn);
12740 reject_bad_reg (Rm);
12741
12742 inst.instruction |= Rd << 8;
12743 inst.instruction |= Rn << 16;
12744 inst.instruction |= Rm;
12745 }
12746
12747 static void
12748 do_t_smc (void)
12749 {
12750 unsigned int value = inst.reloc.exp.X_add_number;
12751 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
12752 _("SMC is not permitted on this architecture"));
12753 constraint (inst.reloc.exp.X_op != O_constant,
12754 _("expression too complex"));
12755 inst.reloc.type = BFD_RELOC_UNUSED;
12756 inst.instruction |= (value & 0xf000) >> 12;
12757 inst.instruction |= (value & 0x0ff0);
12758 inst.instruction |= (value & 0x000f) << 16;
12759 /* PR gas/15623: SMC instructions must be last in an IT block. */
12760 set_it_insn_type_last ();
12761 }
12762
12763 static void
12764 do_t_hvc (void)
12765 {
12766 unsigned int value = inst.reloc.exp.X_add_number;
12767
12768 inst.reloc.type = BFD_RELOC_UNUSED;
12769 inst.instruction |= (value & 0x0fff);
12770 inst.instruction |= (value & 0xf000) << 4;
12771 }
12772
12773 static void
12774 do_t_ssat_usat (int bias)
12775 {
12776 unsigned Rd, Rn;
12777
12778 Rd = inst.operands[0].reg;
12779 Rn = inst.operands[2].reg;
12780
12781 reject_bad_reg (Rd);
12782 reject_bad_reg (Rn);
12783
12784 inst.instruction |= Rd << 8;
12785 inst.instruction |= inst.operands[1].imm - bias;
12786 inst.instruction |= Rn << 16;
12787
12788 if (inst.operands[3].present)
12789 {
12790 offsetT shift_amount = inst.reloc.exp.X_add_number;
12791
12792 inst.reloc.type = BFD_RELOC_UNUSED;
12793
12794 constraint (inst.reloc.exp.X_op != O_constant,
12795 _("expression too complex"));
12796
12797 if (shift_amount != 0)
12798 {
12799 constraint (shift_amount > 31,
12800 _("shift expression is too large"));
12801
12802 if (inst.operands[3].shift_kind == SHIFT_ASR)
12803 inst.instruction |= 0x00200000; /* sh bit. */
12804
12805 inst.instruction |= (shift_amount & 0x1c) << 10;
12806 inst.instruction |= (shift_amount & 0x03) << 6;
12807 }
12808 }
12809 }
12810
12811 static void
12812 do_t_ssat (void)
12813 {
12814 do_t_ssat_usat (1);
12815 }
12816
12817 static void
12818 do_t_ssat16 (void)
12819 {
12820 unsigned Rd, Rn;
12821
12822 Rd = inst.operands[0].reg;
12823 Rn = inst.operands[2].reg;
12824
12825 reject_bad_reg (Rd);
12826 reject_bad_reg (Rn);
12827
12828 inst.instruction |= Rd << 8;
12829 inst.instruction |= inst.operands[1].imm - 1;
12830 inst.instruction |= Rn << 16;
12831 }
12832
12833 static void
12834 do_t_strex (void)
12835 {
12836 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
12837 || inst.operands[2].postind || inst.operands[2].writeback
12838 || inst.operands[2].immisreg || inst.operands[2].shifted
12839 || inst.operands[2].negative,
12840 BAD_ADDR_MODE);
12841
12842 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
12843
12844 inst.instruction |= inst.operands[0].reg << 8;
12845 inst.instruction |= inst.operands[1].reg << 12;
12846 inst.instruction |= inst.operands[2].reg << 16;
12847 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
12848 }
12849
12850 static void
12851 do_t_strexd (void)
12852 {
12853 if (!inst.operands[2].present)
12854 inst.operands[2].reg = inst.operands[1].reg + 1;
12855
12856 constraint (inst.operands[0].reg == inst.operands[1].reg
12857 || inst.operands[0].reg == inst.operands[2].reg
12858 || inst.operands[0].reg == inst.operands[3].reg,
12859 BAD_OVERLAP);
12860
12861 inst.instruction |= inst.operands[0].reg;
12862 inst.instruction |= inst.operands[1].reg << 12;
12863 inst.instruction |= inst.operands[2].reg << 8;
12864 inst.instruction |= inst.operands[3].reg << 16;
12865 }
12866
12867 static void
12868 do_t_sxtah (void)
12869 {
12870 unsigned Rd, Rn, Rm;
12871
12872 Rd = inst.operands[0].reg;
12873 Rn = inst.operands[1].reg;
12874 Rm = inst.operands[2].reg;
12875
12876 reject_bad_reg (Rd);
12877 reject_bad_reg (Rn);
12878 reject_bad_reg (Rm);
12879
12880 inst.instruction |= Rd << 8;
12881 inst.instruction |= Rn << 16;
12882 inst.instruction |= Rm;
12883 inst.instruction |= inst.operands[3].imm << 4;
12884 }
12885
12886 static void
12887 do_t_sxth (void)
12888 {
12889 unsigned Rd, Rm;
12890
12891 Rd = inst.operands[0].reg;
12892 Rm = inst.operands[1].reg;
12893
12894 reject_bad_reg (Rd);
12895 reject_bad_reg (Rm);
12896
12897 if (inst.instruction <= 0xffff
12898 && inst.size_req != 4
12899 && Rd <= 7 && Rm <= 7
12900 && (!inst.operands[2].present || inst.operands[2].imm == 0))
12901 {
12902 inst.instruction = THUMB_OP16 (inst.instruction);
12903 inst.instruction |= Rd;
12904 inst.instruction |= Rm << 3;
12905 }
12906 else if (unified_syntax)
12907 {
12908 if (inst.instruction <= 0xffff)
12909 inst.instruction = THUMB_OP32 (inst.instruction);
12910 inst.instruction |= Rd << 8;
12911 inst.instruction |= Rm;
12912 inst.instruction |= inst.operands[2].imm << 4;
12913 }
12914 else
12915 {
12916 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
12917 _("Thumb encoding does not support rotation"));
12918 constraint (1, BAD_HIREG);
12919 }
12920 }
12921
12922 static void
12923 do_t_swi (void)
12924 {
12925 /* We have to do the following check manually as ARM_EXT_OS only applies
12926 to ARM_EXT_V6M. */
12927 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
12928 {
12929 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
12930 /* This only applies to the v6m howver, not later architectures. */
12931 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
12932 as_bad (_("SVC is not permitted on this architecture"));
12933 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
12934 }
12935
12936 inst.reloc.type = BFD_RELOC_ARM_SWI;
12937 }
12938
12939 static void
12940 do_t_tb (void)
12941 {
12942 unsigned Rn, Rm;
12943 int half;
12944
12945 half = (inst.instruction & 0x10) != 0;
12946 set_it_insn_type_last ();
12947 constraint (inst.operands[0].immisreg,
12948 _("instruction requires register index"));
12949
12950 Rn = inst.operands[0].reg;
12951 Rm = inst.operands[0].imm;
12952
12953 constraint (Rn == REG_SP, BAD_SP);
12954 reject_bad_reg (Rm);
12955
12956 constraint (!half && inst.operands[0].shifted,
12957 _("instruction does not allow shifted index"));
12958 inst.instruction |= (Rn << 16) | Rm;
12959 }
12960
12961 static void
12962 do_t_udf (void)
12963 {
12964 if (!inst.operands[0].present)
12965 inst.operands[0].imm = 0;
12966
12967 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
12968 {
12969 constraint (inst.size_req == 2,
12970 _("immediate value out of range"));
12971 inst.instruction = THUMB_OP32 (inst.instruction);
12972 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
12973 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
12974 }
12975 else
12976 {
12977 inst.instruction = THUMB_OP16 (inst.instruction);
12978 inst.instruction |= inst.operands[0].imm;
12979 }
12980
12981 set_it_insn_type (NEUTRAL_IT_INSN);
12982 }
12983
12984
12985 static void
12986 do_t_usat (void)
12987 {
12988 do_t_ssat_usat (0);
12989 }
12990
12991 static void
12992 do_t_usat16 (void)
12993 {
12994 unsigned Rd, Rn;
12995
12996 Rd = inst.operands[0].reg;
12997 Rn = inst.operands[2].reg;
12998
12999 reject_bad_reg (Rd);
13000 reject_bad_reg (Rn);
13001
13002 inst.instruction |= Rd << 8;
13003 inst.instruction |= inst.operands[1].imm;
13004 inst.instruction |= Rn << 16;
13005 }
13006
13007 /* Neon instruction encoder helpers. */
13008
13009 /* Encodings for the different types for various Neon opcodes. */
13010
13011 /* An "invalid" code for the following tables. */
13012 #define N_INV -1u
13013
13014 struct neon_tab_entry
13015 {
13016 unsigned integer;
13017 unsigned float_or_poly;
13018 unsigned scalar_or_imm;
13019 };
13020
13021 /* Map overloaded Neon opcodes to their respective encodings. */
13022 #define NEON_ENC_TAB \
13023 X(vabd, 0x0000700, 0x1200d00, N_INV), \
13024 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13025 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13026 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13027 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13028 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13029 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13030 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13031 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13032 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13033 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13034 /* Register variants of the following two instructions are encoded as
13035 vcge / vcgt with the operands reversed. */ \
13036 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13037 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
13038 X(vfma, N_INV, 0x0000c10, N_INV), \
13039 X(vfms, N_INV, 0x0200c10, N_INV), \
13040 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13041 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13042 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13043 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13044 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13045 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13046 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13047 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13048 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13049 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13050 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
13051 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13052 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
13053 X(vshl, 0x0000400, N_INV, 0x0800510), \
13054 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13055 X(vand, 0x0000110, N_INV, 0x0800030), \
13056 X(vbic, 0x0100110, N_INV, 0x0800030), \
13057 X(veor, 0x1000110, N_INV, N_INV), \
13058 X(vorn, 0x0300110, N_INV, 0x0800010), \
13059 X(vorr, 0x0200110, N_INV, 0x0800010), \
13060 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13061 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13062 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13063 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13064 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13065 X(vst1, 0x0000000, 0x0800000, N_INV), \
13066 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13067 X(vst2, 0x0000100, 0x0800100, N_INV), \
13068 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13069 X(vst3, 0x0000200, 0x0800200, N_INV), \
13070 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13071 X(vst4, 0x0000300, 0x0800300, N_INV), \
13072 X(vmovn, 0x1b20200, N_INV, N_INV), \
13073 X(vtrn, 0x1b20080, N_INV, N_INV), \
13074 X(vqmovn, 0x1b20200, N_INV, N_INV), \
13075 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13076 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
13077 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13078 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
13079 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13080 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
13081 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13082 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13083 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
13084 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13085 X(vseleq, 0xe000a00, N_INV, N_INV), \
13086 X(vselvs, 0xe100a00, N_INV, N_INV), \
13087 X(vselge, 0xe200a00, N_INV, N_INV), \
13088 X(vselgt, 0xe300a00, N_INV, N_INV), \
13089 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
13090 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
13091 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13092 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
13093 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
13094 X(aes, 0x3b00300, N_INV, N_INV), \
13095 X(sha3op, 0x2000c00, N_INV, N_INV), \
13096 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13097 X(sha2op, 0x3ba0380, N_INV, N_INV)
13098
13099 enum neon_opc
13100 {
13101 #define X(OPC,I,F,S) N_MNEM_##OPC
13102 NEON_ENC_TAB
13103 #undef X
13104 };
13105
13106 static const struct neon_tab_entry neon_enc_tab[] =
13107 {
13108 #define X(OPC,I,F,S) { (I), (F), (S) }
13109 NEON_ENC_TAB
13110 #undef X
13111 };
13112
13113 /* Do not use these macros; instead, use NEON_ENCODE defined below. */
13114 #define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13115 #define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13116 #define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13117 #define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13118 #define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13119 #define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13120 #define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13121 #define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13122 #define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13123 #define NEON_ENC_SINGLE_(X) \
13124 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
13125 #define NEON_ENC_DOUBLE_(X) \
13126 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
13127 #define NEON_ENC_FPV8_(X) \
13128 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
13129
13130 #define NEON_ENCODE(type, inst) \
13131 do \
13132 { \
13133 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13134 inst.is_neon = 1; \
13135 } \
13136 while (0)
13137
13138 #define check_neon_suffixes \
13139 do \
13140 { \
13141 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13142 { \
13143 as_bad (_("invalid neon suffix for non neon instruction")); \
13144 return; \
13145 } \
13146 } \
13147 while (0)
13148
13149 /* Define shapes for instruction operands. The following mnemonic characters
13150 are used in this table:
13151
13152 F - VFP S<n> register
13153 D - Neon D<n> register
13154 Q - Neon Q<n> register
13155 I - Immediate
13156 S - Scalar
13157 R - ARM register
13158 L - D<n> register list
13159
13160 This table is used to generate various data:
13161 - enumerations of the form NS_DDR to be used as arguments to
13162 neon_select_shape.
13163 - a table classifying shapes into single, double, quad, mixed.
13164 - a table used to drive neon_select_shape. */
13165
13166 #define NEON_SHAPE_DEF \
13167 X(3, (D, D, D), DOUBLE), \
13168 X(3, (Q, Q, Q), QUAD), \
13169 X(3, (D, D, I), DOUBLE), \
13170 X(3, (Q, Q, I), QUAD), \
13171 X(3, (D, D, S), DOUBLE), \
13172 X(3, (Q, Q, S), QUAD), \
13173 X(2, (D, D), DOUBLE), \
13174 X(2, (Q, Q), QUAD), \
13175 X(2, (D, S), DOUBLE), \
13176 X(2, (Q, S), QUAD), \
13177 X(2, (D, R), DOUBLE), \
13178 X(2, (Q, R), QUAD), \
13179 X(2, (D, I), DOUBLE), \
13180 X(2, (Q, I), QUAD), \
13181 X(3, (D, L, D), DOUBLE), \
13182 X(2, (D, Q), MIXED), \
13183 X(2, (Q, D), MIXED), \
13184 X(3, (D, Q, I), MIXED), \
13185 X(3, (Q, D, I), MIXED), \
13186 X(3, (Q, D, D), MIXED), \
13187 X(3, (D, Q, Q), MIXED), \
13188 X(3, (Q, Q, D), MIXED), \
13189 X(3, (Q, D, S), MIXED), \
13190 X(3, (D, Q, S), MIXED), \
13191 X(4, (D, D, D, I), DOUBLE), \
13192 X(4, (Q, Q, Q, I), QUAD), \
13193 X(2, (F, F), SINGLE), \
13194 X(3, (F, F, F), SINGLE), \
13195 X(2, (F, I), SINGLE), \
13196 X(2, (F, D), MIXED), \
13197 X(2, (D, F), MIXED), \
13198 X(3, (F, F, I), MIXED), \
13199 X(4, (R, R, F, F), SINGLE), \
13200 X(4, (F, F, R, R), SINGLE), \
13201 X(3, (D, R, R), DOUBLE), \
13202 X(3, (R, R, D), DOUBLE), \
13203 X(2, (S, R), SINGLE), \
13204 X(2, (R, S), SINGLE), \
13205 X(2, (F, R), SINGLE), \
13206 X(2, (R, F), SINGLE)
13207
13208 #define S2(A,B) NS_##A##B
13209 #define S3(A,B,C) NS_##A##B##C
13210 #define S4(A,B,C,D) NS_##A##B##C##D
13211
13212 #define X(N, L, C) S##N L
13213
13214 enum neon_shape
13215 {
13216 NEON_SHAPE_DEF,
13217 NS_NULL
13218 };
13219
13220 #undef X
13221 #undef S2
13222 #undef S3
13223 #undef S4
13224
13225 enum neon_shape_class
13226 {
13227 SC_SINGLE,
13228 SC_DOUBLE,
13229 SC_QUAD,
13230 SC_MIXED
13231 };
13232
13233 #define X(N, L, C) SC_##C
13234
13235 static enum neon_shape_class neon_shape_class[] =
13236 {
13237 NEON_SHAPE_DEF
13238 };
13239
13240 #undef X
13241
13242 enum neon_shape_el
13243 {
13244 SE_F,
13245 SE_D,
13246 SE_Q,
13247 SE_I,
13248 SE_S,
13249 SE_R,
13250 SE_L
13251 };
13252
13253 /* Register widths of above. */
13254 static unsigned neon_shape_el_size[] =
13255 {
13256 32,
13257 64,
13258 128,
13259 0,
13260 32,
13261 32,
13262 0
13263 };
13264
13265 struct neon_shape_info
13266 {
13267 unsigned els;
13268 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13269 };
13270
13271 #define S2(A,B) { SE_##A, SE_##B }
13272 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13273 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13274
13275 #define X(N, L, C) { N, S##N L }
13276
13277 static struct neon_shape_info neon_shape_tab[] =
13278 {
13279 NEON_SHAPE_DEF
13280 };
13281
13282 #undef X
13283 #undef S2
13284 #undef S3
13285 #undef S4
13286
13287 /* Bit masks used in type checking given instructions.
13288 'N_EQK' means the type must be the same as (or based on in some way) the key
13289 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13290 set, various other bits can be set as well in order to modify the meaning of
13291 the type constraint. */
13292
13293 enum neon_type_mask
13294 {
13295 N_S8 = 0x0000001,
13296 N_S16 = 0x0000002,
13297 N_S32 = 0x0000004,
13298 N_S64 = 0x0000008,
13299 N_U8 = 0x0000010,
13300 N_U16 = 0x0000020,
13301 N_U32 = 0x0000040,
13302 N_U64 = 0x0000080,
13303 N_I8 = 0x0000100,
13304 N_I16 = 0x0000200,
13305 N_I32 = 0x0000400,
13306 N_I64 = 0x0000800,
13307 N_8 = 0x0001000,
13308 N_16 = 0x0002000,
13309 N_32 = 0x0004000,
13310 N_64 = 0x0008000,
13311 N_P8 = 0x0010000,
13312 N_P16 = 0x0020000,
13313 N_F16 = 0x0040000,
13314 N_F32 = 0x0080000,
13315 N_F64 = 0x0100000,
13316 N_P64 = 0x0200000,
13317 N_KEY = 0x1000000, /* Key element (main type specifier). */
13318 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
13319 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
13320 N_UNT = 0x8000000, /* Must be explicitly untyped. */
13321 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13322 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13323 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13324 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13325 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13326 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13327 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
13328 N_UTYP = 0,
13329 N_MAX_NONSPECIAL = N_P64
13330 };
13331
13332 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13333
13334 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13335 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13336 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
13337 #define N_SUF_32 (N_SU_32 | N_F32)
13338 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
13339 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
13340
13341 /* Pass this as the first type argument to neon_check_type to ignore types
13342 altogether. */
13343 #define N_IGNORE_TYPE (N_KEY | N_EQK)
13344
13345 /* Select a "shape" for the current instruction (describing register types or
13346 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13347 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13348 function of operand parsing, so this function doesn't need to be called.
13349 Shapes should be listed in order of decreasing length. */
13350
13351 static enum neon_shape
13352 neon_select_shape (enum neon_shape shape, ...)
13353 {
13354 va_list ap;
13355 enum neon_shape first_shape = shape;
13356
13357 /* Fix missing optional operands. FIXME: we don't know at this point how
13358 many arguments we should have, so this makes the assumption that we have
13359 > 1. This is true of all current Neon opcodes, I think, but may not be
13360 true in the future. */
13361 if (!inst.operands[1].present)
13362 inst.operands[1] = inst.operands[0];
13363
13364 va_start (ap, shape);
13365
13366 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
13367 {
13368 unsigned j;
13369 int matches = 1;
13370
13371 for (j = 0; j < neon_shape_tab[shape].els; j++)
13372 {
13373 if (!inst.operands[j].present)
13374 {
13375 matches = 0;
13376 break;
13377 }
13378
13379 switch (neon_shape_tab[shape].el[j])
13380 {
13381 case SE_F:
13382 if (!(inst.operands[j].isreg
13383 && inst.operands[j].isvec
13384 && inst.operands[j].issingle
13385 && !inst.operands[j].isquad))
13386 matches = 0;
13387 break;
13388
13389 case SE_D:
13390 if (!(inst.operands[j].isreg
13391 && inst.operands[j].isvec
13392 && !inst.operands[j].isquad
13393 && !inst.operands[j].issingle))
13394 matches = 0;
13395 break;
13396
13397 case SE_R:
13398 if (!(inst.operands[j].isreg
13399 && !inst.operands[j].isvec))
13400 matches = 0;
13401 break;
13402
13403 case SE_Q:
13404 if (!(inst.operands[j].isreg
13405 && inst.operands[j].isvec
13406 && inst.operands[j].isquad
13407 && !inst.operands[j].issingle))
13408 matches = 0;
13409 break;
13410
13411 case SE_I:
13412 if (!(!inst.operands[j].isreg
13413 && !inst.operands[j].isscalar))
13414 matches = 0;
13415 break;
13416
13417 case SE_S:
13418 if (!(!inst.operands[j].isreg
13419 && inst.operands[j].isscalar))
13420 matches = 0;
13421 break;
13422
13423 case SE_L:
13424 break;
13425 }
13426 if (!matches)
13427 break;
13428 }
13429 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
13430 /* We've matched all the entries in the shape table, and we don't
13431 have any left over operands which have not been matched. */
13432 break;
13433 }
13434
13435 va_end (ap);
13436
13437 if (shape == NS_NULL && first_shape != NS_NULL)
13438 first_error (_("invalid instruction shape"));
13439
13440 return shape;
13441 }
13442
13443 /* True if SHAPE is predominantly a quadword operation (most of the time, this
13444 means the Q bit should be set). */
13445
13446 static int
13447 neon_quad (enum neon_shape shape)
13448 {
13449 return neon_shape_class[shape] == SC_QUAD;
13450 }
13451
13452 static void
13453 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
13454 unsigned *g_size)
13455 {
13456 /* Allow modification to be made to types which are constrained to be
13457 based on the key element, based on bits set alongside N_EQK. */
13458 if ((typebits & N_EQK) != 0)
13459 {
13460 if ((typebits & N_HLF) != 0)
13461 *g_size /= 2;
13462 else if ((typebits & N_DBL) != 0)
13463 *g_size *= 2;
13464 if ((typebits & N_SGN) != 0)
13465 *g_type = NT_signed;
13466 else if ((typebits & N_UNS) != 0)
13467 *g_type = NT_unsigned;
13468 else if ((typebits & N_INT) != 0)
13469 *g_type = NT_integer;
13470 else if ((typebits & N_FLT) != 0)
13471 *g_type = NT_float;
13472 else if ((typebits & N_SIZ) != 0)
13473 *g_type = NT_untyped;
13474 }
13475 }
13476
13477 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
13478 operand type, i.e. the single type specified in a Neon instruction when it
13479 is the only one given. */
13480
13481 static struct neon_type_el
13482 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
13483 {
13484 struct neon_type_el dest = *key;
13485
13486 gas_assert ((thisarg & N_EQK) != 0);
13487
13488 neon_modify_type_size (thisarg, &dest.type, &dest.size);
13489
13490 return dest;
13491 }
13492
13493 /* Convert Neon type and size into compact bitmask representation. */
13494
13495 static enum neon_type_mask
13496 type_chk_of_el_type (enum neon_el_type type, unsigned size)
13497 {
13498 switch (type)
13499 {
13500 case NT_untyped:
13501 switch (size)
13502 {
13503 case 8: return N_8;
13504 case 16: return N_16;
13505 case 32: return N_32;
13506 case 64: return N_64;
13507 default: ;
13508 }
13509 break;
13510
13511 case NT_integer:
13512 switch (size)
13513 {
13514 case 8: return N_I8;
13515 case 16: return N_I16;
13516 case 32: return N_I32;
13517 case 64: return N_I64;
13518 default: ;
13519 }
13520 break;
13521
13522 case NT_float:
13523 switch (size)
13524 {
13525 case 16: return N_F16;
13526 case 32: return N_F32;
13527 case 64: return N_F64;
13528 default: ;
13529 }
13530 break;
13531
13532 case NT_poly:
13533 switch (size)
13534 {
13535 case 8: return N_P8;
13536 case 16: return N_P16;
13537 case 64: return N_P64;
13538 default: ;
13539 }
13540 break;
13541
13542 case NT_signed:
13543 switch (size)
13544 {
13545 case 8: return N_S8;
13546 case 16: return N_S16;
13547 case 32: return N_S32;
13548 case 64: return N_S64;
13549 default: ;
13550 }
13551 break;
13552
13553 case NT_unsigned:
13554 switch (size)
13555 {
13556 case 8: return N_U8;
13557 case 16: return N_U16;
13558 case 32: return N_U32;
13559 case 64: return N_U64;
13560 default: ;
13561 }
13562 break;
13563
13564 default: ;
13565 }
13566
13567 return N_UTYP;
13568 }
13569
13570 /* Convert compact Neon bitmask type representation to a type and size. Only
13571 handles the case where a single bit is set in the mask. */
13572
13573 static int
13574 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
13575 enum neon_type_mask mask)
13576 {
13577 if ((mask & N_EQK) != 0)
13578 return FAIL;
13579
13580 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
13581 *size = 8;
13582 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
13583 *size = 16;
13584 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
13585 *size = 32;
13586 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
13587 *size = 64;
13588 else
13589 return FAIL;
13590
13591 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
13592 *type = NT_signed;
13593 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
13594 *type = NT_unsigned;
13595 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
13596 *type = NT_integer;
13597 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
13598 *type = NT_untyped;
13599 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
13600 *type = NT_poly;
13601 else if ((mask & (N_F16 | N_F32 | N_F64)) != 0)
13602 *type = NT_float;
13603 else
13604 return FAIL;
13605
13606 return SUCCESS;
13607 }
13608
13609 /* Modify a bitmask of allowed types. This is only needed for type
13610 relaxation. */
13611
13612 static unsigned
13613 modify_types_allowed (unsigned allowed, unsigned mods)
13614 {
13615 unsigned size;
13616 enum neon_el_type type;
13617 unsigned destmask;
13618 int i;
13619
13620 destmask = 0;
13621
13622 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
13623 {
13624 if (el_type_of_type_chk (&type, &size,
13625 (enum neon_type_mask) (allowed & i)) == SUCCESS)
13626 {
13627 neon_modify_type_size (mods, &type, &size);
13628 destmask |= type_chk_of_el_type (type, size);
13629 }
13630 }
13631
13632 return destmask;
13633 }
13634
13635 /* Check type and return type classification.
13636 The manual states (paraphrase): If one datatype is given, it indicates the
13637 type given in:
13638 - the second operand, if there is one
13639 - the operand, if there is no second operand
13640 - the result, if there are no operands.
13641 This isn't quite good enough though, so we use a concept of a "key" datatype
13642 which is set on a per-instruction basis, which is the one which matters when
13643 only one data type is written.
13644 Note: this function has side-effects (e.g. filling in missing operands). All
13645 Neon instructions should call it before performing bit encoding. */
13646
13647 static struct neon_type_el
13648 neon_check_type (unsigned els, enum neon_shape ns, ...)
13649 {
13650 va_list ap;
13651 unsigned i, pass, key_el = 0;
13652 unsigned types[NEON_MAX_TYPE_ELS];
13653 enum neon_el_type k_type = NT_invtype;
13654 unsigned k_size = -1u;
13655 struct neon_type_el badtype = {NT_invtype, -1};
13656 unsigned key_allowed = 0;
13657
13658 /* Optional registers in Neon instructions are always (not) in operand 1.
13659 Fill in the missing operand here, if it was omitted. */
13660 if (els > 1 && !inst.operands[1].present)
13661 inst.operands[1] = inst.operands[0];
13662
13663 /* Suck up all the varargs. */
13664 va_start (ap, ns);
13665 for (i = 0; i < els; i++)
13666 {
13667 unsigned thisarg = va_arg (ap, unsigned);
13668 if (thisarg == N_IGNORE_TYPE)
13669 {
13670 va_end (ap);
13671 return badtype;
13672 }
13673 types[i] = thisarg;
13674 if ((thisarg & N_KEY) != 0)
13675 key_el = i;
13676 }
13677 va_end (ap);
13678
13679 if (inst.vectype.elems > 0)
13680 for (i = 0; i < els; i++)
13681 if (inst.operands[i].vectype.type != NT_invtype)
13682 {
13683 first_error (_("types specified in both the mnemonic and operands"));
13684 return badtype;
13685 }
13686
13687 /* Duplicate inst.vectype elements here as necessary.
13688 FIXME: No idea if this is exactly the same as the ARM assembler,
13689 particularly when an insn takes one register and one non-register
13690 operand. */
13691 if (inst.vectype.elems == 1 && els > 1)
13692 {
13693 unsigned j;
13694 inst.vectype.elems = els;
13695 inst.vectype.el[key_el] = inst.vectype.el[0];
13696 for (j = 0; j < els; j++)
13697 if (j != key_el)
13698 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13699 types[j]);
13700 }
13701 else if (inst.vectype.elems == 0 && els > 0)
13702 {
13703 unsigned j;
13704 /* No types were given after the mnemonic, so look for types specified
13705 after each operand. We allow some flexibility here; as long as the
13706 "key" operand has a type, we can infer the others. */
13707 for (j = 0; j < els; j++)
13708 if (inst.operands[j].vectype.type != NT_invtype)
13709 inst.vectype.el[j] = inst.operands[j].vectype;
13710
13711 if (inst.operands[key_el].vectype.type != NT_invtype)
13712 {
13713 for (j = 0; j < els; j++)
13714 if (inst.operands[j].vectype.type == NT_invtype)
13715 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13716 types[j]);
13717 }
13718 else
13719 {
13720 first_error (_("operand types can't be inferred"));
13721 return badtype;
13722 }
13723 }
13724 else if (inst.vectype.elems != els)
13725 {
13726 first_error (_("type specifier has the wrong number of parts"));
13727 return badtype;
13728 }
13729
13730 for (pass = 0; pass < 2; pass++)
13731 {
13732 for (i = 0; i < els; i++)
13733 {
13734 unsigned thisarg = types[i];
13735 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
13736 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
13737 enum neon_el_type g_type = inst.vectype.el[i].type;
13738 unsigned g_size = inst.vectype.el[i].size;
13739
13740 /* Decay more-specific signed & unsigned types to sign-insensitive
13741 integer types if sign-specific variants are unavailable. */
13742 if ((g_type == NT_signed || g_type == NT_unsigned)
13743 && (types_allowed & N_SU_ALL) == 0)
13744 g_type = NT_integer;
13745
13746 /* If only untyped args are allowed, decay any more specific types to
13747 them. Some instructions only care about signs for some element
13748 sizes, so handle that properly. */
13749 if (((types_allowed & N_UNT) == 0)
13750 && ((g_size == 8 && (types_allowed & N_8) != 0)
13751 || (g_size == 16 && (types_allowed & N_16) != 0)
13752 || (g_size == 32 && (types_allowed & N_32) != 0)
13753 || (g_size == 64 && (types_allowed & N_64) != 0)))
13754 g_type = NT_untyped;
13755
13756 if (pass == 0)
13757 {
13758 if ((thisarg & N_KEY) != 0)
13759 {
13760 k_type = g_type;
13761 k_size = g_size;
13762 key_allowed = thisarg & ~N_KEY;
13763 }
13764 }
13765 else
13766 {
13767 if ((thisarg & N_VFP) != 0)
13768 {
13769 enum neon_shape_el regshape;
13770 unsigned regwidth, match;
13771
13772 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
13773 if (ns == NS_NULL)
13774 {
13775 first_error (_("invalid instruction shape"));
13776 return badtype;
13777 }
13778 regshape = neon_shape_tab[ns].el[i];
13779 regwidth = neon_shape_el_size[regshape];
13780
13781 /* In VFP mode, operands must match register widths. If we
13782 have a key operand, use its width, else use the width of
13783 the current operand. */
13784 if (k_size != -1u)
13785 match = k_size;
13786 else
13787 match = g_size;
13788
13789 if (regwidth != match)
13790 {
13791 first_error (_("operand size must match register width"));
13792 return badtype;
13793 }
13794 }
13795
13796 if ((thisarg & N_EQK) == 0)
13797 {
13798 unsigned given_type = type_chk_of_el_type (g_type, g_size);
13799
13800 if ((given_type & types_allowed) == 0)
13801 {
13802 first_error (_("bad type in Neon instruction"));
13803 return badtype;
13804 }
13805 }
13806 else
13807 {
13808 enum neon_el_type mod_k_type = k_type;
13809 unsigned mod_k_size = k_size;
13810 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
13811 if (g_type != mod_k_type || g_size != mod_k_size)
13812 {
13813 first_error (_("inconsistent types in Neon instruction"));
13814 return badtype;
13815 }
13816 }
13817 }
13818 }
13819 }
13820
13821 return inst.vectype.el[key_el];
13822 }
13823
13824 /* Neon-style VFP instruction forwarding. */
13825
13826 /* Thumb VFP instructions have 0xE in the condition field. */
13827
13828 static void
13829 do_vfp_cond_or_thumb (void)
13830 {
13831 inst.is_neon = 1;
13832
13833 if (thumb_mode)
13834 inst.instruction |= 0xe0000000;
13835 else
13836 inst.instruction |= inst.cond << 28;
13837 }
13838
13839 /* Look up and encode a simple mnemonic, for use as a helper function for the
13840 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
13841 etc. It is assumed that operand parsing has already been done, and that the
13842 operands are in the form expected by the given opcode (this isn't necessarily
13843 the same as the form in which they were parsed, hence some massaging must
13844 take place before this function is called).
13845 Checks current arch version against that in the looked-up opcode. */
13846
13847 static void
13848 do_vfp_nsyn_opcode (const char *opname)
13849 {
13850 const struct asm_opcode *opcode;
13851
13852 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
13853
13854 if (!opcode)
13855 abort ();
13856
13857 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
13858 thumb_mode ? *opcode->tvariant : *opcode->avariant),
13859 _(BAD_FPU));
13860
13861 inst.is_neon = 1;
13862
13863 if (thumb_mode)
13864 {
13865 inst.instruction = opcode->tvalue;
13866 opcode->tencode ();
13867 }
13868 else
13869 {
13870 inst.instruction = (inst.cond << 28) | opcode->avalue;
13871 opcode->aencode ();
13872 }
13873 }
13874
13875 static void
13876 do_vfp_nsyn_add_sub (enum neon_shape rs)
13877 {
13878 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
13879
13880 if (rs == NS_FFF)
13881 {
13882 if (is_add)
13883 do_vfp_nsyn_opcode ("fadds");
13884 else
13885 do_vfp_nsyn_opcode ("fsubs");
13886 }
13887 else
13888 {
13889 if (is_add)
13890 do_vfp_nsyn_opcode ("faddd");
13891 else
13892 do_vfp_nsyn_opcode ("fsubd");
13893 }
13894 }
13895
13896 /* Check operand types to see if this is a VFP instruction, and if so call
13897 PFN (). */
13898
13899 static int
13900 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
13901 {
13902 enum neon_shape rs;
13903 struct neon_type_el et;
13904
13905 switch (args)
13906 {
13907 case 2:
13908 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13909 et = neon_check_type (2, rs,
13910 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
13911 break;
13912
13913 case 3:
13914 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13915 et = neon_check_type (3, rs,
13916 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
13917 break;
13918
13919 default:
13920 abort ();
13921 }
13922
13923 if (et.type != NT_invtype)
13924 {
13925 pfn (rs);
13926 return SUCCESS;
13927 }
13928
13929 inst.error = NULL;
13930 return FAIL;
13931 }
13932
13933 static void
13934 do_vfp_nsyn_mla_mls (enum neon_shape rs)
13935 {
13936 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
13937
13938 if (rs == NS_FFF)
13939 {
13940 if (is_mla)
13941 do_vfp_nsyn_opcode ("fmacs");
13942 else
13943 do_vfp_nsyn_opcode ("fnmacs");
13944 }
13945 else
13946 {
13947 if (is_mla)
13948 do_vfp_nsyn_opcode ("fmacd");
13949 else
13950 do_vfp_nsyn_opcode ("fnmacd");
13951 }
13952 }
13953
13954 static void
13955 do_vfp_nsyn_fma_fms (enum neon_shape rs)
13956 {
13957 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
13958
13959 if (rs == NS_FFF)
13960 {
13961 if (is_fma)
13962 do_vfp_nsyn_opcode ("ffmas");
13963 else
13964 do_vfp_nsyn_opcode ("ffnmas");
13965 }
13966 else
13967 {
13968 if (is_fma)
13969 do_vfp_nsyn_opcode ("ffmad");
13970 else
13971 do_vfp_nsyn_opcode ("ffnmad");
13972 }
13973 }
13974
13975 static void
13976 do_vfp_nsyn_mul (enum neon_shape rs)
13977 {
13978 if (rs == NS_FFF)
13979 do_vfp_nsyn_opcode ("fmuls");
13980 else
13981 do_vfp_nsyn_opcode ("fmuld");
13982 }
13983
13984 static void
13985 do_vfp_nsyn_abs_neg (enum neon_shape rs)
13986 {
13987 int is_neg = (inst.instruction & 0x80) != 0;
13988 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
13989
13990 if (rs == NS_FF)
13991 {
13992 if (is_neg)
13993 do_vfp_nsyn_opcode ("fnegs");
13994 else
13995 do_vfp_nsyn_opcode ("fabss");
13996 }
13997 else
13998 {
13999 if (is_neg)
14000 do_vfp_nsyn_opcode ("fnegd");
14001 else
14002 do_vfp_nsyn_opcode ("fabsd");
14003 }
14004 }
14005
14006 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
14007 insns belong to Neon, and are handled elsewhere. */
14008
14009 static void
14010 do_vfp_nsyn_ldm_stm (int is_dbmode)
14011 {
14012 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14013 if (is_ldm)
14014 {
14015 if (is_dbmode)
14016 do_vfp_nsyn_opcode ("fldmdbs");
14017 else
14018 do_vfp_nsyn_opcode ("fldmias");
14019 }
14020 else
14021 {
14022 if (is_dbmode)
14023 do_vfp_nsyn_opcode ("fstmdbs");
14024 else
14025 do_vfp_nsyn_opcode ("fstmias");
14026 }
14027 }
14028
14029 static void
14030 do_vfp_nsyn_sqrt (void)
14031 {
14032 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
14033 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
14034
14035 if (rs == NS_FF)
14036 do_vfp_nsyn_opcode ("fsqrts");
14037 else
14038 do_vfp_nsyn_opcode ("fsqrtd");
14039 }
14040
14041 static void
14042 do_vfp_nsyn_div (void)
14043 {
14044 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
14045 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14046 N_F32 | N_F64 | N_KEY | N_VFP);
14047
14048 if (rs == NS_FFF)
14049 do_vfp_nsyn_opcode ("fdivs");
14050 else
14051 do_vfp_nsyn_opcode ("fdivd");
14052 }
14053
14054 static void
14055 do_vfp_nsyn_nmul (void)
14056 {
14057 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
14058 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14059 N_F32 | N_F64 | N_KEY | N_VFP);
14060
14061 if (rs == NS_FFF)
14062 {
14063 NEON_ENCODE (SINGLE, inst);
14064 do_vfp_sp_dyadic ();
14065 }
14066 else
14067 {
14068 NEON_ENCODE (DOUBLE, inst);
14069 do_vfp_dp_rd_rn_rm ();
14070 }
14071 do_vfp_cond_or_thumb ();
14072 }
14073
14074 static void
14075 do_vfp_nsyn_cmp (void)
14076 {
14077 if (inst.operands[1].isreg)
14078 {
14079 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
14080 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
14081
14082 if (rs == NS_FF)
14083 {
14084 NEON_ENCODE (SINGLE, inst);
14085 do_vfp_sp_monadic ();
14086 }
14087 else
14088 {
14089 NEON_ENCODE (DOUBLE, inst);
14090 do_vfp_dp_rd_rm ();
14091 }
14092 }
14093 else
14094 {
14095 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
14096 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
14097
14098 switch (inst.instruction & 0x0fffffff)
14099 {
14100 case N_MNEM_vcmp:
14101 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
14102 break;
14103 case N_MNEM_vcmpe:
14104 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
14105 break;
14106 default:
14107 abort ();
14108 }
14109
14110 if (rs == NS_FI)
14111 {
14112 NEON_ENCODE (SINGLE, inst);
14113 do_vfp_sp_compare_z ();
14114 }
14115 else
14116 {
14117 NEON_ENCODE (DOUBLE, inst);
14118 do_vfp_dp_rd ();
14119 }
14120 }
14121 do_vfp_cond_or_thumb ();
14122 }
14123
14124 static void
14125 nsyn_insert_sp (void)
14126 {
14127 inst.operands[1] = inst.operands[0];
14128 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
14129 inst.operands[0].reg = REG_SP;
14130 inst.operands[0].isreg = 1;
14131 inst.operands[0].writeback = 1;
14132 inst.operands[0].present = 1;
14133 }
14134
14135 static void
14136 do_vfp_nsyn_push (void)
14137 {
14138 nsyn_insert_sp ();
14139 if (inst.operands[1].issingle)
14140 do_vfp_nsyn_opcode ("fstmdbs");
14141 else
14142 do_vfp_nsyn_opcode ("fstmdbd");
14143 }
14144
14145 static void
14146 do_vfp_nsyn_pop (void)
14147 {
14148 nsyn_insert_sp ();
14149 if (inst.operands[1].issingle)
14150 do_vfp_nsyn_opcode ("fldmias");
14151 else
14152 do_vfp_nsyn_opcode ("fldmiad");
14153 }
14154
14155 /* Fix up Neon data-processing instructions, ORing in the correct bits for
14156 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14157
14158 static void
14159 neon_dp_fixup (struct arm_it* insn)
14160 {
14161 unsigned int i = insn->instruction;
14162 insn->is_neon = 1;
14163
14164 if (thumb_mode)
14165 {
14166 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14167 if (i & (1 << 24))
14168 i |= 1 << 28;
14169
14170 i &= ~(1 << 24);
14171
14172 i |= 0xef000000;
14173 }
14174 else
14175 i |= 0xf2000000;
14176
14177 insn->instruction = i;
14178 }
14179
14180 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14181 (0, 1, 2, 3). */
14182
14183 static unsigned
14184 neon_logbits (unsigned x)
14185 {
14186 return ffs (x) - 4;
14187 }
14188
14189 #define LOW4(R) ((R) & 0xf)
14190 #define HI1(R) (((R) >> 4) & 1)
14191
14192 /* Encode insns with bit pattern:
14193
14194 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14195 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
14196
14197 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14198 different meaning for some instruction. */
14199
14200 static void
14201 neon_three_same (int isquad, int ubit, int size)
14202 {
14203 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14204 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14205 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14206 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14207 inst.instruction |= LOW4 (inst.operands[2].reg);
14208 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14209 inst.instruction |= (isquad != 0) << 6;
14210 inst.instruction |= (ubit != 0) << 24;
14211 if (size != -1)
14212 inst.instruction |= neon_logbits (size) << 20;
14213
14214 neon_dp_fixup (&inst);
14215 }
14216
14217 /* Encode instructions of the form:
14218
14219 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14220 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
14221
14222 Don't write size if SIZE == -1. */
14223
14224 static void
14225 neon_two_same (int qbit, int ubit, int size)
14226 {
14227 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14228 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14229 inst.instruction |= LOW4 (inst.operands[1].reg);
14230 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14231 inst.instruction |= (qbit != 0) << 6;
14232 inst.instruction |= (ubit != 0) << 24;
14233
14234 if (size != -1)
14235 inst.instruction |= neon_logbits (size) << 18;
14236
14237 neon_dp_fixup (&inst);
14238 }
14239
14240 /* Neon instruction encoders, in approximate order of appearance. */
14241
14242 static void
14243 do_neon_dyadic_i_su (void)
14244 {
14245 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14246 struct neon_type_el et = neon_check_type (3, rs,
14247 N_EQK, N_EQK, N_SU_32 | N_KEY);
14248 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14249 }
14250
14251 static void
14252 do_neon_dyadic_i64_su (void)
14253 {
14254 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14255 struct neon_type_el et = neon_check_type (3, rs,
14256 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14257 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14258 }
14259
14260 static void
14261 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
14262 unsigned immbits)
14263 {
14264 unsigned size = et.size >> 3;
14265 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14266 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14267 inst.instruction |= LOW4 (inst.operands[1].reg);
14268 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14269 inst.instruction |= (isquad != 0) << 6;
14270 inst.instruction |= immbits << 16;
14271 inst.instruction |= (size >> 3) << 7;
14272 inst.instruction |= (size & 0x7) << 19;
14273 if (write_ubit)
14274 inst.instruction |= (uval != 0) << 24;
14275
14276 neon_dp_fixup (&inst);
14277 }
14278
14279 static void
14280 do_neon_shl_imm (void)
14281 {
14282 if (!inst.operands[2].isreg)
14283 {
14284 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14285 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
14286 int imm = inst.operands[2].imm;
14287
14288 constraint (imm < 0 || (unsigned)imm >= et.size,
14289 _("immediate out of range for shift"));
14290 NEON_ENCODE (IMMED, inst);
14291 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
14292 }
14293 else
14294 {
14295 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14296 struct neon_type_el et = neon_check_type (3, rs,
14297 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
14298 unsigned int tmp;
14299
14300 /* VSHL/VQSHL 3-register variants have syntax such as:
14301 vshl.xx Dd, Dm, Dn
14302 whereas other 3-register operations encoded by neon_three_same have
14303 syntax like:
14304 vadd.xx Dd, Dn, Dm
14305 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14306 here. */
14307 tmp = inst.operands[2].reg;
14308 inst.operands[2].reg = inst.operands[1].reg;
14309 inst.operands[1].reg = tmp;
14310 NEON_ENCODE (INTEGER, inst);
14311 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14312 }
14313 }
14314
14315 static void
14316 do_neon_qshl_imm (void)
14317 {
14318 if (!inst.operands[2].isreg)
14319 {
14320 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14321 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
14322 int imm = inst.operands[2].imm;
14323
14324 constraint (imm < 0 || (unsigned)imm >= et.size,
14325 _("immediate out of range for shift"));
14326 NEON_ENCODE (IMMED, inst);
14327 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
14328 }
14329 else
14330 {
14331 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14332 struct neon_type_el et = neon_check_type (3, rs,
14333 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
14334 unsigned int tmp;
14335
14336 /* See note in do_neon_shl_imm. */
14337 tmp = inst.operands[2].reg;
14338 inst.operands[2].reg = inst.operands[1].reg;
14339 inst.operands[1].reg = tmp;
14340 NEON_ENCODE (INTEGER, inst);
14341 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14342 }
14343 }
14344
14345 static void
14346 do_neon_rshl (void)
14347 {
14348 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14349 struct neon_type_el et = neon_check_type (3, rs,
14350 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14351 unsigned int tmp;
14352
14353 tmp = inst.operands[2].reg;
14354 inst.operands[2].reg = inst.operands[1].reg;
14355 inst.operands[1].reg = tmp;
14356 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14357 }
14358
14359 static int
14360 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
14361 {
14362 /* Handle .I8 pseudo-instructions. */
14363 if (size == 8)
14364 {
14365 /* Unfortunately, this will make everything apart from zero out-of-range.
14366 FIXME is this the intended semantics? There doesn't seem much point in
14367 accepting .I8 if so. */
14368 immediate |= immediate << 8;
14369 size = 16;
14370 }
14371
14372 if (size >= 32)
14373 {
14374 if (immediate == (immediate & 0x000000ff))
14375 {
14376 *immbits = immediate;
14377 return 0x1;
14378 }
14379 else if (immediate == (immediate & 0x0000ff00))
14380 {
14381 *immbits = immediate >> 8;
14382 return 0x3;
14383 }
14384 else if (immediate == (immediate & 0x00ff0000))
14385 {
14386 *immbits = immediate >> 16;
14387 return 0x5;
14388 }
14389 else if (immediate == (immediate & 0xff000000))
14390 {
14391 *immbits = immediate >> 24;
14392 return 0x7;
14393 }
14394 if ((immediate & 0xffff) != (immediate >> 16))
14395 goto bad_immediate;
14396 immediate &= 0xffff;
14397 }
14398
14399 if (immediate == (immediate & 0x000000ff))
14400 {
14401 *immbits = immediate;
14402 return 0x9;
14403 }
14404 else if (immediate == (immediate & 0x0000ff00))
14405 {
14406 *immbits = immediate >> 8;
14407 return 0xb;
14408 }
14409
14410 bad_immediate:
14411 first_error (_("immediate value out of range"));
14412 return FAIL;
14413 }
14414
14415 static void
14416 do_neon_logic (void)
14417 {
14418 if (inst.operands[2].present && inst.operands[2].isreg)
14419 {
14420 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14421 neon_check_type (3, rs, N_IGNORE_TYPE);
14422 /* U bit and size field were set as part of the bitmask. */
14423 NEON_ENCODE (INTEGER, inst);
14424 neon_three_same (neon_quad (rs), 0, -1);
14425 }
14426 else
14427 {
14428 const int three_ops_form = (inst.operands[2].present
14429 && !inst.operands[2].isreg);
14430 const int immoperand = (three_ops_form ? 2 : 1);
14431 enum neon_shape rs = (three_ops_form
14432 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14433 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
14434 struct neon_type_el et = neon_check_type (2, rs,
14435 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
14436 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
14437 unsigned immbits;
14438 int cmode;
14439
14440 if (et.type == NT_invtype)
14441 return;
14442
14443 if (three_ops_form)
14444 constraint (inst.operands[0].reg != inst.operands[1].reg,
14445 _("first and second operands shall be the same register"));
14446
14447 NEON_ENCODE (IMMED, inst);
14448
14449 immbits = inst.operands[immoperand].imm;
14450 if (et.size == 64)
14451 {
14452 /* .i64 is a pseudo-op, so the immediate must be a repeating
14453 pattern. */
14454 if (immbits != (inst.operands[immoperand].regisimm ?
14455 inst.operands[immoperand].reg : 0))
14456 {
14457 /* Set immbits to an invalid constant. */
14458 immbits = 0xdeadbeef;
14459 }
14460 }
14461
14462 switch (opcode)
14463 {
14464 case N_MNEM_vbic:
14465 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14466 break;
14467
14468 case N_MNEM_vorr:
14469 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14470 break;
14471
14472 case N_MNEM_vand:
14473 /* Pseudo-instruction for VBIC. */
14474 neon_invert_size (&immbits, 0, et.size);
14475 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14476 break;
14477
14478 case N_MNEM_vorn:
14479 /* Pseudo-instruction for VORR. */
14480 neon_invert_size (&immbits, 0, et.size);
14481 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14482 break;
14483
14484 default:
14485 abort ();
14486 }
14487
14488 if (cmode == FAIL)
14489 return;
14490
14491 inst.instruction |= neon_quad (rs) << 6;
14492 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14493 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14494 inst.instruction |= cmode << 8;
14495 neon_write_immbits (immbits);
14496
14497 neon_dp_fixup (&inst);
14498 }
14499 }
14500
14501 static void
14502 do_neon_bitfield (void)
14503 {
14504 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14505 neon_check_type (3, rs, N_IGNORE_TYPE);
14506 neon_three_same (neon_quad (rs), 0, -1);
14507 }
14508
14509 static void
14510 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
14511 unsigned destbits)
14512 {
14513 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14514 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
14515 types | N_KEY);
14516 if (et.type == NT_float)
14517 {
14518 NEON_ENCODE (FLOAT, inst);
14519 neon_three_same (neon_quad (rs), 0, -1);
14520 }
14521 else
14522 {
14523 NEON_ENCODE (INTEGER, inst);
14524 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
14525 }
14526 }
14527
14528 static void
14529 do_neon_dyadic_if_su (void)
14530 {
14531 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
14532 }
14533
14534 static void
14535 do_neon_dyadic_if_su_d (void)
14536 {
14537 /* This version only allow D registers, but that constraint is enforced during
14538 operand parsing so we don't need to do anything extra here. */
14539 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
14540 }
14541
14542 static void
14543 do_neon_dyadic_if_i_d (void)
14544 {
14545 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14546 affected if we specify unsigned args. */
14547 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14548 }
14549
14550 enum vfp_or_neon_is_neon_bits
14551 {
14552 NEON_CHECK_CC = 1,
14553 NEON_CHECK_ARCH = 2,
14554 NEON_CHECK_ARCH8 = 4
14555 };
14556
14557 /* Call this function if an instruction which may have belonged to the VFP or
14558 Neon instruction sets, but turned out to be a Neon instruction (due to the
14559 operand types involved, etc.). We have to check and/or fix-up a couple of
14560 things:
14561
14562 - Make sure the user hasn't attempted to make a Neon instruction
14563 conditional.
14564 - Alter the value in the condition code field if necessary.
14565 - Make sure that the arch supports Neon instructions.
14566
14567 Which of these operations take place depends on bits from enum
14568 vfp_or_neon_is_neon_bits.
14569
14570 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14571 current instruction's condition is COND_ALWAYS, the condition field is
14572 changed to inst.uncond_value. This is necessary because instructions shared
14573 between VFP and Neon may be conditional for the VFP variants only, and the
14574 unconditional Neon version must have, e.g., 0xF in the condition field. */
14575
14576 static int
14577 vfp_or_neon_is_neon (unsigned check)
14578 {
14579 /* Conditions are always legal in Thumb mode (IT blocks). */
14580 if (!thumb_mode && (check & NEON_CHECK_CC))
14581 {
14582 if (inst.cond != COND_ALWAYS)
14583 {
14584 first_error (_(BAD_COND));
14585 return FAIL;
14586 }
14587 if (inst.uncond_value != -1)
14588 inst.instruction |= inst.uncond_value << 28;
14589 }
14590
14591 if ((check & NEON_CHECK_ARCH)
14592 && !mark_feature_used (&fpu_neon_ext_v1))
14593 {
14594 first_error (_(BAD_FPU));
14595 return FAIL;
14596 }
14597
14598 if ((check & NEON_CHECK_ARCH8)
14599 && !mark_feature_used (&fpu_neon_ext_armv8))
14600 {
14601 first_error (_(BAD_FPU));
14602 return FAIL;
14603 }
14604
14605 return SUCCESS;
14606 }
14607
14608 static void
14609 do_neon_addsub_if_i (void)
14610 {
14611 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
14612 return;
14613
14614 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14615 return;
14616
14617 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14618 affected if we specify unsigned args. */
14619 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
14620 }
14621
14622 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
14623 result to be:
14624 V<op> A,B (A is operand 0, B is operand 2)
14625 to mean:
14626 V<op> A,B,A
14627 not:
14628 V<op> A,B,B
14629 so handle that case specially. */
14630
14631 static void
14632 neon_exchange_operands (void)
14633 {
14634 void *scratch = alloca (sizeof (inst.operands[0]));
14635 if (inst.operands[1].present)
14636 {
14637 /* Swap operands[1] and operands[2]. */
14638 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
14639 inst.operands[1] = inst.operands[2];
14640 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
14641 }
14642 else
14643 {
14644 inst.operands[1] = inst.operands[2];
14645 inst.operands[2] = inst.operands[0];
14646 }
14647 }
14648
14649 static void
14650 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
14651 {
14652 if (inst.operands[2].isreg)
14653 {
14654 if (invert)
14655 neon_exchange_operands ();
14656 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
14657 }
14658 else
14659 {
14660 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14661 struct neon_type_el et = neon_check_type (2, rs,
14662 N_EQK | N_SIZ, immtypes | N_KEY);
14663
14664 NEON_ENCODE (IMMED, inst);
14665 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14666 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14667 inst.instruction |= LOW4 (inst.operands[1].reg);
14668 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14669 inst.instruction |= neon_quad (rs) << 6;
14670 inst.instruction |= (et.type == NT_float) << 10;
14671 inst.instruction |= neon_logbits (et.size) << 18;
14672
14673 neon_dp_fixup (&inst);
14674 }
14675 }
14676
14677 static void
14678 do_neon_cmp (void)
14679 {
14680 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
14681 }
14682
14683 static void
14684 do_neon_cmp_inv (void)
14685 {
14686 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
14687 }
14688
14689 static void
14690 do_neon_ceq (void)
14691 {
14692 neon_compare (N_IF_32, N_IF_32, FALSE);
14693 }
14694
14695 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
14696 scalars, which are encoded in 5 bits, M : Rm.
14697 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
14698 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
14699 index in M. */
14700
14701 static unsigned
14702 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
14703 {
14704 unsigned regno = NEON_SCALAR_REG (scalar);
14705 unsigned elno = NEON_SCALAR_INDEX (scalar);
14706
14707 switch (elsize)
14708 {
14709 case 16:
14710 if (regno > 7 || elno > 3)
14711 goto bad_scalar;
14712 return regno | (elno << 3);
14713
14714 case 32:
14715 if (regno > 15 || elno > 1)
14716 goto bad_scalar;
14717 return regno | (elno << 4);
14718
14719 default:
14720 bad_scalar:
14721 first_error (_("scalar out of range for multiply instruction"));
14722 }
14723
14724 return 0;
14725 }
14726
14727 /* Encode multiply / multiply-accumulate scalar instructions. */
14728
14729 static void
14730 neon_mul_mac (struct neon_type_el et, int ubit)
14731 {
14732 unsigned scalar;
14733
14734 /* Give a more helpful error message if we have an invalid type. */
14735 if (et.type == NT_invtype)
14736 return;
14737
14738 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
14739 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14740 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14741 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14742 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14743 inst.instruction |= LOW4 (scalar);
14744 inst.instruction |= HI1 (scalar) << 5;
14745 inst.instruction |= (et.type == NT_float) << 8;
14746 inst.instruction |= neon_logbits (et.size) << 20;
14747 inst.instruction |= (ubit != 0) << 24;
14748
14749 neon_dp_fixup (&inst);
14750 }
14751
14752 static void
14753 do_neon_mac_maybe_scalar (void)
14754 {
14755 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
14756 return;
14757
14758 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14759 return;
14760
14761 if (inst.operands[2].isscalar)
14762 {
14763 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
14764 struct neon_type_el et = neon_check_type (3, rs,
14765 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
14766 NEON_ENCODE (SCALAR, inst);
14767 neon_mul_mac (et, neon_quad (rs));
14768 }
14769 else
14770 {
14771 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14772 affected if we specify unsigned args. */
14773 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14774 }
14775 }
14776
14777 static void
14778 do_neon_fmac (void)
14779 {
14780 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
14781 return;
14782
14783 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14784 return;
14785
14786 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14787 }
14788
14789 static void
14790 do_neon_tst (void)
14791 {
14792 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14793 struct neon_type_el et = neon_check_type (3, rs,
14794 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
14795 neon_three_same (neon_quad (rs), 0, et.size);
14796 }
14797
14798 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
14799 same types as the MAC equivalents. The polynomial type for this instruction
14800 is encoded the same as the integer type. */
14801
14802 static void
14803 do_neon_mul (void)
14804 {
14805 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
14806 return;
14807
14808 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14809 return;
14810
14811 if (inst.operands[2].isscalar)
14812 do_neon_mac_maybe_scalar ();
14813 else
14814 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
14815 }
14816
14817 static void
14818 do_neon_qdmulh (void)
14819 {
14820 if (inst.operands[2].isscalar)
14821 {
14822 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
14823 struct neon_type_el et = neon_check_type (3, rs,
14824 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
14825 NEON_ENCODE (SCALAR, inst);
14826 neon_mul_mac (et, neon_quad (rs));
14827 }
14828 else
14829 {
14830 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14831 struct neon_type_el et = neon_check_type (3, rs,
14832 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
14833 NEON_ENCODE (INTEGER, inst);
14834 /* The U bit (rounding) comes from bit mask. */
14835 neon_three_same (neon_quad (rs), 0, et.size);
14836 }
14837 }
14838
14839 static void
14840 do_neon_fcmp_absolute (void)
14841 {
14842 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14843 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
14844 /* Size field comes from bit mask. */
14845 neon_three_same (neon_quad (rs), 1, -1);
14846 }
14847
14848 static void
14849 do_neon_fcmp_absolute_inv (void)
14850 {
14851 neon_exchange_operands ();
14852 do_neon_fcmp_absolute ();
14853 }
14854
14855 static void
14856 do_neon_step (void)
14857 {
14858 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14859 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
14860 neon_three_same (neon_quad (rs), 0, -1);
14861 }
14862
14863 static void
14864 do_neon_abs_neg (void)
14865 {
14866 enum neon_shape rs;
14867 struct neon_type_el et;
14868
14869 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
14870 return;
14871
14872 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14873 return;
14874
14875 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14876 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
14877
14878 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14879 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14880 inst.instruction |= LOW4 (inst.operands[1].reg);
14881 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14882 inst.instruction |= neon_quad (rs) << 6;
14883 inst.instruction |= (et.type == NT_float) << 10;
14884 inst.instruction |= neon_logbits (et.size) << 18;
14885
14886 neon_dp_fixup (&inst);
14887 }
14888
14889 static void
14890 do_neon_sli (void)
14891 {
14892 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14893 struct neon_type_el et = neon_check_type (2, rs,
14894 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14895 int imm = inst.operands[2].imm;
14896 constraint (imm < 0 || (unsigned)imm >= et.size,
14897 _("immediate out of range for insert"));
14898 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
14899 }
14900
14901 static void
14902 do_neon_sri (void)
14903 {
14904 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14905 struct neon_type_el et = neon_check_type (2, rs,
14906 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14907 int imm = inst.operands[2].imm;
14908 constraint (imm < 1 || (unsigned)imm > et.size,
14909 _("immediate out of range for insert"));
14910 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
14911 }
14912
14913 static void
14914 do_neon_qshlu_imm (void)
14915 {
14916 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14917 struct neon_type_el et = neon_check_type (2, rs,
14918 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
14919 int imm = inst.operands[2].imm;
14920 constraint (imm < 0 || (unsigned)imm >= et.size,
14921 _("immediate out of range for shift"));
14922 /* Only encodes the 'U present' variant of the instruction.
14923 In this case, signed types have OP (bit 8) set to 0.
14924 Unsigned types have OP set to 1. */
14925 inst.instruction |= (et.type == NT_unsigned) << 8;
14926 /* The rest of the bits are the same as other immediate shifts. */
14927 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
14928 }
14929
14930 static void
14931 do_neon_qmovn (void)
14932 {
14933 struct neon_type_el et = neon_check_type (2, NS_DQ,
14934 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14935 /* Saturating move where operands can be signed or unsigned, and the
14936 destination has the same signedness. */
14937 NEON_ENCODE (INTEGER, inst);
14938 if (et.type == NT_unsigned)
14939 inst.instruction |= 0xc0;
14940 else
14941 inst.instruction |= 0x80;
14942 neon_two_same (0, 1, et.size / 2);
14943 }
14944
14945 static void
14946 do_neon_qmovun (void)
14947 {
14948 struct neon_type_el et = neon_check_type (2, NS_DQ,
14949 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14950 /* Saturating move with unsigned results. Operands must be signed. */
14951 NEON_ENCODE (INTEGER, inst);
14952 neon_two_same (0, 1, et.size / 2);
14953 }
14954
14955 static void
14956 do_neon_rshift_sat_narrow (void)
14957 {
14958 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14959 or unsigned. If operands are unsigned, results must also be unsigned. */
14960 struct neon_type_el et = neon_check_type (2, NS_DQI,
14961 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14962 int imm = inst.operands[2].imm;
14963 /* This gets the bounds check, size encoding and immediate bits calculation
14964 right. */
14965 et.size /= 2;
14966
14967 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
14968 VQMOVN.I<size> <Dd>, <Qm>. */
14969 if (imm == 0)
14970 {
14971 inst.operands[2].present = 0;
14972 inst.instruction = N_MNEM_vqmovn;
14973 do_neon_qmovn ();
14974 return;
14975 }
14976
14977 constraint (imm < 1 || (unsigned)imm > et.size,
14978 _("immediate out of range"));
14979 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
14980 }
14981
14982 static void
14983 do_neon_rshift_sat_narrow_u (void)
14984 {
14985 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14986 or unsigned. If operands are unsigned, results must also be unsigned. */
14987 struct neon_type_el et = neon_check_type (2, NS_DQI,
14988 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14989 int imm = inst.operands[2].imm;
14990 /* This gets the bounds check, size encoding and immediate bits calculation
14991 right. */
14992 et.size /= 2;
14993
14994 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
14995 VQMOVUN.I<size> <Dd>, <Qm>. */
14996 if (imm == 0)
14997 {
14998 inst.operands[2].present = 0;
14999 inst.instruction = N_MNEM_vqmovun;
15000 do_neon_qmovun ();
15001 return;
15002 }
15003
15004 constraint (imm < 1 || (unsigned)imm > et.size,
15005 _("immediate out of range"));
15006 /* FIXME: The manual is kind of unclear about what value U should have in
15007 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
15008 must be 1. */
15009 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
15010 }
15011
15012 static void
15013 do_neon_movn (void)
15014 {
15015 struct neon_type_el et = neon_check_type (2, NS_DQ,
15016 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15017 NEON_ENCODE (INTEGER, inst);
15018 neon_two_same (0, 1, et.size / 2);
15019 }
15020
15021 static void
15022 do_neon_rshift_narrow (void)
15023 {
15024 struct neon_type_el et = neon_check_type (2, NS_DQI,
15025 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15026 int imm = inst.operands[2].imm;
15027 /* This gets the bounds check, size encoding and immediate bits calculation
15028 right. */
15029 et.size /= 2;
15030
15031 /* If immediate is zero then we are a pseudo-instruction for
15032 VMOVN.I<size> <Dd>, <Qm> */
15033 if (imm == 0)
15034 {
15035 inst.operands[2].present = 0;
15036 inst.instruction = N_MNEM_vmovn;
15037 do_neon_movn ();
15038 return;
15039 }
15040
15041 constraint (imm < 1 || (unsigned)imm > et.size,
15042 _("immediate out of range for narrowing operation"));
15043 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
15044 }
15045
15046 static void
15047 do_neon_shll (void)
15048 {
15049 /* FIXME: Type checking when lengthening. */
15050 struct neon_type_el et = neon_check_type (2, NS_QDI,
15051 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
15052 unsigned imm = inst.operands[2].imm;
15053
15054 if (imm == et.size)
15055 {
15056 /* Maximum shift variant. */
15057 NEON_ENCODE (INTEGER, inst);
15058 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15059 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15060 inst.instruction |= LOW4 (inst.operands[1].reg);
15061 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15062 inst.instruction |= neon_logbits (et.size) << 18;
15063
15064 neon_dp_fixup (&inst);
15065 }
15066 else
15067 {
15068 /* A more-specific type check for non-max versions. */
15069 et = neon_check_type (2, NS_QDI,
15070 N_EQK | N_DBL, N_SU_32 | N_KEY);
15071 NEON_ENCODE (IMMED, inst);
15072 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
15073 }
15074 }
15075
15076 /* Check the various types for the VCVT instruction, and return which version
15077 the current instruction is. */
15078
15079 #define CVT_FLAVOUR_VAR \
15080 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
15081 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
15082 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
15083 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
15084 /* Half-precision conversions. */ \
15085 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
15086 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
15087 /* VFP instructions. */ \
15088 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
15089 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
15090 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
15091 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
15092 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
15093 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
15094 /* VFP instructions with bitshift. */ \
15095 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
15096 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
15097 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
15098 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
15099 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
15100 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
15101 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
15102 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
15103
15104 #define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
15105 neon_cvt_flavour_##C,
15106
15107 /* The different types of conversions we can do. */
15108 enum neon_cvt_flavour
15109 {
15110 CVT_FLAVOUR_VAR
15111 neon_cvt_flavour_invalid,
15112 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
15113 };
15114
15115 #undef CVT_VAR
15116
15117 static enum neon_cvt_flavour
15118 get_neon_cvt_flavour (enum neon_shape rs)
15119 {
15120 #define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
15121 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
15122 if (et.type != NT_invtype) \
15123 { \
15124 inst.error = NULL; \
15125 return (neon_cvt_flavour_##C); \
15126 }
15127
15128 struct neon_type_el et;
15129 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
15130 || rs == NS_FF) ? N_VFP : 0;
15131 /* The instruction versions which take an immediate take one register
15132 argument, which is extended to the width of the full register. Thus the
15133 "source" and "destination" registers must have the same width. Hack that
15134 here by making the size equal to the key (wider, in this case) operand. */
15135 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
15136
15137 CVT_FLAVOUR_VAR;
15138
15139 return neon_cvt_flavour_invalid;
15140 #undef CVT_VAR
15141 }
15142
15143 enum neon_cvt_mode
15144 {
15145 neon_cvt_mode_a,
15146 neon_cvt_mode_n,
15147 neon_cvt_mode_p,
15148 neon_cvt_mode_m,
15149 neon_cvt_mode_z,
15150 neon_cvt_mode_x,
15151 neon_cvt_mode_r
15152 };
15153
15154 /* Neon-syntax VFP conversions. */
15155
15156 static void
15157 do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
15158 {
15159 const char *opname = 0;
15160
15161 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
15162 {
15163 /* Conversions with immediate bitshift. */
15164 const char *enc[] =
15165 {
15166 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15167 CVT_FLAVOUR_VAR
15168 NULL
15169 #undef CVT_VAR
15170 };
15171
15172 if (flavour < (int) ARRAY_SIZE (enc))
15173 {
15174 opname = enc[flavour];
15175 constraint (inst.operands[0].reg != inst.operands[1].reg,
15176 _("operands 0 and 1 must be the same register"));
15177 inst.operands[1] = inst.operands[2];
15178 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15179 }
15180 }
15181 else
15182 {
15183 /* Conversions without bitshift. */
15184 const char *enc[] =
15185 {
15186 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15187 CVT_FLAVOUR_VAR
15188 NULL
15189 #undef CVT_VAR
15190 };
15191
15192 if (flavour < (int) ARRAY_SIZE (enc))
15193 opname = enc[flavour];
15194 }
15195
15196 if (opname)
15197 do_vfp_nsyn_opcode (opname);
15198 }
15199
15200 static void
15201 do_vfp_nsyn_cvtz (void)
15202 {
15203 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
15204 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
15205 const char *enc[] =
15206 {
15207 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15208 CVT_FLAVOUR_VAR
15209 NULL
15210 #undef CVT_VAR
15211 };
15212
15213 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
15214 do_vfp_nsyn_opcode (enc[flavour]);
15215 }
15216
15217 static void
15218 do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
15219 enum neon_cvt_mode mode)
15220 {
15221 int sz, op;
15222 int rm;
15223
15224 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15225 D register operands. */
15226 if (flavour == neon_cvt_flavour_s32_f64
15227 || flavour == neon_cvt_flavour_u32_f64)
15228 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15229 _(BAD_FPU));
15230
15231 set_it_insn_type (OUTSIDE_IT_INSN);
15232
15233 switch (flavour)
15234 {
15235 case neon_cvt_flavour_s32_f64:
15236 sz = 1;
15237 op = 1;
15238 break;
15239 case neon_cvt_flavour_s32_f32:
15240 sz = 0;
15241 op = 1;
15242 break;
15243 case neon_cvt_flavour_u32_f64:
15244 sz = 1;
15245 op = 0;
15246 break;
15247 case neon_cvt_flavour_u32_f32:
15248 sz = 0;
15249 op = 0;
15250 break;
15251 default:
15252 first_error (_("invalid instruction shape"));
15253 return;
15254 }
15255
15256 switch (mode)
15257 {
15258 case neon_cvt_mode_a: rm = 0; break;
15259 case neon_cvt_mode_n: rm = 1; break;
15260 case neon_cvt_mode_p: rm = 2; break;
15261 case neon_cvt_mode_m: rm = 3; break;
15262 default: first_error (_("invalid rounding mode")); return;
15263 }
15264
15265 NEON_ENCODE (FPV8, inst);
15266 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15267 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15268 inst.instruction |= sz << 8;
15269 inst.instruction |= op << 7;
15270 inst.instruction |= rm << 16;
15271 inst.instruction |= 0xf0000000;
15272 inst.is_neon = TRUE;
15273 }
15274
15275 static void
15276 do_neon_cvt_1 (enum neon_cvt_mode mode)
15277 {
15278 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
15279 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
15280 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
15281
15282 /* PR11109: Handle round-to-zero for VCVT conversions. */
15283 if (mode == neon_cvt_mode_z
15284 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
15285 && (flavour == neon_cvt_flavour_s32_f32
15286 || flavour == neon_cvt_flavour_u32_f32
15287 || flavour == neon_cvt_flavour_s32_f64
15288 || flavour == neon_cvt_flavour_u32_f64)
15289 && (rs == NS_FD || rs == NS_FF))
15290 {
15291 do_vfp_nsyn_cvtz ();
15292 return;
15293 }
15294
15295 /* VFP rather than Neon conversions. */
15296 if (flavour >= neon_cvt_flavour_first_fp)
15297 {
15298 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15299 do_vfp_nsyn_cvt (rs, flavour);
15300 else
15301 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15302
15303 return;
15304 }
15305
15306 switch (rs)
15307 {
15308 case NS_DDI:
15309 case NS_QQI:
15310 {
15311 unsigned immbits;
15312 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
15313
15314 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15315 return;
15316
15317 /* Fixed-point conversion with #0 immediate is encoded as an
15318 integer conversion. */
15319 if (inst.operands[2].present && inst.operands[2].imm == 0)
15320 goto int_encode;
15321 immbits = 32 - inst.operands[2].imm;
15322 NEON_ENCODE (IMMED, inst);
15323 if (flavour != neon_cvt_flavour_invalid)
15324 inst.instruction |= enctab[flavour];
15325 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15326 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15327 inst.instruction |= LOW4 (inst.operands[1].reg);
15328 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15329 inst.instruction |= neon_quad (rs) << 6;
15330 inst.instruction |= 1 << 21;
15331 inst.instruction |= immbits << 16;
15332
15333 neon_dp_fixup (&inst);
15334 }
15335 break;
15336
15337 case NS_DD:
15338 case NS_QQ:
15339 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
15340 {
15341 NEON_ENCODE (FLOAT, inst);
15342 set_it_insn_type (OUTSIDE_IT_INSN);
15343
15344 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
15345 return;
15346
15347 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15348 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15349 inst.instruction |= LOW4 (inst.operands[1].reg);
15350 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15351 inst.instruction |= neon_quad (rs) << 6;
15352 inst.instruction |= (flavour == neon_cvt_flavour_u32_f32) << 7;
15353 inst.instruction |= mode << 8;
15354 if (thumb_mode)
15355 inst.instruction |= 0xfc000000;
15356 else
15357 inst.instruction |= 0xf0000000;
15358 }
15359 else
15360 {
15361 int_encode:
15362 {
15363 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
15364
15365 NEON_ENCODE (INTEGER, inst);
15366
15367 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15368 return;
15369
15370 if (flavour != neon_cvt_flavour_invalid)
15371 inst.instruction |= enctab[flavour];
15372
15373 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15374 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15375 inst.instruction |= LOW4 (inst.operands[1].reg);
15376 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15377 inst.instruction |= neon_quad (rs) << 6;
15378 inst.instruction |= 2 << 18;
15379
15380 neon_dp_fixup (&inst);
15381 }
15382 }
15383 break;
15384
15385 /* Half-precision conversions for Advanced SIMD -- neon. */
15386 case NS_QD:
15387 case NS_DQ:
15388
15389 if ((rs == NS_DQ)
15390 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
15391 {
15392 as_bad (_("operand size must match register width"));
15393 break;
15394 }
15395
15396 if ((rs == NS_QD)
15397 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
15398 {
15399 as_bad (_("operand size must match register width"));
15400 break;
15401 }
15402
15403 if (rs == NS_DQ)
15404 inst.instruction = 0x3b60600;
15405 else
15406 inst.instruction = 0x3b60700;
15407
15408 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15409 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15410 inst.instruction |= LOW4 (inst.operands[1].reg);
15411 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15412 neon_dp_fixup (&inst);
15413 break;
15414
15415 default:
15416 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
15417 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15418 do_vfp_nsyn_cvt (rs, flavour);
15419 else
15420 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15421 }
15422 }
15423
15424 static void
15425 do_neon_cvtr (void)
15426 {
15427 do_neon_cvt_1 (neon_cvt_mode_x);
15428 }
15429
15430 static void
15431 do_neon_cvt (void)
15432 {
15433 do_neon_cvt_1 (neon_cvt_mode_z);
15434 }
15435
15436 static void
15437 do_neon_cvta (void)
15438 {
15439 do_neon_cvt_1 (neon_cvt_mode_a);
15440 }
15441
15442 static void
15443 do_neon_cvtn (void)
15444 {
15445 do_neon_cvt_1 (neon_cvt_mode_n);
15446 }
15447
15448 static void
15449 do_neon_cvtp (void)
15450 {
15451 do_neon_cvt_1 (neon_cvt_mode_p);
15452 }
15453
15454 static void
15455 do_neon_cvtm (void)
15456 {
15457 do_neon_cvt_1 (neon_cvt_mode_m);
15458 }
15459
15460 static void
15461 do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
15462 {
15463 if (is_double)
15464 mark_feature_used (&fpu_vfp_ext_armv8);
15465
15466 encode_arm_vfp_reg (inst.operands[0].reg,
15467 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
15468 encode_arm_vfp_reg (inst.operands[1].reg,
15469 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
15470 inst.instruction |= to ? 0x10000 : 0;
15471 inst.instruction |= t ? 0x80 : 0;
15472 inst.instruction |= is_double ? 0x100 : 0;
15473 do_vfp_cond_or_thumb ();
15474 }
15475
15476 static void
15477 do_neon_cvttb_1 (bfd_boolean t)
15478 {
15479 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_DF, NS_NULL);
15480
15481 if (rs == NS_NULL)
15482 return;
15483 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
15484 {
15485 inst.error = NULL;
15486 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
15487 }
15488 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
15489 {
15490 inst.error = NULL;
15491 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
15492 }
15493 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
15494 {
15495 /* The VCVTB and VCVTT instructions with D-register operands
15496 don't work for SP only targets. */
15497 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15498 _(BAD_FPU));
15499
15500 inst.error = NULL;
15501 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
15502 }
15503 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
15504 {
15505 /* The VCVTB and VCVTT instructions with D-register operands
15506 don't work for SP only targets. */
15507 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15508 _(BAD_FPU));
15509
15510 inst.error = NULL;
15511 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
15512 }
15513 else
15514 return;
15515 }
15516
15517 static void
15518 do_neon_cvtb (void)
15519 {
15520 do_neon_cvttb_1 (FALSE);
15521 }
15522
15523
15524 static void
15525 do_neon_cvtt (void)
15526 {
15527 do_neon_cvttb_1 (TRUE);
15528 }
15529
15530 static void
15531 neon_move_immediate (void)
15532 {
15533 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
15534 struct neon_type_el et = neon_check_type (2, rs,
15535 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
15536 unsigned immlo, immhi = 0, immbits;
15537 int op, cmode, float_p;
15538
15539 constraint (et.type == NT_invtype,
15540 _("operand size must be specified for immediate VMOV"));
15541
15542 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
15543 op = (inst.instruction & (1 << 5)) != 0;
15544
15545 immlo = inst.operands[1].imm;
15546 if (inst.operands[1].regisimm)
15547 immhi = inst.operands[1].reg;
15548
15549 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
15550 _("immediate has bits set outside the operand size"));
15551
15552 float_p = inst.operands[1].immisfloat;
15553
15554 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
15555 et.size, et.type)) == FAIL)
15556 {
15557 /* Invert relevant bits only. */
15558 neon_invert_size (&immlo, &immhi, et.size);
15559 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
15560 with one or the other; those cases are caught by
15561 neon_cmode_for_move_imm. */
15562 op = !op;
15563 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
15564 &op, et.size, et.type)) == FAIL)
15565 {
15566 first_error (_("immediate out of range"));
15567 return;
15568 }
15569 }
15570
15571 inst.instruction &= ~(1 << 5);
15572 inst.instruction |= op << 5;
15573
15574 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15575 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15576 inst.instruction |= neon_quad (rs) << 6;
15577 inst.instruction |= cmode << 8;
15578
15579 neon_write_immbits (immbits);
15580 }
15581
15582 static void
15583 do_neon_mvn (void)
15584 {
15585 if (inst.operands[1].isreg)
15586 {
15587 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15588
15589 NEON_ENCODE (INTEGER, inst);
15590 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15591 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15592 inst.instruction |= LOW4 (inst.operands[1].reg);
15593 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15594 inst.instruction |= neon_quad (rs) << 6;
15595 }
15596 else
15597 {
15598 NEON_ENCODE (IMMED, inst);
15599 neon_move_immediate ();
15600 }
15601
15602 neon_dp_fixup (&inst);
15603 }
15604
15605 /* Encode instructions of form:
15606
15607 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
15608 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
15609
15610 static void
15611 neon_mixed_length (struct neon_type_el et, unsigned size)
15612 {
15613 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15614 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15615 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15616 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15617 inst.instruction |= LOW4 (inst.operands[2].reg);
15618 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15619 inst.instruction |= (et.type == NT_unsigned) << 24;
15620 inst.instruction |= neon_logbits (size) << 20;
15621
15622 neon_dp_fixup (&inst);
15623 }
15624
15625 static void
15626 do_neon_dyadic_long (void)
15627 {
15628 /* FIXME: Type checking for lengthening op. */
15629 struct neon_type_el et = neon_check_type (3, NS_QDD,
15630 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
15631 neon_mixed_length (et, et.size);
15632 }
15633
15634 static void
15635 do_neon_abal (void)
15636 {
15637 struct neon_type_el et = neon_check_type (3, NS_QDD,
15638 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
15639 neon_mixed_length (et, et.size);
15640 }
15641
15642 static void
15643 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
15644 {
15645 if (inst.operands[2].isscalar)
15646 {
15647 struct neon_type_el et = neon_check_type (3, NS_QDS,
15648 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
15649 NEON_ENCODE (SCALAR, inst);
15650 neon_mul_mac (et, et.type == NT_unsigned);
15651 }
15652 else
15653 {
15654 struct neon_type_el et = neon_check_type (3, NS_QDD,
15655 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
15656 NEON_ENCODE (INTEGER, inst);
15657 neon_mixed_length (et, et.size);
15658 }
15659 }
15660
15661 static void
15662 do_neon_mac_maybe_scalar_long (void)
15663 {
15664 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
15665 }
15666
15667 static void
15668 do_neon_dyadic_wide (void)
15669 {
15670 struct neon_type_el et = neon_check_type (3, NS_QQD,
15671 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
15672 neon_mixed_length (et, et.size);
15673 }
15674
15675 static void
15676 do_neon_dyadic_narrow (void)
15677 {
15678 struct neon_type_el et = neon_check_type (3, NS_QDD,
15679 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
15680 /* Operand sign is unimportant, and the U bit is part of the opcode,
15681 so force the operand type to integer. */
15682 et.type = NT_integer;
15683 neon_mixed_length (et, et.size / 2);
15684 }
15685
15686 static void
15687 do_neon_mul_sat_scalar_long (void)
15688 {
15689 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
15690 }
15691
15692 static void
15693 do_neon_vmull (void)
15694 {
15695 if (inst.operands[2].isscalar)
15696 do_neon_mac_maybe_scalar_long ();
15697 else
15698 {
15699 struct neon_type_el et = neon_check_type (3, NS_QDD,
15700 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
15701
15702 if (et.type == NT_poly)
15703 NEON_ENCODE (POLY, inst);
15704 else
15705 NEON_ENCODE (INTEGER, inst);
15706
15707 /* For polynomial encoding the U bit must be zero, and the size must
15708 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
15709 obviously, as 0b10). */
15710 if (et.size == 64)
15711 {
15712 /* Check we're on the correct architecture. */
15713 if (!mark_feature_used (&fpu_crypto_ext_armv8))
15714 inst.error =
15715 _("Instruction form not available on this architecture.");
15716
15717 et.size = 32;
15718 }
15719
15720 neon_mixed_length (et, et.size);
15721 }
15722 }
15723
15724 static void
15725 do_neon_ext (void)
15726 {
15727 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
15728 struct neon_type_el et = neon_check_type (3, rs,
15729 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15730 unsigned imm = (inst.operands[3].imm * et.size) / 8;
15731
15732 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
15733 _("shift out of range"));
15734 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15735 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15736 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15737 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15738 inst.instruction |= LOW4 (inst.operands[2].reg);
15739 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15740 inst.instruction |= neon_quad (rs) << 6;
15741 inst.instruction |= imm << 8;
15742
15743 neon_dp_fixup (&inst);
15744 }
15745
15746 static void
15747 do_neon_rev (void)
15748 {
15749 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15750 struct neon_type_el et = neon_check_type (2, rs,
15751 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15752 unsigned op = (inst.instruction >> 7) & 3;
15753 /* N (width of reversed regions) is encoded as part of the bitmask. We
15754 extract it here to check the elements to be reversed are smaller.
15755 Otherwise we'd get a reserved instruction. */
15756 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
15757 gas_assert (elsize != 0);
15758 constraint (et.size >= elsize,
15759 _("elements must be smaller than reversal region"));
15760 neon_two_same (neon_quad (rs), 1, et.size);
15761 }
15762
15763 static void
15764 do_neon_dup (void)
15765 {
15766 if (inst.operands[1].isscalar)
15767 {
15768 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
15769 struct neon_type_el et = neon_check_type (2, rs,
15770 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15771 unsigned sizebits = et.size >> 3;
15772 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
15773 int logsize = neon_logbits (et.size);
15774 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
15775
15776 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
15777 return;
15778
15779 NEON_ENCODE (SCALAR, inst);
15780 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15781 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15782 inst.instruction |= LOW4 (dm);
15783 inst.instruction |= HI1 (dm) << 5;
15784 inst.instruction |= neon_quad (rs) << 6;
15785 inst.instruction |= x << 17;
15786 inst.instruction |= sizebits << 16;
15787
15788 neon_dp_fixup (&inst);
15789 }
15790 else
15791 {
15792 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
15793 struct neon_type_el et = neon_check_type (2, rs,
15794 N_8 | N_16 | N_32 | N_KEY, N_EQK);
15795 /* Duplicate ARM register to lanes of vector. */
15796 NEON_ENCODE (ARMREG, inst);
15797 switch (et.size)
15798 {
15799 case 8: inst.instruction |= 0x400000; break;
15800 case 16: inst.instruction |= 0x000020; break;
15801 case 32: inst.instruction |= 0x000000; break;
15802 default: break;
15803 }
15804 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
15805 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
15806 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
15807 inst.instruction |= neon_quad (rs) << 21;
15808 /* The encoding for this instruction is identical for the ARM and Thumb
15809 variants, except for the condition field. */
15810 do_vfp_cond_or_thumb ();
15811 }
15812 }
15813
15814 /* VMOV has particularly many variations. It can be one of:
15815 0. VMOV<c><q> <Qd>, <Qm>
15816 1. VMOV<c><q> <Dd>, <Dm>
15817 (Register operations, which are VORR with Rm = Rn.)
15818 2. VMOV<c><q>.<dt> <Qd>, #<imm>
15819 3. VMOV<c><q>.<dt> <Dd>, #<imm>
15820 (Immediate loads.)
15821 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
15822 (ARM register to scalar.)
15823 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
15824 (Two ARM registers to vector.)
15825 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
15826 (Scalar to ARM register.)
15827 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
15828 (Vector to two ARM registers.)
15829 8. VMOV.F32 <Sd>, <Sm>
15830 9. VMOV.F64 <Dd>, <Dm>
15831 (VFP register moves.)
15832 10. VMOV.F32 <Sd>, #imm
15833 11. VMOV.F64 <Dd>, #imm
15834 (VFP float immediate load.)
15835 12. VMOV <Rd>, <Sm>
15836 (VFP single to ARM reg.)
15837 13. VMOV <Sd>, <Rm>
15838 (ARM reg to VFP single.)
15839 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
15840 (Two ARM regs to two VFP singles.)
15841 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
15842 (Two VFP singles to two ARM regs.)
15843
15844 These cases can be disambiguated using neon_select_shape, except cases 1/9
15845 and 3/11 which depend on the operand type too.
15846
15847 All the encoded bits are hardcoded by this function.
15848
15849 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
15850 Cases 5, 7 may be used with VFPv2 and above.
15851
15852 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
15853 can specify a type where it doesn't make sense to, and is ignored). */
15854
15855 static void
15856 do_neon_mov (void)
15857 {
15858 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
15859 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
15860 NS_NULL);
15861 struct neon_type_el et;
15862 const char *ldconst = 0;
15863
15864 switch (rs)
15865 {
15866 case NS_DD: /* case 1/9. */
15867 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
15868 /* It is not an error here if no type is given. */
15869 inst.error = NULL;
15870 if (et.type == NT_float && et.size == 64)
15871 {
15872 do_vfp_nsyn_opcode ("fcpyd");
15873 break;
15874 }
15875 /* fall through. */
15876
15877 case NS_QQ: /* case 0/1. */
15878 {
15879 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15880 return;
15881 /* The architecture manual I have doesn't explicitly state which
15882 value the U bit should have for register->register moves, but
15883 the equivalent VORR instruction has U = 0, so do that. */
15884 inst.instruction = 0x0200110;
15885 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15886 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15887 inst.instruction |= LOW4 (inst.operands[1].reg);
15888 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15889 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15890 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15891 inst.instruction |= neon_quad (rs) << 6;
15892
15893 neon_dp_fixup (&inst);
15894 }
15895 break;
15896
15897 case NS_DI: /* case 3/11. */
15898 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
15899 inst.error = NULL;
15900 if (et.type == NT_float && et.size == 64)
15901 {
15902 /* case 11 (fconstd). */
15903 ldconst = "fconstd";
15904 goto encode_fconstd;
15905 }
15906 /* fall through. */
15907
15908 case NS_QI: /* case 2/3. */
15909 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15910 return;
15911 inst.instruction = 0x0800010;
15912 neon_move_immediate ();
15913 neon_dp_fixup (&inst);
15914 break;
15915
15916 case NS_SR: /* case 4. */
15917 {
15918 unsigned bcdebits = 0;
15919 int logsize;
15920 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
15921 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
15922
15923 /* .<size> is optional here, defaulting to .32. */
15924 if (inst.vectype.elems == 0
15925 && inst.operands[0].vectype.type == NT_invtype
15926 && inst.operands[1].vectype.type == NT_invtype)
15927 {
15928 inst.vectype.el[0].type = NT_untyped;
15929 inst.vectype.el[0].size = 32;
15930 inst.vectype.elems = 1;
15931 }
15932
15933 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
15934 logsize = neon_logbits (et.size);
15935
15936 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
15937 _(BAD_FPU));
15938 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
15939 && et.size != 32, _(BAD_FPU));
15940 constraint (et.type == NT_invtype, _("bad type for scalar"));
15941 constraint (x >= 64 / et.size, _("scalar index out of range"));
15942
15943 switch (et.size)
15944 {
15945 case 8: bcdebits = 0x8; break;
15946 case 16: bcdebits = 0x1; break;
15947 case 32: bcdebits = 0x0; break;
15948 default: ;
15949 }
15950
15951 bcdebits |= x << logsize;
15952
15953 inst.instruction = 0xe000b10;
15954 do_vfp_cond_or_thumb ();
15955 inst.instruction |= LOW4 (dn) << 16;
15956 inst.instruction |= HI1 (dn) << 7;
15957 inst.instruction |= inst.operands[1].reg << 12;
15958 inst.instruction |= (bcdebits & 3) << 5;
15959 inst.instruction |= (bcdebits >> 2) << 21;
15960 }
15961 break;
15962
15963 case NS_DRR: /* case 5 (fmdrr). */
15964 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
15965 _(BAD_FPU));
15966
15967 inst.instruction = 0xc400b10;
15968 do_vfp_cond_or_thumb ();
15969 inst.instruction |= LOW4 (inst.operands[0].reg);
15970 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
15971 inst.instruction |= inst.operands[1].reg << 12;
15972 inst.instruction |= inst.operands[2].reg << 16;
15973 break;
15974
15975 case NS_RS: /* case 6. */
15976 {
15977 unsigned logsize;
15978 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
15979 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
15980 unsigned abcdebits = 0;
15981
15982 /* .<dt> is optional here, defaulting to .32. */
15983 if (inst.vectype.elems == 0
15984 && inst.operands[0].vectype.type == NT_invtype
15985 && inst.operands[1].vectype.type == NT_invtype)
15986 {
15987 inst.vectype.el[0].type = NT_untyped;
15988 inst.vectype.el[0].size = 32;
15989 inst.vectype.elems = 1;
15990 }
15991
15992 et = neon_check_type (2, NS_NULL,
15993 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
15994 logsize = neon_logbits (et.size);
15995
15996 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
15997 _(BAD_FPU));
15998 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
15999 && et.size != 32, _(BAD_FPU));
16000 constraint (et.type == NT_invtype, _("bad type for scalar"));
16001 constraint (x >= 64 / et.size, _("scalar index out of range"));
16002
16003 switch (et.size)
16004 {
16005 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
16006 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
16007 case 32: abcdebits = 0x00; break;
16008 default: ;
16009 }
16010
16011 abcdebits |= x << logsize;
16012 inst.instruction = 0xe100b10;
16013 do_vfp_cond_or_thumb ();
16014 inst.instruction |= LOW4 (dn) << 16;
16015 inst.instruction |= HI1 (dn) << 7;
16016 inst.instruction |= inst.operands[0].reg << 12;
16017 inst.instruction |= (abcdebits & 3) << 5;
16018 inst.instruction |= (abcdebits >> 2) << 21;
16019 }
16020 break;
16021
16022 case NS_RRD: /* case 7 (fmrrd). */
16023 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
16024 _(BAD_FPU));
16025
16026 inst.instruction = 0xc500b10;
16027 do_vfp_cond_or_thumb ();
16028 inst.instruction |= inst.operands[0].reg << 12;
16029 inst.instruction |= inst.operands[1].reg << 16;
16030 inst.instruction |= LOW4 (inst.operands[2].reg);
16031 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16032 break;
16033
16034 case NS_FF: /* case 8 (fcpys). */
16035 do_vfp_nsyn_opcode ("fcpys");
16036 break;
16037
16038 case NS_FI: /* case 10 (fconsts). */
16039 ldconst = "fconsts";
16040 encode_fconstd:
16041 if (is_quarter_float (inst.operands[1].imm))
16042 {
16043 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
16044 do_vfp_nsyn_opcode (ldconst);
16045 }
16046 else
16047 first_error (_("immediate out of range"));
16048 break;
16049
16050 case NS_RF: /* case 12 (fmrs). */
16051 do_vfp_nsyn_opcode ("fmrs");
16052 break;
16053
16054 case NS_FR: /* case 13 (fmsr). */
16055 do_vfp_nsyn_opcode ("fmsr");
16056 break;
16057
16058 /* The encoders for the fmrrs and fmsrr instructions expect three operands
16059 (one of which is a list), but we have parsed four. Do some fiddling to
16060 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
16061 expect. */
16062 case NS_RRFF: /* case 14 (fmrrs). */
16063 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
16064 _("VFP registers must be adjacent"));
16065 inst.operands[2].imm = 2;
16066 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16067 do_vfp_nsyn_opcode ("fmrrs");
16068 break;
16069
16070 case NS_FFRR: /* case 15 (fmsrr). */
16071 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
16072 _("VFP registers must be adjacent"));
16073 inst.operands[1] = inst.operands[2];
16074 inst.operands[2] = inst.operands[3];
16075 inst.operands[0].imm = 2;
16076 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16077 do_vfp_nsyn_opcode ("fmsrr");
16078 break;
16079
16080 case NS_NULL:
16081 /* neon_select_shape has determined that the instruction
16082 shape is wrong and has already set the error message. */
16083 break;
16084
16085 default:
16086 abort ();
16087 }
16088 }
16089
16090 static void
16091 do_neon_rshift_round_imm (void)
16092 {
16093 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
16094 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16095 int imm = inst.operands[2].imm;
16096
16097 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
16098 if (imm == 0)
16099 {
16100 inst.operands[2].present = 0;
16101 do_neon_mov ();
16102 return;
16103 }
16104
16105 constraint (imm < 1 || (unsigned)imm > et.size,
16106 _("immediate out of range for shift"));
16107 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
16108 et.size - imm);
16109 }
16110
16111 static void
16112 do_neon_movl (void)
16113 {
16114 struct neon_type_el et = neon_check_type (2, NS_QD,
16115 N_EQK | N_DBL, N_SU_32 | N_KEY);
16116 unsigned sizebits = et.size >> 3;
16117 inst.instruction |= sizebits << 19;
16118 neon_two_same (0, et.type == NT_unsigned, -1);
16119 }
16120
16121 static void
16122 do_neon_trn (void)
16123 {
16124 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16125 struct neon_type_el et = neon_check_type (2, rs,
16126 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16127 NEON_ENCODE (INTEGER, inst);
16128 neon_two_same (neon_quad (rs), 1, et.size);
16129 }
16130
16131 static void
16132 do_neon_zip_uzp (void)
16133 {
16134 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16135 struct neon_type_el et = neon_check_type (2, rs,
16136 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16137 if (rs == NS_DD && et.size == 32)
16138 {
16139 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
16140 inst.instruction = N_MNEM_vtrn;
16141 do_neon_trn ();
16142 return;
16143 }
16144 neon_two_same (neon_quad (rs), 1, et.size);
16145 }
16146
16147 static void
16148 do_neon_sat_abs_neg (void)
16149 {
16150 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16151 struct neon_type_el et = neon_check_type (2, rs,
16152 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
16153 neon_two_same (neon_quad (rs), 1, et.size);
16154 }
16155
16156 static void
16157 do_neon_pair_long (void)
16158 {
16159 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16160 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
16161 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
16162 inst.instruction |= (et.type == NT_unsigned) << 7;
16163 neon_two_same (neon_quad (rs), 1, et.size);
16164 }
16165
16166 static void
16167 do_neon_recip_est (void)
16168 {
16169 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16170 struct neon_type_el et = neon_check_type (2, rs,
16171 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
16172 inst.instruction |= (et.type == NT_float) << 8;
16173 neon_two_same (neon_quad (rs), 1, et.size);
16174 }
16175
16176 static void
16177 do_neon_cls (void)
16178 {
16179 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16180 struct neon_type_el et = neon_check_type (2, rs,
16181 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
16182 neon_two_same (neon_quad (rs), 1, et.size);
16183 }
16184
16185 static void
16186 do_neon_clz (void)
16187 {
16188 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16189 struct neon_type_el et = neon_check_type (2, rs,
16190 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
16191 neon_two_same (neon_quad (rs), 1, et.size);
16192 }
16193
16194 static void
16195 do_neon_cnt (void)
16196 {
16197 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16198 struct neon_type_el et = neon_check_type (2, rs,
16199 N_EQK | N_INT, N_8 | N_KEY);
16200 neon_two_same (neon_quad (rs), 1, et.size);
16201 }
16202
16203 static void
16204 do_neon_swp (void)
16205 {
16206 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16207 neon_two_same (neon_quad (rs), 1, -1);
16208 }
16209
16210 static void
16211 do_neon_tbl_tbx (void)
16212 {
16213 unsigned listlenbits;
16214 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
16215
16216 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
16217 {
16218 first_error (_("bad list length for table lookup"));
16219 return;
16220 }
16221
16222 listlenbits = inst.operands[1].imm - 1;
16223 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16224 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16225 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16226 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16227 inst.instruction |= LOW4 (inst.operands[2].reg);
16228 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16229 inst.instruction |= listlenbits << 8;
16230
16231 neon_dp_fixup (&inst);
16232 }
16233
16234 static void
16235 do_neon_ldm_stm (void)
16236 {
16237 /* P, U and L bits are part of bitmask. */
16238 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
16239 unsigned offsetbits = inst.operands[1].imm * 2;
16240
16241 if (inst.operands[1].issingle)
16242 {
16243 do_vfp_nsyn_ldm_stm (is_dbmode);
16244 return;
16245 }
16246
16247 constraint (is_dbmode && !inst.operands[0].writeback,
16248 _("writeback (!) must be used for VLDMDB and VSTMDB"));
16249
16250 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
16251 _("register list must contain at least 1 and at most 16 "
16252 "registers"));
16253
16254 inst.instruction |= inst.operands[0].reg << 16;
16255 inst.instruction |= inst.operands[0].writeback << 21;
16256 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16257 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
16258
16259 inst.instruction |= offsetbits;
16260
16261 do_vfp_cond_or_thumb ();
16262 }
16263
16264 static void
16265 do_neon_ldr_str (void)
16266 {
16267 int is_ldr = (inst.instruction & (1 << 20)) != 0;
16268
16269 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
16270 And is UNPREDICTABLE in thumb mode. */
16271 if (!is_ldr
16272 && inst.operands[1].reg == REG_PC
16273 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
16274 {
16275 if (thumb_mode)
16276 inst.error = _("Use of PC here is UNPREDICTABLE");
16277 else if (warn_on_deprecated)
16278 as_tsktsk (_("Use of PC here is deprecated"));
16279 }
16280
16281 if (inst.operands[0].issingle)
16282 {
16283 if (is_ldr)
16284 do_vfp_nsyn_opcode ("flds");
16285 else
16286 do_vfp_nsyn_opcode ("fsts");
16287 }
16288 else
16289 {
16290 if (is_ldr)
16291 do_vfp_nsyn_opcode ("fldd");
16292 else
16293 do_vfp_nsyn_opcode ("fstd");
16294 }
16295 }
16296
16297 /* "interleave" version also handles non-interleaving register VLD1/VST1
16298 instructions. */
16299
16300 static void
16301 do_neon_ld_st_interleave (void)
16302 {
16303 struct neon_type_el et = neon_check_type (1, NS_NULL,
16304 N_8 | N_16 | N_32 | N_64);
16305 unsigned alignbits = 0;
16306 unsigned idx;
16307 /* The bits in this table go:
16308 0: register stride of one (0) or two (1)
16309 1,2: register list length, minus one (1, 2, 3, 4).
16310 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
16311 We use -1 for invalid entries. */
16312 const int typetable[] =
16313 {
16314 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
16315 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
16316 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
16317 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
16318 };
16319 int typebits;
16320
16321 if (et.type == NT_invtype)
16322 return;
16323
16324 if (inst.operands[1].immisalign)
16325 switch (inst.operands[1].imm >> 8)
16326 {
16327 case 64: alignbits = 1; break;
16328 case 128:
16329 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
16330 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
16331 goto bad_alignment;
16332 alignbits = 2;
16333 break;
16334 case 256:
16335 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
16336 goto bad_alignment;
16337 alignbits = 3;
16338 break;
16339 default:
16340 bad_alignment:
16341 first_error (_("bad alignment"));
16342 return;
16343 }
16344
16345 inst.instruction |= alignbits << 4;
16346 inst.instruction |= neon_logbits (et.size) << 6;
16347
16348 /* Bits [4:6] of the immediate in a list specifier encode register stride
16349 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
16350 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
16351 up the right value for "type" in a table based on this value and the given
16352 list style, then stick it back. */
16353 idx = ((inst.operands[0].imm >> 4) & 7)
16354 | (((inst.instruction >> 8) & 3) << 3);
16355
16356 typebits = typetable[idx];
16357
16358 constraint (typebits == -1, _("bad list type for instruction"));
16359 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
16360 _("bad element type for instruction"));
16361
16362 inst.instruction &= ~0xf00;
16363 inst.instruction |= typebits << 8;
16364 }
16365
16366 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
16367 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
16368 otherwise. The variable arguments are a list of pairs of legal (size, align)
16369 values, terminated with -1. */
16370
16371 static int
16372 neon_alignment_bit (int size, int align, int *do_align, ...)
16373 {
16374 va_list ap;
16375 int result = FAIL, thissize, thisalign;
16376
16377 if (!inst.operands[1].immisalign)
16378 {
16379 *do_align = 0;
16380 return SUCCESS;
16381 }
16382
16383 va_start (ap, do_align);
16384
16385 do
16386 {
16387 thissize = va_arg (ap, int);
16388 if (thissize == -1)
16389 break;
16390 thisalign = va_arg (ap, int);
16391
16392 if (size == thissize && align == thisalign)
16393 result = SUCCESS;
16394 }
16395 while (result != SUCCESS);
16396
16397 va_end (ap);
16398
16399 if (result == SUCCESS)
16400 *do_align = 1;
16401 else
16402 first_error (_("unsupported alignment for instruction"));
16403
16404 return result;
16405 }
16406
16407 static void
16408 do_neon_ld_st_lane (void)
16409 {
16410 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
16411 int align_good, do_align = 0;
16412 int logsize = neon_logbits (et.size);
16413 int align = inst.operands[1].imm >> 8;
16414 int n = (inst.instruction >> 8) & 3;
16415 int max_el = 64 / et.size;
16416
16417 if (et.type == NT_invtype)
16418 return;
16419
16420 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
16421 _("bad list length"));
16422 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
16423 _("scalar index out of range"));
16424 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
16425 && et.size == 8,
16426 _("stride of 2 unavailable when element size is 8"));
16427
16428 switch (n)
16429 {
16430 case 0: /* VLD1 / VST1. */
16431 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
16432 32, 32, -1);
16433 if (align_good == FAIL)
16434 return;
16435 if (do_align)
16436 {
16437 unsigned alignbits = 0;
16438 switch (et.size)
16439 {
16440 case 16: alignbits = 0x1; break;
16441 case 32: alignbits = 0x3; break;
16442 default: ;
16443 }
16444 inst.instruction |= alignbits << 4;
16445 }
16446 break;
16447
16448 case 1: /* VLD2 / VST2. */
16449 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
16450 32, 64, -1);
16451 if (align_good == FAIL)
16452 return;
16453 if (do_align)
16454 inst.instruction |= 1 << 4;
16455 break;
16456
16457 case 2: /* VLD3 / VST3. */
16458 constraint (inst.operands[1].immisalign,
16459 _("can't use alignment with this instruction"));
16460 break;
16461
16462 case 3: /* VLD4 / VST4. */
16463 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
16464 16, 64, 32, 64, 32, 128, -1);
16465 if (align_good == FAIL)
16466 return;
16467 if (do_align)
16468 {
16469 unsigned alignbits = 0;
16470 switch (et.size)
16471 {
16472 case 8: alignbits = 0x1; break;
16473 case 16: alignbits = 0x1; break;
16474 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
16475 default: ;
16476 }
16477 inst.instruction |= alignbits << 4;
16478 }
16479 break;
16480
16481 default: ;
16482 }
16483
16484 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
16485 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16486 inst.instruction |= 1 << (4 + logsize);
16487
16488 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
16489 inst.instruction |= logsize << 10;
16490 }
16491
16492 /* Encode single n-element structure to all lanes VLD<n> instructions. */
16493
16494 static void
16495 do_neon_ld_dup (void)
16496 {
16497 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
16498 int align_good, do_align = 0;
16499
16500 if (et.type == NT_invtype)
16501 return;
16502
16503 switch ((inst.instruction >> 8) & 3)
16504 {
16505 case 0: /* VLD1. */
16506 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
16507 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
16508 &do_align, 16, 16, 32, 32, -1);
16509 if (align_good == FAIL)
16510 return;
16511 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
16512 {
16513 case 1: break;
16514 case 2: inst.instruction |= 1 << 5; break;
16515 default: first_error (_("bad list length")); return;
16516 }
16517 inst.instruction |= neon_logbits (et.size) << 6;
16518 break;
16519
16520 case 1: /* VLD2. */
16521 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
16522 &do_align, 8, 16, 16, 32, 32, 64, -1);
16523 if (align_good == FAIL)
16524 return;
16525 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
16526 _("bad list length"));
16527 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16528 inst.instruction |= 1 << 5;
16529 inst.instruction |= neon_logbits (et.size) << 6;
16530 break;
16531
16532 case 2: /* VLD3. */
16533 constraint (inst.operands[1].immisalign,
16534 _("can't use alignment with this instruction"));
16535 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
16536 _("bad list length"));
16537 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16538 inst.instruction |= 1 << 5;
16539 inst.instruction |= neon_logbits (et.size) << 6;
16540 break;
16541
16542 case 3: /* VLD4. */
16543 {
16544 int align = inst.operands[1].imm >> 8;
16545 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
16546 16, 64, 32, 64, 32, 128, -1);
16547 if (align_good == FAIL)
16548 return;
16549 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
16550 _("bad list length"));
16551 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16552 inst.instruction |= 1 << 5;
16553 if (et.size == 32 && align == 128)
16554 inst.instruction |= 0x3 << 6;
16555 else
16556 inst.instruction |= neon_logbits (et.size) << 6;
16557 }
16558 break;
16559
16560 default: ;
16561 }
16562
16563 inst.instruction |= do_align << 4;
16564 }
16565
16566 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
16567 apart from bits [11:4]. */
16568
16569 static void
16570 do_neon_ldx_stx (void)
16571 {
16572 if (inst.operands[1].isreg)
16573 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
16574
16575 switch (NEON_LANE (inst.operands[0].imm))
16576 {
16577 case NEON_INTERLEAVE_LANES:
16578 NEON_ENCODE (INTERLV, inst);
16579 do_neon_ld_st_interleave ();
16580 break;
16581
16582 case NEON_ALL_LANES:
16583 NEON_ENCODE (DUP, inst);
16584 if (inst.instruction == N_INV)
16585 {
16586 first_error ("only loads support such operands");
16587 break;
16588 }
16589 do_neon_ld_dup ();
16590 break;
16591
16592 default:
16593 NEON_ENCODE (LANE, inst);
16594 do_neon_ld_st_lane ();
16595 }
16596
16597 /* L bit comes from bit mask. */
16598 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16599 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16600 inst.instruction |= inst.operands[1].reg << 16;
16601
16602 if (inst.operands[1].postind)
16603 {
16604 int postreg = inst.operands[1].imm & 0xf;
16605 constraint (!inst.operands[1].immisreg,
16606 _("post-index must be a register"));
16607 constraint (postreg == 0xd || postreg == 0xf,
16608 _("bad register for post-index"));
16609 inst.instruction |= postreg;
16610 }
16611 else
16612 {
16613 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
16614 constraint (inst.reloc.exp.X_op != O_constant
16615 || inst.reloc.exp.X_add_number != 0,
16616 BAD_ADDR_MODE);
16617
16618 if (inst.operands[1].writeback)
16619 {
16620 inst.instruction |= 0xd;
16621 }
16622 else
16623 inst.instruction |= 0xf;
16624 }
16625
16626 if (thumb_mode)
16627 inst.instruction |= 0xf9000000;
16628 else
16629 inst.instruction |= 0xf4000000;
16630 }
16631
16632 /* FP v8. */
16633 static void
16634 do_vfp_nsyn_fpv8 (enum neon_shape rs)
16635 {
16636 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
16637 D register operands. */
16638 if (neon_shape_class[rs] == SC_DOUBLE)
16639 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16640 _(BAD_FPU));
16641
16642 NEON_ENCODE (FPV8, inst);
16643
16644 if (rs == NS_FFF)
16645 do_vfp_sp_dyadic ();
16646 else
16647 do_vfp_dp_rd_rn_rm ();
16648
16649 if (rs == NS_DDD)
16650 inst.instruction |= 0x100;
16651
16652 inst.instruction |= 0xf0000000;
16653 }
16654
16655 static void
16656 do_vsel (void)
16657 {
16658 set_it_insn_type (OUTSIDE_IT_INSN);
16659
16660 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
16661 first_error (_("invalid instruction shape"));
16662 }
16663
16664 static void
16665 do_vmaxnm (void)
16666 {
16667 set_it_insn_type (OUTSIDE_IT_INSN);
16668
16669 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
16670 return;
16671
16672 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
16673 return;
16674
16675 neon_dyadic_misc (NT_untyped, N_F32, 0);
16676 }
16677
16678 static void
16679 do_vrint_1 (enum neon_cvt_mode mode)
16680 {
16681 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_QQ, NS_NULL);
16682 struct neon_type_el et;
16683
16684 if (rs == NS_NULL)
16685 return;
16686
16687 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
16688 D register operands. */
16689 if (neon_shape_class[rs] == SC_DOUBLE)
16690 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16691 _(BAD_FPU));
16692
16693 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
16694 if (et.type != NT_invtype)
16695 {
16696 /* VFP encodings. */
16697 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
16698 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
16699 set_it_insn_type (OUTSIDE_IT_INSN);
16700
16701 NEON_ENCODE (FPV8, inst);
16702 if (rs == NS_FF)
16703 do_vfp_sp_monadic ();
16704 else
16705 do_vfp_dp_rd_rm ();
16706
16707 switch (mode)
16708 {
16709 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
16710 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
16711 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
16712 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
16713 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
16714 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
16715 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
16716 default: abort ();
16717 }
16718
16719 inst.instruction |= (rs == NS_DD) << 8;
16720 do_vfp_cond_or_thumb ();
16721 }
16722 else
16723 {
16724 /* Neon encodings (or something broken...). */
16725 inst.error = NULL;
16726 et = neon_check_type (2, rs, N_EQK, N_F32 | N_KEY);
16727
16728 if (et.type == NT_invtype)
16729 return;
16730
16731 set_it_insn_type (OUTSIDE_IT_INSN);
16732 NEON_ENCODE (FLOAT, inst);
16733
16734 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
16735 return;
16736
16737 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16738 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16739 inst.instruction |= LOW4 (inst.operands[1].reg);
16740 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16741 inst.instruction |= neon_quad (rs) << 6;
16742 switch (mode)
16743 {
16744 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
16745 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
16746 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
16747 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
16748 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
16749 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
16750 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
16751 default: abort ();
16752 }
16753
16754 if (thumb_mode)
16755 inst.instruction |= 0xfc000000;
16756 else
16757 inst.instruction |= 0xf0000000;
16758 }
16759 }
16760
16761 static void
16762 do_vrintx (void)
16763 {
16764 do_vrint_1 (neon_cvt_mode_x);
16765 }
16766
16767 static void
16768 do_vrintz (void)
16769 {
16770 do_vrint_1 (neon_cvt_mode_z);
16771 }
16772
16773 static void
16774 do_vrintr (void)
16775 {
16776 do_vrint_1 (neon_cvt_mode_r);
16777 }
16778
16779 static void
16780 do_vrinta (void)
16781 {
16782 do_vrint_1 (neon_cvt_mode_a);
16783 }
16784
16785 static void
16786 do_vrintn (void)
16787 {
16788 do_vrint_1 (neon_cvt_mode_n);
16789 }
16790
16791 static void
16792 do_vrintp (void)
16793 {
16794 do_vrint_1 (neon_cvt_mode_p);
16795 }
16796
16797 static void
16798 do_vrintm (void)
16799 {
16800 do_vrint_1 (neon_cvt_mode_m);
16801 }
16802
16803 /* Crypto v1 instructions. */
16804 static void
16805 do_crypto_2op_1 (unsigned elttype, int op)
16806 {
16807 set_it_insn_type (OUTSIDE_IT_INSN);
16808
16809 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
16810 == NT_invtype)
16811 return;
16812
16813 inst.error = NULL;
16814
16815 NEON_ENCODE (INTEGER, inst);
16816 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16817 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16818 inst.instruction |= LOW4 (inst.operands[1].reg);
16819 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16820 if (op != -1)
16821 inst.instruction |= op << 6;
16822
16823 if (thumb_mode)
16824 inst.instruction |= 0xfc000000;
16825 else
16826 inst.instruction |= 0xf0000000;
16827 }
16828
16829 static void
16830 do_crypto_3op_1 (int u, int op)
16831 {
16832 set_it_insn_type (OUTSIDE_IT_INSN);
16833
16834 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
16835 N_32 | N_UNT | N_KEY).type == NT_invtype)
16836 return;
16837
16838 inst.error = NULL;
16839
16840 NEON_ENCODE (INTEGER, inst);
16841 neon_three_same (1, u, 8 << op);
16842 }
16843
16844 static void
16845 do_aese (void)
16846 {
16847 do_crypto_2op_1 (N_8, 0);
16848 }
16849
16850 static void
16851 do_aesd (void)
16852 {
16853 do_crypto_2op_1 (N_8, 1);
16854 }
16855
16856 static void
16857 do_aesmc (void)
16858 {
16859 do_crypto_2op_1 (N_8, 2);
16860 }
16861
16862 static void
16863 do_aesimc (void)
16864 {
16865 do_crypto_2op_1 (N_8, 3);
16866 }
16867
16868 static void
16869 do_sha1c (void)
16870 {
16871 do_crypto_3op_1 (0, 0);
16872 }
16873
16874 static void
16875 do_sha1p (void)
16876 {
16877 do_crypto_3op_1 (0, 1);
16878 }
16879
16880 static void
16881 do_sha1m (void)
16882 {
16883 do_crypto_3op_1 (0, 2);
16884 }
16885
16886 static void
16887 do_sha1su0 (void)
16888 {
16889 do_crypto_3op_1 (0, 3);
16890 }
16891
16892 static void
16893 do_sha256h (void)
16894 {
16895 do_crypto_3op_1 (1, 0);
16896 }
16897
16898 static void
16899 do_sha256h2 (void)
16900 {
16901 do_crypto_3op_1 (1, 1);
16902 }
16903
16904 static void
16905 do_sha256su1 (void)
16906 {
16907 do_crypto_3op_1 (1, 2);
16908 }
16909
16910 static void
16911 do_sha1h (void)
16912 {
16913 do_crypto_2op_1 (N_32, -1);
16914 }
16915
16916 static void
16917 do_sha1su1 (void)
16918 {
16919 do_crypto_2op_1 (N_32, 0);
16920 }
16921
16922 static void
16923 do_sha256su0 (void)
16924 {
16925 do_crypto_2op_1 (N_32, 1);
16926 }
16927
16928 static void
16929 do_crc32_1 (unsigned int poly, unsigned int sz)
16930 {
16931 unsigned int Rd = inst.operands[0].reg;
16932 unsigned int Rn = inst.operands[1].reg;
16933 unsigned int Rm = inst.operands[2].reg;
16934
16935 set_it_insn_type (OUTSIDE_IT_INSN);
16936 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
16937 inst.instruction |= LOW4 (Rn) << 16;
16938 inst.instruction |= LOW4 (Rm);
16939 inst.instruction |= sz << (thumb_mode ? 4 : 21);
16940 inst.instruction |= poly << (thumb_mode ? 20 : 9);
16941
16942 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
16943 as_warn (UNPRED_REG ("r15"));
16944 if (thumb_mode && (Rd == REG_SP || Rn == REG_SP || Rm == REG_SP))
16945 as_warn (UNPRED_REG ("r13"));
16946 }
16947
16948 static void
16949 do_crc32b (void)
16950 {
16951 do_crc32_1 (0, 0);
16952 }
16953
16954 static void
16955 do_crc32h (void)
16956 {
16957 do_crc32_1 (0, 1);
16958 }
16959
16960 static void
16961 do_crc32w (void)
16962 {
16963 do_crc32_1 (0, 2);
16964 }
16965
16966 static void
16967 do_crc32cb (void)
16968 {
16969 do_crc32_1 (1, 0);
16970 }
16971
16972 static void
16973 do_crc32ch (void)
16974 {
16975 do_crc32_1 (1, 1);
16976 }
16977
16978 static void
16979 do_crc32cw (void)
16980 {
16981 do_crc32_1 (1, 2);
16982 }
16983
16984 \f
16985 /* Overall per-instruction processing. */
16986
16987 /* We need to be able to fix up arbitrary expressions in some statements.
16988 This is so that we can handle symbols that are an arbitrary distance from
16989 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
16990 which returns part of an address in a form which will be valid for
16991 a data instruction. We do this by pushing the expression into a symbol
16992 in the expr_section, and creating a fix for that. */
16993
16994 static void
16995 fix_new_arm (fragS * frag,
16996 int where,
16997 short int size,
16998 expressionS * exp,
16999 int pc_rel,
17000 int reloc)
17001 {
17002 fixS * new_fix;
17003
17004 switch (exp->X_op)
17005 {
17006 case O_constant:
17007 if (pc_rel)
17008 {
17009 /* Create an absolute valued symbol, so we have something to
17010 refer to in the object file. Unfortunately for us, gas's
17011 generic expression parsing will already have folded out
17012 any use of .set foo/.type foo %function that may have
17013 been used to set type information of the target location,
17014 that's being specified symbolically. We have to presume
17015 the user knows what they are doing. */
17016 char name[16 + 8];
17017 symbolS *symbol;
17018
17019 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
17020
17021 symbol = symbol_find_or_make (name);
17022 S_SET_SEGMENT (symbol, absolute_section);
17023 symbol_set_frag (symbol, &zero_address_frag);
17024 S_SET_VALUE (symbol, exp->X_add_number);
17025 exp->X_op = O_symbol;
17026 exp->X_add_symbol = symbol;
17027 exp->X_add_number = 0;
17028 }
17029 /* FALLTHROUGH */
17030 case O_symbol:
17031 case O_add:
17032 case O_subtract:
17033 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
17034 (enum bfd_reloc_code_real) reloc);
17035 break;
17036
17037 default:
17038 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
17039 pc_rel, (enum bfd_reloc_code_real) reloc);
17040 break;
17041 }
17042
17043 /* Mark whether the fix is to a THUMB instruction, or an ARM
17044 instruction. */
17045 new_fix->tc_fix_data = thumb_mode;
17046 }
17047
17048 /* Create a frg for an instruction requiring relaxation. */
17049 static void
17050 output_relax_insn (void)
17051 {
17052 char * to;
17053 symbolS *sym;
17054 int offset;
17055
17056 /* The size of the instruction is unknown, so tie the debug info to the
17057 start of the instruction. */
17058 dwarf2_emit_insn (0);
17059
17060 switch (inst.reloc.exp.X_op)
17061 {
17062 case O_symbol:
17063 sym = inst.reloc.exp.X_add_symbol;
17064 offset = inst.reloc.exp.X_add_number;
17065 break;
17066 case O_constant:
17067 sym = NULL;
17068 offset = inst.reloc.exp.X_add_number;
17069 break;
17070 default:
17071 sym = make_expr_symbol (&inst.reloc.exp);
17072 offset = 0;
17073 break;
17074 }
17075 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
17076 inst.relax, sym, offset, NULL/*offset, opcode*/);
17077 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
17078 }
17079
17080 /* Write a 32-bit thumb instruction to buf. */
17081 static void
17082 put_thumb32_insn (char * buf, unsigned long insn)
17083 {
17084 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
17085 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
17086 }
17087
17088 static void
17089 output_inst (const char * str)
17090 {
17091 char * to = NULL;
17092
17093 if (inst.error)
17094 {
17095 as_bad ("%s -- `%s'", inst.error, str);
17096 return;
17097 }
17098 if (inst.relax)
17099 {
17100 output_relax_insn ();
17101 return;
17102 }
17103 if (inst.size == 0)
17104 return;
17105
17106 to = frag_more (inst.size);
17107 /* PR 9814: Record the thumb mode into the current frag so that we know
17108 what type of NOP padding to use, if necessary. We override any previous
17109 setting so that if the mode has changed then the NOPS that we use will
17110 match the encoding of the last instruction in the frag. */
17111 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
17112
17113 if (thumb_mode && (inst.size > THUMB_SIZE))
17114 {
17115 gas_assert (inst.size == (2 * THUMB_SIZE));
17116 put_thumb32_insn (to, inst.instruction);
17117 }
17118 else if (inst.size > INSN_SIZE)
17119 {
17120 gas_assert (inst.size == (2 * INSN_SIZE));
17121 md_number_to_chars (to, inst.instruction, INSN_SIZE);
17122 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
17123 }
17124 else
17125 md_number_to_chars (to, inst.instruction, inst.size);
17126
17127 if (inst.reloc.type != BFD_RELOC_UNUSED)
17128 fix_new_arm (frag_now, to - frag_now->fr_literal,
17129 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
17130 inst.reloc.type);
17131
17132 dwarf2_emit_insn (inst.size);
17133 }
17134
17135 static char *
17136 output_it_inst (int cond, int mask, char * to)
17137 {
17138 unsigned long instruction = 0xbf00;
17139
17140 mask &= 0xf;
17141 instruction |= mask;
17142 instruction |= cond << 4;
17143
17144 if (to == NULL)
17145 {
17146 to = frag_more (2);
17147 #ifdef OBJ_ELF
17148 dwarf2_emit_insn (2);
17149 #endif
17150 }
17151
17152 md_number_to_chars (to, instruction, 2);
17153
17154 return to;
17155 }
17156
17157 /* Tag values used in struct asm_opcode's tag field. */
17158 enum opcode_tag
17159 {
17160 OT_unconditional, /* Instruction cannot be conditionalized.
17161 The ARM condition field is still 0xE. */
17162 OT_unconditionalF, /* Instruction cannot be conditionalized
17163 and carries 0xF in its ARM condition field. */
17164 OT_csuffix, /* Instruction takes a conditional suffix. */
17165 OT_csuffixF, /* Some forms of the instruction take a conditional
17166 suffix, others place 0xF where the condition field
17167 would be. */
17168 OT_cinfix3, /* Instruction takes a conditional infix,
17169 beginning at character index 3. (In
17170 unified mode, it becomes a suffix.) */
17171 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
17172 tsts, cmps, cmns, and teqs. */
17173 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
17174 character index 3, even in unified mode. Used for
17175 legacy instructions where suffix and infix forms
17176 may be ambiguous. */
17177 OT_csuf_or_in3, /* Instruction takes either a conditional
17178 suffix or an infix at character index 3. */
17179 OT_odd_infix_unc, /* This is the unconditional variant of an
17180 instruction that takes a conditional infix
17181 at an unusual position. In unified mode,
17182 this variant will accept a suffix. */
17183 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
17184 are the conditional variants of instructions that
17185 take conditional infixes in unusual positions.
17186 The infix appears at character index
17187 (tag - OT_odd_infix_0). These are not accepted
17188 in unified mode. */
17189 };
17190
17191 /* Subroutine of md_assemble, responsible for looking up the primary
17192 opcode from the mnemonic the user wrote. STR points to the
17193 beginning of the mnemonic.
17194
17195 This is not simply a hash table lookup, because of conditional
17196 variants. Most instructions have conditional variants, which are
17197 expressed with a _conditional affix_ to the mnemonic. If we were
17198 to encode each conditional variant as a literal string in the opcode
17199 table, it would have approximately 20,000 entries.
17200
17201 Most mnemonics take this affix as a suffix, and in unified syntax,
17202 'most' is upgraded to 'all'. However, in the divided syntax, some
17203 instructions take the affix as an infix, notably the s-variants of
17204 the arithmetic instructions. Of those instructions, all but six
17205 have the infix appear after the third character of the mnemonic.
17206
17207 Accordingly, the algorithm for looking up primary opcodes given
17208 an identifier is:
17209
17210 1. Look up the identifier in the opcode table.
17211 If we find a match, go to step U.
17212
17213 2. Look up the last two characters of the identifier in the
17214 conditions table. If we find a match, look up the first N-2
17215 characters of the identifier in the opcode table. If we
17216 find a match, go to step CE.
17217
17218 3. Look up the fourth and fifth characters of the identifier in
17219 the conditions table. If we find a match, extract those
17220 characters from the identifier, and look up the remaining
17221 characters in the opcode table. If we find a match, go
17222 to step CM.
17223
17224 4. Fail.
17225
17226 U. Examine the tag field of the opcode structure, in case this is
17227 one of the six instructions with its conditional infix in an
17228 unusual place. If it is, the tag tells us where to find the
17229 infix; look it up in the conditions table and set inst.cond
17230 accordingly. Otherwise, this is an unconditional instruction.
17231 Again set inst.cond accordingly. Return the opcode structure.
17232
17233 CE. Examine the tag field to make sure this is an instruction that
17234 should receive a conditional suffix. If it is not, fail.
17235 Otherwise, set inst.cond from the suffix we already looked up,
17236 and return the opcode structure.
17237
17238 CM. Examine the tag field to make sure this is an instruction that
17239 should receive a conditional infix after the third character.
17240 If it is not, fail. Otherwise, undo the edits to the current
17241 line of input and proceed as for case CE. */
17242
17243 static const struct asm_opcode *
17244 opcode_lookup (char **str)
17245 {
17246 char *end, *base;
17247 char *affix;
17248 const struct asm_opcode *opcode;
17249 const struct asm_cond *cond;
17250 char save[2];
17251
17252 /* Scan up to the end of the mnemonic, which must end in white space,
17253 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
17254 for (base = end = *str; *end != '\0'; end++)
17255 if (*end == ' ' || *end == '.')
17256 break;
17257
17258 if (end == base)
17259 return NULL;
17260
17261 /* Handle a possible width suffix and/or Neon type suffix. */
17262 if (end[0] == '.')
17263 {
17264 int offset = 2;
17265
17266 /* The .w and .n suffixes are only valid if the unified syntax is in
17267 use. */
17268 if (unified_syntax && end[1] == 'w')
17269 inst.size_req = 4;
17270 else if (unified_syntax && end[1] == 'n')
17271 inst.size_req = 2;
17272 else
17273 offset = 0;
17274
17275 inst.vectype.elems = 0;
17276
17277 *str = end + offset;
17278
17279 if (end[offset] == '.')
17280 {
17281 /* See if we have a Neon type suffix (possible in either unified or
17282 non-unified ARM syntax mode). */
17283 if (parse_neon_type (&inst.vectype, str) == FAIL)
17284 return NULL;
17285 }
17286 else if (end[offset] != '\0' && end[offset] != ' ')
17287 return NULL;
17288 }
17289 else
17290 *str = end;
17291
17292 /* Look for unaffixed or special-case affixed mnemonic. */
17293 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
17294 end - base);
17295 if (opcode)
17296 {
17297 /* step U */
17298 if (opcode->tag < OT_odd_infix_0)
17299 {
17300 inst.cond = COND_ALWAYS;
17301 return opcode;
17302 }
17303
17304 if (warn_on_deprecated && unified_syntax)
17305 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
17306 affix = base + (opcode->tag - OT_odd_infix_0);
17307 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
17308 gas_assert (cond);
17309
17310 inst.cond = cond->value;
17311 return opcode;
17312 }
17313
17314 /* Cannot have a conditional suffix on a mnemonic of less than two
17315 characters. */
17316 if (end - base < 3)
17317 return NULL;
17318
17319 /* Look for suffixed mnemonic. */
17320 affix = end - 2;
17321 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
17322 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
17323 affix - base);
17324 if (opcode && cond)
17325 {
17326 /* step CE */
17327 switch (opcode->tag)
17328 {
17329 case OT_cinfix3_legacy:
17330 /* Ignore conditional suffixes matched on infix only mnemonics. */
17331 break;
17332
17333 case OT_cinfix3:
17334 case OT_cinfix3_deprecated:
17335 case OT_odd_infix_unc:
17336 if (!unified_syntax)
17337 return 0;
17338 /* else fall through */
17339
17340 case OT_csuffix:
17341 case OT_csuffixF:
17342 case OT_csuf_or_in3:
17343 inst.cond = cond->value;
17344 return opcode;
17345
17346 case OT_unconditional:
17347 case OT_unconditionalF:
17348 if (thumb_mode)
17349 inst.cond = cond->value;
17350 else
17351 {
17352 /* Delayed diagnostic. */
17353 inst.error = BAD_COND;
17354 inst.cond = COND_ALWAYS;
17355 }
17356 return opcode;
17357
17358 default:
17359 return NULL;
17360 }
17361 }
17362
17363 /* Cannot have a usual-position infix on a mnemonic of less than
17364 six characters (five would be a suffix). */
17365 if (end - base < 6)
17366 return NULL;
17367
17368 /* Look for infixed mnemonic in the usual position. */
17369 affix = base + 3;
17370 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
17371 if (!cond)
17372 return NULL;
17373
17374 memcpy (save, affix, 2);
17375 memmove (affix, affix + 2, (end - affix) - 2);
17376 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
17377 (end - base) - 2);
17378 memmove (affix + 2, affix, (end - affix) - 2);
17379 memcpy (affix, save, 2);
17380
17381 if (opcode
17382 && (opcode->tag == OT_cinfix3
17383 || opcode->tag == OT_cinfix3_deprecated
17384 || opcode->tag == OT_csuf_or_in3
17385 || opcode->tag == OT_cinfix3_legacy))
17386 {
17387 /* Step CM. */
17388 if (warn_on_deprecated && unified_syntax
17389 && (opcode->tag == OT_cinfix3
17390 || opcode->tag == OT_cinfix3_deprecated))
17391 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
17392
17393 inst.cond = cond->value;
17394 return opcode;
17395 }
17396
17397 return NULL;
17398 }
17399
17400 /* This function generates an initial IT instruction, leaving its block
17401 virtually open for the new instructions. Eventually,
17402 the mask will be updated by now_it_add_mask () each time
17403 a new instruction needs to be included in the IT block.
17404 Finally, the block is closed with close_automatic_it_block ().
17405 The block closure can be requested either from md_assemble (),
17406 a tencode (), or due to a label hook. */
17407
17408 static void
17409 new_automatic_it_block (int cond)
17410 {
17411 now_it.state = AUTOMATIC_IT_BLOCK;
17412 now_it.mask = 0x18;
17413 now_it.cc = cond;
17414 now_it.block_length = 1;
17415 mapping_state (MAP_THUMB);
17416 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
17417 now_it.warn_deprecated = FALSE;
17418 now_it.insn_cond = TRUE;
17419 }
17420
17421 /* Close an automatic IT block.
17422 See comments in new_automatic_it_block (). */
17423
17424 static void
17425 close_automatic_it_block (void)
17426 {
17427 now_it.mask = 0x10;
17428 now_it.block_length = 0;
17429 }
17430
17431 /* Update the mask of the current automatically-generated IT
17432 instruction. See comments in new_automatic_it_block (). */
17433
17434 static void
17435 now_it_add_mask (int cond)
17436 {
17437 #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
17438 #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
17439 | ((bitvalue) << (nbit)))
17440 const int resulting_bit = (cond & 1);
17441
17442 now_it.mask &= 0xf;
17443 now_it.mask = SET_BIT_VALUE (now_it.mask,
17444 resulting_bit,
17445 (5 - now_it.block_length));
17446 now_it.mask = SET_BIT_VALUE (now_it.mask,
17447 1,
17448 ((5 - now_it.block_length) - 1) );
17449 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
17450
17451 #undef CLEAR_BIT
17452 #undef SET_BIT_VALUE
17453 }
17454
17455 /* The IT blocks handling machinery is accessed through the these functions:
17456 it_fsm_pre_encode () from md_assemble ()
17457 set_it_insn_type () optional, from the tencode functions
17458 set_it_insn_type_last () ditto
17459 in_it_block () ditto
17460 it_fsm_post_encode () from md_assemble ()
17461 force_automatic_it_block_close () from label habdling functions
17462
17463 Rationale:
17464 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
17465 initializing the IT insn type with a generic initial value depending
17466 on the inst.condition.
17467 2) During the tencode function, two things may happen:
17468 a) The tencode function overrides the IT insn type by
17469 calling either set_it_insn_type (type) or set_it_insn_type_last ().
17470 b) The tencode function queries the IT block state by
17471 calling in_it_block () (i.e. to determine narrow/not narrow mode).
17472
17473 Both set_it_insn_type and in_it_block run the internal FSM state
17474 handling function (handle_it_state), because: a) setting the IT insn
17475 type may incur in an invalid state (exiting the function),
17476 and b) querying the state requires the FSM to be updated.
17477 Specifically we want to avoid creating an IT block for conditional
17478 branches, so it_fsm_pre_encode is actually a guess and we can't
17479 determine whether an IT block is required until the tencode () routine
17480 has decided what type of instruction this actually it.
17481 Because of this, if set_it_insn_type and in_it_block have to be used,
17482 set_it_insn_type has to be called first.
17483
17484 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
17485 determines the insn IT type depending on the inst.cond code.
17486 When a tencode () routine encodes an instruction that can be
17487 either outside an IT block, or, in the case of being inside, has to be
17488 the last one, set_it_insn_type_last () will determine the proper
17489 IT instruction type based on the inst.cond code. Otherwise,
17490 set_it_insn_type can be called for overriding that logic or
17491 for covering other cases.
17492
17493 Calling handle_it_state () may not transition the IT block state to
17494 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
17495 still queried. Instead, if the FSM determines that the state should
17496 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
17497 after the tencode () function: that's what it_fsm_post_encode () does.
17498
17499 Since in_it_block () calls the state handling function to get an
17500 updated state, an error may occur (due to invalid insns combination).
17501 In that case, inst.error is set.
17502 Therefore, inst.error has to be checked after the execution of
17503 the tencode () routine.
17504
17505 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
17506 any pending state change (if any) that didn't take place in
17507 handle_it_state () as explained above. */
17508
17509 static void
17510 it_fsm_pre_encode (void)
17511 {
17512 if (inst.cond != COND_ALWAYS)
17513 inst.it_insn_type = INSIDE_IT_INSN;
17514 else
17515 inst.it_insn_type = OUTSIDE_IT_INSN;
17516
17517 now_it.state_handled = 0;
17518 }
17519
17520 /* IT state FSM handling function. */
17521
17522 static int
17523 handle_it_state (void)
17524 {
17525 now_it.state_handled = 1;
17526 now_it.insn_cond = FALSE;
17527
17528 switch (now_it.state)
17529 {
17530 case OUTSIDE_IT_BLOCK:
17531 switch (inst.it_insn_type)
17532 {
17533 case OUTSIDE_IT_INSN:
17534 break;
17535
17536 case INSIDE_IT_INSN:
17537 case INSIDE_IT_LAST_INSN:
17538 if (thumb_mode == 0)
17539 {
17540 if (unified_syntax
17541 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
17542 as_tsktsk (_("Warning: conditional outside an IT block"\
17543 " for Thumb."));
17544 }
17545 else
17546 {
17547 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
17548 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
17549 {
17550 /* Automatically generate the IT instruction. */
17551 new_automatic_it_block (inst.cond);
17552 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
17553 close_automatic_it_block ();
17554 }
17555 else
17556 {
17557 inst.error = BAD_OUT_IT;
17558 return FAIL;
17559 }
17560 }
17561 break;
17562
17563 case IF_INSIDE_IT_LAST_INSN:
17564 case NEUTRAL_IT_INSN:
17565 break;
17566
17567 case IT_INSN:
17568 now_it.state = MANUAL_IT_BLOCK;
17569 now_it.block_length = 0;
17570 break;
17571 }
17572 break;
17573
17574 case AUTOMATIC_IT_BLOCK:
17575 /* Three things may happen now:
17576 a) We should increment current it block size;
17577 b) We should close current it block (closing insn or 4 insns);
17578 c) We should close current it block and start a new one (due
17579 to incompatible conditions or
17580 4 insns-length block reached). */
17581
17582 switch (inst.it_insn_type)
17583 {
17584 case OUTSIDE_IT_INSN:
17585 /* The closure of the block shall happen immediatelly,
17586 so any in_it_block () call reports the block as closed. */
17587 force_automatic_it_block_close ();
17588 break;
17589
17590 case INSIDE_IT_INSN:
17591 case INSIDE_IT_LAST_INSN:
17592 case IF_INSIDE_IT_LAST_INSN:
17593 now_it.block_length++;
17594
17595 if (now_it.block_length > 4
17596 || !now_it_compatible (inst.cond))
17597 {
17598 force_automatic_it_block_close ();
17599 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
17600 new_automatic_it_block (inst.cond);
17601 }
17602 else
17603 {
17604 now_it.insn_cond = TRUE;
17605 now_it_add_mask (inst.cond);
17606 }
17607
17608 if (now_it.state == AUTOMATIC_IT_BLOCK
17609 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
17610 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
17611 close_automatic_it_block ();
17612 break;
17613
17614 case NEUTRAL_IT_INSN:
17615 now_it.block_length++;
17616 now_it.insn_cond = TRUE;
17617
17618 if (now_it.block_length > 4)
17619 force_automatic_it_block_close ();
17620 else
17621 now_it_add_mask (now_it.cc & 1);
17622 break;
17623
17624 case IT_INSN:
17625 close_automatic_it_block ();
17626 now_it.state = MANUAL_IT_BLOCK;
17627 break;
17628 }
17629 break;
17630
17631 case MANUAL_IT_BLOCK:
17632 {
17633 /* Check conditional suffixes. */
17634 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
17635 int is_last;
17636 now_it.mask <<= 1;
17637 now_it.mask &= 0x1f;
17638 is_last = (now_it.mask == 0x10);
17639 now_it.insn_cond = TRUE;
17640
17641 switch (inst.it_insn_type)
17642 {
17643 case OUTSIDE_IT_INSN:
17644 inst.error = BAD_NOT_IT;
17645 return FAIL;
17646
17647 case INSIDE_IT_INSN:
17648 if (cond != inst.cond)
17649 {
17650 inst.error = BAD_IT_COND;
17651 return FAIL;
17652 }
17653 break;
17654
17655 case INSIDE_IT_LAST_INSN:
17656 case IF_INSIDE_IT_LAST_INSN:
17657 if (cond != inst.cond)
17658 {
17659 inst.error = BAD_IT_COND;
17660 return FAIL;
17661 }
17662 if (!is_last)
17663 {
17664 inst.error = BAD_BRANCH;
17665 return FAIL;
17666 }
17667 break;
17668
17669 case NEUTRAL_IT_INSN:
17670 /* The BKPT instruction is unconditional even in an IT block. */
17671 break;
17672
17673 case IT_INSN:
17674 inst.error = BAD_IT_IT;
17675 return FAIL;
17676 }
17677 }
17678 break;
17679 }
17680
17681 return SUCCESS;
17682 }
17683
17684 struct depr_insn_mask
17685 {
17686 unsigned long pattern;
17687 unsigned long mask;
17688 const char* description;
17689 };
17690
17691 /* List of 16-bit instruction patterns deprecated in an IT block in
17692 ARMv8. */
17693 static const struct depr_insn_mask depr_it_insns[] = {
17694 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
17695 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
17696 { 0xa000, 0xb800, N_("ADR") },
17697 { 0x4800, 0xf800, N_("Literal loads") },
17698 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
17699 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
17700 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
17701 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
17702 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
17703 { 0, 0, NULL }
17704 };
17705
17706 static void
17707 it_fsm_post_encode (void)
17708 {
17709 int is_last;
17710
17711 if (!now_it.state_handled)
17712 handle_it_state ();
17713
17714 if (now_it.insn_cond
17715 && !now_it.warn_deprecated
17716 && warn_on_deprecated
17717 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
17718 {
17719 if (inst.instruction >= 0x10000)
17720 {
17721 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
17722 "deprecated in ARMv8"));
17723 now_it.warn_deprecated = TRUE;
17724 }
17725 else
17726 {
17727 const struct depr_insn_mask *p = depr_it_insns;
17728
17729 while (p->mask != 0)
17730 {
17731 if ((inst.instruction & p->mask) == p->pattern)
17732 {
17733 as_tsktsk (_("IT blocks containing 16-bit Thumb instructions "
17734 "of the following class are deprecated in ARMv8: "
17735 "%s"), p->description);
17736 now_it.warn_deprecated = TRUE;
17737 break;
17738 }
17739
17740 ++p;
17741 }
17742 }
17743
17744 if (now_it.block_length > 1)
17745 {
17746 as_tsktsk (_("IT blocks containing more than one conditional "
17747 "instruction are deprecated in ARMv8"));
17748 now_it.warn_deprecated = TRUE;
17749 }
17750 }
17751
17752 is_last = (now_it.mask == 0x10);
17753 if (is_last)
17754 {
17755 now_it.state = OUTSIDE_IT_BLOCK;
17756 now_it.mask = 0;
17757 }
17758 }
17759
17760 static void
17761 force_automatic_it_block_close (void)
17762 {
17763 if (now_it.state == AUTOMATIC_IT_BLOCK)
17764 {
17765 close_automatic_it_block ();
17766 now_it.state = OUTSIDE_IT_BLOCK;
17767 now_it.mask = 0;
17768 }
17769 }
17770
17771 static int
17772 in_it_block (void)
17773 {
17774 if (!now_it.state_handled)
17775 handle_it_state ();
17776
17777 return now_it.state != OUTSIDE_IT_BLOCK;
17778 }
17779
17780 void
17781 md_assemble (char *str)
17782 {
17783 char *p = str;
17784 const struct asm_opcode * opcode;
17785
17786 /* Align the previous label if needed. */
17787 if (last_label_seen != NULL)
17788 {
17789 symbol_set_frag (last_label_seen, frag_now);
17790 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
17791 S_SET_SEGMENT (last_label_seen, now_seg);
17792 }
17793
17794 memset (&inst, '\0', sizeof (inst));
17795 inst.reloc.type = BFD_RELOC_UNUSED;
17796
17797 opcode = opcode_lookup (&p);
17798 if (!opcode)
17799 {
17800 /* It wasn't an instruction, but it might be a register alias of
17801 the form alias .req reg, or a Neon .dn/.qn directive. */
17802 if (! create_register_alias (str, p)
17803 && ! create_neon_reg_alias (str, p))
17804 as_bad (_("bad instruction `%s'"), str);
17805
17806 return;
17807 }
17808
17809 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
17810 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
17811
17812 /* The value which unconditional instructions should have in place of the
17813 condition field. */
17814 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
17815
17816 if (thumb_mode)
17817 {
17818 arm_feature_set variant;
17819
17820 variant = cpu_variant;
17821 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
17822 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
17823 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
17824 /* Check that this instruction is supported for this CPU. */
17825 if (!opcode->tvariant
17826 || (thumb_mode == 1
17827 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
17828 {
17829 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
17830 return;
17831 }
17832 if (inst.cond != COND_ALWAYS && !unified_syntax
17833 && opcode->tencode != do_t_branch)
17834 {
17835 as_bad (_("Thumb does not support conditional execution"));
17836 return;
17837 }
17838
17839 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
17840 {
17841 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
17842 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
17843 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
17844 {
17845 /* Two things are addressed here.
17846 1) Implicit require narrow instructions on Thumb-1.
17847 This avoids relaxation accidentally introducing Thumb-2
17848 instructions.
17849 2) Reject wide instructions in non Thumb-2 cores. */
17850 if (inst.size_req == 0)
17851 inst.size_req = 2;
17852 else if (inst.size_req == 4)
17853 {
17854 as_bad (_("selected processor does not support `%s' in Thumb-2 mode"), str);
17855 return;
17856 }
17857 }
17858 }
17859
17860 inst.instruction = opcode->tvalue;
17861
17862 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
17863 {
17864 /* Prepare the it_insn_type for those encodings that don't set
17865 it. */
17866 it_fsm_pre_encode ();
17867
17868 opcode->tencode ();
17869
17870 it_fsm_post_encode ();
17871 }
17872
17873 if (!(inst.error || inst.relax))
17874 {
17875 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
17876 inst.size = (inst.instruction > 0xffff ? 4 : 2);
17877 if (inst.size_req && inst.size_req != inst.size)
17878 {
17879 as_bad (_("cannot honor width suffix -- `%s'"), str);
17880 return;
17881 }
17882 }
17883
17884 /* Something has gone badly wrong if we try to relax a fixed size
17885 instruction. */
17886 gas_assert (inst.size_req == 0 || !inst.relax);
17887
17888 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
17889 *opcode->tvariant);
17890 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
17891 set those bits when Thumb-2 32-bit instructions are seen. ie.
17892 anything other than bl/blx and v6-M instructions.
17893 The impact of relaxable instructions will be considered later after we
17894 finish all relaxation. */
17895 if ((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
17896 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
17897 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
17898 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
17899 arm_ext_v6t2);
17900
17901 check_neon_suffixes;
17902
17903 if (!inst.error)
17904 {
17905 mapping_state (MAP_THUMB);
17906 }
17907 }
17908 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
17909 {
17910 bfd_boolean is_bx;
17911
17912 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
17913 is_bx = (opcode->aencode == do_bx);
17914
17915 /* Check that this instruction is supported for this CPU. */
17916 if (!(is_bx && fix_v4bx)
17917 && !(opcode->avariant &&
17918 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
17919 {
17920 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
17921 return;
17922 }
17923 if (inst.size_req)
17924 {
17925 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
17926 return;
17927 }
17928
17929 inst.instruction = opcode->avalue;
17930 if (opcode->tag == OT_unconditionalF)
17931 inst.instruction |= 0xFU << 28;
17932 else
17933 inst.instruction |= inst.cond << 28;
17934 inst.size = INSN_SIZE;
17935 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
17936 {
17937 it_fsm_pre_encode ();
17938 opcode->aencode ();
17939 it_fsm_post_encode ();
17940 }
17941 /* Arm mode bx is marked as both v4T and v5 because it's still required
17942 on a hypothetical non-thumb v5 core. */
17943 if (is_bx)
17944 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
17945 else
17946 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
17947 *opcode->avariant);
17948
17949 check_neon_suffixes;
17950
17951 if (!inst.error)
17952 {
17953 mapping_state (MAP_ARM);
17954 }
17955 }
17956 else
17957 {
17958 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
17959 "-- `%s'"), str);
17960 return;
17961 }
17962 output_inst (str);
17963 }
17964
17965 static void
17966 check_it_blocks_finished (void)
17967 {
17968 #ifdef OBJ_ELF
17969 asection *sect;
17970
17971 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
17972 if (seg_info (sect)->tc_segment_info_data.current_it.state
17973 == MANUAL_IT_BLOCK)
17974 {
17975 as_warn (_("section '%s' finished with an open IT block."),
17976 sect->name);
17977 }
17978 #else
17979 if (now_it.state == MANUAL_IT_BLOCK)
17980 as_warn (_("file finished with an open IT block."));
17981 #endif
17982 }
17983
17984 /* Various frobbings of labels and their addresses. */
17985
17986 void
17987 arm_start_line_hook (void)
17988 {
17989 last_label_seen = NULL;
17990 }
17991
17992 void
17993 arm_frob_label (symbolS * sym)
17994 {
17995 last_label_seen = sym;
17996
17997 ARM_SET_THUMB (sym, thumb_mode);
17998
17999 #if defined OBJ_COFF || defined OBJ_ELF
18000 ARM_SET_INTERWORK (sym, support_interwork);
18001 #endif
18002
18003 force_automatic_it_block_close ();
18004
18005 /* Note - do not allow local symbols (.Lxxx) to be labelled
18006 as Thumb functions. This is because these labels, whilst
18007 they exist inside Thumb code, are not the entry points for
18008 possible ARM->Thumb calls. Also, these labels can be used
18009 as part of a computed goto or switch statement. eg gcc
18010 can generate code that looks like this:
18011
18012 ldr r2, [pc, .Laaa]
18013 lsl r3, r3, #2
18014 ldr r2, [r3, r2]
18015 mov pc, r2
18016
18017 .Lbbb: .word .Lxxx
18018 .Lccc: .word .Lyyy
18019 ..etc...
18020 .Laaa: .word Lbbb
18021
18022 The first instruction loads the address of the jump table.
18023 The second instruction converts a table index into a byte offset.
18024 The third instruction gets the jump address out of the table.
18025 The fourth instruction performs the jump.
18026
18027 If the address stored at .Laaa is that of a symbol which has the
18028 Thumb_Func bit set, then the linker will arrange for this address
18029 to have the bottom bit set, which in turn would mean that the
18030 address computation performed by the third instruction would end
18031 up with the bottom bit set. Since the ARM is capable of unaligned
18032 word loads, the instruction would then load the incorrect address
18033 out of the jump table, and chaos would ensue. */
18034 if (label_is_thumb_function_name
18035 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
18036 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
18037 {
18038 /* When the address of a Thumb function is taken the bottom
18039 bit of that address should be set. This will allow
18040 interworking between Arm and Thumb functions to work
18041 correctly. */
18042
18043 THUMB_SET_FUNC (sym, 1);
18044
18045 label_is_thumb_function_name = FALSE;
18046 }
18047
18048 dwarf2_emit_label (sym);
18049 }
18050
18051 bfd_boolean
18052 arm_data_in_code (void)
18053 {
18054 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
18055 {
18056 *input_line_pointer = '/';
18057 input_line_pointer += 5;
18058 *input_line_pointer = 0;
18059 return TRUE;
18060 }
18061
18062 return FALSE;
18063 }
18064
18065 char *
18066 arm_canonicalize_symbol_name (char * name)
18067 {
18068 int len;
18069
18070 if (thumb_mode && (len = strlen (name)) > 5
18071 && streq (name + len - 5, "/data"))
18072 *(name + len - 5) = 0;
18073
18074 return name;
18075 }
18076 \f
18077 /* Table of all register names defined by default. The user can
18078 define additional names with .req. Note that all register names
18079 should appear in both upper and lowercase variants. Some registers
18080 also have mixed-case names. */
18081
18082 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
18083 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
18084 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
18085 #define REGSET(p,t) \
18086 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
18087 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
18088 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
18089 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
18090 #define REGSETH(p,t) \
18091 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
18092 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
18093 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
18094 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
18095 #define REGSET2(p,t) \
18096 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
18097 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
18098 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
18099 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
18100 #define SPLRBANK(base,bank,t) \
18101 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
18102 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
18103 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
18104 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
18105 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
18106 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
18107
18108 static const struct reg_entry reg_names[] =
18109 {
18110 /* ARM integer registers. */
18111 REGSET(r, RN), REGSET(R, RN),
18112
18113 /* ATPCS synonyms. */
18114 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
18115 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
18116 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
18117
18118 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
18119 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
18120 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
18121
18122 /* Well-known aliases. */
18123 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
18124 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
18125
18126 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
18127 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
18128
18129 /* Coprocessor numbers. */
18130 REGSET(p, CP), REGSET(P, CP),
18131
18132 /* Coprocessor register numbers. The "cr" variants are for backward
18133 compatibility. */
18134 REGSET(c, CN), REGSET(C, CN),
18135 REGSET(cr, CN), REGSET(CR, CN),
18136
18137 /* ARM banked registers. */
18138 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
18139 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
18140 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
18141 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
18142 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
18143 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
18144 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
18145
18146 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
18147 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
18148 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
18149 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
18150 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
18151 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
18152 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
18153 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
18154
18155 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
18156 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
18157 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
18158 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
18159 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
18160 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
18161 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
18162 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
18163 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
18164
18165 /* FPA registers. */
18166 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
18167 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
18168
18169 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
18170 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
18171
18172 /* VFP SP registers. */
18173 REGSET(s,VFS), REGSET(S,VFS),
18174 REGSETH(s,VFS), REGSETH(S,VFS),
18175
18176 /* VFP DP Registers. */
18177 REGSET(d,VFD), REGSET(D,VFD),
18178 /* Extra Neon DP registers. */
18179 REGSETH(d,VFD), REGSETH(D,VFD),
18180
18181 /* Neon QP registers. */
18182 REGSET2(q,NQ), REGSET2(Q,NQ),
18183
18184 /* VFP control registers. */
18185 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
18186 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
18187 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
18188 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
18189 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
18190 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
18191
18192 /* Maverick DSP coprocessor registers. */
18193 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
18194 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
18195
18196 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
18197 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
18198 REGDEF(dspsc,0,DSPSC),
18199
18200 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
18201 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
18202 REGDEF(DSPSC,0,DSPSC),
18203
18204 /* iWMMXt data registers - p0, c0-15. */
18205 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
18206
18207 /* iWMMXt control registers - p1, c0-3. */
18208 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
18209 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
18210 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
18211 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
18212
18213 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
18214 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
18215 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
18216 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
18217 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
18218
18219 /* XScale accumulator registers. */
18220 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
18221 };
18222 #undef REGDEF
18223 #undef REGNUM
18224 #undef REGSET
18225
18226 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
18227 within psr_required_here. */
18228 static const struct asm_psr psrs[] =
18229 {
18230 /* Backward compatibility notation. Note that "all" is no longer
18231 truly all possible PSR bits. */
18232 {"all", PSR_c | PSR_f},
18233 {"flg", PSR_f},
18234 {"ctl", PSR_c},
18235
18236 /* Individual flags. */
18237 {"f", PSR_f},
18238 {"c", PSR_c},
18239 {"x", PSR_x},
18240 {"s", PSR_s},
18241
18242 /* Combinations of flags. */
18243 {"fs", PSR_f | PSR_s},
18244 {"fx", PSR_f | PSR_x},
18245 {"fc", PSR_f | PSR_c},
18246 {"sf", PSR_s | PSR_f},
18247 {"sx", PSR_s | PSR_x},
18248 {"sc", PSR_s | PSR_c},
18249 {"xf", PSR_x | PSR_f},
18250 {"xs", PSR_x | PSR_s},
18251 {"xc", PSR_x | PSR_c},
18252 {"cf", PSR_c | PSR_f},
18253 {"cs", PSR_c | PSR_s},
18254 {"cx", PSR_c | PSR_x},
18255 {"fsx", PSR_f | PSR_s | PSR_x},
18256 {"fsc", PSR_f | PSR_s | PSR_c},
18257 {"fxs", PSR_f | PSR_x | PSR_s},
18258 {"fxc", PSR_f | PSR_x | PSR_c},
18259 {"fcs", PSR_f | PSR_c | PSR_s},
18260 {"fcx", PSR_f | PSR_c | PSR_x},
18261 {"sfx", PSR_s | PSR_f | PSR_x},
18262 {"sfc", PSR_s | PSR_f | PSR_c},
18263 {"sxf", PSR_s | PSR_x | PSR_f},
18264 {"sxc", PSR_s | PSR_x | PSR_c},
18265 {"scf", PSR_s | PSR_c | PSR_f},
18266 {"scx", PSR_s | PSR_c | PSR_x},
18267 {"xfs", PSR_x | PSR_f | PSR_s},
18268 {"xfc", PSR_x | PSR_f | PSR_c},
18269 {"xsf", PSR_x | PSR_s | PSR_f},
18270 {"xsc", PSR_x | PSR_s | PSR_c},
18271 {"xcf", PSR_x | PSR_c | PSR_f},
18272 {"xcs", PSR_x | PSR_c | PSR_s},
18273 {"cfs", PSR_c | PSR_f | PSR_s},
18274 {"cfx", PSR_c | PSR_f | PSR_x},
18275 {"csf", PSR_c | PSR_s | PSR_f},
18276 {"csx", PSR_c | PSR_s | PSR_x},
18277 {"cxf", PSR_c | PSR_x | PSR_f},
18278 {"cxs", PSR_c | PSR_x | PSR_s},
18279 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
18280 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
18281 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
18282 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
18283 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
18284 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
18285 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
18286 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
18287 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
18288 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
18289 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
18290 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
18291 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
18292 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
18293 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
18294 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
18295 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
18296 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
18297 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
18298 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
18299 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
18300 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
18301 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
18302 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
18303 };
18304
18305 /* Table of V7M psr names. */
18306 static const struct asm_psr v7m_psrs[] =
18307 {
18308 {"apsr", 0 }, {"APSR", 0 },
18309 {"iapsr", 1 }, {"IAPSR", 1 },
18310 {"eapsr", 2 }, {"EAPSR", 2 },
18311 {"psr", 3 }, {"PSR", 3 },
18312 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
18313 {"ipsr", 5 }, {"IPSR", 5 },
18314 {"epsr", 6 }, {"EPSR", 6 },
18315 {"iepsr", 7 }, {"IEPSR", 7 },
18316 {"msp", 8 }, {"MSP", 8 },
18317 {"psp", 9 }, {"PSP", 9 },
18318 {"primask", 16}, {"PRIMASK", 16},
18319 {"basepri", 17}, {"BASEPRI", 17},
18320 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
18321 {"basepri_max", 18}, {"BASEPRI_MASK", 18}, /* Typo, preserved for backwards compatibility. */
18322 {"faultmask", 19}, {"FAULTMASK", 19},
18323 {"control", 20}, {"CONTROL", 20}
18324 };
18325
18326 /* Table of all shift-in-operand names. */
18327 static const struct asm_shift_name shift_names [] =
18328 {
18329 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
18330 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
18331 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
18332 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
18333 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
18334 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
18335 };
18336
18337 /* Table of all explicit relocation names. */
18338 #ifdef OBJ_ELF
18339 static struct reloc_entry reloc_names[] =
18340 {
18341 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
18342 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
18343 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
18344 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
18345 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
18346 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
18347 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
18348 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
18349 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
18350 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
18351 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
18352 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
18353 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
18354 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
18355 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
18356 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
18357 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
18358 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
18359 };
18360 #endif
18361
18362 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
18363 static const struct asm_cond conds[] =
18364 {
18365 {"eq", 0x0},
18366 {"ne", 0x1},
18367 {"cs", 0x2}, {"hs", 0x2},
18368 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
18369 {"mi", 0x4},
18370 {"pl", 0x5},
18371 {"vs", 0x6},
18372 {"vc", 0x7},
18373 {"hi", 0x8},
18374 {"ls", 0x9},
18375 {"ge", 0xa},
18376 {"lt", 0xb},
18377 {"gt", 0xc},
18378 {"le", 0xd},
18379 {"al", 0xe}
18380 };
18381
18382 #define UL_BARRIER(L,U,CODE,FEAT) \
18383 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
18384 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
18385
18386 static struct asm_barrier_opt barrier_opt_names[] =
18387 {
18388 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
18389 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
18390 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
18391 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
18392 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
18393 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
18394 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
18395 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
18396 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
18397 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
18398 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
18399 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
18400 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
18401 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
18402 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
18403 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
18404 };
18405
18406 #undef UL_BARRIER
18407
18408 /* Table of ARM-format instructions. */
18409
18410 /* Macros for gluing together operand strings. N.B. In all cases
18411 other than OPS0, the trailing OP_stop comes from default
18412 zero-initialization of the unspecified elements of the array. */
18413 #define OPS0() { OP_stop, }
18414 #define OPS1(a) { OP_##a, }
18415 #define OPS2(a,b) { OP_##a,OP_##b, }
18416 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
18417 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
18418 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
18419 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
18420
18421 /* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
18422 This is useful when mixing operands for ARM and THUMB, i.e. using the
18423 MIX_ARM_THUMB_OPERANDS macro.
18424 In order to use these macros, prefix the number of operands with _
18425 e.g. _3. */
18426 #define OPS_1(a) { a, }
18427 #define OPS_2(a,b) { a,b, }
18428 #define OPS_3(a,b,c) { a,b,c, }
18429 #define OPS_4(a,b,c,d) { a,b,c,d, }
18430 #define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
18431 #define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
18432
18433 /* These macros abstract out the exact format of the mnemonic table and
18434 save some repeated characters. */
18435
18436 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
18437 #define TxCE(mnem, op, top, nops, ops, ae, te) \
18438 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
18439 THUMB_VARIANT, do_##ae, do_##te }
18440
18441 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
18442 a T_MNEM_xyz enumerator. */
18443 #define TCE(mnem, aop, top, nops, ops, ae, te) \
18444 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
18445 #define tCE(mnem, aop, top, nops, ops, ae, te) \
18446 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
18447
18448 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
18449 infix after the third character. */
18450 #define TxC3(mnem, op, top, nops, ops, ae, te) \
18451 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
18452 THUMB_VARIANT, do_##ae, do_##te }
18453 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
18454 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
18455 THUMB_VARIANT, do_##ae, do_##te }
18456 #define TC3(mnem, aop, top, nops, ops, ae, te) \
18457 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
18458 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
18459 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
18460 #define tC3(mnem, aop, top, nops, ops, ae, te) \
18461 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
18462 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
18463 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
18464
18465 /* Mnemonic that cannot be conditionalized. The ARM condition-code
18466 field is still 0xE. Many of the Thumb variants can be executed
18467 conditionally, so this is checked separately. */
18468 #define TUE(mnem, op, top, nops, ops, ae, te) \
18469 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
18470 THUMB_VARIANT, do_##ae, do_##te }
18471
18472 /* Same as TUE but the encoding function for ARM and Thumb modes is the same.
18473 Used by mnemonics that have very minimal differences in the encoding for
18474 ARM and Thumb variants and can be handled in a common function. */
18475 #define TUEc(mnem, op, top, nops, ops, en) \
18476 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
18477 THUMB_VARIANT, do_##en, do_##en }
18478
18479 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
18480 condition code field. */
18481 #define TUF(mnem, op, top, nops, ops, ae, te) \
18482 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
18483 THUMB_VARIANT, do_##ae, do_##te }
18484
18485 /* ARM-only variants of all the above. */
18486 #define CE(mnem, op, nops, ops, ae) \
18487 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18488
18489 #define C3(mnem, op, nops, ops, ae) \
18490 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18491
18492 /* Legacy mnemonics that always have conditional infix after the third
18493 character. */
18494 #define CL(mnem, op, nops, ops, ae) \
18495 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
18496 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18497
18498 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
18499 #define cCE(mnem, op, nops, ops, ae) \
18500 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
18501
18502 /* Legacy coprocessor instructions where conditional infix and conditional
18503 suffix are ambiguous. For consistency this includes all FPA instructions,
18504 not just the potentially ambiguous ones. */
18505 #define cCL(mnem, op, nops, ops, ae) \
18506 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
18507 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
18508
18509 /* Coprocessor, takes either a suffix or a position-3 infix
18510 (for an FPA corner case). */
18511 #define C3E(mnem, op, nops, ops, ae) \
18512 { mnem, OPS##nops ops, OT_csuf_or_in3, \
18513 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
18514
18515 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
18516 { m1 #m2 m3, OPS##nops ops, \
18517 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
18518 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18519
18520 #define CM(m1, m2, op, nops, ops, ae) \
18521 xCM_ (m1, , m2, op, nops, ops, ae), \
18522 xCM_ (m1, eq, m2, op, nops, ops, ae), \
18523 xCM_ (m1, ne, m2, op, nops, ops, ae), \
18524 xCM_ (m1, cs, m2, op, nops, ops, ae), \
18525 xCM_ (m1, hs, m2, op, nops, ops, ae), \
18526 xCM_ (m1, cc, m2, op, nops, ops, ae), \
18527 xCM_ (m1, ul, m2, op, nops, ops, ae), \
18528 xCM_ (m1, lo, m2, op, nops, ops, ae), \
18529 xCM_ (m1, mi, m2, op, nops, ops, ae), \
18530 xCM_ (m1, pl, m2, op, nops, ops, ae), \
18531 xCM_ (m1, vs, m2, op, nops, ops, ae), \
18532 xCM_ (m1, vc, m2, op, nops, ops, ae), \
18533 xCM_ (m1, hi, m2, op, nops, ops, ae), \
18534 xCM_ (m1, ls, m2, op, nops, ops, ae), \
18535 xCM_ (m1, ge, m2, op, nops, ops, ae), \
18536 xCM_ (m1, lt, m2, op, nops, ops, ae), \
18537 xCM_ (m1, gt, m2, op, nops, ops, ae), \
18538 xCM_ (m1, le, m2, op, nops, ops, ae), \
18539 xCM_ (m1, al, m2, op, nops, ops, ae)
18540
18541 #define UE(mnem, op, nops, ops, ae) \
18542 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
18543
18544 #define UF(mnem, op, nops, ops, ae) \
18545 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
18546
18547 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
18548 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
18549 use the same encoding function for each. */
18550 #define NUF(mnem, op, nops, ops, enc) \
18551 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
18552 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
18553
18554 /* Neon data processing, version which indirects through neon_enc_tab for
18555 the various overloaded versions of opcodes. */
18556 #define nUF(mnem, op, nops, ops, enc) \
18557 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
18558 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
18559
18560 /* Neon insn with conditional suffix for the ARM version, non-overloaded
18561 version. */
18562 #define NCE_tag(mnem, op, nops, ops, enc, tag) \
18563 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
18564 THUMB_VARIANT, do_##enc, do_##enc }
18565
18566 #define NCE(mnem, op, nops, ops, enc) \
18567 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
18568
18569 #define NCEF(mnem, op, nops, ops, enc) \
18570 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
18571
18572 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
18573 #define nCE_tag(mnem, op, nops, ops, enc, tag) \
18574 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
18575 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
18576
18577 #define nCE(mnem, op, nops, ops, enc) \
18578 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
18579
18580 #define nCEF(mnem, op, nops, ops, enc) \
18581 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
18582
18583 #define do_0 0
18584
18585 static const struct asm_opcode insns[] =
18586 {
18587 #define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
18588 #define THUMB_VARIANT & arm_ext_v4t
18589 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
18590 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
18591 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
18592 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
18593 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
18594 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
18595 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
18596 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
18597 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
18598 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
18599 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
18600 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
18601 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
18602 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
18603 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
18604 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
18605
18606 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
18607 for setting PSR flag bits. They are obsolete in V6 and do not
18608 have Thumb equivalents. */
18609 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
18610 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
18611 CL("tstp", 110f000, 2, (RR, SH), cmp),
18612 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
18613 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
18614 CL("cmpp", 150f000, 2, (RR, SH), cmp),
18615 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
18616 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
18617 CL("cmnp", 170f000, 2, (RR, SH), cmp),
18618
18619 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
18620 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
18621 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
18622 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
18623
18624 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
18625 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
18626 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
18627 OP_RRnpc),
18628 OP_ADDRGLDR),ldst, t_ldst),
18629 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
18630
18631 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18632 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18633 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18634 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18635 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18636 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18637
18638 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
18639 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
18640 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
18641 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
18642
18643 /* Pseudo ops. */
18644 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
18645 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
18646 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
18647 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
18648
18649 /* Thumb-compatibility pseudo ops. */
18650 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
18651 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
18652 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
18653 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
18654 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
18655 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
18656 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
18657 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
18658 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
18659 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
18660 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
18661 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
18662
18663 /* These may simplify to neg. */
18664 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
18665 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
18666
18667 #undef THUMB_VARIANT
18668 #define THUMB_VARIANT & arm_ext_v6
18669
18670 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
18671
18672 /* V1 instructions with no Thumb analogue prior to V6T2. */
18673 #undef THUMB_VARIANT
18674 #define THUMB_VARIANT & arm_ext_v6t2
18675
18676 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
18677 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
18678 CL("teqp", 130f000, 2, (RR, SH), cmp),
18679
18680 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
18681 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
18682 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
18683 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
18684
18685 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18686 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18687
18688 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18689 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18690
18691 /* V1 instructions with no Thumb analogue at all. */
18692 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
18693 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
18694
18695 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
18696 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
18697 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
18698 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
18699 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
18700 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
18701 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
18702 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
18703
18704 #undef ARM_VARIANT
18705 #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
18706 #undef THUMB_VARIANT
18707 #define THUMB_VARIANT & arm_ext_v4t
18708
18709 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
18710 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
18711
18712 #undef THUMB_VARIANT
18713 #define THUMB_VARIANT & arm_ext_v6t2
18714
18715 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
18716 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
18717
18718 /* Generic coprocessor instructions. */
18719 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
18720 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18721 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18722 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18723 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18724 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
18725 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
18726
18727 #undef ARM_VARIANT
18728 #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
18729
18730 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
18731 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
18732
18733 #undef ARM_VARIANT
18734 #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
18735 #undef THUMB_VARIANT
18736 #define THUMB_VARIANT & arm_ext_msr
18737
18738 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
18739 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
18740
18741 #undef ARM_VARIANT
18742 #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
18743 #undef THUMB_VARIANT
18744 #define THUMB_VARIANT & arm_ext_v6t2
18745
18746 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18747 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18748 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18749 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18750 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18751 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18752 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18753 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18754
18755 #undef ARM_VARIANT
18756 #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
18757 #undef THUMB_VARIANT
18758 #define THUMB_VARIANT & arm_ext_v4t
18759
18760 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18761 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18762 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18763 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18764 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18765 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18766
18767 #undef ARM_VARIANT
18768 #define ARM_VARIANT & arm_ext_v4t_5
18769
18770 /* ARM Architecture 4T. */
18771 /* Note: bx (and blx) are required on V5, even if the processor does
18772 not support Thumb. */
18773 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
18774
18775 #undef ARM_VARIANT
18776 #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
18777 #undef THUMB_VARIANT
18778 #define THUMB_VARIANT & arm_ext_v5t
18779
18780 /* Note: blx has 2 variants; the .value coded here is for
18781 BLX(2). Only this variant has conditional execution. */
18782 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
18783 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
18784
18785 #undef THUMB_VARIANT
18786 #define THUMB_VARIANT & arm_ext_v6t2
18787
18788 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
18789 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18790 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18791 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18792 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18793 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
18794 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
18795 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
18796
18797 #undef ARM_VARIANT
18798 #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
18799 #undef THUMB_VARIANT
18800 #define THUMB_VARIANT & arm_ext_v5exp
18801
18802 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18803 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18804 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18805 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18806
18807 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18808 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18809
18810 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18811 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18812 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18813 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18814
18815 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18816 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18817 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18818 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18819
18820 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18821 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18822
18823 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18824 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18825 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18826 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18827
18828 #undef ARM_VARIANT
18829 #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
18830 #undef THUMB_VARIANT
18831 #define THUMB_VARIANT & arm_ext_v6t2
18832
18833 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
18834 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
18835 ldrd, t_ldstd),
18836 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
18837 ADDRGLDRS), ldrd, t_ldstd),
18838
18839 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
18840 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
18841
18842 #undef ARM_VARIANT
18843 #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
18844
18845 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
18846
18847 #undef ARM_VARIANT
18848 #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
18849 #undef THUMB_VARIANT
18850 #define THUMB_VARIANT & arm_ext_v6
18851
18852 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
18853 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
18854 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18855 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18856 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18857 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18858 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18859 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18860 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18861 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
18862
18863 #undef THUMB_VARIANT
18864 #define THUMB_VARIANT & arm_ext_v6t2
18865
18866 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
18867 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
18868 strex, t_strex),
18869 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
18870 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
18871
18872 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
18873 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
18874
18875 /* ARM V6 not included in V7M. */
18876 #undef THUMB_VARIANT
18877 #define THUMB_VARIANT & arm_ext_v6_notm
18878 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
18879 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
18880 UF(rfeib, 9900a00, 1, (RRw), rfe),
18881 UF(rfeda, 8100a00, 1, (RRw), rfe),
18882 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
18883 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
18884 UF(rfefa, 8100a00, 1, (RRw), rfe),
18885 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
18886 UF(rfeed, 9900a00, 1, (RRw), rfe),
18887 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
18888 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
18889 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
18890 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
18891 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
18892 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
18893 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
18894 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
18895 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
18896
18897 /* ARM V6 not included in V7M (eg. integer SIMD). */
18898 #undef THUMB_VARIANT
18899 #define THUMB_VARIANT & arm_ext_v6_dsp
18900 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
18901 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
18902 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
18903 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18904 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18905 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18906 /* Old name for QASX. */
18907 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18908 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18909 /* Old name for QSAX. */
18910 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18911 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18912 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18913 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18914 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18915 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18916 /* Old name for SASX. */
18917 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18918 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18919 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18920 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18921 /* Old name for SHASX. */
18922 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18923 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18924 /* Old name for SHSAX. */
18925 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18926 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18927 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18928 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18929 /* Old name for SSAX. */
18930 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18931 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18932 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18933 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18934 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18935 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18936 /* Old name for UASX. */
18937 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18938 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18939 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18940 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18941 /* Old name for UHASX. */
18942 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18943 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18944 /* Old name for UHSAX. */
18945 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18946 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18947 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18948 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18949 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18950 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18951 /* Old name for UQASX. */
18952 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18953 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18954 /* Old name for UQSAX. */
18955 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18956 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18957 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18958 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18959 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18960 /* Old name for USAX. */
18961 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18962 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18963 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18964 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18965 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18966 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18967 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18968 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18969 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18970 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18971 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18972 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18973 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18974 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18975 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18976 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18977 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18978 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18979 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18980 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18981 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18982 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18983 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18984 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18985 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18986 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18987 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18988 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18989 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18990 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
18991 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
18992 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18993 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18994 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
18995
18996 #undef ARM_VARIANT
18997 #define ARM_VARIANT & arm_ext_v6k
18998 #undef THUMB_VARIANT
18999 #define THUMB_VARIANT & arm_ext_v6k
19000
19001 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
19002 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
19003 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
19004 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
19005
19006 #undef THUMB_VARIANT
19007 #define THUMB_VARIANT & arm_ext_v6_notm
19008 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
19009 ldrexd, t_ldrexd),
19010 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
19011 RRnpcb), strexd, t_strexd),
19012
19013 #undef THUMB_VARIANT
19014 #define THUMB_VARIANT & arm_ext_v6t2
19015 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
19016 rd_rn, rd_rn),
19017 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
19018 rd_rn, rd_rn),
19019 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
19020 strex, t_strexbh),
19021 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
19022 strex, t_strexbh),
19023 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
19024
19025 #undef ARM_VARIANT
19026 #define ARM_VARIANT & arm_ext_sec
19027 #undef THUMB_VARIANT
19028 #define THUMB_VARIANT & arm_ext_sec
19029
19030 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
19031
19032 #undef ARM_VARIANT
19033 #define ARM_VARIANT & arm_ext_virt
19034 #undef THUMB_VARIANT
19035 #define THUMB_VARIANT & arm_ext_virt
19036
19037 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
19038 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
19039
19040 #undef ARM_VARIANT
19041 #define ARM_VARIANT & arm_ext_pan
19042 #undef THUMB_VARIANT
19043 #define THUMB_VARIANT & arm_ext_pan
19044
19045 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
19046
19047 #undef ARM_VARIANT
19048 #define ARM_VARIANT & arm_ext_v6t2
19049 #undef THUMB_VARIANT
19050 #define THUMB_VARIANT & arm_ext_v6t2
19051
19052 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
19053 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
19054 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
19055 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
19056
19057 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
19058 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
19059 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
19060 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
19061
19062 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19063 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19064 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19065 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19066
19067 /* Thumb-only instructions. */
19068 #undef ARM_VARIANT
19069 #define ARM_VARIANT NULL
19070 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
19071 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
19072
19073 /* ARM does not really have an IT instruction, so always allow it.
19074 The opcode is copied from Thumb in order to allow warnings in
19075 -mimplicit-it=[never | arm] modes. */
19076 #undef ARM_VARIANT
19077 #define ARM_VARIANT & arm_ext_v1
19078
19079 TUE("it", bf08, bf08, 1, (COND), it, t_it),
19080 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
19081 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
19082 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
19083 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
19084 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
19085 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
19086 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
19087 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
19088 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
19089 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
19090 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
19091 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
19092 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
19093 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
19094 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
19095 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
19096 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
19097
19098 /* Thumb2 only instructions. */
19099 #undef ARM_VARIANT
19100 #define ARM_VARIANT NULL
19101
19102 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19103 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19104 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
19105 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
19106 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
19107 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
19108
19109 /* Hardware division instructions. */
19110 #undef ARM_VARIANT
19111 #define ARM_VARIANT & arm_ext_adiv
19112 #undef THUMB_VARIANT
19113 #define THUMB_VARIANT & arm_ext_div
19114
19115 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
19116 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
19117
19118 /* ARM V6M/V7 instructions. */
19119 #undef ARM_VARIANT
19120 #define ARM_VARIANT & arm_ext_barrier
19121 #undef THUMB_VARIANT
19122 #define THUMB_VARIANT & arm_ext_barrier
19123
19124 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
19125 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
19126 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
19127
19128 /* ARM V7 instructions. */
19129 #undef ARM_VARIANT
19130 #define ARM_VARIANT & arm_ext_v7
19131 #undef THUMB_VARIANT
19132 #define THUMB_VARIANT & arm_ext_v7
19133
19134 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
19135 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
19136
19137 #undef ARM_VARIANT
19138 #define ARM_VARIANT & arm_ext_mp
19139 #undef THUMB_VARIANT
19140 #define THUMB_VARIANT & arm_ext_mp
19141
19142 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
19143
19144 /* AArchv8 instructions. */
19145 #undef ARM_VARIANT
19146 #define ARM_VARIANT & arm_ext_v8
19147 #undef THUMB_VARIANT
19148 #define THUMB_VARIANT & arm_ext_v8
19149
19150 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
19151 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
19152 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19153 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
19154 ldrexd, t_ldrexd),
19155 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
19156 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19157 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
19158 stlex, t_stlex),
19159 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
19160 strexd, t_strexd),
19161 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
19162 stlex, t_stlex),
19163 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
19164 stlex, t_stlex),
19165 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19166 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19167 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19168 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19169 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19170 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19171
19172 /* ARMv8 T32 only. */
19173 #undef ARM_VARIANT
19174 #define ARM_VARIANT NULL
19175 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
19176 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
19177 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
19178
19179 /* FP for ARMv8. */
19180 #undef ARM_VARIANT
19181 #define ARM_VARIANT & fpu_vfp_ext_armv8xd
19182 #undef THUMB_VARIANT
19183 #define THUMB_VARIANT & fpu_vfp_ext_armv8xd
19184
19185 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
19186 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
19187 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
19188 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
19189 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
19190 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
19191 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
19192 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
19193 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
19194 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
19195 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
19196 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
19197 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
19198 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
19199 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
19200 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
19201 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
19202
19203 /* Crypto v1 extensions. */
19204 #undef ARM_VARIANT
19205 #define ARM_VARIANT & fpu_crypto_ext_armv8
19206 #undef THUMB_VARIANT
19207 #define THUMB_VARIANT & fpu_crypto_ext_armv8
19208
19209 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
19210 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
19211 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
19212 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
19213 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
19214 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
19215 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
19216 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
19217 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
19218 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
19219 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
19220 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
19221 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
19222 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
19223
19224 #undef ARM_VARIANT
19225 #define ARM_VARIANT & crc_ext_armv8
19226 #undef THUMB_VARIANT
19227 #define THUMB_VARIANT & crc_ext_armv8
19228 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
19229 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
19230 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
19231 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
19232 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
19233 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
19234
19235 #undef ARM_VARIANT
19236 #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
19237 #undef THUMB_VARIANT
19238 #define THUMB_VARIANT NULL
19239
19240 cCE("wfs", e200110, 1, (RR), rd),
19241 cCE("rfs", e300110, 1, (RR), rd),
19242 cCE("wfc", e400110, 1, (RR), rd),
19243 cCE("rfc", e500110, 1, (RR), rd),
19244
19245 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
19246 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
19247 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
19248 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
19249
19250 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
19251 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
19252 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
19253 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
19254
19255 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
19256 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
19257 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
19258 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
19259 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
19260 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
19261 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
19262 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
19263 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
19264 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
19265 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
19266 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
19267
19268 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
19269 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
19270 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
19271 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
19272 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
19273 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
19274 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
19275 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
19276 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
19277 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
19278 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
19279 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
19280
19281 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
19282 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
19283 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
19284 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
19285 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
19286 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
19287 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
19288 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
19289 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
19290 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
19291 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
19292 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
19293
19294 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
19295 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
19296 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
19297 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
19298 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
19299 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
19300 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
19301 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
19302 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
19303 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
19304 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
19305 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
19306
19307 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
19308 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
19309 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
19310 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
19311 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
19312 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
19313 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
19314 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
19315 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
19316 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
19317 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
19318 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
19319
19320 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
19321 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
19322 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
19323 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
19324 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
19325 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
19326 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
19327 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
19328 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
19329 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
19330 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
19331 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
19332
19333 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
19334 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
19335 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
19336 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
19337 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
19338 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
19339 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
19340 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
19341 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
19342 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
19343 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
19344 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
19345
19346 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
19347 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
19348 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
19349 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
19350 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
19351 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
19352 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
19353 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
19354 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
19355 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
19356 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
19357 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
19358
19359 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
19360 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
19361 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
19362 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
19363 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
19364 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
19365 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
19366 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
19367 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
19368 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
19369 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
19370 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
19371
19372 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
19373 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
19374 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
19375 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
19376 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
19377 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
19378 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
19379 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
19380 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
19381 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
19382 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
19383 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
19384
19385 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
19386 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
19387 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
19388 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
19389 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
19390 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
19391 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
19392 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
19393 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
19394 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
19395 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
19396 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
19397
19398 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
19399 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
19400 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
19401 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
19402 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
19403 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
19404 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
19405 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
19406 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
19407 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
19408 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
19409 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
19410
19411 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
19412 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
19413 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
19414 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
19415 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
19416 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
19417 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
19418 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
19419 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
19420 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
19421 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
19422 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
19423
19424 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
19425 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
19426 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
19427 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
19428 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
19429 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
19430 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
19431 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
19432 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
19433 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
19434 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
19435 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
19436
19437 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
19438 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
19439 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
19440 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
19441 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
19442 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
19443 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
19444 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
19445 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
19446 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
19447 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
19448 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
19449
19450 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
19451 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
19452 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
19453 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
19454 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
19455 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
19456 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
19457 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
19458 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
19459 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
19460 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
19461 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
19462
19463 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
19464 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
19465 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
19466 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
19467 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
19468 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19469 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19470 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19471 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
19472 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
19473 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
19474 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
19475
19476 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
19477 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
19478 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
19479 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
19480 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
19481 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19482 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19483 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19484 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
19485 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
19486 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
19487 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
19488
19489 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
19490 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
19491 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
19492 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
19493 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
19494 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19495 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19496 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19497 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
19498 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
19499 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
19500 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
19501
19502 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
19503 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
19504 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
19505 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
19506 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
19507 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19508 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19509 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19510 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
19511 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
19512 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
19513 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
19514
19515 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
19516 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
19517 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
19518 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
19519 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
19520 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19521 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19522 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19523 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
19524 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
19525 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
19526 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
19527
19528 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
19529 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
19530 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
19531 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
19532 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
19533 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19534 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19535 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19536 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
19537 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
19538 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
19539 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
19540
19541 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
19542 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
19543 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
19544 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
19545 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
19546 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19547 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19548 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19549 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
19550 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
19551 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
19552 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
19553
19554 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
19555 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
19556 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
19557 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
19558 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
19559 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19560 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19561 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19562 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
19563 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
19564 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
19565 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
19566
19567 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
19568 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
19569 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
19570 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
19571 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
19572 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19573 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19574 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19575 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
19576 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
19577 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
19578 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
19579
19580 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
19581 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
19582 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
19583 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
19584 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
19585 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19586 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19587 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19588 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
19589 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
19590 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
19591 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
19592
19593 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
19594 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
19595 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
19596 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
19597 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
19598 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19599 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19600 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19601 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
19602 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
19603 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
19604 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
19605
19606 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
19607 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
19608 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
19609 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
19610 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
19611 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19612 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19613 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19614 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
19615 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
19616 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
19617 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
19618
19619 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
19620 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
19621 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
19622 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
19623 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
19624 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19625 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19626 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19627 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
19628 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
19629 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
19630 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
19631
19632 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
19633 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
19634 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
19635 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
19636
19637 cCL("flts", e000110, 2, (RF, RR), rn_rd),
19638 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
19639 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
19640 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
19641 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
19642 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
19643 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
19644 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
19645 cCL("flte", e080110, 2, (RF, RR), rn_rd),
19646 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
19647 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
19648 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
19649
19650 /* The implementation of the FIX instruction is broken on some
19651 assemblers, in that it accepts a precision specifier as well as a
19652 rounding specifier, despite the fact that this is meaningless.
19653 To be more compatible, we accept it as well, though of course it
19654 does not set any bits. */
19655 cCE("fix", e100110, 2, (RR, RF), rd_rm),
19656 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
19657 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
19658 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
19659 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
19660 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
19661 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
19662 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
19663 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
19664 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
19665 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
19666 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
19667 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
19668
19669 /* Instructions that were new with the real FPA, call them V2. */
19670 #undef ARM_VARIANT
19671 #define ARM_VARIANT & fpu_fpa_ext_v2
19672
19673 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19674 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19675 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19676 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19677 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19678 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19679
19680 #undef ARM_VARIANT
19681 #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
19682
19683 /* Moves and type conversions. */
19684 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
19685 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
19686 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
19687 cCE("fmstat", ef1fa10, 0, (), noargs),
19688 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
19689 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
19690 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
19691 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
19692 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
19693 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
19694 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
19695 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
19696 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
19697 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
19698
19699 /* Memory operations. */
19700 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
19701 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
19702 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19703 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19704 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19705 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19706 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19707 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19708 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19709 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19710 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19711 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19712 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19713 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19714 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19715 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19716 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19717 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19718
19719 /* Monadic operations. */
19720 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
19721 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
19722 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
19723
19724 /* Dyadic operations. */
19725 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19726 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19727 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19728 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19729 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19730 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19731 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19732 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19733 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19734
19735 /* Comparisons. */
19736 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
19737 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
19738 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
19739 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
19740
19741 /* Double precision load/store are still present on single precision
19742 implementations. */
19743 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
19744 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
19745 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19746 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19747 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19748 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19749 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19750 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19751 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19752 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19753
19754 #undef ARM_VARIANT
19755 #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
19756
19757 /* Moves and type conversions. */
19758 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19759 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
19760 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
19761 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
19762 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
19763 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
19764 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
19765 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
19766 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
19767 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
19768 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
19769 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
19770 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
19771
19772 /* Monadic operations. */
19773 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
19774 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19775 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
19776
19777 /* Dyadic operations. */
19778 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19779 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19780 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19781 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19782 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19783 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19784 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19785 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19786 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19787
19788 /* Comparisons. */
19789 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19790 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
19791 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
19792 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
19793
19794 #undef ARM_VARIANT
19795 #define ARM_VARIANT & fpu_vfp_ext_v2
19796
19797 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
19798 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
19799 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
19800 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
19801
19802 /* Instructions which may belong to either the Neon or VFP instruction sets.
19803 Individual encoder functions perform additional architecture checks. */
19804 #undef ARM_VARIANT
19805 #define ARM_VARIANT & fpu_vfp_ext_v1xd
19806 #undef THUMB_VARIANT
19807 #define THUMB_VARIANT & fpu_vfp_ext_v1xd
19808
19809 /* These mnemonics are unique to VFP. */
19810 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
19811 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
19812 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19813 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19814 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19815 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
19816 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
19817 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
19818 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
19819 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
19820
19821 /* Mnemonics shared by Neon and VFP. */
19822 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
19823 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
19824 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
19825
19826 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
19827 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
19828
19829 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
19830 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
19831
19832 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19833 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19834 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19835 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19836 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19837 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19838 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
19839 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
19840
19841 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
19842 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
19843 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
19844 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
19845
19846
19847 /* NOTE: All VMOV encoding is special-cased! */
19848 NCE(vmov, 0, 1, (VMOV), neon_mov),
19849 NCE(vmovq, 0, 1, (VMOV), neon_mov),
19850
19851 #undef THUMB_VARIANT
19852 #define THUMB_VARIANT & fpu_neon_ext_v1
19853 #undef ARM_VARIANT
19854 #define ARM_VARIANT & fpu_neon_ext_v1
19855
19856 /* Data processing with three registers of the same length. */
19857 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
19858 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
19859 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
19860 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19861 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19862 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19863 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19864 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19865 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19866 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
19867 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
19868 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
19869 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
19870 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
19871 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
19872 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
19873 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
19874 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
19875 /* If not immediate, fall back to neon_dyadic_i64_su.
19876 shl_imm should accept I8 I16 I32 I64,
19877 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
19878 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
19879 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
19880 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
19881 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
19882 /* Logic ops, types optional & ignored. */
19883 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19884 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19885 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19886 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19887 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19888 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19889 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19890 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19891 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
19892 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
19893 /* Bitfield ops, untyped. */
19894 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19895 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19896 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19897 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19898 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19899 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19900 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
19901 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19902 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
19903 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19904 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
19905 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19906 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
19907 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
19908 back to neon_dyadic_if_su. */
19909 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
19910 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
19911 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
19912 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
19913 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
19914 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
19915 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
19916 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
19917 /* Comparison. Type I8 I16 I32 F32. */
19918 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
19919 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
19920 /* As above, D registers only. */
19921 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
19922 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
19923 /* Int and float variants, signedness unimportant. */
19924 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
19925 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
19926 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
19927 /* Add/sub take types I8 I16 I32 I64 F32. */
19928 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
19929 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
19930 /* vtst takes sizes 8, 16, 32. */
19931 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
19932 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
19933 /* VMUL takes I8 I16 I32 F32 P8. */
19934 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
19935 /* VQD{R}MULH takes S16 S32. */
19936 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
19937 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
19938 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
19939 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
19940 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
19941 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
19942 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
19943 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
19944 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
19945 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
19946 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
19947 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
19948 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
19949 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
19950 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
19951 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
19952 /* ARM v8.1 extension. */
19953 nUF(vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
19954 nUF(vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
19955 nUF(vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
19956 nUF(vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
19957
19958 /* Two address, int/float. Types S8 S16 S32 F32. */
19959 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
19960 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
19961
19962 /* Data processing with two registers and a shift amount. */
19963 /* Right shifts, and variants with rounding.
19964 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
19965 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
19966 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
19967 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
19968 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
19969 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
19970 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
19971 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
19972 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
19973 /* Shift and insert. Sizes accepted 8 16 32 64. */
19974 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
19975 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
19976 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
19977 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
19978 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
19979 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
19980 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
19981 /* Right shift immediate, saturating & narrowing, with rounding variants.
19982 Types accepted S16 S32 S64 U16 U32 U64. */
19983 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
19984 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
19985 /* As above, unsigned. Types accepted S16 S32 S64. */
19986 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
19987 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
19988 /* Right shift narrowing. Types accepted I16 I32 I64. */
19989 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
19990 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
19991 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
19992 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
19993 /* CVT with optional immediate for fixed-point variant. */
19994 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
19995
19996 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
19997 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
19998
19999 /* Data processing, three registers of different lengths. */
20000 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
20001 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
20002 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
20003 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
20004 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
20005 /* If not scalar, fall back to neon_dyadic_long.
20006 Vector types as above, scalar types S16 S32 U16 U32. */
20007 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
20008 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
20009 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
20010 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20011 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20012 /* Dyadic, narrowing insns. Types I16 I32 I64. */
20013 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20014 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20015 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20016 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20017 /* Saturating doubling multiplies. Types S16 S32. */
20018 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20019 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20020 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20021 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
20022 S16 S32 U16 U32. */
20023 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
20024
20025 /* Extract. Size 8. */
20026 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
20027 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
20028
20029 /* Two registers, miscellaneous. */
20030 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
20031 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
20032 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
20033 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
20034 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
20035 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
20036 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
20037 /* Vector replicate. Sizes 8 16 32. */
20038 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
20039 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
20040 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
20041 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
20042 /* VMOVN. Types I16 I32 I64. */
20043 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
20044 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
20045 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
20046 /* VQMOVUN. Types S16 S32 S64. */
20047 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
20048 /* VZIP / VUZP. Sizes 8 16 32. */
20049 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
20050 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
20051 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
20052 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
20053 /* VQABS / VQNEG. Types S8 S16 S32. */
20054 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20055 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
20056 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20057 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
20058 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
20059 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
20060 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
20061 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
20062 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
20063 /* Reciprocal estimates. Types U32 F32. */
20064 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
20065 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
20066 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
20067 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
20068 /* VCLS. Types S8 S16 S32. */
20069 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
20070 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
20071 /* VCLZ. Types I8 I16 I32. */
20072 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
20073 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
20074 /* VCNT. Size 8. */
20075 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
20076 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
20077 /* Two address, untyped. */
20078 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
20079 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
20080 /* VTRN. Sizes 8 16 32. */
20081 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
20082 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
20083
20084 /* Table lookup. Size 8. */
20085 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20086 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20087
20088 #undef THUMB_VARIANT
20089 #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
20090 #undef ARM_VARIANT
20091 #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
20092
20093 /* Neon element/structure load/store. */
20094 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20095 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20096 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20097 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20098 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20099 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20100 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
20101 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
20102
20103 #undef THUMB_VARIANT
20104 #define THUMB_VARIANT & fpu_vfp_ext_v3xd
20105 #undef ARM_VARIANT
20106 #define ARM_VARIANT & fpu_vfp_ext_v3xd
20107 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
20108 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20109 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20110 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20111 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20112 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20113 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20114 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20115 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20116
20117 #undef THUMB_VARIANT
20118 #define THUMB_VARIANT & fpu_vfp_ext_v3
20119 #undef ARM_VARIANT
20120 #define ARM_VARIANT & fpu_vfp_ext_v3
20121
20122 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
20123 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
20124 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
20125 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
20126 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
20127 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
20128 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
20129 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
20130 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
20131
20132 #undef ARM_VARIANT
20133 #define ARM_VARIANT & fpu_vfp_ext_fma
20134 #undef THUMB_VARIANT
20135 #define THUMB_VARIANT & fpu_vfp_ext_fma
20136 /* Mnemonics shared by Neon and VFP. These are included in the
20137 VFP FMA variant; NEON and VFP FMA always includes the NEON
20138 FMA instructions. */
20139 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20140 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20141 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
20142 the v form should always be used. */
20143 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20144 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20145 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20146 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20147 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20148 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20149
20150 #undef THUMB_VARIANT
20151 #undef ARM_VARIANT
20152 #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
20153
20154 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20155 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20156 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20157 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20158 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20159 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20160 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
20161 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
20162
20163 #undef ARM_VARIANT
20164 #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
20165
20166 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
20167 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
20168 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
20169 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
20170 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
20171 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
20172 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
20173 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
20174 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
20175 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20176 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20177 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20178 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20179 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20180 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20181 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20182 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20183 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20184 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
20185 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
20186 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20187 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20188 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20189 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20190 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20191 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20192 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
20193 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
20194 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
20195 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
20196 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
20197 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
20198 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
20199 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
20200 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
20201 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
20202 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
20203 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20204 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20205 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20206 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20207 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20208 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20209 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20210 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20211 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20212 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
20213 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20214 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20215 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20216 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20217 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20218 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20219 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20220 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20221 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20222 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20223 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20224 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20225 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20226 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20227 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20228 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20229 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20230 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20231 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20232 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20233 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20234 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20235 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20236 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20237 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20238 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20239 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20240 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20241 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20242 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20243 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20244 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20245 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20246 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20247 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20248 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20249 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20250 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20251 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20252 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20253 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20254 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
20255 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20256 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20257 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20258 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20259 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20260 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20261 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20262 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20263 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20264 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20265 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20266 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20267 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20268 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20269 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20270 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20271 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20272 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20273 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20274 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20275 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20276 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
20277 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20278 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20279 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20280 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20281 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20282 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20283 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20284 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20285 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20286 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20287 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20288 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20289 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20290 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20291 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20292 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20293 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20294 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20295 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20296 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20297 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20298 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20299 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20300 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20301 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20302 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20303 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20304 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20305 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20306 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20307 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20308 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
20309 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
20310 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
20311 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
20312 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
20313 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
20314 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20315 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20316 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20317 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
20318 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
20319 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
20320 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
20321 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
20322 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
20323 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20324 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20325 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20326 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20327 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
20328
20329 #undef ARM_VARIANT
20330 #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
20331
20332 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
20333 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
20334 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
20335 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
20336 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
20337 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
20338 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20339 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20340 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20341 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20342 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20343 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20344 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20345 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20346 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20347 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20348 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20349 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20350 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20351 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20352 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
20353 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20354 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20355 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20356 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20357 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20358 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20359 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20360 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20361 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20362 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20363 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20364 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20365 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20366 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20367 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20368 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20369 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20370 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20371 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20372 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20373 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20374 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20375 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20376 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20377 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20378 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20379 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20380 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20381 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20382 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20383 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20384 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20385 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20386 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20387 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20388 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20389
20390 #undef ARM_VARIANT
20391 #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
20392
20393 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
20394 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
20395 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
20396 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
20397 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
20398 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
20399 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
20400 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
20401 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
20402 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
20403 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
20404 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
20405 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
20406 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
20407 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
20408 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
20409 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
20410 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
20411 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
20412 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
20413 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
20414 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
20415 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
20416 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
20417 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
20418 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
20419 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
20420 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
20421 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
20422 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
20423 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
20424 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
20425 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
20426 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
20427 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
20428 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
20429 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
20430 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
20431 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
20432 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
20433 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
20434 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
20435 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
20436 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
20437 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
20438 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
20439 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
20440 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
20441 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
20442 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
20443 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
20444 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
20445 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
20446 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
20447 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
20448 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
20449 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
20450 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
20451 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
20452 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
20453 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
20454 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
20455 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
20456 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
20457 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20458 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20459 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20460 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20461 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20462 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20463 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20464 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20465 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
20466 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
20467 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
20468 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
20469 };
20470 #undef ARM_VARIANT
20471 #undef THUMB_VARIANT
20472 #undef TCE
20473 #undef TUE
20474 #undef TUF
20475 #undef TCC
20476 #undef cCE
20477 #undef cCL
20478 #undef C3E
20479 #undef CE
20480 #undef CM
20481 #undef UE
20482 #undef UF
20483 #undef UT
20484 #undef NUF
20485 #undef nUF
20486 #undef NCE
20487 #undef nCE
20488 #undef OPS0
20489 #undef OPS1
20490 #undef OPS2
20491 #undef OPS3
20492 #undef OPS4
20493 #undef OPS5
20494 #undef OPS6
20495 #undef do_0
20496 \f
20497 /* MD interface: bits in the object file. */
20498
20499 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
20500 for use in the a.out file, and stores them in the array pointed to by buf.
20501 This knows about the endian-ness of the target machine and does
20502 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
20503 2 (short) and 4 (long) Floating numbers are put out as a series of
20504 LITTLENUMS (shorts, here at least). */
20505
20506 void
20507 md_number_to_chars (char * buf, valueT val, int n)
20508 {
20509 if (target_big_endian)
20510 number_to_chars_bigendian (buf, val, n);
20511 else
20512 number_to_chars_littleendian (buf, val, n);
20513 }
20514
20515 static valueT
20516 md_chars_to_number (char * buf, int n)
20517 {
20518 valueT result = 0;
20519 unsigned char * where = (unsigned char *) buf;
20520
20521 if (target_big_endian)
20522 {
20523 while (n--)
20524 {
20525 result <<= 8;
20526 result |= (*where++ & 255);
20527 }
20528 }
20529 else
20530 {
20531 while (n--)
20532 {
20533 result <<= 8;
20534 result |= (where[n] & 255);
20535 }
20536 }
20537
20538 return result;
20539 }
20540
20541 /* MD interface: Sections. */
20542
20543 /* Calculate the maximum variable size (i.e., excluding fr_fix)
20544 that an rs_machine_dependent frag may reach. */
20545
20546 unsigned int
20547 arm_frag_max_var (fragS *fragp)
20548 {
20549 /* We only use rs_machine_dependent for variable-size Thumb instructions,
20550 which are either THUMB_SIZE (2) or INSN_SIZE (4).
20551
20552 Note that we generate relaxable instructions even for cases that don't
20553 really need it, like an immediate that's a trivial constant. So we're
20554 overestimating the instruction size for some of those cases. Rather
20555 than putting more intelligence here, it would probably be better to
20556 avoid generating a relaxation frag in the first place when it can be
20557 determined up front that a short instruction will suffice. */
20558
20559 gas_assert (fragp->fr_type == rs_machine_dependent);
20560 return INSN_SIZE;
20561 }
20562
20563 /* Estimate the size of a frag before relaxing. Assume everything fits in
20564 2 bytes. */
20565
20566 int
20567 md_estimate_size_before_relax (fragS * fragp,
20568 segT segtype ATTRIBUTE_UNUSED)
20569 {
20570 fragp->fr_var = 2;
20571 return 2;
20572 }
20573
20574 /* Convert a machine dependent frag. */
20575
20576 void
20577 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
20578 {
20579 unsigned long insn;
20580 unsigned long old_op;
20581 char *buf;
20582 expressionS exp;
20583 fixS *fixp;
20584 int reloc_type;
20585 int pc_rel;
20586 int opcode;
20587
20588 buf = fragp->fr_literal + fragp->fr_fix;
20589
20590 old_op = bfd_get_16(abfd, buf);
20591 if (fragp->fr_symbol)
20592 {
20593 exp.X_op = O_symbol;
20594 exp.X_add_symbol = fragp->fr_symbol;
20595 }
20596 else
20597 {
20598 exp.X_op = O_constant;
20599 }
20600 exp.X_add_number = fragp->fr_offset;
20601 opcode = fragp->fr_subtype;
20602 switch (opcode)
20603 {
20604 case T_MNEM_ldr_pc:
20605 case T_MNEM_ldr_pc2:
20606 case T_MNEM_ldr_sp:
20607 case T_MNEM_str_sp:
20608 case T_MNEM_ldr:
20609 case T_MNEM_ldrb:
20610 case T_MNEM_ldrh:
20611 case T_MNEM_str:
20612 case T_MNEM_strb:
20613 case T_MNEM_strh:
20614 if (fragp->fr_var == 4)
20615 {
20616 insn = THUMB_OP32 (opcode);
20617 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
20618 {
20619 insn |= (old_op & 0x700) << 4;
20620 }
20621 else
20622 {
20623 insn |= (old_op & 7) << 12;
20624 insn |= (old_op & 0x38) << 13;
20625 }
20626 insn |= 0x00000c00;
20627 put_thumb32_insn (buf, insn);
20628 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
20629 }
20630 else
20631 {
20632 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
20633 }
20634 pc_rel = (opcode == T_MNEM_ldr_pc2);
20635 break;
20636 case T_MNEM_adr:
20637 if (fragp->fr_var == 4)
20638 {
20639 insn = THUMB_OP32 (opcode);
20640 insn |= (old_op & 0xf0) << 4;
20641 put_thumb32_insn (buf, insn);
20642 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
20643 }
20644 else
20645 {
20646 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
20647 exp.X_add_number -= 4;
20648 }
20649 pc_rel = 1;
20650 break;
20651 case T_MNEM_mov:
20652 case T_MNEM_movs:
20653 case T_MNEM_cmp:
20654 case T_MNEM_cmn:
20655 if (fragp->fr_var == 4)
20656 {
20657 int r0off = (opcode == T_MNEM_mov
20658 || opcode == T_MNEM_movs) ? 0 : 8;
20659 insn = THUMB_OP32 (opcode);
20660 insn = (insn & 0xe1ffffff) | 0x10000000;
20661 insn |= (old_op & 0x700) << r0off;
20662 put_thumb32_insn (buf, insn);
20663 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
20664 }
20665 else
20666 {
20667 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
20668 }
20669 pc_rel = 0;
20670 break;
20671 case T_MNEM_b:
20672 if (fragp->fr_var == 4)
20673 {
20674 insn = THUMB_OP32(opcode);
20675 put_thumb32_insn (buf, insn);
20676 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
20677 }
20678 else
20679 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
20680 pc_rel = 1;
20681 break;
20682 case T_MNEM_bcond:
20683 if (fragp->fr_var == 4)
20684 {
20685 insn = THUMB_OP32(opcode);
20686 insn |= (old_op & 0xf00) << 14;
20687 put_thumb32_insn (buf, insn);
20688 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
20689 }
20690 else
20691 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
20692 pc_rel = 1;
20693 break;
20694 case T_MNEM_add_sp:
20695 case T_MNEM_add_pc:
20696 case T_MNEM_inc_sp:
20697 case T_MNEM_dec_sp:
20698 if (fragp->fr_var == 4)
20699 {
20700 /* ??? Choose between add and addw. */
20701 insn = THUMB_OP32 (opcode);
20702 insn |= (old_op & 0xf0) << 4;
20703 put_thumb32_insn (buf, insn);
20704 if (opcode == T_MNEM_add_pc)
20705 reloc_type = BFD_RELOC_ARM_T32_IMM12;
20706 else
20707 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
20708 }
20709 else
20710 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
20711 pc_rel = 0;
20712 break;
20713
20714 case T_MNEM_addi:
20715 case T_MNEM_addis:
20716 case T_MNEM_subi:
20717 case T_MNEM_subis:
20718 if (fragp->fr_var == 4)
20719 {
20720 insn = THUMB_OP32 (opcode);
20721 insn |= (old_op & 0xf0) << 4;
20722 insn |= (old_op & 0xf) << 16;
20723 put_thumb32_insn (buf, insn);
20724 if (insn & (1 << 20))
20725 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
20726 else
20727 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
20728 }
20729 else
20730 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
20731 pc_rel = 0;
20732 break;
20733 default:
20734 abort ();
20735 }
20736 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
20737 (enum bfd_reloc_code_real) reloc_type);
20738 fixp->fx_file = fragp->fr_file;
20739 fixp->fx_line = fragp->fr_line;
20740 fragp->fr_fix += fragp->fr_var;
20741
20742 /* Set whether we use thumb-2 ISA based on final relaxation results. */
20743 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
20744 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
20745 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
20746 }
20747
20748 /* Return the size of a relaxable immediate operand instruction.
20749 SHIFT and SIZE specify the form of the allowable immediate. */
20750 static int
20751 relax_immediate (fragS *fragp, int size, int shift)
20752 {
20753 offsetT offset;
20754 offsetT mask;
20755 offsetT low;
20756
20757 /* ??? Should be able to do better than this. */
20758 if (fragp->fr_symbol)
20759 return 4;
20760
20761 low = (1 << shift) - 1;
20762 mask = (1 << (shift + size)) - (1 << shift);
20763 offset = fragp->fr_offset;
20764 /* Force misaligned offsets to 32-bit variant. */
20765 if (offset & low)
20766 return 4;
20767 if (offset & ~mask)
20768 return 4;
20769 return 2;
20770 }
20771
20772 /* Get the address of a symbol during relaxation. */
20773 static addressT
20774 relaxed_symbol_addr (fragS *fragp, long stretch)
20775 {
20776 fragS *sym_frag;
20777 addressT addr;
20778 symbolS *sym;
20779
20780 sym = fragp->fr_symbol;
20781 sym_frag = symbol_get_frag (sym);
20782 know (S_GET_SEGMENT (sym) != absolute_section
20783 || sym_frag == &zero_address_frag);
20784 addr = S_GET_VALUE (sym) + fragp->fr_offset;
20785
20786 /* If frag has yet to be reached on this pass, assume it will
20787 move by STRETCH just as we did. If this is not so, it will
20788 be because some frag between grows, and that will force
20789 another pass. */
20790
20791 if (stretch != 0
20792 && sym_frag->relax_marker != fragp->relax_marker)
20793 {
20794 fragS *f;
20795
20796 /* Adjust stretch for any alignment frag. Note that if have
20797 been expanding the earlier code, the symbol may be
20798 defined in what appears to be an earlier frag. FIXME:
20799 This doesn't handle the fr_subtype field, which specifies
20800 a maximum number of bytes to skip when doing an
20801 alignment. */
20802 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
20803 {
20804 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
20805 {
20806 if (stretch < 0)
20807 stretch = - ((- stretch)
20808 & ~ ((1 << (int) f->fr_offset) - 1));
20809 else
20810 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
20811 if (stretch == 0)
20812 break;
20813 }
20814 }
20815 if (f != NULL)
20816 addr += stretch;
20817 }
20818
20819 return addr;
20820 }
20821
20822 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
20823 load. */
20824 static int
20825 relax_adr (fragS *fragp, asection *sec, long stretch)
20826 {
20827 addressT addr;
20828 offsetT val;
20829
20830 /* Assume worst case for symbols not known to be in the same section. */
20831 if (fragp->fr_symbol == NULL
20832 || !S_IS_DEFINED (fragp->fr_symbol)
20833 || sec != S_GET_SEGMENT (fragp->fr_symbol)
20834 || S_IS_WEAK (fragp->fr_symbol))
20835 return 4;
20836
20837 val = relaxed_symbol_addr (fragp, stretch);
20838 addr = fragp->fr_address + fragp->fr_fix;
20839 addr = (addr + 4) & ~3;
20840 /* Force misaligned targets to 32-bit variant. */
20841 if (val & 3)
20842 return 4;
20843 val -= addr;
20844 if (val < 0 || val > 1020)
20845 return 4;
20846 return 2;
20847 }
20848
20849 /* Return the size of a relaxable add/sub immediate instruction. */
20850 static int
20851 relax_addsub (fragS *fragp, asection *sec)
20852 {
20853 char *buf;
20854 int op;
20855
20856 buf = fragp->fr_literal + fragp->fr_fix;
20857 op = bfd_get_16(sec->owner, buf);
20858 if ((op & 0xf) == ((op >> 4) & 0xf))
20859 return relax_immediate (fragp, 8, 0);
20860 else
20861 return relax_immediate (fragp, 3, 0);
20862 }
20863
20864 /* Return TRUE iff the definition of symbol S could be pre-empted
20865 (overridden) at link or load time. */
20866 static bfd_boolean
20867 symbol_preemptible (symbolS *s)
20868 {
20869 /* Weak symbols can always be pre-empted. */
20870 if (S_IS_WEAK (s))
20871 return TRUE;
20872
20873 /* Non-global symbols cannot be pre-empted. */
20874 if (! S_IS_EXTERNAL (s))
20875 return FALSE;
20876
20877 #ifdef OBJ_ELF
20878 /* In ELF, a global symbol can be marked protected, or private. In that
20879 case it can't be pre-empted (other definitions in the same link unit
20880 would violate the ODR). */
20881 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
20882 return FALSE;
20883 #endif
20884
20885 /* Other global symbols might be pre-empted. */
20886 return TRUE;
20887 }
20888
20889 /* Return the size of a relaxable branch instruction. BITS is the
20890 size of the offset field in the narrow instruction. */
20891
20892 static int
20893 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
20894 {
20895 addressT addr;
20896 offsetT val;
20897 offsetT limit;
20898
20899 /* Assume worst case for symbols not known to be in the same section. */
20900 if (!S_IS_DEFINED (fragp->fr_symbol)
20901 || sec != S_GET_SEGMENT (fragp->fr_symbol)
20902 || S_IS_WEAK (fragp->fr_symbol))
20903 return 4;
20904
20905 #ifdef OBJ_ELF
20906 /* A branch to a function in ARM state will require interworking. */
20907 if (S_IS_DEFINED (fragp->fr_symbol)
20908 && ARM_IS_FUNC (fragp->fr_symbol))
20909 return 4;
20910 #endif
20911
20912 if (symbol_preemptible (fragp->fr_symbol))
20913 return 4;
20914
20915 val = relaxed_symbol_addr (fragp, stretch);
20916 addr = fragp->fr_address + fragp->fr_fix + 4;
20917 val -= addr;
20918
20919 /* Offset is a signed value *2 */
20920 limit = 1 << bits;
20921 if (val >= limit || val < -limit)
20922 return 4;
20923 return 2;
20924 }
20925
20926
20927 /* Relax a machine dependent frag. This returns the amount by which
20928 the current size of the frag should change. */
20929
20930 int
20931 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
20932 {
20933 int oldsize;
20934 int newsize;
20935
20936 oldsize = fragp->fr_var;
20937 switch (fragp->fr_subtype)
20938 {
20939 case T_MNEM_ldr_pc2:
20940 newsize = relax_adr (fragp, sec, stretch);
20941 break;
20942 case T_MNEM_ldr_pc:
20943 case T_MNEM_ldr_sp:
20944 case T_MNEM_str_sp:
20945 newsize = relax_immediate (fragp, 8, 2);
20946 break;
20947 case T_MNEM_ldr:
20948 case T_MNEM_str:
20949 newsize = relax_immediate (fragp, 5, 2);
20950 break;
20951 case T_MNEM_ldrh:
20952 case T_MNEM_strh:
20953 newsize = relax_immediate (fragp, 5, 1);
20954 break;
20955 case T_MNEM_ldrb:
20956 case T_MNEM_strb:
20957 newsize = relax_immediate (fragp, 5, 0);
20958 break;
20959 case T_MNEM_adr:
20960 newsize = relax_adr (fragp, sec, stretch);
20961 break;
20962 case T_MNEM_mov:
20963 case T_MNEM_movs:
20964 case T_MNEM_cmp:
20965 case T_MNEM_cmn:
20966 newsize = relax_immediate (fragp, 8, 0);
20967 break;
20968 case T_MNEM_b:
20969 newsize = relax_branch (fragp, sec, 11, stretch);
20970 break;
20971 case T_MNEM_bcond:
20972 newsize = relax_branch (fragp, sec, 8, stretch);
20973 break;
20974 case T_MNEM_add_sp:
20975 case T_MNEM_add_pc:
20976 newsize = relax_immediate (fragp, 8, 2);
20977 break;
20978 case T_MNEM_inc_sp:
20979 case T_MNEM_dec_sp:
20980 newsize = relax_immediate (fragp, 7, 2);
20981 break;
20982 case T_MNEM_addi:
20983 case T_MNEM_addis:
20984 case T_MNEM_subi:
20985 case T_MNEM_subis:
20986 newsize = relax_addsub (fragp, sec);
20987 break;
20988 default:
20989 abort ();
20990 }
20991
20992 fragp->fr_var = newsize;
20993 /* Freeze wide instructions that are at or before the same location as
20994 in the previous pass. This avoids infinite loops.
20995 Don't freeze them unconditionally because targets may be artificially
20996 misaligned by the expansion of preceding frags. */
20997 if (stretch <= 0 && newsize > 2)
20998 {
20999 md_convert_frag (sec->owner, sec, fragp);
21000 frag_wane (fragp);
21001 }
21002
21003 return newsize - oldsize;
21004 }
21005
21006 /* Round up a section size to the appropriate boundary. */
21007
21008 valueT
21009 md_section_align (segT segment ATTRIBUTE_UNUSED,
21010 valueT size)
21011 {
21012 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
21013 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
21014 {
21015 /* For a.out, force the section size to be aligned. If we don't do
21016 this, BFD will align it for us, but it will not write out the
21017 final bytes of the section. This may be a bug in BFD, but it is
21018 easier to fix it here since that is how the other a.out targets
21019 work. */
21020 int align;
21021
21022 align = bfd_get_section_alignment (stdoutput, segment);
21023 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
21024 }
21025 #endif
21026
21027 return size;
21028 }
21029
21030 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
21031 of an rs_align_code fragment. */
21032
21033 void
21034 arm_handle_align (fragS * fragP)
21035 {
21036 static char const arm_noop[2][2][4] =
21037 {
21038 { /* ARMv1 */
21039 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
21040 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
21041 },
21042 { /* ARMv6k */
21043 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
21044 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
21045 },
21046 };
21047 static char const thumb_noop[2][2][2] =
21048 {
21049 { /* Thumb-1 */
21050 {0xc0, 0x46}, /* LE */
21051 {0x46, 0xc0}, /* BE */
21052 },
21053 { /* Thumb-2 */
21054 {0x00, 0xbf}, /* LE */
21055 {0xbf, 0x00} /* BE */
21056 }
21057 };
21058 static char const wide_thumb_noop[2][4] =
21059 { /* Wide Thumb-2 */
21060 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
21061 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
21062 };
21063
21064 unsigned bytes, fix, noop_size;
21065 char * p;
21066 const char * noop;
21067 const char *narrow_noop = NULL;
21068 #ifdef OBJ_ELF
21069 enum mstate state;
21070 #endif
21071
21072 if (fragP->fr_type != rs_align_code)
21073 return;
21074
21075 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
21076 p = fragP->fr_literal + fragP->fr_fix;
21077 fix = 0;
21078
21079 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
21080 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
21081
21082 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
21083
21084 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
21085 {
21086 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21087 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
21088 {
21089 narrow_noop = thumb_noop[1][target_big_endian];
21090 noop = wide_thumb_noop[target_big_endian];
21091 }
21092 else
21093 noop = thumb_noop[0][target_big_endian];
21094 noop_size = 2;
21095 #ifdef OBJ_ELF
21096 state = MAP_THUMB;
21097 #endif
21098 }
21099 else
21100 {
21101 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21102 ? selected_cpu : arm_arch_none,
21103 arm_ext_v6k) != 0]
21104 [target_big_endian];
21105 noop_size = 4;
21106 #ifdef OBJ_ELF
21107 state = MAP_ARM;
21108 #endif
21109 }
21110
21111 fragP->fr_var = noop_size;
21112
21113 if (bytes & (noop_size - 1))
21114 {
21115 fix = bytes & (noop_size - 1);
21116 #ifdef OBJ_ELF
21117 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
21118 #endif
21119 memset (p, 0, fix);
21120 p += fix;
21121 bytes -= fix;
21122 }
21123
21124 if (narrow_noop)
21125 {
21126 if (bytes & noop_size)
21127 {
21128 /* Insert a narrow noop. */
21129 memcpy (p, narrow_noop, noop_size);
21130 p += noop_size;
21131 bytes -= noop_size;
21132 fix += noop_size;
21133 }
21134
21135 /* Use wide noops for the remainder */
21136 noop_size = 4;
21137 }
21138
21139 while (bytes >= noop_size)
21140 {
21141 memcpy (p, noop, noop_size);
21142 p += noop_size;
21143 bytes -= noop_size;
21144 fix += noop_size;
21145 }
21146
21147 fragP->fr_fix += fix;
21148 }
21149
21150 /* Called from md_do_align. Used to create an alignment
21151 frag in a code section. */
21152
21153 void
21154 arm_frag_align_code (int n, int max)
21155 {
21156 char * p;
21157
21158 /* We assume that there will never be a requirement
21159 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
21160 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
21161 {
21162 char err_msg[128];
21163
21164 sprintf (err_msg,
21165 _("alignments greater than %d bytes not supported in .text sections."),
21166 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
21167 as_fatal ("%s", err_msg);
21168 }
21169
21170 p = frag_var (rs_align_code,
21171 MAX_MEM_FOR_RS_ALIGN_CODE,
21172 1,
21173 (relax_substateT) max,
21174 (symbolS *) NULL,
21175 (offsetT) n,
21176 (char *) NULL);
21177 *p = 0;
21178 }
21179
21180 /* Perform target specific initialisation of a frag.
21181 Note - despite the name this initialisation is not done when the frag
21182 is created, but only when its type is assigned. A frag can be created
21183 and used a long time before its type is set, so beware of assuming that
21184 this initialisationis performed first. */
21185
21186 #ifndef OBJ_ELF
21187 void
21188 arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
21189 {
21190 /* Record whether this frag is in an ARM or a THUMB area. */
21191 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
21192 }
21193
21194 #else /* OBJ_ELF is defined. */
21195 void
21196 arm_init_frag (fragS * fragP, int max_chars)
21197 {
21198 int frag_thumb_mode;
21199
21200 /* If the current ARM vs THUMB mode has not already
21201 been recorded into this frag then do so now. */
21202 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
21203 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
21204
21205 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
21206
21207 /* Record a mapping symbol for alignment frags. We will delete this
21208 later if the alignment ends up empty. */
21209 switch (fragP->fr_type)
21210 {
21211 case rs_align:
21212 case rs_align_test:
21213 case rs_fill:
21214 mapping_state_2 (MAP_DATA, max_chars);
21215 break;
21216 case rs_align_code:
21217 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
21218 break;
21219 default:
21220 break;
21221 }
21222 }
21223
21224 /* When we change sections we need to issue a new mapping symbol. */
21225
21226 void
21227 arm_elf_change_section (void)
21228 {
21229 /* Link an unlinked unwind index table section to the .text section. */
21230 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
21231 && elf_linked_to_section (now_seg) == NULL)
21232 elf_linked_to_section (now_seg) = text_section;
21233 }
21234
21235 int
21236 arm_elf_section_type (const char * str, size_t len)
21237 {
21238 if (len == 5 && strncmp (str, "exidx", 5) == 0)
21239 return SHT_ARM_EXIDX;
21240
21241 return -1;
21242 }
21243 \f
21244 /* Code to deal with unwinding tables. */
21245
21246 static void add_unwind_adjustsp (offsetT);
21247
21248 /* Generate any deferred unwind frame offset. */
21249
21250 static void
21251 flush_pending_unwind (void)
21252 {
21253 offsetT offset;
21254
21255 offset = unwind.pending_offset;
21256 unwind.pending_offset = 0;
21257 if (offset != 0)
21258 add_unwind_adjustsp (offset);
21259 }
21260
21261 /* Add an opcode to this list for this function. Two-byte opcodes should
21262 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
21263 order. */
21264
21265 static void
21266 add_unwind_opcode (valueT op, int length)
21267 {
21268 /* Add any deferred stack adjustment. */
21269 if (unwind.pending_offset)
21270 flush_pending_unwind ();
21271
21272 unwind.sp_restored = 0;
21273
21274 if (unwind.opcode_count + length > unwind.opcode_alloc)
21275 {
21276 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
21277 if (unwind.opcodes)
21278 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
21279 unwind.opcode_alloc);
21280 else
21281 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
21282 }
21283 while (length > 0)
21284 {
21285 length--;
21286 unwind.opcodes[unwind.opcode_count] = op & 0xff;
21287 op >>= 8;
21288 unwind.opcode_count++;
21289 }
21290 }
21291
21292 /* Add unwind opcodes to adjust the stack pointer. */
21293
21294 static void
21295 add_unwind_adjustsp (offsetT offset)
21296 {
21297 valueT op;
21298
21299 if (offset > 0x200)
21300 {
21301 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
21302 char bytes[5];
21303 int n;
21304 valueT o;
21305
21306 /* Long form: 0xb2, uleb128. */
21307 /* This might not fit in a word so add the individual bytes,
21308 remembering the list is built in reverse order. */
21309 o = (valueT) ((offset - 0x204) >> 2);
21310 if (o == 0)
21311 add_unwind_opcode (0, 1);
21312
21313 /* Calculate the uleb128 encoding of the offset. */
21314 n = 0;
21315 while (o)
21316 {
21317 bytes[n] = o & 0x7f;
21318 o >>= 7;
21319 if (o)
21320 bytes[n] |= 0x80;
21321 n++;
21322 }
21323 /* Add the insn. */
21324 for (; n; n--)
21325 add_unwind_opcode (bytes[n - 1], 1);
21326 add_unwind_opcode (0xb2, 1);
21327 }
21328 else if (offset > 0x100)
21329 {
21330 /* Two short opcodes. */
21331 add_unwind_opcode (0x3f, 1);
21332 op = (offset - 0x104) >> 2;
21333 add_unwind_opcode (op, 1);
21334 }
21335 else if (offset > 0)
21336 {
21337 /* Short opcode. */
21338 op = (offset - 4) >> 2;
21339 add_unwind_opcode (op, 1);
21340 }
21341 else if (offset < 0)
21342 {
21343 offset = -offset;
21344 while (offset > 0x100)
21345 {
21346 add_unwind_opcode (0x7f, 1);
21347 offset -= 0x100;
21348 }
21349 op = ((offset - 4) >> 2) | 0x40;
21350 add_unwind_opcode (op, 1);
21351 }
21352 }
21353
21354 /* Finish the list of unwind opcodes for this function. */
21355 static void
21356 finish_unwind_opcodes (void)
21357 {
21358 valueT op;
21359
21360 if (unwind.fp_used)
21361 {
21362 /* Adjust sp as necessary. */
21363 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
21364 flush_pending_unwind ();
21365
21366 /* After restoring sp from the frame pointer. */
21367 op = 0x90 | unwind.fp_reg;
21368 add_unwind_opcode (op, 1);
21369 }
21370 else
21371 flush_pending_unwind ();
21372 }
21373
21374
21375 /* Start an exception table entry. If idx is nonzero this is an index table
21376 entry. */
21377
21378 static void
21379 start_unwind_section (const segT text_seg, int idx)
21380 {
21381 const char * text_name;
21382 const char * prefix;
21383 const char * prefix_once;
21384 const char * group_name;
21385 size_t prefix_len;
21386 size_t text_len;
21387 char * sec_name;
21388 size_t sec_name_len;
21389 int type;
21390 int flags;
21391 int linkonce;
21392
21393 if (idx)
21394 {
21395 prefix = ELF_STRING_ARM_unwind;
21396 prefix_once = ELF_STRING_ARM_unwind_once;
21397 type = SHT_ARM_EXIDX;
21398 }
21399 else
21400 {
21401 prefix = ELF_STRING_ARM_unwind_info;
21402 prefix_once = ELF_STRING_ARM_unwind_info_once;
21403 type = SHT_PROGBITS;
21404 }
21405
21406 text_name = segment_name (text_seg);
21407 if (streq (text_name, ".text"))
21408 text_name = "";
21409
21410 if (strncmp (text_name, ".gnu.linkonce.t.",
21411 strlen (".gnu.linkonce.t.")) == 0)
21412 {
21413 prefix = prefix_once;
21414 text_name += strlen (".gnu.linkonce.t.");
21415 }
21416
21417 prefix_len = strlen (prefix);
21418 text_len = strlen (text_name);
21419 sec_name_len = prefix_len + text_len;
21420 sec_name = (char *) xmalloc (sec_name_len + 1);
21421 memcpy (sec_name, prefix, prefix_len);
21422 memcpy (sec_name + prefix_len, text_name, text_len);
21423 sec_name[prefix_len + text_len] = '\0';
21424
21425 flags = SHF_ALLOC;
21426 linkonce = 0;
21427 group_name = 0;
21428
21429 /* Handle COMDAT group. */
21430 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
21431 {
21432 group_name = elf_group_name (text_seg);
21433 if (group_name == NULL)
21434 {
21435 as_bad (_("Group section `%s' has no group signature"),
21436 segment_name (text_seg));
21437 ignore_rest_of_line ();
21438 return;
21439 }
21440 flags |= SHF_GROUP;
21441 linkonce = 1;
21442 }
21443
21444 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
21445
21446 /* Set the section link for index tables. */
21447 if (idx)
21448 elf_linked_to_section (now_seg) = text_seg;
21449 }
21450
21451
21452 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
21453 personality routine data. Returns zero, or the index table value for
21454 an inline entry. */
21455
21456 static valueT
21457 create_unwind_entry (int have_data)
21458 {
21459 int size;
21460 addressT where;
21461 char *ptr;
21462 /* The current word of data. */
21463 valueT data;
21464 /* The number of bytes left in this word. */
21465 int n;
21466
21467 finish_unwind_opcodes ();
21468
21469 /* Remember the current text section. */
21470 unwind.saved_seg = now_seg;
21471 unwind.saved_subseg = now_subseg;
21472
21473 start_unwind_section (now_seg, 0);
21474
21475 if (unwind.personality_routine == NULL)
21476 {
21477 if (unwind.personality_index == -2)
21478 {
21479 if (have_data)
21480 as_bad (_("handlerdata in cantunwind frame"));
21481 return 1; /* EXIDX_CANTUNWIND. */
21482 }
21483
21484 /* Use a default personality routine if none is specified. */
21485 if (unwind.personality_index == -1)
21486 {
21487 if (unwind.opcode_count > 3)
21488 unwind.personality_index = 1;
21489 else
21490 unwind.personality_index = 0;
21491 }
21492
21493 /* Space for the personality routine entry. */
21494 if (unwind.personality_index == 0)
21495 {
21496 if (unwind.opcode_count > 3)
21497 as_bad (_("too many unwind opcodes for personality routine 0"));
21498
21499 if (!have_data)
21500 {
21501 /* All the data is inline in the index table. */
21502 data = 0x80;
21503 n = 3;
21504 while (unwind.opcode_count > 0)
21505 {
21506 unwind.opcode_count--;
21507 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
21508 n--;
21509 }
21510
21511 /* Pad with "finish" opcodes. */
21512 while (n--)
21513 data = (data << 8) | 0xb0;
21514
21515 return data;
21516 }
21517 size = 0;
21518 }
21519 else
21520 /* We get two opcodes "free" in the first word. */
21521 size = unwind.opcode_count - 2;
21522 }
21523 else
21524 {
21525 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
21526 if (unwind.personality_index != -1)
21527 {
21528 as_bad (_("attempt to recreate an unwind entry"));
21529 return 1;
21530 }
21531
21532 /* An extra byte is required for the opcode count. */
21533 size = unwind.opcode_count + 1;
21534 }
21535
21536 size = (size + 3) >> 2;
21537 if (size > 0xff)
21538 as_bad (_("too many unwind opcodes"));
21539
21540 frag_align (2, 0, 0);
21541 record_alignment (now_seg, 2);
21542 unwind.table_entry = expr_build_dot ();
21543
21544 /* Allocate the table entry. */
21545 ptr = frag_more ((size << 2) + 4);
21546 /* PR 13449: Zero the table entries in case some of them are not used. */
21547 memset (ptr, 0, (size << 2) + 4);
21548 where = frag_now_fix () - ((size << 2) + 4);
21549
21550 switch (unwind.personality_index)
21551 {
21552 case -1:
21553 /* ??? Should this be a PLT generating relocation? */
21554 /* Custom personality routine. */
21555 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
21556 BFD_RELOC_ARM_PREL31);
21557
21558 where += 4;
21559 ptr += 4;
21560
21561 /* Set the first byte to the number of additional words. */
21562 data = size > 0 ? size - 1 : 0;
21563 n = 3;
21564 break;
21565
21566 /* ABI defined personality routines. */
21567 case 0:
21568 /* Three opcodes bytes are packed into the first word. */
21569 data = 0x80;
21570 n = 3;
21571 break;
21572
21573 case 1:
21574 case 2:
21575 /* The size and first two opcode bytes go in the first word. */
21576 data = ((0x80 + unwind.personality_index) << 8) | size;
21577 n = 2;
21578 break;
21579
21580 default:
21581 /* Should never happen. */
21582 abort ();
21583 }
21584
21585 /* Pack the opcodes into words (MSB first), reversing the list at the same
21586 time. */
21587 while (unwind.opcode_count > 0)
21588 {
21589 if (n == 0)
21590 {
21591 md_number_to_chars (ptr, data, 4);
21592 ptr += 4;
21593 n = 4;
21594 data = 0;
21595 }
21596 unwind.opcode_count--;
21597 n--;
21598 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
21599 }
21600
21601 /* Finish off the last word. */
21602 if (n < 4)
21603 {
21604 /* Pad with "finish" opcodes. */
21605 while (n--)
21606 data = (data << 8) | 0xb0;
21607
21608 md_number_to_chars (ptr, data, 4);
21609 }
21610
21611 if (!have_data)
21612 {
21613 /* Add an empty descriptor if there is no user-specified data. */
21614 ptr = frag_more (4);
21615 md_number_to_chars (ptr, 0, 4);
21616 }
21617
21618 return 0;
21619 }
21620
21621
21622 /* Initialize the DWARF-2 unwind information for this procedure. */
21623
21624 void
21625 tc_arm_frame_initial_instructions (void)
21626 {
21627 cfi_add_CFA_def_cfa (REG_SP, 0);
21628 }
21629 #endif /* OBJ_ELF */
21630
21631 /* Convert REGNAME to a DWARF-2 register number. */
21632
21633 int
21634 tc_arm_regname_to_dw2regnum (char *regname)
21635 {
21636 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
21637 if (reg != FAIL)
21638 return reg;
21639
21640 /* PR 16694: Allow VFP registers as well. */
21641 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
21642 if (reg != FAIL)
21643 return 64 + reg;
21644
21645 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
21646 if (reg != FAIL)
21647 return reg + 256;
21648
21649 return -1;
21650 }
21651
21652 #ifdef TE_PE
21653 void
21654 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
21655 {
21656 expressionS exp;
21657
21658 exp.X_op = O_secrel;
21659 exp.X_add_symbol = symbol;
21660 exp.X_add_number = 0;
21661 emit_expr (&exp, size);
21662 }
21663 #endif
21664
21665 /* MD interface: Symbol and relocation handling. */
21666
21667 /* Return the address within the segment that a PC-relative fixup is
21668 relative to. For ARM, PC-relative fixups applied to instructions
21669 are generally relative to the location of the fixup plus 8 bytes.
21670 Thumb branches are offset by 4, and Thumb loads relative to PC
21671 require special handling. */
21672
21673 long
21674 md_pcrel_from_section (fixS * fixP, segT seg)
21675 {
21676 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
21677
21678 /* If this is pc-relative and we are going to emit a relocation
21679 then we just want to put out any pipeline compensation that the linker
21680 will need. Otherwise we want to use the calculated base.
21681 For WinCE we skip the bias for externals as well, since this
21682 is how the MS ARM-CE assembler behaves and we want to be compatible. */
21683 if (fixP->fx_pcrel
21684 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
21685 || (arm_force_relocation (fixP)
21686 #ifdef TE_WINCE
21687 && !S_IS_EXTERNAL (fixP->fx_addsy)
21688 #endif
21689 )))
21690 base = 0;
21691
21692
21693 switch (fixP->fx_r_type)
21694 {
21695 /* PC relative addressing on the Thumb is slightly odd as the
21696 bottom two bits of the PC are forced to zero for the
21697 calculation. This happens *after* application of the
21698 pipeline offset. However, Thumb adrl already adjusts for
21699 this, so we need not do it again. */
21700 case BFD_RELOC_ARM_THUMB_ADD:
21701 return base & ~3;
21702
21703 case BFD_RELOC_ARM_THUMB_OFFSET:
21704 case BFD_RELOC_ARM_T32_OFFSET_IMM:
21705 case BFD_RELOC_ARM_T32_ADD_PC12:
21706 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
21707 return (base + 4) & ~3;
21708
21709 /* Thumb branches are simply offset by +4. */
21710 case BFD_RELOC_THUMB_PCREL_BRANCH7:
21711 case BFD_RELOC_THUMB_PCREL_BRANCH9:
21712 case BFD_RELOC_THUMB_PCREL_BRANCH12:
21713 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21714 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21715 return base + 4;
21716
21717 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21718 if (fixP->fx_addsy
21719 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21720 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21721 && ARM_IS_FUNC (fixP->fx_addsy)
21722 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21723 base = fixP->fx_where + fixP->fx_frag->fr_address;
21724 return base + 4;
21725
21726 /* BLX is like branches above, but forces the low two bits of PC to
21727 zero. */
21728 case BFD_RELOC_THUMB_PCREL_BLX:
21729 if (fixP->fx_addsy
21730 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21731 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21732 && THUMB_IS_FUNC (fixP->fx_addsy)
21733 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21734 base = fixP->fx_where + fixP->fx_frag->fr_address;
21735 return (base + 4) & ~3;
21736
21737 /* ARM mode branches are offset by +8. However, the Windows CE
21738 loader expects the relocation not to take this into account. */
21739 case BFD_RELOC_ARM_PCREL_BLX:
21740 if (fixP->fx_addsy
21741 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21742 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21743 && ARM_IS_FUNC (fixP->fx_addsy)
21744 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21745 base = fixP->fx_where + fixP->fx_frag->fr_address;
21746 return base + 8;
21747
21748 case BFD_RELOC_ARM_PCREL_CALL:
21749 if (fixP->fx_addsy
21750 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21751 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21752 && THUMB_IS_FUNC (fixP->fx_addsy)
21753 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21754 base = fixP->fx_where + fixP->fx_frag->fr_address;
21755 return base + 8;
21756
21757 case BFD_RELOC_ARM_PCREL_BRANCH:
21758 case BFD_RELOC_ARM_PCREL_JUMP:
21759 case BFD_RELOC_ARM_PLT32:
21760 #ifdef TE_WINCE
21761 /* When handling fixups immediately, because we have already
21762 discovered the value of a symbol, or the address of the frag involved
21763 we must account for the offset by +8, as the OS loader will never see the reloc.
21764 see fixup_segment() in write.c
21765 The S_IS_EXTERNAL test handles the case of global symbols.
21766 Those need the calculated base, not just the pipe compensation the linker will need. */
21767 if (fixP->fx_pcrel
21768 && fixP->fx_addsy != NULL
21769 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21770 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
21771 return base + 8;
21772 return base;
21773 #else
21774 return base + 8;
21775 #endif
21776
21777
21778 /* ARM mode loads relative to PC are also offset by +8. Unlike
21779 branches, the Windows CE loader *does* expect the relocation
21780 to take this into account. */
21781 case BFD_RELOC_ARM_OFFSET_IMM:
21782 case BFD_RELOC_ARM_OFFSET_IMM8:
21783 case BFD_RELOC_ARM_HWLITERAL:
21784 case BFD_RELOC_ARM_LITERAL:
21785 case BFD_RELOC_ARM_CP_OFF_IMM:
21786 return base + 8;
21787
21788
21789 /* Other PC-relative relocations are un-offset. */
21790 default:
21791 return base;
21792 }
21793 }
21794
21795 static bfd_boolean flag_warn_syms = TRUE;
21796
21797 bfd_boolean
21798 arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
21799 {
21800 /* PR 18347 - Warn if the user attempts to create a symbol with the same
21801 name as an ARM instruction. Whilst strictly speaking it is allowed, it
21802 does mean that the resulting code might be very confusing to the reader.
21803 Also this warning can be triggered if the user omits an operand before
21804 an immediate address, eg:
21805
21806 LDR =foo
21807
21808 GAS treats this as an assignment of the value of the symbol foo to a
21809 symbol LDR, and so (without this code) it will not issue any kind of
21810 warning or error message.
21811
21812 Note - ARM instructions are case-insensitive but the strings in the hash
21813 table are all stored in lower case, so we must first ensure that name is
21814 lower case too. */
21815 if (flag_warn_syms && arm_ops_hsh)
21816 {
21817 char * nbuf = strdup (name);
21818 char * p;
21819
21820 for (p = nbuf; *p; p++)
21821 *p = TOLOWER (*p);
21822 if (hash_find (arm_ops_hsh, nbuf) != NULL)
21823 {
21824 static struct hash_control * already_warned = NULL;
21825
21826 if (already_warned == NULL)
21827 already_warned = hash_new ();
21828 /* Only warn about the symbol once. To keep the code
21829 simple we let hash_insert do the lookup for us. */
21830 if (hash_insert (already_warned, name, NULL) == NULL)
21831 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
21832 }
21833 else
21834 free (nbuf);
21835 }
21836
21837 return FALSE;
21838 }
21839
21840 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
21841 Otherwise we have no need to default values of symbols. */
21842
21843 symbolS *
21844 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
21845 {
21846 #ifdef OBJ_ELF
21847 if (name[0] == '_' && name[1] == 'G'
21848 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
21849 {
21850 if (!GOT_symbol)
21851 {
21852 if (symbol_find (name))
21853 as_bad (_("GOT already in the symbol table"));
21854
21855 GOT_symbol = symbol_new (name, undefined_section,
21856 (valueT) 0, & zero_address_frag);
21857 }
21858
21859 return GOT_symbol;
21860 }
21861 #endif
21862
21863 return NULL;
21864 }
21865
21866 /* Subroutine of md_apply_fix. Check to see if an immediate can be
21867 computed as two separate immediate values, added together. We
21868 already know that this value cannot be computed by just one ARM
21869 instruction. */
21870
21871 static unsigned int
21872 validate_immediate_twopart (unsigned int val,
21873 unsigned int * highpart)
21874 {
21875 unsigned int a;
21876 unsigned int i;
21877
21878 for (i = 0; i < 32; i += 2)
21879 if (((a = rotate_left (val, i)) & 0xff) != 0)
21880 {
21881 if (a & 0xff00)
21882 {
21883 if (a & ~ 0xffff)
21884 continue;
21885 * highpart = (a >> 8) | ((i + 24) << 7);
21886 }
21887 else if (a & 0xff0000)
21888 {
21889 if (a & 0xff000000)
21890 continue;
21891 * highpart = (a >> 16) | ((i + 16) << 7);
21892 }
21893 else
21894 {
21895 gas_assert (a & 0xff000000);
21896 * highpart = (a >> 24) | ((i + 8) << 7);
21897 }
21898
21899 return (a & 0xff) | (i << 7);
21900 }
21901
21902 return FAIL;
21903 }
21904
21905 static int
21906 validate_offset_imm (unsigned int val, int hwse)
21907 {
21908 if ((hwse && val > 255) || val > 4095)
21909 return FAIL;
21910 return val;
21911 }
21912
21913 /* Subroutine of md_apply_fix. Do those data_ops which can take a
21914 negative immediate constant by altering the instruction. A bit of
21915 a hack really.
21916 MOV <-> MVN
21917 AND <-> BIC
21918 ADC <-> SBC
21919 by inverting the second operand, and
21920 ADD <-> SUB
21921 CMP <-> CMN
21922 by negating the second operand. */
21923
21924 static int
21925 negate_data_op (unsigned long * instruction,
21926 unsigned long value)
21927 {
21928 int op, new_inst;
21929 unsigned long negated, inverted;
21930
21931 negated = encode_arm_immediate (-value);
21932 inverted = encode_arm_immediate (~value);
21933
21934 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
21935 switch (op)
21936 {
21937 /* First negates. */
21938 case OPCODE_SUB: /* ADD <-> SUB */
21939 new_inst = OPCODE_ADD;
21940 value = negated;
21941 break;
21942
21943 case OPCODE_ADD:
21944 new_inst = OPCODE_SUB;
21945 value = negated;
21946 break;
21947
21948 case OPCODE_CMP: /* CMP <-> CMN */
21949 new_inst = OPCODE_CMN;
21950 value = negated;
21951 break;
21952
21953 case OPCODE_CMN:
21954 new_inst = OPCODE_CMP;
21955 value = negated;
21956 break;
21957
21958 /* Now Inverted ops. */
21959 case OPCODE_MOV: /* MOV <-> MVN */
21960 new_inst = OPCODE_MVN;
21961 value = inverted;
21962 break;
21963
21964 case OPCODE_MVN:
21965 new_inst = OPCODE_MOV;
21966 value = inverted;
21967 break;
21968
21969 case OPCODE_AND: /* AND <-> BIC */
21970 new_inst = OPCODE_BIC;
21971 value = inverted;
21972 break;
21973
21974 case OPCODE_BIC:
21975 new_inst = OPCODE_AND;
21976 value = inverted;
21977 break;
21978
21979 case OPCODE_ADC: /* ADC <-> SBC */
21980 new_inst = OPCODE_SBC;
21981 value = inverted;
21982 break;
21983
21984 case OPCODE_SBC:
21985 new_inst = OPCODE_ADC;
21986 value = inverted;
21987 break;
21988
21989 /* We cannot do anything. */
21990 default:
21991 return FAIL;
21992 }
21993
21994 if (value == (unsigned) FAIL)
21995 return FAIL;
21996
21997 *instruction &= OPCODE_MASK;
21998 *instruction |= new_inst << DATA_OP_SHIFT;
21999 return value;
22000 }
22001
22002 /* Like negate_data_op, but for Thumb-2. */
22003
22004 static unsigned int
22005 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
22006 {
22007 int op, new_inst;
22008 int rd;
22009 unsigned int negated, inverted;
22010
22011 negated = encode_thumb32_immediate (-value);
22012 inverted = encode_thumb32_immediate (~value);
22013
22014 rd = (*instruction >> 8) & 0xf;
22015 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
22016 switch (op)
22017 {
22018 /* ADD <-> SUB. Includes CMP <-> CMN. */
22019 case T2_OPCODE_SUB:
22020 new_inst = T2_OPCODE_ADD;
22021 value = negated;
22022 break;
22023
22024 case T2_OPCODE_ADD:
22025 new_inst = T2_OPCODE_SUB;
22026 value = negated;
22027 break;
22028
22029 /* ORR <-> ORN. Includes MOV <-> MVN. */
22030 case T2_OPCODE_ORR:
22031 new_inst = T2_OPCODE_ORN;
22032 value = inverted;
22033 break;
22034
22035 case T2_OPCODE_ORN:
22036 new_inst = T2_OPCODE_ORR;
22037 value = inverted;
22038 break;
22039
22040 /* AND <-> BIC. TST has no inverted equivalent. */
22041 case T2_OPCODE_AND:
22042 new_inst = T2_OPCODE_BIC;
22043 if (rd == 15)
22044 value = FAIL;
22045 else
22046 value = inverted;
22047 break;
22048
22049 case T2_OPCODE_BIC:
22050 new_inst = T2_OPCODE_AND;
22051 value = inverted;
22052 break;
22053
22054 /* ADC <-> SBC */
22055 case T2_OPCODE_ADC:
22056 new_inst = T2_OPCODE_SBC;
22057 value = inverted;
22058 break;
22059
22060 case T2_OPCODE_SBC:
22061 new_inst = T2_OPCODE_ADC;
22062 value = inverted;
22063 break;
22064
22065 /* We cannot do anything. */
22066 default:
22067 return FAIL;
22068 }
22069
22070 if (value == (unsigned int)FAIL)
22071 return FAIL;
22072
22073 *instruction &= T2_OPCODE_MASK;
22074 *instruction |= new_inst << T2_DATA_OP_SHIFT;
22075 return value;
22076 }
22077
22078 /* Read a 32-bit thumb instruction from buf. */
22079 static unsigned long
22080 get_thumb32_insn (char * buf)
22081 {
22082 unsigned long insn;
22083 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
22084 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22085
22086 return insn;
22087 }
22088
22089
22090 /* We usually want to set the low bit on the address of thumb function
22091 symbols. In particular .word foo - . should have the low bit set.
22092 Generic code tries to fold the difference of two symbols to
22093 a constant. Prevent this and force a relocation when the first symbols
22094 is a thumb function. */
22095
22096 bfd_boolean
22097 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
22098 {
22099 if (op == O_subtract
22100 && l->X_op == O_symbol
22101 && r->X_op == O_symbol
22102 && THUMB_IS_FUNC (l->X_add_symbol))
22103 {
22104 l->X_op = O_subtract;
22105 l->X_op_symbol = r->X_add_symbol;
22106 l->X_add_number -= r->X_add_number;
22107 return TRUE;
22108 }
22109
22110 /* Process as normal. */
22111 return FALSE;
22112 }
22113
22114 /* Encode Thumb2 unconditional branches and calls. The encoding
22115 for the 2 are identical for the immediate values. */
22116
22117 static void
22118 encode_thumb2_b_bl_offset (char * buf, offsetT value)
22119 {
22120 #define T2I1I2MASK ((1 << 13) | (1 << 11))
22121 offsetT newval;
22122 offsetT newval2;
22123 addressT S, I1, I2, lo, hi;
22124
22125 S = (value >> 24) & 0x01;
22126 I1 = (value >> 23) & 0x01;
22127 I2 = (value >> 22) & 0x01;
22128 hi = (value >> 12) & 0x3ff;
22129 lo = (value >> 1) & 0x7ff;
22130 newval = md_chars_to_number (buf, THUMB_SIZE);
22131 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22132 newval |= (S << 10) | hi;
22133 newval2 &= ~T2I1I2MASK;
22134 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
22135 md_number_to_chars (buf, newval, THUMB_SIZE);
22136 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
22137 }
22138
22139 void
22140 md_apply_fix (fixS * fixP,
22141 valueT * valP,
22142 segT seg)
22143 {
22144 offsetT value = * valP;
22145 offsetT newval;
22146 unsigned int newimm;
22147 unsigned long temp;
22148 int sign;
22149 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
22150
22151 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
22152
22153 /* Note whether this will delete the relocation. */
22154
22155 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
22156 fixP->fx_done = 1;
22157
22158 /* On a 64-bit host, silently truncate 'value' to 32 bits for
22159 consistency with the behaviour on 32-bit hosts. Remember value
22160 for emit_reloc. */
22161 value &= 0xffffffff;
22162 value ^= 0x80000000;
22163 value -= 0x80000000;
22164
22165 *valP = value;
22166 fixP->fx_addnumber = value;
22167
22168 /* Same treatment for fixP->fx_offset. */
22169 fixP->fx_offset &= 0xffffffff;
22170 fixP->fx_offset ^= 0x80000000;
22171 fixP->fx_offset -= 0x80000000;
22172
22173 switch (fixP->fx_r_type)
22174 {
22175 case BFD_RELOC_NONE:
22176 /* This will need to go in the object file. */
22177 fixP->fx_done = 0;
22178 break;
22179
22180 case BFD_RELOC_ARM_IMMEDIATE:
22181 /* We claim that this fixup has been processed here,
22182 even if in fact we generate an error because we do
22183 not have a reloc for it, so tc_gen_reloc will reject it. */
22184 fixP->fx_done = 1;
22185
22186 if (fixP->fx_addsy)
22187 {
22188 const char *msg = 0;
22189
22190 if (! S_IS_DEFINED (fixP->fx_addsy))
22191 msg = _("undefined symbol %s used as an immediate value");
22192 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22193 msg = _("symbol %s is in a different section");
22194 else if (S_IS_WEAK (fixP->fx_addsy))
22195 msg = _("symbol %s is weak and may be overridden later");
22196
22197 if (msg)
22198 {
22199 as_bad_where (fixP->fx_file, fixP->fx_line,
22200 msg, S_GET_NAME (fixP->fx_addsy));
22201 break;
22202 }
22203 }
22204
22205 temp = md_chars_to_number (buf, INSN_SIZE);
22206
22207 /* If the offset is negative, we should use encoding A2 for ADR. */
22208 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
22209 newimm = negate_data_op (&temp, value);
22210 else
22211 {
22212 newimm = encode_arm_immediate (value);
22213
22214 /* If the instruction will fail, see if we can fix things up by
22215 changing the opcode. */
22216 if (newimm == (unsigned int) FAIL)
22217 newimm = negate_data_op (&temp, value);
22218 }
22219
22220 if (newimm == (unsigned int) FAIL)
22221 {
22222 as_bad_where (fixP->fx_file, fixP->fx_line,
22223 _("invalid constant (%lx) after fixup"),
22224 (unsigned long) value);
22225 break;
22226 }
22227
22228 newimm |= (temp & 0xfffff000);
22229 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
22230 break;
22231
22232 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
22233 {
22234 unsigned int highpart = 0;
22235 unsigned int newinsn = 0xe1a00000; /* nop. */
22236
22237 if (fixP->fx_addsy)
22238 {
22239 const char *msg = 0;
22240
22241 if (! S_IS_DEFINED (fixP->fx_addsy))
22242 msg = _("undefined symbol %s used as an immediate value");
22243 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22244 msg = _("symbol %s is in a different section");
22245 else if (S_IS_WEAK (fixP->fx_addsy))
22246 msg = _("symbol %s is weak and may be overridden later");
22247
22248 if (msg)
22249 {
22250 as_bad_where (fixP->fx_file, fixP->fx_line,
22251 msg, S_GET_NAME (fixP->fx_addsy));
22252 break;
22253 }
22254 }
22255
22256 newimm = encode_arm_immediate (value);
22257 temp = md_chars_to_number (buf, INSN_SIZE);
22258
22259 /* If the instruction will fail, see if we can fix things up by
22260 changing the opcode. */
22261 if (newimm == (unsigned int) FAIL
22262 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
22263 {
22264 /* No ? OK - try using two ADD instructions to generate
22265 the value. */
22266 newimm = validate_immediate_twopart (value, & highpart);
22267
22268 /* Yes - then make sure that the second instruction is
22269 also an add. */
22270 if (newimm != (unsigned int) FAIL)
22271 newinsn = temp;
22272 /* Still No ? Try using a negated value. */
22273 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
22274 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
22275 /* Otherwise - give up. */
22276 else
22277 {
22278 as_bad_where (fixP->fx_file, fixP->fx_line,
22279 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
22280 (long) value);
22281 break;
22282 }
22283
22284 /* Replace the first operand in the 2nd instruction (which
22285 is the PC) with the destination register. We have
22286 already added in the PC in the first instruction and we
22287 do not want to do it again. */
22288 newinsn &= ~ 0xf0000;
22289 newinsn |= ((newinsn & 0x0f000) << 4);
22290 }
22291
22292 newimm |= (temp & 0xfffff000);
22293 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
22294
22295 highpart |= (newinsn & 0xfffff000);
22296 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
22297 }
22298 break;
22299
22300 case BFD_RELOC_ARM_OFFSET_IMM:
22301 if (!fixP->fx_done && seg->use_rela_p)
22302 value = 0;
22303
22304 case BFD_RELOC_ARM_LITERAL:
22305 sign = value > 0;
22306
22307 if (value < 0)
22308 value = - value;
22309
22310 if (validate_offset_imm (value, 0) == FAIL)
22311 {
22312 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
22313 as_bad_where (fixP->fx_file, fixP->fx_line,
22314 _("invalid literal constant: pool needs to be closer"));
22315 else
22316 as_bad_where (fixP->fx_file, fixP->fx_line,
22317 _("bad immediate value for offset (%ld)"),
22318 (long) value);
22319 break;
22320 }
22321
22322 newval = md_chars_to_number (buf, INSN_SIZE);
22323 if (value == 0)
22324 newval &= 0xfffff000;
22325 else
22326 {
22327 newval &= 0xff7ff000;
22328 newval |= value | (sign ? INDEX_UP : 0);
22329 }
22330 md_number_to_chars (buf, newval, INSN_SIZE);
22331 break;
22332
22333 case BFD_RELOC_ARM_OFFSET_IMM8:
22334 case BFD_RELOC_ARM_HWLITERAL:
22335 sign = value > 0;
22336
22337 if (value < 0)
22338 value = - value;
22339
22340 if (validate_offset_imm (value, 1) == FAIL)
22341 {
22342 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
22343 as_bad_where (fixP->fx_file, fixP->fx_line,
22344 _("invalid literal constant: pool needs to be closer"));
22345 else
22346 as_bad_where (fixP->fx_file, fixP->fx_line,
22347 _("bad immediate value for 8-bit offset (%ld)"),
22348 (long) value);
22349 break;
22350 }
22351
22352 newval = md_chars_to_number (buf, INSN_SIZE);
22353 if (value == 0)
22354 newval &= 0xfffff0f0;
22355 else
22356 {
22357 newval &= 0xff7ff0f0;
22358 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
22359 }
22360 md_number_to_chars (buf, newval, INSN_SIZE);
22361 break;
22362
22363 case BFD_RELOC_ARM_T32_OFFSET_U8:
22364 if (value < 0 || value > 1020 || value % 4 != 0)
22365 as_bad_where (fixP->fx_file, fixP->fx_line,
22366 _("bad immediate value for offset (%ld)"), (long) value);
22367 value /= 4;
22368
22369 newval = md_chars_to_number (buf+2, THUMB_SIZE);
22370 newval |= value;
22371 md_number_to_chars (buf+2, newval, THUMB_SIZE);
22372 break;
22373
22374 case BFD_RELOC_ARM_T32_OFFSET_IMM:
22375 /* This is a complicated relocation used for all varieties of Thumb32
22376 load/store instruction with immediate offset:
22377
22378 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
22379 *4, optional writeback(W)
22380 (doubleword load/store)
22381
22382 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
22383 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
22384 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
22385 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
22386 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
22387
22388 Uppercase letters indicate bits that are already encoded at
22389 this point. Lowercase letters are our problem. For the
22390 second block of instructions, the secondary opcode nybble
22391 (bits 8..11) is present, and bit 23 is zero, even if this is
22392 a PC-relative operation. */
22393 newval = md_chars_to_number (buf, THUMB_SIZE);
22394 newval <<= 16;
22395 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
22396
22397 if ((newval & 0xf0000000) == 0xe0000000)
22398 {
22399 /* Doubleword load/store: 8-bit offset, scaled by 4. */
22400 if (value >= 0)
22401 newval |= (1 << 23);
22402 else
22403 value = -value;
22404 if (value % 4 != 0)
22405 {
22406 as_bad_where (fixP->fx_file, fixP->fx_line,
22407 _("offset not a multiple of 4"));
22408 break;
22409 }
22410 value /= 4;
22411 if (value > 0xff)
22412 {
22413 as_bad_where (fixP->fx_file, fixP->fx_line,
22414 _("offset out of range"));
22415 break;
22416 }
22417 newval &= ~0xff;
22418 }
22419 else if ((newval & 0x000f0000) == 0x000f0000)
22420 {
22421 /* PC-relative, 12-bit offset. */
22422 if (value >= 0)
22423 newval |= (1 << 23);
22424 else
22425 value = -value;
22426 if (value > 0xfff)
22427 {
22428 as_bad_where (fixP->fx_file, fixP->fx_line,
22429 _("offset out of range"));
22430 break;
22431 }
22432 newval &= ~0xfff;
22433 }
22434 else if ((newval & 0x00000100) == 0x00000100)
22435 {
22436 /* Writeback: 8-bit, +/- offset. */
22437 if (value >= 0)
22438 newval |= (1 << 9);
22439 else
22440 value = -value;
22441 if (value > 0xff)
22442 {
22443 as_bad_where (fixP->fx_file, fixP->fx_line,
22444 _("offset out of range"));
22445 break;
22446 }
22447 newval &= ~0xff;
22448 }
22449 else if ((newval & 0x00000f00) == 0x00000e00)
22450 {
22451 /* T-instruction: positive 8-bit offset. */
22452 if (value < 0 || value > 0xff)
22453 {
22454 as_bad_where (fixP->fx_file, fixP->fx_line,
22455 _("offset out of range"));
22456 break;
22457 }
22458 newval &= ~0xff;
22459 newval |= value;
22460 }
22461 else
22462 {
22463 /* Positive 12-bit or negative 8-bit offset. */
22464 int limit;
22465 if (value >= 0)
22466 {
22467 newval |= (1 << 23);
22468 limit = 0xfff;
22469 }
22470 else
22471 {
22472 value = -value;
22473 limit = 0xff;
22474 }
22475 if (value > limit)
22476 {
22477 as_bad_where (fixP->fx_file, fixP->fx_line,
22478 _("offset out of range"));
22479 break;
22480 }
22481 newval &= ~limit;
22482 }
22483
22484 newval |= value;
22485 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
22486 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
22487 break;
22488
22489 case BFD_RELOC_ARM_SHIFT_IMM:
22490 newval = md_chars_to_number (buf, INSN_SIZE);
22491 if (((unsigned long) value) > 32
22492 || (value == 32
22493 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
22494 {
22495 as_bad_where (fixP->fx_file, fixP->fx_line,
22496 _("shift expression is too large"));
22497 break;
22498 }
22499
22500 if (value == 0)
22501 /* Shifts of zero must be done as lsl. */
22502 newval &= ~0x60;
22503 else if (value == 32)
22504 value = 0;
22505 newval &= 0xfffff07f;
22506 newval |= (value & 0x1f) << 7;
22507 md_number_to_chars (buf, newval, INSN_SIZE);
22508 break;
22509
22510 case BFD_RELOC_ARM_T32_IMMEDIATE:
22511 case BFD_RELOC_ARM_T32_ADD_IMM:
22512 case BFD_RELOC_ARM_T32_IMM12:
22513 case BFD_RELOC_ARM_T32_ADD_PC12:
22514 /* We claim that this fixup has been processed here,
22515 even if in fact we generate an error because we do
22516 not have a reloc for it, so tc_gen_reloc will reject it. */
22517 fixP->fx_done = 1;
22518
22519 if (fixP->fx_addsy
22520 && ! S_IS_DEFINED (fixP->fx_addsy))
22521 {
22522 as_bad_where (fixP->fx_file, fixP->fx_line,
22523 _("undefined symbol %s used as an immediate value"),
22524 S_GET_NAME (fixP->fx_addsy));
22525 break;
22526 }
22527
22528 newval = md_chars_to_number (buf, THUMB_SIZE);
22529 newval <<= 16;
22530 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
22531
22532 newimm = FAIL;
22533 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
22534 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
22535 {
22536 newimm = encode_thumb32_immediate (value);
22537 if (newimm == (unsigned int) FAIL)
22538 newimm = thumb32_negate_data_op (&newval, value);
22539 }
22540 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
22541 && newimm == (unsigned int) FAIL)
22542 {
22543 /* Turn add/sum into addw/subw. */
22544 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
22545 newval = (newval & 0xfeffffff) | 0x02000000;
22546 /* No flat 12-bit imm encoding for addsw/subsw. */
22547 if ((newval & 0x00100000) == 0)
22548 {
22549 /* 12 bit immediate for addw/subw. */
22550 if (value < 0)
22551 {
22552 value = -value;
22553 newval ^= 0x00a00000;
22554 }
22555 if (value > 0xfff)
22556 newimm = (unsigned int) FAIL;
22557 else
22558 newimm = value;
22559 }
22560 }
22561
22562 if (newimm == (unsigned int)FAIL)
22563 {
22564 as_bad_where (fixP->fx_file, fixP->fx_line,
22565 _("invalid constant (%lx) after fixup"),
22566 (unsigned long) value);
22567 break;
22568 }
22569
22570 newval |= (newimm & 0x800) << 15;
22571 newval |= (newimm & 0x700) << 4;
22572 newval |= (newimm & 0x0ff);
22573
22574 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
22575 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
22576 break;
22577
22578 case BFD_RELOC_ARM_SMC:
22579 if (((unsigned long) value) > 0xffff)
22580 as_bad_where (fixP->fx_file, fixP->fx_line,
22581 _("invalid smc expression"));
22582 newval = md_chars_to_number (buf, INSN_SIZE);
22583 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
22584 md_number_to_chars (buf, newval, INSN_SIZE);
22585 break;
22586
22587 case BFD_RELOC_ARM_HVC:
22588 if (((unsigned long) value) > 0xffff)
22589 as_bad_where (fixP->fx_file, fixP->fx_line,
22590 _("invalid hvc expression"));
22591 newval = md_chars_to_number (buf, INSN_SIZE);
22592 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
22593 md_number_to_chars (buf, newval, INSN_SIZE);
22594 break;
22595
22596 case BFD_RELOC_ARM_SWI:
22597 if (fixP->tc_fix_data != 0)
22598 {
22599 if (((unsigned long) value) > 0xff)
22600 as_bad_where (fixP->fx_file, fixP->fx_line,
22601 _("invalid swi expression"));
22602 newval = md_chars_to_number (buf, THUMB_SIZE);
22603 newval |= value;
22604 md_number_to_chars (buf, newval, THUMB_SIZE);
22605 }
22606 else
22607 {
22608 if (((unsigned long) value) > 0x00ffffff)
22609 as_bad_where (fixP->fx_file, fixP->fx_line,
22610 _("invalid swi expression"));
22611 newval = md_chars_to_number (buf, INSN_SIZE);
22612 newval |= value;
22613 md_number_to_chars (buf, newval, INSN_SIZE);
22614 }
22615 break;
22616
22617 case BFD_RELOC_ARM_MULTI:
22618 if (((unsigned long) value) > 0xffff)
22619 as_bad_where (fixP->fx_file, fixP->fx_line,
22620 _("invalid expression in load/store multiple"));
22621 newval = value | md_chars_to_number (buf, INSN_SIZE);
22622 md_number_to_chars (buf, newval, INSN_SIZE);
22623 break;
22624
22625 #ifdef OBJ_ELF
22626 case BFD_RELOC_ARM_PCREL_CALL:
22627
22628 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
22629 && fixP->fx_addsy
22630 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
22631 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22632 && THUMB_IS_FUNC (fixP->fx_addsy))
22633 /* Flip the bl to blx. This is a simple flip
22634 bit here because we generate PCREL_CALL for
22635 unconditional bls. */
22636 {
22637 newval = md_chars_to_number (buf, INSN_SIZE);
22638 newval = newval | 0x10000000;
22639 md_number_to_chars (buf, newval, INSN_SIZE);
22640 temp = 1;
22641 fixP->fx_done = 1;
22642 }
22643 else
22644 temp = 3;
22645 goto arm_branch_common;
22646
22647 case BFD_RELOC_ARM_PCREL_JUMP:
22648 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
22649 && fixP->fx_addsy
22650 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
22651 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22652 && THUMB_IS_FUNC (fixP->fx_addsy))
22653 {
22654 /* This would map to a bl<cond>, b<cond>,
22655 b<always> to a Thumb function. We
22656 need to force a relocation for this particular
22657 case. */
22658 newval = md_chars_to_number (buf, INSN_SIZE);
22659 fixP->fx_done = 0;
22660 }
22661
22662 case BFD_RELOC_ARM_PLT32:
22663 #endif
22664 case BFD_RELOC_ARM_PCREL_BRANCH:
22665 temp = 3;
22666 goto arm_branch_common;
22667
22668 case BFD_RELOC_ARM_PCREL_BLX:
22669
22670 temp = 1;
22671 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
22672 && fixP->fx_addsy
22673 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
22674 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22675 && ARM_IS_FUNC (fixP->fx_addsy))
22676 {
22677 /* Flip the blx to a bl and warn. */
22678 const char *name = S_GET_NAME (fixP->fx_addsy);
22679 newval = 0xeb000000;
22680 as_warn_where (fixP->fx_file, fixP->fx_line,
22681 _("blx to '%s' an ARM ISA state function changed to bl"),
22682 name);
22683 md_number_to_chars (buf, newval, INSN_SIZE);
22684 temp = 3;
22685 fixP->fx_done = 1;
22686 }
22687
22688 #ifdef OBJ_ELF
22689 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
22690 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
22691 #endif
22692
22693 arm_branch_common:
22694 /* We are going to store value (shifted right by two) in the
22695 instruction, in a 24 bit, signed field. Bits 26 through 32 either
22696 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
22697 also be be clear. */
22698 if (value & temp)
22699 as_bad_where (fixP->fx_file, fixP->fx_line,
22700 _("misaligned branch destination"));
22701 if ((value & (offsetT)0xfe000000) != (offsetT)0
22702 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
22703 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
22704
22705 if (fixP->fx_done || !seg->use_rela_p)
22706 {
22707 newval = md_chars_to_number (buf, INSN_SIZE);
22708 newval |= (value >> 2) & 0x00ffffff;
22709 /* Set the H bit on BLX instructions. */
22710 if (temp == 1)
22711 {
22712 if (value & 2)
22713 newval |= 0x01000000;
22714 else
22715 newval &= ~0x01000000;
22716 }
22717 md_number_to_chars (buf, newval, INSN_SIZE);
22718 }
22719 break;
22720
22721 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
22722 /* CBZ can only branch forward. */
22723
22724 /* Attempts to use CBZ to branch to the next instruction
22725 (which, strictly speaking, are prohibited) will be turned into
22726 no-ops.
22727
22728 FIXME: It may be better to remove the instruction completely and
22729 perform relaxation. */
22730 if (value == -2)
22731 {
22732 newval = md_chars_to_number (buf, THUMB_SIZE);
22733 newval = 0xbf00; /* NOP encoding T1 */
22734 md_number_to_chars (buf, newval, THUMB_SIZE);
22735 }
22736 else
22737 {
22738 if (value & ~0x7e)
22739 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
22740
22741 if (fixP->fx_done || !seg->use_rela_p)
22742 {
22743 newval = md_chars_to_number (buf, THUMB_SIZE);
22744 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
22745 md_number_to_chars (buf, newval, THUMB_SIZE);
22746 }
22747 }
22748 break;
22749
22750 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
22751 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
22752 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
22753
22754 if (fixP->fx_done || !seg->use_rela_p)
22755 {
22756 newval = md_chars_to_number (buf, THUMB_SIZE);
22757 newval |= (value & 0x1ff) >> 1;
22758 md_number_to_chars (buf, newval, THUMB_SIZE);
22759 }
22760 break;
22761
22762 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
22763 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
22764 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
22765
22766 if (fixP->fx_done || !seg->use_rela_p)
22767 {
22768 newval = md_chars_to_number (buf, THUMB_SIZE);
22769 newval |= (value & 0xfff) >> 1;
22770 md_number_to_chars (buf, newval, THUMB_SIZE);
22771 }
22772 break;
22773
22774 case BFD_RELOC_THUMB_PCREL_BRANCH20:
22775 if (fixP->fx_addsy
22776 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22777 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
22778 && ARM_IS_FUNC (fixP->fx_addsy)
22779 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22780 {
22781 /* Force a relocation for a branch 20 bits wide. */
22782 fixP->fx_done = 0;
22783 }
22784 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
22785 as_bad_where (fixP->fx_file, fixP->fx_line,
22786 _("conditional branch out of range"));
22787
22788 if (fixP->fx_done || !seg->use_rela_p)
22789 {
22790 offsetT newval2;
22791 addressT S, J1, J2, lo, hi;
22792
22793 S = (value & 0x00100000) >> 20;
22794 J2 = (value & 0x00080000) >> 19;
22795 J1 = (value & 0x00040000) >> 18;
22796 hi = (value & 0x0003f000) >> 12;
22797 lo = (value & 0x00000ffe) >> 1;
22798
22799 newval = md_chars_to_number (buf, THUMB_SIZE);
22800 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22801 newval |= (S << 10) | hi;
22802 newval2 |= (J1 << 13) | (J2 << 11) | lo;
22803 md_number_to_chars (buf, newval, THUMB_SIZE);
22804 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
22805 }
22806 break;
22807
22808 case BFD_RELOC_THUMB_PCREL_BLX:
22809 /* If there is a blx from a thumb state function to
22810 another thumb function flip this to a bl and warn
22811 about it. */
22812
22813 if (fixP->fx_addsy
22814 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
22815 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22816 && THUMB_IS_FUNC (fixP->fx_addsy))
22817 {
22818 const char *name = S_GET_NAME (fixP->fx_addsy);
22819 as_warn_where (fixP->fx_file, fixP->fx_line,
22820 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
22821 name);
22822 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22823 newval = newval | 0x1000;
22824 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
22825 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
22826 fixP->fx_done = 1;
22827 }
22828
22829
22830 goto thumb_bl_common;
22831
22832 case BFD_RELOC_THUMB_PCREL_BRANCH23:
22833 /* A bl from Thumb state ISA to an internal ARM state function
22834 is converted to a blx. */
22835 if (fixP->fx_addsy
22836 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22837 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
22838 && ARM_IS_FUNC (fixP->fx_addsy)
22839 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22840 {
22841 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22842 newval = newval & ~0x1000;
22843 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
22844 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
22845 fixP->fx_done = 1;
22846 }
22847
22848 thumb_bl_common:
22849
22850 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
22851 /* For a BLX instruction, make sure that the relocation is rounded up
22852 to a word boundary. This follows the semantics of the instruction
22853 which specifies that bit 1 of the target address will come from bit
22854 1 of the base address. */
22855 value = (value + 3) & ~ 3;
22856
22857 #ifdef OBJ_ELF
22858 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
22859 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
22860 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
22861 #endif
22862
22863 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
22864 {
22865 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
22866 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
22867 else if ((value & ~0x1ffffff)
22868 && ((value & ~0x1ffffff) != ~0x1ffffff))
22869 as_bad_where (fixP->fx_file, fixP->fx_line,
22870 _("Thumb2 branch out of range"));
22871 }
22872
22873 if (fixP->fx_done || !seg->use_rela_p)
22874 encode_thumb2_b_bl_offset (buf, value);
22875
22876 break;
22877
22878 case BFD_RELOC_THUMB_PCREL_BRANCH25:
22879 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
22880 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
22881
22882 if (fixP->fx_done || !seg->use_rela_p)
22883 encode_thumb2_b_bl_offset (buf, value);
22884
22885 break;
22886
22887 case BFD_RELOC_8:
22888 if (fixP->fx_done || !seg->use_rela_p)
22889 *buf = value;
22890 break;
22891
22892 case BFD_RELOC_16:
22893 if (fixP->fx_done || !seg->use_rela_p)
22894 md_number_to_chars (buf, value, 2);
22895 break;
22896
22897 #ifdef OBJ_ELF
22898 case BFD_RELOC_ARM_TLS_CALL:
22899 case BFD_RELOC_ARM_THM_TLS_CALL:
22900 case BFD_RELOC_ARM_TLS_DESCSEQ:
22901 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
22902 case BFD_RELOC_ARM_TLS_GOTDESC:
22903 case BFD_RELOC_ARM_TLS_GD32:
22904 case BFD_RELOC_ARM_TLS_LE32:
22905 case BFD_RELOC_ARM_TLS_IE32:
22906 case BFD_RELOC_ARM_TLS_LDM32:
22907 case BFD_RELOC_ARM_TLS_LDO32:
22908 S_SET_THREAD_LOCAL (fixP->fx_addsy);
22909 break;
22910
22911 case BFD_RELOC_ARM_GOT32:
22912 case BFD_RELOC_ARM_GOTOFF:
22913 break;
22914
22915 case BFD_RELOC_ARM_GOT_PREL:
22916 if (fixP->fx_done || !seg->use_rela_p)
22917 md_number_to_chars (buf, value, 4);
22918 break;
22919
22920 case BFD_RELOC_ARM_TARGET2:
22921 /* TARGET2 is not partial-inplace, so we need to write the
22922 addend here for REL targets, because it won't be written out
22923 during reloc processing later. */
22924 if (fixP->fx_done || !seg->use_rela_p)
22925 md_number_to_chars (buf, fixP->fx_offset, 4);
22926 break;
22927 #endif
22928
22929 case BFD_RELOC_RVA:
22930 case BFD_RELOC_32:
22931 case BFD_RELOC_ARM_TARGET1:
22932 case BFD_RELOC_ARM_ROSEGREL32:
22933 case BFD_RELOC_ARM_SBREL32:
22934 case BFD_RELOC_32_PCREL:
22935 #ifdef TE_PE
22936 case BFD_RELOC_32_SECREL:
22937 #endif
22938 if (fixP->fx_done || !seg->use_rela_p)
22939 #ifdef TE_WINCE
22940 /* For WinCE we only do this for pcrel fixups. */
22941 if (fixP->fx_done || fixP->fx_pcrel)
22942 #endif
22943 md_number_to_chars (buf, value, 4);
22944 break;
22945
22946 #ifdef OBJ_ELF
22947 case BFD_RELOC_ARM_PREL31:
22948 if (fixP->fx_done || !seg->use_rela_p)
22949 {
22950 newval = md_chars_to_number (buf, 4) & 0x80000000;
22951 if ((value ^ (value >> 1)) & 0x40000000)
22952 {
22953 as_bad_where (fixP->fx_file, fixP->fx_line,
22954 _("rel31 relocation overflow"));
22955 }
22956 newval |= value & 0x7fffffff;
22957 md_number_to_chars (buf, newval, 4);
22958 }
22959 break;
22960 #endif
22961
22962 case BFD_RELOC_ARM_CP_OFF_IMM:
22963 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
22964 if (value < -1023 || value > 1023 || (value & 3))
22965 as_bad_where (fixP->fx_file, fixP->fx_line,
22966 _("co-processor offset out of range"));
22967 cp_off_common:
22968 sign = value > 0;
22969 if (value < 0)
22970 value = -value;
22971 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
22972 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
22973 newval = md_chars_to_number (buf, INSN_SIZE);
22974 else
22975 newval = get_thumb32_insn (buf);
22976 if (value == 0)
22977 newval &= 0xffffff00;
22978 else
22979 {
22980 newval &= 0xff7fff00;
22981 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
22982 }
22983 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
22984 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
22985 md_number_to_chars (buf, newval, INSN_SIZE);
22986 else
22987 put_thumb32_insn (buf, newval);
22988 break;
22989
22990 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
22991 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
22992 if (value < -255 || value > 255)
22993 as_bad_where (fixP->fx_file, fixP->fx_line,
22994 _("co-processor offset out of range"));
22995 value *= 4;
22996 goto cp_off_common;
22997
22998 case BFD_RELOC_ARM_THUMB_OFFSET:
22999 newval = md_chars_to_number (buf, THUMB_SIZE);
23000 /* Exactly what ranges, and where the offset is inserted depends
23001 on the type of instruction, we can establish this from the
23002 top 4 bits. */
23003 switch (newval >> 12)
23004 {
23005 case 4: /* PC load. */
23006 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
23007 forced to zero for these loads; md_pcrel_from has already
23008 compensated for this. */
23009 if (value & 3)
23010 as_bad_where (fixP->fx_file, fixP->fx_line,
23011 _("invalid offset, target not word aligned (0x%08lX)"),
23012 (((unsigned long) fixP->fx_frag->fr_address
23013 + (unsigned long) fixP->fx_where) & ~3)
23014 + (unsigned long) value);
23015
23016 if (value & ~0x3fc)
23017 as_bad_where (fixP->fx_file, fixP->fx_line,
23018 _("invalid offset, value too big (0x%08lX)"),
23019 (long) value);
23020
23021 newval |= value >> 2;
23022 break;
23023
23024 case 9: /* SP load/store. */
23025 if (value & ~0x3fc)
23026 as_bad_where (fixP->fx_file, fixP->fx_line,
23027 _("invalid offset, value too big (0x%08lX)"),
23028 (long) value);
23029 newval |= value >> 2;
23030 break;
23031
23032 case 6: /* Word load/store. */
23033 if (value & ~0x7c)
23034 as_bad_where (fixP->fx_file, fixP->fx_line,
23035 _("invalid offset, value too big (0x%08lX)"),
23036 (long) value);
23037 newval |= value << 4; /* 6 - 2. */
23038 break;
23039
23040 case 7: /* Byte load/store. */
23041 if (value & ~0x1f)
23042 as_bad_where (fixP->fx_file, fixP->fx_line,
23043 _("invalid offset, value too big (0x%08lX)"),
23044 (long) value);
23045 newval |= value << 6;
23046 break;
23047
23048 case 8: /* Halfword load/store. */
23049 if (value & ~0x3e)
23050 as_bad_where (fixP->fx_file, fixP->fx_line,
23051 _("invalid offset, value too big (0x%08lX)"),
23052 (long) value);
23053 newval |= value << 5; /* 6 - 1. */
23054 break;
23055
23056 default:
23057 as_bad_where (fixP->fx_file, fixP->fx_line,
23058 "Unable to process relocation for thumb opcode: %lx",
23059 (unsigned long) newval);
23060 break;
23061 }
23062 md_number_to_chars (buf, newval, THUMB_SIZE);
23063 break;
23064
23065 case BFD_RELOC_ARM_THUMB_ADD:
23066 /* This is a complicated relocation, since we use it for all of
23067 the following immediate relocations:
23068
23069 3bit ADD/SUB
23070 8bit ADD/SUB
23071 9bit ADD/SUB SP word-aligned
23072 10bit ADD PC/SP word-aligned
23073
23074 The type of instruction being processed is encoded in the
23075 instruction field:
23076
23077 0x8000 SUB
23078 0x00F0 Rd
23079 0x000F Rs
23080 */
23081 newval = md_chars_to_number (buf, THUMB_SIZE);
23082 {
23083 int rd = (newval >> 4) & 0xf;
23084 int rs = newval & 0xf;
23085 int subtract = !!(newval & 0x8000);
23086
23087 /* Check for HI regs, only very restricted cases allowed:
23088 Adjusting SP, and using PC or SP to get an address. */
23089 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
23090 || (rs > 7 && rs != REG_SP && rs != REG_PC))
23091 as_bad_where (fixP->fx_file, fixP->fx_line,
23092 _("invalid Hi register with immediate"));
23093
23094 /* If value is negative, choose the opposite instruction. */
23095 if (value < 0)
23096 {
23097 value = -value;
23098 subtract = !subtract;
23099 if (value < 0)
23100 as_bad_where (fixP->fx_file, fixP->fx_line,
23101 _("immediate value out of range"));
23102 }
23103
23104 if (rd == REG_SP)
23105 {
23106 if (value & ~0x1fc)
23107 as_bad_where (fixP->fx_file, fixP->fx_line,
23108 _("invalid immediate for stack address calculation"));
23109 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
23110 newval |= value >> 2;
23111 }
23112 else if (rs == REG_PC || rs == REG_SP)
23113 {
23114 /* PR gas/18541. If the addition is for a defined symbol
23115 within range of an ADR instruction then accept it. */
23116 if (subtract
23117 && value == 4
23118 && fixP->fx_addsy != NULL)
23119 {
23120 subtract = 0;
23121
23122 if (! S_IS_DEFINED (fixP->fx_addsy)
23123 || S_GET_SEGMENT (fixP->fx_addsy) != seg
23124 || S_IS_WEAK (fixP->fx_addsy))
23125 {
23126 as_bad_where (fixP->fx_file, fixP->fx_line,
23127 _("address calculation needs a strongly defined nearby symbol"));
23128 }
23129 else
23130 {
23131 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
23132
23133 /* Round up to the next 4-byte boundary. */
23134 if (v & 3)
23135 v = (v + 3) & ~ 3;
23136 else
23137 v += 4;
23138 v = S_GET_VALUE (fixP->fx_addsy) - v;
23139
23140 if (v & ~0x3fc)
23141 {
23142 as_bad_where (fixP->fx_file, fixP->fx_line,
23143 _("symbol too far away"));
23144 }
23145 else
23146 {
23147 fixP->fx_done = 1;
23148 value = v;
23149 }
23150 }
23151 }
23152
23153 if (subtract || value & ~0x3fc)
23154 as_bad_where (fixP->fx_file, fixP->fx_line,
23155 _("invalid immediate for address calculation (value = 0x%08lX)"),
23156 (unsigned long) (subtract ? - value : value));
23157 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
23158 newval |= rd << 8;
23159 newval |= value >> 2;
23160 }
23161 else if (rs == rd)
23162 {
23163 if (value & ~0xff)
23164 as_bad_where (fixP->fx_file, fixP->fx_line,
23165 _("immediate value out of range"));
23166 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
23167 newval |= (rd << 8) | value;
23168 }
23169 else
23170 {
23171 if (value & ~0x7)
23172 as_bad_where (fixP->fx_file, fixP->fx_line,
23173 _("immediate value out of range"));
23174 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
23175 newval |= rd | (rs << 3) | (value << 6);
23176 }
23177 }
23178 md_number_to_chars (buf, newval, THUMB_SIZE);
23179 break;
23180
23181 case BFD_RELOC_ARM_THUMB_IMM:
23182 newval = md_chars_to_number (buf, THUMB_SIZE);
23183 if (value < 0 || value > 255)
23184 as_bad_where (fixP->fx_file, fixP->fx_line,
23185 _("invalid immediate: %ld is out of range"),
23186 (long) value);
23187 newval |= value;
23188 md_number_to_chars (buf, newval, THUMB_SIZE);
23189 break;
23190
23191 case BFD_RELOC_ARM_THUMB_SHIFT:
23192 /* 5bit shift value (0..32). LSL cannot take 32. */
23193 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
23194 temp = newval & 0xf800;
23195 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
23196 as_bad_where (fixP->fx_file, fixP->fx_line,
23197 _("invalid shift value: %ld"), (long) value);
23198 /* Shifts of zero must be encoded as LSL. */
23199 if (value == 0)
23200 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
23201 /* Shifts of 32 are encoded as zero. */
23202 else if (value == 32)
23203 value = 0;
23204 newval |= value << 6;
23205 md_number_to_chars (buf, newval, THUMB_SIZE);
23206 break;
23207
23208 case BFD_RELOC_VTABLE_INHERIT:
23209 case BFD_RELOC_VTABLE_ENTRY:
23210 fixP->fx_done = 0;
23211 return;
23212
23213 case BFD_RELOC_ARM_MOVW:
23214 case BFD_RELOC_ARM_MOVT:
23215 case BFD_RELOC_ARM_THUMB_MOVW:
23216 case BFD_RELOC_ARM_THUMB_MOVT:
23217 if (fixP->fx_done || !seg->use_rela_p)
23218 {
23219 /* REL format relocations are limited to a 16-bit addend. */
23220 if (!fixP->fx_done)
23221 {
23222 if (value < -0x8000 || value > 0x7fff)
23223 as_bad_where (fixP->fx_file, fixP->fx_line,
23224 _("offset out of range"));
23225 }
23226 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
23227 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23228 {
23229 value >>= 16;
23230 }
23231
23232 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
23233 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23234 {
23235 newval = get_thumb32_insn (buf);
23236 newval &= 0xfbf08f00;
23237 newval |= (value & 0xf000) << 4;
23238 newval |= (value & 0x0800) << 15;
23239 newval |= (value & 0x0700) << 4;
23240 newval |= (value & 0x00ff);
23241 put_thumb32_insn (buf, newval);
23242 }
23243 else
23244 {
23245 newval = md_chars_to_number (buf, 4);
23246 newval &= 0xfff0f000;
23247 newval |= value & 0x0fff;
23248 newval |= (value & 0xf000) << 4;
23249 md_number_to_chars (buf, newval, 4);
23250 }
23251 }
23252 return;
23253
23254 case BFD_RELOC_ARM_ALU_PC_G0_NC:
23255 case BFD_RELOC_ARM_ALU_PC_G0:
23256 case BFD_RELOC_ARM_ALU_PC_G1_NC:
23257 case BFD_RELOC_ARM_ALU_PC_G1:
23258 case BFD_RELOC_ARM_ALU_PC_G2:
23259 case BFD_RELOC_ARM_ALU_SB_G0_NC:
23260 case BFD_RELOC_ARM_ALU_SB_G0:
23261 case BFD_RELOC_ARM_ALU_SB_G1_NC:
23262 case BFD_RELOC_ARM_ALU_SB_G1:
23263 case BFD_RELOC_ARM_ALU_SB_G2:
23264 gas_assert (!fixP->fx_done);
23265 if (!seg->use_rela_p)
23266 {
23267 bfd_vma insn;
23268 bfd_vma encoded_addend;
23269 bfd_vma addend_abs = abs (value);
23270
23271 /* Check that the absolute value of the addend can be
23272 expressed as an 8-bit constant plus a rotation. */
23273 encoded_addend = encode_arm_immediate (addend_abs);
23274 if (encoded_addend == (unsigned int) FAIL)
23275 as_bad_where (fixP->fx_file, fixP->fx_line,
23276 _("the offset 0x%08lX is not representable"),
23277 (unsigned long) addend_abs);
23278
23279 /* Extract the instruction. */
23280 insn = md_chars_to_number (buf, INSN_SIZE);
23281
23282 /* If the addend is positive, use an ADD instruction.
23283 Otherwise use a SUB. Take care not to destroy the S bit. */
23284 insn &= 0xff1fffff;
23285 if (value < 0)
23286 insn |= 1 << 22;
23287 else
23288 insn |= 1 << 23;
23289
23290 /* Place the encoded addend into the first 12 bits of the
23291 instruction. */
23292 insn &= 0xfffff000;
23293 insn |= encoded_addend;
23294
23295 /* Update the instruction. */
23296 md_number_to_chars (buf, insn, INSN_SIZE);
23297 }
23298 break;
23299
23300 case BFD_RELOC_ARM_LDR_PC_G0:
23301 case BFD_RELOC_ARM_LDR_PC_G1:
23302 case BFD_RELOC_ARM_LDR_PC_G2:
23303 case BFD_RELOC_ARM_LDR_SB_G0:
23304 case BFD_RELOC_ARM_LDR_SB_G1:
23305 case BFD_RELOC_ARM_LDR_SB_G2:
23306 gas_assert (!fixP->fx_done);
23307 if (!seg->use_rela_p)
23308 {
23309 bfd_vma insn;
23310 bfd_vma addend_abs = abs (value);
23311
23312 /* Check that the absolute value of the addend can be
23313 encoded in 12 bits. */
23314 if (addend_abs >= 0x1000)
23315 as_bad_where (fixP->fx_file, fixP->fx_line,
23316 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
23317 (unsigned long) addend_abs);
23318
23319 /* Extract the instruction. */
23320 insn = md_chars_to_number (buf, INSN_SIZE);
23321
23322 /* If the addend is negative, clear bit 23 of the instruction.
23323 Otherwise set it. */
23324 if (value < 0)
23325 insn &= ~(1 << 23);
23326 else
23327 insn |= 1 << 23;
23328
23329 /* Place the absolute value of the addend into the first 12 bits
23330 of the instruction. */
23331 insn &= 0xfffff000;
23332 insn |= addend_abs;
23333
23334 /* Update the instruction. */
23335 md_number_to_chars (buf, insn, INSN_SIZE);
23336 }
23337 break;
23338
23339 case BFD_RELOC_ARM_LDRS_PC_G0:
23340 case BFD_RELOC_ARM_LDRS_PC_G1:
23341 case BFD_RELOC_ARM_LDRS_PC_G2:
23342 case BFD_RELOC_ARM_LDRS_SB_G0:
23343 case BFD_RELOC_ARM_LDRS_SB_G1:
23344 case BFD_RELOC_ARM_LDRS_SB_G2:
23345 gas_assert (!fixP->fx_done);
23346 if (!seg->use_rela_p)
23347 {
23348 bfd_vma insn;
23349 bfd_vma addend_abs = abs (value);
23350
23351 /* Check that the absolute value of the addend can be
23352 encoded in 8 bits. */
23353 if (addend_abs >= 0x100)
23354 as_bad_where (fixP->fx_file, fixP->fx_line,
23355 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
23356 (unsigned long) addend_abs);
23357
23358 /* Extract the instruction. */
23359 insn = md_chars_to_number (buf, INSN_SIZE);
23360
23361 /* If the addend is negative, clear bit 23 of the instruction.
23362 Otherwise set it. */
23363 if (value < 0)
23364 insn &= ~(1 << 23);
23365 else
23366 insn |= 1 << 23;
23367
23368 /* Place the first four bits of the absolute value of the addend
23369 into the first 4 bits of the instruction, and the remaining
23370 four into bits 8 .. 11. */
23371 insn &= 0xfffff0f0;
23372 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
23373
23374 /* Update the instruction. */
23375 md_number_to_chars (buf, insn, INSN_SIZE);
23376 }
23377 break;
23378
23379 case BFD_RELOC_ARM_LDC_PC_G0:
23380 case BFD_RELOC_ARM_LDC_PC_G1:
23381 case BFD_RELOC_ARM_LDC_PC_G2:
23382 case BFD_RELOC_ARM_LDC_SB_G0:
23383 case BFD_RELOC_ARM_LDC_SB_G1:
23384 case BFD_RELOC_ARM_LDC_SB_G2:
23385 gas_assert (!fixP->fx_done);
23386 if (!seg->use_rela_p)
23387 {
23388 bfd_vma insn;
23389 bfd_vma addend_abs = abs (value);
23390
23391 /* Check that the absolute value of the addend is a multiple of
23392 four and, when divided by four, fits in 8 bits. */
23393 if (addend_abs & 0x3)
23394 as_bad_where (fixP->fx_file, fixP->fx_line,
23395 _("bad offset 0x%08lX (must be word-aligned)"),
23396 (unsigned long) addend_abs);
23397
23398 if ((addend_abs >> 2) > 0xff)
23399 as_bad_where (fixP->fx_file, fixP->fx_line,
23400 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
23401 (unsigned long) addend_abs);
23402
23403 /* Extract the instruction. */
23404 insn = md_chars_to_number (buf, INSN_SIZE);
23405
23406 /* If the addend is negative, clear bit 23 of the instruction.
23407 Otherwise set it. */
23408 if (value < 0)
23409 insn &= ~(1 << 23);
23410 else
23411 insn |= 1 << 23;
23412
23413 /* Place the addend (divided by four) into the first eight
23414 bits of the instruction. */
23415 insn &= 0xfffffff0;
23416 insn |= addend_abs >> 2;
23417
23418 /* Update the instruction. */
23419 md_number_to_chars (buf, insn, INSN_SIZE);
23420 }
23421 break;
23422
23423 case BFD_RELOC_ARM_V4BX:
23424 /* This will need to go in the object file. */
23425 fixP->fx_done = 0;
23426 break;
23427
23428 case BFD_RELOC_UNUSED:
23429 default:
23430 as_bad_where (fixP->fx_file, fixP->fx_line,
23431 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
23432 }
23433 }
23434
23435 /* Translate internal representation of relocation info to BFD target
23436 format. */
23437
23438 arelent *
23439 tc_gen_reloc (asection *section, fixS *fixp)
23440 {
23441 arelent * reloc;
23442 bfd_reloc_code_real_type code;
23443
23444 reloc = (arelent *) xmalloc (sizeof (arelent));
23445
23446 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
23447 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
23448 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
23449
23450 if (fixp->fx_pcrel)
23451 {
23452 if (section->use_rela_p)
23453 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
23454 else
23455 fixp->fx_offset = reloc->address;
23456 }
23457 reloc->addend = fixp->fx_offset;
23458
23459 switch (fixp->fx_r_type)
23460 {
23461 case BFD_RELOC_8:
23462 if (fixp->fx_pcrel)
23463 {
23464 code = BFD_RELOC_8_PCREL;
23465 break;
23466 }
23467
23468 case BFD_RELOC_16:
23469 if (fixp->fx_pcrel)
23470 {
23471 code = BFD_RELOC_16_PCREL;
23472 break;
23473 }
23474
23475 case BFD_RELOC_32:
23476 if (fixp->fx_pcrel)
23477 {
23478 code = BFD_RELOC_32_PCREL;
23479 break;
23480 }
23481
23482 case BFD_RELOC_ARM_MOVW:
23483 if (fixp->fx_pcrel)
23484 {
23485 code = BFD_RELOC_ARM_MOVW_PCREL;
23486 break;
23487 }
23488
23489 case BFD_RELOC_ARM_MOVT:
23490 if (fixp->fx_pcrel)
23491 {
23492 code = BFD_RELOC_ARM_MOVT_PCREL;
23493 break;
23494 }
23495
23496 case BFD_RELOC_ARM_THUMB_MOVW:
23497 if (fixp->fx_pcrel)
23498 {
23499 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
23500 break;
23501 }
23502
23503 case BFD_RELOC_ARM_THUMB_MOVT:
23504 if (fixp->fx_pcrel)
23505 {
23506 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
23507 break;
23508 }
23509
23510 case BFD_RELOC_NONE:
23511 case BFD_RELOC_ARM_PCREL_BRANCH:
23512 case BFD_RELOC_ARM_PCREL_BLX:
23513 case BFD_RELOC_RVA:
23514 case BFD_RELOC_THUMB_PCREL_BRANCH7:
23515 case BFD_RELOC_THUMB_PCREL_BRANCH9:
23516 case BFD_RELOC_THUMB_PCREL_BRANCH12:
23517 case BFD_RELOC_THUMB_PCREL_BRANCH20:
23518 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23519 case BFD_RELOC_THUMB_PCREL_BRANCH25:
23520 case BFD_RELOC_VTABLE_ENTRY:
23521 case BFD_RELOC_VTABLE_INHERIT:
23522 #ifdef TE_PE
23523 case BFD_RELOC_32_SECREL:
23524 #endif
23525 code = fixp->fx_r_type;
23526 break;
23527
23528 case BFD_RELOC_THUMB_PCREL_BLX:
23529 #ifdef OBJ_ELF
23530 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
23531 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
23532 else
23533 #endif
23534 code = BFD_RELOC_THUMB_PCREL_BLX;
23535 break;
23536
23537 case BFD_RELOC_ARM_LITERAL:
23538 case BFD_RELOC_ARM_HWLITERAL:
23539 /* If this is called then the a literal has
23540 been referenced across a section boundary. */
23541 as_bad_where (fixp->fx_file, fixp->fx_line,
23542 _("literal referenced across section boundary"));
23543 return NULL;
23544
23545 #ifdef OBJ_ELF
23546 case BFD_RELOC_ARM_TLS_CALL:
23547 case BFD_RELOC_ARM_THM_TLS_CALL:
23548 case BFD_RELOC_ARM_TLS_DESCSEQ:
23549 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
23550 case BFD_RELOC_ARM_GOT32:
23551 case BFD_RELOC_ARM_GOTOFF:
23552 case BFD_RELOC_ARM_GOT_PREL:
23553 case BFD_RELOC_ARM_PLT32:
23554 case BFD_RELOC_ARM_TARGET1:
23555 case BFD_RELOC_ARM_ROSEGREL32:
23556 case BFD_RELOC_ARM_SBREL32:
23557 case BFD_RELOC_ARM_PREL31:
23558 case BFD_RELOC_ARM_TARGET2:
23559 case BFD_RELOC_ARM_TLS_LDO32:
23560 case BFD_RELOC_ARM_PCREL_CALL:
23561 case BFD_RELOC_ARM_PCREL_JUMP:
23562 case BFD_RELOC_ARM_ALU_PC_G0_NC:
23563 case BFD_RELOC_ARM_ALU_PC_G0:
23564 case BFD_RELOC_ARM_ALU_PC_G1_NC:
23565 case BFD_RELOC_ARM_ALU_PC_G1:
23566 case BFD_RELOC_ARM_ALU_PC_G2:
23567 case BFD_RELOC_ARM_LDR_PC_G0:
23568 case BFD_RELOC_ARM_LDR_PC_G1:
23569 case BFD_RELOC_ARM_LDR_PC_G2:
23570 case BFD_RELOC_ARM_LDRS_PC_G0:
23571 case BFD_RELOC_ARM_LDRS_PC_G1:
23572 case BFD_RELOC_ARM_LDRS_PC_G2:
23573 case BFD_RELOC_ARM_LDC_PC_G0:
23574 case BFD_RELOC_ARM_LDC_PC_G1:
23575 case BFD_RELOC_ARM_LDC_PC_G2:
23576 case BFD_RELOC_ARM_ALU_SB_G0_NC:
23577 case BFD_RELOC_ARM_ALU_SB_G0:
23578 case BFD_RELOC_ARM_ALU_SB_G1_NC:
23579 case BFD_RELOC_ARM_ALU_SB_G1:
23580 case BFD_RELOC_ARM_ALU_SB_G2:
23581 case BFD_RELOC_ARM_LDR_SB_G0:
23582 case BFD_RELOC_ARM_LDR_SB_G1:
23583 case BFD_RELOC_ARM_LDR_SB_G2:
23584 case BFD_RELOC_ARM_LDRS_SB_G0:
23585 case BFD_RELOC_ARM_LDRS_SB_G1:
23586 case BFD_RELOC_ARM_LDRS_SB_G2:
23587 case BFD_RELOC_ARM_LDC_SB_G0:
23588 case BFD_RELOC_ARM_LDC_SB_G1:
23589 case BFD_RELOC_ARM_LDC_SB_G2:
23590 case BFD_RELOC_ARM_V4BX:
23591 code = fixp->fx_r_type;
23592 break;
23593
23594 case BFD_RELOC_ARM_TLS_GOTDESC:
23595 case BFD_RELOC_ARM_TLS_GD32:
23596 case BFD_RELOC_ARM_TLS_LE32:
23597 case BFD_RELOC_ARM_TLS_IE32:
23598 case BFD_RELOC_ARM_TLS_LDM32:
23599 /* BFD will include the symbol's address in the addend.
23600 But we don't want that, so subtract it out again here. */
23601 if (!S_IS_COMMON (fixp->fx_addsy))
23602 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
23603 code = fixp->fx_r_type;
23604 break;
23605 #endif
23606
23607 case BFD_RELOC_ARM_IMMEDIATE:
23608 as_bad_where (fixp->fx_file, fixp->fx_line,
23609 _("internal relocation (type: IMMEDIATE) not fixed up"));
23610 return NULL;
23611
23612 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
23613 as_bad_where (fixp->fx_file, fixp->fx_line,
23614 _("ADRL used for a symbol not defined in the same file"));
23615 return NULL;
23616
23617 case BFD_RELOC_ARM_OFFSET_IMM:
23618 if (section->use_rela_p)
23619 {
23620 code = fixp->fx_r_type;
23621 break;
23622 }
23623
23624 if (fixp->fx_addsy != NULL
23625 && !S_IS_DEFINED (fixp->fx_addsy)
23626 && S_IS_LOCAL (fixp->fx_addsy))
23627 {
23628 as_bad_where (fixp->fx_file, fixp->fx_line,
23629 _("undefined local label `%s'"),
23630 S_GET_NAME (fixp->fx_addsy));
23631 return NULL;
23632 }
23633
23634 as_bad_where (fixp->fx_file, fixp->fx_line,
23635 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
23636 return NULL;
23637
23638 default:
23639 {
23640 char * type;
23641
23642 switch (fixp->fx_r_type)
23643 {
23644 case BFD_RELOC_NONE: type = "NONE"; break;
23645 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
23646 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
23647 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
23648 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
23649 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
23650 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
23651 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
23652 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
23653 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
23654 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
23655 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
23656 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
23657 default: type = _("<unknown>"); break;
23658 }
23659 as_bad_where (fixp->fx_file, fixp->fx_line,
23660 _("cannot represent %s relocation in this object file format"),
23661 type);
23662 return NULL;
23663 }
23664 }
23665
23666 #ifdef OBJ_ELF
23667 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
23668 && GOT_symbol
23669 && fixp->fx_addsy == GOT_symbol)
23670 {
23671 code = BFD_RELOC_ARM_GOTPC;
23672 reloc->addend = fixp->fx_offset = reloc->address;
23673 }
23674 #endif
23675
23676 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
23677
23678 if (reloc->howto == NULL)
23679 {
23680 as_bad_where (fixp->fx_file, fixp->fx_line,
23681 _("cannot represent %s relocation in this object file format"),
23682 bfd_get_reloc_code_name (code));
23683 return NULL;
23684 }
23685
23686 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
23687 vtable entry to be used in the relocation's section offset. */
23688 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
23689 reloc->address = fixp->fx_offset;
23690
23691 return reloc;
23692 }
23693
23694 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
23695
23696 void
23697 cons_fix_new_arm (fragS * frag,
23698 int where,
23699 int size,
23700 expressionS * exp,
23701 bfd_reloc_code_real_type reloc)
23702 {
23703 int pcrel = 0;
23704
23705 /* Pick a reloc.
23706 FIXME: @@ Should look at CPU word size. */
23707 switch (size)
23708 {
23709 case 1:
23710 reloc = BFD_RELOC_8;
23711 break;
23712 case 2:
23713 reloc = BFD_RELOC_16;
23714 break;
23715 case 4:
23716 default:
23717 reloc = BFD_RELOC_32;
23718 break;
23719 case 8:
23720 reloc = BFD_RELOC_64;
23721 break;
23722 }
23723
23724 #ifdef TE_PE
23725 if (exp->X_op == O_secrel)
23726 {
23727 exp->X_op = O_symbol;
23728 reloc = BFD_RELOC_32_SECREL;
23729 }
23730 #endif
23731
23732 fix_new_exp (frag, where, size, exp, pcrel, reloc);
23733 }
23734
23735 #if defined (OBJ_COFF)
23736 void
23737 arm_validate_fix (fixS * fixP)
23738 {
23739 /* If the destination of the branch is a defined symbol which does not have
23740 the THUMB_FUNC attribute, then we must be calling a function which has
23741 the (interfacearm) attribute. We look for the Thumb entry point to that
23742 function and change the branch to refer to that function instead. */
23743 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
23744 && fixP->fx_addsy != NULL
23745 && S_IS_DEFINED (fixP->fx_addsy)
23746 && ! THUMB_IS_FUNC (fixP->fx_addsy))
23747 {
23748 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
23749 }
23750 }
23751 #endif
23752
23753
23754 int
23755 arm_force_relocation (struct fix * fixp)
23756 {
23757 #if defined (OBJ_COFF) && defined (TE_PE)
23758 if (fixp->fx_r_type == BFD_RELOC_RVA)
23759 return 1;
23760 #endif
23761
23762 /* In case we have a call or a branch to a function in ARM ISA mode from
23763 a thumb function or vice-versa force the relocation. These relocations
23764 are cleared off for some cores that might have blx and simple transformations
23765 are possible. */
23766
23767 #ifdef OBJ_ELF
23768 switch (fixp->fx_r_type)
23769 {
23770 case BFD_RELOC_ARM_PCREL_JUMP:
23771 case BFD_RELOC_ARM_PCREL_CALL:
23772 case BFD_RELOC_THUMB_PCREL_BLX:
23773 if (THUMB_IS_FUNC (fixp->fx_addsy))
23774 return 1;
23775 break;
23776
23777 case BFD_RELOC_ARM_PCREL_BLX:
23778 case BFD_RELOC_THUMB_PCREL_BRANCH25:
23779 case BFD_RELOC_THUMB_PCREL_BRANCH20:
23780 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23781 if (ARM_IS_FUNC (fixp->fx_addsy))
23782 return 1;
23783 break;
23784
23785 default:
23786 break;
23787 }
23788 #endif
23789
23790 /* Resolve these relocations even if the symbol is extern or weak.
23791 Technically this is probably wrong due to symbol preemption.
23792 In practice these relocations do not have enough range to be useful
23793 at dynamic link time, and some code (e.g. in the Linux kernel)
23794 expects these references to be resolved. */
23795 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
23796 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
23797 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
23798 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
23799 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23800 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
23801 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
23802 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
23803 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
23804 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
23805 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
23806 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
23807 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
23808 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
23809 return 0;
23810
23811 /* Always leave these relocations for the linker. */
23812 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
23813 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
23814 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
23815 return 1;
23816
23817 /* Always generate relocations against function symbols. */
23818 if (fixp->fx_r_type == BFD_RELOC_32
23819 && fixp->fx_addsy
23820 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
23821 return 1;
23822
23823 return generic_force_reloc (fixp);
23824 }
23825
23826 #if defined (OBJ_ELF) || defined (OBJ_COFF)
23827 /* Relocations against function names must be left unadjusted,
23828 so that the linker can use this information to generate interworking
23829 stubs. The MIPS version of this function
23830 also prevents relocations that are mips-16 specific, but I do not
23831 know why it does this.
23832
23833 FIXME:
23834 There is one other problem that ought to be addressed here, but
23835 which currently is not: Taking the address of a label (rather
23836 than a function) and then later jumping to that address. Such
23837 addresses also ought to have their bottom bit set (assuming that
23838 they reside in Thumb code), but at the moment they will not. */
23839
23840 bfd_boolean
23841 arm_fix_adjustable (fixS * fixP)
23842 {
23843 if (fixP->fx_addsy == NULL)
23844 return 1;
23845
23846 /* Preserve relocations against symbols with function type. */
23847 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
23848 return FALSE;
23849
23850 if (THUMB_IS_FUNC (fixP->fx_addsy)
23851 && fixP->fx_subsy == NULL)
23852 return FALSE;
23853
23854 /* We need the symbol name for the VTABLE entries. */
23855 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
23856 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
23857 return FALSE;
23858
23859 /* Don't allow symbols to be discarded on GOT related relocs. */
23860 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
23861 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
23862 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
23863 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
23864 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
23865 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
23866 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
23867 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
23868 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
23869 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
23870 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
23871 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
23872 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
23873 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
23874 return FALSE;
23875
23876 /* Similarly for group relocations. */
23877 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
23878 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
23879 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
23880 return FALSE;
23881
23882 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
23883 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
23884 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
23885 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
23886 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
23887 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
23888 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
23889 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
23890 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
23891 return FALSE;
23892
23893 return TRUE;
23894 }
23895 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
23896
23897 #ifdef OBJ_ELF
23898
23899 const char *
23900 elf32_arm_target_format (void)
23901 {
23902 #ifdef TE_SYMBIAN
23903 return (target_big_endian
23904 ? "elf32-bigarm-symbian"
23905 : "elf32-littlearm-symbian");
23906 #elif defined (TE_VXWORKS)
23907 return (target_big_endian
23908 ? "elf32-bigarm-vxworks"
23909 : "elf32-littlearm-vxworks");
23910 #elif defined (TE_NACL)
23911 return (target_big_endian
23912 ? "elf32-bigarm-nacl"
23913 : "elf32-littlearm-nacl");
23914 #else
23915 if (target_big_endian)
23916 return "elf32-bigarm";
23917 else
23918 return "elf32-littlearm";
23919 #endif
23920 }
23921
23922 void
23923 armelf_frob_symbol (symbolS * symp,
23924 int * puntp)
23925 {
23926 elf_frob_symbol (symp, puntp);
23927 }
23928 #endif
23929
23930 /* MD interface: Finalization. */
23931
23932 void
23933 arm_cleanup (void)
23934 {
23935 literal_pool * pool;
23936
23937 /* Ensure that all the IT blocks are properly closed. */
23938 check_it_blocks_finished ();
23939
23940 for (pool = list_of_pools; pool; pool = pool->next)
23941 {
23942 /* Put it at the end of the relevant section. */
23943 subseg_set (pool->section, pool->sub_section);
23944 #ifdef OBJ_ELF
23945 arm_elf_change_section ();
23946 #endif
23947 s_ltorg (0);
23948 }
23949 }
23950
23951 #ifdef OBJ_ELF
23952 /* Remove any excess mapping symbols generated for alignment frags in
23953 SEC. We may have created a mapping symbol before a zero byte
23954 alignment; remove it if there's a mapping symbol after the
23955 alignment. */
23956 static void
23957 check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
23958 void *dummy ATTRIBUTE_UNUSED)
23959 {
23960 segment_info_type *seginfo = seg_info (sec);
23961 fragS *fragp;
23962
23963 if (seginfo == NULL || seginfo->frchainP == NULL)
23964 return;
23965
23966 for (fragp = seginfo->frchainP->frch_root;
23967 fragp != NULL;
23968 fragp = fragp->fr_next)
23969 {
23970 symbolS *sym = fragp->tc_frag_data.last_map;
23971 fragS *next = fragp->fr_next;
23972
23973 /* Variable-sized frags have been converted to fixed size by
23974 this point. But if this was variable-sized to start with,
23975 there will be a fixed-size frag after it. So don't handle
23976 next == NULL. */
23977 if (sym == NULL || next == NULL)
23978 continue;
23979
23980 if (S_GET_VALUE (sym) < next->fr_address)
23981 /* Not at the end of this frag. */
23982 continue;
23983 know (S_GET_VALUE (sym) == next->fr_address);
23984
23985 do
23986 {
23987 if (next->tc_frag_data.first_map != NULL)
23988 {
23989 /* Next frag starts with a mapping symbol. Discard this
23990 one. */
23991 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
23992 break;
23993 }
23994
23995 if (next->fr_next == NULL)
23996 {
23997 /* This mapping symbol is at the end of the section. Discard
23998 it. */
23999 know (next->fr_fix == 0 && next->fr_var == 0);
24000 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24001 break;
24002 }
24003
24004 /* As long as we have empty frags without any mapping symbols,
24005 keep looking. */
24006 /* If the next frag is non-empty and does not start with a
24007 mapping symbol, then this mapping symbol is required. */
24008 if (next->fr_address != next->fr_next->fr_address)
24009 break;
24010
24011 next = next->fr_next;
24012 }
24013 while (next != NULL);
24014 }
24015 }
24016 #endif
24017
24018 /* Adjust the symbol table. This marks Thumb symbols as distinct from
24019 ARM ones. */
24020
24021 void
24022 arm_adjust_symtab (void)
24023 {
24024 #ifdef OBJ_COFF
24025 symbolS * sym;
24026
24027 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
24028 {
24029 if (ARM_IS_THUMB (sym))
24030 {
24031 if (THUMB_IS_FUNC (sym))
24032 {
24033 /* Mark the symbol as a Thumb function. */
24034 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
24035 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
24036 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
24037
24038 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
24039 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
24040 else
24041 as_bad (_("%s: unexpected function type: %d"),
24042 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
24043 }
24044 else switch (S_GET_STORAGE_CLASS (sym))
24045 {
24046 case C_EXT:
24047 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
24048 break;
24049 case C_STAT:
24050 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
24051 break;
24052 case C_LABEL:
24053 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
24054 break;
24055 default:
24056 /* Do nothing. */
24057 break;
24058 }
24059 }
24060
24061 if (ARM_IS_INTERWORK (sym))
24062 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
24063 }
24064 #endif
24065 #ifdef OBJ_ELF
24066 symbolS * sym;
24067 char bind;
24068
24069 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
24070 {
24071 if (ARM_IS_THUMB (sym))
24072 {
24073 elf_symbol_type * elf_sym;
24074
24075 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
24076 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
24077
24078 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
24079 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
24080 {
24081 /* If it's a .thumb_func, declare it as so,
24082 otherwise tag label as .code 16. */
24083 if (THUMB_IS_FUNC (sym))
24084 elf_sym->internal_elf_sym.st_target_internal
24085 = ST_BRANCH_TO_THUMB;
24086 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
24087 elf_sym->internal_elf_sym.st_info =
24088 ELF_ST_INFO (bind, STT_ARM_16BIT);
24089 }
24090 }
24091 }
24092
24093 /* Remove any overlapping mapping symbols generated by alignment frags. */
24094 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
24095 /* Now do generic ELF adjustments. */
24096 elf_adjust_symtab ();
24097 #endif
24098 }
24099
24100 /* MD interface: Initialization. */
24101
24102 static void
24103 set_constant_flonums (void)
24104 {
24105 int i;
24106
24107 for (i = 0; i < NUM_FLOAT_VALS; i++)
24108 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
24109 abort ();
24110 }
24111
24112 /* Auto-select Thumb mode if it's the only available instruction set for the
24113 given architecture. */
24114
24115 static void
24116 autoselect_thumb_from_cpu_variant (void)
24117 {
24118 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
24119 opcode_select (16);
24120 }
24121
24122 void
24123 md_begin (void)
24124 {
24125 unsigned mach;
24126 unsigned int i;
24127
24128 if ( (arm_ops_hsh = hash_new ()) == NULL
24129 || (arm_cond_hsh = hash_new ()) == NULL
24130 || (arm_shift_hsh = hash_new ()) == NULL
24131 || (arm_psr_hsh = hash_new ()) == NULL
24132 || (arm_v7m_psr_hsh = hash_new ()) == NULL
24133 || (arm_reg_hsh = hash_new ()) == NULL
24134 || (arm_reloc_hsh = hash_new ()) == NULL
24135 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
24136 as_fatal (_("virtual memory exhausted"));
24137
24138 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
24139 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
24140 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
24141 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
24142 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
24143 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
24144 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
24145 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
24146 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
24147 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
24148 (void *) (v7m_psrs + i));
24149 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
24150 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
24151 for (i = 0;
24152 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
24153 i++)
24154 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
24155 (void *) (barrier_opt_names + i));
24156 #ifdef OBJ_ELF
24157 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
24158 {
24159 struct reloc_entry * entry = reloc_names + i;
24160
24161 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
24162 /* This makes encode_branch() use the EABI versions of this relocation. */
24163 entry->reloc = BFD_RELOC_UNUSED;
24164
24165 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
24166 }
24167 #endif
24168
24169 set_constant_flonums ();
24170
24171 /* Set the cpu variant based on the command-line options. We prefer
24172 -mcpu= over -march= if both are set (as for GCC); and we prefer
24173 -mfpu= over any other way of setting the floating point unit.
24174 Use of legacy options with new options are faulted. */
24175 if (legacy_cpu)
24176 {
24177 if (mcpu_cpu_opt || march_cpu_opt)
24178 as_bad (_("use of old and new-style options to set CPU type"));
24179
24180 mcpu_cpu_opt = legacy_cpu;
24181 }
24182 else if (!mcpu_cpu_opt)
24183 mcpu_cpu_opt = march_cpu_opt;
24184
24185 if (legacy_fpu)
24186 {
24187 if (mfpu_opt)
24188 as_bad (_("use of old and new-style options to set FPU type"));
24189
24190 mfpu_opt = legacy_fpu;
24191 }
24192 else if (!mfpu_opt)
24193 {
24194 #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
24195 || defined (TE_NetBSD) || defined (TE_VXWORKS))
24196 /* Some environments specify a default FPU. If they don't, infer it
24197 from the processor. */
24198 if (mcpu_fpu_opt)
24199 mfpu_opt = mcpu_fpu_opt;
24200 else
24201 mfpu_opt = march_fpu_opt;
24202 #else
24203 mfpu_opt = &fpu_default;
24204 #endif
24205 }
24206
24207 if (!mfpu_opt)
24208 {
24209 if (mcpu_cpu_opt != NULL)
24210 mfpu_opt = &fpu_default;
24211 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
24212 mfpu_opt = &fpu_arch_vfp_v2;
24213 else
24214 mfpu_opt = &fpu_arch_fpa;
24215 }
24216
24217 #ifdef CPU_DEFAULT
24218 if (!mcpu_cpu_opt)
24219 {
24220 mcpu_cpu_opt = &cpu_default;
24221 selected_cpu = cpu_default;
24222 }
24223 else if (no_cpu_selected ())
24224 selected_cpu = cpu_default;
24225 #else
24226 if (mcpu_cpu_opt)
24227 selected_cpu = *mcpu_cpu_opt;
24228 else
24229 mcpu_cpu_opt = &arm_arch_any;
24230 #endif
24231
24232 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
24233
24234 autoselect_thumb_from_cpu_variant ();
24235
24236 arm_arch_used = thumb_arch_used = arm_arch_none;
24237
24238 #if defined OBJ_COFF || defined OBJ_ELF
24239 {
24240 unsigned int flags = 0;
24241
24242 #if defined OBJ_ELF
24243 flags = meabi_flags;
24244
24245 switch (meabi_flags)
24246 {
24247 case EF_ARM_EABI_UNKNOWN:
24248 #endif
24249 /* Set the flags in the private structure. */
24250 if (uses_apcs_26) flags |= F_APCS26;
24251 if (support_interwork) flags |= F_INTERWORK;
24252 if (uses_apcs_float) flags |= F_APCS_FLOAT;
24253 if (pic_code) flags |= F_PIC;
24254 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
24255 flags |= F_SOFT_FLOAT;
24256
24257 switch (mfloat_abi_opt)
24258 {
24259 case ARM_FLOAT_ABI_SOFT:
24260 case ARM_FLOAT_ABI_SOFTFP:
24261 flags |= F_SOFT_FLOAT;
24262 break;
24263
24264 case ARM_FLOAT_ABI_HARD:
24265 if (flags & F_SOFT_FLOAT)
24266 as_bad (_("hard-float conflicts with specified fpu"));
24267 break;
24268 }
24269
24270 /* Using pure-endian doubles (even if soft-float). */
24271 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
24272 flags |= F_VFP_FLOAT;
24273
24274 #if defined OBJ_ELF
24275 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
24276 flags |= EF_ARM_MAVERICK_FLOAT;
24277 break;
24278
24279 case EF_ARM_EABI_VER4:
24280 case EF_ARM_EABI_VER5:
24281 /* No additional flags to set. */
24282 break;
24283
24284 default:
24285 abort ();
24286 }
24287 #endif
24288 bfd_set_private_flags (stdoutput, flags);
24289
24290 /* We have run out flags in the COFF header to encode the
24291 status of ATPCS support, so instead we create a dummy,
24292 empty, debug section called .arm.atpcs. */
24293 if (atpcs)
24294 {
24295 asection * sec;
24296
24297 sec = bfd_make_section (stdoutput, ".arm.atpcs");
24298
24299 if (sec != NULL)
24300 {
24301 bfd_set_section_flags
24302 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
24303 bfd_set_section_size (stdoutput, sec, 0);
24304 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
24305 }
24306 }
24307 }
24308 #endif
24309
24310 /* Record the CPU type as well. */
24311 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
24312 mach = bfd_mach_arm_iWMMXt2;
24313 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
24314 mach = bfd_mach_arm_iWMMXt;
24315 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
24316 mach = bfd_mach_arm_XScale;
24317 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
24318 mach = bfd_mach_arm_ep9312;
24319 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
24320 mach = bfd_mach_arm_5TE;
24321 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
24322 {
24323 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
24324 mach = bfd_mach_arm_5T;
24325 else
24326 mach = bfd_mach_arm_5;
24327 }
24328 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
24329 {
24330 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
24331 mach = bfd_mach_arm_4T;
24332 else
24333 mach = bfd_mach_arm_4;
24334 }
24335 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
24336 mach = bfd_mach_arm_3M;
24337 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
24338 mach = bfd_mach_arm_3;
24339 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
24340 mach = bfd_mach_arm_2a;
24341 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
24342 mach = bfd_mach_arm_2;
24343 else
24344 mach = bfd_mach_arm_unknown;
24345
24346 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
24347 }
24348
24349 /* Command line processing. */
24350
24351 /* md_parse_option
24352 Invocation line includes a switch not recognized by the base assembler.
24353 See if it's a processor-specific option.
24354
24355 This routine is somewhat complicated by the need for backwards
24356 compatibility (since older releases of gcc can't be changed).
24357 The new options try to make the interface as compatible as
24358 possible with GCC.
24359
24360 New options (supported) are:
24361
24362 -mcpu=<cpu name> Assemble for selected processor
24363 -march=<architecture name> Assemble for selected architecture
24364 -mfpu=<fpu architecture> Assemble for selected FPU.
24365 -EB/-mbig-endian Big-endian
24366 -EL/-mlittle-endian Little-endian
24367 -k Generate PIC code
24368 -mthumb Start in Thumb mode
24369 -mthumb-interwork Code supports ARM/Thumb interworking
24370
24371 -m[no-]warn-deprecated Warn about deprecated features
24372 -m[no-]warn-syms Warn when symbols match instructions
24373
24374 For now we will also provide support for:
24375
24376 -mapcs-32 32-bit Program counter
24377 -mapcs-26 26-bit Program counter
24378 -macps-float Floats passed in FP registers
24379 -mapcs-reentrant Reentrant code
24380 -matpcs
24381 (sometime these will probably be replaced with -mapcs=<list of options>
24382 and -matpcs=<list of options>)
24383
24384 The remaining options are only supported for back-wards compatibility.
24385 Cpu variants, the arm part is optional:
24386 -m[arm]1 Currently not supported.
24387 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
24388 -m[arm]3 Arm 3 processor
24389 -m[arm]6[xx], Arm 6 processors
24390 -m[arm]7[xx][t][[d]m] Arm 7 processors
24391 -m[arm]8[10] Arm 8 processors
24392 -m[arm]9[20][tdmi] Arm 9 processors
24393 -mstrongarm[110[0]] StrongARM processors
24394 -mxscale XScale processors
24395 -m[arm]v[2345[t[e]]] Arm architectures
24396 -mall All (except the ARM1)
24397 FP variants:
24398 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
24399 -mfpe-old (No float load/store multiples)
24400 -mvfpxd VFP Single precision
24401 -mvfp All VFP
24402 -mno-fpu Disable all floating point instructions
24403
24404 The following CPU names are recognized:
24405 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
24406 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
24407 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
24408 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
24409 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
24410 arm10t arm10e, arm1020t, arm1020e, arm10200e,
24411 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
24412
24413 */
24414
24415 const char * md_shortopts = "m:k";
24416
24417 #ifdef ARM_BI_ENDIAN
24418 #define OPTION_EB (OPTION_MD_BASE + 0)
24419 #define OPTION_EL (OPTION_MD_BASE + 1)
24420 #else
24421 #if TARGET_BYTES_BIG_ENDIAN
24422 #define OPTION_EB (OPTION_MD_BASE + 0)
24423 #else
24424 #define OPTION_EL (OPTION_MD_BASE + 1)
24425 #endif
24426 #endif
24427 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
24428
24429 struct option md_longopts[] =
24430 {
24431 #ifdef OPTION_EB
24432 {"EB", no_argument, NULL, OPTION_EB},
24433 #endif
24434 #ifdef OPTION_EL
24435 {"EL", no_argument, NULL, OPTION_EL},
24436 #endif
24437 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
24438 {NULL, no_argument, NULL, 0}
24439 };
24440
24441
24442 size_t md_longopts_size = sizeof (md_longopts);
24443
24444 struct arm_option_table
24445 {
24446 char *option; /* Option name to match. */
24447 char *help; /* Help information. */
24448 int *var; /* Variable to change. */
24449 int value; /* What to change it to. */
24450 char *deprecated; /* If non-null, print this message. */
24451 };
24452
24453 struct arm_option_table arm_opts[] =
24454 {
24455 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
24456 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
24457 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
24458 &support_interwork, 1, NULL},
24459 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
24460 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
24461 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
24462 1, NULL},
24463 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
24464 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
24465 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
24466 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
24467 NULL},
24468
24469 /* These are recognized by the assembler, but have no affect on code. */
24470 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
24471 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
24472
24473 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
24474 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
24475 &warn_on_deprecated, 0, NULL},
24476 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
24477 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
24478 {NULL, NULL, NULL, 0, NULL}
24479 };
24480
24481 struct arm_legacy_option_table
24482 {
24483 char *option; /* Option name to match. */
24484 const arm_feature_set **var; /* Variable to change. */
24485 const arm_feature_set value; /* What to change it to. */
24486 char *deprecated; /* If non-null, print this message. */
24487 };
24488
24489 const struct arm_legacy_option_table arm_legacy_opts[] =
24490 {
24491 /* DON'T add any new processors to this list -- we want the whole list
24492 to go away... Add them to the processors table instead. */
24493 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
24494 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
24495 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
24496 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
24497 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
24498 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
24499 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
24500 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
24501 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
24502 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
24503 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
24504 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
24505 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
24506 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
24507 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
24508 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
24509 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
24510 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
24511 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
24512 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
24513 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
24514 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
24515 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
24516 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
24517 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
24518 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
24519 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
24520 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
24521 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
24522 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
24523 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
24524 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
24525 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
24526 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
24527 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
24528 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
24529 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
24530 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
24531 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
24532 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
24533 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
24534 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
24535 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
24536 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
24537 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
24538 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
24539 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
24540 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
24541 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
24542 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
24543 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
24544 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
24545 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
24546 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
24547 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
24548 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
24549 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
24550 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
24551 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
24552 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
24553 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
24554 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
24555 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
24556 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
24557 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
24558 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
24559 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
24560 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
24561 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
24562 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
24563 N_("use -mcpu=strongarm110")},
24564 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
24565 N_("use -mcpu=strongarm1100")},
24566 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
24567 N_("use -mcpu=strongarm1110")},
24568 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
24569 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
24570 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
24571
24572 /* Architecture variants -- don't add any more to this list either. */
24573 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
24574 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
24575 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
24576 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
24577 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
24578 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
24579 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
24580 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
24581 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
24582 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
24583 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
24584 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
24585 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
24586 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
24587 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
24588 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
24589 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
24590 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
24591
24592 /* Floating point variants -- don't add any more to this list either. */
24593 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
24594 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
24595 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
24596 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
24597 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
24598
24599 {NULL, NULL, ARM_ARCH_NONE, NULL}
24600 };
24601
24602 struct arm_cpu_option_table
24603 {
24604 char *name;
24605 size_t name_len;
24606 const arm_feature_set value;
24607 /* For some CPUs we assume an FPU unless the user explicitly sets
24608 -mfpu=... */
24609 const arm_feature_set default_fpu;
24610 /* The canonical name of the CPU, or NULL to use NAME converted to upper
24611 case. */
24612 const char *canonical_name;
24613 };
24614
24615 /* This list should, at a minimum, contain all the cpu names
24616 recognized by GCC. */
24617 #define ARM_CPU_OPT(N, V, DF, CN) { N, sizeof (N) - 1, V, DF, CN }
24618 static const struct arm_cpu_option_table arm_cpus[] =
24619 {
24620 ARM_CPU_OPT ("all", ARM_ANY, FPU_ARCH_FPA, NULL),
24621 ARM_CPU_OPT ("arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL),
24622 ARM_CPU_OPT ("arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL),
24623 ARM_CPU_OPT ("arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
24624 ARM_CPU_OPT ("arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
24625 ARM_CPU_OPT ("arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24626 ARM_CPU_OPT ("arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24627 ARM_CPU_OPT ("arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24628 ARM_CPU_OPT ("arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24629 ARM_CPU_OPT ("arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24630 ARM_CPU_OPT ("arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24631 ARM_CPU_OPT ("arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
24632 ARM_CPU_OPT ("arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24633 ARM_CPU_OPT ("arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
24634 ARM_CPU_OPT ("arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24635 ARM_CPU_OPT ("arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
24636 ARM_CPU_OPT ("arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24637 ARM_CPU_OPT ("arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24638 ARM_CPU_OPT ("arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24639 ARM_CPU_OPT ("arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24640 ARM_CPU_OPT ("arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24641 ARM_CPU_OPT ("arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24642 ARM_CPU_OPT ("arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24643 ARM_CPU_OPT ("arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24644 ARM_CPU_OPT ("arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24645 ARM_CPU_OPT ("arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24646 ARM_CPU_OPT ("arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24647 ARM_CPU_OPT ("arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24648 ARM_CPU_OPT ("arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24649 ARM_CPU_OPT ("arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24650 ARM_CPU_OPT ("arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24651 ARM_CPU_OPT ("arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24652 ARM_CPU_OPT ("arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24653 ARM_CPU_OPT ("strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24654 ARM_CPU_OPT ("strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24655 ARM_CPU_OPT ("strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24656 ARM_CPU_OPT ("strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24657 ARM_CPU_OPT ("strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24658 ARM_CPU_OPT ("arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24659 ARM_CPU_OPT ("arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"),
24660 ARM_CPU_OPT ("arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24661 ARM_CPU_OPT ("arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24662 ARM_CPU_OPT ("arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24663 ARM_CPU_OPT ("arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24664 ARM_CPU_OPT ("fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24665 ARM_CPU_OPT ("fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24666 /* For V5 or later processors we default to using VFP; but the user
24667 should really set the FPU type explicitly. */
24668 ARM_CPU_OPT ("arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
24669 ARM_CPU_OPT ("arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24670 ARM_CPU_OPT ("arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
24671 ARM_CPU_OPT ("arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
24672 ARM_CPU_OPT ("arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
24673 ARM_CPU_OPT ("arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
24674 ARM_CPU_OPT ("arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"),
24675 ARM_CPU_OPT ("arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24676 ARM_CPU_OPT ("arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
24677 ARM_CPU_OPT ("arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"),
24678 ARM_CPU_OPT ("arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24679 ARM_CPU_OPT ("arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24680 ARM_CPU_OPT ("arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
24681 ARM_CPU_OPT ("arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
24682 ARM_CPU_OPT ("arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24683 ARM_CPU_OPT ("arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"),
24684 ARM_CPU_OPT ("arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
24685 ARM_CPU_OPT ("arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24686 ARM_CPU_OPT ("arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24687 ARM_CPU_OPT ("arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2,
24688 "ARM1026EJ-S"),
24689 ARM_CPU_OPT ("arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
24690 ARM_CPU_OPT ("fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24691 ARM_CPU_OPT ("fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24692 ARM_CPU_OPT ("fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24693 ARM_CPU_OPT ("fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24694 ARM_CPU_OPT ("fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24695 ARM_CPU_OPT ("arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"),
24696 ARM_CPU_OPT ("arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL),
24697 ARM_CPU_OPT ("arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2,
24698 "ARM1136JF-S"),
24699 ARM_CPU_OPT ("arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL),
24700 ARM_CPU_OPT ("mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"),
24701 ARM_CPU_OPT ("mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"),
24702 ARM_CPU_OPT ("arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL),
24703 ARM_CPU_OPT ("arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL),
24704 ARM_CPU_OPT ("arm1176jz-s", ARM_ARCH_V6KZ, FPU_NONE, NULL),
24705 ARM_CPU_OPT ("arm1176jzf-s", ARM_ARCH_V6KZ, FPU_ARCH_VFP_V2, NULL),
24706 ARM_CPU_OPT ("cortex-a5", ARM_ARCH_V7A_MP_SEC,
24707 FPU_NONE, "Cortex-A5"),
24708 ARM_CPU_OPT ("cortex-a7", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
24709 "Cortex-A7"),
24710 ARM_CPU_OPT ("cortex-a8", ARM_ARCH_V7A_SEC,
24711 ARM_FEATURE_COPROC (FPU_VFP_V3
24712 | FPU_NEON_EXT_V1),
24713 "Cortex-A8"),
24714 ARM_CPU_OPT ("cortex-a9", ARM_ARCH_V7A_MP_SEC,
24715 ARM_FEATURE_COPROC (FPU_VFP_V3
24716 | FPU_NEON_EXT_V1),
24717 "Cortex-A9"),
24718 ARM_CPU_OPT ("cortex-a12", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
24719 "Cortex-A12"),
24720 ARM_CPU_OPT ("cortex-a15", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
24721 "Cortex-A15"),
24722 ARM_CPU_OPT ("cortex-a17", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
24723 "Cortex-A17"),
24724 ARM_CPU_OPT ("cortex-a53", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24725 "Cortex-A53"),
24726 ARM_CPU_OPT ("cortex-a57", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24727 "Cortex-A57"),
24728 ARM_CPU_OPT ("cortex-a72", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24729 "Cortex-A72"),
24730 ARM_CPU_OPT ("cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"),
24731 ARM_CPU_OPT ("cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
24732 "Cortex-R4F"),
24733 ARM_CPU_OPT ("cortex-r5", ARM_ARCH_V7R_IDIV,
24734 FPU_NONE, "Cortex-R5"),
24735 ARM_CPU_OPT ("cortex-r7", ARM_ARCH_V7R_IDIV,
24736 FPU_ARCH_VFP_V3D16,
24737 "Cortex-R7"),
24738 ARM_CPU_OPT ("cortex-m7", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M7"),
24739 ARM_CPU_OPT ("cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"),
24740 ARM_CPU_OPT ("cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"),
24741 ARM_CPU_OPT ("cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"),
24742 ARM_CPU_OPT ("cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"),
24743 ARM_CPU_OPT ("cortex-m0plus", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0+"),
24744 ARM_CPU_OPT ("exynos-m1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24745 "Samsung " \
24746 "Exynos M1"),
24747 /* ??? XSCALE is really an architecture. */
24748 ARM_CPU_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
24749 /* ??? iwmmxt is not a processor. */
24750 ARM_CPU_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL),
24751 ARM_CPU_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL),
24752 ARM_CPU_OPT ("i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
24753 /* Maverick */
24754 ARM_CPU_OPT ("ep9312", ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
24755 FPU_ARCH_MAVERICK, "ARM920T"),
24756 /* Marvell processors. */
24757 ARM_CPU_OPT ("marvell-pj4", ARM_FEATURE_CORE_LOW (ARM_AEXT_V7A | ARM_EXT_MP
24758 | ARM_EXT_SEC),
24759 FPU_ARCH_VFP_V3D16, NULL),
24760 ARM_CPU_OPT ("marvell-whitney", ARM_FEATURE_CORE_LOW (ARM_AEXT_V7A | ARM_EXT_MP
24761 | ARM_EXT_SEC),
24762 FPU_ARCH_NEON_VFP_V4, NULL),
24763 /* APM X-Gene family. */
24764 ARM_CPU_OPT ("xgene1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24765 "APM X-Gene 1"),
24766 ARM_CPU_OPT ("xgene2", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24767 "APM X-Gene 2"),
24768
24769 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
24770 };
24771 #undef ARM_CPU_OPT
24772
24773 struct arm_arch_option_table
24774 {
24775 char *name;
24776 size_t name_len;
24777 const arm_feature_set value;
24778 const arm_feature_set default_fpu;
24779 };
24780
24781 /* This list should, at a minimum, contain all the architecture names
24782 recognized by GCC. */
24783 #define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
24784 static const struct arm_arch_option_table arm_archs[] =
24785 {
24786 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
24787 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
24788 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
24789 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
24790 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
24791 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
24792 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
24793 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
24794 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
24795 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
24796 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
24797 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
24798 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
24799 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
24800 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
24801 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
24802 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
24803 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
24804 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
24805 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
24806 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
24807 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
24808 kept to preserve existing behaviour. */
24809 ARM_ARCH_OPT ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
24810 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
24811 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
24812 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
24813 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
24814 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
24815 kept to preserve existing behaviour. */
24816 ARM_ARCH_OPT ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
24817 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
24818 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
24819 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
24820 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
24821 /* The official spelling of the ARMv7 profile variants is the dashed form.
24822 Accept the non-dashed form for compatibility with old toolchains. */
24823 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
24824 ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP),
24825 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
24826 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
24827 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
24828 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
24829 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
24830 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
24831 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
24832 ARM_ARCH_OPT ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP),
24833 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
24834 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
24835 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
24836 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
24837 };
24838 #undef ARM_ARCH_OPT
24839
24840 /* ISA extensions in the co-processor and main instruction set space. */
24841 struct arm_option_extension_value_table
24842 {
24843 char *name;
24844 size_t name_len;
24845 const arm_feature_set merge_value;
24846 const arm_feature_set clear_value;
24847 const arm_feature_set allowed_archs;
24848 };
24849
24850 /* The following table must be in alphabetical order with a NULL last entry.
24851 */
24852 #define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, AA }
24853 static const struct arm_option_extension_value_table arm_extensions[] =
24854 {
24855 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
24856 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
24857 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24858 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
24859 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
24860 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
24861 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
24862 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
24863 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
24864 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A | ARM_EXT_V7R)),
24865 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
24866 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ANY),
24867 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
24868 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ANY),
24869 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
24870 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ANY),
24871 ARM_EXT_OPT ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
24872 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
24873 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A | ARM_EXT_V7R)),
24874 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
24875 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
24876 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
24877 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
24878 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
24879 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
24880 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
24881 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
24882 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
24883 ARM_EXT_OPT ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
24884 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
24885 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V7A)),
24886 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
24887 | ARM_EXT_DIV),
24888 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
24889 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
24890 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8,
24891 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
24892 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
24893 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
24894 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ANY),
24895 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE }
24896 };
24897 #undef ARM_EXT_OPT
24898
24899 /* ISA floating-point and Advanced SIMD extensions. */
24900 struct arm_option_fpu_value_table
24901 {
24902 char *name;
24903 const arm_feature_set value;
24904 };
24905
24906 /* This list should, at a minimum, contain all the fpu names
24907 recognized by GCC. */
24908 static const struct arm_option_fpu_value_table arm_fpus[] =
24909 {
24910 {"softfpa", FPU_NONE},
24911 {"fpe", FPU_ARCH_FPE},
24912 {"fpe2", FPU_ARCH_FPE},
24913 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
24914 {"fpa", FPU_ARCH_FPA},
24915 {"fpa10", FPU_ARCH_FPA},
24916 {"fpa11", FPU_ARCH_FPA},
24917 {"arm7500fe", FPU_ARCH_FPA},
24918 {"softvfp", FPU_ARCH_VFP},
24919 {"softvfp+vfp", FPU_ARCH_VFP_V2},
24920 {"vfp", FPU_ARCH_VFP_V2},
24921 {"vfp9", FPU_ARCH_VFP_V2},
24922 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
24923 {"vfp10", FPU_ARCH_VFP_V2},
24924 {"vfp10-r0", FPU_ARCH_VFP_V1},
24925 {"vfpxd", FPU_ARCH_VFP_V1xD},
24926 {"vfpv2", FPU_ARCH_VFP_V2},
24927 {"vfpv3", FPU_ARCH_VFP_V3},
24928 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
24929 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
24930 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
24931 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
24932 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
24933 {"arm1020t", FPU_ARCH_VFP_V1},
24934 {"arm1020e", FPU_ARCH_VFP_V2},
24935 {"arm1136jfs", FPU_ARCH_VFP_V2},
24936 {"arm1136jf-s", FPU_ARCH_VFP_V2},
24937 {"maverick", FPU_ARCH_MAVERICK},
24938 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
24939 {"neon-fp16", FPU_ARCH_NEON_FP16},
24940 {"vfpv4", FPU_ARCH_VFP_V4},
24941 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
24942 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
24943 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
24944 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
24945 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
24946 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
24947 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
24948 {"crypto-neon-fp-armv8",
24949 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
24950 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
24951 {"crypto-neon-fp-armv8.1",
24952 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
24953 {NULL, ARM_ARCH_NONE}
24954 };
24955
24956 struct arm_option_value_table
24957 {
24958 char *name;
24959 long value;
24960 };
24961
24962 static const struct arm_option_value_table arm_float_abis[] =
24963 {
24964 {"hard", ARM_FLOAT_ABI_HARD},
24965 {"softfp", ARM_FLOAT_ABI_SOFTFP},
24966 {"soft", ARM_FLOAT_ABI_SOFT},
24967 {NULL, 0}
24968 };
24969
24970 #ifdef OBJ_ELF
24971 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
24972 static const struct arm_option_value_table arm_eabis[] =
24973 {
24974 {"gnu", EF_ARM_EABI_UNKNOWN},
24975 {"4", EF_ARM_EABI_VER4},
24976 {"5", EF_ARM_EABI_VER5},
24977 {NULL, 0}
24978 };
24979 #endif
24980
24981 struct arm_long_option_table
24982 {
24983 char * option; /* Substring to match. */
24984 char * help; /* Help information. */
24985 int (* func) (char * subopt); /* Function to decode sub-option. */
24986 char * deprecated; /* If non-null, print this message. */
24987 };
24988
24989 static bfd_boolean
24990 arm_parse_extension (char *str, const arm_feature_set **opt_p)
24991 {
24992 arm_feature_set *ext_set = (arm_feature_set *)
24993 xmalloc (sizeof (arm_feature_set));
24994
24995 /* We insist on extensions being specified in alphabetical order, and with
24996 extensions being added before being removed. We achieve this by having
24997 the global ARM_EXTENSIONS table in alphabetical order, and using the
24998 ADDING_VALUE variable to indicate whether we are adding an extension (1)
24999 or removing it (0) and only allowing it to change in the order
25000 -1 -> 1 -> 0. */
25001 const struct arm_option_extension_value_table * opt = NULL;
25002 int adding_value = -1;
25003
25004 /* Copy the feature set, so that we can modify it. */
25005 *ext_set = **opt_p;
25006 *opt_p = ext_set;
25007
25008 while (str != NULL && *str != 0)
25009 {
25010 char *ext;
25011 size_t len;
25012
25013 if (*str != '+')
25014 {
25015 as_bad (_("invalid architectural extension"));
25016 return FALSE;
25017 }
25018
25019 str++;
25020 ext = strchr (str, '+');
25021
25022 if (ext != NULL)
25023 len = ext - str;
25024 else
25025 len = strlen (str);
25026
25027 if (len >= 2 && strncmp (str, "no", 2) == 0)
25028 {
25029 if (adding_value != 0)
25030 {
25031 adding_value = 0;
25032 opt = arm_extensions;
25033 }
25034
25035 len -= 2;
25036 str += 2;
25037 }
25038 else if (len > 0)
25039 {
25040 if (adding_value == -1)
25041 {
25042 adding_value = 1;
25043 opt = arm_extensions;
25044 }
25045 else if (adding_value != 1)
25046 {
25047 as_bad (_("must specify extensions to add before specifying "
25048 "those to remove"));
25049 return FALSE;
25050 }
25051 }
25052
25053 if (len == 0)
25054 {
25055 as_bad (_("missing architectural extension"));
25056 return FALSE;
25057 }
25058
25059 gas_assert (adding_value != -1);
25060 gas_assert (opt != NULL);
25061
25062 /* Scan over the options table trying to find an exact match. */
25063 for (; opt->name != NULL; opt++)
25064 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
25065 {
25066 /* Check we can apply the extension to this architecture. */
25067 if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs))
25068 {
25069 as_bad (_("extension does not apply to the base architecture"));
25070 return FALSE;
25071 }
25072
25073 /* Add or remove the extension. */
25074 if (adding_value)
25075 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
25076 else
25077 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
25078
25079 break;
25080 }
25081
25082 if (opt->name == NULL)
25083 {
25084 /* Did we fail to find an extension because it wasn't specified in
25085 alphabetical order, or because it does not exist? */
25086
25087 for (opt = arm_extensions; opt->name != NULL; opt++)
25088 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
25089 break;
25090
25091 if (opt->name == NULL)
25092 as_bad (_("unknown architectural extension `%s'"), str);
25093 else
25094 as_bad (_("architectural extensions must be specified in "
25095 "alphabetical order"));
25096
25097 return FALSE;
25098 }
25099 else
25100 {
25101 /* We should skip the extension we've just matched the next time
25102 round. */
25103 opt++;
25104 }
25105
25106 str = ext;
25107 };
25108
25109 return TRUE;
25110 }
25111
25112 static bfd_boolean
25113 arm_parse_cpu (char *str)
25114 {
25115 const struct arm_cpu_option_table *opt;
25116 char *ext = strchr (str, '+');
25117 size_t len;
25118
25119 if (ext != NULL)
25120 len = ext - str;
25121 else
25122 len = strlen (str);
25123
25124 if (len == 0)
25125 {
25126 as_bad (_("missing cpu name `%s'"), str);
25127 return FALSE;
25128 }
25129
25130 for (opt = arm_cpus; opt->name != NULL; opt++)
25131 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
25132 {
25133 mcpu_cpu_opt = &opt->value;
25134 mcpu_fpu_opt = &opt->default_fpu;
25135 if (opt->canonical_name)
25136 strcpy (selected_cpu_name, opt->canonical_name);
25137 else
25138 {
25139 size_t i;
25140
25141 for (i = 0; i < len; i++)
25142 selected_cpu_name[i] = TOUPPER (opt->name[i]);
25143 selected_cpu_name[i] = 0;
25144 }
25145
25146 if (ext != NULL)
25147 return arm_parse_extension (ext, &mcpu_cpu_opt);
25148
25149 return TRUE;
25150 }
25151
25152 as_bad (_("unknown cpu `%s'"), str);
25153 return FALSE;
25154 }
25155
25156 static bfd_boolean
25157 arm_parse_arch (char *str)
25158 {
25159 const struct arm_arch_option_table *opt;
25160 char *ext = strchr (str, '+');
25161 size_t len;
25162
25163 if (ext != NULL)
25164 len = ext - str;
25165 else
25166 len = strlen (str);
25167
25168 if (len == 0)
25169 {
25170 as_bad (_("missing architecture name `%s'"), str);
25171 return FALSE;
25172 }
25173
25174 for (opt = arm_archs; opt->name != NULL; opt++)
25175 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
25176 {
25177 march_cpu_opt = &opt->value;
25178 march_fpu_opt = &opt->default_fpu;
25179 strcpy (selected_cpu_name, opt->name);
25180
25181 if (ext != NULL)
25182 return arm_parse_extension (ext, &march_cpu_opt);
25183
25184 return TRUE;
25185 }
25186
25187 as_bad (_("unknown architecture `%s'\n"), str);
25188 return FALSE;
25189 }
25190
25191 static bfd_boolean
25192 arm_parse_fpu (char * str)
25193 {
25194 const struct arm_option_fpu_value_table * opt;
25195
25196 for (opt = arm_fpus; opt->name != NULL; opt++)
25197 if (streq (opt->name, str))
25198 {
25199 mfpu_opt = &opt->value;
25200 return TRUE;
25201 }
25202
25203 as_bad (_("unknown floating point format `%s'\n"), str);
25204 return FALSE;
25205 }
25206
25207 static bfd_boolean
25208 arm_parse_float_abi (char * str)
25209 {
25210 const struct arm_option_value_table * opt;
25211
25212 for (opt = arm_float_abis; opt->name != NULL; opt++)
25213 if (streq (opt->name, str))
25214 {
25215 mfloat_abi_opt = opt->value;
25216 return TRUE;
25217 }
25218
25219 as_bad (_("unknown floating point abi `%s'\n"), str);
25220 return FALSE;
25221 }
25222
25223 #ifdef OBJ_ELF
25224 static bfd_boolean
25225 arm_parse_eabi (char * str)
25226 {
25227 const struct arm_option_value_table *opt;
25228
25229 for (opt = arm_eabis; opt->name != NULL; opt++)
25230 if (streq (opt->name, str))
25231 {
25232 meabi_flags = opt->value;
25233 return TRUE;
25234 }
25235 as_bad (_("unknown EABI `%s'\n"), str);
25236 return FALSE;
25237 }
25238 #endif
25239
25240 static bfd_boolean
25241 arm_parse_it_mode (char * str)
25242 {
25243 bfd_boolean ret = TRUE;
25244
25245 if (streq ("arm", str))
25246 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
25247 else if (streq ("thumb", str))
25248 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
25249 else if (streq ("always", str))
25250 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
25251 else if (streq ("never", str))
25252 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
25253 else
25254 {
25255 as_bad (_("unknown implicit IT mode `%s', should be "\
25256 "arm, thumb, always, or never."), str);
25257 ret = FALSE;
25258 }
25259
25260 return ret;
25261 }
25262
25263 static bfd_boolean
25264 arm_ccs_mode (char * unused ATTRIBUTE_UNUSED)
25265 {
25266 codecomposer_syntax = TRUE;
25267 arm_comment_chars[0] = ';';
25268 arm_line_separator_chars[0] = 0;
25269 return TRUE;
25270 }
25271
25272 struct arm_long_option_table arm_long_opts[] =
25273 {
25274 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
25275 arm_parse_cpu, NULL},
25276 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
25277 arm_parse_arch, NULL},
25278 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
25279 arm_parse_fpu, NULL},
25280 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
25281 arm_parse_float_abi, NULL},
25282 #ifdef OBJ_ELF
25283 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
25284 arm_parse_eabi, NULL},
25285 #endif
25286 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
25287 arm_parse_it_mode, NULL},
25288 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
25289 arm_ccs_mode, NULL},
25290 {NULL, NULL, 0, NULL}
25291 };
25292
25293 int
25294 md_parse_option (int c, char * arg)
25295 {
25296 struct arm_option_table *opt;
25297 const struct arm_legacy_option_table *fopt;
25298 struct arm_long_option_table *lopt;
25299
25300 switch (c)
25301 {
25302 #ifdef OPTION_EB
25303 case OPTION_EB:
25304 target_big_endian = 1;
25305 break;
25306 #endif
25307
25308 #ifdef OPTION_EL
25309 case OPTION_EL:
25310 target_big_endian = 0;
25311 break;
25312 #endif
25313
25314 case OPTION_FIX_V4BX:
25315 fix_v4bx = TRUE;
25316 break;
25317
25318 case 'a':
25319 /* Listing option. Just ignore these, we don't support additional
25320 ones. */
25321 return 0;
25322
25323 default:
25324 for (opt = arm_opts; opt->option != NULL; opt++)
25325 {
25326 if (c == opt->option[0]
25327 && ((arg == NULL && opt->option[1] == 0)
25328 || streq (arg, opt->option + 1)))
25329 {
25330 /* If the option is deprecated, tell the user. */
25331 if (warn_on_deprecated && opt->deprecated != NULL)
25332 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
25333 arg ? arg : "", _(opt->deprecated));
25334
25335 if (opt->var != NULL)
25336 *opt->var = opt->value;
25337
25338 return 1;
25339 }
25340 }
25341
25342 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
25343 {
25344 if (c == fopt->option[0]
25345 && ((arg == NULL && fopt->option[1] == 0)
25346 || streq (arg, fopt->option + 1)))
25347 {
25348 /* If the option is deprecated, tell the user. */
25349 if (warn_on_deprecated && fopt->deprecated != NULL)
25350 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
25351 arg ? arg : "", _(fopt->deprecated));
25352
25353 if (fopt->var != NULL)
25354 *fopt->var = &fopt->value;
25355
25356 return 1;
25357 }
25358 }
25359
25360 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
25361 {
25362 /* These options are expected to have an argument. */
25363 if (c == lopt->option[0]
25364 && arg != NULL
25365 && strncmp (arg, lopt->option + 1,
25366 strlen (lopt->option + 1)) == 0)
25367 {
25368 /* If the option is deprecated, tell the user. */
25369 if (warn_on_deprecated && lopt->deprecated != NULL)
25370 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
25371 _(lopt->deprecated));
25372
25373 /* Call the sup-option parser. */
25374 return lopt->func (arg + strlen (lopt->option) - 1);
25375 }
25376 }
25377
25378 return 0;
25379 }
25380
25381 return 1;
25382 }
25383
25384 void
25385 md_show_usage (FILE * fp)
25386 {
25387 struct arm_option_table *opt;
25388 struct arm_long_option_table *lopt;
25389
25390 fprintf (fp, _(" ARM-specific assembler options:\n"));
25391
25392 for (opt = arm_opts; opt->option != NULL; opt++)
25393 if (opt->help != NULL)
25394 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
25395
25396 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
25397 if (lopt->help != NULL)
25398 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
25399
25400 #ifdef OPTION_EB
25401 fprintf (fp, _("\
25402 -EB assemble code for a big-endian cpu\n"));
25403 #endif
25404
25405 #ifdef OPTION_EL
25406 fprintf (fp, _("\
25407 -EL assemble code for a little-endian cpu\n"));
25408 #endif
25409
25410 fprintf (fp, _("\
25411 --fix-v4bx Allow BX in ARMv4 code\n"));
25412 }
25413
25414
25415 #ifdef OBJ_ELF
25416 typedef struct
25417 {
25418 int val;
25419 arm_feature_set flags;
25420 } cpu_arch_ver_table;
25421
25422 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
25423 least features first. */
25424 static const cpu_arch_ver_table cpu_arch_ver[] =
25425 {
25426 {1, ARM_ARCH_V4},
25427 {2, ARM_ARCH_V4T},
25428 {3, ARM_ARCH_V5},
25429 {3, ARM_ARCH_V5T},
25430 {4, ARM_ARCH_V5TE},
25431 {5, ARM_ARCH_V5TEJ},
25432 {6, ARM_ARCH_V6},
25433 {9, ARM_ARCH_V6K},
25434 {7, ARM_ARCH_V6Z},
25435 {11, ARM_ARCH_V6M},
25436 {12, ARM_ARCH_V6SM},
25437 {8, ARM_ARCH_V6T2},
25438 {10, ARM_ARCH_V7VE},
25439 {10, ARM_ARCH_V7R},
25440 {10, ARM_ARCH_V7M},
25441 {14, ARM_ARCH_V8A},
25442 {0, ARM_ARCH_NONE}
25443 };
25444
25445 /* Set an attribute if it has not already been set by the user. */
25446 static void
25447 aeabi_set_attribute_int (int tag, int value)
25448 {
25449 if (tag < 1
25450 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
25451 || !attributes_set_explicitly[tag])
25452 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
25453 }
25454
25455 static void
25456 aeabi_set_attribute_string (int tag, const char *value)
25457 {
25458 if (tag < 1
25459 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
25460 || !attributes_set_explicitly[tag])
25461 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
25462 }
25463
25464 /* Set the public EABI object attributes. */
25465 void
25466 aeabi_set_public_attributes (void)
25467 {
25468 int arch;
25469 char profile;
25470 int virt_sec = 0;
25471 int fp16_optional = 0;
25472 arm_feature_set flags;
25473 arm_feature_set tmp;
25474 const cpu_arch_ver_table *p;
25475
25476 /* Choose the architecture based on the capabilities of the requested cpu
25477 (if any) and/or the instructions actually used. */
25478 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
25479 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
25480 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
25481
25482 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
25483 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
25484
25485 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
25486 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
25487
25488 selected_cpu = flags;
25489
25490 /* Allow the user to override the reported architecture. */
25491 if (object_arch)
25492 {
25493 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
25494 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
25495 }
25496
25497 /* We need to make sure that the attributes do not identify us as v6S-M
25498 when the only v6S-M feature in use is the Operating System Extensions. */
25499 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
25500 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
25501 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
25502
25503 tmp = flags;
25504 arch = 0;
25505 for (p = cpu_arch_ver; p->val; p++)
25506 {
25507 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
25508 {
25509 arch = p->val;
25510 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
25511 }
25512 }
25513
25514 /* The table lookup above finds the last architecture to contribute
25515 a new feature. Unfortunately, Tag13 is a subset of the union of
25516 v6T2 and v7-M, so it is never seen as contributing a new feature.
25517 We can not search for the last entry which is entirely used,
25518 because if no CPU is specified we build up only those flags
25519 actually used. Perhaps we should separate out the specified
25520 and implicit cases. Avoid taking this path for -march=all by
25521 checking for contradictory v7-A / v7-M features. */
25522 if (arch == 10
25523 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
25524 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
25525 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
25526 arch = 13;
25527
25528 /* Tag_CPU_name. */
25529 if (selected_cpu_name[0])
25530 {
25531 char *q;
25532
25533 q = selected_cpu_name;
25534 if (strncmp (q, "armv", 4) == 0)
25535 {
25536 int i;
25537
25538 q += 4;
25539 for (i = 0; q[i]; i++)
25540 q[i] = TOUPPER (q[i]);
25541 }
25542 aeabi_set_attribute_string (Tag_CPU_name, q);
25543 }
25544
25545 /* Tag_CPU_arch. */
25546 aeabi_set_attribute_int (Tag_CPU_arch, arch);
25547
25548 /* Tag_CPU_arch_profile. */
25549 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
25550 profile = 'A';
25551 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
25552 profile = 'R';
25553 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
25554 profile = 'M';
25555 else
25556 profile = '\0';
25557
25558 if (profile != '\0')
25559 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
25560
25561 /* Tag_ARM_ISA_use. */
25562 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
25563 || arch == 0)
25564 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
25565
25566 /* Tag_THUMB_ISA_use. */
25567 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
25568 || arch == 0)
25569 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
25570 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
25571
25572 /* Tag_VFP_arch. */
25573 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
25574 aeabi_set_attribute_int (Tag_VFP_arch,
25575 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
25576 ? 7 : 8);
25577 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
25578 aeabi_set_attribute_int (Tag_VFP_arch,
25579 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
25580 ? 5 : 6);
25581 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
25582 {
25583 fp16_optional = 1;
25584 aeabi_set_attribute_int (Tag_VFP_arch, 3);
25585 }
25586 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
25587 {
25588 aeabi_set_attribute_int (Tag_VFP_arch, 4);
25589 fp16_optional = 1;
25590 }
25591 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
25592 aeabi_set_attribute_int (Tag_VFP_arch, 2);
25593 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
25594 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
25595 aeabi_set_attribute_int (Tag_VFP_arch, 1);
25596
25597 /* Tag_ABI_HardFP_use. */
25598 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
25599 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
25600 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
25601
25602 /* Tag_WMMX_arch. */
25603 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
25604 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
25605 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
25606 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
25607
25608 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
25609 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
25610 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
25611 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
25612 {
25613 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
25614 {
25615 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
25616 }
25617 else
25618 {
25619 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
25620 fp16_optional = 1;
25621 }
25622 }
25623
25624 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
25625 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
25626 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
25627
25628 /* Tag_DIV_use.
25629
25630 We set Tag_DIV_use to two when integer divide instructions have been used
25631 in ARM state, or when Thumb integer divide instructions have been used,
25632 but we have no architecture profile set, nor have we any ARM instructions.
25633
25634 For ARMv8 we set the tag to 0 as integer divide is implied by the base
25635 architecture.
25636
25637 For new architectures we will have to check these tests. */
25638 gas_assert (arch <= TAG_CPU_ARCH_V8);
25639 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8))
25640 aeabi_set_attribute_int (Tag_DIV_use, 0);
25641 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
25642 || (profile == '\0'
25643 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
25644 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
25645 aeabi_set_attribute_int (Tag_DIV_use, 2);
25646
25647 /* Tag_MP_extension_use. */
25648 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
25649 aeabi_set_attribute_int (Tag_MPextension_use, 1);
25650
25651 /* Tag Virtualization_use. */
25652 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
25653 virt_sec |= 1;
25654 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
25655 virt_sec |= 2;
25656 if (virt_sec != 0)
25657 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
25658 }
25659
25660 /* Add the default contents for the .ARM.attributes section. */
25661 void
25662 arm_md_end (void)
25663 {
25664 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
25665 return;
25666
25667 aeabi_set_public_attributes ();
25668 }
25669 #endif /* OBJ_ELF */
25670
25671
25672 /* Parse a .cpu directive. */
25673
25674 static void
25675 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
25676 {
25677 const struct arm_cpu_option_table *opt;
25678 char *name;
25679 char saved_char;
25680
25681 name = input_line_pointer;
25682 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
25683 input_line_pointer++;
25684 saved_char = *input_line_pointer;
25685 *input_line_pointer = 0;
25686
25687 /* Skip the first "all" entry. */
25688 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
25689 if (streq (opt->name, name))
25690 {
25691 mcpu_cpu_opt = &opt->value;
25692 selected_cpu = opt->value;
25693 if (opt->canonical_name)
25694 strcpy (selected_cpu_name, opt->canonical_name);
25695 else
25696 {
25697 int i;
25698 for (i = 0; opt->name[i]; i++)
25699 selected_cpu_name[i] = TOUPPER (opt->name[i]);
25700
25701 selected_cpu_name[i] = 0;
25702 }
25703 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
25704 *input_line_pointer = saved_char;
25705 demand_empty_rest_of_line ();
25706 return;
25707 }
25708 as_bad (_("unknown cpu `%s'"), name);
25709 *input_line_pointer = saved_char;
25710 ignore_rest_of_line ();
25711 }
25712
25713
25714 /* Parse a .arch directive. */
25715
25716 static void
25717 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
25718 {
25719 const struct arm_arch_option_table *opt;
25720 char saved_char;
25721 char *name;
25722
25723 name = input_line_pointer;
25724 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
25725 input_line_pointer++;
25726 saved_char = *input_line_pointer;
25727 *input_line_pointer = 0;
25728
25729 /* Skip the first "all" entry. */
25730 for (opt = arm_archs + 1; opt->name != NULL; opt++)
25731 if (streq (opt->name, name))
25732 {
25733 mcpu_cpu_opt = &opt->value;
25734 selected_cpu = opt->value;
25735 strcpy (selected_cpu_name, opt->name);
25736 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
25737 *input_line_pointer = saved_char;
25738 demand_empty_rest_of_line ();
25739 return;
25740 }
25741
25742 as_bad (_("unknown architecture `%s'\n"), name);
25743 *input_line_pointer = saved_char;
25744 ignore_rest_of_line ();
25745 }
25746
25747
25748 /* Parse a .object_arch directive. */
25749
25750 static void
25751 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
25752 {
25753 const struct arm_arch_option_table *opt;
25754 char saved_char;
25755 char *name;
25756
25757 name = input_line_pointer;
25758 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
25759 input_line_pointer++;
25760 saved_char = *input_line_pointer;
25761 *input_line_pointer = 0;
25762
25763 /* Skip the first "all" entry. */
25764 for (opt = arm_archs + 1; opt->name != NULL; opt++)
25765 if (streq (opt->name, name))
25766 {
25767 object_arch = &opt->value;
25768 *input_line_pointer = saved_char;
25769 demand_empty_rest_of_line ();
25770 return;
25771 }
25772
25773 as_bad (_("unknown architecture `%s'\n"), name);
25774 *input_line_pointer = saved_char;
25775 ignore_rest_of_line ();
25776 }
25777
25778 /* Parse a .arch_extension directive. */
25779
25780 static void
25781 s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
25782 {
25783 const struct arm_option_extension_value_table *opt;
25784 char saved_char;
25785 char *name;
25786 int adding_value = 1;
25787
25788 name = input_line_pointer;
25789 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
25790 input_line_pointer++;
25791 saved_char = *input_line_pointer;
25792 *input_line_pointer = 0;
25793
25794 if (strlen (name) >= 2
25795 && strncmp (name, "no", 2) == 0)
25796 {
25797 adding_value = 0;
25798 name += 2;
25799 }
25800
25801 for (opt = arm_extensions; opt->name != NULL; opt++)
25802 if (streq (opt->name, name))
25803 {
25804 if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs))
25805 {
25806 as_bad (_("architectural extension `%s' is not allowed for the "
25807 "current base architecture"), name);
25808 break;
25809 }
25810
25811 if (adding_value)
25812 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu,
25813 opt->merge_value);
25814 else
25815 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->clear_value);
25816
25817 mcpu_cpu_opt = &selected_cpu;
25818 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
25819 *input_line_pointer = saved_char;
25820 demand_empty_rest_of_line ();
25821 return;
25822 }
25823
25824 if (opt->name == NULL)
25825 as_bad (_("unknown architecture extension `%s'\n"), name);
25826
25827 *input_line_pointer = saved_char;
25828 ignore_rest_of_line ();
25829 }
25830
25831 /* Parse a .fpu directive. */
25832
25833 static void
25834 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
25835 {
25836 const struct arm_option_fpu_value_table *opt;
25837 char saved_char;
25838 char *name;
25839
25840 name = input_line_pointer;
25841 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
25842 input_line_pointer++;
25843 saved_char = *input_line_pointer;
25844 *input_line_pointer = 0;
25845
25846 for (opt = arm_fpus; opt->name != NULL; opt++)
25847 if (streq (opt->name, name))
25848 {
25849 mfpu_opt = &opt->value;
25850 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
25851 *input_line_pointer = saved_char;
25852 demand_empty_rest_of_line ();
25853 return;
25854 }
25855
25856 as_bad (_("unknown floating point format `%s'\n"), name);
25857 *input_line_pointer = saved_char;
25858 ignore_rest_of_line ();
25859 }
25860
25861 /* Copy symbol information. */
25862
25863 void
25864 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
25865 {
25866 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
25867 }
25868
25869 #ifdef OBJ_ELF
25870 /* Given a symbolic attribute NAME, return the proper integer value.
25871 Returns -1 if the attribute is not known. */
25872
25873 int
25874 arm_convert_symbolic_attribute (const char *name)
25875 {
25876 static const struct
25877 {
25878 const char * name;
25879 const int tag;
25880 }
25881 attribute_table[] =
25882 {
25883 /* When you modify this table you should
25884 also modify the list in doc/c-arm.texi. */
25885 #define T(tag) {#tag, tag}
25886 T (Tag_CPU_raw_name),
25887 T (Tag_CPU_name),
25888 T (Tag_CPU_arch),
25889 T (Tag_CPU_arch_profile),
25890 T (Tag_ARM_ISA_use),
25891 T (Tag_THUMB_ISA_use),
25892 T (Tag_FP_arch),
25893 T (Tag_VFP_arch),
25894 T (Tag_WMMX_arch),
25895 T (Tag_Advanced_SIMD_arch),
25896 T (Tag_PCS_config),
25897 T (Tag_ABI_PCS_R9_use),
25898 T (Tag_ABI_PCS_RW_data),
25899 T (Tag_ABI_PCS_RO_data),
25900 T (Tag_ABI_PCS_GOT_use),
25901 T (Tag_ABI_PCS_wchar_t),
25902 T (Tag_ABI_FP_rounding),
25903 T (Tag_ABI_FP_denormal),
25904 T (Tag_ABI_FP_exceptions),
25905 T (Tag_ABI_FP_user_exceptions),
25906 T (Tag_ABI_FP_number_model),
25907 T (Tag_ABI_align_needed),
25908 T (Tag_ABI_align8_needed),
25909 T (Tag_ABI_align_preserved),
25910 T (Tag_ABI_align8_preserved),
25911 T (Tag_ABI_enum_size),
25912 T (Tag_ABI_HardFP_use),
25913 T (Tag_ABI_VFP_args),
25914 T (Tag_ABI_WMMX_args),
25915 T (Tag_ABI_optimization_goals),
25916 T (Tag_ABI_FP_optimization_goals),
25917 T (Tag_compatibility),
25918 T (Tag_CPU_unaligned_access),
25919 T (Tag_FP_HP_extension),
25920 T (Tag_VFP_HP_extension),
25921 T (Tag_ABI_FP_16bit_format),
25922 T (Tag_MPextension_use),
25923 T (Tag_DIV_use),
25924 T (Tag_nodefaults),
25925 T (Tag_also_compatible_with),
25926 T (Tag_conformance),
25927 T (Tag_T2EE_use),
25928 T (Tag_Virtualization_use),
25929 /* We deliberately do not include Tag_MPextension_use_legacy. */
25930 #undef T
25931 };
25932 unsigned int i;
25933
25934 if (name == NULL)
25935 return -1;
25936
25937 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
25938 if (streq (name, attribute_table[i].name))
25939 return attribute_table[i].tag;
25940
25941 return -1;
25942 }
25943
25944
25945 /* Apply sym value for relocations only in the case that they are for
25946 local symbols in the same segment as the fixup and you have the
25947 respective architectural feature for blx and simple switches. */
25948 int
25949 arm_apply_sym_value (struct fix * fixP, segT this_seg)
25950 {
25951 if (fixP->fx_addsy
25952 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
25953 /* PR 17444: If the local symbol is in a different section then a reloc
25954 will always be generated for it, so applying the symbol value now
25955 will result in a double offset being stored in the relocation. */
25956 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
25957 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
25958 {
25959 switch (fixP->fx_r_type)
25960 {
25961 case BFD_RELOC_ARM_PCREL_BLX:
25962 case BFD_RELOC_THUMB_PCREL_BRANCH23:
25963 if (ARM_IS_FUNC (fixP->fx_addsy))
25964 return 1;
25965 break;
25966
25967 case BFD_RELOC_ARM_PCREL_CALL:
25968 case BFD_RELOC_THUMB_PCREL_BLX:
25969 if (THUMB_IS_FUNC (fixP->fx_addsy))
25970 return 1;
25971 break;
25972
25973 default:
25974 break;
25975 }
25976
25977 }
25978 return 0;
25979 }
25980 #endif /* OBJ_ELF */